< prev index next >

src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollBarUI.java

Print this page

        

@@ -58,39 +58,63 @@
     private static final int MIN_SCROLL = 2;
     private static final int MAX_SCROLL = 3;
 
     // NOTE: DO NOT use this field directly, SynthScrollBarUI assumes you'll
     // call getMinimumThumbSize to access it.
+    /** Minimum thumb size */
     protected Dimension minimumThumbSize;
+    /** Maximum thumb size */
     protected Dimension maximumThumbSize;
 
+    /** Thumb highlight color */
     protected Color thumbHighlightColor;
+    /** Thumb light shadow color */
     protected Color thumbLightShadowColor;
+    /** Thumb dark shadow color */
     protected Color thumbDarkShadowColor;
+    /** Thumb color */
     protected Color thumbColor;
+    /** Track color */
     protected Color trackColor;
+    /** Track highlight color */
     protected Color trackHighlightColor;
 
+    /** Scrollbar */
     protected JScrollBar scrollbar;
+    /** Increment button */
     protected JButton incrButton;
+    /** Decrement button */
     protected JButton decrButton;
+    /** Dragging */
     protected boolean isDragging;
+    /** Track listener */
     protected TrackListener trackListener;
+    /** Button listener */
     protected ArrowButtonListener buttonListener;
+    /** Model listener */
     protected ModelListener modelListener;
 
+    /** Thumb rectangle */
     protected Rectangle thumbRect;
+    /** Track rectangle */
     protected Rectangle trackRect;
 
+    /** Track highlight */
     protected int trackHighlight;
 
+    /** No highlight */
     protected static final int NO_HIGHLIGHT = 0;
+    /** Decrease highlight */
     protected static final int DECREASE_HIGHLIGHT = 1;
+    /** Increase highlight */
     protected static final int INCREASE_HIGHLIGHT = 2;
 
+    /** Scroll listener */
     protected ScrollListener scrollListener;
+    /** Property change listener */
     protected PropertyChangeListener propertyChangeListener;
+    /** Scroll timer */
     protected Timer scrollTimer;
 
     private final static int scrollSpeedThrottle = 60; // delay in milli seconds
 
     /**

@@ -146,16 +170,22 @@
         map.put(new Actions(Actions.NEGATIVE_BLOCK_INCREMENT));
         map.put(new Actions(Actions.MIN_SCROLL));
         map.put(new Actions(Actions.MAX_SCROLL));
     }
 
-
+    /**
+     * Creates the UI.
+     * @param c the component
+     * @return the UI
+     */
     public static ComponentUI createUI(JComponent c)    {
         return new BasicScrollBarUI();
     }
 
-
+    /**
+     * Configures the scroll bar colors.
+     */
     protected void configureScrollBarColors()
     {
         LookAndFeel.installColors(scrollbar, "ScrollBar.background",
                                   "ScrollBar.foreground");
         thumbHighlightColor = UIManager.getColor("ScrollBar.thumbHighlight");

@@ -164,21 +194,28 @@
         thumbColor = UIManager.getColor("ScrollBar.thumb");
         trackColor = UIManager.getColor("ScrollBar.track");
         trackHighlightColor = UIManager.getColor("ScrollBar.trackHighlight");
     }
 
-
+    /**
+     * Installs the UI.
+     * @param c the component
+     */
     public void installUI(JComponent c)   {
         scrollbar = (JScrollBar)c;
         thumbRect = new Rectangle(0, 0, 0, 0);
         trackRect = new Rectangle(0, 0, 0, 0);
         installDefaults();
         installComponents();
         installListeners();
         installKeyboardActions();
     }
 
+    /**
+     * Uninstalls the UI.
+     * @param c the component
+     */
     public void uninstallUI(JComponent c) {
         scrollbar = (JScrollBar)c;
         uninstallListeners();
         uninstallDefaults();
         uninstallComponents();

@@ -187,11 +224,13 @@
         scrollbar = null;
         incrButton = null;
         decrButton = null;
     }
 
-
+    /**
+     * Installs the defaults.
+     */
     protected void installDefaults()
     {
         scrollBarWidth = UIManager.getInt("ScrollBar.width");
         if (scrollBarWidth <= 0) {
             scrollBarWidth = 16;

@@ -238,11 +277,13 @@
                 decrGap *= 0.714;
             }
         }
     }
 
