[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] FYI: Add JColorChooser support from gcj gui branch
From: |
Mark Wielaard |
Subject: |
[cp-patches] FYI: Add JColorChooser support from gcj gui branch |
Date: |
Sat, 04 Sep 2004 22:26:24 +0200 |
Hi,
This adds the JColorChooser from the gcj gui branch that Kim Ho made. It
is a really nice example of what our Swing implementation can already
do. It combines JButtons, Tabs, Spinners, Sliders, and much more. I also
added it as example to the Swing Demo.
Check it Out!
http://www.klomp.org/mark/classpath/jcolorchooser-jamvm-sep-4-2004.png
2004-09-04 Mark Wielaard <address@hidden>
* examples/gnu/classpath/examples/swing/Demo.java (mkColorChooser):
New method.
2004-09-04 Graydon Hoare <address@hidden>
* javax/swing/JColorChooser.java:
Make a couple inner classes static, for jikes.
2004-09-04 Kim Ho <address@hidden>
* java/awt/Color.java: Fix documentation.
(RGBtoHSB): Use floats for conversions.
* javax/swing/ButtonGroup.java: Run Jalopy.
(setSelected): Reimplement.
* javax/swing/DefaultButtonModel.java: Run Jalopy.
(changeState): Let ButtonGroup know that the button
is changing state.
* javax/swing/JColorChooser.java: Implement.
* javax/swing/JLabel.java: Run Jalopy.
* javax/swing/JSpinner.java: Run Jalopy.
(setValue): New method.
* javax/swing/JTabbedPane.java: Run Jalopy.
(removeTabAt): Call correct remove method.
* javax/swing/SpinnerNumberModel.java: Run Jalopy.
(getPreviousValue): Compare minimum value.
* javax/swing/Timer.java: Run Jalopy.
(run): Comment out println.
* javax/swing/ToolTipManager.java:
(mouseMoved): Get new tooltip text for location.
* javax/swing/colorchooser/AbstractColorChooserPanel.java:
Jalopy and Javadoc.
* javax/swing/colorchooser/ColorChooserComponentFactory.java:
Implement.
* javax/swing/colorchooser/DefaultColorSelectionModel.java:
Run Jalopy.
(setSelectedColor): Fire ChangeEvent.
* javax/swing/colorchooser/DefaultHSBChooserPanel.java:
New file. Implement.
* javax/swing/colorchooser/DefaultPreviewPanel.java:
Ditto.
* javax/swing/colorchooser/DefaultRGBChooserPanel.java:
Ditto.
* javax/swing/colorchooser/DefaultSwatchChooserPanel.java:
Ditto.
* javax/swing/plaf/basic/BasicArrowButton.java:
(getArrow): Fix size of upward pointing button.
* javax/swing/plaf/basic/BasicColorChooserUI.java:
Implement.
* javax/swing/plaf/basic/BasicSliderUI.java:
(getWidthOfWidestLabel): Use preferred dimensions.
(getHeightOfTallestLabel): Ditto.
* javax/swing/plaf/basic/BasicSpinnerUI.java:
Run Jalopy.
(mousePressed): Disable changes to spinner if it is not enabled.
Committed.
Cheers,
Mark
Index: examples/gnu/classpath/examples/swing/Demo.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/examples/gnu/classpath/examples/swing/Demo.java,v
retrieving revision 1.3
diff -u -r1.3 Demo.java
--- examples/gnu/classpath/examples/swing/Demo.java 4 Sep 2004 16:55:52
-0000 1.3
+++ examples/gnu/classpath/examples/swing/Demo.java 4 Sep 2004 20:11:26
-0000
@@ -669,6 +669,11 @@
return close;
}
+ public static JColorChooser mkColorChooser()
+ {
+ return new JColorChooser();
+ }
+
private static class PopUpAction
implements ActionListener
{
@@ -758,6 +763,10 @@
mkTextField("Hello, World!"),
panel);
+ new PopUpAction("ColorChooser",
+ mkColorChooser(),
+ panel);
+
JButton exitDisposer = mkDisposerButton(frame);
panel.add(exitDisposer);
Index: java/awt/Color.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Color.java,v
retrieving revision 1.9
diff -u -r1.9 Color.java
--- java/awt/Color.java 28 Apr 2004 07:19:10 -0000 1.9
+++ java/awt/Color.java 4 Sep 2004 20:11:27 -0000
@@ -506,7 +506,7 @@
/**
* Returns the RGB value for this color, in the sRGB color space. The blue
- * value will be in bits 0-7, green in 8-15, red in 6-23, and alpha value in
+ * value will be in bits 0-7, green in 8-15, red in 16-23, and alpha value in
* 24-31.
*
* @return the RGB value for this color
@@ -772,9 +772,9 @@
if (red == max)
array[0] = (green - blue) / delta;
else if (green == max)
- array[0] = 1 / 3 + (blue - red) / delta;
+ array[0] = 1f / 3 + (blue - red) / delta;
else
- array[0] = 2 / 3 + (red - green) / delta;
+ array[0] = 2f / 3 + (red - green) / delta;
if (array[0] < 0)
array[0]++;
}
Index: javax/swing/ButtonGroup.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/ButtonGroup.java,v
retrieving revision 1.6
diff -u -r1.6 ButtonGroup.java
--- javax/swing/ButtonGroup.java 26 Jun 2004 16:06:48 -0000 1.6
+++ javax/swing/ButtonGroup.java 4 Sep 2004 20:11:27 -0000
@@ -42,19 +42,18 @@
import java.util.Vector;
-public class ButtonGroup
- implements Serializable
+/**
+ * DOCUMENT ME!
+ */
+public class ButtonGroup implements Serializable
{
+ /** DOCUMENT ME! */
private static final long serialVersionUID = 4259076101881721375L;
- /**
- * The buttons added to this button group.
- */
+ /** The buttons added to this button group. */
protected Vector buttons = new Vector();
- /**
- * The currently selected button model.
- */
+ /** The currently selected button model. */
ButtonModel sel;
/**
@@ -99,17 +98,24 @@
/**
* Returns the currently selected button model.
*
- * @return the currently selected button model,
- * null if none was selected yet
+ * @return the currently selected button model, null if none was selected
+ * yet
*/
public ButtonModel getSelection()
{
return sel;
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param m DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
AbstractButton FindButton(ButtonModel m)
{
- for (int i = 0;i < buttons.size(); i++)
+ for (int i = 0; i < buttons.size(); i++)
{
AbstractButton a = (AbstractButton) buttons.get(i);
if (a.getModel() == m)
@@ -119,46 +125,40 @@
}
/**
- * Sets the currently selected button model. Only one button of a group
- * can be selected at a time.
+ * Sets the currently selected button model. Only one button of a group can
+ * be selected at a time.
*
* @param m the model to select
* @param b true if this button is to be selected, false otherwise
*/
public void setSelected(ButtonModel m, boolean b)
{
- if ((m == sel) && (b == true))
- {
- // clicked on same item twice.
- System.out.println("PRESSED TWICE:" + m + ", sel=" + sel);
- return;
- }
+ if ((sel != m || b) && (! b || sel == m))
+ return;
- if (sel != null)
+ if (b && sel != m)
{
- System.out.println("DESELECTING: " + sel);
- sel.setSelected(! b);
+ ButtonModel old = sel;
+ sel = m;
- AbstractButton but = FindButton(sel);
- if (but != null)
- {
- System.out.println("REPAINT-REQUEST: " + but.text);
- //but.revalidate();
- but.repaint();
- }
+ if (old != null)
+ old.setSelected(false);
+ AbstractButton button = FindButton(old);
+ if (button != null)
+ button.repaint();
}
- else
- System.out.println("NO SELECTION YET");
-
- sel = m;
+ else if (! b && sel == m)
+ m.setSelected(true);
}
/**
- * Checks if the given <code>ButtonModel</code> is selected
- * in this button group.
+ * Checks if the given <code>ButtonModel</code> is selected in this button
+ * group.
+ *
+ * @param m DOCUMENT ME!
*
- * @return true of given <code>ButtonModel</code> is selected,
- * false otherwise
+ * @return true of given <code>ButtonModel</code> is selected, false
+ * otherwise
*/
public boolean isSelected(ButtonModel m)
{
Index: javax/swing/DefaultButtonModel.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/DefaultButtonModel.java,v
retrieving revision 1.10
diff -u -r1.10 DefaultButtonModel.java
--- javax/swing/DefaultButtonModel.java 26 Jun 2004 16:06:48 -0000 1.10
+++ javax/swing/DefaultButtonModel.java 4 Sep 2004 20:11:27 -0000
@@ -1,4 +1,4 @@
-/* DefaultButtonModel.java --
+/* DefaultButtonModel.java --
Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -44,87 +44,103 @@
import java.awt.event.KeyEvent;
import java.io.Serializable;
import java.util.EventListener;
-
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.EventListenerList;
+
/**
* The purpose of this class is to model the dynamic state of an abstract
* button. The concrete button type holding this state may be a a "toggle"
* button (checkbox, radio button) or a "push" button (menu button, button).
- *
- * If the model is disabled, only the "selected" property can be changed.
- * An attempt to change the "armed", "rollover" or "pressed" properties
- * while the model is disabled will be blocked.
- *
- * Any successful (non-blocked) change to the model's properties will
- * trigger the firing of a ChangeEvent.
- *
- * Any change to the "selected" property will trigger the firing of an
- * ItemEvent in addition to ChangeEvent. This is true whether the model is
- * enabled or not.
- *
- * One other state change is special: the transition from "enabled, armed
- * and pressd" to "enabled, armed and not-pressed". This is considered the
- * "trailing edge" of a successful mouse click, and therefore fires an
- * ActionEvent in addition to a ChangeEvent.
+ * If the model is disabled, only the "selected" property can be changed. An
+ * attempt to change the "armed", "rollover" or "pressed" properties while
+ * the model is disabled will be blocked. Any successful (non-blocked) change
+ * to the model's properties will trigger the firing of a ChangeEvent. Any
+ * change to the "selected" property will trigger the firing of an ItemEvent
+ * in addition to ChangeEvent. This is true whether the model is enabled or
+ * not. One other state change is special: the transition from "enabled,
+ * armed and pressd" to "enabled, armed and not-pressed". This is considered
+ * the "trailing edge" of a successful mouse click, and therefore fires an
+ * ActionEvent in addition to a ChangeEvent. In all other respects this class
+ * is just a container of boolean flags.
*
- * In all other respects this class is just a container of boolean flags.
- *
- * @author Graydon Hoare (address@hidden)
+ * @author Graydon Hoare (graydon_at_redhat.com)
*/
public class DefaultButtonModel implements ButtonModel, Serializable
{
+ /** DOCUMENT ME! */
static final long serialVersionUID = -5342609566534980231L;
- /** Indicates that the button is <em>partially</em> committed to being
- pressed, but not entirely. This usually happens when a user has pressed
- but not yet released the mouse button. */
+ /**
+ * Indicates that the button is <em>partially</em> committed to being
+ * pressed, but not entirely. This usually happens when a user has pressed
+ * but not yet released the mouse button.
+ */
public static final int ARMED = 1;
- /** State constant indicating that the button is enabled. Buttons cannot
- be pressed or selected unless they are enabled. */
+ /**
+ * State constant indicating that the button is enabled. Buttons cannot be
+ * pressed or selected unless they are enabled.
+ */
public static final int ENABLED = 8;
- /** State constant indicating that the user is holding down the button.
- When this transitions from true to false, an ActionEvent may be fired,
- depending on the value of the "armed" property.*/
+ /**
+ * State constant indicating that the user is holding down the button. When
+ * this transitions from true to false, an ActionEvent may be fired,
+ * depending on the value of the "armed" property.
+ */
public static final int PRESSED = 4;
- /** State constant indicating that the mouse is currently positioned over
- the button. */
+ /**
+ * State constant indicating that the mouse is currently positioned over the
+ * button.
+ */
public static final int ROLLOVER = 16;
- /** State constant indicating that the button is selected. This constant
- is only meaningful for toggle-type buttons (radio buttons,
- checkboxes). */
+ /**
+ * State constant indicating that the button is selected. This constant is
+ * only meaningful for toggle-type buttons (radio buttons, checkboxes).
+ */
public static final int SELECTED = 2;
- /** Represents the "state properties" (armed, enabled, pressed, rollover
- and selected) by a bitwise combination of integer constants. */
+ /**
+ * Represents the "state properties" (armed, enabled, pressed, rollover and
+ * selected) by a bitwise combination of integer constants.
+ */
protected int stateMask = ENABLED;
- /** List of ItemListeners, ChangeListeners, and ActionListeners
- registered on this model. */
- protected EventListenerList listenerList = new EventListenerList();;
+ /**
+ * List of ItemListeners, ChangeListeners, and ActionListeners registered on
+ * this model.
+ */
+ protected EventListenerList listenerList = new EventListenerList();
+ ;
- /** The single ChangeEvent this model (re)uses to call its
- ChangeListeners. */
+ /** The single ChangeEvent this model (re)uses to call its ChangeListeners.
*/
protected ChangeEvent changeEvent = new ChangeEvent(this);
- /** The group this model belongs to. Only one button in a group may be
- selected at any given time. */
+ /**
+ * The group this model belongs to. Only one button in a group may be
+ * selected at any given time.
+ */
protected ButtonGroup group;
-
- /** The key code (one of address@hidden java.awt.event.KeyEvent} VK_*) used
to
- press this button via a keyboard interface. */
+
+ /**
+ * The key code (one of address@hidden java.awt.event.KeyEvent} VK_) used to
press
+ * this button via a keyboard interface.
+ */
protected int mnemonic = KeyEvent.VK_UNDEFINED;
- /** The string used as the "command" property of any ActionEvent this
- model sends. */
+ /**
+ * The string used as the "command" property of any ActionEvent this model
+ * sends.
+ */
protected String actionCommand;
+ /**
+ * Creates a new DefaultButtonModel object.
+ */
public DefaultButtonModel()
{
}
@@ -135,10 +151,10 @@
*
* @return <code>null</code>
*/
- public Object[] getSelectedObjects()
- {
- return null;
- }
+ public Object[] getSelectedObjects()
+ {
+ return null;
+ }
/**
* Returns a specified class of listeners.
@@ -151,10 +167,10 @@
{
return listenerList.getListeners(listenerType);
}
-
+
/**
- * Add an ActionListener to the model. Usually only called to subscribe
- * an AbstractButton's listener to the model.
+ * Add an ActionListener to the model. Usually only called to subscribe an
+ * AbstractButton's listener to the model.
*
* @param l The listener to add
*/
@@ -162,10 +178,10 @@
{
listenerList.add(ActionListener.class, l);
}
-
+
/**
- * Remove an ActionListener to the model. Usually only called to
- * unsubscribe an AbstractButton's listener to the model.
+ * Remove an ActionListener to the model. Usually only called to unsubscribe
+ * an AbstractButton's listener to the model.
*
* @param l The listener to remove
*/
@@ -185,8 +201,8 @@
}
/**
- * Add an ItemListener to the model. Usually only called to subscribe
- * an AbstractButton's listener to the model.
+ * Add an ItemListener to the model. Usually only called to subscribe an
+ * AbstractButton's listener to the model.
*
* @param l The listener to add
*/
@@ -196,8 +212,8 @@
}
/**
- * Remove an ItemListener to the model. Usually only called to
- * unsubscribe an AbstractButton's listener to the model.
+ * Remove an ItemListener to the model. Usually only called to unsubscribe
+ * an AbstractButton's listener to the model.
*
* @param l The listener to remove
*/
@@ -217,8 +233,8 @@
}
/**
- * Add a ChangeListener to the model. Usually only called to subscribe
- * an AbstractButton's listener to the model.
+ * Add a ChangeListener to the model. Usually only called to subscribe an
+ * AbstractButton's listener to the model.
*
* @param l The listener to add
*/
@@ -228,8 +244,8 @@
}
/**
- * Remove a ChangeListener to the model. Usually only called to
- * unsubscribe an AbstractButton's listener to the model.
+ * Remove a ChangeListener to the model. Usually only called to unsubscribe
+ * an AbstractButton's listener to the model.
*
* @param l The listener to remove
*/
@@ -258,61 +274,60 @@
public void fireItemStateChanged(ItemEvent e)
{
ItemListener[] ll = getItemListeners();
-
+
for (int i = 0; i < ll.length; i++)
ll[i].itemStateChanged(e);
}
/**
* Inform each ActionListener in the address@hidden listenerList} that an
- * ActionEvent has occurred. This happens in response to the any change
- * to the address@hidden stateMask} field which makes the enabled, armed and
- * pressed properties all simultaneously <code>true</code>.
+ * ActionEvent has occurred. This happens in response to the any change to
+ * the address@hidden stateMask} field which makes the enabled, armed and
pressed
+ * properties all simultaneously <code>true</code>.
*
* @param e The ActionEvent to fire
*/
public void fireActionPerformed(ActionEvent e)
{
ActionListener[] ll = getActionListeners();
-
+
for (int i = 0; i < ll.length; i++)
ll[i].actionPerformed(e);
}
/**
- * Inform each ChangeListener in the address@hidden listenerList} that a
- * ChangeEvent has occurred. This happens in response to the any change
- * to a property of the model.
- *
- * @param event The ChangeEvent to fire
+ * Inform each ChangeListener in the address@hidden listenerList} that a
ChangeEvent
+ * has occurred. This happens in response to the any change to a property
+ * of the model.
*/
public void fireStateChanged()
{
ChangeListener[] ll = getChangeListeners();
-
+
for (int i = 0; i < ll.length; i++)
ll[i].stateChanged(changeEvent);
}
/**
- * Helper method to fire a ChangeEvent with the model as the event's
- * source.
+ * Helper method to fire a ChangeEvent with the model as the event's source.
+ *
+ * @param stateflag DOCUMENT ME!
+ * @param b DOCUMENT ME!
*/
protected void changeState(int stateflag, boolean b)
- {
+ {
int oldstate = stateMask;
int newstate;
if (b)
newstate = oldstate | stateflag;
else
- newstate = oldstate & ~stateflag;
+ newstate = oldstate & ~ stateflag;
if (oldstate == newstate)
return;
- if ((stateflag != SELECTED)
- && (stateflag != ENABLED)
+ if ((stateflag != SELECTED) && (stateflag != ENABLED)
&& (stateMask & ENABLED) == 0)
return;
@@ -320,35 +335,36 @@
fireStateChanged();
- if ((oldstate & SELECTED) == 0
- && (newstate & SELECTED) == SELECTED)
- fireItemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED,
- null, ItemEvent.SELECTED));
-
- else if ((oldstate & SELECTED) == SELECTED
- && (newstate & SELECTED) == 0)
- fireItemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED,
- null, ItemEvent.DESELECTED));
-
- else if (((oldstate & ARMED) == ARMED && (oldstate & PRESSED) == PRESSED)
- &&
- ((newstate & ARMED) == ARMED && (newstate & PRESSED) == 0))
+ if ((oldstate & SELECTED) == 0 && (newstate & SELECTED) == SELECTED)
{
- fireActionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED,
- actionCommand));
+ fireItemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED,
+ null, ItemEvent.SELECTED));
+ group.setSelected(this, true);
}
- }
-
+
+ else if ((oldstate & SELECTED) == SELECTED && (newstate & SELECTED) == 0)
+ {
+ fireItemStateChanged(new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED,
+ null, ItemEvent.DESELECTED));
+ group.setSelected(this, false);
+ }
+
+ else if (((oldstate & ARMED) == ARMED && (oldstate & PRESSED) == PRESSED)
+ && ((newstate & ARMED) == ARMED && (newstate & PRESSED) == 0))
+ fireActionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED,
+ actionCommand));
+ }
+
/**
* Get the value of the model's "armed" property.
- *
- * @return The current "armed" property
+ *
+ * @return The current "armed" property
*/
public boolean isArmed()
{
return (stateMask & ARMED) == ARMED;
}
-
+
/**
* Set the value of the model's "armed" property.
*
@@ -365,9 +381,9 @@
* @return The current "enabled" property.
*/
public boolean isEnabled()
- {
+ {
return (stateMask & ENABLED) == ENABLED;
- }
+ }
/**
* Set the value of the model's "enabled" property.
@@ -385,9 +401,9 @@
* @param p The new "pressed" property
*/
public void setPressed(boolean p)
- {
+ {
changeState(PRESSED, p);
- }
+ }
/**
* Get the value of the model's "pressed" property.
@@ -409,7 +425,6 @@
changeState(ROLLOVER, r);
}
-
/**
* Set the value of the model's "selected" property.
*
@@ -436,9 +451,9 @@
* @return The current "rollover" property
*/
public boolean isRollover()
- {
+ {
return (stateMask & ROLLOVER) == ROLLOVER;
- }
+ }
/**
* Get the value of the model's "mnemonic" property.
@@ -446,7 +461,7 @@
* @return The current "mnemonic" property
*/
public int getMnemonic()
- {
+ {
return mnemonic;
}
@@ -459,15 +474,15 @@
{
if (mnemonic != key)
{
- mnemonic = key;
- fireStateChanged();
+ mnemonic = key;
+ fireStateChanged();
}
}
-
+
/**
- * Set the value of the model's "actionCommand" property. This property
- * is used as the "command" property of the address@hidden ActionEvent} fired
- * from the model.
+ * Set the value of the model's "actionCommand" property. This property is
+ * used as the "command" property of the address@hidden ActionEvent} fired
from the
+ * model.
*
* @param s The new "actionCommand" property.
*/
@@ -475,11 +490,11 @@
{
if (actionCommand != s)
{
- actionCommand = s;
- fireStateChanged();
+ actionCommand = s;
+ fireStateChanged();
}
- }
-
+ }
+
/**
* Returns the current value of the model's "actionCommand" property.
*
@@ -491,9 +506,9 @@
}
/**
- * Set the value of the model's "group" property. The model is said to be
- * a member of the address@hidden ButtonGroup} held in its "group" property,
and
- * only one model in a given group can have their "selected" property be
+ * Set the value of the model's "group" property. The model is said to be a
+ * member of the address@hidden ButtonGroup} held in its "group" property,
and only
+ * one model in a given group can have their "selected" property be
* <code>true</code> at a time.
*
* @param g The new "group" property
@@ -502,8 +517,8 @@
{
if (group != g)
{
- group = g;
- fireStateChanged();
+ group = g;
+ fireStateChanged();
}
}
Index: javax/swing/JColorChooser.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JColorChooser.java,v
retrieving revision 1.3
diff -u -r1.3 JColorChooser.java
--- javax/swing/JColorChooser.java 26 Jun 2004 16:06:48 -0000 1.3
+++ javax/swing/JColorChooser.java 4 Sep 2004 20:11:27 -0000
@@ -35,11 +35,16 @@
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package javax.swing;
+import java.awt.AWTError;
+import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
+import java.awt.Dialog;
+import java.awt.FlowLayout;
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.ObjectOutputStream;
@@ -47,314 +52,521 @@
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
import javax.swing.colorchooser.AbstractColorChooserPanel;
+import javax.swing.colorchooser.ColorChooserComponentFactory;
import javax.swing.colorchooser.ColorSelectionModel;
+import javax.swing.colorchooser.DefaultColorSelectionModel;
import javax.swing.plaf.ColorChooserUI;
+
/**
- * JColorChooser
- * @author Andrew Selkirk
- * @version 1.0
+ * The JColorChooser is a Swing widget that offers users different ways to
+ * select a color. By default, three different panels are presented to the
+ * user that are capable of changing the selected color. There are three ways
+ * to utilize JColorChooser. The first is to build a JColorChooser and add it
+ * to the content pane. The second is to use the createDialog method to
+ * create a JDialog that holds a JColorChooser. The third is to show a
+ * JColorChooser in a JDialog directly using the showDialog method.
*/
-public class JColorChooser extends JComponent implements Accessible {
-
+public class JColorChooser extends JComponent implements Accessible
+{
+ /** DOCUMENT ME! */
private static final long serialVersionUID = 9168066781620640889L;
-
- //-------------------------------------------------------------
- // Classes ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * AccessibleJColorChooser
- */
- protected class AccessibleJColorChooser extends
JComponent.AccessibleJComponent {
-
- private static final long serialVersionUID = -2038297864782299082L;
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * Constructor AccessibleJColorChooser
- * @param component TODO
- */
- protected AccessibleJColorChooser()
+
+ /**
+ * AccessibleJColorChooser
+ */
+ protected class AccessibleJColorChooser
+ extends JComponent.AccessibleJComponent
+ {
+ /** DOCUMENT ME! */
+ private static final long serialVersionUID = -2038297864782299082L;
+
+ /**
+ * Constructor AccessibleJColorChooser
+ */
+ protected AccessibleJColorChooser()
+ {
+ }
+
+ /**
+ * getAccessibleRole
+ *
+ * @return AccessibleRole
+ */
+ public AccessibleRole getAccessibleRole()
+ {
+ return AccessibleRole.COLOR_CHOOSER;
+ } // getAccessibleRole()
+ } // AccessibleJColorChooser
+
+ /** The model used with the JColorChooser. */
+ private ColorSelectionModel selectionModel;
+
+ /** The preview panel associated with the JColorChooser. */
+ private JComponent previewPanel;
+
+ /**
+ * The set of AbstractColorChooserPanels associated with the JColorChooser.
+ */
+ private AbstractColorChooserPanel[] chooserPanels;
+
+ /** A Drag and Drop property. */
+ private boolean dragEnabled;
+
+ /**
+ * The property fired by the JColorChooser when the selectionModel property
+ * changes.
+ */
+ public static final String SELECTION_MODEL_PROPERTY = "selectionModel";
+
+ /**
+ * The property fired by the JColorChooser when the previewPanel property
+ * changes.
+ */
+ public static final String PREVIEW_PANEL_PROPERTY = "previewPanel";
+
+ /**
+ * The property fired by the JColorChooser when the chooserPanels property
+ * changes.
+ */
+ public static final String CHOOSER_PANELS_PROPERTY = "chooserPanels";
+
+ /** accessibleContext */
+ protected AccessibleContext accessibleContext;
+
+ /**
+ * This method creates a new JColorChooser with the default initial color.
+ */
+ public JColorChooser()
+ {
+ this(new DefaultColorSelectionModel());
+ } // JColorChooser()
+
+ /**
+ * This method creates a new JColorChooser with the given initial color.
+ *
+ * @param initial The initial color.
+ */
+ public JColorChooser(Color initial)
+ {
+ this(new DefaultColorSelectionModel(initial));
+ } // JColorChooser()
+
+ /**
+ * This method creates a new JColorChooser with the given model. The model
+ * will dictate what the initial color for the JColorChooser is.
+ *
+ * @param model The Model to use with the JColorChooser.
+ */
+ public JColorChooser(ColorSelectionModel model)
+ {
+ if (model == null)
+ model = new DefaultColorSelectionModel();
+ selectionModel = model;
+ updateUI();
+ } // JColorChooser()
+
+ /**
+ * This method sets the current color for the JColorChooser.
+ *
+ * @param color The new color for the JColorChooser.
+ */
+ public void setColor(Color color)
+ {
+ if (color != null)
+ selectionModel.setSelectedColor(color);
+ } // setColor()
+
+ /**
+ * This method sets the current color for the JColorChooser using RGB
+ * values.
+ *
+ * @param r The red value.
+ * @param g The green value.
+ * @param b The blue value.
+ */
+ public void setColor(int r, int g, int b)
+ {
+ selectionModel.setSelectedColor(new Color(r, g, b));
+ } // setColor()
+
+ /**
+ * This method sets the current color for the JColorChooser using the
+ * integer value. Bits 0-7 represent the blue value. Bits 8-15 represent
+ * the green value. Bits 16-23 represent the red value.
+ *
+ * @param color The new current color of the JColorChooser.
+ */
+ public void setColor(int color)
+ {
+ setColor(new Color(color, false));
+ } // setColor()
+
+ /**
+ * This method shows a JColorChooser inside a JDialog. The JDialog will
+ * block until it is hidden. The JDialog comes with three buttons: OK,
+ * Cancel, and Reset. Pressing OK or Cancel hide the JDialog. Pressing
+ * Reset will reset the JColorChooser to its initial value.
+ *
+ * @param component The Component that parents the JDialog.
+ * @param title The title displayed in the JDialog.
+ * @param initial The initial color.
+ *
+ * @return The selected color.
+ */
+ public static Color showDialog(Component component, String title,
+ Color initial)
+ {
+ JColorChooser choose = new JColorChooser(initial);
+
+ JDialog dialog = createDialog(component, title, true, choose, null, null);
+
+ dialog.getContentPane().add(choose);
+ dialog.pack();
+ dialog.show();
+
+ return choose.getColor();
+ } // showDialog()
+
+ /**
+ * This is a helper method to make the given JDialog block until it is
+ * hidden.
+ *
+ * @param dialog The JDialog to block.
+ */
+ private static void makeModal(JDialog dialog)
+ {
+ try
+ {
+ synchronized (dialog)
{
+ while (dialog.isVisible())
+ dialog.wait();
}
+ }
+ catch (InterruptedException e)
+ {
+ }
+ }
+
+ /**
+ * This is a helper method to find the first Frame or Dialog ancestor of the
+ * given Component.
+ *
+ * @param c The Component to find ancestors for.
+ *
+ * @return A Frame or Dialog ancestor. Null if none are found.
+ */
+ private static Component findParent(Component c)
+ {
+ Component parent = SwingUtilities.getAncestorOfClass(Frame.class, c);
+ if (parent != null)
+ return parent;
+ parent = SwingUtilities.getAncestorOfClass(Dialog.class, c);
+ return parent;
+ }
+
+ /**
+ * This method will take the given JColorChooser and place it in a JDialog
+ * with the given modal property. Three buttons are displayed in the
+ * JDialog: OK, Cancel and Reset. If OK or Cancel are pressed, the JDialog
+ * is hidden. If Reset is pressed, then the JColorChooser will take on its
+ * default color value. The given okListener will be registered to the OK
+ * button and the cancelListener will be registered to the Cancel button.
+ * If the modal property is set, then the JDialog will block until it is
+ * hidden.
+ *
+ * @param component The Component that will parent the JDialog.
+ * @param title The title displayed in the JDialog.
+ * @param modal The modal property.
+ * @param chooserPane The JColorChooser to place in the JDialog.
+ * @param okListener The ActionListener to register to the OK button.
+ * @param cancelListener The ActionListener to register to the Cancel
+ * button.
+ *
+ * @return A JDialog with the JColorChooser inside of it.
+ *
+ * @throws AWTError If the component is not a suitable parent.
+ */
+ public static JDialog createDialog(Component component, String title,
+ boolean modal, JColorChooser chooserPane,
+ ActionListener okListener,
+ ActionListener cancelListener)
+ {
+ Component parent = findParent(component);
+ if (parent == null)
+ throw new AWTError("No suitable parent found for Component.");
+ JDialog dialog;
+ if (parent instanceof Frame)
+ dialog = new ModalDialog((Frame) parent, title);
+ else
+ dialog = new ModalDialog((Dialog) parent, title);
+ dialog.setModal(modal);
+
+ dialog.getContentPane().setLayout(new BorderLayout());
+
+ JPanel panel = new JPanel();
+ panel.setLayout(new FlowLayout());
+
+ ActionListener al = new DefaultOKCancelListener(dialog);
+
+ JButton ok = new JButton("OK");
+ ok.addActionListener(okListener);
+ ok.addActionListener(al);
+
+ JButton cancel = new JButton("Cancel");
+ cancel.addActionListener(cancelListener);
+ cancel.addActionListener(al);
+
+ JButton reset = new JButton("Reset");
+ reset.addActionListener(new DefaultResetListener(chooserPane));
+
+ dialog.getContentPane().add(chooserPane, BorderLayout.NORTH);
+
+ panel.add(ok);
+ panel.add(cancel);
+ panel.add(reset);
+
+ dialog.getContentPane().add(panel, BorderLayout.SOUTH);
+
+ return dialog;
+ } // createDialog()
+
+ /**
+ * This method returns the UI Component used for this JColorChooser.
+ *
+ * @return The UI Component for this JColorChooser.
+ */
+ public ColorChooserUI getUI()
+ {
+ return (ColorChooserUI) ui;
+ } // getUI()
+
+ /**
+ * This method sets the UI Component used for this JColorChooser.
+ *
+ * @param ui The UI Component to use with this JColorChooser.
+ */
+ public void setUI(ColorChooserUI ui)
+ {
+ super.setUI(ui);
+ } // setUI()
+
+ /**
+ * This method resets the UI Component property to the Look and Feel
+ * default.
+ */
+ public void updateUI()
+ {
+ setUI((ColorChooserUI) UIManager.getUI(this));
+ revalidate();
+ } // updateUI()
+
+ /**
+ * This method returns a String identifier for the UI Class to be used with
+ * the JColorChooser.
+ *
+ * @return The String identifier for the UI Class.
+ */
+ public String getUIClassID()
+ {
+ return "ColorChooserUI";
+ } // getUIClassID()
+
+ /**
+ * This method returns the current color for the JColorChooser.
+ *
+ * @return The current color for the JColorChooser.
+ */
+ public Color getColor()
+ {
+ return selectionModel.getSelectedColor(); // TODO
+ } // getColor()
+
+ /**
+ * This method changes the previewPanel property for the JTabbedPane. The
+ * previewPanel is responsible for indicating the current color of the
+ * JColorChooser.
+ *
+ * @param component The Component that will act as the previewPanel.
+ */
+ public void setPreviewPanel(JComponent component)
+ {
+ if (component != previewPanel)
+ {
+ JComponent old = previewPanel;
+ previewPanel = component;
+ firePropertyChange(PREVIEW_PANEL_PROPERTY, old, previewPanel);
+ }
+ } // setPreviewPanel()
+
+ /**
+ * This method returns the current previewPanel used with this
+ * JColorChooser.
+ *
+ * @return The current previewPanel.
+ */
+ public JComponent getPreviewPanel()
+ {
+ return previewPanel; // TODO
+ } // getPreviewPanel()
+
+ /**
+ * This method adds the given AbstractColorChooserPanel to the list of the
+ * JColorChooser's chooserPanels.
+ *
+ * @param panel The AbstractColorChooserPanel to add.
+ */
+ public void addChooserPanel(AbstractColorChooserPanel panel)
+ {
+ if (panel == null)
+ return;
+ AbstractColorChooserPanel[] old = chooserPanels;
+ AbstractColorChooserPanel[] newPanels = new AbstractColorChooserPanel[(old
== null)
+ ? 1
+ :
old.length
+ + 1];
+ if (old != null)
+ System.arraycopy(old, 0, newPanels, 0, old.length);
+ newPanels[newPanels.length - 1] = panel;
+ chooserPanels = newPanels;
+ panel.installChooserPanel(this);
+ firePropertyChange(CHOOSER_PANELS_PROPERTY, old, newPanels);
+ } // addChooserPanel()
+
+ /**
+ * This method removes the given AbstractColorChooserPanel from the
+ * JColorChooser's list of chooserPanels.
+ *
+ * @param panel The AbstractColorChooserPanel to remove.
+ *
+ * @return The AbstractColorChooserPanel that was removed.
+ */
+ public AbstractColorChooserPanel
removeChooserPanel(AbstractColorChooserPanel panel)
+ {
+ int index = -1;
+ for (int i = 0; i < chooserPanels.length; i++)
+ if (panel == chooserPanels[i])
+ {
+ index = i;
+ break;
+ }
+
+ if (index == -1)
+ return null;
+
+ AbstractColorChooserPanel[] old = chooserPanels;
+ if (chooserPanels.length == 1)
+ chooserPanels = null;
+ else
+ {
+ AbstractColorChooserPanel[] newPanels = new
AbstractColorChooserPanel[chooserPanels.length
+ - 1];
+ System.arraycopy(chooserPanels, 0, newPanels, 0, index);
+ System.arraycopy(chooserPanels, index, newPanels, index - 1,
+ chooserPanels.length - index);
+ chooserPanels = newPanels;
+ }
+ panel.uninstallChooserPanel(this);
+ firePropertyChange(CHOOSER_PANELS_PROPERTY, old, chooserPanels);
+ return panel;
+ }
+
+ /**
+ * This method sets the chooserPanels property for this JColorChooser.
+ *
+ * @param panels The new set of AbstractColorChooserPanels to use.
+ */
+ public void setChooserPanels(AbstractColorChooserPanel[] panels)
+ {
+ if (panels != chooserPanels)
+ {
+ if (chooserPanels != null)
+ for (int i = 0; i < chooserPanels.length; i++)
+ if (chooserPanels[i] != null)
+ chooserPanels[i].uninstallChooserPanel(this);
+
+ AbstractColorChooserPanel[] old = chooserPanels;
+ chooserPanels = panels;
+
+ if (panels != null)
+ for (int i = 0; i < panels.length; i++)
+ if (panels[i] != null)
+ panels[i].installChooserPanel(this);
+
+ firePropertyChange(CHOOSER_PANELS_PROPERTY, old, chooserPanels);
+ }
+ } // setChooserPanels()
+
+ /**
+ * This method returns the AbstractColorChooserPanels used with this
+ * JColorChooser.
+ *
+ * @return The AbstractColorChooserPanels used with this JColorChooser.
+ */
+ public AbstractColorChooserPanel[] getChooserPanels()
+ {
+ return chooserPanels;
+ } // getChooserPanels()
- /**
- * getAccessibleRole
- * @returns AccessibleRole
- */
- public AccessibleRole getAccessibleRole() {
- return AccessibleRole.COLOR_CHOOSER;
- } // getAccessibleRole()
-
-
- } // AccessibleJColorChooser
-
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * uiClassID
- */
- private static final String uiClassID = "ColorChooserUI";
-
- /**
- * selectionModel
- */
- private ColorSelectionModel selectionModel;
-
- /**
- * previewPanel
- */
- private JComponent previewPanel;
-
- /**
- * chooserPanels
- */
- private AbstractColorChooserPanel[] chooserPanels;
-
- /**
- * SELECTION_MODEL_PROPERTY
- */
- public static final String SELECTION_MODEL_PROPERTY = "selectionModel";
-
- /**
- * PREVIEW_PANEL_PROPERTY
- */
- public static final String PREVIEW_PANEL_PROPERTY = "previewPanel";
-
- /**
- * CHOOSER_PANELS_PROPERTY
- */
- public static final String CHOOSER_PANELS_PROPERTY = "chooserPanels";
-
- /**
- * accessibleContext
- */
- protected AccessibleContext accessibleContext;
-
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * Constructor JColorChooser
- */
- public JColorChooser() {
- // TODO
- } // JColorChooser()
-
- /**
- * Constructor JColorChooser
- * @param initial TODO
- */
- public JColorChooser(Color initial) {
- // TODO
- } // JColorChooser()
-
- /**
- * Constructor JColorChooser
- * @param model TODO
- */
- public JColorChooser(ColorSelectionModel model) {
- // TODO
- } // JColorChooser()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * writeObject
- * @param stream TODO
- * @exception IOException TODO
- */
- private void writeObject(ObjectOutputStream stream) throws IOException {
- // TODO
- } // writeObject()
-
- /**
- * setColor
- * @param color TODO
- */
- public void setColor(Color color) {
- // TODO
- } // setColor()
-
- /**
- * setColor
- * @param r TODO
- * @param g TODO
- * @param b TODO
- */
- public void setColor(int r, int g, int b) {
- // TODO
- } // setColor()
-
- /**
- * setColor
- * @param color TODO
- */
- public void setColor(int color) {
- // TODO
- } // setColor()
-
- /**
- * showDialog
- * @param component TODO
- * @param title TODO
- * @param initial TODO
- * @returns Color
- */
- public static Color showDialog(Component component, String title,
- Color initial) {
- return null; // TODO
- } // showDialog()
-
- /**
- * createDialog
- * @param component TODO
- * @param title TODO
- * @param modal TODO
- * @param chooserPane TODO
- * @param okListener TODO
- * @param cancelListener TODO
- * @returns JDialog
- */
- public static JDialog createDialog(Component component, String title,
- boolean modal, JColorChooser chooserPane,
- ActionListener okListener, ActionListener
cancelListener) {
- return null; // TODO
- } // createDialog()
-
- /**
- * getUI
- * @returns ColorChooserUI
- */
- public ColorChooserUI getUI() {
- return (ColorChooserUI) ui;
- } // getUI()
-
- /**
- * setUI
- * @param ui TODO
- */
- public void setUI(ColorChooserUI ui) {
- super.setUI(ui);
- } // setUI()
-
- /**
- * updateUI
- */
- public void updateUI() {
- setUI((ColorChooserUI) UIManager.get(this));
- invalidate();
- } // updateUI()
-
- /**
- * getUIClassID
- * @returns String
- */
- public String getUIClassID() {
- return uiClassID;
- } // getUIClassID()
-
- /**
- * getColor
- * @returns Color
- */
- public Color getColor() {
- return null; // TODO
- } // getColor()
-
- /**
- * setPreviewPanel
- * @param component TODO
- */
- public void setPreviewPanel(JComponent component) {
- // TODO
- } // setPreviewPanel()
-
- /**
- * getPreviewPanel
- * @returns JComponent
- */
- public JComponent getPreviewPanel() {
- return null; // TODO
- } // getPreviewPanel()
-
- /**
- * addChooserPanel
- * @param panel TODO
- */
- public void addChooserPanel(AbstractColorChooserPanel panel) {
- // TODO
- } // addChooserPanel()
-
- /**
- * removeChooserPanel
- * @param panel TODO
- * @returns AbstractColorChooserPanel
- */
- public AbstractColorChooserPanel removeChooserPanel(
- AbstractColorChooserPanel panel) {
- return null; // TODO
- } // removeChooserPanel()
-
- /**
- * setChooserPanels
- * @param panels TODO
- */
- public void setChooserPanels(AbstractColorChooserPanel[] panels) {
- // TODO
- } // setChooserPanels()
-
- /**
- * getChooserPanels
- * @returns AbstractColorChooserPanel[]
- */
- public AbstractColorChooserPanel[] getChooserPanels() {
- return null; // TODO
- } // getChooserPanels()
-
- /**
- * getSelectionModel
- * @returns ColorSelectionModel
- */
- public ColorSelectionModel getSelectionModel() {
- return null; // TODO
- } // getSelectionModel()
-
- /**
- * setSelectionModel
- * @param model TODO
- */
- public void setSelectionModel(ColorSelectionModel model) {
- // TODO
- } // setSelectionModel()
-
- /**
- * paramString
- * @returns String
- */
- protected String paramString() {
- return null; // TODO
- } // paramString()
+ /**
+ * This method returns the ColorSelectionModel used with this JColorChooser.
+ *
+ * @return The ColorSelectionModel.
+ */
+ public ColorSelectionModel getSelectionModel()
+ {
+ return selectionModel;
+ } // getSelectionModel()
+
+ /**
+ * This method sets the ColorSelectionModel to be used with this
+ * JColorChooser.
+ *
+ * @param model The ColorSelectionModel to be used with this JColorChooser.
+ *
+ * @throws AWTError If the given model is null.
+ */
+ public void setSelectionModel(ColorSelectionModel model)
+ {
+ if (model == null)
+ throw new AWTError("ColorSelectionModel is not allowed to be null.");
+ selectionModel = model;
+ } // setSelectionModel()
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public boolean getDragEnabled()
+ {
+ return dragEnabled;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param b DOCUMENT ME!
+ */
+ public void setDragEnabled(boolean b)
+ {
+ dragEnabled = b;
+ }
+
+ /**
+ * This method returns a String describing the JColorChooser.
+ *
+ * @return A String describing the JColorChooser.
+ */
+ protected String paramString()
+ {
+ return "JColorChooser";
+ } // paramString()
/**
* getAccessibleContext
+ *
* @return AccessibleContext
*/
public AccessibleContext getAccessibleContext()
@@ -364,4 +576,130 @@
return accessibleContext;
}
+
+ /**
+ * A helper class that hides a JDialog when the action is performed.
+ */
+ static class DefaultOKCancelListener implements ActionListener
+ {
+ /** The JDialog to hide. */
+ private JDialog dialog;
+
+ /**
+ * Creates a new DefaultOKCancelListener with the given JDialog to hide.
+ *
+ * @param dialog The JDialog to hide.
+ */
+ public DefaultOKCancelListener(JDialog dialog)
+ {
+ super();
+ this.dialog = dialog;
+ }
+
+ /**
+ * This method hides the JDialog when called.
+ *
+ * @param e The ActionEvent.
+ */
+ public void actionPerformed(ActionEvent e)
+ {
+ dialog.hide();
+ }
+ }
+
+ /**
+ * This method resets the JColorChooser color to the initial color when the
+ * action is performed.
+ */
+ static class DefaultResetListener implements ActionListener
+ {
+ /** The JColorChooser to reset. */
+ private JColorChooser chooser;
+
+ /** The initial color. */
+ private Color init;
+
+ /**
+ * Creates a new DefaultResetListener with the given JColorChooser.
+ *
+ * @param chooser The JColorChooser to reset.
+ */
+ public DefaultResetListener(JColorChooser chooser)
+ {
+ super();
+ this.chooser = chooser;
+ init = chooser.getColor();
+ }
+
+ /**
+ * This method resets the JColorChooser to its initial color.
+ *
+ * @param e The ActionEvent.
+ */
+ public void actionPerformed(ActionEvent e)
+ {
+ chooser.setColor(init);
+ }
+ }
+
+ /**
+ * This is a custom JDialog that will notify when it is hidden and the modal
+ * property is set.
+ */
+ static class ModalDialog extends JDialog
+ {
+ /** The modal property. */
+ private boolean modal;
+
+ /**
+ * Creates a new ModalDialog object with the given parent and title.
+ *
+ * @param parent The parent of the JDialog.
+ * @param title The title of the JDialog.
+ */
+ public ModalDialog(Frame parent, String title)
+ {
+ super(parent, title);
+ }
+
+ /**
+ * Creates a new ModalDialog object with the given parent and title.
+ *
+ * @param parent The parent of the JDialog.
+ * @param title The title of the JDialog.
+ */
+ public ModalDialog(Dialog parent, String title)
+ {
+ super(parent, title);
+ }
+
+ /**
+ * This method sets the modal property.
+ *
+ * @param modal The modal property.
+ */
+ public void setModal(boolean modal)
+ {
+ this.modal = modal;
+ }
+
+ /**
+ * This method shows the ModalDialog.
+ */
+ public void show()
+ {
+ super.show();
+ if (modal)
+ makeModal(this);
+ }
+
+ /**
+ * This method hides the ModalDialog.
+ */
+ public synchronized void hide()
+ {
+ super.hide();
+ notifyAll();
+ }
+ }
}
Index: javax/swing/JLabel.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JLabel.java,v
retrieving revision 1.13
diff -u -r1.13 JLabel.java
--- javax/swing/JLabel.java 4 Sep 2004 17:14:01 -0000 1.13
+++ javax/swing/JLabel.java 4 Sep 2004 20:11:27 -0000
@@ -38,8 +38,8 @@
package javax.swing;
import java.awt.Component;
-import java.awt.Image;
import java.awt.Font;
+import java.awt.Image;
import java.awt.event.KeyEvent;
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
@@ -49,7 +49,7 @@
/**
* <p>
- * A swing widget that displays a text message and/or an icon.
+ * A swing widget that displays a text message and/or an icon.
* </p>
*/
public class JLabel extends JComponent implements Accessible, SwingConstants
@@ -103,10 +103,11 @@
* changes.
*/
public static final String DISPLAYED_MNEMONIC_CHANGED_PROPERTY =
"displayedMnemonic";
-
+
/**
- * Fired in a PropertyChangeEvent when the "displayedMnemonicIndex"
- * property changes. */
+ * Fired in a PropertyChangeEvent when the "displayedMnemonicIndex" property
+ * changes.
+ */
public static final String DISPLAYED_MNEMONIC_INDEX_CHANGED_PROPERTY =
"displayedMnemonicIndex";
/**
@@ -146,8 +147,8 @@
public static final String VERTICAL_TEXT_POSITION_CHANGED_PROPERTY =
"verticalTextPosition";
/**
- * Creates a new horizontally and vertically centered JLabel object with no
text and no
- * icon.
+ * Creates a new horizontally and vertically centered JLabel object with no
+ * text and no icon.
*/
public JLabel()
{
@@ -155,8 +156,8 @@
}
/**
- * Creates a new horizontally and vertically centered JLabel object with no
text and the
- * given icon.
+ * Creates a new horizontally and vertically centered JLabel object with no
+ * text and the given icon.
*
* @param image The icon to use with the label.
*/
@@ -166,8 +167,9 @@
}
/**
- * Creates a new vertically centered JLabel object with no text and the
given icon and
- * horizontal alignment. By default, the text is TRAILING the image.
+ * Creates a new vertically centered JLabel object with no text and the
+ * given icon and horizontal alignment. By default, the text is TRAILING
+ * the image.
*
* @param image The icon to use with the label.
* @param horizontalAlignment The horizontal alignment of the label.
@@ -178,8 +180,8 @@
}
/**
- * Creates a new horizontally and vertically centered JLabel object with no
icon and the
- * given text.
+ * Creates a new horizontally and vertically centered JLabel object with no
+ * icon and the given text.
*
* @param text The text to use with the label.
*/
@@ -189,8 +191,8 @@
}
/**
- * Creates a new vertically centered JLabel object with no icon and the
given text and
- * horizontal alignment.
+ * Creates a new vertically centered JLabel object with no icon and the
+ * given text and horizontal alignment.
*
* @param text The text to use with the label.
* @param horizontalAlignment The horizontal alignment of the label.
@@ -201,8 +203,8 @@
}
/**
- * Creates a new vertically centered JLabel object with the given text,
icon, and horizontal
- * alignment.
+ * Creates a new vertically centered JLabel object with the given text,
+ * icon, and horizontal alignment.
*
* @param text The text to use with the label.
* @param icon The icon to use with the label.
@@ -290,9 +292,8 @@
String oldText = text;
text = newText;
firePropertyChange(TEXT_CHANGED_PROPERTY, oldText, newText);
-
- if (text != null
- && text.length() <= displayedMnemonicIndex)
+
+ if (text != null && text.length() <= displayedMnemonicIndex)
setDisplayedMnemonicIndex(text.length() - 1);
}
}
@@ -326,17 +327,18 @@
/**
* This method returns the disabled icon. The disabled icon is painted when
- * the label is disabled. If the disabled icon is null and the active icon is
- * an ImageIcon, this method returns a grayed version of the icon. The
grayed
- * version of the icon becomes the disabledIcon.
+ * the label is disabled. If the disabled icon is null and the active icon
+ * is an ImageIcon, this method returns a grayed version of the icon. The
+ * grayed version of the icon becomes the disabledIcon.
*
* @return The disabled icon.
*/
public Icon getDisabledIcon()
{
if (disabledIcon == null && icon instanceof ImageIcon)
- disabledIcon = new ImageIcon(GrayFilter.createDisabledImage(((ImageIcon)
icon).getImage()));
-
+ disabledIcon = new ImageIcon(GrayFilter.createDisabledImage(((ImageIcon)
icon)
+
.getImage()));
+
return disabledIcon;
}
@@ -368,21 +370,20 @@
if (displayedMnemonic != mnemonic)
{
firePropertyChange(DISPLAYED_MNEMONIC_CHANGED_PROPERTY,
- displayedMnemonic, mnemonic);
+ displayedMnemonic, mnemonic);
displayedMnemonic = mnemonic;
-
+
if (text != null)
setDisplayedMnemonicIndex(text.indexOf(mnemonic));
}
}
-
/**
* This method sets the character that will be the mnemonic used. If the
* label is used as a label for another component, the label will give
* focus to that component when the mnemonic is activated.
*
- * @param menmonic The character to use for the mnemonic.
+ * @param mnemonic The character to use for the mnemonic.
*/
public void setDisplayedMnemonic(char mnemonic)
{
@@ -499,8 +500,7 @@
{
if (iconTextGap != newGap)
{
- firePropertyChange(ICON_TEXT_GAP_CHANGED_PROPERTY, iconTextGap,
- newGap);
+ firePropertyChange(ICON_TEXT_GAP_CHANGED_PROPERTY, iconTextGap, newGap);
iconTextGap = newGap;
}
}
@@ -639,7 +639,7 @@
// XXX: Is this the correct way to check for image equality?
if (currIcon != null && currIcon instanceof ImageIcon)
return (((ImageIcon) currIcon).getImage() == img);
-
+
return false;
}
@@ -671,10 +671,10 @@
labelFor = c;
}
}
-
+
/**
- * This method overrides setFont so that we can call for a repaint
- * after the font is changed.
+ * This method overrides setFont so that we can call for a repaint after the
+ * font is changed.
*
* @param f The font for this label.
*/
Index: javax/swing/JSpinner.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JSpinner.java,v
retrieving revision 1.1
diff -u -r1.1 JSpinner.java
--- javax/swing/JSpinner.java 14 Aug 2004 22:17:49 -0000 1.1
+++ javax/swing/JSpinner.java 4 Sep 2004 20:11:27 -0000
@@ -48,29 +48,45 @@
import java.beans.PropertyChangeListener;
import java.text.DecimalFormat;
import java.text.ParseException;
+import java.util.EventListener;
import javax.swing.border.EtchedBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.EventListenerList;
import javax.swing.plaf.SpinnerUI;
-import java.util.EventListener;
+
/**
* A JSpinner is a component which typically contains a numeric value and a
* way to manipulate the value.
*
- * @author Ka-Hing Cheung
- * @version 1.0
+ * @author Ka-Hing Cheung
+ * @version 1.0
*/
-public class JSpinner extends JComponent
+public class JSpinner extends JComponent
{
+ /**
+ * DOCUMENT ME!
+ */
public static class StubEditor extends JLabel implements ChangeListener
{
+ /** DOCUMENT ME! */
private JLabel label;
+
+ /** DOCUMENT ME! */
private JButton up;
+
+ /** DOCUMENT ME! */
private JButton down;
+
+ /** DOCUMENT ME! */
private JSpinner spinner;
-
+
+ /**
+ * Creates a new StubEditor object.
+ *
+ * @param spinner DOCUMENT ME!
+ */
public StubEditor(JSpinner spinner)
{
this.spinner = spinner;
@@ -79,91 +95,161 @@
stateChanged(null); /* fill in the label */
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param evt DOCUMENT ME!
+ */
public void stateChanged(ChangeEvent evt)
{
setText(String.valueOf(spinner.getValue()));
}
}
- public static class DefaultEditor extends JPanel
- implements ChangeListener, PropertyChangeListener, LayoutManager
- {
+ /**
+ * DOCUMENT ME!
+ */
+ public static class DefaultEditor extends JPanel implements ChangeListener,
+
PropertyChangeListener,
+ LayoutManager
+ {
+ /**
+ * Creates a new DefaultEditor object.
+ *
+ * @param spinner DOCUMENT ME!
+ */
public DefaultEditor(JSpinner spinner)
{
spinner.addChangeListener(this);
} /* TODO */
-
+ /**
+ * DOCUMENT ME!
+ */
public void commitEdit()
{
} /* TODO */
-
+ /**
+ * DOCUMENT ME!
+ *
+ * @param spinner DOCUMENT ME!
+ */
public void dismiss(JSpinner spinner)
{
spinner.removeChangeListener(this);
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public JFormattedTextField getTextField()
{
return null;
} /* TODO */
-
+ /**
+ * DOCUMENT ME!
+ *
+ * @param parent DOCUMENT ME!
+ */
public void layoutContainer(Container parent)
{
-
} /* TODO */
-
+ /**
+ * DOCUMENT ME!
+ *
+ * @param parent DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public Dimension minimumLayoutSize(Container parent)
{
return null;
} /* TODO */
-
+ /**
+ * DOCUMENT ME!
+ *
+ * @param parent DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public Dimension preferredLayoutSize(Container parent)
{
return null;
} /* TODO */
-
+ /**
+ * DOCUMENT ME!
+ *
+ * @param evt DOCUMENT ME!
+ */
public void propertyChange(PropertyChangeEvent evt)
{
-
} /* TODO */
-
+ /**
+ * DOCUMENT ME!
+ *
+ * @param evt DOCUMENT ME!
+ */
public void stateChanged(ChangeEvent evt)
{
-
} /* TODO */
-
/* no-ops */
public void removeLayoutComponent(Component child)
{
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param name DOCUMENT ME!
+ * @param child DOCUMENT ME!
+ */
public void addLayoutComponent(String name, Component child)
{
}
}
+ /**
+ * DOCUMENT ME!
+ */
public static class NumberEditor extends DefaultEditor
{
+ /**
+ * Creates a new NumberEditor object.
+ *
+ * @param spinner DOCUMENT ME!
+ */
public NumberEditor(JSpinner spinner)
{
super(spinner);
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public DecimalFormat getFormat()
{
return null;
}
}
+ /** DOCUMENT ME! */
private SpinnerModel model;
+
+ /** DOCUMENT ME! */
private JComponent editor;
+
+ /** DOCUMENT ME! */
private EventListenerList listenerList = new EventListenerList();
-
+
+ /** DOCUMENT ME! */
private ChangeListener listener = new ChangeListener()
{
public void stateChanged(ChangeEvent evt)
{
- fireStateChanged();
+ fireStateChanged();
}
};
@@ -179,6 +265,8 @@
/**
* Creates a JSpinner with the specific model and sets the default editor
+ *
+ * @param model DOCUMENT ME!
*/
public JSpinner(SpinnerModel model)
{
@@ -191,17 +279,20 @@
/**
* If the editor is <code>JSpinner.DefaultEditor</code>, then forwards the
* call to it, otherwise do nothing.
+ *
+ * @throws ParseException DOCUMENT ME!
*/
public void commitEdit() throws ParseException
{
- if(editor instanceof DefaultEditor)
- ((DefaultEditor)editor).commitEdit();
+ if (editor instanceof DefaultEditor)
+ ((DefaultEditor) editor).commitEdit();
}
/**
* Gets the current editor
*
* @return the current editor
+ *
* @see #setEditor
*/
public JComponent getEditor()
@@ -214,20 +305,23 @@
* the old listeners (if any) and adds the new listeners (if any).
*
* @param editor the new editor
+ *
+ * @throws IllegalArgumentException DOCUMENT ME!
+ *
* @see #getEditor
*/
public void setEditor(JComponent editor)
{
- if(editor == null)
+ if (editor == null)
throw new IllegalArgumentException("editor may not be null");
- if(this.editor instanceof DefaultEditor)
- ((DefaultEditor)editor).dismiss(this);
- else if(this.editor instanceof ChangeListener)
- removeChangeListener((ChangeListener)this.editor);
+ if (this.editor instanceof DefaultEditor)
+ ((DefaultEditor) editor).dismiss(this);
+ else if (this.editor instanceof ChangeListener)
+ removeChangeListener((ChangeListener) this.editor);
- if(editor instanceof ChangeListener)
- addChangeListener((ChangeListener)editor);
+ if (editor instanceof ChangeListener)
+ addChangeListener((ChangeListener) editor);
this.editor = editor;
}
@@ -246,6 +340,7 @@
* Gets the next value without changing the current value.
*
* @return the next value
+ *
* @see javax.swing.SpinnerModel#getNextValue
*/
public Object getNextValue()
@@ -257,6 +352,7 @@
* Gets the previous value without changing the current value.
*
* @return the previous value
+ *
* @see javax.swing.SpinnerModel#getPreviousValue
*/
public Object getPreviousValue()
@@ -271,14 +367,15 @@
*/
public SpinnerUI getUI()
{
- return (SpinnerUI)ui;
+ return (SpinnerUI) ui;
}
/**
- * Gets the current value of the spinner, according to the underly model, not
- * the UI.
+ * Gets the current value of the spinner, according to the underly model,
+ * not the UI.
*
* @return the current value
+ *
* @see javax.swing.SpinnerModel#getValue
*/
public Object getValue()
@@ -287,6 +384,16 @@
}
/**
+ * DOCUMENT ME!
+ *
+ * @param value DOCUMENT ME!
+ */
+ public void setValue(Object value)
+ {
+ model.setValue(value);
+ }
+
+ /**
* This method returns a name to identify which look and feel class will be
* the UI delegate for this spinner.
*
@@ -317,7 +424,7 @@
}
/**
- * Adds a <code>ChangeListener</code>
+ * Adds a <code>ChangeListener</code>
*
* @param listener the listener to add
*/
@@ -355,20 +462,21 @@
ChangeEvent evt = new ChangeEvent(this);
ChangeListener[] listeners = getChangeListeners();
- for(int i = 0; i < listeners.length; ++i)
+ for (int i = 0; i < listeners.length; ++i)
listeners[i].stateChanged(evt);
}
/**
* Creates an editor for this <code>JSpinner</code>. Really, it should be a
- * <code>JSpinner.DefaultEditor</code>, but since that should be implemented
- * by a JFormattedTextField, and one is not written, I am just using a dummy
- * one backed by a JLabel.
+ * <code>JSpinner.DefaultEditor</code>, but since that should be
+ * implemented by a JFormattedTextField, and one is not written, I am just
+ * using a dummy one backed by a JLabel.
+ *
+ * @param model DOCUMENT ME!
*
* @return the default editor
*/
protected JComponent createEditor(SpinnerModel model)
{
return new StubEditor(this);
- } /* TODO */
-}
+ } /* TODO */}
Index: javax/swing/JTabbedPane.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JTabbedPane.java,v
retrieving revision 1.11
diff -u -r1.11 JTabbedPane.java
--- javax/swing/JTabbedPane.java 22 Jul 2004 19:45:39 -0000 1.11
+++ javax/swing/JTabbedPane.java 4 Sep 2004 20:11:27 -0000
@@ -44,7 +44,6 @@
import java.awt.event.MouseEvent;
import java.io.Serializable;
import java.util.Vector;
-
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
@@ -79,12 +78,11 @@
protected class AccessibleJTabbedPane extends JComponent.AccessibleJComponent
implements AccessibleSelection, ChangeListener
{
+ /** DOCUMENT ME! */
private static final long serialVersionUID = 7610530885966830483L;
-
+
/**
* Creates a new AccessibleJTabbedPane object.
- *
- * @param c DOCUMENT ME!
*/
public AccessibleJTabbedPane()
{
@@ -226,12 +224,16 @@
*/
protected class ModelListener implements ChangeListener, Serializable
{
+ /** DOCUMENT ME! */
private static final long serialVersionUID = 497359819958114132L;
+ /**
+ * Creates a new ModelListener object.
+ */
protected ModelListener()
{
}
-
+
/**
* This method is called whenever the model is changed.
*
@@ -387,7 +389,8 @@
return title;
}
- private static final long serialVersionUID = 1614381073220130939L;
+ /** DOCUMENT ME! */
+ private static final long serialVersionUID = 1614381073220130939L;
/**
* This method sets the title of the tab.
@@ -398,7 +401,7 @@
{
title = text;
if (title != null && title.length() <= underlinedChar)
- setDisplayedMnemonicIndex(title.length() - 1);
+ setDisplayedMnemonicIndex(title.length() - 1);
}
/**
@@ -817,16 +820,21 @@
* This method checks the index.
*
* @param index The index to check.
+ * @param start DOCUMENT ME!
+ * @param end DOCUMENT ME!
+ *
+ * @throws IndexOutOfBoundsException DOCUMENT ME!
*/
private void checkIndex(int index, int start, int end)
{
if (index < start || index >= end)
- throw new IndexOutOfBoundsException("Index < " + start + " || Index >= "
+ end);
+ throw new IndexOutOfBoundsException("Index < " + start + " || Index >= "
+ + end);
}
/**
- * This method sets the selected index. This method
- * will hide the old component and show the new component.
+ * This method sets the selected index. This method will hide the old
+ * component and show the new component.
*
* @param index The index to set it at.
*/
@@ -839,7 +847,7 @@
getSelectedComponent().hide();
if (index != -1 && getComponentAt(index) != null)
getComponentAt(index).show();
- model.setSelectedIndex(index);
+ model.setSelectedIndex(index);
}
}
@@ -867,8 +875,8 @@
}
/**
- * This method inserts tabs into JTabbedPane. This includes
- * adding the component to the JTabbedPane and hiding it.
+ * This method inserts tabs into JTabbedPane. This includes adding the
+ * component to the JTabbedPane and hiding it.
*
* @param title The title of the tab.
* @param icon The tab's icon.
@@ -885,11 +893,11 @@
// Hide the component so we don't see it. Do it before we parent it
// so we don't trigger a repaint.
if (component != null)
- {
- component.hide();
- super.add(component);
- }
-
+ {
+ component.hide();
+ super.add(component);
+ }
+
if (getSelectedIndex() == -1)
setSelectedIndex(0);
@@ -934,15 +942,14 @@
}
/**
- * This method adds a tab to the JTabbedPane.
- * The title of the tab is the Component's name.
- * If the Component is an instance of UIResource, it doesn't
- * add the tab and instead add the component directly to the
+ * This method adds a tab to the JTabbedPane. The title of the tab is the
+ * Component's name. If the Component is an instance of UIResource, it
+ * doesn't add the tab and instead add the component directly to the
* JTabbedPane.
*
* @param component The associated component.
*
- * @return The Component that was added.
+ * @return The Component that was added.
*/
public Component add(Component component)
{
@@ -954,17 +961,16 @@
}
/**
- * This method adds a tab to the JTabbedPane.
- * If the Component is an instance of UIResource, it doesn't
- * add the tab and instead add the component directly to the
- * JTabbedPane.
+ * This method adds a tab to the JTabbedPane. If the Component is an
+ * instance of UIResource, it doesn't add the tab and instead add the
+ * component directly to the JTabbedPane.
*
* @param title The title of the tab.
* @param component The associated component.
*
* @return The Component that was added.
*/
- public Component add(String title, Component component)
+ public Component add(String title, Component component)
{
if (component instanceof UIResource)
super.add(component);
@@ -974,10 +980,9 @@
}
/**
- * This method adds a tab to the JTabbedPane.
- * If the Component is an instance of UIResource, it doesn't
- * add the tab and instead add the component directly to the
- * JTabbedPane.
+ * This method adds a tab to the JTabbedPane. If the Component is an
+ * instance of UIResource, it doesn't add the tab and instead add the
+ * component directly to the JTabbedPane.
*
* @param component The associated component.
* @param index The index to insert the tab at.
@@ -994,12 +999,11 @@
}
/**
- * This method adds a tab to the JTabbedPane.
- * If the Component is an instance of UIResource, it doesn't
- * add the tab and instead add the component directly to the
- * JTabbedPane. If the constraints object is an icon, it
- * will be used as the tab's icon. If the constraints object
- * is a string, we will use it as the title.
+ * This method adds a tab to the JTabbedPane. If the Component is an
+ * instance of UIResource, it doesn't add the tab and instead add the
+ * component directly to the JTabbedPane. If the constraints object is an
+ * icon, it will be used as the tab's icon. If the constraints object is a
+ * string, we will use it as the title.
*
* @param component The associated component.
* @param constraints The constraints object.
@@ -1010,12 +1014,11 @@
}
/**
- * This method adds a tab to the JTabbedPane.
- * If the Component is an instance of UIResource, it doesn't
- * add the tab and instead add the component directly to the
- * JTabbedPane. If the constraints object is an icon, it
- * will be used as the tab's icon. If the constraints object
- * is a string, we will use it as the title.
+ * This method adds a tab to the JTabbedPane. If the Component is an
+ * instance of UIResource, it doesn't add the tab and instead add the
+ * component directly to the JTabbedPane. If the constraints object is an
+ * icon, it will be used as the tab's icon. If the constraints object is a
+ * string, we will use it as the title.
*
* @param component The associated component.
* @param constraints The constraints object.
@@ -1037,27 +1040,25 @@
}
/**
- * The tab and it's associated component are removed. After
- * the component has been removed from the JTabbedPane, it's
- * set visible to ensure that it can be seen.
+ * The tab and it's associated component are removed. After the component
+ * has been removed from the JTabbedPane, it's set visible to ensure that
+ * it can be seen.
*
* @param index The index of the tab to remove.
- *
- * @throws IndexOutOfBoundsException If the index is not in range.
*/
public void removeTabAt(int index)
{
checkIndex(index, 0, tabs.size());
Component c = getComponentAt(index);
- super.remove(c);
+ super.remove(index);
c.show();
tabs.remove(index);
}
/**
- * This method removes the component from the JTabbedPane. After
- * the component has been removed from the JTabbedPane, it's
- * set visible to ensure that it can be seen.
+ * This method removes the component from the JTabbedPane. After the
+ * component has been removed from the JTabbedPane, it's set visible to
+ * ensure that it can be seen.
*
* @param component The Component to remove.
*/
@@ -1071,8 +1072,8 @@
}
/**
- * This method removes the tab and component from the JTabbedPane.
- * It simply calls removeTabAt(int index).
+ * This method removes the tab and component from the JTabbedPane. It simply
+ * calls removeTabAt(int index).
*
* @param index The index of the tab to remove.
*/
@@ -1082,8 +1083,8 @@
}
/**
- * This method removes all tabs and associated components
- * from the JTabbedPane.
+ * This method removes all tabs and associated components from the
+ * JTabbedPane.
*/
public void removeAll()
{
@@ -1102,8 +1103,7 @@
}
/**
- * This method returns the number of runs used
- * to paint the JTabbedPane.
+ * This method returns the number of runs used to paint the JTabbedPane.
*
* @return The number of runs.
*/
@@ -1204,8 +1204,8 @@
}
/**
- * This method returns whether this tab is enabled.
- * Disabled tabs cannot be selected.
+ * This method returns whether this tab is enabled. Disabled tabs cannot be
+ * selected.
*
* @param index The index of the tab.
*
@@ -1244,8 +1244,7 @@
}
/**
- * This method returns the bounds of the tab given
- * the index.
+ * This method returns the bounds of the tab given the index.
*
* @param index The index of the tab.
*
@@ -1441,9 +1440,9 @@
}
/**
- * This method returns a tab index given an (x,y) location. The origin
- * of the (x,y) pair will be the JTabbedPane's top left position. The
- * tab returned will be the one that contains the point. This method is
+ * This method returns a tab index given an (x,y) location. The origin of
+ * the (x,y) pair will be the JTabbedPane's top left position. The tab
+ * returned will be the one that contains the point. This method is
* delegated to the UI.
*
* @param x The x coordinate of the point.
@@ -1470,8 +1469,8 @@
}
/**
- * This method returns a string representation of this JTabbedPane. It
- * is mainly used for debugging purposes.
+ * This method returns a string representation of this JTabbedPane. It is
+ * mainly used for debugging purposes.
*
* @return A string representation of this JTabbedPane.
*/
Index: javax/swing/SpinnerNumberModel.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/SpinnerNumberModel.java,v
retrieving revision 1.1
diff -u -r1.1 SpinnerNumberModel.java
--- javax/swing/SpinnerNumberModel.java 14 Aug 2004 22:17:49 -0000 1.1
+++ javax/swing/SpinnerNumberModel.java 4 Sep 2004 20:11:27 -0000
@@ -39,14 +39,22 @@
/**
* SpinnerNumberModel
- * @author Ka-Hing Cheung
- * @version 1.0
+ *
+ * @author Ka-Hing Cheung
+ * @version 1.0
*/
public class SpinnerNumberModel extends AbstractSpinnerModel
{
+ /** DOCUMENT ME! */
private Number value;
+
+ /** DOCUMENT ME! */
private Comparable minimum;
+
+ /** DOCUMENT ME! */
private Comparable maximum;
+
+ /** DOCUMENT ME! */
private Number stepSize;
/**
@@ -65,8 +73,6 @@
* @param minimum the minimum value
* @param maximum the maximum value
* @param stepSize the step size
- * @throws IllegalArgumentException if minimum <= value <= maximum
does not
- * hold
*/
public SpinnerNumberModel(double value, double minimum, double maximum,
double stepSize)
@@ -82,8 +88,6 @@
* @param minimum the minimum value
* @param maximum the maximum value
* @param stepSize the step size
- * @throws IllegalArgumentException if minimum <= value <= maximum
does not
- * hold
*/
public SpinnerNumberModel(int value, int minimum, int maximum, int stepSize)
{
@@ -99,48 +103,47 @@
* @param minimum the minimum value, if null there's no minimum
* @param maximum the maximum value, if null there's no maximum
* @param stepSize the step size
- * @throws IllegalArgumentException if minimum <= value <= maximum
does not
- * hold
+ *
+ * @throws IllegalArgumentException if minimum <= value <= maximum
+ * does not hold
*/
- public SpinnerNumberModel(Number value, Comparable minimum,
+ public SpinnerNumberModel(Number value, Comparable minimum,
Comparable maximum, Number stepSize)
{
- if(stepSize == null)
+ if (stepSize == null)
throw new IllegalArgumentException("stepSize may not be null");
- if(value == null)
+ if (value == null)
throw new IllegalArgumentException("value may not be null");
- if(minimum != null)
+ if (minimum != null)
{
- if(minimum.compareTo(value) > 0)
- throw new IllegalArgumentException("minimum is not <= value");
+ if (minimum.compareTo(value) > 0)
+ throw new IllegalArgumentException("minimum is not <= value");
}
else
- {
- minimum = new Comparable()
+ minimum = new Comparable()
{
public int compareTo(Object obj)
{
return -1;
}
};
- }
-
- if(maximum != null)
+
+
+ if (maximum != null)
{
- if(maximum.compareTo(value) < 0)
+ if (maximum.compareTo(value) < 0)
throw new IllegalArgumentException("maximum is not >= value");
}
else
- {
- maximum = new Comparable()
+ maximum = new Comparable()
{
public int compareTo(Object obj)
{
return 1;
}
};
- }
-
+
+
this.value = value;
this.stepSize = stepSize;
this.minimum = minimum;
@@ -151,12 +154,13 @@
* Sets the new value and fire a change event
*
* @param value the new value
- * @throws IllegalArgumentException if minimum <= value <= maximum
does not
- * hold
+ *
+ * @throws IllegalArgumentException if minimum <= value <= maximum
+ * does not hold
*/
public void setValue(Object value)
{
- if(! (value instanceof Number))
+ if (! (value instanceof Number))
throw new IllegalArgumentException("value must be a Number");
this.value = (Number) value;
@@ -183,37 +187,25 @@
{
Number num;
- if(value instanceof Double)
- {
- num = new Double(value.doubleValue() + stepSize.doubleValue());
- }
- else if(value instanceof Float)
- {
- num = new Double(value.floatValue() + stepSize.floatValue());
- }
- else if(value instanceof Long)
- {
- num = new Long(value.longValue() + stepSize.longValue());
- }
- else if(value instanceof Integer)
- {
- num = new Integer(value.intValue() + stepSize.intValue());
- }
- else if(value instanceof Short)
- {
- num = new Short((short) (value.shortValue() + stepSize.shortValue()));
- }
+ if (value instanceof Double)
+ num = new Double(value.doubleValue() + stepSize.doubleValue());
+ else if (value instanceof Float)
+ num = new Double(value.floatValue() + stepSize.floatValue());
+ else if (value instanceof Long)
+ num = new Long(value.longValue() + stepSize.longValue());
+ else if (value instanceof Integer)
+ num = new Integer(value.intValue() + stepSize.intValue());
+ else if (value instanceof Short)
+ num = new Short((short) (value.shortValue() + stepSize.shortValue()));
else
- {
- num = new Byte((byte) (value.byteValue() + stepSize.byteValue()));
- }
+ num = new Byte((byte) (value.byteValue() + stepSize.byteValue()));
return maximum.compareTo(num) >= 0 ? num : null;
}
/**
- * Gets the previous value without changing the current value, or null if the
- * current value is minimum.
+ * Gets the previous value without changing the current value, or null if
+ * the current value is minimum.
*
* @return the previous value
*/
@@ -221,34 +213,27 @@
{
Number num;
- if(value instanceof Double)
- {
- num = new Double(value.doubleValue() - stepSize.doubleValue());
- }
- else if(value instanceof Float)
- {
- num = new Double(value.floatValue() - stepSize.floatValue());
- }
- else if(value instanceof Long)
- {
- num = new Long(value.longValue() - stepSize.longValue());
- }
- else if(value instanceof Integer)
- {
- num = new Integer(value.intValue() - stepSize.intValue());
- }
- else if(value instanceof Short)
- {
- num = new Short((short) (value.shortValue() - stepSize.shortValue()));
- }
+ if (value instanceof Double)
+ num = new Double(value.doubleValue() - stepSize.doubleValue());
+ else if (value instanceof Float)
+ num = new Double(value.floatValue() - stepSize.floatValue());
+ else if (value instanceof Long)
+ num = new Long(value.longValue() - stepSize.longValue());
+ else if (value instanceof Integer)
+ num = new Integer(value.intValue() - stepSize.intValue());
+ else if (value instanceof Short)
+ num = new Short((short) (value.shortValue() - stepSize.shortValue()));
else
- {
- num = new Byte((byte) (value.byteValue() - stepSize.byteValue()));
- }
+ num = new Byte((byte) (value.byteValue() - stepSize.byteValue()));
- return maximum.compareTo(num) >= 0 ? num : null;
+ return minimum.compareTo(num) <= 0 ? num : null;
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public Number getNumber()
{
return value;
Index: javax/swing/Timer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/Timer.java,v
retrieving revision 1.10
diff -u -r1.10 Timer.java
--- javax/swing/Timer.java 31 Jul 2004 15:24:02 -0000 1.10
+++ javax/swing/Timer.java 4 Sep 2004 20:11:27 -0000
@@ -172,7 +172,7 @@
}
catch (Exception e)
{
- System.out.println("swing.Timer::" + e);
+// System.out.println("swing.Timer::" + e);
}
}
}
@@ -374,7 +374,7 @@
public void start()
{
if (isRunning())
- return;
+ return;
waker = new Waker();
waker.start();
}
Index: javax/swing/ToolTipManager.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/ToolTipManager.java,v
retrieving revision 1.5
diff -u -r1.5 ToolTipManager.java
--- javax/swing/ToolTipManager.java 31 Jul 2004 15:24:02 -0000 1.5
+++ javax/swing/ToolTipManager.java 4 Sep 2004 20:11:27 -0000
@@ -460,6 +460,8 @@
public void mouseMoved(MouseEvent event)
{
currentPoint = event.getPoint();
+ if (currentTip != null)
+ currentTip.setTipText(((JComponent)
currentComponent).getToolTipText(event));
if (enterTimer.isRunning())
enterTimer.restart();
}
Index: javax/swing/colorchooser/AbstractColorChooserPanel.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/colorchooser/AbstractColorChooserPanel.java,v
retrieving revision 1.3
diff -u -r1.3 AbstractColorChooserPanel.java
--- javax/swing/colorchooser/AbstractColorChooserPanel.java 5 Feb 2004
18:50:30 -0000 1.3
+++ javax/swing/colorchooser/AbstractColorChooserPanel.java 4 Sep 2004
20:11:27 -0000
@@ -35,7 +35,6 @@
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package javax.swing.colorchooser;
import java.awt.Color;
@@ -44,92 +43,119 @@
import javax.swing.JColorChooser;
import javax.swing.JPanel;
+
/**
* AbstractColorChooserPanel
- * @author Andrew Selkirk
- * @version 1.0
+ *
+ * @author Andrew Selkirk
+ * @version 1.0
*/
public abstract class AbstractColorChooserPanel extends JPanel
{
+ /** DOCUMENT ME! */
private static final long serialVersionUID = -977469671210173863L;
- /**
- * chooser
- */
- private JColorChooser chooser;
-
- /**
- * Constructor AbstractColorChooserPanel
- */
- public AbstractColorChooserPanel() {
- // TODO
- } // AbstractColorChooserPanel()
-
- /**
- * getDisplayName
- * @returns String
- */
- public abstract String getDisplayName();
-
- /**
- * updateChooser
- */
- public abstract void updateChooser();
-
- /**
- * buildChooser
- */
- protected abstract void buildChooser();
-
- /**
- * getSmallDisplayIcon
- * @returns Icon
- */
- public abstract Icon getSmallDisplayIcon();
-
- /**
- * getLargeDisplayIcon
- * @returns Icon
- */
- public abstract Icon getLargeDisplayIcon();
-
- /**
- * installChooserPanel
- * @param chooser TODO
- */
- public void installChooserPanel(JColorChooser chooser) {
- // TODO
- } // installChooserPanel()
-
- /**
- * uninstallChooserPanel
- * @param chooser TODO
- */
- public void uninstallChooserPanel(JColorChooser chooser) {
- // TODO
- } // uninstallChooserPanel()
-
- /**
- * getColorSelectionModel
- * @returns ColorSelectionModel
- */
- public ColorSelectionModel getColorSelectionModel() {
- return null; // TODO
- } // getColorSelectionModel()
-
- /**
- * getColorFromModel
- * @returns Color
- */
- protected Color getColorFromModel() {
- return null; // TODO
- } // getColorFromModel()
-
- /**
- * paint
- * @param graphics TODO
- */
- public void paint(Graphics graphics) {
- // TODO
- } // paint()
+ /** The chooser associated with this panel. */
+ private JColorChooser chooser;
+
+ /**
+ * This is the constructor for the AbstractColorChooserPanel.
+ */
+ public AbstractColorChooserPanel()
+ {
+ } // AbstractColorChooserPanel()
+
+ /**
+ * This method returns the name displayed in the tab for this chooser panel.
+ *
+ * @return The name displayed in the JTabbedPane's tabs.
+ */
+ public abstract String getDisplayName();
+
+ /**
+ * This method updates the chooser panel when the JColorChooser's color has
+ * changed.
+ */
+ public abstract void updateChooser();
+
+ /**
+ * This method constructs and does any initialization necessary for the
+ * chooser panel.
+ */
+ protected abstract void buildChooser();
+
+ /**
+ * This method sets the small icon used in the JTabbedPane for this chooser
+ * panel.
+ *
+ * @return The small icon used in the JTabbedPane.
+ */
+ public abstract Icon getSmallDisplayIcon();
+
+ /**
+ * This method sets the large icon useed in the jTabbedPane for this chooser
+ * panel.
+ *
+ * @return The large icon.
+ */
+ public abstract Icon getLargeDisplayIcon();
+
+ /**
+ * This method installs the chooser panel for the given JColorChooser.
+ *
+ * @param chooser The JColorChooser that will have this panel installed.
+ */
+ public void installChooserPanel(JColorChooser chooser)
+ {
+ this.chooser = chooser;
+ buildChooser();
+ } // installChooserPanel()
+
+ /**
+ * This method removes the chooser panel from the given JColorChooser and
+ * does any necessary clean up for the chooser panel.
+ *
+ * @param chooser The JColorChooser that is having this panel removed.
+ */
+ public void uninstallChooserPanel(JColorChooser chooser)
+ {
+ this.chooser = null;
+ } // uninstallChooserPanel()
+
+ /**
+ * This method returns the ColorSelectionModel for the JColorChooser
+ * associated with this chooser panel.
+ *
+ * @return The ColorSelectionModel for the JColorChooser associated with
+ * this chooser panel.
+ */
+ public ColorSelectionModel getColorSelectionModel()
+ {
+ if (chooser != null)
+ return chooser.getSelectionModel();
+ return null;
+ } // getColorSelectionModel()
+
+ /**
+ * This method returns the current color stored in the model for this
+ * chooser panel.
+ *
+ * @return The current color.
+ */
+ protected Color getColorFromModel()
+ {
+ if (chooser != null)
+ return chooser.getColor();
+ return null;
+ } // getColorFromModel()
+
+ /**
+ * This method paints the chooser panel.
+ *
+ * @param graphics The Graphics object to paint with.
+ */
+ public void paint(Graphics graphics)
+ {
+ super.paint(graphics);
+ } // paint()
} // AbstractColorChooserPanel
Index: javax/swing/colorchooser/ColorChooserComponentFactory.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/colorchooser/ColorChooserComponentFactory.java,v
retrieving revision 1.2
diff -u -r1.2 ColorChooserComponentFactory.java
--- javax/swing/colorchooser/ColorChooserComponentFactory.java 8 Jun 2003
12:14:56 -0000 1.2
+++ javax/swing/colorchooser/ColorChooserComponentFactory.java 4 Sep 2004
20:11:27 -0000
@@ -35,49 +35,51 @@
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package javax.swing.colorchooser;
import javax.swing.JComponent;
+
/**
* ColorChooserComponentFactory
- * @author Andrew Selkirk
- * @version 1.0
+ *
+ * @author Andrew Selkirk
+ * @version 1.0
*/
-public class ColorChooserComponentFactory {
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * Constructor ColorChooserComponentFactory
- */
- private ColorChooserComponentFactory() {
- // TODO
- } // ColorChooserComponentFactory()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * getDefaultChooserPanels
- * @returns AbstractColorChooserPanel[]
- */
- public static AbstractColorChooserPanel[] getDefaultChooserPanels() {
- return null; // TODO
- } // getDefaultChooserPanels()
-
- /**
- * getPreviewPanel
- * @returns JComponent
- */
- public static JComponent getPreviewPanel() {
- return null; // TODO
- } // getPreviewPanel()
-
-
+public class ColorChooserComponentFactory
+{
+ /**
+ * Constructor ColorChooserComponentFactory
+ */
+ private ColorChooserComponentFactory()
+ {
+ } // ColorChooserComponentFactory()
+
+ /**
+ * This method returns the three default chooser panels to be used in
+ * JColorChooser.
+ *
+ * @return The default chooser panels.
+ */
+ public static AbstractColorChooserPanel[] getDefaultChooserPanels()
+ {
+ AbstractColorChooserPanel[] values =
+ {
+ new DefaultSwatchChooserPanel(),
+ new DefaultHSBChooserPanel(),
+ new DefaultRGBChooserPanel()
+ };
+ return values;
+ }
+
+ /**
+ * This method returns the default preview panel to be used with
+ * JColorChoosers.
+ *
+ * @return The default preview panel.
+ */
+ public static JComponent getPreviewPanel()
+ {
+ return new DefaultPreviewPanel();
+ } // getPreviewPanel()
} // ColorChooserComponentFactory
Index: javax/swing/colorchooser/DefaultColorSelectionModel.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/colorchooser/DefaultColorSelectionModel.java,v
retrieving revision 1.4
diff -u -r1.4 DefaultColorSelectionModel.java
--- javax/swing/colorchooser/DefaultColorSelectionModel.java 2 Jul 2003
05:21:52 -0000 1.4
+++ javax/swing/colorchooser/DefaultColorSelectionModel.java 4 Sep 2004
20:11:27 -0000
@@ -35,7 +35,6 @@
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package javax.swing.colorchooser;
import java.awt.Color;
@@ -44,43 +43,55 @@
import javax.swing.event.ChangeListener;
import javax.swing.event.EventListenerList;
+
/**
- * DefaultColorSelectionModel
- * @author Andrew Selkirk
- * @version 1.0
+ * This is the default implementation of the ColorSelectionModel interface
+ * that JColorChoosers use.
+ *
+ * @author Andrew Selkirk
+ * @version 1.0
*/
-public class DefaultColorSelectionModel
- implements ColorSelectionModel, Serializable
+public class DefaultColorSelectionModel implements ColorSelectionModel,
+ Serializable
{
+ /** DOCUMENT ME! */
private static final long serialVersionUID = -8117143602864778804L;
+ /** The currently selected color. */
private Color selectedColor;
- protected transient ChangeEvent changeEvent = new ChangeEvent (this);
- protected EventListenerList listenerList = new EventListenerList ();
+ /** The ChangeEvent fired to all ChangeListeners. */
+ protected transient ChangeEvent changeEvent = new ChangeEvent(this);
+
+ /** The list of listeners. */
+ protected EventListenerList listenerList = new EventListenerList();
/**
- * Creates a new color selection model.
+ * Creates a new color selection model with the default white color.
*/
public DefaultColorSelectionModel()
{
- this (Color.white);
+ this(Color.white);
}
/**
* Creates a new color selection model with a given selected color.
- *
- * @param color The selected color.
+ *
+ * @param color The initial color.
+ *
+ * @throws Error If the color is null.
*/
- public DefaultColorSelectionModel (Color color)
+ public DefaultColorSelectionModel(Color color)
{
super();
+ if (color == null)
+ throw new Error("ColorSelectionModel cannot be set to have null color.");
this.selectedColor = color;
}
/**
* Returns the selected color.
- *
+ *
* @return The selected color.
*/
public Color getSelectedColor()
@@ -89,31 +100,41 @@
}
/**
+ * This method sets the color.
+ *
* @param color The color to set.
+ *
+ * @throws Error If the color is set.
*/
- public void setSelectedColor (Color color)
+ public void setSelectedColor(Color color)
{
- this.selectedColor = color;
+ if (color == null)
+ throw new Error("ColorSelectionModel cannot be set to have null color.");
+ if (color != selectedColor)
+ {
+ this.selectedColor = color;
+ fireStateChanged();
+ }
}
/**
* Adds a listener to this model.
- *
+ *
* @param listener The listener to add.
*/
- public void addChangeListener (ChangeListener listener)
+ public void addChangeListener(ChangeListener listener)
{
- listenerList.add (ChangeListener.class, listener);
+ listenerList.add(ChangeListener.class, listener);
}
/**
* Removes a listener from this model.
- *
+ *
* @param listener The listener to remove.
*/
- public void removeChangeListener (ChangeListener listener)
+ public void removeChangeListener(ChangeListener listener)
{
- listenerList.remove (ChangeListener.class, listener);
+ listenerList.remove(ChangeListener.class, listener);
}
/**
@@ -123,19 +144,19 @@
*/
public ChangeListener[] getChangeListeners()
{
- return (ChangeListener[]) listenerList.getListeners (ChangeListener.class);
+ return (ChangeListener[]) listenerList.getListeners(ChangeListener.class);
}
/**
* Calls all the <code>stateChanged()</code> method of all added
- * <code>ChangeListener</code> objects with <code>changeEvent</code>
- * as argument.
+ * <code>ChangeListener</code> objects with <code>changeEvent</code> as
+ * argument.
*/
protected void fireStateChanged()
{
ChangeListener[] listeners = getChangeListeners();
for (int i = 0; i < listeners.length; i++)
- listeners [i].stateChanged (changeEvent);
+ listeners[i].stateChanged(changeEvent);
}
}
Index: javax/swing/plaf/basic/BasicArrowButton.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicArrowButton.java,v
retrieving revision 1.4
diff -u -r1.4 BasicArrowButton.java
--- javax/swing/plaf/basic/BasicArrowButton.java 31 Jul 2004 22:56:54
-0000 1.4
+++ javax/swing/plaf/basic/BasicArrowButton.java 4 Sep 2004 20:11:28
-0000
@@ -350,30 +350,30 @@
{
Polygon arrow;
double dsize = (double) size;
-
+
+ int one = (int) (dsize * 1 / 10);
int two = (int) (dsize * 2 / 10);
- int three = (int) (dsize * 3 / 10);
- int five = (int) (dsize * 5 / 10);
- int seven = (int) (dsize * 7 / 10);
+ int five = (int) (dsize * 5 / 10);
int eight = (int) (dsize * 8 / 10);
+
switch (direction)
{
case NORTH:
- arrow = new Polygon(new int[] { two, five, eight },
- new int[] { seven, three, seven }, 3);
+ arrow = new Polygon(new int[] { eight, five, one },
+ new int[] { eight, one, eight }, 3);
break;
case SOUTH:
- arrow = new Polygon(new int[] { two, five, eight },
- new int[] { three, seven, three }, 3);
+ arrow = new Polygon(new int[] { eight, five, two },
+ new int[] { two, eight, two }, 3);
break;
case EAST:
case RIGHT:
- arrow = new Polygon(new int[] { three, seven, three },
+ arrow = new Polygon(new int[] { two, eight, two },
new int[] { two, five, eight }, 3);
break;
case WEST:
case LEFT:
- arrow = new Polygon(new int[] { seven, three, seven },
+ arrow = new Polygon(new int[] { eight, two, eight },
new int[] { two, five, eight }, 3);
break;
default:
Index: javax/swing/plaf/basic/BasicSliderUI.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicSliderUI.java,v
retrieving revision 1.6
diff -u -r1.6 BasicSliderUI.java
--- javax/swing/plaf/basic/BasicSliderUI.java 31 Jul 2004 22:56:54 -0000
1.6
+++ javax/swing/plaf/basic/BasicSliderUI.java 4 Sep 2004 20:11:28 -0000
@@ -1226,6 +1226,7 @@
if (slider.getLabelTable() == null)
return 0;
+ Dimension pref;
for (Enumeration list = slider.getLabelTable().elements();
list.hasMoreElements();)
{
@@ -1233,8 +1234,9 @@
if (! (comp instanceof Component))
continue;
label = (Component) comp;
- if (label.getWidth() > widest)
- widest = label.getWidth();
+ pref = label.getPreferredSize();
+ if (pref != null && pref.width > widest)
+ widest = pref.width;
}
return widest;
}
@@ -1252,7 +1254,7 @@
if (slider.getLabelTable() == null)
return 0;
-
+ Dimension pref;
for (Enumeration list = slider.getLabelTable().elements();
list.hasMoreElements();)
{
@@ -1260,8 +1262,9 @@
if (! (comp instanceof Component))
continue;
label = (Component) comp;
- if (label.getHeight() > tallest)
- tallest = label.getHeight();
+ pref = label.getPreferredSize();
+ if (pref != null && pref.height > tallest)
+ tallest = pref.height;
}
return tallest;
}
Index: javax/swing/plaf/basic/BasicSpinnerUI.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicSpinnerUI.java,v
retrieving revision 1.1
diff -u -r1.1 BasicSpinnerUI.java
--- javax/swing/plaf/basic/BasicSpinnerUI.java 14 Aug 2004 22:17:49 -0000
1.1
+++ javax/swing/plaf/basic/BasicSpinnerUI.java 4 Sep 2004 20:11:28 -0000
@@ -44,8 +44,8 @@
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JButton;
@@ -54,20 +54,26 @@
import javax.swing.Timer;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
-import javax.swing.plaf.SpinnerUI;
import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.SpinnerUI;
+
/**
- * @since 1.4
- * @see javax.swing.JSpinner
+ * DOCUMENT ME!
+ *
* @author Ka-Hing Cheung
+ *
+ * @see javax.swing.JSpinner
+ * @since 1.4
*/
public class BasicSpinnerUI extends SpinnerUI
{
/**
- * Creates a new <code>ComponentUI</code> for the specified
+ * Creates a new <code>ComponentUI</code> for the specified
* <code>JComponent</code>
*
+ * @param c DOCUMENT ME!
+ *
* @return a ComponentUI
*/
public static ComponentUI createUI(JComponent c)
@@ -76,10 +82,11 @@
}
/**
- * Creates an editor component. Really, it just returns
+ * Creates an editor component. Really, it just returns
* <code>JSpinner.getEditor()</code>
*
* @return a JComponent as an editor
+ *
* @see javax.swing.JSpinner#getEditor
*/
protected JComponent createEditor()
@@ -88,13 +95,14 @@
}
/**
- * Creates a <code>LayoutManager</code> that layouts the sub components.
- * The subcomponents are identifies by the constraint "Next", "Previous" and
+ * Creates a <code>LayoutManager</code> that layouts the sub components. The
+ * subcomponents are identifies by the constraint "Next", "Previous" and
* "Editor"
*
* @return a LayoutManager
+ *
* @see java.awt.LayoutManager
- */
+ */
protected LayoutManager createLayout()
{
return new DefaultLayoutManager();
@@ -123,26 +131,27 @@
}
/**
- * Creates the <code>PropertyChangeListener</code> that will be attached
- * by <code>installListeners</code>. It should watch for the "editor"
+ * Creates the <code>PropertyChangeListener</code> that will be attached by
+ * <code>installListeners</code>. It should watch for the "editor"
* property, when it's changed, replace the old editor with the new one,
* probably by calling <code>replaceEditor</code>
*
* @return a PropertyChangeListener
+ *
* @see #replaceEditor
- */
+ */
protected PropertyChangeListener createPropertyChangeListener()
{
return new PropertyChangeListener()
{
- public void propertyChange(PropertyChangeEvent evt)
- {
- if("editor".equals(evt.getPropertyName()))
- {
- BasicSpinnerUI.this.replaceEditor((JComponent)evt.getOldValue(),
- (JComponent)evt.getNewValue());
- }
- }
+ public void propertyChange(PropertyChangeEvent evt)
+ {
+ // FIXME: Add check for enabled property change. Need to
+ // disable the buttons.
+ if ("editor".equals(evt.getPropertyName()))
+ BasicSpinnerUI.this.replaceEditor((JComponent) evt.getOldValue(),
+ (JComponent) evt.getNewValue());
+ }
};
}
@@ -153,7 +162,7 @@
*
* @see #javax.swing.UIManager#getLookAndFeelDefaults
* @see #createLayout
- * @see #installUI
+ * @see #installUI
*/
protected void installDefaults()
{
@@ -166,7 +175,7 @@
spinner.setBackground(defaults.getColor("Spinner.background"));
spinner.setFont(defaults.getFont("Spinner.font"));
spinner.setBorder(defaults.getBorder("Spinner.border"));
- */
+ */
spinner.setLayout(createLayout());
}
@@ -189,37 +198,38 @@
protected void installNextButtonListeners(Component c)
{
c.addMouseListener(new MouseAdapter()
- {
- public void mousePressed(MouseEvent evt)
- {
- increment();
- timer.setInitialDelay(500);
- timer.start();
- }
-
- public void mouseReleased(MouseEvent evt)
- {
- timer.stop();
- }
-
- void increment()
{
- Object next = BasicSpinnerUI.this.spinner.getNextValue();
- if(next != null)
- {
- BasicSpinnerUI.this.spinner.getModel().setValue(next);
- }
- }
-
- volatile boolean mouseDown = false;
- Timer timer = new Timer(50, new ActionListener()
- {
- public void actionPerformed(ActionEvent event)
- {
- increment();
- }
- });
- });
+ public void mousePressed(MouseEvent evt)
+ {
+ if (! spinner.isEnabled())
+ return;
+ increment();
+ timer.setInitialDelay(500);
+ timer.start();
+ }
+
+ public void mouseReleased(MouseEvent evt)
+ {
+ timer.stop();
+ }
+
+ void increment()
+ {
+ Object next = BasicSpinnerUI.this.spinner.getNextValue();
+ if (next != null)
+ BasicSpinnerUI.this.spinner.getModel().setValue(next);
+ }
+
+ volatile boolean mouseDown = false;
+ Timer timer = new Timer(50,
+ new ActionListener()
+ {
+ public void actionPerformed(ActionEvent event)
+ {
+ increment();
+ }
+ });
+ });
}
/*
@@ -228,44 +238,46 @@
protected void installPreviousButtonListeners(Component c)
{
c.addMouseListener(new MouseAdapter()
- {
- public void mousePressed(MouseEvent evt)
- {
- decrement();
- timer.setInitialDelay(500);
- timer.start();
- }
-
- public void mouseReleased(MouseEvent evt)
{
- timer.stop();
- }
-
- void decrement()
- {
- Object prev = BasicSpinnerUI.this.spinner.getPreviousValue();
- if(prev != null)
- {
- BasicSpinnerUI.this.spinner.getModel().setValue(prev);
- }
- }
-
- volatile boolean mouseDown = false;
- Timer timer = new Timer(50, new ActionListener()
- {
- public void actionPerformed(ActionEvent event)
- {
- decrement();
- }
- });
- });
+ public void mousePressed(MouseEvent evt)
+ {
+ if (! spinner.isEnabled())
+ return;
+ decrement();
+ timer.setInitialDelay(500);
+ timer.start();
+ }
+
+ public void mouseReleased(MouseEvent evt)
+ {
+ timer.stop();
+ }
+
+ void decrement()
+ {
+ Object prev = BasicSpinnerUI.this.spinner.getPreviousValue();
+ if (prev != null)
+ BasicSpinnerUI.this.spinner.getModel().setValue(prev);
+ }
+
+ volatile boolean mouseDown = false;
+ Timer timer = new Timer(50,
+ new ActionListener()
+ {
+ public void actionPerformed(ActionEvent event)
+ {
+ decrement();
+ }
+ });
+ });
}
/**
- * Install this UI to the <code>JComponent</code>, which in reality,
- * is a <code>JSpinner</code>. Calls <code>installDefaults</code>,
- * <code>installListeners</code>, and also adds the buttons and
- * editor.
+ * Install this UI to the <code>JComponent</code>, which in reality, is a
+ * <code>JSpinner</code>. Calls <code>installDefaults</code>,
+ * <code>installListeners</code>, and also adds the buttons and editor.
+ *
+ * @param c DOCUMENT ME!
*
* @see #installDefaults
* @see #installListeners
@@ -277,13 +289,13 @@
{
super.installUI(c);
- spinner = (JSpinner)c;
+ spinner = (JSpinner) c;
installDefaults();
installListeners();
- Component next = createNextButton(),
- previous = createPreviousButton();
+ Component next = createNextButton();
+ Component previous = createPreviousButton();
installNextButtonListeners(next);
installPreviousButtonListeners(previous);
@@ -320,13 +332,15 @@
*/
protected void uninstallListeners()
{
- spinner.removePropertyChangeListener(listener);
+ spinner.removePropertyChangeListener(listener);
}
/**
* Called when the current L&F is replaced with another one, should call
- * <code>uninstallDefaults</code> and <code>uninstallListeners</code> as well
- * as remove the next/previous buttons and the editor
+ * <code>uninstallDefaults</code> and <code>uninstallListeners</code> as
+ * well as remove the next/previous buttons and the editor
+ *
+ * @param c DOCUMENT ME!
*/
public void uninstallUI(JComponent c)
{
@@ -337,172 +351,222 @@
c.removeAll();
}
- /**
- * The spinner for this UI
- */
+ /** The spinner for this UI */
protected JSpinner spinner;
+
+ /** DOCUMENT ME! */
private PropertyChangeListener listener = createPropertyChangeListener();
+ /**
+ * DOCUMENT ME!
+ */
private class DefaultLayoutManager implements LayoutManager
{
+ /**
+ * DOCUMENT ME!
+ *
+ * @param parent DOCUMENT ME!
+ */
public void layoutContainer(Container parent)
{
-
- synchronized(parent.getTreeLock())
+ synchronized (parent.getTreeLock())
{
- Insets i = parent.getInsets();
- boolean l2r = parent.getComponentOrientation().isLeftToRight();
- /*
- -------------- --------------
- | | n | | n | |
- | e | - | or | - | e |
- | | p | | p | |
- -------------- --------------
- */
-
- Dimension e = minSize(editor);
- Dimension n = minSize(next);
- Dimension p = minSize(previous);
- Dimension s = spinner.getPreferredSize();
-
- int x = l2r ? i.left : i.right, y = i.top;
- int w = Math.max(p.width, n.width);
- int h = Math.max(p.height, n.height);
- h = Math.max(h, e.height / 2);
- int e_width = s.width - w;
-
- if(l2r)
- {
- setBounds(editor, x, y + (s.height - e.height) / 2, e_width,
- e.height);
- x += e_width;
-
- setBounds(next, x, y, w, h);
- y += h;
-
- setBounds(previous, x, y, w, h);
- }
- else
- {
- setBounds(next, x, y + (s.height - e.height) / 2, w, h);
- y += h;
-
- setBounds(previous, x, y, w, h);
- x += w;
- y -= h;
+ Insets i = parent.getInsets();
+ boolean l2r = parent.getComponentOrientation().isLeftToRight();
+ /*
+ -------------- --------------
+ | | n | | n | |
+ | e | - | or | - | e |
+ | | p | | p | |
+ -------------- --------------
+ */
+ Dimension e = minSize(editor);
+ Dimension n = minSize(next);
+ Dimension p = minSize(previous);
+ Dimension s = spinner.getPreferredSize();
+
+ int x = l2r ? i.left : i.right;
+ int y = i.top;
+ int w = Math.max(p.width, n.width);
+ int h = Math.max(p.height, n.height);
+ h = Math.max(h, e.height / 2);
+ int e_width = s.width - w;
+
+ if (l2r)
+ {
+ setBounds(editor, x, y + (s.height - e.height) / 2, e_width,
+ e.height);
+ x += e_width;
+
+ setBounds(next, x, y, w, h);
+ y += h;
+
+ setBounds(previous, x, y, w, h);
+ }
+ else
+ {
+ setBounds(next, x, y + (s.height - e.height) / 2, w, h);
+ y += h;
+
+ setBounds(previous, x, y, w, h);
+ x += w;
+ y -= h;
- setBounds(editor, x, y, e_width, e.height);
- }
+ setBounds(editor, x, y, e_width, e.height);
+ }
}
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param parent DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public Dimension minimumLayoutSize(Container parent)
{
Dimension d = new Dimension();
- if(editor != null)
+ if (editor != null)
{
- Dimension tmp = editor.getMinimumSize();
- d.width += tmp.width;
- d.height = tmp.height;
+ Dimension tmp = editor.getMinimumSize();
+ d.width += tmp.width;
+ d.height = tmp.height;
}
int nextWidth = 0;
int previousWidth = 0;
int otherHeight = 0;
- if(next != null)
+ if (next != null)
{
- Dimension tmp = next.getMinimumSize();
- nextWidth = tmp.width;
- otherHeight += tmp.height;
+ Dimension tmp = next.getMinimumSize();
+ nextWidth = tmp.width;
+ otherHeight += tmp.height;
}
- if(previous != null)
+ if (previous != null)
{
- Dimension tmp = previous.getMinimumSize();
- previousWidth = tmp.width;
- otherHeight += tmp.height;
+ Dimension tmp = previous.getMinimumSize();
+ previousWidth = tmp.width;
+ otherHeight += tmp.height;
}
d.height = Math.max(d.height, otherHeight);
d.width += Math.max(nextWidth, previousWidth);
-
return d;
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param parent DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
public Dimension preferredLayoutSize(Container parent)
{
Dimension d = new Dimension();
- if(editor != null)
+ if (editor != null)
{
- Dimension tmp = editor.getPreferredSize();
- d.width += Math.max(tmp.width, 40);
- d.height = tmp.height;
+ Dimension tmp = editor.getPreferredSize();
+ d.width += Math.max(tmp.width, 40);
+ d.height = tmp.height;
}
int nextWidth = 0;
int previousWidth = 0;
int otherHeight = 0;
- if(next != null)
+ if (next != null)
{
- Dimension tmp = next.getPreferredSize();
- nextWidth = tmp.width;
- otherHeight += tmp.height;
+ Dimension tmp = next.getPreferredSize();
+ nextWidth = tmp.width;
+ otherHeight += tmp.height;
}
- if(previous != null)
+ if (previous != null)
{
- Dimension tmp = previous.getPreferredSize();
- previousWidth = tmp.width;
- otherHeight += tmp.height;
+ Dimension tmp = previous.getPreferredSize();
+ previousWidth = tmp.width;
+ otherHeight += tmp.height;
}
d.height = Math.max(d.height, otherHeight);
d.width += Math.max(nextWidth, previousWidth);
-
return d;
}
- public void removeLayoutComponent(Component child)
+ /**
+ * DOCUMENT ME!
+ *
+ * @param child DOCUMENT ME!
+ */
+ public void removeLayoutComponent(Component child)
{
- if(child == editor)
- editor = null;
- else if(child == next)
- next = null;
- else if(previous == child)
- previous = null;
+ if (child == editor)
+ editor = null;
+ else if (child == next)
+ next = null;
+ else if (previous == child)
+ previous = null;
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param name DOCUMENT ME!
+ * @param child DOCUMENT ME!
+ */
public void addLayoutComponent(String name, Component child)
{
- if("Editor".equals(name))
- editor = child;
- else if("Next".equals(name))
- next = child;
- else if("Previous".equals(name))
- previous = child;
+ if ("Editor".equals(name))
+ editor = child;
+ else if ("Next".equals(name))
+ next = child;
+ else if ("Previous".equals(name))
+ previous = child;
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param c DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
private Dimension minSize(Component c)
{
- if(c == null)
- return new Dimension();
+ if (c == null)
+ return new Dimension();
else
- return c.getMinimumSize();
+ return c.getMinimumSize();
}
+ /**
+ * DOCUMENT ME!
+ *
+ * @param c DOCUMENT ME!
+ * @param x DOCUMENT ME!
+ * @param y DOCUMENT ME!
+ * @param w DOCUMENT ME!
+ * @param h DOCUMENT ME!
+ */
private void setBounds(Component c, int x, int y, int w, int h)
{
- if(c != null)
- c.setBounds(x, y, w, h);
+ if (c != null)
+ c.setBounds(x, y, w, h);
}
+ /** DOCUMENT ME! */
private Component editor;
+
+ /** DOCUMENT ME! */
private Component next;
+
+ /** DOCUMENT ME! */
private Component previous;
}
-
}
signature.asc
Description: This is a digitally signed message part
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] FYI: Add JColorChooser support from gcj gui branch,
Mark Wielaard <=