1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45:
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58:
59:
60:
66: public class MetalBorders
67: {
68:
69:
70: private static Border buttonBorder;
71:
72:
73: private static Border toolbarButtonBorder;
74:
75:
76: private static Border textFieldBorder;
77:
78:
83: private static BasicBorders.MarginBorder marginBorder;
84:
85:
88: public static class ButtonBorder
89: extends AbstractBorder
90: implements UIResource
91: {
92:
93: protected static Insets borderInsets = new Insets(3, 3, 3, 3);
94:
95:
98: public ButtonBorder()
99: {
100: }
101:
102:
112: public void paintBorder(Component c, Graphics g, int x, int y, int w,
113: int h)
114: {
115: ButtonModel bmodel = null;
116:
117: if (c instanceof AbstractButton)
118: bmodel = ((AbstractButton) c).getModel();
119:
120: Color darkShadow = MetalLookAndFeel.getControlDarkShadow();
121: Color shadow = MetalLookAndFeel.getControlShadow();
122: Color light = MetalLookAndFeel.getWhite();
123: Color middle = MetalLookAndFeel.getControl();
124:
125:
126: g.setColor(darkShadow);
127: g.drawRect(x, y, w - 2, h - 2);
128:
129: if (!bmodel.isPressed())
130: {
131:
132: g.setColor(light);
133: g.drawRect(x + 1, y + 1, w - 2, h - 2);
134:
135:
136: g.setColor(middle);
137: g.drawRect(x + 1, y + h - 2, 0, 0);
138: g.drawRect(x + w - 2, y + 1, 0, 0);
139: }
140: else
141: {
142:
143: g.setColor(light);
144: g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
145: g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
146:
147:
148: g.setColor(middle);
149: g.drawLine(x + 1, y + 1, x + w - 2, y + 1);
150: g.drawLine(x + 1, y + 1, x + 1, y + h - 2);
151:
152:
153: g.setColor(shadow);
154: g.drawRect(x + 1, y + h - 2, 0, 0);
155: g.drawRect(x + w - 2, y + 1, 0, 0);
156: }
157: }
158:
159:
166: public Insets getBorderInsets(Component c)
167: {
168: return getBorderInsets(c, null);
169: }
170:
171:
179: public Insets getBorderInsets(Component c, Insets newInsets)
180: {
181: if (newInsets == null)
182: newInsets = new Insets(0, 0, 0, 0);
183:
184: AbstractButton b = (AbstractButton) c;
185: newInsets.bottom = borderInsets.bottom;
186: newInsets.left = borderInsets.left;
187: newInsets.right = borderInsets.right;
188: newInsets.top = borderInsets.top;
189: return newInsets;
190: }
191: }
192:
193:
196: public static class Flush3DBorder extends AbstractBorder
197: implements UIResource
198: {
199:
202: public Flush3DBorder()
203: {
204: }
205:
206:
213: public Insets getBorderInsets(Component c)
214: {
215: return getBorderInsets(c, null);
216: }
217:
218:
224: public Insets getBorderInsets(Component c, Insets newInsets)
225: {
226: if (newInsets == null)
227: newInsets = new Insets(2, 2, 2, 2);
228: else
229: {
230: newInsets.top = 2;
231: newInsets.left = 2;
232: newInsets.bottom = 2;
233: newInsets.right = 2;
234: }
235: return newInsets;
236: }
237:
238:
248: public void paintBorder(Component c, Graphics g, int x, int y, int w,
249: int h)
250: {
251: Color savedColor = g.getColor();
252: g.setColor(MetalLookAndFeel.getControlDarkShadow());
253: g.drawRect(x, y, w - 2, h - 2);
254: g.setColor(MetalLookAndFeel.getControlHighlight());
255: g.drawRect(x + 1, y + 1, w - 2, h - 2);
256: g.setColor(MetalLookAndFeel.getControl());
257: g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
258: g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);
259: g.setColor(savedColor);
260: }
261:
262: }
263:
264:
267: public static class TextFieldBorder extends Flush3DBorder
268: implements UIResource
269: {
270:
273: public TextFieldBorder()
274: {
275: }
276:
277:
287: public void paintBorder(Component c, Graphics g, int x, int y, int w,
288: int h)
289: {
290: if (c.isEnabled())
291: super.paintBorder(c, g, x, y, w, h);
292: else
293: {
294: Color savedColor = g.getColor();
295: g.setColor(MetalLookAndFeel.getControlShadow());
296: g.drawRect(x, y, w - 1, h - 1);
297: g.setColor(savedColor);
298: }
299: }
300:
301: }
302:
303:
306: public static class InternalFrameBorder extends AbstractBorder
307: implements UIResource
308: {
309:
312: public InternalFrameBorder()
313: {
314: }
315:
316:
323: public Insets getBorderInsets(Component c)
324: {
325: return getBorderInsets(c, null);
326: }
327:
328:
334: public Insets getBorderInsets(Component c, Insets newInsets)
335: {
336: if (newInsets == null)
337: newInsets = new Insets(5, 5, 5, 5);
338: else
339: {
340: newInsets.top = 5;
341: newInsets.left = 5;
342: newInsets.bottom = 5;
343: newInsets.right = 5;
344: }
345: return newInsets;
346: }
347:
348:
358: public void paintBorder(Component c, Graphics g, int x, int y, int w,
359: int h)
360: {
361:
362: JInternalFrame f = (JInternalFrame) c;
363: if (f.isSelected())
364: g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
365: else
366: g.setColor(MetalLookAndFeel.getControlDarkShadow());
367:
368:
369: g.fillRect(x, y, w, 5);
370: g.fillRect(x, y, 5, h);
371: g.fillRect(x + w - 5, y, 5, h);
372: g.fillRect(x, y + h - 5, w, 5);
373:
374:
375: g.setColor(MetalLookAndFeel.getControl());
376: g.fillRect(x, y, 1, 1);
377: g.fillRect(x + w - 1, y, 1, 1);
378: g.fillRect(x + w - 1, y + h - 1, 1, 1);
379: g.fillRect(x, y + h - 1, 1, 1);
380:
381:
382: g.setColor(MetalLookAndFeel.getBlack());
383: g.drawLine(x + 14, y + 2, x + w - 15, y + 2);
384: g.drawLine(x + 14, y + h - 3, x + w - 15, y + h - 3);
385: g.drawLine(x + 2, y + 14, x + 2, y + h - 15);
386: g.drawLine(x + w - 3, y + 14, x + w - 3, y + h - 15);
387:
388:
389: g.setColor(MetalLookAndFeel.getControl());
390: g.drawLine(x + 15, y + 3, x + w - 14, y + 3);
391: g.drawLine(x + 15, y + h - 2, x + w - 14, y + h - 2);
392: g.drawLine(x + 3, y + 15, x + 3, y + h - 14);
393: g.drawLine(x + w - 2, y + 15, x + w - 2, y + h - 14);
394: }
395:
396: }
397:
398:
401: public static class MenuItemBorder
402: extends AbstractBorder
403: implements UIResource
404: {
405:
406: protected static Insets borderInsets = new Insets(2, 2, 2, 2);
407:
408:
409: private static Color borderColorDark = new Color(102, 102, 153);
410: private static Color borderColorLight = new Color(255, 255, 255);
411:
412:
415: public MenuItemBorder()
416: {
417: }
418:
419:
430: public void paintBorder(Component c, Graphics g, int x, int y, int w,
431: int h)
432: {
433: if (c instanceof JMenu) {
434: JMenu menu = (JMenu) c;
435: if (menu.isSelected())
436: {
437: g.setColor(borderColorDark);
438: g.drawLine(x, y, x, y + h);
439: g.drawLine(x, y, x + w, y);
440: g.drawLine(x + w - 2, y + 1, x + w - 2, y + h);
441: g.setColor(borderColorLight);
442: g.drawLine(x + w - 1, y + 1, x + w - 1, y + h);
443: }
444: }
445: else if (c instanceof JMenuItem)
446: {
447: JMenuItem item = (JMenuItem) c;
448: if (item.isArmed())
449: {
450: g.setColor(borderColorDark);
451: g.drawLine(x, y, x + w, y);
452: g.setColor(borderColorLight);
453: g.drawLine(x, y + h - 1, x + w, y + h - 1);
454: }
455: }
456: }
457:
458:
465: public Insets getBorderInsets(Component c)
466: {
467: return borderInsets;
468: }
469:
470:
480: public Insets getBorderInsets(Component c, Insets insets)
481: {
482: insets.left = borderInsets.left;
483: insets.top = borderInsets.top;
484: insets.bottom = borderInsets.bottom;
485: insets.right = borderInsets.right;
486: return insets;
487: }
488: }
489:
490:
493: public static class MenuBarBorder
494: extends AbstractBorder
495: implements UIResource
496: {
497:
498: protected static Insets borderInsets = new Insets(1, 0, 1, 0);
499:
500:
501: private static Color borderColor = new Color(153, 153, 153);
502:
503:
506: public MenuBarBorder()
507: {
508: }
509:
510:
521: public void paintBorder(Component c, Graphics g, int x, int y, int w,
522: int h)
523: {
524: g.setColor(borderColor);
525: g.drawLine(x, y + h - 1, x + w, y + h - 1);
526: }
527:
528:
535: public Insets getBorderInsets(Component c)
536: {
537: return borderInsets;
538: }
539:
540:
550: public Insets getBorderInsets(Component c, Insets insets)
551: {
552: insets.left = borderInsets.left;
553: insets.top = borderInsets.top;
554: insets.bottom = borderInsets.bottom;
555: insets.right = borderInsets.right;
556: return insets;
557: }
558: }
559:
560:
563: public static class ScrollPaneBorder
564: extends AbstractBorder
565: implements UIResource
566: {
567:
568: private static Insets insets = new Insets(1, 1, 2, 2);
569:
570:
573: public ScrollPaneBorder()
574: {
575: }
576:
577:
582: public Insets getBorderInsets(Component c)
583: {
584: return insets;
585: }
586:
587:
597: public void paintBorder(Component c, Graphics g, int x, int y,
598: int w, int h)
599: {
600: Color darkShadow = MetalLookAndFeel.getControlDarkShadow();
601: Color shadow = MetalLookAndFeel.getControlShadow();
602: Color light = MetalLookAndFeel.getWhite();
603: Color middle = MetalLookAndFeel.getControl();
604:
605:
606: g.setColor(darkShadow);
607: g.drawLine(x, y, x + w - 2, y);
608:
609:
610: g.drawLine(x, y, x, y + h - 2);
611:
612:
613: g.drawLine(x + w - 2, y, x + w - 2, y + h + 1);
614:
615:
616: g.drawLine(x + 2, y + h - 2, x + w - 2, y + h - 2);
617:
618:
619: g.setColor(light);
620: g.drawLine(x + w - 1, y, x + w - 1, y + h - 1);
621:
622:
623: g.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
624:
625:
626: g.setColor(middle);
627: g.drawLine(x + w - 1, y, x + w - 1, y);
628: g.drawLine(x + w - 2, y + 2, x + w - 2, y + 2);
629: g.drawLine(x, y + h - 1, x, y + h - 1);
630: g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
631:
632: }
633:
634: }
635:
636:
639: static class RolloverMarginBorder extends AbstractBorder
640: {
641:
642: protected static Insets borderInsets = new Insets(3, 3, 3, 3);
643:
644:
647: public RolloverMarginBorder()
648: {
649: }
650:
651:
658: public Insets getBorderInsets(Component c)
659: {
660: return getBorderInsets(c, null);
661: }
662:
663:
672: public Insets getBorderInsets(Component c, Insets newInsets)
673: {
674: if (newInsets == null)
675: newInsets = new Insets(0, 0, 0, 0);
676:
677: AbstractButton b = (AbstractButton) c;
678: Insets margin = b.getMargin();
679: newInsets.bottom = borderInsets.bottom;
680: newInsets.left = borderInsets.left;
681: newInsets.right = borderInsets.right;
682: newInsets.top = borderInsets.top;
683: return newInsets;
684: }
685: }
686:
687:
690: public static class PopupMenuBorder
691: extends AbstractBorder
692: implements UIResource
693: {
694:
695:
696: protected static Insets borderInsets = new Insets(2, 2, 1, 1);
697:
698:
701: public PopupMenuBorder()
702: {
703: }
704:
705:
712: public Insets getBorderInsets(Component c)
713: {
714: return getBorderInsets(c, null);
715: }
716:
717:
724: public Insets getBorderInsets(Component c, Insets i)
725: {
726: Insets insets;
727: if (i == null)
728: insets = new Insets(borderInsets.top, borderInsets.left,
729: borderInsets.bottom, borderInsets.right);
730: else
731: {
732: insets = i;
733: insets.top = borderInsets.top;
734: insets.left = borderInsets.left;
735: insets.bottom = borderInsets.bottom;
736: insets.right = borderInsets.right;
737: }
738:
739: return insets;
740: }
741:
742:
754: public void paintBorder(Component c, Graphics g, int x, int y, int w,
755: int h)
756: {
757: Color darkShadow = MetalLookAndFeel.getPrimaryControlDarkShadow();
758: Color light = MetalLookAndFeel.getPrimaryControlHighlight();
759:
760:
761: g.setColor(darkShadow);
762: g.drawRect(x, y, w - 1, h - 1);
763:
764:
765: g.setColor(light);
766: g.drawLine(x + 1, y + 1, x + 1, y + h - 2);
767: g.drawLine(x + 1, y + 1, x + w - 2, y + 1);
768: }
769:
770: }
771:
772:
777: public static Border getButtonBorder()
778: {
779: if (buttonBorder == null)
780: {
781: Border outer = new ButtonBorder();
782: Border inner = getMarginBorder();
783: buttonBorder = new BorderUIResource.CompoundBorderUIResource
784: (outer, inner);
785: }
786: return buttonBorder;
787: }
788:
789:
796: public static Border getTextFieldBorder()
797: {
798: if (textFieldBorder == null)
799: textFieldBorder = new TextFieldBorder();
800: return textFieldBorder;
801: }
802:
803:
808: static Border getToolbarButtonBorder()
809: {
810: if (toolbarButtonBorder == null)
811: {
812: Border outer = new ButtonBorder();
813: Border inner = new RolloverMarginBorder();
814: toolbarButtonBorder = new BorderUIResource.CompoundBorderUIResource
815: (outer, inner);
816: }
817: return toolbarButtonBorder;
818: }
819:
820:
825: static Border getMarginBorder()
826: {
827: if (marginBorder == null)
828: marginBorder = new BasicBorders.MarginBorder();
829: return marginBorder;
830: }
831: }