-
+    /**
+     * Installs the components.
+     */
     protected void installComponents(){
         switch (scrollbar.getOrientation()) {
         case JScrollBar.VERTICAL:
             incrButton = createIncreaseButton(SOUTH);
             decrButton = createDecreaseButton(NORTH);

@@ -262,16 +303,21 @@
         scrollbar.add(decrButton);
         // Force the children's enabled state to be updated.
         scrollbar.setEnabled(scrollbar.isEnabled());
     }
 
+    /**
+     * Uninstalls the components.
+     */
     protected void uninstallComponents(){
         scrollbar.remove(incrButton);
         scrollbar.remove(decrButton);
     }
 
-
+    /**
+     * Installs the listeners.
+     */
     protected void installListeners(){
         trackListener = createTrackListener();
         buttonListener = createArrowButtonListener();
         modelListener = createModelListener();
         propertyChangeListener = createPropertyChangeListener();

@@ -292,11 +338,13 @@
         scrollListener = createScrollListener();
         scrollTimer = new Timer(scrollSpeedThrottle, scrollListener);
         scrollTimer.setInitialDelay(300);  // default InitialDelay?
     }
 
-
+    /**
+     * Installs the keyboard actions.
+     */
     protected void installKeyboardActions(){
         LazyActionMap.installLazyActionMap(scrollbar, BasicScrollBarUI.class,
                                            "ScrollBar.actionMap");
 
         InputMap inputMap = getInputMap(JComponent.WHEN_FOCUSED);

@@ -305,10 +353,13 @@
         inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
         SwingUtilities.replaceUIInputMap(scrollbar,
                    JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap);
     }
 
+    /**
+     * Uninstalls the keyboard actions.
+     */
     protected void uninstallKeyboardActions(){
         SwingUtilities.replaceUIInputMap(scrollbar, JComponent.WHEN_FOCUSED,
                                          null);
         SwingUtilities.replaceUIActionMap(scrollbar, null);
     }

@@ -341,11 +392,13 @@
             }
         }
         return null;
     }
 
-
+    /**
+     * Uninstall the listeners.
+     */
     protected void uninstallListeners() {
         scrollTimer.stop();
         scrollTimer = null;
 
         if (decrButton != null){

@@ -361,11 +414,13 @@
         scrollbar.removePropertyChangeListener(propertyChangeListener);
         scrollbar.removeFocusListener(getHandler());
         handler = null;
     }
 
-
+    /**
+     * Uninstalls the defaults.
+     */
     protected void uninstallDefaults(){
         LookAndFeel.uninstallBorder(scrollbar);
         if (scrollbar.getLayout() == this) {
             scrollbar.setLayout(null);
         }

@@ -377,26 +432,46 @@
             handler = new Handler();
         }
         return handler;
     }
 
+    /**
+     * Creates a track listener.
+     * @return a track listener
+     */
     protected TrackListener createTrackListener(){
         return new TrackListener();
     }
 
+    /**
+     * Creates an arrow button listener.
+     * @return an arrow button   listener
+     */
     protected ArrowButtonListener createArrowButtonListener(){
         return new ArrowButtonListener();
     }
 
+    /**
+     * Creates a model listener.
+     * @return a model listener
+     */
     protected ModelListener createModelListener(){
         return new ModelListener();
     }
 
+    /**
+     * Creates a scroll listener.
+     * @return a scroll listener
+     */
     protected ScrollListener createScrollListener(){
         return new ScrollListener();
     }
 
+    /**
+     * Creates a property change listener.
+     * @return a property change listener
+     */
     protected PropertyChangeListener createPropertyChangeListener() {
         return getHandler();
     }
 
     private void updateThumbState(int x, int y) {

@@ -468,27 +543,41 @@
      */
     public Dimension getMaximumSize(JComponent c) {
         return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
     }
 
+    /**
+     * Creates a decrease button.
+     * @param orientation the orientation
+     * @return a decrease button
+     */
     protected JButton createDecreaseButton(int orientation)  {
         return new BasicArrowButton(orientation,
                                     UIManager.getColor("ScrollBar.thumb"),
                                     UIManager.getColor("ScrollBar.thumbShadow"),
                                     UIManager.getColor("ScrollBar.thumbDarkShadow"),
                                     UIManager.getColor("ScrollBar.thumbHighlight"));
     }
 
+    /**
+     * Creates an increase button.
+     * @param orientation the orientation
+     * @return an increase button
+     */
     protected JButton createIncreaseButton(int orientation)  {
         return new BasicArrowButton(orientation,
                                     UIManager.getColor("ScrollBar.thumb"),
                                     UIManager.getColor("ScrollBar.thumbShadow"),
                                     UIManager.getColor("ScrollBar.thumbDarkShadow"),
                                     UIManager.getColor("ScrollBar.thumbHighlight"));
     }
 
 
+    /**
+     * Paints the decrease highlight.
+     * @param g the graphics
+     */
     protected void paintDecreaseHighlight(Graphics g)
     {
         Insets insets = scrollbar.getInsets();
         Rectangle thumbR = getThumbBounds();
         g.setColor(trackHighlightColor);

@@ -517,10 +606,14 @@
             g.fillRect(x, y, w, h);
         }
     }
 
 
+    /**
+     * Paints the increase highlight.
+     * @param g the graphics
+     */
     protected void paintIncreaseHighlight(Graphics g)
     {
         Insets insets = scrollbar.getInsets();
         Rectangle thumbR = getThumbBounds();
         g.setColor(trackHighlightColor);

@@ -550,10 +643,16 @@
             g.fillRect(x, y, w, h);
         }
     }
 
 
+    /**
+     * Paints the track.
+     * @param g the graphics
+     * @param c the component
+     * @param trackBounds the track bounds
+     */
     protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds)
     {
         g.setColor(trackColor);
         g.fillRect(trackBounds.x, trackBounds.y, trackBounds.width, trackBounds.height);
 

@@ -563,11 +662,16 @@
         else if(trackHighlight == INCREASE_HIGHLIGHT)           {
             paintIncreaseHighlight(g);
         }
     }
 
