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: import ;
59: import ;
60: import ;
61: import ;
62: import ;
63: import ;
64: import ;
65: import ;
66: import ;
67:
68:
69:
74: public class MetalBorders
75: {
76:
77:
78: private static Border buttonBorder;
79:
80:
81: private static Border toggleButtonBorder;
82:
83:
84: private static Border desktopIconBorder;
85:
86:
87: private static Border toolbarButtonBorder;
88:
89:
90: private static Border textFieldBorder;
91:
92:
93: private static Border textBorder;
94:
95:
96: private static Border rolloverBorder;
97:
98:
103: private static BasicBorders.MarginBorder marginBorder;
104:
105:
108: public static class ButtonBorder extends AbstractBorder implements UIResource
109: {
110:
111: protected static Insets borderInsets = new Insets(3, 3, 3, 3);
112:
113:
116: public ButtonBorder()
117: {
118:
119: }
120:
121:
131: public void paintBorder(Component c, Graphics g, int x, int y, int w,
132: int h)
133: {
134:
135:
136:
137:
138:
139: if (MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme)
140: paintOceanButtonBorder(c, g, x, y, w, h);
141: else
142: paintDefaultButtonBorder(c, g, x, y, w, h);
143: }
144:
145:
155: private void paintDefaultButtonBorder(Component c, Graphics g, int x,
156: int y, int w, int h)
157: {
158: ButtonModel bmodel = null;
159:
160: if (c instanceof AbstractButton)
161: bmodel = ((AbstractButton) c).getModel();
162:
163: Color darkShadow = MetalLookAndFeel.getControlDarkShadow();
164: Color shadow = MetalLookAndFeel.getControlShadow();
165: Color light = MetalLookAndFeel.getControlHighlight();
166: Color middle = MetalLookAndFeel.getControl();
167:
168: if (c.isEnabled())
169: {
170:
171: g.setColor(darkShadow);
172: g.drawRect(x, y, w - 2, h - 2);
173:
174:
175:
176: if (c instanceof JButton && ((JButton) c).isDefaultButton())
177: {
178: g.drawRect(x + 1, y + 1, w - 4, h - 4);
179:
180: g.setColor(light);
181: g.drawLine(x + 2, y + 2, x + w - 4, y + 2);
182: g.drawLine(x + 2, y + 2, x + 2, y + h - 4);
183: g.drawLine(x + 2, y + h - 1, x + w - 1, y + h - 1);
184: g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 1);
185:
186: g.setColor(middle);
187: g.fillRect(x + w - 2, y + 2, 1, 1);
188: g.fillRect(x + 2, y + h - 2, 1, 1);
189: }
190: else
191: {
192:
193:
194: if (! (bmodel.isPressed() && bmodel.isArmed()) )
195: {
196:
197: g.setColor(light);
198: g.drawRect(x + 1, y + 1, w - 2, h - 2);
199:
200:
201: g.setColor(middle);
202: g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
203: g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);
204: }
205:
206:
207: else
208: {
209:
210: g.setColor(light);
211: g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
212: g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
213:
214:
215: g.setColor(middle);
216: g.drawLine(x + 1, y + 1, x + w - 2, y + 1);
217: g.drawLine(x + 1, y + 1, x + 1, y + h - 2);
218:
219:
220: g.setColor(shadow);
221: g.drawRect(x + 1, y + h - 2, 0, 0);
222: g.drawRect(x + w - 2, y + 1, 0, 0);
223: }
224: }
225: }
226: else
227: {
228:
229: g.setColor(MetalLookAndFeel.getInactiveControlTextColor());
230: g.drawRect(x, y, w - 2, h - 2);
231: }
232: }
233:
234:
244: private void paintOceanButtonBorder(Component c, Graphics g, int x,
245: int y, int w, int h)
246: {
247: ButtonModel bmodel = null;
248:
249: if (c instanceof AbstractButton)
250: bmodel = ((AbstractButton) c).getModel();
251:
252: Color darkShadow = MetalLookAndFeel.getControlDarkShadow();
253: Color shadow = MetalLookAndFeel.getControlShadow();
254: Color light = MetalLookAndFeel.getControlHighlight();
255: Color middle = MetalLookAndFeel.getControl();
256:
257: if (c.isEnabled())
258: {
259:
260:
261:
262: if (bmodel.isPressed() || ((c instanceof JButton)
263: && ((JButton) c).isDefaultButton()))
264: {
265:
266: g.setColor(darkShadow);
267: g.drawRect(x, y, w - 1, h - 1);
268: g.drawRect(x + 1, y + 1, w - 3, h - 3);
269: }
270: else if (bmodel.isRollover())
271: {
272: g.setColor(shadow);
273: g.drawRect(x, y, w - 1, h - 1);
274: g.drawRect(x + 2, y + 2, w - 5, h - 5);
275: g.setColor(darkShadow);
276: g.drawRect(x + 1, y + 1, w - 3, h - 3);
277: }
278: else
279: {
280: g.setColor(darkShadow);
281: g.drawRect(x, y, w - 1, h - 1);
282: }
283: }
284: else
285: {
286:
287: g.setColor(MetalLookAndFeel.getInactiveControlTextColor());
288: g.drawRect(x, y, w - 2, h - 2);
289: }
290: }
291:
292:
299: public Insets getBorderInsets(Component c)
300: {
301: return borderInsets;
302: }
303:
304:
314: public Insets getBorderInsets(Component c, Insets newInsets)
315: {
316: newInsets.bottom = borderInsets.bottom;
317: newInsets.left = borderInsets.left;
318: newInsets.right = borderInsets.right;
319: newInsets.top = borderInsets.top;
320: return newInsets;
321: }
322: }
323:
324:
327: static class DesktopIconBorder extends AbstractBorder
328: implements UIResource
329: {
330:
333: public DesktopIconBorder()
334: {
335:
336: }
337:
338:
345: public Insets getBorderInsets(Component c)
346: {
347: return getBorderInsets(c, null);
348: }
349:
350:
356: public Insets getBorderInsets(Component c, Insets newInsets)
357: {
358: if (newInsets == null)
359: newInsets = new Insets(3, 3, 2, 3);
360: else
361: {
362: newInsets.top = 3;
363: newInsets.left = 3;
364: newInsets.bottom = 2;
365: newInsets.right = 3;
366: }
367: return newInsets;
368: }
369:
370:
380: public void paintBorder(Component c, Graphics g, int x, int y, int w,
381: int h)
382: {
383: g.setColor(MetalLookAndFeel.getControlDarkShadow());
384: g.drawRect(x, y, w - 1, h - 1);
385: }
386:
387: }
388:
389:
392: public static class Flush3DBorder extends AbstractBorder
393: implements UIResource
394: {
395: private static final Insets borderInsets = new Insets(2, 2, 2, 2);
396:
397:
400: public Flush3DBorder()
401: {
402:
403: }
404:
405:
412: public Insets getBorderInsets(Component c)
413: {
414: return borderInsets;
415: }
416:
417:
427: public Insets getBorderInsets(Component c, Insets newInsets)
428: {
429: newInsets.top = borderInsets.top;
430: newInsets.left = borderInsets.left;
431: newInsets.bottom = borderInsets.bottom;
432: newInsets.right = borderInsets.right;
433: return newInsets;
434: }
435:
436:
446: public void paintBorder(Component c, Graphics g, int x, int y, int w,
447: int h)
448: {
449: Color savedColor = g.getColor();
450: g.setColor(MetalLookAndFeel.getControlDarkShadow());
451: g.drawRect(x, y, w - 2, h - 2);
452: g.setColor(MetalLookAndFeel.getControlHighlight());
453: g.drawRect(x + 1, y + 1, w - 2, h - 2);
454: g.setColor(MetalLookAndFeel.getControl());
455: g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
456: g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);
457: g.setColor(savedColor);
458: }
459:
460: }
461:
462:
468: public static class PaletteBorder extends AbstractBorder
469: implements UIResource
470: {
471: private static final Insets borderInsets = new Insets(1, 1, 1, 1);
472:
473:
476: public PaletteBorder()
477: {
478:
479: }
480:
481:
488: public Insets getBorderInsets(Component c)
489: {
490: return borderInsets;
491: }
492:
493:
503: public Insets getBorderInsets(Component c, Insets newInsets)
504: {
505: newInsets.top = borderInsets.top;
506: newInsets.left = borderInsets.left;
507: newInsets.bottom = borderInsets.bottom;
508: newInsets.right = borderInsets.right;
509: return newInsets;
510: }
511:
512:
522: public void paintBorder(Component c, Graphics g, int x, int y, int w,
523: int h)
524: {
525: Color savedColor = g.getColor();
526:
527:
528: g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
529: g.drawRect(x, y, w - 1, h - 1);
530:
531:
532: g.setColor(MetalLookAndFeel.getControl());
533: g.fillRect(x, y, 1, 1);
534: g.fillRect(x + w - 1, y, 1, 1);
535: g.fillRect(x + w - 1, y + h - 1, 1, 1);
536: g.fillRect(x, y + h - 1, 1, 1);
537: g.setColor(savedColor);
538: }
539:
540: }
541:
542:
545: public static class TextFieldBorder extends Flush3DBorder
546: implements UIResource
547: {
548:
551: public TextFieldBorder()
552: {
553:
554: }
555:
556:
566: public void paintBorder(Component c, Graphics g, int x, int y, int w,
567: int h)
568: {
569: boolean enabledTextBorder;
570: if (c instanceof JTextComponent)
571: {
572: JTextComponent tc = (JTextComponent) c;
573: enabledTextBorder = tc.isEnabled() && tc.isEditable();
574: }
575: else
576: enabledTextBorder = false;
577:
578: if (enabledTextBorder)
579: super.paintBorder(c, g, x, y, w, h);
580: else
581: {
582: Color savedColor = g.getColor();
583: g.setColor(MetalLookAndFeel.getControlShadow());
584: g.drawRect(x, y, w - 1, h - 1);
585: g.setColor(savedColor);
586: }
587: }
588:
589: }
590:
591:
594: public static class InternalFrameBorder extends AbstractBorder
595: implements UIResource
596: {
597: private static final Insets borderInsets = new Insets(5, 5, 5, 5);
598:
599:
602: public InternalFrameBorder()
603: {
604:
605: }
606:
607:
614: public Insets getBorderInsets(Component c)
615: {
616: return borderInsets;
617: }
618:
619:
629: public Insets getBorderInsets(Component c, Insets newInsets)
630: {
631: newInsets.top = borderInsets.top;
632: newInsets.left = borderInsets.left;
633: newInsets.bottom = borderInsets.bottom;
634: newInsets.right = borderInsets.right;
635: return newInsets;
636: }
637:
638:
648: public void paintBorder(Component c, Graphics g, int x, int y, int w,
649: int h)
650: {
651:
652: JInternalFrame f = (JInternalFrame) c;
653: if (f.isSelected())
654: g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
655: else
656: g.setColor(MetalLookAndFeel.getControlDarkShadow());
657:
658:
659: g.fillRect(x, y, w, 5);
660: g.fillRect(x, y, 5, h);
661: g.fillRect(x + w - 5, y, 5, h);
662: g.fillRect(x, y + h - 5, w, 5);
663:
664:
665: g.setColor(MetalLookAndFeel.getControl());
666: g.fillRect(x, y, 1, 1);
667: g.fillRect(x + w - 1, y, 1, 1);
668: g.fillRect(x + w - 1, y + h - 1, 1, 1);
669: g.fillRect(x, y + h - 1, 1, 1);
670:
671:
672: g.setColor(MetalLookAndFeel.getBlack());
673: g.drawLine(x + 14, y + 2, x + w - 15, y + 2);
674: g.drawLine(x + 14, y + h - 3, x + w - 15, y + h - 3);
675: g.drawLine(x + 2, y + 14, x + 2, y + h - 15);
676: g.drawLine(x + w - 3, y + 14, x + w - 3, y + h - 15);
677:
678:
679: if (f.isSelected())
680: g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
681: else
682: g.setColor(MetalLookAndFeel.getControlShadow());
683: g.drawLine(x + 15, y + 3, x + w - 14, y + 3);
684: g.drawLine(x + 15, y + h - 2, x + w - 14, y + h - 2);
685: g.drawLine(x + 3, y + 15, x + 3, y + h - 14);
686: g.drawLine(x + w - 2, y + 15, x + w - 2, y + h - 14);
687: }
688:
689: }
690:
691:
695: public static class OptionDialogBorder extends AbstractBorder
696: implements UIResource
697: {
698:
699:
702: public OptionDialogBorder()
703: {
704:
705: }
706:
707:
714: public Insets getBorderInsets(Component c)
715: {
716: return getBorderInsets(c, null);
717: }
718:
719:
725: public Insets getBorderInsets(Component c, Insets newInsets)
726: {
727: if (newInsets == null)
728: newInsets = new Insets(3, 3, 3, 3);
729: else
730: {
731: newInsets.top = 3;
732: newInsets.left = 3;
733: newInsets.bottom = 3;
734: newInsets.right = 3;
735: }
736: return newInsets;
737: }
738:
739:
749: public void paintBorder(Component c, Graphics g, int x, int y, int w,
750: int h)
751: {
752:
753: JInternalFrame f = (JInternalFrame) c;
754: g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
755: if (f.getContentPane() instanceof JOptionPane)
756: {
757: JOptionPane pane = (JOptionPane) f.getContentPane();
758: int type = pane.getMessageType();
759: if (type == JOptionPane.QUESTION_MESSAGE)
760: {
761: Color bc = UIManager.getColor(
762: "OptionPane.questionDialog.border.background");
763: if (bc != null)
764: g.setColor(bc);
765: }
766: if (type == JOptionPane.WARNING_MESSAGE)
767: {
768: Color bc = UIManager.getColor(
769: "OptionPane.warningDialog.border.background");
770: if (bc != null)
771: g.setColor(bc);
772: }
773: else if (type == JOptionPane.ERROR_MESSAGE)
774: {
775: Color bc = UIManager.getColor(
776: "OptionPane.errorDialog.border.background");
777: if (bc != null)
778: g.setColor(bc);
779: }
780: }
781:
782:
783: g.fillRect(x, y, w, 3);
784: g.fillRect(x, y, 3, h);
785: g.fillRect(x + w - 3, y, 3, h);
786: g.fillRect(x, y + h - 3, w, 3);
787:
788:
789: g.setColor(MetalLookAndFeel.getControl());
790: g.fillRect(x, y, 1, 1);
791: g.fillRect(x + w - 1, y, 1, 1);
792: g.fillRect(x + w - 1, y + h - 1, 1, 1);
793: g.fillRect(x, y + h - 1, 1, 1);
794:
795: }
796:
797: }
798:
799:
802: public static class MenuItemBorder extends AbstractBorder
803: implements UIResource
804: {
805:
806: protected static Insets borderInsets = new Insets(2, 2, 2, 2);
807:
808:
811: public MenuItemBorder()
812: {
813:
814: }
815:
816:
827: public void paintBorder(Component c, Graphics g, int x, int y, int w,
828: int h)
829: {
830: Color dark = MetalLookAndFeel.getPrimaryControlDarkShadow();
831: Color light = MetalLookAndFeel.getPrimaryControlHighlight();
832: if (c instanceof JMenu) {
833: JMenu menu = (JMenu) c;
834: if (menu.isSelected())
835: {
836: g.setColor(dark);
837: g.drawLine(x, y, x, y + h);
838: g.drawLine(x, y, x + w, y);
839: g.drawLine(x + w - 2, y + 1, x + w - 2, y + h);
840: g.setColor(light);
841: g.drawLine(x + w - 1, y + 1, x + w - 1, y + h);
842: }
843: }
844: else if (c instanceof JMenuItem)
845: {
846: JMenuItem item = (JMenuItem) c;
847: if (item.isArmed())
848: {
849: g.setColor(dark);
850: g.drawLine(x, y, x + w, y);
851: g.setColor(light);
852: g.drawLine(x, y + h - 1, x + w, y + h - 1);
853: }
854: else
855: {
856:
857: g.setColor(light);
858: g.drawLine(x, y, x, y + h);
859: }
860: }
861: }
862:
863:
870: public Insets getBorderInsets(Component c)
871: {
872: return borderInsets;
873: }
874:
875:
885: public Insets getBorderInsets(Component c, Insets insets)
886: {
887: insets.left = borderInsets.left;
888: insets.top = borderInsets.top;
889: insets.bottom = borderInsets.bottom;
890: insets.right = borderInsets.right;
891: return insets;
892: }
893: }
894:
895:
898: public static class MenuBarBorder
899: extends AbstractBorder
900: implements UIResource
901: {
902:
903: protected static Insets borderInsets = new Insets(1, 0, 1, 0);
904:
905:
906: private static Color borderColor = new Color(153, 153, 153);
907:
908:
911: public MenuBarBorder()
912: {
913:
914: }
915:
916:
927: public void paintBorder(Component c, Graphics g, int x, int y, int w,
928: int h)
929: {
930: g.setColor(borderColor);
931: g.drawLine(x, y + h - 1, x + w, y + h - 1);
932: }
933:
934:
941: public Insets getBorderInsets(Component c)
942: {
943: return borderInsets;
944: }
945:
946:
956: public Insets getBorderInsets(Component c, Insets insets)
957: {
958: insets.left = borderInsets.left;
959: insets.top = borderInsets.top;
960: insets.bottom = borderInsets.bottom;
961: insets.right = borderInsets.right;
962: return insets;
963: }
964: }
965:
966:
969: public static class ScrollPaneBorder
970: extends AbstractBorder
971: implements UIResource
972: {
973:
974: private static Insets insets = new Insets(1, 1, 2, 2);
975:
976:
979: public ScrollPaneBorder()
980: {
981:
982: }
983:
984:
989: public Insets getBorderInsets(Component c)
990: {
991: return insets;
992: }
993:
994:
1004: public void paintBorder(Component c, Graphics g, int x, int y,
1005: int w, int h)
1006: {
1007: Color darkShadow = MetalLookAndFeel.getControlDarkShadow();
1008: Color shadow = MetalLookAndFeel.getControlShadow();
1009: Color light = MetalLookAndFeel.getWhite();
1010: Color middle = MetalLookAndFeel.getControl();
1011:
1012:
1013: g.setColor(darkShadow);
1014: g.drawLine(x, y, x + w - 2, y);
1015:
1016:
1017: g.drawLine(x, y, x, y + h - 2);
1018:
1019:
1020: g.drawLine(x + w - 2, y, x + w - 2, y + h + 1);
1021:
1022:
1023: g.drawLine(x + 2, y + h - 2, x + w - 2, y + h - 2);
1024:
1025:
1026: g.setColor(light);
1027: g.drawLine(x + w - 1, y, x + w - 1, y + h - 1);
1028:
1029:
1030: g.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
1031:
1032:
1033: g.setColor(middle);
1034: g.drawLine(x + w - 1, y, x + w - 1, y);
1035: g.drawLine(x + w - 2, y + 2, x + w - 2, y + 2);
1036: g.drawLine(x, y + h - 1, x, y + h - 1);
1037: g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
1038:
1039: }
1040:
1041: }
1042:
1043:
1047: public static class RolloverButtonBorder
1048: extends MetalBorders.ButtonBorder
1049: {
1050:
1053: public RolloverButtonBorder()
1054: {
1055:
1056: }
1057:
1058:
1068: public void paintBorder(Component c, Graphics g, int x, int y, int w,
1069: int h)
1070: {
1071:
1072:
1073:
1074: super.paintBorder(c, g, x, y, w, h);
1075: }
1076: }
1077:
1078:
1081: static class RolloverMarginBorder extends AbstractBorder
1082: {
1083:
1084: protected static Insets borderInsets = new Insets(3, 3, 3, 3);
1085:
1086:
1089: public RolloverMarginBorder()
1090: {
1091:
1092: }
1093:
1094:
1101: public Insets getBorderInsets(Component c)
1102: {
1103: return getBorderInsets(c, null);
1104: }
1105:
1106:
1115: public Insets getBorderInsets(Component c, Insets newInsets)
1116: {
1117: if (newInsets == null)
1118: newInsets = new Insets(0, 0, 0, 0);
1119:
1120: AbstractButton b = (AbstractButton) c;
1121: Insets margin = b.getMargin();
1122: newInsets.bottom = borderInsets.bottom;
1123: newInsets.left = borderInsets.left;
1124: newInsets.right = borderInsets.right;
1125: newInsets.top = borderInsets.top;
1126: return newInsets;
1127: }
1128: }
1129:
1130:
1133: public static class PopupMenuBorder
1134: extends AbstractBorder
1135: implements UIResource
1136: {
1137:
1138:
1139: protected static Insets borderInsets = new Insets(3, 1, 2, 1);
1140:
1141:
1144: public PopupMenuBorder()
1145: {
1146:
1147: }
1148:
1149:
1156: public Insets getBorderInsets(Component c)
1157: {
1158: return getBorderInsets(c, null);
1159: }
1160:
1161:
1168: public Insets getBorderInsets(Component c, Insets i)
1169: {
1170: Insets insets;
1171: if (i == null)
1172: insets = new Insets(borderInsets.top, borderInsets.left,
1173: borderInsets.bottom, borderInsets.right);
1174: else
1175: {
1176: insets = i;
1177: insets.top = borderInsets.top;
1178: insets.left = borderInsets.left;
1179: insets.bottom = borderInsets.bottom;
1180: insets.right = borderInsets.right;
1181: }
1182:
1183: return insets;
1184: }
1185:
1186:
1198: public void paintBorder(Component c, Graphics g, int x, int y, int w,
1199: int h)
1200: {
1201: Color darkShadow = MetalLookAndFeel.getPrimaryControlDarkShadow();
1202: Color light = MetalLookAndFeel.getPrimaryControlHighlight();
1203:
1204:
1205: g.setColor(darkShadow);
1206: g.drawRect(x, y, w - 1, h - 1);
1207:
1208:
1209: g.setColor(light);
1210: g.drawLine(x + 1, y + 1, x + w - 2, y + 1);
1211: }
1212:
1213: }
1214:
1215:
1220: public static class ToggleButtonBorder
1221: extends ButtonBorder
1222: {
1223:
1226: public ToggleButtonBorder()
1227: {
1228:
1229: }
1230:
1231:
1241: public void paintBorder(Component c, Graphics g, int x, int y, int w,
1242: int h)
1243: {
1244: ButtonModel bmodel = null;
1245:
1246: if (c instanceof AbstractButton)
1247: bmodel = ((AbstractButton) c).getModel();
1248:
1249: Color darkShadow = MetalLookAndFeel.getControlDarkShadow();
1250: Color shadow = MetalLookAndFeel.getControlShadow();
1251: Color light = MetalLookAndFeel.getWhite();
1252: Color middle = MetalLookAndFeel.getControl();
1253:
1254: if (c.isEnabled())
1255: {
1256:
1257: g.setColor(darkShadow);
1258: g.drawRect(x, y, w - 2, h - 2);
1259:
1260: if (!bmodel.isArmed())
1261: {
1262:
1263: g.setColor(light);
1264: g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
1265: g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
1266: if (bmodel.isSelected())
1267: g.setColor(middle);
1268: g.drawLine(x + 1, y + 1, x + w - 3, y + 1);
1269: g.drawLine(x + 1, y + 1, x + 1, y + h - 3);
1270:
1271:
1272: g.setColor(shadow);
1273: g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
1274: g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);
1275: }
1276: else
1277: {
1278:
1279: g.setColor(light);
1280: g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
1281: g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
1282:
1283:
1284: g.setColor(shadow);
1285: g.drawLine(x + 1, y + 1, x + w - 2, y + 1);
1286: g.drawLine(x + 1, y + 1, x + 1, y + h - 2);
1287:
1288:
1289: g.setColor(shadow);
1290: g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
1291: g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);
1292:
1293: }
1294:
1295: g.setColor(middle);
1296: g.drawLine(x, y + h - 1, x, y + h - 1);
1297: g.drawLine(x + w - 1, y, x + w - 1, y);
1298: }
1299: else
1300: {
1301:
1302: g.setColor(MetalLookAndFeel.getControlDisabled());
1303: g.drawRect(x, y, w - 2, h - 2);
1304: }
1305: }
1306: }
1307:
1308:
1311: public static class ToolBarBorder extends AbstractBorder
1312: implements UIResource, SwingConstants
1313: {
1314:
1317: public ToolBarBorder()
1318: {
1319:
1320: }
1321:
1322:
1329: public Insets getBorderInsets(Component c)
1330: {
1331: return getBorderInsets(c, null);
1332: }
1333:
1334:
1340: public Insets getBorderInsets(Component c, Insets newInsets)
1341: {
1342: JToolBar tb = (JToolBar) c;
1343: if (tb.getOrientation() == JToolBar.HORIZONTAL)
1344: {
1345: if (newInsets == null)
1346: newInsets = new Insets(2, 16, 2, 2);
1347: else
1348: {
1349: newInsets.top = 2;
1350: newInsets.left = 16;
1351: newInsets.bottom = 2;
1352: newInsets.right = 2;
1353: }
1354: return newInsets;
1355: }
1356: else
1357: {
1358: if (newInsets == null)
1359: newInsets = new Insets(16, 2, 2, 2);
1360: else
1361: {
1362: newInsets.top = 16;
1363: newInsets.left = 2;
1364: newInsets.bottom = 2;
1365: newInsets.right = 2;
1366: }
1367: return newInsets;
1368: }
1369:
1370: }
1371:
1372:
1382: public void paintBorder(Component c, Graphics g, int x, int y, int w,
1383: int h)
1384: {
1385:
1386: JToolBar tb = (JToolBar) c;
1387: if (tb.getOrientation() == JToolBar.HORIZONTAL)
1388: {
1389: MetalUtils.fillMetalPattern(tb, g, x + 2, y + 2, x + 11, y + h - 5,
1390: MetalLookAndFeel.getControlHighlight(),
1391: MetalLookAndFeel.getControlDarkShadow());
1392: }
1393: else
1394: {
1395: MetalUtils.fillMetalPattern(tb, g, x + 2, y + 2, x + w - 5, y + 11,
1396: MetalLookAndFeel.getControlHighlight(),
1397: MetalLookAndFeel.getControlDarkShadow());
1398: }
1399: }
1400:
1401: }
1402:
1403:
1408: public static class TableHeaderBorder extends AbstractBorder
1409: {
1410:
1413:
1414:
1415:
1416: protected Insets editorBorderInsets;
1417:
1418:
1421: public TableHeaderBorder()
1422: {
1423: editorBorderInsets = new Insets(1, 1, 1, 1);
1424: }
1425:
1426:
1431: public Insets getBorderInsets(Component c)
1432: {
1433: return editorBorderInsets;
1434: }
1435:
1436:
1446: public void paintBorder(Component c, Graphics g, int x, int y, int w, int h)
1447: {
1448: Color dark = MetalLookAndFeel.getControlDarkShadow();
1449: Color light = MetalLookAndFeel.getWhite();
1450: Color old = g.getColor();
1451: g.setColor(light);
1452: g.drawLine(x, y, x + w - 2, y);
1453: g.drawLine(x, y, x, y + h - 2);
1454: g.setColor(dark);
1455: g.drawLine(x + w - 1, y, x + w - 1, y + h - 1);
1456: g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
1457: g.setColor(old);
1458: }
1459: }
1460:
1461:
1466: public static Border getButtonBorder()
1467: {
1468: if (buttonBorder == null)
1469: {
1470: Border outer = new ButtonBorder();
1471: Border inner = getMarginBorder();
1472: buttonBorder = new BorderUIResource.CompoundBorderUIResource
1473: (outer, inner);
1474: }
1475: return buttonBorder;
1476: }
1477:
1478:
1485: public static Border getToggleButtonBorder()
1486: {
1487: if (toggleButtonBorder == null)
1488: {
1489: Border outer = new ToggleButtonBorder();
1490: Border inner = getMarginBorder();
1491: toggleButtonBorder = new BorderUIResource.CompoundBorderUIResource
1492: (outer, inner);
1493: }
1494: return toggleButtonBorder;
1495: }
1496:
1497:
1505: public static Border getDesktopIconBorder()
1506: {
1507: if (desktopIconBorder == null)
1508: desktopIconBorder = new DesktopIconBorder();
1509: return desktopIconBorder;
1510: }
1511:
1512:
1519: public static Border getTextFieldBorder()
1520: {
1521: if (textFieldBorder == null)
1522: {
1523: Border inner = getMarginBorder();
1524: Border outer = new TextFieldBorder();
1525: textFieldBorder =
1526: new BorderUIResource.CompoundBorderUIResource(outer, inner);
1527: }
1528: return textFieldBorder;
1529: }
1530:
1531:
1539: public static Border getTextBorder()
1540: {
1541: if (textBorder == null)
1542: {
1543: Border inner = getMarginBorder();
1544: Border outer = new Flush3DBorder();
1545: textBorder =
1546: new BorderUIResource.CompoundBorderUIResource(outer, inner);
1547: }
1548: return textBorder;
1549: }
1550:
1551:
1556: static Border getToolbarButtonBorder()
1557: {
1558: if (toolbarButtonBorder == null)
1559: {
1560: Border outer = new ButtonBorder();
1561: Border inner = new RolloverMarginBorder();
1562: toolbarButtonBorder = new CompoundBorder(outer, inner);
1563: }
1564: return toolbarButtonBorder;
1565: }
1566:
1567:
1572: static Border getMarginBorder()
1573: {
1574: if (marginBorder == null)
1575: marginBorder = new BasicBorders.MarginBorder();
1576: return marginBorder;
1577: }
1578:
1579:
1584: static Border getRolloverBorder()
1585: {
1586: if (rolloverBorder == null)
1587: {
1588: Border outer = new MetalBorders.RolloverButtonBorder();
1589: Border inner = MetalBorders.getMarginBorder();
1590: rolloverBorder = new BorderUIResource.CompoundBorderUIResource(outer,
1591: inner);
1592: }
1593: return rolloverBorder;
1594: }
1595:
1596: }