classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: Fixed JInternalFrame's title bar


From: Roman Kennke
Subject: [cp-patches] FYI: Fixed JInternalFrame's title bar
Date: Tue, 12 Jul 2005 17:39:09 +0200
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050331)

Hi,

I have hacked JInternalFrame's title bar in the Basic L&F, so that it matches the Basic L&F of the JDK more, and also fixed some behavioural aspects. For example, we had some candidates for paint/layout loops in the title bar's LayoutManager that I removed.

2005-07-12  Roman Kennke  <address@hidden>

        * javax/swing/plaf/basic/BasicInternalFrameTitlePane.java
        (TitlePaneLayout.layoutContainer): Do not change any state of
        the components here (visible/enableActions). This is not the
        purpose of
        a layout manager and can lead to loops. Also correct the layout
        to be closer to the layout of the reference implementation.
        (TitlePaneLayout.preferredLayoutSize): Return (22, 18)
        here. That is how high the title pane should be.
        (PaneButton): Don't set the border to null.
        (createButtons): The buttons are opaque.
        (createButtonIcons): Don't create icons in the Basic L&F.

/Roman
Index: javax/swing/plaf/basic/BasicInternalFrameTitlePane.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java,v
retrieving revision 1.9
diff -u -r1.9 BasicInternalFrameTitlePane.java
--- javax/swing/plaf/basic/BasicInternalFrameTitlePane.java     2 Jul 2005 
20:32:50 -0000       1.9
+++ javax/swing/plaf/basic/BasicInternalFrameTitlePane.java     12 Jul 2005 
14:54:54 -0000
@@ -349,48 +349,36 @@
      */
     public void layoutContainer(Container c)
     {
-      enableActions();
-
+      Dimension size = c.getSize();
       Insets insets = c.getInsets();
-      int width = c.getBounds().width - insets.left - insets.right;
-      int height = c.getBounds().height - insets.top - insets.bottom;
+      int width = size.width - insets.left - insets.right;
+      int height = size.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;
-
-      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())
+      int loc = width + insets.left - 1;
+      int top = insets.top + 1;
+      int buttonWidth = height - 2;
+      int buttonHeight = height - 4;
+      if (closeButton.isVisible())
         {
-         loc -= prefs.width;
-         closeButton.setVisible(true);
-         closeButton.setBounds(loc, top, prefs.width, prefs.height);
+         loc -= buttonWidth + 2;
+         closeButton.setBounds(loc, top, buttonWidth, buttonHeight);
         }
-      else
-       closeButton.setVisible(false);
 
-      if (maximizeAction.isEnabled())
+      if (maxButton.isVisible())
         {
-         loc -= prefs.width;
-         maxButton.setVisible(true);
-         maxButton.setBounds(loc, top, prefs.width, prefs.height);
+         loc -= buttonWidth + 2;
+         maxButton.setBounds(loc, top, buttonWidth, buttonHeight);
         }
-      else
-       maxButton.setVisible(false);
 
-      if (iconifyAction.isEnabled())
+      if (iconButton.isVisible())
         {
-         loc -= prefs.width;
-         iconButton.setVisible(true);
-         iconButton.setBounds(loc, top, prefs.width, prefs.height);
+         loc -= buttonWidth + 2;
+         iconButton.setBounds(loc, top, buttonWidth, buttonHeight);
         }
-      else
-       iconButton.setVisible(false);
 
       if (title != null)
        title.setBounds(insets.left + menupref.width, insets.top,
@@ -420,26 +408,7 @@
      */
     public Dimension preferredLayoutSize(Container c)
     {
-      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);
+      return new Dimension(22, 18);
     }
 
     /**
@@ -468,7 +437,6 @@
     {
       super(a);
       setMargin(new Insets(0, 0, 0, 0));
-      setBorder(null);
     }
 
     /**
@@ -813,26 +781,17 @@
   protected void createButtons()
   {
     closeButton = new PaneButton(closeAction);
-    closeButton.setOpaque(false);
-
     iconButton = new PaneButton(iconifyAction);
-    iconButton.setOpaque(false);
-
     maxButton = new PaneButton(maximizeAction);
-    maxButton.setOpaque(false);
   }
 
   /**
-   * This method sets the icons in the buttons.
+   * 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.
    */
   protected void setButtonIcons()
   {
-    if (closeButton != null)
-      closeButton.setIcon(closeIcon);
-    if (iconButton != null)
-      iconButton.setIcon(iconIcon);
-    if (maxButton != null)
-      maxButton.setIcon(maxIcon);
   }
 
   /**

reply via email to

[Prev in Thread] Current Thread [Next in Thread]