--- /home/cpdev/src/classpath/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java	2005-07-12 17:32:36.000000000 +0000
+++ javax/swing/plaf/basic/BasicInternalFrameTitlePane.java	2005-06-30 05:35:18.000000000 +0000
@@ -77,10 +77,6 @@
 {
   /**
    * The Action responsible for closing the JInternalFrame.
-   *
-   * @specnote Apparently this class was intended to be protected,
-   *           but was made public by a compiler bug and is now
-   *           public for compatibility.
    */
   public class CloseAction extends AbstractAction
   {
@@ -106,10 +102,6 @@
 
   /**
    * This Action is responsible for iconifying the JInternalFrame.
-   *
-   * @specnote Apparently this class was intended to be protected,
-   *           but was made public by a compiler bug and is now
-   *           public for compatibility.
    */
   public class IconifyAction extends AbstractAction
   {
@@ -136,10 +128,6 @@
 
   /**
    * This Action is responsible for maximizing the JInternalFrame.
-   *
-   * @specnote Apparently this class was intended to be protected,
-   *           but was made public by a compiler bug and is now
-   *           public for compatibility.
    */
   public class MaximizeAction extends AbstractAction
   {
@@ -166,10 +154,6 @@
 
   /**
    * This Action is responsible for dragging the JInternalFrame.
-   *
-   * @specnote Apparently this class was intended to be protected,
-   *           but was made public by a compiler bug and is now
-   *           public for compatibility.
    */
   public class MoveAction extends AbstractAction
   {
@@ -187,10 +171,6 @@
   /**
    * This Action is responsible for restoring the JInternalFrame. Restoring
    * the JInternalFrame is the same as setting the maximum property to false.
-   *
-   * @specnote Apparently this class was intended to be protected,
-   *           but was made public by a compiler bug and is now
-   *           public for compatibility.
    */
   public class RestoreAction extends AbstractAction
   {
@@ -217,10 +197,6 @@
 
   /**
    * This action is responsible for sizing the JInternalFrame.
-   *
-   * @specnote Apparently this class was intended to be protected,
-   *           but was made public by a compiler bug and is now
-   *           public for compatibility.
    */
   public class SizeAction extends AbstractAction
   {
@@ -238,12 +214,8 @@
   /**
    * This class is responsible for handling property change events from the
    * JInternalFrame and adjusting the Title Pane as necessary.
-   *
-   * @specnote Apparently this class was intended to be protected,
-   *           but was made public by a compiler bug and is now
-   *           public for compatibility.
    */
-  public class PropertyChangeHandler implements PropertyChangeListener
+  protected class PropertyChangeHandler implements PropertyChangeListener
   {
     /**
      * This method is called when a PropertyChangeEvent is received by the
@@ -253,39 +225,17 @@
      */
     public void propertyChange(PropertyChangeEvent evt)
     {
-      String propName = evt.getPropertyName();
-      if (propName.equals("closable"))
-	{
-	  if (evt.getNewValue().equals(Boolean.TRUE))
-	    closeButton.setVisible(true);
-	  else
-	    closeButton.setVisible(false);
-	}
-      else if (propName.equals("iconifiable"))
-	{
-	  if (evt.getNewValue().equals(Boolean.TRUE))
-	    iconButton.setVisible(true);
-	  else
-	    iconButton.setVisible(false);
-	}
-      else if (propName.equals("maximizable"))
-	{
-	  if (evt.getNewValue().equals(Boolean.TRUE))
-	    maxButton.setVisible(true);
-	  else
-	    maxButton.setVisible(false);
-	}
-	
+      // The title and frameIcon are taken care of during painting time.
+      // The only other thing this will care about are the "is----izable"
+      // properties. So we call enable actions to properly handle the 
+      // buttons and menu items for us.
+      enableActions();
     }
   }
 
   /**
    * This class acts as the MenuBar for the TitlePane. Clicking on the Frame
    * Icon in the top left corner will activate it.
-   *
-   * @specnote Apparently this class was intended to be protected,
-   *           but was made public by a compiler bug and is now
-   *           public for compatibility.
    */
   public class SystemMenuBar extends JMenuBar
   {
@@ -334,12 +284,8 @@
 
   /**
    * This class acts as the Layout Manager for the TitlePane.
-   *
-   * @specnote Apparently this class was intended to be protected,
-   *           but was made public by a compiler bug and is now
-   *           public for compatibility.
    */
-  public class TitlePaneLayout implements LayoutManager
+  protected class TitlePaneLayout implements LayoutManager
   {
     /**
      * Creates a new <code>TitlePaneLayout</code> object.
@@ -367,36 +313,48 @@
      */
     public void layoutContainer(Container c)
     {
-      Dimension size = c.getSize();
+      enableActions();
+
       Insets insets = c.getInsets();
-      int width = size.width - insets.left - insets.right;
-      int height = size.height - insets.top - insets.bottom;
+      int width = c.getBounds().width - insets.left - insets.right;
+      int height = c.getBounds().height - insets.top - insets.bottom;
 
       // MenuBar is always present and located at the top left corner.
       Dimension menupref = menuBar.getPreferredSize();
       menuBar.setBounds(insets.left, insets.top, menupref.width, height);
 
-      int loc = width + insets.left - 1;
-      int top = insets.top + 1;
-      int buttonWidth = height - 2;
-      int buttonHeight = height - 4;
-      if (closeButton.isVisible())
+      int loc = width + insets.left;
+
+      Insets i = closeButton.getInsets();
+      Dimension prefs = new Dimension(iconSize + i.left + i.right,
+                                      iconSize + i.top + i.bottom);
+      int top = insets.top + (height - prefs.height) / 2;
+      if (closeAction.isEnabled())
         {
-	  loc -= buttonWidth + 2;
-	  closeButton.setBounds(loc, top, buttonWidth, buttonHeight);
+	  loc -= prefs.width;
+	  closeButton.setVisible(true);
+	  closeButton.setBounds(loc, top, prefs.width, prefs.height);
         }
+      else
+	closeButton.setVisible(false);
 
-      if (maxButton.isVisible())
+      if (maximizeAction.isEnabled())
         {
-	  loc -= buttonWidth + 2;
-	  maxButton.setBounds(loc, top, buttonWidth, buttonHeight);
+	  loc -= prefs.width;
+	  maxButton.setVisible(true);
+	  maxButton.setBounds(loc, top, prefs.width, prefs.height);
         }
+      else
+	maxButton.setVisible(false);
 
-      if (iconButton.isVisible())
+      if (iconifyAction.isEnabled())
         {
-	  loc -= buttonWidth + 2;
-	  iconButton.setBounds(loc, top, buttonWidth, buttonHeight);
+	  loc -= prefs.width;
+	  iconButton.setVisible(true);
+	  iconButton.setBounds(loc, top, prefs.width, prefs.height);
         }
+      else
+	iconButton.setVisible(false);
 
       if (title != null)
 	title.setBounds(insets.left + menupref.width, insets.top,
@@ -426,7 +384,26 @@
      */
     public Dimension preferredLayoutSize(Container c)
     {
-      return new Dimension(22, 18);
+      Insets frameInsets = frame.getInsets();
+
+      // Height is the max of the preferredHeights of all components
+      // inside the pane
+      int height = 0;
+      int width = 0;
+      Dimension d;
+
+      Component[] components = BasicInternalFrameTitlePane.this.getComponents();
+      for (int i = 0; i < components.length; i++)
+        {
+	  d = components[i].getPreferredSize();
+	  height = Math.max(height, d.height);
+	  width += d.width;
+        }
+
+      Insets insets = BasicInternalFrameTitlePane.this.getInsets();
+      height += insets.top + insets.bottom;
+
+      return new Dimension(width, height);
     }
 
     /**
@@ -455,6 +432,7 @@
     {
       super(a);
       setMargin(new Insets(0, 0, 0, 0));
+      setBorder(null);
     }
 
     /**
@@ -526,14 +504,110 @@
   /** Inactive foreground color. */
   protected Color inactiveFGColor;
 
+  // FIXME: These icons need to be moved to MetalIconFactory.
+
+  /** The size of the icons in the buttons. */
+  private static final int iconSize = 16;
+
+  /** The icon displayed in the close button. */
+  protected Icon closeIcon = new Icon()
+    {
+      public int getIconHeight()
+      {
+	return iconSize;
+      }
+
+      public int getIconWidth()
+      {
+	return iconSize;
+      }
+
+      public void paintIcon(Component c, Graphics g, int x, int y)
+      {
+	g.translate(x, y);
+	Color saved = g.getColor();
+	g.setColor(Color.BLACK);
+
+	int four = iconSize / 4;
+	int six = iconSize * 6 / 16;
+	int ten = iconSize * 10 / 16;
+	int twelve = iconSize * 12 / 16;
+
+	Polygon a = new Polygon(new int[] { four, six, ten, twelve },
+	                        new int[] { six, four, twelve, ten }, 4);
+	Polygon b = new Polygon(new int[] { four, six, ten, twelve },
+	                        new int[] { ten, twelve, four, six }, 4);
+
+	g.fillPolygon(a);
+	g.fillPolygon(b);
+
+	g.setColor(saved);
+	g.translate(-x, -y);
+      }
+    };
+
+  // FIXME: Create new icon.
+
   /** The icon displayed in the restore button. */
-  protected Icon minIcon = BasicIconFactory.createEmptyFrameIcon();
+  protected Icon minIcon;
 
   /** The icon displayed in the maximize button. */
-  protected Icon maxIcon = BasicIconFactory.createEmptyFrameIcon();
+  protected Icon maxIcon = new Icon()
+    {
+      public int getIconHeight()
+      {
+	return iconSize;
+      }
+
+      public int getIconWidth()
+      {
+	return iconSize;
+      }
+
+      public void paintIcon(Component c, Graphics g, int x, int y)
+      {
+	g.translate(x, y);
+	Color saved = g.getColor();
+	g.setColor(Color.BLACK);
+
+	int four = iconSize / 4;
+	int two = four / 2;
+	int six = iconSize * 6 / 16;
+	int eight = four * 2;
+
+	g.fillRect(four, four, eight, two);
+	g.drawRect(four, six, eight, six);
+
+	g.setColor(saved);
+	g.translate(-x, -y);
+      }
+    };
 
   /** The icon displayed in the iconify button. */
-  protected Icon iconIcon = BasicIconFactory.createEmptyFrameIcon();
+  protected Icon iconIcon = new Icon()
+    {
+      public int getIconHeight()
+      {
+	return iconSize;
+      }
+
+      public int getIconWidth()
+      {
+	return iconSize;
+      }
+
+      public void paintIcon(Component c, Graphics g, int x, int y)
+      {
+	g.translate(x, y);
+	Color saved = g.getColor();
+	g.setColor(Color.BLACK);
+
+	g.fillRect(iconSize / 4, iconSize * 10 / 16, iconSize / 2, iconSize / 8);
+
+	g.setColor(saved);
+	g.translate(-x, -y);
+      }
+    };
 
   /** The JInternalFrame that this TitlePane is used in. */
   protected JInternalFrame frame;
@@ -703,23 +777,23 @@
   protected void createButtons()
   {
     closeButton = new PaneButton(closeAction);
-    if (!frame.isClosable())
-      closeButton.setVisible(false);
+    closeButton.setOpaque(false);
+
     iconButton = new PaneButton(iconifyAction);
-    if (!frame.isIconifiable())
-      iconButton.setVisible(false);
+    iconButton.setOpaque(false);
+
     maxButton = new PaneButton(maximizeAction);
-    if (!frame.isMaximizable())
-      maxButton.setVisible(false);
+    maxButton.setOpaque(false);
   }
 
   /**
-   * This method sets the icons in the buttons. This is a no-op method here, it
-   * can be overridden by subclasses to set icons for the minimize-, maximize-
-   * and close-buttons.
+   * This method sets the icons in the buttons.
    */
   protected void setButtonIcons()
   {
+    closeButton.setIcon(closeIcon);
+    iconButton.setIcon(iconIcon);
+    maxButton.setIcon(maxIcon);
   }
 
   /**
