summaryrefslogtreecommitdiff
path: root/javax/swing/SwingUtilities.java
diff options
context:
space:
mode:
authorMichael Koch <konqueror@gmx.de>2004-02-14 21:42:56 +0000
committerMichael Koch <konqueror@gmx.de>2004-02-14 21:42:56 +0000
commit03bb9cf84bd9426a18f47338a4a3d9f4101c72c8 (patch)
tree015a047c2eed1700c869764a2cb540f45c3ce885 /javax/swing/SwingUtilities.java
parent0869851f5c8a27ed15022a79bb66cfb0f2733bc8 (diff)
downloadclasspath-03bb9cf84bd9426a18f47338a4a3d9f4101c72c8.tar.gz
2004-02-14 Graydon Hoare <graydon@redhat.com>
* javax/swing/ToggleButtonModel.java: Remove dead class. * javax/swing/plaf/basic/BasicDefaults.java: Remove dead class. * javax/swing/plaf/basic/BasicButtonListener.java: New class. * javax/swing/plaf/basic/BasicRootPaneUI.java: New class. * Makefile.am: Update for new and removed files. * Makefile.in: Regenerate. * gnu/java/awt/peer/gtk/GdkGraphics2D.java: Initialize default hints. * javax/swing/AbstractButton.java (AbstractButton): Initialize fields correctly in ctor. * javax/swing/JCheckbox.java (JCheckBox): Override painting flags. * javax/swing/DefaultButtonModel.java: Conform to sun. * javax/swing/JComponent.java (paint): Fill with background color if available. (processComponentKeyEvent) (processFocusEvent) (processKeyEvent) (processMouseMotionEvent): Remove event-consuming empty methods. (getUIClassID): Return "ComponentUI" not "JComponent" * javax/swing/JFrame.java: Remove some debugging chatter. (JFrame): Subscribe to window events. * javax/swing/JRadioButton.java (JRadioButton): Override painting flags. * javax/swing/JRootPane.java (JRootPane): Set background from UIDefaults. * javax/swing/JToggleButton.java (ToggleButtonModel): New inner class. (JToggleButton): Override layout alighment. * javax/swing/SwingUtilities.java: (getLocalBounds): Return width and height, not x and y. (calculateInnerArea): Use local bounds, not bounds. (layoutCompoundLabel): Provide overridden form. (layoutCompoundLabel): Correct bugs. * javax/swing/UIDefaults.java: Correct comment. * javax/swing/plaf/basic/BasicButtonUI.java: Move most logic into defaults, external listener. (paintIcon): Implement icon painting. (paint): Fix state painting to conform to changes in model. * javax/swing/plaf/basic/BasicCheckBoxUI.java: Remove most dead/wrong methods. (getDefaultIcon): Return defaults.getIcon("CheckBox.icon"). * javax/swing/plaf/basic/BasicIconFactory.java: (DummyIcon): New class. (getMenuItemCheckIcon) (getMenuItemArrowIcon) (getMenuArrowIcon) (getCheckBoxMenuItemIcon) (getRadioButtonMenuItemIcon) (createEmptyFrameIcon): Return DummyIcons, not null. (getCheckBoxIcon): Implement an icon that looks like sun's. (getRadioButtonIcon): Implement an icon that looks like sun's. * javax/swing/plaf/basic/BasicLookAndFeel.java (initComponentDefaults): Fix impossible values, add some missing. * javax/swing/plaf/basic/BasicPanelUI.java (gap): Remove field. * javax/swing/plaf/basic/BasicRadioButtonUI.java: Remove most dead/wrong methods. (icon): New field. (getDefaultIcon): New method. * javax/swing/plaf/basic/BasicToggleButtonUI.java: Remove most dead/wrong methods. * javax/swing/plaf/metal/MetalLookAndFeel.java (getDefaults): Return super.getDefaults(), not BasicDefaults. * jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c (Java_gnu_java_awt_peer_gtk_GdkGraphics_clearRect): Implement "clearing" as drawing, when on pixmap drawables. * javax/swing/JButton.java (getUIClassID): * javax/swing/JCheckBox.java (getUIClassID): * javax/swing/JEditorPane.java (getUIClassID): * javax/swing/JLabel.java (getUIClassID): * javax/swing/JList.java (getUIClassID): * javax/swing/JOptionPane.java (getUIClassID): * javax/swing/JPanel.java (getUIClassID): * javax/swing/JPasswordField.java (uiClassID): * javax/swing/JRadioButton.java (getUIClassID): * javax/swing/JRootPane.java (getUIClassID): * javax/swing/JScrollPane.java (getUIClassID): * javax/swing/JTabbedPane.java (getUIClassID): * javax/swing/JToggleButton.java (getUIClassID): * javax/swing/JTree.java (getUIClassID): * javax/swing/JViewport.java (getUIClassID): * javax/swing/text/JTextComponent.java (getUIClassID): Return "fooUI" not "Jfoo"
Diffstat (limited to 'javax/swing/SwingUtilities.java')
-rw-r--r--javax/swing/SwingUtilities.java162
1 files changed, 132 insertions, 30 deletions
diff --git a/javax/swing/SwingUtilities.java b/javax/swing/SwingUtilities.java
index e226919eb..590c3032f 100644
--- a/javax/swing/SwingUtilities.java
+++ b/javax/swing/SwingUtilities.java
@@ -95,7 +95,9 @@ public class SwingUtilities implements SwingConstants
/**
* Calculates the portion of the component's bounds which is inside the
* component's border insets. This area is usually the area a component
- * should confine its painting to.
+ * should confine its painting to. The coordinates are returned in terms
+ * of the <em>component's</em> coordinate system, where (0,0) is the
+ * upper left corner of the component's bounds.
*
* @param c The component to measure the bounds of
* @param r A Rectangle to store the return value in, or
@@ -108,7 +110,8 @@ public class SwingUtilities implements SwingConstants
*/
public static Rectangle calculateInnerArea(JComponent c, Rectangle r)
{
- return calculateInsetArea(c.getBounds(), c.getInsets(), r);
+ Rectangle b = getLocalBounds(c);
+ return calculateInsetArea(b, c.getInsets(), r);
}
/**
@@ -123,7 +126,7 @@ public class SwingUtilities implements SwingConstants
public static Rectangle getLocalBounds(Component aComponent)
{
Rectangle bounds = aComponent.getBounds();
- return new Rectangle(0, 0, bounds.x, bounds.y);
+ return new Rectangle(0, 0, bounds.width, bounds.height);
}
/**
@@ -460,6 +463,7 @@ public class SwingUtilities implements SwingConstants
((JComponent)comp).updateUI();
}
+
/**
* <p>Layout a "compound label" consisting of a text string and an icon
* which is to be placed near the rendered text. Once the text and icon
@@ -472,9 +476,10 @@ public class SwingUtilities implements SwingConstants
*
* <p>The position values control where the text is placed relative to
* the icon. The horizontal position value should be one of the constants
- * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>. The
- * vertical position value should be one fo the constants
- * <code>TOP</code>, <code>BOTTOM</code>, <code>CENTER</code>.</p>
+ * <code>LEADING</code>, <code>TRAILING</code>, <code>LEFT</code>,
+ * <code>RIGHT</code> or <code>CENTER</code>. The vertical position value
+ * should be one fo the constants <code>TOP</code>, <code>BOTTOM</code>
+ * or <code>CENTER</code>.</p>
*
* <p>The text-icon gap value controls the number of pixels between the
* icon and the text.</p>
@@ -488,12 +493,12 @@ public class SwingUtilities implements SwingConstants
* <code>CENTER</code>.</p>
*
* <p>If the <code>LEADING</code> or <code>TRAILING</code> constants are
- * given for horizontal alignment, they are interpreted relative to the
- * provided component's orientation property, a constant in the {@link
- * java.awt.ComponentOrientation} class. For example, if the component's
- * orientation is <code>LEFT_TO_RIGHT</code>, then the
- * <code>LEADING</code> alignment is a synonym for <code>LEFT</code> and
- * the <code>TRAILING</code> alignment is a synonym for
+ * given for horizontal alignment or horizontal text position, they are
+ * interpreted relative to the provided component's orientation property,
+ * a constant in the {@link java.awt.ComponentOrientation} class. For
+ * example, if the component's orientation is <code>LEFT_TO_RIGHT</code>,
+ * then the <code>LEADING</code> value is a synonym for <code>LEFT</code>
+ * and the <code>TRAILING</code> value is a synonym for
* <code>RIGHT</code></p>
*
* <p>If the text and icon are equal to or larger than the view
@@ -523,6 +528,7 @@ public class SwingUtilities implements SwingConstants
* @return The string of characters, possibly truncated with an elipsis,
* which is laid out in this label
*/
+
public static String layoutCompoundLabel(JComponent c,
FontMetrics fm,
String text,
@@ -537,6 +543,119 @@ public class SwingUtilities implements SwingConstants
int textIconGap)
{
+ // Fix up the orientation-based horizontal positions.
+
+ if (horizontalTextPosition == LEADING)
+ {
+ if (c.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT)
+ horizontalTextPosition = RIGHT;
+ else
+ horizontalTextPosition = LEFT;
+ }
+ else if (horizontalTextPosition == TRAILING)
+ {
+ if (c.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT)
+ horizontalTextPosition = LEFT;
+ else
+ horizontalTextPosition = RIGHT;
+ }
+
+ // Fix up the orientation-based alignments.
+
+ if (horizontalAlignment == LEADING)
+ {
+ if (c.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT)
+ horizontalAlignment = RIGHT;
+ else
+ horizontalAlignment = LEFT;
+ }
+ else if (horizontalAlignment == TRAILING)
+ {
+ if (c.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT)
+ horizontalAlignment = LEFT;
+ else
+ horizontalAlignment = RIGHT;
+ }
+
+ return layoutCompoundLabel(fm, text, icon,
+ verticalAlignment,
+ horizontalAlignment,
+ verticalTextPosition,
+ horizontalTextPosition,
+ viewR, iconR, textR, textIconGap);
+ }
+
+ /**
+ * <p>Layout a "compound label" consisting of a text string and an icon
+ * which is to be placed near the rendered text. Once the text and icon
+ * are laid out, the text rectangle and icon rectangle parameters are
+ * altered to store the calculated positions.</p>
+ *
+ * <p>The size of the text is calculated from the provided font metrics
+ * object. This object should be the metrics of the font you intend to
+ * paint the label with.</p>
+ *
+ * <p>The position values control where the text is placed relative to
+ * the icon. The horizontal position value should be one of the constants
+ * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code>. The
+ * vertical position value should be one fo the constants
+ * <code>TOP</code>, <code>BOTTOM</code> or <code>CENTER</code>.</p>
+ *
+ * <p>The text-icon gap value controls the number of pixels between the
+ * icon and the text.</p>
+ *
+ * <p>The alignment values control where the text and icon are placed, as
+ * a combined unit, within the view rectangle. The horizontal alignment
+ * value should be one of the constants <code>LEFT</code>, <code>RIGHT</code> or
+ * <code>CENTER</code>. The vertical alignment valus should be one of the
+ * constants <code>TOP</code>, <code>BOTTOM</code> or
+ * <code>CENTER</code>.</p>
+ *
+ * <p>If the text and icon are equal to or larger than the view
+ * rectangle, the horizontal and vertical alignment values have no
+ * affect.</p>
+ *
+ * <p>Note that this method does <em>not</em> know how to deal with
+ * horizontal alignments or positions given as <code>LEADING</code> or
+ * <code>TRAILING</code> values. Use the other overloaded variant of this
+ * method if you wish to use such values.
+ *
+ * @param fm The font metrics used to measure the text
+ * @param text The text to place in the compound label
+ * @param icon The icon to place next to the text
+ * @param verticalAlignment The vertical alignment of the label relative
+ * to its component
+ * @param horizontalAlignment The horizontal alignment of the label
+ * relative to its component
+ * @param verticalTextPosition The vertical position of the label's text
+ * relative to its icon
+ * @param horizontalTextPosition The horizontal position of the label's
+ * text relative to its icon
+ * @param viewR The view rectangle, specifying the area which layout is
+ * constrained to
+ * @param iconR A rectangle which is modified to hold the laid-out
+ * position of the icon
+ * @param textR A rectangle which is modified to hold the laid-out
+ * position of the text
+ * @param textIconGap The distance between text and icon
+ *
+ * @return The string of characters, possibly truncated with an elipsis,
+ * which is laid out in this label
+ */
+
+ public static String layoutCompoundLabel(FontMetrics fm,
+ String text,
+ Icon icon,
+ int verticalAlignment,
+ int horizontalAlignment,
+ int verticalTextPosition,
+ int horizontalTextPosition,
+ Rectangle viewR,
+ Rectangle iconR,
+ Rectangle textR,
+ int textIconGap)
+ {
+
// Work out basic height and width.
if (icon == null)
@@ -545,7 +664,7 @@ public class SwingUtilities implements SwingConstants
iconR.width = 0;
iconR.height = 0;
}
- else
+ else
{
iconR.width = icon.getIconWidth();
iconR.height = icon.getIconWidth();
@@ -591,23 +710,6 @@ public class SwingUtilities implements SwingConstants
break;
}
- // Fix up the orientation-based alignments.
-
- if (horizontalAlignment == LEADING)
- {
- if (c.getComponentOrientation() == ComponentOrientation.LEFT_TO_RIGHT)
- horizontalAlignment = LEFT;
- else if (c.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT)
- horizontalAlignment = RIGHT;
- }
- else if (horizontalAlignment == TRAILING)
- {
- if (c.getComponentOrientation() == ComponentOrientation.LEFT_TO_RIGHT)
- horizontalAlignment = RIGHT;
- else if (c.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT)
- horizontalAlignment = LEFT;
- }
-
// The two rectangles are laid out correctly now, but only assuming
// that their upper left corner is at (0,0). If we have any alignment other
// than TOP and LEFT, we need to adjust them.