Revision 270 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/usability/button/JStandardizedButton.java
JStandardizedButton.java | ||
---|---|---|
67 | 67 |
* |
68 | 68 |
*/ |
69 | 69 |
public class JStandardizedButton extends JButton { |
70 |
private static final long serialVersionUID = -1635879317292710725L; |
|
71 | 70 |
|
72 |
// TODO this should be initialized from a properties file or so. |
|
73 |
private static int[][] buttonSizes = new int[][] { new int[] { 90, 23 }, |
|
74 |
new int[] { 110, 23 }, new int[] { 135, 23 }, new int[] { 160, 23 } }; |
|
71 |
private static final long serialVersionUID = -1635879317292710725L; |
|
75 | 72 |
|
76 |
private String enableText; |
|
77 |
private String toolTip; |
|
73 |
// TODO this should be initialized from a properties file or so. |
|
74 |
private static int[][] buttonSizes = |
|
75 |
new int[][] { new int[] { 90, 23 }, new int[] { 110, 23 }, |
|
76 |
new int[] { 135, 23 }, new int[] { 160, 23 } }; |
|
78 | 77 |
|
79 |
/** |
|
80 |
* Creates a new empty instance of org.gvsig.gui.beans.swing.JButton. |
|
81 |
*/ |
|
82 |
public JStandardizedButton() { |
|
83 |
super(); |
|
84 |
} |
|
78 |
private String enableText; |
|
79 |
private String toolTip; |
|
85 | 80 |
|
86 |
/** |
|
87 |
* Creates a new instance of org.gvsig.gui.beans.swing.JButton from an |
|
88 |
* {@link Action}. |
|
89 |
*/ |
|
90 |
public JStandardizedButton(Action action) { |
|
91 |
super(action); |
|
92 |
} |
|
81 |
/** |
|
82 |
* Creates a new empty instance of org.gvsig.gui.beans.swing.JButton. |
|
83 |
*/ |
|
84 |
public JStandardizedButton() { |
|
85 |
super(); |
|
86 |
} |
|
93 | 87 |
|
94 |
/**
|
|
95 |
* Creates a new instance of org.gvsig.gui.beans.swing.JButton containing an
|
|
96 |
* image.
|
|
97 |
*/
|
|
98 |
public JStandardizedButton(Icon icon) {
|
|
99 |
super(icon);
|
|
100 |
}
|
|
88 |
/**
|
|
89 |
* Creates a new instance of org.gvsig.gui.beans.swing.JButton from an
|
|
90 |
* {@link Action}.
|
|
91 |
*/
|
|
92 |
public JStandardizedButton(Action action) {
|
|
93 |
super(action);
|
|
94 |
}
|
|
101 | 95 |
|
102 |
/** |
|
103 |
* Creates a new instance of org.gvsig.gui.beans.swing.JButton containing a |
|
104 |
* text. |
|
105 |
* |
|
106 |
* @param text |
|
107 |
*/ |
|
108 |
public JStandardizedButton(String text) { |
|
109 |
super(); |
|
110 |
setText(text); |
|
111 |
} |
|
96 |
/** |
|
97 |
* Creates a new instance of org.gvsig.gui.beans.swing.JButton containing an |
|
98 |
* image. |
|
99 |
*/ |
|
100 |
public JStandardizedButton(Icon icon) { |
|
101 |
super(icon); |
|
102 |
} |
|
112 | 103 |
|
113 |
/** |
|
114 |
* Creates a new instance of org.gvsig.gui.beans.swing.JButton containing an |
|
115 |
* image and a text. |
|
116 |
* |
|
117 |
* @param text |
|
118 |
* @param icon |
|
119 |
*/ |
|
120 |
public JStandardizedButton(String text, Icon icon) { |
|
121 |
super(icon); |
|
122 |
setText(text); |
|
123 |
} |
|
104 |
/** |
|
105 |
* Creates a new instance of org.gvsig.gui.beans.swing.JButton containing a |
|
106 |
* text. |
|
107 |
* |
|
108 |
* @param text |
|
109 |
*/ |
|
110 |
public JStandardizedButton(String text) { |
|
111 |
super(); |
|
112 |
setText(text); |
|
113 |
} |
|
124 | 114 |
|
125 |
/** |
|
126 |
* Gets the text that appears in the tooltip when the button is disabled. |
|
127 |
* |
|
128 |
* @return String |
|
129 |
*/ |
|
130 |
public String getEnableText() { |
|
131 |
return enableText; |
|
132 |
} |
|
115 |
/** |
|
116 |
* Creates a new instance of org.gvsig.gui.beans.swing.JButton containing an |
|
117 |
* image and a text. |
|
118 |
* |
|
119 |
* @param text |
|
120 |
* @param icon |
|
121 |
*/ |
|
122 |
public JStandardizedButton(String text, Icon icon) { |
|
123 |
super(icon); |
|
124 |
setText(text); |
|
125 |
} |
|
133 | 126 |
|
134 |
@Override |
|
135 |
public Dimension getMaximumSize() { |
|
136 |
return getPreferredSize(); |
|
137 |
} |
|
127 |
/** |
|
128 |
* Gets the text that appears in the tooltip when the button is disabled. |
|
129 |
* |
|
130 |
* @return String |
|
131 |
*/ |
|
132 |
public String getEnableText() { |
|
133 |
return enableText; |
|
134 |
} |
|
138 | 135 |
|
139 |
@Override
|
|
140 |
public Dimension getMinimumSize() {
|
|
141 |
return getPreferredSize();
|
|
142 |
}
|
|
136 |
@Override
|
|
137 |
public Dimension getMaximumSize() {
|
|
138 |
return getPreferredSize();
|
|
139 |
}
|
|
143 | 140 |
|
144 |
@Override |
|
145 |
public Dimension getPreferredSize() { |
|
146 |
Dimension d = getUI().getMinimumSize(this); |
|
147 |
int oldWidth = (int) d.getWidth(), newWidth = oldWidth; |
|
148 |
int oldHeight = (int) d.getHeight(), newHeight = oldHeight; |
|
141 |
@Override |
|
142 |
public Dimension getMinimumSize() { |
|
143 |
return getPreferredSize(); |
|
144 |
} |
|
149 | 145 |
|
150 |
// figure out the suitable width |
|
151 |
for (int i = buttonSizes.length - 1; i >= 0; i--) |
|
152 |
if (oldWidth < buttonSizes[i][0]) |
|
153 |
newWidth = buttonSizes[i][0]; |
|
146 |
@Override |
|
147 |
public Dimension getPreferredSize() { |
|
148 |
Dimension d = getUI().getMinimumSize(this); |
|
149 |
int oldWidth = (int) d.getWidth(), newWidth = oldWidth; |
|
150 |
int oldHeight = (int) d.getHeight(), newHeight = oldHeight; |
|
154 | 151 |
|
155 |
// figure out the suitable height
|
|
156 |
for (int i = buttonSizes.length - 1; i >= 0; i--)
|
|
157 |
if (oldHeight < buttonSizes[i][1])
|
|
158 |
newHeight = buttonSizes[i][1];
|
|
152 |
// figure out the suitable width
|
|
153 |
for (int i = buttonSizes.length - 1; i >= 0; i--)
|
|
154 |
if (oldWidth < buttonSizes[i][0])
|
|
155 |
newWidth = buttonSizes[i][0];
|
|
159 | 156 |
|
160 |
return new Dimension(newWidth, newHeight); |
|
161 |
} |
|
157 |
// figure out the suitable height |
|
158 |
for (int i = buttonSizes.length - 1; i >= 0; i--) |
|
159 |
if (oldHeight < buttonSizes[i][1]) |
|
160 |
newHeight = buttonSizes[i][1]; |
|
162 | 161 |
|
163 |
// public void setText(String text) { |
|
164 |
// super.setText(text); |
|
165 |
// Dimension d = getUI().getMinimumSize(this); |
|
166 |
// int oldWidth = (int) d.getWidth(), newWidth = oldWidth; |
|
167 |
// int oldHeight = (int) d.getHeight(), newHeight = oldHeight; |
|
168 |
// |
|
169 |
// // figure out the suitable width |
|
170 |
// for (int i = buttonSizes.length - 1; i >= 0; i--) |
|
171 |
// if (oldWidth < buttonSizes[i][0]) |
|
172 |
// newWidth = buttonSizes[i][0]; |
|
173 |
// |
|
174 |
// // figure out the suitable height |
|
175 |
// for (int i = buttonSizes.length - 1; i >= 0; i--) |
|
176 |
// if (oldHeight < buttonSizes[i][1]) |
|
177 |
// newHeight = buttonSizes[i][1]; |
|
178 |
// |
|
179 |
// Dimension sz = new Dimension(newWidth, newHeight); |
|
180 |
// super.setSize(sz); |
|
181 |
// super.setPreferredSize(sz); |
|
182 |
// } |
|
162 |
return new Dimension(newWidth, newHeight); |
|
163 |
} |
|
183 | 164 |
|
184 |
public void setEnabled(boolean aFlag) { |
|
185 |
super.setEnabled(aFlag); |
|
186 |
if (aFlag) { |
|
187 |
setToolTipText(toolTip); |
|
188 |
} else { |
|
189 |
setToolTipText(enableText); |
|
190 |
} |
|
191 |
} |
|
165 |
// public void setText(String text) { |
|
166 |
// super.setText(text); |
|
167 |
// Dimension d = getUI().getMinimumSize(this); |
|
168 |
// int oldWidth = (int) d.getWidth(), newWidth = oldWidth; |
|
169 |
// int oldHeight = (int) d.getHeight(), newHeight = oldHeight; |
|
170 |
// |
|
171 |
// // figure out the suitable width |
|
172 |
// for (int i = buttonSizes.length - 1; i >= 0; i--) |
|
173 |
// if (oldWidth < buttonSizes[i][0]) |
|
174 |
// newWidth = buttonSizes[i][0]; |
|
175 |
// |
|
176 |
// // figure out the suitable height |
|
177 |
// for (int i = buttonSizes.length - 1; i >= 0; i--) |
|
178 |
// if (oldHeight < buttonSizes[i][1]) |
|
179 |
// newHeight = buttonSizes[i][1]; |
|
180 |
// |
|
181 |
// Dimension sz = new Dimension(newWidth, newHeight); |
|
182 |
// super.setSize(sz); |
|
183 |
// super.setPreferredSize(sz); |
|
184 |
// } |
|
192 | 185 |
|
193 |
/** |
|
194 |
* Sets the text that appears in the tooltip when the button is disabled. |
|
195 |
* |
|
196 |
* @param enableText |
|
197 |
* The enableText to set. |
|
198 |
*/ |
|
199 |
public void setEnableText(String enableText) { |
|
200 |
this.enableText = enableText; |
|
201 |
} |
|
186 |
public void setEnabled(boolean aFlag) { |
|
187 |
super.setEnabled(aFlag); |
|
188 |
if (aFlag) { |
|
189 |
setToolTipText(toolTip); |
|
190 |
} else { |
|
191 |
setToolTipText(enableText); |
|
192 |
} |
|
193 |
} |
|
202 | 194 |
|
203 |
/** |
|
204 |
* Sets the text that appears in the tooltip when the button is enabled. |
|
205 |
*/ |
|
206 |
public void setToolTip(String text) { |
|
207 |
toolTip = text; |
|
208 |
} |
|
195 |
/** |
|
196 |
* Sets the text that appears in the tooltip when the button is disabled. |
|
197 |
* |
|
198 |
* @param enableText |
|
199 |
* The enableText to set. |
|
200 |
*/ |
|
201 |
public void setEnableText(String enableText) { |
|
202 |
this.enableText = enableText; |
|
203 |
} |
|
204 |
|
|
205 |
/** |
|
206 |
* Sets the text that appears in the tooltip when the button is enabled. |
|
207 |
*/ |
|
208 |
public void setToolTip(String text) { |
|
209 |
toolTip = text; |
|
210 |
} |
|
209 | 211 |
} |
Also available in: Unified diff