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.max(20, height);
663: height = Math.min(getMaximumThumbSize().height, height);
664: }
665: else
666: {
667: height += incrButton.getPreferredSize().getHeight();
668: height += decrButton.getPreferredSize().getHeight();
669:
670: height += (scrollbar.getMaximum() - scrollbar.getMinimum());
671:
672: width = Math.max(incrButton.getPreferredSize().width,
673: decrButton.getPreferredSize().width);
674: width = Math.max(getMinimumThumbSize().width, width);
675: width = Math.max(20, width);
676: width = Math.min(getMaximumThumbSize().width, width);
677: }
678:
679: Insets insets = scrollbar.getInsets();
680:
681: height += insets.top + insets.bottom;
682: width += insets.left + insets.right;
683:
684: preferredSize = new Dimension(width, height);
685: }
686:
687:
698: public Dimension getPreferredSize(JComponent c)
699: {
700: calculatePreferredSize();
701: return preferredSize;
702: }
703:
704:
710: protected Rectangle getThumbBounds()
711: {
712: int max = scrollbar.getMaximum();
713: int min = scrollbar.getMinimum();
714: int value = scrollbar.getValue();
715: int extent = scrollbar.getVisibleAmount();
716:
717:
718: if (max == min)
719: {
720: thumbRect.x = trackRect.x;
721: thumbRect.y = trackRect.y;
722: if (scrollbar.getOrientation() == HORIZONTAL)
723: {
724: thumbRect.width = getMinimumThumbSize().width;
725: thumbRect.height = trackRect.height;
726: }
727: else
728: {
729: thumbRect.width = trackRect.width;
730: thumbRect.height = getMinimumThumbSize().height;
731: }
732: return thumbRect;
733: }
734:
735: if (scrollbar.getOrientation() == HORIZONTAL)
736: {
737: thumbRect.x = trackRect.x;
738: thumbRect.x += (value - min) * trackRect.width / (max - min);
739: thumbRect.y = trackRect.y;
740:
741: thumbRect.width = Math.max(extent * trackRect.width / (max - min),
742: getMinimumThumbSize().width);
743: thumbRect.height = trackRect.height;
744: }
745: else
746: {
747: thumbRect.x = trackRect.x;
748: thumbRect.y = trackRect.y + value * trackRect.height / (max - min);
749:
750: thumbRect.width = trackRect.width;
751: thumbRect.height = Math.max(extent * trackRect.height / (max - min),
752: getMinimumThumbSize().height);
753: }
754: return thumbRect;
755: }
756:
757:
763: protected Rectangle getTrackBounds()
764: {
765: SwingUtilities.calculateInnerArea(scrollbar, trackRect);
766:
767: if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
768: {
769: trackRect.width -= incrButton.getPreferredSize().getWidth();
770: trackRect.width -= decrButton.getPreferredSize().getWidth();
771:
772: trackRect.x += decrButton.getPreferredSize().getWidth();
773: }
774: else
775: {
776: trackRect.height -= incrButton.getPreferredSize().getHeight();
777: trackRect.height -= decrButton.getPreferredSize().getHeight();
778:
779: trackRect.y += incrButton.getPreferredSize().getHeight();
780: }
781: return trackRect;
782: }
783:
784:
788: protected void installComponents()
789: {
790: int orientation = scrollbar.getOrientation();
791: switch (orientation)
792: {
793: case (JScrollBar.HORIZONTAL):
794: incrButton = createIncreaseButton(EAST);
795: decrButton = createDecreaseButton(WEST);
796: break;
797: default:
798: incrButton = createIncreaseButton(SOUTH);
799: decrButton = createDecreaseButton(NORTH);
800: break;
801: }
802: scrollbar.add(incrButton);
803: scrollbar.add(decrButton);
804: }
805:
806:
810: protected void installDefaults()
811: {
812: UIDefaults defaults = UIManager.getLookAndFeelDefaults();
813:
814: scrollbar.setForeground(defaults.getColor("ScrollBar.foreground"));
815: scrollbar.setBackground(defaults.getColor("ScrollBar.background"));
816: scrollbar.setBorder(defaults.getBorder("ScrollBar.border"));
817: scrollbar.setOpaque(true);
818: scrollbar.setLayout(this);
819:
820: thumbColor = defaults.getColor("ScrollBar.thumb");
821: thumbDarkShadowColor = defaults.getColor("ScrollBar.thumbDarkShadow");
822: thumbHighlightColor = defaults.getColor("ScrollBar.thumbHighlight");
823: thumbLightShadowColor = defaults.getColor("ScrollBar.thumbShadow");
824:
825: maximumThumbSize = defaults.getDimension("ScrollBar.maximumThumbSize");
826: minimumThumbSize = defaults.getDimension("ScrollBar.minimumThumbSize");
827: }
828:
829:
832: protected void installKeyboardActions()
833: {
834:
835: }
836:
837:
841: protected void installListeners()
842: {
843: scrollListener = createScrollListener();
844: trackListener = createTrackListener();
845: buttonListener = createArrowButtonListener();
846: modelListener = createModelListener();
847: propertyChangeListener = createPropertyChangeListener();
848:
849: scrollbar.addMouseMotionListener(trackListener);
850: scrollbar.addMouseListener(trackListener);
851:
852: incrButton.addMouseListener(buttonListener);
853: decrButton.addMouseListener(buttonListener);
854:
855: scrollbar.addPropertyChangeListener(propertyChangeListener);
856: scrollbar.getModel().addChangeListener(modelListener);
857:
858: scrollTimer.addActionListener(scrollListener);
859: }
860:
861:
868: public void installUI(JComponent c)
869: {
870: super.installUI(c);
871: if (c instanceof JScrollBar)
872: {
873: scrollbar = (JScrollBar) c;
874:
875: trackRect = new Rectangle();
876: thumbRect = new Rectangle();
877:
878: scrollTimer = new Timer(200, null);
879: scrollTimer.setRepeats(true);
880:
881: installComponents();
882: installDefaults();
883: configureScrollBarColors();
884: installListeners();
885:
886: calculatePreferredSize();
887: }
888: }
889:
890:
895: public void layoutContainer(Container scrollbarContainer)
896: {
897: if (scrollbarContainer instanceof JScrollBar)
898: {
899: if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
900: layoutHScrollbar((JScrollBar) scrollbarContainer);
901: else
902: layoutVScrollbar((JScrollBar) scrollbarContainer);
903: }
904: }
905:
906:
911: protected void layoutHScrollbar(JScrollBar sb)
912: {
913:
914: Rectangle vr = new Rectangle();
915: SwingUtilities.calculateInnerArea(scrollbar, vr);
916:
917:
918: getTrackBounds();
919: getThumbBounds();
920:
921: Dimension incrDims = incrButton.getPreferredSize();
922: Dimension decrDims = decrButton.getPreferredSize();
923:
924: decrButton.setBounds(vr.x, vr.y, decrDims.width, trackRect.height);
925: incrButton.setBounds(trackRect.x + trackRect.width, vr.y, incrDims.width,
926: trackRect.height);
927: }
928:
929:
934: protected void layoutVScrollbar(JScrollBar sb)
935: {
936: Rectangle vr = new Rectangle();
937: SwingUtilities.calculateInnerArea(scrollbar, vr);
938:
939:
940: getTrackBounds();
941: getThumbBounds();
942:
943: Dimension incrDims = incrButton.getPreferredSize();
944: Dimension decrDims = decrButton.getPreferredSize();
945:
946: decrButton.setBounds(vr.x, vr.y, trackRect.width, decrDims.height);
947: incrButton.setBounds(vr.x, trackRect.y + trackRect.height,
948: trackRect.width, incrDims.height);
949: }
950:
951:
958: public Dimension minimumLayoutSize(Container scrollbarContainer)
959: {
960: return preferredLayoutSize(scrollbarContainer);
961: }
962:
963:
969: public void paint(Graphics g, JComponent c)
970: {
971: paintTrack(g, c, getTrackBounds());
972: paintThumb(g, c, getThumbBounds());
973:
974: if (trackHighlight == INCREASE_HIGHLIGHT)
975: paintIncreaseHighlight(g);
976: else if (trackHighlight == DECREASE_HIGHLIGHT)
977: paintDecreaseHighlight(g);
978: }
979:
980:
987: protected void paintDecreaseHighlight(Graphics g)
988: {
989: Color saved = g.getColor();
990:
991: g.setColor(trackHighlightColor);
992: if (scrollbar.getOrientation() == HORIZONTAL)
993: g.fillRect(trackRect.x, trackRect.y, thumbRect.x - trackRect.x,
994: trackRect.height);
995: else
996: g.fillRect(trackRect.x, trackRect.y, trackRect.width,
997: thumbRect.y - trackRect.y);
998: g.setColor(saved);
999: }
1000:
1001:
1008: protected void paintIncreaseHighlight(Graphics g)
1009: {
1010: Color saved = g.getColor();
1011:
1012: g.setColor(trackHighlightColor);
1013: if (scrollbar.getOrientation() == HORIZONTAL)
1014: g.fillRect(thumbRect.x + thumbRect.width, trackRect.y,
1015: trackRect.x + trackRect.width - thumbRect.x - thumbRect.width,
1016: trackRect.height);
1017: else
1018: g.fillRect(trackRect.x, thumbRect.y + thumbRect.height, trackRect.width,
1019: trackRect.y + trackRect.height - thumbRect.y
1020: - thumbRect.height);
1021: g.setColor(saved);
1022: }
1023:
1024:
1031: protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds)
1032: {
1033: g.setColor(thumbColor);
1034: g.fillRect(thumbBounds.x, thumbBounds.y, thumbBounds.width,
1035: thumbBounds.height);
1036:
1037: BasicGraphicsUtils.drawBezel(g, thumbBounds.x, thumbBounds.y,
1038: thumbBounds.width, thumbBounds.height,
1039: false, false, thumbDarkShadowColor,
1040: thumbDarkShadowColor, thumbHighlightColor,
1041: thumbHighlightColor);
1042: }
1043:
1044:
1051: protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds)
1052: {
1053: Color saved = g.getColor();
1054: g.setColor(trackColor);
1055: g.fill3DRect(trackBounds.x, trackBounds.y, trackBounds.width,
1056: trackBounds.height, false);
1057: g.setColor(saved);
1058: }
1059:
1060:
1067: public Dimension preferredLayoutSize(Container scrollbarContainer)
1068: {
1069: if (scrollbarContainer instanceof JComponent)
1070: return getPreferredSize((JComponent) scrollbarContainer);
1071: else
1072: return null;
1073: }
1074:
1075:
1080: public void removeLayoutComponent(Component child)
1081: {
1082:
1083: }
1084:
1085:
1090: protected void scrollByBlock(int direction)
1091: {
1092: scrollbar.setValue(scrollbar.getValue()
1093: + scrollbar.getBlockIncrement(direction));
1094: }
1095:
1096:
1101: protected void scrollByUnit(int direction)
1102: {
1103: scrollbar.setValue(scrollbar.getValue()
1104: + scrollbar.getUnitIncrement(direction));
1105: }
1106:
1107:
1115: protected void setThumbBounds(int x, int y, int width, int height)
1116: {
1117: thumbRect.x = x;
1118: thumbRect.y = y;
1119: thumbRect.width = width;
1120: thumbRect.height = height;
1121: }
1122:
1123:
1127: protected void uninstallComponents()
1128: {
1129: scrollbar.remove(incrButton);
1130: scrollbar.remove(decrButton);
1131: incrButton = null;
1132: decrButton = null;
1133: }
1134:
1135:
1139: protected void uninstallDefaults()
1140: {
1141: scrollbar.setForeground(null);
1142: scrollbar.setBackground(null);
1143: scrollbar.setBorder(null);
1144: }
1145:
1146:
1150: protected void uninstallKeyboardActions()
1151: {
1152:
1153: }
1154:
1155:
1158: protected void uninstallListeners()
1159: {
1160: scrollTimer.removeActionListener(scrollListener);
1161:
1162: scrollbar.getModel().removeChangeListener(modelListener);
1163: scrollbar.removePropertyChangeListener(propertyChangeListener);
1164:
1165: decrButton.removeMouseListener(buttonListener);
1166: incrButton.removeMouseListener(buttonListener);
1167:
1168: scrollbar.removeMouseListener(trackListener);
1169: scrollbar.removeMouseMotionListener(trackListener);
1170:
1171: propertyChangeListener = null;
1172: modelListener = null;
1173: buttonListener = null;
1174: trackListener = null;
1175: scrollListener = null;
1176: }
1177:
1178:
1185: public void uninstallUI(JComponent c)
1186: {
1187: uninstallDefaults();
1188: uninstallListeners();
1189: uninstallComponents();
1190:
1191: scrollTimer = null;
1192:
1193: thumbRect = null;
1194: trackRect = null;
1195:
1196: trackColor = null;
1197: trackHighlightColor = null;
1198: thumbColor = null;
1199: thumbHighlightColor = null;
1200: thumbDarkShadowColor = null;
1201: thumbLightShadowColor = null;
1202:
1203: scrollbar = null;
1204: }
1205:
1206:
1216: int valueForYPosition(int yPos)
1217: {
1218: int min = scrollbar.getMinimum();
1219: int max = scrollbar.getMaximum();
1220: int len = trackRect.height;
1221:
1222: int value;
1223:
1224:
1225:
1226: if (len == 0)
1227: return ((max - min) / 2);
1228:
1229: value = ((yPos - trackRect.y) * (max - min) / len + min);
1230:
1231:
1232: if (value > max)
1233: value = max;
1234: else if (value < min)
1235: value = min;
1236: return value;
1237: }
1238:
1239:
1249: int valueForXPosition(int xPos)
1250: {
1251: int min = scrollbar.getMinimum();
1252: int max = scrollbar.getMaximum();
1253: int len = trackRect.width;
1254:
1255: int value;
1256:
1257:
1258:
1259: if (len == 0)
1260: return ((max - min) / 2);
1261:
1262: value = ((xPos - trackRect.x) * (max - min) / len + min);
1263:
1264:
1265: if (value > max)
1266: value = max;
1267: else if (value < min)
1268: value = min;
1269: return value;
1270: }
1271: }