152 |
{ |
{ |
153 |
incrButton.removeMouseListener(buttonListener); |
incrButton.removeMouseListener(buttonListener); |
154 |
decrButton.removeMouseListener(buttonListener); |
decrButton.removeMouseListener(buttonListener); |
155 |
incrButton = createIncreaseButton(scrollbar.getOrientation()); |
int orientation = scrollbar.getOrientation(); |
156 |
decrButton = createDecreaseButton(scrollbar.getOrientation()); |
switch (orientation) |
157 |
|
{ |
158 |
|
case (JScrollBar.HORIZONTAL): |
159 |
|
incrButton = createIncreaseButton(EAST); |
160 |
|
decrButton = createDecreaseButton(WEST); |
161 |
|
break; |
162 |
|
default: |
163 |
|
incrButton = createIncreaseButton(SOUTH); |
164 |
|
decrButton = createDecreaseButton(NORTH); |
165 |
|
break; |
166 |
|
} |
167 |
incrButton.addMouseListener(buttonListener); |
incrButton.addMouseListener(buttonListener); |
168 |
decrButton.addMouseListener(buttonListener); |
decrButton.addMouseListener(buttonListener); |
169 |
calculatePreferredSize(); |
calculatePreferredSize(); |
499 |
thumbColor = defaults.getColor("ScrollBar.thumb"); |
thumbColor = defaults.getColor("ScrollBar.thumb"); |
500 |
thumbHighlightColor = defaults.getColor("ScrollBar.thumbHighlight"); |
thumbHighlightColor = defaults.getColor("ScrollBar.thumbHighlight"); |
501 |
thumbDarkShadowColor = defaults.getColor("ScrollBar.thumbDarkShadow"); |
thumbDarkShadowColor = defaults.getColor("ScrollBar.thumbDarkShadow"); |
502 |
thumbLightShadowColor = defaults.getColor("ScrollBar.thumbLightShadow"); |
thumbLightShadowColor = defaults.getColor("ScrollBar.thumbShadow"); |
503 |
} |
} |
504 |
|
|
505 |
/** |
/** |
523 |
protected JButton createIncreaseButton(int orientation) |
protected JButton createIncreaseButton(int orientation) |
524 |
{ |
{ |
525 |
if (incrButton == null) |
if (incrButton == null) |
526 |
incrButton = new BasicArrowButton((orientation == SwingConstants.HORIZONTAL) |
incrButton = new BasicArrowButton(orientation); |
|
? SwingConstants.EAST |
|
|
: SwingConstants.SOUTH); |
|
527 |
else |
else |
528 |
{ |
((BasicArrowButton) incrButton).setDirection(orientation); |
|
if (orientation == SwingConstants.HORIZONTAL) |
|
|
((BasicArrowButton) incrButton).setDirection(SwingConstants.EAST); |
|
|
else |
|
|
((BasicArrowButton) incrButton).setDirection(SwingConstants.SOUTH); |
|
|
} |
|
529 |
return incrButton; |
return incrButton; |
530 |
} |
} |
531 |
|
|
540 |
protected JButton createDecreaseButton(int orientation) |
protected JButton createDecreaseButton(int orientation) |
541 |
{ |
{ |
542 |
if (decrButton == null) |
if (decrButton == null) |
543 |
decrButton = new BasicArrowButton((orientation == SwingConstants.HORIZONTAL) |
decrButton = new BasicArrowButton(orientation); |
|
? SwingConstants.WEST |
|
|
: SwingConstants.NORTH); |
|
544 |
else |
else |
545 |
{ |
((BasicArrowButton) decrButton).setDirection(orientation); |
|
if (orientation == SwingConstants.HORIZONTAL) |
|
|
((BasicArrowButton) decrButton).setDirection(SwingConstants.WEST); |
|
|
else |
|
|
((BasicArrowButton) decrButton).setDirection(SwingConstants.NORTH); |
|
|
} |
|
546 |
return decrButton; |
return decrButton; |
547 |
} |
} |
548 |
|
|
645 |
/** |
/** |
646 |
* This method calculates the preferred size since calling |
* This method calculates the preferred size since calling |
647 |
* getPreferredSize() returns a cached value. |
* getPreferredSize() returns a cached value. |
648 |
|
* This is package-private to avoid an accessor method. |
649 |
*/ |
*/ |
650 |
private void calculatePreferredSize() |
void calculatePreferredSize() |
651 |
{ |
{ |
652 |
// System.err.println(this + ".calculatePreferredSize()"); |
// System.err.println(this + ".calculatePreferredSize()"); |
653 |
int height; |
int height; |
743 |
thumbRect.x += (value - min) * trackRect.width / (max - min); |
thumbRect.x += (value - min) * trackRect.width / (max - min); |
744 |
thumbRect.y = trackRect.y; |
thumbRect.y = trackRect.y; |
745 |
|
|
746 |
thumbRect.width = extent * trackRect.width / (max - min); |
thumbRect.width = Math.max(extent * trackRect.width / (max - min), |
747 |
|
getMinimumThumbSize().width); |
748 |
thumbRect.height = trackRect.height; |
thumbRect.height = trackRect.height; |
749 |
} |
} |
750 |
else |
else |
753 |
thumbRect.y = trackRect.y + value * trackRect.height / (max - min); |
thumbRect.y = trackRect.y + value * trackRect.height / (max - min); |
754 |
|
|
755 |
thumbRect.width = trackRect.width; |
thumbRect.width = trackRect.width; |
756 |
thumbRect.height = extent * trackRect.height / (max - min); |
thumbRect.height = Math.max(extent * trackRect.height / (max - min), |
757 |
|
getMinimumThumbSize().height); |
758 |
} |
} |
759 |
return thumbRect; |
return thumbRect; |
760 |
} |
} |
792 |
*/ |
*/ |
793 |
protected void installComponents() |
protected void installComponents() |
794 |
{ |
{ |
795 |
incrButton = createIncreaseButton(scrollbar.getOrientation()); |
int orientation = scrollbar.getOrientation(); |
796 |
|
switch (orientation) |
797 |
|
{ |
798 |
|
case (JScrollBar.HORIZONTAL): |
799 |
|
incrButton = createIncreaseButton(EAST); |
800 |
|
decrButton = createDecreaseButton(WEST); |
801 |
|
break; |
802 |
|
default: |
803 |
|
incrButton = createIncreaseButton(SOUTH); |
804 |
|
decrButton = createDecreaseButton(NORTH); |
805 |
|
break; |
806 |
|
} |
807 |
scrollbar.add(incrButton); |
scrollbar.add(incrButton); |
|
decrButton = createDecreaseButton(scrollbar.getOrientation()); |
|
808 |
scrollbar.add(decrButton); |
scrollbar.add(decrButton); |
809 |
} |
} |
810 |
|
|
821 |
scrollbar.setBorder(defaults.getBorder("ScrollBar.border")); |
scrollbar.setBorder(defaults.getBorder("ScrollBar.border")); |
822 |
scrollbar.setOpaque(true); |
scrollbar.setOpaque(true); |
823 |
|
|
824 |
|
thumbColor = defaults.getColor("ScrollBar.thumb"); |
825 |
|
thumbDarkShadowColor = defaults.getColor("ScrollBar.thumbDarkShadow"); |
826 |
|
thumbHighlightColor = defaults.getColor("ScrollBar.thumbHighlight"); |
827 |
|
thumbLightShadowColor = defaults.getColor("ScrollBar.thumbShadow"); |
828 |
|
|
829 |
maximumThumbSize = defaults.getDimension("ScrollBar.maximumThumbSize"); |
maximumThumbSize = defaults.getDimension("ScrollBar.maximumThumbSize"); |
830 |
minimumThumbSize = defaults.getDimension("ScrollBar.minimumThumbSize"); |
minimumThumbSize = defaults.getDimension("ScrollBar.minimumThumbSize"); |
831 |
} |
} |
883 |
scrollTimer.setRepeats(true); |
scrollTimer.setRepeats(true); |
884 |
|
|
885 |
installComponents(); |
installComponents(); |
|
installListeners(); |
|
886 |
installDefaults(); |
installDefaults(); |
887 |
configureScrollBarColors(); |
configureScrollBarColors(); |
888 |
|
installListeners(); |
889 |
|
|
890 |
calculatePreferredSize(); |
calculatePreferredSize(); |
891 |
layoutContainer(scrollbar); |
layoutContainer(scrollbar); |
1036 |
*/ |
*/ |
1037 |
protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) |
protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) |
1038 |
{ |
{ |
|
Color saved = g.getColor(); |
|
|
Point x; |
|
|
Point y; |
|
|
Point z; |
|
|
Polygon lines; |
|
|
|
|
|
g.setColor(thumbHighlightColor); |
|
|
x = new Point(thumbBounds.x + 1, thumbBounds.y + 1); |
|
|
y = new Point(x); |
|
|
y.translate(thumbBounds.width - 2, 0); |
|
|
z = new Point(x); |
|
|
z.translate(0, thumbBounds.height - 2); |
|
|
|
|
|
lines = new Polygon(new int[] { x.x, y.x, z.x }, |
|
|
new int[] { x.y, y.y, z.y }, 3); |
|
|
|
|
|
g.drawPolygon(lines); |
|
|
|
|
|
g.setColor(thumbLightShadowColor); |
|
|
x = new Point(thumbBounds.x + thumbBounds.width - 1, |
|
|
thumbBounds.y + thumbBounds.height - 1); |
|
|
y = new Point(x); |
|
|
y.translate(-(thumbBounds.width - 2), 0); |
|
|
z = new Point(x); |
|
|
z.translate(0, -(thumbBounds.height - 2)); |
|
|
|
|
|
lines = new Polygon(new int[] { x.x, y.x, z.x }, |
|
|
new int[] { x.y, y.y, z.y }, 3); |
|
|
g.drawPolygon(lines); |
|
|
|
|
|
g.setColor(thumbDarkShadowColor); |
|
|
x = new Point(thumbBounds.x + thumbBounds.width, |
|
|
thumbBounds.y + thumbBounds.height); |
|
|
y = new Point(x); |
|
|
y.translate(-thumbBounds.width, 0); |
|
|
z = new Point(x); |
|
|
z.translate(0, -thumbBounds.height); |
|
|
|
|
|
lines = new Polygon(new int[] { x.x, y.x, z.x }, |
|
|
new int[] { x.y, y.y, z.y }, 3); |
|
|
g.drawPolygon(lines); |
|
|
|
|
1039 |
g.setColor(thumbColor); |
g.setColor(thumbColor); |
1040 |
g.fillRect(thumbBounds.x, thumbBounds.y, thumbBounds.width, |
g.fillRect(thumbBounds.x, thumbBounds.y, thumbBounds.width, |
1041 |
thumbBounds.height); |
thumbBounds.height); |
1042 |
|
|
1043 |
g.setColor(saved); |
BasicGraphicsUtils.drawBezel(g, thumbBounds.x, thumbBounds.y, |
1044 |
|
thumbBounds.width, thumbBounds.height, |
1045 |
|
false, false, thumbDarkShadowColor, |
1046 |
|
thumbDarkShadowColor, thumbHighlightColor, |
1047 |
|
thumbHighlightColor); |
1048 |
} |
} |
1049 |
|
|
1050 |
/** |
/** |
1213 |
* This method returns the value in the scrollbar's range given the y |
* This method returns the value in the scrollbar's range given the y |
1214 |
* coordinate. If the value is out of range, it will return the closest |
* coordinate. If the value is out of range, it will return the closest |
1215 |
* legal value. |
* legal value. |
1216 |
|
* This is package-private to avoid an accessor method. |
1217 |
* |
* |
1218 |
* @param yPos The y coordinate to calculate a value for. |
* @param yPos The y coordinate to calculate a value for. |
1219 |
* |
* |
1220 |
* @return The value for the y coordinate. |
* @return The value for the y coordinate. |
1221 |
*/ |
*/ |
1222 |
private int valueForYPosition(int yPos) |
int valueForYPosition(int yPos) |
1223 |
{ |
{ |
1224 |
int min = scrollbar.getMinimum(); |
int min = scrollbar.getMinimum(); |
1225 |
int max = scrollbar.getMaximum(); |
int max = scrollbar.getMaximum(); |
1246 |
* This method returns the value in the scrollbar's range given the x |
* This method returns the value in the scrollbar's range given the x |
1247 |
* coordinate. If the value is out of range, it will return the closest |
* coordinate. If the value is out of range, it will return the closest |
1248 |
* legal value. |
* legal value. |
1249 |
|
* This is package-private to avoid an accessor method. |
1250 |
* |
* |
1251 |
* @param xPos The x coordinate to calculate a value for. |
* @param xPos The x coordinate to calculate a value for. |
1252 |
* |
* |
1253 |
* @return The value for the x coordinate. |
* @return The value for the x coordinate. |
1254 |
*/ |
*/ |
1255 |
private int valueForXPosition(int xPos) |
int valueForXPosition(int xPos) |
1256 |
{ |
{ |
1257 |
int min = scrollbar.getMinimum(); |
int min = scrollbar.getMinimum(); |
1258 |
int max = scrollbar.getMaximum(); |
int max = scrollbar.getMaximum(); |