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 31 public class LineBorder extends AbstractBorder 32 { 33 private static Border blackLine; 34 private static Border grayLine; 35 36 protected int thickness; 37 protected Color lineColor; 38 protected boolean roundedCorners; 39 40 42 public static Border createBlackLineBorder() { 43 if (blackLine == null) { 44 blackLine = new LineBorder (Color.black, 1); 45 } 46 return blackLine; 47 } 48 49 51 public static Border createGrayLineBorder() { 52 if (grayLine == null) { 53 grayLine = new LineBorder (Color.gray, 1); 54 } 55 return grayLine; 56 } 57 58 63 public LineBorder(Color color) { 64 this(color, 1, false); 65 } 66 67 72 public LineBorder(Color color, int thickness) { 73 this(color, thickness, false); 74 } 75 76 84 public LineBorder(Color color, int thickness, boolean roundedCorners) { 85 lineColor = color; 86 this.thickness = thickness; 87 this.roundedCorners = roundedCorners; 88 } 89 90 100 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { 101 Color oldColor = g.getColor(); 102 int i; 103 104 g.setColor(lineColor); 106 for(i = 0; i < thickness; i++) { 107 if(!roundedCorners) 108 g.drawRect(x+i, y+i, width-i-i-1, height-i-i-1); 109 else 110 g.drawRoundRect(x+i, y+i, width-i-i-1, height-i-i-1, thickness, thickness); 111 } 112 g.setColor(oldColor); 113 } 114 115 119 public Insets getBorderInsets(Component c) { 120 return new Insets (thickness, thickness, thickness, thickness); 121 } 122 123 128 public Insets getBorderInsets(Component c, Insets insets) { 129 insets.left = insets.top = insets.right = insets.bottom = thickness; 130 return insets; 131 } 132 133 136 public Color getLineColor() { 137 return lineColor; 138 } 139 140 143 public int getThickness() { 144 return thickness; 145 } 146 147 150 public boolean getRoundedCorners() { 151 return roundedCorners; 152 } 153 154 157 public boolean isBorderOpaque() { 158 return !roundedCorners; 159 } 160 161 } 162 | Popular Tags |