2658
|
1 |
/*
|
|
2 |
* Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
package javax.swing.plaf.nimbus;
|
|
26 |
|
|
27 |
import java.awt.BorderLayout;
|
|
28 |
import static java.awt.BorderLayout.*;
|
|
29 |
import javax.swing.JComponent;
|
|
30 |
import javax.swing.UIDefaults;
|
|
31 |
import javax.swing.UIManager;
|
|
32 |
import javax.swing.plaf.synth.Region;
|
|
33 |
import javax.swing.plaf.synth.SynthLookAndFeel;
|
|
34 |
import javax.swing.plaf.synth.SynthStyle;
|
|
35 |
import javax.swing.plaf.synth.SynthStyleFactory;
|
|
36 |
import javax.swing.plaf.UIResource;
|
|
37 |
import java.security.AccessController;
|
|
38 |
import java.awt.Color;
|
|
39 |
import java.awt.Container;
|
|
40 |
import java.awt.Graphics2D;
|
|
41 |
import java.awt.LayoutManager;
|
|
42 |
import java.awt.image.BufferedImage;
|
|
43 |
import javax.swing.GrayFilter;
|
|
44 |
import javax.swing.Icon;
|
|
45 |
import javax.swing.JToolBar;
|
|
46 |
import javax.swing.border.TitledBorder;
|
|
47 |
import javax.swing.plaf.BorderUIResource;
|
|
48 |
import javax.swing.plaf.ColorUIResource;
|
|
49 |
import sun.swing.ImageIconUIResource;
|
|
50 |
import sun.swing.plaf.synth.SynthIcon;
|
|
51 |
import sun.swing.plaf.GTKKeybindings;
|
|
52 |
import sun.swing.plaf.WindowsKeybindings;
|
|
53 |
import sun.security.action.GetPropertyAction;
|
|
54 |
|
|
55 |
/**
|
|
56 |
* <p>The NimbusLookAndFeel class.</p>
|
|
57 |
*
|
|
58 |
* @author Jasper Potts
|
|
59 |
* @author Richard Bair
|
|
60 |
*/
|
|
61 |
public class NimbusLookAndFeel extends SynthLookAndFeel {
|
|
62 |
|
|
63 |
/** Set of standard region names for UIDefaults Keys */
|
|
64 |
private static final String[] COMPONENT_KEYS = new String[]{"ArrowButton", "Button",
|
|
65 |
"CheckBox", "CheckBoxMenuItem", "ColorChooser", "ComboBox",
|
|
66 |
"DesktopPane", "DesktopIcon", "EditorPane", "FileChooser",
|
|
67 |
"FormattedTextField", "InternalFrame",
|
|
68 |
"InternalFrameTitlePane", "Label", "List", "Menu",
|
|
69 |
"MenuBar", "MenuItem", "OptionPane", "Panel",
|
|
70 |
"PasswordField", "PopupMenu", "PopupMenuSeparator",
|
|
71 |
"ProgressBar", "RadioButton", "RadioButtonMenuItem",
|
|
72 |
"RootPane", "ScrollBar", "ScrollBarTrack", "ScrollBarThumb",
|
|
73 |
"ScrollPane", "Separator", "Slider", "SliderTrack",
|
|
74 |
"SliderThumb", "Spinner", "SplitPane", "TabbedPane",
|
|
75 |
"Table", "TableHeader", "TextArea", "TextField", "TextPane",
|
|
76 |
"ToggleButton", "ToolBar", "ToolTip", "Tree", "Viewport"};
|
|
77 |
|
|
78 |
/**
|
|
79 |
* A reference to the auto-generated file NimbusDefaults. This file contains
|
|
80 |
* the default mappings and values for the look and feel as specified in the
|
|
81 |
* visual designer.
|
|
82 |
*/
|
|
83 |
private NimbusDefaults defaults;
|
|
84 |
|
|
85 |
/**
|
|
86 |
* Reference to populated LAD uidefaults
|
|
87 |
*/
|
|
88 |
private UIDefaults uiDefaults;
|
|
89 |
|
|
90 |
/**
|
|
91 |
* Create a new NimbusLookAndFeel.
|
|
92 |
*/
|
|
93 |
public NimbusLookAndFeel() {
|
|
94 |
super();
|
|
95 |
defaults = new NimbusDefaults();
|
|
96 |
}
|
|
97 |
|
|
98 |
/** Called by UIManager when this look and feel is installed. */
|
|
99 |
@Override public void initialize() {
|
|
100 |
super.initialize();
|
|
101 |
defaults.initialize();
|
|
102 |
// create synth style factory
|
|
103 |
setStyleFactory(new SynthStyleFactory() {
|
|
104 |
@Override
|
|
105 |
public SynthStyle getStyle(JComponent c, Region r) {
|
|
106 |
return defaults.getStyle(c, r);
|
|
107 |
}
|
|
108 |
});
|
|
109 |
}
|
|
110 |
|
|
111 |
|
|
112 |
/** Called by UIManager when this look and feel is uninstalled. */
|
|
113 |
@Override public void uninitialize() {
|
|
114 |
super.uninitialize();
|
|
115 |
defaults.uninitialize();
|
|
116 |
// clear all cached images to free memory
|
|
117 |
ImageCache.getInstance().flush();
|
|
118 |
// remove the listeners and things installed by NimbusStyle
|
|
119 |
NimbusStyle.uninitialize();
|
|
120 |
}
|
|
121 |
|
|
122 |
/**
|
|
123 |
* @inheritDoc
|
|
124 |
*/
|
|
125 |
@Override public UIDefaults getDefaults() {
|
|
126 |
if (uiDefaults == null){
|
|
127 |
// Detect platform
|
|
128 |
String osName = getSystemProperty("os.name");
|
|
129 |
boolean isWindows = osName != null && osName.contains("Windows");
|
|
130 |
|
|
131 |
// We need to call super for basic's properties file.
|
|
132 |
uiDefaults = super.getDefaults();
|
|
133 |
defaults.initializeDefaults(uiDefaults);
|
|
134 |
|
|
135 |
// Install Keybindings
|
|
136 |
if (isWindows) {
|
|
137 |
WindowsKeybindings.installKeybindings(uiDefaults);
|
|
138 |
} else {
|
|
139 |
GTKKeybindings.installKeybindings(uiDefaults);
|
|
140 |
}
|
|
141 |
|
|
142 |
// Add Titled Border
|
|
143 |
uiDefaults.put("TitledBorder.titlePosition",
|
|
144 |
TitledBorder.ABOVE_TOP);
|
|
145 |
uiDefaults.put("TitledBorder.border", new BorderUIResource(
|
|
146 |
new LoweredBorder()));
|
|
147 |
uiDefaults.put("TitledBorder.titleColor",
|
|
148 |
getDerivedColor("text",0.0f,0.0f,0.23f,0,true));
|
|
149 |
uiDefaults.put("TitledBorder.font",
|
|
150 |
new NimbusDefaults.DerivedFont("defaultFont",
|
|
151 |
1f, true, null));
|
|
152 |
|
|
153 |
// Choose Dialog button positions
|
|
154 |
uiDefaults.put("OptionPane.isYesLast", !isWindows);
|
|
155 |
|
|
156 |
// Store Table ScrollPane Corner Component
|
|
157 |
uiDefaults.put("Table.scrollPaneCornerComponent",
|
|
158 |
TableScrollPaneCorner.class);
|
|
159 |
|
|
160 |
// Setup the settings for ToolBarSeparator which is custom
|
|
161 |
// installed for Nimbus
|
|
162 |
uiDefaults.put("ToolBarSeparator[Enabled].backgroundPainter",
|
|
163 |
new ToolBarSeparatorPainter());
|
|
164 |
|
|
165 |
// Populate UIDefaults with a standard set of properties
|
|
166 |
for (String componentKey : COMPONENT_KEYS) {
|
|
167 |
String key = componentKey+".foreground";
|
|
168 |
if (!uiDefaults.containsKey(key)){
|
|
169 |
uiDefaults.put(key,
|
|
170 |
new NimbusProperty(componentKey,"textForeground"));
|
|
171 |
}
|
|
172 |
key = componentKey+".background";
|
|
173 |
if (!uiDefaults.containsKey(key)){
|
|
174 |
uiDefaults.put(key,
|
|
175 |
new NimbusProperty(componentKey,"background"));
|
|
176 |
}
|
|
177 |
key = componentKey+".font";
|
|
178 |
if (!uiDefaults.containsKey(key)){
|
|
179 |
uiDefaults.put(key,
|
|
180 |
new NimbusProperty(componentKey,"font"));
|
|
181 |
}
|
|
182 |
key = componentKey+".disabledText";
|
|
183 |
if (!uiDefaults.containsKey(key)){
|
|
184 |
uiDefaults.put(key,
|
|
185 |
new NimbusProperty(componentKey,"Disabled",
|
|
186 |
"textForeground"));
|
|
187 |
}
|
|
188 |
key = componentKey+".disabled";
|
|
189 |
if (!uiDefaults.containsKey(key)){
|
|
190 |
uiDefaults.put(key,
|
|
191 |
new NimbusProperty(componentKey,"Disabled",
|
|
192 |
"background"));
|
|
193 |
}
|
|
194 |
}
|
|
195 |
|
|
196 |
// FileView icon keys are used by some applications, we don't have
|
|
197 |
// a computer icon at the moment so using home icon for now
|
|
198 |
uiDefaults.put("FileView.computerIcon",
|
|
199 |
new LinkProperty("FileChooser.homeFolderIcon"));
|
|
200 |
uiDefaults.put("FileView.directoryIcon",
|
|
201 |
new LinkProperty("FileChooser.directoryIcon"));
|
|
202 |
uiDefaults.put("FileView.fileIcon",
|
|
203 |
new LinkProperty("FileChooser.fileIcon"));
|
|
204 |
uiDefaults.put("FileView.floppyDriveIcon",
|
|
205 |
new LinkProperty("FileChooser.floppyDriveIcon"));
|
|
206 |
uiDefaults.put("FileView.hardDriveIcon",
|
|
207 |
new LinkProperty("FileChooser.hardDriveIcon"));
|
|
208 |
}
|
|
209 |
return uiDefaults;
|
|
210 |
}
|
|
211 |
|
|
212 |
/**
|
|
213 |
* Gets the style associated with the given component and region. This
|
|
214 |
* will never return null. If an appropriate component and region cannot
|
|
215 |
* be determined, then a default style is returned.
|
|
216 |
*
|
|
217 |
* @param c a non-null reference to a JComponent
|
|
218 |
* @param r a non-null reference to the region of the component c
|
|
219 |
* @return a non-null reference to a NimbusStyle.
|
|
220 |
*/
|
|
221 |
public static NimbusStyle getStyle(JComponent c, Region r) {
|
|
222 |
return (NimbusStyle)SynthLookAndFeel.getStyle(c, r);
|
|
223 |
}
|
|
224 |
|
|
225 |
/**
|
|
226 |
* Return a short string that identifies this look and feel. This
|
|
227 |
* String will be the unquoted String "Nimbus".
|
|
228 |
*
|
|
229 |
* @return a short string identifying this look and feel.
|
|
230 |
*/
|
|
231 |
@Override public String getName() {
|
|
232 |
return "Nimbus";
|
|
233 |
}
|
|
234 |
|
|
235 |
/**
|
|
236 |
* Return a string that identifies this look and feel. This String will
|
|
237 |
* be the unquoted String "Nimbus".
|
|
238 |
*
|
|
239 |
* @return a short string identifying this look and feel.
|
|
240 |
*/
|
|
241 |
@Override public String getID() {
|
|
242 |
return "Nimbus";
|
|
243 |
}
|
|
244 |
|
|
245 |
/**
|
|
246 |
* Returns a textual description of this look and feel.
|
|
247 |
*
|
|
248 |
* @return textual description of this look and feel.
|
|
249 |
*/
|
|
250 |
@Override public String getDescription() {
|
|
251 |
return "Nimbus Look and Feel";
|
|
252 |
}
|
|
253 |
|
|
254 |
/**
|
|
255 |
* @inheritDoc
|
|
256 |
* @return true
|
|
257 |
*/
|
|
258 |
@Override public boolean shouldUpdateStyleOnAncestorChanged() {
|
|
259 |
return true;
|
|
260 |
}
|
|
261 |
|
|
262 |
/**
|
|
263 |
* <p>Registers a third party component with the NimbusLookAndFeel.</p>
|
|
264 |
*
|
|
265 |
* <p>Regions represent Components and areas within Components that act as
|
|
266 |
* independent painting areas. Once registered with the NimbusLookAndFeel,
|
|
267 |
* NimbusStyles for these Regions can be retrieved via the
|
|
268 |
* <code>getStyle</code> method.</p>
|
|
269 |
*
|
|
270 |
* <p>The NimbusLookAndFeel uses a standard naming scheme for entries in the
|
|
271 |
* UIDefaults table. The key for each property, state, painter, and other
|
|
272 |
* default registered in UIDefaults for a specific Region will begin with
|
|
273 |
* the specified <code>prefix</code></p>
|
|
274 |
*
|
|
275 |
* <p>For example, suppose I had a component named JFoo. Suppose I then registered
|
|
276 |
* this component with the NimbusLookAndFeel in this manner:</p>
|
|
277 |
*
|
|
278 |
* <pre><code>
|
|
279 |
* laf.register(NimbusFooUI.FOO_REGION, "Foo");
|
|
280 |
* </code></pre>
|
|
281 |
*
|
|
282 |
* <p>In this case, I could then register properties for this component with
|
|
283 |
* UIDefaults in the following manner:</p>
|
|
284 |
*
|
|
285 |
* <pre><code>
|
|
286 |
* UIManager.put("Foo.background", new ColorUIResource(Color.BLACK));
|
|
287 |
* UIManager.put("Foo.Enabled.backgroundPainter", new FooBackgroundPainter());
|
|
288 |
* </code></pre>
|
|
289 |
*
|
|
290 |
* <p>It is also possible to register a named component with Nimbus.
|
|
291 |
* For example, suppose you wanted to style the background of a JPanel
|
|
292 |
* named "MyPanel" differently from other JPanels. You could accomplish this
|
|
293 |
* by doing the following:</p>
|
|
294 |
*
|
|
295 |
* <pre><code>
|
|
296 |
* laf.register(Region.PANEL, "\"MyPanel\"");
|
|
297 |
* UIManager.put("\"MyPanel\".background", new ColorUIResource(Color.RED));
|
|
298 |
* </code></pre>
|
|
299 |
*
|
|
300 |
* @param region The Synth Region that is being registered. Such as Button, or
|
|
301 |
* ScrollBarThumb, or NimbusFooUI.FOO_REGION.
|
|
302 |
* @param prefix The UIDefault prefix. For example, could be ComboBox, or if
|
|
303 |
* a named components, "MyComboBox", or even something like
|
|
304 |
* ToolBar."MyComboBox"."ComboBox.arrowButton"
|
|
305 |
*/
|
|
306 |
public void register(Region region, String prefix) {
|
|
307 |
defaults.register(region, prefix);
|
|
308 |
}
|
|
309 |
|
|
310 |
/**
|
|
311 |
* Simple utility method that reads system keys.
|
|
312 |
*/
|
|
313 |
private String getSystemProperty(String key) {
|
|
314 |
return AccessController.doPrivileged(new GetPropertyAction(key));
|
|
315 |
}
|
|
316 |
|
|
317 |
@Override
|
|
318 |
public Icon getDisabledIcon(JComponent component, Icon icon) {
|
|
319 |
if (icon instanceof SynthIcon) {
|
|
320 |
SynthIcon si = (SynthIcon)icon;
|
|
321 |
BufferedImage img = EffectUtils.createCompatibleTranslucentImage(
|
|
322 |
si.getIconWidth(), si.getIconHeight());
|
|
323 |
Graphics2D gfx = img.createGraphics();
|
|
324 |
si.paintIcon(component, gfx, 0, 0);
|
|
325 |
gfx.dispose();
|
|
326 |
return new ImageIconUIResource(GrayFilter.createDisabledImage(img));
|
|
327 |
} else {
|
|
328 |
return super.getDisabledIcon(component, icon);
|
|
329 |
}
|
|
330 |
}
|
|
331 |
|
|
332 |
/**
|
|
333 |
* Get a derived color, derived colors are shared instances and is color
|
|
334 |
* value will change when its parent UIDefault color changes.
|
|
335 |
*
|
|
336 |
* @param uiDefaultParentName The parent UIDefault key
|
|
337 |
* @param hOffset The hue offset
|
|
338 |
* @param sOffset The saturation offset
|
|
339 |
* @param bOffset The brightness offset
|
|
340 |
* @param aOffset The alpha offset
|
|
341 |
* @param uiResource True if the derived color should be a
|
|
342 |
* UIResource, false if it should not be
|
|
343 |
* @return The stored derived color
|
|
344 |
*/
|
|
345 |
public Color getDerivedColor(String uiDefaultParentName,
|
|
346 |
float hOffset, float sOffset,
|
|
347 |
float bOffset, int aOffset,
|
|
348 |
boolean uiResource) {
|
|
349 |
return defaults.getDerivedColor(uiDefaultParentName, hOffset, sOffset,
|
|
350 |
bOffset, aOffset, uiResource);
|
|
351 |
}
|
|
352 |
|
|
353 |
/**
|
|
354 |
* Decodes and returns a color, which is derived from an offset between two
|
|
355 |
* other colors.
|
|
356 |
*
|
|
357 |
* @param color1 The first color
|
|
358 |
* @param color2 The second color
|
|
359 |
* @param midPoint The offset between color 1 and color 2, a value of 0.0 is
|
|
360 |
* color 1 and 1.0 is color 2;
|
|
361 |
* @param uiResource True if the derived color should be a UIResource
|
|
362 |
* @return The derived color
|
|
363 |
*/
|
|
364 |
protected final Color getDerivedColor(Color color1, Color color2,
|
|
365 |
float midPoint, boolean uiResource) {
|
|
366 |
int argb = deriveARGB(color1, color2, midPoint);
|
|
367 |
if (uiResource) {
|
|
368 |
return new ColorUIResource(argb);
|
|
369 |
} else {
|
|
370 |
return new Color(argb);
|
|
371 |
}
|
|
372 |
}
|
|
373 |
|
|
374 |
/**
|
|
375 |
* Decodes and returns a color, which is derived from a offset between two
|
|
376 |
* other colors.
|
|
377 |
*
|
|
378 |
* @param color1 The first color
|
|
379 |
* @param color2 The second color
|
|
380 |
* @param midPoint The offset between color 1 and color 2, a value of 0.0 is
|
|
381 |
* color 1 and 1.0 is color 2;
|
|
382 |
* @return The derived color, which will be a UIResource
|
|
383 |
*/
|
|
384 |
protected final Color getDerivedColor(Color color1, Color color2,
|
|
385 |
float midPoint) {
|
|
386 |
return getDerivedColor(color1, color2, midPoint, true);
|
|
387 |
}
|
|
388 |
|
|
389 |
/**
|
|
390 |
* Package private method which returns either BorderLayout.NORTH,
|
|
391 |
* BorderLayout.SOUTH, BorderLayout.EAST, or BorderLayout.WEST depending
|
|
392 |
* on the location of the toolbar in its parent. The toolbar might be
|
|
393 |
* in PAGE_START, PAGE_END, CENTER, or some other position, but will be
|
|
394 |
* resolved to either NORTH,SOUTH,EAST, or WEST based on where the toolbar
|
|
395 |
* actually IS, with CENTER being NORTH.
|
|
396 |
*
|
|
397 |
* This code is used to determine where the border line should be drawn
|
|
398 |
* by the custom toolbar states, and also used by NimbusIcon to determine
|
|
399 |
* whether the handle icon needs to be shifted to look correct.
|
|
400 |
*
|
|
401 |
* Toollbars are unfortunately odd in the way these things are handled,
|
|
402 |
* and so this code exists to unify the logic related to toolbars so it can
|
|
403 |
* be shared among the static files such as NimbusIcon and generated files
|
|
404 |
* such as the ToolBar state classes.
|
|
405 |
*/
|
|
406 |
static Object resolveToolbarConstraint(JToolBar toolbar) {
|
|
407 |
//NOTE: we don't worry about component orientation or PAGE_END etc
|
|
408 |
//because the BasicToolBarUI always uses an absolute position of
|
|
409 |
//NORTH/SOUTH/EAST/WEST.
|
|
410 |
if (toolbar != null) {
|
|
411 |
Container parent = toolbar.getParent();
|
|
412 |
if (parent != null) {
|
|
413 |
LayoutManager m = parent.getLayout();
|
|
414 |
if (m instanceof BorderLayout) {
|
|
415 |
BorderLayout b = (BorderLayout)m;
|
|
416 |
Object con = b.getConstraints(toolbar);
|
|
417 |
if (con == SOUTH || con == EAST || con == WEST) {
|
|
418 |
return con;
|
|
419 |
}
|
|
420 |
return NORTH;
|
|
421 |
}
|
|
422 |
}
|
|
423 |
}
|
|
424 |
return NORTH;
|
|
425 |
}
|
|
426 |
|
|
427 |
/**
|
|
428 |
* Derives the ARGB value for a color based on an offset between two
|
|
429 |
* other colors.
|
|
430 |
*
|
|
431 |
* @param color1 The first color
|
|
432 |
* @param color2 The second color
|
|
433 |
* @param midPoint The offset between color 1 and color 2, a value of 0.0 is
|
|
434 |
* color 1 and 1.0 is color 2;
|
|
435 |
* @return the ARGB value for a new color based on this derivation
|
|
436 |
*/
|
|
437 |
static int deriveARGB(Color color1, Color color2, float midPoint) {
|
|
438 |
int r = color1.getRed() +
|
|
439 |
(int) ((color2.getRed() - color1.getRed()) * midPoint + 0.5f);
|
|
440 |
int g = color1.getGreen() +
|
|
441 |
(int) ((color2.getGreen() - color1.getGreen()) * midPoint +
|
|
442 |
0.5f);
|
|
443 |
int b = color1.getBlue() +
|
|
444 |
(int) ((color2.getBlue() - color1.getBlue()) * midPoint + 0.5f);
|
|
445 |
int a = color1.getAlpha() +
|
|
446 |
(int) ((color2.getAlpha() - color1.getAlpha()) * midPoint +
|
|
447 |
0.5f);
|
|
448 |
return ((a & 0xFF) << 24) |
|
|
449 |
((r & 0xFF) << 16) |
|
|
450 |
((g & 0xFF) << 8) |
|
|
451 |
(b & 0xFF);
|
|
452 |
}
|
|
453 |
|
|
454 |
/**
|
|
455 |
* Simple Symbolic Link style UIDefalts Property
|
|
456 |
*/
|
|
457 |
private class LinkProperty implements UIDefaults.ActiveValue, UIResource{
|
|
458 |
private String dstPropName;
|
|
459 |
|
|
460 |
private LinkProperty(String dstPropName) {
|
|
461 |
this.dstPropName = dstPropName;
|
|
462 |
}
|
|
463 |
|
|
464 |
@Override
|
|
465 |
public Object createValue(UIDefaults table) {
|
|
466 |
return UIManager.get(dstPropName);
|
|
467 |
}
|
|
468 |
}
|
|
469 |
|
|
470 |
/**
|
|
471 |
* Nimbus Property that looks up Nimbus keys for standard key names. For
|
|
472 |
* example "Button.background" --> "Button[Enabled].backgound"
|
|
473 |
*/
|
|
474 |
private class NimbusProperty implements UIDefaults.ActiveValue, UIResource {
|
|
475 |
private String prefix;
|
|
476 |
private String state = null;
|
|
477 |
private String suffix;
|
|
478 |
private boolean isFont;
|
|
479 |
|
|
480 |
private NimbusProperty(String prefix, String suffix) {
|
|
481 |
this.prefix = prefix;
|
|
482 |
this.suffix = suffix;
|
|
483 |
isFont = "font".equals(suffix);
|
|
484 |
}
|
|
485 |
|
|
486 |
private NimbusProperty(String prefix, String state, String suffix) {
|
|
487 |
this(prefix,suffix);
|
|
488 |
this.state = state;
|
|
489 |
}
|
|
490 |
|
|
491 |
/**
|
|
492 |
* Creates the value retrieved from the <code>UIDefaults</code> table.
|
|
493 |
* The object is created each time it is accessed.
|
|
494 |
*
|
|
495 |
* @param table a <code>UIDefaults</code> table
|
|
496 |
* @return the created <code>Object</code>
|
|
497 |
*/
|
|
498 |
@Override
|
|
499 |
public Object createValue(UIDefaults table) {
|
|
500 |
Object obj = null;
|
|
501 |
// check specified state
|
|
502 |
if (state!=null){
|
|
503 |
obj = uiDefaults.get(prefix+"["+state+"]."+suffix);
|
|
504 |
}
|
|
505 |
// check enabled state
|
|
506 |
if (obj==null){
|
|
507 |
obj = uiDefaults.get(prefix+"[Enabled]."+suffix);
|
|
508 |
}
|
|
509 |
// check for defaults
|
|
510 |
if (obj==null){
|
|
511 |
if (isFont) {
|
|
512 |
obj = uiDefaults.get("defaultFont");
|
|
513 |
} else {
|
|
514 |
obj = uiDefaults.get(suffix);
|
|
515 |
}
|
|
516 |
}
|
|
517 |
return obj;
|
|
518 |
}
|
|
519 |
}
|
|
520 |
}
|