author | pkbalakr |
Fri, 09 Sep 2016 13:15:10 +0530 | |
changeset 41007 | d48361243925 |
parent 30461 | 57e36ed1a9ab |
permissions | -rw-r--r-- |
2 | 1 |
/* |
41007
d48361243925
8009477: PageUp and PageDown keyboard buttons don't move slider indicator to next minor tick
pkbalakr
parents:
30461
diff
changeset
|
2 |
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package javax.swing.plaf.basic; |
|
27 |
||
28 |
import java.awt.event.*; |
|
677
20718977427b
4987336: JSlider doesn't show label's animated icon
rupashka
parents:
676
diff
changeset
|
29 |
import java.awt.*; |
2 | 30 |
import java.beans.*; |
31 |
import java.util.Dictionary; |
|
32 |
import java.util.Enumeration; |
|
33 |
||
34 |
import javax.swing.*; |
|
35 |
import javax.swing.event.*; |
|
36 |
import javax.swing.plaf.*; |
|
37 |
import sun.swing.DefaultLookup; |
|
38 |
import sun.swing.UIAction; |
|
39 |
||
40 |
||
41 |
/** |
|
20169 | 42 |
* A Basic L&F implementation of SliderUI. |
2 | 43 |
* |
44 |
* @author Tom Santos |
|
45 |
*/ |
|
46 |
public class BasicSliderUI extends SliderUI{ |
|
47 |
// Old actions forward to an instance of this. |
|
48 |
private static final Actions SHARED_ACTION = new Actions(); |
|
49 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
50 |
/** Positive scroll */ |
2 | 51 |
public static final int POSITIVE_SCROLL = +1; |
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
52 |
/** Negative scroll */ |
2 | 53 |
public static final int NEGATIVE_SCROLL = -1; |
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
54 |
/** Minimum scroll */ |
2 | 55 |
public static final int MIN_SCROLL = -2; |
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
56 |
/** Maximum scroll */ |
2 | 57 |
public static final int MAX_SCROLL = +2; |
58 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
59 |
/** Scroll timer */ |
2 | 60 |
protected Timer scrollTimer; |
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
61 |
/** Slider */ |
2 | 62 |
protected JSlider slider; |
63 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
64 |
/** Focus insets */ |
2 | 65 |
protected Insets focusInsets = null; |
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
66 |
/** Inset cache */ |
2 | 67 |
protected Insets insetCache = null; |
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
68 |
/** Left-to-right cache */ |
2 | 69 |
protected boolean leftToRightCache = true; |
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
70 |
/** Focus rectangle */ |
2 | 71 |
protected Rectangle focusRect = null; |
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
72 |
/** Content rectangle */ |
2 | 73 |
protected Rectangle contentRect = null; |
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
74 |
/** Label rectangle */ |
2 | 75 |
protected Rectangle labelRect = null; |
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
76 |
/** Tick rectangle */ |
2 | 77 |
protected Rectangle tickRect = null; |
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
78 |
/** Track rectangle */ |
2 | 79 |
protected Rectangle trackRect = null; |
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
80 |
/** Thumb rectangle */ |
2 | 81 |
protected Rectangle thumbRect = null; |
82 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
83 |
/** The distance that the track is from the side of the control */ |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
84 |
protected int trackBuffer = 0; |
2 | 85 |
|
86 |
private transient boolean isDragging; |
|
87 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
88 |
/** Track listener */ |
2 | 89 |
protected TrackListener trackListener; |
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
90 |
/** Change listener */ |
2 | 91 |
protected ChangeListener changeListener; |
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
92 |
/** Component listener */ |
2 | 93 |
protected ComponentListener componentListener; |
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
94 |
/** Focus listener */ |
2 | 95 |
protected FocusListener focusListener; |
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
96 |
/** Scroll listener */ |
2 | 97 |
protected ScrollListener scrollListener; |
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
98 |
/** Property chane listener */ |
2 | 99 |
protected PropertyChangeListener propertyChangeListener; |
100 |
private Handler handler; |
|
101 |
private int lastValue; |
|
102 |
||
103 |
// Colors |
|
104 |
private Color shadowColor; |
|
105 |
private Color highlightColor; |
|
106 |
private Color focusColor; |
|
107 |
||
108 |
/** |
|
109 |
* Whther or not sameLabelBaselines is up to date. |
|
110 |
*/ |
|
111 |
private boolean checkedLabelBaselines; |
|
112 |
/** |
|
113 |
* Whether or not all the entries in the labeltable have the same |
|
114 |
* baseline. |
|
115 |
*/ |
|
116 |
private boolean sameLabelBaselines; |
|
117 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
118 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
119 |
* Returns the shadow color. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
120 |
* @return the shadow color |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
121 |
*/ |
2 | 122 |
protected Color getShadowColor() { |
123 |
return shadowColor; |
|
124 |
} |
|
125 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
126 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
127 |
* Returns the highlight color. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
128 |
* @return the highlight color |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
129 |
*/ |
2 | 130 |
protected Color getHighlightColor() { |
131 |
return highlightColor; |
|
132 |
} |
|
133 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
134 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
135 |
* Returns the focus color. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
136 |
* @return the focus color |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
137 |
*/ |
2 | 138 |
protected Color getFocusColor() { |
139 |
return focusColor; |
|
140 |
} |
|
141 |
||
142 |
/** |
|
143 |
* Returns true if the user is dragging the slider. |
|
144 |
* |
|
145 |
* @return true if the user is dragging the slider |
|
146 |
* @since 1.5 |
|
147 |
*/ |
|
148 |
protected boolean isDragging() { |
|
149 |
return isDragging; |
|
150 |
} |
|
151 |
||
152 |
///////////////////////////////////////////////////////////////////////////// |
|
153 |
// ComponentUI Interface Implementation methods |
|
154 |
///////////////////////////////////////////////////////////////////////////// |
|
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
155 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
156 |
* Creates a UI. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
157 |
* @param b a component |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
158 |
* @return a UI |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
159 |
*/ |
2 | 160 |
public static ComponentUI createUI(JComponent b) { |
161 |
return new BasicSliderUI((JSlider)b); |
|
162 |
} |
|
163 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
164 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
165 |
* Constructs a {@code BasicSliderUI}. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
166 |
* @param b a slider |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
167 |
*/ |
2 | 168 |
public BasicSliderUI(JSlider b) { |
169 |
} |
|
170 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
171 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
172 |
* Installs a UI. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
173 |
* @param c a component |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
174 |
*/ |
2 | 175 |
public void installUI(JComponent c) { |
176 |
slider = (JSlider) c; |
|
177 |
||
178 |
checkedLabelBaselines = false; |
|
179 |
||
180 |
slider.setEnabled(slider.isEnabled()); |
|
181 |
LookAndFeel.installProperty(slider, "opaque", Boolean.TRUE); |
|
182 |
||
183 |
isDragging = false; |
|
184 |
trackListener = createTrackListener( slider ); |
|
185 |
changeListener = createChangeListener( slider ); |
|
186 |
componentListener = createComponentListener( slider ); |
|
187 |
focusListener = createFocusListener( slider ); |
|
188 |
scrollListener = createScrollListener( slider ); |
|
189 |
propertyChangeListener = createPropertyChangeListener( slider ); |
|
190 |
||
191 |
installDefaults( slider ); |
|
192 |
installListeners( slider ); |
|
193 |
installKeyboardActions( slider ); |
|
194 |
||
195 |
scrollTimer = new Timer( 100, scrollListener ); |
|
196 |
scrollTimer.setInitialDelay( 300 ); |
|
197 |
||
198 |
insetCache = slider.getInsets(); |
|
199 |
leftToRightCache = BasicGraphicsUtils.isLeftToRight(slider); |
|
200 |
focusRect = new Rectangle(); |
|
201 |
contentRect = new Rectangle(); |
|
202 |
labelRect = new Rectangle(); |
|
203 |
tickRect = new Rectangle(); |
|
204 |
trackRect = new Rectangle(); |
|
205 |
thumbRect = new Rectangle(); |
|
206 |
lastValue = slider.getValue(); |
|
207 |
||
208 |
calculateGeometry(); // This figures out where the labels, ticks, track, and thumb are. |
|
209 |
} |
|
210 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
211 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
212 |
* Uninstalls a UI. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
213 |
* @param c a component |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
214 |
*/ |
2 | 215 |
public void uninstallUI(JComponent c) { |
216 |
if ( c != slider ) |
|
217 |
throw new IllegalComponentStateException( |
|
218 |
this + " was asked to deinstall() " |
|
219 |
+ c + " when it only knows about " |
|
220 |
+ slider + "."); |
|
221 |
||
222 |
scrollTimer.stop(); |
|
223 |
scrollTimer = null; |
|
224 |
||
4963
004eaf21ba24
6918861: SynthSliderUI.uninstallDefaults() is not called when UI is uninstalled
rupashka
parents:
4957
diff
changeset
|
225 |
uninstallDefaults(slider); |
2 | 226 |
uninstallListeners( slider ); |
227 |
uninstallKeyboardActions(slider); |
|
228 |
||
229 |
insetCache = null; |
|
230 |
leftToRightCache = true; |
|
231 |
focusRect = null; |
|
232 |
contentRect = null; |
|
233 |
labelRect = null; |
|
234 |
tickRect = null; |
|
235 |
trackRect = null; |
|
236 |
thumbRect = null; |
|
237 |
trackListener = null; |
|
238 |
changeListener = null; |
|
239 |
componentListener = null; |
|
240 |
focusListener = null; |
|
241 |
scrollListener = null; |
|
242 |
propertyChangeListener = null; |
|
243 |
slider = null; |
|
244 |
} |
|
245 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
246 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
247 |
* Installs the defaults. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
248 |
* @param slider a slider |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
249 |
*/ |
2 | 250 |
protected void installDefaults( JSlider slider ) { |
251 |
LookAndFeel.installBorder(slider, "Slider.border"); |
|
252 |
LookAndFeel.installColorsAndFont(slider, "Slider.background", |
|
253 |
"Slider.foreground", "Slider.font"); |
|
254 |
highlightColor = UIManager.getColor("Slider.highlight"); |
|
255 |
||
256 |
shadowColor = UIManager.getColor("Slider.shadow"); |
|
257 |
focusColor = UIManager.getColor("Slider.focus"); |
|
258 |
||
259 |
focusInsets = (Insets)UIManager.get( "Slider.focusInsets" ); |
|
2658 | 260 |
// use default if missing so that BasicSliderUI can be used in other |
261 |
// LAFs like Nimbus |
|
262 |
if (focusInsets == null) focusInsets = new InsetsUIResource(2,2,2,2); |
|
2 | 263 |
} |
264 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
265 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
266 |
* Uninstalls the defaults. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
267 |
* @param slider a slider |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
268 |
*/ |
4963
004eaf21ba24
6918861: SynthSliderUI.uninstallDefaults() is not called when UI is uninstalled
rupashka
parents:
4957
diff
changeset
|
269 |
protected void uninstallDefaults(JSlider slider) { |
004eaf21ba24
6918861: SynthSliderUI.uninstallDefaults() is not called when UI is uninstalled
rupashka
parents:
4957
diff
changeset
|
270 |
LookAndFeel.uninstallBorder(slider); |
004eaf21ba24
6918861: SynthSliderUI.uninstallDefaults() is not called when UI is uninstalled
rupashka
parents:
4957
diff
changeset
|
271 |
|
004eaf21ba24
6918861: SynthSliderUI.uninstallDefaults() is not called when UI is uninstalled
rupashka
parents:
4957
diff
changeset
|
272 |
focusInsets = null; |
004eaf21ba24
6918861: SynthSliderUI.uninstallDefaults() is not called when UI is uninstalled
rupashka
parents:
4957
diff
changeset
|
273 |
} |
004eaf21ba24
6918861: SynthSliderUI.uninstallDefaults() is not called when UI is uninstalled
rupashka
parents:
4957
diff
changeset
|
274 |
|
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
275 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
276 |
* Creates a track listener. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
277 |
* @return a track listener |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
278 |
* @param slider a slider |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
279 |
*/ |
2 | 280 |
protected TrackListener createTrackListener(JSlider slider) { |
281 |
return new TrackListener(); |
|
282 |
} |
|
283 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
284 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
285 |
* Creates a change listener. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
286 |
* @return a change listener |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
287 |
* @param slider a slider |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
288 |
*/ |
2 | 289 |
protected ChangeListener createChangeListener(JSlider slider) { |
290 |
return getHandler(); |
|
291 |
} |
|
292 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
293 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
294 |
* Creates a composite listener. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
295 |
* @return a composite listener |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
296 |
* @param slider a slider |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
297 |
*/ |
2 | 298 |
protected ComponentListener createComponentListener(JSlider slider) { |
299 |
return getHandler(); |
|
300 |
} |
|
301 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
302 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
303 |
* Creates a focus listener. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
304 |
* @return a focus listener |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
305 |
* @param slider a slider |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
306 |
*/ |
2 | 307 |
protected FocusListener createFocusListener(JSlider slider) { |
308 |
return getHandler(); |
|
309 |
} |
|
310 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
311 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
312 |
* Creates a scroll listener. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
313 |
* @return a scroll listener |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
314 |
* @param slider a slider |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
315 |
*/ |
2 | 316 |
protected ScrollListener createScrollListener( JSlider slider ) { |
317 |
return new ScrollListener(); |
|
318 |
} |
|
319 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
320 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
321 |
* Creates a property change listener. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
322 |
* @return a property change listener |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
323 |
* @param slider a slider |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
324 |
*/ |
2 | 325 |
protected PropertyChangeListener createPropertyChangeListener( |
326 |
JSlider slider) { |
|
327 |
return getHandler(); |
|
328 |
} |
|
329 |
||
330 |
private Handler getHandler() { |
|
331 |
if (handler == null) { |
|
332 |
handler = new Handler(); |
|
333 |
} |
|
334 |
return handler; |
|
335 |
} |
|
336 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
337 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
338 |
* Installs listeners. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
339 |
* @param slider a slider |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
340 |
*/ |
2 | 341 |
protected void installListeners( JSlider slider ) { |
342 |
slider.addMouseListener(trackListener); |
|
343 |
slider.addMouseMotionListener(trackListener); |
|
344 |
slider.addFocusListener(focusListener); |
|
345 |
slider.addComponentListener(componentListener); |
|
346 |
slider.addPropertyChangeListener( propertyChangeListener ); |
|
347 |
slider.getModel().addChangeListener(changeListener); |
|
348 |
} |
|
349 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
350 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
351 |
* Uninstalls listeners. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
352 |
* @param slider a slider |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
353 |
*/ |
2 | 354 |
protected void uninstallListeners( JSlider slider ) { |
355 |
slider.removeMouseListener(trackListener); |
|
356 |
slider.removeMouseMotionListener(trackListener); |
|
357 |
slider.removeFocusListener(focusListener); |
|
358 |
slider.removeComponentListener(componentListener); |
|
359 |
slider.removePropertyChangeListener( propertyChangeListener ); |
|
360 |
slider.getModel().removeChangeListener(changeListener); |
|
361 |
handler = null; |
|
362 |
} |
|
363 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
364 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
365 |
* Installs keyboard actions. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
366 |
* @param slider a slider |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
367 |
*/ |
2 | 368 |
protected void installKeyboardActions( JSlider slider ) { |
369 |
InputMap km = getInputMap(JComponent.WHEN_FOCUSED, slider); |
|
370 |
SwingUtilities.replaceUIInputMap(slider, JComponent.WHEN_FOCUSED, km); |
|
371 |
LazyActionMap.installLazyActionMap(slider, BasicSliderUI.class, |
|
372 |
"Slider.actionMap"); |
|
373 |
} |
|
374 |
||
375 |
InputMap getInputMap(int condition, JSlider slider) { |
|
376 |
if (condition == JComponent.WHEN_FOCUSED) { |
|
377 |
InputMap keyMap = (InputMap)DefaultLookup.get(slider, this, |
|
378 |
"Slider.focusInputMap"); |
|
379 |
InputMap rtlKeyMap; |
|
380 |
||
381 |
if (slider.getComponentOrientation().isLeftToRight() || |
|
382 |
((rtlKeyMap = (InputMap)DefaultLookup.get(slider, this, |
|
383 |
"Slider.focusInputMap.RightToLeft")) == null)) { |
|
384 |
return keyMap; |
|
385 |
} else { |
|
386 |
rtlKeyMap.setParent(keyMap); |
|
387 |
return rtlKeyMap; |
|
388 |
} |
|
389 |
} |
|
390 |
return null; |
|
391 |
} |
|
392 |
||
393 |
/** |
|
394 |
* Populates ComboBox's actions. |
|
395 |
*/ |
|
396 |
static void loadActionMap(LazyActionMap map) { |
|
397 |
map.put(new Actions(Actions.POSITIVE_UNIT_INCREMENT)); |
|
398 |
map.put(new Actions(Actions.POSITIVE_BLOCK_INCREMENT)); |
|
399 |
map.put(new Actions(Actions.NEGATIVE_UNIT_INCREMENT)); |
|
400 |
map.put(new Actions(Actions.NEGATIVE_BLOCK_INCREMENT)); |
|
401 |
map.put(new Actions(Actions.MIN_SCROLL_INCREMENT)); |
|
402 |
map.put(new Actions(Actions.MAX_SCROLL_INCREMENT)); |
|
403 |
} |
|
404 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
405 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
406 |
* Uninstalls keyboard actions. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
407 |
* @param slider a slider |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
408 |
*/ |
2 | 409 |
protected void uninstallKeyboardActions( JSlider slider ) { |
410 |
SwingUtilities.replaceUIActionMap(slider, null); |
|
411 |
SwingUtilities.replaceUIInputMap(slider, JComponent.WHEN_FOCUSED, |
|
412 |
null); |
|
413 |
} |
|
414 |
||
415 |
||
416 |
/** |
|
417 |
* Returns the baseline. |
|
418 |
* |
|
419 |
* @throws NullPointerException {@inheritDoc} |
|
420 |
* @throws IllegalArgumentException {@inheritDoc} |
|
421 |
* @see javax.swing.JComponent#getBaseline(int, int) |
|
422 |
* @since 1.6 |
|
423 |
*/ |
|
424 |
public int getBaseline(JComponent c, int width, int height) { |
|
425 |
super.getBaseline(c, width, height); |
|
426 |
if (slider.getPaintLabels() && labelsHaveSameBaselines()) { |
|
427 |
FontMetrics metrics = slider.getFontMetrics(slider.getFont()); |
|
428 |
Insets insets = slider.getInsets(); |
|
429 |
Dimension thumbSize = getThumbSize(); |
|
430 |
if (slider.getOrientation() == JSlider.HORIZONTAL) { |
|
431 |
int tickLength = getTickLength(); |
|
432 |
int contentHeight = height - insets.top - insets.bottom - |
|
433 |
focusInsets.top - focusInsets.bottom; |
|
434 |
int thumbHeight = thumbSize.height; |
|
435 |
int centerSpacing = thumbHeight; |
|
436 |
if (slider.getPaintTicks()) { |
|
437 |
centerSpacing += tickLength; |
|
438 |
} |
|
439 |
// Assume uniform labels. |
|
440 |
centerSpacing += getHeightOfTallestLabel(); |
|
441 |
int trackY = insets.top + focusInsets.top + |
|
442 |
(contentHeight - centerSpacing - 1) / 2; |
|
443 |
int trackHeight = thumbHeight; |
|
444 |
int tickY = trackY + trackHeight; |
|
445 |
int tickHeight = tickLength; |
|
446 |
if (!slider.getPaintTicks()) { |
|
447 |
tickHeight = 0; |
|
448 |
} |
|
449 |
int labelY = tickY + tickHeight; |
|
450 |
return labelY + metrics.getAscent(); |
|
451 |
} |
|
452 |
else { // vertical |
|
453 |
boolean inverted = slider.getInverted(); |
|
454 |
Integer value = inverted ? getLowestValue() : |
|
455 |
getHighestValue(); |
|
456 |
if (value != null) { |
|
457 |
int thumbHeight = thumbSize.height; |
|
458 |
int trackBuffer = Math.max(metrics.getHeight() / 2, |
|
459 |
thumbHeight / 2); |
|
460 |
int contentY = focusInsets.top + insets.top; |
|
461 |
int trackY = contentY + trackBuffer; |
|
462 |
int trackHeight = height - focusInsets.top - |
|
463 |
focusInsets.bottom - insets.top - insets.bottom - |
|
464 |
trackBuffer - trackBuffer; |
|
465 |
int yPosition = yPositionForValue(value, trackY, |
|
466 |
trackHeight); |
|
467 |
return yPosition - metrics.getHeight() / 2 + |
|
468 |
metrics.getAscent(); |
|
469 |
} |
|
470 |
} |
|
471 |
} |
|
472 |
return 0; |
|
473 |
} |
|
474 |
||
475 |
/** |
|
476 |
* Returns an enum indicating how the baseline of the component |
|
477 |
* changes as the size changes. |
|
478 |
* |
|
479 |
* @throws NullPointerException {@inheritDoc} |
|
480 |
* @see javax.swing.JComponent#getBaseline(int, int) |
|
481 |
* @since 1.6 |
|
482 |
*/ |
|
483 |
public Component.BaselineResizeBehavior getBaselineResizeBehavior( |
|
484 |
JComponent c) { |
|
485 |
super.getBaselineResizeBehavior(c); |
|
486 |
// NOTE: BasicSpinner really provides for CENTER_OFFSET, but |
|
487 |
// the default min/pref size is smaller than it should be |
|
488 |
// so that getBaseline() doesn't implement the contract |
|
489 |
// for CENTER_OFFSET as defined in Component. |
|
490 |
return Component.BaselineResizeBehavior.OTHER; |
|
491 |
} |
|
492 |
||
493 |
/** |
|
494 |
* Returns true if all the labels from the label table have the same |
|
495 |
* baseline. |
|
496 |
* |
|
497 |
* @return true if all the labels from the label table have the |
|
498 |
* same baseline |
|
499 |
* @since 1.6 |
|
500 |
*/ |
|
501 |
protected boolean labelsHaveSameBaselines() { |
|
502 |
if (!checkedLabelBaselines) { |
|
503 |
checkedLabelBaselines = true; |
|
26352
fa12363e21d6
8055254: Address source incompatability of JSlider generification
darcy
parents:
26351
diff
changeset
|
504 |
@SuppressWarnings("rawtypes") |
fa12363e21d6
8055254: Address source incompatability of JSlider generification
darcy
parents:
26351
diff
changeset
|
505 |
Dictionary dictionary = slider.getLabelTable(); |
2 | 506 |
if (dictionary != null) { |
507 |
sameLabelBaselines = true; |
|
26352
fa12363e21d6
8055254: Address source incompatability of JSlider generification
darcy
parents:
26351
diff
changeset
|
508 |
Enumeration<?> elements = dictionary.elements(); |
2 | 509 |
int baseline = -1; |
510 |
while (elements.hasMoreElements()) { |
|
26352
fa12363e21d6
8055254: Address source incompatability of JSlider generification
darcy
parents:
26351
diff
changeset
|
511 |
JComponent label = (JComponent) elements.nextElement(); |
2 | 512 |
Dimension pref = label.getPreferredSize(); |
513 |
int labelBaseline = label.getBaseline(pref.width, |
|
514 |
pref.height); |
|
515 |
if (labelBaseline >= 0) { |
|
516 |
if (baseline == -1) { |
|
517 |
baseline = labelBaseline; |
|
518 |
} |
|
519 |
else if (baseline != labelBaseline) { |
|
520 |
sameLabelBaselines = false; |
|
521 |
break; |
|
522 |
} |
|
523 |
} |
|
524 |
else { |
|
525 |
sameLabelBaselines = false; |
|
526 |
break; |
|
527 |
} |
|
528 |
} |
|
529 |
} |
|
530 |
else { |
|
531 |
sameLabelBaselines = false; |
|
532 |
} |
|
533 |
} |
|
534 |
return sameLabelBaselines; |
|
535 |
} |
|
536 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
537 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
538 |
* Returns the preferred horizontal size. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
539 |
* @return the preferred horizontal size |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
540 |
*/ |
2 | 541 |
public Dimension getPreferredHorizontalSize() { |
542 |
Dimension horizDim = (Dimension)DefaultLookup.get(slider, |
|
543 |
this, "Slider.horizontalSize"); |
|
544 |
if (horizDim == null) { |
|
545 |
horizDim = new Dimension(200, 21); |
|
546 |
} |
|
547 |
return horizDim; |
|
548 |
} |
|
549 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
550 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
551 |
* Returns the preferred vertical size. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
552 |
* @return the preferred vertical size |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
553 |
*/ |
2 | 554 |
public Dimension getPreferredVerticalSize() { |
555 |
Dimension vertDim = (Dimension)DefaultLookup.get(slider, |
|
556 |
this, "Slider.verticalSize"); |
|
557 |
if (vertDim == null) { |
|
558 |
vertDim = new Dimension(21, 200); |
|
559 |
} |
|
560 |
return vertDim; |
|
561 |
} |
|
562 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
563 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
564 |
* Returns the minimum horizontal size. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
565 |
* @return the minimum horizontal size |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
566 |
*/ |
2 | 567 |
public Dimension getMinimumHorizontalSize() { |
568 |
Dimension minHorizDim = (Dimension)DefaultLookup.get(slider, |
|
569 |
this, "Slider.minimumHorizontalSize"); |
|
570 |
if (minHorizDim == null) { |
|
571 |
minHorizDim = new Dimension(36, 21); |
|
572 |
} |
|
573 |
return minHorizDim; |
|
574 |
} |
|
575 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
576 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
577 |
* Returns the minimum vertical size. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
578 |
* @return the minimum vertical size |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
579 |
*/ |
2 | 580 |
public Dimension getMinimumVerticalSize() { |
581 |
Dimension minVertDim = (Dimension)DefaultLookup.get(slider, |
|
582 |
this, "Slider.minimumVerticalSize"); |
|
583 |
if (minVertDim == null) { |
|
584 |
minVertDim = new Dimension(21, 36); |
|
585 |
} |
|
586 |
return minVertDim; |
|
587 |
} |
|
588 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
589 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
590 |
* Returns the preferred size. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
591 |
* @param c a component |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
592 |
* @return the preferred size |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
593 |
*/ |
2 | 594 |
public Dimension getPreferredSize(JComponent c) { |
595 |
recalculateIfInsetsChanged(); |
|
596 |
Dimension d; |
|
597 |
if ( slider.getOrientation() == JSlider.VERTICAL ) { |
|
598 |
d = new Dimension(getPreferredVerticalSize()); |
|
599 |
d.width = insetCache.left + insetCache.right; |
|
600 |
d.width += focusInsets.left + focusInsets.right; |
|
601 |
d.width += trackRect.width + tickRect.width + labelRect.width; |
|
602 |
} |
|
603 |
else { |
|
604 |
d = new Dimension(getPreferredHorizontalSize()); |
|
605 |
d.height = insetCache.top + insetCache.bottom; |
|
606 |
d.height += focusInsets.top + focusInsets.bottom; |
|
607 |
d.height += trackRect.height + tickRect.height + labelRect.height; |
|
608 |
} |
|
609 |
||
610 |
return d; |
|
611 |
} |
|
612 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
613 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
614 |
* Returns the minimum size. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
615 |
* @param c a component |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
616 |
* @return the minimum size |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
617 |
*/ |
2 | 618 |
public Dimension getMinimumSize(JComponent c) { |
619 |
recalculateIfInsetsChanged(); |
|
620 |
Dimension d; |
|
621 |
||
622 |
if ( slider.getOrientation() == JSlider.VERTICAL ) { |
|
623 |
d = new Dimension(getMinimumVerticalSize()); |
|
624 |
d.width = insetCache.left + insetCache.right; |
|
625 |
d.width += focusInsets.left + focusInsets.right; |
|
626 |
d.width += trackRect.width + tickRect.width + labelRect.width; |
|
627 |
} |
|
628 |
else { |
|
629 |
d = new Dimension(getMinimumHorizontalSize()); |
|
630 |
d.height = insetCache.top + insetCache.bottom; |
|
631 |
d.height += focusInsets.top + focusInsets.bottom; |
|
632 |
d.height += trackRect.height + tickRect.height + labelRect.height; |
|
633 |
} |
|
634 |
||
635 |
return d; |
|
636 |
} |
|
637 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
638 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
639 |
* Returns the maximum size. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
640 |
* @param c a component |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
641 |
* @return the maximum size |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
642 |
*/ |
2 | 643 |
public Dimension getMaximumSize(JComponent c) { |
644 |
Dimension d = getPreferredSize(c); |
|
645 |
if ( slider.getOrientation() == JSlider.VERTICAL ) { |
|
646 |
d.height = Short.MAX_VALUE; |
|
647 |
} |
|
648 |
else { |
|
649 |
d.width = Short.MAX_VALUE; |
|
650 |
} |
|
651 |
||
652 |
return d; |
|
653 |
} |
|
654 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
655 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
656 |
* Calculates the geometry. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
657 |
*/ |
2 | 658 |
protected void calculateGeometry() { |
659 |
calculateFocusRect(); |
|
660 |
calculateContentRect(); |
|
661 |
calculateThumbSize(); |
|
662 |
calculateTrackBuffer(); |
|
663 |
calculateTrackRect(); |
|
664 |
calculateTickRect(); |
|
665 |
calculateLabelRect(); |
|
666 |
calculateThumbLocation(); |
|
667 |
} |
|
668 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
669 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
670 |
* Calculates the focus rectangle. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
671 |
*/ |
2 | 672 |
protected void calculateFocusRect() { |
673 |
focusRect.x = insetCache.left; |
|
674 |
focusRect.y = insetCache.top; |
|
675 |
focusRect.width = slider.getWidth() - (insetCache.left + insetCache.right); |
|
676 |
focusRect.height = slider.getHeight() - (insetCache.top + insetCache.bottom); |
|
677 |
} |
|
678 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
679 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
680 |
* Calculates the thumb size rectangle. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
681 |
*/ |
2 | 682 |
protected void calculateThumbSize() { |
683 |
Dimension size = getThumbSize(); |
|
684 |
thumbRect.setSize( size.width, size.height ); |
|
685 |
} |
|
686 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
687 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
688 |
* Calculates the content rectangle. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
689 |
*/ |
2 | 690 |
protected void calculateContentRect() { |
691 |
contentRect.x = focusRect.x + focusInsets.left; |
|
692 |
contentRect.y = focusRect.y + focusInsets.top; |
|
693 |
contentRect.width = focusRect.width - (focusInsets.left + focusInsets.right); |
|
694 |
contentRect.height = focusRect.height - (focusInsets.top + focusInsets.bottom); |
|
695 |
} |
|
696 |
||
457
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
697 |
private int getTickSpacing() { |
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
698 |
int majorTickSpacing = slider.getMajorTickSpacing(); |
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
699 |
int minorTickSpacing = slider.getMinorTickSpacing(); |
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
700 |
|
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
701 |
int result; |
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
702 |
|
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
703 |
if (minorTickSpacing > 0) { |
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
704 |
result = minorTickSpacing; |
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
705 |
} else if (majorTickSpacing > 0) { |
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
706 |
result = majorTickSpacing; |
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
707 |
} else { |
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
708 |
result = 0; |
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
709 |
} |
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
710 |
|
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
711 |
return result; |
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
712 |
} |
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
713 |
|
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
714 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
715 |
* Calculates the thumb location. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
716 |
*/ |
2 | 717 |
protected void calculateThumbLocation() { |
718 |
if ( slider.getSnapToTicks() ) { |
|
719 |
int sliderValue = slider.getValue(); |
|
720 |
int snappedValue = sliderValue; |
|
457
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
721 |
int tickSpacing = getTickSpacing(); |
2 | 722 |
|
723 |
if ( tickSpacing != 0 ) { |
|
724 |
// If it's not on a tick, change the value |
|
725 |
if ( (sliderValue - slider.getMinimum()) % tickSpacing != 0 ) { |
|
726 |
float temp = (float)(sliderValue - slider.getMinimum()) / (float)tickSpacing; |
|
727 |
int whichTick = Math.round( temp ); |
|
728 |
||
729 |
// This is the fix for the bug #6401380 |
|
730 |
if (temp - (int)temp == .5 && sliderValue < lastValue) { |
|
731 |
whichTick --; |
|
732 |
} |
|
733 |
snappedValue = slider.getMinimum() + (whichTick * tickSpacing); |
|
734 |
} |
|
735 |
||
736 |
if( snappedValue != sliderValue ) { |
|
737 |
slider.setValue( snappedValue ); |
|
738 |
} |
|
739 |
} |
|
740 |
} |
|
741 |
||
742 |
if ( slider.getOrientation() == JSlider.HORIZONTAL ) { |
|
743 |
int valuePosition = xPositionForValue(slider.getValue()); |
|
744 |
||
745 |
thumbRect.x = valuePosition - (thumbRect.width / 2); |
|
746 |
thumbRect.y = trackRect.y; |
|
747 |
} |
|
748 |
else { |
|
749 |
int valuePosition = yPositionForValue(slider.getValue()); |
|
750 |
||
751 |
thumbRect.x = trackRect.x; |
|
752 |
thumbRect.y = valuePosition - (thumbRect.height / 2); |
|
753 |
} |
|
754 |
} |
|
755 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
756 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
757 |
* Calculates the track buffer. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
758 |
*/ |
2 | 759 |
protected void calculateTrackBuffer() { |
760 |
if ( slider.getPaintLabels() && slider.getLabelTable() != null ) { |
|
761 |
Component highLabel = getHighestValueLabel(); |
|
762 |
Component lowLabel = getLowestValueLabel(); |
|
763 |
||
764 |
if ( slider.getOrientation() == JSlider.HORIZONTAL ) { |
|
765 |
trackBuffer = Math.max( highLabel.getBounds().width, lowLabel.getBounds().width ) / 2; |
|
766 |
trackBuffer = Math.max( trackBuffer, thumbRect.width / 2 ); |
|
767 |
} |
|
768 |
else { |
|
769 |
trackBuffer = Math.max( highLabel.getBounds().height, lowLabel.getBounds().height ) / 2; |
|
770 |
trackBuffer = Math.max( trackBuffer, thumbRect.height / 2 ); |
|
771 |
} |
|
772 |
} |
|
773 |
else { |
|
774 |
if ( slider.getOrientation() == JSlider.HORIZONTAL ) { |
|
775 |
trackBuffer = thumbRect.width / 2; |
|
776 |
} |
|
777 |
else { |
|
778 |
trackBuffer = thumbRect.height / 2; |
|
779 |
} |
|
780 |
} |
|
781 |
} |
|
782 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
783 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
784 |
* Calculates the track rectangle. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
785 |
*/ |
2 | 786 |
protected void calculateTrackRect() { |
676
8cf833d60e87
6709530: There are unnecessary code in slider classes, such as in JSlider and SliderUIs
rupashka
parents:
457
diff
changeset
|
787 |
int centerSpacing; // used to center sliders added using BorderLayout.CENTER (bug 4275631) |
2 | 788 |
if ( slider.getOrientation() == JSlider.HORIZONTAL ) { |
789 |
centerSpacing = thumbRect.height; |
|
790 |
if ( slider.getPaintTicks() ) centerSpacing += getTickLength(); |
|
791 |
if ( slider.getPaintLabels() ) centerSpacing += getHeightOfTallestLabel(); |
|
792 |
trackRect.x = contentRect.x + trackBuffer; |
|
793 |
trackRect.y = contentRect.y + (contentRect.height - centerSpacing - 1)/2; |
|
794 |
trackRect.width = contentRect.width - (trackBuffer * 2); |
|
795 |
trackRect.height = thumbRect.height; |
|
796 |
} |
|
797 |
else { |
|
798 |
centerSpacing = thumbRect.width; |
|
799 |
if (BasicGraphicsUtils.isLeftToRight(slider)) { |
|
800 |
if ( slider.getPaintTicks() ) centerSpacing += getTickLength(); |
|
801 |
if ( slider.getPaintLabels() ) centerSpacing += getWidthOfWidestLabel(); |
|
802 |
} else { |
|
803 |
if ( slider.getPaintTicks() ) centerSpacing -= getTickLength(); |
|
804 |
if ( slider.getPaintLabels() ) centerSpacing -= getWidthOfWidestLabel(); |
|
805 |
} |
|
806 |
trackRect.x = contentRect.x + (contentRect.width - centerSpacing - 1)/2; |
|
807 |
trackRect.y = contentRect.y + trackBuffer; |
|
808 |
trackRect.width = thumbRect.width; |
|
809 |
trackRect.height = contentRect.height - (trackBuffer * 2); |
|
810 |
} |
|
811 |
||
812 |
} |
|
813 |
||
814 |
/** |
|
26012
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
815 |
* Gets the height of the tick area for horizontal sliders and the width of |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
816 |
* the tick area for vertical sliders. BasicSliderUI uses the returned value |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
817 |
* to determine the tick area rectangle. If you want to give your ticks some |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
818 |
* room, make this larger than you need and paint your ticks away from the |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
819 |
* sides in paintTicks(). |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
820 |
* |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
821 |
* @return an integer representing the height of the tick area for |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
822 |
* horizontal sliders, and the width of the tick area for the vertical |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
823 |
* sliders |
2 | 824 |
*/ |
825 |
protected int getTickLength() { |
|
826 |
return 8; |
|
827 |
} |
|
828 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
829 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
830 |
* Calculates the tick rectangle. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
831 |
*/ |
2 | 832 |
protected void calculateTickRect() { |
833 |
if ( slider.getOrientation() == JSlider.HORIZONTAL ) { |
|
834 |
tickRect.x = trackRect.x; |
|
835 |
tickRect.y = trackRect.y + trackRect.height; |
|
836 |
tickRect.width = trackRect.width; |
|
837 |
tickRect.height = (slider.getPaintTicks()) ? getTickLength() : 0; |
|
838 |
} |
|
839 |
else { |
|
840 |
tickRect.width = (slider.getPaintTicks()) ? getTickLength() : 0; |
|
841 |
if(BasicGraphicsUtils.isLeftToRight(slider)) { |
|
842 |
tickRect.x = trackRect.x + trackRect.width; |
|
843 |
} |
|
844 |
else { |
|
845 |
tickRect.x = trackRect.x - tickRect.width; |
|
846 |
} |
|
847 |
tickRect.y = trackRect.y; |
|
848 |
tickRect.height = trackRect.height; |
|
849 |
} |
|
850 |
} |
|
851 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
852 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
853 |
* Calculates the label rectangle. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
854 |
*/ |
2 | 855 |
protected void calculateLabelRect() { |
856 |
if ( slider.getPaintLabels() ) { |
|
857 |
if ( slider.getOrientation() == JSlider.HORIZONTAL ) { |
|
858 |
labelRect.x = tickRect.x - trackBuffer; |
|
859 |
labelRect.y = tickRect.y + tickRect.height; |
|
860 |
labelRect.width = tickRect.width + (trackBuffer * 2); |
|
861 |
labelRect.height = getHeightOfTallestLabel(); |
|
862 |
} |
|
863 |
else { |
|
864 |
if(BasicGraphicsUtils.isLeftToRight(slider)) { |
|
865 |
labelRect.x = tickRect.x + tickRect.width; |
|
866 |
labelRect.width = getWidthOfWidestLabel(); |
|
867 |
} |
|
868 |
else { |
|
869 |
labelRect.width = getWidthOfWidestLabel(); |
|
870 |
labelRect.x = tickRect.x - labelRect.width; |
|
871 |
} |
|
872 |
labelRect.y = tickRect.y - trackBuffer; |
|
873 |
labelRect.height = tickRect.height + (trackBuffer * 2); |
|
874 |
} |
|
875 |
} |
|
876 |
else { |
|
877 |
if ( slider.getOrientation() == JSlider.HORIZONTAL ) { |
|
878 |
labelRect.x = tickRect.x; |
|
879 |
labelRect.y = tickRect.y + tickRect.height; |
|
880 |
labelRect.width = tickRect.width; |
|
881 |
labelRect.height = 0; |
|
882 |
} |
|
883 |
else { |
|
884 |
if(BasicGraphicsUtils.isLeftToRight(slider)) { |
|
885 |
labelRect.x = tickRect.x + tickRect.width; |
|
886 |
} |
|
887 |
else { |
|
888 |
labelRect.x = tickRect.x; |
|
889 |
} |
|
890 |
labelRect.y = tickRect.y; |
|
891 |
labelRect.width = 0; |
|
892 |
labelRect.height = tickRect.height; |
|
893 |
} |
|
894 |
} |
|
895 |
} |
|
896 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
897 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
898 |
* Returns the thumb size. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
899 |
* @return the thumb size |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
900 |
*/ |
2 | 901 |
protected Dimension getThumbSize() { |
902 |
Dimension size = new Dimension(); |
|
903 |
||
904 |
if ( slider.getOrientation() == JSlider.VERTICAL ) { |
|
905 |
size.width = 20; |
|
906 |
size.height = 11; |
|
907 |
} |
|
908 |
else { |
|
909 |
size.width = 11; |
|
910 |
size.height = 20; |
|
911 |
} |
|
912 |
||
913 |
return size; |
|
914 |
} |
|
915 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
916 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
917 |
* A property change handler. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
918 |
*/ |
2 | 919 |
public class PropertyChangeHandler implements PropertyChangeListener { |
21278 | 920 |
// NOTE: This class exists only for backward compatibility. All |
2 | 921 |
// its functionality has been moved into Handler. If you need to add |
922 |
// new functionality add it to the Handler, but make sure this |
|
923 |
// class calls into the Handler. |
|
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
924 |
/** {@inheritDoc} */ |
2 | 925 |
public void propertyChange( PropertyChangeEvent e ) { |
926 |
getHandler().propertyChange(e); |
|
927 |
} |
|
928 |
} |
|
929 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
930 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
931 |
* Returns the width of the widest label. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
932 |
* @return the width of the widest label |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
933 |
*/ |
2 | 934 |
protected int getWidthOfWidestLabel() { |
26352
fa12363e21d6
8055254: Address source incompatability of JSlider generification
darcy
parents:
26351
diff
changeset
|
935 |
@SuppressWarnings("rawtypes") |
fa12363e21d6
8055254: Address source incompatability of JSlider generification
darcy
parents:
26351
diff
changeset
|
936 |
Dictionary dictionary = slider.getLabelTable(); |
2 | 937 |
int widest = 0; |
938 |
if ( dictionary != null ) { |
|
25565
ce603b34c98d
8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents:
23697
diff
changeset
|
939 |
Enumeration<?> keys = dictionary.keys(); |
2 | 940 |
while ( keys.hasMoreElements() ) { |
26352
fa12363e21d6
8055254: Address source incompatability of JSlider generification
darcy
parents:
26351
diff
changeset
|
941 |
JComponent label = (JComponent) dictionary.get(keys.nextElement()); |
2 | 942 |
widest = Math.max( label.getPreferredSize().width, widest ); |
943 |
} |
|
944 |
} |
|
945 |
return widest; |
|
946 |
} |
|
947 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
948 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
949 |
* Returns the height of the tallest label. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
950 |
* @return the height of the tallest label |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
951 |
*/ |
2 | 952 |
protected int getHeightOfTallestLabel() { |
26352
fa12363e21d6
8055254: Address source incompatability of JSlider generification
darcy
parents:
26351
diff
changeset
|
953 |
@SuppressWarnings("rawtypes") |
fa12363e21d6
8055254: Address source incompatability of JSlider generification
darcy
parents:
26351
diff
changeset
|
954 |
Dictionary dictionary = slider.getLabelTable(); |
2 | 955 |
int tallest = 0; |
956 |
if ( dictionary != null ) { |
|
25565
ce603b34c98d
8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents:
23697
diff
changeset
|
957 |
Enumeration<?> keys = dictionary.keys(); |
2 | 958 |
while ( keys.hasMoreElements() ) { |
26352
fa12363e21d6
8055254: Address source incompatability of JSlider generification
darcy
parents:
26351
diff
changeset
|
959 |
JComponent label = (JComponent) dictionary.get(keys.nextElement()); |
2 | 960 |
tallest = Math.max( label.getPreferredSize().height, tallest ); |
961 |
} |
|
962 |
} |
|
963 |
return tallest; |
|
964 |
} |
|
965 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
966 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
967 |
* Returns the width of the highest value label. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
968 |
* @return the width of the highest value label |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
969 |
*/ |
2 | 970 |
protected int getWidthOfHighValueLabel() { |
971 |
Component label = getHighestValueLabel(); |
|
972 |
int width = 0; |
|
973 |
||
974 |
if ( label != null ) { |
|
975 |
width = label.getPreferredSize().width; |
|
976 |
} |
|
977 |
||
978 |
return width; |
|
979 |
} |
|
980 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
981 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
982 |
* Returns the width of the lowest value label. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
983 |
* @return the width of the lowest value label |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
984 |
*/ |
2 | 985 |
protected int getWidthOfLowValueLabel() { |
986 |
Component label = getLowestValueLabel(); |
|
987 |
int width = 0; |
|
988 |
||
989 |
if ( label != null ) { |
|
990 |
width = label.getPreferredSize().width; |
|
991 |
} |
|
992 |
||
993 |
return width; |
|
994 |
} |
|
995 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
996 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
997 |
* Returns the height of the highest value label. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
998 |
* @return the height of the highest value label |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
999 |
*/ |
2 | 1000 |
protected int getHeightOfHighValueLabel() { |
1001 |
Component label = getHighestValueLabel(); |
|
1002 |
int height = 0; |
|
1003 |
||
1004 |
if ( label != null ) { |
|
1005 |
height = label.getPreferredSize().height; |
|
1006 |
} |
|
1007 |
||
1008 |
return height; |
|
1009 |
} |
|
1010 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1011 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1012 |
* Returns the height of the lowest value label. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1013 |
* @return the height of the lowest value label |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1014 |
*/ |
2 | 1015 |
protected int getHeightOfLowValueLabel() { |
1016 |
Component label = getLowestValueLabel(); |
|
1017 |
int height = 0; |
|
1018 |
||
1019 |
if ( label != null ) { |
|
1020 |
height = label.getPreferredSize().height; |
|
1021 |
} |
|
1022 |
||
1023 |
return height; |
|
1024 |
} |
|
1025 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1026 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1027 |
* Draws inverted. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1028 |
* @return the inverted-ness |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1029 |
*/ |
2 | 1030 |
protected boolean drawInverted() { |
1031 |
if (slider.getOrientation()==JSlider.HORIZONTAL) { |
|
1032 |
if(BasicGraphicsUtils.isLeftToRight(slider)) { |
|
1033 |
return slider.getInverted(); |
|
1034 |
} else { |
|
1035 |
return !slider.getInverted(); |
|
1036 |
} |
|
1037 |
} else { |
|
1038 |
return slider.getInverted(); |
|
1039 |
} |
|
1040 |
} |
|
1041 |
||
1042 |
/** |
|
1043 |
* Returns the biggest value that has an entry in the label table. |
|
1044 |
* |
|
1045 |
* @return biggest value that has an entry in the label table, or |
|
1046 |
* null. |
|
1047 |
* @since 1.6 |
|
1048 |
*/ |
|
1049 |
protected Integer getHighestValue() { |
|
26352
fa12363e21d6
8055254: Address source incompatability of JSlider generification
darcy
parents:
26351
diff
changeset
|
1050 |
@SuppressWarnings("rawtypes") |
fa12363e21d6
8055254: Address source incompatability of JSlider generification
darcy
parents:
26351
diff
changeset
|
1051 |
Dictionary dictionary = slider.getLabelTable(); |
1852
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1052 |
|
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1053 |
if (dictionary == null) { |
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1054 |
return null; |
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1055 |
} |
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1056 |
|
26352
fa12363e21d6
8055254: Address source incompatability of JSlider generification
darcy
parents:
26351
diff
changeset
|
1057 |
Enumeration<?> keys = dictionary.keys(); |
1852
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1058 |
|
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1059 |
Integer max = null; |
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1060 |
|
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1061 |
while (keys.hasMoreElements()) { |
26352
fa12363e21d6
8055254: Address source incompatability of JSlider generification
darcy
parents:
26351
diff
changeset
|
1062 |
Integer i = (Integer) keys.nextElement(); |
1852
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1063 |
|
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1064 |
if (max == null || i > max) { |
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1065 |
max = i; |
2 | 1066 |
} |
1067 |
} |
|
1852
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1068 |
|
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1069 |
return max; |
2 | 1070 |
} |
1071 |
||
1072 |
/** |
|
1073 |
* Returns the smallest value that has an entry in the label table. |
|
1074 |
* |
|
1075 |
* @return smallest value that has an entry in the label table, or |
|
26012
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1076 |
* null. |
2 | 1077 |
* @since 1.6 |
1078 |
*/ |
|
1079 |
protected Integer getLowestValue() { |
|
26352
fa12363e21d6
8055254: Address source incompatability of JSlider generification
darcy
parents:
26351
diff
changeset
|
1080 |
@SuppressWarnings("rawtypes") |
fa12363e21d6
8055254: Address source incompatability of JSlider generification
darcy
parents:
26351
diff
changeset
|
1081 |
Dictionary dictionary = slider.getLabelTable(); |
1852
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1082 |
|
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1083 |
if (dictionary == null) { |
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1084 |
return null; |
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1085 |
} |
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1086 |
|
26352
fa12363e21d6
8055254: Address source incompatability of JSlider generification
darcy
parents:
26351
diff
changeset
|
1087 |
Enumeration<?> keys = dictionary.keys(); |
1852
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1088 |
|
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1089 |
Integer min = null; |
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1090 |
|
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1091 |
while (keys.hasMoreElements()) { |
26352
fa12363e21d6
8055254: Address source incompatability of JSlider generification
darcy
parents:
26351
diff
changeset
|
1092 |
Integer i = (Integer) keys.nextElement(); |
1852
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1093 |
|
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1094 |
if (min == null || i < min) { |
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1095 |
min = i; |
2 | 1096 |
} |
1097 |
} |
|
1852
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1098 |
|
958801d67667
6794836: BasicSliderUI throws NullPointerExc when JSlider maximum is Integer.MAX_VALUE
rupashka
parents:
715
diff
changeset
|
1099 |
return min; |
2 | 1100 |
} |
1101 |
||
1102 |
||
1103 |
/** |
|
26012
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1104 |
* Returns the label that corresponds to the highest slider value in the |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1105 |
* label table. |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1106 |
* |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1107 |
* @return the label that corresponds to the highest slider value in the |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1108 |
* label table |
2 | 1109 |
* @see JSlider#setLabelTable |
1110 |
*/ |
|
1111 |
protected Component getLowestValueLabel() { |
|
1112 |
Integer min = getLowestValue(); |
|
1113 |
if (min != null) { |
|
1114 |
return (Component)slider.getLabelTable().get(min); |
|
1115 |
} |
|
1116 |
return null; |
|
1117 |
} |
|
1118 |
||
1119 |
/** |
|
26012
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1120 |
* Returns the label that corresponds to the lowest slider value in the |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1121 |
* label table. |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1122 |
* |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1123 |
* @return the label that corresponds to the lowest slider value in the |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1124 |
* label table |
2 | 1125 |
* @see JSlider#setLabelTable |
1126 |
*/ |
|
1127 |
protected Component getHighestValueLabel() { |
|
1128 |
Integer max = getHighestValue(); |
|
1129 |
if (max != null) { |
|
1130 |
return (Component)slider.getLabelTable().get(max); |
|
1131 |
} |
|
1132 |
return null; |
|
1133 |
} |
|
1134 |
||
1135 |
public void paint( Graphics g, JComponent c ) { |
|
1136 |
recalculateIfInsetsChanged(); |
|
1137 |
recalculateIfOrientationChanged(); |
|
1138 |
Rectangle clip = g.getClipBounds(); |
|
1139 |
||
1140 |
if ( !clip.intersects(trackRect) && slider.getPaintTrack()) |
|
1141 |
calculateGeometry(); |
|
1142 |
||
1143 |
if ( slider.getPaintTrack() && clip.intersects( trackRect ) ) { |
|
1144 |
paintTrack( g ); |
|
1145 |
} |
|
1146 |
if ( slider.getPaintTicks() && clip.intersects( tickRect ) ) { |
|
1147 |
paintTicks( g ); |
|
1148 |
} |
|
1149 |
if ( slider.getPaintLabels() && clip.intersects( labelRect ) ) { |
|
1150 |
paintLabels( g ); |
|
1151 |
} |
|
1152 |
if ( slider.hasFocus() && clip.intersects( focusRect ) ) { |
|
1153 |
paintFocus( g ); |
|
1154 |
} |
|
1155 |
if ( clip.intersects( thumbRect ) ) { |
|
1156 |
paintThumb( g ); |
|
1157 |
} |
|
1158 |
} |
|
1159 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1160 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1161 |
* Recalculates if the insets have changed. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1162 |
*/ |
2 | 1163 |
protected void recalculateIfInsetsChanged() { |
1164 |
Insets newInsets = slider.getInsets(); |
|
1165 |
if ( !newInsets.equals( insetCache ) ) { |
|
1166 |
insetCache = newInsets; |
|
1167 |
calculateGeometry(); |
|
1168 |
} |
|
1169 |
} |
|
1170 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1171 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1172 |
* Recalculates if the orientation has changed. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1173 |
*/ |
2 | 1174 |
protected void recalculateIfOrientationChanged() { |
1175 |
boolean ltr = BasicGraphicsUtils.isLeftToRight(slider); |
|
1176 |
if ( ltr!=leftToRightCache ) { |
|
1177 |
leftToRightCache = ltr; |
|
1178 |
calculateGeometry(); |
|
1179 |
} |
|
1180 |
} |
|
1181 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1182 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1183 |
* Paints focus. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1184 |
* @param g the graphics |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1185 |
*/ |
2 | 1186 |
public void paintFocus(Graphics g) { |
1187 |
g.setColor( getFocusColor() ); |
|
1188 |
||
1189 |
BasicGraphicsUtils.drawDashedRect( g, focusRect.x, focusRect.y, |
|
1190 |
focusRect.width, focusRect.height ); |
|
1191 |
} |
|
1192 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1193 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1194 |
* Paints track. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1195 |
* @param g the graphics |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1196 |
*/ |
2 | 1197 |
public void paintTrack(Graphics g) { |
1198 |
||
1199 |
Rectangle trackBounds = trackRect; |
|
1200 |
||
1201 |
if ( slider.getOrientation() == JSlider.HORIZONTAL ) { |
|
1202 |
int cy = (trackBounds.height / 2) - 2; |
|
1203 |
int cw = trackBounds.width; |
|
1204 |
||
1205 |
g.translate(trackBounds.x, trackBounds.y + cy); |
|
1206 |
||
1207 |
g.setColor(getShadowColor()); |
|
1208 |
g.drawLine(0, 0, cw - 1, 0); |
|
1209 |
g.drawLine(0, 1, 0, 2); |
|
1210 |
g.setColor(getHighlightColor()); |
|
1211 |
g.drawLine(0, 3, cw, 3); |
|
1212 |
g.drawLine(cw, 0, cw, 3); |
|
1213 |
g.setColor(Color.black); |
|
1214 |
g.drawLine(1, 1, cw-2, 1); |
|
1215 |
||
1216 |
g.translate(-trackBounds.x, -(trackBounds.y + cy)); |
|
1217 |
} |
|
1218 |
else { |
|
1219 |
int cx = (trackBounds.width / 2) - 2; |
|
1220 |
int ch = trackBounds.height; |
|
1221 |
||
1222 |
g.translate(trackBounds.x + cx, trackBounds.y); |
|
1223 |
||
1224 |
g.setColor(getShadowColor()); |
|
1225 |
g.drawLine(0, 0, 0, ch - 1); |
|
1226 |
g.drawLine(1, 0, 2, 0); |
|
1227 |
g.setColor(getHighlightColor()); |
|
1228 |
g.drawLine(3, 0, 3, ch); |
|
1229 |
g.drawLine(0, ch, 3, ch); |
|
1230 |
g.setColor(Color.black); |
|
1231 |
g.drawLine(1, 1, 1, ch-2); |
|
1232 |
||
1233 |
g.translate(-(trackBounds.x + cx), -trackBounds.y); |
|
1234 |
} |
|
1235 |
} |
|
1236 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1237 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1238 |
* Paints ticks. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1239 |
* @param g the graphics |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1240 |
*/ |
2 | 1241 |
public void paintTicks(Graphics g) { |
1242 |
Rectangle tickBounds = tickRect; |
|
1243 |
||
1244 |
g.setColor(DefaultLookup.getColor(slider, this, "Slider.tickColor", Color.black)); |
|
1245 |
||
1246 |
if ( slider.getOrientation() == JSlider.HORIZONTAL ) { |
|
2488
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1247 |
g.translate(0, tickBounds.y); |
2 | 1248 |
|
2488
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1249 |
if (slider.getMinorTickSpacing() > 0) { |
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1250 |
int value = slider.getMinimum(); |
2 | 1251 |
|
1252 |
while ( value <= slider.getMaximum() ) { |
|
2488
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1253 |
int xPos = xPositionForValue(value); |
2 | 1254 |
paintMinorTickForHorizSlider( g, tickBounds, xPos ); |
2488
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1255 |
|
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1256 |
// Overflow checking |
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1257 |
if (Integer.MAX_VALUE - slider.getMinorTickSpacing() < value) { |
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1258 |
break; |
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1259 |
} |
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1260 |
|
2 | 1261 |
value += slider.getMinorTickSpacing(); |
1262 |
} |
|
1263 |
} |
|
1264 |
||
2488
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1265 |
if (slider.getMajorTickSpacing() > 0) { |
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1266 |
int value = slider.getMinimum(); |
2 | 1267 |
|
1268 |
while ( value <= slider.getMaximum() ) { |
|
2488
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1269 |
int xPos = xPositionForValue(value); |
2 | 1270 |
paintMajorTickForHorizSlider( g, tickBounds, xPos ); |
2488
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1271 |
|
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1272 |
// Overflow checking |
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1273 |
if (Integer.MAX_VALUE - slider.getMajorTickSpacing() < value) { |
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1274 |
break; |
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1275 |
} |
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1276 |
|
2 | 1277 |
value += slider.getMajorTickSpacing(); |
1278 |
} |
|
1279 |
} |
|
1280 |
||
1281 |
g.translate( 0, -tickBounds.y); |
|
2488
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1282 |
} else { |
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1283 |
g.translate(tickBounds.x, 0); |
2 | 1284 |
|
2488
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1285 |
if (slider.getMinorTickSpacing() > 0) { |
2 | 1286 |
int offset = 0; |
1287 |
if(!BasicGraphicsUtils.isLeftToRight(slider)) { |
|
1288 |
offset = tickBounds.width - tickBounds.width / 2; |
|
1289 |
g.translate(offset, 0); |
|
1290 |
} |
|
1291 |
||
2488
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1292 |
int value = slider.getMinimum(); |
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1293 |
|
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1294 |
while (value <= slider.getMaximum()) { |
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1295 |
int yPos = yPositionForValue(value); |
2 | 1296 |
paintMinorTickForVertSlider( g, tickBounds, yPos ); |
2488
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1297 |
|
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1298 |
// Overflow checking |
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1299 |
if (Integer.MAX_VALUE - slider.getMinorTickSpacing() < value) { |
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1300 |
break; |
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1301 |
} |
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1302 |
|
2 | 1303 |
value += slider.getMinorTickSpacing(); |
1304 |
} |
|
1305 |
||
1306 |
if(!BasicGraphicsUtils.isLeftToRight(slider)) { |
|
1307 |
g.translate(-offset, 0); |
|
1308 |
} |
|
1309 |
} |
|
1310 |
||
2488
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1311 |
if (slider.getMajorTickSpacing() > 0) { |
2 | 1312 |
if(!BasicGraphicsUtils.isLeftToRight(slider)) { |
1313 |
g.translate(2, 0); |
|
1314 |
} |
|
1315 |
||
2488
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1316 |
int value = slider.getMinimum(); |
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1317 |
|
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1318 |
while (value <= slider.getMaximum()) { |
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1319 |
int yPos = yPositionForValue(value); |
2 | 1320 |
paintMajorTickForVertSlider( g, tickBounds, yPos ); |
2488
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1321 |
|
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1322 |
// Overflow checking |
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1323 |
if (Integer.MAX_VALUE - slider.getMajorTickSpacing() < value) { |
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1324 |
break; |
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1325 |
} |
4d54c9133cda
6794831: Infinite loop while painting ticks on Slider with maximum=MAX_INT
rupashka
parents:
1852
diff
changeset
|
1326 |
|
2 | 1327 |
value += slider.getMajorTickSpacing(); |
1328 |
} |
|
1329 |
||
1330 |
if(!BasicGraphicsUtils.isLeftToRight(slider)) { |
|
1331 |
g.translate(-2, 0); |
|
1332 |
} |
|
1333 |
} |
|
1334 |
g.translate(-tickBounds.x, 0); |
|
1335 |
} |
|
1336 |
} |
|
1337 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1338 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1339 |
* Paints minor tick for horizontal slider. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1340 |
* @param g the graphics |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1341 |
* @param tickBounds the tick bounds |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1342 |
* @param x the x coordinate |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1343 |
*/ |
2 | 1344 |
protected void paintMinorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) { |
1345 |
g.drawLine( x, 0, x, tickBounds.height / 2 - 1 ); |
|
1346 |
} |
|
1347 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1348 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1349 |
* Paints major tick for horizontal slider. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1350 |
* @param g the graphics |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1351 |
* @param tickBounds the tick bounds |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1352 |
* @param x the x coordinate |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1353 |
*/ |
2 | 1354 |
protected void paintMajorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) { |
1355 |
g.drawLine( x, 0, x, tickBounds.height - 2 ); |
|
1356 |
} |
|
1357 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1358 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1359 |
* Paints minor tick for vertical slider. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1360 |
* @param g the graphics |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1361 |
* @param tickBounds the tick bounds |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1362 |
* @param y the y coordinate |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1363 |
*/ |
2 | 1364 |
protected void paintMinorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) { |
1365 |
g.drawLine( 0, y, tickBounds.width / 2 - 1, y ); |
|
1366 |
} |
|
1367 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1368 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1369 |
* Paints major tick for vertical slider. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1370 |
* @param g the graphics |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1371 |
* @param tickBounds the tick bounds |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1372 |
* @param y the y coordinate |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1373 |
*/ |
2 | 1374 |
protected void paintMajorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) { |
1375 |
g.drawLine( 0, y, tickBounds.width - 2, y ); |
|
1376 |
} |
|
1377 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1378 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1379 |
* Paints the labels. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1380 |
* @param g the graphics |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1381 |
*/ |
2 | 1382 |
public void paintLabels( Graphics g ) { |
1383 |
Rectangle labelBounds = labelRect; |
|
1384 |
||
26352
fa12363e21d6
8055254: Address source incompatability of JSlider generification
darcy
parents:
26351
diff
changeset
|
1385 |
@SuppressWarnings("rawtypes") |
fa12363e21d6
8055254: Address source incompatability of JSlider generification
darcy
parents:
26351
diff
changeset
|
1386 |
Dictionary dictionary = slider.getLabelTable(); |
2 | 1387 |
if ( dictionary != null ) { |
26352
fa12363e21d6
8055254: Address source incompatability of JSlider generification
darcy
parents:
26351
diff
changeset
|
1388 |
Enumeration<?> keys = dictionary.keys(); |
2 | 1389 |
int minValue = slider.getMinimum(); |
1390 |
int maxValue = slider.getMaximum(); |
|
1391 |
boolean enabled = slider.isEnabled(); |
|
1392 |
while ( keys.hasMoreElements() ) { |
|
26352
fa12363e21d6
8055254: Address source incompatability of JSlider generification
darcy
parents:
26351
diff
changeset
|
1393 |
Integer key = (Integer)keys.nextElement(); |
2 | 1394 |
int value = key.intValue(); |
1395 |
if (value >= minValue && value <= maxValue) { |
|
26352
fa12363e21d6
8055254: Address source incompatability of JSlider generification
darcy
parents:
26351
diff
changeset
|
1396 |
JComponent label = (JComponent) dictionary.get(key); |
676
8cf833d60e87
6709530: There are unnecessary code in slider classes, such as in JSlider and SliderUIs
rupashka
parents:
457
diff
changeset
|
1397 |
label.setEnabled(enabled); |
8cf833d60e87
6709530: There are unnecessary code in slider classes, such as in JSlider and SliderUIs
rupashka
parents:
457
diff
changeset
|
1398 |
|
677
20718977427b
4987336: JSlider doesn't show label's animated icon
rupashka
parents:
676
diff
changeset
|
1399 |
if (label instanceof JLabel) { |
20718977427b
4987336: JSlider doesn't show label's animated icon
rupashka
parents:
676
diff
changeset
|
1400 |
Icon icon = label.isEnabled() ? ((JLabel) label).getIcon() : ((JLabel) label).getDisabledIcon(); |
20718977427b
4987336: JSlider doesn't show label's animated icon
rupashka
parents:
676
diff
changeset
|
1401 |
|
20718977427b
4987336: JSlider doesn't show label's animated icon
rupashka
parents:
676
diff
changeset
|
1402 |
if (icon instanceof ImageIcon) { |
20718977427b
4987336: JSlider doesn't show label's animated icon
rupashka
parents:
676
diff
changeset
|
1403 |
// Register Slider as an image observer. It allows to catch notifications about |
20718977427b
4987336: JSlider doesn't show label's animated icon
rupashka
parents:
676
diff
changeset
|
1404 |
// image changes (e.g. gif animation) |
20718977427b
4987336: JSlider doesn't show label's animated icon
rupashka
parents:
676
diff
changeset
|
1405 |
Toolkit.getDefaultToolkit().checkImage(((ImageIcon) icon).getImage(), -1, -1, slider); |
20718977427b
4987336: JSlider doesn't show label's animated icon
rupashka
parents:
676
diff
changeset
|
1406 |
} |
20718977427b
4987336: JSlider doesn't show label's animated icon
rupashka
parents:
676
diff
changeset
|
1407 |
} |
20718977427b
4987336: JSlider doesn't show label's animated icon
rupashka
parents:
676
diff
changeset
|
1408 |
|
2 | 1409 |
if ( slider.getOrientation() == JSlider.HORIZONTAL ) { |
1410 |
g.translate( 0, labelBounds.y ); |
|
1411 |
paintHorizontalLabel( g, value, label ); |
|
1412 |
g.translate( 0, -labelBounds.y ); |
|
1413 |
} |
|
1414 |
else { |
|
1415 |
int offset = 0; |
|
1416 |
if (!BasicGraphicsUtils.isLeftToRight(slider)) { |
|
1417 |
offset = labelBounds.width - |
|
1418 |
label.getPreferredSize().width; |
|
1419 |
} |
|
1420 |
g.translate( labelBounds.x + offset, 0 ); |
|
1421 |
paintVerticalLabel( g, value, label ); |
|
1422 |
g.translate( -labelBounds.x - offset, 0 ); |
|
1423 |
} |
|
1424 |
} |
|
1425 |
} |
|
1426 |
} |
|
1427 |
||
1428 |
} |
|
1429 |
||
1430 |
/** |
|
26012
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1431 |
* Called for every label in the label table. Used to draw the labels for |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1432 |
* horizontal sliders. The graphics have been translated to labelRect.y |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1433 |
* already. |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1434 |
* |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1435 |
* @param g the graphics context in which to paint |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1436 |
* @param value the value of the slider |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1437 |
* @param label the component label in the label table that needs to be |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1438 |
* painted |
2 | 1439 |
* @see JSlider#setLabelTable |
1440 |
*/ |
|
1441 |
protected void paintHorizontalLabel( Graphics g, int value, Component label ) { |
|
1442 |
int labelCenter = xPositionForValue( value ); |
|
1443 |
int labelLeft = labelCenter - (label.getPreferredSize().width / 2); |
|
1444 |
g.translate( labelLeft, 0 ); |
|
1445 |
label.paint( g ); |
|
1446 |
g.translate( -labelLeft, 0 ); |
|
1447 |
} |
|
1448 |
||
1449 |
/** |
|
26012
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1450 |
* Called for every label in the label table. Used to draw the labels for |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1451 |
* vertical sliders. The graphics have been translated to labelRect.x |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1452 |
* already. |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1453 |
* |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1454 |
* @param g the graphics context in which to paint |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1455 |
* @param value the value of the slider |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1456 |
* @param label the component label in the label table that needs to be |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1457 |
* painted |
2 | 1458 |
* @see JSlider#setLabelTable |
1459 |
*/ |
|
1460 |
protected void paintVerticalLabel( Graphics g, int value, Component label ) { |
|
1461 |
int labelCenter = yPositionForValue( value ); |
|
1462 |
int labelTop = labelCenter - (label.getPreferredSize().height / 2); |
|
1463 |
g.translate( 0, labelTop ); |
|
1464 |
label.paint( g ); |
|
1465 |
g.translate( 0, -labelTop ); |
|
1466 |
} |
|
1467 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1468 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1469 |
* Paints the thumb. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1470 |
* @param g the graphics |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1471 |
*/ |
2 | 1472 |
public void paintThumb(Graphics g) { |
1473 |
Rectangle knobBounds = thumbRect; |
|
1474 |
int w = knobBounds.width; |
|
1475 |
int h = knobBounds.height; |
|
1476 |
||
1477 |
g.translate(knobBounds.x, knobBounds.y); |
|
1478 |
||
1479 |
if ( slider.isEnabled() ) { |
|
1480 |
g.setColor(slider.getBackground()); |
|
1481 |
} |
|
1482 |
else { |
|
1483 |
g.setColor(slider.getBackground().darker()); |
|
1484 |
} |
|
1485 |
||
1486 |
Boolean paintThumbArrowShape = |
|
1487 |
(Boolean)slider.getClientProperty("Slider.paintThumbArrowShape"); |
|
1488 |
||
1489 |
if ((!slider.getPaintTicks() && paintThumbArrowShape == null) || |
|
1490 |
paintThumbArrowShape == Boolean.FALSE) { |
|
1491 |
||
1492 |
// "plain" version |
|
1493 |
g.fillRect(0, 0, w, h); |
|
1494 |
||
1495 |
g.setColor(Color.black); |
|
1496 |
g.drawLine(0, h-1, w-1, h-1); |
|
1497 |
g.drawLine(w-1, 0, w-1, h-1); |
|
1498 |
||
1499 |
g.setColor(highlightColor); |
|
1500 |
g.drawLine(0, 0, 0, h-2); |
|
1501 |
g.drawLine(1, 0, w-2, 0); |
|
1502 |
||
1503 |
g.setColor(shadowColor); |
|
1504 |
g.drawLine(1, h-2, w-2, h-2); |
|
1505 |
g.drawLine(w-2, 1, w-2, h-3); |
|
1506 |
} |
|
1507 |
else if ( slider.getOrientation() == JSlider.HORIZONTAL ) { |
|
1508 |
int cw = w / 2; |
|
1509 |
g.fillRect(1, 1, w-3, h-1-cw); |
|
1510 |
Polygon p = new Polygon(); |
|
1511 |
p.addPoint(1, h-cw); |
|
1512 |
p.addPoint(cw-1, h-1); |
|
1513 |
p.addPoint(w-2, h-1-cw); |
|
1514 |
g.fillPolygon(p); |
|
1515 |
||
1516 |
g.setColor(highlightColor); |
|
1517 |
g.drawLine(0, 0, w-2, 0); |
|
1518 |
g.drawLine(0, 1, 0, h-1-cw); |
|
1519 |
g.drawLine(0, h-cw, cw-1, h-1); |
|
1520 |
||
1521 |
g.setColor(Color.black); |
|
1522 |
g.drawLine(w-1, 0, w-1, h-2-cw); |
|
1523 |
g.drawLine(w-1, h-1-cw, w-1-cw, h-1); |
|
1524 |
||
1525 |
g.setColor(shadowColor); |
|
1526 |
g.drawLine(w-2, 1, w-2, h-2-cw); |
|
1527 |
g.drawLine(w-2, h-1-cw, w-1-cw, h-2); |
|
1528 |
} |
|
1529 |
else { // vertical |
|
1530 |
int cw = h / 2; |
|
1531 |
if(BasicGraphicsUtils.isLeftToRight(slider)) { |
|
1532 |
g.fillRect(1, 1, w-1-cw, h-3); |
|
1533 |
Polygon p = new Polygon(); |
|
1534 |
p.addPoint(w-cw-1, 0); |
|
1535 |
p.addPoint(w-1, cw); |
|
1536 |
p.addPoint(w-1-cw, h-2); |
|
1537 |
g.fillPolygon(p); |
|
1538 |
||
1539 |
g.setColor(highlightColor); |
|
1540 |
g.drawLine(0, 0, 0, h - 2); // left |
|
1541 |
g.drawLine(1, 0, w-1-cw, 0); // top |
|
1542 |
g.drawLine(w-cw-1, 0, w-1, cw); // top slant |
|
1543 |
||
1544 |
g.setColor(Color.black); |
|
1545 |
g.drawLine(0, h-1, w-2-cw, h-1); // bottom |
|
1546 |
g.drawLine(w-1-cw, h-1, w-1, h-1-cw); // bottom slant |
|
1547 |
||
1548 |
g.setColor(shadowColor); |
|
1549 |
g.drawLine(1, h-2, w-2-cw, h-2 ); // bottom |
|
1550 |
g.drawLine(w-1-cw, h-2, w-2, h-cw-1 ); // bottom slant |
|
1551 |
} |
|
1552 |
else { |
|
1553 |
g.fillRect(5, 1, w-1-cw, h-3); |
|
1554 |
Polygon p = new Polygon(); |
|
1555 |
p.addPoint(cw, 0); |
|
1556 |
p.addPoint(0, cw); |
|
1557 |
p.addPoint(cw, h-2); |
|
1558 |
g.fillPolygon(p); |
|
1559 |
||
1560 |
g.setColor(highlightColor); |
|
1561 |
g.drawLine(cw-1, 0, w-2, 0); // top |
|
1562 |
g.drawLine(0, cw, cw, 0); // top slant |
|
1563 |
||
1564 |
g.setColor(Color.black); |
|
1565 |
g.drawLine(0, h-1-cw, cw, h-1 ); // bottom slant |
|
1566 |
g.drawLine(cw, h-1, w-1, h-1); // bottom |
|
1567 |
||
1568 |
g.setColor(shadowColor); |
|
1569 |
g.drawLine(cw, h-2, w-2, h-2 ); // bottom |
|
1570 |
g.drawLine(w-1, 1, w-1, h-2 ); // right |
|
1571 |
} |
|
1572 |
} |
|
1573 |
||
1574 |
g.translate(-knobBounds.x, -knobBounds.y); |
|
1575 |
} |
|
1576 |
||
1577 |
// Used exclusively by setThumbLocation() |
|
1578 |
private static Rectangle unionRect = new Rectangle(); |
|
1579 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1580 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1581 |
* Sets the thumb location. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1582 |
* @param x the x coordinate |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1583 |
* @param y the y coordinate |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1584 |
*/ |
2 | 1585 |
public void setThumbLocation(int x, int y) { |
1586 |
unionRect.setBounds( thumbRect ); |
|
1587 |
||
1588 |
thumbRect.setLocation( x, y ); |
|
1589 |
||
1590 |
SwingUtilities.computeUnion( thumbRect.x, thumbRect.y, thumbRect.width, thumbRect.height, unionRect ); |
|
1591 |
slider.repaint( unionRect.x, unionRect.y, unionRect.width, unionRect.height ); |
|
1592 |
} |
|
1593 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1594 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1595 |
* Scrolls by block. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1596 |
* @param direction the direction |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1597 |
*/ |
2 | 1598 |
public void scrollByBlock(int direction) { |
1599 |
synchronized(slider) { |
|
1600 |
int blockIncrement = |
|
1601 |
(slider.getMaximum() - slider.getMinimum()) / 10; |
|
457
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
1602 |
if (blockIncrement == 0) { |
2 | 1603 |
blockIncrement = 1; |
1604 |
} |
|
1605 |
||
41007
d48361243925
8009477: PageUp and PageDown keyboard buttons don't move slider indicator to next minor tick
pkbalakr
parents:
30461
diff
changeset
|
1606 |
int tickSpacing = getTickSpacing(); |
457
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
1607 |
if (slider.getSnapToTicks()) { |
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
1608 |
|
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
1609 |
if (blockIncrement < tickSpacing) { |
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
1610 |
blockIncrement = tickSpacing; |
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
1611 |
} |
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
1612 |
} |
41007
d48361243925
8009477: PageUp and PageDown keyboard buttons don't move slider indicator to next minor tick
pkbalakr
parents:
30461
diff
changeset
|
1613 |
else { |
d48361243925
8009477: PageUp and PageDown keyboard buttons don't move slider indicator to next minor tick
pkbalakr
parents:
30461
diff
changeset
|
1614 |
if (tickSpacing > 0) { |
d48361243925
8009477: PageUp and PageDown keyboard buttons don't move slider indicator to next minor tick
pkbalakr
parents:
30461
diff
changeset
|
1615 |
blockIncrement = tickSpacing; |
d48361243925
8009477: PageUp and PageDown keyboard buttons don't move slider indicator to next minor tick
pkbalakr
parents:
30461
diff
changeset
|
1616 |
} |
d48361243925
8009477: PageUp and PageDown keyboard buttons don't move slider indicator to next minor tick
pkbalakr
parents:
30461
diff
changeset
|
1617 |
} |
457
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
1618 |
|
2 | 1619 |
int delta = blockIncrement * ((direction > 0) ? POSITIVE_SCROLL : NEGATIVE_SCROLL); |
457
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
1620 |
slider.setValue(slider.getValue() + delta); |
2 | 1621 |
} |
1622 |
} |
|
1623 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1624 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1625 |
* Scrolls by unit. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1626 |
* @param direction the direction |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1627 |
*/ |
2 | 1628 |
public void scrollByUnit(int direction) { |
1629 |
synchronized(slider) { |
|
457
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
1630 |
int delta = ((direction > 0) ? POSITIVE_SCROLL : NEGATIVE_SCROLL); |
2 | 1631 |
|
457
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
1632 |
if (slider.getSnapToTicks()) { |
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
1633 |
delta *= getTickSpacing(); |
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
1634 |
} |
2 | 1635 |
|
457
8682623ee3c3
6524424: JSlider Clicking In Tracks Behavior Inconsistent For Different Tick Spacings
rupashka
parents:
456
diff
changeset
|
1636 |
slider.setValue(slider.getValue() + delta); |
2 | 1637 |
} |
1638 |
} |
|
1639 |
||
1640 |
/** |
|
26012
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1641 |
* This function is called when a mousePressed was detected in the track, |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1642 |
* not in the thumb. The default behavior is to scroll by block. You can |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1643 |
* override this method to stop it from scrolling or to add additional |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1644 |
* behavior. |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1645 |
* |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1646 |
* @param dir the direction and number of blocks to scroll |
2 | 1647 |
*/ |
1648 |
protected void scrollDueToClickInTrack( int dir ) { |
|
1649 |
scrollByBlock( dir ); |
|
1650 |
} |
|
1651 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1652 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1653 |
* Returns the x position for a value. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1654 |
* @param value the value |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1655 |
* @return the x position for a value |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1656 |
*/ |
2 | 1657 |
protected int xPositionForValue( int value ) { |
1658 |
int min = slider.getMinimum(); |
|
1659 |
int max = slider.getMaximum(); |
|
1660 |
int trackLength = trackRect.width; |
|
1661 |
double valueRange = (double)max - (double)min; |
|
1662 |
double pixelsPerValue = (double)trackLength / valueRange; |
|
1663 |
int trackLeft = trackRect.x; |
|
1664 |
int trackRight = trackRect.x + (trackRect.width - 1); |
|
1665 |
int xPosition; |
|
1666 |
||
1667 |
if ( !drawInverted() ) { |
|
1668 |
xPosition = trackLeft; |
|
1669 |
xPosition += Math.round( pixelsPerValue * ((double)value - min) ); |
|
1670 |
} |
|
1671 |
else { |
|
1672 |
xPosition = trackRight; |
|
1673 |
xPosition -= Math.round( pixelsPerValue * ((double)value - min) ); |
|
1674 |
} |
|
1675 |
||
1676 |
xPosition = Math.max( trackLeft, xPosition ); |
|
1677 |
xPosition = Math.min( trackRight, xPosition ); |
|
1678 |
||
1679 |
return xPosition; |
|
1680 |
} |
|
1681 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1682 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1683 |
* Returns the y position for a value. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1684 |
* @param value the value |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1685 |
* @return the y position for a value |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1686 |
*/ |
2 | 1687 |
protected int yPositionForValue( int value ) { |
1688 |
return yPositionForValue(value, trackRect.y, trackRect.height); |
|
1689 |
} |
|
1690 |
||
1691 |
/** |
|
1692 |
* Returns the y location for the specified value. No checking is |
|
1693 |
* done on the arguments. In particular if <code>trackHeight</code> is |
|
1694 |
* negative undefined results may occur. |
|
1695 |
* |
|
1696 |
* @param value the slider value to get the location for |
|
1697 |
* @param trackY y-origin of the track |
|
1698 |
* @param trackHeight the height of the track |
|
26012
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1699 |
* @return the y location for the specified value of the slider |
2 | 1700 |
* @since 1.6 |
1701 |
*/ |
|
1702 |
protected int yPositionForValue(int value, int trackY, int trackHeight) { |
|
1703 |
int min = slider.getMinimum(); |
|
1704 |
int max = slider.getMaximum(); |
|
1705 |
double valueRange = (double)max - (double)min; |
|
676
8cf833d60e87
6709530: There are unnecessary code in slider classes, such as in JSlider and SliderUIs
rupashka
parents:
457
diff
changeset
|
1706 |
double pixelsPerValue = (double)trackHeight / valueRange; |
2 | 1707 |
int trackBottom = trackY + (trackHeight - 1); |
1708 |
int yPosition; |
|
1709 |
||
1710 |
if ( !drawInverted() ) { |
|
1711 |
yPosition = trackY; |
|
1712 |
yPosition += Math.round( pixelsPerValue * ((double)max - value ) ); |
|
1713 |
} |
|
1714 |
else { |
|
1715 |
yPosition = trackY; |
|
1716 |
yPosition += Math.round( pixelsPerValue * ((double)value - min) ); |
|
1717 |
} |
|
1718 |
||
1719 |
yPosition = Math.max( trackY, yPosition ); |
|
1720 |
yPosition = Math.min( trackBottom, yPosition ); |
|
1721 |
||
1722 |
return yPosition; |
|
1723 |
} |
|
1724 |
||
1725 |
/** |
|
4394 | 1726 |
* Returns the value at the y position. If {@code yPos} is beyond the |
28059
e576535359cc
8067377: My hobby: caning, then then canning, the the can-can
martin
parents:
26353
diff
changeset
|
1727 |
* track at the bottom or the top, this method sets the value to either |
4394 | 1728 |
* the minimum or maximum value of the slider, depending on if the slider |
1729 |
* is inverted or not. |
|
26012
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1730 |
* |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1731 |
* @param yPos the location of the slider along the y axis |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1732 |
* @return the value at the y position |
2 | 1733 |
*/ |
1734 |
public int valueForYPosition( int yPos ) { |
|
1735 |
int value; |
|
1736 |
final int minValue = slider.getMinimum(); |
|
1737 |
final int maxValue = slider.getMaximum(); |
|
1738 |
final int trackLength = trackRect.height; |
|
1739 |
final int trackTop = trackRect.y; |
|
1740 |
final int trackBottom = trackRect.y + (trackRect.height - 1); |
|
1741 |
||
1742 |
if ( yPos <= trackTop ) { |
|
1743 |
value = drawInverted() ? minValue : maxValue; |
|
1744 |
} |
|
1745 |
else if ( yPos >= trackBottom ) { |
|
1746 |
value = drawInverted() ? maxValue : minValue; |
|
1747 |
} |
|
1748 |
else { |
|
1749 |
int distanceFromTrackTop = yPos - trackTop; |
|
1750 |
double valueRange = (double)maxValue - (double)minValue; |
|
1751 |
double valuePerPixel = valueRange / (double)trackLength; |
|
1752 |
int valueFromTrackTop = (int)Math.round( distanceFromTrackTop * valuePerPixel ); |
|
1753 |
||
1754 |
value = drawInverted() ? minValue + valueFromTrackTop : maxValue - valueFromTrackTop; |
|
1755 |
} |
|
1756 |
||
1757 |
return value; |
|
1758 |
} |
|
1759 |
||
1760 |
/** |
|
4394 | 1761 |
* Returns the value at the x position. If {@code xPos} is beyond the |
1762 |
* track at the left or the right, this method sets the value to either the |
|
1763 |
* minimum or maximum value of the slider, depending on if the slider is |
|
1764 |
* inverted or not. |
|
26012
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1765 |
* |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1766 |
* @param xPos the location of the slider along the x axis |
36ecb579dbc8
8050924: Fix doclint missing tag warnings in javax.swing.plaf.basic parts 5b,6b of 7
yan
parents:
25565
diff
changeset
|
1767 |
* @return the value of the x position |
2 | 1768 |
*/ |
1769 |
public int valueForXPosition( int xPos ) { |
|
1770 |
int value; |
|
1771 |
final int minValue = slider.getMinimum(); |
|
1772 |
final int maxValue = slider.getMaximum(); |
|
1773 |
final int trackLength = trackRect.width; |
|
1774 |
final int trackLeft = trackRect.x; |
|
1775 |
final int trackRight = trackRect.x + (trackRect.width - 1); |
|
1776 |
||
1777 |
if ( xPos <= trackLeft ) { |
|
1778 |
value = drawInverted() ? maxValue : minValue; |
|
1779 |
} |
|
1780 |
else if ( xPos >= trackRight ) { |
|
1781 |
value = drawInverted() ? minValue : maxValue; |
|
1782 |
} |
|
1783 |
else { |
|
1784 |
int distanceFromTrackLeft = xPos - trackLeft; |
|
1785 |
double valueRange = (double)maxValue - (double)minValue; |
|
1786 |
double valuePerPixel = valueRange / (double)trackLength; |
|
1787 |
int valueFromTrackLeft = (int)Math.round( distanceFromTrackLeft * valuePerPixel ); |
|
1788 |
||
1789 |
value = drawInverted() ? maxValue - valueFromTrackLeft : |
|
1790 |
minValue + valueFromTrackLeft; |
|
1791 |
} |
|
1792 |
||
1793 |
return value; |
|
1794 |
} |
|
1795 |
||
1796 |
||
1797 |
private class Handler implements ChangeListener, |
|
1798 |
ComponentListener, FocusListener, PropertyChangeListener { |
|
1799 |
// Change Handler |
|
1800 |
public void stateChanged(ChangeEvent e) { |
|
1801 |
if (!isDragging) { |
|
1802 |
calculateThumbLocation(); |
|
1803 |
slider.repaint(); |
|
1804 |
} |
|
1805 |
lastValue = slider.getValue(); |
|
1806 |
} |
|
1807 |
||
1808 |
// Component Handler |
|
1809 |
public void componentHidden(ComponentEvent e) { } |
|
1810 |
public void componentMoved(ComponentEvent e) { } |
|
1811 |
public void componentResized(ComponentEvent e) { |
|
1812 |
calculateGeometry(); |
|
1813 |
slider.repaint(); |
|
1814 |
} |
|
1815 |
public void componentShown(ComponentEvent e) { } |
|
1816 |
||
1817 |
// Focus Handler |
|
1818 |
public void focusGained(FocusEvent e) { slider.repaint(); } |
|
1819 |
public void focusLost(FocusEvent e) { slider.repaint(); } |
|
1820 |
||
1821 |
// Property Change Handler |
|
1822 |
public void propertyChange(PropertyChangeEvent e) { |
|
1823 |
String propertyName = e.getPropertyName(); |
|
1824 |
if (propertyName == "orientation" || |
|
1825 |
propertyName == "inverted" || |
|
1826 |
propertyName == "labelTable" || |
|
1827 |
propertyName == "majorTickSpacing" || |
|
1828 |
propertyName == "minorTickSpacing" || |
|
1829 |
propertyName == "paintTicks" || |
|
1830 |
propertyName == "paintTrack" || |
|
1831 |
propertyName == "font" || |
|
3735
72286b35d392
6579827: vista : JSlider on JColorchooser is not properly render or can't be seen completely.
rupashka
parents:
2658
diff
changeset
|
1832 |
propertyName == "paintLabels" || |
72286b35d392
6579827: vista : JSlider on JColorchooser is not properly render or can't be seen completely.
rupashka
parents:
2658
diff
changeset
|
1833 |
propertyName == "Slider.paintThumbArrowShape") { |
2 | 1834 |
checkedLabelBaselines = false; |
1835 |
calculateGeometry(); |
|
1836 |
slider.repaint(); |
|
1837 |
} else if (propertyName == "componentOrientation") { |
|
1838 |
calculateGeometry(); |
|
1839 |
slider.repaint(); |
|
1840 |
InputMap km = getInputMap(JComponent.WHEN_FOCUSED, slider); |
|
1841 |
SwingUtilities.replaceUIInputMap(slider, |
|
1842 |
JComponent.WHEN_FOCUSED, km); |
|
1843 |
} else if (propertyName == "model") { |
|
1844 |
((BoundedRangeModel)e.getOldValue()).removeChangeListener( |
|
1845 |
changeListener); |
|
1846 |
((BoundedRangeModel)e.getNewValue()).addChangeListener( |
|
1847 |
changeListener); |
|
1848 |
calculateThumbLocation(); |
|
1849 |
slider.repaint(); |
|
1850 |
} |
|
1851 |
} |
|
1852 |
} |
|
1853 |
||
1854 |
///////////////////////////////////////////////////////////////////////// |
|
1855 |
/// Model Listener Class |
|
1856 |
///////////////////////////////////////////////////////////////////////// |
|
1857 |
/** |
|
1858 |
* Data model listener. |
|
1859 |
* |
|
1860 |
* This class should be treated as a "protected" inner class. |
|
20169 | 1861 |
* Instantiate it only within subclasses of <code>Foo</code>. |
2 | 1862 |
*/ |
1863 |
public class ChangeHandler implements ChangeListener { |
|
21278 | 1864 |
// NOTE: This class exists only for backward compatibility. All |
2 | 1865 |
// its functionality has been moved into Handler. If you need to add |
1866 |
// new functionality add it to the Handler, but make sure this |
|
1867 |
// class calls into the Handler. |
|
1868 |
public void stateChanged(ChangeEvent e) { |
|
1869 |
getHandler().stateChanged(e); |
|
1870 |
} |
|
1871 |
} |
|
1872 |
||
1873 |
///////////////////////////////////////////////////////////////////////// |
|
1874 |
/// Track Listener Class |
|
1875 |
///////////////////////////////////////////////////////////////////////// |
|
1876 |
/** |
|
1877 |
* Track mouse movements. |
|
1878 |
* |
|
1879 |
* This class should be treated as a "protected" inner class. |
|
20169 | 1880 |
* Instantiate it only within subclasses of <code>Foo</code>. |
2 | 1881 |
*/ |
1882 |
public class TrackListener extends MouseInputAdapter { |
|
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1883 |
/** The offset */ |
2 | 1884 |
protected transient int offset; |
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1885 |
/** Current mouse x. */ |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1886 |
protected transient int currentMouseX; |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1887 |
/** Current mouse y. */ |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1888 |
protected transient int currentMouseY; |
2 | 1889 |
|
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1890 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1891 |
* {@inheritDoc} |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
1892 |
*/ |
2 | 1893 |
public void mouseReleased(MouseEvent e) { |
1894 |
if (!slider.isEnabled()) { |
|
1895 |
return; |
|
1896 |
} |
|
1897 |
||
1898 |
offset = 0; |
|
1899 |
scrollTimer.stop(); |
|
1900 |
||
4957
e33105a2db5b
6848475: JSlider does not display the correct value of its BoundedRangeModel
rupashka
parents:
4394
diff
changeset
|
1901 |
isDragging = false; |
e33105a2db5b
6848475: JSlider does not display the correct value of its BoundedRangeModel
rupashka
parents:
4394
diff
changeset
|
1902 |
slider.setValueIsAdjusting(false); |
2 | 1903 |
slider.repaint(); |
1904 |
} |
|
1905 |
||
1906 |
/** |
|
1907 |
* If the mouse is pressed above the "thumb" component |
|
1908 |
* then reduce the scrollbars value by one page ("page up"), |
|
1909 |
* otherwise increase it by one page. If there is no |
|
1910 |
* thumb then page up if the mouse is in the upper half |
|
1911 |
* of the track. |
|
1912 |
*/ |
|
1913 |
public void mousePressed(MouseEvent e) { |
|
1914 |
if (!slider.isEnabled()) { |
|
1915 |
return; |
|
1916 |
} |
|
1917 |
||
1918 |
// We should recalculate geometry just before |
|
1919 |
// calculation of the thumb movement direction. |
|
1920 |
// It is important for the case, when JSlider |
|
1921 |
// is a cell editor in JTable. See 6348946. |
|
1922 |
calculateGeometry(); |
|
1923 |
||
1924 |
currentMouseX = e.getX(); |
|
1925 |
currentMouseY = e.getY(); |
|
1926 |
||
1927 |
if (slider.isRequestFocusEnabled()) { |
|
1928 |
slider.requestFocus(); |
|
1929 |
} |
|
1930 |
||
1931 |
// Clicked in the Thumb area? |
|
1932 |
if (thumbRect.contains(currentMouseX, currentMouseY)) { |
|
456
8ded0dbe4aaa
6614972: JSlider value should not change on right-click
rupashka
parents:
2
diff
changeset
|
1933 |
if (UIManager.getBoolean("Slider.onlyLeftMouseButtonDrag") |
8ded0dbe4aaa
6614972: JSlider value should not change on right-click
rupashka
parents:
2
diff
changeset
|
1934 |
&& !SwingUtilities.isLeftMouseButton(e)) { |
8ded0dbe4aaa
6614972: JSlider value should not change on right-click
rupashka
parents:
2
diff
changeset
|
1935 |
return; |
8ded0dbe4aaa
6614972: JSlider value should not change on right-click
rupashka
parents:
2
diff
changeset
|
1936 |
} |
8ded0dbe4aaa
6614972: JSlider value should not change on right-click
rupashka
parents:
2
diff
changeset
|
1937 |
|
2 | 1938 |
switch (slider.getOrientation()) { |
1939 |
case JSlider.VERTICAL: |
|
1940 |
offset = currentMouseY - thumbRect.y; |
|
1941 |
break; |
|
1942 |
case JSlider.HORIZONTAL: |
|
1943 |
offset = currentMouseX - thumbRect.x; |
|
1944 |
break; |
|
1945 |
} |
|
1946 |
isDragging = true; |
|
1947 |
return; |
|
1948 |
} |
|
456
8ded0dbe4aaa
6614972: JSlider value should not change on right-click
rupashka
parents:
2
diff
changeset
|
1949 |
|
8ded0dbe4aaa
6614972: JSlider value should not change on right-click
rupashka
parents:
2
diff
changeset
|
1950 |
if (!SwingUtilities.isLeftMouseButton(e)) { |
8ded0dbe4aaa
6614972: JSlider value should not change on right-click
rupashka
parents:
2
diff
changeset
|
1951 |
return; |
8ded0dbe4aaa
6614972: JSlider value should not change on right-click
rupashka
parents:
2
diff
changeset
|
1952 |
} |
8ded0dbe4aaa
6614972: JSlider value should not change on right-click
rupashka
parents:
2
diff
changeset
|
1953 |
|
2 | 1954 |
isDragging = false; |
1955 |
slider.setValueIsAdjusting(true); |
|
1956 |
||
1957 |
Dimension sbSize = slider.getSize(); |
|
1958 |
int direction = POSITIVE_SCROLL; |
|
1959 |
||
1960 |
switch (slider.getOrientation()) { |
|
1961 |
case JSlider.VERTICAL: |
|
1962 |
if ( thumbRect.isEmpty() ) { |
|
1963 |
int scrollbarCenter = sbSize.height / 2; |
|
1964 |
if ( !drawInverted() ) { |
|
1965 |
direction = (currentMouseY < scrollbarCenter) ? |
|
1966 |
POSITIVE_SCROLL : NEGATIVE_SCROLL; |
|
1967 |
} |
|
1968 |
else { |
|
1969 |
direction = (currentMouseY < scrollbarCenter) ? |
|
1970 |
NEGATIVE_SCROLL : POSITIVE_SCROLL; |
|
1971 |
} |
|
1972 |
} |
|
1973 |
else { |
|
1974 |
int thumbY = thumbRect.y; |
|
1975 |
if ( !drawInverted() ) { |
|
1976 |
direction = (currentMouseY < thumbY) ? |
|
1977 |
POSITIVE_SCROLL : NEGATIVE_SCROLL; |
|
1978 |
} |
|
1979 |
else { |
|
1980 |
direction = (currentMouseY < thumbY) ? |
|
1981 |
NEGATIVE_SCROLL : POSITIVE_SCROLL; |
|
1982 |
} |
|
1983 |
} |
|
1984 |
break; |
|
1985 |
case JSlider.HORIZONTAL: |
|
1986 |
if ( thumbRect.isEmpty() ) { |
|
1987 |
int scrollbarCenter = sbSize.width / 2; |
|
1988 |
if ( !drawInverted() ) { |
|
1989 |
direction = (currentMouseX < scrollbarCenter) ? |
|
1990 |
NEGATIVE_SCROLL : POSITIVE_SCROLL; |
|
1991 |
} |
|
1992 |
else { |
|
1993 |
direction = (currentMouseX < scrollbarCenter) ? |
|
1994 |
POSITIVE_SCROLL : NEGATIVE_SCROLL; |
|
1995 |
} |
|
1996 |
} |
|
1997 |
else { |
|
1998 |
int thumbX = thumbRect.x; |
|
1999 |
if ( !drawInverted() ) { |
|
2000 |
direction = (currentMouseX < thumbX) ? |
|
2001 |
NEGATIVE_SCROLL : POSITIVE_SCROLL; |
|
2002 |
} |
|
2003 |
else { |
|
2004 |
direction = (currentMouseX < thumbX) ? |
|
2005 |
POSITIVE_SCROLL : NEGATIVE_SCROLL; |
|
2006 |
} |
|
2007 |
} |
|
2008 |
break; |
|
2009 |
} |
|
2010 |
||
2011 |
if (shouldScroll(direction)) { |
|
2012 |
scrollDueToClickInTrack(direction); |
|
2013 |
} |
|
2014 |
if (shouldScroll(direction)) { |
|
2015 |
scrollTimer.stop(); |
|
2016 |
scrollListener.setDirection(direction); |
|
2017 |
scrollTimer.start(); |
|
2018 |
} |
|
2019 |
} |
|
2020 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2021 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2022 |
* Returns if scrolling should occur |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2023 |
* @param direction the direction. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2024 |
* @return if scrolling should occur |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2025 |
*/ |
2 | 2026 |
public boolean shouldScroll(int direction) { |
2027 |
Rectangle r = thumbRect; |
|
2028 |
if (slider.getOrientation() == JSlider.VERTICAL) { |
|
2029 |
if (drawInverted() ? direction < 0 : direction > 0) { |
|
2030 |
if (r.y <= currentMouseY) { |
|
2031 |
return false; |
|
2032 |
} |
|
2033 |
} |
|
2034 |
else if (r.y + r.height >= currentMouseY) { |
|
2035 |
return false; |
|
2036 |
} |
|
2037 |
} |
|
2038 |
else { |
|
2039 |
if (drawInverted() ? direction < 0 : direction > 0) { |
|
2040 |
if (r.x + r.width >= currentMouseX) { |
|
2041 |
return false; |
|
2042 |
} |
|
2043 |
} |
|
2044 |
else if (r.x <= currentMouseX) { |
|
2045 |
return false; |
|
2046 |
} |
|
2047 |
} |
|
2048 |
||
2049 |
if (direction > 0 && slider.getValue() + slider.getExtent() >= |
|
2050 |
slider.getMaximum()) { |
|
2051 |
return false; |
|
2052 |
} |
|
2053 |
else if (direction < 0 && slider.getValue() <= |
|
2054 |
slider.getMinimum()) { |
|
2055 |
return false; |
|
2056 |
} |
|
2057 |
||
2058 |
return true; |
|
2059 |
} |
|
2060 |
||
2061 |
/** |
|
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2062 |
* Set the models value to the position of the top/left |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2063 |
* of the thumb relative to the origin of the track. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2064 |
*/ |
2 | 2065 |
public void mouseDragged(MouseEvent e) { |
676
8cf833d60e87
6709530: There are unnecessary code in slider classes, such as in JSlider and SliderUIs
rupashka
parents:
457
diff
changeset
|
2066 |
int thumbMiddle; |
2 | 2067 |
|
2068 |
if (!slider.isEnabled()) { |
|
2069 |
return; |
|
2070 |
} |
|
2071 |
||
2072 |
currentMouseX = e.getX(); |
|
2073 |
currentMouseY = e.getY(); |
|
2074 |
||
2075 |
if (!isDragging) { |
|
2076 |
return; |
|
2077 |
} |
|
2078 |
||
2079 |
slider.setValueIsAdjusting(true); |
|
2080 |
||
2081 |
switch (slider.getOrientation()) { |
|
2082 |
case JSlider.VERTICAL: |
|
2083 |
int halfThumbHeight = thumbRect.height / 2; |
|
2084 |
int thumbTop = e.getY() - offset; |
|
2085 |
int trackTop = trackRect.y; |
|
2086 |
int trackBottom = trackRect.y + (trackRect.height - 1); |
|
2087 |
int vMax = yPositionForValue(slider.getMaximum() - |
|
2088 |
slider.getExtent()); |
|
2089 |
||
2090 |
if (drawInverted()) { |
|
2091 |
trackBottom = vMax; |
|
2092 |
} |
|
2093 |
else { |
|
2094 |
trackTop = vMax; |
|
2095 |
} |
|
2096 |
thumbTop = Math.max(thumbTop, trackTop - halfThumbHeight); |
|
2097 |
thumbTop = Math.min(thumbTop, trackBottom - halfThumbHeight); |
|
2098 |
||
2099 |
setThumbLocation(thumbRect.x, thumbTop); |
|
2100 |
||
2101 |
thumbMiddle = thumbTop + halfThumbHeight; |
|
2102 |
slider.setValue( valueForYPosition( thumbMiddle ) ); |
|
2103 |
break; |
|
2104 |
case JSlider.HORIZONTAL: |
|
2105 |
int halfThumbWidth = thumbRect.width / 2; |
|
2106 |
int thumbLeft = e.getX() - offset; |
|
2107 |
int trackLeft = trackRect.x; |
|
2108 |
int trackRight = trackRect.x + (trackRect.width - 1); |
|
2109 |
int hMax = xPositionForValue(slider.getMaximum() - |
|
2110 |
slider.getExtent()); |
|
2111 |
||
2112 |
if (drawInverted()) { |
|
2113 |
trackLeft = hMax; |
|
2114 |
} |
|
2115 |
else { |
|
2116 |
trackRight = hMax; |
|
2117 |
} |
|
2118 |
thumbLeft = Math.max(thumbLeft, trackLeft - halfThumbWidth); |
|
2119 |
thumbLeft = Math.min(thumbLeft, trackRight - halfThumbWidth); |
|
2120 |
||
2121 |
setThumbLocation(thumbLeft, thumbRect.y); |
|
2122 |
||
2123 |
thumbMiddle = thumbLeft + halfThumbWidth; |
|
2124 |
slider.setValue(valueForXPosition(thumbMiddle)); |
|
2125 |
break; |
|
2126 |
} |
|
2127 |
} |
|
2128 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2129 |
/** {@inheritDoc} */ |
2 | 2130 |
public void mouseMoved(MouseEvent e) { } |
2131 |
} |
|
2132 |
||
2133 |
/** |
|
2134 |
* Scroll-event listener. |
|
2135 |
* |
|
2136 |
* This class should be treated as a "protected" inner class. |
|
20169 | 2137 |
* Instantiate it only within subclasses of <code>Foo</code>. |
2 | 2138 |
*/ |
2139 |
public class ScrollListener implements ActionListener { |
|
2140 |
// changed this class to public to avoid bogus IllegalAccessException |
|
2141 |
// bug in InternetExplorer browser. It was protected. Work around |
|
2142 |
// for 4109432 |
|
2143 |
int direction = POSITIVE_SCROLL; |
|
2144 |
boolean useBlockIncrement; |
|
2145 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2146 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2147 |
* Constructs a {@code ScrollListener} |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2148 |
*/ |
2 | 2149 |
public ScrollListener() { |
2150 |
direction = POSITIVE_SCROLL; |
|
2151 |
useBlockIncrement = true; |
|
2152 |
} |
|
2153 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2154 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2155 |
* Constructs a {@code ScrollListener} |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2156 |
* @param dir the direction |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2157 |
* @param block whether or not to scroll by block |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2158 |
*/ |
2 | 2159 |
public ScrollListener(int dir, boolean block) { |
2160 |
direction = dir; |
|
2161 |
useBlockIncrement = block; |
|
2162 |
} |
|
2163 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2164 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2165 |
* Sets the direction. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2166 |
* @param direction the new direction |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2167 |
*/ |
2 | 2168 |
public void setDirection(int direction) { |
2169 |
this.direction = direction; |
|
2170 |
} |
|
2171 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2172 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2173 |
* Sets scrolling by block |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2174 |
* @param block the new scroll by block value |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2175 |
*/ |
2 | 2176 |
public void setScrollByBlock(boolean block) { |
2177 |
this.useBlockIncrement = block; |
|
2178 |
} |
|
2179 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2180 |
/** {@inheritDoc} */ |
2 | 2181 |
public void actionPerformed(ActionEvent e) { |
2182 |
if (useBlockIncrement) { |
|
2183 |
scrollByBlock(direction); |
|
2184 |
} |
|
2185 |
else { |
|
2186 |
scrollByUnit(direction); |
|
2187 |
} |
|
2188 |
if (!trackListener.shouldScroll(direction)) { |
|
2189 |
((Timer)e.getSource()).stop(); |
|
2190 |
} |
|
2191 |
} |
|
2192 |
} |
|
2193 |
||
2194 |
/** |
|
2195 |
* Listener for resizing events. |
|
2196 |
* <p> |
|
2197 |
* This class should be treated as a "protected" inner class. |
|
20169 | 2198 |
* Instantiate it only within subclasses of <code>Foo</code>. |
2 | 2199 |
*/ |
2200 |
public class ComponentHandler extends ComponentAdapter { |
|
21278 | 2201 |
// NOTE: This class exists only for backward compatibility. All |
2 | 2202 |
// its functionality has been moved into Handler. If you need to add |
2203 |
// new functionality add it to the Handler, but make sure this |
|
2204 |
// class calls into the Handler. |
|
2205 |
public void componentResized(ComponentEvent e) { |
|
2206 |
getHandler().componentResized(e); |
|
2207 |
} |
|
676
8cf833d60e87
6709530: There are unnecessary code in slider classes, such as in JSlider and SliderUIs
rupashka
parents:
457
diff
changeset
|
2208 |
} |
2 | 2209 |
|
2210 |
/** |
|
2211 |
* Focus-change listener. |
|
2212 |
* <p> |
|
2213 |
* This class should be treated as a "protected" inner class. |
|
20169 | 2214 |
* Instantiate it only within subclasses of <code>Foo</code>. |
2 | 2215 |
*/ |
2216 |
public class FocusHandler implements FocusListener { |
|
21278 | 2217 |
// NOTE: This class exists only for backward compatibility. All |
2 | 2218 |
// its functionality has been moved into Handler. If you need to add |
2219 |
// new functionality add it to the Handler, but make sure this |
|
2220 |
// class calls into the Handler. |
|
2221 |
public void focusGained(FocusEvent e) { |
|
2222 |
getHandler().focusGained(e); |
|
2223 |
} |
|
2224 |
||
2225 |
public void focusLost(FocusEvent e) { |
|
2226 |
getHandler().focusLost(e); |
|
2227 |
} |
|
2228 |
} |
|
2229 |
||
2230 |
/** |
|
2231 |
* As of Java 2 platform v1.3 this undocumented class is no longer used. |
|
2232 |
* The recommended approach to creating bindings is to use a |
|
2233 |
* combination of an <code>ActionMap</code>, to contain the action, |
|
2234 |
* and an <code>InputMap</code> to contain the mapping from KeyStroke |
|
28059
e576535359cc
8067377: My hobby: caning, then then canning, the the can-can
martin
parents:
26353
diff
changeset
|
2235 |
* to action description. The InputMap is usually described in the |
2 | 2236 |
* LookAndFeel tables. |
2237 |
* <p> |
|
2238 |
* Please refer to the key bindings specification for further details. |
|
2239 |
* <p> |
|
2240 |
* This class should be treated as a "protected" inner class. |
|
20169 | 2241 |
* Instantiate it only within subclasses of <code>Foo</code>. |
2 | 2242 |
*/ |
23697 | 2243 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 2244 |
public class ActionScroller extends AbstractAction { |
21278 | 2245 |
// NOTE: This class exists only for backward compatibility. All |
2 | 2246 |
// its functionality has been moved into Actions. If you need to add |
2247 |
// new functionality add it to the Actions, but make sure this |
|
2248 |
// class calls into the Actions. |
|
2249 |
int dir; |
|
2250 |
boolean block; |
|
2251 |
JSlider slider; |
|
2252 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2253 |
/** |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2254 |
* Constructs an {@code ActionScroller}. |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2255 |
* @param slider a slider |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2256 |
* @param dir the direction |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2257 |
* @param block block scrolling or not |
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2258 |
*/ |
2 | 2259 |
public ActionScroller( JSlider slider, int dir, boolean block) { |
2260 |
this.dir = dir; |
|
2261 |
this.block = block; |
|
2262 |
this.slider = slider; |
|
2263 |
} |
|
2264 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2265 |
/** {@inheritDoc} */ |
2 | 2266 |
public void actionPerformed(ActionEvent e) { |
2267 |
SHARED_ACTION.scroll(slider, BasicSliderUI.this, dir, block); |
|
2268 |
} |
|
2269 |
||
30461
57e36ed1a9ab
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents:
28059
diff
changeset
|
2270 |
/** {@inheritDoc} */ |
2 | 2271 |
public boolean isEnabled() { |
2272 |
boolean b = true; |
|
2273 |
if (slider != null) { |
|
2274 |
b = slider.isEnabled(); |
|
2275 |
} |
|
2276 |
return b; |
|
2277 |
} |
|
2278 |
||
676
8cf833d60e87
6709530: There are unnecessary code in slider classes, such as in JSlider and SliderUIs
rupashka
parents:
457
diff
changeset
|
2279 |
} |
2 | 2280 |
|
2281 |
||
2282 |
/** |
|
2283 |
* A static version of the above. |
|
2284 |
*/ |
|
23697 | 2285 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 2286 |
static class SharedActionScroller extends AbstractAction { |
21278 | 2287 |
// NOTE: This class exists only for backward compatibility. All |
2 | 2288 |
// its functionality has been moved into Actions. If you need to add |
2289 |
// new functionality add it to the Actions, but make sure this |
|
2290 |
// class calls into the Actions. |
|
2291 |
int dir; |
|
2292 |
boolean block; |
|
2293 |
||
2294 |
public SharedActionScroller(int dir, boolean block) { |
|
2295 |
this.dir = dir; |
|
2296 |
this.block = block; |
|
2297 |
} |
|
2298 |
||
2299 |
public void actionPerformed(ActionEvent evt) { |
|
2300 |
JSlider slider = (JSlider)evt.getSource(); |
|
2301 |
BasicSliderUI ui = (BasicSliderUI)BasicLookAndFeel.getUIOfType( |
|
2302 |
slider.getUI(), BasicSliderUI.class); |
|
2303 |
if (ui == null) { |
|
2304 |
return; |
|
2305 |
} |
|
2306 |
SHARED_ACTION.scroll(slider, ui, dir, block); |
|
2307 |
} |
|
2308 |
} |
|
2309 |
||
2310 |
private static class Actions extends UIAction { |
|
2311 |
public static final String POSITIVE_UNIT_INCREMENT = |
|
2312 |
"positiveUnitIncrement"; |
|
2313 |
public static final String POSITIVE_BLOCK_INCREMENT = |
|
2314 |
"positiveBlockIncrement"; |
|
2315 |
public static final String NEGATIVE_UNIT_INCREMENT = |
|
2316 |
"negativeUnitIncrement"; |
|
2317 |
public static final String NEGATIVE_BLOCK_INCREMENT = |
|
2318 |
"negativeBlockIncrement"; |
|
2319 |
public static final String MIN_SCROLL_INCREMENT = "minScroll"; |
|
2320 |
public static final String MAX_SCROLL_INCREMENT = "maxScroll"; |
|
2321 |
||
2322 |
||
2323 |
Actions() { |
|
2324 |
super(null); |
|
2325 |
} |
|
2326 |
||
2327 |
public Actions(String name) { |
|
2328 |
super(name); |
|
2329 |
} |
|
2330 |
||
2331 |
public void actionPerformed(ActionEvent evt) { |
|
2332 |
JSlider slider = (JSlider)evt.getSource(); |
|
2333 |
BasicSliderUI ui = (BasicSliderUI)BasicLookAndFeel.getUIOfType( |
|
2334 |
slider.getUI(), BasicSliderUI.class); |
|
2335 |
String name = getName(); |
|
2336 |
||
2337 |
if (ui == null) { |
|
2338 |
return; |
|
2339 |
} |
|
2340 |
if (POSITIVE_UNIT_INCREMENT == name) { |
|
2341 |
scroll(slider, ui, POSITIVE_SCROLL, false); |
|
2342 |
} else if (NEGATIVE_UNIT_INCREMENT == name) { |
|
2343 |
scroll(slider, ui, NEGATIVE_SCROLL, false); |
|
2344 |
} else if (POSITIVE_BLOCK_INCREMENT == name) { |
|
2345 |
scroll(slider, ui, POSITIVE_SCROLL, true); |
|
2346 |
} else if (NEGATIVE_BLOCK_INCREMENT == name) { |
|
2347 |
scroll(slider, ui, NEGATIVE_SCROLL, true); |
|
2348 |
} else if (MIN_SCROLL_INCREMENT == name) { |
|
2349 |
scroll(slider, ui, MIN_SCROLL, false); |
|
2350 |
} else if (MAX_SCROLL_INCREMENT == name) { |
|
2351 |
scroll(slider, ui, MAX_SCROLL, false); |
|
2352 |
} |
|
2353 |
} |
|
2354 |
||
2355 |
private void scroll(JSlider slider, BasicSliderUI ui, int direction, |
|
2356 |
boolean isBlock) { |
|
2357 |
boolean invert = slider.getInverted(); |
|
2358 |
||
2359 |
if (direction == NEGATIVE_SCROLL || direction == POSITIVE_SCROLL) { |
|
2360 |
if (invert) { |
|
2361 |
direction = (direction == POSITIVE_SCROLL) ? |
|
2362 |
NEGATIVE_SCROLL : POSITIVE_SCROLL; |
|
2363 |
} |
|
2364 |
||
2365 |
if (isBlock) { |
|
2366 |
ui.scrollByBlock(direction); |
|
2367 |
} else { |
|
2368 |
ui.scrollByUnit(direction); |
|
2369 |
} |
|
2370 |
} else { // MIN or MAX |
|
2371 |
if (invert) { |
|
2372 |
direction = (direction == MIN_SCROLL) ? |
|
2373 |
MAX_SCROLL : MIN_SCROLL; |
|
2374 |
} |
|
2375 |
||
2376 |
slider.setValue((direction == MIN_SCROLL) ? |
|
2377 |
slider.getMinimum() : slider.getMaximum()); |
|
2378 |
} |
|
2379 |
} |
|
2380 |
} |
|
2381 |
} |