javax.swing.plaf.basic
Class BasicSpinnerUI.ArrowButtonHandler

java.lang.Object
  extended byjavax.swing.AbstractAction
      extended byjavax.swing.plaf.basic.BasicSpinnerUI.ArrowButtonHandler
All Implemented Interfaces:
Action, ActionListener, Cloneable, EventListener, MouseListener, Serializable, UIResource
Enclosing class:
BasicSpinnerUI

private static class BasicSpinnerUI.ArrowButtonHandler
extends AbstractAction
implements MouseListener, UIResource

A handler for spinner arrow button mouse and action events. When a left mouse pressed event occurs we look up the (enabled) spinner that's the source of the event and start the autorepeat timer. The timer fires action events until any button is released at which point the timer is stopped and the reference to the spinner cleared. The timer doesn't start until after a 300ms delay, so often the source of the initial (and final) action event is just the button logic for mouse released - which means that we're relying on the fact that our mouse listener runs after the buttons mouse listener.

Note that one instance of this handler is shared by all slider previous arrow buttons and likewise for all of the next buttons, so it doesn't have any state that persists beyond the limits of a single button pressed/released gesture.


Nested Class Summary
 
Nested classes inherited from class javax.swing.AbstractAction
 
Field Summary
(package private)  Timer autoRepeatTimer
           
(package private)  boolean isNext
           
(package private)  JSpinner spinner
           
 
Fields inherited from class javax.swing.AbstractAction
changeSupport, enabled
 
Fields inherited from interface javax.swing.Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SHORT_DESCRIPTION, SMALL_ICON
 
Constructor Summary
(package private) BasicSpinnerUI.ArrowButtonHandler(String name, boolean isNext)
           
 
Method Summary
 void actionPerformed(ActionEvent e)
          Invoked when an action occurs.
private  JSpinner eventToSpinner(AWTEvent e)
           
private  void focusSpinnerIfNecessary()
          Requests focus on a child of the spinner if the spinner doesn't have focus.
private  int getCalendarField(JSpinner spinner)
          Returns the calendarField under the start of the selection, or -1 if there is no valid calendar field under the selection (or the spinner isn't editing dates.
 void mouseClicked(MouseEvent e)
          Invoked when the mouse button has been clicked (pressed and released) on a component.
 void mouseEntered(MouseEvent e)
          Invoked when the mouse enters a component.
 void mouseExited(MouseEvent e)
          Invoked when the mouse exits a component.
 void mousePressed(MouseEvent e)
          Invoked when a mouse button has been pressed on a component.
 void mouseReleased(MouseEvent e)
          Invoked when a mouse button has been released on a component.
private  boolean select(JFormattedTextField ftf, AttributedCharacterIterator iterator, DateFormat.Field field)
          Selects the passed in field, returning true if it is found, false otherwise.
private  void select(JSpinner spinner)
          If the spinner's editor is a DateEditor, this selects the field associated with the value that is being incremented.
 
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

autoRepeatTimer

final Timer autoRepeatTimer

isNext

final boolean isNext

spinner

JSpinner spinner
Constructor Detail

BasicSpinnerUI.ArrowButtonHandler

BasicSpinnerUI.ArrowButtonHandler(String name,
                                  boolean isNext)
Method Detail

eventToSpinner

private JSpinner eventToSpinner(AWTEvent e)

actionPerformed

public void actionPerformed(ActionEvent e)
Description copied from interface: ActionListener
Invoked when an action occurs.

Specified by:
actionPerformed in interface ActionListener

select

private void select(JSpinner spinner)
If the spinner's editor is a DateEditor, this selects the field associated with the value that is being incremented.


select

private boolean select(JFormattedTextField ftf,
                       AttributedCharacterIterator iterator,
                       DateFormat.Field field)
Selects the passed in field, returning true if it is found, false otherwise.


getCalendarField

private int getCalendarField(JSpinner spinner)
Returns the calendarField under the start of the selection, or -1 if there is no valid calendar field under the selection (or the spinner isn't editing dates.


mousePressed

public void mousePressed(MouseEvent e)
Description copied from interface: MouseListener
Invoked when a mouse button has been pressed on a component.

Specified by:
mousePressed in interface MouseListener

mouseReleased

public void mouseReleased(MouseEvent e)
Description copied from interface: MouseListener
Invoked when a mouse button has been released on a component.

Specified by:
mouseReleased in interface MouseListener

mouseClicked

public void mouseClicked(MouseEvent e)
Description copied from interface: MouseListener
Invoked when the mouse button has been clicked (pressed and released) on a component.

Specified by:
mouseClicked in interface MouseListener

mouseEntered

public void mouseEntered(MouseEvent e)
Description copied from interface: MouseListener
Invoked when the mouse enters a component.

Specified by:
mouseEntered in interface MouseListener

mouseExited

public void mouseExited(MouseEvent e)
Description copied from interface: MouseListener
Invoked when the mouse exits a component.

Specified by:
mouseExited in interface MouseListener

focusSpinnerIfNecessary

private void focusSpinnerIfNecessary()
Requests focus on a child of the spinner if the spinner doesn't have focus.