src/share/classes/javax/swing/plaf/nimbus/NimbusStyle.java
Print this page
*** 281,296 ****
//a list of the different types of states used by this style. This
//list may contain only "standard" states (those defined by Synth),
//or it may contain custom states, or it may contain only "standard"
//states but list them in a non-standard order.
! List<State> states = new ArrayList<State>();
//a map of state name to code
! Map<String,Integer> stateCodes = new HashMap<String,Integer>();
//This is a list of runtime "state" context objects. These contain
//the values associated with each state.
! List<RuntimeState> runtimeStates = new ArrayList<RuntimeState>();
//determine whether there are any custom states, or custom state
//order. If so, then read all those custom states and define the
//"values" stateTypes to be a non-null array.
//Otherwise, let the "values" stateTypes be null to indicate that
--- 281,296 ----
//a list of the different types of states used by this style. This
//list may contain only "standard" states (those defined by Synth),
//or it may contain custom states, or it may contain only "standard"
//states but list them in a non-standard order.
! List<State<?>> states = new ArrayList<>();
//a map of state name to code
! Map<String,Integer> stateCodes = new HashMap<>();
//This is a list of runtime "state" context objects. These contain
//the values associated with each state.
! List<RuntimeState> runtimeStates = new ArrayList<>();
//determine whether there are any custom states, or custom state
//order. If so, then read all those custom states and define the
//"values" stateTypes to be a non-null array.
//Otherwise, let the "values" stateTypes be null to indicate that
*** 302,312 ****
s[i] = s[i].trim();
if (!State.isStandardStateName(s[i])) {
//this is a non-standard state name, so look for the
//custom state associated with it
String stateName = prefix + "." + s[i];
! State customState = (State)defaults.get(stateName);
if (customState != null) {
states.add(customState);
}
} else {
states.add(State.getStandardState(s[i]));
--- 302,313 ----
s[i] = s[i].trim();
if (!State.isStandardStateName(s[i])) {
//this is a non-standard state name, so look for the
//custom state associated with it
String stateName = prefix + "." + s[i];
! @SuppressWarnings("unchecked")
! State<?> customState = (State)defaults.get(stateName);
if (customState != null) {
states.add(customState);
}
} else {
states.add(State.getStandardState(s[i]));
*** 315,330 ****
//if there were any states defined, then set the stateTypes array
//to be non-null. Otherwise, leave it null (meaning, use the
//standard synth states).
if (states.size() > 0) {
! values.stateTypes = states.toArray(new State[states.size()]);
}
//assign codes for each of the state types
int code = 1;
! for (State state : states) {
stateCodes.put(state.getName(), code);
code <<= 1;
}
} else {
//since there were no custom states defined, setup the list of
--- 316,331 ----
//if there were any states defined, then set the stateTypes array
//to be non-null. Otherwise, leave it null (meaning, use the
//standard synth states).
if (states.size() > 0) {
! values.stateTypes = states.toArray(new State<?>[states.size()]);
}
//assign codes for each of the state types
int code = 1;
! for (State<?> state : states) {
stateCodes.put(state.getName(), code);
code <<= 1;
}
} else {
//since there were no custom states defined, setup the list of
*** 461,476 ****
//finally, set the array of runtime states on the values object
values.states = runtimeStates.toArray(new RuntimeState[runtimeStates.size()]);
}
! private Painter getPainter(Map<String, Object> defaults, String key) {
Object p = defaults.get(key);
if (p instanceof UIDefaults.LazyValue) {
p = ((UIDefaults.LazyValue)p).createValue(UIManager.getDefaults());
}
! return (p instanceof Painter ? (Painter)p : null);
}
/**
* {@inheritDoc}
*
--- 462,479 ----
//finally, set the array of runtime states on the values object
values.states = runtimeStates.toArray(new RuntimeState[runtimeStates.size()]);
}
! private Painter<Object> getPainter(Map<String, Object> defaults, String key) {
Object p = defaults.get(key);
if (p instanceof UIDefaults.LazyValue) {
p = ((UIDefaults.LazyValue)p).createValue(UIManager.getDefaults());
}
! @SuppressWarnings("unchecked")
! Painter<Object> tmp = (p instanceof Painter ? (Painter)p : null);
! return tmp;
}
/**
* {@inheritDoc}
*
*** 687,725 ****
}
// return found object
return obj == NULL ? null : obj;
}
/**
* Gets the appropriate background Painter, if there is one, for the state
* specified in the given SynthContext. This method does appropriate
* fallback searching, as described in #get.
*
* @param ctx The SynthContext. Must not be null.
* @return The background painter associated for the given state, or null if
* none could be found.
*/
! public Painter getBackgroundPainter(SynthContext ctx) {
Values v = getValues(ctx);
int xstate = getExtendedState(ctx, v);
! Painter p = null;
// check the cache
tmpKey.init("backgroundPainter$$instance", xstate);
! p = (Painter)v.cache.get(tmpKey);
if (p != null) return p;
// not in cache, so lookup and store in cache
RuntimeState s = null;
int[] lastIndex = new int[] {-1};
while ((s = getNextState(v.states, lastIndex, xstate)) != null) {
if (s.backgroundPainter != null) {
! p = s.backgroundPainter;
break;
}
}
! if (p == null) p = (Painter)get(ctx, "backgroundPainter");
if (p != null) {
v.cache.put(new CacheKey("backgroundPainter$$instance", xstate), p);
}
return p;
}
--- 690,734 ----
}
// return found object
return obj == NULL ? null : obj;
}
+ @SuppressWarnings("unchecked")
+ private static Painter<Object> paintFilter(@SuppressWarnings("rawtypes") Painter painter) {
+ return (Painter<Object>) painter;
+ }
+
+
/**
* Gets the appropriate background Painter, if there is one, for the state
* specified in the given SynthContext. This method does appropriate
* fallback searching, as described in #get.
*
* @param ctx The SynthContext. Must not be null.
* @return The background painter associated for the given state, or null if
* none could be found.
*/
! public Painter<Object> getBackgroundPainter(SynthContext ctx) {
Values v = getValues(ctx);
int xstate = getExtendedState(ctx, v);
! Painter<Object> p = null;
// check the cache
tmpKey.init("backgroundPainter$$instance", xstate);
! p = paintFilter((Painter)v.cache.get(tmpKey));
if (p != null) return p;
// not in cache, so lookup and store in cache
RuntimeState s = null;
int[] lastIndex = new int[] {-1};
while ((s = getNextState(v.states, lastIndex, xstate)) != null) {
if (s.backgroundPainter != null) {
! p = paintFilter(s.backgroundPainter);
break;
}
}
! if (p == null) p = paintFilter((Painter)get(ctx, "backgroundPainter"));
if (p != null) {
v.cache.put(new CacheKey("backgroundPainter$$instance", xstate), p);
}
return p;
}
*** 731,760 ****
*
* @param ctx The SynthContext. Must not be null.
* @return The foreground painter associated for the given state, or null if
* none could be found.
*/
! public Painter getForegroundPainter(SynthContext ctx) {
Values v = getValues(ctx);
int xstate = getExtendedState(ctx, v);
! Painter p = null;
// check the cache
tmpKey.init("foregroundPainter$$instance", xstate);
! p = (Painter)v.cache.get(tmpKey);
if (p != null) return p;
// not in cache, so lookup and store in cache
RuntimeState s = null;
int[] lastIndex = new int[] {-1};
while ((s = getNextState(v.states, lastIndex, xstate)) != null) {
if (s.foregroundPainter != null) {
! p = s.foregroundPainter;
break;
}
}
! if (p == null) p = (Painter)get(ctx, "foregroundPainter");
if (p != null) {
v.cache.put(new CacheKey("foregroundPainter$$instance", xstate), p);
}
return p;
}
--- 740,769 ----
*
* @param ctx The SynthContext. Must not be null.
* @return The foreground painter associated for the given state, or null if
* none could be found.
*/
! public Painter<Object> getForegroundPainter(SynthContext ctx) {
Values v = getValues(ctx);
int xstate = getExtendedState(ctx, v);
! Painter<Object> p = null;
// check the cache
tmpKey.init("foregroundPainter$$instance", xstate);
! p = paintFilter((Painter)v.cache.get(tmpKey));
if (p != null) return p;
// not in cache, so lookup and store in cache
RuntimeState s = null;
int[] lastIndex = new int[] {-1};
while ((s = getNextState(v.states, lastIndex, xstate)) != null) {
if (s.foregroundPainter != null) {
! p = paintFilter(s.foregroundPainter);
break;
}
}
! if (p == null) p = paintFilter((Painter)get(ctx, "foregroundPainter"));
if (p != null) {
v.cache.put(new CacheKey("foregroundPainter$$instance", xstate), p);
}
return p;
}
*** 766,795 ****
*
* @param ctx The SynthContext. Must not be null.
* @return The border painter associated for the given state, or null if
* none could be found.
*/
! public Painter getBorderPainter(SynthContext ctx) {
Values v = getValues(ctx);
int xstate = getExtendedState(ctx, v);
! Painter p = null;
// check the cache
tmpKey.init("borderPainter$$instance", xstate);
! p = (Painter)v.cache.get(tmpKey);
if (p != null) return p;
// not in cache, so lookup and store in cache
RuntimeState s = null;
int[] lastIndex = new int[] {-1};
while ((s = getNextState(v.states, lastIndex, xstate)) != null) {
if (s.borderPainter != null) {
! p = s.borderPainter;
break;
}
}
! if (p == null) p = (Painter)get(ctx, "borderPainter");
if (p != null) {
v.cache.put(new CacheKey("borderPainter$$instance", xstate), p);
}
return p;
}
--- 775,804 ----
*
* @param ctx The SynthContext. Must not be null.
* @return The border painter associated for the given state, or null if
* none could be found.
*/
! public Painter<Object> getBorderPainter(SynthContext ctx) {
Values v = getValues(ctx);
int xstate = getExtendedState(ctx, v);
! Painter<Object> p = null;
// check the cache
tmpKey.init("borderPainter$$instance", xstate);
! p = paintFilter((Painter)v.cache.get(tmpKey));
if (p != null) return p;
// not in cache, so lookup and store in cache
RuntimeState s = null;
int[] lastIndex = new int[] {-1};
while ((s = getNextState(v.states, lastIndex, xstate)) != null) {
if (s.borderPainter != null) {
! p = paintFilter(s.borderPainter);
break;
}
}
! if (p == null) p = paintFilter((Painter)get(ctx, "borderPainter"));
if (p != null) {
v.cache.put(new CacheKey("borderPainter$$instance", xstate), p);
}
return p;
}
*** 849,858 ****
--- 858,868 ----
*
* @param ctx
* @param v
* @return
*/
+ @SuppressWarnings({"unchecked", "rawtypes"}) // Deal with odd generification of State
private int getExtendedState(SynthContext ctx, Values v) {
JComponent c = ctx.getComponent();
int xstate = 0;
int mask = 1;
//check for the Nimbus.State client property
*** 869,879 ****
State.StandardState s = State.getStandardState(stateStr);
if (s != null) xstate |= s.getState();
}
} else {
// custom states
! for (State s : v.stateTypes) {
if (contains(states, s.getName())) {
xstate |= mask;
}
mask <<= 1;
}
--- 879,889 ----
State.StandardState s = State.getStandardState(stateStr);
if (s != null) xstate |= s.getState();
}
} else {
// custom states
! for (State<?> s : v.stateTypes) {
if (contains(states, s.getName())) {
xstate |= mask;
}
mask <<= 1;
}
*** 1016,1028 ****
* fonts, painters, etc associated with some state for this
* style.
*/
private final class RuntimeState implements Cloneable {
int state;
! Painter backgroundPainter;
! Painter foregroundPainter;
! Painter borderPainter;
String stateName;
UIDefaults defaults = new UIDefaults(10, .7f);
private RuntimeState(int state, String stateName) {
this.state = state;
--- 1026,1038 ----
* fonts, painters, etc associated with some state for this
* style.
*/
private final class RuntimeState implements Cloneable {
int state;
! Painter<Object> backgroundPainter;
! Painter<Object> foregroundPainter;
! Painter<Object> borderPainter;
String stateName;
UIDefaults defaults = new UIDefaults(10, .7f);
private RuntimeState(int state, String stateName) {
this.state = state;
*** 1053,1063 ****
private static final class Values {
/**
* The list of State types. A State represents a type of state, such
* as Enabled, Default, WindowFocused, etc. These can be custom states.
*/
! State[] stateTypes = null;
/**
* The list of actual runtime state representations. These can represent things such
* as Enabled + Focused. Thus, they differ from States in that they contain
* several states together, and have associated properties, data, etc.
*/
--- 1063,1073 ----
private static final class Values {
/**
* The list of State types. A State represents a type of state, such
* as Enabled, Default, WindowFocused, etc. These can be custom states.
*/
! State<?>[] stateTypes = null;
/**
* The list of actual runtime state representations. These can represent things such
* as Enabled + Focused. Thus, they differ from States in that they contain
* several states together, and have associated properties, data, etc.
*/