< prev index next >
src/share/classes/javax/swing/plaf/synth/SynthParser.java
Print this page
rev 1580 : 6727661: Code improvement and warnings removing from the swing/plaf packages
Summary: Removed unnecessary castings and other warnings
Reviewed-by: alexp
Contributed-by: Florian Brunner <fbrunnerlist@gmx.ch>
@@ -38,10 +38,11 @@
import java.net.URL;
import java.net.URLClassLoader;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.regex.PatternSyntaxException;
@@ -136,11 +137,11 @@
/**
* Array of state infos for the current style. These are pushed to the
* style when </style> is received.
*/
- private java.util.List _stateInfos;
+ private List<ParsedSynthStyle.StateInfo> _stateInfos;
/**
* Current style.
*/
private ParsedSynthStyle _style;
@@ -151,11 +152,11 @@
private ParsedSynthStyle.StateInfo _stateInfo;
/**
* Bindings for the current InputMap
*/
- private java.util.List _inputMapBindings;
+ private List<String> _inputMapBindings;
/**
* ID for the input map. This is cached as
* the InputMap is created AFTER the inputMapProperty has ended.
*/
@@ -177,34 +178,34 @@
private Class<?> _classResourceBase;
/**
* List of ColorTypes. This is populated in startColorType.
*/
- private java.util.List _colorTypes;
+ private List<ColorType> _colorTypes;
/**
* defaultsPropertys are placed here.
*/
- private Map _defaultsMap;
+ private Map<String, Object> _defaultsMap;
/**
* List of SynthStyle.Painters that will be applied to the current style.
*/
- private java.util.List _stylePainters;
+ private List<ParsedSynthStyle.PainterInfo> _stylePainters;
/**
* List of SynthStyle.Painters that will be applied to the current state.
*/
- private java.util.List _statePainters;
+ private List<ParsedSynthStyle.PainterInfo> _statePainters;
SynthParser() {
_mapping = new HashMap<String,Object>();
- _stateInfos = new ArrayList();
- _colorTypes = new ArrayList();
- _inputMapBindings = new ArrayList();
- _stylePainters = new ArrayList();
- _statePainters = new ArrayList();
+ _stateInfos = new ArrayList<ParsedSynthStyle.StateInfo>();
+ _colorTypes = new ArrayList<ColorType>();
+ _inputMapBindings = new ArrayList<String>();
+ _stylePainters = new ArrayList<ParsedSynthStyle.PainterInfo>();
+ _statePainters = new ArrayList<ParsedSynthStyle.PainterInfo>();
}
/**
* Parses a set of styles from <code>inputStream</code>, adding the
* resulting styles to the passed in DefaultSynthStyleFactory.
@@ -219,11 +220,11 @@
* @param defaultsMap Map that UIDefaults properties are placed in
*/
public void parse(InputStream inputStream,
DefaultSynthStyleFactory factory,
URL urlResourceBase, Class<?> classResourceBase,
- Map defaultsMap)
+ Map<String, Object> defaultsMap)
throws ParseException, IllegalArgumentException {
if (inputStream == null || factory == null ||
(urlResourceBase == null && classResourceBase == null)) {
throw new IllegalArgumentException(
"You must supply an InputStream, StyleFactory and Class or URL");
@@ -333,11 +334,11 @@
/**
* Returns an object created with id=key. If the object is not of
* type type, this will throw an exception.
*/
private Object lookup(String key, Class type) throws SAXException {
- Object value = null;
+ Object value;
if (_handler != null) {
if ((value = _handler.lookup(key)) != null) {
return checkCast(value, type);
}
}
@@ -423,19 +424,16 @@
}
private void endStyle() throws SAXException {
int size = _stylePainters.size();
if (size > 0) {
- _style.setPainters((ParsedSynthStyle.PainterInfo[])
- _stylePainters.toArray(new ParsedSynthStyle.
- PainterInfo[size]));
+ _style.setPainters(_stylePainters.toArray(new ParsedSynthStyle.PainterInfo[size]));
_stylePainters.clear();
}
size = _stateInfos.size();
if (size > 0) {
- _style.setStateInfo((ParsedSynthStyle.StateInfo[])_stateInfos.
- toArray(new ParsedSynthStyle.StateInfo[size]));
+ _style.setStateInfo(_stateInfos.toArray(new ParsedSynthStyle.StateInfo[size]));
_stateInfos.clear();
}
_style = null;
}
@@ -501,13 +499,11 @@
}
private void endState() throws SAXException {
int size = _statePainters.size();
if (size > 0) {
- _stateInfo.setPainters((ParsedSynthStyle.PainterInfo[])
- _statePainters.toArray(new ParsedSynthStyle.
- PainterInfo[size]));
+ _stateInfo.setPainters(_statePainters.toArray(new ParsedSynthStyle.PainterInfo[size]));
_statePainters.clear();
}
_stateInfo = null;
}
@@ -684,32 +680,31 @@
if (_stateInfo != null && _colorTypes.size() > 0) {
Color[] colors = _stateInfo.getColors();
int max = 0;
for (int counter = _colorTypes.size() - 1; counter >= 0;
counter--) {
- max = Math.max(max, ((ColorType)_colorTypes.get(counter)).
- getID());
+ max = Math.max(max, _colorTypes.get(counter).getID());
}
if (colors == null || colors.length <= max) {
Color[] newColors = new Color[max + 1];
if (colors != null) {
System.arraycopy(colors, 0, newColors, 0, colors.length);
}
colors = newColors;
}
for (int counter = _colorTypes.size() - 1; counter >= 0;
counter--) {
- colors[((ColorType)_colorTypes.get(counter)).getID()] = color;
+ colors[_colorTypes.get(counter).getID()] = color;
}
_stateInfo.setColors(colors);
}
}
private void startProperty(AttributeList attributes,
Object property) throws SAXException {
Object value = null;
- Object key = null;
+ String key = null;
// Type of the value: 0=idref, 1=boolean, 2=dimension, 3=insets,
// 4=integer,5=string
int iType = 0;
String aValue = null;
@@ -1027,11 +1022,11 @@
else if (_style != null) {
addPainterOrMerge(_stylePainters, method, painter, direction);
}
}
- private void addPainterOrMerge(java.util.List painters, String method,
+ private void addPainterOrMerge(List<ParsedSynthStyle.PainterInfo> painters, String method,
SynthPainter painter, int direction) {
ParsedSynthStyle.PainterInfo painterInfo;
painterInfo = new ParsedSynthStyle.PainterInfo(method,
painter,
direction);
< prev index next >