56 |
import javax.swing.JToggleButton; |
import javax.swing.JToggleButton; |
57 |
import javax.swing.JToolBar; |
import javax.swing.JToolBar; |
58 |
import javax.swing.SwingConstants; |
import javax.swing.SwingConstants; |
|
import javax.swing.UIDefaults; |
|
59 |
import javax.swing.UIManager; |
import javax.swing.UIManager; |
60 |
import javax.swing.border.AbstractBorder; |
import javax.swing.border.AbstractBorder; |
61 |
import javax.swing.border.Border; |
import javax.swing.border.Border; |
130 |
public void paintBorder(Component c, Graphics g, int x, int y, int w, |
public void paintBorder(Component c, Graphics g, int x, int y, int w, |
131 |
int h) |
int h) |
132 |
{ |
{ |
133 |
|
// With the OceanTheme the button border is painted entirely different. |
134 |
|
// However, I couldn't figure out how this is determined besides checking |
135 |
|
// for instanceof OceanTheme. The button painting is definitely not |
136 |
|
// influenced by a UI default property and it is definitely performed |
137 |
|
// by the same Border class. |
138 |
|
if (MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme) |
139 |
|
paintOceanButtonBorder(c, g, x, y, w, h); |
140 |
|
else |
141 |
|
{ |
142 |
|
ButtonModel bmodel = null; |
143 |
|
|
144 |
|
if (c instanceof AbstractButton) |
145 |
|
bmodel = ((AbstractButton) c).getModel(); |
146 |
|
|
147 |
|
Color darkShadow = MetalLookAndFeel.getControlDarkShadow(); |
148 |
|
Color shadow = MetalLookAndFeel.getControlShadow(); |
149 |
|
Color light = MetalLookAndFeel.getControlHighlight(); |
150 |
|
Color middle = MetalLookAndFeel.getControl(); |
151 |
|
|
152 |
|
if (c.isEnabled()) |
153 |
|
{ |
154 |
|
// draw dark border |
155 |
|
g.setColor(darkShadow); |
156 |
|
g.drawRect(x, y, w - 2, h - 2); |
157 |
|
|
158 |
|
if (!bmodel.isPressed()) |
159 |
|
{ |
160 |
|
// draw light border |
161 |
|
g.setColor(light); |
162 |
|
g.drawRect(x + 1, y + 1, w - 2, h - 2); |
163 |
|
|
164 |
|
// draw crossing pixels of both borders |
165 |
|
g.setColor(middle); |
166 |
|
g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2); |
167 |
|
g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1); |
168 |
|
} |
169 |
|
else |
170 |
|
{ |
171 |
|
// draw light border |
172 |
|
g.setColor(light); |
173 |
|
g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1); |
174 |
|
g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1); |
175 |
|
|
176 |
|
// draw shadow border |
177 |
|
g.setColor(middle); |
178 |
|
g.drawLine(x + 1, y + 1, x + w - 2, y + 1); |
179 |
|
g.drawLine(x + 1, y + 1, x + 1, y + h - 2); |
180 |
|
|
181 |
|
// draw crossing pixels of both borders |
182 |
|
g.setColor(shadow); |
183 |
|
g.drawRect(x + 1, y + h - 2, 0, 0); |
184 |
|
g.drawRect(x + w - 2, y + 1, 0, 0); |
185 |
|
} |
186 |
|
} |
187 |
|
else |
188 |
|
{ |
189 |
|
// draw disabled border |
190 |
|
g.setColor(MetalLookAndFeel.getInactiveControlTextColor()); |
191 |
|
g.drawRect(x, y, w - 2, h - 2); |
192 |
|
} |
193 |
|
} |
194 |
|
} |
195 |
|
|
196 |
|
/** |
197 |
|
* Paints the button border for the OceanTheme. |
198 |
|
* |
199 |
|
* @param c the button |
200 |
|
* @param g the graphics context |
201 |
|
* @param x the X coordinate of the upper left corner of the painting rect |
202 |
|
* @param y the Y coordinate of the upper left corner of the painting rect |
203 |
|
* @param w the width of the painting rect |
204 |
|
* @param h the height of the painting rect |
205 |
|
*/ |
206 |
|
private void paintOceanButtonBorder(Component c, Graphics g, int x, |
207 |
|
int y, int w, int h) |
208 |
|
{ |
209 |
ButtonModel bmodel = null; |
ButtonModel bmodel = null; |
210 |
|
|
211 |
if (c instanceof AbstractButton) |
if (c instanceof AbstractButton) |
213 |
|
|
214 |
Color darkShadow = MetalLookAndFeel.getControlDarkShadow(); |
Color darkShadow = MetalLookAndFeel.getControlDarkShadow(); |
215 |
Color shadow = MetalLookAndFeel.getControlShadow(); |
Color shadow = MetalLookAndFeel.getControlShadow(); |
216 |
Color light = MetalLookAndFeel.getWhite(); |
Color light = MetalLookAndFeel.getControlHighlight(); |
217 |
Color middle = MetalLookAndFeel.getControl(); |
Color middle = MetalLookAndFeel.getControl(); |
218 |
|
|
219 |
if (c.isEnabled()) |
if (c.isEnabled()) |
220 |
{ |
{ |
221 |
// draw dark border |
if (bmodel.isPressed()) |
222 |
g.setColor(darkShadow); |
{ |
223 |
g.drawRect(x, y, w - 2, h - 2); |
// draw fat border |
224 |
|
g.drawLine(x + 1, y + 1, x + w - 2, y + 1); |
225 |
if (!bmodel.isPressed()) |
g.drawLine(x + 1, y + 1, x + 1, y + h - 2); |
226 |
{ |
} |
227 |
// draw light border |
else if (bmodel.isRollover()) |
228 |
g.setColor(light); |
{ |
229 |
g.drawRect(x + 1, y + 1, w - 2, h - 2); |
g.setColor(shadow); |
230 |
|
g.drawRect(x, y, w - 1, h - 1); |
231 |
// draw crossing pixels of both borders |
g.drawRect(x + 2, y + 2, w - 5, h - 5); |
232 |
g.setColor(middle); |
g.setColor(darkShadow); |
233 |
g.drawRect(x + 1, y + h - 2, 0, 0); |
g.drawRect(x + 1, y + 1, w - 3, h - 3); |
234 |
g.drawRect(x + w - 2, y + 1, 0, 0); |
} |
235 |
} |
else |
236 |
else |
{ |
237 |
{ |
g.setColor(darkShadow); |
238 |
// draw light border |
g.drawRect(x, y, w - 1, h - 1); |
239 |
g.setColor(light); |
} |
240 |
g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1); |
} |
|
g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1); |
|
|
|
|
|
// draw shadow border |
|
|
g.setColor(middle); |
|
|
g.drawLine(x + 1, y + 1, x + w - 2, y + 1); |
|
|
g.drawLine(x + 1, y + 1, x + 1, y + h - 2); |
|
|
|
|
|
// draw crossing pixels of both borders |
|
|
g.setColor(shadow); |
|
|
g.drawRect(x + 1, y + h - 2, 0, 0); |
|
|
g.drawRect(x + w - 2, y + 1, 0, 0); |
|
|
} |
|
|
} |
|
241 |
else |
else |
242 |
{ |
{ |
243 |
// draw disabled border |
// draw disabled border |
716 |
{ |
{ |
717 |
JOptionPane pane = (JOptionPane) f.getContentPane(); |
JOptionPane pane = (JOptionPane) f.getContentPane(); |
718 |
int type = pane.getMessageType(); |
int type = pane.getMessageType(); |
|
UIDefaults defaults = UIManager.getLookAndFeelDefaults(); |
|
719 |
if (type == JOptionPane.QUESTION_MESSAGE) |
if (type == JOptionPane.QUESTION_MESSAGE) |
720 |
{ |
{ |
721 |
Color bc = defaults.getColor( |
Color bc = UIManager.getColor( |
722 |
"OptionPane.questionDialog.border.background"); |
"OptionPane.questionDialog.border.background"); |
723 |
if (bc != null) |
if (bc != null) |
724 |
g.setColor(bc); |
g.setColor(bc); |
725 |
} |
} |
726 |
if (type == JOptionPane.WARNING_MESSAGE) |
if (type == JOptionPane.WARNING_MESSAGE) |
727 |
{ |
{ |
728 |
Color bc = defaults.getColor( |
Color bc = UIManager.getColor( |
729 |
"OptionPane.warningDialog.border.background"); |
"OptionPane.warningDialog.border.background"); |
730 |
if (bc != null) |
if (bc != null) |
731 |
g.setColor(bc); |
g.setColor(bc); |
732 |
} |
} |
733 |
else if (type == JOptionPane.ERROR_MESSAGE) |
else if (type == JOptionPane.ERROR_MESSAGE) |
734 |
{ |
{ |
735 |
Color bc = defaults.getColor( |
Color bc = UIManager.getColor( |
736 |
"OptionPane.errorDialog.border.background"); |
"OptionPane.errorDialog.border.background"); |
737 |
if (bc != null) |
if (bc != null) |
738 |
g.setColor(bc); |
g.setColor(bc); |