This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[gui][PATCH] Implementation of JColorChooser
- From: Kim Ho <kho at redhat dot com>
- To: java-patches <java-patches at gcc dot gnu dot org>
- Date: Wed, 25 Aug 2004 17:35:40 -0400
- Subject: [gui][PATCH] Implementation of JColorChooser
Hi,
This patch implements JColorChooser and fixes some other stuff.
Cheers,
Kim
2004-08-25 Kim Ho <kho@redhat.com>
* Makefile.am: New files.
* Makefile.in: Regenerate.
* gcj/Makefile.in: Regenerate.
* include/Makefile.in: Regenerate.
* 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.
* testsuite/Makefile.in: Regenerate.
? javax/swing/plaf/basic/.BasicSliderUI.java.swp
Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.am,v
retrieving revision 1.361.2.41
diff -u -r1.361.2.41 Makefile.am
--- Makefile.am 25 Aug 2004 17:52:06 -0000 1.361.2.41
+++ Makefile.am 25 Aug 2004 21:35:28 -0000
@@ -1304,6 +1304,7 @@
javax/swing/plaf/basic/BasicButtonListener.java \
javax/swing/plaf/basic/BasicButtonUI.java \
javax/swing/plaf/basic/BasicCheckBoxUI.java \
+javax/swing/plaf/basic/BasicColorChooserUI.java \
javax/swing/plaf/basic/BasicComboBoxUI.java \
javax/swing/plaf/basic/BasicComboBoxEditor.java \
javax/swing/plaf/basic/BasicComboBoxRenderer.java \
@@ -1400,6 +1401,10 @@
javax/swing/colorchooser/ColorChooserComponentFactory.java \
javax/swing/colorchooser/ColorSelectionModel.java \
javax/swing/colorchooser/DefaultColorSelectionModel.java \
+javax/swing/colorchooser/DefaultPreviewPanel.java \
+javax/swing/colorchooser/DefaultSwatchChooserPanel.java \
+javax/swing/colorchooser/DefaultHSBChooserPanel.java \
+javax/swing/colorchooser/DefaultRGBChooserPanel.java \
javax/swing/filechooser/FileFilter.java \
javax/swing/filechooser/FileSystemView.java \
javax/swing/filechooser/FileView.java \
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.in,v
retrieving revision 1.385.2.41
diff -u -r1.385.2.41 Makefile.in
--- Makefile.in 25 Aug 2004 17:52:06 -0000 1.385.2.41
+++ Makefile.in 25 Aug 2004 21:35:31 -0000
@@ -982,6 +982,7 @@
javax/swing/plaf/basic/BasicButtonListener.java \
javax/swing/plaf/basic/BasicButtonUI.java \
javax/swing/plaf/basic/BasicCheckBoxUI.java \
+javax/swing/plaf/basic/BasicColorChooserUI.java \
javax/swing/plaf/basic/BasicComboBoxUI.java \
javax/swing/plaf/basic/BasicComboBoxEditor.java \
javax/swing/plaf/basic/BasicComboBoxRenderer.java \
@@ -1078,6 +1079,10 @@
javax/swing/colorchooser/ColorChooserComponentFactory.java \
javax/swing/colorchooser/ColorSelectionModel.java \
javax/swing/colorchooser/DefaultColorSelectionModel.java \
+javax/swing/colorchooser/DefaultPreviewPanel.java \
+javax/swing/colorchooser/DefaultSwatchChooserPanel.java \
+javax/swing/colorchooser/DefaultHSBChooserPanel.java \
+javax/swing/colorchooser/DefaultRGBChooserPanel.java \
javax/swing/filechooser/FileFilter.java \
javax/swing/filechooser/FileSystemView.java \
javax/swing/filechooser/FileView.java \
@@ -3139,6 +3144,7 @@
javax/swing/plaf/basic/BasicButtonListener.lo \
javax/swing/plaf/basic/BasicButtonUI.lo \
javax/swing/plaf/basic/BasicCheckBoxUI.lo \
+javax/swing/plaf/basic/BasicColorChooserUI.lo \
javax/swing/plaf/basic/BasicComboBoxUI.lo \
javax/swing/plaf/basic/BasicComboBoxEditor.lo \
javax/swing/plaf/basic/BasicComboBoxRenderer.lo \
@@ -3218,6 +3224,10 @@
javax/swing/colorchooser/ColorChooserComponentFactory.lo \
javax/swing/colorchooser/ColorSelectionModel.lo \
javax/swing/colorchooser/DefaultColorSelectionModel.lo \
+javax/swing/colorchooser/DefaultPreviewPanel.lo \
+javax/swing/colorchooser/DefaultSwatchChooserPanel.lo \
+javax/swing/colorchooser/DefaultHSBChooserPanel.lo \
+javax/swing/colorchooser/DefaultRGBChooserPanel.lo \
javax/swing/filechooser/FileFilter.lo \
javax/swing/filechooser/FileSystemView.lo \
javax/swing/filechooser/FileView.lo \
@@ -5254,6 +5264,10 @@
.deps/javax/swing/colorchooser/ColorChooserComponentFactory.P \
.deps/javax/swing/colorchooser/ColorSelectionModel.P \
.deps/javax/swing/colorchooser/DefaultColorSelectionModel.P \
+.deps/javax/swing/colorchooser/DefaultHSBChooserPanel.P \
+.deps/javax/swing/colorchooser/DefaultPreviewPanel.P \
+.deps/javax/swing/colorchooser/DefaultRGBChooserPanel.P \
+.deps/javax/swing/colorchooser/DefaultSwatchChooserPanel.P \
.deps/javax/swing/event/AncestorEvent.P \
.deps/javax/swing/event/AncestorListener.P \
.deps/javax/swing/event/CaretEvent.P \
@@ -5338,6 +5352,7 @@
.deps/javax/swing/plaf/basic/BasicButtonUI.P \
.deps/javax/swing/plaf/basic/BasicCheckBoxMenuItemUI.P \
.deps/javax/swing/plaf/basic/BasicCheckBoxUI.P \
+.deps/javax/swing/plaf/basic/BasicColorChooserUI.P \
.deps/javax/swing/plaf/basic/BasicComboBoxEditor.P \
.deps/javax/swing/plaf/basic/BasicComboBoxRenderer.P \
.deps/javax/swing/plaf/basic/BasicComboBoxUI.P \
Index: gcj/Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gcj/Makefile.in,v
retrieving revision 1.43.8.3
diff -u -r1.43.8.3 Makefile.in
--- gcj/Makefile.in 29 Jul 2004 16:02:25 -0000 1.43.8.3
+++ gcj/Makefile.in 25 Aug 2004 21:35:31 -0000
@@ -172,7 +172,7 @@
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
-TAR = gtar
+TAR = tar
GZIP_ENV = --best
all: all-redirect
.SUFFIXES:
Index: include/Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/Makefile.in,v
retrieving revision 1.44.8.3
diff -u -r1.44.8.3 Makefile.in
--- include/Makefile.in 29 Jul 2004 16:02:25 -0000 1.44.8.3
+++ include/Makefile.in 25 Aug 2004 21:35:32 -0000
@@ -168,7 +168,7 @@
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
-TAR = gtar
+TAR = tar
GZIP_ENV = --best
all: all-redirect
.SUFFIXES:
Index: java/awt/Color.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Color.java,v
retrieving revision 1.10.14.1
diff -u -r1.10.14.1 Color.java
--- java/awt/Color.java 24 Jun 2004 05:30:14 -0000 1.10.14.1
+++ java/awt/Color.java 25 Aug 2004 21:35:33 -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: /cvs/gcc/gcc/libjava/javax/swing/ButtonGroup.java,v
retrieving revision 1.4.2.2
diff -u -r1.4.2.2 ButtonGroup.java
--- javax/swing/ButtonGroup.java 10 Jun 2004 09:58:45 -0000 1.4.2.2
+++ javax/swing/ButtonGroup.java 25 Aug 2004 21:35:34 -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: /cvs/gcc/gcc/libjava/javax/swing/DefaultButtonModel.java,v
retrieving revision 1.5.2.3
diff -u -r1.5.2.3 DefaultButtonModel.java
--- javax/swing/DefaultButtonModel.java 10 Jun 2004 06:29:49 -0000 1.5.2.3
+++ javax/swing/DefaultButtonModel.java 25 Aug 2004 21:35:34 -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 (graydon@redhat.com)
+ * @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 {@link java.awt.event.KeyEvent} VK_*) used to
- press this button via a keyboard interface. */
+
+ /**
+ * The key code (one of {@link 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 {@link listenerList} that an
- * ActionEvent has occurred. This happens in response to the any change
- * to the {@link 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 {@link 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 {@link 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 {@link 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 {@link ActionEvent} fired
- * from the model.
+ * Set the value of the model's "actionCommand" property. This property is
+ * used as the "command" property of the {@link 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 {@link 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 {@link 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: /cvs/gcc/gcc/libjava/javax/swing/JColorChooser.java,v
retrieving revision 1.2.18.2
diff -u -r1.2.18.2 JColorChooser.java
--- javax/swing/JColorChooser.java 8 Jun 2004 09:28:42 -0000 1.2.18.2
+++ javax/swing/JColorChooser.java 25 Aug 2004 21:35:34 -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.
+ */
+ 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.
+ */
+ 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.
+ */
+ 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: /cvs/gcc/gcc/libjava/javax/swing/JLabel.java,v
retrieving revision 1.4.2.7
diff -u -r1.4.2.7 JLabel.java
--- javax/swing/JLabel.java 11 Aug 2004 13:57:34 -0000 1.4.2.7
+++ javax/swing/JLabel.java 25 Aug 2004 21:35:35 -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)
{
@@ -411,19 +412,19 @@
* length.
*/
public void setDisplayedMnemonicIndex(int newIndex)
- throws IllegalArgumentException
+ throws IllegalArgumentException
{
if (newIndex < -1 || (text != null && newIndex >= text.length()))
throw new IllegalArgumentException();
-
+
if (text == null || text.charAt(newIndex) != displayedMnemonic)
newIndex = -1;
-
+
if (newIndex != displayedMnemonicIndex)
{
- firePropertyChange(DISPLAYED_MNEMONIC_INDEX_CHANGED_PROPERTY,
- displayedMnemonicIndex, newIndex);
- displayedMnemonicIndex = newIndex;
+ firePropertyChange(DISPLAYED_MNEMONIC_INDEX_CHANGED_PROPERTY,
+ displayedMnemonicIndex, newIndex);
+ displayedMnemonicIndex = newIndex;
}
}
@@ -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: /cvs/gcc/gcc/libjava/javax/swing/Attic/JSpinner.java,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 JSpinner.java
--- javax/swing/JSpinner.java 14 Aug 2004 22:27:53 -0000 1.1.2.2
+++ javax/swing/JSpinner.java 25 Aug 2004 21:35:35 -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: /cvs/gcc/gcc/libjava/javax/swing/JTabbedPane.java,v
retrieving revision 1.3.2.7
diff -u -r1.3.2.7 JTabbedPane.java
--- javax/swing/JTabbedPane.java 12 Jul 2004 19:52:46 -0000 1.3.2.7
+++ javax/swing/JTabbedPane.java 25 Aug 2004 21:35:35 -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: /cvs/gcc/gcc/libjava/javax/swing/Attic/SpinnerNumberModel.java,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 SpinnerNumberModel.java
--- javax/swing/SpinnerNumberModel.java 11 Aug 2004 13:19:05 -0000 1.1.2.1
+++ javax/swing/SpinnerNumberModel.java 25 Aug 2004 21:35:35 -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: /cvs/gcc/gcc/libjava/javax/swing/Timer.java,v
retrieving revision 1.3.18.9
diff -u -r1.3.18.9 Timer.java
--- javax/swing/Timer.java 17 Aug 2004 23:26:10 -0000 1.3.18.9
+++ javax/swing/Timer.java 25 Aug 2004 21:35:36 -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: /cvs/gcc/gcc/libjava/javax/swing/ToolTipManager.java,v
retrieving revision 1.2.8.3
diff -u -r1.2.8.3 ToolTipManager.java
--- javax/swing/ToolTipManager.java 29 Jul 2004 16:02:27 -0000 1.2.8.3
+++ javax/swing/ToolTipManager.java 25 Aug 2004 21:35:36 -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: /cvs/gcc/gcc/libjava/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:48:53 -0000 1.3
+++ javax/swing/colorchooser/AbstractColorChooserPanel.java 25 Aug 2004 21:35:36 -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: /cvs/gcc/gcc/libjava/javax/swing/colorchooser/ColorChooserComponentFactory.java,v
retrieving revision 1.2
diff -u -r1.2 ColorChooserComponentFactory.java
--- javax/swing/colorchooser/ColorChooserComponentFactory.java 11 Jun 2003 13:20:40 -0000 1.2
+++ javax/swing/colorchooser/ColorChooserComponentFactory.java 25 Aug 2004 21:35:36 -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: /cvs/gcc/gcc/libjava/javax/swing/colorchooser/DefaultColorSelectionModel.java,v
retrieving revision 1.4
diff -u -r1.4 DefaultColorSelectionModel.java
--- javax/swing/colorchooser/DefaultColorSelectionModel.java 14 Jul 2003 05:33:30 -0000 1.4
+++ javax/swing/colorchooser/DefaultColorSelectionModel.java 25 Aug 2004 21:35:36 -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/colorchooser/DefaultHSBChooserPanel.java
===================================================================
RCS file: javax/swing/colorchooser/DefaultHSBChooserPanel.java
diff -N javax/swing/colorchooser/DefaultHSBChooserPanel.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ javax/swing/colorchooser/DefaultHSBChooserPanel.java 25 Aug 2004 21:35:36 -0000
@@ -0,0 +1,860 @@
+/* DefaultHSBChooserPanel.java --
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+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.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.ComponentOrientation;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.GridLayout;
+import java.awt.Image;
+import java.awt.LayoutManager;
+import java.awt.Point;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionListener;
+import java.awt.image.MemoryImageSource;
+import javax.swing.AbstractButton;
+import javax.swing.ButtonGroup;
+import javax.swing.Icon;
+import javax.swing.JColorChooser;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JRadioButton;
+import javax.swing.JSlider;
+import javax.swing.JSpinner;
+import javax.swing.SpinnerNumberModel;
+import javax.swing.SwingConstants;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+
+/**
+ * This is the Default HSB Panel displayed in the JColorChooser.
+ */
+class DefaultHSBChooserPanel extends AbstractColorChooserPanel
+{
+ /** The gradient image displayed. */
+ private transient Image gradientImage;
+
+ /** The Panel that holds the gradient image. */
+ private transient JPanel gradientPanel;
+
+ /** The track gradient image. */
+ private transient Image trackImage;
+
+ /** The panel that holds the track. */
+ private transient JPanel trackPanel;
+
+ /** The slider for the locked HSB value. */
+ private transient JSlider slider;
+
+ /** The RadioButton that controls the Hue. */
+ private transient JRadioButton hRadio;
+
+ /** The RadioButton that controls the Saturation. */
+ private transient JRadioButton sRadio;
+
+ /** The RadioButton that controls the Brightness. */
+ private transient JRadioButton bRadio;
+
+ /** The JSpinner that controls the Hue. */
+ private transient JSpinner hSpinner;
+
+ /** The JSpinner that controls the Saturation. */
+ private transient JSpinner sSpinner;
+
+ /** The JSpinner that controls the Brightness. */
+ private transient JSpinner bSpinner;
+
+ /** The default width of the gradient image. */
+ private static final int imgWidth = 200;
+
+ /** The default height of the gradient image. */
+ private static final int imgHeight = 200;
+
+ /** The default width of the track gradient. */
+ private static final int trackWidth = 30;
+
+ /** The JLabel for Red. */
+ private static final JLabel R = new JLabel("R");
+
+ /** The JLabel for Green. */
+ private static final JLabel G = new JLabel("G");
+
+ /** The JLabel for Blue. */
+ private static final JLabel B = new JLabel("B");
+
+ // FIXME: Should be textfields.
+
+ /** The JLabel that displays the value of Red. */
+ private transient JLabel rFull;
+
+ /** The JLabel that displays the value of Green. */
+ private transient JLabel gFull;
+
+ /** The JLabel that displays the value of Blue. */
+ private transient JLabel bFull;
+
+ /** The point that is displayed in the gradient image. */
+ private transient Point gradientPoint = new Point();
+
+ /**
+ * This indicates that the change to the slider or point is triggered
+ * internally.
+ */
+ private transient boolean internalChange = false;
+
+ /** This indicates that the change to the spinner is triggered internally. */
+ private transient boolean spinnerTrigger = false;
+
+ /** This int identifies which spinner is currently locked. */
+ private transient int locked = -1;
+
+ /** This value indicates that the Hue spinner is locked. */
+ static final int HLOCKED = 0;
+
+ /** This value indicates that the Saturation spinner is locked. */
+ static final int SLOCKED = 1;
+
+ /** This value indicates that the Brightness spinner is locked. */
+ static final int BLOCKED = 2;
+
+ /**
+ * This method indicates that the mouse event is in the process of being
+ * handled.
+ */
+ private transient boolean handlingMouse;
+
+ /**
+ * This helper class handles mouse events on the gradient image.
+ */
+ class MainGradientMouseListener extends MouseAdapter
+ implements MouseMotionListener
+ {
+ /**
+ * This method is called when the mouse is pressed over the gradient
+ * image. The JColorChooser is then updated with new HSB values.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mousePressed(MouseEvent e)
+ {
+ gradientPoint = e.getPoint();
+ update(e.getPoint());
+ }
+
+ /**
+ * This method is called when the mouse is dragged over the gradient
+ * image. The JColorChooser is then updated with the new HSB values.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mouseDragged(MouseEvent e)
+ {
+ Point p = e.getPoint();
+ if (p.x < 0 || p.y < 0 || p.y > imgHeight || p.x > imgWidth)
+ return;
+
+ gradientPoint = p;
+ update(p);
+ }
+
+ /**
+ * This method is called when the mouse is moved over the gradient image.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mouseMoved(MouseEvent e)
+ {
+ // Do nothing.
+ }
+
+ /**
+ * This method updates the JColorChooser with the new values.
+ *
+ * @param p The Point where the MouseEvent occurred.
+ */
+ private void update(Point p)
+ {
+ handlingMouse = true;
+ if (hSpinner.isEnabled())
+ updateH(p);
+ else if (sSpinner.isEnabled())
+ updateS(p);
+ else
+ updateB(p);
+ handlingMouse = false;
+ }
+
+ /**
+ * This method updates the SB values if Hue is locked.
+ *
+ * @param p The point where the MouseEvent occurred.
+ */
+ private void updateH(Point p)
+ {
+ float s = (imgWidth - p.x * 1f) / imgWidth;
+ float b = (imgHeight - p.y * 1f) / imgHeight;
+
+ // Avoid two changes to the model by changing internalChange to true.
+ internalChange = true;
+ sSpinner.setValue(new Integer((int) (s * 100)));
+ internalChange = false;
+ bSpinner.setValue(new Integer((int) (b * 100)));
+
+ revalidate();
+ }
+
+ /**
+ * This method updates the HB values if Saturation is locked.
+ *
+ * @param p The point where the MouseEvent occurred.
+ */
+ private void updateS(Point p)
+ {
+ float h = p.x * 1f / imgWidth;
+ float b = (imgHeight - p.y * 1f) / imgHeight;
+
+ internalChange = true;
+ hSpinner.setValue(new Integer((int) (h * 365)));
+ internalChange = false;
+ bSpinner.setValue(new Integer((int) (b * 100)));
+
+ revalidate();
+ }
+
+ /**
+ * This method updates the HS values if Brightness is locked.
+ *
+ * @param p The point where the MouseEvent occurred.
+ */
+ private void updateB(Point p)
+ {
+ float h = p.x * 1f / imgWidth;
+ float s = (imgHeight - p.y * 1f) / imgHeight;
+
+ internalChange = true;
+ hSpinner.setValue(new Integer((int) (h * 365)));
+ internalChange = false;
+ sSpinner.setValue(new Integer((int) (s * 100)));
+
+ revalidate();
+ }
+ }
+
+ /**
+ * This method listens for slider value changes.
+ */
+ class SliderChangeListener implements ChangeListener
+ {
+ /**
+ * This method is called when the slider value changes. It should change
+ * the color of the JColorChooser.
+ *
+ * @param e The ChangeEvent.
+ */
+ public void stateChanged(ChangeEvent e)
+ {
+ if (internalChange)
+ return;
+
+ Integer value = new Integer(slider.getValue());
+
+ switch (locked)
+ {
+ case HLOCKED:
+ hSpinner.setValue(value);
+ break;
+ case SLOCKED:
+ sSpinner.setValue(value);
+ break;
+ case BLOCKED:
+ bSpinner.setValue(value);
+ break;
+ }
+ }
+ }
+
+ /**
+ * This helper class determines the active JSpinner.
+ */
+ class RadioStateListener implements ChangeListener
+ {
+ /**
+ * This method is called when there is a new JRadioButton that was
+ * selected. As a result, it should activate the associated JSpinner.
+ *
+ * @param e The ChangeEvent.
+ */
+ public void stateChanged(ChangeEvent e)
+ {
+ JSpinner change;
+ if (e.getSource() == hRadio)
+ {
+ locked = HLOCKED;
+ change = hSpinner;
+ }
+ else if (e.getSource() == sRadio)
+ {
+ locked = SLOCKED;
+ change = sSpinner;
+ }
+ else
+ {
+ locked = BLOCKED;
+ change = bSpinner;
+ }
+
+ change.setEnabled(((AbstractButton) e.getSource()).isSelected());
+ updateSlider();
+ updateTrack();
+ updateImage();
+ repaint();
+ }
+ }
+
+ /**
+ * This class listens to the JSpinners for changes.
+ */
+ class ImageScrollListener implements ChangeListener
+ {
+ /**
+ * This method is called whenever one of the JSpinner values change. The
+ * JColorChooser should be updated with the new HSB values.
+ *
+ * @param e The ChangeEvent.
+ */
+ public void stateChanged(ChangeEvent e)
+ {
+ if (internalChange)
+ return;
+
+ float h = ((Number) hSpinner.getValue()).intValue() / 360f;
+ float s = ((Number) sSpinner.getValue()).intValue() / 100f;
+ float b = ((Number) bSpinner.getValue()).intValue() / 100f;
+
+ spinnerTrigger = true;
+ getColorSelectionModel().setSelectedColor(new Color(Color.HSBtoRGB(h, s,
+ b)));
+ spinnerTrigger = false;
+
+ if (! handlingMouse)
+ {
+ updateImage();
+ updateTrack();
+ }
+ repaint();
+ }
+ }
+
+ /**
+ * Creates a new DefaultHSBChooserPanel object.
+ */
+ DefaultHSBChooserPanel()
+ {
+ super();
+ }
+
+ /**
+ * This method returns the name displayed by the JColorChooser tab that
+ * holds this panel.
+ *
+ * @return The name displayed in the JColorChooser tab.
+ */
+ public String getDisplayName()
+ {
+ return "HSB";
+ }
+
+ /**
+ * This method updates the various components inside the HSBPanel (the
+ * JSpinners, the JSlider, and the gradient image point) with updated
+ * values when the JColorChooser color value changes.
+ */
+ public void updateChooser()
+ {
+ Color c = getColorSelectionModel().getSelectedColor();
+
+ float[] hsbVals = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(),
+ null);
+
+ internalChange = true;
+
+ // spinnerTrigger, internalChange, and handlingMouse are used because of the
+ // we don't want things like: change spinner -> update chooser -> change spinner
+ // That's because the value from before and after the update can differ
+ // slightly because of the conversion.
+ // FIXME: Think of better way to deal with this.
+ if (! spinnerTrigger)
+ {
+ hSpinner.setValue(new Integer((int) (hsbVals[0] * 360)));
+ sSpinner.setValue(new Integer((int) (hsbVals[1] * 100)));
+ bSpinner.setValue(new Integer((int) (hsbVals[2] * 100)));
+ }
+
+ switch (locked)
+ {
+ case HLOCKED:
+ if (slider != null)
+ slider.setValue(((Number) hSpinner.getValue()).intValue());
+ if (! handlingMouse)
+ {
+ gradientPoint.x = (int) ((1 - hsbVals[1]) * imgWidth);
+ gradientPoint.y = (int) ((1 - hsbVals[2]) * imgHeight);
+ }
+ break;
+ case SLOCKED:
+ if (slider != null)
+ slider.setValue(((Number) sSpinner.getValue()).intValue());
+ if (! handlingMouse)
+ {
+ gradientPoint.x = (int) (hsbVals[0] * imgWidth);
+ gradientPoint.y = (int) ((1 - hsbVals[2]) * imgHeight);
+ }
+ break;
+ case BLOCKED:
+ if (slider != null)
+ slider.setValue(((Number) bSpinner.getValue()).intValue());
+ if (! handlingMouse)
+ {
+ gradientPoint.x = (int) (hsbVals[0] * imgWidth);
+ gradientPoint.y = (int) ((1 - hsbVals[1]) * imgHeight);
+ }
+ break;
+ }
+ internalChange = false;
+
+ updateImage();
+ updateTrack();
+ updateTextFields();
+ }
+
+ /**
+ * This method builds the DefaultHSBChooserPanel.
+ */
+ protected void buildChooser()
+ {
+ setLayout(new BorderLayout());
+
+ add(buildRightPanel(), BorderLayout.EAST);
+
+ JPanel container = new JPanel();
+ container.setLayout(new BorderLayout());
+
+ gradientPanel = new JPanel()
+ {
+ public Dimension getPreferredSize()
+ {
+ return new Dimension(imgWidth, imgHeight);
+ }
+
+ public void paint(Graphics g)
+ {
+ if (gradientImage != null)
+ g.drawImage(gradientImage, 0, 0, this);
+
+ Color saved = g.getColor();
+ g.setColor(Color.WHITE);
+ g.drawOval(gradientPoint.x - 3, gradientPoint.y - 3, 6, 6);
+ g.setColor(saved);
+ }
+ };
+
+ MouseAdapter ml = new MainGradientMouseListener();
+ gradientPanel.addMouseListener(ml);
+ gradientPanel.addMouseMotionListener((MouseMotionListener) ml);
+
+ trackPanel = new JPanel()
+ {
+ public Dimension getPreferredSize()
+ {
+ return new Dimension(trackWidth, imgHeight);
+ }
+
+ public void paint(Graphics g)
+ {
+ if (trackImage != null)
+ g.drawImage(trackImage, 0, 0, this);
+ }
+ };
+
+ slider = new JSlider();
+ slider.setPaintTrack(false);
+ slider.setPaintTicks(false);
+
+ slider.setOrientation(SwingConstants.VERTICAL);
+
+ updateSlider();
+
+ container.add(gradientPanel, BorderLayout.WEST);
+ container.add(slider, BorderLayout.CENTER);
+ container.add(trackPanel, BorderLayout.EAST);
+
+ add(container, BorderLayout.WEST);
+ slider.addChangeListener(new SliderChangeListener());
+ repaint();
+ }
+
+ /**
+ * This method uninstalls the DefaultHSBPanel.
+ *
+ * @param chooser The JColorChooser to remove this panel from.
+ */
+ public void uninstallChooserPanel(JColorChooser chooser)
+ {
+ trackImage = null;
+ gradientImage = null;
+ gradientPanel = null;
+ slider = null;
+
+ hSpinner = null;
+ sSpinner = null;
+ bSpinner = null;
+
+ hRadio = null;
+ sRadio = null;
+ bRadio = null;
+
+ removeAll();
+ super.uninstallChooserPanel(chooser);
+ }
+
+ /**
+ * This helper method creates the right side panel (the panel with the
+ * Spinners and TextFields).
+ *
+ * @return The right side panel.
+ */
+ private Container buildRightPanel()
+ {
+ JPanel container = new JPanel();
+ container.setLayout(new GridLayout(6, 2));
+
+ hRadio = new JRadioButton("H");
+ sRadio = new JRadioButton("S");
+ bRadio = new JRadioButton("B");
+
+ ButtonGroup group = new ButtonGroup();
+ group.add(hRadio);
+ group.add(sRadio);
+ group.add(bRadio);
+
+ hSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 359, 1));
+ sSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 100, 1));
+ bSpinner = new JSpinner(new SpinnerNumberModel(100, 0, 100, 1));
+
+ hSpinner.setEnabled(false);
+ sSpinner.setEnabled(false);
+ bSpinner.setEnabled(false);
+
+ ChangeListener cl = new RadioStateListener();
+ ChangeListener scroll = new ImageScrollListener();
+
+ hRadio.addChangeListener(cl);
+ sRadio.addChangeListener(cl);
+ bRadio.addChangeListener(cl);
+
+ hSpinner.addChangeListener(scroll);
+ sSpinner.addChangeListener(scroll);
+ bSpinner.addChangeListener(scroll);
+
+ hRadio.setSelected(true);
+
+ container.add(hRadio);
+ container.add(hSpinner);
+
+ container.add(sRadio);
+ container.add(sSpinner);
+
+ container.add(bRadio);
+ container.add(bSpinner);
+
+ rFull = new JLabel("red full");
+ gFull = new JLabel("green full");
+ bFull = new JLabel("blue full");
+
+ container.add(R);
+ container.add(rFull);
+
+ container.add(G);
+ container.add(gFull);
+
+ container.add(B);
+ container.add(bFull);
+
+ return container;
+ }
+
+ /**
+ * This method returns the small display icon.
+ *
+ * @return The small display icon.
+ */
+ public Icon getSmallDisplayIcon()
+ {
+ return null;
+ }
+
+ /**
+ * This method returns the large display icon.
+ *
+ * @return The large display icon.
+ */
+ public Icon getLargeDisplayIcon()
+ {
+ return null;
+ }
+
+ /**
+ * This method paints the chooser panel.
+ *
+ * @param g The graphics object to paint with.
+ */
+ public void paint(Graphics g)
+ {
+ super.paint(g);
+ }
+
+ /**
+ * This method updates the gradient image with a new one taking the Hue
+ * value as the constant.
+ */
+ private void updateHLockImage()
+ {
+ int index = 0;
+ int[] pix = new int[imgWidth * imgHeight];
+ float hValue = ((Number) hSpinner.getValue()).intValue() / 360f;
+
+ for (int j = 0; j < imgHeight; j++)
+ for (int i = 0; i < imgWidth; i++)
+ pix[index++] = Color.HSBtoRGB(hValue, (imgWidth - i * 1f) / imgWidth,
+ (imgHeight - j * 1f) / imgHeight)
+ | (255 << 24);
+
+ gradientImage = createImage(new MemoryImageSource(imgWidth, imgHeight,
+ pix, 0, imgWidth));
+ }
+
+ /**
+ * This method updates the gradient image with a new one taking the
+ * Brightness value as the constant.
+ */
+ private void updateBLockImage()
+ {
+ int[] pix = new int[imgWidth * imgHeight];
+ float bValue = ((Number) bSpinner.getValue()).intValue() / 100f;
+
+ int index = 0;
+ for (int j = 0; j < imgHeight; j++)
+ for (int i = 0; i < imgWidth; i++)
+ pix[index++] = Color.HSBtoRGB(i * 1f / imgWidth,
+ (imgHeight - j * 1f) / imgHeight, bValue)
+ | (255 << 24);
+
+ gradientImage = createImage(new MemoryImageSource(imgWidth, imgHeight,
+ pix, 0, imgWidth));
+ }
+
+ /**
+ * This method updates the gradient image with a new one taking the
+ * Saturation value as the constant.
+ */
+ private void updateSLockImage()
+ {
+ int[] pix = new int[imgWidth * imgHeight];
+ float sValue = ((Number) sSpinner.getValue()).intValue() / 100f;
+
+ int index = 0;
+ for (int j = 0; j < imgHeight; j++)
+ for (int i = 0; i < imgWidth; i++)
+ pix[index++] = Color.HSBtoRGB(i * 1f / imgWidth, sValue,
+ (imgHeight - j * 1f) / imgHeight)
+ | (255 << 24);
+ gradientImage = createImage(new MemoryImageSource(imgWidth, imgHeight,
+ pix, 0, imgWidth));
+ }
+
+ /**
+ * This method calls the appropriate method to update the gradient image
+ * depending on which HSB value is constant.
+ */
+ private void updateImage()
+ {
+ switch (locked)
+ {
+ case HLOCKED:
+ updateHLockImage();
+ break;
+ case SLOCKED:
+ updateSLockImage();
+ break;
+ case BLOCKED:
+ updateBLockImage();
+ break;
+ }
+ }
+
+ /**
+ * This method updates the TextFields with the correct RGB values.
+ */
+ private void updateTextFields()
+ {
+ int c = getColorSelectionModel().getSelectedColor().getRGB();
+
+ rFull.setText("" + (c >> 16 & 0xff));
+ gFull.setText("" + (c >> 8 & 0xff));
+ bFull.setText("" + (c & 0xff));
+
+ repaint();
+ }
+
+ /**
+ * This method updates the slider in response to making a different HSB
+ * property the constant.
+ */
+ private void updateSlider()
+ {
+ if (slider == null)
+ return;
+
+ slider.setMinimum(0);
+ if (locked == HLOCKED)
+ {
+ slider.setMaximum(359);
+ ;
+ slider.setValue(((Number) hSpinner.getValue()).intValue());
+ slider.setInverted(true);
+ }
+ else
+ {
+ slider.setMaximum(100);
+ slider.setInverted(false);
+ if (sRadio.isSelected())
+ slider.setValue(((Number) sSpinner.getValue()).intValue());
+ else
+ slider.setValue(((Number) bSpinner.getValue()).intValue());
+ }
+ repaint();
+ }
+
+ /**
+ * This method updates the track gradient image depending on which HSB
+ * property is constant.
+ */
+ private void updateTrack()
+ {
+ switch (locked)
+ {
+ case HLOCKED:
+ updateHTrack();
+ break;
+ case SLOCKED:
+ updateSTrack();
+ break;
+ case BLOCKED:
+ updateBTrack();
+ break;
+ }
+ }
+
+ /**
+ * This method updates the track gradient image if the Hue value is allowed
+ * to change (according to the JRadioButtons).
+ */
+ private void updateHTrack()
+ {
+ int trackIndex = 0;
+ int[] trackPix = new int[trackWidth * imgHeight];
+
+ for (int j = 0; j < imgHeight; j++)
+ for (int i = 0; i < trackWidth; i++)
+ trackPix[trackIndex++] = Color.HSBtoRGB(j * 1f / imgHeight, 1f, 1f)
+ | (255 << 24);
+
+ trackImage = createImage(new MemoryImageSource(trackWidth, imgHeight,
+ trackPix, 0, trackWidth));
+ }
+
+ /**
+ * This method updates the track gradient image if the Saturation value is
+ * allowed to change (according to the JRadioButtons).
+ */
+ private void updateSTrack()
+ {
+ int[] trackPix = new int[trackWidth * imgHeight];
+
+ float hValue = ((Number) hSpinner.getValue()).intValue() / 360f;
+ float bValue = ((Number) bSpinner.getValue()).intValue() / 100f;
+
+ int trackIndex = 0;
+ for (int j = 0; j < imgHeight; j++)
+ for (int i = 0; i < trackWidth; i++)
+ trackPix[trackIndex++] = Color.HSBtoRGB(hValue,
+ (imgHeight - j * 1f) / imgHeight,
+ bValue) | (255 << 24);
+
+ trackImage = createImage(new MemoryImageSource(trackWidth, imgHeight,
+ trackPix, 0, trackWidth));
+ }
+
+ /**
+ * This method updates the track gradient image if the Brightness value is
+ * allowed to change (according to the JRadioButtons).
+ */
+ private void updateBTrack()
+ {
+ int[] trackPix = new int[trackWidth * imgHeight];
+
+ float hValue = ((Number) hSpinner.getValue()).intValue() / 360f;
+ float sValue = ((Number) sSpinner.getValue()).intValue() / 100f;
+
+ int trackIndex = 0;
+ for (int j = 0; j < imgHeight; j++)
+ for (int i = 0; i < trackWidth; i++)
+ trackPix[trackIndex++] = Color.HSBtoRGB(hValue, sValue,
+ (imgHeight - j * 1f) / imgHeight)
+ | (255 << 24);
+
+ trackImage = createImage(new MemoryImageSource(trackWidth, imgHeight,
+ trackPix, 0, trackWidth));
+ }
+}
Index: javax/swing/colorchooser/DefaultPreviewPanel.java
===================================================================
RCS file: javax/swing/colorchooser/DefaultPreviewPanel.java
diff -N javax/swing/colorchooser/DefaultPreviewPanel.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ javax/swing/colorchooser/DefaultPreviewPanel.java 25 Aug 2004 21:35:36 -0000
@@ -0,0 +1,317 @@
+/* DefaultPreviewPanel.java --
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+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;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Insets;
+import javax.swing.JColorChooser;
+import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
+import javax.swing.border.Border;
+
+
+/**
+ * This is the default preview panel for the JColorChooser. The default
+ * preview panel is responsible for displaying the currently selected color
+ * of the JColorChooser.
+ */
+class DefaultPreviewPanel extends JPanel
+{
+ /**
+ * This is the border around the preview panel.
+ */
+ class PreviewBorder implements Border
+ {
+ /** This is the value of the top, bottom, top, and right inset. */
+ private static final int edge = 20;
+
+ /**
+ * This is the distance from the top left corner of the border to the
+ * text.
+ */
+ private static final int lead = 5;
+
+ /** This is the horizontal gap between the text and the border. */
+ private static final int gap = 3;
+
+ /**
+ * This method returns the border insets for the given Component.
+ *
+ * @param c The Component to retrieve insets for.
+ *
+ * @return The insets for the given Component.
+ */
+ public Insets getBorderInsets(Component c)
+ {
+ return new Insets(edge, edge, edge, edge);
+ }
+
+ /**
+ * This method returns whether the border is responsible for painting its
+ * own background.
+ *
+ * @return Whether the border is responsible for painting its own
+ * background.
+ */
+ public boolean isBorderOpaque()
+ {
+ return true;
+ }
+
+ /**
+ * This method paints the border for the given component with the graphics
+ * object using the given properties.
+ *
+ * @param c The Component to paint the border for.
+ * @param g The Graphics object to paint with.
+ * @param x The x location to paint at.
+ * @param y The y location to paint at.
+ * @param width The width of the component.
+ * @param height The height of the component.
+ */
+ public void paintBorder(Component c, Graphics g, int x, int y, int width,
+ int height)
+ {
+ Color saved = g.getColor();
+ FontMetrics fm = g.getFontMetrics();
+
+ g.setColor(Color.BLACK);
+ g.drawLine(x + edge / 2, y + edge / 2, x + edge / 2,
+ y + height - edge / 2);
+ g.drawLine(x + edge / 2, y + height - edge / 2, x + width - edge / 2,
+ y + height - edge / 2);
+ g.drawLine(x + width - edge / 2, y + edge / 2, x + width - edge / 2,
+ y + height - edge / 2);
+ g.drawLine(x + edge / 2, y + edge / 2, x + edge / 2 + lead, y + edge / 2);
+
+ int strwidth = fm.stringWidth("Preview");
+
+ g.drawString("Preview", x + edge / 2 + lead + gap,
+ y + edge / 2 + fm.getAscent() / 2);
+
+ g.drawLine(x + lead + edge / 2 + strwidth + gap * 2, y + edge / 2,
+ x + width - edge / 2, y + edge / 2);
+
+ g.setColor(saved);
+ }
+ }
+
+ /** A standard large gap size. */
+ private static int largeGap = 6;
+
+ /** A standard small gap size. */
+ private static int smallGap = 2;
+
+ /** The size of each side of the square. */
+ private static int squareSize = 36;
+
+ /** This padding between the text and the edge of its box. */
+ private static int textPadding = 4;
+
+ /** The width of the right most rectangles. */
+ private static int rightSideRectWidth = 60;
+
+ /** The sample text. */
+ private static String sample = "Sample Text Sample Text";
+
+ /**
+ * Creates a new DefaultPreviewPanel object.
+ */
+ DefaultPreviewPanel()
+ {
+ super();
+ setBorder(new PreviewBorder());
+ }
+
+ /**
+ * This method paints the default preview panel with the given Graphics
+ * object.
+ *
+ * @param g The Graphics object.
+ */
+ public void paint(Graphics g)
+ {
+ super.paint(g);
+ Color currentColor = null;
+ JColorChooser chooser = (JColorChooser) SwingUtilities.getAncestorOfClass(JColorChooser.class,
+ this);
+ if (chooser != null)
+ currentColor = chooser.getColor();
+
+ Color saved = g.getColor();
+ Insets insets = getInsets();
+
+ int down = insets.top + squareSize + largeGap;
+ int currX = insets.left;
+
+ paintSquare(g, currX, insets.top, Color.WHITE, currentColor, Color.WHITE,
+ -1, -1, -1);
+ paintSquare(g, currX, down, currentColor, null, null, -1, -1, -1);
+
+ currX += squareSize + largeGap;
+
+ paintSquare(g, currX, insets.top, Color.BLACK, currentColor, Color.WHITE,
+ -1, -1, -1);
+ paintSquare(g, currX, down, Color.WHITE, currentColor, null, -1, -1, -1);
+
+ currX += squareSize + largeGap;
+
+ paintSquare(g, currX, insets.top, Color.WHITE, currentColor, Color.BLACK,
+ -1, -1, -1);
+ paintSquare(g, currX, down, Color.BLACK, currentColor, null, -1, -1, -1);
+
+ FontMetrics fm = g.getFontMetrics();
+ int strWidth = fm.stringWidth(sample);
+ int strHeight = fm.getHeight();
+
+ currX += squareSize + largeGap;
+
+ int boxWidth = 2 * textPadding + strWidth;
+ int boxHeight = 2 * textPadding + strHeight;
+
+ int first = insets.top + textPadding;
+ int second = insets.top + boxHeight + smallGap;
+ int third = insets.top + 2 * (boxHeight + smallGap);
+
+ g.setColor(Color.WHITE);
+ g.fillRect(currX, third, boxWidth, boxHeight);
+
+ g.setColor(currentColor);
+ g.drawString(sample, currX + textPadding,
+ first + textPadding + fm.getAscent());
+
+ g.fillRect(currX, second, boxWidth, boxHeight);
+
+ g.drawString(sample, currX + textPadding,
+ third + textPadding + fm.getAscent());
+
+ g.setColor(Color.BLACK);
+ g.drawString(sample, currX + textPadding,
+ second + textPadding + fm.getAscent());
+
+ currX += boxWidth + largeGap;
+
+ g.setColor(Color.WHITE);
+ g.fillRect(currX, insets.top, rightSideRectWidth, squareSize
+ + largeGap / 2);
+
+ g.setColor(currentColor);
+ g.fillRect(currX, insets.top + squareSize + largeGap / 2,
+ rightSideRectWidth, squareSize + largeGap / 2);
+
+ g.setColor(saved);
+ }
+
+ /**
+ * This method creates and paints a square. The square has two smaller
+ * squares inside of it. Each of the three squares has their sizes
+ * determined by the size arguments. If the size is not given (by passing
+ * in -1), then the size is determined automatically.
+ *
+ * @param g The Graphics object to paint with.
+ * @param x The x location to paint at.
+ * @param y The y location to paint at.
+ * @param first The color of the first square.
+ * @param second The color of the second square.
+ * @param third The color of the third square.
+ * @param firstSize The size of the first square.
+ * @param secondSize The size of the second square.
+ * @param thirdSize The size of the third square.
+ */
+ private void paintSquare(Graphics g, int x, int y, Color first,
+ Color second, Color third, int firstSize,
+ int secondSize, int thirdSize)
+ {
+ Color saved = g.getColor();
+ if (firstSize == -1)
+ firstSize = squareSize;
+ if (secondSize == -1)
+ secondSize = squareSize * 2 / 3;
+ if (thirdSize == -1)
+ thirdSize = squareSize / 3;
+ int secondOffset = (firstSize - secondSize) / 2;
+ int thirdOffset = (firstSize - thirdSize) / 2;
+
+ if (first == null)
+ return;
+ g.setColor(first);
+ g.fillRect(x, y, firstSize, firstSize);
+ if (second == null)
+ return;
+ g.setColor(second);
+ g.fillRect(x + secondOffset, y + secondOffset, secondSize, secondSize);
+ if (third == null)
+ return;
+ g.setColor(third);
+ g.fillRect(x + thirdOffset, y + thirdOffset, thirdSize, thirdSize);
+
+ g.setColor(saved);
+ }
+
+ /**
+ * This method returns the preferred size of the default preview panel.
+ *
+ * @return The preferred size of the default preview panel.
+ */
+ public Dimension getPreferredSize()
+ {
+ Graphics g = getGraphics();
+ FontMetrics fm = g.getFontMetrics();
+ g.dispose();
+
+ int strWidth = fm.stringWidth(sample);
+ int strHeight = fm.getHeight();
+
+ int h1 = (strHeight + 2 * textPadding) * 3 + 2 * smallGap;
+ int h2 = 2 * squareSize + largeGap;
+
+ int height = Math.max(h1, h2);
+
+ int width = 3 * (squareSize + largeGap) + strWidth + 2 * textPadding
+ + largeGap + rightSideRectWidth;
+
+ Insets insets = getInsets();
+
+ return new Dimension(width + insets.right + insets.left,
+ height + insets.top + insets.bottom);
+ }
+}
Index: javax/swing/colorchooser/DefaultRGBChooserPanel.java
===================================================================
RCS file: javax/swing/colorchooser/DefaultRGBChooserPanel.java
diff -N javax/swing/colorchooser/DefaultRGBChooserPanel.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ javax/swing/colorchooser/DefaultRGBChooserPanel.java 25 Aug 2004 21:35:36 -0000
@@ -0,0 +1,377 @@
+/* DefaultRGHChooserPanel.java --
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+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.BorderLayout;
+import java.awt.Color;
+import java.awt.FlowLayout;
+import java.awt.Graphics;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import javax.swing.Icon;
+import javax.swing.JColorChooser;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JSlider;
+import javax.swing.JSpinner;
+import javax.swing.SpinnerNumberModel;
+import javax.swing.SwingConstants;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+
+/**
+ * This is the default RGB panel for the JColorChooser. The color is selected
+ * using three sliders that represent the RGB values.
+ */
+public class DefaultRGBChooserPanel extends AbstractColorChooserPanel
+{
+ /**
+ * This class handles the slider value changes for all three sliders.
+ */
+ class SliderHandler implements ChangeListener
+ {
+ /**
+ * This method is called whenever any of the slider values change.
+ *
+ * @param e The ChangeEvent.
+ */
+ public void stateChanged(ChangeEvent e)
+ {
+ if (internalChange)
+ return;
+ int color = R.getValue() << 16 | G.getValue() << 8 | B.getValue();
+
+ getColorSelectionModel().setSelectedColor(new Color(color));
+ }
+ }
+
+ /**
+ * This class handles the Spinner values changing.
+ */
+ class SpinnerHandler implements ChangeListener
+ {
+ /**
+ * This method is called whenever any of the JSpinners change values.
+ *
+ * @param e The ChangeEvent.
+ */
+ public void stateChanged(ChangeEvent e)
+ {
+ if (internalChange)
+ return;
+ int red = ((Number) RSpinner.getValue()).intValue();
+ int green = ((Number) GSpinner.getValue()).intValue();
+ int blue = ((Number) BSpinner.getValue()).intValue();
+
+ int color = red << 16 | green << 8 | blue;
+
+ getColorSelectionModel().setSelectedColor(new Color(color));
+ }
+ }
+
+ /**
+ * Whether the color change was initiated from the slider or spinner rather
+ * than externally.
+ */
+ private transient boolean internalChange = false;
+
+ /** The ChangeListener for the sliders. */
+ private transient ChangeListener colorChanger;
+
+ /** The ChangeListener for the spinners. */
+ private transient ChangeListener spinnerHandler;
+
+ /** The slider that handles the red values. */
+ private transient JSlider R;
+
+ /** The slider that handles the green values. */
+ private transient JSlider G;
+
+ /** The slider that handles the blue values. */
+ private transient JSlider B;
+
+ /** The label for the red slider. */
+ private transient JLabel RLabel;
+
+ /** The label for the green slider. */
+ private transient JLabel GLabel;
+
+ /** The label for the blue slider. */
+ private transient JLabel BLabel;
+
+ /** The spinner that handles the red values. */
+ private transient JSpinner RSpinner;
+
+ /** The spinner that handles the green values. */
+ private transient JSpinner GSpinner;
+
+ /** The spinner that handles the blue values. */
+ private transient JSpinner BSpinner;
+
+ /**
+ * Creates a new DefaultRGBChooserPanel object.
+ */
+ public DefaultRGBChooserPanel()
+ {
+ super();
+ }
+
+ /**
+ * This method returns the name displayed in the JTabbedPane.
+ *
+ * @return The name displayed in the JTabbedPane.
+ */
+ public String getDisplayName()
+ {
+ return "RGB";
+ }
+
+ /**
+ * This method updates the chooser panel with the new color chosen in the
+ * JColorChooser.
+ */
+ public void updateChooser()
+ {
+ Color c = getColorFromModel();
+ int rgb = c.getRGB();
+
+ int red = rgb >> 16 & 0xff;
+ int green = rgb >> 8 & 0xff;
+ int blue = rgb & 0xff;
+
+ internalChange = true;
+
+ if (R != null)
+ R.setValue(red);
+ if (RSpinner != null)
+ RSpinner.setValue(new Integer(red));
+ if (G != null)
+ G.setValue(green);
+ if (GSpinner != null)
+ GSpinner.setValue(new Integer(green));
+ if (B != null)
+ B.setValue(blue);
+ if (BSpinner != null)
+ BSpinner.setValue(new Integer(blue));
+
+ internalChange = false;
+
+ revalidate();
+ repaint();
+ }
+
+ /**
+ * This method builds the chooser panel.
+ */
+ protected void buildChooser()
+ {
+ setLayout(new GridBagLayout());
+
+ RLabel = new JLabel("Red");
+ RLabel.setDisplayedMnemonic('d');
+ GLabel = new JLabel("Green");
+ GLabel.setDisplayedMnemonic('n');
+ BLabel = new JLabel("Blue");
+ BLabel.setDisplayedMnemonic('B');
+
+ R = new JSlider(SwingConstants.HORIZONTAL, 0, 255, 255);
+ G = new JSlider(SwingConstants.HORIZONTAL, 0, 255, 255);
+ B = new JSlider(SwingConstants.HORIZONTAL, 0, 255, 255);
+
+ R.setPaintTicks(true);
+ R.setSnapToTicks(false);
+ G.setPaintTicks(true);
+ G.setSnapToTicks(false);
+ B.setPaintTicks(true);
+ B.setSnapToTicks(false);
+
+ R.setLabelTable(R.createStandardLabels(85));
+ R.setPaintLabels(true);
+ G.setLabelTable(G.createStandardLabels(85));
+ G.setPaintLabels(true);
+ B.setLabelTable(B.createStandardLabels(85));
+ B.setPaintLabels(true);
+
+ R.setMajorTickSpacing(85);
+ G.setMajorTickSpacing(85);
+ B.setMajorTickSpacing(85);
+
+ R.setMinorTickSpacing(17);
+ G.setMinorTickSpacing(17);
+ B.setMinorTickSpacing(17);
+
+ RSpinner = new JSpinner(new SpinnerNumberModel(R.getValue(),
+ R.getMinimum(),
+ R.getMaximum(), 1));
+ GSpinner = new JSpinner(new SpinnerNumberModel(G.getValue(),
+ G.getMinimum(),
+ G.getMaximum(), 1));
+ BSpinner = new JSpinner(new SpinnerNumberModel(B.getValue(),
+ B.getMinimum(),
+ B.getMaximum(), 1));
+
+ RLabel.setLabelFor(R);
+ GLabel.setLabelFor(G);
+ BLabel.setLabelFor(B);
+
+ GridBagConstraints bag = new GridBagConstraints();
+ bag.fill = GridBagConstraints.VERTICAL;
+
+ bag.gridx = 0;
+ bag.gridy = 0;
+ add(RLabel, bag);
+
+ bag.gridx = 1;
+ add(R, bag);
+
+ bag.gridx = 2;
+ add(RSpinner, bag);
+
+ bag.gridx = 0;
+ bag.gridy = 1;
+ add(GLabel, bag);
+
+ bag.gridx = 1;
+ add(G, bag);
+
+ bag.gridx = 2;
+ add(GSpinner, bag);
+
+ bag.gridx = 0;
+ bag.gridy = 2;
+ add(BLabel, bag);
+
+ bag.gridx = 1;
+ add(B, bag);
+
+ bag.gridx = 2;
+ add(BSpinner, bag);
+
+ installListeners();
+ }
+
+ /**
+ * This method uninstalls the chooser panel from the JColorChooser.
+ *
+ * @param chooser The JColorChooser to remove this chooser panel from.
+ */
+ public void uninstallChooserPanel(JColorChooser chooser)
+ {
+ uninstallListeners();
+ removeAll();
+
+ R = null;
+ G = null;
+ B = null;
+
+ RSpinner = null;
+ GSpinner = null;
+ BSpinner = null;
+
+ super.uninstallChooserPanel(chooser);
+ }
+
+ /**
+ * This method uninstalls any listeners that were added by the chooser
+ * panel.
+ */
+ private void uninstallListeners()
+ {
+ R.removeChangeListener(colorChanger);
+ G.removeChangeListener(colorChanger);
+ B.removeChangeListener(colorChanger);
+
+ colorChanger = null;
+
+ RSpinner.removeChangeListener(spinnerHandler);
+ GSpinner.removeChangeListener(spinnerHandler);
+ BSpinner.removeChangeListener(spinnerHandler);
+
+ spinnerHandler = null;
+ }
+
+ /**
+ * This method installs any listeners that the chooser panel needs to
+ * operate.
+ */
+ private void installListeners()
+ {
+ colorChanger = new SliderHandler();
+
+ R.addChangeListener(colorChanger);
+ G.addChangeListener(colorChanger);
+ B.addChangeListener(colorChanger);
+
+ spinnerHandler = new SpinnerHandler();
+
+ RSpinner.addChangeListener(spinnerHandler);
+ GSpinner.addChangeListener(spinnerHandler);
+ BSpinner.addChangeListener(spinnerHandler);
+ }
+
+ /**
+ * This method returns the small display icon.
+ *
+ * @return The small display icon.
+ */
+ public Icon getSmallDisplayIcon()
+ {
+ return null;
+ }
+
+ /**
+ * This method returns the large display icon.
+ *
+ * @return The large display icon.
+ */
+ public Icon getLargeDisplayIcon()
+ {
+ return null;
+ }
+
+ /**
+ * This method paints the default RGB chooser panel.
+ *
+ * @param g The Graphics object to paint with.
+ */
+ public void paint(Graphics g)
+ {
+ super.paint(g);
+ }
+}
Index: javax/swing/colorchooser/DefaultSwatchChooserPanel.java
===================================================================
RCS file: javax/swing/colorchooser/DefaultSwatchChooserPanel.java
diff -N javax/swing/colorchooser/DefaultSwatchChooserPanel.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ javax/swing/colorchooser/DefaultSwatchChooserPanel.java 25 Aug 2004 21:35:37 -0000
@@ -0,0 +1,891 @@
+/* DefaultSwatchChooserPanel.java --
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+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.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Insets;
+import java.awt.LayoutManager;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import javax.swing.Icon;
+import javax.swing.JColorChooser;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+
+/**
+ * This class is the DefaultSwatchChooserPanel. This chooser panel displays a
+ * set of colors that can be picked. Recently picked items will go into a
+ * side panel so the user can see the history of the chosen colors.
+ */
+class DefaultSwatchChooserPanel extends AbstractColorChooserPanel
+{
+ /** The main panel that holds the set of choosable colors. */
+ MainSwatchPanel mainPalette;
+
+ /** A panel that holds the recent colors. */
+ RecentSwatchPanel recentPalette;
+
+ /** The mouse handlers for the panels. */
+ MouseListener mouseHandler;
+
+ /**
+ * This the base class for all swatch panels. Swatch panels are panels that
+ * hold a set of blocks where colors are displayed.
+ */
+ abstract static class SwatchPanel extends JPanel
+ {
+ /** The width of each block. */
+ protected int cellWidth = 10;
+
+ /** The height of each block. */
+ protected int cellHeight = 10;
+
+ /** The gap between blocks. */
+ protected int gap = 1;
+
+ /** The number of rows in the swatch panel. */
+ protected int numRows;
+
+ /** The number of columns in the swatch panel. */
+ protected int numCols;
+
+ /**
+ * Creates a new SwatchPanel object.
+ */
+ SwatchPanel()
+ {
+ super();
+ setBackground(Color.WHITE);
+ }
+
+ /**
+ * This method returns the preferred size of the swatch panel based on the
+ * number of rows and columns and the size of each cell.
+ *
+ * @return The preferred size of the swatch panel.
+ */
+ public Dimension getPreferredSize()
+ {
+ int height = numRows * cellHeight + (numRows - 1) * gap;
+ int width = numCols * cellWidth + (numCols - 1) * gap;
+ Insets insets = getInsets();
+
+ return new Dimension(width + insets.left + insets.right,
+ height + insets.top + insets.bottom);
+ }
+
+ /**
+ * This method returns the color for the given position.
+ *
+ * @param x The x coordinate of the position.
+ * @param y The y coordinate of the position.
+ *
+ * @return The color at the given position.
+ */
+ public abstract Color getColorForPosition(int x, int y);
+
+ /**
+ * This method initializes the colors for the swatch panel.
+ */
+ protected abstract void initializeColors();
+ }
+
+ /**
+ * This is the main swatch panel. This panel sits in the middle and allows a
+ * set of colors to be picked which will move to the recent swatch panel.
+ */
+ static class MainSwatchPanel extends SwatchPanel
+ {
+ /** The color describing (204, 255, 255) */
+ public static final Color C204255255 = new Color(204, 204, 255);
+
+ /** The color describing (255, 204, 204) */
+ public static final Color C255204204 = new Color(255, 204, 204);
+
+ /** The color describing (204, 255, 204) */
+ public static final Color C204255204 = new Color(204, 255, 204);
+
+ /** The color describing (204, 204, 204) */
+ public static final Color C204204204 = new Color(204, 204, 204);
+
+ /** The color (153, 153, 255). */
+ public static final Color C153153255 = new Color(153, 153, 255);
+
+ /** The color (51, 51, 255). */
+ public static final Color C051051255 = new Color(51, 51, 255);
+
+ /** The color (153, 0, 153). */
+ public static final Color C153000153 = new Color(153, 0, 153);
+
+ /** The color (0, 51, 51). */
+ public static final Color C000051051 = new Color(0, 51, 51);
+
+ /** The color (51, 0, 51). */
+ public static final Color C051000051 = new Color(51, 0, 51);
+
+ /** The color (51, 51, 0). */
+ public static final Color C051051000 = new Color(51, 51, 0);
+
+ /** The color (102, 102, 0). */
+ public static final Color C102102000 = new Color(102, 102, 0);
+
+ /** The color (153, 255, 153). */
+ public static final Color C153255153 = new Color(153, 255, 153);
+
+ /** The color (102, 255, 102). */
+ public static final Color C102255102 = new Color(102, 255, 102);
+
+ /** The color (0, 102, 102). */
+ public static final Color C000102102 = new Color(0, 102, 102);
+
+ /** The color (102, 0, 102). */
+ public static final Color C102000102 = new Color(102, 0, 102);
+
+ /** The color (0, 153, 153). */
+ public static final Color C000153153 = new Color(0, 153, 153);
+
+ /** The color (153, 153, 0). */
+ public static final Color C153153000 = new Color(153, 153, 0);
+
+ /** The color (204, 204, 0). */
+ public static final Color C204204000 = new Color(204, 204, 0);
+
+ /** The color (204, 0, 204). */
+ public static final Color C204000204 = new Color(204, 0, 204);
+
+ /** The color (0, 204, 204). */
+ public static final Color C000204204 = new Color(0, 204, 204);
+
+ /** The color (51, 255, 51). */
+ public static final Color C051255051 = new Color(51, 255, 51);
+
+ /** The color (255, 51, 51). */
+ public static final Color C255051051 = new Color(255, 51, 51);
+
+ /** The color (255, 102, 102). */
+ public static final Color C255102102 = new Color(255, 102, 102);
+
+ /** The color (102, 102, 255). */
+ public static final Color C102102255 = new Color(102, 102, 255);
+
+ /** The color (255, 153, 153). */
+ public static final Color C255153153 = new Color(255, 153, 153);
+ static Color[] colors =
+ {
+ // Row 1
+ Color.WHITE, new Color(204, 255, 255), C204255255, C204255255, C204255255,
+ C204255255, C204255255, C204255255, C204255255,
+ C204255255, C204255255, new Color(255, 204, 255),
+ C255204204, C255204204, C255204204, C255204204,
+ C255204204, C255204204, C255204204, C255204204,
+ C255204204, new Color(255, 255, 204), C204255204,
+ C204255204, C204255204, C204255204, C204255204,
+ C204255204, C204255204, C204255204, C204255204,
+
+ // Row 2
+ C204204204, new Color(153, 255, 255), new Color(153, 204, 255), C153153255,
+ C153153255, C153153255, C153153255, C153153255,
+ C153153255, C153153255, new Color(204, 153, 255),
+ new Color(255, 153, 255),
+ new Color(255, 153, 204), C255153153, C255153153,
+ C255153153, C255153153, C255153153, C255153153,
+ C255153153, new Color(255, 204, 153),
+ new Color(255, 255, 153),
+ new Color(204, 255, 153), C153255153, C153255153,
+ C153255153, C153255153, C153255153, C153255153,
+ C153255153, new Color(153, 255, 204),
+
+ // Row 3
+ C204204204, new Color(102, 255, 255), new Color(102, 204, 255),
+ new Color(102, 153, 255), C102102255, C102102255,
+ C102102255, C102102255, C102102255,
+ new Color(153, 102, 255),
+ new Color(204, 102, 255),
+ new Color(255, 102, 255),
+ new Color(255, 102, 204),
+ new Color(255, 102, 153), C255102102, C255102102,
+ C255102102, C255102102, C255102102,
+ new Color(255, 153, 102),
+ new Color(255, 204, 102),
+ new Color(255, 255, 102),
+ new Color(204, 255, 102),
+ new Color(153, 255, 102), C102255102, C102255102,
+ C102255102, C102255102, C102255102,
+ new Color(102, 255, 153),
+ new Color(102, 255, 204),
+
+ // Row 4
+ new Color(153, 153, 153), new Color(51, 255, 255), new Color(51, 204, 255),
+ new Color(51, 153, 255), new Color(51, 102, 255),
+ C051051255, C051051255, C051051255,
+ new Color(102, 51, 255), new Color(153, 51, 255),
+ new Color(204, 51, 255), new Color(255, 51, 255),
+ new Color(255, 51, 204), new Color(255, 51, 153),
+ new Color(255, 51, 102), C255051051, C255051051,
+ C255051051, new Color(255, 102, 51),
+ new Color(255, 153, 51), new Color(255, 204, 51),
+ new Color(255, 255, 51), new Color(204, 255, 51),
+ new Color(153, 255, 51), new Color(102, 255, 51),
+ C051255051, C051255051, C051255051,
+ new Color(51, 255, 102), new Color(51, 255, 153),
+ new Color(51, 255, 204),
+
+ // Row 5
+ new Color(153, 153, 153), new Color(0, 255, 255), new Color(0, 204, 255),
+ new Color(0, 153, 255), new Color(0, 102, 255),
+ new Color(0, 51, 255), new Color(0, 0, 255),
+ new Color(51, 0, 255), new Color(102, 0, 255),
+ new Color(153, 0, 255), new Color(204, 0, 255),
+ new Color(255, 0, 255), new Color(255, 0, 204),
+ new Color(255, 0, 153), new Color(255, 0, 102),
+ new Color(255, 0, 51), new Color(255, 0, 0),
+ new Color(255, 51, 0), new Color(255, 102, 0),
+ new Color(255, 153, 0), new Color(255, 204, 0),
+ new Color(255, 255, 0), new Color(204, 255, 0),
+ new Color(153, 255, 0), new Color(102, 255, 0),
+ new Color(51, 255, 0), new Color(0, 255, 0),
+ new Color(0, 255, 51), new Color(0, 255, 102),
+ new Color(0, 255, 153), new Color(0, 255, 204),
+
+ // Row 6
+ new Color(102, 102, 102), C000204204, C000204204, new Color(0, 153, 204),
+ new Color(0, 102, 204), new Color(0, 51, 204),
+ new Color(0, 0, 204), new Color(51, 0, 204),
+ new Color(102, 0, 204), new Color(153, 0, 204),
+ C204000204, C204000204, C204000204,
+ new Color(204, 0, 153), new Color(204, 0, 102),
+ new Color(204, 0, 51), new Color(204, 0, 0),
+ new Color(204, 51, 0), new Color(204, 102, 0),
+ new Color(204, 153, 0), C204204000, C204204000,
+ C204204000, new Color(153, 204, 0),
+ new Color(102, 204, 0), new Color(51, 204, 0),
+ new Color(0, 204, 0), new Color(0, 204, 51),
+ new Color(0, 204, 102), new Color(0, 204, 153),
+ new Color(0, 204, 204),
+
+ // Row 7
+ new Color(102, 102, 102), C000153153, C000153153, C000153153,
+ new Color(0, 102, 153), new Color(0, 51, 153),
+ new Color(0, 0, 153), new Color(51, 0, 153),
+ new Color(102, 0, 153), C153000153, C153000153,
+ C153000153, C153000153, C153000153,
+ new Color(153, 0, 102), new Color(153, 0, 51),
+ new Color(153, 0, 0), new Color(153, 51, 0),
+ new Color(153, 102, 0), C153153000, C153153000,
+ C153153000, C153153000, C153153000,
+ new Color(102, 153, 0), new Color(51, 153, 0),
+ new Color(0, 153, 0), new Color(0, 153, 51),
+ new Color(0, 153, 102), C000153153, C000153153,
+
+ // Row 8
+ new Color(51, 51, 51), C000102102, C000102102, C000102102, C000102102,
+ new Color(0, 51, 102), new Color(0, 0, 102),
+ new Color(51, 0, 102), C102000102, C102000102,
+ C102000102, C102000102, C102000102, C102000102,
+ C102000102, new Color(102, 0, 51),
+ new Color(102, 0, 0), new Color(102, 51, 0),
+ C102102000, C102102000, C102102000, C102102000,
+ C102102000, C102102000, C102102000,
+ new Color(51, 102, 0), new Color(0, 102, 0),
+ new Color(0, 102, 51), C000102102, C000102102,
+ C000102102,
+
+ // Row 9.
+ Color.BLACK, C000051051, C000051051, C000051051, C000051051, C000051051,
+ new Color(0, 0, 51), C051000051, C051000051,
+ C051000051, C051000051, C051000051, C051000051,
+ C051000051, C051000051, C051000051,
+ new Color(51, 0, 0), C051051000, C051051000,
+ C051051000, C051051000, C051051000, C051051000,
+ C051051000, C051051000, new Color(0, 51, 0),
+ C000051051, C000051051, C000051051, C000051051,
+ new Color(51, 51, 51)
+ };
+
+ /**
+ * Creates a new MainSwatchPanel object.
+ */
+ MainSwatchPanel()
+ {
+ super();
+ numCols = 31;
+ numRows = 9;
+ initializeColors();
+ revalidate();
+ }
+
+ /**
+ * This method returns the color for the given position.
+ *
+ * @param x The x location for the position.
+ * @param y The y location for the position.
+ *
+ * @return The color for the given position.
+ */
+ public Color getColorForPosition(int x, int y)
+ {
+ if (x % (cellWidth + gap) > cellWidth
+ || y % (cellHeight + gap) > cellHeight)
+ // position is located in gap.
+ return null;
+
+ int row = y / (cellHeight + gap);
+ int col = x / (cellWidth + gap);
+ return colors[row * numCols + col];
+ }
+
+ /**
+ * This method initializes the colors for the main swatch panel.
+ */
+ protected void initializeColors()
+ {
+ // Unnecessary
+ }
+
+ /**
+ * This method paints the main graphics panel with the given Graphics
+ * object.
+ *
+ * @param graphics The Graphics object to paint with.
+ */
+ public void paint(Graphics graphics)
+ {
+ int index = 0;
+ Insets insets = getInsets();
+ int currX = insets.left;
+ int currY = insets.top;
+ Color saved = graphics.getColor();
+
+ for (int i = 0; i < numRows; i++)
+ {
+ for (int j = 0; j < numCols; j++)
+ {
+ graphics.setColor(colors[index++]);
+ graphics.fill3DRect(currX, currY, cellWidth, cellHeight, true);
+ currX += gap + cellWidth;
+ }
+ currX = insets.left;
+ currY += gap + cellHeight;
+ }
+ graphics.setColor(saved);
+ }
+
+ /**
+ * This method returns the tooltip text for the given MouseEvent.
+ *
+ * @param e The MouseEvent to find tooltip text for.
+ *
+ * @return The tooltip text.
+ */
+ public String getToolTipText(MouseEvent e)
+ {
+ Color c = getColorForPosition(e.getX(), e.getY());
+ if (c == null)
+ return null;
+ return (c.getRed() + "," + c.getGreen() + "," + c.getBlue());
+ }
+ }
+
+ /**
+ * This class is the recent swatch panel. It holds recently selected colors.
+ */
+ public static class RecentSwatchPanel extends SwatchPanel
+ {
+ /** The array for storing recently stored colors. */
+ Color[] colors;
+
+ /** The default color. */
+ public static final Color defaultColor = Color.GRAY;
+
+ /** The index of the array that is the start. */
+ int start = 0;
+
+ /**
+ * Creates a new RecentSwatchPanel object.
+ */
+ RecentSwatchPanel()
+ {
+ super();
+ numCols = 5;
+ numRows = 7;
+ initializeColors();
+ revalidate();
+ }
+
+ /**
+ * This method returns the color for the given position.
+ *
+ * @param x The x coordinate of the position.
+ * @param y The y coordinate of the position.
+ *
+ * @return The color for the given position.
+ */
+ public Color getColorForPosition(int x, int y)
+ {
+ if (x % (cellWidth + gap) > cellWidth
+ || y % (cellHeight + gap) > cellHeight)
+ // position is located in gap.
+ return null;
+
+ int row = y / (cellHeight + gap);
+ int col = x / (cellWidth + gap);
+
+ return colors[getIndexForCell(row, col)];
+ }
+
+ /**
+ * This method initializes the colors for the recent swatch panel.
+ */
+ protected void initializeColors()
+ {
+ colors = new Color[numRows * numCols];
+ for (int i = 0; i < colors.length; i++)
+ colors[i] = defaultColor;
+ }
+
+ /**
+ * This method returns the array index for the given row and column.
+ *
+ * @param row The row.
+ * @param col The column.
+ *
+ * @return The array index for the given row and column.
+ */
+ private int getIndexForCell(int row, int col)
+ {
+ return ((row * numCols) + col + start) % (numRows * numCols);
+ }
+
+ /**
+ * This method adds the given color to the beginning of the swatch panel.
+ *
+ * @param c The color to add.
+ */
+ private void addColorToQueue(Color c)
+ {
+ if (--start == -1)
+ start = numRows * numCols - 1;
+
+ colors[start] = c;
+ }
+
+ /**
+ * This method paints the panel with the given Graphics object.
+ *
+ * @param g The Graphics object to paint with.
+ */
+ public void paint(Graphics g)
+ {
+ Color saved = g.getColor();
+ Insets insets = getInsets();
+ int currX = insets.left;
+ int currY = insets.top;
+
+ for (int i = 0; i < numRows; i++)
+ {
+ for (int j = 0; j < numCols; j++)
+ {
+ g.setColor(colors[getIndexForCell(i, j)]);
+ g.fill3DRect(currX, currY, cellWidth, cellHeight, true);
+ currX += cellWidth + gap;
+ }
+ currX = insets.left;
+ currY += cellWidth + gap;
+ }
+ }
+
+ /**
+ * This method returns the tooltip text for the given MouseEvent.
+ *
+ * @param e The MouseEvent.
+ *
+ * @return The tooltip text.
+ */
+ public String getToolTipText(MouseEvent e)
+ {
+ Color c = getColorForPosition(e.getX(), e.getY());
+ if (c == null)
+ return null;
+ return c.getRed() + "," + c.getGreen() + "," + c.getBlue();
+ }
+ }
+
+ /**
+ * This class handles mouse events for the two swatch panels.
+ */
+ class MouseHandler extends MouseAdapter
+ {
+ /**
+ * This method is called whenever the mouse is pressed.
+ *
+ * @param e The MouseEvent.
+ */
+ public void mousePressed(MouseEvent e)
+ {
+ SwatchPanel panel = (SwatchPanel) e.getSource();
+ Color c = panel.getColorForPosition(e.getX(), e.getY());
+ recentPalette.addColorToQueue(c);
+ DefaultSwatchChooserPanel.this.getColorSelectionModel().setSelectedColor(c);
+ DefaultSwatchChooserPanel.this.repaint();
+ }
+ }
+
+ /**
+ * This is the layout manager for the main panel.
+ */
+ static class MainPanelLayout implements LayoutManager
+ {
+ /**
+ * This method is called when a new component is added to the container.
+ *
+ * @param name The name of the component.
+ * @param comp The added component.
+ */
+ public void addLayoutComponent(String name, Component comp)
+ {
+ }
+
+ /**
+ * This method is called to set the size and position of the child
+ * components for the given container.
+ *
+ * @param parent The container to lay out.
+ */
+ public void layoutContainer(Container parent)
+ {
+ Component[] comps = parent.getComponents();
+ Insets insets = parent.getInsets();
+ Dimension[] pref = new Dimension[comps.length];
+
+ int xpos = 0;
+ int ypos = 0;
+ int maxHeight = 0;
+ int totalWidth = 0;
+
+ for (int i = 0; i < comps.length; i++)
+ {
+ pref[i] = comps[i].getPreferredSize();
+ if (pref[i] == null)
+ return;
+ maxHeight = Math.max(maxHeight, pref[i].height);
+ totalWidth += pref[i].width;
+ }
+
+ ypos = (parent.getSize().height - maxHeight) / 2 + insets.top;
+ xpos = insets.left + (parent.getSize().width - totalWidth) / 2;
+
+ for (int i = 0; i < comps.length; i++)
+ {
+ if (pref[i] == null)
+ continue;
+ comps[i].setBounds(xpos, ypos, pref[i].width, pref[i].height);
+ xpos += pref[i].width;
+ }
+ }
+
+ /**
+ * This method is called when a component is removed from the container.
+ *
+ * @param comp The component that was removed.
+ */
+ public void removeLayoutComponent(Component comp)
+ {
+ }
+
+ /**
+ * This methods calculates the minimum layout size for the container.
+ *
+ * @param parent The container.
+ *
+ * @return The minimum layout size.
+ */
+ public Dimension minimumLayoutSize(Container parent)
+ {
+ return preferredLayoutSize(parent);
+ }
+
+ /**
+ * This method returns the preferred layout size for the given container.
+ *
+ * @param parent The container.
+ *
+ * @return The preferred layout size.
+ */
+ public Dimension preferredLayoutSize(Container parent)
+ {
+ int xmax = 0;
+ int ymax = 0;
+
+ Component[] comps = parent.getComponents();
+ Dimension pref;
+
+ for (int i = 0; i < comps.length; i++)
+ {
+ pref = comps[i].getPreferredSize();
+ if (pref == null)
+ continue;
+ xmax += pref.width;
+ ymax = Math.max(ymax, pref.height);
+ }
+
+ Insets insets = parent.getInsets();
+
+ return new Dimension(insets.left + insets.right + xmax,
+ insets.top + insets.bottom + ymax);
+ }
+ }
+
+ /**
+ * This is the layout manager for the recent swatch panel.
+ */
+ static class RecentPanelLayout implements LayoutManager
+ {
+ /**
+ * This method is called when a component is added to the container.
+ *
+ * @param name The name of the component.
+ * @param comp The added component.
+ */
+ public void addLayoutComponent(String name, Component comp)
+ {
+ // Nothing needs to be done.
+ }
+
+ /**
+ * This method sets the size and position of the child components of the
+ * given container.
+ *
+ * @param parent The container to lay out.
+ */
+ public void layoutContainer(Container parent)
+ {
+ Component[] comps = parent.getComponents();
+ Dimension parentSize = parent.getSize();
+ Insets insets = parent.getInsets();
+ int currY = insets.top;
+ Dimension pref;
+
+ for (int i = 0; i < comps.length; i++)
+ {
+ pref = comps[i].getPreferredSize();
+ if (pref == null)
+ continue;
+ comps[i].setBounds(insets.left, currY, pref.width, pref.height);
+ currY += pref.height;
+ }
+ }
+
+ /**
+ * This method calculates the minimum layout size for the given container.
+ *
+ * @param parent The container.
+ *
+ * @return The minimum layout size.
+ */
+ public Dimension minimumLayoutSize(Container parent)
+ {
+ return preferredLayoutSize(parent);
+ }
+
+ /**
+ * This method calculates the preferred layout size for the given
+ * container.
+ *
+ * @param parent The container.
+ *
+ * @return The preferred layout size.
+ */
+ public Dimension preferredLayoutSize(Container parent)
+ {
+ int width = 0;
+ int height = 0;
+ Insets insets = parent.getInsets();
+ Component[] comps = parent.getComponents();
+ Dimension pref;
+ for (int i = 0; i < comps.length; i++)
+ {
+ pref = comps[i].getPreferredSize();
+ if (pref != null)
+ {
+ width = Math.max(width, pref.width);
+ height += pref.height;
+ }
+ }
+
+ return new Dimension(width + insets.left + insets.right,
+ height + insets.top + insets.bottom);
+ }
+
+ /**
+ * This method is called whenever a component is removed from the
+ * container.
+ *
+ * @param comp The removed component.
+ */
+ public void removeLayoutComponent(Component comp)
+ {
+ // Nothing needs to be done.
+ }
+ }
+
+ /**
+ * Creates a new DefaultSwatchChooserPanel object.
+ */
+ DefaultSwatchChooserPanel()
+ {
+ super();
+ }
+
+ /**
+ * This method updates the chooser panel with the new value from the
+ * JColorChooser.
+ */
+ public void updateChooser()
+ {
+ }
+
+ /**
+ * This method builds the chooser panel.
+ */
+ protected void buildChooser()
+ {
+ // The structure of the swatch panel is:
+ // One large panel (minus the insets).
+ // Inside that panel, there are two panels, one holds the palette.
+ // The other holds the label and the recent colors palette.
+ // The two palettes are two custom swatch panels.
+ setLayout(new MainPanelLayout());
+
+ JPanel mainPaletteHolder = new JPanel();
+ JPanel recentPaletteHolder = new JPanel();
+
+ mainPalette = new MainSwatchPanel();
+ recentPalette = new RecentSwatchPanel();
+ JLabel label = new JLabel("Recent:");
+
+ mouseHandler = new MouseHandler();
+ mainPalette.addMouseListener(mouseHandler);
+ recentPalette.addMouseListener(mouseHandler);
+
+ mainPaletteHolder.setLayout(new BorderLayout());
+ mainPaletteHolder.add(mainPalette, BorderLayout.CENTER);
+
+ recentPaletteHolder.setLayout(new RecentPanelLayout());
+ recentPaletteHolder.add(label);
+ recentPaletteHolder.add(recentPalette);
+
+ JPanel main = new JPanel();
+ main.add(mainPaletteHolder);
+ main.add(recentPaletteHolder);
+
+ this.add(main);
+ }
+
+ /**
+ * This method removes the chooser panel from the JColorChooser.
+ *
+ * @param chooser The JColorChooser this panel is being removed from.
+ */
+ public void uninstallChooserPanel(JColorChooser chooser)
+ {
+ recentPalette = null;
+ mainPalette = null;
+
+ removeAll();
+ super.uninstallChooserPanel(chooser);
+ }
+
+ /**
+ * This method returns the JTabbedPane displayed name.
+ *
+ * @return The name displayed in the JTabbedPane.
+ */
+ public String getDisplayName()
+ {
+ return "Swatches";
+ }
+
+ /**
+ * This method returns the small display icon.
+ *
+ * @return The small display icon.
+ */
+ public Icon getSmallDisplayIcon()
+ {
+ return null;
+ }
+
+ /**
+ * This method returns the large display icon.
+ *
+ * @return The large display icon.
+ */
+ public Icon getLargeDisplayIcon()
+ {
+ return null;
+ }
+
+ /**
+ * This method paints the chooser panel with the given Graphics object.
+ *
+ * @param g The Graphics object to paint with.
+ */
+ public void paint(Graphics g)
+ {
+ super.paint(g);
+ }
+
+ /**
+ * This method returns the tooltip text for the given MouseEvent.
+ *
+ * @param e The MouseEvent.
+ *
+ * @return The tooltip text.
+ */
+ public String getToolTipText(MouseEvent e)
+ {
+ return null;
+ }
+}
Index: javax/swing/plaf/basic/BasicArrowButton.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicArrowButton.java,v
retrieving revision 1.1.2.4
diff -u -r1.1.2.4 BasicArrowButton.java
--- javax/swing/plaf/basic/BasicArrowButton.java 25 Aug 2004 17:52:11 -0000 1.1.2.4
+++ javax/swing/plaf/basic/BasicArrowButton.java 25 Aug 2004 21:35:37 -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/BasicColorChooserUI.java
===================================================================
RCS file: javax/swing/plaf/basic/BasicColorChooserUI.java
diff -N javax/swing/plaf/basic/BasicColorChooserUI.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ javax/swing/plaf/basic/BasicColorChooserUI.java 25 Aug 2004 21:35:37 -0000
@@ -0,0 +1,338 @@
+/* BasicColorChooserUI.java
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.plaf.basic;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Insets;
+import java.awt.LayoutManager;
+import java.awt.Rectangle;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import javax.swing.JColorChooser;
+import javax.swing.JComponent;
+import javax.swing.JPanel;
+import javax.swing.JTabbedPane;
+import javax.swing.UIDefaults;
+import javax.swing.UIManager;
+import javax.swing.colorchooser.AbstractColorChooserPanel;
+import javax.swing.colorchooser.ColorChooserComponentFactory;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.plaf.ColorChooserUI;
+import javax.swing.plaf.ComponentUI;
+
+
+/**
+ * This is the UI Class for the JColorChooser in the Basic Look and Feel.
+ */
+public class BasicColorChooserUI extends ColorChooserUI
+{
+ /**
+ * This helper class handles property changes from the JColorChooser.
+ */
+ public class PropertyHandler implements PropertyChangeListener
+ {
+ /**
+ * This method is called when any of the properties of the JColorChooser
+ * change.
+ *
+ * @param e The PropertyChangeEvent.
+ */
+ public void propertyChange(PropertyChangeEvent e)
+ {
+ if (e.getPropertyName() == JColorChooser.CHOOSER_PANELS_PROPERTY)
+ makeTabs(chooser.getChooserPanels());
+ else if (e.getPropertyName() == JColorChooser.PREVIEW_PANEL_PROPERTY)
+ updatePreviewPanel(chooser.getPreviewPanel());
+ else if (e.getPropertyName() == JColorChooser.SELECTION_MODEL_PROPERTY)
+ ((AbstractColorChooserPanel) pane.getSelectedComponent())
+ .updateChooser();
+
+ chooser.repaint();
+ }
+ }
+
+ /**
+ * This is a helper class that listens to the Model of the JColorChooser for
+ * color change events so it can update the preview panel.
+ */
+ private class PreviewListener implements ChangeListener
+ {
+ /**
+ * This method is called whenever the JColorChooser's color changes.
+ *
+ * @param e The ChangeEvent.
+ */
+ public void stateChanged(ChangeEvent e)
+ {
+ if (pane != null)
+ {
+ AbstractColorChooserPanel panel = (AbstractColorChooserPanel) pane
+ .getSelectedComponent();
+ if (panel != null)
+ panel.updateChooser();
+ }
+ chooser.repaint();
+ }
+ }
+
+ /**
+ * This helper class listens to the JTabbedPane that is used for tab
+ * changes.
+ */
+ private class TabPaneListener implements ChangeListener
+ {
+ /**
+ * This method is called whenever a different tab is selected in the
+ * JTabbedPane.
+ *
+ * @param e The ChangeEvent.
+ */
+ public void stateChanged(ChangeEvent e)
+ {
+ // Need to do this because we don't update all the tabs when they're not
+ // visible, so they are not informed of new colors when they're hidden.
+ AbstractColorChooserPanel comp = (AbstractColorChooserPanel) pane
+ .getSelectedComponent();
+ comp.updateChooser();
+ }
+ }
+
+ /** An array of default choosers to use in the JColorChooser. */
+ protected AbstractColorChooserPanel[] defaultChoosers;
+
+ /** The listener for the preview panel. */
+ protected ChangeListener previewListener;
+
+ /** The PropertyChangeListener for the JColorChooser. */
+ protected PropertyChangeListener propertyChangeListener;
+
+ /** The JColorChooser. */
+ private JColorChooser chooser;
+
+ /** The JTabbedPane that is used. */
+ private JTabbedPane pane;
+
+ /** The Container that holds the preview panel. */
+ private Container prevContainer;
+
+ /**
+ * Creates a new BasicColorChooserUI object.
+ */
+ public BasicColorChooserUI()
+ {
+ super();
+ }
+
+ /**
+ * This method creates a new UI Component for the given JComponent.
+ *
+ * @param c The JComponent to create an UI for.
+ *
+ * @return A new BasicColorChooserUI.
+ */
+ public static ComponentUI createUI(JComponent c)
+ {
+ return new BasicColorChooserUI();
+ }
+
+ /**
+ * This method creates the default chooser panels for the JColorChooser.
+ *
+ * @return The default chooser panels.
+ */
+ protected AbstractColorChooserPanel[] createDefaultChoosers()
+ {
+ return ColorChooserComponentFactory.getDefaultChooserPanels();
+ }
+
+ /**
+ * This method installs the UI Component for the given JComponent.
+ *
+ * @param c The JComponent to install this UI for.
+ */
+ public void installUI(JComponent c)
+ {
+ if (c instanceof JColorChooser)
+ {
+ chooser = (JColorChooser) c;
+ chooser.setLayout(new BorderLayout());
+
+ // Do this first, so we avoid doing work for property change events.
+ defaultChoosers = createDefaultChoosers();
+ chooser.setChooserPanels(defaultChoosers);
+ pane = new JTabbedPane();
+
+ pane.addChangeListener(new ChangeListener()
+ {
+ public void stateChanged(ChangeEvent e)
+ {
+ pane.repaint();
+ }
+ });
+
+ makeTabs(defaultChoosers);
+
+ chooser.add(pane, BorderLayout.NORTH);
+
+ installPreviewPanel();
+
+ installDefaults();
+ installListeners();
+ }
+ }
+
+ /**
+ * This method adds tabs to the JTabbedPane for the chooserPanels defined in
+ * the JColorChooser.
+ *
+ * @param panels The Panels that need tabs to be made for them.
+ */
+ private void makeTabs(AbstractColorChooserPanel[] panels)
+ {
+ pane.removeAll();
+ for (int i = 0; i < panels.length; i++)
+ pane.addTab(panels[i].getDisplayName(), panels[i].getSmallDisplayIcon(),
+ panels[i]);
+ }
+
+ /**
+ * This method uninstalls this UI for the given JComponent.
+ *
+ * @param c The JComponent that will have this UI removed.
+ */
+ public void uninstallUI(JComponent c)
+ {
+ uninstallListeners();
+ uninstallDefaults();
+
+ pane = null;
+ chooser = null;
+ }
+
+ /**
+ * This method installs the preview panel for the JColorChooser.
+ */
+ protected void installPreviewPanel()
+ {
+ updatePreviewPanel(ColorChooserComponentFactory.getPreviewPanel());
+ }
+
+ /**
+ * This is a helper method that swaps the existing preview panel with the
+ * given panel.
+ *
+ * @param preview The new preview panel.
+ */
+ private void updatePreviewPanel(JComponent preview)
+ {
+ if (prevContainer == null)
+ {
+ prevContainer = new JPanel();
+ prevContainer.setLayout(new BorderLayout());
+ chooser.add(prevContainer, BorderLayout.CENTER);
+ }
+ prevContainer.removeAll();
+ prevContainer.add(preview, BorderLayout.CENTER);
+ }
+
+ /**
+ * This method installs the default properties given by the Basic Look and
+ * Feel.
+ */
+ protected void installDefaults()
+ {
+ UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+
+ chooser.setFont(defaults.getFont("ColorChooser.font"));
+ chooser.setForeground(defaults.getColor("ColorChooser.foreground"));
+ chooser.setBackground(defaults.getColor("ColorChooser.background"));
+ }
+
+ /**
+ * This method uninstalls the default properties given by the Basic Look and
+ * Feel.
+ */
+ protected void uninstallDefaults()
+ {
+ chooser.setBackground(null);
+ chooser.setForeground(null);
+ chooser.setFont(null);
+ }
+
+ /**
+ * This method installs any listeners required for this UI to function.
+ */
+ protected void installListeners()
+ {
+ propertyChangeListener = createPropertyChangeListener();
+ previewListener = new PreviewListener();
+
+ chooser.addPropertyChangeListener(propertyChangeListener);
+ chooser.getSelectionModel().addChangeListener(previewListener);
+
+ pane.addChangeListener(new TabPaneListener());
+ }
+
+ /**
+ * This method creates the PropertyChangeListener used for listening to the
+ * JColorChooser.
+ *
+ * @return A PropertyChangeListener.
+ */
+ protected PropertyChangeListener createPropertyChangeListener()
+ {
+ return new PropertyHandler();
+ }
+
+ /**
+ * This method uninstalls any listeners that were previously installed by
+ * the UI.
+ */
+ protected void uninstallListeners()
+ {
+ chooser.removePropertyChangeListener(propertyChangeListener);
+ chooser.getSelectionModel().removeChangeListener(previewListener);
+
+ previewListener = null;
+ propertyChangeListener = null;
+ }
+}
Index: javax/swing/plaf/basic/BasicSliderUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicSliderUI.java,v
retrieving revision 1.1.2.12
diff -u -r1.1.2.12 BasicSliderUI.java
--- javax/swing/plaf/basic/BasicSliderUI.java 16 Jul 2004 21:46:35 -0000 1.1.2.12
+++ javax/swing/plaf/basic/BasicSliderUI.java 25 Aug 2004 21:35:38 -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: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/Attic/BasicSpinnerUI.java,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 BasicSpinnerUI.java
--- javax/swing/plaf/basic/BasicSpinnerUI.java 11 Aug 2004 13:19:05 -0000 1.1.2.1
+++ javax/swing/plaf/basic/BasicSpinnerUI.java 25 Aug 2004 21:35:38 -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;
}
-
}
Index: testsuite/Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/libjava/testsuite/Makefile.in,v
retrieving revision 1.53.8.4
diff -u -r1.53.8.4 Makefile.in
--- testsuite/Makefile.in 29 Jul 2004 16:02:28 -0000 1.53.8.4
+++ testsuite/Makefile.in 25 Aug 2004 21:35:39 -0000
@@ -177,7 +177,7 @@
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
-TAR = gtar
+TAR = tar
GZIP_ENV = --best
all: all-redirect
.SUFFIXES: