commit-classpath
[Top][All Lists]
Advanced

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

[commit-cp] FYI: MetalToolBarUI etc


From: David Gilbert
Subject: [commit-cp] FYI: MetalToolBarUI etc
Date: Tue, 27 Sep 2005 16:45:20 +0000
User-agent: Mozilla Thunderbird 1.0.6 (X11/20050728)

I committed this patch to implement some of the missing items in MetalToolBarUI:

2005-09-27  David Gilbert  <address@hidden>

        * javax/swing/plaf/basic/BasicToolBarUI.java
        (instalDefaults): get border from UI defaults,
        * javax/swing/plaf/metal/MetalBorders.java:
        (ToolBarBorder): new class,
        * javax/swing/plaf/metal/MetalLookAndFeel.java
        (initComponentDefaults): added tool bar border default,
        * javax/swing/plaf/metal/MetalToolBarUI.java
        (MetalContainerListener): new class,
        (instance): removed field,
        (MetalRolloverListener): new class,
        (contListener): new field,
        (rolloverListener): new field,
        (createUI): return a new instance every time,
        (createRolloverListener): implemented,
        (createContainerListener): implemented,
        (createNonRolloverBorder): implemented.

Regards,

Dave
Index: javax/swing/plaf/basic/BasicToolBarUI.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicToolBarUI.java,v
retrieving revision 1.13
diff -u -r1.13 BasicToolBarUI.java
--- javax/swing/plaf/basic/BasicToolBarUI.java  24 Sep 2005 20:56:20 -0000      
1.13
+++ javax/swing/plaf/basic/BasicToolBarUI.java  27 Sep 2005 15:29:19 -0000
@@ -589,7 +589,7 @@
   {
     UIDefaults defaults = UIManager.getLookAndFeelDefaults();
 
-    toolBar.setBorder(new ToolBarBorder());
+    toolBar.setBorder(defaults.getBorder("ToolBar.border"));
     toolBar.setBackground(defaults.getColor("ToolBar.background"));
     toolBar.setForeground(defaults.getColor("ToolBar.foreground"));
     toolBar.setFont(defaults.getFont("ToolBar.font"));
Index: javax/swing/plaf/metal/MetalBorders.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalBorders.java,v
retrieving revision 1.19
diff -u -r1.19 MetalBorders.java
--- javax/swing/plaf/metal/MetalBorders.java    23 Sep 2005 10:47:34 -0000      
1.19
+++ javax/swing/plaf/metal/MetalBorders.java    27 Sep 2005 15:29:21 -0000
@@ -52,6 +52,7 @@
 import javax.swing.JOptionPane;
 import javax.swing.JTextField;
 import javax.swing.JToggleButton;
+import javax.swing.JToolBar;
 import javax.swing.UIDefaults;
 import javax.swing.UIManager;
 import javax.swing.border.AbstractBorder;
@@ -1144,6 +1145,100 @@
     }
   }
 
