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:
84:
90: public void mousePressed(MouseEvent e)
91: {
92: scrollTimer.stop();
93: scrollListener.setScrollByBlock(false);
94: if (e.getSource() == incrButton)
95: scrollListener.setDirection(POSITIVE_SCROLL);
96: else if (e.getSource() == decrButton)
97: scrollListener.setDirection(NEGATIVE_SCROLL);
98: scrollTimer.setDelay(100);
99: scrollTimer.start();
100: }
101:
102:
107: public void mouseReleased(MouseEvent e)
108: {
109: scrollTimer.stop();
110: scrollTimer.setDelay(300);
111: if (e.getSource() == incrButton)
112: scrollByUnit(POSITIVE_SCROLL);
113: else if (e.getSource() == decrButton)
114: scrollByUnit(NEGATIVE_SCROLL);
115: }
116: }
117:
118:
121: protected class ModelListener implements ChangeListener
122: {
123:
128: public void stateChanged(ChangeEvent e)
129: {
130: calculatePreferredSize();
131: updateThumbRect();
132: scrollbar.repaint();
133: }
134: }
135:
136:
139: public class PropertyChangeHandler implements PropertyChangeListener
140: {
141:
146: public void propertyChange(PropertyChangeEvent e)
147: {
148: if (e.getPropertyName().equals("model"))
149: {
150: ((BoundedRangeModel) e.getOldValue()).removeChangeListener(modelListener);
151: scrollbar.getModel().addChangeListener(modelListener);
152: updateThumbRect();
153: }
154: else if (e.getPropertyName().equals("orientation"))
155: {
156: uninstallListeners();
157: uninstallComponents();
158: uninstallDefaults();
159: installDefaults();
160: installComponents();
161: installListeners();
162: }
163: else if (e.getPropertyName().equals("enabled"))
164: {
165: Boolean b = (Boolean) e.getNewValue();
166: if (incrButton != null)
167: incrButton.setEnabled(b.booleanValue());
168: if (decrButton != null)
169: decrButton.setEnabled(b.booleanValue());
170: }
171: }
172: }
173:
174:
178: protected class ScrollListener implements ActionListener
179: {
180:
181: private transient int direction;
182:
183:
184: private transient boolean block;
185:
186:
190: public ScrollListener()
191: {
192: direction = POSITIVE_SCROLL;
193: block = true;
194: }
195:
196:
203: public ScrollListener(int dir, boolean block)
204: {
205: direction = dir;
206: this.block = block;
207: }
208:
209:
214: public void setDirection(int direction)
215: {
216: this.direction = direction;
217: }
218:
219:
224: public void setScrollByBlock(boolean block)
225: {
226: this.block = block;
227: }
228:
229:
234: public void actionPerformed(ActionEvent e)
235: {
236: if (block)
237: {
238:
239:
240:
241: if (!trackListener.shouldScroll(direction))
242: {
243: trackHighlight = NO_HIGHLIGHT;
244: scrollbar.repaint();
245: return;
246: }
247: scrollByBlock(direction);
248: }
249: else
250: scrollByUnit(direction);
251: }
252: }
253:
254:
257: protected class TrackListener extends MouseAdapter
258: implements MouseMotionListener
259: {
260:
261: protected int currentMouseX;
262:
263:
264: protected int currentMouseY;
265:
266:
270: protected int offset;
271:
272:
277: public void mouseDragged(MouseEvent e)
278: {
279: currentMouseX = e.getX();
280: currentMouseY = e.getY();
281: if (scrollbar.getValueIsAdjusting())
282: {
283: int value;
284: if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
285: value = valueForXPosition(currentMouseX) - offset;
286: else
287: value = valueForYPosition(currentMouseY) - offset;
288:
289: scrollbar.setValue(value);
290: }
291: }
292:
293:
298: public void mouseMoved(MouseEvent e)
299: {
300:
301:
302: }
303:
304:
310: public void mousePressed(MouseEvent e)
311: {
312: currentMouseX = e.getX();
313: currentMouseY = e.getY();
314:
315: int value;
316: if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
317: value = valueForXPosition(currentMouseX);
318: else
319: value = valueForYPosition(currentMouseY);
320:
321: if (! thumbRect.contains(e.getPoint()))
322: {
323: scrollTimer.stop();
324: scrollListener.setScrollByBlock(true);
325: if (value > scrollbar.getValue())
326: {
327: trackHighlight = INCREASE_HIGHLIGHT;
328: scrollListener.setDirection(POSITIVE_SCROLL);
329: }
330: else
331: {
332: trackHighlight = DECREASE_HIGHLIGHT;
333: scrollListener.setDirection(NEGATIVE_SCROLL);
334: }
335: scrollTimer.setDelay(100);
336: scrollTimer.start();
337: }
338: else
339: {
340:
341:
342:
343:
344:
345:
346:
347: scrollListener.setScrollByBlock(false);
348: scrollbar.setValueIsAdjusting(true);
349: offset = value - scrollbar.getValue();
350: }
351: scrollbar.repaint();
352: }
353:
354:
360: public void mouseReleased(MouseEvent e)
361: {
362: scrollTimer.stop();
363: scrollTimer.setDelay(300);
364: currentMouseX = e.getX();
365: currentMouseY = e.getY();
366:
367: if (shouldScroll(POSITIVE_SCROLL))
368: scrollByBlock(POSITIVE_SCROLL);
369: else if (shouldScroll(NEGATIVE_SCROLL))
370: scrollByBlock(NEGATIVE_SCROLL);
371:
372: trackHighlight = NO_HIGHLIGHT;
373: scrollListener.setScrollByBlock(false);
374: scrollbar.setValueIsAdjusting(true);
375: scrollbar.repaint();
376: }
377:
378:
386: public boolean shouldScroll(int direction)
387: {
388: int value;
389: if (scrollbar.getOrientation() == HORIZONTAL)
390: value = valueForXPosition(currentMouseX);
391: else
392: value = valueForYPosition(currentMouseY);
393:
394: if (thumbRect.contains(currentMouseX, currentMouseY))
395: return false;
396:
397: if (direction == POSITIVE_SCROLL)
398: return (value > scrollbar.getValue());
399: else
400: return (value < scrollbar.getValue());
401: }
402: }
403:
404:
405: protected ArrowButtonListener buttonListener;
406:
407:
408: protected ModelListener modelListener;
409:
410:
411: protected PropertyChangeListener propertyChangeListener;
412:
413:
414: protected ScrollListener scrollListener;
415:
416:
417: protected TrackListener trackListener;
418:
419:
420: protected JButton decrButton;
421:
422:
423: protected JButton incrButton;
424:
425:
426: protected Dimension maximumThumbSize;
427:
428:
429: protected Dimension minimumThumbSize;
430:
431:
432: protected Color thumbColor;
433:
434:
435: protected Color thumbDarkShadowColor;
436:
437:
438: protected Color thumbHighlightColor;
439:
440:
441: protected Color thumbLightShadowColor;
442:
443:
444: protected Color trackHighlightColor;
445:
446:
447: protected Color trackColor;
448:
449:
450: protected Rectangle trackRect;
451:
452:
453: protected Rectangle thumbRect;
454:
455:
456: protected static final int DECREASE_HIGHLIGHT = 1;
457:
458:
459: protected static final int INCREASE_HIGHLIGHT = 2;
460:
461:
462: protected static final int NO_HIGHLIGHT = 0;
463:
464:
465: private static final int POSITIVE_SCROLL = 1;
466:
467:
468: private static final int NEGATIVE_SCROLL = -1;
469:
470:
471: private transient Dimension preferredSize;
472:
473:
474: protected int trackHighlight;
475:
476:
477: protected boolean isDragging;
478:
479:
480: protected Timer scrollTimer;
481:
482:
483: protected JScrollBar scrollbar;
484:
485:
491: public void addLayoutComponent(String name, Component child)
492: {
493:
494:
495: }
496:
497:
501: protected void configureScrollBarColors()
502: {
503: trackColor = UIManager.getColor("ScrollBar.track");
504: trackHighlightColor = UIManager.getColor("ScrollBar.trackHighlight");
505: thumbColor = UIManager.getColor("ScrollBar.thumb");
506: thumbHighlightColor = UIManager.getColor("ScrollBar.thumbHighlight");
507: thumbDarkShadowColor = UIManager.getColor("ScrollBar.thumbDarkShadow");
508: thumbLightShadowColor = UIManager.getColor("ScrollBar.thumbShadow");
509: }
510:
511:
516: protected ArrowButtonListener createArrowButtonListener()
517: {
518: return new ArrowButtonListener();
519: }
520:
521:
529: protected JButton createIncreaseButton(int orientation)
530: {
531: return new BasicArrowButton(orientation);
532: }
533:
534:
542: protected JButton createDecreaseButton(int orientation)
543: {
544: return new BasicArrowButton(orientation);
545: }
546:
547:
552: protected ModelListener createModelListener()
553: {
554: return new ModelListener();
555: }
556:
557:
562: protected PropertyChangeListener createPropertyChangeListener()
563: {
564: return new PropertyChangeHandler();
565: }
566:
567:
572: protected ScrollListener createScrollListener()
573: {
574: return new ScrollListener();
575: }
576:
577:
582: protected TrackListener createTrackListener()
583: {
584: return new TrackListener();
585: }
586:
587:
594: public static ComponentUI createUI(JComponent c)
595: {
596: return new BasicScrollBarUI();
597: }
598:
599:
606: public Dimension getMaximumSize(JComponent c)
607: {
608: return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
609: }
610:
611:
616: protected Dimension getMaximumThumbSize()
617: {
618: return maximumThumbSize;
619: }
620:
621:
628: public Dimension getMinimumSize(JComponent c)
629: {
630: return getPreferredSize(c);
631: }
632:
633:
638: protected Dimension getMinimumThumbSize()
639: {
640: return minimumThumbSize;
641: }
642:
643:
648: void calculatePreferredSize()
649: {
650: int height;
651: int width;
652: height = width = 0;
653:
654: if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
655: {
656: width += incrButton.getPreferredSize().getWidth();
657: width += decrButton.getPreferredSize().getWidth();
658:
659: width += (scrollbar.getMaximum() - scrollbar.getMinimum());
660: height = UIManager.getInt("ScrollBar.width");
661: }
662: else
663: {
664: height += incrButton.getPreferredSize().getHeight();
665: height += decrButton.getPreferredSize().getHeight();
666:
667: height += (scrollbar.getMaximum() - scrollbar.getMinimum());
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: if (incrButton != null)
725: scrollbar.add(incrButton);
726: if (decrButton != null)
727: scrollbar.add(decrButton);
728: }
729:
730:
734: protected void installDefaults()
735: {
736: int orientation = scrollbar.getOrientation();
737: switch (orientation)
738: {
739: case (JScrollBar.HORIZONTAL):
740: incrButton = createIncreaseButton(EAST);
741: decrButton = createDecreaseButton(WEST);
742: break;
743: default:
744: incrButton = createIncreaseButton(SOUTH);
745: decrButton = createDecreaseButton(NORTH);
746: break;
747: }
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: {
769:
770: }
771:
772:
776: protected void installListeners()
777: {
778: scrollListener = createScrollListener();
779: trackListener = createTrackListener();
780: buttonListener = createArrowButtonListener();
781: modelListener = createModelListener();
782: propertyChangeListener = createPropertyChangeListener();
783:
784: scrollbar.addMouseMotionListener(trackListener);
785: scrollbar.addMouseListener(trackListener);
786:
787: incrButton.addMouseListener(buttonListener);
788: decrButton.addMouseListener(buttonListener);
789:
790: scrollbar.addPropertyChangeListener(propertyChangeListener);
791: scrollbar.getModel().addChangeListener(modelListener);
792:
793: scrollTimer.addActionListener(scrollListener);
794: }
795:
796:
803: public void installUI(JComponent c)
804: {
805: super.installUI(c);
806: if (c instanceof JScrollBar)
807: {
808: scrollbar = (JScrollBar) c;
809:
810: trackRect = new Rectangle();
811: thumbRect = new Rectangle();
812:
813: scrollTimer = new Timer(300, null);
814:
815: installDefaults();
816: installComponents();
817: configureScrollBarColors();
818: installListeners();
819:
820: calculatePreferredSize();
821: }
822: }
823:
824:
829: public void layoutContainer(Container scrollbarContainer)
830: {
831: if (scrollbarContainer instanceof JScrollBar)
832: {
833: if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
834: layoutHScrollbar((JScrollBar) scrollbarContainer);
835: else
836: layoutVScrollbar((JScrollBar) scrollbarContainer);
837: }
838: }
839:
840:
845: protected void layoutHScrollbar(JScrollBar sb)
846: {
847: Rectangle vr = new Rectangle();
848: SwingUtilities.calculateInnerArea(scrollbar, vr);
849:
850: Dimension incrDims = incrButton.getPreferredSize();
851: Dimension decrDims = decrButton.getPreferredSize();
852:
853:
854: SwingUtilities.calculateInnerArea(scrollbar, trackRect);
855: trackRect.width -= incrDims.getWidth();
856: trackRect.width -= decrDims.getWidth();
857: trackRect.x += decrDims.getWidth();
858:
859: updateThumbRect();
860:
861: decrButton.setBounds(vr.x, vr.y, decrDims.width, trackRect.height);
862: incrButton.setBounds(trackRect.x + trackRect.width, vr.y, incrDims.width,
863: trackRect.height);
864: }
865:
866:
871: protected void layoutVScrollbar(JScrollBar sb)
872: {
873: Rectangle vr = new Rectangle();
874: SwingUtilities.calculateInnerArea(scrollbar, vr);
875:
876: Dimension incrDims = incrButton.getPreferredSize();
877: Dimension decrDims = decrButton.getPreferredSize();
878:
879:
880: SwingUtilities.calculateInnerArea(scrollbar, trackRect);
881: trackRect.height -= incrDims.getHeight();
882: trackRect.height -= decrDims.getHeight();
883: trackRect.y += decrDims.getHeight();
884:
885: updateThumbRect();
886:
887: decrButton.setBounds(vr.x, vr.y, trackRect.width, decrDims.height);
888: incrButton.setBounds(vr.x, trackRect.y + trackRect.height,
889: trackRect.width, incrDims.height);
890: }
891:
892:
895: void updateThumbRect()
896: {
897: int max = scrollbar.getMaximum();
898: int min = scrollbar.getMinimum();
899: int value = scrollbar.getValue();
900: int extent = scrollbar.getVisibleAmount();
901: if (max - extent <= min)
902: {
903: if (scrollbar.getOrientation() == JScrollBar.HORIZONTAL)
904: {
905: thumbRect.x = trackRect.x;
906: thumbRect.y = trackRect.y;
907: thumbRect.width = getMinimumThumbSize().width;
908: thumbRect.height = trackRect.height;
909: }
910: else
911: {
912: thumbRect.x = trackRect.x;
913: thumbRect.y = trackRect.y;
914: thumbRect.width = trackRect.width;
915: thumbRect.height = getMinimumThumbSize().height;
916: }
917: }
918: else
919: {
920: if (scrollbar.getOrientation() == JScrollBar.HORIZONTAL)
921: {
922: thumbRect.x = trackRect.x;
923: thumbRect.width = Math.max(extent * trackRect.width / (max - min),
924: getMinimumThumbSize().width);
925: int availableWidth = trackRect.width - thumbRect.width;
926: thumbRect.x += (value - min) * availableWidth / (max - min - extent);
927: thumbRect.y = trackRect.y;
928: thumbRect.height = trackRect.height;
929: }
930: else
931: {
932: thumbRect.x = trackRect.x;
933: thumbRect.height = Math.max(extent * trackRect.height / (max - min),
934: getMinimumThumbSize().height);
935: int availableHeight = trackRect.height - thumbRect.height;
936: thumbRect.y = trackRect.y
937: + (value - min) * availableHeight / (max - min - extent);
938: thumbRect.width = trackRect.width;
939: }
940: }
941:
942: }
943:
944:
951: public Dimension minimumLayoutSize(Container scrollbarContainer)
952: {
953: return preferredLayoutSize(scrollbarContainer);
954: }
955:
956:
962: public void paint(Graphics g, JComponent c)
963: {
964: paintTrack(g, c, getTrackBounds());
965: paintThumb(g, c, getThumbBounds());
966:
967: if (trackHighlight == INCREASE_HIGHLIGHT)
968: paintIncreaseHighlight(g);
969: else if (trackHighlight == DECREASE_HIGHLIGHT)
970: paintDecreaseHighlight(g);
971: }
972:
973:
980: protected void paintDecreaseHighlight(Graphics g)
981: {
982: Color saved = g.getColor();
983:
984: g.setColor(trackHighlightColor);
985: if (scrollbar.getOrientation() == HORIZONTAL)
986: g.fillRect(trackRect.x, trackRect.y, thumbRect.x - trackRect.x,
987: trackRect.height);
988: else
989: g.fillRect(trackRect.x, trackRect.y, trackRect.width,
990: thumbRect.y - trackRect.y);
991: g.setColor(saved);
992: }
993:
994:
1001: protected void paintIncreaseHighlight(Graphics g)
1002: {
1003: Color saved = g.getColor();
1004:
1005: g.setColor(trackHighlightColor);
1006: if (scrollbar.getOrientation() == HORIZONTAL)
1007: g.fillRect(thumbRect.x + thumbRect.width, trackRect.y,
1008: trackRect.x + trackRect.width - thumbRect.x - thumbRect.width,
1009: trackRect.height);
1010: else
1011: g.fillRect(trackRect.x, thumbRect.y + thumbRect.height, trackRect.width,
1012: trackRect.y + trackRect.height - thumbRect.y
1013: - thumbRect.height);
1014: g.setColor(saved);
1015: }
1016:
1017:
1024: protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds)
1025: {
1026: g.setColor(thumbColor);
1027: g.fillRect(thumbBounds.x, thumbBounds.y, thumbBounds.width,
1028: thumbBounds.height);
1029:
1030: BasicGraphicsUtils.drawBezel(g, thumbBounds.x, thumbBounds.y,
1031: thumbBounds.width, thumbBounds.height,
1032: false, false, thumbDarkShadowColor,
1033: thumbDarkShadowColor, thumbHighlightColor,
1034: thumbHighlightColor);
1035: }
1036:
1037:
1044: protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds)
1045: {
1046: Color saved = g.getColor();
1047: g.setColor(trackColor);
1048: g.fill3DRect(trackBounds.x, trackBounds.y, trackBounds.width,
1049: trackBounds.height, false);
1050: g.setColor(saved);
1051: }
1052:
1053:
1060: public Dimension preferredLayoutSize(Container scrollbarContainer)
1061: {
1062: if (scrollbarContainer instanceof JComponent)
1063: return getPreferredSize((JComponent) scrollbarContainer);
1064: else
1065: return null;
1066: }
1067:
1068:
1073: public void removeLayoutComponent(Component child)
1074: {
1075:
1076: }
1077:
1078:
1083: protected void scrollByBlock(int direction)
1084: {
1085: scrollbar.setValue(scrollbar.getValue()
1086: + scrollbar.getBlockIncrement(direction));
1087: }
1088:
1089:
1094: protected void scrollByUnit(int direction)
1095: {
1096: scrollbar.setValue(scrollbar.getValue()
1097: + scrollbar.getUnitIncrement(direction));
1098: }
1099:
1100:
1108: protected void setThumbBounds(int x, int y, int width, int height)
1109: {
1110: thumbRect.x = x;
1111: thumbRect.y = y;
1112: thumbRect.width = width;
1113: thumbRect.height = height;
1114: }
1115:
1116:
1120: protected void uninstallComponents()
1121: {
1122: if (incrButton != null)
1123: scrollbar.remove(incrButton);
1124: if (decrButton != null)
1125: scrollbar.remove(decrButton);
1126: }
1127:
1128:
1132: protected void uninstallDefaults()
1133: {
1134: scrollbar.setForeground(null);
1135: scrollbar.setBackground(null);
1136: LookAndFeel.uninstallBorder(scrollbar);
1137: incrButton = null;
1138: decrButton = null;
1139: }
1140:
1141:
1145: protected void uninstallKeyboardActions()
1146: {
1147:
1148: }
1149:
1150:
1153: protected void uninstallListeners()
1154: {
1155: if (scrollTimer != null)
1156: scrollTimer.removeActionListener(scrollListener);
1157:
1158: if (scrollbar != null)
1159: {
1160: scrollbar.getModel().removeChangeListener(modelListener);
1161: scrollbar.removePropertyChangeListener(propertyChangeListener);
1162: scrollbar.removeMouseListener(trackListener);
1163: scrollbar.removeMouseMotionListener(trackListener);
1164: }
1165:
1166: if (decrButton != null)
1167: decrButton.removeMouseListener(buttonListener);
1168: if (incrButton != null)
1169: incrButton.removeMouseListener(buttonListener);
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: uninstallListeners();
1188: uninstallDefaults();
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: }