54 |
import java.awt.event.MouseMotionListener; |
import java.awt.event.MouseMotionListener; |
55 |
import java.beans.PropertyChangeEvent; |
import java.beans.PropertyChangeEvent; |
56 |
import java.beans.PropertyChangeListener; |
import java.beans.PropertyChangeListener; |
|
|
|
57 |
import javax.swing.BoundedRangeModel; |
import javax.swing.BoundedRangeModel; |
58 |
import javax.swing.Icon; |
import javax.swing.Icon; |
59 |
import javax.swing.JButton; |
import javax.swing.JButton; |
77 |
SwingConstants |
SwingConstants |
78 |
{ |
{ |
79 |
/** |
/** |
80 |
* A helper class that listens to the two JButtons on each end |
* A helper class that listens to the two JButtons on each end of the |
81 |
* of the JScrollBar. |
* JScrollBar. |
82 |
*/ |
*/ |
83 |
protected class ArrowButtonListener extends MouseAdapter |
protected class ArrowButtonListener extends MouseAdapter |
84 |
{ |
{ |
85 |
/** |
/** |
86 |
* Move the thumb in the direction specified by the |
* Move the thumb in the direction specified by the button's arrow. If |
87 |
* button's arrow. If this button is held down, then |
* this button is held down, then it should keep moving the thumb. |
|
* it should keep moving the thumb. |
|
88 |
* |
* |
89 |
* @param e The MouseEvent fired by the JButton. |
* @param e The MouseEvent fired by the JButton. |
90 |
*/ |
*/ |
111 |
} |
} |
112 |
|
|
113 |
/** |
/** |
114 |
* A helper class that listens to the ScrollBar's model |
* A helper class that listens to the ScrollBar's model for ChangeEvents. |
|
* for ChangeEvents. |
|
115 |
*/ |
*/ |
116 |
protected class ModelListener implements ChangeListener |
protected class ModelListener implements ChangeListener |
117 |
{ |
{ |
124 |
{ |
{ |
125 |
// System.err.println(this + ".stateChanged()"); |
// System.err.println(this + ".stateChanged()"); |
126 |
calculatePreferredSize(); |
calculatePreferredSize(); |
127 |
layoutContainer(scrollbar); |
layoutContainer(scrollbar); |
128 |
getThumbBounds(); |
getThumbBounds(); |
129 |
scrollbar.repaint(); |
scrollbar.repaint(); |
130 |
} |
} |
154 |
decrButton.removeMouseListener(buttonListener); |
decrButton.removeMouseListener(buttonListener); |
155 |
incrButton = createIncreaseButton(scrollbar.getOrientation()); |
incrButton = createIncreaseButton(scrollbar.getOrientation()); |
156 |
decrButton = createDecreaseButton(scrollbar.getOrientation()); |
decrButton = createDecreaseButton(scrollbar.getOrientation()); |
157 |
incrButton.addMouseListener(buttonListener); |
incrButton.addMouseListener(buttonListener); |
158 |
decrButton.addMouseListener(buttonListener); |
decrButton.addMouseListener(buttonListener); |
159 |
calculatePreferredSize(); |
calculatePreferredSize(); |
160 |
layoutContainer(scrollbar); |
layoutContainer(scrollbar); |
161 |
} |
} |
162 |
layoutContainer(scrollbar); |
layoutContainer(scrollbar); |
163 |
scrollbar.repaint(); |
scrollbar.repaint(); |
164 |
} |
} |
165 |
} |
} |
166 |
|
|
167 |
/** |
/** |
168 |
* A helper class that listens for events from |
* A helper class that listens for events from the timer that is used to |
169 |
* the timer that is used to move the thumb. |
* move the thumb. |
170 |
*/ |
*/ |
171 |
protected class ScrollListener implements ActionListener |
protected class ScrollListener implements ActionListener |
172 |
{ |
{ |
177 |
private transient boolean block; |
private transient boolean block; |
178 |
|
|
179 |
/** |
/** |
180 |
* Creates a new ScrollListener object. |
* Creates a new ScrollListener object. The default is scrolling |
181 |
* The default is scrolling positively with block movement. |
* positively with block movement. |
182 |
*/ |
*/ |
183 |
public ScrollListener() |
public ScrollListener() |
184 |
{ |
{ |
187 |
} |
} |
188 |
|
|
189 |
/** |
/** |
190 |
* Creates a new ScrollListener object using |
* Creates a new ScrollListener object using the given direction and |
191 |
* the given direction and block. |
* block. |
192 |
* |
* |
193 |
* @param dir The direction to move in. |
* @param dir The direction to move in. |
194 |
* @param block Whether movement will be in blocks. |
* @param block Whether movement will be in blocks. |
231 |
// Only need to check it if it's block scrolling |
// Only need to check it if it's block scrolling |
232 |
// We only block scroll if the click occurs |
// We only block scroll if the click occurs |
233 |
// in the track. |
// in the track. |
234 |
|
if (! trackListener.shouldScroll(direction)) |
|
if (!trackListener.shouldScroll(direction)) |
|
235 |
{ |
{ |
236 |
trackHighlight = NO_HIGHLIGHT; |
trackHighlight = NO_HIGHLIGHT; |
237 |
scrollbar.repaint(); |
scrollbar.repaint(); |
256 |
/** The current Y coordinate of the mouse. */ |
/** The current Y coordinate of the mouse. */ |
257 |
protected int currentMouseY; |
protected int currentMouseY; |
258 |
|
|
259 |
/** The offset between the current mouse cursor and the |
/** |
260 |
current value of the scrollbar. */ |
* The offset between the current mouse cursor and the current value of |
261 |
|
* the scrollbar. |
262 |
|
*/ |
263 |
protected int offset; |
protected int offset; |
264 |
|
|
265 |
/** |
/** |
266 |
* This method is called when the mouse is being |
* This method is called when the mouse is being dragged. |
|
* dragged. |
|
267 |
* |
* |
268 |
* @param e The MouseEvent given. |
* @param e The MouseEvent given. |
269 |
*/ |
*/ |
272 |
currentMouseX = e.getX(); |
currentMouseX = e.getX(); |
273 |
currentMouseY = e.getY(); |
currentMouseY = e.getY(); |
274 |
if (scrollbar.getValueIsAdjusting()) |
if (scrollbar.getValueIsAdjusting()) |
275 |
{ |
{ |
276 |
int value; |
int value; |
277 |
if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL) |
if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL) |
278 |
value = valueForXPosition(currentMouseX) - offset; |
value = valueForXPosition(currentMouseX) - offset; |
279 |
else |
else |
280 |
value = valueForYPosition(currentMouseY) - offset; |
value = valueForYPosition(currentMouseY) - offset; |
281 |
|
|
282 |
scrollbar.setValue(value); |
scrollbar.setValue(value); |
283 |
} |
} |
284 |
} |
} |
285 |
|
|
286 |
/** |
/** |
295 |
} |
} |
296 |
|
|
297 |
/** |
/** |
298 |
* This method is called when the mouse is |
* This method is called when the mouse is pressed. When it is pressed, |
299 |
* pressed. When it is pressed, the thumb should |
* the thumb should move in blocks towards the cursor. |
|
* move in blocks towards the cursor. |
|
300 |
* |
* |
301 |
* @param e The MouseEvent given. |
* @param e The MouseEvent given. |
302 |
*/ |
*/ |
314 |
if (value == scrollbar.getValue()) |
if (value == scrollbar.getValue()) |
315 |
return; |
return; |
316 |
|
|
317 |
if (!thumbRect.contains(e.getPoint())) |
if (! thumbRect.contains(e.getPoint())) |
318 |
{ |
{ |
319 |
scrollTimer.stop(); |
scrollTimer.stop(); |
320 |
scrollListener.setScrollByBlock(true); |
scrollListener.setScrollByBlock(true); |
340 |
// to that value. |
// to that value. |
341 |
scrollbar.setValueIsAdjusting(true); |
scrollbar.setValueIsAdjusting(true); |
342 |
offset = value - scrollbar.getValue(); |
offset = value - scrollbar.getValue(); |
343 |
} |
} |
344 |
scrollbar.repaint(); |
scrollbar.repaint(); |
345 |
} |
} |
346 |
|
|
347 |
/** |
/** |
348 |
* This method is called when the mouse is released. |
* This method is called when the mouse is released. It should stop |
349 |
* It should stop movement on the thumb |
* movement on the thumb |
350 |
* |
* |
351 |
* @param e The MouseEvent given. |
* @param e The MouseEvent given. |
352 |
*/ |
*/ |
354 |
{ |
{ |
355 |
trackHighlight = NO_HIGHLIGHT; |
trackHighlight = NO_HIGHLIGHT; |
356 |
scrollTimer.stop(); |
scrollTimer.stop(); |
357 |
|
|
358 |
if (scrollbar.getValueIsAdjusting()) |
if (scrollbar.getValueIsAdjusting()) |
359 |
scrollbar.setValueIsAdjusting(false); |
scrollbar.setValueIsAdjusting(false); |
360 |
scrollbar.repaint(); |
scrollbar.repaint(); |
361 |
} |
} |
362 |
|
|
363 |
/** |
/** |
364 |
* A helper method that decides whether we should |
* A helper method that decides whether we should keep scrolling in the |
365 |
* keep scrolling in the given direction. |
* given direction. |
366 |
* |
* |
367 |
* @param direction The direction to check for. |
* @param direction The direction to check for. |
368 |
* |
* |
369 |
* @return Whether the thumb should keep scrolling. |
* @return Whether the thumb should keep scrolling. |
370 |
*/ |
*/ |
371 |
public boolean shouldScroll (int direction) |
public boolean shouldScroll(int direction) |
372 |
{ |
{ |
373 |
int value; |
int value; |
374 |
if (scrollbar.getOrientation() == HORIZONTAL) |
if (scrollbar.getOrientation() == HORIZONTAL) |
375 |
value = valueForXPosition(currentMouseX); |
value = valueForXPosition(currentMouseX); |
376 |
else |
else |
377 |
value = valueForYPosition(currentMouseY); |
value = valueForYPosition(currentMouseY); |
378 |
|
|
379 |
if (direction == POSITIVE_SCROLL) |
if (direction == POSITIVE_SCROLL) |
380 |
return (value > scrollbar.getValue()); |
return (value > scrollbar.getValue()); |
381 |
else |
else |
382 |
return (value < scrollbar.getValue()); |
return (value < scrollbar.getValue()); |
383 |
} |
} |
384 |
} |
} |
385 |
|
|
389 |
/** The listener that listens to the model. */ |
/** The listener that listens to the model. */ |
390 |
protected ModelListener modelListener; |
protected ModelListener modelListener; |
391 |
|
|
392 |
/** The listener that listens to the scrollbar for property |
/** The listener that listens to the scrollbar for property changes. */ |
|
changes. */ |
|
393 |
protected PropertyChangeListener propertyChangeListener; |
protected PropertyChangeListener propertyChangeListener; |
394 |
|
|
395 |
/** The listener that listens to the timer. */ |
/** The listener that listens to the timer. */ |
422 |
/** The outer light shadow for the thumb. */ |
/** The outer light shadow for the thumb. */ |
423 |
protected Color thumbLightShadowColor; |
protected Color thumbLightShadowColor; |
424 |
|
|
425 |
/** The color that is used when the mouse press |
/** The color that is used when the mouse press occurs in the track. */ |
|
occurs in the track. */ |
|
426 |
protected Color trackHighlightColor; |
protected Color trackHighlightColor; |
427 |
|
|
428 |
/** The color of the track. */ |
/** The color of the track. */ |
465 |
protected JScrollBar scrollbar; |
protected JScrollBar scrollbar; |
466 |
|
|
467 |
/** |
/** |
|
* A helper class that allows us to draw icons for |
|
|
* the JButton. |
|
|
*/ |
|
|
private static class arrowIcon implements Icon |
|
|
{ |
|
|
/** The polygon that describes the icon. */ |
|
|
private Polygon arrow; |
|
|
|
|
|
/** |
|
|
* Creates a new arrowIcon object. |
|
|
* |
|
|
* @param arrow The polygon that describes the arrow. |
|
|
*/ |
|
|
public arrowIcon(Polygon arrow) |
|
|
{ |
|
|
this.arrow = arrow; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Returns the height of the icon. |
|
|
* |
|
|
* @return The height of the icon. |
|
|
*/ |
|
|
public int getIconHeight() |
|
|
{ |
|
|
return 10; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Returns the width of the icon. |
|
|
* |
|
|
* @return The width of the icon. |
|
|
*/ |
|
|
public int getIconWidth() |
|
|
{ |
|
|
return 10; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Paints the icon. |
|
|
* |
|
|
* @param c The Component to paint for. |
|
|
* @param g The Graphics object to draw with. |
|
|
* @param x The X coordinate to draw at. |
|
|
* @param y The Y coordinate to draw at. |
|
|
*/ |
|
|
public void paintIcon(Component c, Graphics g, int x, int y) |
|
|
{ |
|
|
g.translate(x, y); |
|
|
|
|
|
Color saved = g.getColor(); |
|
|
|
|
|
g.setColor(Color.BLACK); |
|
|
|
|
|
g.fillPolygon(arrow); |
|
|
|
|
|
g.setColor(saved); |
|
|
g.translate(-x, -y); |
|
|
} |
|
|
} |
|
|
|
|
|
/** The Icon that points up. */ |
|
|
private static Icon upIcon = new arrowIcon(new Polygon(new int[] { 2, 5, 8 }, |
|
|
new int[] { 7, 3, 7 }, |
|
|
3)); |
|
|
|
|
|
/** The Icon that points down. */ |
|
|
private static Icon downIcon = new arrowIcon(new Polygon(new int[] { 2, 5, 8 }, |
|
|
new int[] { 3, 7, 3 }, |
|
|
3)); |
|
|
|
|
|
/** The Icon that points left. */ |
|
|
private static Icon leftIcon = new arrowIcon(new Polygon(new int[] { 7, 3, 7 }, |
|
|
new int[] { 2, 5, 8 }, |
|
|
3)); |
|
|
|
|
|
/** The Icon that points right. */ |
|
|
private static Icon rightIcon = new arrowIcon(new Polygon(new int[] { 3, 7, 3}, |
|
|
new int[] { 2, 5, 8}, |
|
|
3)); |
|
|
|
|
|
/** |
|
468 |
* This method adds a component to the layout. |
* This method adds a component to the layout. |
469 |
* |
* |
470 |
* @param name The name to associate with the component that is added. |
* @param name The name to associate with the component that is added. |
477 |
} |
} |
478 |
|
|
479 |
/** |
/** |
480 |
* This method configures the scrollbar's colors. This can be |
* This method configures the scrollbar's colors. This can be done by |
481 |
* done by looking up the standard colors from the Look and Feel defaults. |
* looking up the standard colors from the Look and Feel defaults. |
482 |
*/ |
*/ |
483 |
protected void configureScrollBarColors() |
protected void configureScrollBarColors() |
484 |
{ |
{ |
485 |
UIDefaults defaults = UIManager.getLookAndFeelDefaults(); |
UIDefaults defaults = UIManager.getLookAndFeelDefaults(); |
486 |
|
|
487 |
trackColor = defaults.getColor("ScrollBar.track"); |
trackColor = defaults.getColor("ScrollBar.track"); |
488 |
trackHighlightColor = defaults.getColor("ScrollBar.trackHighlight"); |
trackHighlightColor = defaults.getColor("ScrollBar.trackHighlight"); |
489 |
thumbColor = defaults.getColor("ScrollBar.thumb"); |
thumbColor = defaults.getColor("ScrollBar.thumb"); |
490 |
thumbHighlightColor = defaults.getColor("ScrollBar.thumbHighlight"); |
thumbHighlightColor = defaults.getColor("ScrollBar.thumbHighlight"); |
491 |
thumbDarkShadowColor = defaults.getColor("ScrollBar.thumbDarkShadow"); |
thumbDarkShadowColor = defaults.getColor("ScrollBar.thumbDarkShadow"); |
492 |
thumbLightShadowColor = defaults.getColor("ScrollBar.thumbLightShadow"); |
thumbLightShadowColor = defaults.getColor("ScrollBar.thumbLightShadow"); |
493 |
} |
} |
494 |
|
|
495 |
/** |
/** |
502 |
return new ArrowButtonListener(); |
return new ArrowButtonListener(); |
503 |
} |
} |
504 |
|
|
505 |
/** |
/** |
506 |
* This method creates a new JButton with the appropriate |
* This method creates a new JButton with the appropriate icon for the |
507 |
* icon for the orientation. |
* orientation. |
508 |
* |
* |
509 |
* @param orientation The orientation this JButton uses. |
* @param orientation The orientation this JButton uses. |
510 |
* |
* |
513 |
protected JButton createIncreaseButton(int orientation) |
protected JButton createIncreaseButton(int orientation) |
514 |
{ |
{ |
515 |
if (incrButton == null) |
if (incrButton == null) |
516 |
|
incrButton = new BasicArrowButton((orientation == SwingConstants.HORIZONTAL) |
517 |
|
? SwingConstants.EAST |
518 |
|
: SwingConstants.SOUTH); |
519 |
|
else |
520 |
{ |
{ |
521 |
incrButton = new JButton(); |
if (orientation == SwingConstants.HORIZONTAL) |
522 |
incrButton.setMargin(new Insets(0,0,0,0)); |
((BasicArrowButton) incrButton).setDirection(SwingConstants.EAST); |
523 |
incrButton.setHorizontalAlignment(SwingConstants.CENTER); |
else |
524 |
incrButton.setHorizontalTextPosition(SwingConstants.CENTER); |
((BasicArrowButton) incrButton).setDirection(SwingConstants.SOUTH); |
|
incrButton.setVerticalAlignment(SwingConstants.CENTER); |
|
|
incrButton.setVerticalTextPosition(SwingConstants.CENTER); |
|
525 |
} |
} |
|
|
|
|
if (orientation == SwingConstants.HORIZONTAL) |
|
|
incrButton.setIcon(rightIcon); |
|
|
else |
|
|
incrButton.setIcon(downIcon); |
|
|
|
|
526 |
return incrButton; |
return incrButton; |
527 |
} |
} |
528 |
|
|
529 |
/** |
/** |
530 |
* This method creates a new JButton with the appropriate |
* This method creates a new JButton with the appropriate icon for the |
531 |
* icon for the orientation. |
* orientation. |
532 |
* |
* |
533 |
* @param orientation The orientation this JButton uses. |
* @param orientation The orientation this JButton uses. |
534 |
* |
* |
537 |
protected JButton createDecreaseButton(int orientation) |
protected JButton createDecreaseButton(int orientation) |
538 |
{ |
{ |
539 |
if (decrButton == null) |
if (decrButton == null) |
540 |
|
decrButton = new BasicArrowButton((orientation == SwingConstants.HORIZONTAL) |
541 |
|
? SwingConstants.WEST |
542 |
|
: SwingConstants.NORTH); |
543 |
|
else |
544 |
{ |
{ |
545 |
decrButton = new JButton(); |
if (orientation == SwingConstants.HORIZONTAL) |
546 |
decrButton.setMargin(new Insets(0,0,0,0)); |
((BasicArrowButton) decrButton).setDirection(SwingConstants.WEST); |
547 |
decrButton.setHorizontalAlignment(SwingConstants.CENTER); |
else |
548 |
decrButton.setHorizontalTextPosition(SwingConstants.CENTER); |
((BasicArrowButton) decrButton).setDirection(SwingConstants.NORTH); |
|
decrButton.setVerticalAlignment(SwingConstants.CENTER); |
|
|
decrButton.setVerticalTextPosition(SwingConstants.CENTER); |
|
549 |
} |
} |
|
|
|
|
if (orientation == SwingConstants.HORIZONTAL) |
|
|
decrButton.setIcon(leftIcon); |
|
|
else |
|
|
decrButton.setIcon(upIcon); |
|
|
|
|
550 |
return decrButton; |
return decrButton; |
551 |
} |
} |
552 |
|
|
647 |
} |
} |
648 |
|
|
649 |
/** |
/** |
650 |
* This method calculates the preferred size since |
* This method calculates the preferred size since calling |
651 |
* calling getPreferredSize() returns a cached value. |
* getPreferredSize() returns a cached value. |
652 |
*/ |
*/ |
653 |
private void calculatePreferredSize() |
private void calculatePreferredSize() |
654 |
{ |
{ |
655 |
// System.err.println(this + ".calculatePreferredSize()"); |
// System.err.println(this + ".calculatePreferredSize()"); |
|
|
|
656 |
int height; |
int height; |
657 |
int width; |
int width; |
658 |
height = width = 0; |
height = width = 0; |
693 |
} |
} |
694 |
|
|
695 |
/** |
/** |
696 |
* This method returns a cached value of the preferredSize. |
* This method returns a cached value of the preferredSize. The only |
697 |
* The only restrictions are: If the scrollbar is horizontal, the |
* restrictions are: If the scrollbar is horizontal, the height should be |
698 |
* height should be the maximum of the height of the JButtons and |
* the maximum of the height of the JButtons and the minimum width of the |
699 |
* the minimum width of the thumb. For vertical scrollbars, the |
* thumb. For vertical scrollbars, the calculation is similar (swap width |
700 |
* calculation is similar (swap width for height and vice versa). |
* for height and vice versa). |
701 |
* |
* |
702 |
* @param c The JComponent to measure. |
* @param c The JComponent to measure. |
703 |
* |
* |
710 |
} |
} |
711 |
|
|
712 |
/** |
/** |
713 |
* This method returns the thumb's bounds based on the |
* This method returns the thumb's bounds based on the current value of the |
714 |
* current value of the scrollbar. This method updates the |
* scrollbar. This method updates the cached value and returns that. |
|
* cached value and returns that. |
|
715 |
* |
* |
716 |
* @return The thumb bounds. |
* @return The thumb bounds. |
717 |
*/ |
*/ |
723 |
int extent = scrollbar.getVisibleAmount(); |
int extent = scrollbar.getVisibleAmount(); |
724 |
|
|
725 |
// System.err.println(this + ".getThumbBounds()"); |
// System.err.println(this + ".getThumbBounds()"); |
|
|
|
726 |
if (max == min) |
if (max == min) |
|
{ |
|
|
thumbRect.x = trackRect.x; |
|
|
thumbRect.y = trackRect.y; |
|
|
if (scrollbar.getOrientation() == HORIZONTAL) |
|
727 |
{ |
{ |
728 |
thumbRect.width = getMinimumThumbSize().width; |
thumbRect.x = trackRect.x; |
729 |
thumbRect.height = trackRect.height; |
thumbRect.y = trackRect.y; |
730 |
|
if (scrollbar.getOrientation() == HORIZONTAL) |
731 |
|
{ |
732 |
|
thumbRect.width = getMinimumThumbSize().width; |
733 |
|
thumbRect.height = trackRect.height; |
734 |
|
} |
735 |
|
else |
736 |
|
{ |
737 |
|
thumbRect.width = trackRect.width; |
738 |
|
thumbRect.height = getMinimumThumbSize().height; |
739 |
|
} |
740 |
|
return thumbRect; |
741 |
} |
} |
|
else |
|
|
{ |
|
|
thumbRect.width = trackRect.width; |
|
|
thumbRect.height = getMinimumThumbSize().height; |
|
|
} |
|
|
return thumbRect; |
|
|
} |
|
|
|
|
742 |
|
|
743 |
if (scrollbar.getOrientation() == HORIZONTAL) |
if (scrollbar.getOrientation() == HORIZONTAL) |
744 |
{ |
{ |
752 |
else |
else |
753 |
{ |
{ |
754 |
thumbRect.x = trackRect.x; |
thumbRect.x = trackRect.x; |
755 |
thumbRect.y = trackRect.y |
thumbRect.y = trackRect.y + value * trackRect.height / (max - min); |
|
+ value * trackRect.height / (max - min); |
|
756 |
|
|
757 |
thumbRect.width = trackRect.width; |
thumbRect.width = trackRect.width; |
758 |
thumbRect.height = extent * trackRect.height / (max - min); |
thumbRect.height = extent * trackRect.height / (max - min); |
761 |
} |
} |
762 |
|
|
763 |
/** |
/** |
764 |
* This method calculates the bounds of the track. This method |
* This method calculates the bounds of the track. This method updates the |
765 |
* updates the cached value and returns it. |
* cached value and returns it. |
766 |
* |
* |
767 |
* @return The track's bounds. |
* @return The track's bounds. |
768 |
*/ |
*/ |
788 |
} |
} |
789 |
|
|
790 |
/** |
/** |
791 |
* This method installs any addition Components that |
* This method installs any addition Components that are a part of or |
792 |
* are a part of or related to this scrollbar. |
* related to this scrollbar. |
793 |
*/ |
*/ |
794 |
protected void installComponents() |
protected void installComponents() |
795 |
{ |
{ |
800 |
} |
} |
801 |
|
|
802 |
/** |
/** |
803 |
* This method installs the defaults for the scrollbar specified |
* This method installs the defaults for the scrollbar specified by the |
804 |
* by the Basic Look and Feel. |
* Basic Look and Feel. |
805 |
*/ |
*/ |
806 |
protected void installDefaults() |
protected void installDefaults() |
807 |
{ |
{ |
825 |
} |
} |
826 |
|
|
827 |
/** |
/** |
828 |
* This method installs any listeners for the scrollbar. |
* This method installs any listeners for the scrollbar. This method also |
829 |
* This method also installs listeners for things such as |
* installs listeners for things such as the JButtons and the timer. |
|
* the JButtons and the timer. |
|
830 |
*/ |
*/ |
831 |
protected void installListeners() |
protected void installListeners() |
832 |
{ |
{ |
849 |
} |
} |
850 |
|
|
851 |
/** |
/** |
852 |
* This method installs the UI for the component. |
* This method installs the UI for the component. This can include setting |
853 |
* This can include setting up listeners, defaults, |
* up listeners, defaults, and components. This also includes initializing |
854 |
* and components. This also includes initializing any data |
* any data objects. |
|
* objects. |
|
855 |
* |
* |
856 |
* @param c The JComponent to install. |
* @param c The JComponent to install. |
857 |
*/ |
*/ |
874 |
configureScrollBarColors(); |
configureScrollBarColors(); |
875 |
|
|
876 |
calculatePreferredSize(); |
calculatePreferredSize(); |
877 |
layoutContainer(scrollbar); |
layoutContainer(scrollbar); |
878 |
} |
} |
879 |
} |
} |
880 |
|
|
970 |
} |
} |
971 |
|
|
972 |
/** |
/** |
973 |
* This method is called when repainting and the mouse is |
* This method is called when repainting and the mouse is pressed in the |
974 |
* pressed in the track. It paints the track below the thumb |
* track. It paints the track below the thumb with the trackHighlight |
975 |
* with the trackHighlight color. |
* color. |
976 |
* |
* |
977 |
* @param g The Graphics object to paint with. |
* @param g The Graphics object to paint with. |
978 |
*/ |
*/ |
985 |
g.fillRect(trackRect.x, trackRect.y, thumbRect.x - trackRect.x, |
g.fillRect(trackRect.x, trackRect.y, thumbRect.x - trackRect.x, |
986 |
trackRect.height); |
trackRect.height); |
987 |
else |
else |
988 |
g.fillRect(trackRect.x, trackRect.y, trackRect.width, |
g.fillRect(trackRect.x, trackRect.y, trackRect.width, |
989 |
thumbRect.y - trackRect.y); |
thumbRect.y - trackRect.y); |
990 |
g.setColor(saved); |
g.setColor(saved); |
991 |
} |
} |
992 |
|
|
993 |
/** |
/** |
994 |
* This method is called when repainting and the mouse is |
* This method is called when repainting and the mouse is pressed in the |
995 |
* pressed in the track. It paints the track above the thumb |
* track. It paints the track above the thumb with the trackHighlight |
996 |
* with the trackHighlight color. |
* color. |
997 |
* |
* |
998 |
* @param g The Graphics objet to paint with. |
* @param g The Graphics objet to paint with. |
999 |
*/ |
*/ |
1006 |
g.fillRect(thumbRect.x + thumbRect.width, trackRect.y, |
g.fillRect(thumbRect.x + thumbRect.width, trackRect.y, |
1007 |
trackRect.x + trackRect.width - thumbRect.x - thumbRect.width, |
trackRect.x + trackRect.width - thumbRect.x - thumbRect.width, |
1008 |
trackRect.height); |
trackRect.height); |
1009 |
else |
else |
1010 |
g.fillRect(trackRect.x, thumbRect.y + thumbRect.height, |
g.fillRect(trackRect.x, thumbRect.y + thumbRect.height, trackRect.width, |
1011 |
trackRect.width, |
trackRect.y + trackRect.height - thumbRect.y |
1012 |
trackRect.y + trackRect.height - thumbRect.y - |
- thumbRect.height); |
|
thumbRect.height); |
|
1013 |
g.setColor(saved); |
g.setColor(saved); |
1014 |
} |
} |
1015 |
|
|
1113 |
} |
} |
1114 |
|
|
1115 |
/** |
/** |
1116 |
* The method scrolls the thumb by a block in the |
* The method scrolls the thumb by a block in the direction specified. |
|
* direction specified. |
|
1117 |
* |
* |
1118 |
* @param direction The direction to scroll. |
* @param direction The direction to scroll. |
1119 |
*/ |
*/ |
1120 |
protected void scrollByBlock(int direction) |
protected void scrollByBlock(int direction) |
1121 |
{ |
{ |
1122 |
scrollbar.setValue(scrollbar.getValue() + scrollbar.getBlockIncrement(direction)); |
scrollbar.setValue(scrollbar.getValue() |
1123 |
|
+ scrollbar.getBlockIncrement(direction)); |
1124 |
} |
} |
1125 |
|
|
1126 |
/** |
/** |
1127 |
* The method scrolls the thumb by a unit in the |
* The method scrolls the thumb by a unit in the direction specified. |
|
* direction specified. |
|
1128 |
* |
* |
1129 |
* @param direction The direction to scroll. |
* @param direction The direction to scroll. |
1130 |
*/ |
*/ |
1131 |
protected void scrollByUnit(int direction) |
protected void scrollByUnit(int direction) |
1132 |
{ |
{ |
1133 |
scrollbar.setValue(scrollbar.getValue() + scrollbar.getUnitIncrement(direction)); |
scrollbar.setValue(scrollbar.getValue() |
1134 |
|
+ scrollbar.getUnitIncrement(direction)); |
1135 |
} |
} |
1136 |
|
|
1137 |
/** |
/** |
1151 |
} |
} |
1152 |
|
|
1153 |
/** |
/** |
1154 |
* This method uninstalls any components that |
* This method uninstalls any components that are a part of or related to |
1155 |
* are a part of or related to this scrollbar. |
* this scrollbar. |
1156 |
*/ |
*/ |
1157 |
protected void uninstallComponents() |
protected void uninstallComponents() |
1158 |
{ |
{ |
1163 |
} |
} |
1164 |
|
|
1165 |
/** |
/** |
1166 |
* This method uninstalls any defaults that this |
* This method uninstalls any defaults that this scrollbar acquired from the |
1167 |
* scrollbar acquired from the Basic Look and Feel defaults. |
* Basic Look and Feel defaults. |
1168 |
*/ |
*/ |
1169 |
protected void uninstallDefaults() |
protected void uninstallDefaults() |
1170 |
{ |
{ |
1174 |
} |
} |
1175 |
|
|
1176 |
/** |
/** |
1177 |
* This method uninstalls any keyboard |
* This method uninstalls any keyboard actions this scrollbar acquired |
1178 |
* actions this scrollbar acquired during install. |
* during install. |
1179 |
*/ |
*/ |
1180 |
protected void uninstallKeyboardActions() |
protected void uninstallKeyboardActions() |
1181 |
{ |
{ |
1183 |
} |
} |
1184 |
|
|
1185 |
/** |
/** |
1186 |
* This method uninstalls any listeners that |
* This method uninstalls any listeners that were registered during install. |
|
* were registered during install. |
|
1187 |
*/ |
*/ |
1188 |
protected void uninstallListeners() |
protected void uninstallListeners() |
1189 |
{ |
{ |
1190 |
scrollTimer.removeActionListener(scrollListener); |
scrollTimer.removeActionListener(scrollListener); |
1191 |
|
|
1192 |
scrollbar.getModel().removeChangeListener(modelListener); |
scrollbar.getModel().removeChangeListener(modelListener); |
1193 |
scrollbar.removePropertyChangeListener(propertyChangeListener); |
scrollbar.removePropertyChangeListener(propertyChangeListener); |
1194 |
|
|
1195 |
decrButton.removeMouseListener(buttonListener); |
decrButton.removeMouseListener(buttonListener); |
1196 |
incrButton.removeMouseListener(buttonListener); |
incrButton.removeMouseListener(buttonListener); |
1197 |
|
|
1198 |
scrollbar.removeMouseListener(trackListener); |
scrollbar.removeMouseListener(trackListener); |
1199 |
scrollbar.removeMouseMotionListener(trackListener); |
scrollbar.removeMouseMotionListener(trackListener); |
1200 |
|
|
1201 |
propertyChangeListener = null; |
propertyChangeListener = null; |
1202 |
modelListener = null; |
modelListener = null; |
1203 |
buttonListener = null; |
buttonListener = null; |
1206 |
} |
} |
1207 |
|
|
1208 |
/** |
/** |
1209 |
* This method uninstalls the UI. This includes |
* This method uninstalls the UI. This includes removing any defaults, |
1210 |
* removing any defaults, listeners, and components |
* listeners, and components that this UI may have initialized. It also |
1211 |
* that this UI may have initialized. It also nulls |
* nulls any instance data. |
|
* any instance data. |
|
1212 |
* |
* |
1213 |
* @param c The Component to uninstall for. |
* @param c The Component to uninstall for. |
1214 |
*/ |
*/ |
1217 |
uninstallDefaults(); |
uninstallDefaults(); |
1218 |
uninstallListeners(); |
uninstallListeners(); |
1219 |
uninstallComponents(); |
uninstallComponents(); |
1220 |
|
|
1221 |
scrollTimer = null; |
scrollTimer = null; |
1222 |
|
|
1223 |
thumbRect = null; |
thumbRect = null; |
1224 |
trackRect = null; |
trackRect = null; |
1225 |
|
|
1226 |
trackColor = null; |
trackColor = null; |
1227 |
trackHighlightColor = null; |
trackHighlightColor = null; |
1228 |
thumbColor = null; |
thumbColor = null; |
1229 |
thumbHighlightColor = null; |
thumbHighlightColor = null; |
1230 |
thumbDarkShadowColor = null; |
thumbDarkShadowColor = null; |
1231 |
thumbLightShadowColor = null; |
thumbLightShadowColor = null; |
1232 |
|
|
1233 |
scrollbar = null; |
scrollbar = null; |
1234 |
} |
} |
1235 |
|
|