[Patch] javax.swing.plaf.metal merged

Michael Koch konqueror@gmx.de
Wed Apr 20 05:49:00 GMT 2005


Hi list,


in order to get javax.swing.plaf.metal merged with GNU classpath again I
commited the attached patches.


Michael


2005-04-20  Roman Kennke  <roman@kennke.org>

	* javax/swing/plaf/basic/BasicButtonUI.java
	(paint): This should not care about margin and insets
	at the same time, as insets already include the margin
	through the border.
	* javax/swing/plaf/basic/BasicGraphicsUtils.java
	(getPreferredButtonSize): Likewise.
	* javax/swing/plaf/metal/MetalBorders.java
	(getBorderInsets): Likewise.

2005-04-20  Roman Kennke  <roman@kennke.org>

	* javax/swing/plaf/basic/BasicOptionPaneUI.java
	(createMessageArea): The JPanel that holds the message area
	doesn't need to override getPreferredSize. This prevents some
	message components from rendering nicely.

2005-04-20  Roman Kennke  <roman@kennke.org>

	* javax/swing/plaf/metal/MetalInternalFrameUI.java
	(createUI): Do not share instances between components.
	* javax/swing/plaf/metal/MetalSliderUI.java
	(createUI): Do not share instances between components.

2005-04-20  Roman Kennke  <roman@kennke.org>

	* javax/swing/plaf/metal/MetalBorders:
	(PopupMenuBorder): Added.
	* javax/swing/plaf/metal/MetalLookAndFeel
	(initComponentDefaults): Added PopupMenuBorder.

2005-04-20  Roman Kennke  <roman@kennke.org>

	* javax/swing/tree/DefaultTreeSelectionModel.java:
	Added API documentation all over the class.

2005-04-20  Roman Kennke  <roman@kennke.org>

	* javax/swing/plaf/basic/BasicScrollPaneUI.java
	(installDefaults): Link managed JScrollPane in instance field.
	(uninstallDefaults): Unlink managed JScrollPane in instance field.

2005-04-20  Roman Kennke  <roman@kennke.org>

	* javax/swing/plaf/basic/BasicScrollBarUI.java
	(PropertyChangeHandler.propertyChange): Add default
	to switch statement to avoid errors with unusual values
	for orientation.
	(installComponents): Likewise.

2005-04-20  Roman Kennke  <roman@kennke.org>

	* javax/swing/plaf/metal/MetalScrollBarUI.java:
	(createUI): Instances cannot be shared among JScrollPanes.

2005-04-20  Roman Kennke  <roman@kennke.org>

	* javax/swing/plaf/metal/MetalLookAndFeel.java
	(initComponentDefaults): Added defaults for Menu, MenuBar
	MenuEntry fonts.

2005-04-20  Roman Kennke  <roman@kennke.org>

	* javax/swing/plaf/basic/BasicScrollBarUI.java
	(installUI): Install listeners after everything all, otherwise
	we get strange NPEs in some situations, especially with
	custom L&Fs.
	(createIncreaseButton): Orientation is expected to be
	SwingConstants.NORTH, ..SOUTH, ..WEST or ..EAST and not
	HORIZONTAL or VERTICAL.
	(createDecreaseButton): Orientation is expected to be
	SwingConstants.NORTH, ..SOUTH, ..WEST or ..EAST and not
	HORIZONTAL or VERTICAL.
	(installComponents): Orientation for buttons is expected to be
	SwingConstants.NORTH, ..SOUTH, ..WEST or ..EAST and not
	HORIZONTAL or VERTICAL.

2005-04-20  Roman Kennke  <roman@kennke.org>

	* javax/swing/JToolBar.java
	(addImpl): Adjust added AbstractButtons to look and feel like
	toolbar buttons.
	* javax/swing/plaf/metal/MetalBorders.java:
	Adjusted insets of ButtonBorder.
	(RolloverMarginBorder): Added class for toolbar buttons.
	(getButtonBorder): Adjusted factory method to return a shared
	instance of button border.
	(getToolbarButtonBorder): Added factory method to return a shared
	instance of toolbar button border.
	(getMarginBorder): Added factory method to return a shared
	instance of margin border.
	* javax/swing/plaf/metal/MetalButtonUI.java
	(installDefauls): If button is child of a JToolBar then set
	special border on this button.

-------------- next part --------------
Index: javax/swing/JToolBar.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JToolBar.java,v
retrieving revision 1.8
diff -u -r1.8 JToolBar.java
--- javax/swing/JToolBar.java	16 Feb 2005 20:02:37 -0000	1.8
+++ javax/swing/JToolBar.java	20 Apr 2005 05:47:09 -0000
@@ -50,6 +50,7 @@
 import javax.accessibility.AccessibleContext;
 import javax.accessibility.AccessibleRole;
 import javax.accessibility.AccessibleStateSet;
