1:
31: package ;
32:
33: import ;
34: import ;
35: import ;
36: import ;
37: import ;
38: import ;
39: import ;
40: import ;
41: import ;
42: import ;
43:
44: import ;
45: import ;
46:
47: public class JStatusBar extends JComponent
48: {
49: public static final int TYPE_ERROR = 3;
50: public static final int TYPE_WARNING = 2;
51: public static final int TYPE_INFORMATION = 1;
52: public static final int TYPE_NONE = 0;
53:
54: private JComponent otherComponents;
55: private JLabel statusHolder;
56: private IconTheme iconTheme;
57: private int statusType;
58:
59: public JStatusBar()
60: {
61: this(new DefaultIconTheme());
62: }
63:
64: public JStatusBar (final IconTheme theme)
65: {
66: setLayout(new BorderLayout());
67: setBorder(BorderFactory.createMatteBorder
68: (1, 0, 0, 0, UIManager.getDefaults().getColor("controlShadow")));
69: statusHolder = new JLabel(" ");
70: statusHolder.setMinimumSize(new Dimension(0, 20));
71: add(statusHolder, BorderLayout.CENTER);
72:
73: otherComponents = new JPanel();
74: add(otherComponents, BorderLayout.EAST);
75: this.iconTheme = theme;
76: }
77:
78: protected IconTheme getIconTheme()
79: {
80: return iconTheme;
81: }
82:
83: public void setIconTheme(final IconTheme iconTheme)
84: {
85: final IconTheme oldTheme = this.iconTheme;
86: this.iconTheme = iconTheme;
87: firePropertyChange("iconTheme", oldTheme, iconTheme);
88:
89: if (iconTheme == null)
90: {
91: statusHolder.setIcon(null);
92: }
93: else
94: {
95: updateTypeIcon(getStatusType());
96: }
97: }
98:
99: public JComponent getExtensionArea ()
100: {
101: return otherComponents;
102: }
103:
104: public int getStatusType()
105: {
106: return statusType;
107: }
108:
109: public String getStatusText()
110: {
111: return statusHolder.getText();
112: }
113:
114: public void setStatusText (final String text)
115: {
116: final String oldText = statusHolder.getText();
117: this.statusHolder.setText(text);
118: firePropertyChange("statusText", oldText, text);
119: }
120:
121: public void setStatusType (final int type)
122: {
123: final int oldType = statusType;
124: this.statusType = type;
125: firePropertyChange("statusType", oldType, type);
126: updateTypeIcon(type);
127: }
128:
129: public void setStatus (final int type, final String text)
130: {
131: this.statusType = type;
132: updateTypeIcon(type);
133: statusHolder.setText(text);
134: }
135:
136: private void updateTypeIcon(final int type)
137: {
138: if (iconTheme != null)
139: {
140: if (type == TYPE_ERROR)
141: {
142: final Icon res = getIconTheme().getSmallIcon(getLocale(), "statusbar.errorIcon");
143: statusHolder.setIcon(res);
144: }
145: else if (type == TYPE_WARNING)
146: {
147: final Icon res = getIconTheme().getSmallIcon(getLocale(), "statusbar.warningIcon");
148: statusHolder.setIcon(res);
149: }
150: else if (type == TYPE_INFORMATION)
151: {
152: final Icon res = getIconTheme().getSmallIcon(getLocale(), "statusbar.informationIcon");
153: statusHolder.setIcon(res);
154: }
155: else
156: {
157: final Icon res = getIconTheme().getSmallIcon(getLocale(), "statusbar.otherIcon");
158: statusHolder.setIcon(res);
159: }
160: }
161: }
162:
163: public void clear ()
164: {
165: setStatus(TYPE_NONE, " ");
166: }
167:
168:
180: public Locale getLocale()
181: {
182: try
183: {
184: return super.getLocale();
185: }
186: catch(IllegalComponentStateException ice)
187: {
188: return Locale.getDefault();
189: }
190: }
191: }