src/share/classes/javax/swing/plaf/nimbus/NimbusStyle.java
Print this page
@@ -281,16 +281,16 @@
//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>();
+ List<State<?>> states = new ArrayList<>();
//a map of state name to code
- Map<String,Integer> stateCodes = new HashMap<String,Integer>();
+ 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<RuntimeState>();
+ 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,11 +302,11 @@
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);
+ State<?> customState = (State)defaults.get(stateName);
if (customState != null) {
states.add(customState);
}
} else {
states.add(State.getStandardState(s[i]));
@@ -315,16 +315,16 @@
//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()]);
+ values.stateTypes = states.toArray(new State<?>[states.size()]);
}
//assign codes for each of the state types
int code = 1;
- for (State state : states) {
+ for (State<?> state : states) {
stateCodes.put(state.getName(), code);
code <<= 1;
}
} else {
//since there were no custom states defined, setup the list of
@@ -461,16 +461,18 @@
//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) {
+ 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());
}
- return (p instanceof Painter ? (Painter)p : null);
+ @SuppressWarnings("unchecked")
+ Painter<Object> tmp = (p instanceof Painter ? (Painter)p : null);
+ return tmp;
}
/**
* {@inheritDoc}
*
@@ -687,39 +689,45 @@
}
// 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 getBackgroundPainter(SynthContext ctx) {
+ public Painter<Object> getBackgroundPainter(SynthContext ctx) {
Values v = getValues(ctx);
int xstate = getExtendedState(ctx, v);
- Painter p = null;
+ Painter<Object> p = null;
// check the cache
tmpKey.init("backgroundPainter$$instance", xstate);
- p = (Painter)v.cache.get(tmpKey);
+ 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 = s.backgroundPainter;
+ p = paintFilter(s.backgroundPainter);
break;
}
}
- if (p == null) p = (Painter)get(ctx, "backgroundPainter");
+ if (p == null) p = paintFilter((Painter)get(ctx, "backgroundPainter"));
if (p != null) {
v.cache.put(new CacheKey("backgroundPainter$$instance", xstate), p);
}
return p;
}
@@ -731,30 +739,30 @@
*
* @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) {
+ public Painter<Object> getForegroundPainter(SynthContext ctx) {
Values v = getValues(ctx);
int xstate = getExtendedState(ctx, v);
- Painter p = null;
+ Painter<Object> p = null;
// check the cache
tmpKey.init("foregroundPainter$$instance", xstate);
- p = (Painter)v.cache.get(tmpKey);
+ 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 = s.foregroundPainter;
+ p = paintFilter(s.foregroundPainter);
break;
}
}
- if (p == null) p = (Painter)get(ctx, "foregroundPainter");
+ if (p == null) p = paintFilter((Painter)get(ctx, "foregroundPainter"));
if (p != null) {
v.cache.put(new CacheKey("foregroundPainter$$instance", xstate), p);
}
return p;
}
@@ -766,30 +774,30 @@
*
* @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) {
+ public Painter<Object> getBorderPainter(SynthContext ctx) {
Values v = getValues(ctx);
int xstate = getExtendedState(ctx, v);
- Painter p = null;
+ Painter<Object> p = null;
// check the cache
tmpKey.init("borderPainter$$instance", xstate);
- p = (Painter)v.cache.get(tmpKey);
+ 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 = s.borderPainter;
+ p = paintFilter(s.borderPainter);
break;
}
}
- if (p == null) p = (Painter)get(ctx, "borderPainter");
+ if (p == null) p = paintFilter((Painter)get(ctx, "borderPainter"));
if (p != null) {
v.cache.put(new CacheKey("borderPainter$$instance", xstate), p);
}
return p;
}
@@ -849,10 +857,11 @@
*
* @param ctx
* @param v
* @return
*/
+ @SuppressWarnings({"unchecked", "rawtypes"})
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,11 +878,11 @@
State.StandardState s = State.getStandardState(stateStr);
if (s != null) xstate |= s.getState();
}
} else {
// custom states
- for (State s : v.stateTypes) {
+ for (State<?> s : v.stateTypes) {
if (contains(states, s.getName())) {
xstate |= mask;
}
mask <<= 1;
}
@@ -1016,13 +1025,13 @@
* fonts, painters, etc associated with some state for this
* style.
*/
private final class RuntimeState implements Cloneable {
int state;
- Painter backgroundPainter;
- Painter foregroundPainter;
- Painter borderPainter;
+ 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,11 +1062,11 @@
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;
+ 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.
*/