Java Reference
In-Depth Information
Example 10•28: ThemeManager.java (continued)
else controlFont = defaultTheme.getControlTextFont();
if (menu != null) menuFont = new FontUIResource(menu);
else menuFont = defaultTheme.getMenuTextFont();
if (small != null) smallFont = new FontUIResource(small);
else smallFont = defaultTheme.getSubTextFont();
if (system != null) systemFont = new FontUIResource(system);
else systemFont = defaultTheme.getSystemTextFont();
if (user != null) userFont = new FontUIResource(user);
else userFont = defaultTheme.getUserTextFont();
if (title != null) titleFont = new FontUIResource(title);
else titleFont = defaultTheme.getWindowTitleFont();
// Look up primary and secondary colors
Color primary = resources.getColor(name + ".primary", null);
Color secondary = resources.getColor(name + ".secondary", null);
// Derive all six colors from these two, using defaults if needed
if (primary != null) primary1 = new ColorUIResource(primary);
else primary1 = new ColorUIResource(102, 102, 153);
primary2 = new ColorUIResource(primary1.brighter());
primary3 = new ColorUIResource(primary2.brighter());
if (secondary != null) secondary1 = new ColorUIResource(secondary);
else secondary1 = new ColorUIResource(102, 102, 102);
secondary2 = new ColorUIResource(secondary1.brighter());
secondary3 = new ColorUIResource(secondary2.brighter());
}
// These methods override DefaultMetalTheme and return the property
// values we looked up and computed for this theme
public String getName() { return displayName; }
public FontUIResource getControlTextFont() { return controlFont;}
public FontUIResource getSystemTextFont() { return systemFont;}
public FontUIResource getUserTextFont() { return userFont;}
public FontUIResource getMenuTextFont() { return menuFont;}
public FontUIResource getWindowTitleFont() { return titleFont;}
public FontUIResource getSubTextFont() { return smallFont;}
protected ColorUIResource getPrimary1() { return primary1; }
protected ColorUIResource getPrimary2() { return primary2; }
protected ColorUIResource getPrimary3() { return primary3; }
protected ColorUIResource getSecondary1() { return secondary1; }
protected ColorUIResource getSecondary2() { return secondary2; }
protected ColorUIResource getSecondary3() { return secondary3; }
}
}
Custom Components
Most examples in this chapter have been subclasses of JFrame , JPanel , or some
other Swing component. In this sense, they have all been “custom components.”
The ItemChooser class is a particularly useful example of this kind of component.
Most of these examples, however, have not handled their own low-level mouse
and keyboard events or done their own drawing; they've relied on superclasses to
handle low-level events and subcomponents to provide a visual appearance.
There is another kind of lower-level custom component, though; one that provides
its own “look” by drawing itself with a Graphics object and its own “feel” by
Search WWH ::




Custom Search