提交 363ab66c 编写于 作者: R rupashka

6727662: Code improvement and warnings removing from swing packages

Summary: Removed unnecessary castings and other warnings
Reviewed-by: malenkov
上级 a90d474b
......@@ -1315,8 +1315,7 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl
// Make sure the change actually took effect
if (!selected && isSelected()) {
if (getModel() instanceof DefaultButtonModel) {
ButtonGroup group = (ButtonGroup)
((DefaultButtonModel)getModel()).getGroup();
ButtonGroup group = ((DefaultButtonModel)getModel()).getGroup();
if (group != null) {
group.clearSelection();
}
......@@ -1886,8 +1885,7 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl
* @since 1.4
*/
public ChangeListener[] getChangeListeners() {
return (ChangeListener[])(listenerList.getListeners(
ChangeListener.class));
return listenerList.getListeners(ChangeListener.class);
}
/**
......@@ -1944,8 +1942,7 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl
* @since 1.4
*/
public ActionListener[] getActionListeners() {
return (ActionListener[])(listenerList.getListeners(
ActionListener.class));
return listenerList.getListeners(ActionListener.class);
}
/**
......@@ -2137,7 +2134,7 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl
* @since 1.4
*/
public ItemListener[] getItemListeners() {
return (ItemListener[])listenerList.getListeners(ItemListener.class);
return listenerList.getListeners(ItemListener.class);
}
/**
......@@ -2981,7 +2978,7 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl
paintViewR.height = AbstractButton.this.getHeight() - (paintViewInsets.top + paintViewInsets.bottom);
String clippedText = SwingUtilities.layoutCompoundLabel(
(JComponent)AbstractButton.this,
AbstractButton.this,
getFontMetrics(getFont()),
text,
icon,
......
......@@ -118,8 +118,7 @@ public abstract class AbstractCellEditor implements CellEditor, Serializable {
* @since 1.4
*/
public CellEditorListener[] getCellEditorListeners() {
return (CellEditorListener[])listenerList.getListeners(
CellEditorListener.class);
return listenerList.getListeners(CellEditorListener.class);
}
/**
......
......@@ -85,8 +85,7 @@ public abstract class AbstractListModel implements ListModel, Serializable
* @since 1.4
*/
public ListDataListener[] getListDataListeners() {
return (ListDataListener[])listenerList.getListeners(
ListDataListener.class);
return listenerList.getListeners(ListDataListener.class);
}
......
......@@ -98,8 +98,7 @@ public abstract class AbstractSpinnerModel implements SpinnerModel, Serializable
* @since 1.4
*/
public ChangeListener[] getChangeListeners() {
return (ChangeListener[])listenerList.getListeners(
ChangeListener.class);
return listenerList.getListeners(ChangeListener.class);
}
......
......@@ -197,7 +197,7 @@ public class ActionMap implements Serializable {
return pKeys;
}
HashMap keyMap = new HashMap();
HashMap<Object, Object> keyMap = new HashMap<Object, Object>();
int counter;
for (counter = keys.length - 1; counter >= 0; counter--) {
......
......@@ -62,7 +62,7 @@ class AncestorNotifier implements ComponentListener, PropertyChangeListener, Ser
}
AncestorListener[] getAncestorListeners() {
return (AncestorListener[])listenerList.getListeners(AncestorListener.class);
return listenerList.getListeners(AncestorListener.class);
}
/**
......
......@@ -88,10 +88,10 @@ class ArrayTable implements Cloneable {
// Write ou the Serializable key/value pairs.
s.writeInt(validCount);
if (validCount > 0) {
for (int counter = 0; counter < keys.length; counter++) {
if (keys[counter] != null) {
s.writeObject(keys[counter]);
s.writeObject(table.get(keys[counter]));
for (Object key : keys) {
if (key != null) {
s.writeObject(key);
s.writeObject(table.get(key));
if (--validCount == 0) {
break;
}
......@@ -315,7 +315,7 @@ class ArrayTable implements Cloneable {
*/
private void grow() {
Object[] array = (Object[])table;
Hashtable tmp = new Hashtable(array.length/2);
Hashtable<Object, Object> tmp = new Hashtable<Object, Object>(array.length/2);
for (int i = 0; i<array.length; i+=2) {
tmp.put(array[i], array[i+1]);
}
......
......@@ -68,7 +68,7 @@ import java.io.Serializable;
public class ButtonGroup implements Serializable {
// the list of buttons participating in this group
protected Vector<AbstractButton> buttons = new Vector();
protected Vector<AbstractButton> buttons = new Vector<AbstractButton>();
/**
* The current selection.
......
......@@ -37,7 +37,7 @@ class DebugGraphicsInfo {
Color flashColor = Color.red;
int flashTime = 100;
int flashCount = 2;
Hashtable componentToDebug;
Hashtable<JComponent, Integer> componentToDebug;
JFrame debugFrame = null;
java.io.PrintStream stream = System.out;
......@@ -46,7 +46,7 @@ class DebugGraphicsInfo {
return;
}
if (componentToDebug == null) {
componentToDebug = new Hashtable();
componentToDebug = new Hashtable<JComponent, Integer>();
}
if (debug > 0) {
componentToDebug.put(component, Integer.valueOf(debug));
......@@ -59,7 +59,7 @@ class DebugGraphicsInfo {
if (componentToDebug == null) {
return 0;
} else {
Integer integer = (Integer)componentToDebug.get(component);
Integer integer = componentToDebug.get(component);
return integer == null ? 0 : integer.intValue();
}
......
......@@ -343,8 +343,7 @@ public class DefaultBoundedRangeModel implements BoundedRangeModel, Serializable
* @since 1.4
*/
public ChangeListener[] getChangeListeners() {
return (ChangeListener[])listenerList.getListeners(
ChangeListener.class);
return listenerList.getListeners(ChangeListener.class);
}
......
......@@ -326,8 +326,7 @@ public class DefaultButtonModel implements ButtonModel, Serializable {
* @since 1.4
*/
public ChangeListener[] getChangeListeners() {
return (ChangeListener[])listenerList.getListeners(
ChangeListener.class);
return listenerList.getListeners(ChangeListener.class);
}
/**
......@@ -380,8 +379,7 @@ public class DefaultButtonModel implements ButtonModel, Serializable {
* @since 1.4
*/
public ActionListener[] getActionListeners() {
return (ActionListener[])listenerList.getListeners(
ActionListener.class);
return listenerList.getListeners(ActionListener.class);
}
/**
......@@ -434,7 +432,7 @@ public class DefaultButtonModel implements ButtonModel, Serializable {
* @since 1.4
*/
public ItemListener[] getItemListeners() {
return (ItemListener[])listenerList.getListeners(ItemListener.class);
return listenerList.getListeners(ItemListener.class);
}
/**
......
......@@ -156,18 +156,17 @@ final class LegacyLayoutFocusTraversalPolicy
}
}
final class CompareTabOrderComparator implements Comparator {
final class CompareTabOrderComparator implements Comparator<Component> {
private final DefaultFocusManager defaultFocusManager;
CompareTabOrderComparator(DefaultFocusManager defaultFocusManager) {
this.defaultFocusManager = defaultFocusManager;
}
public int compare(Object o1, Object o2) {
public int compare(Component o1, Component o2) {
if (o1 == o2) {
return 0;
}
return (defaultFocusManager.compareTabOrder((Component)o1,
(Component)o2)) ? -1 : 1;
return (defaultFocusManager.compareTabOrder(o1, o2)) ? -1 : 1;
}
}
......@@ -133,8 +133,7 @@ public class DefaultListSelectionModel implements ListSelectionModel, Cloneable,
* @since 1.4
*/
public ListSelectionListener[] getListSelectionListeners() {
return (ListSelectionListener[])listenerList.getListeners(
ListSelectionListener.class);
return listenerList.getListeners(ListSelectionListener.class);
}
/**
......
......@@ -110,8 +110,7 @@ Serializable {
* @since 1.4
*/
public ChangeListener[] getChangeListeners() {
return (ChangeListener[])listenerList.getListeners(
ChangeListener.class);
return listenerList.getListeners(ChangeListener.class);
}
/**
......
......@@ -1119,7 +1119,7 @@ public class GroupLayout implements LayoutManager2 {
* creating one if necessary.
*/
private ComponentInfo getComponentInfo(Component component) {
ComponentInfo info = (ComponentInfo)componentInfos.get(component);
ComponentInfo info = componentInfos.get(component);
if (info == null) {
info = new ComponentInfo(component);
componentInfos.put(component, info);
......@@ -1698,7 +1698,7 @@ public class GroupLayout implements LayoutManager2 {
for (int counter = springs.size() - 1; counter >= 0; counter--) {
Spring spring = springs.get(counter);
if (spring instanceof AutoPreferredGapSpring) {
((AutoPreferredGapSpring)spring).unset();
spring.unset();
} else if (spring instanceof Group) {
((Group)spring).unsetAutopadding();
}
......
......@@ -200,7 +200,7 @@ public class InputMap implements Serializable {
return pKeys;
}
HashMap keyMap = new HashMap();
HashMap<KeyStroke, KeyStroke> keyMap = new HashMap<KeyStroke, KeyStroke>();
int counter;
for (counter = keys.length - 1; counter >= 0; counter--) {
......@@ -212,7 +212,7 @@ public class InputMap implements Serializable {
KeyStroke[] allKeys = new KeyStroke[keyMap.size()];
return (KeyStroke[])keyMap.keySet().toArray(allKeys);
return keyMap.keySet().toArray(allKeys);
}
private void writeObject(ObjectOutputStream s) throws IOException {
......
......@@ -859,7 +859,7 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible {
* @since 1.4
*/
public ItemListener[] getItemListeners() {
return (ItemListener[])listenerList.getListeners(ItemListener.class);
return listenerList.getListeners(ItemListener.class);
}
/**
......@@ -897,8 +897,7 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible {
* @since 1.4
*/
public ActionListener[] getActionListeners() {
return (ActionListener[])listenerList.getListeners(
ActionListener.class);
return listenerList.getListeners(ActionListener.class);
}
/**
......@@ -937,8 +936,7 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible {
* @since 1.4
*/
public PopupMenuListener[] getPopupMenuListeners() {
return (PopupMenuListener[])listenerList.getListeners(
PopupMenuListener.class);
return listenerList.getListeners(PopupMenuListener.class);
}
/**
......@@ -1668,7 +1666,7 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible {
if (editor != null) {
Component comp = editor.getEditorComponent();
if (comp instanceof Accessible) {
AccessibleContext ac = ((Accessible)comp).getAccessibleContext();
AccessibleContext ac = comp.getAccessibleContext();
if (ac != null) { // may be null
ac.setAccessibleName(getAccessibleName());
ac.setAccessibleDescription(getAccessibleDescription());
......@@ -1741,7 +1739,7 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible {
// Fire a FOCUSED lost PropertyChangeEvent for the
// previously selected list item.
PropertyChangeEvent pce = null;
PropertyChangeEvent pce;
if (previousSelectedAccessible != null) {
pce = new PropertyChangeEvent(previousSelectedAccessible,
......
......@@ -192,7 +192,8 @@ public abstract class JComponent extends Container implements Serializable,
/**
* @see #readObject
*/
private static final Hashtable readObjectCallbacks = new Hashtable(1);
private static final Hashtable<ObjectInputStream, ReadObjectCallback> readObjectCallbacks =
new Hashtable<ObjectInputStream, ReadObjectCallback>(1);
/**
* Keys to use for forward focus traversal when the JComponent is
......@@ -356,7 +357,7 @@ public abstract class JComponent extends Container implements Serializable,
/**
* Temporary rectangles.
*/
private static java.util.List tempRectangles = new java.util.ArrayList(11);
private static java.util.List<Rectangle> tempRectangles = new java.util.ArrayList<Rectangle>(11);
/** Used for <code>WHEN_FOCUSED</code> bindings. */
private InputMap focusInputMap;
......@@ -451,7 +452,7 @@ public abstract class JComponent extends Container implements Serializable,
Rectangle rect;
int size = tempRectangles.size();
if (size > 0) {
rect = (Rectangle)tempRectangles.remove(size - 1);
rect = tempRectangles.remove(size - 1);
}
else {
rect = new Rectangle(0, 0, 0, 0);
......@@ -806,7 +807,7 @@ public abstract class JComponent extends Container implements Serializable,
// its index.
if (paintingChild != null &&
(paintingChild instanceof JComponent) &&
((JComponent)paintingChild).isOpaque()) {
paintingChild.isOpaque()) {
for (; i >= 0; i--) {
if (getComponent(i) == paintingChild){
break;
......@@ -875,7 +876,7 @@ public abstract class JComponent extends Container implements Serializable,
shouldSetFlagBack = true;
}
if(!printing) {
((JComponent)comp).paint(cg);
comp.paint(cg);
}
else {
if (!getFlag(IS_PRINTING_ALL)) {
......@@ -1098,7 +1099,7 @@ public abstract class JComponent extends Container implements Serializable,
}
private void adjustPaintFlags() {
JComponent jparent = null;
JComponent jparent;
Container parent;
for(parent = getParent() ; parent != null ; parent =
parent.getParent()) {
......@@ -2096,7 +2097,7 @@ public abstract class JComponent extends Container implements Serializable,
private void registerWithKeyboardManager(boolean onlyIfNew) {
InputMap inputMap = getInputMap(WHEN_IN_FOCUSED_WINDOW, false);
KeyStroke[] strokes;
Hashtable registered = (Hashtable)getClientProperty
Hashtable<KeyStroke, KeyStroke> registered = (Hashtable)getClientProperty
(WHEN_IN_FOCUSED_WINDOW_BINDINGS);
if (inputMap != null) {
......@@ -2120,10 +2121,10 @@ public abstract class JComponent extends Container implements Serializable,
}
// Remove any old ones.
if (registered != null && registered.size() > 0) {
Enumeration keys = registered.keys();
Enumeration<KeyStroke> keys = registered.keys();
while (keys.hasMoreElements()) {
KeyStroke ks = (KeyStroke)keys.nextElement();
KeyStroke ks = keys.nextElement();
unregisterWithKeyboardManager(ks);
}
registered.clear();
......@@ -2131,7 +2132,7 @@ public abstract class JComponent extends Container implements Serializable,
// Updated the registered Hashtable.
if (strokes != null && strokes.length > 0) {
if (registered == null) {
registered = new Hashtable(strokes.length);
registered = new Hashtable<KeyStroke, KeyStroke>(strokes.length);
putClientProperty(WHEN_IN_FOCUSED_WINDOW_BINDINGS, registered);
}
for (int counter = strokes.length - 1; counter >= 0; counter--) {
......@@ -2174,7 +2175,7 @@ public abstract class JComponent extends Container implements Serializable,
InputMap km = getInputMap(WHEN_IN_FOCUSED_WINDOW, false);
while (km != inputMap && km != null) {
km = (ComponentInputMap)km.getParent();
km = km.getParent();
}
if (km != null) {
registerWithKeyboardManager(false);
......@@ -3673,7 +3674,7 @@ public abstract class JComponent extends Container implements Serializable,
if (c != null && c instanceof Accessible) {
AccessibleJComponent.this.firePropertyChange(
AccessibleContext.ACCESSIBLE_CHILD_PROPERTY,
null, ((Accessible) c).getAccessibleContext());
null, c.getAccessibleContext());
}
}
public void componentRemoved(ContainerEvent e) {
......@@ -3681,7 +3682,7 @@ public abstract class JComponent extends Container implements Serializable,
if (c != null && c instanceof Accessible) {
AccessibleJComponent.this.firePropertyChange(
AccessibleContext.ACCESSIBLE_CHILD_PROPERTY,
((Accessible) c).getAccessibleContext(), null);
c.getAccessibleContext(), null);
}
}
}
......@@ -4377,7 +4378,7 @@ public abstract class JComponent extends Container implements Serializable,
// System.out.println("A) checking opaque: " + ((JComponent)child).isOpaque() + " " + child);
// System.out.print("B) ");
// Thread.dumpStack();
return ((JComponent)child).isOpaque();
return child.isOpaque();
} else {
/** Sometimes a heavy weight can have a bound larger than its peer size
* so we should always draw under heavy weights
......@@ -4693,7 +4694,7 @@ public abstract class JComponent extends Container implements Serializable,
result = (T[])getPropertyChangeListeners();
}
else {
result = (T[])listenerList.getListeners(listenerType);
result = listenerList.getListeners(listenerType);
}
if (result.length == 0) {
......@@ -4904,7 +4905,7 @@ public abstract class JComponent extends Container implements Serializable,
if(!isShowing()) {
return;
}
while(!((JComponent)c).isOpaque()) {
while(!c.isOpaque()) {
parent = c.getParent();
if(parent != null) {
x += c.getX();
......@@ -5198,7 +5199,7 @@ public abstract class JComponent extends Container implements Serializable,
Rectangle siblingRect;
boolean opaque;
if (sibling instanceof JComponent) {
opaque = ((JComponent)sibling).isOpaque();
opaque = sibling.isOpaque();
if (!opaque) {
if (retValue == PARTIALLY_OBSCURED) {
continue;
......@@ -5345,7 +5346,7 @@ public abstract class JComponent extends Container implements Serializable,
*/
private class ReadObjectCallback implements ObjectInputValidation
{
private final Vector roots = new Vector(1);
private final Vector<JComponent> roots = new Vector<JComponent>(1);
private final ObjectInputStream inputStream;
ReadObjectCallback(ObjectInputStream s) throws Exception {
......@@ -5361,8 +5362,7 @@ public abstract class JComponent extends Container implements Serializable,
*/
public void validateObject() throws InvalidObjectException {
try {
for(int i = 0; i < roots.size(); i++) {
JComponent root = (JComponent)(roots.elementAt(i));
for (JComponent root : roots) {
SwingUtilities.updateComponentTreeUI(root);
}
}
......@@ -5382,8 +5382,7 @@ public abstract class JComponent extends Container implements Serializable,
/* If the Component c is a descendant of one of the
* existing roots (or it IS an existing root), we're done.
*/
for(int i = 0; i < roots.size(); i++) {
JComponent root = (JComponent)roots.elementAt(i);
for (JComponent root : roots) {
for(Component p = c; p != null; p = p.getParent()) {
if (p == root) {
return;
......@@ -5396,7 +5395,7 @@ public abstract class JComponent extends Container implements Serializable,
* to the roots vector.
*/
for(int i = 0; i < roots.size(); i++) {
JComponent root = (JComponent)roots.elementAt(i);
JComponent root = roots.elementAt(i);
for(Component p = root.getParent(); p != null; p = p.getParent()) {
if (p == c) {
roots.removeElementAt(i--); // !!
......@@ -5428,7 +5427,7 @@ public abstract class JComponent extends Container implements Serializable,
* in the readObjectCallbacks table. Note that the ReadObjectCallback
* constructor takes care of calling s.registerValidation().
*/
ReadObjectCallback cb = (ReadObjectCallback)(readObjectCallbacks.get(s));
ReadObjectCallback cb = readObjectCallbacks.get(s);
if (cb == null) {
try {
readObjectCallbacks.put(s, cb = new ReadObjectCallback(s));
......
......@@ -133,8 +133,8 @@ public class JDesktopPane extends JLayeredPane implements Accessible
public Component getDefaultComponent(Container c) {
JInternalFrame jifArray[] = getAllFrames();
Component comp = null;
for (int i = 0; i < jifArray.length; i++) {
comp = jifArray[i].getFocusTraversalPolicy().getDefaultComponent(jifArray[i]);
for (JInternalFrame jif : jifArray) {
comp = jif.getFocusTraversalPolicy().getDefaultComponent(jif);
if (comp != null) {
break;
}
......@@ -262,16 +262,15 @@ public class JDesktopPane extends JLayeredPane implements Accessible
public JInternalFrame[] getAllFrames() {
int i, count;
JInternalFrame[] results;
Vector vResults = new Vector(10);
Object next, tmp;
Vector<JInternalFrame> vResults = new Vector<JInternalFrame>(10);
count = getComponentCount();
for(i = 0; i < count; i++) {
next = getComponent(i);
Component next = getComponent(i);
if(next instanceof JInternalFrame)
vResults.addElement(next);
vResults.addElement((JInternalFrame) next);
else if(next instanceof JInternalFrame.JDesktopIcon) {
tmp = ((JInternalFrame.JDesktopIcon)next).getInternalFrame();
JInternalFrame tmp = ((JInternalFrame.JDesktopIcon)next).getInternalFrame();
if(tmp != null)
vResults.addElement(tmp);
}
......@@ -324,18 +323,17 @@ public class JDesktopPane extends JLayeredPane implements Accessible
public JInternalFrame[] getAllFramesInLayer(int layer) {
int i, count;
JInternalFrame[] results;
Vector vResults = new Vector(10);
Object next, tmp;
Vector<JInternalFrame> vResults = new Vector<JInternalFrame>(10);
count = getComponentCount();
for(i = 0; i < count; i++) {
next = getComponent(i);
Component next = getComponent(i);
if(next instanceof JInternalFrame) {
if(((JInternalFrame)next).getLayer() == layer)
vResults.addElement(next);
vResults.addElement((JInternalFrame) next);
} else if(next instanceof JInternalFrame.JDesktopIcon) {
tmp = ((JInternalFrame.JDesktopIcon)next).getInternalFrame();
if(tmp != null && ((JInternalFrame)tmp).getLayer() == layer)
JInternalFrame tmp = ((JInternalFrame.JDesktopIcon)next).getInternalFrame();
if(tmp != null && tmp.getLayer() == layer)
vResults.addElement(tmp);
}
}
......
......@@ -277,7 +277,7 @@ public class JDialog extends Dialog implements WindowConstants,
title, modal);
if (owner == null) {
WindowListener ownerShutdownListener =
(WindowListener)SwingUtilities.getSharedOwnerFrameShutdownListener();
SwingUtilities.getSharedOwnerFrameShutdownListener();
addWindowListener(ownerShutdownListener);
}
dialogInit();
......@@ -329,7 +329,7 @@ public class JDialog extends Dialog implements WindowConstants,
title, modal, gc);
if (owner == null) {
WindowListener ownerShutdownListener =
(WindowListener)SwingUtilities.getSharedOwnerFrameShutdownListener();
SwingUtilities.getSharedOwnerFrameShutdownListener();
addWindowListener(ownerShutdownListener);
}
dialogInit();
......
......@@ -319,8 +319,7 @@ public class JEditorPane extends JTextComponent {
* @since 1.4
*/
public synchronized HyperlinkListener[] getHyperlinkListeners() {
return (HyperlinkListener[])listenerList.getListeners(
HyperlinkListener.class);
return listenerList.getListeners(javax.swing.event.HyperlinkListener.class);
}
/**
......@@ -492,8 +491,8 @@ public class JEditorPane extends JTextComponent {
if (pageProperties != null) {
// transfer properties discovered in stream to the
// document property collection.
for (Enumeration e = pageProperties.keys(); e.hasMoreElements() ;) {
Object key = e.nextElement();
for (Enumeration<String> e = pageProperties.keys(); e.hasMoreElements() ;) {
String key = e.nextElement();
doc.putProperty(key, pageProperties.get(key));
}
pageProperties.clear();
......@@ -775,7 +774,7 @@ public class JEditorPane extends JTextComponent {
*/
private void handleConnectionProperties(URLConnection conn) {
if (pageProperties == null) {
pageProperties = new Hashtable();
pageProperties = new Hashtable<String, Object>();
}
String type = conn.getContentType();
if (type != null) {
......@@ -989,7 +988,7 @@ public class JEditorPane extends JTextComponent {
* of the content type in the http header information.
*/
private void setCharsetFromContentTypeParameters(String paramlist) {
String charset = null;
String charset;
try {
// paramlist is handed to us with a leading ';', strip it.
int semi = paramlist.indexOf(';');
......@@ -1080,9 +1079,9 @@ public class JEditorPane extends JTextComponent {
*/
public EditorKit getEditorKitForContentType(String type) {
if (typeHandlers == null) {
typeHandlers = new Hashtable(3);
typeHandlers = new Hashtable<String, EditorKit>(3);
}
EditorKit k = (EditorKit) typeHandlers.get(type);
EditorKit k = typeHandlers.get(type);
if (k == null) {
k = createEditorKitForContentType(type);
if (k != null) {
......@@ -1106,7 +1105,7 @@ public class JEditorPane extends JTextComponent {
*/
public void setEditorKitForContentType(String type, EditorKit k) {
if (typeHandlers == null) {
typeHandlers = new Hashtable(3);
typeHandlers = new Hashtable<String, EditorKit>(3);
}
typeHandlers.put(type, k);
}
......@@ -1176,13 +1175,12 @@ public class JEditorPane extends JTextComponent {
* registered for the given type
*/
public static EditorKit createEditorKitForContentType(String type) {
EditorKit k = null;
Hashtable kitRegistry = getKitRegisty();
k = (EditorKit) kitRegistry.get(type);
Hashtable<String, EditorKit> kitRegistry = getKitRegisty();
EditorKit k = kitRegistry.get(type);
if (k == null) {
// try to dynamically load the support
String classname = (String) getKitTypeRegistry().get(type);
ClassLoader loader = (ClassLoader) getKitLoaderRegistry().get(type);
String classname = getKitTypeRegistry().get(type);
ClassLoader loader = getKitLoaderRegistry().get(type);
try {
Class c;
if (loader != null) {
......@@ -1252,20 +1250,20 @@ public class JEditorPane extends JTextComponent {
* @since 1.3
*/
public static String getEditorKitClassNameForContentType(String type) {
return (String)getKitTypeRegistry().get(type);
return getKitTypeRegistry().get(type);
}
private static Hashtable getKitTypeRegistry() {
private static Hashtable<String, String> getKitTypeRegistry() {
loadDefaultKitsIfNecessary();
return (Hashtable)SwingUtilities.appContextGet(kitTypeRegistryKey);
}
private static Hashtable getKitLoaderRegistry() {
private static Hashtable<String, ClassLoader> getKitLoaderRegistry() {
loadDefaultKitsIfNecessary();
return (Hashtable)SwingUtilities.appContextGet(kitLoaderRegistryKey);
}
private static Hashtable getKitRegisty() {
private static Hashtable<String, EditorKit> getKitRegisty() {
Hashtable ht = (Hashtable)SwingUtilities.appContextGet(kitRegistryKey);
if (ht == null) {
ht = new Hashtable(3);
......@@ -1512,7 +1510,7 @@ public class JEditorPane extends JTextComponent {
private EditorKit kit;
private boolean isUserSetEditorKit;
private Hashtable pageProperties;
private Hashtable<String, Object> pageProperties;
/** Should be kept in sync with javax.swing.text.html.FormView counterpart. */
final static String PostDataProperty = "javax.swing.JEditorPane.postdata";
......@@ -1520,7 +1518,7 @@ public class JEditorPane extends JTextComponent {
/**
* Table of registered type handlers for this editor.
*/
private Hashtable typeHandlers;
private Hashtable<String, EditorKit> typeHandlers;
/*
* Private AppContext keys for this class's static variables.
......@@ -1913,11 +1911,11 @@ public class JEditorPane extends JTextComponent {
}
}
private class LinkVector extends Vector {
private class LinkVector extends Vector<HTMLLink> {
public int baseElementIndex(Element e) {
HTMLLink l;
for (int i = 0; i < elementCount; i++) {
l = (HTMLLink) elementAt(i);
l = elementAt(i);
if (l.element == e) {
return i;
}
......@@ -2029,7 +2027,7 @@ public class JEditorPane extends JTextComponent {
buildLinkTable();
}
if (linkIndex >= 0 && linkIndex < hyperlinks.size()) {
return (AccessibleHyperlink) hyperlinks.elementAt(linkIndex);
return hyperlinks.elementAt(linkIndex);
} else {
return null;
}
......
......@@ -248,7 +248,7 @@ public class JFileChooser extends JComponent implements Accessible {
private String approveButtonToolTipText = null;
private int approveButtonMnemonic = 0;
private Vector filters = new Vector(5);
private Vector<FileFilter> filters = new Vector<FileFilter>(5);
private JDialog dialog = null;
private int dialogType = OPEN_DIALOG;
private int returnValue = ERROR_OPTION;
......@@ -503,7 +503,7 @@ public class JFileChooser extends JComponent implements Accessible {
if(selectedFiles == null) {
return new File[0];
} else {
return (File[]) selectedFiles.clone();
return selectedFiles.clone();
}
}
......@@ -1415,17 +1415,17 @@ public class JFileChooser extends JComponent implements Accessible {
fileFilter = filter;
if (filter != null) {
if (isMultiSelectionEnabled() && selectedFiles != null && selectedFiles.length > 0) {
Vector fList = new Vector();
Vector<File> fList = new Vector<File>();
boolean failed = false;
for (int i = 0; i < selectedFiles.length; i++) {
if (filter.accept(selectedFiles[i])) {
fList.add(selectedFiles[i]);
for (File file : selectedFiles) {
if (filter.accept(file)) {
fList.add(file);
} else {
failed = true;
}
}
if (failed) {
setSelectedFiles((fList.size() == 0) ? null : (File[])fList.toArray(new File[fList.size()]));
setSelectedFiles((fList.size() == 0) ? null : fList.toArray(new File[fList.size()]));
}
} else if (selectedFile != null && !filter.accept(selectedFile)) {
setSelectedFile(null);
......@@ -1702,8 +1702,7 @@ public class JFileChooser extends JComponent implements Accessible {
* @since 1.4
*/
public ActionListener[] getActionListeners() {
return (ActionListener[])listenerList.getListeners(
ActionListener.class);
return listenerList.getListeners(ActionListener.class);
}
/**
......@@ -1744,7 +1743,7 @@ public class JFileChooser extends JComponent implements Accessible {
WeakReference<JFileChooser> jfcRef;
public WeakPCL(JFileChooser jfc) {
jfcRef = new WeakReference(jfc);
jfcRef = new WeakReference<JFileChooser>(jfc);
}
public void propertyChange(PropertyChangeEvent ev) {
assert ev.getPropertyName().equals(SHOW_HIDDEN_PROP);
......
......@@ -421,8 +421,8 @@ public class JInternalFrame extends JComponent implements
invalidate();
Component[] children = getComponents();
if (children != null) {
for(int i = 0; i < children.length; i++) {
SwingUtilities.updateComponentTreeUI(children[i]);
for (Component child : children) {
SwingUtilities.updateComponentTreeUI(child);
}
}
}
......@@ -1535,8 +1535,7 @@ public class JInternalFrame extends JComponent implements
* @see #addInternalFrameListener
*/
public InternalFrameListener[] getInternalFrameListeners() {
return (InternalFrameListener[])listenerList.getListeners(
InternalFrameListener.class);
return listenerList.getListeners(InternalFrameListener.class);
}
// remind: name ok? all one method ok? need to be synchronized?
......@@ -2258,8 +2257,8 @@ public class JInternalFrame extends JComponent implements
invalidate();
Component[] children = getComponents();
if (children != null) {
for(int i = 0; i < children.length; i++) {
SwingUtilities.updateComponentTreeUI(children[i]);
for (Component child : children) {
SwingUtilities.updateComponentTreeUI(child);
}
}
}
......
......@@ -191,7 +191,7 @@ public class JLayeredPane extends JComponent implements Accessible {
private void validateOptimizedDrawing() {
boolean layeredComponentFound = false;
synchronized(getTreeLock()) {
Integer layer = null;
Integer layer;
for (Component c : getComponents()) {
layer = null;
......@@ -213,7 +213,7 @@ public class JLayeredPane extends JComponent implements Accessible {
}
protected void addImpl(Component comp, Object constraints, int index) {
int layer = DEFAULT_LAYER.intValue();
int layer;
int pos;
if(constraints instanceof Integer) {
......@@ -364,7 +364,7 @@ public class JLayeredPane extends JComponent implements Accessible {
if(c instanceof JComponent)
((JComponent)c).putClientProperty(LAYER_PROPERTY, layerObj);
else
getComponentToLayer().put((Component)c, layerObj);
getComponentToLayer().put(c, layerObj);
if(c.getParent() == null || c.getParent() != this) {
repaint(c.getBounds());
......@@ -388,7 +388,7 @@ public class JLayeredPane extends JComponent implements Accessible {
if(c instanceof JComponent)
i = (Integer)((JComponent)c).getClientProperty(LAYER_PROPERTY);
else
i = (Integer)getComponentToLayer().get((Component)c);
i = getComponentToLayer().get(c);
if(i == null)
return DEFAULT_LAYER.intValue();
......@@ -465,9 +465,9 @@ public class JLayeredPane extends JComponent implements Accessible {
* @see #getComponentCountInLayer
*/
public int getPosition(Component c) {
int i, count, startLayer, curLayer, startLocation, pos = 0;
int i, startLayer, curLayer, startLocation, pos = 0;
count = getComponentCount();
getComponentCount();
startLocation = getIndexOf(c);
if(startLocation == -1)
......
......@@ -1848,8 +1848,7 @@ public class JList extends JComponent implements Scrollable, Accessible
* @since 1.4
*/
public ListSelectionListener[] getListSelectionListeners() {
return (ListSelectionListener[])listenerList.getListeners(
ListSelectionListener.class);
return listenerList.getListeners(ListSelectionListener.class);
}
......@@ -2220,9 +2219,9 @@ public class JList extends JComponent implements Scrollable, Accessible
ListSelectionModel sm = getSelectionModel();
sm.clearSelection();
int size = getModel().getSize();
for(int i = 0; i < indices.length; i++) {
if (indices[i] < size) {
sm.addSelectionInterval(indices[i], indices[i]);
for (int i : indices) {
if (i < size) {
sm.addSelectionInterval(i, i);
}
}
}
......@@ -2724,7 +2723,7 @@ public class JList extends JComponent implements Scrollable, Accessible
return true;
}
if (getParent() instanceof JViewport) {
return (((JViewport)getParent()).getWidth() > getPreferredSize().width);
return (getParent().getWidth() > getPreferredSize().width);
}
return false;
}
......@@ -2749,7 +2748,7 @@ public class JList extends JComponent implements Scrollable, Accessible
return true;
}
if (getParent() instanceof JViewport) {
return (((JViewport)getParent()).getHeight() > getPreferredSize().height);
return (getParent().getHeight() > getPreferredSize().height);
}
return false;
}
......@@ -3161,7 +3160,7 @@ public class JList extends JComponent implements Scrollable, Accessible
private AccessibleContext getCurrentAccessibleContext() {
Component c = getComponentAtIndex(indexInParent);
if (c instanceof Accessible) {
return ((Accessible) c).getAccessibleContext();
return c.getAccessibleContext();
} else {
return null;
}
......
......@@ -371,8 +371,8 @@ public class JMenu extends JMenuItem implements Accessible,MenuElement
* @since 1.3
*/
protected Point getPopupMenuOrigin() {
int x = 0;
int y = 0;
int x;
int y;
JPopupMenu pm = getPopupMenu();
// Figure out the sizes needed to caclulate the menu position
Dimension s = getSize();
......@@ -900,10 +900,8 @@ public class JMenu extends JMenuItem implements Accessible,MenuElement
* on another menu
*/
public boolean isTopLevelMenu() {
if (getParent() instanceof JMenuBar)
return true;
return getParent() instanceof JMenuBar;
return false;
}
/**
......@@ -1015,7 +1013,7 @@ public class JMenu extends JMenuItem implements Accessible,MenuElement
* @since 1.4
*/
public MenuListener[] getMenuListeners() {
return (MenuListener[])listenerList.getListeners(MenuListener.class);
return listenerList.getListeners(MenuListener.class);
}
/**
......@@ -1305,7 +1303,7 @@ public class JMenu extends JMenuItem implements Accessible,MenuElement
* @return the array of menu items
*/
private MenuElement[] buildMenuElementArray(JMenu leaf) {
Vector elements = new Vector();
Vector<MenuElement> elements = new Vector<MenuElement>();
Component current = leaf.getPopupMenu();
JPopupMenu pop;
JMenu menu;
......@@ -1409,8 +1407,8 @@ public class JMenu extends JMenuItem implements Accessible,MenuElement
public int getAccessibleChildrenCount() {
Component[] children = getMenuComponents();
int count = 0;
for (int j = 0; j < children.length; j++) {
if (children[j] instanceof Accessible) {
for (Component child : children) {
if (child instanceof Accessible) {
count++;
}
}
......@@ -1426,18 +1424,18 @@ public class JMenu extends JMenuItem implements Accessible,MenuElement
public Accessible getAccessibleChild(int i) {
Component[] children = getMenuComponents();
int count = 0;
for (int j = 0; j < children.length; j++) {
if (children[j] instanceof Accessible) {
for (Component child : children) {
if (child instanceof Accessible) {
if (count == i) {
if (children[j] instanceof JComponent) {
if (child instanceof JComponent) {
// FIXME: [[[WDW - probably should set this when
// the component is added to the menu. I tried
// to do this in most cases, but the separators
// added by addSeparator are hard to get to.]]]
AccessibleContext ac = ((Accessible) children[j]).getAccessibleContext();
AccessibleContext ac = child.getAccessibleContext();
ac.setAccessibleParent(JMenu.this);
}
return (Accessible) children[j];
return (Accessible) child;
} else {
count++;
}
......@@ -1581,7 +1579,7 @@ public class JMenu extends JMenuItem implements Accessible,MenuElement
}
JMenuItem mi = getItem(i);
if (mi != null && mi instanceof JMenu) {
if (((JMenu) mi).isSelected()) {
if (mi.isSelected()) {
MenuElement old[] =
MenuSelectionManager.defaultManager().getSelectedPath();
MenuElement me[] = new MenuElement[old.length-2];
......
......@@ -414,7 +414,7 @@ public class JMenuBar extends JComponent implements Accessible,MenuElement
*/
public MenuElement[] getSubElements() {
MenuElement result[];
Vector tmp = new Vector();
Vector<MenuElement> tmp = new Vector<MenuElement>();
int c = getComponentCount();
int i;
Component m;
......@@ -422,12 +422,12 @@ public class JMenuBar extends JComponent implements Accessible,MenuElement
for(i=0 ; i < c ; i++) {
m = getComponent(i);
if(m instanceof MenuElement)
tmp.addElement(m);
tmp.addElement((MenuElement) m);
}
result = new MenuElement[tmp.size()];
for(i=0,c=tmp.size() ; i < c ; i++)
result[i] = (MenuElement) tmp.elementAt(i);
result[i] = tmp.elementAt(i);
return result;
}
......@@ -664,9 +664,9 @@ public class JMenuBar extends JComponent implements Accessible,MenuElement
boolean retValue = super.processKeyBinding(ks, e, condition, pressed);
if (!retValue) {
MenuElement[] subElements = getSubElements();
for (int i=0; i<subElements.length; i++) {
for (MenuElement subElement : subElements) {
if (processBindingForKeyStrokeRecursive(
subElements[i], ks, e, condition, pressed)) {
subElement, ks, e, condition, pressed)) {
return true;
}
}
......@@ -693,9 +693,8 @@ public class JMenuBar extends JComponent implements Accessible,MenuElement
}
MenuElement[] subElements = elem.getSubElements();
for(int i=0; i<subElements.length; i++) {
if (processBindingForKeyStrokeRecursive(subElements[i], ks, e,
condition, pressed)) {
for (MenuElement subElement : subElements) {
if (processBindingForKeyStrokeRecursive(subElement, ks, e, condition, pressed)) {
return true;
// We don't, pass along to children JMenu's
}
......
......@@ -275,7 +275,7 @@ public class JMenuItem extends AbstractButton implements Accessible,MenuElement
* hidden: true
*/
public void setArmed(boolean b) {
ButtonModel model = (ButtonModel) getModel();
ButtonModel model = getModel();
boolean oldValue = model.isArmed();
if(model.isArmed() != b) {
......@@ -290,7 +290,7 @@ public class JMenuItem extends AbstractButton implements Accessible,MenuElement
* @see #setArmed
*/
public boolean isArmed() {
ButtonModel model = (ButtonModel) getModel();
ButtonModel model = getModel();
return model.isArmed();
}
......@@ -721,8 +721,7 @@ public class JMenuItem extends AbstractButton implements Accessible,MenuElement
* @since 1.4
*/
public MenuDragMouseListener[] getMenuDragMouseListeners() {
return (MenuDragMouseListener[])listenerList.getListeners(
MenuDragMouseListener.class);
return listenerList.getListeners(MenuDragMouseListener.class);
}
/**
......@@ -752,8 +751,7 @@ public class JMenuItem extends AbstractButton implements Accessible,MenuElement
* @since 1.4
*/
public MenuKeyListener[] getMenuKeyListeners() {
return (MenuKeyListener[])listenerList.getListeners(
MenuKeyListener.class);
return listenerList.getListeners(MenuKeyListener.class);
}
/**
......
......@@ -963,7 +963,7 @@ public class JOptionPane extends JComponent implements Accessible
}
if (window instanceof SwingUtilities.SharedOwnerFrame) {
WindowListener ownerShutdownListener =
(WindowListener)SwingUtilities.getSharedOwnerFrameShutdownListener();
SwingUtilities.getSharedOwnerFrameShutdownListener();
dialog.addWindowListener(ownerShutdownListener);
}
initDialog(dialog, style, parentComponent);
......@@ -1300,11 +1300,10 @@ public class JOptionPane extends JComponent implements Accessible
// Use reflection to get Container.startLWModal.
try {
Object obj;
obj = AccessController.doPrivileged(new ModalPrivilegedAction(
Method method = AccessController.doPrivileged(new ModalPrivilegedAction(
Container.class, "startLWModal"));
if (obj != null) {
((Method)obj).invoke(dialog, (Object[])null);
if (method != null) {
method.invoke(dialog, (Object[])null);
}
} catch (IllegalAccessException ex) {
} catch (IllegalArgumentException ex) {
......@@ -1446,11 +1445,10 @@ public class JOptionPane extends JComponent implements Accessible
// Use reflection to get Container.startLWModal.
try {
Object obj;
obj = AccessController.doPrivileged(new ModalPrivilegedAction(
Method method = AccessController.doPrivileged(new ModalPrivilegedAction(
Container.class, "startLWModal"));
if (obj != null) {
((Method)obj).invoke(dialog, (Object[])null);
if (method != null) {
method.invoke(dialog, (Object[])null);
}
} catch (IllegalAccessException ex) {
} catch (IllegalArgumentException ex) {
......@@ -1531,12 +1529,11 @@ public class JOptionPane extends JComponent implements Accessible
event.getPropertyName().equals(VALUE_PROPERTY)) {
// Use reflection to get Container.stopLWModal().
try {
Object obj;
obj = AccessController.doPrivileged(
Method method = AccessController.doPrivileged(
new ModalPrivilegedAction(
Container.class, "stopLWModal"));
if (obj != null) {
((Method)obj).invoke(iFrame, (Object[])null);
if (method != null) {
method.invoke(iFrame, (Object[])null);
}
} catch (IllegalAccessException ex) {
} catch (IllegalArgumentException ex) {
......@@ -1852,7 +1849,7 @@ public class JOptionPane extends JComponent implements Accessible
* description: The UI object that implements the optionpane's LookAndFeel
*/
public void setUI(OptionPaneUI ui) {
if ((OptionPaneUI)this.ui != ui) {
if (this.ui != ui) {
super.setUI(ui);
invalidate();
}
......@@ -2327,7 +2324,7 @@ public class JOptionPane extends JComponent implements Accessible
// Serialization support.
private void writeObject(ObjectOutputStream s) throws IOException {
Vector values = new Vector();
Vector<Object> values = new Vector<Object>();
s.defaultWriteObject();
// Save the icon, if its Serializable.
......@@ -2342,7 +2339,7 @@ public class JOptionPane extends JComponent implements Accessible
}
// Save the treeModel, if its Serializable.
if(options != null) {
Vector serOptions = new Vector();
Vector<Object> serOptions = new Vector<Object>();
for(int counter = 0, maxCounter = options.length;
counter < maxCounter; counter++)
......@@ -2510,16 +2507,16 @@ public class JOptionPane extends JComponent implements Accessible
/**
* Retrieves a method from the provided class and makes it accessible.
*/
private static class ModalPrivilegedAction implements PrivilegedAction {
private Class clazz;
private static class ModalPrivilegedAction implements PrivilegedAction<Method> {
private Class<?> clazz;
private String methodName;
public ModalPrivilegedAction(Class clazz, String methodName) {
public ModalPrivilegedAction(Class<?> clazz, String methodName) {
this.clazz = clazz;
this.methodName = methodName;
}
public Object run() {
public Method run() {
Method method = null;
try {
method = clazz.getDeclaredMethod(methodName, (Class[])null);
......
......@@ -584,7 +584,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
int nitems = getComponentCount();
// PENDING(ges): Why not use an array?
Vector tempItems = new Vector();
Vector<Component> tempItems = new Vector<Component>();
/* Remove the item at index, nitems-index times
storing them in a temporary vector in the
......@@ -600,8 +600,8 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
/* Add the removed items back to the menu, they are
already in the correct order in the temp vector.
*/
for (int i = 0; i < tempItems.size() ; i++) {
add((Component)tempItems.elementAt(i));
for (Component tempItem : tempItems) {
add(tempItem);
}
}
......@@ -632,8 +632,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
* @since 1.4
*/
public PopupMenuListener[] getPopupMenuListeners() {
return (PopupMenuListener[])listenerList.getListeners(
PopupMenuListener.class);
return listenerList.getListeners(PopupMenuListener.class);
}
/**
......@@ -665,8 +664,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
* @since 1.5
*/
public MenuKeyListener[] getMenuKeyListeners() {
return (MenuKeyListener[])listenerList.getListeners(
MenuKeyListener.class);
return listenerList.getListeners(MenuKeyListener.class);
}
/**
......@@ -781,7 +779,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
// set selection path before popping up!
if (isPopupMenu()) {
MenuElement me[] = new MenuElement[1];
me[0] = (MenuElement) this;
me[0] = this;
MenuSelectionManager.defaultManager().setSelectedPath(me);
}
}
......@@ -848,10 +846,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
* being displayed).
*/
public boolean isVisible() {
if(popup != null)
return true;
else
return false;
return popup != null;
}
/**
......@@ -1311,7 +1306,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
// Serialization support.
////////////
private void writeObject(ObjectOutputStream s) throws IOException {
Vector values = new Vector();
Vector<Object> values = new Vector<Object>();
s.defaultWriteObject();
// Save the invoker, if its Serializable.
......@@ -1494,7 +1489,7 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
*/
public MenuElement[] getSubElements() {
MenuElement result[];
Vector tmp = new Vector();
Vector<MenuElement> tmp = new Vector<MenuElement>();
int c = getComponentCount();
int i;
Component m;
......@@ -1502,12 +1497,12 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
for(i=0 ; i < c ; i++) {
m = getComponent(i);
if(m instanceof MenuElement)
tmp.addElement(m);
tmp.addElement((MenuElement) m);
}
result = new MenuElement[tmp.size()];
for(i=0,c=tmp.size() ; i < c ; i++)
result[i] = (MenuElement) tmp.elementAt(i);
result[i] = tmp.elementAt(i);
return result;
}
......
......@@ -699,8 +699,7 @@ public class JProgressBar extends JComponent implements SwingConstants, Accessib
* @since 1.4
*/
public ChangeListener[] getChangeListeners() {
return (ChangeListener[])listenerList.getListeners(
ChangeListener.class);
return listenerList.getListeners(ChangeListener.class);
}
/**
......
......@@ -659,8 +659,7 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible
* @since 1.4
*/
public AdjustmentListener[] getAdjustmentListeners() {
return (AdjustmentListener[])listenerList.getListeners(
AdjustmentListener.class);
return listenerList.getListeners(AdjustmentListener.class);
}
......@@ -754,8 +753,8 @@ public class JScrollBar extends JComponent implements Adjustable, Accessible
public void setEnabled(boolean x) {
super.setEnabled(x);
Component[] children = getComponents();
for(int i = 0; i < children.length; i++) {
children[i].setEnabled(x);
for (Component child : children) {
child.setEnabled(x);
}
}
......
......@@ -930,7 +930,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible {
throw new IllegalArgumentException( "Label incremement must be > 0" );
}
class SmartHashtable extends Hashtable implements PropertyChangeListener {
class SmartHashtable extends Hashtable<Object, Object> implements PropertyChangeListener {
int increment = 0;
int start = 0;
boolean startAtMin = false;
......@@ -977,9 +977,8 @@ public class JSlider extends JComponent implements SwingConstants, Accessible {
if ( e.getPropertyName().equals( "minimum" ) ||
e.getPropertyName().equals( "maximum" ) ) {
Dictionary labelTable = getLabelTable();
Enumeration keys = labelTable.keys();
Hashtable hashtable = new Hashtable();
Enumeration keys = getLabelTable().keys();
Hashtable<Object, Object> hashtable = new Hashtable<Object, Object>();
// Save the labels that were added by the developer
while ( keys.hasMoreElements() ) {
......
......@@ -433,8 +433,7 @@ public class JSpinner extends JComponent implements Accessible
* @since 1.4
*/
public ChangeListener[] getChangeListeners() {
return (ChangeListener[])listenerList.getListeners(
ChangeListener.class);
return listenerList.getListeners(ChangeListener.class);
}
......@@ -1536,7 +1535,7 @@ public class JSpinner extends JComponent implements Accessible
return textField.getAccessibleContext();
}
} else if (editor instanceof Accessible) {
return ((Accessible)editor).getAccessibleContext();
return editor.getAccessibleContext();
}
return null;
}
......@@ -1693,7 +1692,7 @@ public class JSpinner extends JComponent implements Accessible
if (i < 0 || i > 1) {
return false;
}
Object o = null;
Object o;
if (i == 0) {
o = getNextValue(); // AccessibleAction.INCREMENT
} else {
......
......@@ -313,8 +313,7 @@ public class JTabbedPane extends JComponent
* @since 1.4
*/
public ChangeListener[] getChangeListeners() {
return (ChangeListener[])listenerList.getListeners(
ChangeListener.class);
return listenerList.getListeners(ChangeListener.class);
}
/**
......@@ -2062,7 +2061,7 @@ public class JTabbedPane extends JComponent
* Accessibility classes unnecessarily.
*/
AccessibleContext ac;
ac = ((Accessible) component).getAccessibleContext();
ac = component.getAccessibleContext();
if (ac != null) {
ac.setAccessibleParent(this);
}
......
......@@ -1677,16 +1677,16 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
if (!forDrop && state != null) {
clearSelection();
int[] rows = (int[])((int[][])state)[0];
int[] cols = (int[])((int[][])state)[1];
int[] anchleads = (int[])((int[][])state)[2];
int[] rows = ((int[][])state)[0];
int[] cols = ((int[][])state)[1];
int[] anchleads = ((int[][])state)[2];
for (int i = 0; i < rows.length; i++) {
addRowSelectionInterval(rows[i], rows[i]);
for (int row : rows) {
addRowSelectionInterval(row, row);
}
for (int i = 0; i < cols.length; i++) {
addColumnSelectionInterval(cols[i], cols[i]);
for (int col : cols) {
addColumnSelectionInterval(col, col);
}
SwingUtilities2.setLeadAnchorWithoutSelection(
......@@ -1776,7 +1776,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
boolean oldValue = this.autoCreateRowSorter;
this.autoCreateRowSorter = autoCreateRowSorter;
if (autoCreateRowSorter) {
setRowSorter(new TableRowSorter(getModel()));
setRowSorter(new TableRowSorter<TableModel>(getModel()));
}
firePropertyChange("autoCreateRowSorter", oldValue,
autoCreateRowSorter);
......@@ -3198,7 +3198,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
private void accommodateDelta(int resizingColumnIndex, int delta) {
int columnCount = getColumnCount();
int from = resizingColumnIndex;
int to = columnCount;
int to;
// Use the mode to determine how to absorb the changes.
switch(autoResizeMode) {
......@@ -3237,8 +3237,6 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
}
adjustSizes(totalWidth + delta, r, false);
return;
}
private interface Resizable2 {
......@@ -3492,7 +3490,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
* @see #editingRow
*/
public boolean isEditing() {
return (cellEditor == null)? false : true;
return cellEditor != null;
}
/**
......@@ -3642,7 +3640,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
firePropertyChange("model", old, dataModel);
if (getAutoCreateRowSorter()) {
setRowSorter(new TableRowSorter(dataModel));
setRowSorter(new TableRowSorter<TableModel>(dataModel));
}
}
}
......@@ -5160,7 +5158,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
public boolean getScrollableTracksViewportHeight() {
return getFillsViewportHeight()
&& getParent() instanceof JViewport
&& (((JViewport)getParent()).getHeight() > getPreferredSize().height);
&& (getParent().getHeight() > getPreferredSize().height);
}
/**
......@@ -5214,7 +5212,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
// by setting the client property JTable.autoStartsEdit to Boolean.FALSE.
if (!retValue && condition == WHEN_ANCESTOR_OF_FOCUSED_COMPONENT &&
isFocusOwner() &&
!Boolean.FALSE.equals((Boolean)getClientProperty("JTable.autoStartsEdit"))) {
!Boolean.FALSE.equals(getClientProperty("JTable.autoStartsEdit"))) {
// We do not have a binding for the event.
Component editorComponent = getEditorComponent();
if (editorComponent == null) {
......@@ -5436,7 +5434,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
this.value = null;
((JComponent)getComponent()).setBorder(new LineBorder(Color.black));
try {
Class type = table.getColumnClass(column);
Class<?> type = table.getColumnClass(column);
// Since our obligation is to produce a value which is
// assignable for the required type it is OK to use the
// String constructor for columns which are declared
......@@ -6627,10 +6625,10 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
} else if (name.compareTo("tableCellEditor") == 0) {
if (oldValue != null && oldValue instanceof TableCellEditor) {
((TableCellEditor) oldValue).removeCellEditorListener((CellEditorListener) this);
((TableCellEditor) oldValue).removeCellEditorListener(this);
}
if (newValue != null && newValue instanceof TableCellEditor) {
((TableCellEditor) newValue).addCellEditorListener((CellEditorListener) this);
((TableCellEditor) newValue).addCellEditorListener(this);
}
}
}
......@@ -7045,7 +7043,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
*/
public Accessible getAccessibleSelection(int i) {
if (i < 0 || i > getAccessibleSelectionCount()) {
return (Accessible) null;
return null;
}
int rowsSel = JTable.this.getSelectedRowCount();
......@@ -7158,7 +7156,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
return getAccessibleChild((r * ttlCols) + c);
}
}
return (Accessible) null;
return null;
}
/**
......@@ -7906,7 +7904,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
JTable.this, getValueAt(row, column),
false, false, row, column);
if (component instanceof Accessible) {
return ((Accessible) component).getAccessibleContext();
return component.getAccessibleContext();
} else {
return null;
}
......
......@@ -475,8 +475,7 @@ public class JTextField extends JTextComponent implements SwingConstants {
* @since 1.4
*/
public synchronized ActionListener[] getActionListeners() {
return (ActionListener[])listenerList.getListeners(
ActionListener.class);
return listenerList.getListeners(ActionListener.class);
}
/**
......
......@@ -187,7 +187,7 @@ public class JTree extends JComponent implements Scrollable, Accessible
* information must be determined by visiting all the parent
* paths and seeing if they are visible.
*/
transient private Hashtable expandedState;
transient private Hashtable<TreePath, Boolean> expandedState;
/**
......@@ -281,7 +281,7 @@ public class JTree extends JComponent implements Scrollable, Accessible
* Used when <code>setExpandedState</code> is invoked,
* will be a <code>Stack</code> of <code>Stack</code>s.
*/
transient private Stack expandedStack;
transient private Stack<Stack<TreePath>> expandedStack;
/**
* Lead selection path, may not be <code>null</code>.
......@@ -652,9 +652,9 @@ public class JTree extends JComponent implements Scrollable, Accessible
@ConstructorProperties({"model"})
public JTree(TreeModel newModel) {
super();
expandedStack = new Stack();
expandedStack = new Stack<Stack<TreePath>>();
toggleClickCount = 2;
expandedState = new Hashtable();
expandedState = new Hashtable<TreePath, Boolean>();
setLayout(null);
rowHeight = 16;
visibleRowCount = 20;
......@@ -691,7 +691,7 @@ public class JTree extends JComponent implements Scrollable, Accessible
* description: The UI object that implements the Component's LookAndFeel.
*/
public void setUI(TreeUI ui) {
if ((TreeUI)this.ui != ui) {
if (this.ui != ui) {
settingUI = true;
uiTreeExpansionListener = null;
try {
......@@ -1298,8 +1298,8 @@ public class JTree extends JComponent implements Scrollable, Accessible
Object root = (model == null) ? null : model.getRoot();
TreePath rootPath = (root == null) ? null : new TreePath(root);
TreePath child = null;
TreePath parent = null;
TreePath child;
TreePath parent;
boolean outside = row == -1
|| p.y < bounds.y
|| p.y >= bounds.y + bounds.height;
......@@ -1940,14 +1940,14 @@ public class JTree extends JComponent implements Scrollable, Accessible
if(!isExpanded(parent))
return null;
Enumeration toggledPaths = expandedState.keys();
Vector elements = null;
Enumeration<TreePath> toggledPaths = expandedState.keys();
Vector<TreePath> elements = null;
TreePath path;
Object value;
if(toggledPaths != null) {
while(toggledPaths.hasMoreElements()) {
path = (TreePath)toggledPaths.nextElement();
path = toggledPaths.nextElement();
value = expandedState.get(path);
// Add the path if it is expanded, a descendant of parent,
// and it is visible (all parents expanded). This is rather
......@@ -1956,7 +1956,7 @@ public class JTree extends JComponent implements Scrollable, Accessible
((Boolean)value).booleanValue() &&
parent.isDescendant(path) && isVisible(path)) {
if (elements == null) {
elements = new Vector();
elements = new Vector<TreePath>();
}
elements.addElement(path);
}
......@@ -1990,9 +1990,9 @@ public class JTree extends JComponent implements Scrollable, Accessible
return false;
// Is this node expanded?
Object value = expandedState.get(path);
Boolean value = expandedState.get(path);
if(value == null || !((Boolean)value).booleanValue())
if(value == null || !value.booleanValue())
return false;
// It is, make sure its parent is also expanded.
......@@ -2018,7 +2018,7 @@ public class JTree extends JComponent implements Scrollable, Accessible
TreePath path = tree.getPathForRow(this, row);
if(path != null) {
Boolean value = (Boolean)expandedState.get(path);
Boolean value = expandedState.get(path);
return (value != null && value.booleanValue());
}
......@@ -2704,8 +2704,7 @@ public class JTree extends JComponent implements Scrollable, Accessible
* @since 1.4
*/
public TreeExpansionListener[] getTreeExpansionListeners() {
return (TreeExpansionListener[])listenerList.getListeners(
TreeExpansionListener.class);
return listenerList.getListeners(TreeExpansionListener.class);
}
/**
......@@ -2737,8 +2736,7 @@ public class JTree extends JComponent implements Scrollable, Accessible
* @since 1.4
*/
public TreeWillExpandListener[] getTreeWillExpandListeners() {
return (TreeWillExpandListener[])listenerList.getListeners(
TreeWillExpandListener.class);
return listenerList.getListeners(TreeWillExpandListener.class);
}
/**
......@@ -2895,8 +2893,7 @@ public class JTree extends JComponent implements Scrollable, Accessible
* @since 1.4
*/
public TreeSelectionListener[] getTreeSelectionListeners() {
return (TreeSelectionListener[])listenerList.getListeners(
TreeSelectionListener.class);
return listenerList.getListeners(TreeSelectionListener.class);
}
/**
......@@ -3030,7 +3027,7 @@ public class JTree extends JComponent implements Scrollable, Accessible
// Serialization support.
private void writeObject(ObjectOutputStream s) throws IOException {
Vector values = new Vector();
Vector<Object> values = new Vector<Object>();
s.defaultWriteObject();
// Save the cellRenderer, if its Serializable.
......@@ -3077,9 +3074,9 @@ public class JTree extends JComponent implements Scrollable, Accessible
// Create an instance of expanded state.
expandedState = new Hashtable();
expandedState = new Hashtable<TreePath, Boolean>();
expandedStack = new Stack();
expandedStack = new Stack<Stack<TreePath>>();
Vector values = (Vector)s.readObject();
int indexCounter = 0;
......@@ -3132,13 +3129,13 @@ public class JTree extends JComponent implements Scrollable, Accessible
TreeModel model = getModel();
if(model != null) {
Enumeration paths = expandedState.keys();
Enumeration<TreePath> paths = expandedState.keys();
if(paths != null) {
Vector state = new Vector();
Vector<Object> state = new Vector<Object>();
while(paths.hasMoreElements()) {
TreePath path = (TreePath)paths.nextElement();
TreePath path = paths.nextElement();
Object archivePath;
try {
......@@ -3502,7 +3499,7 @@ public class JTree extends JComponent implements Scrollable, Accessible
*/
public boolean getScrollableTracksViewportWidth() {
if (getParent() instanceof JViewport) {
return (((JViewport)getParent()).getWidth() > getPreferredSize().width);
return getParent().getWidth() > getPreferredSize().width;
}
return false;
}
......@@ -3518,7 +3515,7 @@ public class JTree extends JComponent implements Scrollable, Accessible
*/
public boolean getScrollableTracksViewportHeight() {
if (getParent() instanceof JViewport) {
return (((JViewport)getParent()).getHeight() > getPreferredSize().height);
return getParent().getHeight() > getPreferredSize().height;
}
return false;
}
......@@ -3535,14 +3532,14 @@ public class JTree extends JComponent implements Scrollable, Accessible
protected void setExpandedState(TreePath path, boolean state) {
if(path != null) {
// Make sure all parents of path are expanded.
Stack stack;
Stack<TreePath> stack;
TreePath parentPath = path.getParentPath();
if (expandedStack.size() == 0) {
stack = new Stack();
stack = new Stack<TreePath>();
}
else {
stack = (Stack)expandedStack.pop();
stack = expandedStack.pop();
}
try {
......@@ -3556,7 +3553,7 @@ public class JTree extends JComponent implements Scrollable, Accessible
}
}
for(int counter = stack.size() - 1; counter >= 0; counter--) {
parentPath = (TreePath)stack.pop();
parentPath = stack.pop();
if(!isExpanded(parentPath)) {
try {
fireTreeWillExpand(parentPath);
......@@ -3636,12 +3633,11 @@ public class JTree extends JComponent implements Scrollable, Accessible
if(parent == null)
return null;
Vector descendants = new Vector();
Enumeration nodes = expandedState.keys();
TreePath path;
Vector<TreePath> descendants = new Vector<TreePath>();
Enumeration<TreePath> nodes = expandedState.keys();
while(nodes.hasMoreElements()) {
path = (TreePath)nodes.nextElement();
TreePath path = nodes.nextElement();
if(parent.isDescendant(path))
descendants.addElement(path);
}
......@@ -3665,7 +3661,7 @@ public class JTree extends JComponent implements Scrollable, Accessible
if(toRemove != null) {
while(toRemove.hasMoreElements()) {
Enumeration descendants = getDescendantToggledPaths
((TreePath)toRemove.nextElement());
(toRemove.nextElement());
if(descendants != null) {
while(descendants.hasMoreElements()) {
......@@ -4250,7 +4246,7 @@ public class JTree extends JComponent implements Scrollable, Accessible
private AccessibleContext getCurrentAccessibleContext() {
Component c = getCurrentComponent();
if (c instanceof Accessible) {
return (((Accessible) c).getAccessibleContext());
return c.getAccessibleContext();
} else {
return null;
}
......@@ -4573,7 +4569,7 @@ public class JTree extends JComponent implements Scrollable, Accessible
private AccessibleContext getCurrentAccessibleContext() {
Component c = getCurrentComponent();
if (c instanceof Accessible) {
return (((Accessible) c).getAccessibleContext());
return c.getAccessibleContext();
} else {
return null;
}
......@@ -5117,12 +5113,8 @@ public class JTree extends JComponent implements Scrollable, Accessible
public boolean isVisible() {
Rectangle pathBounds = tree.getPathBounds(path);
Rectangle parentBounds = tree.getVisibleRect();
if (pathBounds != null && parentBounds != null &&
parentBounds.intersects(pathBounds)) {
return true;
} else {
return false;
}
return pathBounds != null && parentBounds != null &&
parentBounds.intersects(pathBounds);
}
public void setVisible(boolean b) {
......
......@@ -389,7 +389,7 @@ public class JViewport extends JComponent implements Accessible
// could be bigger than invalid size.
validateView();
}
int dx = 0, dy = 0;
int dx, dy;
dx = positionAdjustment(getWidth(), contentRect.width, contentRect.x);
dy = positionAdjustment(getHeight(), contentRect.height, contentRect.y);
......@@ -682,10 +682,7 @@ public class JViewport extends JComponent implements Accessible
* @see JComponent#isPaintingOrigin()
*/
boolean isPaintingOrigin() {
if (scrollMode == BACKINGSTORE_SCROLL_MODE) {
return true;
}
return false;
return scrollMode == BACKINGSTORE_SCROLL_MODE;
}
......@@ -903,11 +900,7 @@ public class JViewport extends JComponent implements Accessible
*/
public void setScrollMode(int mode) {
scrollMode = mode;
if (mode == BACKINGSTORE_SCROLL_MODE) {
backingStore = true;
} else {
backingStore = false;
}
backingStore = mode == BACKINGSTORE_SCROLL_MODE;
}
/**
......@@ -958,10 +951,10 @@ public class JViewport extends JComponent implements Accessible
}
}
private final boolean isBlitting() {
private boolean isBlitting() {
Component view = getView();
return (scrollMode == BLIT_SCROLL_MODE) &&
(view instanceof JComponent) && ((JComponent)view).isOpaque();
(view instanceof JComponent) && view.isOpaque();
}
......@@ -1380,8 +1373,7 @@ public class JViewport extends JComponent implements Accessible
* @since 1.4
*/
public ChangeListener[] getChangeListeners() {
return (ChangeListener[])listenerList.getListeners(
ChangeListener.class);
return listenerList.getListeners(ChangeListener.class);
}
/**
......
......@@ -185,7 +185,7 @@ public class JWindow extends Window implements Accessible,
super(owner == null? SwingUtilities.getSharedOwnerFrame() : owner);
if (owner == null) {
WindowListener ownerShutdownListener =
(WindowListener)SwingUtilities.getSharedOwnerFrameShutdownListener();
SwingUtilities.getSharedOwnerFrameShutdownListener();
addWindowListener(ownerShutdownListener);
}
windowInit();
......@@ -212,7 +212,7 @@ public class JWindow extends Window implements Accessible,
owner);
if (owner == null) {
WindowListener ownerShutdownListener =
(WindowListener)SwingUtilities.getSharedOwnerFrameShutdownListener();
SwingUtilities.getSharedOwnerFrameShutdownListener();
addWindowListener(ownerShutdownListener);
}
windowInit();
......@@ -250,7 +250,7 @@ public class JWindow extends Window implements Accessible,
owner, gc);
if (owner == null) {
WindowListener ownerShutdownListener =
(WindowListener)SwingUtilities.getSharedOwnerFrameShutdownListener();
SwingUtilities.getSharedOwnerFrameShutdownListener();
addWindowListener(ownerShutdownListener);
}
windowInit();
......
......@@ -68,13 +68,13 @@ class KeyboardManager {
/**
* maps top-level containers to a sub-hashtable full of keystrokes
*/
Hashtable containerMap = new Hashtable();
Hashtable<Container, Hashtable> containerMap = new Hashtable<Container, Hashtable>();
/**
* Maps component/keystroke pairs to a topLevel container
* This is mainly used for fast unregister operations
*/
Hashtable componentKeyStrokeMap = new Hashtable();
Hashtable<ComponentKeyStrokePair, Container> componentKeyStrokeMap = new Hashtable<ComponentKeyStrokePair, Container>();
public static KeyboardManager getCurrentManager() {
return currentManager;
......@@ -95,7 +95,7 @@ class KeyboardManager {
if (topContainer == null) {
return;
}
Hashtable keyMap = (Hashtable)containerMap.get(topContainer);
Hashtable keyMap = containerMap.get(topContainer);
if (keyMap == null) { // lazy evaluate one
keyMap = registerNewTopContainer(topContainer);
......@@ -114,8 +114,8 @@ class KeyboardManager {
// Then add the old compoennt and the new compoent to the vector
// then insert the vector in the table
if (tmp != c) { // this means this is already registered for this component, no need to dup
Vector v = new Vector();
v.addElement(tmp);
Vector<JComponent> v = new Vector<JComponent>();
v.addElement((JComponent) tmp);
v.addElement(c);
keyMap.put(k, v);
}
......@@ -154,13 +154,13 @@ class KeyboardManager {
ComponentKeyStrokePair ckp = new ComponentKeyStrokePair(c,ks);
Object topContainer = componentKeyStrokeMap.get(ckp);
Container topContainer = componentKeyStrokeMap.get(ckp);
if (topContainer == null) { // never heard of this pairing, so bail
return;
}
Hashtable keyMap = (Hashtable)containerMap.get(topContainer);
Hashtable keyMap = containerMap.get(topContainer);
if (keyMap == null) { // this should never happen, but I'm being safe
Thread.dumpStack();
return;
......@@ -221,7 +221,7 @@ class KeyboardManager {
ks=KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers(), !pressed);
}
Hashtable keyMap = (Hashtable)containerMap.get(topAncestor);
Hashtable keyMap = containerMap.get(topAncestor);
if (keyMap != null) { // this container isn't registered, so bail
Object tmp = keyMap.get(ks);
......@@ -293,7 +293,7 @@ class KeyboardManager {
if (top == null) {
return;
}
Hashtable keyMap = (Hashtable)containerMap.get(top);
Hashtable keyMap = containerMap.get(top);
if (keyMap == null) { // lazy evaluate one
keyMap = registerNewTopContainer(top);
......@@ -314,11 +314,11 @@ class KeyboardManager {
public void unregisterMenuBar(JMenuBar mb) {
Object topContainer = getTopAncestor(mb);
Container topContainer = getTopAncestor(mb);
if (topContainer == null) {
return;
}
Hashtable keyMap = (Hashtable)containerMap.get(topContainer);
Hashtable keyMap = containerMap.get(topContainer);
if (keyMap!=null) {
Vector v = (Vector)keyMap.get(JMenuBar.class);
if (v != null) {
......
......@@ -39,7 +39,7 @@ import java.awt.Window;
*
* @author David Mendenhall
*/
final class LayoutComparator implements Comparator, java.io.Serializable {
final class LayoutComparator implements Comparator<Component>, java.io.Serializable {
private static final int ROW_TOLERANCE = 10;
......@@ -51,10 +51,7 @@ final class LayoutComparator implements Comparator, java.io.Serializable {
leftToRight = orientation.isLeftToRight();
}
public int compare(Object o1, Object o2) {
Component a = (Component)o1;
Component b = (Component)o2;
public int compare(Component a, Component b) {
if (a == b) {
return 0;
}
......@@ -65,9 +62,9 @@ final class LayoutComparator implements Comparator, java.io.Serializable {
// each Component and then search from the Window down until the
// hierarchy branches.
if (a.getParent() != b.getParent()) {
LinkedList aAncestory, bAncestory;
LinkedList<Component> aAncestory = new LinkedList<Component>();
for(aAncestory = new LinkedList(); a != null; a = a.getParent()) {
for(; a != null; a = a.getParent()) {
aAncestory.add(a);
if (a instanceof Window) {
break;
......@@ -78,7 +75,9 @@ final class LayoutComparator implements Comparator, java.io.Serializable {
throw new ClassCastException();
}
for(bAncestory = new LinkedList(); b != null; b = b.getParent()) {
LinkedList<Component> bAncestory = new LinkedList<Component>();
for(; b != null; b = b.getParent()) {
bAncestory.add(b);
if (b instanceof Window) {
break;
......@@ -89,18 +88,18 @@ final class LayoutComparator implements Comparator, java.io.Serializable {
throw new ClassCastException();
}
for (ListIterator
for (ListIterator<Component>
aIter = aAncestory.listIterator(aAncestory.size()),
bIter = bAncestory.listIterator(bAncestory.size()); ;) {
if (aIter.hasPrevious()) {
a = (Component)aIter.previous();
a = aIter.previous();
} else {
// a is an ancestor of b
return -1;
}
if (bIter.hasPrevious()) {
b = (Component)bIter.previous();
b = bIter.previous();
} else {
// b is an ancestor of a
return 1;
......
......@@ -65,7 +65,7 @@ public class LayoutFocusTraversalPolicy extends SortingFocusTraversalPolicy
* Constructs a LayoutFocusTraversalPolicy with the passed in
* <code>Comparator</code>.
*/
LayoutFocusTraversalPolicy(Comparator c) {
LayoutFocusTraversalPolicy(Comparator<? super Component> c) {
super(c);
}
......
......@@ -48,8 +48,8 @@ final class LegacyGlueFocusTraversalPolicy extends FocusTraversalPolicy
private transient FocusTraversalPolicy delegatePolicy;
private transient DefaultFocusManager delegateManager;
private HashMap forwardMap = new HashMap(),
backwardMap = new HashMap();
private HashMap<Component, Component> forwardMap = new HashMap<Component, Component>(),
backwardMap = new HashMap<Component, Component>();
LegacyGlueFocusTraversalPolicy(FocusTraversalPolicy delegatePolicy) {
this.delegatePolicy = delegatePolicy;
......@@ -70,11 +70,11 @@ final class LegacyGlueFocusTraversalPolicy extends FocusTraversalPolicy
public Component getComponentAfter(Container focusCycleRoot,
Component aComponent) {
Component hardCoded = aComponent, prevHardCoded;
HashSet sanity = new HashSet();
HashSet<Component> sanity = new HashSet<Component>();
do {
prevHardCoded = hardCoded;
hardCoded = (Component)forwardMap.get(hardCoded);
hardCoded = forwardMap.get(hardCoded);
if (hardCoded == null) {
if (delegatePolicy != null &&
prevHardCoded.isFocusCycleRoot(focusCycleRoot)) {
......@@ -99,11 +99,11 @@ final class LegacyGlueFocusTraversalPolicy extends FocusTraversalPolicy
public Component getComponentBefore(Container focusCycleRoot,
Component aComponent) {
Component hardCoded = aComponent, prevHardCoded;
HashSet sanity = new HashSet();
HashSet<Component> sanity = new HashSet<Component>();
do {
prevHardCoded = hardCoded;
hardCoded = (Component)backwardMap.get(hardCoded);
hardCoded = backwardMap.get(hardCoded);
if (hardCoded == null) {
if (delegatePolicy != null &&
prevHardCoded.isFocusCycleRoot(focusCycleRoot)) {
......
......@@ -37,7 +37,7 @@ import sun.awt.AppContext;
* @author Arnaud Weber
*/
public class MenuSelectionManager {
private Vector selection = new Vector();
private Vector<MenuElement> selection = new Vector<MenuElement>();
/* diagnostic aids -- should be false for production builds. */
private static final boolean TRACE = false; // trace creates and disposes
......@@ -100,14 +100,14 @@ public class MenuSelectionManager {
}
for(i=0,c=path.length;i<c;i++) {
if(i < currentSelectionCount && (MenuElement)selection.elementAt(i) == path[i])
if (i < currentSelectionCount && selection.elementAt(i) == path[i])
firstDifference++;
else
break;
}
for(i=currentSelectionCount - 1 ; i >= firstDifference ; i--) {
MenuElement me = (MenuElement)selection.elementAt(i);
MenuElement me = selection.elementAt(i);
selection.removeElementAt(i);
me.menuSelectionChanged(false);
}
......@@ -131,7 +131,7 @@ public class MenuSelectionManager {
MenuElement res[] = new MenuElement[selection.size()];
int i,c;
for(i=0,c=selection.size();i<c;i++)
res[i] = (MenuElement) selection.elementAt(i);
res[i] = selection.elementAt(i);
return res;
}
......@@ -172,8 +172,7 @@ public class MenuSelectionManager {
* @since 1.4
*/
public ChangeListener[] getChangeListeners() {
return (ChangeListener[])listenerList.getListeners(
ChangeListener.class);
return listenerList.getListeners(ChangeListener.class);
}
/**
......@@ -258,8 +257,8 @@ public class MenuSelectionManager {
if(!mc.isShowing())
continue;
if(mc instanceof JComponent) {
cWidth = ((JComponent)mc).getWidth();
cHeight = ((JComponent)mc).getHeight();
cWidth = mc.getWidth();
cHeight = mc.getHeight();
} else {
r2 = mc.getBounds();
cWidth = r2.width;
......@@ -338,7 +337,7 @@ public class MenuSelectionManager {
for(i=0,j=path.length; i<j ;i++){
for (int k=0; k<=i; k++)
System.out.print(" ");
MenuElement me = (MenuElement) path[i];
MenuElement me = path[i];
if(me instanceof JMenuItem) {
System.out.println(((JMenuItem)me).getText() + ", ");
} else if (me instanceof JMenuBar) {
......@@ -399,8 +398,8 @@ public class MenuSelectionManager {
if(!mc.isShowing())
continue;
if(mc instanceof JComponent) {
cWidth = ((JComponent)mc).getWidth();
cHeight = ((JComponent)mc).getHeight();
cWidth = mc.getWidth();
cHeight = mc.getHeight();
} else {
r2 = mc.getBounds();
cWidth = r2.width;
......@@ -429,7 +428,7 @@ public class MenuSelectionManager {
*/
public void processKeyEvent(KeyEvent e) {
MenuElement[] sel2 = new MenuElement[0];
sel2 = (MenuElement[])selection.toArray(sel2);
sel2 = selection.toArray(sel2);
int selSize = sel2.length;
MenuElement[] path;
......@@ -474,7 +473,7 @@ public class MenuSelectionManager {
*/
public boolean isComponentPartOfCurrentMenu(Component c) {
if(selection.size() > 0) {
MenuElement me = (MenuElement)selection.elementAt(0);
MenuElement me = selection.elementAt(0);
return isComponentPartOfCurrentMenu(me,c);
} else
return false;
......
......@@ -56,8 +56,7 @@ class MultiUIDefaults extends UIDefaults
return value;
}
for(int i = 0; i < tables.length; i++) {
UIDefaults table = tables[i];
for (UIDefaults table : tables) {
value = (table != null) ? table.get(key) : null;
if (value != null) {
return value;
......@@ -75,8 +74,7 @@ class MultiUIDefaults extends UIDefaults
return value;
}
for(int i = 0; i < tables.length; i++) {
UIDefaults table = tables[i];
for (UIDefaults table : tables) {
value = (table != null) ? table.get(key,l) : null;
if (value != null) {
return value;
......@@ -89,8 +87,7 @@ class MultiUIDefaults extends UIDefaults
public int size() {
int n = super.size();
for(int i = 0; i < tables.length; i++) {
UIDefaults table = tables[i];
for (UIDefaults table : tables) {
n += (table != null) ? table.size() : 0;
}
return n;
......@@ -102,7 +99,7 @@ class MultiUIDefaults extends UIDefaults
}
public Enumeration keys()
public Enumeration<Object> keys()
{
Enumeration[] enums = new Enumeration[1 + tables.length];
enums[0] = super.keys();
......@@ -116,7 +113,7 @@ class MultiUIDefaults extends UIDefaults
}
public Enumeration elements()
public Enumeration<Object> elements()
{
Enumeration[] enums = new Enumeration[1 + tables.length];
enums[0] = super.elements();
......@@ -137,7 +134,7 @@ class MultiUIDefaults extends UIDefaults
}
}
private static class MultiUIDefaultsEnumerator implements Enumeration
private static class MultiUIDefaultsEnumerator implements Enumeration<Object>
{
Enumeration[] enums;
int n = 0;
......@@ -175,8 +172,7 @@ class MultiUIDefaults extends UIDefaults
return value;
}
for(int i = 0; i < tables.length; i++) {
UIDefaults table = tables[i];
for (UIDefaults table : tables) {
value = (table != null) ? table.remove(key) : null;
if (value != null) {
return value;
......@@ -189,8 +185,7 @@ class MultiUIDefaults extends UIDefaults
public void clear() {
super.clear();
for(int i = 0; i < tables.length; i++) {
UIDefaults table = tables[i];
for (UIDefaults table : tables) {
if (table != null) {
table.clear();
}
......
......@@ -313,9 +313,9 @@ public class PopupFactory {
if(contents instanceof JPopupMenu) {
JPopupMenu jpm = (JPopupMenu) contents;
Component popComps[] = jpm.getComponents();
for(int i=0;i<popComps.length;i++) {
if(!(popComps[i] instanceof MenuElement) &&
!(popComps[i] instanceof JSeparator)) {
for (Component popComp : popComps) {
if (!(popComp instanceof MenuElement) &&
!(popComp instanceof JSeparator)) {
focusPopup = true;
break;
}
......@@ -357,17 +357,16 @@ public class PopupFactory {
*/
private static HeavyWeightPopup getRecycledHeavyWeightPopup(Window w) {
synchronized (HeavyWeightPopup.class) {
List cache;
Map heavyPopupCache = getHeavyWeightPopupCache();
List<HeavyWeightPopup> cache;
Map<Window, List<HeavyWeightPopup>> heavyPopupCache = getHeavyWeightPopupCache();
if (heavyPopupCache.containsKey(w)) {
cache = (List)heavyPopupCache.get(w);
cache = heavyPopupCache.get(w);
} else {
return null;
}
int c;
if ((c = cache.size()) > 0) {
HeavyWeightPopup r = (HeavyWeightPopup)cache.get(0);
if (cache.size() > 0) {
HeavyWeightPopup r = cache.get(0);
cache.remove(0);
return r;
}
......@@ -380,13 +379,13 @@ public class PopupFactory {
* <code>Window</code> to a <code>List</code> of
* <code>HeavyWeightPopup</code>s.
*/
private static Map getHeavyWeightPopupCache() {
private static Map<Window, List<HeavyWeightPopup>> getHeavyWeightPopupCache() {
synchronized (HeavyWeightPopup.class) {
Map cache = (Map)SwingUtilities.appContextGet(
Map<Window, List<HeavyWeightPopup>> cache = (Map<Window, List<HeavyWeightPopup>>)SwingUtilities.appContextGet(
heavyWeightPopupCacheKey);
if (cache == null) {
cache = new HashMap(2);
cache = new HashMap<Window, List<HeavyWeightPopup>>(2);
SwingUtilities.appContextPut(heavyWeightPopupCacheKey,
cache);
}
......@@ -399,13 +398,13 @@ public class PopupFactory {
*/
private static void recycleHeavyWeightPopup(HeavyWeightPopup popup) {
synchronized (HeavyWeightPopup.class) {
List cache;
Object window = SwingUtilities.getWindowAncestor(
List<HeavyWeightPopup> cache;
Window window = SwingUtilities.getWindowAncestor(
popup.getComponent());
Map heavyPopupCache = getHeavyWeightPopupCache();
Map<Window, List<HeavyWeightPopup>> heavyPopupCache = getHeavyWeightPopupCache();
if (window instanceof Popup.DefaultFrame ||
!((Window)window).isVisible()) {
!window.isVisible()) {
// If the Window isn't visible, we don't cache it as we
// likely won't ever get a windowClosed event to clean up.
// We also don't cache DefaultFrames as this indicates
......@@ -414,28 +413,27 @@ public class PopupFactory {
popup._dispose();
return;
} else if (heavyPopupCache.containsKey(window)) {
cache = (List)heavyPopupCache.get(window);
cache = heavyPopupCache.get(window);
} else {
cache = new ArrayList();
cache = new ArrayList<HeavyWeightPopup>();
heavyPopupCache.put(window, cache);
// Clean up if the Window is closed
final Window w = (Window)window;
final Window w = window;
w.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
List popups;
List<HeavyWeightPopup> popups;
synchronized(HeavyWeightPopup.class) {
Map heavyPopupCache2 =
Map<Window, List<HeavyWeightPopup>> heavyPopupCache2 =
getHeavyWeightPopupCache();
popups = (List)heavyPopupCache2.remove(w);
popups = heavyPopupCache2.remove(w);
}
if (popups != null) {
for (int counter = popups.size() - 1;
counter >= 0; counter--) {
((HeavyWeightPopup)popups.get(counter)).
_dispose();
popups.get(counter)._dispose();
}
}
}
......@@ -534,10 +532,9 @@ public class PopupFactory {
Window[] ownedWindows = w.getOwnedWindows();
if(ownedWindows != null) {
Rectangle bnd = component.getBounds();
for(int i=0; i<ownedWindows.length;i++) {
Window owned = ownedWindows[i];
if (owned.isVisible() &&
bnd.intersects(owned.getBounds())) {
for (Window window : ownedWindows) {
if (window.isVisible() &&
bnd.intersects(window.getBounds())) {
return true;
}
......@@ -667,11 +664,11 @@ public class PopupFactory {
/**
* Returns the cache to use for heavy weight popups.
*/
private static List getLightWeightPopupCache() {
List cache = (List)SwingUtilities.appContextGet(
private static List<LightWeightPopup> getLightWeightPopupCache() {
List<LightWeightPopup> cache = (List<LightWeightPopup>)SwingUtilities.appContextGet(
lightWeightPopupCacheKey);
if (cache == null) {
cache = new ArrayList();
cache = new ArrayList<LightWeightPopup>();
SwingUtilities.appContextPut(lightWeightPopupCacheKey, cache);
}
return cache;
......@@ -682,7 +679,7 @@ public class PopupFactory {
*/
private static void recycleLightWeightPopup(LightWeightPopup popup) {
synchronized (LightWeightPopup.class) {
List lightPopupCache = getLightWeightPopupCache();
List<LightWeightPopup> lightPopupCache = getLightWeightPopupCache();
if (lightPopupCache.size() < MAX_CACHE_SIZE) {
lightPopupCache.add(popup);
}
......@@ -695,11 +692,9 @@ public class PopupFactory {
*/
private static LightWeightPopup getRecycledLightWeightPopup() {
synchronized (LightWeightPopup.class) {
List lightPopupCache = getLightWeightPopupCache();
int c;
if((c = lightPopupCache.size()) > 0) {
LightWeightPopup r = (LightWeightPopup)lightPopupCache.
get(0);
List<LightWeightPopup> lightPopupCache = getLightWeightPopupCache();
if (lightPopupCache.size() > 0) {
LightWeightPopup r = lightPopupCache.get(0);
lightPopupCache.remove(0);
return r;
}
......@@ -755,8 +750,7 @@ public class PopupFactory {
component.setLocation(p.x, p.y);
if (parent instanceof JLayeredPane) {
((JLayeredPane)parent).add(component,
JLayeredPane.POPUP_LAYER, 0);
parent.add(component, JLayeredPane.POPUP_LAYER, 0);
} else {
parent.add(component);
}
......@@ -826,12 +820,12 @@ public class PopupFactory {
/**
* Returns the cache to use for medium weight popups.
*/
private static List getMediumWeightPopupCache() {
List cache = (List)SwingUtilities.appContextGet(
private static List<MediumWeightPopup> getMediumWeightPopupCache() {
List<MediumWeightPopup> cache = (List<MediumWeightPopup>)SwingUtilities.appContextGet(
mediumWeightPopupCacheKey);
if (cache == null) {
cache = new ArrayList();
cache = new ArrayList<MediumWeightPopup>();
SwingUtilities.appContextPut(mediumWeightPopupCacheKey, cache);
}
return cache;
......@@ -842,7 +836,7 @@ public class PopupFactory {
*/
private static void recycleMediumWeightPopup(MediumWeightPopup popup) {
synchronized (MediumWeightPopup.class) {
List mediumPopupCache = getMediumWeightPopupCache();
List<MediumWeightPopup> mediumPopupCache = getMediumWeightPopupCache();
if (mediumPopupCache.size() < MAX_CACHE_SIZE) {
mediumPopupCache.add(popup);
}
......@@ -855,12 +849,9 @@ public class PopupFactory {
*/
private static MediumWeightPopup getRecycledMediumWeightPopup() {
synchronized (MediumWeightPopup.class) {
java.util.List mediumPopupCache =
getMediumWeightPopupCache();
int c;
if ((c=mediumPopupCache.size()) > 0) {
MediumWeightPopup r = (MediumWeightPopup)mediumPopupCache.
get(0);
List<MediumWeightPopup> mediumPopupCache = getMediumWeightPopupCache();
if (mediumPopupCache.size() > 0) {
MediumWeightPopup r = mediumPopupCache.get(0);
mediumPopupCache.remove(0);
return r;
}
......@@ -904,7 +895,7 @@ public class PopupFactory {
x, y);
component.setVisible(false);
component.setLocation(p.x, p.y);
((JLayeredPane)parent).add(component, JLayeredPane.POPUP_LAYER,
parent.add(component, JLayeredPane.POPUP_LAYER,
0);
} else {
Point p = SwingUtilities.convertScreenLocationToParent(parent,
......
......@@ -589,7 +589,7 @@ public class RepaintManager
*/
private synchronized boolean extendDirtyRegion(
Component c, int x, int y, int w, int h) {
Rectangle r = (Rectangle)dirtyComponents.get(c);
Rectangle r = dirtyComponents.get(c);
if (r != null) {
// A non-null r implies c is already marked as dirty,
// and that the parent is valid. Therefore we can
......@@ -609,9 +609,9 @@ public class RepaintManager
if (delegate != null) {
return delegate.getDirtyRegion(aComponent);
}
Rectangle r = null;
Rectangle r;
synchronized(this) {
r = (Rectangle)dirtyComponents.get(aComponent);
r = dirtyComponents.get(aComponent);
}
if(r == null)
return new Rectangle(0,0,0,0);
......@@ -745,8 +745,8 @@ public class RepaintManager
Rectangle rect;
int localBoundsX = 0;
int localBoundsY = 0;
int localBoundsH = 0;
int localBoundsW = 0;
int localBoundsH;
int localBoundsW;
Enumeration keys;
roots = new ArrayList<Component>(count);
......@@ -853,7 +853,7 @@ public class RepaintManager
dx = rootDx = 0;
dy = rootDy = 0;
tmp.setBounds((Rectangle) dirtyComponents.get(dirtyComponent));
tmp.setBounds(dirtyComponents.get(dirtyComponent));
// System.out.println("Collect dirty component for bound " + tmp +
// "component bounds is " + cBounds);;
......@@ -900,7 +900,7 @@ public class RepaintManager
Rectangle r;
tmp.setLocation(tmp.x + rootDx - dx,
tmp.y + rootDy - dy);
r = (Rectangle)dirtyComponents.get(rootDirtyComponent);
r = dirtyComponents.get(rootDirtyComponent);
SwingUtilities.computeUnion(tmp.x,tmp.y,tmp.width,tmp.height,r);
}
......@@ -985,7 +985,7 @@ public class RepaintManager
private Image _getOffscreenBuffer(Component c, int proposedWidth, int proposedHeight) {
Dimension maxSize = getDoubleBufferMaximumSize();
DoubleBufferInfo doubleBuffer = null;
DoubleBufferInfo doubleBuffer;
int width, height;
if (standardDoubleBuffer == null) {
......@@ -1054,7 +1054,7 @@ public class RepaintManager
Iterator gcs = volatileMap.keySet().iterator();
while (gcs.hasNext()) {
GraphicsConfiguration gc = (GraphicsConfiguration)gcs.next();
VolatileImage image = (VolatileImage)volatileMap.get(gc);
VolatileImage image = volatileMap.get(gc);
if (image.getWidth() > width || image.getHeight() > height) {
image.flush();
gcs.remove();
......@@ -1222,7 +1222,7 @@ public class RepaintManager
*/
void beginPaint() {
boolean multiThreadedPaint = false;
int paintDepth = 0;
int paintDepth;
Thread currentThread = Thread.currentThread();
synchronized(this) {
paintDepth = this.paintDepth;
......
......@@ -79,7 +79,7 @@ public class SortingFocusTraversalPolicy
* sorted list should be reused if possible.
*/
transient private Container cachedRoot;
transient private List cachedCycle;
transient private List<Component> cachedCycle;
// Delegate our fitness test to ContainerOrder so that we only have to
// code the algorithm once.
......@@ -111,7 +111,7 @@ public class SortingFocusTraversalPolicy
return cycle;
}
private int getComponentIndex(List<Component> cycle, Component aComponent) {
int index = 0;
int index;
try {
index = Collections.binarySearch(cycle, aComponent, comparator);
} catch (ClassCastException e) {
......@@ -130,14 +130,14 @@ public class SortingFocusTraversalPolicy
return index;
}
private void enumerateAndSortCycle(Container focusCycleRoot, List cycle) {
private void enumerateAndSortCycle(Container focusCycleRoot, List<Component> cycle) {
if (focusCycleRoot.isShowing()) {
enumerateCycle(focusCycleRoot, cycle);
Collections.sort(cycle, comparator);
}
}
private void enumerateCycle(Container container, List cycle) {
private void enumerateCycle(Container container, List<Component> cycle) {
if (!(container.isVisible() && container.isDisplayable())) {
return;
}
......@@ -145,8 +145,7 @@ public class SortingFocusTraversalPolicy
cycle.add(container);
Component[] components = container.getComponents();
for (int i = 0; i < components.length; i++) {
Component comp = components[i];
for (Component comp : components) {
if (comp instanceof Container) {
Container cont = (Container)comp;
......@@ -385,8 +384,8 @@ public class SortingFocusTraversalPolicy
return getLastComponent(aContainer);
}
Component comp = null;
Component tryComp = null;
Component comp;
Component tryComp;
for (index--; index>=0; index--) {
comp = cycle.get(index);
......@@ -442,8 +441,7 @@ public class SortingFocusTraversalPolicy
}
if (log.isLoggable(Level.FINE)) log.fine("### Cycle is " + cycle);
for (int i = 0; i < cycle.size(); i++) {
Component comp = cycle.get(i);
for (Component comp : cycle) {
if (accept(comp)) {
return comp;
} else if (comp instanceof Container && comp != aContainer) {
......
......@@ -185,11 +185,11 @@ import java.util.*;
* @since 1.4
*/
public class SpringLayout implements LayoutManager2 {
private Map componentConstraints = new HashMap();
private Map<Component, Constraints> componentConstraints = new HashMap<Component, Constraints>();
private Spring cyclicReference = Spring.constant(Spring.UNSET);
private Set cyclicSprings;
private Set acyclicSprings;
private Set<Spring> cyclicSprings;
private Set<Spring> acyclicSprings;
/**
......@@ -415,8 +415,7 @@ public class SpringLayout implements LayoutManager2 {
}
if (!valid) {
String[] all = horizontal ? ALL_HORIZONTAL : ALL_VERTICAL;
for (int i = 0; i < all.length; i++) {
String s = all[i];
for (String s : all) {
if (!history.contains(s)) {
setConstraint(s, null);
}
......@@ -822,8 +821,7 @@ public class SpringLayout implements LayoutManager2 {
/*pp*/ void reset() {
Spring[] allSprings = {x, y, width, height, east, south,
horizontalCenter, verticalCenter, baseline};
for (int i = 0; i < allSprings.length; i++) {
Spring s = allSprings[i];
for (Spring s : allSprings) {
if (s != null) {
s.setValue(Spring.UNSET);
}
......@@ -881,8 +879,8 @@ public class SpringLayout implements LayoutManager2 {
public SpringLayout() {}
private void resetCyclicStatuses() {
cyclicSprings = new HashSet();
acyclicSprings = new HashSet();
cyclicSprings = new HashSet<Spring>();
acyclicSprings = new HashSet<Spring>();
}
private void setParent(Container p) {
......@@ -1145,7 +1143,7 @@ public class SpringLayout implements LayoutManager2 {
* @return the constraints for the specified component
*/
public Constraints getConstraints(Component c) {
Constraints result = (Constraints)componentConstraints.get(c);
Constraints result = componentConstraints.get(c);
if (result == null) {
if (c instanceof javax.swing.JComponent) {
Object cp = ((javax.swing.JComponent)c).getClientProperty(SpringLayout.class);
......
......@@ -108,11 +108,8 @@ public class SwingUtilities implements SwingConstants
* Return true if <code>a</code> contains <code>b</code>
*/
public static final boolean isRectangleContainingRectangle(Rectangle a,Rectangle b) {
if (b.x >= a.x && (b.x + b.width) <= (a.x + a.width) &&
b.y >= a.y && (b.y + b.height) <= (a.y + a.height)) {
return true;
}
return false;
return b.x >= a.x && (b.x + b.width) <= (a.x + a.width) &&
b.y >= a.y && (b.y + b.height) <= (a.y + a.height);
}
/**
......@@ -272,8 +269,7 @@ public class SwingUtilities implements SwingConstants
}
if (parent instanceof Container) {
Component components[] = ((Container)parent).getComponents();
for (int i = 0 ; i < components.length ; i++) {
Component comp = components[i];
for (Component comp : components) {
if (comp != null && comp.isVisible()) {
Point loc = comp.getLocation();
if (comp instanceof Container) {
......@@ -376,8 +372,8 @@ public class SwingUtilities implements SwingConstants
do {
if(c instanceof JComponent) {
x = ((JComponent)c).getX();
y = ((JComponent)c).getY();
x = c.getX();
y = c.getY();
} else if(c instanceof java.applet.Applet ||
c instanceof java.awt.Window) {
try {
......@@ -415,8 +411,8 @@ public class SwingUtilities implements SwingConstants
do {
if(c instanceof JComponent) {
x = ((JComponent)c).getX();
y = ((JComponent)c).getY();
x = c.getX();
y = c.getY();
} else if(c instanceof java.applet.Applet ||
c instanceof java.awt.Window) {
try {
......@@ -980,7 +976,7 @@ public class SwingUtilities implements SwingConstants
*/
int gap;
View v = null;
View v;
if (textIsEmpty) {
textR.width = textR.height = 0;
text = "";
......@@ -1248,8 +1244,8 @@ public class SwingUtilities implements SwingConstants
children = ((Container)c).getComponents();
}
if (children != null) {
for(int i = 0; i < children.length; i++) {
updateComponentTreeUI0(children[i]);
for (Component child : children) {
updateComponentTreeUI0(child);
}
}
}
......@@ -1702,7 +1698,7 @@ public class SwingUtilities implements SwingConstants
*/
public static void replaceUIActionMap(JComponent component,
ActionMap uiActionMap) {
ActionMap map = component.getActionMap((uiActionMap != null));;
ActionMap map = component.getActionMap((uiActionMap != null));
while (map != null) {
ActionMap parent = map.getParent();
......@@ -1770,8 +1766,7 @@ public class SwingUtilities implements SwingConstants
*/
void installListeners() {
Window[] windows = getOwnedWindows();
for (int ind = 0; ind < windows.length; ind++){
Window window = windows[ind];
for (Window window : windows) {
if (window != null) {
window.removeWindowListener(this);
window.addWindowListener(this);
......@@ -1786,8 +1781,7 @@ public class SwingUtilities implements SwingConstants
public void windowClosed(WindowEvent e) {
synchronized(getTreeLock()) {
Window[] windows = getOwnedWindows();
for (int ind = 0; ind < windows.length; ind++) {
Window window = windows[ind];
for (Window window : windows) {
if (window != null) {
if (window.isDisplayable()) {
return;
......@@ -1875,7 +1869,7 @@ public class SwingUtilities implements SwingConstants
}
static Class loadSystemClass(String className) throws ClassNotFoundException {
static Class<?> loadSystemClass(String className) throws ClassNotFoundException {
return Class.forName(className, true, Thread.currentThread().
getContextClassLoader());
}
......
......@@ -270,8 +270,7 @@ public class Timer implements Serializable
* @since 1.4
*/
public ActionListener[] getActionListeners() {
return (ActionListener[])listenerList.getListeners(
ActionListener.class);
return listenerList.getListeners(ActionListener.class);
}
......
......@@ -97,7 +97,7 @@ class TimerQueue implements Runnable
final ThreadGroup threadGroup =
AppContext.getAppContext().getThreadGroup();
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
new java.security.PrivilegedAction<Object>() {
public Object run() {
Thread timerThread = new Thread(threadGroup, TimerQueue.this,
"TimerQueue");
......@@ -226,7 +226,7 @@ class TimerQueue implements Runnable
/**
* Returns nanosecond time offset by origin
*/
private final static long now() {
private static long now() {
return System.nanoTime() - NANO_ORIGIN;
}
......
......@@ -72,11 +72,11 @@ import sun.util.CoreResourceBundleControl;
*/
public class UIDefaults extends Hashtable<Object,Object>
{
private static final Object PENDING = new String("Pending");
private static final Object PENDING = "Pending";
private SwingPropertyChangeSupport changeSupport;
private Vector resourceBundles;
private Vector<String> resourceBundles;
private Locale defaultLocale = Locale.getDefault();
......@@ -86,7 +86,7 @@ public class UIDefaults extends Hashtable<Object,Object>
* Access to this should be done while holding a lock on the
* UIDefaults, eg synchronized(this).
*/
private Map resourceCache;
private Map<Locale, Map<String, Object>> resourceCache;
/**
* Creates an empty defaults table.
......@@ -106,7 +106,7 @@ public class UIDefaults extends Hashtable<Object,Object>
*/
public UIDefaults(int initialCapacity, float loadFactor) {
super(initialCapacity, loadFactor);
resourceCache = new HashMap();
resourceCache = new HashMap<Locale, Map<String, Object>>();
}
......@@ -281,24 +281,24 @@ public class UIDefaults extends Hashtable<Object,Object>
if( defaultLocale == null )
return null;
else
l = (Locale)defaultLocale;
l = defaultLocale;
}
synchronized(this) {
return getResourceCache(l).get((String)key);
return getResourceCache(l).get(key);
}
}
/**
* Returns a Map of the known resources for the given locale.
*/
private Map getResourceCache(Locale l) {
Map values = (Map)resourceCache.get(l);
private Map<String, Object> getResourceCache(Locale l) {
Map<String, Object> values = resourceCache.get(l);
if (values == null) {
values = new HashMap();
values = new HashMap<String, Object>();
for (int i=resourceBundles.size()-1; i >= 0; i--) {
String bundleName = (String)resourceBundles.get(i);
String bundleName = resourceBundles.get(i);
try {
Control c = CoreResourceBundleControl.getRBControlInstance(bundleName);
ResourceBundle b;
......@@ -751,7 +751,7 @@ public class UIDefaults extends Hashtable<Object,Object>
Object cl = get("ClassLoader");
ClassLoader uiClassLoader =
(cl != null) ? (ClassLoader)cl : target.getClass().getClassLoader();
Class uiClass = getUIClass(target.getUIClassID(), uiClassLoader);
Class<? extends ComponentUI> uiClass = getUIClass(target.getUIClassID(), uiClassLoader);
Object uiObject = null;
if (uiClass == null) {
......@@ -761,8 +761,7 @@ public class UIDefaults extends Hashtable<Object,Object>
try {
Method m = (Method)get(uiClass);
if (m == null) {
Class acClass = javax.swing.JComponent.class;
m = uiClass.getMethod("createUI", new Class[]{acClass});
m = uiClass.getMethod("createUI", new Class[]{JComponent.class});
put(uiClass, m);
}
uiObject = MethodUtil.invoke(m, null, new Object[]{target});
......@@ -862,7 +861,7 @@ public class UIDefaults extends Hashtable<Object,Object>
return;
}
if( resourceBundles == null ) {
resourceBundles = new Vector(5);
resourceBundles = new Vector<String>(5);
}
if (!resourceBundles.contains(bundleName)) {
resourceBundles.add( bundleName );
......@@ -1064,7 +1063,7 @@ public class UIDefaults extends Hashtable<Object,Object>
className = c;
methodName = m;
if (o != null) {
args = (Object[])o.clone();
args = o.clone();
}
}
......@@ -1079,10 +1078,10 @@ public class UIDefaults extends Hashtable<Object,Object>
// In order to pick up the security policy in effect at the
// time of creation we use a doPrivileged with the
// AccessControlContext that was in place when this was created.
return AccessController.doPrivileged(new PrivilegedAction() {
return AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
try {
Class c;
Class<?> c;
Object cl;
// See if we should use a separate ClassLoader
if (table == null || !((cl = table.get("ClassLoader"))
......
......@@ -191,7 +191,7 @@ public class UIManager implements Serializable
MultiUIDefaults multiUIDefaults = new MultiUIDefaults(tables);
LookAndFeel lookAndFeel;
LookAndFeel multiLookAndFeel = null;
Vector auxLookAndFeels = null;
Vector<LookAndFeel> auxLookAndFeels = null;
SwingPropertyChangeSupport changeSupport;
UIDefaults getLookAndFeelDefaults() { return tables[0]; }
......@@ -378,7 +378,7 @@ public class UIManager implements Serializable
private static LookAndFeelInfo[] installedLAFs;
static {
ArrayList iLAFs = new ArrayList(4);
ArrayList<LookAndFeelInfo> iLAFs = new ArrayList<LookAndFeelInfo>(4);
iLAFs.add(new LookAndFeelInfo(
"Metal", "javax.swing.plaf.metal.MetalLookAndFeel"));
iLAFs.add(new LookAndFeelInfo("CDE/Motif",
......@@ -400,8 +400,7 @@ public class UIManager implements Serializable
iLAFs.add(new LookAndFeelInfo("GTK+",
"com.sun.java.swing.plaf.gtk.GTKLookAndFeel"));
}
installedLAFs = (LookAndFeelInfo[])iLAFs.toArray(
new LookAndFeelInfo[iLAFs.size()]);
installedLAFs = iLAFs.toArray(new LookAndFeelInfo[iLAFs.size()]);
}
......@@ -640,7 +639,7 @@ public class UIManager implements Serializable
* @see #getSystemLookAndFeelClassName
*/
public static String getCrossPlatformLookAndFeelClassName() {
String laf = (String)AccessController.doPrivileged(
String laf = AccessController.doPrivileged(
new GetPropertyAction("swing.crossplatformlaf"));
if (laf != null) {
return laf;
......@@ -1079,9 +1078,9 @@ public class UIManager implements Serializable
// for that.
return;
}
Vector v = getLAFState().auxLookAndFeels;
Vector<LookAndFeel> v = getLAFState().auxLookAndFeels;
if (v == null) {
v = new Vector();
v = new Vector<LookAndFeel>();
}
if (!v.contains(laf)) {
......@@ -1115,7 +1114,7 @@ public class UIManager implements Serializable
boolean result;
Vector v = getLAFState().auxLookAndFeels;
Vector<LookAndFeel> v = getLAFState().auxLookAndFeels;
if ((v == null) || (v.size() == 0)) {
return false;
}
......@@ -1151,14 +1150,14 @@ public class UIManager implements Serializable
static public LookAndFeel[] getAuxiliaryLookAndFeels() {
maybeInitialize();
Vector v = getLAFState().auxLookAndFeels;
Vector<LookAndFeel> v = getLAFState().auxLookAndFeels;
if ((v == null) || (v.size() == 0)) {
return null;
}
else {
LookAndFeel[] rv = new LookAndFeel[v.size()];
for (int i = 0; i < rv.length; i++) {
rv[i] = (LookAndFeel)v.elementAt(i);
rv[i] = v.elementAt(i);
}
return rv;
}
......@@ -1225,7 +1224,7 @@ public class UIManager implements Serializable
final Properties props = new Properties();
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
new java.security.PrivilegedAction<Object>() {
public Object run() {
try {
File file = new File(makeSwingPropertiesFilename());
......@@ -1284,7 +1283,7 @@ public class UIManager implements Serializable
* property. For example given "swing.installedlafs=motif,windows"
* lafs = {"motif", "windows"}.
*/
Vector lafs = new Vector();
Vector<String> lafs = new Vector<String>();
StringTokenizer st = new StringTokenizer(ilafsString, ",", false);
while (st.hasMoreTokens()) {
lafs.addElement(st.nextToken());
......@@ -1294,9 +1293,8 @@ public class UIManager implements Serializable
* list. If they both exist then add a LookAndFeelInfo to
* the installedLafs array.
*/
Vector ilafs = new Vector(lafs.size());
for(int i = 0; i < lafs.size(); i++) {
String laf = (String)lafs.elementAt(i);
Vector<LookAndFeelInfo> ilafs = new Vector<LookAndFeelInfo>(lafs.size());
for (String laf : lafs) {
String name = swingProps.getProperty(makeInstalledLAFKey(laf, "name"), laf);
String cls = swingProps.getProperty(makeInstalledLAFKey(laf, "class"));
if (cls != null) {
......@@ -1306,7 +1304,7 @@ public class UIManager implements Serializable
installedLAFs = new LookAndFeelInfo[ilafs.size()];
for(int i = 0; i < ilafs.size(); i++) {
installedLAFs[i] = (LookAndFeelInfo)(ilafs.elementAt(i));
installedLAFs[i] = ilafs.elementAt(i);
}
}
......@@ -1350,7 +1348,7 @@ public class UIManager implements Serializable
return;
}
Vector auxLookAndFeels = new Vector();
Vector<LookAndFeel> auxLookAndFeels = new Vector<LookAndFeel>();
StringTokenizer p = new StringTokenizer(auxLookAndFeelNames,",");
String factoryName;
......@@ -1451,7 +1449,7 @@ public class UIManager implements Serializable
Component c = e.getComponent();
if ((!(c instanceof JComponent) ||
(c != null && !((JComponent)c).isEnabled())) &&
(c != null && !c.isEnabled())) &&
JComponent.KeyboardState.shouldProcess(e) &&
SwingUtilities.processKeyBindings(e)) {
e.consume();
......
......@@ -136,8 +136,8 @@ public abstract class FileSystemView {
}
File[] roots = getRoots();
for (int i = 0; i < roots.length; i++) {
if (roots[i].equals(f)) {
for (File root : roots) {
if (root.equals(f)) {
return true;
}
}
......@@ -252,8 +252,8 @@ public abstract class FileSystemView {
return true;
}
File[] children = getFiles(folder, false);
for (int i = 0; i < children.length; i++) {
if (file.equals(children[i])) {
for (File child : children) {
if (file.equals(child)) {
return true;
}
}
......@@ -276,9 +276,9 @@ public abstract class FileSystemView {
public File getChild(File parent, String fileName) {
if (parent instanceof ShellFolder) {
File[] children = getFiles(parent, false);
for (int i = 0; i < children.length; i++) {
if (children[i].getName().equals(fileName)) {
return children[i];
for (File child : children) {
if (child.getName().equals(fileName)) {
return child;
}
}
}
......@@ -444,7 +444,7 @@ public abstract class FileSystemView {
* Gets the list of shown (i.e. not hidden) files.
*/
public File[] getFiles(File dir, boolean useFileHiding) {
Vector files = new Vector();
Vector<File> files = new Vector<File>();
// add all files in dir
......@@ -483,7 +483,7 @@ public abstract class FileSystemView {
}
}
return (File[])files.toArray(new File[files.size()]);
return files.toArray(new File[files.size()]);
}
......@@ -590,7 +590,7 @@ class UnixFileSystemView extends FileSystemView {
if(containingDir == null) {
throw new IOException("Containing directory is null:");
}
File newFolder = null;
File newFolder;
// Unix - using OpenWindows' default folder name. Can't find one for Motif/CDE.
newFolder = createFileObject(containingDir, newFolderString);
int i = 1;
......@@ -614,11 +614,7 @@ class UnixFileSystemView extends FileSystemView {
}
public boolean isDrive(File dir) {
if (isFloppyDrive(dir)) {
return true;
} else {
return false;
}
return isFloppyDrive(dir);
}
public boolean isFloppyDrive(File dir) {
......@@ -700,9 +696,8 @@ class WindowsFileSystemView extends FileSystemView {
if(containingDir == null) {
throw new IOException("Containing directory is null:");
}
File newFolder = null;
// Using NT's default folder name
newFolder = createFileObject(containingDir, newFolderString);
File newFolder = createFileObject(containingDir, newFolderString);
int i = 2;
while (newFolder.exists() && (i < 100)) {
newFolder = createFileObject(containingDir, MessageFormat.format(
......@@ -770,9 +765,8 @@ class GenericFileSystemView extends FileSystemView {
if(containingDir == null) {
throw new IOException("Containing directory is null:");
}
File newFolder = null;
// Using NT's default folder name
newFolder = createFileObject(containingDir, newFolderString);
File newFolder = createFileObject(containingDir, newFolderString);
if(newFolder.exists()) {
throw new IOException("Directory already exists:" + newFolder.getAbsolutePath());
......
......@@ -176,8 +176,7 @@ public abstract class AbstractTableModel implements TableModel, Serializable
* @since 1.4
*/
public TableModelListener[] getTableModelListeners() {
return (TableModelListener[])listenerList.getListeners(
TableModelListener.class);
return listenerList.getListeners(TableModelListener.class);
}
//
......
......@@ -681,9 +681,9 @@ public class DefaultTableModel extends AbstractTableModel implements Serializabl
if (anArray == null) {
return null;
}
Vector v = new Vector(anArray.length);
for (int i=0; i < anArray.length; i++) {
v.addElement(anArray[i]);
Vector<Object> v = new Vector<Object>(anArray.length);
for (Object o : anArray) {
v.addElement(o);
}
return v;
}
......@@ -698,9 +698,9 @@ public class DefaultTableModel extends AbstractTableModel implements Serializabl
if (anArray == null) {
return null;
}
Vector v = new Vector(anArray.length);
for (int i=0; i < anArray.length; i++) {
v.addElement(convertToVector(anArray[i]));
Vector<Vector> v = new Vector<Vector>(anArray.length);
for (Object[] o : anArray) {
v.addElement(convertToVector(o));
}
return v;
}
......
......@@ -551,7 +551,7 @@ public class DefaultTreeCellEditor implements ActionListener, TreeCellEditor,
// Serialization support.
private void writeObject(ObjectOutputStream s) throws IOException {
Vector values = new Vector();
Vector<Object> values = new Vector<Object>();
s.defaultWriteObject();
// Save the realEditor, if its Serializable.
......
......@@ -453,8 +453,7 @@ public class DefaultTreeModel implements Serializable, TreeModel {
* @since 1.4
*/
public TreeModelListener[] getTreeModelListeners() {
return (TreeModelListener[])listenerList.getListeners(
TreeModelListener.class);
return listenerList.getListeners(TreeModelListener.class);
}
/**
......@@ -652,7 +651,7 @@ public class DefaultTreeModel implements Serializable, TreeModel {
// Serialization support.
private void writeObject(ObjectOutputStream s) throws IOException {
Vector values = new Vector();
Vector<Object> values = new Vector<Object>();
s.defaultWriteObject();
// Save the root, if its Serializable.
......
......@@ -61,7 +61,7 @@ import javax.swing.DefaultListSelectionModel;
*
* @author Scott Violet
*/
public class DefaultTreeSelectionModel extends Object implements Cloneable, Serializable, TreeSelectionModel
public class DefaultTreeSelectionModel implements Cloneable, Serializable, TreeSelectionModel
{
/** Property name for selectionMode. */
public static final String SELECTION_MODE_PROPERTY = "selectionMode";
......@@ -98,8 +98,8 @@ public class DefaultTreeSelectionModel extends Object implements Cloneable, Seri
/** Used to make sure the paths are unique, will contain all the paths
* in <code>selection</code>.
*/
private Hashtable uniquePaths;
private Hashtable lastPaths;
private Hashtable<TreePath, Boolean> uniquePaths;
private Hashtable<TreePath, Boolean> lastPaths;
private TreePath[] tempPaths;
......@@ -111,8 +111,8 @@ public class DefaultTreeSelectionModel extends Object implements Cloneable, Seri
listSelectionModel = new DefaultListSelectionModel();
selectionMode = DISCONTIGUOUS_TREE_SELECTION;
leadIndex = leadRow = -1;
uniquePaths = new Hashtable();
lastPaths = new Hashtable();
uniquePaths = new Hashtable<TreePath, Boolean>();
lastPaths = new Hashtable<TreePath, Boolean>();
tempPaths = new TreePath[1];
}
......@@ -245,7 +245,7 @@ public class DefaultTreeSelectionModel extends Object implements Cloneable, Seri
}
TreePath beginLeadPath = leadPath;
Vector cPaths = new Vector(newCount + oldCount);
Vector<PathPlaceHolder> cPaths = new Vector<PathPlaceHolder>(newCount + oldCount);
List<TreePath> newSelectionAsList =
new ArrayList<TreePath>(newCount);
......@@ -276,7 +276,7 @@ public class DefaultTreeSelectionModel extends Object implements Cloneable, Seri
selection = newSelection;
Hashtable tempHT = uniquePaths;
Hashtable<TreePath, Boolean> tempHT = uniquePaths;
uniquePaths = lastPaths;
lastPaths = tempHT;
......@@ -348,7 +348,7 @@ public class DefaultTreeSelectionModel extends Object implements Cloneable, Seri
int counter, validCount;
int oldCount;
TreePath beginLeadPath = leadPath;
Vector cPaths = null;
Vector<PathPlaceHolder> cPaths = null;
if(selection == null)
oldCount = 0;
......@@ -363,7 +363,7 @@ public class DefaultTreeSelectionModel extends Object implements Cloneable, Seri
if (uniquePaths.get(paths[counter]) == null) {
validCount++;
if(cPaths == null)
cPaths = new Vector();
cPaths = new Vector<PathPlaceHolder>();
cPaths.addElement(new PathPlaceHolder
(paths[counter], true));
uniquePaths.put(paths[counter], Boolean.TRUE);
......@@ -388,12 +388,11 @@ public class DefaultTreeSelectionModel extends Object implements Cloneable, Seri
if(validCount != paths.length) {
/* Some of the paths in paths are already in
the selection. */
Enumeration newPaths = lastPaths.keys();
Enumeration<TreePath> newPaths = lastPaths.keys();
counter = oldCount;
while (newPaths.hasMoreElements()) {
newSelection[counter++] = (TreePath)newPaths.
nextElement();
newSelection[counter++] = newPaths.nextElement();
}
}
else {
......@@ -448,7 +447,7 @@ public class DefaultTreeSelectionModel extends Object implements Cloneable, Seri
clearSelection();
}
else {
Vector pathsToRemove = null;
Vector<PathPlaceHolder> pathsToRemove = null;
/* Find the paths that can be removed. */
for (int removeCounter = paths.length - 1; removeCounter >= 0;
......@@ -456,7 +455,7 @@ public class DefaultTreeSelectionModel extends Object implements Cloneable, Seri
if(paths[removeCounter] != null) {
if (uniquePaths.get(paths[removeCounter]) != null) {
if(pathsToRemove == null)
pathsToRemove = new Vector(paths.length);
pathsToRemove = new Vector<PathPlaceHolder>(paths.length);
uniquePaths.remove(paths[removeCounter]);
pathsToRemove.addElement(new PathPlaceHolder
(paths[removeCounter], false));
......@@ -471,14 +470,13 @@ public class DefaultTreeSelectionModel extends Object implements Cloneable, Seri
selection = null;
}
else {
Enumeration pEnum = uniquePaths.keys();
Enumeration<TreePath> pEnum = uniquePaths.keys();
int validCount = 0;
selection = new TreePath[selection.length -
removeCount];
while (pEnum.hasMoreElements()) {
selection[validCount++] = (TreePath)pEnum.
nextElement();
selection[validCount++] = pEnum.nextElement();
}
}
if (leadPath != null &&
......@@ -613,8 +611,7 @@ public class DefaultTreeSelectionModel extends Object implements Cloneable, Seri
* @since 1.4
*/
public TreeSelectionListener[] getTreeSelectionListeners() {
return (TreeSelectionListener[])listenerList.getListeners(
TreeSelectionListener.class);
return listenerList.getListeners(TreeSelectionListener.class);
}
/**
......@@ -1081,7 +1078,7 @@ public class DefaultTreeSelectionModel extends Object implements Cloneable, Seri
PathPlaceHolder placeholder;
for(int counter = 0; counter < cPathCount; counter++) {
placeholder = (PathPlaceHolder)changedPaths.elementAt(counter);
placeholder = changedPaths.elementAt(counter);
newness[counter] = placeholder.isNew;
paths[counter] = placeholder.path;
}
......@@ -1177,8 +1174,8 @@ public class DefaultTreeSelectionModel extends Object implements Cloneable, Seri
clone.listenerList = new EventListenerList();
clone.listSelectionModel = (DefaultListSelectionModel)
listSelectionModel.clone();
clone.uniquePaths = new Hashtable();
clone.lastPaths = new Hashtable();
clone.uniquePaths = new Hashtable<TreePath, Boolean>();
clone.lastPaths = new Hashtable<TreePath, Boolean>();
clone.tempPaths = new TreePath[1];
return clone;
}
......
......@@ -64,21 +64,21 @@ public class FixedHeightLayoutCache extends AbstractLayoutCache {
/**
* Maps from TreePath to a FHTreeStateNode.
*/
private Hashtable treePathMapping;
private Hashtable<TreePath, FHTreeStateNode> treePathMapping;
/**
* Used for getting path/row information.
*/
private SearchInfo info;
private Stack tempStacks;
private Stack<Stack<TreePath>> tempStacks;
public FixedHeightLayoutCache() {
super();
tempStacks = new Stack();
tempStacks = new Stack<Stack<TreePath>>();
boundsBuffer = new Rectangle();
treePathMapping = new Hashtable();
treePathMapping = new Hashtable<TreePath, FHTreeStateNode>();
info = new SearchInfo();
setRowHeight(1);
}
......@@ -592,7 +592,7 @@ public class FixedHeightLayoutCache extends AbstractLayoutCache {
* return null, if you to create a node use getNodeForPath.
*/
private FHTreeStateNode getMapping(TreePath path) {
return (FHTreeStateNode)treePathMapping.get(path);
return treePathMapping.get(path);
}
/**
......@@ -695,13 +695,13 @@ public class FixedHeightLayoutCache extends AbstractLayoutCache {
return null;
// Check all the parent paths, until a match is found.
Stack paths;
Stack<TreePath> paths;
if(tempStacks.size() == 0) {
paths = new Stack();
paths = new Stack<TreePath>();
}
else {
paths = (Stack)tempStacks.pop();
paths = tempStacks.pop();
}
try {
......@@ -714,7 +714,7 @@ public class FixedHeightLayoutCache extends AbstractLayoutCache {
// Found a match, create entries for all paths in
// paths.
while(node != null && paths.size() > 0) {
path = (TreePath)paths.pop();
path = paths.pop();
node = node.createChildFor(path.
getLastPathComponent());
}
......
......@@ -56,7 +56,7 @@ public class VariableHeightLayoutCache extends AbstractLayoutCache {
* The array of nodes that are currently visible, in the order they
* are displayed.
*/
private Vector visibleNodes;
private Vector<Object> visibleNodes;
/**
* This is set to true if one of the entries has an invalid size.
......@@ -79,20 +79,20 @@ public class VariableHeightLayoutCache extends AbstractLayoutCache {
/**
* Maps from <code>TreePath</code> to a <code>TreeStateNode</code>.
*/
private Hashtable treePathMapping;
private Hashtable<TreePath, TreeStateNode> treePathMapping;
/**
* A stack of stacks.
*/
private Stack tempStacks;
private Stack<Stack<TreePath>> tempStacks;
public VariableHeightLayoutCache() {
super();
tempStacks = new Stack();
visibleNodes = new Vector();
tempStacks = new Stack<Stack<TreePath>>();
visibleNodes = new Vector<Object>();
boundsBuffer = new Rectangle();
treePathMapping = new Hashtable();
treePathMapping = new Hashtable<TreePath, TreeStateNode>();
}
/**
......@@ -704,7 +704,7 @@ public class VariableHeightLayoutCache extends AbstractLayoutCache {
* return null, if you to create a node use getNodeForPath.
*/
private TreeStateNode getMapping(TreePath path) {
return (TreeStateNode)treePathMapping.get(path);
return treePathMapping.get(path);
}
/**
......@@ -824,13 +824,13 @@ public class VariableHeightLayoutCache extends AbstractLayoutCache {
}
// Check all the parent paths, until a match is found.
Stack paths;
Stack<TreePath> paths;
if(tempStacks.size() == 0) {
paths = new Stack();
paths = new Stack<TreePath>();
}
else {
paths = (Stack)tempStacks.pop();
paths = tempStacks.pop();
}
try {
......@@ -843,7 +843,7 @@ public class VariableHeightLayoutCache extends AbstractLayoutCache {
// Found a match, create entries for all paths in
// paths.
while(node != null && paths.size() > 0) {
path = (TreePath)paths.pop();
path = paths.pop();
node.getLoadedChildren(shouldCreate);
int childIndex = treeModel.
......
......@@ -116,7 +116,7 @@ public class StateEdit
protected void init (StateEditable anObject, String name) {
this.object = anObject;
this.preState = new Hashtable(11);
this.preState = new Hashtable<Object, Object>(11);
this.object.storeState(this.preState);
this.postState = null;
this.undoRedoName = name;
......@@ -133,7 +133,7 @@ public class StateEdit
* ends the edit.
*/
public void end() {
this.postState = new Hashtable(11);
this.postState = new Hashtable<Object, Object>(11);
this.object.storeState(this.postState);
this.removeRedundantState();
}
......@@ -170,7 +170,7 @@ public class StateEdit
* Remove redundant key/values in state hashtables.
*/
protected void removeRedundantState() {
Vector uselessKeys = new Vector();
Vector<Object> uselessKeys = new Vector<Object>();
Enumeration myKeys = preState.keys();
// Locate redundant state
......
......@@ -166,12 +166,10 @@ public class UndoManager extends CompoundEdit implements UndoableEditListener {
* @see AbstractUndoableEdit#die
*/
public synchronized void discardAllEdits() {
Enumeration cursor = edits.elements();
while (cursor.hasMoreElements()) {
UndoableEdit e = (UndoableEdit)cursor.nextElement();
for (UndoableEdit e : edits) {
e.die();
}
edits = new Vector();
edits = new Vector<UndoableEdit>();
indexOfNextAdd = 0;
// PENDING(rjrjr) when vector grows a removeRange() method
// (expected in JDK 1.2), trimEdits() will be nice and
......@@ -240,7 +238,7 @@ public class UndoManager extends CompoundEdit implements UndoableEditListener {
// System.out.println("Trimming " + from + " " + to + " with index " +
// indexOfNextAdd);
for (int i = to; from <= i; i--) {
UndoableEdit e = (UndoableEdit)edits.elementAt(i);
UndoableEdit e = edits.elementAt(i);
// System.out.println("JUM: Discarding " +
// e.getUndoPresentationName());
e.die();
......@@ -293,7 +291,7 @@ public class UndoManager extends CompoundEdit implements UndoableEditListener {
protected UndoableEdit editToBeUndone() {
int i = indexOfNextAdd;
while (i > 0) {
UndoableEdit edit = (UndoableEdit)edits.elementAt(--i);
UndoableEdit edit = edits.elementAt(--i);
if (edit.isSignificant()) {
return edit;
}
......@@ -314,7 +312,7 @@ public class UndoManager extends CompoundEdit implements UndoableEditListener {
int i = indexOfNextAdd;
while (i < count) {
UndoableEdit edit = (UndoableEdit)edits.elementAt(i++);
UndoableEdit edit = edits.elementAt(i++);
if (edit.isSignificant()) {
return edit;
}
......@@ -333,7 +331,7 @@ public class UndoManager extends CompoundEdit implements UndoableEditListener {
protected void undoTo(UndoableEdit edit) throws CannotUndoException {
boolean done = false;
while (!done) {
UndoableEdit next = (UndoableEdit)edits.elementAt(--indexOfNextAdd);
UndoableEdit next = edits.elementAt(--indexOfNextAdd);
next.undo();
done = next == edit;
}
......@@ -349,7 +347,7 @@ public class UndoManager extends CompoundEdit implements UndoableEditListener {
protected void redoTo(UndoableEdit edit) throws CannotRedoException {
boolean done = false;
while (!done) {
UndoableEdit next = (UndoableEdit)edits.elementAt(indexOfNextAdd++);
UndoableEdit next = edits.elementAt(indexOfNextAdd++);
next.redo();
done = next == edit;
}
......
......@@ -89,8 +89,7 @@ public class UndoableEditSupport {
* @since 1.4
*/
public synchronized UndoableEditListener[] getUndoableEditListeners() {
return (UndoableEditListener[])(listeners.toArray(
new UndoableEditListener[0]));
return listeners.toArray(new UndoableEditListener[0]);
}
/**
......
......@@ -114,7 +114,7 @@ public class AccessibleMethod {
/** The action used to fetch the method and make it accessible */
private static class AccessMethodAction implements PrivilegedExceptionAction<Method> {
private final Class klass;
private final Class<?> klass;
private final String methodName;
private final Class[] paramTypes;
......
......@@ -546,8 +546,7 @@ public class FilePane extends JPanel implements PropertyChangeListener {
public static void addActionsToMap(ActionMap map, Action[] actions) {
if (map != null && actions != null) {
for (int i = 0; i < actions.length; i++) {
Action a = actions[i];
for (Action a : actions) {
String cmd = (String)a.getValue(Action.ACTION_COMMAND_KEY);
if (cmd == null) {
cmd = (String)a.getValue(Action.NAME);
......@@ -715,13 +714,13 @@ public class FilePane extends JPanel implements PropertyChangeListener {
visibleColumns.toArray(columns);
columnMap = Arrays.copyOf(columnMap, columns.length);
List<RowSorter.SortKey> sortKeys =
List<? extends RowSorter.SortKey> sortKeys =
(rowSorter == null) ? null : rowSorter.getSortKeys();
fireTableStructureChanged();
restoreSortKeys(sortKeys);
}
private void restoreSortKeys(List<RowSorter.SortKey> sortKeys) {
private void restoreSortKeys(List<? extends RowSorter.SortKey> sortKeys) {
if (sortKeys != null) {
// check if preserved sortKeys are valid for this folder
for (int i = 0; i < sortKeys.size(); i++) {
......@@ -886,7 +885,7 @@ public class FilePane extends JPanel implements PropertyChangeListener {
return rowSorter;
}
private class DetailsTableRowSorter extends TableRowSorter {
private class DetailsTableRowSorter extends TableRowSorter<TableModel> {
public DetailsTableRowSorter() {
setModelWrapper(new SorterModelWrapper());
}
......@@ -906,8 +905,8 @@ public class FilePane extends JPanel implements PropertyChangeListener {
updateComparators(detailsTableModel.getColumns());
}
private class SorterModelWrapper extends ModelWrapper {
public Object getModel() {
private class SorterModelWrapper extends ModelWrapper<TableModel, Integer> {
public TableModel getModel() {
return getDetailsTableModel();
}
......@@ -923,7 +922,7 @@ public class FilePane extends JPanel implements PropertyChangeListener {
return FilePane.this.getModel().getElementAt(row);
}
public Object getIdentifier(int row) {
public Integer getIdentifier(int row) {
return row;
}
}
......@@ -1718,9 +1717,9 @@ public class FilePane extends JPanel implements PropertyChangeListener {
private void updateViewMenu() {
if (viewMenu != null) {
Component[] comps = viewMenu.getMenuComponents();
for (int i = 0; i < comps.length; i++) {
if (comps[i] instanceof JRadioButtonMenuItem) {
JRadioButtonMenuItem mi = (JRadioButtonMenuItem)comps[i];
for (Component comp : comps) {
if (comp instanceof JRadioButtonMenuItem) {
JRadioButtonMenuItem mi = (JRadioButtonMenuItem) comp;
if (((ViewTypeAction)mi.getAction()).viewType == viewType) {
mi.setSelected(true);
}
......
......@@ -54,15 +54,14 @@ public class SwingLazyValue implements UIDefaults.LazyValue {
className = c;
methodName = m;
if (o != null) {
args = (Object[])o.clone();
args = o.clone();
}
}
public Object createValue(final UIDefaults table) {
try {
Class c;
Object cl;
c = Class.forName(className, true, null);
Class<?> c = Class.forName(className, true, null);
if (methodName != null) {
Class[] types = getClassArray(args);
Method m = c.getMethod(methodName, types);
......
......@@ -460,7 +460,7 @@ public class SwingUtilities2 {
return clipString;
}
boolean needsTextLayout = false;
boolean needsTextLayout;
synchronized (charsBufferLock) {
if (charsBuffer == null || charsBuffer.length < stringLength) {
......@@ -715,11 +715,8 @@ public class SwingUtilities2 {
// See if coords are inside
// ASSUME: mouse x,y will never be < cell's x,y
assert (p.x >= cellBounds.x && p.y >= cellBounds.y);
if (p.x > cellBounds.x + cellBounds.width ||
p.y > cellBounds.y + cellBounds.height) {
return true;
}
return false;
return p.x > cellBounds.x + cellBounds.width ||
p.y > cellBounds.y + cellBounds.height;
}
/**
......@@ -1239,12 +1236,11 @@ public class SwingUtilities2 {
private static synchronized boolean inputEvent_canAccessSystemClipboard(InputEvent ie) {
if (inputEvent_CanAccessSystemClipboard_Field == null) {
inputEvent_CanAccessSystemClipboard_Field =
(Field)AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
Field field = null;
AccessController.doPrivileged(
new java.security.PrivilegedAction<Field>() {
public Field run() {
try {
field = InputEvent.class.
Field field = InputEvent.class.
getDeclaredField("canAccessSystemClipboard");
field.setAccessible(true);
return field;
......@@ -1419,10 +1415,10 @@ public class SwingUtilities2 {
* Class.getResourceAsStream just returns raw
* bytes, which we can convert to an image.
*/
byte[] buffer = (byte[])
byte[] buffer =
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
new java.security.PrivilegedAction<byte[]>() {
public byte[] run() {
try {
InputStream resource = null;
Class<?> srchClass = baseClass;
......@@ -1489,7 +1485,7 @@ public class SwingUtilities2 {
return true;
}
// Else probably Solaris or Linux in which case may be remote X11
Class x11Class = Class.forName("sun.awt.X11GraphicsEnvironment");
Class<?> x11Class = Class.forName("sun.awt.X11GraphicsEnvironment");
Method isDisplayLocalMethod = x11Class.getMethod(
"isDisplayLocal", new Class[0]);
return (Boolean)isDisplayLocalMethod.invoke(null, (Object[])null);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册