-
+    /**
+     * Paints the thumb.
+     * @param g the graphics
+     * @param c the component
+     * @param thumbBounds the thumb bounds
+     */
     protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds)
     {
         if(thumbBounds.isEmpty() || !scrollbar.isEnabled())     {
             return;
         }

@@ -642,10 +746,14 @@
 
     private int getValue(JScrollBar sb) {
         return (useCachedValue) ? scrollBarValue : sb.getValue();
     }
 
+    /**
+     * Laysouts a  vertical scroll bar.
+     * @param sb the scroll bar
+     */
     protected void layoutVScrollbar(JScrollBar sb)
     {
         Dimension sbSize = sb.getSize();
         Insets sbInsets = sb.getInsets();
 

@@ -740,11 +848,14 @@
             }
             setThumbBounds(itemX, thumbY, itemW, thumbH);
         }
     }
 
-
+    /**
+     * Laysouts a  vertical scroll bar.
+     * @param sb the scroll bar
+     */
     protected void layoutHScrollbar(JScrollBar sb)
     {
         Dimension sbSize = sb.getSize();
         Insets sbInsets = sb.getInsets();
 

@@ -964,10 +1075,14 @@
             }
 
             scrollbar.setValue(newValue);
     }
 
+    /**
+     * Scrolls by block.
+     * @param direction the direction to scroll
+     */
     protected void scrollByBlock(int direction)
     {
         scrollByBlock(scrollbar, direction);
             trackHighlight = direction > 0 ? INCREASE_HIGHLIGHT : DECREASE_HIGHLIGHT;
             Rectangle dirtyRect = getTrackBounds();

@@ -1031,10 +1146,14 @@
             }
             scrollbar.setValue(newValue);
         }
     }
 
+    /**
+     * Scrolls by unit.
+     * @param direction the direction to scroll
+     */
     protected void scrollByUnit(int direction)  {
         scrollByUnits(scrollbar, direction, 1, false);
     }
 
     /**

@@ -1048,11 +1167,10 @@
         return supportsAbsolutePositioning;
     }
 
     /**
      * A listener to listen for model changes.
-     *
      */
     protected class ModelListener implements ChangeListener {
         public void stateChanged(ChangeEvent e) {
             if (!useCachedValue) {
                 scrollBarValue = scrollbar.getValue();

@@ -1067,14 +1185,19 @@
      * Track mouse drags.
      */
     protected class TrackListener
         extends MouseAdapter implements MouseMotionListener
     {
+        /** The offset */
         protected transient int offset;
-        protected transient int currentMouseX, currentMouseY;
+        /** Current mouse x position */
+        protected transient int currentMouseX;
+        /** Current mouse y position */
+        protected transient int currentMouseY;
         private transient int direction = +1;
 
+        /** {@inheritDoc} */
         public void mouseReleased(MouseEvent e)
         {
             if (isDragging) {
                 updateThumbState(e.getX(), e.getY());
             }

@@ -1337,10 +1460,11 @@
                 }
                 break;
             }
         }
 
+        /** {@inheritDoc} */
         public void mouseMoved(MouseEvent e) {
             if (!isDragging) {
                 updateThumbState(e.getX(), e.getY());
             }
         }

@@ -1404,23 +1528,38 @@
     protected class ScrollListener implements ActionListener
     {
         int direction = +1;
         boolean useBlockIncrement;
 
+        /** Constructs a {@code ScrollListener}. */
         public ScrollListener() {
             direction = +1;
             useBlockIncrement = false;
         }
 
+        /**
+         * Constructs a {@code ScrollListener}.
+         * @param dir direction
+         * @param block use block increment
+         */
         public ScrollListener(int dir, boolean block)   {
             direction = dir;
             useBlockIncrement = block;
         }
 
+        /**
+         * Sets the direction.
+         * @param direction the new direction
+         */
         public void setDirection(int direction) { this.direction = direction; }
+        /**
+         * Sets the scrolling by block
+         * @param block whether or not to scroll by block
+         */
         public void setScrollByBlock(boolean block) { this.useBlockIncrement = block; }
 
+        /** {@inheritDoc} */
         public void actionPerformed(ActionEvent e) {
             if(useBlockIncrement)       {
                 scrollByBlock(direction);
                 // Stop scrolling if the thumb catches up with the mouse
                 if(scrollbar.getOrientation() == JScrollBar.VERTICAL)   {

@@ -1495,17 +1634,18 @@
                         orient == HORIZONTAL ? EAST : NORTH);
             }
         }
     }
 
+    /** Property change handler */
     public class PropertyChangeHandler implements PropertyChangeListener
     {
         // NOTE: This class exists only for backward compatibility. All
         // its functionality has been moved into Handler. If you need to add
         // new functionality add it to the Handler, but make sure this
         // class calls into the Handler.
-
+        /** {@inheritDoc} */
         public void propertyChange(PropertyChangeEvent e) {
             getHandler().propertyChange(e);
         }
     }
 
< prev index next >