1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56:
57: import ;
58: import ;
59: import ;
60: import ;
61: import ;
62: import ;
63: import ;
64: import ;
65: import ;
66: import ;
67: import ;
68: import ;
69: import ;
70: import ;
71: import ;
72: import ;
73: import ;
74: import ;
75:
76:
79: public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager,
80: SwingConstants
81: {
82:
86: protected class ArrowButtonListener extends MouseAdapter
87: {
88:
89:
95: public void mousePressed(MouseEvent e)
96: {
97: scrollTimer.stop();
98: scrollListener.setScrollByBlock(false);
99: if (e.getSource() == incrButton)
100: scrollListener.setDirection(POSITIVE_SCROLL);
101: else if (e.getSource() == decrButton)
102: scrollListener.setDirection(NEGATIVE_SCROLL);
103: scrollTimer.setDelay(100);
104: scrollTimer.start();
105: }
106:
107:
112: public void mouseReleased(MouseEvent e)
113: {
114: scrollTimer.stop();
115: scrollTimer.setDelay(300);
116: if (e.getSource() == incrButton)
117: scrollByUnit(POSITIVE_SCROLL);
118: else if (e.getSource() == decrButton)
119: scrollByUnit(NEGATIVE_SCROLL);
120: }
121: }
122:
123:
126: protected class ModelListener implements ChangeListener
127: {
128:
133: public void stateChanged(ChangeEvent e)
134: {
135: calculatePreferredSize();
136: updateThumbRect();
137: scrollbar.repaint();
138: }
139: }
140:
141:
144: public class PropertyChangeHandler implements PropertyChangeListener
145: {
146:
151: public void propertyChange(PropertyChangeEvent e)
152: {
153: if (e.getPropertyName().equals("model"))
154: {
155: ((BoundedRangeModel) e.getOldValue()).removeChangeListener(modelListener);
156: scrollbar.getModel().addChangeListener(modelListener);
157: updateThumbRect();
158: }
159: else if (e.getPropertyName().equals("orientation"))
160: {
161: uninstallListeners();
162: uninstallComponents();
163: uninstallDefaults();
164: installDefaults();
165: installComponents();
166: installListeners();
167: }
168: else if (e.getPropertyName().equals("enabled"))
169: {
170: Boolean b = (Boolean) e.getNewValue();
171: if (incrButton != null)
172: incrButton.setEnabled(b.booleanValue());
173: if (decrButton != null)
174: decrButton.setEnabled(b.booleanValue());
175: }
176: }
177: }
178:
179:
183: protected class ScrollListener implements ActionListener
184: {
185:
186: private transient int direction;
187:
188:
189: private transient boolean block;
190:
191:
195: public ScrollListener()
196: {
197: direction = POSITIVE_SCROLL;
198: block = true;
199: }
200:
201:
208: public ScrollListener(int dir, boolean block)
209: {
210: direction = dir;
211: this.block = block;
212: }
213:
214:
219: public void setDirection(int direction)
220: {
221: this.direction = direction;
222: }
223:
224:
229: public void setScrollByBlock(boolean block)
230: {
231: this.block = block;
232: }
233:
234:
239: public void actionPerformed(ActionEvent e)
240: {
241: if (block)
242: {
243:
244:
245:
246: if (!trackListener.shouldScroll(direction))
247: {
248: trackHighlight = NO_HIGHLIGHT;
249: scrollbar.repaint();
250: return;
251: }
252: scrollByBlock(direction);
253: }
254: else
255: scrollByUnit(direction);
256: }
257: }
258:
259:
262: protected class TrackListener extends MouseAdapter
263: implements MouseMotionListener
264: {
265:
266: protected int currentMouseX;
267:
268:
269: protected int currentMouseY;
270:
271:
275: protected int offset;
276:
277:
282: public void mouseDragged(MouseEvent e)
283: {
284: currentMouseX = e.getX();
285: currentMouseY = e.getY();
286: if (scrollbar.getValueIsAdjusting())
287: {
288: int value;
289: if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
290: value = valueForXPosition(currentMouseX) - offset;
291: else
292: value = valueForYPosition(currentMouseY) - offset;
293:
294: scrollbar.setValue(value);
295: }
296: }
297:
298:
303: public void mouseMoved(MouseEvent e)
304: {
305:
306:
307: }
308:
309:
315: public void mousePressed(MouseEvent e)
316: {
317: currentMouseX = e.getX();
318: currentMouseY = e.getY();
319:
320: int value;
321: if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
322: value = valueForXPosition(currentMouseX);
323: else
324: value = valueForYPosition(currentMouseY);
325:
326: if (! thumbRect.contains(e.getPoint()))
327: {
328: scrollTimer.stop();
329: scrollListener.setScrollByBlock(true);
330: if (value > scrollbar.getValue())
331: {
332: trackHighlight = INCREASE_HIGHLIGHT;
333: scrollListener.setDirection(POSITIVE_SCROLL);
334: }
335: else
336: {
337: trackHighlight = DECREASE_HIGHLIGHT;
338: scrollListener.setDirection(NEGATIVE_SCROLL);
339: }
340: scrollTimer.setDelay(100);
341: scrollTimer.start();
342: }
343: else
344: {
345:
346:
347:
348:
349:
350:
351:
352: scrollListener.setScrollByBlock(false);
353: scrollbar.setValueIsAdjusting(true);
354: offset = value - scrollbar.getValue();
355: }
356: scrollbar.repaint();
357: }
358:
359:
365: public void mouseReleased(MouseEvent e)
366: {
367: scrollTimer.stop();
368: scrollTimer.setDelay(300);
369: currentMouseX = e.getX();
370: currentMouseY = e.getY();
371:
372: if (shouldScroll(POSITIVE_SCROLL))
373: scrollByBlock(POSITIVE_SCROLL);
374: else if (shouldScroll(NEGATIVE_SCROLL))
375: scrollByBlock(NEGATIVE_SCROLL);
376:
377: trackHighlight = NO_HIGHLIGHT;
378: scrollListener.setScrollByBlock(false);
379: scrollbar.setValueIsAdjusting(true);
380: scrollbar.repaint();
381: }
382:
383:
391: boolean shouldScroll(int direction)
392: {
393: int value;
394: if (scrollbar.getOrientation() == HORIZONTAL)
395: value = valueForXPosition(currentMouseX);
396: else
397: value = valueForYPosition(currentMouseY);
398:
399: if (thumbRect.contains(currentMouseX, currentMouseY))
400: return false;
401:
402: if (direction == POSITIVE_SCROLL)
403: return value > scrollbar.getValue();
404: else
405: return value < scrollbar.getValue();
406: }
407: }
408:
409:
410: protected ArrowButtonListener buttonListener;
411:
412:
413: protected ModelListener modelListener;
414:
415:
416: protected PropertyChangeListener propertyChangeListener;
417:
418:
419: protected ScrollListener scrollListener;
420:
421:
422: protected TrackListener trackListener;
423:
424:
425: protected JButton decrButton;
426:
427:
428: protected JButton incrButton;
429:
430:
431: protected Dimension maximumThumbSize;
432:
433:
434: protected Dimension minimumThumbSize;
435:
436:
437: protected Color thumbColor;
438:
439:
440: protected Color thumbDarkShadowColor;
441:
442:
443: protected Color thumbHighlightColor;
444:
445:
446: protected Color thumbLightShadowColor;
447:
448:
449: protected Color trackHighlightColor;
450:
451:
452: protected Color trackColor;
453:
454:
455: protected Rectangle trackRect;
456:
457:
458: protected Rectangle thumbRect;
459:
460:
461: protected static final int DECREASE_HIGHLIGHT = 1;
462:
463:
464: protected static final int INCREASE_HIGHLIGHT = 2;
465:
466:
467: protected static final int NO_HIGHLIGHT = 0;
468:
469:
470: private static final int POSITIVE_SCROLL = 1;
471:
472:
473: private static final int NEGATIVE_SCROLL = -1;
474:
475:
476: private transient Dimension preferredSize;
477:
478:
479: protected int trackHighlight;
480:
481:
482: protected boolean isDragging;
483:
484:
485: protected Timer scrollTimer;
486:
487:
488: protected JScrollBar scrollbar;
489:
490:
496: public void addLayoutComponent(String name, Component child)
497: {
498:
499:
500: }
501:
502:
506: protected void configureScrollBarColors()
507: {
508: trackColor = UIManager.getColor("ScrollBar.track");
509: trackHighlightColor = UIManager.getColor("ScrollBar.trackHighlight");
510: thumbColor = UIManager.getColor("ScrollBar.thumb");
511: thumbHighlightColor = UIManager.getColor("ScrollBar.thumbHighlight");
512: thumbDarkShadowColor = UIManager.getColor("ScrollBar.thumbDarkShadow");
513: thumbLightShadowColor = UIManager.getColor("ScrollBar.thumbShadow");
514: }
515:
516:
521: protected ArrowButtonListener createArrowButtonListener()
522: {
523: return new ArrowButtonListener();
524: }
525:
526:
534: protected JButton createIncreaseButton(int orientation)
535: {
536: return new BasicArrowButton(orientation);
537: }
538:
539:
547: protected JButton createDecreaseButton(int orientation)
548: {
549: return new BasicArrowButton(orientation);
550: }
551:
552:
557: protected ModelListener createModelListener()
558: {
559: return new ModelListener();
560: }
561:
562:
567: protected PropertyChangeListener createPropertyChangeListener()
568: {
569: return new PropertyChangeHandler();
570: }
571:
572:
577: protected ScrollListener createScrollListener()
578: {
579: return new ScrollListener();
580: }
581:
582:
587: protected TrackListener createTrackListener()
588: {
589: return new TrackListener();
590: }
591:
592:
599: public static ComponentUI createUI(JComponent c)
600: {
601: return new BasicScrollBarUI();
602: }
603:
604:
611: public Dimension getMaximumSize(JComponent c)
612: {
613: return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
614: }
615:
616:
621: protected Dimension getMaximumThumbSize()
622: {
623: return maximumThumbSize;
624: }
625:
626:
633: public Dimension getMinimumSize(JComponent c)
634: {
635: return getPreferredSize(c);
636: }
637:
638:
643: protected Dimension getMinimumThumbSize()
644: {
645: return minimumThumbSize;
646: }
647:
648:
653: void calculatePreferredSize()
654: {
655: int height;
656: int width;
657: height = width = 0;
658:
659: if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
660: {
661: width += incrButton.getPreferredSize().getWidth();
662: width += decrButton.getPreferredSize().getWidth();
663: width += 16;
664: height = UIManager.getInt("ScrollBar.width");
665: }
666: else
667: {
668: height += incrButton.getPreferredSize().getHeight();
669: height += decrButton.getPreferredSize().getHeight();
670: height += 16;
671: width = UIManager.getInt("ScrollBar.width");
672: }
673:
674: Insets insets = scrollbar.getInsets();
675:
676: height += insets.top + insets.bottom;
677: width += insets.left + insets.right;
678:
679: preferredSize = new Dimension(width, height);
680: }
681:
682:
693: public Dimension getPreferredSize(JComponent c)
694: {
695: calculatePreferredSize();
696: return preferredSize;
697: }
698:
699:
705: protected Rectangle getThumbBounds()
706: {
707: return thumbRect;
708: }
709:
710:
716: protected Rectangle getTrackBounds()
717: {
718: return trackRect;
719: }
720:
721:
725: protected void installComponents()
726: {
727: int orientation = scrollbar.getOrientation();
728: switch (orientation)
729: {
730: case JScrollBar.HORIZONTAL:
731: incrButton = createIncreaseButton(EAST);
732: decrButton = createDecreaseButton(WEST);
733: break;
734: default:
735: incrButton = createIncreaseButton(SOUTH);
736: decrButton = createDecreaseButton(NORTH);
737: break;
738: }
739:
740: if (incrButton != null)
741: scrollbar.add(incrButton);
742: if (decrButton != null)
743: scrollbar.add(decrButton);
744: }
745:
746:
750: protected void installDefaults()
751: {
752: LookAndFeel.installColors(scrollbar, "ScrollBar.background",
753: "ScrollBar.foreground");
754: LookAndFeel.installBorder(scrollbar, "ScrollBar.border");
755: scrollbar.setOpaque(true);
756: scrollbar.setLayout(this);
757:
758: thumbColor = UIManager.getColor("ScrollBar.thumb");
759: thumbDarkShadowColor = UIManager.getColor("ScrollBar.thumbDarkShadow");
760: thumbHighlightColor = UIManager.getColor("ScrollBar.thumbHighlight");
761: thumbLightShadowColor = UIManager.getColor("ScrollBar.thumbShadow");
762:
763: maximumThumbSize = UIManager.getDimension("ScrollBar.maximumThumbSize");
764: minimumThumbSize = UIManager.getDimension("ScrollBar.minimumThumbSize");
765: }
766:
767:
772: protected void installKeyboardActions()
773: {
774: InputMap keyMap = getInputMap(
775: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
776: SwingUtilities.replaceUIInputMap(scrollbar,
777: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, keyMap);
778: ActionMap map = getActionMap();
779: SwingUtilities.replaceUIActionMap(scrollbar, map);
780: }
781:
782:
786: protected void uninstallKeyboardActions()
787: {
788: SwingUtilities.replaceUIActionMap(scrollbar, null);
789: SwingUtilities.replaceUIInputMap(scrollbar,
790: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null);
791: }
792:
793: InputMap getInputMap(int condition)
794: {
795: if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
796: return (InputMap) UIManager.get("ScrollBar.focusInputMap");
797: return null;
798: }
799:
800:
807: ActionMap getActionMap()
808: {
809: ActionMap map = (ActionMap) UIManager.get("ScrollBar.actionMap");
810:
811: if (map == null)
812: {
813: map = createActionMap();
814: if (map != null)
815: UIManager.put("ScrollBar.actionMap", map);
816: }
817: return map;
818: }
819:
820:
830: ActionMap createActionMap()
831: {
832: ActionMap map = new ActionMapUIResource();
833: map.put("positiveUnitIncrement",
834: new AbstractAction("positiveUnitIncrement") {
835: public void actionPerformed(ActionEvent event)
836: {
837: JScrollBar sb = (JScrollBar) event.getSource();
838: if (sb.isVisible())
839: {
840: int delta = sb.getUnitIncrement(1);
841: sb.setValue(sb.getValue() + delta);
842: }
843: }
844: }
845: );
846: map.put("positiveBlockIncrement",
847: new AbstractAction("positiveBlockIncrement") {
848: public void actionPerformed(ActionEvent event)
849: {
850: JScrollBar sb = (JScrollBar) event.getSource();
851: if (sb.isVisible())
852: {
853: int delta = sb.getBlockIncrement(1);
854: sb.setValue(sb.getValue() + delta);
855: }
856: }
857: }
858: );
859: map.put("negativeUnitIncrement",
860: new AbstractAction("negativeUnitIncrement") {
861: public void actionPerformed(ActionEvent event)
862: {
863: JScrollBar sb = (JScrollBar) event.getSource();
864: if (sb.isVisible())
865: {
866: int delta = sb.getUnitIncrement(-1);
867: sb.setValue(sb.getValue() + delta);
868: }
869: }
870: }
871: );
872: map.put("negativeBlockIncrement",
873: new AbstractAction("negativeBlockIncrement") {
874: public void actionPerformed(ActionEvent event)
875: {
876: JScrollBar sb = (JScrollBar) event.getSource();
877: if (sb.isVisible())
878: {
879: int delta = sb.getBlockIncrement(-1);
880: sb.setValue(sb.getValue() + delta);
881: }
882: }
883: }
884: );
885: map.put("minScroll",
886: new AbstractAction("minScroll") {
887: public void actionPerformed(ActionEvent event)
888: {
889: JScrollBar sb = (JScrollBar) event.getSource();
890: if (sb.isVisible())
891: {
892: sb.setValue(sb.getMinimum());
893: }
894: }
895: }
896: );
897: map.put("maxScroll",
898: new AbstractAction("maxScroll") {
899: public void actionPerformed(ActionEvent event)
900: {
901: JScrollBar sb = (JScrollBar) event.getSource();
902: if (sb.isVisible())
903: {
904: sb.setValue(sb.getMaximum());
905: }
906: }
907: }
908: );
909: return map;
910: }
911:
912:
916: protected void installListeners()
917: {
918: scrollListener = createScrollListener();
919: trackListener = createTrackListener();
920: buttonListener = createArrowButtonListener();
921: modelListener = createModelListener();
922: propertyChangeListener = createPropertyChangeListener();
923:
924: scrollbar.addMouseMotionListener(trackListener);
925: scrollbar.addMouseListener(trackListener);
926:
927: incrButton.addMouseListener(buttonListener);
928: decrButton.addMouseListener(buttonListener);
929:
930: scrollbar.addPropertyChangeListener(propertyChangeListener);
931: scrollbar.getModel().addChangeListener(modelListener);
932:
933: scrollTimer.addActionListener(scrollListener);
934: }
935:
936:
943: public void installUI(JComponent c)
944: {
945: super.installUI(c);
946: if (c instanceof JScrollBar)
947: {
948: scrollbar = (JScrollBar) c;
949:
950: trackRect = new Rectangle();
951: thumbRect = new Rectangle();
952:
953: scrollTimer = new Timer(300, null);
954:
955: installDefaults();
956: installComponents();
957: configureScrollBarColors();
958: installListeners();
959: installKeyboardActions();
960:
961: calculatePreferredSize();
962: }
963: }
964:
965:
970: public void layoutContainer(Container scrollbarContainer)
971: {
972: if (scrollbarContainer instanceof JScrollBar)
973: {
974: if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
975: layoutHScrollbar((JScrollBar) scrollbarContainer);
976: else
977: layoutVScrollbar((JScrollBar) scrollbarContainer);
978: }
979: }
980:
981:
986: protected void layoutHScrollbar(JScrollBar sb)
987: {
988: Rectangle vr = new Rectangle();
989: SwingUtilities.calculateInnerArea(scrollbar, vr);
990:
991: Dimension incrDims = incrButton.getPreferredSize();
992: Dimension decrDims = decrButton.getPreferredSize();
993:
994:
995: SwingUtilities.calculateInnerArea(scrollbar, trackRect);
996: trackRect.width -= incrDims.getWidth();
997: trackRect.width -= decrDims.getWidth();
998: trackRect.x += decrDims.getWidth();
999:
1000: updateThumbRect();
1001:
1002: decrButton.setBounds(vr.x, vr.y, decrDims.width, trackRect.height);
1003: incrButton.setBounds(trackRect.x + trackRect.width, vr.y, incrDims.width,
1004: trackRect.height);
1005: }
1006:
1007:
1012: protected void layoutVScrollbar(JScrollBar sb)
1013: {
1014: Rectangle vr = new Rectangle();
1015: SwingUtilities.calculateInnerArea(scrollbar, vr);
1016:
1017: Dimension incrDims = incrButton.getPreferredSize();
1018: Dimension decrDims = decrButton.getPreferredSize();
1019:
1020:
1021: SwingUtilities.calculateInnerArea(scrollbar, trackRect);
1022: trackRect.height -= incrDims.getHeight();
1023: trackRect.height -= decrDims.getHeight();
1024: trackRect.y += decrDims.getHeight();
1025:
1026: updateThumbRect();
1027:
1028: decrButton.setBounds(vr.x, vr.y, trackRect.width, decrDims.height);
1029: incrButton.setBounds(vr.x, trackRect.y + trackRect.height,
1030: trackRect.width, incrDims.height);
1031: }
1032:
1033:
1036: void updateThumbRect()
1037: {
1038: int max = scrollbar.getMaximum();
1039: int min = scrollbar.getMinimum();
1040: int value = scrollbar.getValue();
1041: int extent = scrollbar.getVisibleAmount();
1042: if (max - extent <= min)
1043: {
1044: if (scrollbar.getOrientation() == JScrollBar.HORIZONTAL)
1045: {
1046: thumbRect.x = trackRect.x;
1047: thumbRect.y = trackRect.y;
1048: thumbRect.width = getMinimumThumbSize().width;
1049: thumbRect.height = trackRect.height;
1050: }
1051: else
1052: {
1053: thumbRect.x = trackRect.x;
1054: thumbRect.y = trackRect.y;
1055: thumbRect.width = trackRect.width;
1056: thumbRect.height = getMinimumThumbSize().height;
1057: }
1058: }
1059: else
1060: {
1061: if (scrollbar.getOrientation() == JScrollBar.HORIZONTAL)
1062: {
1063: thumbRect.x = trackRect.x;
1064: thumbRect.width = Math.max(extent * trackRect.width / (max - min),
1065: getMinimumThumbSize().width);
1066: int availableWidth = trackRect.width - thumbRect.width;
1067: thumbRect.x += (value - min) * availableWidth / (max - min - extent);
1068: thumbRect.y = trackRect.y;
1069: thumbRect.height = trackRect.height;
1070: }
1071: else
1072: {
1073: thumbRect.x = trackRect.x;
1074: thumbRect.height = Math.max(extent * trackRect.height / (max - min),
1075: getMinimumThumbSize().height);
1076: int availableHeight = trackRect.height - thumbRect.height;
1077: thumbRect.y = trackRect.y
1078: + (value - min) * availableHeight / (max - min - extent);
1079: thumbRect.width = trackRect.width;
1080: }
1081: }
1082:
1083: }
1084:
1085:
1092: public Dimension minimumLayoutSize(Container scrollbarContainer)
1093: {
1094: return preferredLayoutSize(scrollbarContainer);
1095: }
1096:
1097:
1103: public void paint(Graphics g, JComponent c)
1104: {
1105: paintTrack(g, c, getTrackBounds());
1106: paintThumb(g, c, getThumbBounds());
1107:
1108: if (trackHighlight == INCREASE_HIGHLIGHT)
1109: paintIncreaseHighlight(g);
1110: else if (trackHighlight == DECREASE_HIGHLIGHT)
1111: paintDecreaseHighlight(g);
1112: }
1113:
1114:
1121: protected void paintDecreaseHighlight(Graphics g)
1122: {
1123: Color saved = g.getColor();
1124:
1125: g.setColor(trackHighlightColor);
1126: if (scrollbar.getOrientation() == HORIZONTAL)
1127: g.fillRect(trackRect.x, trackRect.y, thumbRect.x - trackRect.x,
1128: trackRect.height);
1129: else
1130: g.fillRect(trackRect.x, trackRect.y, trackRect.width,
1131: thumbRect.y - trackRect.y);
1132: g.setColor(saved);
1133: }
1134:
1135:
1142: protected void paintIncreaseHighlight(Graphics g)
1143: {
1144: Color saved = g.getColor();
1145:
1146: g.setColor(trackHighlightColor);
1147: if (scrollbar.getOrientation() == HORIZONTAL)
1148: g.fillRect(thumbRect.x + thumbRect.width, trackRect.y,
1149: trackRect.x + trackRect.width - thumbRect.x - thumbRect.width,
1150: trackRect.height);
1151: else
1152: g.fillRect(trackRect.x, thumbRect.y + thumbRect.height, trackRect.width,
1153: trackRect.y + trackRect.height - thumbRect.y
1154: - thumbRect.height);
1155: g.setColor(saved);
1156: }
1157:
1158:
1165: protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds)
1166: {
1167: g.setColor(thumbColor);
1168: g.fillRect(thumbBounds.x, thumbBounds.y, thumbBounds.width,
1169: thumbBounds.height);
1170:
1171: BasicGraphicsUtils.drawBezel(g, thumbBounds.x, thumbBounds.y,
1172: thumbBounds.width, thumbBounds.height,
1173: false, false, thumbDarkShadowColor,
1174: thumbDarkShadowColor, thumbHighlightColor,
1175: thumbHighlightColor);
1176: }
1177:
1178:
1185: protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds)
1186: {
1187: Color saved = g.getColor();
1188: g.setColor(trackColor);
1189: g.fill3DRect(trackBounds.x, trackBounds.y, trackBounds.width,
1190: trackBounds.height, false);
1191: g.setColor(saved);
1192: }
1193:
1194:
1201: public Dimension preferredLayoutSize(Container scrollbarContainer)
1202: {
1203: if (scrollbarContainer instanceof JComponent)
1204: return getPreferredSize((JComponent) scrollbarContainer);
1205: else
1206: return null;
1207: }
1208:
1209:
1214: public void removeLayoutComponent(Component child)
1215: {
1216:
1217: }
1218:
1219:
1224: protected void scrollByBlock(int direction)
1225: {
1226: scrollbar.setValue(scrollbar.getValue()
1227: + scrollbar.getBlockIncrement(direction));
1228: }
1229:
1230:
1235: protected void scrollByUnit(int direction)
1236: {
1237: scrollbar.setValue(scrollbar.getValue()
1238: + scrollbar.getUnitIncrement(direction));
1239: }
1240:
1241:
1249: protected void setThumbBounds(int x, int y, int width, int height)
1250: {
1251: thumbRect.x = x;
1252: thumbRect.y = y;
1253: thumbRect.width = width;
1254: thumbRect.height = height;
1255: }
1256:
1257:
1261: protected void uninstallComponents()
1262: {
1263: if (incrButton != null)
1264: scrollbar.remove(incrButton);
1265: if (decrButton != null)
1266: scrollbar.remove(decrButton);
1267: }
1268:
1269:
1273: protected void uninstallDefaults()
1274: {
1275: scrollbar.setForeground(null);
1276: scrollbar.setBackground(null);
1277: LookAndFeel.uninstallBorder(scrollbar);
1278: incrButton = null;
1279: decrButton = null;
1280: }
1281:
1282:
1285: protected void uninstallListeners()
1286: {
1287: if (scrollTimer != null)
1288: scrollTimer.removeActionListener(scrollListener);
1289:
1290: if (scrollbar != null)
1291: {
1292: scrollbar.getModel().removeChangeListener(modelListener);
1293: scrollbar.removePropertyChangeListener(propertyChangeListener);
1294: scrollbar.removeMouseListener(trackListener);
1295: scrollbar.removeMouseMotionListener(trackListener);
1296: }
1297:
1298: if (decrButton != null)
1299: decrButton.removeMouseListener(buttonListener);
1300: if (incrButton != null)
1301: incrButton.removeMouseListener(buttonListener);
1302:
1303: propertyChangeListener = null;
1304: modelListener = null;
1305: buttonListener = null;
1306: trackListener = null;
1307: scrollListener = null;
1308: }
1309:
1310:
1317: public void uninstallUI(JComponent c)
1318: {
1319: uninstallKeyboardActions();
1320: uninstallListeners();
1321: uninstallDefaults();
1322: uninstallComponents();
1323:
1324: scrollTimer = null;
1325:
1326: thumbRect = null;
1327: trackRect = null;
1328:
1329: trackColor = null;
1330: trackHighlightColor = null;
1331: thumbColor = null;
1332: thumbHighlightColor = null;
1333: thumbDarkShadowColor = null;
1334: thumbLightShadowColor = null;
1335:
1336: scrollbar = null;
1337: }
1338:
1339:
1349: int valueForYPosition(int yPos)
1350: {
1351: int min = scrollbar.getMinimum();
1352: int max = scrollbar.getMaximum();
1353: int len = trackRect.height;
1354:
1355: int value;
1356:
1357:
1358:
1359: if (len == 0)
1360: return (max - min) / 2;
1361:
1362: value = (yPos - trackRect.y) * (max - min) / len + min;
1363:
1364:
1365: if (value > max)
1366: value = max;
1367: else if (value < min)
1368: value = min;
1369: return value;
1370: }
1371:
1372:
1382: int valueForXPosition(int xPos)
1383: {
1384: int min = scrollbar.getMinimum();
1385: int max = scrollbar.getMaximum();
1386: int len = trackRect.width;
1387:
1388: int value;
1389:
1390:
1391:
1392: if (len == 0)
1393: return (max - min) / 2;
1394:
1395: value = (xPos - trackRect.x) * (max - min) / len + min;
1396:
1397:
1398: if (value > max)
1399: value = max;
1400: else if (value < min)
1401: value = min;
1402: return value;
1403: }
1404: }