Mercurial > hg > openjdk > jdk6 > jdk
changeset 1527:c3e8ac70542b
6727662: Code improvement and warnings removing from swing packages
Summary: Removed unnecessary castings and other warnings
Reviewed-by: malenkov
line wrap: on
line diff
--- a/src/share/classes/javax/swing/AbstractButton.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/AbstractButton.java Mon Dec 05 17:32:29 2016 +0000 @@ -1312,8 +1312,7 @@ // 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(); } @@ -1883,8 +1882,7 @@ * @since 1.4 */ public ChangeListener[] getChangeListeners() { - return (ChangeListener[])(listenerList.getListeners( - ChangeListener.class)); + return listenerList.getListeners(ChangeListener.class); } /** @@ -1941,8 +1939,7 @@ * @since 1.4 */ public ActionListener[] getActionListeners() { - return (ActionListener[])(listenerList.getListeners( - ActionListener.class)); + return listenerList.getListeners(ActionListener.class); } /** @@ -2134,7 +2131,7 @@ * @since 1.4 */ public ItemListener[] getItemListeners() { - return (ItemListener[])listenerList.getListeners(ItemListener.class); + return listenerList.getListeners(ItemListener.class); } /** @@ -2978,7 +2975,7 @@ paintViewR.height = AbstractButton.this.getHeight() - (paintViewInsets.top + paintViewInsets.bottom); String clippedText = SwingUtilities.layoutCompoundLabel( - (JComponent)AbstractButton.this, + AbstractButton.this, getFontMetrics(getFont()), text, icon,
--- a/src/share/classes/javax/swing/AbstractCellEditor.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/AbstractCellEditor.java Mon Dec 05 17:32:29 2016 +0000 @@ -118,8 +118,7 @@ * @since 1.4 */ public CellEditorListener[] getCellEditorListeners() { - return (CellEditorListener[])listenerList.getListeners( - CellEditorListener.class); + return listenerList.getListeners(CellEditorListener.class); } /**
--- a/src/share/classes/javax/swing/AbstractListModel.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/AbstractListModel.java Mon Dec 05 17:32:29 2016 +0000 @@ -85,8 +85,7 @@ * @since 1.4 */ public ListDataListener[] getListDataListeners() { - return (ListDataListener[])listenerList.getListeners( - ListDataListener.class); + return listenerList.getListeners(ListDataListener.class); }
--- a/src/share/classes/javax/swing/AbstractSpinnerModel.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/AbstractSpinnerModel.java Mon Dec 05 17:32:29 2016 +0000 @@ -97,8 +97,7 @@ * @since 1.4 */ public ChangeListener[] getChangeListeners() { - return (ChangeListener[])listenerList.getListeners( - ChangeListener.class); + return listenerList.getListeners(ChangeListener.class); }
--- a/src/share/classes/javax/swing/ActionMap.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/ActionMap.java Mon Dec 05 17:32:29 2016 +0000 @@ -197,7 +197,7 @@ return pKeys; } - HashMap keyMap = new HashMap(); + HashMap<Object, Object> keyMap = new HashMap<Object, Object>(); int counter; for (counter = keys.length - 1; counter >= 0; counter--) {
--- a/src/share/classes/javax/swing/AncestorNotifier.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/AncestorNotifier.java Mon Dec 05 17:32:29 2016 +0000 @@ -62,7 +62,7 @@ } AncestorListener[] getAncestorListeners() { - return (AncestorListener[])listenerList.getListeners(AncestorListener.class); + return listenerList.getListeners(AncestorListener.class); } /**
--- a/src/share/classes/javax/swing/ArrayTable.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/ArrayTable.java Mon Dec 05 17:32:29 2016 +0000 @@ -88,10 +88,10 @@ // 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 @@ */ 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]); }
--- a/src/share/classes/javax/swing/ButtonGroup.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/ButtonGroup.java Mon Dec 05 17:32:29 2016 +0000 @@ -68,7 +68,7 @@ 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.
--- a/src/share/classes/javax/swing/DebugGraphicsInfo.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/DebugGraphicsInfo.java Mon Dec 05 17:32:29 2016 +0000 @@ -37,7 +37,7 @@ 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 @@ return; } if (componentToDebug == null) { - componentToDebug = new Hashtable(); + componentToDebug = new Hashtable<JComponent, Integer>(); } if (debug > 0) { componentToDebug.put(component, new Integer(debug)); @@ -59,7 +59,7 @@ if (componentToDebug == null) { return 0; } else { - Integer integer = (Integer)componentToDebug.get(component); + Integer integer = componentToDebug.get(component); return integer == null ? 0 : integer.intValue(); }
--- a/src/share/classes/javax/swing/DefaultBoundedRangeModel.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/DefaultBoundedRangeModel.java Mon Dec 05 17:32:29 2016 +0000 @@ -343,8 +343,7 @@ * @since 1.4 */ public ChangeListener[] getChangeListeners() { - return (ChangeListener[])listenerList.getListeners( - ChangeListener.class); + return listenerList.getListeners(ChangeListener.class); }
--- a/src/share/classes/javax/swing/DefaultButtonModel.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/DefaultButtonModel.java Mon Dec 05 17:32:29 2016 +0000 @@ -326,8 +326,7 @@ * @since 1.4 */ public ChangeListener[] getChangeListeners() { - return (ChangeListener[])listenerList.getListeners( - ChangeListener.class); + return listenerList.getListeners(ChangeListener.class); } /** @@ -380,8 +379,7 @@ * @since 1.4 */ public ActionListener[] getActionListeners() { - return (ActionListener[])listenerList.getListeners( - ActionListener.class); + return listenerList.getListeners(ActionListener.class); } /** @@ -434,7 +432,7 @@ * @since 1.4 */ public ItemListener[] getItemListeners() { - return (ItemListener[])listenerList.getListeners(ItemListener.class); + return listenerList.getListeners(ItemListener.class); } /**
--- a/src/share/classes/javax/swing/DefaultFocusManager.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/DefaultFocusManager.java Mon Dec 05 17:32:29 2016 +0000 @@ -156,18 +156,17 @@ } } -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; } }
--- a/src/share/classes/javax/swing/DefaultListSelectionModel.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/DefaultListSelectionModel.java Mon Dec 05 17:32:29 2016 +0000 @@ -132,8 +132,7 @@ * @since 1.4 */ public ListSelectionListener[] getListSelectionListeners() { - return (ListSelectionListener[])listenerList.getListeners( - ListSelectionListener.class); + return listenerList.getListeners(ListSelectionListener.class); } /**
--- a/src/share/classes/javax/swing/DefaultSingleSelectionModel.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/DefaultSingleSelectionModel.java Mon Dec 05 17:32:29 2016 +0000 @@ -110,8 +110,7 @@ * @since 1.4 */ public ChangeListener[] getChangeListeners() { - return (ChangeListener[])listenerList.getListeners( - ChangeListener.class); + return listenerList.getListeners(ChangeListener.class); } /**
--- a/src/share/classes/javax/swing/GroupLayout.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/GroupLayout.java Mon Dec 05 17:32:29 2016 +0000 @@ -1119,7 +1119,7 @@ * 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 @@ 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(); }
--- a/src/share/classes/javax/swing/InputMap.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/InputMap.java Mon Dec 05 17:32:29 2016 +0000 @@ -200,7 +200,7 @@ 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 @@ KeyStroke[] allKeys = new KeyStroke[keyMap.size()]; - return (KeyStroke[])keyMap.keySet().toArray(allKeys); + return keyMap.keySet().toArray(allKeys); } private void writeObject(ObjectOutputStream s) throws IOException {
--- a/src/share/classes/javax/swing/JComboBox.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/JComboBox.java Mon Dec 05 17:32:29 2016 +0000 @@ -854,7 +854,7 @@ * @since 1.4 */ public ItemListener[] getItemListeners() { - return (ItemListener[])listenerList.getListeners(ItemListener.class); + return listenerList.getListeners(ItemListener.class); } /** @@ -892,8 +892,7 @@ * @since 1.4 */ public ActionListener[] getActionListeners() { - return (ActionListener[])listenerList.getListeners( - ActionListener.class); + return listenerList.getListeners(ActionListener.class); } /** @@ -932,8 +931,7 @@ * @since 1.4 */ public PopupMenuListener[] getPopupMenuListeners() { - return (PopupMenuListener[])listenerList.getListeners( - PopupMenuListener.class); + return listenerList.getListeners(PopupMenuListener.class); } /** @@ -1663,7 +1661,7 @@ 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()); @@ -1736,7 +1734,7 @@ // Fire a FOCUSED lost PropertyChangeEvent for the // previously selected list item. - PropertyChangeEvent pce = null; + PropertyChangeEvent pce; if (previousSelectedAccessible != null) { pce = new PropertyChangeEvent(previousSelectedAccessible,
--- a/src/share/classes/javax/swing/JComponent.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/JComponent.java Mon Dec 05 17:32:29 2016 +0000 @@ -182,7 +182,8 @@ /** * @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 @@ -345,7 +346,7 @@ /** * 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; @@ -439,7 +440,7 @@ 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); @@ -794,7 +795,7 @@ // its index. if (paintingChild != null && (paintingChild instanceof JComponent) && - ((JComponent)paintingChild).isOpaque()) { + paintingChild.isOpaque()) { for (; i >= 0; i--) { if (getComponent(i) == paintingChild){ break; @@ -863,7 +864,7 @@ shouldSetFlagBack = true; } if(!printing) { - ((JComponent)comp).paint(cg); + comp.paint(cg); } else { if (!getFlag(IS_PRINTING_ALL)) { @@ -1086,7 +1087,7 @@ } private void adjustPaintFlags() { - JComponent jparent = null; + JComponent jparent; Container parent; for(parent = getParent() ; parent != null ; parent = parent.getParent()) { @@ -2081,7 +2082,7 @@ 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) { @@ -2105,10 +2106,10 @@ } // 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(); @@ -2116,7 +2117,7 @@ // 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--) { @@ -2159,7 +2160,7 @@ 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); @@ -3647,7 +3648,7 @@ 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) { @@ -3655,7 +3656,7 @@ if (c != null && c instanceof Accessible) { AccessibleJComponent.this.firePropertyChange( AccessibleContext.ACCESSIBLE_CHILD_PROPERTY, - ((Accessible) c).getAccessibleContext(), null); + c.getAccessibleContext(), null); } } } @@ -4351,7 +4352,7 @@ // 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 @@ -4667,7 +4668,7 @@ result = (T[])getPropertyChangeListeners(); } else { - result = (T[])listenerList.getListeners(listenerType); + result = listenerList.getListeners(listenerType); } if (result.length == 0) { @@ -4878,7 +4879,7 @@ if(!isShowing()) { return; } - while(!((JComponent)c).isOpaque()) { + while(!c.isOpaque()) { parent = c.getParent(); if(parent != null) { x += c.getX(); @@ -5172,7 +5173,7 @@ Rectangle siblingRect; boolean opaque; if (sibling instanceof JComponent) { - opaque = ((JComponent)sibling).isOpaque(); + opaque = sibling.isOpaque(); if (!opaque) { if (retValue == PARTIALLY_OBSCURED) { continue; @@ -5319,7 +5320,7 @@ */ 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 { @@ -5335,8 +5336,7 @@ */ 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); } } @@ -5356,8 +5356,7 @@ /* 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; @@ -5370,7 +5369,7 @@ * 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--); // !! @@ -5402,7 +5401,7 @@ * 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));
--- a/src/share/classes/javax/swing/JDesktopPane.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/JDesktopPane.java Mon Dec 05 17:32:29 2016 +0000 @@ -133,8 +133,8 @@ 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 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 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); } }
--- a/src/share/classes/javax/swing/JDialog.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/JDialog.java Mon Dec 05 17:32:29 2016 +0000 @@ -271,7 +271,7 @@ title, modal); if (owner == null) { WindowListener ownerShutdownListener = - (WindowListener)SwingUtilities.getSharedOwnerFrameShutdownListener(); + SwingUtilities.getSharedOwnerFrameShutdownListener(); addWindowListener(ownerShutdownListener); } dialogInit(); @@ -323,7 +323,7 @@ title, modal, gc); if (owner == null) { WindowListener ownerShutdownListener = - (WindowListener)SwingUtilities.getSharedOwnerFrameShutdownListener(); + SwingUtilities.getSharedOwnerFrameShutdownListener(); addWindowListener(ownerShutdownListener); } dialogInit();
--- a/src/share/classes/javax/swing/JEditorPane.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/JEditorPane.java Mon Dec 05 17:32:29 2016 +0000 @@ -317,8 +317,7 @@ * @since 1.4 */ public synchronized HyperlinkListener[] getHyperlinkListeners() { - return (HyperlinkListener[])listenerList.getListeners( - HyperlinkListener.class); + return listenerList.getListeners(javax.swing.event.HyperlinkListener.class); } /** @@ -496,8 +495,8 @@ 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(); @@ -832,7 +831,7 @@ */ private void handleConnectionProperties(URLConnection conn) { if (pageProperties == null) { - pageProperties = new Hashtable(); + pageProperties = new Hashtable<String, Object>(); } String type = conn.getContentType(); if (type != null) { @@ -1046,7 +1045,7 @@ * 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(';'); @@ -1137,9 +1136,9 @@ */ 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) { @@ -1163,7 +1162,7 @@ */ public void setEditorKitForContentType(String type, EditorKit k) { if (typeHandlers == null) { - typeHandlers = new Hashtable(3); + typeHandlers = new Hashtable<String, EditorKit>(3); } typeHandlers.put(type, k); } @@ -1238,13 +1237,12 @@ * 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) { @@ -1314,20 +1312,20 @@ * @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); @@ -1583,7 +1581,7 @@ 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"; @@ -1591,7 +1589,7 @@ /** * 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. @@ -1981,11 +1979,11 @@ } } - 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; } @@ -2097,7 +2095,7 @@ buildLinkTable(); } if (linkIndex >= 0 && linkIndex < hyperlinks.size()) { - return (AccessibleHyperlink) hyperlinks.elementAt(linkIndex); + return hyperlinks.elementAt(linkIndex); } else { return null; }
--- a/src/share/classes/javax/swing/JFileChooser.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/JFileChooser.java Mon Dec 05 17:32:29 2016 +0000 @@ -248,7 +248,7 @@ 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 @@ if(selectedFiles == null) { return new File[0]; } else { - return (File[]) selectedFiles.clone(); + return selectedFiles.clone(); } } @@ -1413,17 +1413,17 @@ 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); @@ -1700,8 +1700,7 @@ * @since 1.4 */ public ActionListener[] getActionListeners() { - return (ActionListener[])listenerList.getListeners( - ActionListener.class); + return listenerList.getListeners(ActionListener.class); } /** @@ -1742,7 +1741,7 @@ 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);
--- a/src/share/classes/javax/swing/JInternalFrame.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/JInternalFrame.java Mon Dec 05 17:32:29 2016 +0000 @@ -415,8 +415,8 @@ 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); } } } @@ -1529,8 +1529,7 @@ * @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? @@ -2252,8 +2251,8 @@ 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); } } }
--- a/src/share/classes/javax/swing/JLayeredPane.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/JLayeredPane.java Mon Dec 05 17:32:29 2016 +0000 @@ -191,7 +191,7 @@ private void validateOptimizedDrawing() { boolean layeredComponentFound = false; synchronized(getTreeLock()) { - Integer layer = null; + Integer layer; for (Component c : getComponents()) { layer = null; @@ -213,7 +213,7 @@ } 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 @@ 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 @@ 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 @@ * @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)
--- a/src/share/classes/javax/swing/JList.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/JList.java Mon Dec 05 17:32:29 2016 +0000 @@ -1845,8 +1845,7 @@ * @since 1.4 */ public ListSelectionListener[] getListSelectionListeners() { - return (ListSelectionListener[])listenerList.getListeners( - ListSelectionListener.class); + return listenerList.getListeners(ListSelectionListener.class); } @@ -2216,9 +2215,9 @@ 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); } } } @@ -2720,7 +2719,7 @@ return true; } if (getParent() instanceof JViewport) { - return (((JViewport)getParent()).getWidth() > getPreferredSize().width); + return (getParent().getWidth() > getPreferredSize().width); } return false; } @@ -2745,7 +2744,7 @@ return true; } if (getParent() instanceof JViewport) { - return (((JViewport)getParent()).getHeight() > getPreferredSize().height); + return (getParent().getHeight() > getPreferredSize().height); } return false; } @@ -3157,7 +3156,7 @@ private AccessibleContext getCurrentAccessibleContext() { Component c = getComponentAtIndex(indexInParent); if (c instanceof Accessible) { - return ((Accessible) c).getAccessibleContext(); + return c.getAccessibleContext(); } else { return null; }
--- a/src/share/classes/javax/swing/JMenu.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/JMenu.java Mon Dec 05 17:32:29 2016 +0000 @@ -371,8 +371,8 @@ * @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 @@ * on another menu */ public boolean isTopLevelMenu() { - if (getParent() instanceof JMenuBar) - return true; + return getParent() instanceof JMenuBar; - return false; } /** @@ -1015,7 +1013,7 @@ * @since 1.4 */ public MenuListener[] getMenuListeners() { - return (MenuListener[])listenerList.getListeners(MenuListener.class); + return listenerList.getListeners(MenuListener.class); } /** @@ -1305,7 +1303,7 @@ * @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 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 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 @@ } 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];
--- a/src/share/classes/javax/swing/JMenuBar.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/JMenuBar.java Mon Dec 05 17:32:29 2016 +0000 @@ -412,7 +412,7 @@ */ public MenuElement[] getSubElements() { MenuElement result[]; - Vector tmp = new Vector(); + Vector<MenuElement> tmp = new Vector<MenuElement>(); int c = getComponentCount(); int i; Component m; @@ -420,12 +420,12 @@ 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; } @@ -662,9 +662,9 @@ 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; } } @@ -691,9 +691,8 @@ } 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 }
--- a/src/share/classes/javax/swing/JMenuItem.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/JMenuItem.java Mon Dec 05 17:32:29 2016 +0000 @@ -275,7 +275,7 @@ * 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 @@ * @see #setArmed */ public boolean isArmed() { - ButtonModel model = (ButtonModel) getModel(); + ButtonModel model = getModel(); return model.isArmed(); } @@ -721,8 +721,7 @@ * @since 1.4 */ public MenuDragMouseListener[] getMenuDragMouseListeners() { - return (MenuDragMouseListener[])listenerList.getListeners( - MenuDragMouseListener.class); + return listenerList.getListeners(MenuDragMouseListener.class); } /** @@ -752,8 +751,7 @@ * @since 1.4 */ public MenuKeyListener[] getMenuKeyListeners() { - return (MenuKeyListener[])listenerList.getListeners( - MenuKeyListener.class); + return listenerList.getListeners(MenuKeyListener.class); } /**
--- a/src/share/classes/javax/swing/JOptionPane.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/JOptionPane.java Mon Dec 05 17:32:29 2016 +0000 @@ -963,7 +963,7 @@ } if (window instanceof SwingUtilities.SharedOwnerFrame) { WindowListener ownerShutdownListener = - (WindowListener)SwingUtilities.getSharedOwnerFrameShutdownListener(); + SwingUtilities.getSharedOwnerFrameShutdownListener(); dialog.addWindowListener(ownerShutdownListener); } initDialog(dialog, style, parentComponent); @@ -1300,11 +1300,10 @@ // 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 @@ // 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 @@ 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 @@ * 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 @@ // 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 @@ } // 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 @@ /** * 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);
--- a/src/share/classes/javax/swing/JPopupMenu.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/JPopupMenu.java Mon Dec 05 17:32:29 2016 +0000 @@ -541,7 +541,7 @@ 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 @@ -557,8 +557,8 @@ /* 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); } } @@ -589,8 +589,7 @@ * @since 1.4 */ public PopupMenuListener[] getPopupMenuListeners() { - return (PopupMenuListener[])listenerList.getListeners( - PopupMenuListener.class); + return listenerList.getListeners(PopupMenuListener.class); } /** @@ -622,8 +621,7 @@ * @since 1.5 */ public MenuKeyListener[] getMenuKeyListeners() { - return (MenuKeyListener[])listenerList.getListeners( - MenuKeyListener.class); + return listenerList.getListeners(MenuKeyListener.class); } /** @@ -738,7 +736,7 @@ // set selection path before popping up! if (isPopupMenu()) { MenuElement me[] = new MenuElement[1]; - me[0] = (MenuElement) this; + me[0] = this; MenuSelectionManager.defaultManager().setSelectedPath(me); } } @@ -805,10 +803,7 @@ * being displayed). */ public boolean isVisible() { - if(popup != null) - return true; - else - return false; + return popup != null; } /** @@ -1268,7 +1263,7 @@ // 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. @@ -1451,7 +1446,7 @@ */ public MenuElement[] getSubElements() { MenuElement result[]; - Vector tmp = new Vector(); + Vector<MenuElement> tmp = new Vector<MenuElement>(); int c = getComponentCount(); int i; Component m; @@ -1459,12 +1454,12 @@ 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; }
--- a/src/share/classes/javax/swing/JProgressBar.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/JProgressBar.java Mon Dec 05 17:32:29 2016 +0000 @@ -699,8 +699,7 @@ * @since 1.4 */ public ChangeListener[] getChangeListeners() { - return (ChangeListener[])listenerList.getListeners( - ChangeListener.class); + return listenerList.getListeners(ChangeListener.class); } /**
--- a/src/share/classes/javax/swing/JScrollBar.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/JScrollBar.java Mon Dec 05 17:32:29 2016 +0000 @@ -659,8 +659,7 @@ * @since 1.4 */ public AdjustmentListener[] getAdjustmentListeners() { - return (AdjustmentListener[])listenerList.getListeners( - AdjustmentListener.class); + return listenerList.getListeners(AdjustmentListener.class); } @@ -754,8 +753,8 @@ 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); } }
--- a/src/share/classes/javax/swing/JSlider.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/JSlider.java Mon Dec 05 17:32:29 2016 +0000 @@ -913,7 +913,7 @@ 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; @@ -962,7 +962,7 @@ Enumeration keys = getLabelTable().keys(); Object key = null; - Hashtable hashtable = new Hashtable(); + Hashtable<Object, Object> hashtable = new Hashtable<Object, Object>(); // Save the labels that were added by the developer while ( keys.hasMoreElements() ) {
--- a/src/share/classes/javax/swing/JSpinner.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/JSpinner.java Mon Dec 05 17:32:29 2016 +0000 @@ -426,8 +426,7 @@ * @since 1.4 */ public ChangeListener[] getChangeListeners() { - return (ChangeListener[])listenerList.getListeners( - ChangeListener.class); + return listenerList.getListeners(ChangeListener.class); } @@ -1546,7 +1545,7 @@ return textField.getAccessibleContext(); } } else if (editor instanceof Accessible) { - return ((Accessible)editor).getAccessibleContext(); + return editor.getAccessibleContext(); } return null; } @@ -1703,7 +1702,7 @@ if (i < 0 || i > 1) { return false; } - Object o = null; + Object o; if (i == 0) { o = getNextValue(); // AccessibleAction.INCREMENT } else {
--- a/src/share/classes/javax/swing/JTabbedPane.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/JTabbedPane.java Mon Dec 05 17:32:29 2016 +0000 @@ -313,8 +313,7 @@ * @since 1.4 */ public ChangeListener[] getChangeListeners() { - return (ChangeListener[])listenerList.getListeners( - ChangeListener.class); + return listenerList.getListeners(ChangeListener.class); } /** @@ -2060,7 +2059,7 @@ * Accessibility classes unnecessarily. */ AccessibleContext ac; - ac = ((Accessible) component).getAccessibleContext(); + ac = component.getAccessibleContext(); if (ac != null) { ac.setAccessibleParent(this); }
--- a/src/share/classes/javax/swing/JTable.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/JTable.java Mon Dec 05 17:32:29 2016 +0000 @@ -1731,16 +1731,16 @@ if (!forDrop && state != null) { clearSelection(); - int[] rows = (int[])((int[][])state)[0]; - int[] cols = (int[])((int[][])state)[1]; - int[] anchleads = (int[])((int[][])state)[2]; - - for (int i = 0; i < rows.length; i++) { - addRowSelectionInterval(rows[i], rows[i]); + int[] rows = ((int[][])state)[0]; + int[] cols = ((int[][])state)[1]; + int[] anchleads = ((int[][])state)[2]; + + 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( @@ -1830,7 +1830,7 @@ boolean oldValue = this.autoCreateRowSorter; this.autoCreateRowSorter = autoCreateRowSorter; if (autoCreateRowSorter) { - setRowSorter(new TableRowSorter(getModel())); + setRowSorter(new TableRowSorter<TableModel>(getModel())); } firePropertyChange("autoCreateRowSorter", oldValue, autoCreateRowSorter); @@ -3244,7 +3244,7 @@ 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) { @@ -3283,8 +3283,6 @@ } adjustSizes(totalWidth + delta, r, false); - - return; } private interface Resizable2 { @@ -3538,7 +3536,7 @@ * @see #editingRow */ public boolean isEditing() { - return (cellEditor == null)? false : true; + return cellEditor != null; } /** @@ -3691,7 +3689,7 @@ firePropertyChange("model", old, dataModel); if (getAutoCreateRowSorter()) { - setRowSorter(new TableRowSorter(dataModel)); + setRowSorter(new TableRowSorter<TableModel>(dataModel)); } } } @@ -5209,7 +5207,7 @@ public boolean getScrollableTracksViewportHeight() { return getFillsViewportHeight() && getParent() instanceof JViewport - && (((JViewport)getParent()).getHeight() > getPreferredSize().height); + && (getParent().getHeight() > getPreferredSize().height); } /** @@ -5263,7 +5261,7 @@ // 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) { @@ -5486,7 +5484,7 @@ 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 @@ -6679,10 +6677,10 @@ } 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); } } } @@ -7097,7 +7095,7 @@ */ public Accessible getAccessibleSelection(int i) { if (i < 0 || i > getAccessibleSelectionCount()) { - return (Accessible) null; + return null; } int rowsSel = JTable.this.getSelectedRowCount(); @@ -7210,7 +7208,7 @@ return getAccessibleChild((r * ttlCols) + c); } } - return (Accessible) null; + return null; } /** @@ -7958,7 +7956,7 @@ JTable.this, getValueAt(row, column), false, false, row, column); if (component instanceof Accessible) { - return ((Accessible) component).getAccessibleContext(); + return component.getAccessibleContext(); } else { return null; }
--- a/src/share/classes/javax/swing/JTextField.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/JTextField.java Mon Dec 05 17:32:29 2016 +0000 @@ -475,8 +475,7 @@ * @since 1.4 */ public synchronized ActionListener[] getActionListeners() { - return (ActionListener[])listenerList.getListeners( - ActionListener.class); + return listenerList.getListeners(ActionListener.class); } /**
--- a/src/share/classes/javax/swing/JTree.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/JTree.java Mon Dec 05 17:32:29 2016 +0000 @@ -187,7 +187,7 @@ * 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 @@ * 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>. @@ -651,9 +651,9 @@ */ 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; @@ -688,7 +688,7 @@ * 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 { @@ -1273,8 +1273,8 @@ 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; @@ -1907,14 +1907,14 @@ 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 @@ -1923,7 +1923,7 @@ ((Boolean)value).booleanValue() && parent.isDescendant(path) && isVisible(path)) { if (elements == null) { - elements = new Vector(); + elements = new Vector<TreePath>(); } elements.addElement(path); } @@ -1957,9 +1957,9 @@ return false; // Is this node expanded? - Object value = expandedState.get(path); - - if(value == null || !((Boolean)value).booleanValue()) + Boolean value = expandedState.get(path); + + if(value == null || !value.booleanValue()) return false; // It is, make sure its parent is also expanded. @@ -1985,7 +1985,7 @@ 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()); } @@ -2607,8 +2607,7 @@ * @since 1.4 */ public TreeExpansionListener[] getTreeExpansionListeners() { - return (TreeExpansionListener[])listenerList.getListeners( - TreeExpansionListener.class); + return listenerList.getListeners(TreeExpansionListener.class); } /** @@ -2640,8 +2639,7 @@ * @since 1.4 */ public TreeWillExpandListener[] getTreeWillExpandListeners() { - return (TreeWillExpandListener[])listenerList.getListeners( - TreeWillExpandListener.class); + return listenerList.getListeners(TreeWillExpandListener.class); } /** @@ -2798,8 +2796,7 @@ * @since 1.4 */ public TreeSelectionListener[] getTreeSelectionListeners() { - return (TreeSelectionListener[])listenerList.getListeners( - TreeSelectionListener.class); + return listenerList.getListeners(TreeSelectionListener.class); } /** @@ -2931,7 +2928,7 @@ // 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. @@ -2978,9 +2975,9 @@ // Create an instance of expanded state. - expandedState = new Hashtable(); - - expandedStack = new Stack(); + expandedState = new Hashtable<TreePath, Boolean>(); + + expandedStack = new Stack<Stack<TreePath>>(); Vector values = (Vector)s.readObject(); int indexCounter = 0; @@ -3033,13 +3030,13 @@ 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 { @@ -3317,7 +3314,7 @@ */ public boolean getScrollableTracksViewportWidth() { if (getParent() instanceof JViewport) { - return (((JViewport)getParent()).getWidth() > getPreferredSize().width); + return getParent().getWidth() > getPreferredSize().width; } return false; } @@ -3333,7 +3330,7 @@ */ public boolean getScrollableTracksViewportHeight() { if (getParent() instanceof JViewport) { - return (((JViewport)getParent()).getHeight() > getPreferredSize().height); + return getParent().getHeight() > getPreferredSize().height; } return false; } @@ -3350,14 +3347,14 @@ protected void setExpandedState(TreePath path, boolean state) { if(path != null) { // Make sure all parents of path are expanded. - Stack stack; - TreePath parentPath = path.getParentPath(); + 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 { @@ -3371,7 +3368,7 @@ } } for(int counter = stack.size() - 1; counter >= 0; counter--) { - parentPath = (TreePath)stack.pop(); + parentPath = stack.pop(); if(!isExpanded(parentPath)) { try { fireTreeWillExpand(parentPath); @@ -3451,12 +3448,11 @@ 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); } @@ -3473,8 +3469,8 @@ { if(toRemove != null) { while(toRemove.hasMoreElements()) { - Enumeration descendants = getDescendantToggledPaths - ((TreePath)toRemove.nextElement()); + Enumeration descendants = getDescendantToggledPaths + (toRemove.nextElement()); if(descendants != null) { while(descendants.hasMoreElements()) { @@ -4059,7 +4055,7 @@ private AccessibleContext getCurrentAccessibleContext() { Component c = getCurrentComponent(); if (c instanceof Accessible) { - return (((Accessible) c).getAccessibleContext()); + return c.getAccessibleContext(); } else { return null; } @@ -4382,7 +4378,7 @@ private AccessibleContext getCurrentAccessibleContext() { Component c = getCurrentComponent(); if (c instanceof Accessible) { - return (((Accessible) c).getAccessibleContext()); + return c.getAccessibleContext(); } else { return null; } @@ -4926,12 +4922,8 @@ 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) {
--- a/src/share/classes/javax/swing/JViewport.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/JViewport.java Mon Dec 05 17:32:29 2016 +0000 @@ -388,7 +388,7 @@ // 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); @@ -681,10 +681,7 @@ * @see JComponent#isPaintingOrigin() */ boolean isPaintingOrigin() { - if (scrollMode == BACKINGSTORE_SCROLL_MODE) { - return true; - } - return false; + return scrollMode == BACKINGSTORE_SCROLL_MODE; } @@ -902,11 +899,7 @@ */ public void setScrollMode(int mode) { scrollMode = mode; - if (mode == BACKINGSTORE_SCROLL_MODE) { - backingStore = true; - } else { - backingStore = false; - } + backingStore = mode == BACKINGSTORE_SCROLL_MODE; } /** @@ -957,10 +950,10 @@ } } - 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(); } @@ -1378,8 +1371,7 @@ * @since 1.4 */ public ChangeListener[] getChangeListeners() { - return (ChangeListener[])listenerList.getListeners( - ChangeListener.class); + return listenerList.getListeners(ChangeListener.class); } /**
--- a/src/share/classes/javax/swing/JWindow.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/JWindow.java Mon Dec 05 17:32:29 2016 +0000 @@ -185,7 +185,7 @@ super(owner == null? SwingUtilities.getSharedOwnerFrame() : owner); if (owner == null) { WindowListener ownerShutdownListener = - (WindowListener)SwingUtilities.getSharedOwnerFrameShutdownListener(); + SwingUtilities.getSharedOwnerFrameShutdownListener(); addWindowListener(ownerShutdownListener); } windowInit(); @@ -212,7 +212,7 @@ owner); if (owner == null) { WindowListener ownerShutdownListener = - (WindowListener)SwingUtilities.getSharedOwnerFrameShutdownListener(); + SwingUtilities.getSharedOwnerFrameShutdownListener(); addWindowListener(ownerShutdownListener); } windowInit(); @@ -250,7 +250,7 @@ owner, gc); if (owner == null) { WindowListener ownerShutdownListener = - (WindowListener)SwingUtilities.getSharedOwnerFrameShutdownListener(); + SwingUtilities.getSharedOwnerFrameShutdownListener(); addWindowListener(ownerShutdownListener); } windowInit();
--- a/src/share/classes/javax/swing/KeyboardManager.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/KeyboardManager.java Mon Dec 05 17:32:29 2016 +0000 @@ -68,13 +68,13 @@ /** * 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 @@ 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 @@ // 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 @@ 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 @@ 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 @@ 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 @@ 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) {
--- a/src/share/classes/javax/swing/LayoutComparator.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/LayoutComparator.java Mon Dec 05 17:32:29 2016 +0000 @@ -39,7 +39,7 @@ * * @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 @@ 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 @@ // 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 @@ 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 @@ 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;
--- a/src/share/classes/javax/swing/LayoutFocusTraversalPolicy.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/LayoutFocusTraversalPolicy.java Mon Dec 05 17:32:29 2016 +0000 @@ -65,7 +65,7 @@ * Constructs a LayoutFocusTraversalPolicy with the passed in * <code>Comparator</code>. */ - LayoutFocusTraversalPolicy(Comparator c) { + LayoutFocusTraversalPolicy(Comparator<? super Component> c) { super(c); }
--- a/src/share/classes/javax/swing/LegacyGlueFocusTraversalPolicy.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/LegacyGlueFocusTraversalPolicy.java Mon Dec 05 17:32:29 2016 +0000 @@ -48,8 +48,8 @@ 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 @@ 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 @@ 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)) {
--- a/src/share/classes/javax/swing/MenuSelectionManager.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/MenuSelectionManager.java Mon Dec 05 17:32:29 2016 +0000 @@ -37,7 +37,7 @@ * @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 @@ -99,14 +99,14 @@ } 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); } @@ -130,7 +130,7 @@ 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; } @@ -171,8 +171,7 @@ * @since 1.4 */ public ChangeListener[] getChangeListeners() { - return (ChangeListener[])listenerList.getListeners( - ChangeListener.class); + return listenerList.getListeners(ChangeListener.class); } /** @@ -255,8 +254,8 @@ 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; @@ -335,7 +334,7 @@ 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) { @@ -396,8 +395,8 @@ 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; @@ -426,7 +425,7 @@ */ 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; @@ -471,7 +470,7 @@ */ 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;
--- a/src/share/classes/javax/swing/MultiUIDefaults.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/MultiUIDefaults.java Mon Dec 05 17:32:29 2016 +0000 @@ -60,8 +60,7 @@ 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; @@ -79,8 +78,7 @@ 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; @@ -101,7 +99,7 @@ } @Override - public Enumeration keys() + public Enumeration<Object> keys() { return new MultiUIDefaultsEnumerator( MultiUIDefaultsEnumerator.Type.KEYS, entrySet()); @@ -109,7 +107,7 @@ @Override - public Enumeration elements() + public Enumeration<Object> elements() { return new MultiUIDefaultsEnumerator( MultiUIDefaultsEnumerator.Type.ELEMENTS, entrySet()); @@ -136,7 +134,7 @@ } } - private static class MultiUIDefaultsEnumerator implements Enumeration + private static class MultiUIDefaultsEnumerator implements Enumeration<Object> { public static enum Type { KEYS, ELEMENTS }; private Iterator<Entry<Object, Object>> iterator; @@ -183,8 +181,7 @@ @Override 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(); }
--- a/src/share/classes/javax/swing/PopupFactory.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/PopupFactory.java Mon Dec 05 17:32:29 2016 +0000 @@ -311,9 +311,9 @@ 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; } @@ -355,17 +355,16 @@ */ 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; } @@ -378,13 +377,13 @@ * <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); } @@ -397,13 +396,13 @@ */ 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 @@ -412,28 +411,27 @@ 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(); } } } @@ -532,10 +530,9 @@ 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; } @@ -665,11 +662,11 @@ /** * 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; @@ -680,7 +677,7 @@ */ 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); } @@ -693,11 +690,9 @@ */ 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; } @@ -753,8 +748,7 @@ 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); } @@ -823,12 +817,12 @@ /** * 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; @@ -839,7 +833,7 @@ */ 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); } @@ -852,12 +846,9 @@ */ 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; } @@ -901,7 +892,7 @@ 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,
--- a/src/share/classes/javax/swing/RepaintManager.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/RepaintManager.java Mon Dec 05 17:32:29 2016 +0000 @@ -593,7 +593,7 @@ */ 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 @@ * dirty. */ public Rectangle getDirtyRegion(JComponent 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); @@ -890,7 +890,7 @@ 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);; @@ -937,7 +937,7 @@ 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); } @@ -1013,7 +1013,7 @@ private Image _getOffscreenBuffer(Component c, int proposedWidth, int proposedHeight) { Dimension maxSize = getDoubleBufferMaximumSize(); - DoubleBufferInfo doubleBuffer = null; + DoubleBufferInfo doubleBuffer; int width, height; if (standardDoubleBuffer == null) { @@ -1082,7 +1082,7 @@ 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(); @@ -1250,7 +1250,7 @@ */ void beginPaint() { boolean multiThreadedPaint = false; - int paintDepth = 0; + int paintDepth; Thread currentThread = Thread.currentThread(); synchronized(this) { paintDepth = this.paintDepth;
--- a/src/share/classes/javax/swing/SortingFocusTraversalPolicy.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/SortingFocusTraversalPolicy.java Mon Dec 05 17:32:29 2016 +0000 @@ -79,7 +79,7 @@ * sorted list should be reused if possible. */ private Container cachedRoot; - private List cachedCycle; + private List<Component> cachedCycle; // Delegate our fitness test to ContainerOrder so that we only have to // code the algorithm once. @@ -103,7 +103,7 @@ } private void enumerateAndSortCycle(Container focusCycleRoot, - List cycle, Map defaults) { + List<Component> cycle, Map defaults) { List defaultRoots = null; if (!focusCycleRoot.isShowing()) { @@ -165,7 +165,7 @@ } } - private void enumerateCycle(Container container, List cycle) { + private void enumerateCycle(Container container, List<Component> cycle) { if (!(container.isVisible() && container.isDisplayable())) { return; } @@ -173,8 +173,7 @@ 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)comp).isFocusTraversalPolicyProvider() && !((Container)comp).isFocusCycleRoot() @@ -437,7 +436,7 @@ * @throws IllegalArgumentException if aContainer is null */ public Component getFirstComponent(Container aContainer) { - List cycle; + List<Component> cycle; if (log.isLoggable(Level.FINE)) log.fine("### Getting first component in " + aContainer.getName()); if (aContainer == null) { @@ -447,7 +446,7 @@ if (this.cachedRoot == aContainer) { cycle = this.cachedCycle; } else { - cycle = new ArrayList(); + cycle = new ArrayList<Component>(); enumerateAndSortCycle(aContainer, cycle, null); } @@ -456,8 +455,7 @@ return null; } - for (int i= 0; i < cycle.size(); i++) { - Component comp = (Component)cycle.get(i); + for (Component comp : cycle) { if (accept(comp)) { return comp; } else if (comp instanceof Container && !(comp == aContainer) && ((Container)comp).isFocusTraversalPolicyProvider()) { @@ -479,7 +477,7 @@ * @throws IllegalArgumentException if aContainer is null */ public Component getLastComponent(Container aContainer) { - List cycle; + List<Component> cycle; if (log.isLoggable(Level.FINE)) log.fine("### Getting last component in " + aContainer.getName()); if (aContainer == null) { @@ -489,7 +487,7 @@ if (this.cachedRoot == aContainer) { cycle = this.cachedCycle; } else { - cycle = new ArrayList(); + cycle = new ArrayList<Component>(); enumerateAndSortCycle(aContainer, cycle, null); } @@ -500,8 +498,7 @@ } if (log.isLoggable(Level.FINE)) log.fine("### Cycle is " + cycle); - for (int i= cycle.size()-1; i >= 0; i--) { - Component comp = (Component)cycle.get(i); + for (Component comp : cycle) { if (accept(comp)) { return comp; } else if (comp instanceof Container && !(comp == aContainer) && ((Container)comp).isFocusTraversalPolicyProvider()) {
--- a/src/share/classes/javax/swing/SpringLayout.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/SpringLayout.java Mon Dec 05 17:32:29 2016 +0000 @@ -185,11 +185,11 @@ * @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 @@ } 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 @@ /*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 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 @@ * @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);
--- a/src/share/classes/javax/swing/SwingUtilities.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/SwingUtilities.java Mon Dec 05 17:32:29 2016 +0000 @@ -106,11 +106,8 @@ * 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); } /** @@ -270,8 +267,7 @@ } 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) { @@ -374,8 +370,8 @@ 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 { @@ -413,8 +409,8 @@ 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 { @@ -978,7 +974,7 @@ */ int gap; - View v = null; + View v; if (textIsEmpty) { textR.width = textR.height = 0; text = ""; @@ -1246,8 +1242,8 @@ children = ((Container)c).getComponents(); } if (children != null) { - for(int i = 0; i < children.length; i++) { - updateComponentTreeUI0(children[i]); + for (Component child : children) { + updateComponentTreeUI0(child); } } } @@ -1700,7 +1696,7 @@ */ 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(); @@ -1767,8 +1763,7 @@ */ 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); @@ -1783,8 +1778,7 @@ 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; @@ -1872,7 +1866,7 @@ } - static Class loadSystemClass(String className) throws ClassNotFoundException { + static Class<?> loadSystemClass(String className) throws ClassNotFoundException { ReflectUtil.checkPackageAccess(className); return Class.forName(className, true, Thread.currentThread(). getContextClassLoader());
--- a/src/share/classes/javax/swing/Timer.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/Timer.java Mon Dec 05 17:32:29 2016 +0000 @@ -290,8 +290,7 @@ * @since 1.4 */ public ActionListener[] getActionListeners() { - return (ActionListener[])listenerList.getListeners( - ActionListener.class); + return listenerList.getListeners(ActionListener.class); }
--- a/src/share/classes/javax/swing/TimerQueue.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/TimerQueue.java Mon Dec 05 17:32:29 2016 +0000 @@ -96,7 +96,7 @@ 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"); @@ -232,7 +232,7 @@ /** * Returns nanosecond time offset by origin */ - private final static long now() { + private static long now() { return System.nanoTime() - NANO_ORIGIN; }
--- a/src/share/classes/javax/swing/UIDefaults.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/UIDefaults.java Mon Dec 05 17:32:29 2016 +0000 @@ -74,11 +74,11 @@ */ 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(); @@ -88,7 +88,7 @@ * 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. @@ -108,7 +108,7 @@ */ public UIDefaults(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); - resourceCache = new HashMap(); + resourceCache = new HashMap<Locale, Map<String, Object>>(); } @@ -283,24 +283,24 @@ 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 TextAndMnemonicHashMap(); 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; @@ -755,7 +755,7 @@ 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) { @@ -765,8 +765,7 @@ 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}); @@ -866,7 +865,7 @@ return; } if( resourceBundles == null ) { - resourceBundles = new Vector(5); + resourceBundles = new Vector<String>(5); } if (!resourceBundles.contains(bundleName)) { resourceBundles.add( bundleName ); @@ -1068,7 +1067,7 @@ className = c; methodName = m; if (o != null) { - args = (Object[])o.clone(); + args = o.clone(); } } @@ -1086,10 +1085,10 @@ if (acc == null && System.getSecurityManager() != null) { throw new SecurityException("null AccessControlContext"); } - 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"))
--- a/src/share/classes/javax/swing/UIManager.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/UIManager.java Mon Dec 05 17:32:29 2016 +0000 @@ -191,7 +191,7 @@ MultiUIDefaults multiUIDefaults = new MultiUIDefaults(tables); LookAndFeel lookAndFeel; LookAndFeel multiLookAndFeel = null; - Vector auxLookAndFeels = null; + Vector<LookAndFeel> auxLookAndFeels = null; SwingPropertyChangeSupport changeSupport; LookAndFeelInfo[] installedLAFs; @@ -357,7 +357,7 @@ 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( @@ -381,8 +381,7 @@ 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()]); } @@ -625,7 +624,7 @@ * @see #getSystemLookAndFeelClassName */ public static String getCrossPlatformLookAndFeelClassName() { - String laf = (String)AccessController.doPrivileged( + String laf = AccessController.doPrivileged( new GetPropertyAction("swing.crossplatformlaf")); if (laf != null) { return laf; @@ -1064,9 +1063,9 @@ // 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)) { @@ -1100,7 +1099,7 @@ boolean result; - Vector v = getLAFState().auxLookAndFeels; + Vector<LookAndFeel> v = getLAFState().auxLookAndFeels; if ((v == null) || (v.size() == 0)) { return false; } @@ -1136,14 +1135,14 @@ 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; } @@ -1210,7 +1209,7 @@ 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()); @@ -1269,7 +1268,7 @@ * 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()); @@ -1279,9 +1278,8 @@ * 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) { @@ -1291,7 +1289,7 @@ LookAndFeelInfo[] installedLAFs = new LookAndFeelInfo[ilafs.size()]; for(int i = 0; i < ilafs.size(); i++) { - installedLAFs[i] = (LookAndFeelInfo)(ilafs.elementAt(i)); + installedLAFs[i] = ilafs.elementAt(i); } getLAFState().installedLAFs = installedLAFs; } @@ -1336,7 +1334,7 @@ return; } - Vector auxLookAndFeels = new Vector(); + Vector<LookAndFeel> auxLookAndFeels = new Vector<LookAndFeel>(); StringTokenizer p = new StringTokenizer(auxLookAndFeelNames,","); String factoryName; @@ -1437,7 +1435,7 @@ 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();
--- a/src/share/classes/javax/swing/filechooser/FileSystemView.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/filechooser/FileSystemView.java Mon Dec 05 17:32:29 2016 +0000 @@ -131,8 +131,8 @@ } 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; } } @@ -247,8 +247,8 @@ 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; } } @@ -271,9 +271,9 @@ 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; } } } @@ -439,7 +439,7 @@ * 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 @@ -478,7 +478,7 @@ } } - return (File[])files.toArray(new File[files.size()]); + return files.toArray(new File[files.size()]); } @@ -585,7 +585,7 @@ 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; @@ -609,11 +609,7 @@ } public boolean isDrive(File dir) { - if (isFloppyDrive(dir)) { - return true; - } else { - return false; - } + return isFloppyDrive(dir); } public boolean isFloppyDrive(File dir) { @@ -696,9 +692,8 @@ 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( @@ -766,9 +761,8 @@ 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());
--- a/src/share/classes/javax/swing/table/AbstractTableModel.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/table/AbstractTableModel.java Mon Dec 05 17:32:29 2016 +0000 @@ -176,8 +176,7 @@ * @since 1.4 */ public TableModelListener[] getTableModelListeners() { - return (TableModelListener[])listenerList.getListeners( - TableModelListener.class); + return listenerList.getListeners(TableModelListener.class); } //
--- a/src/share/classes/javax/swing/table/DefaultTableModel.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/table/DefaultTableModel.java Mon Dec 05 17:32:29 2016 +0000 @@ -681,9 +681,9 @@ 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 @@ 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; }
--- a/src/share/classes/javax/swing/tree/DefaultTreeCellEditor.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/tree/DefaultTreeCellEditor.java Mon Dec 05 17:32:29 2016 +0000 @@ -551,7 +551,7 @@ // 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.
--- a/src/share/classes/javax/swing/tree/DefaultTreeModel.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/tree/DefaultTreeModel.java Mon Dec 05 17:32:29 2016 +0000 @@ -451,8 +451,7 @@ * @since 1.4 */ public TreeModelListener[] getTreeModelListeners() { - return (TreeModelListener[])listenerList.getListeners( - TreeModelListener.class); + return listenerList.getListeners(TreeModelListener.class); } /** @@ -647,7 +646,7 @@ // 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.
--- a/src/share/classes/javax/swing/tree/DefaultTreeSelectionModel.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/tree/DefaultTreeSelectionModel.java Mon Dec 05 17:32:29 2016 +0000 @@ -61,7 +61,7 @@ * * @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 @@ /** 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 @@ 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]; } @@ -237,7 +237,7 @@ int validCount = 0; TreePath beginLeadPath = leadPath; - Vector cPaths = new Vector(newCount + oldCount); + Vector<PathPlaceHolder> cPaths = new Vector<PathPlaceHolder>(newCount + oldCount); lastPaths.clear(); leadPath = null; @@ -286,7 +286,7 @@ selection = newSelection; - Hashtable tempHT = uniquePaths; + Hashtable<TreePath, Boolean> tempHT = uniquePaths; uniquePaths = lastPaths; lastPaths = tempHT; @@ -359,7 +359,7 @@ int counter, validCount; int oldCount; TreePath beginLeadPath = leadPath; - Vector cPaths = null; + Vector<PathPlaceHolder> cPaths = null; if(selection == null) oldCount = 0; @@ -374,7 +374,7 @@ 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); @@ -399,12 +399,11 @@ 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 { @@ -459,7 +458,7 @@ clearSelection(); } else { - Vector pathsToRemove = null; + Vector<PathPlaceHolder> pathsToRemove = null; /* Find the paths that can be removed. */ for (int removeCounter = paths.length - 1; removeCounter >= 0; @@ -467,7 +466,7 @@ 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)); @@ -482,14 +481,13 @@ 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 && @@ -622,8 +620,7 @@ * @since 1.4 */ public TreeSelectionListener[] getTreeSelectionListeners() { - return (TreeSelectionListener[])listenerList.getListeners( - TreeSelectionListener.class); + return listenerList.getListeners(TreeSelectionListener.class); } /** @@ -1084,7 +1081,7 @@ 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; } @@ -1180,8 +1177,8 @@ 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; }
--- a/src/share/classes/javax/swing/tree/FixedHeightLayoutCache.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/tree/FixedHeightLayoutCache.java Mon Dec 05 17:32:29 2016 +0000 @@ -64,21 +64,21 @@ /** * 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 @@ * 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 @@ 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 @@ // 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()); }
--- a/src/share/classes/javax/swing/tree/VariableHeightLayoutCache.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/tree/VariableHeightLayoutCache.java Mon Dec 05 17:32:29 2016 +0000 @@ -56,7 +56,7 @@ * 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 @@ /** * 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 @@ * 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 @@ } // 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 @@ // 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.
--- a/src/share/classes/javax/swing/undo/StateEdit.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/undo/StateEdit.java Mon Dec 05 17:32:29 2016 +0000 @@ -116,7 +116,7 @@ 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 @@ * 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 @@ * 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
--- a/src/share/classes/javax/swing/undo/UndoManager.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/undo/UndoManager.java Mon Dec 05 17:32:29 2016 +0000 @@ -166,12 +166,10 @@ * @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 @@ // 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 @@ 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 @@ 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 @@ 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 @@ 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; }
--- a/src/share/classes/javax/swing/undo/UndoableEditSupport.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/javax/swing/undo/UndoableEditSupport.java Mon Dec 05 17:32:29 2016 +0000 @@ -89,8 +89,7 @@ * @since 1.4 */ public synchronized UndoableEditListener[] getUndoableEditListeners() { - return (UndoableEditListener[])(listeners.toArray( - new UndoableEditListener[0])); + return listeners.toArray(new UndoableEditListener[0]); } /**
--- a/src/share/classes/sun/swing/AccessibleMethod.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/sun/swing/AccessibleMethod.java Mon Dec 05 17:32:29 2016 +0000 @@ -114,7 +114,7 @@ /** 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;
--- a/src/share/classes/sun/swing/FilePane.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/sun/swing/FilePane.java Mon Dec 05 17:32:29 2016 +0000 @@ -553,8 +553,7 @@ 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); @@ -725,13 +724,13 @@ 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++) { @@ -893,7 +892,7 @@ return rowSorter; } - private class DetailsTableRowSorter extends TableRowSorter { + private class DetailsTableRowSorter extends TableRowSorter<TableModel> { public DetailsTableRowSorter() { setModelWrapper(new SorterModelWrapper()); } @@ -913,8 +912,8 @@ updateComparators(detailsTableModel.getColumns()); } - private class SorterModelWrapper extends ModelWrapper { - public Object getModel() { + private class SorterModelWrapper extends ModelWrapper<TableModel, Integer> { + public TableModel getModel() { return getDetailsTableModel(); } @@ -930,7 +929,7 @@ return FilePane.this.getModel().getElementAt(row); } - public Object getIdentifier(int row) { + public Integer getIdentifier(int row) { return row; } } @@ -1722,9 +1721,9 @@ 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); }
--- a/src/share/classes/sun/swing/SwingLazyValue.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/sun/swing/SwingLazyValue.java Mon Dec 05 17:32:29 2016 +0000 @@ -58,15 +58,14 @@ className = c; methodName = m; if (o != null) { - args = (Object[])o.clone(); + args = o.clone(); } } public Object createValue(final UIDefaults table) { try { - Class c; ReflectUtil.checkPackageAccess(className); - 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);
--- a/src/share/classes/sun/swing/SwingUtilities2.java Tue Feb 26 11:12:40 2013 -0800 +++ b/src/share/classes/sun/swing/SwingUtilities2.java Mon Dec 05 17:32:29 2016 +0000 @@ -450,7 +450,7 @@ return clipString; } - boolean needsTextLayout = false; + boolean needsTextLayout; synchronized (charsBufferLock) { if (charsBuffer == null || charsBuffer.length < stringLength) { @@ -705,11 +705,8 @@ // 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; } /** @@ -1229,12 +1226,11 @@ 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; @@ -1422,10 +1418,10 @@ * 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;