1 27 28 package swingwtx.swing.border; 29 30 import swingwt.awt.*; 31 import swingwtx.swing.SwingWTUtils; 32 33 public class TitledBorder extends AbstractBorder implements Border { 34 35 public static final int DEFAULT_POSITION = 0; 36 public static final int ABOVE_TOP = 1; 37 public static final int TOP = 2; 38 public static final int BELOW_TOP = 3; 39 public static final int ABOVE_BOTTOM = 4; 40 public static final int BOTTOM = 5; 41 public static final int BELOW_BOTTOM = 6; 42 public static final int DEFAULT_JUSTIFICATION = 0; 43 public static final int LEFT = 1; 44 public static final int CENTER = 2; 45 public static final int RIGHT = 3; 46 public static final int LEADING = 4; 47 public static final int TRAILING = 5; 48 49 protected String title = ""; 50 protected Font font = null; 51 protected Color color = null; 52 protected Border border = null; 53 54 public TitledBorder(String title) {this.title = title; this.border = new EmptyBorder(0, 0, 0, 0);} 55 public TitledBorder(Border border) {this.border = border;} 56 public TitledBorder(Border border, String title) {this.title = title; this.border = border;} 57 public TitledBorder(Border border, String title, int titleJustification, int titlePosition) {this.title = title; this.border = border;} 58 public TitledBorder(Border border, String title, int titleJustification, int titlePosition, Font titleFont) {this.title = title; font = titleFont; this.border = border; } 59 public TitledBorder(Border border, String title, int titleJustification, int titlePosition, Font titleFont, Color titleColor) {this.title = title; font = titleFont; color = titleColor; this.border = border;} 60 61 65 public java.lang.String getTitle() { 66 return title; 67 } 68 69 73 public void setTitle(java.lang.String title) { 74 this.title = title; 75 } 76 77 81 public swingwt.awt.Font getFont() { 82 return font; 83 } 84 85 89 public void setFont(swingwt.awt.Font font) { 90 this.font = font; 91 } 92 93 97 public swingwt.awt.Color getColor() { 98 return color; 99 } 100 101 105 public void setColor(swingwt.awt.Color color) { 106 this.color = color; 107 } 108 109 113 public swingwtx.swing.border.Border getBorder() { 114 return border; 115 } 116 117 121 public void setBorder(swingwtx.swing.border.Border border) { 122 this.border = border; 123 } 124 125 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { 126 g.drawLine(2, 10, width - 3, 10); 127 g.drawLine(2, 10, 2, height - 3); 128 g.drawLine(2, height - 3, width - 2, height - 3); 129 g.drawLine(width - 3, 10, width - 3, height - 3); 130 131 if (font != null) g.setFont( font ); 132 if (color != null) g.setColor( color ); 133 g.drawString(title, 5, 3); 134 } 135 136 public Insets getBorderInsets(Component c) { 137 return getBorderInsets(c, new Insets()); 138 } 139 140 public Insets getBorderInsets(Component c, Insets insets) { 141 insets.top = insets.bottom = SwingWTUtils.getRenderStringHeight("W"); 142 insets.left = insets.right = 4; 143 return insets; 144 } 145 146 public void setTitleJustification( int titleJustification) {} 147 public int getTitleJustification() { return DEFAULT_JUSTIFICATION; } 148 149 } 150 | Popular Tags |