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