1 7 package javax.swing.plaf.synth; 8 9 import java.awt.*; 10 import javax.swing.*; 11 import javax.swing.border.*; 12 import javax.swing.plaf.UIResource ; 13 import sun.swing.plaf.synth.SynthUI; 14 15 22 class SynthBorder extends AbstractBorder implements UIResource { 23 private SynthUI ui; 24 private Insets insets; 25 26 SynthBorder(SynthUI ui, Insets insets) { 27 this.ui = ui; 28 this.insets = insets; 29 } 30 31 SynthBorder(SynthUI ui) { 32 this(ui, null); 33 } 34 35 public void paintBorder(Component c, Graphics g, int x, int y, 36 int width, int height) { 37 JComponent jc = (JComponent)c; 38 SynthContext context = ui.getContext(jc); 39 SynthStyle style = context.getStyle(); 40 if (style == null) { 41 assert false: "SynthBorder is being used outside after the UI " + 42 "has been uninstalled"; 43 return; 44 } 45 ui.paintBorder(context, g, x, y, width, height); 46 context.dispose(); 47 } 48 49 57 public Insets getBorderInsets(Component c) { 58 return getBorderInsets(c, null); 59 } 60 61 67 public Insets getBorderInsets(Component c, Insets insets) { 68 if (this.insets != null) { 69 if (insets == null) { 70 insets = new Insets(this.insets.top, this.insets.left, 71 this.insets.bottom, this.insets.right); 72 } 73 else { 74 insets.top = this.insets.top; 75 insets.bottom = this.insets.bottom; 76 insets.left = this.insets.left; 77 insets.right = this.insets.left; 78 } 79 } 80 else if (insets == null) { 81 insets = new Insets(0, 0, 0, 0); 82 } 83 else { 84 insets.top = insets.bottom = insets.left = insets.right = 0; 85 } 86 if (c instanceof JComponent) { 87 Region region = Region.getRegion((JComponent)c); 88 Insets margin = null; 89 if ((region == Region.ARROW_BUTTON || region == Region.BUTTON || 90 region == Region.CHECK_BOX || 91 region == Region.CHECK_BOX_MENU_ITEM || 92 region == Region.MENU || region == Region.MENU_ITEM || 93 region == Region.RADIO_BUTTON || 94 region == Region.RADIO_BUTTON_MENU_ITEM || 95 region == Region.TOGGLE_BUTTON) && 96 (c instanceof AbstractButton)) { 97 margin = ((AbstractButton)c).getMargin(); 98 } 99 else if (region == Region.TOOL_BAR && (c instanceof JToolBar)) { 100 margin = ((JToolBar)c).getMargin(); 101 } 102 else if (region == Region.MENU_BAR && (c instanceof JMenuBar)) { 103 margin = ((JMenuBar)c).getMargin(); 104 } 105 if (margin != null) { 106 insets.top += margin.top; 107 insets.bottom += margin.bottom; 108 insets.left += margin.left; 109 insets.right += margin.right; 110 } 111 } 112 return insets; 113 } 114 115 119 public boolean isBorderOpaque() { 120 return false; 121 } 122 } 123 | Popular Tags |