1 19 package org.columba.core.gui.base; 20 21 import java.awt.Component ; 22 import java.awt.Graphics ; 23 import java.awt.Insets ; 24 25 import javax.swing.SwingConstants ; 26 import javax.swing.border.EtchedBorder ; 27 28 public class SingleSideEtchedBorder extends EtchedBorder { 29 protected int side; 30 31 public SingleSideEtchedBorder(int side) { 32 this(side, LOWERED); 33 } 34 35 public SingleSideEtchedBorder(int side, int etchType) { 36 super(etchType); 37 this.side = side; 38 } 39 40 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { 41 g.translate(x, y); 42 int x1, y1, x2, y2; 43 switch(side) { 44 case SwingConstants.TOP: 45 x2 = width-2; 46 x1 = y1 = y2 = 0; 47 break; 48 case SwingConstants.LEFT: 49 y2 = height-2; 50 x1 = y1 = x2 = 0; 51 break; 52 case SwingConstants.RIGHT: 53 x1 = x2 = width-2; 54 y1 = 0; 55 y2 = height-2; 56 break; 57 default: 58 x1 = 0; 59 x2 = width-2; 60 y1 = y2 = height-2; 61 } 62 g.setColor(etchType == LOWERED? getShadowColor(c) : getHighlightColor(c)); 63 g.drawLine(x1, y1, x2, y2); 64 g.setColor(etchType == LOWERED? getHighlightColor(c) : getShadowColor(c)); 65 g.drawLine(x1+1, y1+1, x2+1, y2+1); 66 g.translate(-x, -y); 67 } 68 69 public Insets getBorderInsets(Component c) { 70 return getBorderInsets(c, new Insets (0, 0, 0, 0)); 71 } 72 73 public Insets getBorderInsets(Component c, Insets i) { 74 switch(side) { 75 case SwingConstants.TOP: 76 i.top = 2; 77 i.left = i.right = i.bottom = 0; 78 break; 79 case SwingConstants.LEFT: 80 i.left = 2; 81 i.top = i.right = i.bottom = 0; 82 break; 83 case SwingConstants.RIGHT: 84 i.right = 2; 85 i.top = i.left = i.bottom = 0; 86 break; 87 default: 88 i.bottom = 2; 89 i.top = i.left = i.right = 0; 90 } 91 return i; 92 } 93 } 94 | Popular Tags |