author | yan |
Mon, 30 Jun 2014 16:32:36 +0400 | |
changeset 25178 | dbab904451e9 |
parent 22574 | 7f8ce0c8c20a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
22574
7f8ce0c8c20a
8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents:
21278
diff
changeset
|
2 |
* Copyright (c) 1998, 2014, 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.metal; |
|
27 |
||
28 |
import javax.swing.plaf.basic.BasicSliderUI; |
|
29 |
||
30 |
import java.awt.Graphics; |
|
31 |
import java.awt.Dimension; |
|
32 |
import java.awt.Rectangle; |
|
33 |
import java.awt.Color; |
|
34 |
import java.beans.*; |
|
35 |
||
36 |
import javax.swing.*; |
|
37 |
import javax.swing.plaf.*; |
|
38 |
||
39 |
/** |
|
20169 | 40 |
* A Java L&F implementation of SliderUI. |
2 | 41 |
* <p> |
42 |
* <strong>Warning:</strong> |
|
43 |
* Serialized objects of this class will not be compatible with |
|
44 |
* future Swing releases. The current serialization support is |
|
45 |
* appropriate for short term storage or RMI between applications running |
|
46 |
* the same version of Swing. As of 1.4, support for long term storage |
|
20458 | 47 |
* of all JavaBeans™ |
2 | 48 |
* has been added to the <code>java.beans</code> package. |
49 |
* Please see {@link java.beans.XMLEncoder}. |
|
50 |
* |
|
51 |
* @author Tom Santos |
|
52 |
*/ |
|
22574
7f8ce0c8c20a
8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents:
21278
diff
changeset
|
53 |
@SuppressWarnings("serial") // Same-version serialization only |
2 | 54 |
public class MetalSliderUI extends BasicSliderUI { |
55 |
||
25178
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
56 |
/** |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
57 |
* The buffer of a tick. |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
58 |
*/ |
2 | 59 |
protected final int TICK_BUFFER = 4; |
25178
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
60 |
|
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
61 |
/** |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
62 |
* The value of the property {@code JSlider.isFilled}. |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
63 |
* By default, {@code false} if the property is not set, |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
64 |
* {@code true} for Ocean theme. |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
65 |
*/ |
2 | 66 |
protected boolean filledSlider = false; |
25178
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
67 |
|
4199
151e13fd2df1
6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
1639
diff
changeset
|
68 |
// NOTE: these next five variables are currently unused. |
25178
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
69 |
/** |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
70 |
* The color of a thumb |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
71 |
*/ |
2 | 72 |
protected static Color thumbColor; |
25178
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
73 |
|
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
74 |
/** |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
75 |
* The color of highlighting. |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
76 |
*/ |
2 | 77 |
protected static Color highlightColor; |
25178
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
78 |
|
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
79 |
/** |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
80 |
* The color of dark shadow. |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
81 |
*/ |
2 | 82 |
protected static Color darkShadowColor; |
25178
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
83 |
|
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
84 |
/** |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
85 |
* The width of a track. |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
86 |
*/ |
2 | 87 |
protected static int trackWidth; |
25178
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
88 |
|
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
89 |
/** |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
90 |
* The length of a tick. |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
91 |
*/ |
2 | 92 |
protected static int tickLength; |
4199
151e13fd2df1
6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
1639
diff
changeset
|
93 |
private int safeLength; |
2 | 94 |
|
95 |
/** |
|
96 |
* A default horizontal thumb <code>Icon</code>. This field might not be |
|
21278 | 97 |
* used. To change the <code>Icon</code> used by this delegate directly set it |
2 | 98 |
* using the <code>Slider.horizontalThumbIcon</code> UIManager property. |
99 |
*/ |
|
100 |
protected static Icon horizThumbIcon; |
|
101 |
||
102 |
/** |
|
103 |
* A default vertical thumb <code>Icon</code>. This field might not be |
|
21278 | 104 |
* used. To change the <code>Icon</code> used by this delegate directly set it |
2 | 105 |
* using the <code>Slider.verticalThumbIcon</code> UIManager property. |
106 |
*/ |
|
107 |
protected static Icon vertThumbIcon; |
|
108 |
||
109 |
private static Icon SAFE_HORIZ_THUMB_ICON; |
|
110 |
private static Icon SAFE_VERT_THUMB_ICON; |
|
111 |
||
25178
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
112 |
/** |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
113 |
* Property for {@code JSlider.isFilled}. |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
114 |
*/ |
2 | 115 |
protected final String SLIDER_FILL = "JSlider.isFilled"; |
116 |
||
25178
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
117 |
/** |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
118 |
* Constructs a {@code MetalSliderUI} instance. |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
119 |
* |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
120 |
* @param c a component |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
121 |
* @return a {@code MetalSliderUI} instance |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
122 |
*/ |
2 | 123 |
public static ComponentUI createUI(JComponent c) { |
124 |
return new MetalSliderUI(); |
|
125 |
} |
|
126 |
||
25178
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
127 |
/** |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
128 |
* Constructs a {@code MetalSliderUI} instance. |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
129 |
*/ |
2 | 130 |
public MetalSliderUI() { |
131 |
super( null ); |
|
132 |
} |
|
133 |
||
134 |
private static Icon getHorizThumbIcon() { |
|
135 |
if (System.getSecurityManager() != null) { |
|
136 |
return SAFE_HORIZ_THUMB_ICON; |
|
137 |
} else { |
|
138 |
return horizThumbIcon; |
|
139 |
} |
|
140 |
} |
|
141 |
||
142 |
private static Icon getVertThumbIcon() { |
|
143 |
if (System.getSecurityManager() != null) { |
|
144 |
return SAFE_VERT_THUMB_ICON; |
|
145 |
} else { |
|
146 |
return vertThumbIcon; |
|
147 |
} |
|
148 |
} |
|
149 |
||
150 |
public void installUI( JComponent c ) { |
|
151 |
trackWidth = ((Integer)UIManager.get( "Slider.trackWidth" )).intValue(); |
|
4199
151e13fd2df1
6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
1639
diff
changeset
|
152 |
tickLength = safeLength = ((Integer)UIManager.get( "Slider.majorTickLength" )).intValue(); |
2 | 153 |
horizThumbIcon = SAFE_HORIZ_THUMB_ICON = |
154 |
UIManager.getIcon( "Slider.horizontalThumbIcon" ); |
|
155 |
vertThumbIcon = SAFE_VERT_THUMB_ICON = |
|
156 |
UIManager.getIcon( "Slider.verticalThumbIcon" ); |
|
157 |
||
158 |
super.installUI( c ); |
|
159 |
||
160 |
thumbColor = UIManager.getColor("Slider.thumb"); |
|
161 |
highlightColor = UIManager.getColor("Slider.highlight"); |
|
162 |
darkShadowColor = UIManager.getColor("Slider.darkShadow"); |
|
163 |
||
164 |
scrollListener.setScrollByBlock( false ); |
|
165 |
||
1317
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
166 |
prepareFilledSliderField(); |
2 | 167 |
} |
168 |
||
25178
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
169 |
/** |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
170 |
* Constructs {@code MetalPropertyListener}. |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
171 |
* |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
172 |
* @param slider a {@code JSlider} |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
173 |
* @return the {@code MetalPropertyListener} |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
174 |
*/ |
2 | 175 |
protected PropertyChangeListener createPropertyChangeListener( JSlider slider ) { |
176 |
return new MetalPropertyListener(); |
|
177 |
} |
|
178 |
||
25178
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
179 |
/** |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
180 |
* {@code PropertyListener} for {@code JSlider.isFilled}. |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
181 |
*/ |
2 | 182 |
protected class MetalPropertyListener extends BasicSliderUI.PropertyChangeHandler { |
183 |
public void propertyChange( PropertyChangeEvent e ) { // listen for slider fill |
|
184 |
super.propertyChange( e ); |
|
185 |
||
1317
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
186 |
if (e.getPropertyName().equals(SLIDER_FILL)) { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
187 |
prepareFilledSliderField(); |
2 | 188 |
} |
189 |
} |
|
190 |
} |
|
191 |
||
1317
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
192 |
private void prepareFilledSliderField() { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
193 |
// Use true for Ocean theme |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
194 |
filledSlider = MetalLookAndFeel.usingOcean(); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
195 |
|
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
196 |
Object sliderFillProp = slider.getClientProperty(SLIDER_FILL); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
197 |
|
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
198 |
if (sliderFillProp != null) { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
199 |
filledSlider = ((Boolean) sliderFillProp).booleanValue(); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
200 |
} |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
201 |
} |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
202 |
|
2 | 203 |
public void paintThumb(Graphics g) { |
204 |
Rectangle knobBounds = thumbRect; |
|
205 |
||
206 |
g.translate( knobBounds.x, knobBounds.y ); |
|
207 |
||
208 |
if ( slider.getOrientation() == JSlider.HORIZONTAL ) { |
|
209 |
getHorizThumbIcon().paintIcon( slider, g, 0, 0 ); |
|
210 |
} |
|
211 |
else { |
|
212 |
getVertThumbIcon().paintIcon( slider, g, 0, 0 ); |
|
213 |
} |
|
214 |
||
215 |
g.translate( -knobBounds.x, -knobBounds.y ); |
|
216 |
} |
|
217 |
||
218 |
/** |
|
219 |
* Returns a rectangle enclosing the track that will be painted. |
|
220 |
*/ |
|
221 |
private Rectangle getPaintTrackRect() { |
|
1317
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
222 |
int trackLeft = 0, trackRight, trackTop = 0, trackBottom; |
2 | 223 |
if (slider.getOrientation() == JSlider.HORIZONTAL) { |
224 |
trackBottom = (trackRect.height - 1) - getThumbOverhang(); |
|
225 |
trackTop = trackBottom - (getTrackWidth() - 1); |
|
226 |
trackRight = trackRect.width - 1; |
|
227 |
} |
|
228 |
else { |
|
229 |
if (MetalUtils.isLeftToRight(slider)) { |
|
230 |
trackLeft = (trackRect.width - getThumbOverhang()) - |
|
231 |
getTrackWidth(); |
|
232 |
trackRight = (trackRect.width - getThumbOverhang()) - 1; |
|
233 |
} |
|
234 |
else { |
|
235 |
trackLeft = getThumbOverhang(); |
|
236 |
trackRight = getThumbOverhang() + getTrackWidth() - 1; |
|
237 |
} |
|
238 |
trackBottom = trackRect.height - 1; |
|
239 |
} |
|
240 |
return new Rectangle(trackRect.x + trackLeft, trackRect.y + trackTop, |
|
241 |
trackRight - trackLeft, trackBottom - trackTop); |
|
242 |
} |
|
243 |
||
244 |
public void paintTrack(Graphics g) { |
|
245 |
if (MetalLookAndFeel.usingOcean()) { |
|
246 |
oceanPaintTrack(g); |
|
247 |
return; |
|
248 |
} |
|
249 |
Color trackColor = !slider.isEnabled() ? MetalLookAndFeel.getControlShadow() : |
|
250 |
slider.getForeground(); |
|
251 |
||
252 |
boolean leftToRight = MetalUtils.isLeftToRight(slider); |
|
253 |
||
254 |
g.translate( trackRect.x, trackRect.y ); |
|
255 |
||
256 |
int trackLeft = 0; |
|
257 |
int trackTop = 0; |
|
1317
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
258 |
int trackRight; |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
259 |
int trackBottom; |
2 | 260 |
|
261 |
// Draw the track |
|
262 |
if ( slider.getOrientation() == JSlider.HORIZONTAL ) { |
|
263 |
trackBottom = (trackRect.height - 1) - getThumbOverhang(); |
|
264 |
trackTop = trackBottom - (getTrackWidth() - 1); |
|
265 |
trackRight = trackRect.width - 1; |
|
266 |
} |
|
267 |
else { |
|
268 |
if (leftToRight) { |
|
269 |
trackLeft = (trackRect.width - getThumbOverhang()) - |
|
270 |
getTrackWidth(); |
|
271 |
trackRight = (trackRect.width - getThumbOverhang()) - 1; |
|
272 |
} |
|
273 |
else { |
|
274 |
trackLeft = getThumbOverhang(); |
|
275 |
trackRight = getThumbOverhang() + getTrackWidth() - 1; |
|
276 |
} |
|
277 |
trackBottom = trackRect.height - 1; |
|
278 |
} |
|
279 |
||
280 |
if ( slider.isEnabled() ) { |
|
281 |
g.setColor( MetalLookAndFeel.getControlDarkShadow() ); |
|
282 |
g.drawRect( trackLeft, trackTop, |
|
283 |
(trackRight - trackLeft) - 1, (trackBottom - trackTop) - 1 ); |
|
284 |
||
285 |
g.setColor( MetalLookAndFeel.getControlHighlight() ); |
|
286 |
g.drawLine( trackLeft + 1, trackBottom, trackRight, trackBottom ); |
|
287 |
g.drawLine( trackRight, trackTop + 1, trackRight, trackBottom ); |
|
288 |
||
289 |
g.setColor( MetalLookAndFeel.getControlShadow() ); |
|
290 |
g.drawLine( trackLeft + 1, trackTop + 1, trackRight - 2, trackTop + 1 ); |
|
291 |
g.drawLine( trackLeft + 1, trackTop + 1, trackLeft + 1, trackBottom - 2 ); |
|
292 |
} |
|
293 |
else { |
|
294 |
g.setColor( MetalLookAndFeel.getControlShadow() ); |
|
295 |
g.drawRect( trackLeft, trackTop, |
|
296 |
(trackRight - trackLeft) - 1, (trackBottom - trackTop) - 1 ); |
|
297 |
} |
|
298 |
||
299 |
// Draw the fill |
|
300 |
if ( filledSlider ) { |
|
1317
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
301 |
int middleOfThumb; |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
302 |
int fillTop; |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
303 |
int fillLeft; |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
304 |
int fillBottom; |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
305 |
int fillRight; |
2 | 306 |
|
307 |
if ( slider.getOrientation() == JSlider.HORIZONTAL ) { |
|
308 |
middleOfThumb = thumbRect.x + (thumbRect.width / 2); |
|
309 |
middleOfThumb -= trackRect.x; // To compensate for the g.translate() |
|
310 |
fillTop = !slider.isEnabled() ? trackTop : trackTop + 1; |
|
311 |
fillBottom = !slider.isEnabled() ? trackBottom - 1 : trackBottom - 2; |
|
312 |
||
313 |
if ( !drawInverted() ) { |
|
314 |
fillLeft = !slider.isEnabled() ? trackLeft : trackLeft + 1; |
|
315 |
fillRight = middleOfThumb; |
|
316 |
} |
|
317 |
else { |
|
318 |
fillLeft = middleOfThumb; |
|
319 |
fillRight = !slider.isEnabled() ? trackRight - 1 : trackRight - 2; |
|
320 |
} |
|
321 |
} |
|
322 |
else { |
|
323 |
middleOfThumb = thumbRect.y + (thumbRect.height / 2); |
|
324 |
middleOfThumb -= trackRect.y; // To compensate for the g.translate() |
|
325 |
fillLeft = !slider.isEnabled() ? trackLeft : trackLeft + 1; |
|
326 |
fillRight = !slider.isEnabled() ? trackRight - 1 : trackRight - 2; |
|
327 |
||
328 |
if ( !drawInverted() ) { |
|
329 |
fillTop = middleOfThumb; |
|
330 |
fillBottom = !slider.isEnabled() ? trackBottom - 1 : trackBottom - 2; |
|
331 |
} |
|
332 |
else { |
|
333 |
fillTop = !slider.isEnabled() ? trackTop : trackTop + 1; |
|
334 |
fillBottom = middleOfThumb; |
|
335 |
} |
|
336 |
} |
|
337 |
||
338 |
if ( slider.isEnabled() ) { |
|
339 |
g.setColor( slider.getBackground() ); |
|
340 |
g.drawLine( fillLeft, fillTop, fillRight, fillTop ); |
|
341 |
g.drawLine( fillLeft, fillTop, fillLeft, fillBottom ); |
|
342 |
||
343 |
g.setColor( MetalLookAndFeel.getControlShadow() ); |
|
344 |
g.fillRect( fillLeft + 1, fillTop + 1, |
|
345 |
fillRight - fillLeft, fillBottom - fillTop ); |
|
346 |
} |
|
347 |
else { |
|
348 |
g.setColor( MetalLookAndFeel.getControlShadow() ); |
|
1304
f0e7af74a2bc
6742358: MetalSliderUI paint wrong vertical disabled filled JSlider for DefaultMetalTheme
rupashka
parents:
2
diff
changeset
|
349 |
g.fillRect(fillLeft, fillTop, fillRight - fillLeft, fillBottom - fillTop); |
2 | 350 |
} |
351 |
} |
|
352 |
||
353 |
g.translate( -trackRect.x, -trackRect.y ); |
|
354 |
} |
|
355 |
||
356 |
private void oceanPaintTrack(Graphics g) { |
|
357 |
boolean leftToRight = MetalUtils.isLeftToRight(slider); |
|
358 |
boolean drawInverted = drawInverted(); |
|
359 |
Color sliderAltTrackColor = (Color)UIManager.get( |
|
360 |
"Slider.altTrackColor"); |
|
361 |
||
362 |
// Translate to the origin of the painting rectangle |
|
363 |
Rectangle paintRect = getPaintTrackRect(); |
|
364 |
g.translate(paintRect.x, paintRect.y); |
|
365 |
||
366 |
// Width and height of the painting rectangle. |
|
367 |
int w = paintRect.width; |
|
368 |
int h = paintRect.height; |
|
369 |
||
1317
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
370 |
if (slider.getOrientation() == JSlider.HORIZONTAL) { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
371 |
int middleOfThumb = thumbRect.x + thumbRect.width / 2 - paintRect.x; |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
372 |
|
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
373 |
if (slider.isEnabled()) { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
374 |
int fillMinX; |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
375 |
int fillMaxX; |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
376 |
|
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
377 |
if (middleOfThumb > 0) { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
378 |
g.setColor(drawInverted ? MetalLookAndFeel.getControlDarkShadow() : |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
379 |
MetalLookAndFeel.getPrimaryControlDarkShadow()); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
380 |
|
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
381 |
g.drawRect(0, 0, middleOfThumb - 1, h - 1); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
382 |
} |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
383 |
|
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
384 |
if (middleOfThumb < w) { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
385 |
g.setColor(drawInverted ? MetalLookAndFeel.getPrimaryControlDarkShadow() : |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
386 |
MetalLookAndFeel.getControlDarkShadow()); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
387 |
|
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
388 |
g.drawRect(middleOfThumb, 0, w - middleOfThumb - 1, h - 1); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
389 |
} |
2 | 390 |
|
1317
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
391 |
if (filledSlider) { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
392 |
g.setColor(MetalLookAndFeel.getPrimaryControlShadow()); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
393 |
if (drawInverted) { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
394 |
fillMinX = middleOfThumb; |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
395 |
fillMaxX = w - 2; |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
396 |
g.drawLine(1, 1, middleOfThumb, 1); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
397 |
} else { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
398 |
fillMinX = 1; |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
399 |
fillMaxX = middleOfThumb; |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
400 |
g.drawLine(middleOfThumb, 1, w - 1, 1); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
401 |
} |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
402 |
if (h == 6) { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
403 |
g.setColor(MetalLookAndFeel.getWhite()); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
404 |
g.drawLine(fillMinX, 1, fillMaxX, 1); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
405 |
g.setColor(sliderAltTrackColor); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
406 |
g.drawLine(fillMinX, 2, fillMaxX, 2); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
407 |
g.setColor(MetalLookAndFeel.getControlShadow()); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
408 |
g.drawLine(fillMinX, 3, fillMaxX, 3); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
409 |
g.setColor(MetalLookAndFeel.getPrimaryControlShadow()); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
410 |
g.drawLine(fillMinX, 4, fillMaxX, 4); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
411 |
} |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
412 |
} |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
413 |
} else { |
2 | 414 |
g.setColor(MetalLookAndFeel.getControlShadow()); |
415 |
||
1317
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
416 |
if (middleOfThumb > 0) { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
417 |
if (!drawInverted && filledSlider) { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
418 |
g.fillRect(0, 0, middleOfThumb - 1, h - 1); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
419 |
} else { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
420 |
g.drawRect(0, 0, middleOfThumb - 1, h - 1); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
421 |
} |
2 | 422 |
} |
1317
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
423 |
|
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
424 |
if (middleOfThumb < w) { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
425 |
if (drawInverted && filledSlider) { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
426 |
g.fillRect(middleOfThumb, 0, w - middleOfThumb - 1, h - 1); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
427 |
} else { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
428 |
g.drawRect(middleOfThumb, 0, w - middleOfThumb - 1, h - 1); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
429 |
} |
2 | 430 |
} |
431 |
} |
|
1317
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
432 |
} else { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
433 |
int middleOfThumb = thumbRect.y + (thumbRect.height / 2) - paintRect.y; |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
434 |
|
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
435 |
if (slider.isEnabled()) { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
436 |
int fillMinY; |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
437 |
int fillMaxY; |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
438 |
|
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
439 |
if (middleOfThumb > 0) { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
440 |
g.setColor(drawInverted ? MetalLookAndFeel.getPrimaryControlDarkShadow() : |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
441 |
MetalLookAndFeel.getControlDarkShadow()); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
442 |
|
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
443 |
g.drawRect(0, 0, w - 1, middleOfThumb - 1); |
2 | 444 |
} |
1317
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
445 |
|
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
446 |
if (middleOfThumb < h) { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
447 |
g.setColor(drawInverted ? MetalLookAndFeel.getControlDarkShadow() : |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
448 |
MetalLookAndFeel.getPrimaryControlDarkShadow()); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
449 |
|
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
450 |
g.drawRect(0, middleOfThumb, w - 1, h - middleOfThumb - 1); |
2 | 451 |
} |
1317
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
452 |
|
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
453 |
if (filledSlider) { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
454 |
g.setColor(MetalLookAndFeel.getPrimaryControlShadow()); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
455 |
if (drawInverted()) { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
456 |
fillMinY = 1; |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
457 |
fillMaxY = middleOfThumb; |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
458 |
if (leftToRight) { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
459 |
g.drawLine(1, middleOfThumb, 1, h - 1); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
460 |
} else { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
461 |
g.drawLine(w - 2, middleOfThumb, w - 2, h - 1); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
462 |
} |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
463 |
} else { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
464 |
fillMinY = middleOfThumb; |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
465 |
fillMaxY = h - 2; |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
466 |
if (leftToRight) { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
467 |
g.drawLine(1, 1, 1, middleOfThumb); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
468 |
} else { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
469 |
g.drawLine(w - 2, 1, w - 2, middleOfThumb); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
470 |
} |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
471 |
} |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
472 |
if (w == 6) { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
473 |
g.setColor(leftToRight ? MetalLookAndFeel.getWhite() : MetalLookAndFeel.getPrimaryControlShadow()); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
474 |
g.drawLine(1, fillMinY, 1, fillMaxY); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
475 |
g.setColor(leftToRight ? sliderAltTrackColor : MetalLookAndFeel.getControlShadow()); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
476 |
g.drawLine(2, fillMinY, 2, fillMaxY); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
477 |
g.setColor(leftToRight ? MetalLookAndFeel.getControlShadow() : sliderAltTrackColor); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
478 |
g.drawLine(3, fillMinY, 3, fillMaxY); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
479 |
g.setColor(leftToRight ? MetalLookAndFeel.getPrimaryControlShadow() : MetalLookAndFeel.getWhite()); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
480 |
g.drawLine(4, fillMinY, 4, fillMaxY); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
481 |
} |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
482 |
} |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
483 |
} else { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
484 |
g.setColor(MetalLookAndFeel.getControlShadow()); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
485 |
|
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
486 |
if (middleOfThumb > 0) { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
487 |
if (drawInverted && filledSlider) { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
488 |
g.fillRect(0, 0, w - 1, middleOfThumb - 1); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
489 |
} else { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
490 |
g.drawRect(0, 0, w - 1, middleOfThumb - 1); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
491 |
} |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
492 |
} |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
493 |
|
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
494 |
if (middleOfThumb < h) { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
495 |
if (!drawInverted && filledSlider) { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
496 |
g.fillRect(0, middleOfThumb, w - 1, h - middleOfThumb - 1); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
497 |
} else { |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
498 |
g.drawRect(0, middleOfThumb, w - 1, h - middleOfThumb - 1); |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
499 |
} |
0ba1e3d36c19
6587742: filling half of a JSlider's track is no longer optional
rupashka
parents:
1304
diff
changeset
|
500 |
} |
2 | 501 |
} |
502 |
} |
|
503 |
||
504 |
g.translate(-paintRect.x, -paintRect.y); |
|
505 |
} |
|
506 |
||
507 |
public void paintFocus(Graphics g) { |
|
508 |
} |
|
509 |
||
510 |
protected Dimension getThumbSize() { |
|
511 |
Dimension size = new Dimension(); |
|
512 |
||
513 |
if ( slider.getOrientation() == JSlider.VERTICAL ) { |
|
514 |
size.width = getVertThumbIcon().getIconWidth(); |
|
515 |
size.height = getVertThumbIcon().getIconHeight(); |
|
516 |
} |
|
517 |
else { |
|
518 |
size.width = getHorizThumbIcon().getIconWidth(); |
|
519 |
size.height = getHorizThumbIcon().getIconHeight(); |
|
520 |
} |
|
521 |
||
522 |
return size; |
|
523 |
} |
|
524 |
||
525 |
/** |
|
526 |
* Gets the height of the tick area for horizontal sliders and the width of the |
|
527 |
* tick area for vertical sliders. BasicSliderUI uses the returned value to |
|
528 |
* determine the tick area rectangle. |
|
529 |
*/ |
|
530 |
public int getTickLength() { |
|
4199
151e13fd2df1
6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
1639
diff
changeset
|
531 |
return slider.getOrientation() == JSlider.HORIZONTAL ? safeLength + TICK_BUFFER + 1 : |
151e13fd2df1
6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
1639
diff
changeset
|
532 |
safeLength + TICK_BUFFER + 3; |
2 | 533 |
} |
534 |
||
535 |
/** |
|
536 |
* Returns the shorter dimension of the track. |
|
25178
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
537 |
* |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
538 |
* @return the shorter dimension of the track |
2 | 539 |
*/ |
540 |
protected int getTrackWidth() { |
|
541 |
// This strange calculation is here to keep the |
|
542 |
// track in proportion to the thumb. |
|
543 |
final double kIdealTrackWidth = 7.0; |
|
544 |
final double kIdealThumbHeight = 16.0; |
|
545 |
final double kWidthScalar = kIdealTrackWidth / kIdealThumbHeight; |
|
546 |
||
547 |
if ( slider.getOrientation() == JSlider.HORIZONTAL ) { |
|
548 |
return (int)(kWidthScalar * thumbRect.height); |
|
549 |
} |
|
550 |
else { |
|
551 |
return (int)(kWidthScalar * thumbRect.width); |
|
552 |
} |
|
553 |
} |
|
554 |
||
555 |
/** |
|
556 |
* Returns the longer dimension of the slide bar. (The slide bar is only the |
|
557 |
* part that runs directly under the thumb) |
|
25178
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
558 |
* |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
559 |
* @return the longer dimension of the slide bar |
2 | 560 |
*/ |
561 |
protected int getTrackLength() { |
|
562 |
if ( slider.getOrientation() == JSlider.HORIZONTAL ) { |
|
563 |
return trackRect.width; |
|
564 |
} |
|
565 |
return trackRect.height; |
|
566 |
} |
|
567 |
||
568 |
/** |
|
569 |
* Returns the amount that the thumb goes past the slide bar. |
|
25178
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
570 |
* |
dbab904451e9
8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents:
22574
diff
changeset
|
571 |
* @return the amount that the thumb goes past the slide bar |
2 | 572 |
*/ |
573 |
protected int getThumbOverhang() { |
|
574 |
return (int)(getThumbSize().getHeight()-getTrackWidth())/2; |
|
575 |
} |
|
576 |
||
577 |
protected void scrollDueToClickInTrack( int dir ) { |
|
578 |
scrollByUnit( dir ); |
|
579 |
} |
|
580 |
||
581 |
protected void paintMinorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) { |
|
582 |
g.setColor( slider.isEnabled() ? slider.getForeground() : MetalLookAndFeel.getControlShadow() ); |
|
4199
151e13fd2df1
6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
1639
diff
changeset
|
583 |
g.drawLine( x, TICK_BUFFER, x, TICK_BUFFER + (safeLength / 2) ); |
2 | 584 |
} |
585 |
||
586 |
protected void paintMajorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) { |
|
587 |
g.setColor( slider.isEnabled() ? slider.getForeground() : MetalLookAndFeel.getControlShadow() ); |
|
4199
151e13fd2df1
6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
1639
diff
changeset
|
588 |
g.drawLine( x, TICK_BUFFER , x, TICK_BUFFER + (safeLength - 1) ); |
2 | 589 |
} |
590 |
||
591 |
protected void paintMinorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) { |
|
592 |
g.setColor( slider.isEnabled() ? slider.getForeground() : MetalLookAndFeel.getControlShadow() ); |
|
593 |
||
594 |
if (MetalUtils.isLeftToRight(slider)) { |
|
4199
151e13fd2df1
6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
1639
diff
changeset
|
595 |
g.drawLine( TICK_BUFFER, y, TICK_BUFFER + (safeLength / 2), y ); |
2 | 596 |
} |
597 |
else { |
|
4199
151e13fd2df1
6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
1639
diff
changeset
|
598 |
g.drawLine( 0, y, safeLength/2, y ); |
2 | 599 |
} |
600 |
} |
|
601 |
||
602 |
protected void paintMajorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) { |
|
603 |
g.setColor( slider.isEnabled() ? slider.getForeground() : MetalLookAndFeel.getControlShadow() ); |
|
604 |
||
605 |
if (MetalUtils.isLeftToRight(slider)) { |
|
4199
151e13fd2df1
6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
1639
diff
changeset
|
606 |
g.drawLine( TICK_BUFFER, y, TICK_BUFFER + safeLength, y ); |
2 | 607 |
} |
608 |
else { |
|
4199
151e13fd2df1
6657026: Numerous static security flaws in Swing (findbugs)
malenkov
parents:
1639
diff
changeset
|
609 |
g.drawLine( 0, y, safeLength, y ); |
2 | 610 |
} |
611 |
} |
|
612 |
} |