51 * @author Tom Santos |
51 * @author Tom Santos |
52 */ |
52 */ |
53 @SuppressWarnings("serial") // Same-version serialization only |
53 @SuppressWarnings("serial") // Same-version serialization only |
54 public class MetalSliderUI extends BasicSliderUI { |
54 public class MetalSliderUI extends BasicSliderUI { |
55 |
55 |
|
56 /** |
|
57 * The buffer of a tick. |
|
58 */ |
56 protected final int TICK_BUFFER = 4; |
59 protected final int TICK_BUFFER = 4; |
|
60 |
|
61 /** |
|
62 * The value of the property {@code JSlider.isFilled}. |
|
63 * By default, {@code false} if the property is not set, |
|
64 * {@code true} for Ocean theme. |
|
65 */ |
57 protected boolean filledSlider = false; |
66 protected boolean filledSlider = false; |
|
67 |
58 // NOTE: these next five variables are currently unused. |
68 // NOTE: these next five variables are currently unused. |
|
69 /** |
|
70 * The color of a thumb |
|
71 */ |
59 protected static Color thumbColor; |
72 protected static Color thumbColor; |
|
73 |
|
74 /** |
|
75 * The color of highlighting. |
|
76 */ |
60 protected static Color highlightColor; |
77 protected static Color highlightColor; |
|
78 |
|
79 /** |
|
80 * The color of dark shadow. |
|
81 */ |
61 protected static Color darkShadowColor; |
82 protected static Color darkShadowColor; |
|
83 |
|
84 /** |
|
85 * The width of a track. |
|
86 */ |
62 protected static int trackWidth; |
87 protected static int trackWidth; |
|
88 |
|
89 /** |
|
90 * The length of a tick. |
|
91 */ |
63 protected static int tickLength; |
92 protected static int tickLength; |
64 private int safeLength; |
93 private int safeLength; |
65 |
94 |
66 /** |
95 /** |
67 * A default horizontal thumb <code>Icon</code>. This field might not be |
96 * A default horizontal thumb <code>Icon</code>. This field might not be |
78 protected static Icon vertThumbIcon; |
107 protected static Icon vertThumbIcon; |
79 |
108 |
80 private static Icon SAFE_HORIZ_THUMB_ICON; |
109 private static Icon SAFE_HORIZ_THUMB_ICON; |
81 private static Icon SAFE_VERT_THUMB_ICON; |
110 private static Icon SAFE_VERT_THUMB_ICON; |
82 |
111 |
83 |
112 /** |
|
113 * Property for {@code JSlider.isFilled}. |
|
114 */ |
84 protected final String SLIDER_FILL = "JSlider.isFilled"; |
115 protected final String SLIDER_FILL = "JSlider.isFilled"; |
85 |
116 |
|
117 /** |
|
118 * Constructs a {@code MetalSliderUI} instance. |
|
119 * |
|
120 * @param c a component |
|
121 * @return a {@code MetalSliderUI} instance |
|
122 */ |
86 public static ComponentUI createUI(JComponent c) { |
123 public static ComponentUI createUI(JComponent c) { |
87 return new MetalSliderUI(); |
124 return new MetalSliderUI(); |
88 } |
125 } |
89 |
126 |
|
127 /** |
|
128 * Constructs a {@code MetalSliderUI} instance. |
|
129 */ |
90 public MetalSliderUI() { |
130 public MetalSliderUI() { |
91 super( null ); |
131 super( null ); |
92 } |
132 } |
93 |
133 |
94 private static Icon getHorizThumbIcon() { |
134 private static Icon getHorizThumbIcon() { |
124 scrollListener.setScrollByBlock( false ); |
164 scrollListener.setScrollByBlock( false ); |
125 |
165 |
126 prepareFilledSliderField(); |
166 prepareFilledSliderField(); |
127 } |
167 } |
128 |
168 |
|
169 /** |
|
170 * Constructs {@code MetalPropertyListener}. |
|
171 * |
|
172 * @param slider a {@code JSlider} |
|
173 * @return the {@code MetalPropertyListener} |
|
174 */ |
129 protected PropertyChangeListener createPropertyChangeListener( JSlider slider ) { |
175 protected PropertyChangeListener createPropertyChangeListener( JSlider slider ) { |
130 return new MetalPropertyListener(); |
176 return new MetalPropertyListener(); |
131 } |
177 } |
132 |
178 |
|
179 /** |
|
180 * {@code PropertyListener} for {@code JSlider.isFilled}. |
|
181 */ |
133 protected class MetalPropertyListener extends BasicSliderUI.PropertyChangeHandler { |
182 protected class MetalPropertyListener extends BasicSliderUI.PropertyChangeHandler { |
134 public void propertyChange( PropertyChangeEvent e ) { // listen for slider fill |
183 public void propertyChange( PropertyChangeEvent e ) { // listen for slider fill |
135 super.propertyChange( e ); |
184 super.propertyChange( e ); |
136 |
185 |
137 if (e.getPropertyName().equals(SLIDER_FILL)) { |
186 if (e.getPropertyName().equals(SLIDER_FILL)) { |
483 safeLength + TICK_BUFFER + 3; |
532 safeLength + TICK_BUFFER + 3; |
484 } |
533 } |
485 |
534 |
486 /** |
535 /** |
487 * Returns the shorter dimension of the track. |
536 * Returns the shorter dimension of the track. |
|
537 * |
|
538 * @return the shorter dimension of the track |
488 */ |
539 */ |
489 protected int getTrackWidth() { |
540 protected int getTrackWidth() { |
490 // This strange calculation is here to keep the |
541 // This strange calculation is here to keep the |
491 // track in proportion to the thumb. |
542 // track in proportion to the thumb. |
492 final double kIdealTrackWidth = 7.0; |
543 final double kIdealTrackWidth = 7.0; |
502 } |
553 } |
503 |
554 |
504 /** |
555 /** |
505 * Returns the longer dimension of the slide bar. (The slide bar is only the |
556 * Returns the longer dimension of the slide bar. (The slide bar is only the |
506 * part that runs directly under the thumb) |
557 * part that runs directly under the thumb) |
|
558 * |
|
559 * @return the longer dimension of the slide bar |
507 */ |
560 */ |
508 protected int getTrackLength() { |
561 protected int getTrackLength() { |
509 if ( slider.getOrientation() == JSlider.HORIZONTAL ) { |
562 if ( slider.getOrientation() == JSlider.HORIZONTAL ) { |
510 return trackRect.width; |
563 return trackRect.width; |
511 } |
564 } |
512 return trackRect.height; |
565 return trackRect.height; |
513 } |
566 } |
514 |
567 |
515 /** |
568 /** |
516 * Returns the amount that the thumb goes past the slide bar. |
569 * Returns the amount that the thumb goes past the slide bar. |
|
570 * |
|
571 * @return the amount that the thumb goes past the slide bar |
517 */ |
572 */ |
518 protected int getThumbOverhang() { |
573 protected int getThumbOverhang() { |
519 return (int)(getThumbSize().getHeight()-getTrackWidth())/2; |
574 return (int)(getThumbSize().getHeight()-getTrackWidth())/2; |
520 } |
575 } |
521 |
576 |