KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwtx > swing > border > TitledBorder


1 /*
2    SwingWT
3    Copyright(c)2003-2004, R. Rawson-Tetley
4
5    For more information on distributing and using this program, please
6    see the accompanying "COPYING" file.
7
8    Contact me by electronic mail: bobintetley@users.sourceforge.net
9
10    $Log: TitledBorder.java,v $
11    Revision 1.7 2004/05/05 12:43:22 bobintetley
12    Patches/new files from Laurent Martell
13
14    Revision 1.6 2004/04/23 00:52:32 dannaab
15    Handle borders in a Swing-like way. Implement EmptyBorder & TitledBorder
16
17    Revision 1.5 2004/01/26 12:02:49 bobintetley
18    JPanel titled border support
19
20    Revision 1.4 2004/01/09 14:48:40 bobintetley
21    *** empty log message ***
22
23    Revision 1.3 2003/12/14 09:13:38 bobintetley
24    Added CVS log to source headers
25
26 */

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 JavaDoc title = "";
50     protected Font font = null;
51     protected Color color = null;
52     protected Border border = null;
53
54     public TitledBorder(String JavaDoc 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 JavaDoc title) {this.title = title; this.border = border;}
57     public TitledBorder(Border border, String JavaDoc title, int titleJustification, int titlePosition) {this.title = title; this.border = border;}
58     public TitledBorder(Border border, String JavaDoc title, int titleJustification, int titlePosition, Font titleFont) {this.title = title; font = titleFont; this.border = border; }
59     public TitledBorder(Border border, String JavaDoc title, int titleJustification, int titlePosition, Font titleFont, Color titleColor) {this.title = title; font = titleFont; color = titleColor; this.border = border;}
60     
61     /** Getter for property title.
62      * @return Value of property title.
63      *
64      */

65     public java.lang.String JavaDoc getTitle() {
66         return title;
67     }
68     
69     /** Setter for property title.
70      * @param title New value of property title.
71      *
72      */

73     public void setTitle(java.lang.String JavaDoc title) {
74         this.title = title;
75     }
76     
77     /** Getter for property font.
78      * @return Value of property font.
79      *
80      */

81     public swingwt.awt.Font getFont() {
82         return font;
83     }
84     
85     /** Setter for property font.
86      * @param font New value of property font.
87      *
88      */

89     public void setFont(swingwt.awt.Font font) {
90         this.font = font;
91     }
92     
93     /** Getter for property color.
94      * @return Value of property color.
95      *
96      */

97     public swingwt.awt.Color getColor() {
98         return color;
99     }
100     
101     /** Setter for property color.
102      * @param color New value of property color.
103      *
104      */

105     public void setColor(swingwt.awt.Color color) {
106         this.color = color;
107     }
108     
109     /** Getter for property border.
110      * @return Value of property border.
111      *
112      */

113     public swingwtx.swing.border.Border getBorder() {
114         return border;
115     }
116     
117     /** Setter for property border.
118      * @param border New value of property border.
119      *
120      */

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