classpath-patches
[Top][All Lists]
Advanced

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

[cp-patches] FYI: MetalIconFactory.getRadioButtonMenuItemIcon()


From: David Gilbert
Subject: [cp-patches] FYI: MetalIconFactory.getRadioButtonMenuItemIcon()
Date: Tue, 30 Aug 2005 21:35:57 +0000
User-agent: Mozilla Thunderbird 1.0.6 (X11/20050728)

I committed this patch to add an icon for JRadioButtonMenuItems under the Metal look and feel:

2005-08-30  David Gilbert  <address@hidden>

        * examples/gnu/classpath/examples/swing/Demo.java
        (mkMenuBar): added a JRadioButtonMenuItem,
        * javax/swing/plaf/metal/MetalIconFactory.java
        (RadioButtonMenuItemIcon): new inner class,
        (getRadioButtonMenuItemIcon): implemented,
        * javax/swing/plaf/metal/MetalLookAndFeel.java
        (initComponentDefaults): added RadioButtonMenuItem defaults.

Regards,

Dave
Index: examples/gnu/classpath/examples/swing/Demo.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/examples/gnu/classpath/examples/swing/Demo.java,v
retrieving revision 1.19
diff -u -r1.19 Demo.java
--- examples/gnu/classpath/examples/swing/Demo.java     30 Aug 2005 20:05:57 
-0000      1.19
+++ examples/gnu/classpath/examples/swing/Demo.java     30 Aug 2005 20:29:18 
-0000
@@ -141,6 +141,8 @@
     preferences.add(new JCheckBoxMenuItem("Check Spelling",
                    stockIcon("spell-check")));
     preferences.add(new JCheckBoxMenuItem("World Peace"));
+    preferences.add(new JSeparator());
+    preferences.add(new JRadioButtonMenuItem("Radio Button"));
     edit.add(preferences);
 
     JMenu examples = new JMenu("Examples");
Index: javax/swing/plaf/metal/MetalIconFactory.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalIconFactory.java,v
retrieving revision 1.7
diff -u -r1.7 MetalIconFactory.java
--- javax/swing/plaf/metal/MetalIconFactory.java        26 Aug 2005 18:17:57 
-0000      1.7
+++ javax/swing/plaf/metal/MetalIconFactory.java        30 Aug 2005 20:29:30 
-0000
@@ -48,6 +48,7 @@
 import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JInternalFrame;
 import javax.swing.JRadioButton;
+import javax.swing.JRadioButtonMenuItem;
 import javax.swing.JSlider;
 import javax.swing.plaf.UIResource;
 
@@ -382,7 +383,83 @@
     }
   }
 
