1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44:
45: import ;
46: import ;
47:
48:
53: public class MetalScrollButton extends BasicArrowButton
54: {
55:
56:
60: private static Dimension maximumSize;
61:
62:
63: private int buttonWidth;
64:
65:
69: private boolean freeStanding;
70:
71:
81: public MetalScrollButton(int direction, int width, boolean freeStanding)
82: {
83: super(direction);
84: buttonWidth = width;
85: this.freeStanding = freeStanding;
86: setFocusable(false);
87: }
88:
89:
94: public int getButtonWidth()
95: {
96: return buttonWidth;
97: }
98:
99:
105: public void setFreeStanding(boolean freeStanding)
106: {
107: this.freeStanding = freeStanding;
108: }
109:
110:
115: public void paint(Graphics g)
116: {
117: Rectangle bounds = SwingUtilities.getLocalBounds(this);
118:
119:
120: if (getModel().isPressed())
121: g.setColor(MetalLookAndFeel.getControlShadow());
122: else
123: g.setColor(MetalLookAndFeel.getControl());
124: g.fillRect(0, 0, bounds.width, bounds.height);
125:
126: paintArrow(g, bounds.width, bounds.height);
127:
128:
129:
130:
131: if (freeStanding)
132: {
133: if (direction == WEST)
134: paintWestBorderFreeStanding(g, bounds.width, bounds.height);
135: else if (direction == EAST)
136: paintEastBorderFreeStanding(g, bounds.width, bounds.height);
137: else if (direction == SOUTH)
138: paintSouthBorderFreeStanding(g, bounds.width, bounds.height);
139: else
140: paintNorthBorderFreeStanding(g, bounds.width, bounds.height);
141: }
142: else
143: {
144: if (direction == WEST)
145: paintWestBorder(g, bounds.width, bounds.height);
146: else if (direction == EAST)
147: paintEastBorder(g, bounds.width, bounds.height);
148: else if (direction == SOUTH)
149: paintSouthBorder(g, bounds.width, bounds.height);
150: else
151: paintNorthBorder(g, bounds.width, bounds.height);
152: }
153: }
154:
155: private void paintArrow(Graphics g, int w, int h)
156: {
157: if (isEnabled())
158: g.setColor(MetalLookAndFeel.getBlack());
159: else
160: g.setColor(MetalLookAndFeel.getControlDisabled());
161:
162: if (direction == SOUTH)
163: {
164: int x = w / 2;
165: int y = h / 2 + 2;
166: for (int i = 1; i < 5; i++)
167: g.drawLine(x - i, y - i, x + i - 1, y - i);
168: }
169: else if (direction == EAST)
170: {
171: int x = w / 2 + 2;
172: int y = h / 2;
173: for (int i = 1; i < 5; i++)
174: g.drawLine(x - i, y - i, x - i, y + i - 1);
175: }
176: else if (direction == WEST)
177: {
178: int x = w / 2 - 3;
179: int y = h / 2;
180: for (int i = 1; i < 5; i++)
181: g.drawLine(x + i, y - i, x + i, y + i - 1);
182: }
183: else
184: {
185: int x = w / 2;
186: int y = h / 2 - 3;
187: for (int i = 1; i < 5; i++)
188: g.drawLine(x - i, y + i, x + i - 1, y + i);
189: }
190: }
191:
199: private void paintNorthBorderFreeStanding(Graphics g, int w, int h)
200: {
201: if (isEnabled())
202: {
203: g.setColor(MetalLookAndFeel.getControlDarkShadow());
204: g.drawLine(0, 0, w - 2, 0);
205: g.drawLine(0, 0, 0, h - 1);
206: g.drawLine(2, h - 1, w - 2, h - 1);
207: g.drawLine(w - 2, 2, w - 2, h - 1);
208:
209: g.setColor(MetalLookAndFeel.getControlHighlight());
210: g.drawLine(1, 1, 1, h - 2);
211: g.drawLine(1, 1, w - 3, 1);
212: g.drawLine(w - 1, 1, w - 1, h - 1);
213:
214: g.setColor(MetalLookAndFeel.getControl());
215: g.drawLine(1, h - 1, 1, h - 1);
216: g.drawLine(w - 2, 1, w - 2, 1);
217: }
218: else
219: {
220: g.setColor(MetalLookAndFeel.getControlDisabled());
221: g.drawLine(0, 0, w - 1, 0);
222: g.drawLine(w - 1, 0, w - 1, h - 1);
223: g.drawLine(0, 0, 0, h - 1);
224: }
225: }
226:
227:
235: private void paintSouthBorderFreeStanding(Graphics g, int w, int h)
236: {
237: if (isEnabled())
238: {
239: g.setColor(MetalLookAndFeel.getControlDarkShadow());
240: g.drawLine(0, 0, w - 2, 0);
241: g.drawLine(0, 0, 0, h - 1);
242: g.drawLine(2, h - 1, w - 2, h - 1);
243: g.drawLine(w - 2, 2, w - 2, h - 1);
244:
245: g.setColor(MetalLookAndFeel.getControlHighlight());
246: g.drawLine(1, 1, 1, h - 1);
247: g.drawLine(1, 1, w - 1, 1);
248: g.drawLine(w - 1, 1, w - 1, h - 1);
249:
250: g.setColor(MetalLookAndFeel.getControl());
251: g.drawLine(1, h - 1, 1, h - 1);
252: g.drawLine(w - 1, 1, w - 1, 1);
253: }
254: else
255: {
256: g.setColor(MetalLookAndFeel.getControlDisabled());
257: g.drawLine(0, h - 1, w - 1, h - 1);
258: g.drawLine(w - 1, 0, w - 1, h - 1);
259: g.drawLine(0, 0, 0, h - 1);
260: }
261: }
262:
263:
271: private void paintEastBorderFreeStanding(Graphics g, int w, int h)
272: {
273: if (isEnabled())
274: {
275: g.setColor(MetalLookAndFeel.getControlDarkShadow());
276: g.drawLine(0, 0, w - 2, 0);
277: g.drawLine(w - 2, 0, w - 2, h - 2);
278: g.drawLine(0, h - 2, w - 2, h - 2);
279:
280: g.setColor(MetalLookAndFeel.getControlHighlight());
281: g.drawLine(0, 1, w - 1, 1);
282: g.drawLine(w - 1, 1, w - 1, h - 1);
283: g.drawLine(0, h - 1, w - 1, h - 1);
284:
285: g.setColor(MetalLookAndFeel.getControl());
286: g.drawLine(w - 2, 1, w - 2, 1);
287: }
288: else
289: {
290: g.setColor(MetalLookAndFeel.getControlDisabled());
291: g.drawLine(0, 0, w - 1, 0);
292: g.drawLine(w - 1, 0, w - 1, h - 1);
293: g.drawLine(0, h - 1, w - 1, h - 1);
294: }
295: }
296:
297:
305: private void paintWestBorderFreeStanding(Graphics g, int w, int h)
306: {
307: if (isEnabled())
308: {
309: g.setColor(MetalLookAndFeel.getControlDarkShadow());
310: g.drawLine(0, 0, w - 1, 0);
311: g.drawLine(0, 0, 0, h - 2);
312: g.drawLine(0, h - 2, w - 1, h - 2);
313:
314: g.setColor(MetalLookAndFeel.getControlHighlight());
315: g.drawLine(1, 1, w - 1, 1);
316: g.drawLine(1, 1, 1, h - 1);
317: g.drawLine(1, h - 1, w - 1, h - 1);
318:
319: g.setColor(MetalLookAndFeel.getControl());
320: g.drawLine(1, h - 2, 1, h - 2);
321: }
322: else
323: {
324: g.setColor(MetalLookAndFeel.getControlDisabled());
325: g.drawLine(0, 0, w - 1, 0);
326: g.drawLine(0, 0, 0, h - 1);
327: g.drawLine(0, h - 1, w - 1, h - 1);
328: }
329: }
330:
331:
339: private void paintNorthBorder(Graphics g, int w, int h)
340: {
341: if (isEnabled())
342: {
343: g.setColor(MetalLookAndFeel.getControlDarkShadow());
344: g.drawLine(0, 0, 0, h - 1);
345:
346: g.setColor(MetalLookAndFeel.getControlHighlight());
347: g.drawLine(1, 0, 1, h - 1);
348: g.drawLine(1, 0, w - 1, 0);
349: }
350: else
351: {
352: g.setColor(MetalLookAndFeel.getControlDisabled());
353: g.drawLine(0, 0, 0, h - 1);
354: }
355: }
356:
357:
365: private void paintSouthBorder(Graphics g, int w, int h)
366: {
367: if (isEnabled())
368: {
369: g.setColor(MetalLookAndFeel.getControlDarkShadow());
370: g.drawLine(0, 0, 0, h - 1);
371: g.drawLine(0, h - 1, w - 1, h - 1);
372:
373: g.setColor(MetalLookAndFeel.getControlHighlight());
374: g.drawLine(1, 0, 1, h - 1);
375: g.drawLine(1, 0, w - 1, 0);
376:
377: g.setColor(MetalLookAndFeel.getControl());
378: g.drawLine(1, h - 1, 1, h - 1);
379: }
380: else
381: {
382: g.setColor(MetalLookAndFeel.getControlDisabled());
383: g.drawLine(0, 0, 0, h - 1);
384: }
385: }
386:
387:
395: private void paintEastBorder(Graphics g, int w, int h)
396: {
397: if (isEnabled())
398: {
399: g.setColor(MetalLookAndFeel.getControlDarkShadow());
400: g.drawLine(0, 0, w - 1, 0);
401: g.drawLine(w - 1, 2, w - 1, h - 1);
402: g.setColor(MetalLookAndFeel.getControlHighlight());
403: g.drawLine(0, 1, w - 2, 1);
404: g.drawLine(0, 1, 0, h - 1);
405: }
406: else
407: {
408: g.setColor(MetalLookAndFeel.getControlDisabled());
409: g.drawLine(0, 0, w - 1, 0);
410: }
411: }
412:
413:
421: private void paintWestBorder(Graphics g, int w, int h)
422: {
423: Rectangle bounds = SwingUtilities.getLocalBounds(this);
424: if (isEnabled())
425: {
426: g.setColor(MetalLookAndFeel.getControlDarkShadow());
427: g.drawLine(0, 0, bounds.width - 1, 0);
428: g.setColor(MetalLookAndFeel.getControlHighlight());
429: g.drawLine(0, 1, bounds.width - 1, 1);
430: g.drawLine(0, 1, 0, bounds.height - 1);
431: }
432: else
433: {
434: g.setColor(MetalLookAndFeel.getControlDisabled());
435: g.drawLine(0, 0, bounds.width - 1, 0);
436: }
437: }
438:
439:
445: public Dimension getPreferredSize()
446: {
447: int adj = 1;
448: if (!freeStanding)
449: adj = 2;
450:
451: if (direction == EAST)
452: return new Dimension(buttonWidth - adj, buttonWidth);
453: else if (direction == WEST)
454: return new Dimension(buttonWidth - 2, buttonWidth);
455: else if (direction == SOUTH)
456: return new Dimension(buttonWidth, buttonWidth - adj);
457: else
458: return new Dimension(buttonWidth, buttonWidth - 2);
459: }
460:
461:
466: public Dimension getMinimumSize()
467: {
468: return getPreferredSize();
469: }
470:
471:
476: public Dimension getMaximumSize()
477: {
478: if (maximumSize == null)
479: maximumSize = new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
480: return maximumSize;
481: }
482:
483: }