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: import ;
57: import ;
58: import ;
59: import ;
60: import ;
61: import ;
62:
63: import ;
64: import ;
65: import ;
66: import ;
67: import ;
68: import ;
69: import ;
70: import ;
71: import ;
72: import ;
73: import ;
74: import ;
75: import ;
76: import ;
77: import ;
78: import ;
79: import ;
80:
81:
141: public class BasicSliderUI extends SliderUI
142: {
143:
150: public class ChangeHandler implements ChangeListener
151: {
152:
159: public void stateChanged(ChangeEvent e)
160: {
161:
162:
163:
164: calculateThumbLocation();
165: slider.repaint();
166: }
167: }
168:
169:
176: public class ComponentHandler extends ComponentAdapter
177: {
178:
185: public void componentResized(ComponentEvent e)
186: {
187: calculateGeometry();
188:
189: slider.revalidate();
190: slider.repaint();
191: }
192: }
193:
194:
201: public class FocusHandler implements FocusListener
202: {
203:
209: public void focusGained(FocusEvent e)
210: {
211: slider.repaint();
212: hasFocus = true;
213: }
214:
215:
221: public void focusLost(FocusEvent e)
222: {
223: slider.repaint();
224: hasFocus = false;
225: }
226: }
227:
228:
232: public class PropertyChangeHandler implements PropertyChangeListener
233: {
234:
240: public void propertyChange(PropertyChangeEvent e)
241: {
242:
243: if (e.getPropertyName().equals("orientation"))
244: recalculateIfOrientationChanged();
245: else if (e.getPropertyName().equals("model"))
246: {
247: BoundedRangeModel oldModel = (BoundedRangeModel) e.getOldValue();
248: oldModel.removeChangeListener(changeListener);
249: slider.getModel().addChangeListener(changeListener);
250: calculateThumbLocation();
251: }
252: else if (e.getPropertyName().equals("paintTicks"))
253: calculateGeometry();
254:
255:
256:
257:
258:
259:
260:
261: slider.repaint();
262: }
263: }
264:
265:
274: public class ScrollListener implements ActionListener
275: {
276:
277: private transient int direction;
278:
279:
280: private transient boolean block;
281:
282:
285: public ScrollListener()
286: {
287: direction = POSITIVE_SCROLL;
288: block = false;
289: }
290:
291:
297: public ScrollListener(int dir, boolean block)
298: {
299: direction = dir;
300: this.block = block;
301: }
302:
303:
310: public void actionPerformed(ActionEvent e)
311: {
312: if (! trackListener.shouldScroll(direction))
313: {
314: scrollTimer.stop();
315: return;
316: }
317:
318: if (block)
319: scrollByBlock(direction);
320: else
321: scrollByUnit(direction);
322: }
323:
324:
329: public void setDirection(int direction)
330: {
331: this.direction = direction;
332: }
333:
334:
339: public void setScrollByBlock(boolean block)
340: {
341: this.block = block;
342: }
343: }
344:
345:
352: public class TrackListener extends MouseInputAdapter
353: {
354:
355: protected int currentMouseX;
356:
357:
358: protected int currentMouseY;
359:
360:
363: protected int offset;
364:
365:
372: public void mouseDragged(MouseEvent e)
373: {
374: if (slider.isEnabled())
375: {
376: currentMouseX = e.getX();
377: currentMouseY = e.getY();
378: if (slider.getValueIsAdjusting())
379: {
380: int value;
381: if (slider.getOrientation() == JSlider.HORIZONTAL)
382: value = valueForXPosition(currentMouseX) - offset;
383: else
384: value = valueForYPosition(currentMouseY) - offset;
385:
386: slider.setValue(value);
387: }
388: }
389: }
390:
391:
397: public void mouseMoved(MouseEvent e)
398: {
399:
400: }
401:
402:
410: public void mousePressed(MouseEvent e)
411: {
412: if (slider.isEnabled())
413: {
414: currentMouseX = e.getX();
415: currentMouseY = e.getY();
416:
417: int value;
418: if (slider.getOrientation() == JSlider.HORIZONTAL)
419: value = valueForXPosition(currentMouseX);
420: else
421: value = valueForYPosition(currentMouseY);
422:
423: if (slider.getSnapToTicks())
424: value = findClosestTick(value);
425:
426:
427:
428: if (! thumbRect.contains(e.getPoint()))
429: {
430:
431:
432: if (value > slider.getValue())
433: scrollDueToClickInTrack(POSITIVE_SCROLL);
434: else
435: scrollDueToClickInTrack(NEGATIVE_SCROLL);
436: }
437: else
438: {
439: slider.setValueIsAdjusting(true);
440: offset = value - slider.getValue();
441: }
442: }
443: }
444:
445:
451: public void mouseReleased(MouseEvent e)
452: {
453: if (slider.isEnabled())
454: {
455: currentMouseX = e.getX();
456: currentMouseY = e.getY();
457:
458: if (slider.getValueIsAdjusting())
459: {
460: slider.setValueIsAdjusting(false);
461: if (slider.getSnapToTicks())
462: slider.setValue(findClosestTick(slider.getValue()));
463: }
464: if (scrollTimer != null)
465: scrollTimer.stop();
466: }
467: }
468:
469:
476: public boolean shouldScroll(int direction)
477: {
478: int value;
479: if (slider.getOrientation() == JSlider.HORIZONTAL)
480: value = valueForXPosition(currentMouseX);
481: else
482: value = valueForYPosition(currentMouseY);
483:
484: if (direction == POSITIVE_SCROLL)
485: return value > slider.getValue();
486: else
487: return value < slider.getValue();
488: }
489: }
490:
491:
494: public class ActionScroller extends AbstractAction
495: {
496:
503: public ActionScroller(JSlider slider, int dir, boolean block)
504: {
505:
506: }
507:
508:
513: public void actionPerformed(ActionEvent event)
514: {
515:
516: }
517: }
518:
519:
520: protected ChangeListener changeListener;
521:
522:
523: protected PropertyChangeListener propertyChangeListener;
524:
525:
526: protected ScrollListener scrollListener;
527:
528:
529: protected ComponentListener componentListener;
530:
531:
532: protected FocusListener focusListener;
533:
534:
535: protected TrackListener trackListener;
536:
537:
538: protected Insets focusInsets;
539:
540:
541: protected Insets insetCache;
542:
543:
544: protected Rectangle contentRect;
545:
546:
547: protected Rectangle focusRect;
548:
549:
550: protected Rectangle thumbRect;
551:
552:
553: protected Rectangle tickRect;
554:
555:
556: protected Rectangle labelRect;
557:
558:
559: protected Rectangle trackRect;
560:
561:
562: public static final int MAX_SCROLL = 2;
563:
564:
565: public static final int MIN_SCROLL = -2;
566:
567:
568: public static final int NEGATIVE_SCROLL = -1;
569:
570:
571: public static final int POSITIVE_SCROLL = 1;
572:
573:
574: protected int trackBuffer;
575:
576:
577: protected boolean leftToRightCache;
578:
579:
580: protected Timer scrollTimer;
581:
582:
583: protected JSlider slider;
584:
585:
586: private transient Color shadowColor;
587:
588:
589: private transient Color highlightColor;
590:
591:
592: private transient Color focusColor;
593:
594:
595: private transient boolean hasFocus;
596:
597:
602: public BasicSliderUI(JSlider b)
603: {
604: super();
605: }
606:
607:
613: protected Color getShadowColor()
614: {
615: return shadowColor;
616: }
617:
618:
624: protected Color getHighlightColor()
625: {
626: return highlightColor;
627: }
628:
629:
636: protected Color getFocusColor()
637: {
638: return focusColor;
639: }
640:
641:
649: public static ComponentUI createUI(JComponent b)
650: {
651: return new BasicSliderUI((JSlider) b);
652: }
653:
654:
661: public void installUI(JComponent c)
662: {
663: super.installUI(c);
664: if (c instanceof JSlider)
665: {
666: slider = (JSlider) c;
667:
668: focusRect = new Rectangle();
669: contentRect = new Rectangle();
670: thumbRect = new Rectangle();
671: trackRect = new Rectangle();
672: tickRect = new Rectangle();
673: labelRect = new Rectangle();
674:
675: insetCache = slider.getInsets();
676: leftToRightCache = ! slider.getInverted();
677:
678: scrollTimer = new Timer(200, null);
679: scrollTimer.setRepeats(true);
680:
681: installDefaults(slider);
682: installListeners(slider);
683: installKeyboardActions(slider);
684:
685: calculateFocusRect();
686:
687: calculateContentRect();
688: calculateThumbSize();
689: calculateTrackBuffer();
690: calculateTrackRect();
691: calculateThumbLocation();
692:
693: calculateTickRect();
694: calculateLabelRect();
695: }
696: }
697:
698:
705: public void uninstallUI(JComponent c)
706: {
707: super.uninstallUI(c);
708:
709: uninstallKeyboardActions(slider);
710: uninstallListeners(slider);
711:
712: scrollTimer = null;
713:
714: focusRect = null;
715: contentRect = null;
716: thumbRect = null;
717: trackRect = null;
718: tickRect = null;
719: labelRect = null;
720:
721: focusInsets = null;
722: }
723:
724:
730: protected void installDefaults(JSlider slider)
731: {
732: LookAndFeel.installColors(slider, "Slider.background",
733: "Slider.foreground");
734: LookAndFeel.installBorder(slider, "Slider.border");
735: shadowColor = UIManager.getColor("Slider.shadow");
736: highlightColor = UIManager.getColor("Slider.highlight");
737: focusColor = UIManager.getColor("Slider.focus");
738: focusInsets = UIManager.getInsets("Slider.focusInsets");
739: slider.setOpaque(true);
740: }
741:
742:
750: protected TrackListener createTrackListener(JSlider slider)
751: {
752: return new TrackListener();
753: }
754:
755:
763: protected ChangeListener createChangeListener(JSlider slider)
764: {
765: return new ChangeHandler();
766: }
767:
768:
776: protected ComponentListener createComponentListener(JSlider slider)
777: {
778: return new ComponentHandler();
779: }
780:
781:
789: protected FocusListener createFocusListener(JSlider slider)
790: {
791: return new FocusHandler();
792: }
793:
794:
802: protected ScrollListener createScrollListener(JSlider slider)
803: {
804: return new ScrollListener();
805: }
806:
807:
815: protected PropertyChangeListener createPropertyChangeListener(JSlider slider)
816: {
817: return new PropertyChangeHandler();
818: }
819:
820:
826: protected void installListeners(JSlider slider)
827: {
828: propertyChangeListener = createPropertyChangeListener(slider);
829: componentListener = createComponentListener(slider);
830: trackListener = createTrackListener(slider);
831: focusListener = createFocusListener(slider);
832: changeListener = createChangeListener(slider);
833: scrollListener = createScrollListener(slider);
834:
835: slider.addPropertyChangeListener(propertyChangeListener);
836: slider.addComponentListener(componentListener);
837: slider.addMouseListener(trackListener);
838: slider.addMouseMotionListener(trackListener);
839: slider.addFocusListener(focusListener);
840: slider.getModel().addChangeListener(changeListener);
841:
842: scrollTimer.addActionListener(scrollListener);
843: }
844:
845:
851: protected void uninstallListeners(JSlider slider)
852: {
853: slider.removePropertyChangeListener(propertyChangeListener);
854: slider.removeComponentListener(componentListener);
855: slider.removeMouseListener(trackListener);
856: slider.removeMouseMotionListener(trackListener);
857: slider.removeFocusListener(focusListener);
858: slider.getModel().removeChangeListener(changeListener);
859:
860: scrollTimer.removeActionListener(scrollListener);
861:
862: propertyChangeListener = null;
863: componentListener = null;
864: trackListener = null;
865: focusListener = null;
866: changeListener = null;
867: scrollListener = null;
868: }
869:
870:
877: protected void installKeyboardActions(JSlider slider)
878: {
879: InputMap keyMap = getInputMap(JComponent.WHEN_FOCUSED);
880: SwingUtilities.replaceUIInputMap(slider, JComponent.WHEN_FOCUSED, keyMap);
881: ActionMap map = getActionMap();
882: SwingUtilities.replaceUIActionMap(slider, map);
883: }
884:
885:
892: protected void uninstallKeyboardActions(JSlider slider)
893: {
894: SwingUtilities.replaceUIActionMap(slider, null);
895: SwingUtilities.replaceUIInputMap(slider, JComponent.WHEN_FOCUSED, null);
896: }
897:
898:
912:
913:
919: public Dimension getPreferredHorizontalSize()
920: {
921: Insets insets = slider.getInsets();
922:
923:
924:
925: int width = getWidthOfWidestLabel() * (slider.getLabelTable() == null ? 0
926: : slider.getLabelTable().size());
927:
928:
929:
930: if (width < 200)
931: width = 200;
932:
933:
934:
935: width += insets.left + insets.right + focusInsets.left + focusInsets.right;
936:
937:
938: int height = getThumbSize().height;
939:
940: if (slider.getPaintTicks() && slider.getMajorTickSpacing() > 0
941: || slider.getMinorTickSpacing() > 0)
942: height += getTickLength();
943:
944: if (slider.getPaintLabels())
945: height += getHeightOfTallestLabel();
946:
947: height += insets.top + insets.bottom + focusInsets.top
948: + focusInsets.bottom;
949:
950: return new Dimension(width, height);
951: }
952:
953:
959: public Dimension getPreferredVerticalSize()
960: {
961: Insets insets = slider.getInsets();
962:
963: int height = getHeightOfTallestLabel() * (slider.getLabelTable() == null
964: ? 0 : slider.getLabelTable()
965: .size());
966:
967: if (height < 200)
968: height = 200;
969:
970: height += insets.top + insets.bottom + focusInsets.top
971: + focusInsets.bottom;
972:
973: int width = getThumbSize().width;
974:
975: if (slider.getPaintTicks() && slider.getMajorTickSpacing() > 0
976: || slider.getMinorTickSpacing() > 0)
977: width += getTickLength();
978:
979: if (slider.getPaintLabels())
980: width += getWidthOfWidestLabel();
981:
982: width += insets.left + insets.right + focusInsets.left + focusInsets.right;
983:
984: return new Dimension(width, height);
985: }
986:
987:
993: public Dimension getMinimumHorizontalSize()
994: {
995: Insets insets = slider.getInsets();
996:
997: int height = getThumbSize().height;
998:
999: if (slider.getPaintTicks() && slider.getMajorTickSpacing() > 0
1000: || slider.getMinorTickSpacing() > 0)
1001: height += getTickLength();
1002:
1003: if (slider.getPaintLabels())
1004: height += getHeightOfTallestLabel();
1005:
1006: height += insets.top + insets.bottom + focusInsets.top
1007: + focusInsets.bottom;
1008:
1009: return new Dimension(36, height);
1010: }
1011:
1012:
1018: public Dimension getMinimumVerticalSize()
1019: {
1020: Insets insets = slider.getInsets();
1021: int width = getThumbSize().width;
1022:
1023: if (slider.getPaintTicks() && slider.getMajorTickSpacing() > 0
1024: || slider.getMinorTickSpacing() > 0)
1025: width += getTickLength();
1026:
1027: if (slider.getPaintLabels())
1028: width += getWidthOfWidestLabel();
1029:
1030: width += insets.left + insets.right + focusInsets.left + focusInsets.right;
1031:
1032: return new Dimension(width, 36);
1033: }
1034:
1035:
1044: public Dimension getPreferredSize(JComponent c)
1045: {
1046: if (slider.getOrientation() == JSlider.HORIZONTAL)
1047: return getPreferredHorizontalSize();
1048: else
1049: return getPreferredVerticalSize();
1050: }
1051:
1052:
1061: public Dimension getMinimumSize(JComponent c)
1062: {
1063: if (slider.getOrientation() == JSlider.HORIZONTAL)
1064: return getMinimumHorizontalSize();
1065: else
1066: return getMinimumVerticalSize();
1067: }
1068:
1069:
1077: public Dimension getMaximumSize(JComponent c)
1078: {
1079: Insets insets = slider.getInsets();
1080: if (slider.getOrientation() == JSlider.HORIZONTAL)
1081: {
1082:
1083: int height = getThumbSize().height;
1084:
1085: if (slider.getPaintTicks() && slider.getMajorTickSpacing() > 0
1086: || slider.getMinorTickSpacing() > 0)
1087: height += getTickLength();
1088:
1089: if (slider.getPaintLabels())
1090: height += getHeightOfTallestLabel();
1091:
1092: height += insets.top + insets.bottom + focusInsets.top
1093: + focusInsets.bottom;
1094:
1095: return new Dimension(32767, height);
1096: }
1097: else
1098: {
1099: int width = getThumbSize().width;
1100:
1101: if (slider.getPaintTicks() && slider.getMajorTickSpacing() > 0
1102: || slider.getMinorTickSpacing() > 0)
1103: width += getTickLength();
1104:
1105: if (slider.getPaintLabels())
1106: width += getWidthOfWidestLabel();
1107:
1108: width += insets.left + insets.right + focusInsets.left
1109: + focusInsets.right;
1110:
1111: return new Dimension(width, 32767);
1112: }
1113: }
1114:
1115:
1119: protected void calculateGeometry()
1120: {
1121: calculateFocusRect();
1122: calculateContentRect();
1123: calculateThumbSize();
1124: calculateTrackBuffer();
1125: calculateTrackRect();
1126: calculateTickRect();
1127: calculateLabelRect();
1128: calculateThumbLocation();
1129: }
1130:
1131:
1135: protected void calculateFocusRect()
1136: {
1137: insetCache = slider.getInsets();
1138: focusRect = SwingUtilities.calculateInnerArea(slider, focusRect);
1139: if (focusRect.width < 0)
1140: focusRect.width = 0;
1141: if (focusRect.height < 0)
1142: focusRect.height = 0;
1143: }
1144:
1145:
1149: protected void calculateThumbSize()
1150: {
1151: Dimension d = getThumbSize();
1152: thumbRect.width = d.width;
1153: thumbRect.height = d.height;
1154: }
1155:
1156:
1161: protected void calculateContentRect()
1162: {
1163: contentRect.x = focusRect.x + focusInsets.left;
1164: contentRect.y = focusRect.y + focusInsets.top;
1165:
1166: contentRect.width = focusRect.width - focusInsets.left - focusInsets.right;
1167: contentRect.height = focusRect.height - focusInsets.top
1168: - focusInsets.bottom;
1169:
1170: if (contentRect.width < 0)
1171: contentRect.width = 0;
1172: if (contentRect.height < 0)
1173: contentRect.height = 0;
1174: }
1175:
1176:
1180: protected void calculateThumbLocation()
1181: {
1182: int value = slider.getValue();
1183:
1184: if (slider.getOrientation() == JSlider.HORIZONTAL)
1185: {
1186: thumbRect.x = xPositionForValue(value) - thumbRect.width / 2;
1187: thumbRect.y = trackRect.y + 1;
1188: }
1189: else
1190: {
1191: thumbRect.x = trackRect.x + 1;
1192: thumbRect.y = yPositionForValue(value) - thumbRect.height / 2;
1193: }
1194: }
1195:
1196:
1202: protected void calculateTrackBuffer()
1203: {
1204: if (slider.getOrientation() == JSlider.HORIZONTAL)
1205: {
1206: int w = Math.max(getWidthOfLowValueLabel(), getWidthOfHighValueLabel());
1207: trackBuffer = Math.max(thumbRect.width / 2, w / 2);
1208:
1209: }
1210: else
1211: {
1212: int h = Math.max(getHeightOfLowValueLabel(),
1213: getHeightOfHighValueLabel());
1214: trackBuffer = Math.max(thumbRect.height / 2, h / 2);
1215: }
1216: }
1217:
1218:
1228: protected Dimension getThumbSize()
1229: {
1230: if (slider.getOrientation() == JSlider.HORIZONTAL)
1231: return new Dimension(11, 20);
1232: else
1233: return new Dimension(20, 11);
1234: }
1235:
1236:
1240: protected void calculateTrackRect()
1241: {
1242: if (slider.getOrientation() == JSlider.HORIZONTAL)
1243: {
1244: trackRect.x = contentRect.x + trackBuffer;
1245: int h = getThumbSize().height;
1246: if (slider.getPaintTicks() && (slider.getMajorTickSpacing() > 0
1247: || slider.getMinorTickSpacing() > 0))
1248: h += getTickLength();
1249: if (slider.getPaintLabels())
1250: h += getHeightOfTallestLabel();
1251: trackRect.y = contentRect.y + (contentRect.height - h) / 2 - 1;
1252: trackRect.width = contentRect.width - 2 * trackBuffer;
1253: trackRect.height = thumbRect.height;
1254: }
1255: else
1256: {
1257: int w = getThumbSize().width;
1258: if (slider.getPaintTicks() && (slider.getMajorTickSpacing() > 0
1259: || slider.getMinorTickSpacing() > 0))
1260: w += getTickLength();
1261: if (slider.getPaintLabels())
1262: w += getWidthOfWidestLabel();
1263: trackRect.x = contentRect.x + (contentRect.width - w) / 2 - 1;
1264: trackRect.y = contentRect.y + trackBuffer;
1265: trackRect.width = thumbRect.width;
1266: trackRect.height = contentRect.height - 2 * trackBuffer;
1267: }
1268: }
1269:
1270:
1280: protected int getTickLength()
1281: {
1282: return 8;
1283: }
1284:
1285:
1289: protected void calculateTickRect()
1290: {
1291: if (slider.getOrientation() == JSlider.HORIZONTAL)
1292: {
1293: tickRect.x = trackRect.x;
1294: tickRect.y = trackRect.y + trackRect.height;
1295: tickRect.width = trackRect.width;
1296: tickRect.height = slider.getPaintTicks() ? getTickLength() : 0;
1297:
1298:
1299: if (!slider.getPaintTicks())
1300: tickRect.y--;
1301:
1302: if (tickRect.y + tickRect.height > contentRect.y + contentRect.height)
1303: tickRect.height = contentRect.y + contentRect.height - tickRect.y;
1304: }
1305: else
1306: {
1307: tickRect.x = trackRect.x + trackRect.width;
1308: tickRect.y = trackRect.y;
1309: tickRect.width = slider.getPaintTicks() ? getTickLength() : 0;
1310: tickRect.height = trackRect.height;
1311:
1312:
1313: if (!slider.getPaintTicks())
1314: tickRect.x--;
1315:
1316: if (tickRect.x + tickRect.width > contentRect.x + contentRect.width)
1317: tickRect.width = contentRect.x + contentRect.width - tickRect.x;
1318: }
1319: }
1320:
1321:
1325: protected void calculateLabelRect()
1326: {
1327: if (slider.getOrientation() == JSlider.HORIZONTAL)
1328: {
1329: if (slider.getPaintLabels())
1330: {
1331: labelRect.x = contentRect.x;
1332: labelRect.y = tickRect.y + tickRect.height - 1;
1333: labelRect.width = contentRect.width;
1334: }
1335: else
1336: {
1337: labelRect.x = trackRect.x;
1338: labelRect.y = tickRect.y + tickRect.height;
1339: labelRect.width = trackRect.width;
1340: }
1341: labelRect.height = getHeightOfTallestLabel();
1342: }
1343: else
1344: {
1345: if (slider.getPaintLabels())
1346: {
1347: labelRect.x = tickRect.x + tickRect.width - 1;
1348: labelRect.y = contentRect.y;
1349: labelRect.height = contentRect.height;
1350: }
1351: else
1352: {
1353: labelRect.x = tickRect.x + tickRect.width;
1354: labelRect.y = trackRect.y;
1355: labelRect.height = trackRect.height;
1356: }
1357: labelRect.width = getWidthOfWidestLabel();
1358: }
1359: }
1360:
1361:
1367: protected int getWidthOfWidestLabel()
1368: {
1369: int widest = 0;
1370: Component label;
1371:
1372: if (slider.getLabelTable() == null)
1373: return 0;
1374:
1375: Dimension pref;
1376: for (Enumeration list = slider.getLabelTable().elements();
1377: list.hasMoreElements();)
1378: {
1379: Object comp = list.nextElement();
1380: if (! (comp instanceof Component))
1381: continue;
1382: label = (Component) comp;
1383: pref = label.getPreferredSize();
1384: if (pref != null && pref.width > widest)
1385: widest = pref.width;
1386: }
1387: return widest;
1388: }
1389:
1390:
1396: protected int getHeightOfTallestLabel()
1397: {
1398: int tallest = 0;
1399: Component label;
1400:
1401: if (slider.getLabelTable() == null)
1402: return 0;
1403: Dimension pref;
1404: for (Enumeration list = slider.getLabelTable().elements();
1405: list.hasMoreElements();)
1406: {
1407: Object comp = list.nextElement();
1408: if (! (comp instanceof Component))
1409: continue;
1410: label = (Component) comp;
1411: pref = label.getPreferredSize();
1412: if (pref != null && pref.height > tallest)
1413: tallest = pref.height;
1414: }
1415: return tallest;
1416: }
1417:
1418:
1426: protected int getWidthOfHighValueLabel()
1427: {
1428: Component highValueLabel = getHighestValueLabel();
1429: if (highValueLabel != null)
1430: return highValueLabel.getPreferredSize().width;
1431: else
1432: return 0;
1433: }
1434:
1435:
1443: protected int getWidthOfLowValueLabel()
1444: {
1445: Component lowValueLabel = getLowestValueLabel();
1446: if (lowValueLabel != null)
1447: return lowValueLabel.getPreferredSize().width;
1448: else
1449: return 0;
1450: }
1451:
1452:
1458: protected int getHeightOfHighValueLabel()
1459: {
1460: Component highValueLabel = getHighestValueLabel();
1461: if (highValueLabel != null)
1462: return highValueLabel.getPreferredSize().height;
1463: else
1464: return 0;
1465: }
1466:
1467:
1473: protected int getHeightOfLowValueLabel()
1474: {
1475: Component lowValueLabel = getLowestValueLabel();
1476: if (lowValueLabel != null)
1477: return lowValueLabel.getPreferredSize().height;
1478: else
1479: return 0;
1480: }
1481:
1482:
1488: protected boolean drawInverted()
1489: {
1490: return slider.getInverted();
1491: }
1492:
1493:
1498: protected Component getLowestValueLabel()
1499: {
1500: Integer key = new Integer(Integer.MAX_VALUE);
1501: Integer tmpKey;
1502: Dictionary labelTable = slider.getLabelTable();
1503:
1504: if (labelTable == null)
1505: return null;
1506:
1507: for (Enumeration list = labelTable.keys(); list.hasMoreElements();)
1508: {
1509: Object value = list.nextElement();
1510: if (! (value instanceof Integer))
1511: continue;
1512: tmpKey = (Integer) value;
1513: if (tmpKey.intValue() < key.intValue())
1514: key = tmpKey;
1515: }
1516: Object comp = labelTable.get(key);
1517: if (! (comp instanceof Component))
1518: return null;
1519: return (Component) comp;
1520: }
1521:
1522:
1528: protected Component getHighestValueLabel()
1529: {
1530: Integer key = new Integer(Integer.MIN_VALUE);
1531: Integer tmpKey;
1532: Dictionary labelTable = slider.getLabelTable();
1533:
1534: if (labelTable == null)
1535: return null;
1536:
1537: for (Enumeration list = labelTable.keys(); list.hasMoreElements();)
1538: {
1539: Object value = list.nextElement();
1540: if (! (value instanceof Integer))
1541: continue;
1542: tmpKey = (Integer) value;
1543: if (tmpKey.intValue() > key.intValue())
1544: key = tmpKey;
1545: }
1546: Object comp = labelTable.get(key);
1547: if (! (comp instanceof Component))
1548: return null;
1549: return (Component) comp;
1550: }
1551:
1552:
1560: public void paint(Graphics g, JComponent c)
1561: {
1562:
1563: leftToRightCache = slider.getComponentOrientation()
1564: != ComponentOrientation.RIGHT_TO_LEFT;
1565:
1566: calculateGeometry();
1567:
1568: if (slider.getPaintTrack())
1569: paintTrack(g);
1570: if (slider.getPaintTicks())
1571: paintTicks(g);
1572: if (slider.getPaintLabels())
1573: paintLabels(g);
1574:
1575: paintThumb(g);
1576:
1577: if (hasFocus)
1578: paintFocus(g);
1579: }
1580:
1581:
1585: protected void recalculateIfInsetsChanged()
1586: {
1587:
1588:
1589: calculateFocusRect();
1590:
1591: calculateContentRect();
1592: calculateThumbSize();
1593: calculateTrackBuffer();
1594: calculateTrackRect();
1595: calculateThumbLocation();
1596:
1597: calculateTickRect();
1598: calculateLabelRect();
1599: }
1600:
1601:
1605: protected void recalculateIfOrientationChanged()
1606: {
1607:
1608:
1609: calculateThumbSize();
1610: calculateTrackBuffer();
1611: calculateTrackRect();
1612: calculateThumbLocation();
1613:
1614: calculateTickRect();
1615: calculateLabelRect();
1616: }
1617:
1618:
1625: public void paintFocus(Graphics g)
1626: {
1627: Color saved_color = g.getColor();
1628:
1629: g.setColor(getFocusColor());
1630:
1631: g.drawRect(focusRect.x, focusRect.y, focusRect.width, focusRect.height);
1632:
1633: g.setColor(saved_color);
1634: }
1635:
1636:
1662: public void paintTrack(Graphics g)
1663: {
1664: Color saved_color = g.getColor();
1665: int width;
1666: int height;
1667:
1668: Point a = new Point(trackRect.x, trackRect.y + 1);
1669: Point b = new Point(a);
1670: Point c = new Point(a);
1671: Point d = new Point(a);
1672:
1673: if (slider.getOrientation() == JSlider.HORIZONTAL)
1674: {
1675: width = trackRect.width;
1676: height = (thumbRect.height / 4 == 0) ? 1 : thumbRect.height / 4;
1677:
1678: a.translate(0, (trackRect.height / 2) - (height / 2));
1679: b.translate(0, (trackRect.height / 2) + (height / 2));
1680: c.translate(trackRect.width, (trackRect.height / 2) + (height / 2));
1681: d.translate(trackRect.width, (trackRect.height / 2) - (height / 2));
1682: }
1683: else
1684: {
1685: width = (thumbRect.width / 4 == 0) ? 1 : thumbRect.width / 4;
1686: height = trackRect.height;
1687:
1688: a.translate((trackRect.width / 2) - (width / 2), 0);
1689: b.translate((trackRect.width / 2) - (width / 2), trackRect.height);
1690: c.translate((trackRect.width / 2) + (width / 2), trackRect.height);
1691: d.translate((trackRect.width / 2) + (width / 2), 0);
1692: }
1693: g.setColor(Color.GRAY);
1694: g.fillRect(a.x, a.y, width, height);
1695:
1696: g.setColor(getHighlightColor());
1697: g.drawLine(b.x, b.y, c.x, c.y);
1698: g.drawLine(c.x, c.y, d.x, d.y);
1699:
1700: g.setColor(getShadowColor());
1701: g.drawLine(b.x, b.y, a.x, a.y);
1702: g.drawLine(a.x, a.y, d.x, d.y);
1703:
1704: g.setColor(saved_color);
1705: }
1706:
1707:
1714: public void paintTicks(Graphics g)
1715: {
1716: int max = slider.getMaximum();
1717: int min = slider.getMinimum();
1718: int majorSpace = slider.getMajorTickSpacing();
1719: int minorSpace = slider.getMinorTickSpacing();
1720:
1721: if (majorSpace > 0)
1722: {
1723: if (slider.getOrientation() == JSlider.HORIZONTAL)
1724: {
1725: g.translate(0, tickRect.y);
1726: for (int i = min; i <= max; i += majorSpace)
1727: paintMajorTickForHorizSlider(g, tickRect, xPositionForValue(i));
1728: g.translate(0, -tickRect.y);
1729: }
1730: else
1731: {
1732: g.translate(tickRect.x, 0);
1733: for (int i = min; i <= max; i += majorSpace)
1734: paintMajorTickForVertSlider(g, tickRect, yPositionForValue(i));
1735: g.translate(-tickRect.x, 0);
1736: }
1737: }
1738: if (minorSpace > 0)
1739: {
1740: if (slider.getOrientation() == JSlider.HORIZONTAL)
1741: {
1742: g.translate(0, tickRect.y);
1743: for (int i = min; i <= max; i += minorSpace)
1744: paintMinorTickForHorizSlider(g, tickRect, xPositionForValue(i));
1745: g.translate(0, -tickRect.y);
1746: }
1747: else
1748: {
1749: g.translate(tickRect.x, 0);
1750: for (int i = min; i <= max; i += minorSpace)
1751: paintMinorTickForVertSlider(g, tickRect, yPositionForValue(i));
1752: g.translate(-tickRect.x, 0);
1753: }
1754: }
1755: }
1756:
1757:
1762:
1763:
1771: protected void paintMinorTickForHorizSlider(Graphics g,
1772: Rectangle tickBounds, int x)
1773: {
1774: int y = tickRect.height / 4;
1775: Color saved = g.getColor();
1776: g.setColor(Color.BLACK);
1777:
1778: g.drawLine(x, y, x, y + tickRect.height / 4);
1779: g.setColor(saved);
1780: }
1781:
1782:
1790: protected void paintMajorTickForHorizSlider(Graphics g,
1791: Rectangle tickBounds, int x)
1792: {
1793: int y = tickRect.height / 4;
1794: Color saved = g.getColor();
1795: g.setColor(Color.BLACK);
1796:
1797: g.drawLine(x, y, x, y + tickRect.height / 2);
1798: g.setColor(saved);
1799: }
1800:
1801:
1809: protected void paintMinorTickForVertSlider(Graphics g, Rectangle tickBounds,
1810: int y)
1811: {
1812: int x = tickRect.width / 4;
1813: Color saved = g.getColor();
1814: g.setColor(Color.BLACK);
1815:
1816: g.drawLine(x, y, x + tickRect.width / 4, y);
1817: g.setColor(saved);
1818: }
1819:
1820:
1828: protected void paintMajorTickForVertSlider(Graphics g, Rectangle tickBounds,
1829: int y)
1830: {
1831: int x = tickRect.width / 4;
1832: Color saved = g.getColor();
1833: g.setColor(Color.BLACK);
1834:
1835: g.drawLine(x, y, x + tickRect.width / 2, y);
1836: g.setColor(saved);
1837: }
1838:
1839:
1847: public void paintLabels(Graphics g)
1848: {
1849: if (slider.getLabelTable() != null)
1850: {
1851: Dictionary table = slider.getLabelTable();
1852: Integer tmpKey;
1853: Object key;
1854: Object element;
1855: Component label;
1856: if (slider.getOrientation() == JSlider.HORIZONTAL)
1857: {
1858: for (Enumeration list = table.keys(); list.hasMoreElements();)
1859: {
1860: key = list.nextElement();
1861: if (! (key instanceof Integer))
1862: continue;
1863: tmpKey = (Integer) key;
1864: element = table.get(tmpKey);
1865:
1866:
1867: if (! (element instanceof JLabel))
1868: continue;
1869: label = (Component) element;
1870: paintHorizontalLabel(g, tmpKey.intValue(), label);
1871: }
1872: }
1873: else
1874: {
1875: for (Enumeration list = table.keys(); list.hasMoreElements();)
1876: {
1877: key = list.nextElement();
1878: if (! (key instanceof Integer))
1879: continue;
1880: tmpKey = (Integer) key;
1881: element = table.get(tmpKey);
1882:
1883:
1884: if (! (element instanceof JLabel))
1885: continue;
1886: label = (Component) element;
1887: paintVerticalLabel(g, tmpKey.intValue(), label);
1888: }
1889: }
1890: }
1891: }
1892:
1893:
1904: protected void paintHorizontalLabel(Graphics g, int value, Component label)
1905: {
1906:
1907:
1908:
1909:
1910:
1911: Dimension dim = label.getPreferredSize();
1912: int w = (int) dim.getWidth();
1913: int h = (int) dim.getHeight();
1914:
1915: int max = slider.getMaximum();
1916: int min = slider.getMinimum();
1917:
1918: if (value > max || value < min)
1919: return;
1920:
1921:
1922:
1923:
1924:
1925:
1926:
1927:
1928: int xpos = xPositionForValue(value) - w / 2;
1929: int ypos = labelRect.y;
1930:
1931:
1932:
1933:
1934:
1935: if (xpos < 0)
1936: xpos = 0;
1937:
1938:
1939:
1940:
1941: if (xpos + w > labelRect.x + labelRect.width)
1942: w = labelRect.x + labelRect.width - xpos;
1943:
1944:
1945:
1946: if (h > labelRect.height)
1947: h = labelRect.height;
1948:
1949: label.setBounds(xpos, ypos, w, h);
1950: SwingUtilities.paintComponent(g, label, null, label.getBounds());
1951: }
1952:
1953:
1964: protected void paintVerticalLabel(Graphics g, int value, Component label)
1965: {
1966: Dimension dim = label.getPreferredSize();
1967: int w = (int) dim.getWidth();
1968: int h = (int) dim.getHeight();
1969:
1970: int max = slider.getMaximum();
1971: int min = slider.getMinimum();
1972:
1973: if (value > max || value < min)
1974: return;
1975:
1976: int xpos = labelRect.x;
1977: int ypos = yPositionForValue(value) - h / 2;
1978:
1979: if (ypos < 0)
1980: ypos = 0;
1981:
1982: if (ypos + h > labelRect.y + labelRect.height)
1983: h = labelRect.y + labelRect.height - ypos;
1984:
1985: if (w > labelRect.width)
1986: w = labelRect.width;
1987:
1988: label.setBounds(xpos, ypos, w, h);
1989: SwingUtilities.paintComponent(g, label, null, label.getBounds());
1990: }
1991:
1992:
2014: public void paintThumb(Graphics g)
2015: {
2016: Color saved_color = g.getColor();
2017:
2018: Point a = new Point(thumbRect.x, thumbRect.y);
2019: Point b = new Point(a);
2020: Point c = new Point(a);
2021: Point d = new Point(a);
2022: Point e = new Point(a);
2023:
2024: Polygon bright;
2025: Polygon light;
2026: Polygon dark;
2027: Polygon all;
2028:
2029:
2030: int turnPoint;
2031:
2032: if (slider.getOrientation() == JSlider.HORIZONTAL)
2033: {
2034: turnPoint = thumbRect.height * 3 / 4;
2035:
2036: b.translate(thumbRect.width - 1, 0);
2037: c.translate(thumbRect.width - 1, turnPoint);
2038: d.translate(thumbRect.width / 2 - 1, thumbRect.height - 1);
2039: e.translate(0, turnPoint);
2040:
2041: bright = new Polygon(new int[] { b.x - 1, a.x, e.x, d.x },
2042: new int[] { b.y, a.y, e.y, d.y }, 4);
2043:
2044: dark = new Polygon(new int[] { b.x, c.x, d.x + 1 }, new int[] { b.y,
2045: c.y - 1,
2046: d.y }, 3);
2047:
2048: light = new Polygon(new int[] { b.x - 1, c.x - 1, d.x + 1 },
2049: new int[] { b.y + 1, c.y - 1, d.y - 1 }, 3);
2050:
2051: all = new Polygon(
2052: new int[] { a.x + 1, b.x - 2, c.x - 2, d.x, e.x + 1 },
2053: new int[] { a.y + 1, b.y + 1, c.y - 1, d.y - 1, e.y },
2054: 5);
2055: }
2056: else
2057: {
2058: turnPoint = thumbRect.width * 3 / 4 - 1;
2059:
2060: b.translate(turnPoint, 0);
2061: c.translate(thumbRect.width - 1, thumbRect.height / 2);
2062: d.translate(turnPoint, thumbRect.height - 1);
2063: e.translate(0, thumbRect.height - 1);
2064:
2065: bright = new Polygon(new int[] { c.x - 1, b.x, a.x, e.x },
2066: new int[] { c.y - 1, b.y, a.y, e.y - 1 }, 4);
2067:
2068: dark = new Polygon(new int[] { c.x, d.x, e.x }, new int[] { c.y, d.y,
2069: e.y }, 3);
2070:
2071: light = new Polygon(new int[] { c.x - 1, d.x, e.x + 1 },
2072: new int[] { c.y, d.y - 1, e.y - 1 }, 3);
2073: all = new Polygon(new int[] { a.x + 1, b.x, c.x - 2, c.x - 2, d.x,
2074: e.x + 1 }, new int[] { a.y + 1, b.y + 1,
2075: c.y - 1, c.y,
2076: d.y - 2, e.y - 2 },
2077: 6);
2078: }
2079:
2080: g.setColor(Color.WHITE);
2081: g.drawPolyline(bright.xpoints, bright.ypoints, bright.npoints);
2082:
2083: g.setColor(Color.BLACK);
2084: g.drawPolyline(dark.xpoints, dark.ypoints, dark.npoints);
2085:
2086: g.setColor(Color.GRAY);
2087: g.drawPolyline(light.xpoints, light.ypoints, light.npoints);
2088:
2089: g.setColor(Color.LIGHT_GRAY);
2090: g.drawPolyline(all.xpoints, all.ypoints, all.npoints);
2091: g.fillPolygon(all);
2092:
2093: g.setColor(saved_color);
2094: }
2095:
2096:
2102: public void setThumbLocation(int x, int y)
2103: {
2104: thumbRect.x = x;
2105: thumbRect.y = y;
2106: }
2107:
2108:
2117: public void scrollByBlock(int direction)
2118: {
2119: int unit = (slider.getMaximum() - slider.getMinimum()) / 10;
2120: int moveTo = slider.getValue();
2121: if (direction > 0)
2122: moveTo += unit;
2123: else
2124: moveTo -= unit;
2125:
2126: if (slider.getSnapToTicks())
2127: moveTo = findClosestTick(moveTo);
2128:
2129: slider.setValue(moveTo);
2130: }
2131:
2132:
2141: public void scrollByUnit(int direction)
2142: {
2143: int moveTo = slider.getValue();
2144: if (direction > 0)
2145: moveTo++;
2146: else
2147: moveTo--;
2148:
2149: if (slider.getSnapToTicks())
2150: moveTo = findClosestTick(moveTo);
2151:
2152: slider.setValue(moveTo);
2153: }
2154:
2155:
2162: protected void scrollDueToClickInTrack(int dir)
2163: {
2164: scrollTimer.stop();
2165:
2166: scrollListener.setDirection(dir);
2167: scrollListener.setScrollByBlock(true);
2168:
2169: scrollTimer.start();
2170: }
2171:
2172:
2181: protected int xPositionForValue(int value)
2182: {
2183: double min = slider.getMinimum();
2184: if (value < min)
2185: value = (int) min;
2186: double max = slider.getMaximum();
2187: if (value > max)
2188: value = (int) max;
2189: double len = trackRect.width;
2190: if ((max - min) <= 0.0)
2191: return 0;
2192: int xPos = (int) ((value - min) / (max - min) * len + 0.5);
2193:
2194: if (drawInverted())
2195: return trackRect.x + Math.max(trackRect.width - xPos - 1, 0);
2196: else
2197: return trackRect.x + Math.min(xPos, trackRect.width - 1);
2198: }
2199:
2200:
2209: protected int yPositionForValue(int value)
2210: {
2211: double min = slider.getMinimum();
2212: if (value < min)
2213: value = (int) min;
2214: double max = slider.getMaximum();
2215: if (value > max)
2216: value = (int) max;
2217: int len = trackRect.height;
2218: if ((max - min) <= 0.0)
2219: return 0;
2220:
2221: int yPos = (int) ((value - min) / (max - min) * len + 0.5);
2222:
2223: if (! drawInverted())
2224: return trackRect.y + trackRect.height - Math.max(yPos, 1);
2225: else
2226: return trackRect.y + Math.min(yPos, trackRect.height - 1);
2227: }
2228:
2229:
2238: public int valueForYPosition(int yPos)
2239: {
2240: int min = slider.getMinimum();
2241: int max = slider.getMaximum();
2242: int len = trackRect.height;
2243:
2244: int value;
2245:
2246:
2247:
2248:
2249: if (len == 0)
2250: return (max - min) / 2;
2251:
2252: if (! drawInverted())
2253: value = (len - (yPos - trackRect.y)) * (max - min) / len + min;
2254: else
2255: value = (yPos - trackRect.y) * (max - min) / len + min;
2256:
2257:
2258: if (value > max)
2259: value = max;
2260: else if (value < min)
2261: value = min;
2262: return value;
2263: }
2264:
2265:
2274: public int valueForXPosition(int xPos)
2275: {
2276: int min = slider.getMinimum();
2277: int max = slider.getMaximum();
2278: int len = trackRect.width;
2279:
2280: int value;
2281:
2282:
2283:
2284:
2285: if (len == 0)
2286: return (max - min) / 2;
2287:
2288: if (! drawInverted())
2289: value = (xPos - trackRect.x) * (max - min) / len + min;
2290: else
2291: value = (len - (xPos - trackRect.x)) * (max - min) / len + min;
2292:
2293:
2294: if (value > max)
2295: value = max;
2296: else if (value < min)
2297: value = min;
2298: return value;
2299: }
2300:
2301:
2309: int findClosestTick(int value)
2310: {
2311: int min = slider.getMinimum();
2312: int max = slider.getMaximum();
2313: int majorSpace = slider.getMajorTickSpacing();
2314: int minorSpace = slider.getMinorTickSpacing();
2315:
2316:
2317:
2318:
2319:
2320:
2321: int minor = min - value;
2322: int major = min - value;
2323:
2324:
2325:
2326:
2327: if (majorSpace <= 0 && minorSpace <= 0)
2328: return value;
2329:
2330:
2331: if (majorSpace > 0)
2332: {
2333: int lowerBound = (value - min) / majorSpace;
2334: int majLower = majorSpace * lowerBound + min;
2335: int majHigher = majorSpace * (lowerBound + 1) + min;
2336:
2337: if (majHigher <= max && majHigher - value <= value - majLower)
2338: major = majHigher - value;
2339: else
2340: major = majLower - value;
2341: }
2342:
2343: if (minorSpace > 0)
2344: {
2345: int lowerBound = value / minorSpace;
2346: int minLower = minorSpace * lowerBound;
2347: int minHigher = minorSpace * (lowerBound + 1);
2348:
2349: if (minHigher <= max && minHigher - value <= value - minLower)
2350: minor = minHigher - value;
2351: else
2352: minor = minLower - value;
2353: }
2354:
2355:
2356: if (Math.abs(minor) > Math.abs(major))
2357: return value + major;
2358: else
2359: return value + minor;
2360: }
2361:
2362: InputMap getInputMap(int condition)
2363: {
2364: if (condition == JComponent.WHEN_FOCUSED)
2365: return (InputMap) UIManager.get("Slider.focusInputMap");
2366: return null;
2367: }
2368:
2369:
2376: ActionMap getActionMap()
2377: {
2378: ActionMap map = (ActionMap) UIManager.get("Slider.actionMap");
2379:
2380: if (map == null)
2381: {
2382: map = createActionMap();
2383: if (map != null)
2384: UIManager.put("Slider.actionMap", map);
2385: }
2386: return map;
2387: }
2388:
2389:
2399: ActionMap createActionMap()
2400: {
2401: ActionMap map = new ActionMapUIResource();
2402: map.put("positiveUnitIncrement",
2403: new AbstractAction("positiveUnitIncrement") {
2404: public void actionPerformed(ActionEvent event)
2405: {
2406: JSlider slider = (JSlider) event.getSource();
2407: BasicSliderUI ui = (BasicSliderUI) slider.getUI();
2408: if (slider.getInverted())
2409: ui.scrollByUnit(BasicSliderUI.NEGATIVE_SCROLL);
2410: else
2411: ui.scrollByUnit(BasicSliderUI.POSITIVE_SCROLL);
2412: }
2413: }
2414: );
2415: map.put("negativeUnitIncrement",
2416: new AbstractAction("negativeUnitIncrement") {
2417: public void actionPerformed(ActionEvent event)
2418: {
2419: JSlider slider = (JSlider) event.getSource();
2420: BasicSliderUI ui = (BasicSliderUI) slider.getUI();
2421: if (slider.getInverted())
2422: ui.scrollByUnit(BasicSliderUI.POSITIVE_SCROLL);
2423: else
2424: ui.scrollByUnit(BasicSliderUI.NEGATIVE_SCROLL);
2425: }
2426: }
2427: );
2428: map.put("positiveBlockIncrement",
2429: new AbstractAction("positiveBlockIncrement") {
2430: public void actionPerformed(ActionEvent event)
2431: {
2432: JSlider slider = (JSlider) event.getSource();
2433: BasicSliderUI ui = (BasicSliderUI) slider.getUI();
2434: if (slider.getInverted())
2435: ui.scrollByBlock(BasicSliderUI.NEGATIVE_SCROLL);
2436: else
2437: ui.scrollByBlock(BasicSliderUI.POSITIVE_SCROLL);
2438: }
2439: }
2440: );
2441: map.put("negativeBlockIncrement",
2442: new AbstractAction("negativeBlockIncrement") {
2443: public void actionPerformed(ActionEvent event)
2444: {
2445: JSlider slider = (JSlider) event.getSource();
2446: BasicSliderUI ui = (BasicSliderUI) slider.getUI();
2447: if (slider.getInverted())
2448: ui.scrollByBlock(BasicSliderUI.POSITIVE_SCROLL);
2449: else
2450: ui.scrollByBlock(BasicSliderUI.NEGATIVE_SCROLL);
2451: }
2452: }
2453: );
2454: map.put("minScroll",
2455: new AbstractAction("minScroll") {
2456: public void actionPerformed(ActionEvent event)
2457: {
2458: JSlider slider = (JSlider) event.getSource();
2459: if (slider.getInverted())
2460: slider.setValue(slider.getMaximum());
2461: else
2462: slider.setValue(slider.getMinimum());
2463: }
2464: }
2465: );
2466: map.put("maxScroll",
2467: new AbstractAction("maxScroll") {
2468: public void actionPerformed(ActionEvent event)
2469: {
2470: JSlider slider = (JSlider) event.getSource();
2471: if (slider.getInverted())
2472: slider.setValue(slider.getMinimum());
2473: else
2474: slider.setValue(slider.getMaximum());
2475: }
2476: }
2477: );
2478: return map;
2479: }
2480: }