1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47:
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55:
56:
59: public class MetalSliderUI extends BasicSliderUI
60: {
61:
67: protected class MetalPropertyListener
68: extends BasicSliderUI.PropertyChangeHandler
69: {
70:
73: protected MetalPropertyListener()
74: {
75:
76: }
77:
78:
84: public void propertyChange(PropertyChangeEvent e)
85: {
86: if (e.getPropertyName().equals(SLIDER_FILL))
87: {
88: Boolean b = (Boolean) e.getNewValue();
89: if (b == null)
90: filledSlider = false;
91: else
92: filledSlider = b.booleanValue();
93: }
94: else
95: super.propertyChange(e);
96: }
97: }
98:
99:
100: protected static Color thumbColor;
101:
102:
106: protected static Color highlightColor;
107:
108:
112: protected static Color darkShadowColor;
113:
114:
115: protected static int trackWidth = UIManager.getInt("Slider.trackWidth");
116:
117:
118: protected static int tickLength = UIManager.getInt("Slider.majorTickLength");
119:
120:
121: protected static Icon horizThumbIcon = UIManager.getIcon(
122: "Slider.horizontalThumbIcon");
123:
124:
125: protected static Icon vertThumbIcon = UIManager.getIcon(
126: "Slider.verticalThumbIcon");
127:
128:
129: protected final int TICK_BUFFER = 4;
130:
131:
132: protected final String SLIDER_FILL = "JSlider.isFilled";
133:
134:
138: protected boolean filledSlider;
139:
140:
143: public MetalSliderUI()
144: {
145: super(null);
146: filledSlider = UIManager.getBoolean(SLIDER_FILL);
147: darkShadowColor = MetalLookAndFeel.getControlDarkShadow();
148: highlightColor = MetalLookAndFeel.getControlHighlight();
149: }
150:
151:
158: public static ComponentUI createUI(JComponent component)
159: {
160: return new MetalSliderUI();
161: }
162:
163:
168: public void installUI(JComponent c)
169: {
170: super.installUI(c);
171: Boolean b = (Boolean) c.getClientProperty(SLIDER_FILL);
172: if (b != null)
173: filledSlider = b.booleanValue();
174: }
175:
176:
183: protected PropertyChangeListener createPropertyChangeListener(JSlider slider)
184: {
185: return new MetalPropertyListener();
186: }
187:
188:
193: public void paintThumb(Graphics g)
194: {
195: if (slider.getOrientation() == JSlider.HORIZONTAL)
196: horizThumbIcon.paintIcon(slider, g, thumbRect.x, thumbRect.y);
197: else
198: vertThumbIcon.paintIcon(slider, g, thumbRect.x, thumbRect.y);
199: }
200:
201:
206: public void paintTrack(Graphics g)
207: {
208: Color shadowColor = MetalLookAndFeel.getControlShadow();
209: if (slider.getOrientation() == JSlider.HORIZONTAL)
210: {
211: int trackX = trackRect.x;
212: int trackY = trackRect.y + (trackRect.height - getTrackWidth()) / 2;
213: int trackW = trackRect.width;
214: int trackH = getTrackWidth();
215:
216:
217: if (slider.isEnabled())
218: BasicGraphicsUtils.drawEtchedRect(g, trackX, trackY, trackW, trackH,
219: darkShadowColor, shadowColor, darkShadowColor, highlightColor);
220: else
221: {
222: g.setColor(MetalLookAndFeel.getControlShadow());
223: g.drawRect(trackX, trackY, trackW - 2, trackH - 2);
224: }
225:
226:
227: if (MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme)
228: {
229: if (slider.isEnabled())
230: {
231: int xPos = xPositionForValue(slider.getValue());
232: int x = (slider.getInverted() ? xPos : trackRect.x);
233: int w = (slider.getInverted() ? trackX + trackW - xPos
234: : xPos - trackRect.x);
235: g.setColor(MetalLookAndFeel.getWhite());
236: g.drawLine(x + 1, trackY + 1, x + w - 3, trackY + 1);
237: g.setColor(UIManager.getColor("Slider.altTrackColor"));
238: g.drawLine(x + 1, trackY + 2, x + w - 3, trackY + 2);
239: g.setColor(MetalLookAndFeel.getControlShadow());
240: g.drawLine(x + 1, trackY + 3, x + w - 3, trackY + 3);
241: g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
242: g.drawLine(x + 1, trackY + 4, x + w - 3, trackY + 4);
243: }
244: }
245: else if (filledSlider)
246: {
247: int xPos = xPositionForValue(slider.getValue());
248: int x = (slider.getInverted() ? xPos : trackRect.x);
249: int w = (slider.getInverted() ? trackX + trackW - xPos
250: : xPos - trackRect.x);
251: g.setColor(MetalLookAndFeel.getControlShadow());
252: g.fillRect(x + 1, trackY + 1, w - 3, getTrackWidth() - 3);
253: if (slider.isEnabled())
254: {
255: g.setColor(MetalLookAndFeel.getControl());
256: g.drawLine(x + 1, trackY + 1, x + w - 3, trackY + 1);
257: g.drawLine(x + 1, trackY + 1, x + 1,
258: trackY + getTrackWidth() - 3);
259: }
260: }
261: }
262: else
263: {
264: int trackX = trackRect.x + (trackRect.width - getTrackWidth()) / 2;
265: int trackY = trackRect.y;
266: int trackW = getTrackWidth();
267: int trackH = trackRect.height;
268: if (slider.isEnabled())
269: BasicGraphicsUtils.drawEtchedRect(g, trackX, trackY, trackW, trackH,
270: darkShadowColor, shadowColor, darkShadowColor, highlightColor);
271: else
272: {
273: g.setColor(MetalLookAndFeel.getControlShadow());
274: g.drawRect(trackX, trackY, trackW - 2, trackH - 2);
275: }
276:
277:
278: if (MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme)
279: {
280: if (slider.isEnabled())
281: {
282: int yPos = yPositionForValue(slider.getValue());
283: int y = (slider.getInverted() ? trackY : yPos);
284: int h = (slider.getInverted() ? yPos - trackY
285: : trackY + trackH - yPos);
286:
287: g.setColor(MetalLookAndFeel.getWhite());
288: g.drawLine(trackX + 1, y + 1, trackX + 1, y + h - 3);
289: g.setColor(UIManager.getColor("Slider.altTrackColor"));
290: g.drawLine(trackX + 2, y + 1, trackX + 2, y + h - 3);
291: g.setColor(MetalLookAndFeel.getControlShadow());
292: g.drawLine(trackX + 3, y + 1, trackX + 3, y + h - 3);
293: g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
294: g.drawLine(trackX + 4, y + 1, trackX + 4, y + h - 3);
295: }
296: }
297: else if (filledSlider)
298: {
299: int yPos = yPositionForValue(slider.getValue());
300: int y = (slider.getInverted() ? trackY : yPos);
301: int h = (slider.getInverted() ? yPos - trackY
302: : trackY + trackH - yPos);
303: g.setColor(MetalLookAndFeel.getControlShadow());
304: g.fillRect(trackX + 1, y + 1, getTrackWidth() - 3, h - 3);
305: if (slider.isEnabled())
306: {
307: g.setColor(MetalLookAndFeel.getControl());
308: g.drawLine(trackX + 1, y + 1, trackX + trackW - 3, y + 1);
309: g.drawLine(trackX + 1, y + 1, trackX + 1, y + h - 3);
310: }
311: }
312: }
313: }
314:
315:
324: public void paintFocus(Graphics g)
325: {
326:
327: }
328:
329:
334: protected Dimension getThumbSize()
335: {
336: if (slider.getOrientation() == JSlider.HORIZONTAL)
337: return new Dimension(horizThumbIcon.getIconWidth(),
338: horizThumbIcon.getIconHeight());
339: else
340: return new Dimension(vertThumbIcon.getIconWidth(),
341: vertThumbIcon.getIconHeight());
342: }
343:
344:
349: public int getTickLength()
350: {
351: return tickLength + TICK_BUFFER;
352: }
353:
354:
359: protected int getTrackWidth()
360: {
361: return trackWidth;
362: }
363:
364:
369: protected int getTrackLength()
370: {
371: return (slider.getOrientation() == JSlider.HORIZONTAL
372: ? tickRect.width : tickRect.height);
373: }
374:
375:
380: protected int getThumbOverhang()
381: {
382:
383: return 0;
384: }
385:
386: protected void scrollDueToClickInTrack(int dir)
387: {
388:
389: super.scrollDueToClickInTrack(dir);
390: }
391:
392:
399: protected void paintMinorTickForHorizSlider(Graphics g, Rectangle tickBounds,
400: int x)
401: {
402:
403:
404: if (slider.isEnabled())
405: g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
406: else
407: g.setColor(MetalLookAndFeel.getControlDisabled());
408: g.drawLine(x, TICK_BUFFER, x, TICK_BUFFER + tickLength / 2);
409: }
410:
411:
418: protected void paintMajorTickForHorizSlider(Graphics g, Rectangle tickBounds,
419: int x)
420: {
421:
422:
423: if (slider.isEnabled())
424: g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
425: else
426: g.setColor(MetalLookAndFeel.getControlDisabled());
427: g.drawLine(x, TICK_BUFFER, x, TICK_BUFFER + tickLength);
428: }
429:
430:
437: protected void paintMinorTickForVertSlider(Graphics g, Rectangle tickBounds,
438: int y)
439: {
440:
441:
442: if (slider.isEnabled())
443: g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
444: else
445: g.setColor(MetalLookAndFeel.getControlDisabled());
446: g.drawLine(TICK_BUFFER - 1, y, TICK_BUFFER - 1 + tickLength / 2, y);
447: }
448:
449:
456: protected void paintMajorTickForVertSlider(Graphics g, Rectangle tickBounds,
457: int y)
458: {
459:
460:
461: if (slider.isEnabled())
462: g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
463: else
464: g.setColor(MetalLookAndFeel.getControlDisabled());
465: g.drawLine(TICK_BUFFER - 1, y, TICK_BUFFER - 1 + tickLength, y);
466: }
467:
468: }