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:
72:
75: public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager,
76: SwingConstants
77: {
78:
82: protected class ArrowButtonListener extends MouseAdapter
83: {
84:
85:
91: public void mousePressed(MouseEvent e)
92: {
93: scrollTimer.stop();
94: scrollListener.setScrollByBlock(false);
95: if (e.getSource() == incrButton)
96: scrollListener.setDirection(POSITIVE_SCROLL);
97: else if (e.getSource() == decrButton)
98: scrollListener.setDirection(NEGATIVE_SCROLL);
99: scrollTimer.setDelay(100);
100: scrollTimer.start();
101: }
102:
103:
108: public void mouseReleased(MouseEvent e)
109: {
110: scrollTimer.stop();
111: scrollTimer.setDelay(300);
112: if (e.getSource() == incrButton)
113: scrollByUnit(POSITIVE_SCROLL);
114: else if (e.getSource() == decrButton)
115: scrollByUnit(NEGATIVE_SCROLL);
116: }
117: }
118:
119:
122: protected class ModelListener implements ChangeListener
123: {
124:
129: public void stateChanged(ChangeEvent e)
130: {
131: calculatePreferredSize();
132: updateThumbRect();
133: scrollbar.repaint();
134: }
135: }
136:
137:
140: public class PropertyChangeHandler implements PropertyChangeListener
141: {
142:
147: public void propertyChange(PropertyChangeEvent e)
148: {
149: if (e.getPropertyName().equals("model"))
150: {
151: ((BoundedRangeModel) e.getOldValue()).removeChangeListener(modelListener);
152: scrollbar.getModel().addChangeListener(modelListener);
153: updateThumbRect();
154: }
155: else if (e.getPropertyName().equals("orientation"))
156: {
157: uninstallListeners();
158: uninstallComponents();
159: uninstallDefaults();
160: installDefaults();
161: installComponents();
162: installListeners();
163: }
164: else if (e.getPropertyName().equals("enabled"))
165: {
166: Boolean b = (Boolean) e.getNewValue();
167: if (incrButton != null)
168: incrButton.setEnabled(b.booleanValue());
169: if (decrButton != null)
170: decrButton.setEnabled(b.booleanValue());
171: }
172: }
173: }
174:
175:
179: protected class ScrollListener implements ActionListener
180: {
181:
182: private transient int direction;
183:
184:
185: private transient boolean block;
186:
187:
191: public ScrollListener()
192: {
193: direction = POSITIVE_SCROLL;
194: block = true;
195: }
196:
197:
204: public ScrollListener(int dir, boolean block)
205: {
206: direction = dir;
207: this.block = block;
208: }
209:
210:
215: public void setDirection(int direction)
216: {
217: this.direction = direction;
218: }
219:
220:
225: public void setScrollByBlock(boolean block)
226: {
227: this.block = block;
228: }
229:
230:
235: public void actionPerformed(ActionEvent e)
236: {
237: if (block)
238: {
239:
240:
241:
242: if (!trackListener.shouldScroll(direction))
243: {
244: trackHighlight = NO_HIGHLIGHT;
245: scrollbar.repaint();
246: return;
247: }
248: scrollByBlock(direction);
249: }
250: else
251: scrollByUnit(direction);
252: }
253: }
254:
255:
258: protected class TrackListener extends MouseAdapter
259: implements MouseMotionListener
260: {
261:
262: protected int currentMouseX;
263:
264:
265: protected int currentMouseY;
266:
267:
271: protected int offset;
272:
273:
278: public void mouseDragged(MouseEvent e)
279: {
280: currentMouseX = e.getX();
281: currentMouseY = e.getY();
282: if (scrollbar.getValueIsAdjusting())
283: {
284: int value;
285: if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
286: value = valueForXPosition(currentMouseX) - offset;
287: else
288: value = valueForYPosition(currentMouseY) - offset;
289:
290: scrollbar.setValue(value);
291: }
292: }
293:
294:
299: public void mouseMoved(MouseEvent e)
300: {
301:
302:
303: }
304:
305:
311: public void mousePressed(MouseEvent e)
312: {
313: currentMouseX = e.getX();
314: currentMouseY = e.getY();
315:
316: int value;
317: if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
318: value = valueForXPosition(currentMouseX);
319: else
320: value = valueForYPosition(currentMouseY);
321:
322: if (! thumbRect.contains(e.getPoint()))
323: {
324: scrollTimer.stop();
325: scrollListener.setScrollByBlock(true);
326: if (value > scrollbar.getValue())
327: {
328: trackHighlight = INCREASE_HIGHLIGHT;
329: scrollListener.setDirection(POSITIVE_SCROLL);
330: }
331: else
332: {
333: trackHighlight = DECREASE_HIGHLIGHT;
334: scrollListener.setDirection(NEGATIVE_SCROLL);
335: }
336: scrollTimer.setDelay(100);
337: scrollTimer.start();
338: }
339: else
340: {
341:
342:
343:
344:
345:
346:
347:
348: scrollListener.setScrollByBlock(false);
349: scrollbar.setValueIsAdjusting(true);
350: offset = value - scrollbar.getValue();
351: }
352: scrollbar.repaint();
353: }
354:
355:
361: public void mouseReleased(MouseEvent e)
362: {
363: scrollTimer.stop();
364: scrollTimer.setDelay(300);
365: currentMouseX = e.getX();
366: currentMouseY = e.getY();
367:
368: if (shouldScroll(POSITIVE_SCROLL))
369: scrollByBlock(POSITIVE_SCROLL);
370: else if (shouldScroll(NEGATIVE_SCROLL))
371: scrollByBlock(NEGATIVE_SCROLL);
372:
373: trackHighlight = NO_HIGHLIGHT;
374: scrollListener.setScrollByBlock(false);
375: scrollbar.setValueIsAdjusting(true);
376: scrollbar.repaint();
377: }
378:
379:
387: public boolean shouldScroll(int direction)
388: {
389: int value;
390: if (scrollbar.getOrientation() == HORIZONTAL)
391: value = valueForXPosition(currentMouseX);
392: else
393: value = valueForYPosition(currentMouseY);
394:
395: if (thumbRect.contains(currentMouseX, currentMouseY))
396: return false;
397:
398: if (direction == POSITIVE_SCROLL)
399: return (value > scrollbar.getValue());
400: else
401: return (value < scrollbar.getValue());
402: }
403: }
404:
405:
406: protected ArrowButtonListener buttonListener;
407:
408:
409: protected ModelListener modelListener;
410:
411:
412: protected PropertyChangeListener propertyChangeListener;
413:
414:
415: protected ScrollListener scrollListener;
416:
417:
418: protected TrackListener trackListener;
419:
420:
421: protected JButton decrButton;
422:
423:
424: protected JButton incrButton;
425:
426:
427: protected Dimension maximumThumbSize;
428:
429:
430: protected Dimension minimumThumbSize;
431:
432:
433: protected Color thumbColor;
434:
435:
436: protected Color thumbDarkShadowColor;
437:
438:
439: protected Color thumbHighlightColor;
440:
441:
442: protected Color thumbLightShadowColor;
443:
444:
445: protected Color trackHighlightColor;
446:
447:
448: protected Color trackColor;
449:
450:
451: protected Rectangle trackRect;
452:
453:
454: protected Rectangle thumbRect;
455:
456:
457: protected static final int DECREASE_HIGHLIGHT = 1;
458:
459:
460: protected static final int INCREASE_HIGHLIGHT = 2;
461:
462:
463: protected static final int NO_HIGHLIGHT = 0;
464:
465:
466: private static final int POSITIVE_SCROLL = 1;
467:
468:
469: private static final int NEGATIVE_SCROLL = -1;
470:
471:
472: private transient Dimension preferredSize;
473:
474:
475: protected int trackHighlight;
476:
477:
478: protected boolean isDragging;
479:
480:
481: protected Timer scrollTimer;
482:
483:
484: protected JScrollBar scrollbar;
485:
486:
492: public void addLayoutComponent(String name, Component child)
493: {
494:
495:
496: }
497:
498:
502: protected void configureScrollBarColors()
503: {
504: UIDefaults defaults = UIManager.getLookAndFeelDefaults();
505:
506: trackColor = defaults.getColor("ScrollBar.track");
507: trackHighlightColor = defaults.getColor("ScrollBar.trackHighlight");
508: thumbColor = defaults.getColor("ScrollBar.thumb");
509: thumbHighlightColor = defaults.getColor("ScrollBar.thumbHighlight");
510: thumbDarkShadowColor = defaults.getColor("ScrollBar.thumbDarkShadow");
511: thumbLightShadowColor = defaults.getColor("ScrollBar.thumbShadow");
512: }
513:
514:
519: protected ArrowButtonListener createArrowButtonListener()
520: {
521: return new ArrowButtonListener();
522: }
523:
524:
532: protected JButton createIncreaseButton(int orientation)
533: {
534: return new BasicArrowButton(orientation);
535: }
536:
537:
545: protected JButton createDecreaseButton(int orientation)
546: {
547: return new BasicArrowButton(orientation);
548: }
549:
550:
555: protected ModelListener createModelListener()
556: {
557: return new ModelListener();
558: }
559:
560:
565: protected PropertyChangeListener createPropertyChangeListener()
566: {
567: return new PropertyChangeHandler();
568: }
569:
570:
575: protected ScrollListener createScrollListener()
576: {
577: return new ScrollListener();
578: }
579:
580:
585: protected TrackListener createTrackListener()
586: {
587: return new TrackListener();
588: }
589:
590:
597: public static ComponentUI createUI(JComponent c)
598: {
599: return new BasicScrollBarUI();
600: }
601:
602:
609: public Dimension getMaximumSize(JComponent c)
610: {
611: return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
612: }
613:
614:
619: protected Dimension getMaximumThumbSize()
620: {
621: return maximumThumbSize;
622: }
623:
624:
631: public Dimension getMinimumSize(JComponent c)
632: {
633: return getPreferredSize(c);
634: }
635:
636:
641: protected Dimension getMinimumThumbSize()
642: {
643: return minimumThumbSize;
644: }
645:
646:
651: void calculatePreferredSize()
652: {
653: int height;
654: int width;
655: height = width = 0;
656:
657: if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
658: {
659: width += incrButton.getPreferredSize().getWidth();
660: width += decrButton.getPreferredSize().getWidth();
661:
662: width += (scrollbar.getMaximum() - scrollbar.getMinimum());
663:
664: height = Math.max(incrButton.getPreferredSize().height,
665: decrButton.getPreferredSize().height);
666: height = Math.max(getMinimumThumbSize().height, height);
667: height = Math.min(getMaximumThumbSize().height, height);
668: }
669: else
670: {
671: height += incrButton.getPreferredSize().getHeight();
672: height += decrButton.getPreferredSize().getHeight();
673:
674: height += (scrollbar.getMaximum() - scrollbar.getMinimum());
675:
676: width = Math.max(incrButton.getPreferredSize().width,
677: decrButton.getPreferredSize().width);
678: width = Math.max(getMinimumThumbSize().width, width);
679: width = Math.min(getMaximumThumbSize().width, width);
680: }
681:
682: Insets insets = scrollbar.getInsets();
683:
684: height += insets.top + insets.bottom;
685: width += insets.left + insets.right;
686:
687: preferredSize = new Dimension(width, height);
688: }
689:
690:
701: public Dimension getPreferredSize(JComponent c)
702: {
703: calculatePreferredSize();
704: return preferredSize;
705: }
706:
707:
713: protected Rectangle getThumbBounds()
714: {
715: return thumbRect;
716: }
717:
718:
724: protected Rectangle getTrackBounds()
725: {
726: return trackRect;
727: }
728:
729:
733: protected void installComponents()
734: {
735: if (incrButton != null)
736: scrollbar.add(incrButton);
737: if (decrButton != null)
738: scrollbar.add(decrButton);
739: }
740:
741:
745: protected void installDefaults()
746: {
747: int orientation = scrollbar.getOrientation();
748: switch (orientation)
749: {
750: case (JScrollBar.HORIZONTAL):
751: incrButton = createIncreaseButton(EAST);
752: decrButton = createDecreaseButton(WEST);
753: break;
754: default:
755: incrButton = createIncreaseButton(SOUTH);
756: decrButton = createDecreaseButton(NORTH);
757: break;
758: }
759:
760: LookAndFeel.installColors(scrollbar, "ScrollBar.background",
761: "ScrollBar.foreground");
762: LookAndFeel.installBorder(scrollbar, "ScrollBar.border");
763: scrollbar.setOpaque(true);
764: scrollbar.setLayout(this);
765:
766: thumbColor = UIManager.getColor("ScrollBar.thumb");
767: thumbDarkShadowColor = UIManager.getColor("ScrollBar.thumbDarkShadow");
768: thumbHighlightColor = UIManager.getColor("ScrollBar.thumbHighlight");
769: thumbLightShadowColor = UIManager.getColor("ScrollBar.thumbShadow");
770:
771: maximumThumbSize = UIManager.getDimension("ScrollBar.maximumThumbSize");
772: minimumThumbSize = UIManager.getDimension("ScrollBar.minimumThumbSize");
773: }
774:
775:
778: protected void installKeyboardActions()
779: {
780:
781: }
782:
783:
787: protected void installListeners()
788: {
789: scrollListener = createScrollListener();
790: trackListener = createTrackListener();
791: buttonListener = createArrowButtonListener();
792: modelListener = createModelListener();
793: propertyChangeListener = createPropertyChangeListener();
794:
795: scrollbar.addMouseMotionListener(trackListener);
796: scrollbar.addMouseListener(trackListener);
797:
798: incrButton.addMouseListener(buttonListener);
799: decrButton.addMouseListener(buttonListener);
800:
801: scrollbar.addPropertyChangeListener(propertyChangeListener);
802: scrollbar.getModel().addChangeListener(modelListener);
803:
804: scrollTimer.addActionListener(scrollListener);
805: }
806:
807:
814: public void installUI(JComponent c)
815: {
816: super.installUI(c);
817: if (c instanceof JScrollBar)
818: {
819: scrollbar = (JScrollBar) c;
820:
821: trackRect = new Rectangle();
822: thumbRect = new Rectangle();
823:
824: scrollTimer = new Timer(300, null);
825:
826: installDefaults();
827: installComponents();
828: configureScrollBarColors();
829: installListeners();
830:
831: calculatePreferredSize();
832: }
833: }
834:
835:
840: public void layoutContainer(Container scrollbarContainer)
841: {
842: if (scrollbarContainer instanceof JScrollBar)
843: {
844: if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
845: layoutHScrollbar((JScrollBar) scrollbarContainer);
846: else
847: layoutVScrollbar((JScrollBar) scrollbarContainer);
848: }
849: }
850:
851:
856: protected void layoutHScrollbar(JScrollBar sb)
857: {
858: Rectangle vr = new Rectangle();
859: SwingUtilities.calculateInnerArea(scrollbar, vr);
860:
861: Dimension incrDims = incrButton.getPreferredSize();
862: Dimension decrDims = decrButton.getPreferredSize();
863:
864:
865: SwingUtilities.calculateInnerArea(scrollbar, trackRect);
866: trackRect.width -= incrDims.getWidth();
867: trackRect.width -= decrDims.getWidth();
868: trackRect.x += decrDims.getWidth();
869:
870: updateThumbRect();
871:
872: decrButton.setBounds(vr.x, vr.y, decrDims.width, trackRect.height);
873: incrButton.setBounds(trackRect.x + trackRect.width, vr.y, incrDims.width,
874: trackRect.height);
875: }
876:
877:
882: protected void layoutVScrollbar(JScrollBar sb)
883: {
884: Rectangle vr = new Rectangle();
885: SwingUtilities.calculateInnerArea(scrollbar, vr);
886:
887: Dimension incrDims = incrButton.getPreferredSize();
888: Dimension decrDims = decrButton.getPreferredSize();
889:
890:
891: SwingUtilities.calculateInnerArea(scrollbar, trackRect);
892: trackRect.height -= incrDims.getHeight();
893: trackRect.height -= decrDims.getHeight();
894: trackRect.y += decrDims.getHeight();
895:
896: updateThumbRect();
897:
898: decrButton.setBounds(vr.x, vr.y, trackRect.width, decrDims.height);
899: incrButton.setBounds(vr.x, trackRect.y + trackRect.height,
900: trackRect.width, incrDims.height);
901: }
902:
903:
906: void updateThumbRect()
907: {
908: int max = scrollbar.getMaximum();
909: int min = scrollbar.getMinimum();
910: int value = scrollbar.getValue();
911: int extent = scrollbar.getVisibleAmount();
912: if (max - extent <= min)
913: {
914: if (scrollbar.getOrientation() == JScrollBar.HORIZONTAL)
915: {
916: thumbRect.x = trackRect.x;
917: thumbRect.y = trackRect.y;
918: thumbRect.width = getMinimumThumbSize().width;
919: thumbRect.height = trackRect.height;
920: }
921: else
922: {
923: thumbRect.x = trackRect.x;
924: thumbRect.y = trackRect.y;
925: thumbRect.width = trackRect.width;
926: thumbRect.height = getMinimumThumbSize().height;
927: }
928: }
929: else
930: {
931: if (scrollbar.getOrientation() == JScrollBar.HORIZONTAL)
932: {
933: thumbRect.x = trackRect.x;
934: thumbRect.width = Math.max(extent * trackRect.width / (max - min),
935: getMinimumThumbSize().width);
936: int availableWidth = trackRect.width - thumbRect.width;
937: thumbRect.x += (value - min) * availableWidth / (max - min - extent);
938: thumbRect.y = trackRect.y;
939: thumbRect.height = trackRect.height;
940: }
941: else
942: {
943: thumbRect.x = trackRect.x;
944: thumbRect.height = Math.max(extent * trackRect.height / (max - min),
945: getMinimumThumbSize().height);
946: int availableHeight = trackRect.height - thumbRect.height;
947: thumbRect.y = trackRect.y
948: + (value - min) * availableHeight / (max - min - extent);
949: thumbRect.width = trackRect.width;
950: }
951: }
952:
953: }
954:
955:
962: public Dimension minimumLayoutSize(Container scrollbarContainer)
963: {
964: return preferredLayoutSize(scrollbarContainer);
965: }
966:
967:
973: public void paint(Graphics g, JComponent c)
974: {
975: paintTrack(g, c, getTrackBounds());
976: paintThumb(g, c, getThumbBounds());
977:
978: if (trackHighlight == INCREASE_HIGHLIGHT)
979: paintIncreaseHighlight(g);
980: else if (trackHighlight == DECREASE_HIGHLIGHT)
981: paintDecreaseHighlight(g);
982: }
983:
984:
991: protected void paintDecreaseHighlight(Graphics g)
992: {
993: Color saved = g.getColor();
994:
995: g.setColor(trackHighlightColor);
996: if (scrollbar.getOrientation() == HORIZONTAL)
997: g.fillRect(trackRect.x, trackRect.y, thumbRect.x - trackRect.x,
998: trackRect.height);
999: else
1000: g.fillRect(trackRect.x, trackRect.y, trackRect.width,
1001: thumbRect.y - trackRect.y);
1002: g.setColor(saved);
1003: }
1004:
1005:
1012: protected void paintIncreaseHighlight(Graphics g)
1013: {
1014: Color saved = g.getColor();
1015:
1016: g.setColor(trackHighlightColor);
1017: if (scrollbar.getOrientation() == HORIZONTAL)
1018: g.fillRect(thumbRect.x + thumbRect.width, trackRect.y,
1019: trackRect.x + trackRect.width - thumbRect.x - thumbRect.width,
1020: trackRect.height);
1021: else
1022: g.fillRect(trackRect.x, thumbRect.y + thumbRect.height, trackRect.width,
1023: trackRect.y + trackRect.height - thumbRect.y
1024: - thumbRect.height);
1025: g.setColor(saved);
1026: }
1027:
1028:
1035: protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds)
1036: {
1037: g.setColor(thumbColor);
1038: g.fillRect(thumbBounds.x, thumbBounds.y, thumbBounds.width,
1039: thumbBounds.height);
1040:
1041: BasicGraphicsUtils.drawBezel(g, thumbBounds.x, thumbBounds.y,
1042: thumbBounds.width, thumbBounds.height,
1043: false, false, thumbDarkShadowColor,
1044: thumbDarkShadowColor, thumbHighlightColor,
1045: thumbHighlightColor);
1046: }
1047:
1048:
1055: protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds)
1056: {
1057: Color saved = g.getColor();
1058: g.setColor(trackColor);
1059: g.fill3DRect(trackBounds.x, trackBounds.y, trackBounds.width,
1060: trackBounds.height, false);
1061: g.setColor(saved);
1062: }
1063:
1064:
1071: public Dimension preferredLayoutSize(Container scrollbarContainer)
1072: {
1073: if (scrollbarContainer instanceof JComponent)
1074: return getPreferredSize((JComponent) scrollbarContainer);
1075: else
1076: return null;
1077: }
1078:
1079:
1084: public void removeLayoutComponent(Component child)
1085: {
1086:
1087: }
1088:
1089:
1094: protected void scrollByBlock(int direction)
1095: {
1096: scrollbar.setValue(scrollbar.getValue()
1097: + scrollbar.getBlockIncrement(direction));
1098: }
1099:
1100:
1105: protected void scrollByUnit(int direction)
1106: {
1107: scrollbar.setValue(scrollbar.getValue()
1108: + scrollbar.getUnitIncrement(direction));
1109: }
1110:
1111:
1119: protected void setThumbBounds(int x, int y, int width, int height)
1120: {
1121: thumbRect.x = x;
1122: thumbRect.y = y;
1123: thumbRect.width = width;
1124: thumbRect.height = height;
1125: }
1126:
1127:
1131: protected void uninstallComponents()
1132: {
1133: if (incrButton != null)
1134: scrollbar.remove(incrButton);
1135: if (decrButton != null)
1136: scrollbar.remove(decrButton);
1137: }
1138:
1139:
1143: protected void uninstallDefaults()
1144: {
1145: scrollbar.setForeground(null);
1146: scrollbar.setBackground(null);
1147: LookAndFeel.uninstallBorder(scrollbar);
1148: incrButton = null;
1149: decrButton = null;
1150: }
1151:
1152:
1156: protected void uninstallKeyboardActions()
1157: {
1158:
1159: }
1160:
1161:
1164: protected void uninstallListeners()
1165: {
1166: if (scrollTimer != null)
1167: scrollTimer.removeActionListener(scrollListener);
1168:
1169: if (scrollbar != null)
1170: {
1171: scrollbar.getModel().removeChangeListener(modelListener);
1172: scrollbar.removePropertyChangeListener(propertyChangeListener);
1173: scrollbar.removeMouseListener(trackListener);
1174: scrollbar.removeMouseMotionListener(trackListener);
1175: }
1176:
1177: if (decrButton != null)
1178: decrButton.removeMouseListener(buttonListener);
1179: if (incrButton != null)
1180: incrButton.removeMouseListener(buttonListener);
1181:
1182: propertyChangeListener = null;
1183: modelListener = null;
1184: buttonListener = null;
1185: trackListener = null;
1186: scrollListener = null;
1187: }
1188:
1189:
1196: public void uninstallUI(JComponent c)
1197: {
1198: uninstallListeners();
1199: uninstallDefaults();
1200: uninstallComponents();
1201:
1202: scrollTimer = null;
1203:
1204: thumbRect = null;
1205: trackRect = null;
1206:
1207: trackColor = null;
1208: trackHighlightColor = null;
1209: thumbColor = null;
1210: thumbHighlightColor = null;
1211: thumbDarkShadowColor = null;
1212: thumbLightShadowColor = null;
1213:
1214: scrollbar = null;
1215: }
1216:
1217:
1227: int valueForYPosition(int yPos)
1228: {
1229: int min = scrollbar.getMinimum();
1230: int max = scrollbar.getMaximum();
1231: int len = trackRect.height;
1232:
1233: int value;
1234:
1235:
1236:
1237: if (len == 0)
1238: return ((max - min) / 2);
1239:
1240: value = ((yPos - trackRect.y) * (max - min) / len + min);
1241:
1242:
1243: if (value > max)
1244: value = max;
1245: else if (value < min)
1246: value = min;
1247: return value;
1248: }
1249:
1250:
1260: int valueForXPosition(int xPos)
1261: {
1262: int min = scrollbar.getMinimum();
1263: int max = scrollbar.getMaximum();
1264: int len = trackRect.width;
1265:
1266: int value;
1267:
1268:
1269:
1270: if (len == 0)
1271: return ((max - min) / 2);
1272:
1273: value = ((xPos - trackRect.x) * (max - min) / len + min);
1274:
1275:
1276: if (value > max)
1277: value = max;
1278: else if (value < min)
1279: value = min;
1280: return value;
1281: }
1282: }