+import javax.swing.JButton;
 import javax.swing.plaf.ToolBarUI;
 
 /**
@@ -742,6 +743,15 @@
   {
     // XXX: Sun says disable button but test cases show otherwise.
     super.addImpl(component, constraints, index);
+
+    // if we added a Swing Button then adjust this a little
+    if (component instanceof AbstractButton)
+      {
+        AbstractButton b = (AbstractButton) component;
+        b.setRolloverEnabled(rollover);
+        b.updateUI();
+      }
+
   } // addImpl()
 
   /**
Index: javax/swing/plaf/basic/BasicButtonUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicButtonUI.java,v
retrieving revision 1.14
diff -u -r1.14 BasicButtonUI.java
--- javax/swing/plaf/basic/BasicButtonUI.java	16 Feb 2005 20:02:49 -0000	1.14
+++ javax/swing/plaf/basic/BasicButtonUI.java	20 Apr 2005 05:47:09 -0000
@@ -247,14 +247,12 @@
     Rectangle tr = new Rectangle();
     Rectangle ir = new Rectangle();
     Rectangle vr = new Rectangle();
-    Rectangle br = new Rectangle();
 
     Font f = c.getFont();
 
     g.setFont(f);
 
-    SwingUtilities.calculateInnerArea(b, br);
-    SwingUtilities.calculateInsetArea(br, b.getMargin(), vr);    
+    SwingUtilities.calculateInnerArea(b, vr);
     String text = SwingUtilities.layoutCompoundLabel(c, g.getFontMetrics(f), 
                                                      b.getText(),
                                                      currentIcon(b),
@@ -270,7 +268,7 @@
         || b.isSelected())
       paintButtonPressed(g, b);
     else
-      paintButtonNormal(g, br, c);
+      paintButtonNormal(g, vr, c);
 	
     paintIcon(g, c, ir);
     if (text != null)
Index: javax/swing/plaf/basic/BasicGraphicsUtils.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicGraphicsUtils.java,v
retrieving revision 1.10
diff -u -r1.10 BasicGraphicsUtils.java
--- javax/swing/plaf/basic/BasicGraphicsUtils.java	30 Nov 2004 23:59:03 -0000	1.10
+++ javax/swing/plaf/basic/BasicGraphicsUtils.java	20 Apr 2005 05:47:09 -0000
@@ -595,7 +595,6 @@
     Rectangle iconRect = new Rectangle();
     Rectangle textRect = new Rectangle();
     Insets insets = b.getInsets();
-    Insets margin = b.getMargin();
     
     viewRect = new Rectangle();
 
@@ -628,11 +627,11 @@
 
     contentRect = textRect.union(iconRect);
 
-    return new Dimension(insets.left + margin.left
+    return new Dimension(insets.left
 			 + contentRect.width 
-			 + insets.right + margin.right,
-                         insets.top + margin.top
+			 + insets.right,
+                         insets.top
 			 + contentRect.height 
-			 + insets.bottom + margin.bottom);
+			 + insets.bottom);
   }
 }
Index: javax/swing/plaf/basic/BasicOptionPaneUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicOptionPaneUI.java,v
retrieving revision 1.10
diff -u -r1.10 BasicOptionPaneUI.java
--- javax/swing/plaf/basic/BasicOptionPaneUI.java	16 Feb 2005 20:02:54 -0000	1.10
+++ javax/swing/plaf/basic/BasicOptionPaneUI.java	20 Apr 2005 05:47:09 -0000
@@ -846,18 +846,7 @@
     messageArea.setLayout(new BorderLayout());
     addIcon(messageArea);
 
-    JPanel rightSide = new JPanel()
-      {
-	public Dimension getPreferredSize()
-	{
-	  int w = Math.max(optionPane.getSize().width, minimumWidth);
-	  Insets i = optionPane.getInsets();
-	  Dimension orig = super.getPreferredSize();
-	  Dimension value = new Dimension(w - i.left - i.right - iconSize,
-	                                  orig.height);
-	  return value;
-	}
-      };
+    JPanel rightSide = new JPanel();
     rightSide.setLayout(new GridBagLayout());
     GridBagConstraints con = createConstraints();
 
Index: javax/swing/plaf/basic/BasicScrollBarUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicScrollBarUI.java,v
retrieving revision 1.10
diff -u -r1.10 BasicScrollBarUI.java
--- javax/swing/plaf/basic/BasicScrollBarUI.java	16 Feb 2005 20:02:56 -0000	1.10
+++ javax/swing/plaf/basic/BasicScrollBarUI.java	20 Apr 2005 05:47:10 -0000
@@ -152,8 +152,18 @@
         {
 	  incrButton.removeMouseListener(buttonListener);
 	  decrButton.removeMouseListener(buttonListener);
-	  incrButton = createIncreaseButton(scrollbar.getOrientation());
-	  decrButton = createDecreaseButton(scrollbar.getOrientation());
+          int orientation = scrollbar.getOrientation();
+          switch (orientation)
+            {
+            case (JScrollBar.HORIZONTAL):
+              incrButton = createIncreaseButton(EAST);
+              decrButton = createDecreaseButton(WEST);
+              break;
+            default:
+              incrButton = createIncreaseButton(SOUTH);
+              decrButton = createDecreaseButton(NORTH);
+              break;
+            }
 	  incrButton.addMouseListener(buttonListener);
 	  decrButton.addMouseListener(buttonListener);
 	  calculatePreferredSize();
@@ -513,16 +523,9 @@
   protected JButton createIncreaseButton(int orientation)
   {
     if (incrButton == null)
-      incrButton = new BasicArrowButton((orientation == SwingConstants.HORIZONTAL)
-                                        ? SwingConstants.EAST
-                                        : SwingConstants.SOUTH);
+      incrButton = new BasicArrowButton(orientation);
     else
-      {
-	if (orientation == SwingConstants.HORIZONTAL)
-	  ((BasicArrowButton) incrButton).setDirection(SwingConstants.EAST);
-	else
-	  ((BasicArrowButton) incrButton).setDirection(SwingConstants.SOUTH);
-      }
+      ((BasicArrowButton) incrButton).setDirection(orientation);
     return incrButton;
   }
 
@@ -537,16 +540,9 @@
   protected JButton createDecreaseButton(int orientation)
   {
     if (decrButton == null)
-      decrButton = new BasicArrowButton((orientation == SwingConstants.HORIZONTAL)
-                                        ? SwingConstants.WEST
-                                        : SwingConstants.NORTH);
+      decrButton = new BasicArrowButton(orientation);
     else
-      {
-	if (orientation == SwingConstants.HORIZONTAL)
-	  ((BasicArrowButton) decrButton).setDirection(SwingConstants.WEST);
-	else
-	  ((BasicArrowButton) decrButton).setDirection(SwingConstants.NORTH);
-      }
+      ((BasicArrowButton) decrButton).setDirection(orientation);
     return decrButton;
   }
 
@@ -793,9 +789,19 @@
    */
   protected void installComponents()
   {
-    incrButton = createIncreaseButton(scrollbar.getOrientation());
+    int orientation = scrollbar.getOrientation();
+    switch (orientation)
+      {
+      case (JScrollBar.HORIZONTAL):
+        incrButton = createIncreaseButton(EAST);
+        decrButton = createDecreaseButton(WEST);
+        break;
+      default:
+        incrButton = createIncreaseButton(SOUTH);
+        decrButton = createDecreaseButton(NORTH);
+        break;
+      }
     scrollbar.add(incrButton);
-    decrButton = createDecreaseButton(scrollbar.getOrientation());
     scrollbar.add(decrButton);
   }
 
