/*
* 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.
*/
/**
* Default implementation of SynthStyle. Has setters for the various
* SynthStyle methods. Many of the properties can be specified for all states,
* using SynthStyle directly, or a specific state using one of the StateInfo
* methods.
* <p>
* Beyond the constructor a subclass should override the <code>addTo</code>
* and <code>clone</code> methods, these are used when the Styles are being
* merged into a resulting style.
*
* @author Scott Violet
*/
/**
* Should the component be opaque?
*/
private boolean opaque;
/**
* Insets.
*/
/**
* Information specific to ComponentState.
*/
/**
* User specific data.
*/
/**
* Font to use if there is no matching StateInfo, or the StateInfo doesn't
* define one.
*/
/**
* SynthGraphics, may be null.
*/
/**
* Painter to use if the StateInfo doesn't have one.
*/
/**
* Nullary constructor, intended for subclassers.
*/
public DefaultSynthStyle() {
}
/**
* Creates a new DefaultSynthStyle that is a copy of the passed in
* style. Any StateInfo's of the passed in style are clonsed as well.
*
* @param style Style to duplicate
*/
}
counter--) {
}
}
}
}
/**
* Creates a new DefaultSynthStyle.
*
* @param insets Insets for the Style
* @param opaque Whether or not the background is completely painted in
* an opaque color
* @param states StateInfos describing properties per state
* @param data Style specific data.
*/
}
}
// For the enabled state, prefer the widget's colors
return c.getBackground();
}
return c.getForeground();
}
// If getForeground returns a non-UIResource it means the
// developer has explicitly set the foreground, use it over
// that of TEXT_FOREGROUND as that is typically the expected
// behavior.
if (!(color instanceof UIResource)) {
return color;
}
}
}
// Then use what we've locally defined
// No color, fallback to that of the widget.
return c.getBackground();
}
return c.getForeground();
}
}
return color;
}
}
/**
* Returns the color for the specified state.
*
* @param c JComponent the style is associated with
* @param id Region identifier
* @param state State of the region.
* @param type Type of color being requested.
* @return Color to render with
*/
// Use the best state.
return color;
}
}
}
return null;
}
/**
* Sets the font that is used if there is no matching StateInfo, or
* it does not define a font.
*
* @param font Font to use for rendering
*/
}
}
return c.getFont();
}
return cFont;
}
}
/**
* Returns the font for the specified state. This should NOT callback
* to the JComponent.
*
* @param c JComponent the style is associated with
* @param id Region identifier
* @param state State of the region.
* @return Font to render with
*/
if (c == null) {
return this.font;
}
// First pass, look for the best match
return font;
}
return font;
}
}
// Fallback font.
return this.font;
}
}
/**
* Sets the SynthGraphicsUtils that will be used for rendering.
*
* @param graphics SynthGraphics
*/
this.synthGraphics = graphics;
}
/**
* Returns a SynthGraphicsUtils.
*
* @param context SynthContext indentifying requestor
* @return SynthGraphicsUtils
*/
if (synthGraphics == null) {
return super.getGraphicsUtils(context);
}
return synthGraphics;
}
/**
* Sets the insets.
*
* @param Insets.
*/
}
/**
* Returns the Insets. If <code>to</code> is non-null the resulting
* insets will be placed in it, otherwise a new Insets object will be
* created and returned.
*
* @param context SynthContext indentifying requestor
* @param to Where to place Insets
* @return Insets.
*/
}
}
else {
}
return to;
}
/**
* Sets the Painter to use for the border.
*
* @param painter Painter for the Border.
*/
}
/**
* Returns the Painter for the passed in Component. This may return null.
*
* @param ss SynthContext indentifying requestor
* @return Painter for the border
*/
return painter;
}
/**
* Sets whether or not the JComponent should be opaque.
*
* @param opaque Whether or not the JComponent should be opaque.
*/
}
/**
* Returns the value to initialize the opacity property of the Component
* to. A Style should NOT assume the opacity will remain this value, the
* developer may reset it or override it.
*
* @param ss SynthContext indentifying requestor
* @return opaque Whether or not the JComponent is opaque.
*/
return opaque;
}
/**
* Sets style specific values. This does NOT copy the data, it
* assigns it directly to this Style.
*
* @param data Style specific values
*/
}
/**
* Returns the style specific data.
*
* @return Style specific data.
*/
return data;
}
/**
* Getter for a region specific style property.
*
* @param state SynthContext indentifying requestor
* @param key Property being requested.
* @return Value of the named property
*/
// Look for the best match
}
}
}
synchronized(stateData) {
}
synchronized(stateData) {
try {
} catch (InterruptedException ie) {}
}
}
synchronized(stateData) {
}
synchronized(stateData) {
}
}
}
return value;
}
/**
* Returns the default value for a particular property. This is only
* invoked if this style doesn't define a property for <code>key</code>.
*
* @param state SynthContext indentifying requestor
* @param key Property being requested.
* @return Value of the named property
*/
}
/**
* Creates a clone of this style.
*
* @return Clone of this style
*/
try {
} catch (CloneNotSupportedException cnse) {
return null;
}
}
}
}
return style;
}
/**
* Merges the contents of this Style with that of the passed in Style,
* returning the resulting merged syle. Properties of this
* <code>DefaultSynthStyle</code> will take precedence over those of the
* passed in <code>DefaultSynthStyle</code>. For example, if this
* style specifics a non-null font, the returned style will have its
* font so to that regardless of the <code>style</code>'s font.
*
* @param style Style to add our styles to
* @return Merged style.
*/
}
}
}
if (synthGraphics != null) {
}
clone();
}
}
}
else {
// Find the number of new states in unique, merging any
// matching states as we go. Also, move any merge styles
// to the end to give them precedence.
int unique = 0;
// Number of StateInfos that match.
int matchCount = 0;
thisCounter--) {
boolean found = false;
getComponentState()) {
// Move StateInfo to end, giving it precedence.
matchCount++;
found = true;
break;
}
}
if (!found) {
unique++;
}
}
if (unique != 0) {
// There are states that exist in this Style that
// don't exist in the other style, recreate the array
// and add them.
unique + maxOStyles];
int newIndex = maxOStyles;
thisCounter--) {
boolean found = false;
oCounter--) {
getComponentState()) {
found = true;
break;
}
}
if (!found) {
thisCounter].clone();
}
}
}
}
}
}
}
return style;
}
/**
* Sets the array of StateInfo's which are used to specify properties
* specific to a particular style.
*
* @param states StateInfos
*/
}
/**
* Returns the array of StateInfo's that that are used to specify
* properties specific to a particular style.
*
* @return Array of StateInfos.
*/
return states;
}
/**
* Returns the best matching StateInfo for a particular state.
*
* @param state Component state.
* @return Best matching StateInfo, or null
*/
// Use the StateInfo with the most bits that matches that of state.
// If there is none, than fallback to
// the StateInfo with a state of 0, indicating it'll match anything.
// Consider if we have 3 StateInfos a, b and c with states:
// SELECTED, SELECTED | ENABLED, 0
//
// Input Return Value
// ----- ------------
// SELECTED a
// SELECTED | ENABLED b
// MOUSE_OVER c
// SELECTED | ENABLED | FOCUSED b
// ENABLED c
int bestCount = 0;
int bestIndex = -1;
int wildIndex = -1;
if (state == 0) {
}
}
return null;
}
if (oState == 0) {
if (wildIndex == -1) {
}
}
// This is key, we need to make sure all bits of the
// StateInfo match, otherwise a StateInfo with
// SELECTED | ENABLED would match ENABLED, which we
// don't want.
// This comes from BigInteger.bitCnt
0x33333333);
}
}
}
if (bestIndex != -1) {
}
if (wildIndex != -1) {
}
}
return null;
}
}
}
// remove last newline
}
/**
* StateInfo represents Style information specific to the state of
* a component.
*/
public static class StateInfo {
private int state;
/**
* Creates a new StateInfo.
*/
public StateInfo() {
}
/**
* Creates a new StateInfo with the specified properties
*
* @param state Component state(s) that this StateInfo should be used
* for
* @param painter Painter responsible for rendering
* @param bgPainter Painter responsible for rendering the background
* @param font Font for this state
* @param colors Colors for this state
*/
}
/**
* Creates a new StateInfo that is a copy of the passed in
* StateInfo.
*
* @param info StateInfo to copy.
*/
}
}
}
}
return data;
}
}
/**
* Sets the font for this state.
*
* @param font Font to use for rendering
*/
}
/**
* Returns the font for this state.
*
* @return Returns the font to use for rendering this state
*/
return font;
}
/**
* Sets the array of colors to use for rendering this state. This
* is indexed by <code>ColorType.getID()</code>.
*
* @param colors Array of colors
*/
}
/**
* Returns the array of colors to use for rendering this state. This
* is indexed by <code>ColorType.getID()</code>.
*
* @return Array of colors
*/
return colors;
}
/**
* Returns the Color to used for the specified ColorType.
*
* @return Color.
*/
}
}
return null;
}
/**
* Merges the contents of this StateInfo with that of the passed in
* StateInfo, returning the resulting merged StateInfo. Properties of
* this <code>StateInfo</code> will take precedence over those of the
* passed in <code>StateInfo</code>. For example, if this
* StateInfo specifics a non-null font, the returned StateInfo will
* have its font so to that regardless of the <code>StateInfo</code>'s
* font.
*
* @param info StateInfo to add our styles to
* @return Merged StateInfo.
*/
}
}
}
}
else {
}
counter--) {
}
}
}
}
return info;
}
/**
* Sets the state this StateInfo corresponds to.
*
* @see SynthConstants
* @param state info.
*/
}
/**
* Returns the state this StateInfo corresponds to.
*
* @see SynthConstants
* @return state info.
*/
public int getComponentState() {
return state;
}
/**
* Returns the number of states that are similar between the
* ComponentState this StateInfo represents and val.
*/
// This comes from BigInteger.bitCnt
return val & 0xff;
}
/**
* Creates and returns a copy of this StateInfo.
*
* @return Copy of this StateInfo.
*/
return new StateInfo(this);
}
append(',');
}
}
}
}