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