@@ -869,9 +875,9 @@
 	scrollTimer.setRepeats(true);
 
 	installComponents();
-	installListeners();
 	installDefaults();
 	configureScrollBarColors();
+	installListeners();
 
 	calculatePreferredSize();
 	layoutContainer(scrollbar);
Index: javax/swing/plaf/basic/BasicScrollPaneUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicScrollPaneUI.java,v
retrieving revision 1.7
diff -u -r1.7 BasicScrollPaneUI.java
--- javax/swing/plaf/basic/BasicScrollPaneUI.java	16 Feb 2005 20:02:57 -0000	1.7
+++ javax/swing/plaf/basic/BasicScrollPaneUI.java	20 Apr 2005 05:47:10 -0000
@@ -53,7 +53,10 @@
 public class BasicScrollPaneUI extends ScrollPaneUI
   implements ScrollPaneConstants
 {
-  
+
+  /** The Scrollpane for which the UI is provided by this class. */
+  protected JScrollPane scrollpane;
+
   public static ComponentUI createUI(final JComponent c) 
   {
     return new BasicScrollPaneUI();
@@ -61,6 +64,7 @@
 
   protected void installDefaults(JScrollPane p)
   {
+    scrollpane = p;
     UIDefaults defaults = UIManager.getLookAndFeelDefaults();
     p.setForeground(defaults.getColor("ScrollPane.foreground"));
     p.setBackground(defaults.getColor("ScrollPane.background"));
@@ -75,6 +79,7 @@
     p.setBackground(null);
     p.setFont(null);
     p.setBorder(null);
+    scrollpane = null;
   }
     
   public void installUI(final JComponent c) 
Index: javax/swing/plaf/metal/MetalBorders.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/metal/MetalBorders.java,v
retrieving revision 1.1
diff -u -r1.1 MetalBorders.java
--- javax/swing/plaf/metal/MetalBorders.java	19 Apr 2005 09:59:53 -0000	1.1
+++ javax/swing/plaf/metal/MetalBorders.java	20 Apr 2005 05:47:10 -0000
@@ -49,6 +49,7 @@
 import javax.swing.border.AbstractBorder;
 import javax.swing.border.Border;
 import javax.swing.plaf.BorderUIResource;
+import javax.swing.plaf.UIResource;
 import javax.swing.plaf.basic.BasicGraphicsUtils;
 import javax.swing.plaf.basic.BasicBorders;
 
@@ -61,21 +62,28 @@
 public class MetalBorders
 {
 
+  /** The shared instance for getButtonBorder(). */
+  private static Border buttonBorder;
+
+  /** The shared instance for getRolloverButtonBorder(). */
+  private static Border toolbarButtonBorder;
+
   /**
    * A MarginBorder that gets shared by multiple components.
    * Created on demand by the private helper function {@link
    * #getMarginBorder()}.
    */
-  private static BasicBorders.MarginBorder sharedMarginBorder;
+  private static BasicBorders.MarginBorder marginBorder;
 
   /**
    * The border that is drawn around Swing buttons.
    */
   public static class MetalButtonBorder
     extends AbstractBorder
+    implements UIResource
   {
     /** The borders insets. */
-    protected static Insets borderInsets = new Insets(2, 2, 2, 2);
+    protected static Insets borderInsets = new Insets(3, 3, 3, 3);
 
     /**
      * Creates a new instance of ButtonBorder.
@@ -166,6 +174,7 @@
       if (newInsets == null)
         newInsets = new Insets(0, 0, 0, 0);
 
+      AbstractButton b = (AbstractButton) c;
       newInsets.bottom = borderInsets.bottom;
       newInsets.left = borderInsets.left;
       newInsets.right = borderInsets.right;
@@ -174,6 +183,141 @@
     }
   }
 
+  /**
+   * This border is used in Toolbar buttons as inner border.
+   */
+  static class RolloverMarginBorder extends AbstractBorder
+  {
+    /** The borders insets. */
+    protected static Insets borderInsets = new Insets(3, 3, 3, 3);
+
+    /**
+     * Creates a new instance of RolloverBorder.
+     */
+    public RolloverMarginBorder()
+    {
+    }
+    
+    /**
+     * Returns the insets of the RolloverBorder.
+     *
+     * @param c the component for which the border is used
+     *
+     * @return the insets of the RolloverBorder
+     */
+    public Insets getBorderInsets(Component c)
+    {
+      return getBorderInsets(c, null);
+    }
+
+    /**
+     * Returns the insets of the RolloverMarginBorder in the specified
+     * Insets object.
+     *
+     * @param c the component for which the border is used
+     * @param newInsets the insets object where to put the values
+     *
+     * @return the insets of the RolloverMarginBorder
+     */
+    public Insets getBorderInsets(Component c, Insets newInsets)
+    {
+      if (newInsets == null)
+        newInsets = new Insets(0, 0, 0, 0);
+
+      AbstractButton b = (AbstractButton) c;
+      Insets margin = b.getMargin();
+      newInsets.bottom = borderInsets.bottom;
+      newInsets.left = borderInsets.left;
+      newInsets.right = borderInsets.right;
+      newInsets.top = borderInsets.top;
+      return newInsets;
+    }
+  }
+
+  /**
+   * A border implementation for popup menus.
+   */
+  public static class PopupMenuBorder
+    extends AbstractBorder
+    implements UIResource
+  {
+
+    /** The border's insets. */
+    protected static Insets borderInsets = new Insets(2, 2, 1, 1);
+
+    /**
+     * Constructs a new PopupMenuBorder.
+     */
+    public PopupMenuBorder()
+    {
+    }
+    
+    /**
+     * Returns the insets of the border, creating a new Insets instance
+     * with each call.
+     *
+     * @param c the component for which we return the border insets
+     *          (not used here)
+     */
+    public Insets getBorderInsets(Component c)
+    {
+      return getBorderInsets(c, null);
+    }
+    
+    /**
+     * Returns the insets of the border, using the supplied Insets instance.
+     *
+     * @param c the component for which we return the border insets
+     *          (not used here)
+     * @param i the Insets instance to fill with the Insets values
+     */
+    public Insets getBorderInsets(Component c, Insets i)
+    {
+      Insets insets;
+      if (i == null)
+        insets = new Insets(borderInsets.top, borderInsets.left,
+                            borderInsets.bottom, borderInsets.right);
+      else
+        {
+          insets = i;
+          insets.top = borderInsets.top;
+          insets.left = borderInsets.left;
+          insets.bottom = borderInsets.bottom;
+          insets.right = borderInsets.right;
+        }
+      
+      return insets;
+    }
+
+    /**
+     * Paints the border for component <code>c</code> using the
+     * Graphics context <code>g</code> with the dimension
+     * <code>x, y, w, h</code>.
+     *
+     * @param c the component for which we paint the border
+     * @param g the Graphics context to use
+     * @param x the X coordinate of the upper left corner of c
+     * @param y the Y coordinate of the upper left corner of c
+     * @param w the width of c
+     * @param h the height of c
+     */
+    public void paintBorder(Component c, Graphics g, int x, int y, int w,
+                            int h)
+    {
+      Color darkShadow = MetalLookAndFeel.getPrimaryControlDarkShadow();
+      Color light = MetalLookAndFeel.getPrimaryControlHighlight();
+
+      // draw dark outer border
+      g.setColor(darkShadow);
+      g.drawRect(x, y, w - 1, h - 1);
+      
+      // draw highlighted inner border (only top and left)
+      g.setColor(light);
+      g.drawLine(x + 1, y + 1, x + 1, y + h - 2);
+      g.drawLine(x + 1, y + 1, x + w - 2, y + 1);
+    }
+    
+  }
 
   /**
    * Returns a border for Swing buttons in the Metal Look & Feel.
@@ -182,24 +326,42 @@
    */
   public static Border getButtonBorder()
   {
-    Border outer = new MetalButtonBorder();
-    Border inner = getMarginBorder();
-
-    return new BorderUIResource.CompoundBorderUIResource(outer, inner);
+    if (buttonBorder == null)
+      {
+        Border outer = new MetalButtonBorder();
+        Border inner = getMarginBorder();
+        buttonBorder = new BorderUIResource.CompoundBorderUIResource
+            (outer, inner);
+      }
+    return buttonBorder;
   }
 
   /**
-   * Returns a shared MarginBorder.
+   * Returns a border for Toolbar buttons in the Metal Look & Feel.
+   *
+   * @return a border for Toolbar buttons in the Metal Look & Feel
    */
-  static Border getMarginBorder()  // intentionally not public
+  static Border getToolbarButtonBorder()
   {
-    /* Swing is not designed to be thread-safe, so there is no
-     * need to synchronize the access to the global variable.
-     */
-    if (sharedMarginBorder == null)
-      sharedMarginBorder = new BasicBorders.MarginBorder();
-
-    return sharedMarginBorder;
+    if (toolbarButtonBorder == null)
+      {
+        Border outer = new MetalButtonBorder();
+        Border inner = new RolloverMarginBorder();
+        toolbarButtonBorder = new BorderUIResource.CompoundBorderUIResource
+          (outer, inner);
+      }
+    return toolbarButtonBorder;
   }
 
+  /**
+   * Returns a shared instance of {@link BasicBorders.MarginBorder}.
+   *
+   * @return a shared instance of {@link BasicBorders.MarginBorder}
+   */
+  static Border getMarginBorder()
+  {
+    if (marginBorder == null)
+      marginBorder = new BasicBorders.MarginBorder();
+    return marginBorder;
+  }
 }
Index: javax/swing/plaf/metal/MetalButtonUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/metal/MetalButtonUI.java,v
retrieving revision 1.1
diff -u -r1.1 MetalButtonUI.java
--- javax/swing/plaf/metal/MetalButtonUI.java	19 Apr 2005 09:59:53 -0000	1.1
+++ javax/swing/plaf/metal/MetalButtonUI.java	20 Apr 2005 05:47:10 -0000
@@ -40,6 +40,7 @@
 
 import javax.swing.AbstractButton;
 import javax.swing.JComponent;
+import javax.swing.JToolBar;
 import javax.swing.UIDefaults;
 import javax.swing.UIManager;
 import javax.swing.plaf.ComponentUI;
@@ -92,6 +93,9 @@
 
     UIDefaults defaults = UIManager.getLookAndFeelDefaults();
     button.setFont(defaults.getFont("Button.font"));
+
+    if (button.getParent() instanceof JToolBar)
+      button.setBorder(MetalBorders.getToolbarButtonBorder());
   }
 
 }
Index: javax/swing/plaf/metal/MetalInternalFrameUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/metal/MetalInternalFrameUI.java,v
retrieving revision 1.1
diff -u -r1.1 MetalInternalFrameUI.java
--- javax/swing/plaf/metal/MetalInternalFrameUI.java	19 Apr 2005 09:59:53 -0000	1.1
+++ javax/swing/plaf/metal/MetalInternalFrameUI.java	20 Apr 2005 05:47:10 -0000
@@ -38,6 +38,8 @@
 
 package javax.swing.plaf.metal;
 
+import java.util.HashMap;
+
 import javax.swing.JComponent;
 import javax.swing.JInternalFrame;
 import javax.swing.plaf.ComponentUI;
@@ -47,9 +49,8 @@
   extends BasicInternalFrameUI
 {
 
-  // FIXME: maybe replace by a Map of instances when this becomes stateful
-  /** The shared UI instance for JInternalFrames */
-  private static MetalInternalFrameUI instance = null;
+  /** The instances of MetalInternalFrameUI*/
+  private static HashMap instances;
 
   /**
    * Constructs a new instance of MetalInternalFrameUI.
@@ -68,8 +69,20 @@
    */
   public static ComponentUI createUI(JComponent component)
   {
-    if (instance == null)
-      instance = new MetalInternalFrameUI((JInternalFrame) component);
+    if (instances == null)
+      instances = new HashMap();
+
+
+    Object o = instances.get(component);
+    MetalInternalFrameUI instance;
+    if (o == null)
+      {
+	instance = new MetalInternalFrameUI((JInternalFrame) component);
+	instances.put(component, instance);
+      }
+    else
+      instance = (MetalInternalFrameUI) o;
+
     return instance;
   }
 }
Index: javax/swing/plaf/metal/MetalLookAndFeel.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/metal/MetalLookAndFeel.java,v
retrieving revision 1.8
diff -u -r1.8 MetalLookAndFeel.java
--- javax/swing/plaf/metal/MetalLookAndFeel.java	19 Apr 2005 09:59:53 -0000	1.8
+++ javax/swing/plaf/metal/MetalLookAndFeel.java	20 Apr 2005 05:47:10 -0000
@@ -449,6 +449,9 @@
    * </tr><tr>
    * <td>ScrollBar.background</td><td>0xcccccc</td>
    * </tr><tr>
+   * <td>PopupMenu.border</td>
+   * <td><code>new javax.swing.plaf.metal.MetalBorders.PopupMenuBorder()</td>
+   * </tr><tr>
    * </table>
    *
    * @param defaults the UIDefaults instance to which the values are added
@@ -472,9 +475,13 @@
       "Label.background", new ColorUIResource(getControl()),
       "Label.font", getControlTextFont(),
       "Menu.background", new ColorUIResource(getControl()),
+      "Menu.font", getControlTextFont(),
       "MenuBar.background", new ColorUIResource(getControl()),
+      "MenuBar.font", getControlTextFont(),
       "MenuItem.background", new ColorUIResource(getControl()),
-      "ScrollBar.background", new ColorUIResource(getControl())
+      "MenuItem.font", getControlTextFont(),
+      "ScrollBar.background", new ColorUIResource(getControl()),
+      "PopupMenu.border", new MetalBorders.PopupMenuBorder()
     };
     defaults.putDefaults(myDefaults);
   }