+  /**
+   * An icon displayed for address@hidden JRadioButtonMenuItem} components.
+   */
+  private static class RadioButtonMenuItemIcon 
+      implements Icon, Serializable 
+  {
     /**
+     * Creates a new icon instance.
+     */
+    public RadioButtonMenuItemIcon() 
+    {  
+    }
+
+    /**
+     * Returns the width of the icon, in pixels.
+     * 
+     * @return The width of the icon.
+     */
+    public int getIconWidth() 
+    {
+      return 10;
+    }
+
+    /**
+     * Returns the height of the icon, in pixels.
+     * 
+     * @return The height of the icon.
+     */
+    public int getIconHeight()   
+    {
+      return 10;
+    }
+
+    /**
+     * Paints the icon.
+     * 
+     * @param c  the component.
+     * @param g  the graphics device.
+     * @param x  the x-coordinate.
+     * @param y  the y-coordinate.
+     */
+    public void paintIcon(Component c, Graphics g, int x, int y) 
+    {
+      Color savedColor = g.getColor();
+      JRadioButtonMenuItem item = (JRadioButtonMenuItem) c;
+      g.setColor(MetalLookAndFeel.getBlack());
+      g.drawLine(x + 2, y, x + 6, y);
+      g.drawLine(x + 7, y + 1, x + 7, y + 1);
+      g.drawLine(x + 8, y + 2, x + 8, y + 6);
+      g.drawLine(x + 7, y + 7, x + 7, y + 7);
+      g.drawLine(x + 2, y + 8, x + 6, y + 8);
+      g.drawLine(x + 1, y + 7, x + 1, y + 7);
+      g.drawLine(x, y + 2, x, y + 6);
+      g.drawLine(x + 1, y + 1, x + 1, y + 1);
+      
+      if (item.isSelected())
+        {
+          g.drawLine(x + 3, y + 2, x + 5, y + 2);
+          g.fillRect(x + 2, y + 3, 5, 3);
+          g.drawLine(x + 3, y + 6, x + 5, y + 6);
+        }
+
+      // highlight
+      g.setColor(MetalLookAndFeel.getControlHighlight());
+      g.drawLine(x + 3, y + 1, x + 6, y + 1);
+      g.drawLine(x + 8, y + 1, x + 8, y + 1);
+      g.drawLine(x + 9, y + 2, x + 9, y + 7);
+      g.drawLine(x + 8, y + 8, x + 8, y + 8);
+      g.drawLine(x + 2, y + 9, x + 7, y + 9);
+      g.drawLine(x + 1, y + 8, x + 1, y + 8);
+      g.drawLine(x + 1, y + 3, x + 1, y + 6);
+      g.drawLine(x + 2, y + 2, x + 2, y + 2);
+      g.setColor(savedColor);
+    }        
+  }
+
+  /**
    * The icon used to display the thumb control on a horizontally oriented
    * address@hidden JSlider} component.
    */
@@ -1265,6 +1342,16 @@
     if (radioButtonIcon == null)
       radioButtonIcon = new RadioButtonIcon();
     return radioButtonIcon;
+  }
+
+  /**
+   * Creates a new instance of the icon used in a address@hidden 
JRadioButtonMenuItem}.
+   * 
+   * @return A new icon instance.
+   */
+  public static Icon getRadioButtonMenuItemIcon() 
+  {
+    return new RadioButtonMenuItemIcon();
   }
 
   /**
Index: javax/swing/plaf/metal/MetalLookAndFeel.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalLookAndFeel.java,v
retrieving revision 1.45
diff -u -r1.45 MetalLookAndFeel.java
--- javax/swing/plaf/metal/MetalLookAndFeel.java        30 Aug 2005 12:48:39 
-0000      1.45
+++ javax/swing/plaf/metal/MetalLookAndFeel.java        30 Aug 2005 20:29:34 
-0000
@@ -49,6 +49,7 @@
 import javax.swing.plaf.InsetsUIResource;
 import javax.swing.plaf.basic.BasicLookAndFeel;
 
+
 /**
  * A custom look and feel that is designed to look similar across different
  * operating systems.
@@ -822,6 +823,18 @@
             return MetalIconFactory.getRadioButtonIcon();
           }
       },
+
+      "RadioButtonMenuItem.border", new MetalBorders.MenuItemBorder(),
+      "RadioButtonMenuItem.borderPainted", Boolean.TRUE,
+      "RadioButtonMenuItem.checkIcon", 
+        MetalIconFactory.getRadioButtonMenuItemIcon(),
+      "RadioButtonMenuItem.font", MetalLookAndFeel.getControlTextFont(),
+      "RadioButtonMenuItem.margin", new InsetsUIResource(2, 2, 2, 2),
+      "RadioButtonMenuItem.selectionBackground", 
+        MetalLookAndFeel.getMenuSelectedBackground(),
+      "RadioButtonMenuItem.selectionForeground", 
+        MetalLookAndFeel.getMenuSelectedForeground(),
+
       "ScrollBar.background", new ColorUIResource(getControl()),
       "ScrollBar.shadow", new ColorUIResource(getControlShadow()),
       "ScrollBar.thumb", new ColorUIResource(getPrimaryControlShadow()),

reply via email to

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