author | darcy |
Fri, 03 Apr 2015 10:41:34 -0700 | |
changeset 29894 | 3e16b51732f5 |
parent 25859 | 3317bb8137f4 |
child 37698 | 4d798c873df0 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
29894
3e16b51732f5
8076520: Fix missing doclint warnings in javax.swing.{table, tree, undo, plaf.{metal, nimbus, synth}}
darcy
parents:
25859
diff
changeset
|
2 |
* Copyright (c) 2002, 2015, 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.synth; |
|
27 |
||
28 |
import java.awt.*; |
|
29 |
import java.beans.*; |
|
30 |
import javax.swing.*; |
|
31 |
import javax.swing.plaf.*; |
|
32 |
import javax.swing.plaf.basic.*; |
|
33 |
||
34 |
||
35 |
/** |
|
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
16463
diff
changeset
|
36 |
* Provides the Synth L&F UI delegate for |
4394 | 37 |
* {@link javax.swing.JScrollBar}. |
2 | 38 |
* |
39 |
* @author Scott Violet |
|
4394 | 40 |
* @since 1.7 |
2 | 41 |
*/ |
4394 | 42 |
public class SynthScrollBarUI extends BasicScrollBarUI |
43 |
implements PropertyChangeListener, SynthUI { |
|
2 | 44 |
|
45 |
private SynthStyle style; |
|
46 |
private SynthStyle thumbStyle; |
|
47 |
private SynthStyle trackStyle; |
|
48 |
||
49 |
private boolean validMinimumThumbSize; |
|
50 |
||
29894
3e16b51732f5
8076520: Fix missing doclint warnings in javax.swing.{table, tree, undo, plaf.{metal, nimbus, synth}}
darcy
parents:
25859
diff
changeset
|
51 |
/** |
3e16b51732f5
8076520: Fix missing doclint warnings in javax.swing.{table, tree, undo, plaf.{metal, nimbus, synth}}
darcy
parents:
25859
diff
changeset
|
52 |
* Returns a UI. |
3e16b51732f5
8076520: Fix missing doclint warnings in javax.swing.{table, tree, undo, plaf.{metal, nimbus, synth}}
darcy
parents:
25859
diff
changeset
|
53 |
* @return a UI |
3e16b51732f5
8076520: Fix missing doclint warnings in javax.swing.{table, tree, undo, plaf.{metal, nimbus, synth}}
darcy
parents:
25859
diff
changeset
|
54 |
* @param c a component |
3e16b51732f5
8076520: Fix missing doclint warnings in javax.swing.{table, tree, undo, plaf.{metal, nimbus, synth}}
darcy
parents:
25859
diff
changeset
|
55 |
*/ |
2 | 56 |
public static ComponentUI createUI(JComponent c) { |
57 |
return new SynthScrollBarUI(); |
|
58 |
} |
|
59 |
||
4394 | 60 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
16463
diff
changeset
|
61 |
* {@inheritDoc} |
4394 | 62 |
*/ |
63 |
@Override |
|
2 | 64 |
protected void installDefaults() { |
16463
9f9632c2aede
8000183: 7163696: JCK Swing interactive test JScrollBarTest0013 fails with Nimbus and GTK L&Fs
malenkov
parents:
7668
diff
changeset
|
65 |
super.installDefaults(); |
2 | 66 |
trackHighlight = NO_HIGHLIGHT; |
67 |
if (scrollbar.getLayout() == null || |
|
68 |
(scrollbar.getLayout() instanceof UIResource)) { |
|
69 |
scrollbar.setLayout(this); |
|
70 |
} |
|
4966
ff6769741ba1
6924059: SynthScrollBarUI.configureScrollBarColors() should have spec different from the overridden method
rupashka
parents:
4848
diff
changeset
|
71 |
configureScrollBarColors(); |
2 | 72 |
updateStyle(scrollbar); |
73 |
} |
|
74 |
||
4394 | 75 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
16463
diff
changeset
|
76 |
* {@inheritDoc} |
4394 | 77 |
*/ |
78 |
@Override |
|
2 | 79 |
protected void configureScrollBarColors() { |
80 |
} |
|
81 |
||
82 |
private void updateStyle(JScrollBar c) { |
|
83 |
SynthStyle oldStyle = style; |
|
84 |
SynthContext context = getContext(c, ENABLED); |
|
85 |
style = SynthLookAndFeel.updateStyle(context, this); |
|
86 |
if (style != oldStyle) { |
|
87 |
scrollBarWidth = style.getInt(context,"ScrollBar.thumbHeight", 14); |
|
88 |
minimumThumbSize = (Dimension)style.get(context, |
|
89 |
"ScrollBar.minimumThumbSize"); |
|
90 |
if (minimumThumbSize == null) { |
|
91 |
minimumThumbSize = new Dimension(); |
|
92 |
validMinimumThumbSize = false; |
|
93 |
} |
|
94 |
else { |
|
95 |
validMinimumThumbSize = true; |
|
96 |
} |
|
97 |
maximumThumbSize = (Dimension)style.get(context, |
|
98 |
"ScrollBar.maximumThumbSize"); |
|
99 |
if (maximumThumbSize == null) { |
|
100 |
maximumThumbSize = new Dimension(4096, 4097); |
|
101 |
} |
|
2658 | 102 |
|
103 |
incrGap = style.getInt(context, "ScrollBar.incrementButtonGap", 0); |
|
104 |
decrGap = style.getInt(context, "ScrollBar.decrementButtonGap", 0); |
|
105 |
||
106 |
// handle scaling for sizeVarients for special case components. The |
|
107 |
// key "JComponent.sizeVariant" scales for large/small/mini |
|
108 |
// components are based on Apples LAF |
|
109 |
String scaleKey = (String)scrollbar.getClientProperty( |
|
110 |
"JComponent.sizeVariant"); |
|
111 |
if (scaleKey != null){ |
|
112 |
if ("large".equals(scaleKey)){ |
|
113 |
scrollBarWidth *= 1.15; |
|
114 |
incrGap *= 1.15; |
|
115 |
decrGap *= 1.15; |
|
116 |
} else if ("small".equals(scaleKey)){ |
|
117 |
scrollBarWidth *= 0.857; |
|
118 |
incrGap *= 0.857; |
|
119 |
decrGap *= 0.857; |
|
120 |
} else if ("mini".equals(scaleKey)){ |
|
121 |
scrollBarWidth *= 0.714; |
|
122 |
incrGap *= 0.714; |
|
123 |
decrGap *= 0.714; |
|
124 |
} |
|
125 |
} |
|
126 |
||
2 | 127 |
if (oldStyle != null) { |
128 |
uninstallKeyboardActions(); |
|
129 |
installKeyboardActions(); |
|
130 |
} |
|
131 |
} |
|
132 |
context.dispose(); |
|
133 |
||
134 |
context = getContext(c, Region.SCROLL_BAR_TRACK, ENABLED); |
|
135 |
trackStyle = SynthLookAndFeel.updateStyle(context, this); |
|
136 |
context.dispose(); |
|
137 |
||
138 |
context = getContext(c, Region.SCROLL_BAR_THUMB, ENABLED); |
|
139 |
thumbStyle = SynthLookAndFeel.updateStyle(context, this); |
|
140 |
context.dispose(); |
|
141 |
} |
|
142 |
||
4394 | 143 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
16463
diff
changeset
|
144 |
* {@inheritDoc} |
4394 | 145 |
*/ |
146 |
@Override |
|
2 | 147 |
protected void installListeners() { |
148 |
super.installListeners(); |
|
149 |
scrollbar.addPropertyChangeListener(this); |
|
150 |
} |
|
151 |
||
4394 | 152 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
16463
diff
changeset
|
153 |
* {@inheritDoc} |
4394 | 154 |
*/ |
155 |
@Override |
|
2 | 156 |
protected void uninstallListeners() { |
157 |
super.uninstallListeners(); |
|
158 |
scrollbar.removePropertyChangeListener(this); |
|
159 |
} |
|
160 |
||
4394 | 161 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
16463
diff
changeset
|
162 |
* {@inheritDoc} |
4394 | 163 |
*/ |
164 |
@Override |
|
2 | 165 |
protected void uninstallDefaults(){ |
166 |
SynthContext context = getContext(scrollbar, ENABLED); |
|
167 |
style.uninstallDefaults(context); |
|
168 |
context.dispose(); |
|
169 |
style = null; |
|
170 |
||
171 |
context = getContext(scrollbar, Region.SCROLL_BAR_TRACK, ENABLED); |
|
172 |
trackStyle.uninstallDefaults(context); |
|
173 |
context.dispose(); |
|
174 |
trackStyle = null; |
|
175 |
||
176 |
context = getContext(scrollbar, Region.SCROLL_BAR_THUMB, ENABLED); |
|
177 |
thumbStyle.uninstallDefaults(context); |
|
178 |
context.dispose(); |
|
179 |
thumbStyle = null; |
|
180 |
||
181 |
super.uninstallDefaults(); |
|
182 |
} |
|
183 |
||
4394 | 184 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
16463
diff
changeset
|
185 |
* {@inheritDoc} |
4394 | 186 |
*/ |
187 |
@Override |
|
2 | 188 |
public SynthContext getContext(JComponent c) { |
4394 | 189 |
return getContext(c, SynthLookAndFeel.getComponentState(c)); |
2 | 190 |
} |
191 |
||
192 |
private SynthContext getContext(JComponent c, int state) { |
|
25100 | 193 |
return SynthContext.getContext(c, style, state); |
2 | 194 |
} |
195 |
||
196 |
private SynthContext getContext(JComponent c, Region region) { |
|
197 |
return getContext(c, region, getComponentState(c, region)); |
|
198 |
} |
|
199 |
||
200 |
private SynthContext getContext(JComponent c, Region region, int state) { |
|
201 |
SynthStyle style = trackStyle; |
|
202 |
||
203 |
if (region == Region.SCROLL_BAR_THUMB) { |
|
204 |
style = thumbStyle; |
|
205 |
} |
|
25100 | 206 |
return SynthContext.getContext(c, region, style, state); |
2 | 207 |
} |
208 |
||
209 |
private int getComponentState(JComponent c, Region region) { |
|
210 |
if (region == Region.SCROLL_BAR_THUMB && isThumbRollover() && |
|
211 |
c.isEnabled()) { |
|
212 |
return MOUSE_OVER; |
|
213 |
} |
|
214 |
return SynthLookAndFeel.getComponentState(c); |
|
215 |
} |
|
216 |
||
4394 | 217 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
16463
diff
changeset
|
218 |
* {@inheritDoc} |
4394 | 219 |
*/ |
220 |
@Override |
|
2 | 221 |
public boolean getSupportsAbsolutePositioning() { |
222 |
SynthContext context = getContext(scrollbar); |
|
223 |
boolean value = style.getBoolean(context, |
|
224 |
"ScrollBar.allowsAbsolutePositioning", false); |
|
225 |
context.dispose(); |
|
226 |
return value; |
|
227 |
} |
|
228 |
||
4394 | 229 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
230 |
* Notifies this UI delegate to repaint the specified component. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
231 |
* This method paints the component background, then calls |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
232 |
* the {@link #paint(SynthContext,Graphics)} method. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
233 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
234 |
* <p>In general, this method does not need to be overridden by subclasses. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
235 |
* All Look and Feel rendering code should reside in the {@code paint} method. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
236 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
237 |
* @param g the {@code Graphics} object used for painting |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
238 |
* @param c the component being painted |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
239 |
* @see #paint(SynthContext,Graphics) |
4394 | 240 |
*/ |
241 |
@Override |
|
2 | 242 |
public void update(Graphics g, JComponent c) { |
243 |
SynthContext context = getContext(c); |
|
244 |
||
245 |
SynthLookAndFeel.update(context, g); |
|
246 |
context.getPainter().paintScrollBarBackground(context, |
|
247 |
g, 0, 0, c.getWidth(), c.getHeight(), |
|
248 |
scrollbar.getOrientation()); |
|
249 |
paint(context, g); |
|
250 |
context.dispose(); |
|
251 |
} |
|
252 |
||
4394 | 253 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
254 |
* Paints the specified component according to the Look and Feel. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
255 |
* <p>This method is not used by Synth Look and Feel. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
256 |
* Painting is handled by the {@link #paint(SynthContext,Graphics)} method. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
257 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
258 |
* @param g the {@code Graphics} object used for painting |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
259 |
* @param c the component being painted |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
260 |
* @see #paint(SynthContext,Graphics) |
4394 | 261 |
*/ |
262 |
@Override |
|
2 | 263 |
public void paint(Graphics g, JComponent c) { |
264 |
SynthContext context = getContext(c); |
|
265 |
||
266 |
paint(context, g); |
|
267 |
context.dispose(); |
|
268 |
} |
|
269 |
||
4394 | 270 |
/** |
271 |
* Paints the specified component. |
|
272 |
* |
|
273 |
* @param context context for the component being painted |
|
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
274 |
* @param g the {@code Graphics} object used for painting |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
275 |
* @see #update(Graphics,JComponent) |
4394 | 276 |
*/ |
2 | 277 |
protected void paint(SynthContext context, Graphics g) { |
278 |
SynthContext subcontext = getContext(scrollbar, |
|
279 |
Region.SCROLL_BAR_TRACK); |
|
280 |
paintTrack(subcontext, g, getTrackBounds()); |
|
281 |
subcontext.dispose(); |
|
282 |
||
283 |
subcontext = getContext(scrollbar, Region.SCROLL_BAR_THUMB); |
|
284 |
paintThumb(subcontext, g, getThumbBounds()); |
|
285 |
subcontext.dispose(); |
|
286 |
} |
|
287 |
||
4394 | 288 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
16463
diff
changeset
|
289 |
* {@inheritDoc} |
4394 | 290 |
*/ |
291 |
@Override |
|
2 | 292 |
public void paintBorder(SynthContext context, Graphics g, int x, |
293 |
int y, int w, int h) { |
|
294 |
context.getPainter().paintScrollBarBorder(context, g, x, y, w, h, |
|
295 |
scrollbar.getOrientation()); |
|
296 |
} |
|
297 |
||
4394 | 298 |
/** |
299 |
* Paints the scrollbar track. |
|
300 |
* |
|
301 |
* @param context context for the component being painted |
|
302 |
* @param g {@code Graphics} object used for painting |
|
303 |
* @param trackBounds bounding box for the track |
|
304 |
*/ |
|
305 |
protected void paintTrack(SynthContext context, Graphics g, |
|
2 | 306 |
Rectangle trackBounds) { |
4394 | 307 |
SynthLookAndFeel.updateSubregion(context, g, trackBounds); |
308 |
context.getPainter().paintScrollBarTrackBackground(context, g, trackBounds.x, |
|
2 | 309 |
trackBounds.y, trackBounds.width, trackBounds.height, |
310 |
scrollbar.getOrientation()); |
|
4394 | 311 |
context.getPainter().paintScrollBarTrackBorder(context, g, trackBounds.x, |
2 | 312 |
trackBounds.y, trackBounds.width, trackBounds.height, |
313 |
scrollbar.getOrientation()); |
|
314 |
} |
|
315 |
||
4394 | 316 |
/** |
317 |
* Paints the scrollbar thumb. |
|
318 |
* |
|
319 |
* @param context context for the component being painted |
|
320 |
* @param g {@code Graphics} object used for painting |
|
321 |
* @param thumbBounds bounding box for the thumb |
|
322 |
*/ |
|
323 |
protected void paintThumb(SynthContext context, Graphics g, |
|
2 | 324 |
Rectangle thumbBounds) { |
4394 | 325 |
SynthLookAndFeel.updateSubregion(context, g, thumbBounds); |
2 | 326 |
int orientation = scrollbar.getOrientation(); |
4394 | 327 |
context.getPainter().paintScrollBarThumbBackground(context, g, thumbBounds.x, |
2 | 328 |
thumbBounds.y, thumbBounds.width, thumbBounds.height, |
329 |
orientation); |
|
4394 | 330 |
context.getPainter().paintScrollBarThumbBorder(context, g, thumbBounds.x, |
2 | 331 |
thumbBounds.y, thumbBounds.width, thumbBounds.height, |
332 |
orientation); |
|
333 |
} |
|
334 |
||
335 |
/** |
|
336 |
* A vertical scrollbar's preferred width is the maximum of |
|
337 |
* preferred widths of the (non <code>null</code>) |
|
338 |
* increment/decrement buttons, |
|
339 |
* and the minimum width of the thumb. The preferred height is the |
|
340 |
* sum of the preferred heights of the same parts. The basis for |
|
341 |
* the preferred size of a horizontal scrollbar is similar. |
|
342 |
* <p> |
|
343 |
* The <code>preferredSize</code> is only computed once, subsequent |
|
344 |
* calls to this method just return a cached size. |
|
345 |
* |
|
346 |
* @param c the <code>JScrollBar</code> that's delegating this method to us |
|
347 |
* @return the preferred size of a Basic JScrollBar |
|
348 |
* @see #getMaximumSize |
|
349 |
* @see #getMinimumSize |
|
350 |
*/ |
|
4394 | 351 |
@Override |
2 | 352 |
public Dimension getPreferredSize(JComponent c) { |
353 |
Insets insets = c.getInsets(); |
|
354 |
return (scrollbar.getOrientation() == JScrollBar.VERTICAL) |
|
355 |
? new Dimension(scrollBarWidth + insets.left + insets.right, 48) |
|
356 |
: new Dimension(48, scrollBarWidth + insets.top + insets.bottom); |
|
357 |
} |
|
358 |
||
4394 | 359 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
16463
diff
changeset
|
360 |
* {@inheritDoc} |
4394 | 361 |
*/ |
362 |
@Override |
|
2 | 363 |
protected Dimension getMinimumThumbSize() { |
364 |
if (!validMinimumThumbSize) { |
|
365 |
if (scrollbar.getOrientation() == JScrollBar.VERTICAL) { |
|
366 |
minimumThumbSize.width = scrollBarWidth; |
|
367 |
minimumThumbSize.height = 7; |
|
368 |
} else { |
|
369 |
minimumThumbSize.width = 7; |
|
370 |
minimumThumbSize.height = scrollBarWidth; |
|
371 |
} |
|
372 |
} |
|
373 |
return minimumThumbSize; |
|
374 |
} |
|
375 |
||
4394 | 376 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
16463
diff
changeset
|
377 |
* {@inheritDoc} |
4394 | 378 |
*/ |
379 |
@Override |
|
2 | 380 |
protected JButton createDecreaseButton(int orientation) { |
23697 | 381 |
@SuppressWarnings("serial") // anonymous class |
2658 | 382 |
SynthArrowButton synthArrowButton = new SynthArrowButton(orientation) { |
383 |
@Override |
|
384 |
public boolean contains(int x, int y) { |
|
385 |
if (decrGap < 0) { //there is an overlap between the track and button |
|
386 |
int width = getWidth(); |
|
387 |
int height = getHeight(); |
|
388 |
if (scrollbar.getOrientation() == JScrollBar.VERTICAL) { |
|
389 |
//adjust the height by decrGap |
|
390 |
//Note: decrGap is negative! |
|
391 |
height += decrGap; |
|
392 |
} else { |
|
393 |
//adjust the width by decrGap |
|
394 |
//Note: decrGap is negative! |
|
395 |
width += decrGap; |
|
396 |
} |
|
397 |
return (x >= 0) && (x < width) && (y >= 0) && (y < height); |
|
398 |
} |
|
399 |
return super.contains(x, y); |
|
400 |
} |
|
401 |
}; |
|
2 | 402 |
synthArrowButton.setName("ScrollBar.button"); |
403 |
return synthArrowButton; |
|
404 |
} |
|
405 |
||
4394 | 406 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
16463
diff
changeset
|
407 |
* {@inheritDoc} |
4394 | 408 |
*/ |
409 |
@Override |
|
2 | 410 |
protected JButton createIncreaseButton(int orientation) { |
23697 | 411 |
@SuppressWarnings("serial") // anonymous class |
2658 | 412 |
SynthArrowButton synthArrowButton = new SynthArrowButton(orientation) { |
413 |
@Override |
|
414 |
public boolean contains(int x, int y) { |
|
415 |
if (incrGap < 0) { //there is an overlap between the track and button |
|
416 |
int width = getWidth(); |
|
417 |
int height = getHeight(); |
|
418 |
if (scrollbar.getOrientation() == JScrollBar.VERTICAL) { |
|
419 |
//adjust the height and y by incrGap |
|
420 |
//Note: incrGap is negative! |
|
421 |
height += incrGap; |
|
422 |
y += incrGap; |
|
423 |
} else { |
|
424 |
//adjust the width and x by incrGap |
|
425 |
//Note: incrGap is negative! |
|
426 |
width += incrGap; |
|
427 |
x += incrGap; |
|
428 |
} |
|
429 |
return (x >= 0) && (x < width) && (y >= 0) && (y < height); |
|
430 |
} |
|
431 |
return super.contains(x, y); |
|
432 |
} |
|
433 |
}; |
|
2 | 434 |
synthArrowButton.setName("ScrollBar.button"); |
435 |
return synthArrowButton; |
|
436 |
} |
|
437 |
||
4394 | 438 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
16463
diff
changeset
|
439 |
* {@inheritDoc} |
4394 | 440 |
*/ |
441 |
@Override |
|
2 | 442 |
protected void setThumbRollover(boolean active) { |
443 |
if (isThumbRollover() != active) { |
|
444 |
scrollbar.repaint(getThumbBounds()); |
|
445 |
super.setThumbRollover(active); |
|
446 |
} |
|
447 |
} |
|
448 |
||
449 |
private void updateButtonDirections() { |
|
450 |
int orient = scrollbar.getOrientation(); |
|
451 |
if (scrollbar.getComponentOrientation().isLeftToRight()) { |
|
452 |
((SynthArrowButton)incrButton).setDirection( |
|
453 |
orient == HORIZONTAL? EAST : SOUTH); |
|
454 |
((SynthArrowButton)decrButton).setDirection( |
|
455 |
orient == HORIZONTAL? WEST : NORTH); |
|
456 |
} |
|
457 |
else { |
|
458 |
((SynthArrowButton)incrButton).setDirection( |
|
459 |
orient == HORIZONTAL? WEST : SOUTH); |
|
460 |
((SynthArrowButton)decrButton).setDirection( |
|
461 |
orient == HORIZONTAL ? EAST : NORTH); |
|
462 |
} |
|
463 |
} |
|
464 |
||
465 |
// |
|
466 |
// PropertyChangeListener |
|
467 |
// |
|
468 |
public void propertyChange(PropertyChangeEvent e) { |
|
469 |
String propertyName = e.getPropertyName(); |
|
470 |
||
471 |
if (SynthLookAndFeel.shouldUpdateStyle(e)) { |
|
472 |
updateStyle((JScrollBar)e.getSource()); |
|
473 |
} |
|
474 |
||
475 |
if ("orientation" == propertyName) { |
|
476 |
updateButtonDirections(); |
|
477 |
} |
|
478 |
else if ("componentOrientation" == propertyName) { |
|
479 |
updateButtonDirections(); |
|
480 |
} |
|
481 |
} |
|
482 |
} |