380 JComponent c) { 381 super.getBaselineResizeBehavior(c); 382 // NOTE: BasicSpinner really provides for CENTER_OFFSET, but 383 // the default min/pref size is smaller than it should be 384 // so that getBaseline() doesn't implement the contract 385 // for CENTER_OFFSET as defined in Component. 386 return Component.BaselineResizeBehavior.OTHER; 387 } 388 389 /** 390 * Returns true if all the labels from the label table have the same 391 * baseline. 392 * 393 * @return true if all the labels from the label table have the 394 * same baseline 395 * @since 1.6 396 */ 397 protected boolean labelsHaveSameBaselines() { 398 if (!checkedLabelBaselines) { 399 checkedLabelBaselines = true; 400 Dictionary<Integer, ? extends JComponent> dictionary = slider.getLabelTable(); 401 if (dictionary != null) { 402 sameLabelBaselines = true; 403 Enumeration<? extends JComponent> elements = dictionary.elements(); 404 int baseline = -1; 405 while (elements.hasMoreElements()) { 406 JComponent label = elements.nextElement(); 407 Dimension pref = label.getPreferredSize(); 408 int labelBaseline = label.getBaseline(pref.width, 409 pref.height); 410 if (labelBaseline >= 0) { 411 if (baseline == -1) { 412 baseline = labelBaseline; 413 } 414 else if (baseline != labelBaseline) { 415 sameLabelBaselines = false; 416 break; 417 } 418 } 419 else { 420 sameLabelBaselines = false; 421 break; 422 } 423 } 424 } 425 else { 426 sameLabelBaselines = false; 741 } 742 else { 743 size.width = 11; 744 size.height = 20; 745 } 746 747 return size; 748 } 749 750 public class PropertyChangeHandler implements PropertyChangeListener { 751 // NOTE: This class exists only for backward compatibility. All 752 // its functionality has been moved into Handler. If you need to add 753 // new functionality add it to the Handler, but make sure this 754 // class calls into the Handler. 755 public void propertyChange( PropertyChangeEvent e ) { 756 getHandler().propertyChange(e); 757 } 758 } 759 760 protected int getWidthOfWidestLabel() { 761 Dictionary<?, ? extends JComponent> dictionary = slider.getLabelTable(); 762 int widest = 0; 763 if ( dictionary != null ) { 764 Enumeration<?> keys = dictionary.keys(); 765 while ( keys.hasMoreElements() ) { 766 JComponent label = dictionary.get(keys.nextElement()); 767 widest = Math.max( label.getPreferredSize().width, widest ); 768 } 769 } 770 return widest; 771 } 772 773 protected int getHeightOfTallestLabel() { 774 Dictionary<?, ? extends JComponent> dictionary = slider.getLabelTable(); 775 int tallest = 0; 776 if ( dictionary != null ) { 777 Enumeration<?> keys = dictionary.keys(); 778 while ( keys.hasMoreElements() ) { 779 JComponent label = dictionary.get(keys.nextElement()); 780 tallest = Math.max( label.getPreferredSize().height, tallest ); 781 } 782 } 783 return tallest; 784 } 785 786 protected int getWidthOfHighValueLabel() { 787 Component label = getHighestValueLabel(); 788 int width = 0; 789 790 if ( label != null ) { 791 width = label.getPreferredSize().width; 792 } 793 794 return width; 795 } 796 797 protected int getWidthOfLowValueLabel() { 798 Component label = getLowestValueLabel(); 799 int width = 0; 830 protected boolean drawInverted() { 831 if (slider.getOrientation()==JSlider.HORIZONTAL) { 832 if(BasicGraphicsUtils.isLeftToRight(slider)) { 833 return slider.getInverted(); 834 } else { 835 return !slider.getInverted(); 836 } 837 } else { 838 return slider.getInverted(); 839 } 840 } 841 842 /** 843 * Returns the biggest value that has an entry in the label table. 844 * 845 * @return biggest value that has an entry in the label table, or 846 * null. 847 * @since 1.6 848 */ 849 protected Integer getHighestValue() { 850 Dictionary<Integer, ?> dictionary = slider.getLabelTable(); 851 852 if (dictionary == null) { 853 return null; 854 } 855 856 Enumeration<Integer> keys = dictionary.keys(); 857 858 Integer max = null; 859 860 while (keys.hasMoreElements()) { 861 Integer i = keys.nextElement(); 862 863 if (max == null || i > max) { 864 max = i; 865 } 866 } 867 868 return max; 869 } 870 871 /** 872 * Returns the smallest value that has an entry in the label table. 873 * 874 * @return smallest value that has an entry in the label table, or 875 * null. 876 * @since 1.6 877 */ 878 protected Integer getLowestValue() { 879 Dictionary<Integer, ? extends JComponent> dictionary = slider.getLabelTable(); 880 881 if (dictionary == null) { 882 return null; 883 } 884 885 Enumeration<Integer> keys = dictionary.keys(); 886 887 Integer min = null; 888 889 while (keys.hasMoreElements()) { 890 Integer i = keys.nextElement(); 891 892 if (min == null || i < min) { 893 min = i; 894 } 895 } 896 897 return min; 898 } 899 900 901 /** 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 907 * @see JSlider#setLabelTable 908 */ 909 protected Component getLowestValueLabel() { 910 Integer min = getLowestValue(); 1117 1118 protected void paintMinorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) { 1119 g.drawLine( x, 0, x, tickBounds.height / 2 - 1 ); 1120 } 1121 1122 protected void paintMajorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) { 1123 g.drawLine( x, 0, x, tickBounds.height - 2 ); 1124 } 1125 1126 protected void paintMinorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) { 1127 g.drawLine( 0, y, tickBounds.width / 2 - 1, y ); 1128 } 1129 1130 protected void paintMajorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) { 1131 g.drawLine( 0, y, tickBounds.width - 2, y ); 1132 } 1133 1134 public void paintLabels( Graphics g ) { 1135 Rectangle labelBounds = labelRect; 1136 1137 Dictionary<Integer, ? extends JComponent> dictionary = slider.getLabelTable(); 1138 if ( dictionary != null ) { 1139 Enumeration<Integer> keys = dictionary.keys(); 1140 int minValue = slider.getMinimum(); 1141 int maxValue = slider.getMaximum(); 1142 boolean enabled = slider.isEnabled(); 1143 while ( keys.hasMoreElements() ) { 1144 Integer key = keys.nextElement(); 1145 int value = key.intValue(); 1146 if (value >= minValue && value <= maxValue) { 1147 JComponent label = dictionary.get(key); 1148 label.setEnabled(enabled); 1149 1150 if (label instanceof JLabel) { 1151 Icon icon = label.isEnabled() ? ((JLabel) label).getIcon() : ((JLabel) label).getDisabledIcon(); 1152 1153 if (icon instanceof ImageIcon) { 1154 // Register Slider as an image observer. It allows to catch notifications about 1155 // image changes (e.g. gif animation) 1156 Toolkit.getDefaultToolkit().checkImage(((ImageIcon) icon).getImage(), -1, -1, slider); 1157 } 1158 } 1159 1160 if ( slider.getOrientation() == JSlider.HORIZONTAL ) { 1161 g.translate( 0, labelBounds.y ); 1162 paintHorizontalLabel( g, value, label ); 1163 g.translate( 0, -labelBounds.y ); 1164 } 1165 else { 1166 int offset = 0; 1167 if (!BasicGraphicsUtils.isLeftToRight(slider)) { | 380 JComponent c) { 381 super.getBaselineResizeBehavior(c); 382 // NOTE: BasicSpinner really provides for CENTER_OFFSET, but 383 // the default min/pref size is smaller than it should be 384 // so that getBaseline() doesn't implement the contract 385 // for CENTER_OFFSET as defined in Component. 386 return Component.BaselineResizeBehavior.OTHER; 387 } 388 389 /** 390 * Returns true if all the labels from the label table have the same 391 * baseline. 392 * 393 * @return true if all the labels from the label table have the 394 * same baseline 395 * @since 1.6 396 */ 397 protected boolean labelsHaveSameBaselines() { 398 if (!checkedLabelBaselines) { 399 checkedLabelBaselines = true; 400 @SuppressWarnings("rawtypes") 401 Dictionary dictionary = slider.getLabelTable(); 402 if (dictionary != null) { 403 sameLabelBaselines = true; 404 Enumeration<?> elements = dictionary.elements(); 405 int baseline = -1; 406 while (elements.hasMoreElements()) { 407 JComponent label = (JComponent) elements.nextElement(); 408 Dimension pref = label.getPreferredSize(); 409 int labelBaseline = label.getBaseline(pref.width, 410 pref.height); 411 if (labelBaseline >= 0) { 412 if (baseline == -1) { 413 baseline = labelBaseline; 414 } 415 else if (baseline != labelBaseline) { 416 sameLabelBaselines = false; 417 break; 418 } 419 } 420 else { 421 sameLabelBaselines = false; 422 break; 423 } 424 } 425 } 426 else { 427 sameLabelBaselines = false; 742 } 743 else { 744 size.width = 11; 745 size.height = 20; 746 } 747 748 return size; 749 } 750 751 public class PropertyChangeHandler implements PropertyChangeListener { 752 // NOTE: This class exists only for backward compatibility. All 753 // its functionality has been moved into Handler. If you need to add 754 // new functionality add it to the Handler, but make sure this 755 // class calls into the Handler. 756 public void propertyChange( PropertyChangeEvent e ) { 757 getHandler().propertyChange(e); 758 } 759 } 760 761 protected int getWidthOfWidestLabel() { 762 @SuppressWarnings("rawtypes") 763 Dictionary dictionary = slider.getLabelTable(); 764 int widest = 0; 765 if ( dictionary != null ) { 766 Enumeration<?> keys = dictionary.keys(); 767 while ( keys.hasMoreElements() ) { 768 JComponent label = (JComponent) dictionary.get(keys.nextElement()); 769 widest = Math.max( label.getPreferredSize().width, widest ); 770 } 771 } 772 return widest; 773 } 774 775 protected int getHeightOfTallestLabel() { 776 @SuppressWarnings("rawtypes") 777 Dictionary dictionary = slider.getLabelTable(); 778 int tallest = 0; 779 if ( dictionary != null ) { 780 Enumeration<?> keys = dictionary.keys(); 781 while ( keys.hasMoreElements() ) { 782 JComponent label = (JComponent) dictionary.get(keys.nextElement()); 783 tallest = Math.max( label.getPreferredSize().height, tallest ); 784 } 785 } 786 return tallest; 787 } 788 789 protected int getWidthOfHighValueLabel() { 790 Component label = getHighestValueLabel(); 791 int width = 0; 792 793 if ( label != null ) { 794 width = label.getPreferredSize().width; 795 } 796 797 return width; 798 } 799 800 protected int getWidthOfLowValueLabel() { 801 Component label = getLowestValueLabel(); 802 int width = 0; 833 protected boolean drawInverted() { 834 if (slider.getOrientation()==JSlider.HORIZONTAL) { 835 if(BasicGraphicsUtils.isLeftToRight(slider)) { 836 return slider.getInverted(); 837 } else { 838 return !slider.getInverted(); 839 } 840 } else { 841 return slider.getInverted(); 842 } 843 } 844 845 /** 846 * Returns the biggest value that has an entry in the label table. 847 * 848 * @return biggest value that has an entry in the label table, or 849 * null. 850 * @since 1.6 851 */ 852 protected Integer getHighestValue() { 853 @SuppressWarnings("rawtypes") 854 Dictionary dictionary = slider.getLabelTable(); 855 856 if (dictionary == null) { 857 return null; 858 } 859 860 Enumeration<?> keys = dictionary.keys(); 861 862 Integer max = null; 863 864 while (keys.hasMoreElements()) { 865 Integer i = (Integer) keys.nextElement(); 866 867 if (max == null || i > max) { 868 max = i; 869 } 870 } 871 872 return max; 873 } 874 875 /** 876 * Returns the smallest value that has an entry in the label table. 877 * 878 * @return smallest value that has an entry in the label table, or 879 * null. 880 * @since 1.6 881 */ 882 protected Integer getLowestValue() { 883 @SuppressWarnings("rawtypes") 884 Dictionary dictionary = slider.getLabelTable(); 885 886 if (dictionary == null) { 887 return null; 888 } 889 890 Enumeration<?> keys = dictionary.keys(); 891 892 Integer min = null; 893 894 while (keys.hasMoreElements()) { 895 Integer i = (Integer) keys.nextElement(); 896 897 if (min == null || i < min) { 898 min = i; 899 } 900 } 901 902 return min; 903 } 904 905 906 /** 907 * Returns the label that corresponds to the highest slider value in the 908 * label table. 909 * 910 * @return the label that corresponds to the highest slider value in the 911 * label table 912 * @see JSlider#setLabelTable 913 */ 914 protected Component getLowestValueLabel() { 915 Integer min = getLowestValue(); 1122 1123 protected void paintMinorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) { 1124 g.drawLine( x, 0, x, tickBounds.height / 2 - 1 ); 1125 } 1126 1127 protected void paintMajorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) { 1128 g.drawLine( x, 0, x, tickBounds.height - 2 ); 1129 } 1130 1131 protected void paintMinorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) { 1132 g.drawLine( 0, y, tickBounds.width / 2 - 1, y ); 1133 } 1134 1135 protected void paintMajorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) { 1136 g.drawLine( 0, y, tickBounds.width - 2, y ); 1137 } 1138 1139 public void paintLabels( Graphics g ) { 1140 Rectangle labelBounds = labelRect; 1141 1142 @SuppressWarnings("rawtypes") 1143 Dictionary dictionary = slider.getLabelTable(); 1144 if ( dictionary != null ) { 1145 Enumeration<?> keys = dictionary.keys(); 1146 int minValue = slider.getMinimum(); 1147 int maxValue = slider.getMaximum(); 1148 boolean enabled = slider.isEnabled(); 1149 while ( keys.hasMoreElements() ) { 1150 Integer key = (Integer)keys.nextElement(); 1151 int value = key.intValue(); 1152 if (value >= minValue && value <= maxValue) { 1153 JComponent label = (JComponent) dictionary.get(key); 1154 label.setEnabled(enabled); 1155 1156 if (label instanceof JLabel) { 1157 Icon icon = label.isEnabled() ? ((JLabel) label).getIcon() : ((JLabel) label).getDisabledIcon(); 1158 1159 if (icon instanceof ImageIcon) { 1160 // Register Slider as an image observer. It allows to catch notifications about 1161 // image changes (e.g. gif animation) 1162 Toolkit.getDefaultToolkit().checkImage(((ImageIcon) icon).getImage(), -1, -1, slider); 1163 } 1164 } 1165 1166 if ( slider.getOrientation() == JSlider.HORIZONTAL ) { 1167 g.translate( 0, labelBounds.y ); 1168 paintHorizontalLabel( g, value, label ); 1169 g.translate( 0, -labelBounds.y ); 1170 } 1171 else { 1172 int offset = 0; 1173 if (!BasicGraphicsUtils.isLeftToRight(slider)) { |