Index: javax/swing/plaf/metal/MetalScrollBarUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/metal/MetalScrollBarUI.java,v
retrieving revision 1.1
diff -u -r1.1 MetalScrollBarUI.java
--- javax/swing/plaf/metal/MetalScrollBarUI.java	19 Apr 2005 09:59:53 -0000	1.1
+++ javax/swing/plaf/metal/MetalScrollBarUI.java	20 Apr 2005 05:47:10 -0000
@@ -38,6 +38,8 @@
 
 package javax.swing.plaf.metal;
 
+import java.util.HashMap;
+
 import javax.swing.JComponent;
 import javax.swing.plaf.ComponentUI;
 import javax.swing.plaf.basic.BasicScrollBarUI;
@@ -48,7 +50,7 @@
 
   // FIXME: maybe replace by a Map of instances when this becomes stateful
   /** The shared UI instance for JScrollBars. */
-  private static MetalScrollBarUI instance = null;
+  private static HashMap instances = null;
 
   /**
    * Constructs a new instance of MetalScrollBarUI.
@@ -67,8 +69,19 @@
    */
   public static ComponentUI createUI(JComponent component)
   {
-    if (instance == null)
-      instance = new MetalScrollBarUI();
+    if (instances == null)
+      instances = new HashMap();
+
+    Object o = instances.get(component);
+    MetalScrollBarUI instance;
+    if (o == null)
+      {
+	instance = new MetalScrollBarUI();
+	instances.put(component, instance);
+      }
+    else
+      instance = (MetalScrollBarUI) o;
+
     return instance;
   }
 }
