1 7 package javax.swing.border; 8 9 import java.awt.Graphics ; 10 import java.awt.Insets ; 11 import java.awt.Rectangle ; 12 import java.awt.Color ; 13 import java.awt.Component ; 14 15 36 public class EtchedBorder extends AbstractBorder 37 { 38 39 public static final int RAISED = 0; 40 41 public static final int LOWERED = 1; 42 43 protected int etchType; 44 protected Color highlight; 45 protected Color shadow; 46 47 52 public EtchedBorder() { 53 this(LOWERED); 54 } 55 56 63 public EtchedBorder(int etchType) { 64 this(etchType, null, null); 65 } 66 67 73 public EtchedBorder(Color highlight, Color shadow) { 74 this(LOWERED, highlight, shadow); 75 } 76 77 84 public EtchedBorder(int etchType, Color highlight, Color shadow) { 85 this.etchType = etchType; 86 this.highlight = highlight; 87 this.shadow = shadow; 88 } 89 90 100 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { 101 int w = width; 102 int h = height; 103 104 g.translate(x, y); 105 106 g.setColor(etchType == LOWERED? getShadowColor(c) : getHighlightColor(c)); 107 g.drawRect(0, 0, w-2, h-2); 108 109 g.setColor(etchType == LOWERED? getHighlightColor(c) : getShadowColor(c)); 110 g.drawLine(1, h-3, 1, 1); 111 g.drawLine(1, 1, w-3, 1); 112 113 g.drawLine(0, h-1, w-1, h-1); 114 g.drawLine(w-1, h-1, w-1, 0); 115 116 g.translate(-x, -y); 117 } 118 119 123 public Insets getBorderInsets(Component c) { 124 return new Insets (2, 2, 2, 2); 125 } 126 127 132 public Insets getBorderInsets(Component c, Insets insets) { 133 insets.left = insets.top = insets.right = insets.bottom = 2; 134 return insets; 135 } 136 137 140 public boolean isBorderOpaque() { return true; } 141 142 145 public int getEtchType() { 146 return etchType; 147 } 148 149 156 public Color getHighlightColor(Component c) { 157 return highlight != null? highlight : 158 c.getBackground().brighter(); 159 } 160 161 166 public Color getHighlightColor() { 167 return highlight; 168 } 169 170 177 public Color getShadowColor(Component c) { 178 return shadow != null? shadow : c.getBackground().darker(); 179 } 180 181 186 public Color getShadowColor() { 187 return shadow; 188 } 189 190 } 191 | Popular Tags |