jdk/src/share/classes/javax/swing/plaf/synth/SynthSpinnerUI.java
changeset 4394 92a8ec883f5d
parent 2658 43e06bc950ec
child 4848 ffcc849b9351
--- a/jdk/src/share/classes/javax/swing/plaf/synth/SynthSpinnerUI.java	Wed Dec 09 11:38:30 2009 +0300
+++ b/jdk/src/share/classes/javax/swing/plaf/synth/SynthSpinnerUI.java	Thu Dec 10 12:08:58 2009 +0300
@@ -26,22 +26,21 @@
 
 import java.awt.*;
 import java.awt.event.*;
-
 import javax.swing.*;
 import javax.swing.plaf.*;
 import javax.swing.plaf.basic.BasicSpinnerUI;
-
 import java.beans.*;
-import sun.swing.plaf.synth.SynthUI;
 
 /**
- * Synth's SpinnerUI.
+ * Provides the Synth L&F UI delegate for
+ * {@link javax.swing.JSpinner}.
  *
  * @author Hans Muller
  * @author Joshua Outwater
+ * @since 1.7
  */
-class SynthSpinnerUI extends BasicSpinnerUI implements PropertyChangeListener,
-        SynthUI {
+public class SynthSpinnerUI extends BasicSpinnerUI
+                            implements PropertyChangeListener, SynthUI {
     private SynthStyle style;
     /**
      * A FocusListener implementation which causes the entire spinner to be
@@ -65,6 +64,9 @@
         return new SynthSpinnerUI();
     }
 
+    /**
+     * @inheritDoc
+     */
     @Override
     protected void installListeners() {
         super.installListeners();
@@ -79,12 +81,7 @@
     }
 
     /**
-     * Removes the <code>propertyChangeListener</code> added
-     * by installListeners.
-     * <p>
-     * This method is called by <code>uninstallUI</code>.
-     *
-     * @see #installListeners
+     * @inheritDoc
      */
     @Override
     protected void uninstallListeners() {
@@ -100,7 +97,7 @@
     }
 
     /**
-     * Initialize the <code>JSpinner</code> <code>border</code>,
+     * Initializes the <code>JSpinner</code> <code>border</code>,
      * <code>foreground</code>, and <code>background</code>, properties
      * based on the corresponding "Spinner.*" properties from defaults table.
      * The <code>JSpinners</code> layout is set to the value returned by
@@ -112,6 +109,7 @@
      * @see LookAndFeel#installBorder
      * @see LookAndFeel#installColors
      */
+    @Override
     protected void installDefaults() {
         LayoutManager layout = spinner.getLayout();
 
@@ -144,6 +142,7 @@
      * @see #installDefaults
      * @see #uninstallUI
      */
+    @Override
     protected void uninstallDefaults() {
         if (spinner.getLayout() instanceof UIResource) {
             spinner.setLayout(null);
@@ -156,25 +155,19 @@
         style = null;
     }
 
-
+    /**
+     * @inheritDoc
+     */
+    @Override
     protected LayoutManager createLayout() {
         return new SpinnerLayout();
     }
 
 
     /**
-     * Create a component that will replace the spinner models value
-     * with the object returned by <code>spinner.getPreviousValue</code>.
-     * By default the <code>previousButton</code> is a JButton
-     * who's <code>ActionListener</code> updates it's <code>JSpinner</code>
-     * ancestors model.  If a previousButton isn't needed (in a subclass)
-     * then override this method to return null.
-     *
-     * @return a component that will replace the spinners model with the
-     *     next value in the sequence, or null
-     * @see #installUI
-     * @see #createNextButton
+     * @inheritDoc
      */
+    @Override
     protected Component createPreviousButton() {
         JButton b = new SynthArrowButton(SwingConstants.SOUTH);
         b.setName("Spinner.previousButton");
@@ -184,18 +177,9 @@
 
 
     /**
-     * Create a component that will replace the spinner models value
-     * with the object returned by <code>spinner.getNextValue</code>.
-     * By default the <code>nextButton</code> is a JButton
-     * who's <code>ActionListener</code> updates it's <code>JSpinner</code>
-     * ancestors model.  If a nextButton isn't needed (in a subclass)
-     * then override this method to return null.
-     *
-     * @return a component that will replace the spinners model with the
-     *     next value in the sequence, or null
-     * @see #installUI
-     * @see #createPreviousButton
+     * @inheritDoc
      */
+    @Override
     protected Component createNextButton() {
         JButton b = new SynthArrowButton(SwingConstants.NORTH);
         b.setName("Spinner.nextButton");
@@ -227,6 +211,7 @@
      * @see #replaceEditor
      * @see JSpinner#getEditor
      */
+    @Override
     protected JComponent createEditor() {
         JComponent editor = spinner.getEditor();
         editor.setName("Spinner.editor");
@@ -250,6 +235,7 @@
      * @see #createEditor
      * @see #createPropertyChangeListener
      */
+    @Override
     protected void replaceEditor(JComponent oldEditor, JComponent newEditor) {
         spinner.remove(oldEditor);
         spinner.add(newEditor, "Editor");
@@ -283,8 +269,12 @@
         }
     }
 
+    /**
+     * @inheritDoc
+     */
+    @Override
     public SynthContext getContext(JComponent c) {
-        return getContext(c, getComponentState(c));
+        return getContext(c, SynthLookAndFeel.getComponentState(c));
     }
 
     private SynthContext getContext(JComponent c, int state) {
@@ -292,17 +282,10 @@
                     SynthLookAndFeel.getRegion(c), style, state);
     }
 
-
-    private Region getRegion(JComponent c) {
-        return SynthLookAndFeel.getRegion(c);
-    }
-
-
-    private int getComponentState(JComponent c) {
-        return SynthLookAndFeel.getComponentState(c);
-    }
-
-
+    /**
+     * @inheritDoc
+     */
+    @Override
     public void update(Graphics g, JComponent c) {
         SynthContext context = getContext(c);
 
@@ -314,6 +297,10 @@
     }
 
 
+    /**
+     * @inheritDoc
+     */
+    @Override
     public void paint(Graphics g, JComponent c) {
         SynthContext context = getContext(c);
 
@@ -321,10 +308,19 @@
         context.dispose();
     }
 
-
+    /**
+     * Paints the specified component. This implementation does nothing.
+     *
+     * @param context context for the component being painted
+     * @param g {@code Graphics} object used for painting
+     */
     protected void paint(SynthContext context, Graphics g) {
     }
 
+    /**
+     * @inheritDoc
+     */
+    @Override
     public void paintBorder(SynthContext context, Graphics g, int x,
                             int y, int w, int h) {
         context.getPainter().paintSpinnerBorder(context, g, x, y, w, h);
@@ -426,9 +422,11 @@
         }
     }
 
-
+    /**
+     * @inheritDoc
+     */
+    @Override
     public void propertyChange(PropertyChangeEvent e) {
-        String propertyName = e.getPropertyName();
         JSpinner spinner = (JSpinner)(e.getSource());
         SpinnerUI spinnerUI = spinner.getUI();
 
@@ -444,34 +442,13 @@
     /** Listen to editor text field focus changes and repaint whole spinner */
     private class EditorFocusHandler implements FocusListener{
         /** Invoked when a editor text field gains the keyboard focus. */
-        public void focusGained(FocusEvent e) {
+        @Override public void focusGained(FocusEvent e) {
             spinner.repaint();
         }
 
         /** Invoked when a editor text field loses the keyboard focus. */
-        public void focusLost(FocusEvent e) {
+        @Override public void focusLost(FocusEvent e) {
             spinner.repaint();
         }
     }
-
-    /** Override the arrowbuttons focus handling to follow the text fields focus */
-    private class SpinnerArrowButton extends SynthArrowButton{
-        public SpinnerArrowButton(int direction) {
-            super(direction);
-        }
-
-        @Override
-        public boolean isFocusOwner() {
-            if (spinner == null){
-                return super.isFocusOwner();
-            } else if (spinner.getEditor() instanceof JSpinner.DefaultEditor){
-                return ((JSpinner.DefaultEditor)spinner.getEditor())
-                        .getTextField().isFocusOwner();
-            } else if (spinner.getEditor()!= null) {
-                return spinner.getEditor().isFocusOwner();
-            } else {
-                return super.isFocusOwner();
-            }
-        }
-    }
 }