equal
deleted
inserted
replaced
654 } |
654 } |
655 |
655 |
656 } |
656 } |
657 |
657 |
658 /** |
658 /** |
659 * Gets the height of the tick area for horizontal sliders and the width of the |
659 * Gets the height of the tick area for horizontal sliders and the width of |
660 * tick area for vertical sliders. BasicSliderUI uses the returned value to |
660 * the tick area for vertical sliders. BasicSliderUI uses the returned value |
661 * determine the tick area rectangle. If you want to give your ticks some room, |
661 * to determine the tick area rectangle. If you want to give your ticks some |
662 * make this larger than you need and paint your ticks away from the sides in paintTicks(). |
662 * room, make this larger than you need and paint your ticks away from the |
|
663 * sides in paintTicks(). |
|
664 * |
|
665 * @return an integer representing the height of the tick area for |
|
666 * horizontal sliders, and the width of the tick area for the vertical |
|
667 * sliders |
663 */ |
668 */ |
664 protected int getTickLength() { |
669 protected int getTickLength() { |
665 return 8; |
670 return 8; |
666 } |
671 } |
667 |
672 |
865 |
870 |
866 /** |
871 /** |
867 * Returns the smallest value that has an entry in the label table. |
872 * Returns the smallest value that has an entry in the label table. |
868 * |
873 * |
869 * @return smallest value that has an entry in the label table, or |
874 * @return smallest value that has an entry in the label table, or |
870 * null. |
875 * null. |
871 * @since 1.6 |
876 * @since 1.6 |
872 */ |
877 */ |
873 protected Integer getLowestValue() { |
878 protected Integer getLowestValue() { |
874 Dictionary<Integer, JComponent> dictionary = slider.getLabelTable(); |
879 Dictionary<Integer, JComponent> dictionary = slider.getLabelTable(); |
875 |
880 |
892 return min; |
897 return min; |
893 } |
898 } |
894 |
899 |
895 |
900 |
896 /** |
901 /** |
897 * Returns the label that corresponds to the highest slider value in the label table. |
902 * Returns the label that corresponds to the highest slider value in the |
|
903 * label table. |
|
904 * |
|
905 * @return the label that corresponds to the highest slider value in the |
|
906 * label table |
898 * @see JSlider#setLabelTable |
907 * @see JSlider#setLabelTable |
899 */ |
908 */ |
900 protected Component getLowestValueLabel() { |
909 protected Component getLowestValueLabel() { |
901 Integer min = getLowestValue(); |
910 Integer min = getLowestValue(); |
902 if (min != null) { |
911 if (min != null) { |
904 } |
913 } |
905 return null; |
914 return null; |
906 } |
915 } |
907 |
916 |
908 /** |
917 /** |
909 * Returns the label that corresponds to the lowest slider value in the label table. |
918 * Returns the label that corresponds to the lowest slider value in the |
|
919 * label table. |
|
920 * |
|
921 * @return the label that corresponds to the lowest slider value in the |
|
922 * label table |
910 * @see JSlider#setLabelTable |
923 * @see JSlider#setLabelTable |
911 */ |
924 */ |
912 protected Component getHighestValueLabel() { |
925 protected Component getHighestValueLabel() { |
913 Integer max = getHighestValue(); |
926 Integer max = getHighestValue(); |
914 if (max != null) { |
927 if (max != null) { |
1164 } |
1177 } |
1165 |
1178 |
1166 } |
1179 } |
1167 |
1180 |
1168 /** |
1181 /** |
1169 * Called for every label in the label table. Used to draw the labels for horizontal sliders. |
1182 * Called for every label in the label table. Used to draw the labels for |
1170 * The graphics have been translated to labelRect.y already. |
1183 * horizontal sliders. The graphics have been translated to labelRect.y |
|
1184 * already. |
|
1185 * |
|
1186 * @param g the graphics context in which to paint |
|
1187 * @param value the value of the slider |
|
1188 * @param label the component label in the label table that needs to be |
|
1189 * painted |
1171 * @see JSlider#setLabelTable |
1190 * @see JSlider#setLabelTable |
1172 */ |
1191 */ |
1173 protected void paintHorizontalLabel( Graphics g, int value, Component label ) { |
1192 protected void paintHorizontalLabel( Graphics g, int value, Component label ) { |
1174 int labelCenter = xPositionForValue( value ); |
1193 int labelCenter = xPositionForValue( value ); |
1175 int labelLeft = labelCenter - (label.getPreferredSize().width / 2); |
1194 int labelLeft = labelCenter - (label.getPreferredSize().width / 2); |
1177 label.paint( g ); |
1196 label.paint( g ); |
1178 g.translate( -labelLeft, 0 ); |
1197 g.translate( -labelLeft, 0 ); |
1179 } |
1198 } |
1180 |
1199 |
1181 /** |
1200 /** |
1182 * Called for every label in the label table. Used to draw the labels for vertical sliders. |
1201 * Called for every label in the label table. Used to draw the labels for |
1183 * The graphics have been translated to labelRect.x already. |
1202 * vertical sliders. The graphics have been translated to labelRect.x |
|
1203 * already. |
|
1204 * |
|
1205 * @param g the graphics context in which to paint |
|
1206 * @param value the value of the slider |
|
1207 * @param label the component label in the label table that needs to be |
|
1208 * painted |
1184 * @see JSlider#setLabelTable |
1209 * @see JSlider#setLabelTable |
1185 */ |
1210 */ |
1186 protected void paintVerticalLabel( Graphics g, int value, Component label ) { |
1211 protected void paintVerticalLabel( Graphics g, int value, Component label ) { |
1187 int labelCenter = yPositionForValue( value ); |
1212 int labelCenter = yPositionForValue( value ); |
1188 int labelTop = labelCenter - (label.getPreferredSize().height / 2); |
1213 int labelTop = labelCenter - (label.getPreferredSize().height / 2); |
1340 slider.setValue(slider.getValue() + delta); |
1365 slider.setValue(slider.getValue() + delta); |
1341 } |
1366 } |
1342 } |
1367 } |
1343 |
1368 |
1344 /** |
1369 /** |
1345 * This function is called when a mousePressed was detected in the track, not |
1370 * This function is called when a mousePressed was detected in the track, |
1346 * in the thumb. The default behavior is to scroll by block. You can |
1371 * not in the thumb. The default behavior is to scroll by block. You can |
1347 * override this method to stop it from scrolling or to add additional behavior. |
1372 * override this method to stop it from scrolling or to add additional |
|
1373 * behavior. |
|
1374 * |
|
1375 * @param dir the direction and number of blocks to scroll |
1348 */ |
1376 */ |
1349 protected void scrollDueToClickInTrack( int dir ) { |
1377 protected void scrollDueToClickInTrack( int dir ) { |
1350 scrollByBlock( dir ); |
1378 scrollByBlock( dir ); |
1351 } |
1379 } |
1352 |
1380 |
1385 * negative undefined results may occur. |
1413 * negative undefined results may occur. |
1386 * |
1414 * |
1387 * @param value the slider value to get the location for |
1415 * @param value the slider value to get the location for |
1388 * @param trackY y-origin of the track |
1416 * @param trackY y-origin of the track |
1389 * @param trackHeight the height of the track |
1417 * @param trackHeight the height of the track |
|
1418 * @return the y location for the specified value of the slider |
1390 * @since 1.6 |
1419 * @since 1.6 |
1391 */ |
1420 */ |
1392 protected int yPositionForValue(int value, int trackY, int trackHeight) { |
1421 protected int yPositionForValue(int value, int trackY, int trackHeight) { |
1393 int min = slider.getMinimum(); |
1422 int min = slider.getMinimum(); |
1394 int max = slider.getMaximum(); |
1423 int max = slider.getMaximum(); |
1415 /** |
1444 /** |
1416 * Returns the value at the y position. If {@code yPos} is beyond the |
1445 * Returns the value at the y position. If {@code yPos} is beyond the |
1417 * track at the the bottom or the top, this method sets the value to either |
1446 * track at the the bottom or the top, this method sets the value to either |
1418 * the minimum or maximum value of the slider, depending on if the slider |
1447 * the minimum or maximum value of the slider, depending on if the slider |
1419 * is inverted or not. |
1448 * is inverted or not. |
|
1449 * |
|
1450 * @param yPos the location of the slider along the y axis |
|
1451 * @return the value at the y position |
1420 */ |
1452 */ |
1421 public int valueForYPosition( int yPos ) { |
1453 public int valueForYPosition( int yPos ) { |
1422 int value; |
1454 int value; |
1423 final int minValue = slider.getMinimum(); |
1455 final int minValue = slider.getMinimum(); |
1424 final int maxValue = slider.getMaximum(); |
1456 final int maxValue = slider.getMaximum(); |
1447 /** |
1479 /** |
1448 * Returns the value at the x position. If {@code xPos} is beyond the |
1480 * Returns the value at the x position. If {@code xPos} is beyond the |
1449 * track at the left or the right, this method sets the value to either the |
1481 * track at the left or the right, this method sets the value to either the |
1450 * minimum or maximum value of the slider, depending on if the slider is |
1482 * minimum or maximum value of the slider, depending on if the slider is |
1451 * inverted or not. |
1483 * inverted or not. |
|
1484 * |
|
1485 * @param xPos the location of the slider along the x axis |
|
1486 * @return the value of the x position |
1452 */ |
1487 */ |
1453 public int valueForXPosition( int xPos ) { |
1488 public int valueForXPosition( int xPos ) { |
1454 int value; |
1489 int value; |
1455 final int minValue = slider.getMinimum(); |
1490 final int minValue = slider.getMinimum(); |
1456 final int maxValue = slider.getMaximum(); |
1491 final int maxValue = slider.getMaximum(); |