Index: javax/swing/plaf/metal/MetalSliderUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/metal/MetalSliderUI.java,v
retrieving revision 1.1
diff -u -r1.1 MetalSliderUI.java
--- javax/swing/plaf/metal/MetalSliderUI.java	19 Apr 2005 09:59:53 -0000	1.1
+++ javax/swing/plaf/metal/MetalSliderUI.java	20 Apr 2005 05:47:10 -0000
@@ -38,6 +38,8 @@
 
 package javax.swing.plaf.metal;
 
+import java.util.HashMap;
+
 import javax.swing.JComponent;
 import javax.swing.plaf.ComponentUI;
 import javax.swing.plaf.basic.BasicSliderUI;
@@ -46,9 +48,8 @@
   extends BasicSliderUI
 {
 
-  // FIXME: maybe replace by a Map of instances when this becomes stateful
-  /** The shared UI instance for MetalSliderUIs */
-  private static MetalSliderUI instance = null;
+  /** The UI instances for MetalSliderUIs */
+  private static HashMap instances;
 
   /**
    * Constructs a new instance of MetalSliderUI.
@@ -67,8 +68,20 @@
    */
   public static ComponentUI createUI(JComponent component)
   {
-    if (instance == null)
-      instance = new MetalSliderUI();
+    if (instances == null)
+      instances = new HashMap();
+
+
+    Object o = instances.get(component);
+    MetalSliderUI instance;
+    if (o == null)
+      {
+	instance = new MetalSliderUI();
+	instances.put(component, instance);
+      }
+    else
+      instance = (MetalSliderUI) o;
+
     return instance;
   }
 }
