/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package ${PACKAGE};
/**
* This class contains all the implementation details related to
* ${LAF_NAME}. It contains all the code for initializing the UIDefaults table,
* as well as for selecting
* a SynthStyle based on a JComponent/Region pair.
*
* @author Richard Bair
*/
/**
* The map of SynthStyles. This map is keyed by Region. Each Region maps
* to a List of LazyStyles. Each LazyStyle has a reference to the prefix
* that was registered with it. This reference can then be inspected to see
* if it is the proper lazy style.
* <p/>
* There can be more than one LazyStyle for a single Region if there is more
* than one prefix defined for a given region. For example, both Button and
* "MyButton" might be prefixes assigned to the Region.Button region.
*/
/**
* A map of regions which have been registered.
* This mapping is maintained so that the Region can be found based on
* prefix in a very fast manner. This is used in the "matches" method of
* LazyStyle.
*/
/**
* Our fallback style to avoid NPEs if the proper style cannot be found in
* this class. Not sure if relying on DefaultSynthStyle is the best choice.
*/
private DefaultSynthStyle defaultStyle;
/**
* The default font that will be used. I store this value so that it can be
* set in the UIDefaults when requested.
*/
private FontUIResource defaultFont;
/** Listener for changes to user defaults table */
/** Called by UIManager when this look and feel is installed. */
void initialize() {
// add listener for derived colors
}
/** Called by UIManager when this look and feel is uninstalled. */
void uninitialize() {
// remove listener for derived colors
}
/**
* Create a new ${LAF_NAME}Defaults. This constructor is only called from
* within ${LAF_NAME}LookAndFeel.
*/
//Create the default font and default style. Also register all of the
//regions and their states that this class will use for later lookup.
//Additional regions can be registered later by 3rd party components.
//These are simply the default registrations.
defaultStyle = new DefaultSynthStyle();
//initialize the map of styles
${STYLE_INIT}
}
//--------------- Methods called by ${LAF_NAME}LookAndFeel
/**
* Called from ${LAF_NAME}LookAndFeel to initialize the UIDefaults.
*
* @param d UIDefaults table to initialize. This will never be null.
* If listeners are attached to <code>d</code>, then you will
* only receive notification of LookAndFeel level defaults, not
* all defaults on the UIManager.
*/
void initializeDefaults(UIDefaults d) {
}
/**
* <p>Registers the given region and prefix. The prefix, if it contains
* quoted sections, refers to certain named components. If there are not
* quoted sections, then the prefix refers to a generic component type.</p>
*
* it will not be registered twice. The second registration attempt will
* fail silently.</p>
*
* @param region The Synth Region that is being registered. Such as Button,
* or ScrollBarThumb.
* @param prefix The UIDefault prefix. For example, could be ComboBox, or if
* a named components, "MyComboBox", or even something like
* ToolBar:"MyComboBox":"ComboBox.arrowButton"
*/
//validate the method arguments
throw new IllegalArgumentException(
"Neither Region nor Prefix may be null");
}
} else {
//iterate over all the current styles and see if this prefix has
//already been registered. If not, then register it.
return;
}
}
}
//add this region to the map of registered regions
}
/**
* <p>Locate the style associated with the given region, and component.
* This is called from ${LAF_NAME}LookAndFeel in the SynthStyleFactory
* implementation.</p>
*
* <p>Lookup occurs as follows:<br/>
* Check the map of styles <code>m</code>. If the map contains no styles at
* all, then simply return the defaultStyle. If the map contains styles,
* then iterate over all of the styles for the Region <code>r</code> looking
* for the best match, based on prefix. If a match was made, then return
* that SynthStyle. Otherwise, return the defaultStyle.</p>
*
* @param comp The component associated with this region. For example, if
* the Region is Region.Button then the component will be a JButton.
* If the Region is a subregion, such as ScrollBarThumb, then the
* associated component will be the component that subregion belongs
* to, such as JScrollBar. The JComponent may be named. It may not be
* null.
* @param r The region we are looking for a style for. May not be null.
*/
//validate method arguments
throw new IllegalArgumentException(
"Neither comp nor r may be null");
}
//if there are no lazy styles registered for the region r, then return
//the default style
return defaultStyle;
}
//replace the foundStyle if foundStyle is null, or
//if the new style "s" is more specific (ie, its path was
//longer), or if the foundStyle was "simple" and the new style
//was not (ie: the foundStyle was for something like Button and
//the new style was for something like "MyButton", hence, being
//more specific.) In all cases, favor the most specific style
//found.
if (foundStyle == null ||
foundStyle = s;
}
}
}
//return the style, if found, or the default style if not found
}
public void clearOverridesCache(JComponent c) {
overridesCache.remove(c);
}
/*
Various public helper classes.
These may be used to register 3rd party values into UIDefaults
*/
/**
* <p>Derives its font value based on a parent font and a set of offsets and
* attributes. This class is an ActiveValue, meaning that it will recompute
* its value each time it is requested from UIDefaults. It is therefore
* recommended to read this value once and cache it in the UI delegate class
* until asked to reinitialize.</p>
*
* <p>To use this class, create an instance with the key of the font in the
* UI defaults table from which to derive this font, along with a size
* offset (if any), and whether it is to be bold, italic, or left in its
* default form.</p>
*/
private float sizeOffset;
/**
* Create a new DerivedFont.
*
* @param key The UIDefault key associated with this derived font's
* parent or source. If this key leads to a null value, or a
* value that is not a font, then null will be returned as
* the derived font. The key must not be null.
* @param sizeOffset The size offset, as a percentage, to use. For
* example, if the source font was a 12pt font and the
* sizeOffset were specified as .9, then the new font
* will be 90% of what the source font was, or, 10.8
* pts which is rounded to 11pts. This fractional
* based offset allows for proper font scaling in high
* DPI or large system font scenarios.
* @param bold Whether the new font should be bold. If null, then this
* new font will inherit the bold setting of the source
* font.
* @param italic Whether the new font should be italicized. If null,
* then this new font will inherit the italic setting of
* the source font.
*/
//validate the constructor arguments
throw new IllegalArgumentException("You must specify a key");
}
//set the values
this.sizeOffset = sizeOffset;
}
/**
* @inheritDoc
*/
if (f != null) {
// always round size for now so we have exact int font size
// (or we may have lame looking fonts)
if (bold.booleanValue()) {
} else {
}
}
if (italic.booleanValue()) {
} else {
}
}
} else {
return null;
}
}
}
/**
* This class is private because it relies on the constructor of the
* auto-generated AbstractRegionPainter subclasses. Hence, it is not
* generally useful, and is private.
* <p/>
* LazyPainter is a LazyValue class. It will create the
* AbstractRegionPainter lazily, when asked. It uses reflection to load the
* proper class and invoke its constructor.
*/
private int which;
throw new IllegalArgumentException(
"The className must be specified");
}
}
throw new IllegalArgumentException(
"The className must be specified");
}
}
try {
Class c;
// See if we should use a separate ClassLoader
instanceof ClassLoader)) {
// Fallback to the system class loader.
}
}
AbstractRegionPainter.PaintContext.class, int.class);
if (constructor == null) {
throw new NullPointerException(
"Failed to find the constructor for the class: " +
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
/**
* A class which creates the NimbusStyle associated with it lazily, but also
* manages a lot more information about the style. It is less of a LazyValue
* type of class, and more of an Entry or Item type of class, as it
* represents an entry in the list of LazyStyles in the map m.
*
* The primary responsibilities of this class include:
* <ul>
* style</li>
* <li>Splitting the prefix specified in the constructor into its
* constituent parts to facilitate quicker matching</li>
* <li>Creating and vending a NimbusStyle lazily.</li>
* </ul>
*/
private final class LazyStyle {
/**
* The prefix this LazyStyle was registered with. Something like
* Button or ComboBox:"ComboBox.arrowButton"
*/
/**
* Whether or not this LazyStyle represents an unnamed component
*/
private boolean simple = true;
/**
* The various parts, or sections, of the prefix. For example,
* the prefix:
* ComboBox:"ComboBox.arrowButton"
*
* will be broken into two parts,
* ComboBox and "ComboBox.arrowButton"
*/
/**
* Cached shared style.
*/
private NimbusStyle style;
/**
* Create a new LazyStyle.
*
* @param prefix The prefix associated with this style. Cannot be null.
*/
throw new IllegalArgumentException(
"The prefix must not be null");
}
//there is one odd case that needs to be supported here: cell
//renderers. A cell renderer is defined as a named internal
//component, so for example:
// List."List.cellRenderer"
//The problem is that the component named List.cellRenderer is not a
//child of a JList. Rather, it is treated more as a direct component
//Thus, if the prefix ends with "cellRenderer", then remove all the
//previous dotted parts of the prefix name so that it becomes, for
//example: "List.cellRenderer"
//Likewise, we have a hacked work around for cellRenderer, renderer,
//and listRenderer.
}
//otherwise, normal code path
simple = false;
}
}
}
/**
* Gets the style. Creates it if necessary.
* @return the style
*/
// if the component has overrides, it gets its own unique style
// instead of the shared style.
SynthStyle s = null;
} else {
}
if (s == null) {
s = new NimbusStyle(prefix, c);
}
return s;
}
// lazily create the style if necessary
// return the style
return style;
}
/**
* This LazyStyle is a match for the given component if, and only if,
* for each part of the prefix the component hierarchy matches exactly.
* That is, if given "a":something:"b", then:
* c.getName() must equals "b"
* c.getParent() can be anything
* c.getParent().getParent().getName() must equal "a".
*/
boolean matches(JComponent c) {
}
if (partIndex < 0) return true;
if (c == null) return false;
//only get here if partIndex > 0 and c == null
//so far so good, recurse
//if c is not named, and parts[partIndex] has an expected class
//type registered, then check to make sure c is of the
//right type;
//so far so good, recurse
//special case the JInternalFrameTitlePane, because it
//doesn't fit the mold. very, very funky.
}
//it was the name of a region. So far, so good. Recurse.
}
}
return false;
}
/**
* Given some dot separated prefix, split on the colons that are
* not within quotes, and not within brackets.
*
* @param prefix
* @return
*/
int bracketCount = 0;
boolean inquotes = false;
int lastIndex = 0;
if (c == '[') {
bracketCount++;
continue;
} else if (c == '"') {
continue;
} else if (c == ']') {
bracketCount--;
if (bracketCount < 0) {
throw new RuntimeException(
"Malformed prefix: " + prefix);
}
continue;
}
//found a character to split on.
lastIndex = i + 1;
}
}
&& bracketCount == 0) {
}
return parts;
}
private final class Part {
private String s;
//true if this part represents a component name
private boolean named;
private Class c;
if (named) {
} else {
this.s = s;
//TODO use a map of known regions for Synth and Swing, and
//then use [classname] instead of org_class_name style
try {
} catch (Exception e) {
}
try {
} catch (Exception e) {
}
}
}
}
}
}
}
int aOffset, boolean uiResource) {
}
/**
* Get a derived color, derived colors are shared instances and will be
* updated when its parent UIDefault color changes.
*
* @param uiDefaultParentName The parent UIDefault key
* @param hOffset The hue offset
* @param sOffset The saturation offset
* @param bOffset The brightness offset
* @param aOffset The alpha offset
* @param uiResource True if the derived color should be a UIResource,
* false if it should not be a UIResource
* @return The stored derived color
*/
boolean uiResource){
}
boolean uiResource) {
if (uiResource) {
} else {
}
} else {
return color;
}
}
private class ColorTree implements PropertyChangeListener {
}
}
}
if (color instanceof DerivedColor) {
if (p != null) {
parent = p;
}
}
return parent;
}
public void update() {
}
// this is a registered color
}
}
class Node {
}
}
public void update() {
if (color instanceof DerivedColor) {
}
}
}
}
}
/**
* Listener to update derived colors on UIManager Defaults changes
*/
private class DefaultsListener implements PropertyChangeListener {
// LAF has been installed, this is the first point at which we
// can access our defaults table via UIManager so before now
// all derived colors will be incorrect.
// First we need to update
}
}
}
private String painterKey;
this.painterKey = painterKey;
}
}
g.translate(x, y);
if (g instanceof Graphics2D)
else {
}
g.translate(-x, -y);
}
}
public boolean isBorderOpaque() {
return false;
}
}
}