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