classpath-patches
[Top][All Lists]
Advanced

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

[cp-patches] FYI: MetalBorders.MenuItemBorder implemented


From: David Gilbert
Subject: [cp-patches] FYI: MetalBorders.MenuItemBorder implemented
Date: Tue, 26 Jul 2005 13:46:41 +0000
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050426)

I committed this patch:

2005-07-26  David Gilbert  <address@hidden>

        * javax/swing/plaf/metal/MetalBorders.java:
        (MenuItemBorder): new inner class.

Regards,

Dave Gilbert

Index: javax/swing/plaf/metal/MetalBorders.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalBorders.java,v
retrieving revision 1.7
diff -u -r1.7 MetalBorders.java
--- javax/swing/plaf/metal/MetalBorders.java    15 Jul 2005 14:55:24 -0000      
1.7
+++ javax/swing/plaf/metal/MetalBorders.java    26 Jul 2005 12:41:38 -0000
@@ -46,6 +46,8 @@
 import javax.swing.AbstractButton;
 import javax.swing.ButtonModel;
 import javax.swing.JButton;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
 import javax.swing.border.AbstractBorder;
 import javax.swing.border.Border;
 import javax.swing.plaf.BorderUIResource;
@@ -180,6 +182,98 @@
       newInsets.right = borderInsets.right;
       newInsets.top = borderInsets.top;
       return newInsets;
+    }
+  }
+
+  /**
+   * A border used for address@hidden JMenu} and address@hidden JMenuItem} 
components.
+   */
+  public static class MenuItemBorder
+      extends AbstractBorder
+      implements UIResource
+  {
+    /** The border insets. */
+    protected static Insets borderInsets = new Insets(2, 2, 2, 2);
+    
+    // TODO: find where the real colors come from
+    private static Color borderColorDark = new Color(102, 102, 153);
+    private static Color borderColorLight = new Color(255, 255, 255);
+    
+    /**
+     * Creates a new border instance.
+     */
+    public MenuItemBorder()
+    {
+    }
+    
+    /**
+     * Paints the border for the component.  A border is painted only if the
+     * component is a selected address@hidden JMenu} or an armed 
address@hidden JMenuItem}.
+     * 
+     * @param c  the component.
+     * @param g  the graphics device.
+     * @param x  the x-coordinate of the border area.
+     * @param y  the y-coordinate of the border area.
+     * @param w  the width of the border area.
+     * @param h  the height of the border area.
+     */
+    public void paintBorder(Component c, Graphics g, int x, int y, int w,
+        int h)
+    {
+      if (c instanceof JMenu) {
+        JMenu menu = (JMenu) c;
+        if (menu.isSelected())
+        {
+          g.setColor(borderColorDark);
+          g.drawLine(x, y, x, y + h);
+          g.drawLine(x, y, x + w, y);
+          g.drawLine(x + w - 2, y + 1, x + w - 2, y + h);
+          g.setColor(borderColorLight);
+          g.drawLine(x + w - 1, y + 1, x + w - 1, y + h);
+        }
+      }
+      else if (c instanceof JMenuItem)
+      {
+        JMenuItem item = (JMenuItem) c;
+        if (item.isArmed()) 
+        {
+          g.setColor(borderColorDark);
+          g.drawLine(x, y, x + w, y);
+          g.setColor(borderColorLight);
+          g.drawLine(x, y + h - 1, x + w, y + h - 1);
+        }          
+      }
+    }
+    
+    /**
+     * Returns the border insets.
+     * 
+     * @param c  the component (ignored).
+     * 
+     * @return The border insets.
+     */
+    public Insets getBorderInsets(Component c)
+    {
+      return borderInsets;
+    }
+    
+    /**
+     * Populates <code>insets</code> with the border insets, then returns it.
+     * 
+     * @param c  the component (ignored).
+     * @param insets  the object to populate with the border insets.
+     * 
+     * @return The border insets.
+     * 
+     * @throws NullPointerException if <code>insets</code> is 
<code>null</code>.
+     */
+    public Insets getBorderInsets(Component c, Insets insets)
+    {
+      insets.left = borderInsets.left;
+      insets.top = borderInsets.top;
+      insets.bottom = borderInsets.bottom;
+      insets.right = borderInsets.right;
+      return insets;
     }
   }
 

reply via email to

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