[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] FYI: CheckBoxMenuItem icons
From: |
David Gilbert |
Subject: |
[cp-patches] FYI: CheckBoxMenuItem icons |
Date: |
Fri, 26 Aug 2005 19:24:24 +0000 |
User-agent: |
Mozilla Thunderbird 1.0.6 (X11/20050728) |
I committed this patch. It cleans up a few aspects of the icons on
JCheckBoxMenuItems:
2005-08-26 David Gilbert <address@hidden>
* javax/swing/plaf/basic/BasicCheckBoxUI.java
(installUI): removed,
* javax/swing/plaf/basic/BasicIconFactory.java
(CheckBoxMenuItemIcon): new support class,
(getCheckBoxMenuItemIcon): return instance of CheckBoxMenuItemIcon,
* javax/swing/plaf/basic/BasicLookAndFeel.java
(initComponentDefaults): changed value for 'CheckBoxMenuItem.checkIcon'
and removed entry for 'CheckBoxMenuItem.icon',
* javax/swing/plaf/basic/BasicMenuItemUI.java
(paintMenuItem): let icon handle selection status,
* javax/swing/plaf/metal/MetalIconFactory.java
(CheckBoxMenuItemIcon): new support class,
(getCheckBoxIcon): implemented,
(getCheckBoxMenuItemIcon): implemented,
* javax/swing/plaf/metal/MetalLookAndFeel.java
(initComponentDefaults): added entry for 'CheckBoxMenuItem.checkIcon'.
Regards,
Dave Gilbert
Index: javax/swing/plaf/basic/BasicCheckBoxUI.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicCheckBoxUI.java,v
retrieving revision 1.9
diff -u -r1.9 BasicCheckBoxUI.java
--- javax/swing/plaf/basic/BasicCheckBoxUI.java 4 Aug 2005 15:47:31 -0000
1.9
+++ javax/swing/plaf/basic/BasicCheckBoxUI.java 26 Aug 2005 17:59:55 -0000
@@ -58,13 +58,6 @@
return defaults.getIcon("CheckBox.icon");
}
- public void installUI(final JComponent c) {
- super.installUI(c);
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
- ((AbstractButton) c).setIcon(defaults.getIcon("CheckBox.icon"));
- ((AbstractButton)
c).setSelectedIcon(defaults.getIcon("CheckBox.checkIcon"));
- }
-
// Overridden to change method access.
public String getPropertyPrefix()
{
Index: javax/swing/plaf/basic/BasicIconFactory.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicIconFactory.java,v
retrieving revision 1.11
diff -u -r1.11 BasicIconFactory.java
--- javax/swing/plaf/basic/BasicIconFactory.java 3 Aug 2005 18:09:44
-0000 1.11
+++ javax/swing/plaf/basic/BasicIconFactory.java 26 Aug 2005 17:59:56
-0000
@@ -1,5 +1,5 @@
/* BasicIconFactory.java --
- Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -44,13 +44,11 @@
import java.awt.Polygon;
import java.io.Serializable;
-import javax.swing.AbstractButton;
import javax.swing.Icon;
-import javax.swing.UIDefaults;
-import javax.swing.UIManager;
+import javax.swing.JCheckBoxMenuItem;
/**
- * STUBBED
+ * Creates icons for the address@hidden BasicLookAndFeel}.
*/
public class BasicIconFactory implements Serializable
{
@@ -115,6 +113,56 @@
}
/**
+ * The icon used for address@hidden JCheckBoxMenuItem}s in the
+ * address@hidden BasicLookAndFeel}. This icon has a size of 9x9 pixels.
+ */
+ static class CheckBoxMenuItemIcon
+ implements Icon
+ {
+ /**
+ * Returns the height of the icon in pixels.
+ *
+ * @return the height of the icon
+ */
+ public int getIconHeight()
+ {
+ return 9;
+ }
+
+ /**
+ * Returns the width of the icon in pixels.
+ *
+ * @return the height of the icon
+ */
+ public int getIconWidth()
+ {
+ return 9;
+ }
+
+ /**
+ * Paints the icon.
+ *
+ * @param c the component to be painted
+ * @param g the Graphics context to be painted with
+ * @param x the x position of the icon
+ * @param y the y position of the icon
+ */
+ public void paintIcon(Component c, Graphics g, int x, int y)
+ {
+ JCheckBoxMenuItem item = (JCheckBoxMenuItem) c;
+ if (item.isSelected())
+ {
+ // paint the check...
+ g.setColor(Color.black);
+ g.drawLine(x + 1, y + 3, x + 1, y + 4);
+ g.drawLine(x + 2, y + 4, x + 2, y + 5);
+ for (int i = 0; i < 5; i++)
+ g.drawLine(x + 3 + i, y + 5 - i, x + 3 + i, y + 6 - i);
+ }
+ }
+ }
+
+ /**
* The icon used for RadioButtons in the BasicLookAndFeel. This is an empty
* icon with a size of 13x13 pixels.
*/
@@ -253,9 +301,15 @@
return radioButtonIcon;
}
+ /**
+ * Creates and returns an icon used when rendering address@hidden
JCheckBoxMenuItem}
+ * components.
+ *
+ * @return An icon.
+ */
public static Icon getCheckBoxMenuItemIcon()
{
- return getCheckBoxIcon();
+ return new CheckBoxMenuItemIcon();
}
public static Icon getRadioButtonMenuItemIcon()
Index: javax/swing/plaf/basic/BasicLookAndFeel.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicLookAndFeel.java,v
retrieving revision 1.48
diff -u -r1.48 BasicLookAndFeel.java
--- javax/swing/plaf/basic/BasicLookAndFeel.java 24 Aug 2005 08:01:00
-0000 1.48
+++ javax/swing/plaf/basic/BasicLookAndFeel.java 26 Aug 2005 17:59:58
-0000
@@ -305,14 +305,6 @@
"CheckBox.margin",new InsetsUIResource(2, 2, 2, 2),
"CheckBox.textIconGap", new Integer(4),
"CheckBox.textShiftOffset", new Integer(0),
- "CheckBoxMenuItem.icon",
- new UIDefaults.LazyValue()
- {
- public Object createValue(UIDefaults def)
- {
- return BasicIconFactory.getCheckBoxIcon();
- }
- },
"CheckBoxMenuItem.acceleratorFont", new FontUIResource("Dialog",
Font.PLAIN, 12),
"CheckBoxMenuItem.acceleratorForeground",
@@ -328,7 +320,7 @@
{
public Object createValue(UIDefaults def)
{
- return BasicIconFactory.getMenuItemCheckIcon();
+ return BasicIconFactory.getCheckBoxMenuItemIcon();
}
},
"CheckBoxMenuItem.font", new FontUIResource("Dialog", Font.PLAIN, 12),
Index: javax/swing/plaf/basic/BasicMenuItemUI.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicMenuItemUI.java,v
retrieving revision 1.19
diff -u -r1.19 BasicMenuItemUI.java
--- javax/swing/plaf/basic/BasicMenuItemUI.java 5 Aug 2005 12:28:04 -0000
1.19
+++ javax/swing/plaf/basic/BasicMenuItemUI.java 26 Aug 2005 17:59:59 -0000
@@ -295,7 +295,7 @@
* Returns preferred size for the given menu item.
*
* @param c menu item for which to get preferred size
- * @param checkIcon chech icon displayed in the given menu item
+ * @param checkIcon check icon displayed in the given menu item
* @param arrowIcon arrow icon displayed in the given menu item
* @param defaultTextIconGap space between icon and text in the given
menuItem
*
@@ -533,12 +533,7 @@
SwingUtilities.layoutCompoundLabel(m, fm, null, checkIcon, vertAlign,
horAlign, vertTextPos, horTextPos,
vr, cr, tr, defaultTextIconGap);
- if (m.isSelected())
- checkIcon.paintIcon(m, g, cr.x, cr.y);
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
- defaults.getBorder("CheckBox.border").paintBorder(m, g, cr.x, cr.y,
- cr.width, cr.height);
-
+ checkIcon.paintIcon(m, g, cr.x, cr.y);
// We need to calculate position of the menu text and position of
// user menu icon if there exists one relative to the check icon.
// So we need to adjust view rectangle s.t. its starting point is at
@@ -567,7 +562,6 @@
defaultTextIconGap);
if (i != null)
i.paintIcon(c, g, ir.x, ir.y);
-
paintText(g, m, tr, m.getText());
// paint accelerator
Index: javax/swing/plaf/metal/MetalIconFactory.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalIconFactory.java,v
retrieving revision 1.6
diff -u -r1.6 MetalIconFactory.java
--- javax/swing/plaf/metal/MetalIconFactory.java 24 Aug 2005 23:14:23
-0000 1.6
+++ javax/swing/plaf/metal/MetalIconFactory.java 26 Aug 2005 18:00:01
-0000
@@ -44,6 +44,8 @@
import java.io.Serializable;
import javax.swing.Icon;
+import javax.swing.JCheckBox;
+import javax.swing.JCheckBoxMenuItem;
import javax.swing.JInternalFrame;
import javax.swing.JRadioButton;
import javax.swing.JSlider;
@@ -63,6 +65,77 @@
public static final boolean LIGHT = true;
/**
+ * An icon displayed for address@hidden JCheckBoxMenuItem} components.
+ */
+ private static class CheckBoxMenuItemIcon implements Icon, Serializable
+ {
+ /**
+ * Creates a new icon instance.
+ */
+ public CheckBoxMenuItemIcon()
+ {
+ }
+
+ /**
+ * Returns the width of the icon, in pixels.
+ *
+ * @return The width of the icon (10 pixels).
+ */
+ public int getIconWidth()
+ {
+ return 10;
+ }
+
+ /**
+ * Returns the height of the icon, in pixels.
+ *
+ * @return The height of the icon (10 pixels).
+ */
+ 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)
+ {
+ JCheckBoxMenuItem item = (JCheckBoxMenuItem) c;
+
+ if (item.isArmed())
+ g.setColor(MetalLookAndFeel.getBlack());
+ else
+ g.setColor(MetalLookAndFeel.getControlDarkShadow());
+ g.drawLine(x, y, x + 8, y);
+ g.drawLine(x, y + 1, x, y + 8);
+ g.drawLine(x + 2, y + 8, x + 8, y + 8);
+ g.drawLine(x + 8, y + 2, x + 8, y + 7);
+
+ g.setColor(MetalLookAndFeel.getWhite());
+ g.drawLine(x + 1, y + 1, x + 7, y + 1);
+ g.drawLine(x + 1, y + 2, x + 1, y + 7);
+ g.drawLine(x + 1, y + 9, x + 9, y + 9);
+ g.drawLine(x + 9, y + 1, x + 9, y + 8);
+
+ // if the item is selected, we should draw a tick
+ if (item.isSelected())
+ {
+ g.setColor(MetalLookAndFeel.getBlack());
+ g.fillRect(x + 2, y + 2, 2, 5);
+ for (int i = 0; i < 6; i++)
+ g.drawLine(x + 8 - i, y + i, x + 9 - i, y + i);
+ }
+
+ }
+ }
+
+ /**
* An icon representing a file (drawn as a piece of paper with the top-right
* corner turned down).
*/
@@ -1157,6 +1230,29 @@
*/
public MetalIconFactory()
{
+ }
+
+ /**
+ * Returns an icon for use when rendering the address@hidden JCheckBox}
component.
+ *
+ * @return A check box icon.
+ *
+ * @since 1.3
+ */
+ public static Icon getCheckBoxIcon()
+ {
+ return new MetalCheckBoxIcon();
+ }
+
+ /**
+ * Returns an icon for use when rendering the address@hidden
JCheckBoxMenuItem}
+ * component.
+ *
+ * @return An icon.
+ */
+ public static Icon getCheckBoxMenuItemIcon()
+ {
+ return new CheckBoxMenuItemIcon();
}
/**
Index: javax/swing/plaf/metal/MetalLookAndFeel.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalLookAndFeel.java,v
retrieving revision 1.42
diff -u -r1.42 MetalLookAndFeel.java
--- javax/swing/plaf/metal/MetalLookAndFeel.java 25 Aug 2005 10:48:59
-0000 1.42
+++ javax/swing/plaf/metal/MetalLookAndFeel.java 26 Aug 2005 18:00:02
-0000
@@ -42,13 +42,10 @@
import java.awt.Font;
import java.awt.Insets;
-import javax.swing.ImageIcon;
import javax.swing.UIDefaults;
-import javax.swing.border.Border;
import javax.swing.plaf.BorderUIResource;
import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.FontUIResource;
-import javax.swing.plaf.IconUIResource;
import javax.swing.plaf.InsetsUIResource;
import javax.swing.plaf.basic.BasicLookAndFeel;
@@ -782,6 +779,7 @@
new UIDefaults.ProxyLazyValue
("javax.swing.plaf.metal.MetalCheckBoxIcon"),
"CheckBoxMenuItem.background", new ColorUIResource(getControl()),
+ "CheckBoxMenuItem.checkIcon", MetalIconFactory.getCheckBoxMenuItemIcon(),
"ToolBar.background", new ColorUIResource(getControl()),
"Panel.background", new ColorUIResource(getControl()),
"Slider.background", new ColorUIResource(getControl()),
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] FYI: CheckBoxMenuItem icons,
David Gilbert <=