1 package snow.utils.gui; 2 3 import java.awt.*; 4 import javax.swing.border.*; 5 import javax.swing.UIManager ; 6 7 8 9 15 16 public final class CustomEtchedBorder extends EmptyBorder 17 { 18 19 protected Color lightColor; 20 protected Color darkColor; 21 22 private boolean on_top; 23 private boolean on_left; 24 private boolean on_bottom; 25 private boolean on_right; 26 27 28 boolean doUpdateColors = true; 30 31 34 public CustomEtchedBorder( boolean on_top, boolean on_left, boolean on_bottom, boolean on_right, 35 final Color lightColor, 36 final Color darkColor ) 37 { 38 super( on_top ? 2 : 0, 39 on_left ? 2 : 0, 40 on_bottom ? 2 : 0, 41 on_right ? 2 : 0 ); 42 this.lightColor = lightColor; 43 this.darkColor = darkColor; 44 this.doUpdateColors = false; this.on_top = on_top; 46 this.on_left = on_left; 47 this.on_bottom = on_bottom; 48 this.on_right = on_right; 49 } 50 51 52 53 54 57 public CustomEtchedBorder( boolean on_top, boolean on_left, boolean on_bottom, boolean on_right ) 58 { 59 super( on_top ? 2 : 0, 60 on_left ? 2 : 0, 61 on_bottom ? 2 : 0, 62 on_right ? 2 : 0 ); 63 this.lightColor = UIManager.getColor("Panel.background").brighter(); 64 this.darkColor = UIManager.getColor("Panel.background").darker(); 65 this.doUpdateColors = true; this.on_top = on_top; 67 this.on_left = on_left; 68 this.on_bottom = on_bottom; 69 this.on_right = on_right; 70 } 71 72 73 74 77 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) 78 { 79 if( this.doUpdateColors ) 80 { 81 this.lightColor = UIManager.getColor("Panel.background").brighter(); 82 this.darkColor = UIManager.getColor("Panel.background").darker(); 83 } 84 85 Insets insets = getBorderInsets(c); 86 Color oldColor = g.getColor(); 87 g.translate(x, y); 88 89 g.setColor( this.darkColor ); 90 91 if( this.on_top ) g.drawLine( 0,0,width-1,0 ); 92 if( this.on_left ) g.drawLine( 0,0,0,height-1 ); 93 if( this.on_bottom ) g.drawLine( 1,height-2,width-2,height-2 ); 94 if( this.on_right ) g.drawLine( width-2,1,width-2,height-2 ); 95 96 g.setColor( this.lightColor ); 97 98 if( this.on_bottom ) g.drawLine( 1,height-1,width-1,height-1 ); 99 if( this.on_right ) g.drawLine( width-1,1,width-1,height-1 ); 100 if( this.on_top ) g.drawLine( 1,1,width-2,1 ); 101 if( this.on_left ) g.drawLine( 1,1,1,height-2 ); 102 103 g.translate(-x, -y); 104 g.setColor(oldColor); 105 } 106 107 111 public Insets getBorderInsets(Component c) { 112 return getBorderInsets(); 113 } 114 115 120 public Insets getBorderInsets(Component c, Insets insets) { 121 return computeInsets(insets); 122 } 123 124 127 public Insets getBorderInsets() { 128 return computeInsets(new Insets(0,0,0,0)); 129 } 130 131 132 protected Insets computeInsets(Insets insets) 133 { 134 insets.left = left; 135 insets.top = top; 136 insets.right = right; 137 insets.bottom = bottom; 138 return insets; 139 } 140 141 142 145 public boolean isBorderOpaque() 146 { 147 return true; 148 } 149 150 } | Popular Tags |