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:
55:
58: public class MetalScrollBarUI extends BasicScrollBarUI
59: {
60:
61:
66: class MetalScrollBarPropertyChangeHandler
67: extends BasicScrollBarUI.PropertyChangeHandler
68: {
69:
74: public MetalScrollBarPropertyChangeHandler()
75: {
76:
77: }
78:
79:
86: public void propertyChange(PropertyChangeEvent e)
87: {
88: if (e.getPropertyName().equals(FREE_STANDING_PROP))
89: {
90: Boolean prop = (Boolean) e.getNewValue();
91: isFreeStanding = (prop == null ? true : prop.booleanValue());
92: if (increaseButton != null)
93: increaseButton.setFreeStanding(isFreeStanding);
94: if (decreaseButton != null)
95: decreaseButton.setFreeStanding(isFreeStanding);
96: }
97: else
98: super.propertyChange(e);
99: }
100: }
101:
102:
103: public static final String FREE_STANDING_PROP = "JScrollBar.isFreeStanding";
104:
105:
106: private static final Dimension MIN_THUMB_SIZE = new Dimension(15, 15);
107:
108:
109: private static final Dimension MIN_THUMB_SIZE_FREE_STANDING
110: = new Dimension(17, 17);
111:
112:
113: protected MetalScrollButton increaseButton;
114:
115:
116: protected MetalScrollButton decreaseButton;
117:
118:
121: protected int scrollBarWidth;
122:
123:
129: protected boolean isFreeStanding = true;
130:
131:
135: Color scrollBarShadowColor;
136:
137:
141: public MetalScrollBarUI()
142: {
143: super();
144: }
145:
146:
153: public static ComponentUI createUI(JComponent component)
154: {
155: return new MetalScrollBarUI();
156: }
157:
158:
161: protected void installDefaults()
162: {
163:
164:
165:
166:
167: Boolean prop = (Boolean) scrollbar.getClientProperty(FREE_STANDING_PROP);
168: isFreeStanding = (prop == null ? true : prop.booleanValue());
169: scrollBarShadowColor = UIManager.getColor("ScrollBar.shadow");
170: super.installDefaults();
171: }
172:
173:
181: protected PropertyChangeListener createPropertyChangeListener()
182: {
183: return new MetalScrollBarPropertyChangeHandler();
184: }
185:
186:
195: protected JButton createDecreaseButton(int orientation)
196: {
197: scrollBarWidth = UIManager.getInt("ScrollBar.width");
198: decreaseButton = new MetalScrollButton(orientation, scrollBarWidth,
199: isFreeStanding);
200: return decreaseButton;
201: }
202:
203:
212: protected JButton createIncreaseButton(int orientation)
213: {
214: scrollBarWidth = UIManager.getInt("ScrollBar.width");
215: increaseButton = new MetalScrollButton(orientation, scrollBarWidth,
216: isFreeStanding);
217: return increaseButton;
218: }
219:
220:
227: protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds)
228: {
229: g.setColor(MetalLookAndFeel.getControl());
230: g.fillRect(trackBounds.x, trackBounds.y, trackBounds.width,
231: trackBounds.height);
232: if (scrollbar.getOrientation() == HORIZONTAL)
233: paintTrackHorizontal(g, c, trackBounds.x, trackBounds.y,
234: trackBounds.width, trackBounds.height);
235: else
236: paintTrackVertical(g, c, trackBounds.x, trackBounds.y,
237: trackBounds.width, trackBounds.height);
238:
239: }
240:
241:
251: private void paintTrackHorizontal(Graphics g, JComponent c,
252: int x, int y, int w, int h)
253: {
254: if (c.isEnabled())
255: {
256: g.setColor(MetalLookAndFeel.getControlDarkShadow());
257: g.drawLine(x, y, x, y + h - 1);
258: g.drawLine(x, y, x + w - 1, y);
259: g.drawLine(x + w - 1, y, x + w - 1, y + h - 1);
260:
261: g.setColor(scrollBarShadowColor);
262: g.drawLine(x + 1, y + 1, x + 1, y + h - 1);
263: g.drawLine(x + 1, y + 1, x + w - 2, y + 1);
264:
265: if (isFreeStanding)
266: {
267: g.setColor(MetalLookAndFeel.getControlDarkShadow());
268: g.drawLine(x, y + h - 2, x + w - 1, y + h - 2);
269: g.setColor(scrollBarShadowColor);
270: g.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
271: }
272: }
273: else
274: {
275: g.setColor(MetalLookAndFeel.getControlDisabled());
276: if (isFreeStanding)
277: g.drawRect(x, y, w - 1, h - 1);
278: else
279: {
280: g.drawLine(x, y, x + w - 1, y);
281: g.drawLine(x, y, x, y + h - 1);
282: g.drawLine(x + w - 1, y, x + w - 1, y + h - 1);
283: }
284: }
285: }
286:
287:
297: private void paintTrackVertical(Graphics g, JComponent c,
298: int x, int y, int w, int h)
299: {
300: if (c.isEnabled())
301: {
302: g.setColor(MetalLookAndFeel.getControlDarkShadow());
303: g.drawLine(x, y, x, y + h - 1);
304: g.drawLine(x, y, x + w - 1, y);
305: g.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
306:
307: g.setColor(scrollBarShadowColor);
308: g.drawLine(x + 1, y + 1, x + w - 1, y + 1);
309: g.drawLine(x + 1, y + 1, x + 1, y + h - 2);
310:
311: if (isFreeStanding)
312: {
313: g.setColor(MetalLookAndFeel.getControlDarkShadow());
314: g.drawLine(x + w - 2, y, x + w - 2, y + h - 1);
315: g.setColor(MetalLookAndFeel.getControlHighlight());
316: g.drawLine(x + w - 1, y, x + w - 1, y + h - 1);
317: }
318: }
319: else
320: {
321: g.setColor(MetalLookAndFeel.getControlDisabled());
322: if (isFreeStanding)
323: g.drawRect(x, y, w - 1, h - 1);
324: else
325: {
326: g.drawLine(x, y, x + w - 1, y);
327: g.drawLine(x, y, x, y + h - 1);
328: g.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
329: }
330: }
331: }
332:
333:
340: protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds)
341: {
342:
343: if (!c.isEnabled())
344: return;
345: if (scrollbar.getOrientation() == HORIZONTAL)
346: paintThumbHorizontal(g, c, thumbBounds);
347: else
348: paintThumbVertical(g, c, thumbBounds);
349:
350:
351: MetalUtils.fillMetalPattern(c, g, thumbBounds.x + 3, thumbBounds.y + 3,
352: thumbBounds.width - 6, thumbBounds.height - 6,
353: thumbHighlightColor, thumbLightShadowColor);
354: }
355:
356:
363: private void paintThumbHorizontal(Graphics g, JComponent c,
364: Rectangle thumbBounds)
365: {
366: int x = thumbBounds.x;
367: int y = thumbBounds.y;
368: int w = thumbBounds.width;
369: int h = thumbBounds.height;
370:
371:
372: g.setColor(thumbColor);
373: if (isFreeStanding)
374: g.fillRect(x, y, w, h - 1);
375: else
376: g.fillRect(x, y, w, h);
377:
378:
379: g.setColor(thumbLightShadowColor);
380: if (isFreeStanding)
381: g.drawRect(x, y, w - 1, h - 2);
382: else
383: {
384: g.drawLine(x, y, x + w - 1, y);
385: g.drawLine(x, y, x, y + h - 1);
386: g.drawLine(x + w - 1, y, x + w - 1, y + h -1);
387: }
388:
389:
390: g.setColor(thumbHighlightColor);
391: if (isFreeStanding)
392: {
393: g.drawLine(x + 1, y + 1, x + w - 3, y + 1);
394: g.drawLine(x + 1, y + 1, x + 1, y + h - 3);
395: }
396: else
397: {
398: g.drawLine(x + 1, y + 1, x + w - 3, y + 1);
399: g.drawLine(x + 1, y + 1, x + 1, y + h - 1);
400: }
401:
402:
403: g.setColor(UIManager.getColor("ScrollBar.shadow"));
404: g.drawLine(x + w, y + 1, x + w, y + h - 1);
405:
406: }
407:
408:
415: private void paintThumbVertical(Graphics g, JComponent c,
416: Rectangle thumbBounds)
417: {
418: int x = thumbBounds.x;
419: int y = thumbBounds.y;
420: int w = thumbBounds.width;
421: int h = thumbBounds.height;
422:
423:
424: g.setColor(thumbColor);
425: if (isFreeStanding)
426: g.fillRect(x, y, w - 1, h);
427: else
428: g.fillRect(x, y, w, h);
429:
430:
431: g.setColor(thumbLightShadowColor);
432: if (isFreeStanding)
433: g.drawRect(x, y, w - 2, h - 1);
434: else
435: {
436: g.drawLine(x, y, x + w - 1, y);
437: g.drawLine(x, y, x, y + h - 1);
438: g.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
439: }
440:
441:
442: g.setColor(thumbHighlightColor);
443: if (isFreeStanding)
444: {
445: g.drawLine(x + 1, y + 1, x + w - 3, y + 1);
446: g.drawLine(x + 1, y + 1, x + 1, y + h - 3);
447: }
448: else
449: {
450: g.drawLine(x + 1, y + 1, x + w - 1, y + 1);
451: g.drawLine(x + 1, y + 1, x + 1, y + h - 3);
452: }
453:
454:
455: g.setColor(UIManager.getColor("ScrollBar.shadow"));
456: g.drawLine(x + 1, y + h, x + w - 2, y + h);
457: }
458:
459:
466: protected Dimension getMinimumThumbSize()
467: {
468: if (isFreeStanding)
469: return MIN_THUMB_SIZE_FREE_STANDING;
470: else
471: return MIN_THUMB_SIZE;
472: }
473:
474: }