Index: javax/swing/tree/DefaultTreeSelectionModel.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/tree/DefaultTreeSelectionModel.java,v
retrieving revision 1.4
diff -u -r1.4 DefaultTreeSelectionModel.java
--- javax/swing/tree/DefaultTreeSelectionModel.java	30 Nov 2004 23:59:09 -0000	1.4
+++ javax/swing/tree/DefaultTreeSelectionModel.java	20 Apr 2005 05:47:10 -0000
@@ -67,52 +67,52 @@
   public static final String SELECTION_MODE_PROPERTY = "selectionMode";
 
   /**
-   * changeSupport
+   * Our Swing property change support.
    */
   protected SwingPropertyChangeSupport changeSupport;
 
   /**
-   * selection
+   * The current selection.
    */
   protected TreePath[] selection;
 
   /**
-   * listenerList
+   * Our TreeSelectionListeners.
    */
   protected EventListenerList listenerList;
 
   /**
-   * rowMapper
+   * The current RowMapper.
    */
   protected transient RowMapper rowMapper;
 
   /**
-   * listSelectionModel
+   * The current listSelectionModel.
    */
   protected DefaultListSelectionModel listSelectionModel;
 
   /**
-   * selectionMode
+   * The current selection mode.
    */
   protected int selectionMode;
 
   /**
-   * leadPath
+   * The path that has been added last.
    */
   protected TreePath leadPath;
 
   /**
-   * leadIndex
+   * The index of the last added path.
    */
   protected int leadIndex;
 
   /**
-   * leadRow
+   * The row of the last added path according to the RowMapper.
    */
   protected int leadRow;
 
   /**
-   * Constructor DefaultTreeSelectionModel
+   * Constructs a new DefaultTreeSelectionModel.
    */
   public DefaultTreeSelectionModel()
   {
@@ -120,9 +120,12 @@
   }
 
   /**
-   * clone
-   * @exception CloneNotSupportedException TODO
-   * @return Object
+   * Creates a clone of this DefaultTreeSelectionModel with the same
+   * selection.
+   *
+   * @exception CloneNotSupportedException should not be thrown here
+   *
+   * @return a clone of this DefaultTreeSelectionModel
    */
   public Object clone() throws CloneNotSupportedException
   {
@@ -130,8 +133,9 @@
   }
 
   /**
-   * toString
-   * @return String
+   * Returns a string that shows this object's properties.
+   *
+   * @return a string that shows this object's properties
    */
   public String toString()
   {
@@ -161,8 +165,12 @@
   }
 
   /**
-   * setRowMapper
-   * @param value0 TODO
+   * Sets the RowMapper that should be used to map between paths and their
+   * rows.
+   *
+   * @param rowMapper the RowMapper to set
+   *
+   * @see {@link RowMapper
    */
   public void setRowMapper(RowMapper value0)
   {
@@ -170,8 +178,12 @@
   }
 
   /**
-   * getRowMapper
-   * @return RowMapper
+   * Returns the RowMapper that is currently used to map between paths and
+   * their rows.
+   *
+   * @return the current RowMapper
+   *
+   * @see {@link RowMapper
    */
   public RowMapper getRowMapper()
   {
@@ -179,8 +191,16 @@
   }
 
   /**
-   * setSelectionMode
-   * @param value0 TODO
+   * Sets the current selection mode. Possible values are
+   * {@link #SINGLE_TREE_SELECTION}, {@link CONTIGUOUS_TREE_SELECTION}
+   * and {@link #DISCONTIGUOUS_TREE_SELECTION}.
+   *
+   * @param mode the selection mode to be set
+   *
+   * @see {@link #getSelectionMode}
+   * @see {@link #SINGLE_TREE_SELECTION}
+   * @see {@link #CONTIGUOUS_TREE_SELECTION}
+   * @see {@link #DISCONTIGUOUS_TREE_SELECTION}
    */
   public void setSelectionMode(int value0)
   {
@@ -188,8 +208,14 @@
   }
 
   /**
-   * getSelectionMode
-   * @return int
+   * Returns the current selection mode.
+   *
+   * @return the current selection mode
+   *
+   * @see {@link #setSelectionMode}
+   * @see {@link #SINGLE_TREE_SELECTION}
+   * @see {@link #CONTIGUOUS_TREE_SELECTION}
+   * @see {@link #DISCONTIGUOUS_TREE_SELECTION}
    */
   public int getSelectionMode()
   {
@@ -197,8 +223,12 @@
   }
 
   /**
-   * setSelectionPath
-   * @param value0 TODO
+   * Sets this path as the only selection.
+   *
+   * If this changes the selection the registered TreeSelectionListeners
+   * are notified.
+   *
+   * @param path the path to set as selection
    */
   public void setSelectionPath(TreePath value0)
   {
@@ -206,8 +236,13 @@
   }
 
   /**
-   * setSelectionPaths
-   * @param value0 TODO
+   * Sets the paths as selection. This method checks for duplicates and
+   * removes them.
+   *
+   * If this changes the selection the registered TreeSelectionListeners
+   * are notified.
+   *
+   * @param paths the paths to set as selection
    */
   public void setSelectionPaths(TreePath[] value0)
   {
@@ -215,8 +250,13 @@
   }
 
   /**
-   * addSelectionPath
-   * @param value0 TODO
+   * Adds a path to the list of selected paths. This method checks if the
+   * path is already selected and doesn't add the same path twice.
+   *
+   * If this changes the selection the registered TreeSelectionListeners
+   * are notified.
+   *
+   * @param path the path to add to the selection
    */
   public void addSelectionPath(TreePath value0)
   {
@@ -224,8 +264,13 @@
   }
 
   /**
-   * addSelectionPaths
-   * @param value0 TODO
+   * Adds the paths to the list of selected paths. This method checks if the
+   * paths are already selected and doesn't add the same path twice.
+   *
+   * If this changes the selection the registered TreeSelectionListeners
+   * are notified.
+   *
+   * @param paths the paths to add to the selection
    */
   public void addSelectionPaths(TreePath[] value0)
   {
@@ -233,8 +278,12 @@
   }
 
   /**
-   * removeSelectionPath
-   * @param value0 TODO
+   * Removes the path from the selection.
+   *
+   * If this changes the selection the registered TreeSelectionListeners
+   * are notified.
+   *
+   * @param path the path to remove
    */
   public void removeSelectionPath(TreePath value0)
   {
@@ -242,8 +291,12 @@
   }
 
   /**
-   * removeSelectionPaths
-   * @param value0 TODO
+   * Removes the paths from the selection.
+   *
+   * If this changes the selection the registered TreeSelectionListeners
+   * are notified.
+   *
+   * @param paths the path to remove
    */
   public void removeSelectionPaths(TreePath[] value0)
   {
@@ -251,8 +304,10 @@
   }
 
   /**
-   * getSelectionPath
-   * @return TreePath
+   * Returns the first path in the selection. This is especially useful
+   * when the selectionMode is {@link #SINGLE_TREE_SELECTION}.
+   *
+   * @return the first path in the selection
    */
   public TreePath getSelectionPath()
   {
@@ -260,8 +315,9 @@
   }
 
   /**
-   * getSelectionPaths
-   * @return TreePath[]
+   * Returns the complete selection.
+   *
+   * @return the complete selection
    */
   public TreePath[] getSelectionPaths()
   {
@@ -269,8 +325,9 @@
   }
 
   /**
-   * getSelectionCount
-   * @return int
+   * Returns the number of paths in the selection.
+   *
+   * @return the number of paths in the selection
    */
   public int getSelectionCount()
   {
@@ -278,9 +335,12 @@
   }
 
   /**
-   * isPathSelected
-   * @param value0 TODO
-   * @return boolean
+   * Checks if a given path is in the selection.
+   *
+   * @param path the path to check
+   *
+   * @return <code>true</code> if the path is in the selection,
+   *         <code>false</code> otherwise
    */
   public boolean isPathSelected(TreePath value0)
   {
@@ -288,8 +348,10 @@
   }
 
   /**
-   * isSelectionEmpty
-   * @return boolean
+   * Checks if the selection is empty.
+   *
+   * @return <code>true</code> if the selection is empty,
+   *         <code>false</code> otherwise
    */
   public boolean isSelectionEmpty()
   {
@@ -297,7 +359,7 @@
   }
 
   /**
-   * clearSelection
+   * Removes all paths from the selection.
    */
   public void clearSelection()
   {
@@ -364,8 +426,9 @@
   }
 
   /**
-   * getSelectionRows
-   * @return int[]
+   * Returns the currently selected rows.
+   *
+   * @return the currently selected rows
    */
   public int[] getSelectionRows()
   {
@@ -373,8 +436,9 @@
   }
 
   /**
-   * getMinSelectionRow
-   * @return int
+   * Returns the smallest row index from the selection.
+   *
+   * @return the smallest row index from the selection
    */
   public int getMinSelectionRow()
   {
@@ -382,8 +446,9 @@
   }
 
   /**
-   * getMaxSelectionRow
-   * @return int
+   * Returns the largest row index from the selection.
+   *
+   * @return the largest row index from the selection
    */
   public int getMaxSelectionRow()
   {
@@ -391,9 +456,12 @@
   }
 
   /**
-   * isRowSelected
-   * @param value0 TODO
-   * @return boolean
+   * Checks if a particular row is selected.
+   *
+   * @param row the index of the row to check
+   *
+   * @return <code>true</code> if the row is in this selection,
+   *         <code>false</code> otherwise
    */
   public boolean isRowSelected(int value0)
   {
@@ -401,7 +469,7 @@
   }
 
   /**
-   * resetRowSelection
+   * Updates the mappings from TreePaths to row indices.
    */
   public void resetRowSelection()
   {
@@ -459,7 +527,16 @@
   }
 
   /**
-   * insureRowContinuity
+   * Makes sure the currently selected paths are valid according to the
+   * current selectionMode.
+   *
+   * If the selectionMode is set to {@link CONTIGUOUS_TREE_SELECTION}
+   * and the selection isn't contiguous then the selection is reset to
+   * the first set of contguous paths.
+   *
+   * If the selectionMode is set to {@link SINGLE_TREE_SELECTION}
+   * and the selection has more than one path, the selection is reset to
+   * the contain only the first path.
    */
   protected void insureRowContinuity()
   {
@@ -467,9 +544,12 @@
   }
 
   /**
-   * arePathsContiguous
-   * @param value0 TODO
-   * @return boolean
+   * Returns <code>true</code> if the paths are contiguous or we
+   * have no RowMapper assigned.
+   *
+   * @param paths the paths to check for continuity
+   * @return <code>true</code> if the paths are contiguous or we
+   *         have no RowMapper assigned
    */
   protected boolean arePathsContiguous(TreePath[] value0)
   {
@@ -477,9 +557,19 @@
   }
 
   /**
-   * canPathsBeAdded
-   * @param value0 TODO
-   * @return boolean
+   * Checks if the paths can be added. This returns <code>true</code> if:
+   * <ul>
+   * <li><code>paths</code> is <code>null</code> or empty</li>
+   * <li>we have no RowMapper assigned</li>
+   * <li>nothing is currently selected</li>
+   * <li>selectionMode is {@link DISCONTIGUOUS_TREE_SELECTION</li>
+   * <li>adding the paths to the selection still results in a contiguous set
+   *   of paths</li>
+   *
+   * @param paths the paths to check
+   *
+   * @return <code>true</code> if the paths can be added with respect to the
+   *         selectionMode
    */
   protected boolean canPathsBeAdded(TreePath[] value0)
   {
@@ -487,9 +577,12 @@
   }
 
   /**
-   * canPathsBeRemoved
-   * @param value0 TODO
-   * @return boolean
+   * Checks if the paths can be removed without breaking the continuity of
+   * the selection according to selectionMode.
+   *
+   * @param paths the paths to check
+   * @return  <code>true</code> if the paths can be removed with respect to the
+   *         selectionMode
    */
   protected boolean canPathsBeRemoved(TreePath[] value0)
   {
@@ -507,7 +600,7 @@
   }
 
   /**
-   * updateLeadIndex
+   * Updates the lead index instance field.
    */
   protected void updateLeadIndex()
   {
@@ -515,7 +608,7 @@
   }
 
   /**
-   * insureUniqueness
+   * Deprecated and not used.
    */
   protected void insureUniqueness()
   {


More information about the Java-patches mailing list