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 dictionary = slider.getLabelTable(); 401 if (dictionary != null) { 402 sameLabelBaselines = true; 403 Enumeration elements = dictionary.elements(); 404 int baseline = -1; 405 while (elements.hasMoreElements()) { 406 JComponent label = (JComponent) 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; 736 } 737 else { 738 size.width = 11; 739 size.height = 20; 740 } 741 742 return size; 743 } 744 745 public class PropertyChangeHandler implements PropertyChangeListener { 746 // NOTE: This class exists only for backward compatibility. All 747 // its functionality has been moved into Handler. If you need to add 748 // new functionality add it to the Handler, but make sure this 749 // class calls into the Handler. 750 public void propertyChange( PropertyChangeEvent e ) { 751 getHandler().propertyChange(e); 752 } 753 } 754 755 protected int getWidthOfWidestLabel() { 756 Dictionary dictionary = slider.getLabelTable(); 757 int widest = 0; 758 if ( dictionary != null ) { 759 Enumeration keys = dictionary.keys(); 760 while ( keys.hasMoreElements() ) { 761 JComponent label = (JComponent) dictionary.get(keys.nextElement()); 762 widest = Math.max( label.getPreferredSize().width, widest ); 763 } 764 } 765 return widest; 766 } 767 768 protected int getHeightOfTallestLabel() { 769 Dictionary dictionary = slider.getLabelTable(); 770 int tallest = 0; 771 if ( dictionary != null ) { 772 Enumeration keys = dictionary.keys(); 773 while ( keys.hasMoreElements() ) { 774 JComponent label = (JComponent) dictionary.get(keys.nextElement()); 775 tallest = Math.max( label.getPreferredSize().height, tallest ); 776 } 777 } 778 return tallest; 779 } 780 781 protected int getWidthOfHighValueLabel() { 782 Component label = getHighestValueLabel(); 783 int width = 0; 784 785 if ( label != null ) { 786 width = label.getPreferredSize().width; 787 } 788 789 return width; 790 } 791 792 protected int getWidthOfLowValueLabel() { 793 Component label = getLowestValueLabel(); 794 int width = 0; 825 protected boolean drawInverted() { 826 if (slider.getOrientation()==JSlider.HORIZONTAL) { 827 if(BasicGraphicsUtils.isLeftToRight(slider)) { 828 return slider.getInverted(); 829 } else { 830 return !slider.getInverted(); 831 } 832 } else { 833 return slider.getInverted(); 834 } 835 } 836 837 /** 838 * Returns the biggest value that has an entry in the label table. 839 * 840 * @return biggest value that has an entry in the label table, or 841 * null. 842 * @since 1.6 843 */ 844 protected Integer getHighestValue() { 845 Dictionary dictionary = slider.getLabelTable(); 846 847 if (dictionary == null) { 848 return null; 849 } 850 851 Enumeration keys = dictionary.keys(); 852 853 Integer max = null; 854 855 while (keys.hasMoreElements()) { 856 Integer i = (Integer) keys.nextElement(); 857 858 if (max == null || i > max) { 859 max = i; 860 } 861 } 862 863 return max; 864 } 865 866 /** 867 * Returns the smallest value that has an entry in the label table. 868 * 869 * @return smallest value that has an entry in the label table, or 870 * null. 871 * @since 1.6 872 */ 873 protected Integer getLowestValue() { 874 Dictionary dictionary = slider.getLabelTable(); 875 876 if (dictionary == null) { 877 return null; 878 } 879 880 Enumeration keys = dictionary.keys(); 881 882 Integer min = null; 883 884 while (keys.hasMoreElements()) { 885 Integer i = (Integer) keys.nextElement(); 886 887 if (min == null || i < min) { 888 min = i; 889 } 890 } 891 892 return min; 893 } 894 895 896 /** 897 * Returns the label that corresponds to the highest slider value in the label table. 898 * @see JSlider#setLabelTable 899 */ 900 protected Component getLowestValueLabel() { 901 Integer min = getLowestValue(); 902 if (min != null) { 903 return (Component)slider.getLabelTable().get(min); 904 } 905 return null; 1104 1105 protected void paintMinorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) { 1106 g.drawLine( x, 0, x, tickBounds.height / 2 - 1 ); 1107 } 1108 1109 protected void paintMajorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) { 1110 g.drawLine( x, 0, x, tickBounds.height - 2 ); 1111 } 1112 1113 protected void paintMinorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) { 1114 g.drawLine( 0, y, tickBounds.width / 2 - 1, y ); 1115 } 1116 1117 protected void paintMajorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) { 1118 g.drawLine( 0, y, tickBounds.width - 2, y ); 1119 } 1120 1121 public void paintLabels( Graphics g ) { 1122 Rectangle labelBounds = labelRect; 1123 1124 Dictionary dictionary = slider.getLabelTable(); 1125 if ( dictionary != null ) { 1126 Enumeration keys = dictionary.keys(); 1127 int minValue = slider.getMinimum(); 1128 int maxValue = slider.getMaximum(); 1129 boolean enabled = slider.isEnabled(); 1130 while ( keys.hasMoreElements() ) { 1131 Integer key = (Integer)keys.nextElement(); 1132 int value = key.intValue(); 1133 if (value >= minValue && value <= maxValue) { 1134 JComponent label = (JComponent) dictionary.get(key); 1135 label.setEnabled(enabled); 1136 1137 if (label instanceof JLabel) { 1138 Icon icon = label.isEnabled() ? ((JLabel) label).getIcon() : ((JLabel) label).getDisabledIcon(); 1139 1140 if (icon instanceof ImageIcon) { 1141 // Register Slider as an image observer. It allows to catch notifications about 1142 // image changes (e.g. gif animation) 1143 Toolkit.getDefaultToolkit().checkImage(((ImageIcon) icon).getImage(), -1, -1, slider); 1144 } 1145 } 1146 1147 if ( slider.getOrientation() == JSlider.HORIZONTAL ) { 1148 g.translate( 0, labelBounds.y ); 1149 paintHorizontalLabel( g, value, label ); 1150 g.translate( 0, -labelBounds.y ); 1151 } 1152 else { 1153 int offset = 0; 1154 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 Dictionary<?, JComponent> dictionary = slider.getLabelTable(); 401 if (dictionary != null) { 402 sameLabelBaselines = true; 403 Enumeration<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; 736 } 737 else { 738 size.width = 11; 739 size.height = 20; 740 } 741 742 return size; 743 } 744 745 public class PropertyChangeHandler implements PropertyChangeListener { 746 // NOTE: This class exists only for backward compatibility. All 747 // its functionality has been moved into Handler. If you need to add 748 // new functionality add it to the Handler, but make sure this 749 // class calls into the Handler. 750 public void propertyChange( PropertyChangeEvent e ) { 751 getHandler().propertyChange(e); 752 } 753 } 754 755 protected int getWidthOfWidestLabel() { 756 Dictionary<?, JComponent> dictionary = slider.getLabelTable(); 757 int widest = 0; 758 if ( dictionary != null ) { 759 Enumeration<?> keys = dictionary.keys(); 760 while ( keys.hasMoreElements() ) { 761 JComponent label = dictionary.get(keys.nextElement()); 762 widest = Math.max( label.getPreferredSize().width, widest ); 763 } 764 } 765 return widest; 766 } 767 768 protected int getHeightOfTallestLabel() { 769 Dictionary<?, JComponent> dictionary = slider.getLabelTable(); 770 int tallest = 0; 771 if ( dictionary != null ) { 772 Enumeration<?> keys = dictionary.keys(); 773 while ( keys.hasMoreElements() ) { 774 JComponent label = dictionary.get(keys.nextElement()); 775 tallest = Math.max( label.getPreferredSize().height, tallest ); 776 } 777 } 778 return tallest; 779 } 780 781 protected int getWidthOfHighValueLabel() { 782 Component label = getHighestValueLabel(); 783 int width = 0; 784 785 if ( label != null ) { 786 width = label.getPreferredSize().width; 787 } 788 789 return width; 790 } 791 792 protected int getWidthOfLowValueLabel() { 793 Component label = getLowestValueLabel(); 794 int width = 0; 825 protected boolean drawInverted() { 826 if (slider.getOrientation()==JSlider.HORIZONTAL) { 827 if(BasicGraphicsUtils.isLeftToRight(slider)) { 828 return slider.getInverted(); 829 } else { 830 return !slider.getInverted(); 831 } 832 } else { 833 return slider.getInverted(); 834 } 835 } 836 837 /** 838 * Returns the biggest value that has an entry in the label table. 839 * 840 * @return biggest value that has an entry in the label table, or 841 * null. 842 * @since 1.6 843 */ 844 protected Integer getHighestValue() { 845 Dictionary<Integer, ?> dictionary = slider.getLabelTable(); 846 847 if (dictionary == null) { 848 return null; 849 } 850 851 Enumeration<Integer> keys = dictionary.keys(); 852 853 Integer max = null; 854 855 while (keys.hasMoreElements()) { 856 Integer i = keys.nextElement(); 857 858 if (max == null || i > max) { 859 max = i; 860 } 861 } 862 863 return max; 864 } 865 866 /** 867 * Returns the smallest value that has an entry in the label table. 868 * 869 * @return smallest value that has an entry in the label table, or 870 * null. 871 * @since 1.6 872 */ 873 protected Integer getLowestValue() { 874 Dictionary<Integer, JComponent> dictionary = slider.getLabelTable(); 875 876 if (dictionary == null) { 877 return null; 878 } 879 880 Enumeration<Integer> keys = dictionary.keys(); 881 882 Integer min = null; 883 884 while (keys.hasMoreElements()) { 885 Integer i = keys.nextElement(); 886 887 if (min == null || i < min) { 888 min = i; 889 } 890 } 891 892 return min; 893 } 894 895 896 /** 897 * Returns the label that corresponds to the highest slider value in the label table. 898 * @see JSlider#setLabelTable 899 */ 900 protected Component getLowestValueLabel() { 901 Integer min = getLowestValue(); 902 if (min != null) { 903 return (Component)slider.getLabelTable().get(min); 904 } 905 return null; 1104 1105 protected void paintMinorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) { 1106 g.drawLine( x, 0, x, tickBounds.height / 2 - 1 ); 1107 } 1108 1109 protected void paintMajorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) { 1110 g.drawLine( x, 0, x, tickBounds.height - 2 ); 1111 } 1112 1113 protected void paintMinorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) { 1114 g.drawLine( 0, y, tickBounds.width / 2 - 1, y ); 1115 } 1116 1117 protected void paintMajorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) { 1118 g.drawLine( 0, y, tickBounds.width - 2, y ); 1119 } 1120 1121 public void paintLabels( Graphics g ) { 1122 Rectangle labelBounds = labelRect; 1123 1124 Dictionary<Integer, JComponent> dictionary = slider.getLabelTable(); 1125 if ( dictionary != null ) { 1126 Enumeration<Integer> keys = dictionary.keys(); 1127 int minValue = slider.getMinimum(); 1128 int maxValue = slider.getMaximum(); 1129 boolean enabled = slider.isEnabled(); 1130 while ( keys.hasMoreElements() ) { 1131 Integer key = keys.nextElement(); 1132 int value = key.intValue(); 1133 if (value >= minValue && value <= maxValue) { 1134 JComponent label = dictionary.get(key); 1135 label.setEnabled(enabled); 1136 1137 if (label instanceof JLabel) { 1138 Icon icon = label.isEnabled() ? ((JLabel) label).getIcon() : ((JLabel) label).getDisabledIcon(); 1139 1140 if (icon instanceof ImageIcon) { 1141 // Register Slider as an image observer. It allows to catch notifications about 1142 // image changes (e.g. gif animation) 1143 Toolkit.getDefaultToolkit().checkImage(((ImageIcon) icon).getImage(), -1, -1, slider); 1144 } 1145 } 1146 1147 if ( slider.getOrientation() == JSlider.HORIZONTAL ) { 1148 g.translate( 0, labelBounds.y ); 1149 paintHorizontalLabel( g, value, label ); 1150 g.translate( 0, -labelBounds.y ); 1151 } 1152 else { 1153 int offset = 0; 1154 if (!BasicGraphicsUtils.isLeftToRight(slider)) { |