[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] FYI: Toolbar buttons fix
From: |
Roman Kennke |
Subject: |
[cp-patches] FYI: Toolbar buttons fix |
Date: |
Mon, 18 Apr 2005 09:48:05 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021204 |
The attached patch fixes JToolBar and Button related classes so that
buttons that are added to JToolBars get a special border, so that the
button actually looks like a toolbar button. This border ignores the
margin property of AbstractButton and replaces it with its own fixed margin.
2005-04-17 Roman Kennke <address@hidden>
* 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.
/Roman
Index: javax/swing/JToolBar.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JToolBar.java,v
retrieving revision 1.9
diff -u -r1.9 JToolBar.java
--- javax/swing/JToolBar.java 26 Jan 2005 23:32:51 -0000 1.9
+++ javax/swing/JToolBar.java 18 Apr 2005 07:44:32 -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/metal/MetalBorders.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalBorders.java,v
retrieving revision 1.1
diff -u -r1.1 MetalBorders.java
--- javax/swing/plaf/metal/MetalBorders.java 15 Apr 2005 12:01:01 -0000
1.1
+++ javax/swing/plaf/metal/MetalBorders.java 18 Apr 2005 07:44:32 -0000
@@ -61,12 +61,18 @@
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 address@hidden
* #getMarginBorder()}.
*/
- private static BasicBorders.MarginBorder sharedMarginBorder;
+ private static BasicBorders.MarginBorder marginBorder;
/**
* The border that is drawn around Swing buttons.
@@ -75,7 +81,7 @@
extends AbstractBorder
{
/** 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 +172,8 @@
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;
@@ -174,6 +182,56 @@
}
}
+ /**
+ * 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;
+ }
+ }
/**
* Returns a border for Swing buttons in the Metal Look & Feel.
@@ -182,24 +240,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 address@hidden BasicBorders.MarginBorder}.
+ *
+ * @return a shared instance of address@hidden BasicBorders.MarginBorder}
+ */
+ static Border getMarginBorder()
+ {
+ if (marginBorder == null)
+ marginBorder = new BasicBorders.MarginBorder();
+ return marginBorder;
+ }
}
Index: javax/swing/plaf/metal/MetalButtonUI.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalButtonUI.java,v
retrieving revision 1.3
diff -u -r1.3 MetalButtonUI.java
--- javax/swing/plaf/metal/MetalButtonUI.java 15 Apr 2005 12:01:01 -0000
1.3
+++ javax/swing/plaf/metal/MetalButtonUI.java 18 Apr 2005 07:44:32 -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());
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] FYI: Toolbar buttons fix,
Roman Kennke <=