Methods Summary |
---|
private java.awt.Component | createArrowButton(int direction)
JButton b = new BasicArrowButton(direction);
Border buttonBorder = UIManager.getBorder("Spinner.arrowButtonBorder");
if (buttonBorder instanceof UIResource) {
// Wrap the border to avoid having the UIResource be replaced by
// the ButtonUI. This is the opposite of using BorderUIResource.
b.setBorder(new CompoundBorder(buttonBorder, null));
} else {
b.setBorder(buttonBorder);
}
b.setInheritsPopupMenu(true);
return b;
|
protected javax.swing.JComponent | createEditor()This method is called by installUI to get the editor component
of the JSpinner . By default it just returns
JSpinner.getEditor() . Subclasses can override
createEditor to return a component that contains
the spinner's editor or null, if they're going to handle adding
the editor to the JSpinner in an
installUI override.
Typically this method would be overridden to wrap the editor
with a container with a custom border, since one can't assume
that the editors border can be set directly.
The replaceEditor method is called when the spinners
editor is changed with JSpinner.setEditor . If you've
overriden this method, then you'll probably want to override
replaceEditor as well.
JComponent editor = spinner.getEditor();
maybeRemoveEditorBorder(editor);
installEditorBorderListener(editor);
editor.setInheritsPopupMenu(true);
updateEditorAlignment(editor);
return editor;
|
protected java.awt.LayoutManager | createLayout()Create a LayoutManager that manages the editor ,
nextButton , and previousButton
children of the JSpinner. These three children must be
added with a constraint that identifies their role:
"Editor", "Next", and "Previous". The default layout manager
can handle the absence of any of these children.
return getHandler();
|
protected java.awt.Component | createNextButton()Create a component that will replace the spinner models value
with the object returned by spinner.getNextValue .
By default the nextButton is a JButton
who's ActionListener updates it's JSpinner
ancestors model. If a nextButton isn't needed (in a subclass)
then override this method to return null.
Component c = createArrowButton(SwingConstants.NORTH);
c.setName("Spinner.nextButton");
installNextButtonListeners(c);
return c;
|
protected java.awt.Component | createPreviousButton()Create a component that will replace the spinner models value
with the object returned by spinner.getPreviousValue .
By default the previousButton is a JButton. This
method invokes installPreviousButtonListeners to
install the necessary listeners to update the JSpinner 's
model in response to a user gesture. If a previousButton isn't needed
(in a subclass) then override this method to return null.
Component c = createArrowButton(SwingConstants.SOUTH);
c.setName("Spinner.previousButton");
installPreviousButtonListeners(c);
return c;
|
protected java.beans.PropertyChangeListener | createPropertyChangeListener()Create a PropertyChangeListener that can be
added to the JSpinner itself. Typically, this listener
will call replaceEditor when the "editor" property changes,
since it's the SpinnerUI's responsibility to
add the editor to the JSpinner (and remove the old one).
This method is called by installListeners .
return getHandler();
|
public static javax.swing.plaf.ComponentUI | createUI(javax.swing.JComponent c)Returns a new instance of BasicSpinnerUI. SpinnerListUI
delegates are allocated one per JSpinner.
return new BasicSpinnerUI();
|
public int | getBaseline(javax.swing.JComponent c, int width, int height)Returns the baseline.
super.getBaseline(c, width, height);
JComponent editor = spinner.getEditor();
Insets insets = spinner.getInsets();
width = width - insets.left - insets.right;
height = height - insets.top - insets.bottom;
if (width >= 0 && height >= 0) {
int baseline = editor.getBaseline(width, height);
if (baseline >= 0) {
return insets.top + baseline;
}
}
return -1;
|
public java.awt.Component$BaselineResizeBehavior | getBaselineResizeBehavior(javax.swing.JComponent c)Returns an enum indicating how the baseline of the component
changes as the size changes.
super.getBaselineResizeBehavior(c);
return spinner.getEditor().getBaselineResizeBehavior();
|
private javax.swing.plaf.basic.BasicSpinnerUI$Handler | getHandler()
if (handler == null) {
handler = new Handler();
}
return handler;
|
private javax.swing.InputMap | getInputMap(int condition)Returns the InputMap to install for condition .
if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
return (InputMap)DefaultLookup.get(spinner, this,
"Spinner.ancestorInputMap");
}
return null;
|
private void | installButtonListeners(java.awt.Component c, javax.swing.plaf.basic.BasicSpinnerUI$ArrowButtonHandler handler)
if (c instanceof JButton) {
((JButton)c).addActionListener(handler);
}
c.addMouseListener(handler);
|
protected void | installDefaults()Initialize the JSpinner border ,
foreground , and background , properties
based on the corresponding "Spinner.*" properties from defaults table.
The JSpinners layout is set to the value returned by
createLayout . This method is called by installUI .
spinner.setLayout(createLayout());
LookAndFeel.installBorder(spinner, "Spinner.border");
LookAndFeel.installColorsAndFont(spinner, "Spinner.background", "Spinner.foreground", "Spinner.font");
LookAndFeel.installProperty(spinner, "opaque", Boolean.TRUE);
|
private void | installEditorBorderListener(javax.swing.JComponent editor)Remove the border around the inner editor component for LaFs
that install an outside border around the spinner,
if (!UIManager.getBoolean("Spinner.editorBorderPainted")) {
if (editor instanceof JPanel &&
editor.getBorder() == null &&
editor.getComponentCount() > 0) {
editor = (JComponent)editor.getComponent(0);
}
if (editor != null &&
(editor.getBorder() == null ||
editor.getBorder() instanceof UIResource)) {
editor.addPropertyChangeListener(getHandler());
}
}
|
protected void | installKeyboardActions()Installs the keyboard Actions onto the JSpinner.
InputMap iMap = getInputMap(JComponent.
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
SwingUtilities.replaceUIInputMap(spinner, JComponent.
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
iMap);
LazyActionMap.installLazyActionMap(spinner, BasicSpinnerUI.class,
"Spinner.actionMap");
|
protected void | installListeners()Initializes PropertyChangeListener with
a shared object that delegates interesting PropertyChangeEvents
to protected methods.
This method is called by installUI .
propertyChangeListener = createPropertyChangeListener();
spinner.addPropertyChangeListener(propertyChangeListener);
if (DefaultLookup.getBoolean(spinner, this,
"Spinner.disableOnBoundaryValues", false)) {
spinner.addChangeListener(getHandler());
}
JComponent editor = spinner.getEditor();
if (editor != null && editor instanceof JSpinner.DefaultEditor) {
JTextField tf = ((JSpinner.DefaultEditor)editor).getTextField();
if (tf != null) {
tf.addFocusListener(nextButtonHandler);
tf.addFocusListener(previousButtonHandler);
}
}
|
protected void | installNextButtonListeners(java.awt.Component c)Installs the necessary listeners on the next button, c ,
to update the JSpinner in response to a user gesture.
installButtonListeners(c, nextButtonHandler);
|
protected void | installPreviousButtonListeners(java.awt.Component c)Installs the necessary listeners on the previous button, c ,
to update the JSpinner in response to a user gesture.
installButtonListeners(c, previousButtonHandler);
|
public void | installUI(javax.swing.JComponent c)Calls installDefaults , installListeners ,
and then adds the components returned by createNextButton ,
createPreviousButton , and createEditor .
this.spinner = (JSpinner)c;
installDefaults();
installListeners();
maybeAdd(createNextButton(), "Next");
maybeAdd(createPreviousButton(), "Previous");
maybeAdd(createEditor(), "Editor");
updateEnabledState();
installKeyboardActions();
|
static void | loadActionMap(javax.swing.plaf.basic.LazyActionMap map)
map.put("increment", nextButtonHandler);
map.put("decrement", previousButtonHandler);
|
private void | maybeAdd(java.awt.Component c, java.lang.String s)
if (c != null) {
spinner.add(c, s);
}
|
private void | maybeRemoveEditorBorder(javax.swing.JComponent editor)Remove the border around the inner editor component for LaFs
that install an outside border around the spinner,
if (!UIManager.getBoolean("Spinner.editorBorderPainted")) {
if (editor instanceof JPanel &&
editor.getBorder() == null &&
editor.getComponentCount() > 0) {
editor = (JComponent)editor.getComponent(0);
}
if (editor != null && editor.getBorder() instanceof UIResource) {
editor.setBorder(null);
}
}
|
private void | removeEditorBorderListener(javax.swing.JComponent editor)
if (!UIManager.getBoolean("Spinner.editorBorderPainted")) {
if (editor instanceof JPanel &&
editor.getComponentCount() > 0) {
editor = (JComponent)editor.getComponent(0);
}
if (editor != null) {
editor.removePropertyChangeListener(getHandler());
}
}
|
protected void | replaceEditor(javax.swing.JComponent oldEditor, javax.swing.JComponent newEditor)Called by the PropertyChangeListener when the
JSpinner editor property changes. It's the responsibility
of this method to remove the old editor and add the new one. By
default this operation is just:
spinner.remove(oldEditor);
spinner.add(newEditor, "Editor");
The implementation of replaceEditor should be coordinated
with the createEditor method.
spinner.remove(oldEditor);
maybeRemoveEditorBorder(newEditor);
installEditorBorderListener(newEditor);
newEditor.setInheritsPopupMenu(true);
updateEditorAlignment(newEditor);
spinner.add(newEditor, "Editor");
|
protected void | uninstallDefaults()Sets the JSpinner's layout manager to null. This
method is called by uninstallUI .
spinner.setLayout(null);
|
protected void | uninstallListeners()Removes the PropertyChangeListener added
by installListeners.
This method is called by uninstallUI .
spinner.removePropertyChangeListener(propertyChangeListener);
spinner.removeChangeListener(handler);
JComponent editor = spinner.getEditor();
removeEditorBorderListener(editor);
if (editor instanceof JSpinner.DefaultEditor) {
JTextField tf = ((JSpinner.DefaultEditor)editor).getTextField();
if (tf != null) {
tf.removeFocusListener(nextButtonHandler);
tf.removeFocusListener(previousButtonHandler);
}
}
propertyChangeListener = null;
handler = null;
|
public void | uninstallUI(javax.swing.JComponent c)Calls uninstallDefaults , uninstallListeners ,
and then removes all of the spinners children.
uninstallDefaults();
uninstallListeners();
this.spinner = null;
c.removeAll();
|
private void | updateEditorAlignment(javax.swing.JComponent editor)
if (editor instanceof JSpinner.DefaultEditor) {
// if editor alignment isn't set in LAF, we get 0 (CENTER) here
int alignment = UIManager.getInt("Spinner.editorAlignment");
JTextField text = ((JSpinner.DefaultEditor)editor).getTextField();
text.setHorizontalAlignment(alignment);
}
|
private void | updateEnabledState()Updates the enabled state of the children Components based on the
enabled state of the JSpinner .
updateEnabledState(spinner, spinner.isEnabled());
|
private void | updateEnabledState(java.awt.Container c, boolean enabled)Recursively updates the enabled state of the child
Component s of c .
for (int counter = c.getComponentCount() - 1; counter >= 0;counter--) {
Component child = c.getComponent(counter);
if (DefaultLookup.getBoolean(spinner, this,
"Spinner.disableOnBoundaryValues", false)) {
SpinnerModel model = spinner.getModel();
if (child.getName() == "Spinner.nextButton" &&
model.getNextValue() == null) {
child.setEnabled(false);
}
else if (child.getName() == "Spinner.previousButton" &&
model.getPreviousValue() == null) {
child.setEnabled(false);
}
else {
child.setEnabled(enabled);
}
}
else {
child.setEnabled(enabled);
}
if (child instanceof Container) {
updateEnabledState((Container)child, enabled);
}
}
|