Revision 168 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 | ||
---|---|---|
84 | 84 |
} |
85 | 85 |
|
86 | 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 |
} |
|
93 |
|
|
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 |
} |
|
101 |
|
|
102 |
/** |
|
87 | 103 |
* Creates a new instance of org.gvsig.gui.beans.swing.JButton containing a |
88 | 104 |
* text. |
89 | 105 |
* |
... | ... | |
107 | 123 |
} |
108 | 124 |
|
109 | 125 |
/** |
110 |
* Creates a new instance of org.gvsig.gui.beans.swing.JButton containing an |
|
111 |
* image. |
|
112 |
*/ |
|
113 |
public JStandardizedButton(Icon icon) { |
|
114 |
super(icon); |
|
115 |
} |
|
116 |
|
|
117 |
/** |
|
118 |
* Creates a new instance of org.gvsig.gui.beans.swing.JButton from an |
|
119 |
* {@link Action}. |
|
120 |
*/ |
|
121 |
public JStandardizedButton(Action action) { |
|
122 |
super(action); |
|
123 |
} |
|
124 |
|
|
125 |
/** |
|
126 | 126 |
* Gets the text that appears in the tooltip when the button is disabled. |
127 | 127 |
* |
128 | 128 |
* @return String |
... | ... | |
131 | 131 |
return enableText; |
132 | 132 |
} |
133 | 133 |
|
134 |
/** |
|
135 |
* Sets the text that appears in the tooltip when the button is disabled. |
|
136 |
* |
|
137 |
* @param enableText |
|
138 |
* The enableText to set. |
|
139 |
*/ |
|
140 |
public void setEnableText(String enableText) { |
|
141 |
this.enableText = enableText; |
|
134 |
@Override |
|
135 |
public Dimension getMaximumSize() { |
|
136 |
return getPreferredSize(); |
|
142 | 137 |
} |
143 | 138 |
|
144 |
public void setEnabled(boolean aFlag) { |
|
145 |
super.setEnabled(aFlag); |
|
146 |
if (aFlag) { |
|
147 |
setToolTipText(toolTip); |
|
148 |
} else { |
|
149 |
setToolTipText(enableText); |
|
150 |
} |
|
139 |
@Override |
|
140 |
public Dimension getMinimumSize() { |
|
141 |
return getPreferredSize(); |
|
151 | 142 |
} |
152 | 143 |
|
153 |
/** |
|
154 |
* Sets the text that appears in the tooltip when the button is enabled. |
|
155 |
*/ |
|
156 |
public void setToolTip(String text) { |
|
157 |
toolTip = text; |
|
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; |
|
149 |
|
|
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]; |
|
154 |
|
|
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]; |
|
159 |
|
|
160 |
return new Dimension(newWidth, newHeight); |
|
158 | 161 |
} |
159 | 162 |
|
160 | 163 |
// public void setText(String text) { |
... | ... | |
178 | 181 |
// super.setPreferredSize(sz); |
179 | 182 |
// } |
180 | 183 |
|
181 |
@Override |
|
182 |
public Dimension getPreferredSize() { |
|
183 |
Dimension d = getUI().getMinimumSize(this); |
|
184 |
int oldWidth = (int) d.getWidth(), newWidth = oldWidth; |
|
185 |
int oldHeight = (int) d.getHeight(), newHeight = oldHeight; |
|
186 |
|
|
187 |
// figure out the suitable width |
|
188 |
for (int i = buttonSizes.length - 1; i >= 0; i--) |
|
189 |
if (oldWidth < buttonSizes[i][0]) |
|
190 |
newWidth = buttonSizes[i][0]; |
|
191 |
|
|
192 |
// figure out the suitable height |
|
193 |
for (int i = buttonSizes.length - 1; i >= 0; i--) |
|
194 |
if (oldHeight < buttonSizes[i][1]) |
|
195 |
newHeight = buttonSizes[i][1]; |
|
196 |
|
|
197 |
return new Dimension(newWidth, newHeight); |
|
184 |
public void setEnabled(boolean aFlag) { |
|
185 |
super.setEnabled(aFlag); |
|
186 |
if (aFlag) { |
|
187 |
setToolTipText(toolTip); |
|
188 |
} else { |
|
189 |
setToolTipText(enableText); |
|
190 |
} |
|
198 | 191 |
} |
199 | 192 |
|
200 |
@Override |
|
201 |
public Dimension getMaximumSize() { |
|
202 |
return getPreferredSize(); |
|
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; |
|
203 | 201 |
} |
204 | 202 |
|
205 |
@Override |
|
206 |
public Dimension getMinimumSize() { |
|
207 |
return getPreferredSize(); |
|
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 | 208 |
} |
209 | 209 |
} |
Also available in: Unified diff