< prev index next >
src/java.desktop/share/classes/javax/swing/JSpinner.java
Print this page
*** 51,78 ****
* elements. The user may also be allowed to type a (legal) value directly
* into the spinner. Although combo boxes provide similar functionality,
* spinners are sometimes preferred because they don't require a drop down list
* that can obscure important data.
* <p>
! * A <code>JSpinner</code>'s sequence value is defined by its
! * <code>SpinnerModel</code>.
! * The <code>model</code> can be specified as a constructor argument and
! * changed with the <code>model</code> property. <code>SpinnerModel</code>
! * classes for some common types are provided: <code>SpinnerListModel</code>,
! * <code>SpinnerNumberModel</code>, and <code>SpinnerDateModel</code>.
* <p>
! * A <code>JSpinner</code> has a single child component that's
* responsible for displaying
* and potentially changing the current element or <i>value</i> of
! * the model, which is called the <code>editor</code>. The editor is created
! * by the <code>JSpinner</code>'s constructor and can be changed with the
! * <code>editor</code> property. The <code>JSpinner</code>'s editor stays
! * in sync with the model by listening for <code>ChangeEvent</code>s. If the
! * user has changed the value displayed by the <code>editor</code> it is
! * possible for the <code>model</code>'s value to differ from that of
! * the <code>editor</code>. To make sure the <code>model</code> has the same
! * value as the editor use the <code>commitEdit</code> method, eg:
* <pre>
* try {
* spinner.commitEdit();
* }
* catch (ParseException pe) {
--- 51,78 ----
* elements. The user may also be allowed to type a (legal) value directly
* into the spinner. Although combo boxes provide similar functionality,
* spinners are sometimes preferred because they don't require a drop down list
* that can obscure important data.
* <p>
! * A {@code JSpinner}'s sequence value is defined by its
! * {@code SpinnerModel}.
! * The {@code model} can be specified as a constructor argument and
! * changed with the {@code model} property. {@code SpinnerModel}
! * classes for some common types are provided: {@code SpinnerListModel},
! * {@code SpinnerNumberModel}, and {@code SpinnerDateModel}.
* <p>
! * A {@code JSpinner} has a single child component that's
* responsible for displaying
* and potentially changing the current element or <i>value</i> of
! * the model, which is called the {@code editor}. The editor is created
! * by the {@code JSpinner}'s constructor and can be changed with the
! * {@code editor} property. The {@code JSpinner}'s editor stays
! * in sync with the model by listening for {@code ChangeEvent}s. If the
! * user has changed the value displayed by the {@code editor} it is
! * possible for the {@code model}'s value to differ from that of
! * the {@code editor}. To make sure the {@code model} has the same
! * value as the editor use the {@code commitEdit} method, eg:
* <pre>
* try {
* spinner.commitEdit();
* }
* catch (ParseException pe) {
*** 103,113 ****
* Serialized objects of this class will not be compatible with
* future Swing releases. The current serialization support is
* appropriate for short term storage or RMI between applications running
* the same version of Swing. As of 1.4, support for long term storage
* of all JavaBeans™
! * has been added to the <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}.
*
* @beaninfo
* attribute: isContainer false
* description: A single line input field that lets the user select a
--- 103,113 ----
* Serialized objects of this class will not be compatible with
* future Swing releases. The current serialization support is
* appropriate for short term storage or RMI between applications running
* the same version of Swing. As of 1.4, support for long term storage
* of all JavaBeans™
! * has been added to the {@code java.beans} package.
* Please see {@link java.beans.XMLEncoder}.
*
* @beaninfo
* attribute: isContainer false
* description: A single line input field that lets the user select a
*** 160,191 ****
updateUI();
}
/**
! * Constructs a spinner with an <code>Integer SpinnerNumberModel</code>
* with initial value 0 and no minimum or maximum limits.
*/
public JSpinner() {
this(new SpinnerNumberModel());
}
/**
* Returns the look and feel (L&F) object that renders this component.
*
! * @return the <code>SpinnerUI</code> object that renders this component
*/
public SpinnerUI getUI() {
return (SpinnerUI)ui;
}
/**
* Sets the look and feel (L&F) object that renders this component.
*
! * @param ui the <code>SpinnerUI</code> L&F object
* @see UIDefaults#getUI
*/
public void setUI(SpinnerUI ui) {
super.setUI(ui);
}
--- 160,191 ----
updateUI();
}
/**
! * Constructs a spinner with an {@code Integer SpinnerNumberModel}
* with initial value 0 and no minimum or maximum limits.
*/
public JSpinner() {
this(new SpinnerNumberModel());
}
/**
* Returns the look and feel (L&F) object that renders this component.
*
! * @return the {@code SpinnerUI} object that renders this component
*/
public SpinnerUI getUI() {
return (SpinnerUI)ui;
}
/**
* Sets the look and feel (L&F) object that renders this component.
*
! * @param ui the {@code SpinnerUI} L&F object
* @see UIDefaults#getUI
*/
public void setUI(SpinnerUI ui) {
super.setUI(ui);
}
*** 216,241 ****
}
/**
* This method is called by the constructors to create the
! * <code>JComponent</code>
* that displays the current value of the sequence. The editor may
* also allow the user to enter an element of the sequence directly.
! * An editor must listen for <code>ChangeEvents</code> on the
! * <code>model</code> and keep the value it displays
* in sync with the value of the model.
* <p>
* Subclasses may override this method to add support for new
! * <code>SpinnerModel</code> classes. Alternatively one can just
! * replace the editor created here with the <code>setEditor</code>
* method. The default mapping from model type to editor is:
* <ul>
! * <li> <code>SpinnerNumberModel => JSpinner.NumberEditor</code>
! * <li> <code>SpinnerDateModel => JSpinner.DateEditor</code>
! * <li> <code>SpinnerListModel => JSpinner.ListEditor</code>
! * <li> <i>all others</i> => <code>JSpinner.DefaultEditor</code>
* </ul>
*
* @return a component that displays the current value of the sequence
* @param model the value of getModel
* @see #getModel
--- 216,241 ----
}
/**
* This method is called by the constructors to create the
! * {@code JComponent}
* that displays the current value of the sequence. The editor may
* also allow the user to enter an element of the sequence directly.
! * An editor must listen for {@code ChangeEvents} on the
! * {@code model} and keep the value it displays
* in sync with the value of the model.
* <p>
* Subclasses may override this method to add support for new
! * {@code SpinnerModel} classes. Alternatively one can just
! * replace the editor created here with the {@code setEditor}
* method. The default mapping from model type to editor is:
* <ul>
! * <li> {@code SpinnerNumberModel => JSpinner.NumberEditor}
! * <li> {@code SpinnerDateModel => JSpinner.DateEditor}
! * <li> {@code SpinnerListModel => JSpinner.ListEditor}
! * <li> <i>all others</i> {@code => JSpinner.DefaultEditor}
* </ul>
*
* @return a component that displays the current value of the sequence
* @param model the value of getModel
* @see #getModel
*** 258,280 ****
/**
* Changes the model that represents the value of this spinner.
* If the editor property has not been explicitly set,
! * the editor property is (implicitly) set after the <code>"model"</code>
! * <code>PropertyChangeEvent</code> has been fired. The editor
! * property is set to the value returned by <code>createEditor</code>,
* as in:
* <pre>
* setEditor(createEditor(model));
* </pre>
*
! * @param model the new <code>SpinnerModel</code>
* @see #getModel
* @see #getEditor
* @see #setEditor
! * @throws IllegalArgumentException if model is <code>null</code>
*
* @beaninfo
* bound: true
* attribute: visualUpdate true
* description: Model that represents the value of this spinner.
--- 258,280 ----
/**
* Changes the model that represents the value of this spinner.
* If the editor property has not been explicitly set,
! * the editor property is (implicitly) set after the {@code "model"}
! * {@code PropertyChangeEvent} has been fired. The editor
! * property is set to the value returned by {@code createEditor},
* as in:
* <pre>
* setEditor(createEditor(model));
* </pre>
*
! * @param model the new {@code SpinnerModel}
* @see #getModel
* @see #getEditor
* @see #setEditor
! * @throws IllegalArgumentException if model is {@code null}
*
* @beaninfo
* bound: true
* attribute: visualUpdate true
* description: Model that represents the value of this spinner.
*** 300,310 ****
}
}
/**
! * Returns the <code>SpinnerModel</code> that defines
* this spinners sequence of values.
*
* @return the value of the model property
* @see #setModel
*/
--- 300,310 ----
}
}
/**
! * Returns the {@code SpinnerModel} that defines
* this spinners sequence of values.
*
* @return the value of the model property
* @see #setModel
*/
*** 313,329 ****
}
/**
* Returns the current value of the model, typically
! * this value is displayed by the <code>editor</code>. If the
! * user has changed the value displayed by the <code>editor</code> it is
! * possible for the <code>model</code>'s value to differ from that of
! * the <code>editor</code>, refer to the class level javadoc for examples
* of how to deal with this.
* <p>
! * This method simply delegates to the <code>model</code>.
* It is equivalent to:
* <pre>
* getModel().getValue()
* </pre>
*
--- 313,329 ----
}
/**
* Returns the current value of the model, typically
! * this value is displayed by the {@code editor}. If the
! * user has changed the value displayed by the {@code editor} it is
! * possible for the {@code model}'s value to differ from that of
! * the {@code editor}, refer to the class level javadoc for examples
* of how to deal with this.
* <p>
! * This method simply delegates to the {@code model}.
* It is equivalent to:
* <pre>
* getModel().getValue()
* </pre>
*
*** 336,390 ****
}
/**
* Changes current value of the model, typically
! * this value is displayed by the <code>editor</code>.
! * If the <code>SpinnerModel</code> implementation
* doesn't support the specified value then an
! * <code>IllegalArgumentException</code> is thrown.
* <p>
! * This method simply delegates to the <code>model</code>.
* It is equivalent to:
* <pre>
* getModel().setValue(value)
* </pre>
*
* @param value new value for the spinner
! * @throws IllegalArgumentException if <code>value</code> isn't allowed
* @see #getValue
* @see SpinnerModel#setValue
*/
public void setValue(Object value) {
getModel().setValue(value);
}
/**
* Returns the object in the sequence that comes after the object returned
! * by <code>getValue()</code>. If the end of the sequence has been reached
! * then return <code>null</code>.
! * Calling this method does not effect <code>value</code>.
* <p>
! * This method simply delegates to the <code>model</code>.
* It is equivalent to:
* <pre>
* getModel().getNextValue()
* </pre>
*
! * @return the next legal value or <code>null</code> if one doesn't exist
* @see #getValue
* @see #getPreviousValue
* @see SpinnerModel#getNextValue
*/
public Object getNextValue() {
return getModel().getNextValue();
}
/**
! * We pass <code>Change</code> events along to the listeners with the
* the slider (instead of the model itself) as the event source.
*/
private class ModelListener implements ChangeListener, Serializable {
public void stateChanged(ChangeEvent e) {
fireStateChanged();
--- 336,390 ----
}
/**
* Changes current value of the model, typically
! * this value is displayed by the {@code editor}.
! * If the {@code SpinnerModel} implementation
* doesn't support the specified value then an
! * {@code IllegalArgumentException} is thrown.
* <p>
! * This method simply delegates to the {@code model}.
* It is equivalent to:
* <pre>
* getModel().setValue(value)
* </pre>
*
* @param value new value for the spinner
! * @throws IllegalArgumentException if {@code value} isn't allowed
* @see #getValue
* @see SpinnerModel#setValue
*/
public void setValue(Object value) {
getModel().setValue(value);
}
/**
* Returns the object in the sequence that comes after the object returned
! * by {@code getValue()}. If the end of the sequence has been reached
! * then return {@code null}.
! * Calling this method does not effect {@code value}.
* <p>
! * This method simply delegates to the {@code model}.
* It is equivalent to:
* <pre>
* getModel().getNextValue()
* </pre>
*
! * @return the next legal value or {@code null} if one doesn't exist
* @see #getValue
* @see #getPreviousValue
* @see SpinnerModel#getNextValue
*/
public Object getNextValue() {
return getModel().getNextValue();
}
/**
! * We pass {@code Change} events along to the listeners with the
* the slider (instead of the model itself) as the event source.
*/
private class ModelListener implements ChangeListener, Serializable {
public void stateChanged(ChangeEvent e) {
fireStateChanged();
*** 392,410 ****
}
/**
* Adds a listener to the list that is notified each time a change
! * to the model occurs. The source of <code>ChangeEvents</code>
! * delivered to <code>ChangeListeners</code> will be this
! * <code>JSpinner</code>. Note also that replacing the model
* will not affect listeners added directly to JSpinner.
* Applications can add listeners to the model directly. In that
* case is that the source of the event would be the
! * <code>SpinnerModel</code>.
*
! * @param listener the <code>ChangeListener</code> to add
* @see #removeChangeListener
* @see #getModel
*/
public void addChangeListener(ChangeListener listener) {
if (modelListener == null) {
--- 392,410 ----
}
/**
* Adds a listener to the list that is notified each time a change
! * to the model occurs. The source of {@code ChangeEvents}
! * delivered to {@code ChangeListeners} will be this
! * {@code JSpinner}. Note also that replacing the model
* will not affect listeners added directly to JSpinner.
* Applications can add listeners to the model directly. In that
* case is that the source of the event would be the
! * {@code SpinnerModel}.
*
! * @param listener the {@code ChangeListener} to add
* @see #removeChangeListener
* @see #getModel
*/
public void addChangeListener(ChangeListener listener) {
if (modelListener == null) {
*** 415,454 ****
}
/**
! * Removes a <code>ChangeListener</code> from this spinner.
*
! * @param listener the <code>ChangeListener</code> to remove
* @see #fireStateChanged
* @see #addChangeListener
*/
public void removeChangeListener(ChangeListener listener) {
listenerList.remove(ChangeListener.class, listener);
}
/**
! * Returns an array of all the <code>ChangeListener</code>s added
* to this JSpinner with addChangeListener().
*
! * @return all of the <code>ChangeListener</code>s added or an empty
* array if no listeners have been added
* @since 1.4
*/
public ChangeListener[] getChangeListeners() {
return listenerList.getListeners(ChangeListener.class);
}
/**
! * Sends a <code>ChangeEvent</code>, whose source is this
! * <code>JSpinner</code>, to each <code>ChangeListener</code>.
! * When a <code>ChangeListener</code> has been added
* to the spinner, this method is called each time
! * a <code>ChangeEvent</code> is received from the model.
*
* @see #addChangeListener
* @see #removeChangeListener
* @see EventListenerList
*/
--- 415,454 ----
}
/**
! * Removes a {@code ChangeListener} from this spinner.
*
! * @param listener the {@code ChangeListener} to remove
* @see #fireStateChanged
* @see #addChangeListener
*/
public void removeChangeListener(ChangeListener listener) {
listenerList.remove(ChangeListener.class, listener);
}
/**
! * Returns an array of all the {@code ChangeListener}s added
* to this JSpinner with addChangeListener().
*
! * @return all of the {@code ChangeListener}s added or an empty
* array if no listeners have been added
* @since 1.4
*/
public ChangeListener[] getChangeListeners() {
return listenerList.getListeners(ChangeListener.class);
}
/**
! * Sends a {@code ChangeEvent}, whose source is this
! * {@code JSpinner}, to each {@code ChangeListener}.
! * When a {@code ChangeListener} has been added
* to the spinner, this method is called each time
! * a {@code ChangeEvent} is received from the model.
*
* @see #addChangeListener
* @see #removeChangeListener
* @see EventListenerList
*/
*** 465,486 ****
}
/**
* Returns the object in the sequence that comes
! * before the object returned by <code>getValue()</code>.
* If the end of the sequence has been reached then
! * return <code>null</code>. Calling this method does
! * not effect <code>value</code>.
* <p>
! * This method simply delegates to the <code>model</code>.
* It is equivalent to:
* <pre>
* getModel().getPreviousValue()
* </pre>
*
! * @return the previous legal value or <code>null</code>
* if one doesn't exist
* @see #getValue
* @see #getNextValue
* @see SpinnerModel#getPreviousValue
*/
--- 465,486 ----
}
/**
* Returns the object in the sequence that comes
! * before the object returned by {@code getValue()}.
* If the end of the sequence has been reached then
! * return {@code null}. Calling this method does
! * not effect {@code value}.
* <p>
! * This method simply delegates to the {@code model}.
* It is equivalent to:
* <pre>
* getModel().getPreviousValue()
* </pre>
*
! * @return the previous legal value or {@code null}
* if one doesn't exist
* @see #getValue
* @see #getNextValue
* @see SpinnerModel#getPreviousValue
*/
*** 488,509 ****
return getModel().getPreviousValue();
}
/**
! * Changes the <code>JComponent</code> that displays the current value
! * of the <code>SpinnerModel</code>. It is the responsibility of this
* method to <i>disconnect</i> the old editor from the model and to
* connect the new editor. This may mean removing the
! * old editors <code>ChangeListener</code> from the model or the
* spinner itself and adding one for the new editor.
*
* @param editor the new editor
* @see #getEditor
* @see #createEditor
* @see #getModel
! * @throws IllegalArgumentException if editor is <code>null</code>
*
* @beaninfo
* bound: true
* attribute: visualUpdate true
* description: JComponent that displays the current value of the model
--- 488,509 ----
return getModel().getPreviousValue();
}
/**
! * Changes the {@code JComponent} that displays the current value
! * of the {@code SpinnerModel}. It is the responsibility of this
* method to <i>disconnect</i> the old editor from the model and to
* connect the new editor. This may mean removing the
! * old editors {@code ChangeListener} from the model or the
* spinner itself and adding one for the new editor.
*
* @param editor the new editor
* @see #getEditor
* @see #createEditor
* @see #getModel
! * @throws IllegalArgumentException if editor is {@code null}
*
* @beaninfo
* bound: true
* attribute: visualUpdate true
* description: JComponent that displays the current value of the model
*** 539,551 ****
return editor;
}
/**
! * Commits the currently edited value to the <code>SpinnerModel</code>.
* <p>
! * If the editor is an instance of <code>DefaultEditor</code>, the
* call if forwarded to the editor, otherwise this does nothing.
*
* @throws ParseException if the currently edited value couldn't
* be committed.
*/
--- 539,551 ----
return editor;
}
/**
! * Commits the currently edited value to the {@code SpinnerModel}.
* <p>
! * If the editor is an instance of {@code DefaultEditor}, the
* call if forwarded to the editor, otherwise this does nothing.
*
* @throws ParseException if the currently edited value couldn't
* be committed.
*/
*** 576,624 ****
/**
* A simple base class for more specialized editors
* that displays a read-only view of the model's current
! * value with a <code>JFormattedTextField</code>. Subclasses
! * can configure the <code>JFormattedTextField</code> to create
* an editor that's appropriate for the type of model they
* support and they may want to override
! * the <code>stateChanged</code> and <code>propertyChanged</code>
* methods, which keep the model and the text field in sync.
* <p>
! * This class defines a <code>dismiss</code> method that removes the
! * editors <code>ChangeListener</code> from the <code>JSpinner</code>
! * that it's part of. The <code>setEditor</code> method knows about
! * <code>DefaultEditor.dismiss</code>, so if the developer
! * replaces an editor that's derived from <code>JSpinner.DefaultEditor</code>
! * its <code>ChangeListener</code> connection back to the
! * <code>JSpinner</code> will be removed. However after that,
* it's up to the developer to manage their editor listeners.
! * Similarly, if a subclass overrides <code>createEditor</code>,
* it's up to the subclasser to deal with their editor
! * subsequently being replaced (with <code>setEditor</code>).
* We expect that in most cases, and in editor installed
! * with <code>setEditor</code> or created by a <code>createEditor</code>
* override, will not be replaced anyway.
* <p>
! * This class is the <code>LayoutManager</code> for it's single
! * <code>JFormattedTextField</code> child. By default the
* child is just centered with the parents insets.
* @since 1.4
*/
public static class DefaultEditor extends JPanel
implements ChangeListener, PropertyChangeListener, LayoutManager
{
/**
! * Constructs an editor component for the specified <code>JSpinner</code>.
! * This <code>DefaultEditor</code> is it's own layout manager and
! * it is added to the spinner's <code>ChangeListener</code> list.
! * The constructor creates a single <code>JFormattedTextField</code> child,
* initializes it's value to be the spinner model's current value
! * and adds it to <code>this</code> <code>DefaultEditor</code>.
*
! * @param spinner the spinner whose model <code>this</code> editor will monitor
* @see #getTextField
* @see JSpinner#addChangeListener
*/
public DefaultEditor(JSpinner spinner) {
super(null);
--- 576,624 ----
/**
* A simple base class for more specialized editors
* that displays a read-only view of the model's current
! * value with a {@code JFormattedTextField}. Subclasses
! * can configure the {@code JFormattedTextField} to create
* an editor that's appropriate for the type of model they
* support and they may want to override
! * the {@code stateChanged} and {@code propertyChanged}
* methods, which keep the model and the text field in sync.
* <p>
! * This class defines a {@code dismiss} method that removes the
! * editors {@code ChangeListener} from the {@code JSpinner}
! * that it's part of. The {@code setEditor} method knows about
! * {@code DefaultEditor.dismiss}, so if the developer
! * replaces an editor that's derived from {@code JSpinner.DefaultEditor}
! * its {@code ChangeListener} connection back to the
! * {@code JSpinner} will be removed. However after that,
* it's up to the developer to manage their editor listeners.
! * Similarly, if a subclass overrides {@code createEditor},
* it's up to the subclasser to deal with their editor
! * subsequently being replaced (with {@code setEditor}).
* We expect that in most cases, and in editor installed
! * with {@code setEditor} or created by a {@code createEditor}
* override, will not be replaced anyway.
* <p>
! * This class is the {@code LayoutManager} for it's single
! * {@code JFormattedTextField} child. By default the
* child is just centered with the parents insets.
* @since 1.4
*/
public static class DefaultEditor extends JPanel
implements ChangeListener, PropertyChangeListener, LayoutManager
{
/**
! * Constructs an editor component for the specified {@code JSpinner}.
! * This {@code DefaultEditor} is it's own layout manager and
! * it is added to the spinner's {@code ChangeListener} list.
! * The constructor creates a single {@code JFormattedTextField} child,
* initializes it's value to be the spinner model's current value
! * and adds it to {@code this DefaultEditor}.
*
! * @param spinner the spinner whose model {@code this} editor will monitor
* @see #getTextField
* @see JSpinner#addChangeListener
*/
public DefaultEditor(JSpinner spinner) {
super(null);
*** 653,685 ****
}
}
/**
! * Disconnect <code>this</code> editor from the specified
! * <code>JSpinner</code>. By default, this method removes
! * itself from the spinners <code>ChangeListener</code> list.
*
! * @param spinner the <code>JSpinner</code> to disconnect this
* editor from; the same spinner as was passed to the constructor.
*/
public void dismiss(JSpinner spinner) {
spinner.removeChangeListener(this);
}
/**
! * Returns the <code>JSpinner</code> ancestor of this editor or
! * <code>null</code> if none of the ancestors are a
! * <code>JSpinner</code>.
! * Typically the editor's parent is a <code>JSpinner</code> however
! * subclasses of <code>JSpinner</code> may override the
! * the <code>createEditor</code> method and insert one or more containers
! * between the <code>JSpinner</code> and it's editor.
*
! * @return <code>JSpinner</code> ancestor; <code>null</code>
! * if none of the ancestors are a <code>JSpinner</code>
*
* @see JSpinner#createEditor
*/
public JSpinner getSpinner() {
for (Component c = this; c != null; c = c.getParent()) {
--- 653,685 ----
}
}
/**
! * Disconnect {@code this} editor from the specified
! * {@code JSpinner}. By default, this method removes
! * itself from the spinners {@code ChangeListener} list.
*
! * @param spinner the {@code JSpinner} to disconnect this
* editor from; the same spinner as was passed to the constructor.
*/
public void dismiss(JSpinner spinner) {
spinner.removeChangeListener(this);
}
/**
! * Returns the {@code JSpinner} ancestor of this editor or
! * {@code null} if none of the ancestors are a
! * {@code JSpinner}.
! * Typically the editor's parent is a {@code JSpinner} however
! * subclasses of {@code JSpinner} may override the
! * the {@code createEditor} method and insert one or more containers
! * between the {@code JSpinner} and it's editor.
*
! * @return {@code JSpinner} ancestor; {@code null}
! * if none of the ancestors are a {@code JSpinner}
*
* @see JSpinner#createEditor
*/
public JSpinner getSpinner() {
for (Component c = this; c != null; c = c.getParent()) {
*** 690,742 ****
return null;
}
/**
! * Returns the <code>JFormattedTextField</code> child of this
* editor. By default the text field is the first and only
* child of editor.
*
! * @return the <code>JFormattedTextField</code> that gives the user
! * access to the <code>SpinnerDateModel's</code> value.
* @see #getSpinner
* @see #getModel
*/
public JFormattedTextField getTextField() {
return (JFormattedTextField)getComponent(0);
}
/**
* This method is called when the spinner's model's state changes.
! * It sets the <code>value</code> of the text field to the current
* value of the spinners model.
*
! * @param e the <code>ChangeEvent</code> whose source is the
! * <code>JSpinner</code> whose model has changed.
* @see #getTextField
* @see JSpinner#getValue
*/
public void stateChanged(ChangeEvent e) {
JSpinner spinner = (JSpinner)(e.getSource());
getTextField().setValue(spinner.getValue());
}
/**
! * Called by the <code>JFormattedTextField</code>
! * <code>PropertyChangeListener</code>. When the <code>"value"</code>
* property changes, which implies that the user has typed a new
* number, we set the value of the spinners model.
* <p>
! * This class ignores <code>PropertyChangeEvents</code> whose
! * source is not the <code>JFormattedTextField</code>, so subclasses
! * may safely make <code>this</code> <code>DefaultEditor</code> a
! * <code>PropertyChangeListener</code> on other objects.
*
! * @param e the <code>PropertyChangeEvent</code> whose source is
! * the <code>JFormattedTextField</code> created by this class.
* @see #getTextField
*/
public void propertyChange(PropertyChangeEvent e)
{
JSpinner spinner = getSpinner();
--- 690,742 ----
return null;
}
/**
! * Returns the {@code JFormattedTextField} child of this
* editor. By default the text field is the first and only
* child of editor.
*
! * @return the {@code JFormattedTextField} that gives the user
! * access to the {@code SpinnerDateModel's} value.
* @see #getSpinner
* @see #getModel
*/
public JFormattedTextField getTextField() {
return (JFormattedTextField)getComponent(0);
}
/**
* This method is called when the spinner's model's state changes.
! * It sets the {@code value} of the text field to the current
* value of the spinners model.
*
! * @param e the {@code ChangeEvent} whose source is the
! * {@code JSpinner} whose model has changed.
* @see #getTextField
* @see JSpinner#getValue
*/
public void stateChanged(ChangeEvent e) {
JSpinner spinner = (JSpinner)(e.getSource());
getTextField().setValue(spinner.getValue());
}
/**
! * Called by the {@code JFormattedTextField}
! * {@code PropertyChangeListener}. When the {@code "value"}
* property changes, which implies that the user has typed a new
* number, we set the value of the spinners model.
* <p>
! * This class ignores {@code PropertyChangeEvents} whose
! * source is not the {@code JFormattedTextField}, so subclasses
! * may safely make {@code this DefaultEditor} a
! * {@code PropertyChangeListener} on other objects.
*
! * @param e the {@code PropertyChangeEvent} whose source is
! * the {@code JFormattedTextField} created by this class.
* @see #getTextField
*/
public void propertyChange(PropertyChangeEvent e)
{
JSpinner spinner = getSpinner();
*** 767,777 ****
}
}
/**
! * This <code>LayoutManager</code> method does nothing. We're
* only managing a single child and there's no support
* for layout constraints.
*
* @param name ignored
* @param child ignored
--- 767,777 ----
}
}
/**
! * This {@code LayoutManager} method does nothing. We're
* only managing a single child and there's no support
* for layout constraints.
*
* @param name ignored
* @param child ignored
*** 779,789 ****
public void addLayoutComponent(String name, Component child) {
}
/**
! * This <code>LayoutManager</code> method does nothing. There
* isn't any per-child state.
*
* @param child ignored
*/
public void removeLayoutComponent(Component child) {
--- 779,789 ----
public void addLayoutComponent(String name, Component child) {
}
/**
! * This {@code LayoutManager} method does nothing. There
* isn't any per-child state.
*
* @param child ignored
*/
public void removeLayoutComponent(Component child) {
*** 851,864 ****
getComponent(0).setBounds(insets.left, insets.top, w, h);
}
}
/**
! * Pushes the currently edited value to the <code>SpinnerModel</code>.
* <p>
! * The default implementation invokes <code>commitEdit</code> on the
! * <code>JFormattedTextField</code>.
*
* @throws ParseException if the edited value is not legal
*/
public void commitEdit() throws ParseException {
// If the value in the JFormattedTextField is legal, this will have
--- 851,864 ----
getComponent(0).setBounds(insets.left, insets.top, w, h);
}
}
/**
! * Pushes the currently edited value to the {@code SpinnerModel}.
* <p>
! * The default implementation invokes {@code commitEdit} on the
! * {@code JFormattedTextField}.
*
* @throws ParseException if the edited value is not legal
*/
public void commitEdit() throws ParseException {
// If the value in the JFormattedTextField is legal, this will have
*** 941,956 ****
}
}
/**
! * An editor for a <code>JSpinner</code> whose model is a
! * <code>SpinnerDateModel</code>. The value of the editor is
! * displayed with a <code>JFormattedTextField</code> whose format
! * is defined by a <code>DateFormatter</code> instance whose
! * <code>minimum</code> and <code>maximum</code> properties
! * are mapped to the <code>SpinnerDateModel</code>.
* @since 1.4
*/
// PENDING(hmuller): more example javadoc
public static class DateEditor extends DefaultEditor
{
--- 941,956 ----
}
}
/**
! * An editor for a {@code JSpinner} whose model is a
! * {@code SpinnerDateModel}. The value of the editor is
! * displayed with a {@code JFormattedTextField} whose format
! * is defined by a {@code DateFormatter} instance whose
! * {@code minimum} and {@code maximum} properties
! * are mapped to the {@code SpinnerDateModel}.
* @since 1.4
*/
// PENDING(hmuller): more example javadoc
public static class DateEditor extends DefaultEditor
{
*** 964,983 ****
}
return lr.getDateTimePattern(DateFormat.SHORT, DateFormat.SHORT, null);
}
/**
! * Construct a <code>JSpinner</code> editor that supports displaying
! * and editing the value of a <code>SpinnerDateModel</code>
! * with a <code>JFormattedTextField</code>. <code>This</code>
! * <code>DateEditor</code> becomes both a <code>ChangeListener</code>
! * on the spinner and a <code>PropertyChangeListener</code>
! * on the new <code>JFormattedTextField</code>.
*
! * @param spinner the spinner whose model <code>this</code> editor will monitor
* @exception IllegalArgumentException if the spinners model is not
! * an instance of <code>SpinnerDateModel</code>
*
* @see #getModel
* @see #getFormat
* @see SpinnerDateModel
*/
--- 964,983 ----
}
return lr.getDateTimePattern(DateFormat.SHORT, DateFormat.SHORT, null);
}
/**
! * Construct a {@code JSpinner} editor that supports displaying
! * and editing the value of a {@code SpinnerDateModel}
! * with a {@code JFormattedTextField}. {@code This}
! * {@code DateEditor} becomes both a {@code ChangeListener}
! * on the spinner and a {@code PropertyChangeListener}
! * on the new {@code JFormattedTextField}.
*
! * @param spinner the spinner whose model {@code this} editor will monitor
* @exception IllegalArgumentException if the spinners model is not
! * an instance of {@code SpinnerDateModel}
*
* @see #getModel
* @see #getFormat
* @see SpinnerDateModel
*/
*** 985,1007 ****
this(spinner, getDefaultPattern(spinner.getLocale()));
}
/**
! * Construct a <code>JSpinner</code> editor that supports displaying
! * and editing the value of a <code>SpinnerDateModel</code>
! * with a <code>JFormattedTextField</code>. <code>This</code>
! * <code>DateEditor</code> becomes both a <code>ChangeListener</code>
! * on the spinner and a <code>PropertyChangeListener</code>
! * on the new <code>JFormattedTextField</code>.
*
! * @param spinner the spinner whose model <code>this</code> editor will monitor
* @param dateFormatPattern the initial pattern for the
! * <code>SimpleDateFormat</code> object that's used to display
* and parse the value of the text field.
* @exception IllegalArgumentException if the spinners model is not
! * an instance of <code>SpinnerDateModel</code>
*
* @see #getModel
* @see #getFormat
* @see SpinnerDateModel
* @see java.text.SimpleDateFormat
--- 985,1007 ----
this(spinner, getDefaultPattern(spinner.getLocale()));
}
/**
! * Construct a {@code JSpinner} editor that supports displaying
! * and editing the value of a {@code SpinnerDateModel}
! * with a {@code JFormattedTextField}. {@code This}
! * {@code DateEditor} becomes both a {@code ChangeListener}
! * on the spinner and a {@code PropertyChangeListener}
! * on the new {@code JFormattedTextField}.
*
! * @param spinner the spinner whose model {@code this} editor will monitor
* @param dateFormatPattern the initial pattern for the
! * {@code SimpleDateFormat} object that's used to display
* and parse the value of the text field.
* @exception IllegalArgumentException if the spinners model is not
! * an instance of {@code SpinnerDateModel}
*
* @see #getModel
* @see #getFormat
* @see SpinnerDateModel
* @see java.text.SimpleDateFormat
*** 1010,1032 ****
this(spinner, new SimpleDateFormat(dateFormatPattern,
spinner.getLocale()));
}
/**
! * Construct a <code>JSpinner</code> editor that supports displaying
! * and editing the value of a <code>SpinnerDateModel</code>
! * with a <code>JFormattedTextField</code>. <code>This</code>
! * <code>DateEditor</code> becomes both a <code>ChangeListener</code>
! * on the spinner and a <code>PropertyChangeListener</code>
! * on the new <code>JFormattedTextField</code>.
*
! * @param spinner the spinner whose model <code>this</code> editor
* will monitor
! * @param format <code>DateFormat</code> object that's used to display
* and parse the value of the text field.
* @exception IllegalArgumentException if the spinners model is not
! * an instance of <code>SpinnerDateModel</code>
*
* @see #getModel
* @see #getFormat
* @see SpinnerDateModel
* @see java.text.SimpleDateFormat
--- 1010,1032 ----
this(spinner, new SimpleDateFormat(dateFormatPattern,
spinner.getLocale()));
}
/**
! * Construct a {@code JSpinner} editor that supports displaying
! * and editing the value of a {@code SpinnerDateModel}
! * with a {@code JFormattedTextField}. {@code This}
! * {@code DateEditor} becomes both a {@code ChangeListener}
! * on the spinner and a {@code PropertyChangeListener}
! * on the new {@code JFormattedTextField}.
*
! * @param spinner the spinner whose model {@code this} editor
* will monitor
! * @param format {@code DateFormat} object that's used to display
* and parse the value of the text field.
* @exception IllegalArgumentException if the spinners model is not
! * an instance of {@code SpinnerDateModel}
*
* @see #getModel
* @see #getFormat
* @see SpinnerDateModel
* @see java.text.SimpleDateFormat
*** 1060,1086 ****
// PENDING: hmuller
}
}
/**
! * Returns the <code>java.text.SimpleDateFormat</code> object the
! * <code>JFormattedTextField</code> uses to parse and format
* numbers.
*
! * @return the value of <code>getTextField().getFormatter().getFormat()</code>.
* @see #getTextField
* @see java.text.SimpleDateFormat
*/
public SimpleDateFormat getFormat() {
return (SimpleDateFormat)((DateFormatter)(getTextField().getFormatter())).getFormat();
}
/**
! * Return our spinner ancestor's <code>SpinnerDateModel</code>.
*
! * @return <code>getSpinner().getModel()</code>
* @see #getSpinner
* @see #getTextField
*/
public SpinnerDateModel getModel() {
return (SpinnerDateModel)(getSpinner().getModel());
--- 1060,1086 ----
// PENDING: hmuller
}
}
/**
! * Returns the {@code java.text.SimpleDateFormat} object the
! * {@code JFormattedTextField} uses to parse and format
* numbers.
*
! * @return the value of {@code getTextField().getFormatter().getFormat()}.
* @see #getTextField
* @see java.text.SimpleDateFormat
*/
public SimpleDateFormat getFormat() {
return (SimpleDateFormat)((DateFormatter)(getTextField().getFormatter())).getFormat();
}
/**
! * Return our spinner ancestor's {@code SpinnerDateModel}.
*
! * @return {@code getSpinner().getModel()}
* @see #getSpinner
* @see #getTextField
*/
public SpinnerDateModel getModel() {
return (SpinnerDateModel)(getSpinner().getModel());
*** 1124,1139 ****
}
/**
! * An editor for a <code>JSpinner</code> whose model is a
! * <code>SpinnerNumberModel</code>. The value of the editor is
! * displayed with a <code>JFormattedTextField</code> whose format
! * is defined by a <code>NumberFormatter</code> instance whose
! * <code>minimum</code> and <code>maximum</code> properties
! * are mapped to the <code>SpinnerNumberModel</code>.
* @since 1.4
*/
// PENDING(hmuller): more example javadoc
public static class NumberEditor extends DefaultEditor
{
--- 1124,1139 ----
}
/**
! * An editor for a {@code JSpinner} whose model is a
! * {@code SpinnerNumberModel}. The value of the editor is
! * displayed with a {@code JFormattedTextField} whose format
! * is defined by a {@code NumberFormatter} instance whose
! * {@code minimum} and {@code maximum} properties
! * are mapped to the {@code SpinnerNumberModel}.
* @since 1.4
*/
// PENDING(hmuller): more example javadoc
public static class NumberEditor extends DefaultEditor
{
*** 1151,1195 ****
String[] all = lr.getNumberPatterns();
return all[0];
}
/**
! * Construct a <code>JSpinner</code> editor that supports displaying
! * and editing the value of a <code>SpinnerNumberModel</code>
! * with a <code>JFormattedTextField</code>. <code>This</code>
! * <code>NumberEditor</code> becomes both a <code>ChangeListener</code>
! * on the spinner and a <code>PropertyChangeListener</code>
! * on the new <code>JFormattedTextField</code>.
*
! * @param spinner the spinner whose model <code>this</code> editor will monitor
* @exception IllegalArgumentException if the spinners model is not
! * an instance of <code>SpinnerNumberModel</code>
*
* @see #getModel
* @see #getFormat
* @see SpinnerNumberModel
*/
public NumberEditor(JSpinner spinner) {
this(spinner, getDefaultPattern(spinner.getLocale()));
}
/**
! * Construct a <code>JSpinner</code> editor that supports displaying
! * and editing the value of a <code>SpinnerNumberModel</code>
! * with a <code>JFormattedTextField</code>. <code>This</code>
! * <code>NumberEditor</code> becomes both a <code>ChangeListener</code>
! * on the spinner and a <code>PropertyChangeListener</code>
! * on the new <code>JFormattedTextField</code>.
*
! * @param spinner the spinner whose model <code>this</code> editor will monitor
* @param decimalFormatPattern the initial pattern for the
! * <code>DecimalFormat</code> object that's used to display
* and parse the value of the text field.
* @exception IllegalArgumentException if the spinners model is not
! * an instance of <code>SpinnerNumberModel</code> or if
! * <code>decimalFormatPattern</code> is not a legal
! * argument to <code>DecimalFormat</code>
*
* @see #getTextField
* @see SpinnerNumberModel
* @see java.text.DecimalFormat
*/
--- 1151,1195 ----
String[] all = lr.getNumberPatterns();
return all[0];
}
/**
! * Construct a {@code JSpinner} editor that supports displaying
! * and editing the value of a {@code SpinnerNumberModel}
! * with a {@code JFormattedTextField}. {@code This}
! * {@code NumberEditor} becomes both a {@code ChangeListener}
! * on the spinner and a {@code PropertyChangeListener}
! * on the new {@code JFormattedTextField}.
*
! * @param spinner the spinner whose model {@code this} editor will monitor
* @exception IllegalArgumentException if the spinners model is not
! * an instance of {@code SpinnerNumberModel}
*
* @see #getModel
* @see #getFormat
* @see SpinnerNumberModel
*/
public NumberEditor(JSpinner spinner) {
this(spinner, getDefaultPattern(spinner.getLocale()));
}
/**
! * Construct a {@code JSpinner} editor that supports displaying
! * and editing the value of a {@code SpinnerNumberModel}
! * with a {@code JFormattedTextField}. {@code This}
! * {@code NumberEditor} becomes both a {@code ChangeListener}
! * on the spinner and a {@code PropertyChangeListener}
! * on the new {@code JFormattedTextField}.
*
! * @param spinner the spinner whose model {@code this} editor will monitor
* @param decimalFormatPattern the initial pattern for the
! * {@code DecimalFormat} object that's used to display
* and parse the value of the text field.
* @exception IllegalArgumentException if the spinners model is not
! * an instance of {@code SpinnerNumberModel} or if
! * {@code decimalFormatPattern} is not a legal
! * argument to {@code DecimalFormat}
*
* @see #getTextField
* @see SpinnerNumberModel
* @see java.text.DecimalFormat
*/
*** 1197,1219 ****
this(spinner, new DecimalFormat(decimalFormatPattern));
}
/**
! * Construct a <code>JSpinner</code> editor that supports displaying
! * and editing the value of a <code>SpinnerNumberModel</code>
! * with a <code>JFormattedTextField</code>. <code>This</code>
! * <code>NumberEditor</code> becomes both a <code>ChangeListener</code>
! * on the spinner and a <code>PropertyChangeListener</code>
! * on the new <code>JFormattedTextField</code>.
*
! * @param spinner the spinner whose model <code>this</code> editor will monitor
* @param decimalFormatPattern the initial pattern for the
! * <code>DecimalFormat</code> object that's used to display
* and parse the value of the text field.
* @exception IllegalArgumentException if the spinners model is not
! * an instance of <code>SpinnerNumberModel</code>
*
* @see #getTextField
* @see SpinnerNumberModel
* @see java.text.DecimalFormat
*/
--- 1197,1219 ----
this(spinner, new DecimalFormat(decimalFormatPattern));
}
/**
! * Construct a {@code JSpinner} editor that supports displaying
! * and editing the value of a {@code SpinnerNumberModel}
! * with a {@code JFormattedTextField}. {@code This}
! * {@code NumberEditor} becomes both a {@code ChangeListener}
! * on the spinner and a {@code PropertyChangeListener}
! * on the new {@code JFormattedTextField}.
*
! * @param spinner the spinner whose model {@code this} editor will monitor
* @param decimalFormatPattern the initial pattern for the
! * {@code DecimalFormat} object that's used to display
* and parse the value of the text field.
* @exception IllegalArgumentException if the spinners model is not
! * an instance of {@code SpinnerNumberModel}
*
* @see #getTextField
* @see SpinnerNumberModel
* @see java.text.DecimalFormat
*/
*** 1251,1277 ****
}
/**
! * Returns the <code>java.text.DecimalFormat</code> object the
! * <code>JFormattedTextField</code> uses to parse and format
* numbers.
*
! * @return the value of <code>getTextField().getFormatter().getFormat()</code>.
* @see #getTextField
* @see java.text.DecimalFormat
*/
public DecimalFormat getFormat() {
return (DecimalFormat)((NumberFormatter)(getTextField().getFormatter())).getFormat();
}
/**
! * Return our spinner ancestor's <code>SpinnerNumberModel</code>.
*
! * @return <code>getSpinner().getModel()</code>
* @see #getSpinner
* @see #getTextField
*/
public SpinnerNumberModel getModel() {
return (SpinnerNumberModel)(getSpinner().getModel());
--- 1251,1277 ----
}
/**
! * Returns the {@code java.text.DecimalFormat} object the
! * {@code JFormattedTextField} uses to parse and format
* numbers.
*
! * @return the value of {@code getTextField().getFormatter().getFormat()}.
* @see #getTextField
* @see java.text.DecimalFormat
*/
public DecimalFormat getFormat() {
return (DecimalFormat)((NumberFormatter)(getTextField().getFormatter())).getFormat();
}
/**
! * Return our spinner ancestor's {@code SpinnerNumberModel}.
*
! * @return {@code getSpinner().getModel()}
* @see #getSpinner
* @see #getTextField
*/
public SpinnerNumberModel getModel() {
return (SpinnerNumberModel)(getSpinner().getModel());
*** 1288,1314 ****
}
}
/**
! * An editor for a <code>JSpinner</code> whose model is a
! * <code>SpinnerListModel</code>.
* @since 1.4
*/
public static class ListEditor extends DefaultEditor
{
/**
! * Construct a <code>JSpinner</code> editor that supports displaying
! * and editing the value of a <code>SpinnerListModel</code>
! * with a <code>JFormattedTextField</code>. <code>This</code>
! * <code>ListEditor</code> becomes both a <code>ChangeListener</code>
! * on the spinner and a <code>PropertyChangeListener</code>
! * on the new <code>JFormattedTextField</code>.
*
! * @param spinner the spinner whose model <code>this</code> editor will monitor
* @exception IllegalArgumentException if the spinners model is not
! * an instance of <code>SpinnerListModel</code>
*
* @see #getModel
* @see SpinnerListModel
*/
public ListEditor(JSpinner spinner) {
--- 1288,1314 ----
}
}
/**
! * An editor for a {@code JSpinner} whose model is a
! * {@code SpinnerListModel}.
* @since 1.4
*/
public static class ListEditor extends DefaultEditor
{
/**
! * Construct a {@code JSpinner} editor that supports displaying
! * and editing the value of a {@code SpinnerListModel}
! * with a {@code JFormattedTextField}. {@code This}
! * {@code ListEditor} becomes both a {@code ChangeListener}
! * on the spinner and a {@code PropertyChangeListener}
! * on the new {@code JFormattedTextField}.
*
! * @param spinner the spinner whose model {@code this} editor will monitor
* @exception IllegalArgumentException if the spinners model is not
! * an instance of {@code SpinnerListModel}
*
* @see #getModel
* @see SpinnerListModel
*/
public ListEditor(JSpinner spinner) {
*** 1320,1332 ****
getTextField().setFormatterFactory(new
DefaultFormatterFactory(new ListFormatter()));
}
/**
! * Return our spinner ancestor's <code>SpinnerNumberModel</code>.
*
! * @return <code>getSpinner().getModel()</code>
* @see #getSpinner
* @see #getTextField
*/
public SpinnerListModel getModel() {
return (SpinnerListModel)(getSpinner().getModel());
--- 1320,1332 ----
getTextField().setFormatterFactory(new
DefaultFormatterFactory(new ListFormatter()));
}
/**
! * Return our spinner ancestor's {@code SpinnerNumberModel}.
*
! * @return {@code getSpinner().getModel()}
* @see #getSpinner
* @see #getTextField
*/
public SpinnerListModel getModel() {
return (SpinnerListModel)(getSpinner().getModel());
*** 1420,1444 ****
/////////////////
// Accessibility support
////////////////
/**
! * Gets the <code>AccessibleContext</code> for the <code>JSpinner</code>
*
! * @return the <code>AccessibleContext</code> for the <code>JSpinner</code>
* @since 1.5
*/
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleJSpinner();
}
return accessibleContext;
}
/**
! * <code>AccessibleJSpinner</code> implements accessibility
! * support for the <code>JSpinner</code> class.
* @since 1.5
*/
protected class AccessibleJSpinner extends AccessibleJComponent
implements AccessibleValue, AccessibleAction, AccessibleText,
AccessibleEditableText, ChangeListener {
--- 1420,1444 ----
/////////////////
// Accessibility support
////////////////
/**
! * Gets the {@code AccessibleContext} for the {@code JSpinner}
*
! * @return the {@code AccessibleContext} for the {@code JSpinner}
* @since 1.5
*/
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleJSpinner();
}
return accessibleContext;
}
/**
! * {@code AccessibleJSpinner} implements accessibility
! * support for the {@code JSpinner} class.
* @since 1.5
*/
protected class AccessibleJSpinner extends AccessibleJComponent
implements AccessibleValue, AccessibleAction, AccessibleText,
AccessibleEditableText, ChangeListener {
*** 1455,1465 ****
}
/**
* Invoked when the target of the listener has changed its state.
*
! * @param e a <code>ChangeEvent</code> object. Must not be null.
* @throws NullPointerException if the parameter is null.
*/
public void stateChanged(ChangeEvent e) {
if (e == null) {
throw new NullPointerException();
--- 1455,1465 ----
}
/**
* Invoked when the target of the listener has changed its state.
*
! * @param e a {@code ChangeEvent} object. Must not be null.
* @throws NullPointerException if the parameter is null.
*/
public void stateChanged(ChangeEvent e) {
if (e == null) {
throw new NullPointerException();
< prev index next >