+  /**
+   * A border used when painting address@hidden JToolBar} instances.
+   */
+  public static class ToolBarBorder extends AbstractBorder
+    implements UIResource
+  {
+    /**
+     * Creates a new border instance.
+     */
+    public ToolBarBorder()
+    {
+    }
+    
+    /**
+     * Returns the border insets.
+     * 
+     * @param c  the component (ignored).
+     * 
+     * @return The border insets.
+     */
+    public Insets getBorderInsets(Component c)
+    {
+      return getBorderInsets(c, null);
+    }
+    
+    /**
+     * Returns the border insets.
+     * 
+     * @param c  the component (ignored).
+     * @return The border insets.
+     */
+    public Insets getBorderInsets(Component c, Insets newInsets)
+    {
+      JToolBar tb = (JToolBar) c;
+      if (tb.getOrientation() == JToolBar.HORIZONTAL)
+        {   
+          if (newInsets == null)
+            newInsets = new Insets(2, 16, 2, 2);
+          else
+            {
+              newInsets.top = 2;
+              newInsets.left = 16;
+              newInsets.bottom = 2;
+              newInsets.right = 2;
+            }
+          return newInsets;  
+        }
+      else // assume JToolBar.VERTICAL
+        { 
+          if (newInsets == null)
+            newInsets = new Insets(16, 2, 2, 2);
+          else
+            {
+              newInsets.top = 16;
+              newInsets.left = 2;
+              newInsets.bottom = 2;
+              newInsets.right = 2;
+            }
+          return newInsets;  
+        }
+
+    }
+    
+    /**
+     * Paints the border for the specified component.
+     * 
+     * @param c  the component.
+     * @param g  the graphics device.
+     * @param x  the x-coordinate.
+     * @param y  the y-coordinate.
+     * @param w  the width.
+     * @param h  the height.
+     */
+    public void paintBorder(Component c, Graphics g, int x, int y, int w, 
+        int h)
+    {
+        
+      JToolBar tb = (JToolBar) c;
+      if (tb.getOrientation() == JToolBar.HORIZONTAL)
+        {
+           MetalUtils.fillMetalPattern(g, x + 2, y + 2, x + 11, y + h - 5, 
+                  MetalLookAndFeel.getControlHighlight(), 
+                  MetalLookAndFeel.getControlDarkShadow());
+        }
+      else
+        { 
+          MetalUtils.fillMetalPattern(g, x + 2, y + 2, x + w - 5, y + 11, 
+                  MetalLookAndFeel.getControlHighlight(), 
+                  MetalLookAndFeel.getControlDarkShadow());
+        }
+    }
+    
+  }
+  
   /**
    * A border for table header cells.
    *
Index: javax/swing/plaf/metal/MetalLookAndFeel.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalLookAndFeel.java,v
retrieving revision 1.60
diff -u -r1.60 MetalLookAndFeel.java
--- javax/swing/plaf/metal/MetalLookAndFeel.java        23 Sep 2005 08:29:09 
-0000      1.60
+++ javax/swing/plaf/metal/MetalLookAndFeel.java        27 Sep 2005 15:29:22 
-0000
@@ -1129,6 +1129,7 @@
       "ToolBar.highlight", getControlHighlight(),
       "ToolBar.light", getControlHighlight(),
       "ToolBar.shadow", getControlShadow(),
+      "ToolBar.border", new MetalBorders.ToolBarBorder(),
 
       "ToolTip.background", getPrimaryControl(),
       "ToolTip.backgroundInactive", getControl(),
Index: javax/swing/plaf/metal/MetalToolBarUI.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalToolBarUI.java,v
retrieving revision 1.2
diff -u -r1.2 MetalToolBarUI.java
--- javax/swing/plaf/metal/MetalToolBarUI.java  2 Jul 2005 20:32:51 -0000       
1.2
+++ javax/swing/plaf/metal/MetalToolBarUI.java  27 Sep 2005 15:29:23 -0000
@@ -38,20 +38,71 @@
 
 package javax.swing.plaf.metal;
 
+import java.awt.event.ContainerListener;
+import java.beans.PropertyChangeListener;
+
 import javax.swing.JComponent;
+import javax.swing.JToolBar;
+import javax.swing.border.Border;
 import javax.swing.plaf.ComponentUI;
 import javax.swing.plaf.basic.BasicToolBarUI;
 
+/**
+ * A UI delegate for the address@hidden JToolBar} component.
+ */
 public class MetalToolBarUI
   extends BasicToolBarUI
 {
+  
+  /**
+   * A listener that responds when components are added to or removed from the
+   * toolbar.  This class is no longer used - the required behaviour is now
+   * handled in the super class. 
+   * 
+   * @see MetalToolBarUI#createContainerListener()
+   */
+  protected class MetalContainerListener
+    extends BasicToolBarUI.ToolBarContListener
+  {
+    /**
+     * Creates a new instance.
+     */
+    protected MetalContainerListener()
+    {     
+    }
+  }
 
-  // FIXME: maybe replace by a Map of instances when this becomes stateful
-  /** The shared UI instance for MetalToolBarUIs */
-  private static MetalToolBarUI instance = null;
+  /**
+   * A listener that responds to property change events.  This class is no 
+   * longer used - the required behaviour is now handled in the super class. 
+   * 
+   * @see MetalToolBarUI#createRolloverListener()
+   */
+  protected class MetalRolloverListener
+    extends BasicToolBarUI.PropertyListener
+  {
+    /**
+     * Creates a new instance.
+     */
+    protected MetalRolloverListener()
+    {
+    }
+  }
+  
+  /** 
+   * The container listener (an implementation specific field, according to the
+   * spec, and not used in GNU Classpath).
+   */
+  protected ContainerListener contListener;
+  
+  /** 
+   * The rollover listener (an implementation specific field, according to the
+   * spec, and not used in GNU Classpath). 
+   */
+  protected PropertyChangeListener rolloverListener;
 
   /**
-   * Constructs a new instance of MetalToolBarUI.
+   * Creates a new instance of this UI delegate.
    */
   public MetalToolBarUI()
   {
@@ -59,16 +110,51 @@
   }
 
   /**
-   * Returns an instance of MetalToolBarUI.
+   * Returns a new instance of <code>MetalToolBarUI</code>.
    *
-   * @param component the component for which we return an UI instance
+   * @param component  the component for which we return an UI instance
    *
-   * @return an instance of MetalToolBarUI
+   * @return A new instance of <code>MetalToolBarUI</code>.
    */
   public static ComponentUI createUI(JComponent component)
   {
-    if (instance == null)
-      instance = new MetalToolBarUI();
-    return instance;
+    return new MetalToolBarUI();
+  }
+  
+  /**
+   * Returns <code>null</code> as permitted by recent versions of the API
+   * specification.  Originally it seems this method returned a new instance 
of 
+   * address@hidden MetalRolloverListener}, but this is now redundant.
+   * 
+   * @return <code>null</code>.
+   */
+  protected PropertyChangeListener createRolloverListener()
+  {
+    return null;
+  }
+  
+  /**
+   * Returns <code>null</code> as permitted by recent versions of the API
+   * specification.  Originally it seems this method returned a new instance 
of 
+   * address@hidden MetalContainerListener}, but this is now redundant.
+   * 
+   * @return <code>null</code>.
+   */
+  protected ContainerListener createContainerListener()
+  {
+    return null;
+  }
+  
+  /**
+   * Returns a border with no rollover effect for buttons in the tool bar.
+   * 
+   * @return A border.
+   * 
+   * @see MetalBorders#getToolbarButtonBorder()
+   */
+  protected Border createNonRolloverBorder()
+  {
+    return MetalBorders.getToolbarButtonBorder();   
   }
+
 }

reply via email to

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