1:
37:
38:
39: package ;
40:
41: import ;
42:
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: import ;
57: import ;
58:
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:
73:
76: public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager,
77: SwingConstants
78: {
79:
83: protected class ArrowButtonListener extends MouseAdapter
84: {
85:
86:
92: public void mousePressed(MouseEvent e)
93: {
94: scrollTimer.stop();
95: scrollListener.setScrollByBlock(false);
96: if (e.getSource() == incrButton)
97: scrollListener.setDirection(POSITIVE_SCROLL);
98: else if (e.getSource() == decrButton)
99: scrollListener.setDirection(NEGATIVE_SCROLL);
100: scrollTimer.setDelay(100);
101: scrollTimer.start();
102: }
103:
104:
109: public void mouseReleased(MouseEvent e)
110: {
111: scrollTimer.stop();
112: scrollTimer.setDelay(300);
113: if (e.getSource() == incrButton)
114: scrollByUnit(POSITIVE_SCROLL);
115: else if (e.getSource() == decrButton)
116: scrollByUnit(NEGATIVE_SCROLL);
117: }
118: }
119:
120:
123: protected class ModelListener implements ChangeListener
124: {
125:
130: public void stateChanged(ChangeEvent e)
131: {
132: calculatePreferredSize();
133: updateThumbRect();
134: scrollbar.repaint();
135: }
136: }
137:
138:
141: public class PropertyChangeHandler implements PropertyChangeListener
142: {
143:
148: public void propertyChange(PropertyChangeEvent e)
149: {
150: if (e.getPropertyName().equals("model"))
151: {
152: ((BoundedRangeModel) e.getOldValue()).removeChangeListener(modelListener);
153: scrollbar.getModel().addChangeListener(modelListener);
154: updateThumbRect();
155: }
156: else if (e.getPropertyName().equals("orientation"))
157: {
158: uninstallListeners();
159: uninstallComponents();
160: uninstallDefaults();
161: installDefaults();
162: installComponents();
163: installListeners();
164: }
165: else if (e.getPropertyName().equals("enabled"))
166: {
167: Boolean b = (Boolean) e.getNewValue();
168: if (incrButton != null)
169: incrButton.setEnabled(b.booleanValue());
170: if (decrButton != null)
171: decrButton.setEnabled(b.booleanValue());
172: }
173: }
174: }
175:
176:
180: protected class ScrollListener implements ActionListener
181: {
182:
183: private transient int direction;
184:
185:
186: private transient boolean block;
187:
188:
192: public ScrollListener()
193: {
194: direction = POSITIVE_SCROLL;
195: block = true;
196: }
197:
198:
205: public ScrollListener(int dir, boolean block)
206: {
207: direction = dir;
208: this.block = block;
209: }
210:
211:
216: public void setDirection(int direction)
217: {
218: this.direction = direction;
219: }
220:
221:
226: public void setScrollByBlock(boolean block)
227: {
228: this.block = block;
229: }
230:
231:
236: public void actionPerformed(ActionEvent e)
237: {
238: if (block)
239: {
240:
241:
242:
243: if (!trackListener.shouldScroll(direction))
244: {
245: trackHighlight = NO_HIGHLIGHT;
246: scrollbar.repaint();
247: return;
248: }
249: scrollByBlock(direction);
250: }
251: else
252: scrollByUnit(direction);
253: }
254: }
255:
256:
259: protected class TrackListener extends MouseAdapter
260: implements MouseMotionListener
261: {
262:
263: protected int currentMouseX;
264:
265:
266: protected int currentMouseY;
267:
268:
272: protected int offset;
273:
274:
279: public void mouseDragged(MouseEvent e)
280: {
281: currentMouseX = e.getX();
282: currentMouseY = e.getY();
283: if (scrollbar.getValueIsAdjusting())
284: {
285: int value;
286: if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
287: value = valueForXPosition(currentMouseX) - offset;
288: else
289: value = valueForYPosition(currentMouseY) - offset;
290:
291: scrollbar.setValue(value);
292: }
293: }
294:
295:
300: public void mouseMoved(MouseEvent e)
301: {
302:
303:
304: }
305:
306:
312: public void mousePressed(MouseEvent e)
313: {
314: currentMouseX = e.getX();
315: currentMouseY = e.getY();
316:
317: int value;
318: if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
319: value = valueForXPosition(currentMouseX);
320: else
321: value = valueForYPosition(currentMouseY);
322:
323: if (! thumbRect.contains(e.getPoint()))
324: {
325: scrollTimer.stop();
326: scrollListener.setScrollByBlock(true);
327: if (value > scrollbar.getValue())
328: {
329: trackHighlight = INCREASE_HIGHLIGHT;
330: scrollListener.setDirection(POSITIVE_SCROLL);
331: }
332: else
333: {
334: trackHighlight = DECREASE_HIGHLIGHT;
335: scrollListener.setDirection(NEGATIVE_SCROLL);
336: }
337: scrollTimer.setDelay(100);
338: scrollTimer.start();
339: }
340: else
341: {
342:
343:
344:
345:
346:
347:
348:
349: scrollListener.setScrollByBlock(false);
350: scrollbar.setValueIsAdjusting(true);
351: offset = value - scrollbar.getValue();
352: }
353: scrollbar.repaint();
354: }
355:
356:
362: public void mouseReleased(MouseEvent e)
363: {
364: scrollTimer.stop();
365: scrollTimer.setDelay(300);
366: currentMouseX = e.getX();
367: currentMouseY = e.getY();
368:
369: if (shouldScroll(POSITIVE_SCROLL))
370: scrollByBlock(POSITIVE_SCROLL);
371: else if (shouldScroll(NEGATIVE_SCROLL))
372: scrollByBlock(NEGATIVE_SCROLL);
373:
374: trackHighlight = NO_HIGHLIGHT;
375: scrollListener.setScrollByBlock(false);
376: scrollbar.setValueIsAdjusting(true);
377: scrollbar.repaint();
378: }
379:
380:
388: boolean shouldScroll(int direction)
389: {
390: int value;
391: if (scrollbar.getOrientation() == HORIZONTAL)
392: value = valueForXPosition(currentMouseX);
393: else
394: value = valueForYPosition(currentMouseY);
395:
396: if (thumbRect.contains(currentMouseX, currentMouseY))
397: return false;
398:
399: if (direction == POSITIVE_SCROLL)
400: return (value > scrollbar.getValue());
401: else
402: return (value < scrollbar.getValue());
403: }
404: }
405:
406:
407: protected ArrowButtonListener buttonListener;
408:
409:
410: protected ModelListener modelListener;
411:
412:
413: protected PropertyChangeListener propertyChangeListener;
414:
415:
416: protected ScrollListener scrollListener;
417:
418:
419: protected TrackListener trackListener;
420:
421:
422: protected JButton decrButton;
423:
424:
425: protected JButton incrButton;
426:
427:
428: protected Dimension maximumThumbSize;
429:
430:
431: protected Dimension minimumThumbSize;
432:
433:
434: protected Color thumbColor;
435:
436:
437: protected Color thumbDarkShadowColor;
438:
439:
440: protected Color thumbHighlightColor;
441:
442:
443: protected Color thumbLightShadowColor;
444:
445:
446: protected Color trackHighlightColor;
447:
448:
449: protected Color trackColor;
450:
451:
452: protected Rectangle trackRect;
453:
454:
455: protected Rectangle thumbRect;
456:
457:
458: protected static final int DECREASE_HIGHLIGHT = 1;
459:
460:
461: protected static final int INCREASE_HIGHLIGHT = 2;
462:
463:
464: protected static final int NO_HIGHLIGHT = 0;
465:
466:
467: private static final int POSITIVE_SCROLL = 1;
468:
469:
470: private static final int NEGATIVE_SCROLL = -1;
471:
472:
473: private transient Dimension preferredSize;
474:
475:
476: protected int trackHighlight;
477:
478:
479: protected boolean isDragging;
480:
481:
482: protected Timer scrollTimer;
483:
484:
485: protected JScrollBar scrollbar;
486:
487:
493: public void addLayoutComponent(String name, Component child)
494: {
495:
496:
497: }
498:
499:
503: protected void configureScrollBarColors()
504: {
505: trackColor = UIManager.getColor("ScrollBar.track");
506: trackHighlightColor = UIManager.getColor("ScrollBar.trackHighlight");
507: thumbColor = UIManager.getColor("ScrollBar.thumb");
508: thumbHighlightColor = UIManager.getColor("ScrollBar.thumbHighlight");
509: thumbDarkShadowColor = UIManager.getColor("ScrollBar.thumbDarkShadow");
510: thumbLightShadowColor = UIManager.getColor("ScrollBar.thumbShadow");
511: }
512:
513:
518: protected ArrowButtonListener createArrowButtonListener()
519: {
520: return new ArrowButtonListener();
521: }
522:
523:
531: protected JButton createIncreaseButton(int orientation)
532: {
533: return new BasicArrowButton(orientation);
534: }
535:
536:
544: protected JButton createDecreaseButton(int orientation)
545: {
546: return new BasicArrowButton(orientation);
547: }
548:
549:
554: protected ModelListener createModelListener()
555: {
556: return new ModelListener();
557: }
558:
559:
564: protected PropertyChangeListener createPropertyChangeListener()
565: {
566: return new PropertyChangeHandler();
567: }
568:
569:
574: protected ScrollListener createScrollListener()
575: {
576: return new ScrollListener();
577: }
578:
579:
584: protected TrackListener createTrackListener()
585: {
586: return new TrackListener();
587: }
588:
589:
596: public static ComponentUI createUI(JComponent c)
597: {
598: return new BasicScrollBarUI();
599: }
600:
601:
608: public Dimension getMaximumSize(JComponent c)
609: {
610: return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
611: }
612:
613:
618: protected Dimension getMaximumThumbSize()
619: {
620: return maximumThumbSize;
621: }
622:
623:
630: public Dimension getMinimumSize(JComponent c)
631: {
632: return getPreferredSize(c);
633: }
634:
635:
640: protected Dimension getMinimumThumbSize()
641: {
642: return minimumThumbSize;
643: }
644:
645:
650: void calculatePreferredSize()
651: {
652: int height;
653: int width;
654: height = width = 0;
655:
656: if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
657: {
658: width += incrButton.getPreferredSize().getWidth();
659: width += decrButton.getPreferredSize().getWidth();
660: width += 16;
661: height = UIManager.getInt("ScrollBar.width");
662: }
663: else
664: {
665: height += incrButton.getPreferredSize().getHeight();
666: height += decrButton.getPreferredSize().getHeight();
667: height += 16;
668: width = UIManager.getInt("ScrollBar.width");
669: }
670:
671: Insets insets = scrollbar.getInsets();
672:
673: height += insets.top + insets.bottom;
674: width += insets.left + insets.right;
675:
676: preferredSize = new Dimension(width, height);
677: }
678:
679:
690: public Dimension getPreferredSize(JComponent c)
691: {
692: calculatePreferredSize();
693: return preferredSize;
694: }
695:
696:
702: protected Rectangle getThumbBounds()
703: {
704: return thumbRect;
705: }
706:
707:
713: protected Rectangle getTrackBounds()
714: {
715: return trackRect;
716: }
717:
718:
722: protected void installComponents()
723: {
724: int orientation = scrollbar.getOrientation();
725: switch (orientation)
726: {
727: case (JScrollBar.HORIZONTAL):
728: incrButton = createIncreaseButton(EAST);
729: decrButton = createDecreaseButton(WEST);
730: break;
731: default:
732: incrButton = createIncreaseButton(SOUTH);
733: decrButton = createDecreaseButton(NORTH);
734: break;
735: }
736:
737: if (incrButton != null)
738: scrollbar.add(incrButton);
739: if (decrButton != null)
740: scrollbar.add(decrButton);
741: }
742:
743:
747: protected void installDefaults()
748: {
749: LookAndFeel.installColors(scrollbar, "ScrollBar.background",
750: "ScrollBar.foreground");
751: LookAndFeel.installBorder(scrollbar, "ScrollBar.border");
752: scrollbar.setOpaque(true);
753: scrollbar.setLayout(this);
754:
755: thumbColor = UIManager.getColor("ScrollBar.thumb");
756: thumbDarkShadowColor = UIManager.getColor("ScrollBar.thumbDarkShadow");
757: thumbHighlightColor = UIManager.getColor("ScrollBar.thumbHighlight");
758: thumbLightShadowColor = UIManager.getColor("ScrollBar.thumbShadow");
759:
760: maximumThumbSize = UIManager.getDimension("ScrollBar.maximumThumbSize");
761: minimumThumbSize = UIManager.getDimension("ScrollBar.minimumThumbSize");
762: }
763:
764:
767: protected void installKeyboardActions()
768: throws NotImplementedException
769: {
770:
771: }
772:
773:
777: protected void installListeners()
778: {
779: scrollListener = createScrollListener();
780: trackListener = createTrackListener();
781: buttonListener = createArrowButtonListener();
782: modelListener = createModelListener();
783: propertyChangeListener = createPropertyChangeListener();
784:
785: scrollbar.addMouseMotionListener(trackListener);
786: scrollbar.addMouseListener(trackListener);
787:
788: incrButton.addMouseListener(buttonListener);
789: decrButton.addMouseListener(buttonListener);
790:
791: scrollbar.addPropertyChangeListener(propertyChangeListener);
792: scrollbar.getModel().addChangeListener(modelListener);
793:
794: scrollTimer.addActionListener(scrollListener);
795: }
796:
797:
804: public void installUI(JComponent c)
805: {
806: super.installUI(c);
807: if (c instanceof JScrollBar)
808: {
809: scrollbar = (JScrollBar) c;
810:
811: trackRect = new Rectangle();
812: thumbRect = new Rectangle();
813:
814: scrollTimer = new Timer(300, null);
815:
816: installDefaults();
817: installComponents();
818: configureScrollBarColors();
819: installListeners();
820:
821: calculatePreferredSize();
822: }
823: }
824:
825:
830: public void layoutContainer(Container scrollbarContainer)
831: {
832: if (scrollbarContainer instanceof JScrollBar)
833: {
834: if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
835: layoutHScrollbar((JScrollBar) scrollbarContainer);
836: else
837: layoutVScrollbar((JScrollBar) scrollbarContainer);
838: }
839: }
840:
841:
846: protected void layoutHScrollbar(JScrollBar sb)
847: {
848: Rectangle vr = new Rectangle();
849: SwingUtilities.calculateInnerArea(scrollbar, vr);
850:
851: Dimension incrDims = incrButton.getPreferredSize();
852: Dimension decrDims = decrButton.getPreferredSize();
853:
854:
855: SwingUtilities.calculateInnerArea(scrollbar, trackRect);
856: trackRect.width -= incrDims.getWidth();
857: trackRect.width -= decrDims.getWidth();
858: trackRect.x += decrDims.getWidth();
859:
860: updateThumbRect();
861:
862: decrButton.setBounds(vr.x, vr.y, decrDims.width, trackRect.height);
863: incrButton.setBounds(trackRect.x + trackRect.width, vr.y, incrDims.width,
864: trackRect.height);
865: }
866:
867:
872: protected void layoutVScrollbar(JScrollBar sb)
873: {
874: Rectangle vr = new Rectangle();
875: SwingUtilities.calculateInnerArea(scrollbar, vr);
876:
877: Dimension incrDims = incrButton.getPreferredSize();
878: Dimension decrDims = decrButton.getPreferredSize();
879:
880:
881: SwingUtilities.calculateInnerArea(scrollbar, trackRect);
882: trackRect.height -= incrDims.getHeight();
883: trackRect.height -= decrDims.getHeight();
884: trackRect.y += decrDims.getHeight();
885:
886: updateThumbRect();
887:
888: decrButton.setBounds(vr.x, vr.y, trackRect.width, decrDims.height);
889: incrButton.setBounds(vr.x, trackRect.y + trackRect.height,
890: trackRect.width, incrDims.height);
891: }
892:
893:
896: void updateThumbRect()
897: {
898: int max = scrollbar.getMaximum();
899: int min = scrollbar.getMinimum();
900: int value = scrollbar.getValue();
901: int extent = scrollbar.getVisibleAmount();
902: if (max - extent <= min)
903: {
904: if (scrollbar.getOrientation() == JScrollBar.HORIZONTAL)
905: {
906: thumbRect.x = trackRect.x;
907: thumbRect.y = trackRect.y;
908: thumbRect.width = getMinimumThumbSize().width;
909: thumbRect.height = trackRect.height;
910: }
911: else
912: {
913: thumbRect.x = trackRect.x;
914: thumbRect.y = trackRect.y;
915: thumbRect.width = trackRect.width;
916: thumbRect.height = getMinimumThumbSize().height;
917: }
918: }
919: else
920: {
921: if (scrollbar.getOrientation() == JScrollBar.HORIZONTAL)
922: {
923: thumbRect.x = trackRect.x;
924: thumbRect.width = Math.max(extent * trackRect.width / (max - min),
925: getMinimumThumbSize().width);
926: int availableWidth = trackRect.width - thumbRect.width;
927: thumbRect.x += (value - min) * availableWidth / (max - min - extent);
928: thumbRect.y = trackRect.y;
929: thumbRect.height = trackRect.height;
930: }
931: else
932: {
933: thumbRect.x = trackRect.x;
934: thumbRect.height = Math.max(extent * trackRect.height / (max - min),
935: getMinimumThumbSize().height);
936: int availableHeight = trackRect.height - thumbRect.height;
937: thumbRect.y = trackRect.y
938: + (value - min) * availableHeight / (max - min - extent);
939: thumbRect.width = trackRect.width;
940: }
941: }
942:
943: }
944:
945:
952: public Dimension minimumLayoutSize(Container scrollbarContainer)
953: {
954: return preferredLayoutSize(scrollbarContainer);
955: }
956:
957:
963: public void paint(Graphics g, JComponent c)
964: {
965: paintTrack(g, c, getTrackBounds());
966: paintThumb(g, c, getThumbBounds());
967:
968: if (trackHighlight == INCREASE_HIGHLIGHT)
969: paintIncreaseHighlight(g);
970: else if (trackHighlight == DECREASE_HIGHLIGHT)
971: paintDecreaseHighlight(g);
972: }
973:
974:
981: protected void paintDecreaseHighlight(Graphics g)
982: {
983: Color saved = g.getColor();
984:
985: g.setColor(trackHighlightColor);
986: if (scrollbar.getOrientation() == HORIZONTAL)
987: g.fillRect(trackRect.x, trackRect.y, thumbRect.x - trackRect.x,
988: trackRect.height);
989: else
990: g.fillRect(trackRect.x, trackRect.y, trackRect.width,
991: thumbRect.y - trackRect.y);
992: g.setColor(saved);
993: }
994:
995:
1002: protected void paintIncreaseHighlight(Graphics g)
1003: {
1004: Color saved = g.getColor();
1005:
1006: g.setColor(trackHighlightColor);
1007: if (scrollbar.getOrientation() == HORIZONTAL)
1008: g.fillRect(thumbRect.x + thumbRect.width, trackRect.y,
1009: trackRect.x + trackRect.width - thumbRect.x - thumbRect.width,
1010: trackRect.height);
1011: else
1012: g.fillRect(trackRect.x, thumbRect.y + thumbRect.height, trackRect.width,
1013: trackRect.y + trackRect.height - thumbRect.y
1014: - thumbRect.height);
1015: g.setColor(saved);
1016: }
1017:
1018:
1025: protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds)
1026: {
1027: g.setColor(thumbColor);
1028: g.fillRect(thumbBounds.x, thumbBounds.y, thumbBounds.width,
1029: thumbBounds.height);
1030:
1031: BasicGraphicsUtils.drawBezel(g, thumbBounds.x, thumbBounds.y,
1032: thumbBounds.width, thumbBounds.height,
1033: false, false, thumbDarkShadowColor,
1034: thumbDarkShadowColor, thumbHighlightColor,
1035: thumbHighlightColor);
1036: }
1037:
1038:
1045: protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds)
1046: {
1047: Color saved = g.getColor();
1048: g.setColor(trackColor);
1049: g.fill3DRect(trackBounds.x, trackBounds.y, trackBounds.width,
1050: trackBounds.height, false);
1051: g.setColor(saved);
1052: }
1053:
1054:
1061: public Dimension preferredLayoutSize(Container scrollbarContainer)
1062: {
1063: if (scrollbarContainer instanceof JComponent)
1064: return getPreferredSize((JComponent) scrollbarContainer);
1065: else
1066: return null;
1067: }
1068:
1069:
1074: public void removeLayoutComponent(Component child)
1075: {
1076:
1077: }
1078:
1079:
1084: protected void scrollByBlock(int direction)
1085: {
1086: scrollbar.setValue(scrollbar.getValue()
1087: + scrollbar.getBlockIncrement(direction));
1088: }
1089:
1090:
1095: protected void scrollByUnit(int direction)
1096: {
1097: scrollbar.setValue(scrollbar.getValue()
1098: + scrollbar.getUnitIncrement(direction));
1099: }
1100:
1101:
1109: protected void setThumbBounds(int x, int y, int width, int height)
1110: {
1111: thumbRect.x = x;
1112: thumbRect.y = y;
1113: thumbRect.width = width;
1114: thumbRect.height = height;
1115: }
1116:
1117:
1121: protected void uninstallComponents()
1122: {
1123: if (incrButton != null)
1124: scrollbar.remove(incrButton);
1125: if (decrButton != null)
1126: scrollbar.remove(decrButton);
1127: }
1128:
1129:
1133: protected void uninstallDefaults()
1134: {
1135: scrollbar.setForeground(null);
1136: scrollbar.setBackground(null);
1137: LookAndFeel.uninstallBorder(scrollbar);
1138: incrButton = null;
1139: decrButton = null;
1140: }
1141:
1142:
1146: protected void uninstallKeyboardActions()
1147: throws NotImplementedException
1148: {
1149:
1150: }
1151:
1152:
1155: protected void uninstallListeners()
1156: {
1157: if (scrollTimer != null)
1158: scrollTimer.removeActionListener(scrollListener);
1159:
1160: if (scrollbar != null)
1161: {
1162: scrollbar.getModel().removeChangeListener(modelListener);
1163: scrollbar.removePropertyChangeListener(propertyChangeListener);
1164: scrollbar.removeMouseListener(trackListener);
1165: scrollbar.removeMouseMotionListener(trackListener);
1166: }
1167:
1168: if (decrButton != null)
1169: decrButton.removeMouseListener(buttonListener);
1170: if (incrButton != null)
1171: incrButton.removeMouseListener(buttonListener);
1172:
1173: propertyChangeListener = null;
1174: modelListener = null;
1175: buttonListener = null;
1176: trackListener = null;
1177: scrollListener = null;
1178: }
1179:
1180:
1187: public void uninstallUI(JComponent c)
1188: {
1189: uninstallListeners();
1190: uninstallDefaults();
1191: uninstallComponents();
1192:
1193: scrollTimer = null;
1194:
1195: thumbRect = null;
1196: trackRect = null;
1197:
1198: trackColor = null;
1199: trackHighlightColor = null;
1200: thumbColor = null;
1201: thumbHighlightColor = null;
1202: thumbDarkShadowColor = null;
1203: thumbLightShadowColor = null;
1204:
1205: scrollbar = null;
1206: }
1207:
1208:
1218: int valueForYPosition(int yPos)
1219: {
1220: int min = scrollbar.getMinimum();
1221: int max = scrollbar.getMaximum();
1222: int len = trackRect.height;
1223:
1224: int value;
1225:
1226:
1227:
1228: if (len == 0)
1229: return ((max - min) / 2);
1230:
1231: value = ((yPos - trackRect.y) * (max - min) / len + min);
1232:
1233:
1234: if (value > max)
1235: value = max;
1236: else if (value < min)
1237: value = min;
1238: return value;
1239: }
1240:
1241:
1251: int valueForXPosition(int xPos)
1252: {
1253: int min = scrollbar.getMinimum();
1254: int max = scrollbar.getMaximum();
1255: int len = trackRect.width;
1256:
1257: int value;
1258:
1259:
1260:
1261: if (len == 0)
1262: return ((max - min) / 2);
1263:
1264: value = ((xPos - trackRect.x) * (max - min) / len + min);
1265:
1266:
1267: if (value > max)
1268: value = max;
1269: else if (value < min)
1270: value = min;
1271: return value;
1272: }
1273: }