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:
71:
74: public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager,
75: SwingConstants
76: {
77:
81: protected class ArrowButtonListener extends MouseAdapter
82: {
83:
89: public void mousePressed(MouseEvent e)
90: {
91: scrollTimer.stop();
92: scrollListener.setScrollByBlock(false);
93: if (e.getSource() == incrButton)
94: scrollListener.setDirection(POSITIVE_SCROLL);
95: else
96: scrollListener.setDirection(NEGATIVE_SCROLL);
97: scrollTimer.start();
98: }
99:
100:
105: public void mouseReleased(MouseEvent e)
106: {
107: scrollTimer.stop();
108: }
109: }
110:
111:
114: protected class ModelListener implements ChangeListener
115: {
116:
121: public void stateChanged(ChangeEvent e)
122: {
123:
124: calculatePreferredSize();
125: getThumbBounds();
126: scrollbar.repaint();
127: }
128: }
129:
130:
133: public class PropertyChangeHandler implements PropertyChangeListener
134: {
135:
140: public void propertyChange(PropertyChangeEvent e)
141: {
142: if (e.getPropertyName().equals("model"))
143: {
144: ((BoundedRangeModel) e.getOldValue()).removeChangeListener(modelListener);
145: scrollbar.getModel().addChangeListener(modelListener);
146: getThumbBounds();
147: }
148: else if (e.getPropertyName().equals("orientation"))
149: {
150: incrButton.removeMouseListener(buttonListener);
151: decrButton.removeMouseListener(buttonListener);
152: int orientation = scrollbar.getOrientation();
153: switch (orientation)
154: {
155: case (JScrollBar.HORIZONTAL):
156: incrButton = createIncreaseButton(EAST);
157: decrButton = createDecreaseButton(WEST);
158: break;
159: default:
160: incrButton = createIncreaseButton(SOUTH);
161: decrButton = createDecreaseButton(NORTH);
162: break;
163: }
164: incrButton.addMouseListener(buttonListener);
165: decrButton.addMouseListener(buttonListener);
166: calculatePreferredSize();
167: }
168: scrollbar.repaint();
169: }
170: }
171:
172:
176: protected class ScrollListener implements ActionListener
177: {
178:
179: private transient int direction;
180:
181:
182: private transient boolean block;
183:
184:
188: public ScrollListener()
189: {
190: direction = POSITIVE_SCROLL;
191: block = true;
192: }
193:
194:
201: public ScrollListener(int dir, boolean block)
202: {
203: direction = dir;
204: this.block = block;
205: }
206:
207:
212: public void setDirection(int direction)
213: {
214: this.direction = direction;
215: }
216:
217:
222: public void setScrollByBlock(boolean block)
223: {
224: this.block = block;
225: }
226:
227:
232: public void actionPerformed(ActionEvent e)
233: {
234: if (block)
235: {
236:
237:
238:
239: if (! trackListener.shouldScroll(direction))
240: {
241: trackHighlight = NO_HIGHLIGHT;
242: scrollbar.repaint();
243: return;
244: }
245: scrollByBlock(direction);
246: }
247: else
248: scrollByUnit(direction);
249: }
250: }
251:
252:
255: protected class TrackListener extends MouseAdapter
256: implements MouseMotionListener
257: {
258:
259: protected int currentMouseX;
260:
261:
262: protected int currentMouseY;
263:
264:
268: protected int offset;
269:
270:
275: public void mouseDragged(MouseEvent e)
276: {
277: currentMouseX = e.getX();
278: currentMouseY = e.getY();
279: if (scrollbar.getValueIsAdjusting())
280: {
281: int value;
282: if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
283: value = valueForXPosition(currentMouseX) - offset;
284: else
285: value = valueForYPosition(currentMouseY) - offset;
286:
287: scrollbar.setValue(value);
288: }
289: }
290:
291:
296: public void mouseMoved(MouseEvent e)
297: {
298:
299:
300: }
301:
302:
308: public void mousePressed(MouseEvent e)
309: {
310: currentMouseX = e.getX();
311: currentMouseY = e.getY();
312:
313: int value;
314: if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
315: value = valueForXPosition(currentMouseX);
316: else
317: value = valueForYPosition(currentMouseY);
318:
319: if (value == scrollbar.getValue())
320: return;
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.start();
337: }
338: else
339: {
340:
341:
342:
343:
344:
345:
346: scrollbar.setValueIsAdjusting(true);
347: offset = value - scrollbar.getValue();
348: }
349: scrollbar.repaint();
350: }
351:
352:
358: public void mouseReleased(MouseEvent e)
359: {
360: trackHighlight = NO_HIGHLIGHT;
361: scrollTimer.stop();
362:
363: if (scrollbar.getValueIsAdjusting())
364: scrollbar.setValueIsAdjusting(false);
365: scrollbar.repaint();
366: }
367:
368:
376: public boolean shouldScroll(int direction)
377: {
378: int value;
379: if (scrollbar.getOrientation() == HORIZONTAL)
380: value = valueForXPosition(currentMouseX);
381: else
382: value = valueForYPosition(currentMouseY);
383:
384: if (direction == POSITIVE_SCROLL)
385: return (value > scrollbar.getValue());
386: else
387: return (value < scrollbar.getValue());
388: }
389: }
390:
391:
392: protected ArrowButtonListener buttonListener;
393:
394:
395: protected ModelListener modelListener;
396:
397:
398: protected PropertyChangeListener propertyChangeListener;
399:
400:
401: protected ScrollListener scrollListener;
402:
403:
404: protected TrackListener trackListener;
405:
406:
407: protected JButton decrButton;
408:
409:
410: protected JButton incrButton;
411:
412:
413: protected Dimension maximumThumbSize;
414:
415:
416: protected Dimension minimumThumbSize;
417:
418:
419: protected Color thumbColor;
420:
421:
422: protected Color thumbDarkShadowColor;
423:
424:
425: protected Color thumbHighlightColor;
426:
427:
428: protected Color thumbLightShadowColor;
429:
430:
431: protected Color trackHighlightColor;
432:
433:
434: protected Color trackColor;
435:
436:
437: protected Rectangle trackRect;
438:
439:
440: protected Rectangle thumbRect;
441:
442:
443: protected static final int DECREASE_HIGHLIGHT = 1;
444:
445:
446: protected static final int INCREASE_HIGHLIGHT = 2;
447:
448:
449: protected static final int NO_HIGHLIGHT = 0;
450:
451:
452: private static final int POSITIVE_SCROLL = 1;
453:
454:
455: private static final int NEGATIVE_SCROLL = -1;
456:
457:
458: private transient Dimension preferredSize;
459:
460:
461: protected int trackHighlight;
462:
463:
464: protected boolean isDragging;
465:
466:
467: protected Timer scrollTimer;
468:
469:
470: protected JScrollBar scrollbar;
471:
472:
478: public void addLayoutComponent(String name, Component child)
479: {
480:
481:
482: }
483:
484:
488: protected void configureScrollBarColors()
489: {
490: UIDefaults defaults = UIManager.getLookAndFeelDefaults();
491:
492: trackColor = defaults.getColor("ScrollBar.track");
493: trackHighlightColor = defaults.getColor("ScrollBar.trackHighlight");
494: thumbColor = defaults.getColor("ScrollBar.thumb");
495: thumbHighlightColor = defaults.getColor("ScrollBar.thumbHighlight");
496: thumbDarkShadowColor = defaults.getColor("ScrollBar.thumbDarkShadow");
497: thumbLightShadowColor = defaults.getColor("ScrollBar.thumbShadow");
498: }
499:
500:
505: protected ArrowButtonListener createArrowButtonListener()
506: {
507: return new ArrowButtonListener();
508: }
509:
510:
518: protected JButton createIncreaseButton(int orientation)
519: {
520: if (incrButton == null)
521: incrButton = new BasicArrowButton(orientation);
522: else
523: ((BasicArrowButton) incrButton).setDirection(orientation);
524: return incrButton;
525: }
526:
527:
535: protected JButton createDecreaseButton(int orientation)
536: {
537: if (decrButton == null)
538: decrButton = new BasicArrowButton(orientation);
539: else
540: ((BasicArrowButton) decrButton).setDirection(orientation);
541: return decrButton;
542: }
543:
544:
549: protected ModelListener createModelListener()
550: {
551: return new ModelListener();
552: }
553:
554:
559: protected PropertyChangeListener createPropertyChangeListener()
560: {
561: return new PropertyChangeHandler();
562: }
563:
564:
569: protected ScrollListener createScrollListener()
570: {
571: return new ScrollListener();
572: }
573:
574:
579: protected TrackListener createTrackListener()
580: {
581: return new TrackListener();
582: }
583:
584:
591: public static ComponentUI createUI(JComponent c)
592: {
593: return new BasicScrollBarUI();
594: }
595:
596:
603: public Dimension getMaximumSize(JComponent c)
604: {
605: return getPreferredSize(c);
606: }
607:
608:
613: protected Dimension getMaximumThumbSize()
614: {
615: return maximumThumbSize;
616: }
617:
618:
625: public Dimension getMinimumSize(JComponent c)
626: {
627: return getPreferredSize(c);
628: }
629:
630:
635: protected Dimension getMinimumThumbSize()
636: {
637: return minimumThumbSize;
638: }
639:
640:
645: void calculatePreferredSize()
646: {
647:
648: int height;
649: int width;
650: height = width = 0;
651:
652: if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
653: {
654: width += incrButton.getPreferredSize().getWidth();
655: width += decrButton.getPreferredSize().getWidth();
656:
657: width += (scrollbar.getMaximum() - scrollbar.getMinimum());
658:
659: height = Math.max(incrButton.getPreferredSize().height,
660: decrButton.getPreferredSize().height);
661: height = Math.max(getMinimumThumbSize().height, height);
662: height = Math.min(getMaximumThumbSize().height, height);
663: }
664: else
665: {
666: height += incrButton.getPreferredSize().getHeight();
667: height += decrButton.getPreferredSize().getHeight();
668:
669: height += (scrollbar.getMaximum() - scrollbar.getMinimum());
670:
671: width = Math.max(incrButton.getPreferredSize().width,
672: decrButton.getPreferredSize().width);
673: width = Math.max(getMinimumThumbSize().width, width);
674: width = Math.min(getMaximumThumbSize().width, width);
675: }
676:
677: Insets insets = scrollbar.getInsets();
678:
679: height += insets.top + insets.bottom;
680: width += insets.left + insets.right;
681:
682: preferredSize = new Dimension(width, height);
683: }
684:
685:
696: public Dimension getPreferredSize(JComponent c)
697: {
698: calculatePreferredSize();
699: return preferredSize;
700: }
701:
702:
708: protected Rectangle getThumbBounds()
709: {
710: int max = scrollbar.getMaximum();
711: int min = scrollbar.getMinimum();
712: int value = scrollbar.getValue();
713: int extent = scrollbar.getVisibleAmount();
714:
715:
716: if (max == min)
717: {
718: thumbRect.x = trackRect.x;
719: thumbRect.y = trackRect.y;
720: if (scrollbar.getOrientation() == HORIZONTAL)
721: {
722: thumbRect.width = getMinimumThumbSize().width;
723: thumbRect.height = trackRect.height;
724: }
725: else
726: {
727: thumbRect.width = trackRect.width;
728: thumbRect.height = getMinimumThumbSize().height;
729: }
730: return thumbRect;
731: }
732:
733: if (scrollbar.getOrientation() == HORIZONTAL)
734: {
735: thumbRect.x = trackRect.x;
736: thumbRect.x += (value - min) * trackRect.width / (max - min);
737: thumbRect.y = trackRect.y;
738:
739: thumbRect.width = Math.max(extent * trackRect.width / (max - min),
740: getMinimumThumbSize().width);
741: thumbRect.height = trackRect.height;
742: }
743: else
744: {
745: thumbRect.x = trackRect.x;
746: thumbRect.y = trackRect.y + value * trackRect.height / (max - min);
747:
748: thumbRect.width = trackRect.width;
749: thumbRect.height = Math.max(extent * trackRect.height / (max - min),
750: getMinimumThumbSize().height);
751: }
752: return thumbRect;
753: }
754:
755:
761: protected Rectangle getTrackBounds()
762: {
763: SwingUtilities.calculateInnerArea(scrollbar, trackRect);
764:
765: if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
766: {
767: trackRect.width -= incrButton.getPreferredSize().getWidth();
768: trackRect.width -= decrButton.getPreferredSize().getWidth();
769:
770: trackRect.x += decrButton.getPreferredSize().getWidth();
771: }
772: else
773: {
774: trackRect.height -= incrButton.getPreferredSize().getHeight();
775: trackRect.height -= decrButton.getPreferredSize().getHeight();
776:
777: trackRect.y += incrButton.getPreferredSize().getHeight();
778: }
779: return trackRect;
780: }
781:
782:
786: protected void installComponents()
787: {
788: int orientation = scrollbar.getOrientation();
789: switch (orientation)
790: {
791: case (JScrollBar.HORIZONTAL):
792: incrButton = createIncreaseButton(EAST);
793: decrButton = createDecreaseButton(WEST);
794: break;
795: default:
796: incrButton = createIncreaseButton(SOUTH);
797: decrButton = createDecreaseButton(NORTH);
798: break;
799: }
800: scrollbar.add(incrButton);
801: scrollbar.add(decrButton);
802: }
803:
804:
808: protected void installDefaults()
809: {
810: UIDefaults defaults = UIManager.getLookAndFeelDefaults();
811:
812: scrollbar.setForeground(defaults.getColor("ScrollBar.foreground"));
813: scrollbar.setBackground(defaults.getColor("ScrollBar.background"));
814: scrollbar.setBorder(defaults.getBorder("ScrollBar.border"));
815: scrollbar.setOpaque(true);
816: scrollbar.setLayout(this);
817:
818: thumbColor = defaults.getColor("ScrollBar.thumb");
819: thumbDarkShadowColor = defaults.getColor("ScrollBar.thumbDarkShadow");
820: thumbHighlightColor = defaults.getColor("ScrollBar.thumbHighlight");
821: thumbLightShadowColor = defaults.getColor("ScrollBar.thumbShadow");
822:
823: maximumThumbSize = defaults.getDimension("ScrollBar.maximumThumbSize");
824: minimumThumbSize = defaults.getDimension("ScrollBar.minimumThumbSize");
825: }
826:
827:
830: protected void installKeyboardActions()
831: {
832:
833: }
834:
835:
839: protected void installListeners()
840: {
841: scrollListener = createScrollListener();
842: trackListener = createTrackListener();
843: buttonListener = createArrowButtonListener();
844: modelListener = createModelListener();
845: propertyChangeListener = createPropertyChangeListener();
846:
847: scrollbar.addMouseMotionListener(trackListener);
848: scrollbar.addMouseListener(trackListener);
849:
850: incrButton.addMouseListener(buttonListener);
851: decrButton.addMouseListener(buttonListener);
852:
853: scrollbar.addPropertyChangeListener(propertyChangeListener);
854: scrollbar.getModel().addChangeListener(modelListener);
855:
856: scrollTimer.addActionListener(scrollListener);
857: }
858:
859:
866: public void installUI(JComponent c)
867: {
868: super.installUI(c);
869: if (c instanceof JScrollBar)
870: {
871: scrollbar = (JScrollBar) c;
872:
873: trackRect = new Rectangle();
874: thumbRect = new Rectangle();
875:
876: scrollTimer = new Timer(200, null);
877: scrollTimer.setRepeats(true);
878:
879: installComponents();
880: installDefaults();
881: configureScrollBarColors();
882: installListeners();
883:
884: calculatePreferredSize();
885: }
886: }
887:
888:
893: public void layoutContainer(Container scrollbarContainer)
894: {
895: if (scrollbarContainer instanceof JScrollBar)
896: {
897: if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
898: layoutHScrollbar((JScrollBar) scrollbarContainer);
899: else
900: layoutVScrollbar((JScrollBar) scrollbarContainer);
901: }
902: }
903:
904:
909: protected void layoutHScrollbar(JScrollBar sb)
910: {
911:
912: Rectangle vr = new Rectangle();
913: SwingUtilities.calculateInnerArea(scrollbar, vr);
914:
915:
916: getTrackBounds();
917: getThumbBounds();
918:
919: Dimension incrDims = incrButton.getPreferredSize();
920: Dimension decrDims = decrButton.getPreferredSize();
921:
922: decrButton.setBounds(vr.x, vr.y, decrDims.width, trackRect.height);
923: incrButton.setBounds(trackRect.x + trackRect.width, vr.y, incrDims.width,
924: trackRect.height);
925: }
926:
927:
932: protected void layoutVScrollbar(JScrollBar sb)
933: {
934: Rectangle vr = new Rectangle();
935: SwingUtilities.calculateInnerArea(scrollbar, vr);
936:
937:
938: getTrackBounds();
939: getThumbBounds();
940:
941: Dimension incrDims = incrButton.getPreferredSize();
942: Dimension decrDims = decrButton.getPreferredSize();
943:
944: decrButton.setBounds(vr.x, vr.y, trackRect.width, decrDims.height);
945: incrButton.setBounds(vr.x, trackRect.y + trackRect.height,
946: trackRect.width, incrDims.height);
947: }
948:
949:
956: public Dimension minimumLayoutSize(Container scrollbarContainer)
957: {
958: return preferredLayoutSize(scrollbarContainer);
959: }
960:
961:
967: public void paint(Graphics g, JComponent c)
968: {
969: paintTrack(g, c, getTrackBounds());
970: paintThumb(g, c, getThumbBounds());
971:
972: if (trackHighlight == INCREASE_HIGHLIGHT)
973: paintIncreaseHighlight(g);
974: else if (trackHighlight == DECREASE_HIGHLIGHT)
975: paintDecreaseHighlight(g);
976: }
977:
978:
985: protected void paintDecreaseHighlight(Graphics g)
986: {
987: Color saved = g.getColor();
988:
989: g.setColor(trackHighlightColor);
990: if (scrollbar.getOrientation() == HORIZONTAL)
991: g.fillRect(trackRect.x, trackRect.y, thumbRect.x - trackRect.x,
992: trackRect.height);
993: else
994: g.fillRect(trackRect.x, trackRect.y, trackRect.width,
995: thumbRect.y - trackRect.y);
996: g.setColor(saved);
997: }
998:
999:
1006: protected void paintIncreaseHighlight(Graphics g)
1007: {
1008: Color saved = g.getColor();
1009:
1010: g.setColor(trackHighlightColor);
1011: if (scrollbar.getOrientation() == HORIZONTAL)
1012: g.fillRect(thumbRect.x + thumbRect.width, trackRect.y,
1013: trackRect.x + trackRect.width - thumbRect.x - thumbRect.width,
1014: trackRect.height);
1015: else
1016: g.fillRect(trackRect.x, thumbRect.y + thumbRect.height, trackRect.width,
1017: trackRect.y + trackRect.height - thumbRect.y
1018: - thumbRect.height);
1019: g.setColor(saved);
1020: }
1021:
1022:
1029: protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds)
1030: {
1031: g.setColor(thumbColor);
1032: g.fillRect(thumbBounds.x, thumbBounds.y, thumbBounds.width,
1033: thumbBounds.height);
1034:
1035: BasicGraphicsUtils.drawBezel(g, thumbBounds.x, thumbBounds.y,
1036: thumbBounds.width, thumbBounds.height,
1037: false, false, thumbDarkShadowColor,
1038: thumbDarkShadowColor, thumbHighlightColor,
1039: thumbHighlightColor);
1040: }
1041:
1042:
1049: protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds)
1050: {
1051: Color saved = g.getColor();
1052: g.setColor(trackColor);
1053: g.fill3DRect(trackBounds.x, trackBounds.y, trackBounds.width,
1054: trackBounds.height, false);
1055: g.setColor(saved);
1056: }
1057:
1058:
1065: public Dimension preferredLayoutSize(Container scrollbarContainer)
1066: {
1067: if (scrollbarContainer instanceof JComponent)
1068: return getPreferredSize((JComponent) scrollbarContainer);
1069: else
1070: return null;
1071: }
1072:
1073:
1078: public void removeLayoutComponent(Component child)
1079: {
1080:
1081: }
1082:
1083:
1088: protected void scrollByBlock(int direction)
1089: {
1090: scrollbar.setValue(scrollbar.getValue()
1091: + scrollbar.getBlockIncrement(direction));
1092: }
1093:
1094:
1099: protected void scrollByUnit(int direction)
1100: {
1101: scrollbar.setValue(scrollbar.getValue()
1102: + scrollbar.getUnitIncrement(direction));
1103: }
1104:
1105:
1113: protected void setThumbBounds(int x, int y, int width, int height)
1114: {
1115: thumbRect.x = x;
1116: thumbRect.y = y;
1117: thumbRect.width = width;
1118: thumbRect.height = height;
1119: }
1120:
1121:
1125: protected void uninstallComponents()
1126: {
1127: scrollbar.remove(incrButton);
1128: scrollbar.remove(decrButton);
1129: incrButton = null;
1130: decrButton = null;
1131: }
1132:
1133:
1137: protected void uninstallDefaults()
1138: {
1139: scrollbar.setForeground(null);
1140: scrollbar.setBackground(null);
1141: scrollbar.setBorder(null);
1142: }
1143:
1144:
1148: protected void uninstallKeyboardActions()
1149: {
1150:
1151: }
1152:
1153:
1156: protected void uninstallListeners()
1157: {
1158: scrollTimer.removeActionListener(scrollListener);
1159:
1160: scrollbar.getModel().removeChangeListener(modelListener);
1161: scrollbar.removePropertyChangeListener(propertyChangeListener);
1162:
1163: decrButton.removeMouseListener(buttonListener);
1164: incrButton.removeMouseListener(buttonListener);
1165:
1166: scrollbar.removeMouseListener(trackListener);
1167: scrollbar.removeMouseMotionListener(trackListener);
1168:
1169: propertyChangeListener = null;
1170: modelListener = null;
1171: buttonListener = null;
1172: trackListener = null;
1173: scrollListener = null;
1174: }
1175:
1176:
1183: public void uninstallUI(JComponent c)
1184: {
1185: uninstallDefaults();
1186: uninstallListeners();
1187: uninstallComponents();
1188:
1189: scrollTimer = null;
1190:
1191: thumbRect = null;
1192: trackRect = null;
1193:
1194: trackColor = null;
1195: trackHighlightColor = null;
1196: thumbColor = null;
1197: thumbHighlightColor = null;
1198: thumbDarkShadowColor = null;
1199: thumbLightShadowColor = null;
1200:
1201: scrollbar = null;
1202: }
1203:
1204:
1214: int valueForYPosition(int yPos)
1215: {
1216: int min = scrollbar.getMinimum();
1217: int max = scrollbar.getMaximum();
1218: int len = trackRect.height;
1219:
1220: int value;
1221:
1222:
1223:
1224: if (len == 0)
1225: return ((max - min) / 2);
1226:
1227: value = ((yPos - trackRect.y) * (max - min) / len + min);
1228:
1229:
1230: if (value > max)
1231: value = max;
1232: else if (value < min)
1233: value = min;
1234: return value;
1235: }
1236:
1237:
1247: int valueForXPosition(int xPos)
1248: {
1249: int min = scrollbar.getMinimum();
1250: int max = scrollbar.getMaximum();
1251: int len = trackRect.width;
1252:
1253: int value;
1254:
1255:
1256:
1257: if (len == 0)
1258: return ((max - min) / 2);
1259:
1260: value = ((xPos - trackRect.x) * (max - min) / len + min);
1261:
1262:
1263: if (value > max)
1264: value = max;
1265: else if (value < min)
1266: value = min;
1267: return value;
1268: }
1269: }