From 852d7734608a7a02c36c3830996569b349b6213d Mon Sep 17 00:00:00 2001 From: rupashka Date: Fri, 25 Jul 2008 17:50:36 +0400 Subject: [PATCH] 6727661: Code improvement and warnings removing from the swing/plaf packages Summary: Removed unnecessary castings and other warnings Reviewed-by: alexp Contributed-by: Florian Brunner --- .../swing/plaf/windows/DesktopProperty.java | 19 ++++--- .../plaf/windows/WindowsDesktopManager.java | 2 +- .../plaf/windows/WindowsFileChooserUI.java | 18 +++---- .../WindowsInternalFrameTitlePane.java | 18 +++---- .../plaf/windows/WindowsScrollBarUI.java | 10 ++-- .../plaf/windows/WindowsTabbedPaneUI.java | 8 +-- .../swing/plaf/basic/BasicButtonListener.java | 12 ++--- .../javax/swing/plaf/basic/BasicButtonUI.java | 18 +++---- .../swing/plaf/basic/BasicComboBoxEditor.java | 2 +- .../swing/plaf/basic/BasicDirectoryModel.java | 45 ++++++++-------- .../swing/plaf/basic/BasicFileChooserUI.java | 29 +++++----- .../swing/plaf/basic/BasicGraphicsUtils.java | 4 +- .../basic/BasicInternalFrameTitlePane.java | 24 ++++----- .../plaf/basic/BasicInternalFrameUI.java | 14 ++--- .../swing/plaf/basic/BasicLookAndFeel.java | 16 +++--- .../swing/plaf/basic/BasicMenuItemUI.java | 10 ++-- .../javax/swing/plaf/basic/BasicMenuUI.java | 21 ++++---- .../swing/plaf/basic/BasicOptionPaneUI.java | 14 ++--- .../swing/plaf/basic/BasicPopupMenuUI.java | 35 ++++++------ .../swing/plaf/basic/BasicRadioButtonUI.java | 10 ++-- .../swing/plaf/basic/BasicSplitPaneUI.java | 12 ++--- .../swing/plaf/basic/BasicTabbedPaneUI.java | 36 ++++++------- .../javax/swing/plaf/basic/BasicTextUI.java | 25 +++++---- .../swing/plaf/basic/BasicToggleButtonUI.java | 18 +++---- .../swing/plaf/basic/BasicToolBarUI.java | 54 +++++++++---------- .../javax/swing/plaf/basic/BasicTreeUI.java | 29 +++++----- .../plaf/basic/DragRecognitionSupport.java | 9 ++-- .../javax/swing/plaf/basic/LazyActionMap.java | 2 +- .../swing/plaf/metal/DefaultMetalTheme.java | 6 +-- .../javax/swing/plaf/metal/MetalBumps.java | 10 ++-- .../swing/plaf/metal/MetalFileChooserUI.java | 18 +++---- .../swing/plaf/metal/MetalIconFactory.java | 16 ++---- .../metal/MetalInternalFrameTitlePane.java | 6 +-- .../swing/plaf/metal/MetalLookAndFeel.java | 20 +++---- .../swing/plaf/metal/MetalRadioButtonUI.java | 8 +-- .../swing/plaf/metal/MetalToolBarUI.java | 7 ++- .../plaf/synth/DefaultSynthStyleFactory.java | 14 ++--- .../javax/swing/plaf/synth/ImagePainter.java | 2 +- .../javax/swing/plaf/synth/Region.java | 14 ++--- .../swing/plaf/synth/SynthComboBoxUI.java | 2 +- .../javax/swing/plaf/synth/SynthContext.java | 13 +++-- .../swing/plaf/synth/SynthEditorPaneUI.java | 6 +-- .../swing/plaf/synth/SynthGraphicsUtils.java | 5 +- .../synth/SynthInternalFrameTitlePane.java | 12 ++--- .../swing/plaf/synth/SynthLookAndFeel.java | 28 +++++----- .../swing/plaf/synth/SynthMenuItemUI.java | 10 ++-- .../javax/swing/plaf/synth/SynthParser.java | 47 ++++++++-------- .../swing/plaf/synth/SynthSplitPaneUI.java | 8 +-- .../javax/swing/plaf/synth/SynthStyle.java | 4 +- .../swing/plaf/synth/SynthTextAreaUI.java | 2 +- .../swing/plaf/synth/SynthTextFieldUI.java | 2 +- .../javax/swing/plaf/synth/SynthTreeUI.java | 4 +- .../swing/plaf/synth/DefaultSynthStyle.java | 8 +-- .../plaf/synth/SynthFileChooserUIImpl.java | 16 +++--- 54 files changed, 377 insertions(+), 425 deletions(-) diff --git a/src/share/classes/com/sun/java/swing/plaf/windows/DesktopProperty.java b/src/share/classes/com/sun/java/swing/plaf/windows/DesktopProperty.java index d7d5c0205..139b0db55 100644 --- a/src/share/classes/com/sun/java/swing/plaf/windows/DesktopProperty.java +++ b/src/share/classes/com/sun/java/swing/plaf/windows/DesktopProperty.java @@ -49,8 +49,7 @@ public class DesktopProperty implements UIDefaults.ActiveValue { /** * ReferenceQueue of unreferenced WeakPCLs. */ - private static ReferenceQueue queue; - + private static ReferenceQueue queue; /** * PropertyChangeListener attached to the Toolkit. @@ -76,7 +75,7 @@ public class DesktopProperty implements UIDefaults.ActiveValue { static { - queue = new ReferenceQueue(); + queue = new ReferenceQueue(); } /** @@ -117,8 +116,8 @@ public class DesktopProperty implements UIDefaults.ActiveValue { XPStyle.invalidateStyle(); } Frame appFrames[] = Frame.getFrames(); - for (int j=0; j < appFrames.length; j++) { - updateWindowUI(appFrames[j]); + for (Frame appFrame : appFrames) { + updateWindowUI(appFrame); } } @@ -128,8 +127,8 @@ public class DesktopProperty implements UIDefaults.ActiveValue { private static void updateWindowUI(Window window) { SwingUtilities.updateComponentTreeUI(window); Window ownedWins[] = window.getOwnedWindows(); - for (int i=0; i < ownedWins.length; i++) { - updateWindowUI(ownedWins[i]); + for (Window ownedWin : ownedWins) { + updateWindowUI(ownedWin); } } @@ -270,13 +269,13 @@ public class DesktopProperty implements UIDefaults.ActiveValue { * is handled via a WeakReference so as not to pin down the * DesktopProperty. */ - private static class WeakPCL extends WeakReference + private static class WeakPCL extends WeakReference implements PropertyChangeListener { private Toolkit kit; private String key; private LookAndFeel laf; - WeakPCL(Object target, Toolkit kit, String key, LookAndFeel laf) { + WeakPCL(DesktopProperty target, Toolkit kit, String key, LookAndFeel laf) { super(target, queue); this.kit = kit; this.key = key; @@ -284,7 +283,7 @@ public class DesktopProperty implements UIDefaults.ActiveValue { } public void propertyChange(PropertyChangeEvent pce) { - DesktopProperty property = (DesktopProperty)get(); + DesktopProperty property = get(); if (property == null || laf != UIManager.getLookAndFeel()) { // The property was GC'ed, we're no longer interested in diff --git a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsDesktopManager.java b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsDesktopManager.java index e27ac218e..20d87d015 100644 --- a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsDesktopManager.java +++ b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsDesktopManager.java @@ -96,7 +96,7 @@ public class WindowsDesktopManager extends DefaultDesktopManager } } catch (PropertyVetoException e) {} if (f != currentFrame) { - currentFrameRef = new WeakReference(f); + currentFrameRef = new WeakReference(f); } } diff --git a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java index 43d840b1d..e0fb203e0 100644 --- a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java +++ b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java @@ -983,7 +983,7 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { } else if (s.equals("componentOrientation")) { ComponentOrientation o = (ComponentOrientation)e.getNewValue(); JFileChooser cc = (JFileChooser)e.getSource(); - if (o != (ComponentOrientation)e.getOldValue()) { + if (o != e.getOldValue()) { cc.applyComponentOrientation(o); } } else if (s.equals("ancestor")) { @@ -1123,7 +1123,7 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { * Data model for a type-face selection combo-box. */ protected class DirectoryComboBoxModel extends AbstractListModel implements ComboBoxModel { - Vector directories = new Vector(); + Vector directories = new Vector(); int[] depths = null; File selectedDirectory = null; JFileChooser chooser = getFileChooser(); @@ -1162,7 +1162,7 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { // Get the canonical (full) path. This has the side // benefit of removing extraneous chars from the path, // for example /foo/bar/ becomes /foo/bar - File canonical = null; + File canonical; try { canonical = directory.getCanonicalFile(); } catch (IOException e) { @@ -1175,7 +1175,7 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { File sf = useShellFolder ? ShellFolder.getShellFolder(canonical) : canonical; File f = sf; - Vector path = new Vector(10); + Vector path = new Vector(10); do { path.addElement(f); } while ((f = f.getParentFile()) != null); @@ -1183,7 +1183,7 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { int pathCount = path.size(); // Insert chain at appropriate place in vector for (int i = 0; i < pathCount; i++) { - f = (File)path.get(i); + f = path.get(i); if (directories.contains(f)) { int topIndex = directories.indexOf(f); for (int j = i-1; j >= 0; j--) { @@ -1202,12 +1202,12 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { private void calculateDepths() { depths = new int[directories.size()]; for (int i = 0; i < depths.length; i++) { - File dir = (File)directories.get(i); + File dir = directories.get(i); File parent = dir.getParentFile(); depths[i] = 0; if (parent != null) { for (int j = i-1; j >= 0; j--) { - if (parent.equals((File)directories.get(j))) { + if (parent.equals(directories.get(j))) { depths[i] = depths[j] + 1; break; } @@ -1306,8 +1306,8 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { FileFilter currentFilter = getFileChooser().getFileFilter(); boolean found = false; if(currentFilter != null) { - for(int i=0; i < filters.length; i++) { - if(filters[i] == currentFilter) { + for (FileFilter filter : filters) { + if (filter == currentFilter) { found = true; } } diff --git a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsInternalFrameTitlePane.java b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsInternalFrameTitlePane.java index b13033bf7..63d853a28 100644 --- a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsInternalFrameTitlePane.java +++ b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsInternalFrameTitlePane.java @@ -258,8 +258,8 @@ public class WindowsInternalFrameTitlePane extends BasicInternalFrameTitlePane { g.fillRect(0, 0, w, h); } Icon icon = getIcon(); - int iconWidth = 0; - int iconHeight = 0; + int iconWidth; + int iconHeight; if (icon != null && (iconWidth = icon.getIconWidth()) > 0 && (iconHeight = icon.getIconHeight()) > 0) { @@ -304,18 +304,18 @@ public class WindowsInternalFrameTitlePane extends BasicInternalFrameTitlePane { } protected void addSystemMenuItems(JPopupMenu menu) { - JMenuItem mi = (JMenuItem)menu.add(restoreAction); + JMenuItem mi = menu.add(restoreAction); mi.setMnemonic('R'); - mi = (JMenuItem)menu.add(moveAction); + mi = menu.add(moveAction); mi.setMnemonic('M'); - mi = (JMenuItem)menu.add(sizeAction); + mi = menu.add(sizeAction); mi.setMnemonic('S'); - mi = (JMenuItem)menu.add(iconifyAction); + mi = menu.add(iconifyAction); mi.setMnemonic('n'); - mi = (JMenuItem)menu.add(maximizeAction); + mi = menu.add(maximizeAction); mi.setMnemonic('x'); systemPopupMenu.add(new JSeparator()); - mi = (JMenuItem)menu.add(closeAction); + mi = menu.add(closeAction); mi.setMnemonic('C'); } @@ -441,7 +441,7 @@ public class WindowsInternalFrameTitlePane extends BasicInternalFrameTitlePane { public class WindowsPropertyChangeHandler extends PropertyChangeHandler { public void propertyChange(PropertyChangeEvent evt) { - String prop = (String)evt.getPropertyName(); + String prop = evt.getPropertyName(); // Update the internal frame icon for the system menu. if (JInternalFrame.FRAME_ICON_PROPERTY.equals(prop) && diff --git a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsScrollBarUI.java b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsScrollBarUI.java index b137b38c0..f79f9d644 100644 --- a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsScrollBarUI.java +++ b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsScrollBarUI.java @@ -369,21 +369,21 @@ public class WindowsScrollBarUI extends BasicScrollBarUI { */ private static class Grid { private static final int BUFFER_SIZE = 64; - private static HashMap map; + private static HashMap> map; private BufferedImage image; static { - map = new HashMap(); + map = new HashMap>(); } public static Grid getGrid(Color fg, Color bg) { String key = fg.getRGB() + " " + bg.getRGB(); - WeakReference ref = (WeakReference)map.get(key); - Grid grid = (ref == null) ? null : (Grid)ref.get(); + WeakReference ref = map.get(key); + Grid grid = (ref == null) ? null : ref.get(); if (grid == null) { grid = new Grid(fg, bg); - map.put(key, new WeakReference(grid)); + map.put(key, new WeakReference(grid)); } return grid; } diff --git a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsTabbedPaneUI.java b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsTabbedPaneUI.java index 54d21e8f0..b781caa3c 100644 --- a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsTabbedPaneUI.java +++ b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsTabbedPaneUI.java @@ -53,13 +53,13 @@ public class WindowsTabbedPaneUI extends BasicTabbedPaneUI { * Keys to use for forward focus traversal when the JComponent is * managing focus. */ - private static Set managingFocusForwardTraversalKeys; + private static Set managingFocusForwardTraversalKeys; /** * Keys to use for backward focus traversal when the JComponent is * managing focus. */ - private static Set managingFocusBackwardTraversalKeys; + private static Set managingFocusBackwardTraversalKeys; private boolean contentOpaque = true; @@ -69,13 +69,13 @@ public class WindowsTabbedPaneUI extends BasicTabbedPaneUI { // focus forward traversal key if (managingFocusForwardTraversalKeys==null) { - managingFocusForwardTraversalKeys = new HashSet(); + managingFocusForwardTraversalKeys = new HashSet(); managingFocusForwardTraversalKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0)); } tabPane.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, managingFocusForwardTraversalKeys); // focus backward traversal key if (managingFocusBackwardTraversalKeys==null) { - managingFocusBackwardTraversalKeys = new HashSet(); + managingFocusBackwardTraversalKeys = new HashSet(); managingFocusBackwardTraversalKeys.add( KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK)); } tabPane.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, managingFocusBackwardTraversalKeys); diff --git a/src/share/classes/javax/swing/plaf/basic/BasicButtonListener.java b/src/share/classes/javax/swing/plaf/basic/BasicButtonListener.java index 05e35cc72..c366217b7 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicButtonListener.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicButtonListener.java @@ -165,7 +165,7 @@ public class BasicButtonListener implements MouseListener, MouseMotionListener, JRootPane root = b.getRootPane(); if (root != null) { BasicButtonUI ui = (BasicButtonUI)BasicLookAndFeel.getUIOfType( - ((AbstractButton)b).getUI(), BasicButtonUI.class); + b.getUI(), BasicButtonUI.class); if (ui != null && DefaultLookup.getBoolean(b, ui, ui.getPropertyPrefix() + "defaultButtonFollowsFocus", true)) { @@ -185,7 +185,7 @@ public class BasicButtonListener implements MouseListener, MouseMotionListener, JButton initialDefault = (JButton)root.getClientProperty("initialDefaultButton"); if (b != initialDefault) { BasicButtonUI ui = (BasicButtonUI)BasicLookAndFeel.getUIOfType( - ((AbstractButton)b).getUI(), BasicButtonUI.class); + b.getUI(), BasicButtonUI.class); if (ui != null && DefaultLookup.getBoolean(b, ui, ui.getPropertyPrefix() + "defaultButtonFollowsFocus", true)) { @@ -239,7 +239,7 @@ public class BasicButtonListener implements MouseListener, MouseMotionListener, } } } - }; + } public void mouseReleased(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { @@ -253,7 +253,7 @@ public class BasicButtonListener implements MouseListener, MouseMotionListener, model.setPressed(false); model.setArmed(false); } - }; + } public void mouseEntered(MouseEvent e) { AbstractButton b = (AbstractButton) e.getSource(); @@ -263,7 +263,7 @@ public class BasicButtonListener implements MouseListener, MouseMotionListener, } if (model.isPressed()) model.setArmed(true); - }; + } public void mouseExited(MouseEvent e) { AbstractButton b = (AbstractButton) e.getSource(); @@ -272,7 +272,7 @@ public class BasicButtonListener implements MouseListener, MouseMotionListener, model.setRollover(false); } model.setArmed(false); - }; + } /** diff --git a/src/share/classes/javax/swing/plaf/basic/BasicButtonUI.java b/src/share/classes/javax/swing/plaf/basic/BasicButtonUI.java index d6ad0643c..36b67287d 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicButtonUI.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicButtonUI.java @@ -237,7 +237,7 @@ public class BasicButtonUI extends ButtonUI{ /* the fallback icon should be based on the selected state */ if (model.isSelected()) { - selectedIcon = (Icon) b.getSelectedIcon(); + selectedIcon = b.getSelectedIcon(); if (selectedIcon != null) { icon = selectedIcon; } @@ -245,31 +245,31 @@ public class BasicButtonUI extends ButtonUI{ if(!model.isEnabled()) { if(model.isSelected()) { - tmpIcon = (Icon) b.getDisabledSelectedIcon(); + tmpIcon = b.getDisabledSelectedIcon(); if (tmpIcon == null) { tmpIcon = selectedIcon; } } if (tmpIcon == null) { - tmpIcon = (Icon) b.getDisabledIcon(); + tmpIcon = b.getDisabledIcon(); } } else if(model.isPressed() && model.isArmed()) { - tmpIcon = (Icon) b.getPressedIcon(); + tmpIcon = b.getPressedIcon(); if(tmpIcon != null) { // revert back to 0 offset clearTextShiftOffset(); } } else if(b.isRolloverEnabled() && model.isRollover()) { if(model.isSelected()) { - tmpIcon = (Icon) b.getRolloverSelectedIcon(); + tmpIcon = b.getRolloverSelectedIcon(); if (tmpIcon == null) { tmpIcon = selectedIcon; } } if (tmpIcon == null) { - tmpIcon = (Icon) b.getRolloverIcon(); + tmpIcon = b.getRolloverIcon(); } } @@ -451,9 +451,9 @@ public class BasicButtonUI extends ButtonUI{ MouseMotionListener[] listeners = b.getMouseMotionListeners(); if (listeners != null) { - for (int counter = 0; counter < listeners.length; counter++) { - if (listeners[counter] instanceof BasicButtonListener) { - return (BasicButtonListener)listeners[counter]; + for (MouseMotionListener listener : listeners) { + if (listener instanceof BasicButtonListener) { + return (BasicButtonListener) listener; } } } diff --git a/src/share/classes/javax/swing/plaf/basic/BasicComboBoxEditor.java b/src/share/classes/javax/swing/plaf/basic/BasicComboBoxEditor.java index bc41bfb08..c7ec98184 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicComboBoxEditor.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicComboBoxEditor.java @@ -92,7 +92,7 @@ public class BasicComboBoxEditor implements ComboBoxEditor,FocusListener { return oldValue; } else { // Must take the value from the editor and get the value and cast it to the new type. - Class cls = oldValue.getClass(); + Class cls = oldValue.getClass(); try { Method method = cls.getMethod("valueOf", new Class[]{String.class}); newValue = method.invoke(oldValue, new Object[] { editor.getText()}); diff --git a/src/share/classes/javax/swing/plaf/basic/BasicDirectoryModel.java b/src/share/classes/javax/swing/plaf/basic/BasicDirectoryModel.java index 6bc400f97..7ee4df381 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicDirectoryModel.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicDirectoryModel.java @@ -43,10 +43,10 @@ public class BasicDirectoryModel extends AbstractListModel implements PropertyCh private JFileChooser filechooser = null; // PENDING(jeff) pick the size more sensibly - private Vector fileCache = new Vector(50); + private Vector fileCache = new Vector(50); private LoadFilesThread loadThread = null; - private Vector files = null; - private Vector directories = null; + private Vector files = null; + private Vector directories = null; private int fetchID = 0; private PropertyChangeSupport changeSupport; @@ -106,14 +106,14 @@ public class BasicDirectoryModel extends AbstractListModel implements PropertyCh if (files != null) { return files; } - files = new Vector(); - directories = new Vector(); + files = new Vector(); + directories = new Vector(); directories.addElement(filechooser.getFileSystemView().createFileObject( filechooser.getCurrentDirectory(), "..") ); for (int i = 0; i < getSize(); i++) { - File f = (File)fileCache.get(i); + File f = fileCache.get(i); if (filechooser.isTraversable(f)) { directories.add(f); } else { @@ -215,7 +215,7 @@ public class BasicDirectoryModel extends AbstractListModel implements PropertyCh class LoadFilesThread extends Thread { File currentDirectory = null; int fid; - Vector runnables = new Vector(10); + Vector runnables = new Vector(10); public LoadFilesThread(File currentDirectory, int fid) { super("Basic L&F File Loading Thread"); @@ -223,7 +223,7 @@ public class BasicDirectoryModel extends AbstractListModel implements PropertyCh this.fid = fid; } - private void invokeLater(Runnable runnable) { + private void invokeLater(DoChangeContents runnable) { runnables.addElement(runnable); SwingUtilities.invokeLater(runnable); } @@ -245,9 +245,9 @@ public class BasicDirectoryModel extends AbstractListModel implements PropertyCh } // run through the file list, add directories and selectable files to fileCache - for (int i = 0; i < list.length; i++) { - if(filechooser.accept(list[i])) { - acceptsList.addElement(list[i]); + for (File file : list) { + if (filechooser.accept(file)) { + acceptsList.addElement(file); } } @@ -258,11 +258,11 @@ public class BasicDirectoryModel extends AbstractListModel implements PropertyCh // First sort alphabetically by filename sort(acceptsList); - Vector newDirectories = new Vector(50); - Vector newFiles = new Vector(); + Vector newDirectories = new Vector(50); + Vector newFiles = new Vector(); // run through list grabbing directories in chunks of ten for(int i = 0; i < acceptsList.size(); i++) { - File f = (File) acceptsList.elementAt(i); + File f = acceptsList.elementAt(i); boolean isTraversable = filechooser.isTraversable(f); if (isTraversable) { newDirectories.addElement(f); @@ -274,7 +274,7 @@ public class BasicDirectoryModel extends AbstractListModel implements PropertyCh } } - Vector newFileCache = new Vector(newDirectories); + Vector newFileCache = new Vector(newDirectories); newFileCache.addAll(newFiles); int newSize = newFileCache.size(); @@ -320,7 +320,7 @@ public class BasicDirectoryModel extends AbstractListModel implements PropertyCh if(isInterrupted()) { return; } - invokeLater(new DoChangeContents(null, 0, new Vector(fileCache.subList(start, end)), + invokeLater(new DoChangeContents(null, 0, new Vector(fileCache.subList(start, end)), start, fid)); newFileCache = null; } @@ -334,9 +334,9 @@ public class BasicDirectoryModel extends AbstractListModel implements PropertyCh } - public void cancelRunnables(Vector runnables) { - for(int i = 0; i < runnables.size(); i++) { - ((DoChangeContents)runnables.elementAt(i)).cancel(); + public void cancelRunnables(Vector runnables) { + for (DoChangeContents runnable : runnables) { + runnable.cancel(); } } @@ -449,15 +449,14 @@ public class BasicDirectoryModel extends AbstractListModel implements PropertyCh class DoChangeContents implements Runnable { - private List addFiles; - private List remFiles; + private List addFiles; + private List remFiles; private boolean doFire = true; private int fid; private int addStart = 0; private int remStart = 0; - private int change; - public DoChangeContents(List addFiles, int addStart, List remFiles, int remStart, int fid) { + public DoChangeContents(List addFiles, int addStart, List remFiles, int remStart, int fid) { this.addFiles = addFiles; this.addStart = addStart; this.remFiles = remFiles; diff --git a/src/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java b/src/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java index e8728d807..7e0e20bf4 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java @@ -159,9 +159,9 @@ public class BasicFileChooserUI extends FileChooserUI { } public void uninstallUI(JComponent c) { - uninstallListeners((JFileChooser) filechooser); - uninstallComponents((JFileChooser) filechooser); - uninstallDefaults((JFileChooser) filechooser); + uninstallListeners(filechooser); + uninstallComponents(filechooser); + uninstallDefaults(filechooser); if(accessoryPanel != null) { accessoryPanel.removeAll(); @@ -506,9 +506,9 @@ public class BasicFileChooserUI extends FileChooserUI { setDirectorySelected(true); setDirectory(((File)objects[0])); } else { - ArrayList fList = new ArrayList(objects.length); - for (int i = 0; i < objects.length; i++) { - File f = (File)objects[i]; + ArrayList fList = new ArrayList(objects.length); + for (Object object : objects) { + File f = (File) object; boolean isDir = f.isDirectory(); if ((chooser.isFileSelectionEnabled() && !isDir) || (chooser.isDirectorySelectionEnabled() @@ -518,7 +518,7 @@ public class BasicFileChooserUI extends FileChooserUI { } } if (fList.size() > 0) { - files = (File[])fList.toArray(new File[fList.size()]); + files = fList.toArray(new File[fList.size()]); } setDirectorySelected(false); } @@ -853,7 +853,7 @@ public class BasicFileChooserUI extends FileChooserUI { } if (chooser.isMultiSelectionEnabled() && filename.startsWith("\"")) { - ArrayList fList = new ArrayList(); + ArrayList fList = new ArrayList(); filename = filename.substring(1); if (filename.endsWith("\"")) { @@ -889,7 +889,7 @@ public class BasicFileChooserUI extends FileChooserUI { fList.add(file); } while (filename.length() > 0); if (fList.size() > 0) { - selectedFiles = (File[])fList.toArray(new File[fList.size()]); + selectedFiles = fList.toArray(new File[fList.size()]); } resetGlobFilter(); } else { @@ -1213,7 +1213,7 @@ public class BasicFileChooserUI extends FileChooserUI { } public Icon getCachedIcon(File f) { - return (Icon) iconCache.get(f); + return iconCache.get(f); } public void cacheIcon(File f, Icon i) { @@ -1296,8 +1296,7 @@ public class BasicFileChooserUI extends FileChooserUI { htmlBuf.append("\n\n
    \n"); - for (int i = 0; i < values.length; i++) { - Object obj = values[i]; + for (Object obj : values) { String val = ((obj == null) ? "" : obj.toString()); plainBuf.append(val + "\n"); htmlBuf.append("
  • " + val + "\n"); @@ -1337,9 +1336,9 @@ public class BasicFileChooserUI extends FileChooserUI { */ protected Object getRicherData(DataFlavor flavor) { if (DataFlavor.javaFileListFlavor.equals(flavor)) { - ArrayList files = new ArrayList(); - for (int i = 0; i < fileData.length; i++) { - files.add(fileData[i]); + ArrayList files = new ArrayList(); + for (Object file : this.fileData) { + files.add(file); } return files; } diff --git a/src/share/classes/javax/swing/plaf/basic/BasicGraphicsUtils.java b/src/share/classes/javax/swing/plaf/basic/BasicGraphicsUtils.java index ecb8f0dcc..3cf822cfe 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicGraphicsUtils.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicGraphicsUtils.java @@ -266,7 +266,7 @@ public class BasicGraphicsUtils return null; } - Icon icon = (Icon) b.getIcon(); + Icon icon = b.getIcon(); String text = b.getText(); Font font = b.getFont(); @@ -277,7 +277,7 @@ public class BasicGraphicsUtils Rectangle viewR = new Rectangle(Short.MAX_VALUE, Short.MAX_VALUE); SwingUtilities.layoutCompoundLabel( - (JComponent) b, fm, text, icon, + b, fm, text, icon, b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewR, iconR, textR, (text == null ? 0 : textIconGap) diff --git a/src/share/classes/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java b/src/share/classes/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java index d8f257312..b131824f4 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java @@ -269,18 +269,18 @@ public class BasicInternalFrameTitlePane extends JComponent } protected void addSystemMenuItems(JMenu systemMenu) { - JMenuItem mi = (JMenuItem)systemMenu.add(restoreAction); + JMenuItem mi = systemMenu.add(restoreAction); mi.setMnemonic('R'); - mi = (JMenuItem)systemMenu.add(moveAction); + mi = systemMenu.add(moveAction); mi.setMnemonic('M'); - mi = (JMenuItem)systemMenu.add(sizeAction); + mi = systemMenu.add(sizeAction); mi.setMnemonic('S'); - mi = (JMenuItem)systemMenu.add(iconifyAction); + mi = systemMenu.add(iconifyAction); mi.setMnemonic('n'); - mi = (JMenuItem)systemMenu.add(maximizeAction); + mi = systemMenu.add(maximizeAction); mi.setMnemonic('x'); systemMenu.add(new JSeparator()); - mi = (JMenuItem)systemMenu.add(closeAction); + mi = systemMenu.add(closeAction); mi.setMnemonic('C'); } @@ -414,7 +414,7 @@ public class BasicInternalFrameTitlePane extends JComponent // PropertyChangeListener // public void propertyChange(PropertyChangeEvent evt) { - String prop = (String)evt.getPropertyName(); + String prop = evt.getPropertyName(); if (prop == JInternalFrame.IS_SELECTED_PROPERTY) { repaint(); @@ -429,19 +429,19 @@ public class BasicInternalFrameTitlePane extends JComponent } if ("closable" == prop) { - if ((Boolean)evt.getNewValue() == Boolean.TRUE) { + if (evt.getNewValue() == Boolean.TRUE) { add(closeButton); } else { remove(closeButton); } } else if ("maximizable" == prop) { - if ((Boolean)evt.getNewValue() == Boolean.TRUE) { + if (evt.getNewValue() == Boolean.TRUE) { add(maxButton); } else { remove(maxButton); } } else if ("iconable" == prop) { - if ((Boolean)evt.getNewValue() == Boolean.TRUE) { + if (evt.getNewValue() == Boolean.TRUE) { add(iconButton); } else { remove(iconButton); @@ -781,7 +781,7 @@ public class BasicInternalFrameTitlePane extends JComponent } } public boolean isFocusTraversable() { return false; } - public void requestFocus() {}; + public void requestFocus() {} public AccessibleContext getAccessibleContext() { AccessibleContext ac = super.getAccessibleContext(); if (uiKey != null) { @@ -790,6 +790,6 @@ public class BasicInternalFrameTitlePane extends JComponent } return ac; } - }; // end NoFocusButton + } // end NoFocusButton } // End Title Pane Class diff --git a/src/share/classes/javax/swing/plaf/basic/BasicInternalFrameUI.java b/src/share/classes/javax/swing/plaf/basic/BasicInternalFrameUI.java index 86a8f15dd..46eefa26c 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicInternalFrameUI.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicInternalFrameUI.java @@ -318,7 +318,7 @@ public class BasicInternalFrameUI extends InternalFrameUI if (resizing) { return; } - Cursor s = (Cursor)frame.getLastCursor(); + Cursor s = frame.getLastCursor(); if (s == null) { s = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); } @@ -336,13 +336,13 @@ public class BasicInternalFrameUI extends InternalFrameUI public Dimension getPreferredSize(JComponent x) { - if((JComponent)frame == x) + if(frame == x) return frame.getLayout().preferredLayoutSize(x); return new Dimension(100, 100); } public Dimension getMinimumSize(JComponent x) { - if((JComponent)frame == x) { + if(frame == x) { return frame.getLayout().minimumLayoutSize(x); } return new Dimension(0, 0); @@ -1093,7 +1093,7 @@ public class BasicInternalFrameUI extends InternalFrameUI updateFrameCursor(); } - }; /// End BorderListener Class + } /// End BorderListener Class protected class ComponentHandler implements ComponentListener { // NOTE: This class exists only for backward compatability. All @@ -1196,7 +1196,6 @@ public class BasicInternalFrameUI extends InternalFrameUI } } - private static boolean isDragging = false; private class Handler implements ComponentListener, InternalFrameListener, LayoutManager, MouseInputListener, PropertyChangeListener, WindowFocusListener, SwingConstants { @@ -1373,9 +1372,6 @@ public class BasicInternalFrameUI extends InternalFrameUI // MouseInputListener - private Component mouseEventTarget = null; - private Component dragSource = null; - public void mousePressed(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } @@ -1392,7 +1388,7 @@ public class BasicInternalFrameUI extends InternalFrameUI // PropertyChangeListener public void propertyChange(PropertyChangeEvent evt) { - String prop = (String)evt.getPropertyName(); + String prop = evt.getPropertyName(); JInternalFrame f = (JInternalFrame)evt.getSource(); Object newValue = evt.getNewValue(); Object oldValue = evt.getOldValue(); diff --git a/src/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java b/src/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java index df078dbf6..1c1d579fc 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java @@ -2102,8 +2102,6 @@ public abstract class BasicLookAndFeel extends LookAndFeel implements Serializab * soundFile passed into this method, it will * return null. * - * @param baseClass used as the root class/location to get the - * soundFile from * @param soundFile the name of the audio file to be retrieved * from disk * @return A byte[] with audio data or null @@ -2120,9 +2118,9 @@ public abstract class BasicLookAndFeel extends LookAndFeel implements Serializab * Class.getResourceAsStream just returns raw * bytes, which we can convert to a sound. */ - byte[] buffer = (byte[])AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { + byte[] buffer = AccessController.doPrivileged( + new PrivilegedAction() { + public byte[] run() { try { InputStream resource = BasicLookAndFeel.this. getClass().getResourceAsStream(soundFile); @@ -2184,9 +2182,9 @@ public abstract class BasicLookAndFeel extends LookAndFeel implements Serializab UIManager.get("AuditoryCues.playList"); if (audioStrings != null) { // create a HashSet to help us decide to play or not - HashSet audioCues = new HashSet(); - for (int i = 0; i < audioStrings.length; i++) { - audioCues.add(audioStrings[i]); + HashSet audioCues = new HashSet(); + for (Object audioString : audioStrings) { + audioCues.add(audioString); } // get the name of the Action String actionName = (String)audioAction.getValue(Action.NAME); @@ -2237,7 +2235,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel implements Serializab * This class contains listener that watches for all the mouse * events that can possibly invoke popup on the component */ - class AWTEventHelper implements AWTEventListener,PrivilegedAction { + class AWTEventHelper implements AWTEventListener,PrivilegedAction { AWTEventHelper() { super(); AccessController.doPrivileged(this); diff --git a/src/share/classes/javax/swing/plaf/basic/BasicMenuItemUI.java b/src/share/classes/javax/swing/plaf/basic/BasicMenuItemUI.java index c56a1b49d..5e81bfd06 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicMenuItemUI.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicMenuItemUI.java @@ -1041,15 +1041,15 @@ public class BasicMenuItemUI extends MenuItemUI Icon icon; ButtonModel model = li.mi.getModel(); if (!model.isEnabled()) { - icon = (Icon) li.mi.getDisabledIcon(); + icon = li.mi.getDisabledIcon(); } else if (model.isPressed() && model.isArmed()) { - icon = (Icon) li.mi.getPressedIcon(); + icon = li.mi.getPressedIcon(); if (icon == null) { // Use default icon - icon = (Icon) li.mi.getIcon(); + icon = li.mi.getIcon(); } } else { - icon = (Icon) li.mi.getIcon(); + icon = li.mi.getIcon(); } if (icon != null) { @@ -1601,7 +1601,7 @@ public class BasicMenuItemUI extends MenuItemUI for(i=0,j=path.length; i 0) { me = new MenuElement[4]; me[0] = (MenuElement) cnt; - me[1] = (MenuElement) menu; - me[2] = (MenuElement) menu.getPopupMenu(); + me[1] = menu; + me[2] = menu.getPopupMenu(); me[3] = subElements[0]; } else { me = new MenuElement[3]; me[0] = (MenuElement)cnt; me[1] = menu; - me[2] = (MenuElement) menu.getPopupMenu(); + me[2] = menu.getPopupMenu(); } defaultManager.setSelectedPath(me); } @@ -606,7 +605,7 @@ public class BasicMenuUI extends BasicMenuItemUI MenuSelectionManager manager = e.getMenuSelectionManager(); if (key == Character.toLowerCase(e.getKeyChar())) { JPopupMenu popupMenu = ((JMenu)menuItem).getPopupMenu(); - ArrayList newList = new ArrayList(Arrays.asList(path)); + ArrayList newList = new ArrayList(Arrays.asList(path)); newList.add(popupMenu); MenuElement subs[] = popupMenu.getSubElements(); MenuElement sub = @@ -614,8 +613,8 @@ public class BasicMenuUI extends BasicMenuItemUI if(sub != null) { newList.add(sub); } - MenuElement newPath[] = new MenuElement[0];; - newPath = (MenuElement[]) newList.toArray(newPath); + MenuElement newPath[] = new MenuElement[0]; + newPath = newList.toArray(newPath); manager.setSelectedPath(newPath); e.consume(); } else if (((JMenu)menuItem).isTopLevelMenu() diff --git a/src/share/classes/javax/swing/plaf/basic/BasicOptionPaneUI.java b/src/share/classes/javax/swing/plaf/basic/BasicOptionPaneUI.java index 5ad6c2b92..226ce3c20 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicOptionPaneUI.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicOptionPaneUI.java @@ -109,7 +109,7 @@ public class BasicOptionPaneUI extends OptionPaneUI { static { - newline = (String)java.security.AccessController.doPrivileged( + newline = java.security.AccessController.doPrivileged( new GetPropertyAction("line.separator")); if (newline == null) { newline = "\n"; @@ -262,7 +262,7 @@ public class BasicOptionPaneUI extends OptionPaneUI { * getMinimumOptionPaneSize. */ public Dimension getPreferredSize(JComponent c) { - if ((JOptionPane)c == optionPane) { + if (c == optionPane) { Dimension ourMin = getMinimumOptionPaneSize(); LayoutManager lm = c.getLayout(); @@ -366,8 +366,8 @@ public class BasicOptionPaneUI extends OptionPaneUI { } else if (msg instanceof Object[]) { Object [] msgs = (Object[]) msg; - for (int i = 0; i < msgs.length; i++) { - addMessageComponents(container, cons, msgs[i], maxll, false); + for (Object o : msgs) { + addMessageComponents(container, cons, o, maxll, false); } } else if (msg instanceof Icon) { @@ -381,7 +381,7 @@ public class BasicOptionPaneUI extends OptionPaneUI { if (len <= 0) { return; } - int nl = -1; + int nl; int nll = 0; if ((nl = s.indexOf(newline)) >= 0) { @@ -1320,7 +1320,7 @@ public class BasicOptionPaneUI extends OptionPaneUI { else if (changeName == "componentOrientation") { ComponentOrientation o = (ComponentOrientation)e.getNewValue(); JOptionPane op = (JOptionPane)e.getSource(); - if (o != (ComponentOrientation)e.getOldValue()) { + if (o != e.getOldValue()) { op.applyComponentOrientation(o); } } @@ -1418,7 +1418,7 @@ public class BasicOptionPaneUI extends OptionPaneUI { } JButton createButton() { - JButton button = null; + JButton button; if (minimumWidth > 0) { button = new ConstrainedButton(text, minimumWidth); diff --git a/src/share/classes/javax/swing/plaf/basic/BasicPopupMenuUI.java b/src/share/classes/javax/swing/plaf/basic/BasicPopupMenuUI.java index d2d3a0197..8fbb79fff 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicPopupMenuUI.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicPopupMenuUI.java @@ -225,14 +225,14 @@ public class BasicPopupMenuUI extends PopupMenuUI { return popup; } - static List getPopups() { + static List getPopups() { MenuSelectionManager msm = MenuSelectionManager.defaultManager(); MenuElement[] p = msm.getSelectedPath(); - List list = new ArrayList(p.length); - for(int i = 0; i < p.length; i++) { - if (p[i] instanceof JPopupMenu) { - list.add((JPopupMenu)p[i]); + List list = new ArrayList(p.length); + for (MenuElement element : p) { + if (element instanceof JPopupMenu) { + list.add((JPopupMenu) element); } } return list; @@ -290,14 +290,14 @@ public class BasicPopupMenuUI extends PopupMenuUI { MenuElement subitem = findEnabledChild( subpopup.getSubElements(), -1, true); - ArrayList lst = new ArrayList(Arrays.asList(e.getPath())); + ArrayList lst = new ArrayList(Arrays.asList(e.getPath())); lst.add(menuToOpen); lst.add(subpopup); if (subitem != null) { lst.add(subitem); } - MenuElement newPath[] = new MenuElement[0];; - newPath = (MenuElement[])lst.toArray(newPath); + MenuElement newPath[] = new MenuElement[0]; + newPath = lst.toArray(newPath); MenuSelectionManager.defaultManager().setSelectedPath(newPath); e.consume(); } @@ -345,7 +345,7 @@ public class BasicPopupMenuUI extends PopupMenuUI { } if (matches == 0) { - ; // no op + // no op } else if (matches == 1) { // Invoke the menu action JMenuItem item = (JMenuItem)items[firstMatch]; @@ -362,7 +362,7 @@ public class BasicPopupMenuUI extends PopupMenuUI { // Select the menu item with the matching mnemonic. If // the same mnemonic has been invoked then select the next // menu item in the cycle. - MenuElement newItem = null; + MenuElement newItem; newItem = items[indexes[(currentIndex + 1) % matches]]; @@ -372,7 +372,6 @@ public class BasicPopupMenuUI extends PopupMenuUI { manager.setSelectedPath(newPath); e.consume(); } - return; } public void menuKeyReleased(MenuKeyEvent e) { @@ -625,7 +624,7 @@ public class BasicPopupMenuUI extends PopupMenuUI { // 4234793: This action should call JPopupMenu.firePopupMenuCanceled but it's // a protected method. The real solution could be to make // firePopupMenuCanceled public and call it directly. - JPopupMenu lastPopup = (JPopupMenu)getLastPopup(); + JPopupMenu lastPopup = getLastPopup(); if (lastPopup != null) { lastPopup.putClientProperty("JPopupMenu.firePopupMenuCanceled", Boolean.TRUE); } @@ -703,7 +702,7 @@ public class BasicPopupMenuUI extends PopupMenuUI { static MenuElement findEnabledChild(MenuElement e[], int fromIndex, boolean forward) { - MenuElement result = null; + MenuElement result; if (forward) { result = nextEnabledChild(e, fromIndex+1, e.length-1); if (result == null) result = nextEnabledChild(e, 0, fromIndex-1); @@ -752,7 +751,7 @@ public class BasicPopupMenuUI extends PopupMenuUI { // A grab needs to be added final Toolkit tk = Toolkit.getDefaultToolkit(); java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { + new java.security.PrivilegedAction() { public Object run() { tk.addAWTEventListener(MouseGrabber.this, AWTEvent.MOUSE_EVENT_MASK | @@ -785,7 +784,7 @@ public class BasicPopupMenuUI extends PopupMenuUI { final Toolkit tk = Toolkit.getDefaultToolkit(); // The grab should be removed java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { + new java.security.PrivilegedAction() { public Object run() { tk.removeAWTEventListener(MouseGrabber.this); return null; @@ -911,10 +910,8 @@ public class BasicPopupMenuUI extends PopupMenuUI { // 4234793: This action should call firePopupMenuCanceled but it's // a protected method. The real solution could be to make // firePopupMenuCanceled public and call it directly. - List popups = getPopups(); - Iterator iter = popups.iterator(); - while (iter.hasNext()) { - JPopupMenu popup = (JPopupMenu) iter.next(); + List popups = getPopups(); + for (JPopupMenu popup : popups) { popup.putClientProperty("JPopupMenu.firePopupMenuCanceled", Boolean.TRUE); } MenuSelectionManager.defaultManager().clearSelectedPath(); diff --git a/src/share/classes/javax/swing/plaf/basic/BasicRadioButtonUI.java b/src/share/classes/javax/swing/plaf/basic/BasicRadioButtonUI.java index 567f4e794..d1ddab993 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicRadioButtonUI.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicRadioButtonUI.java @@ -150,15 +150,15 @@ public class BasicRadioButtonUI extends BasicToggleButtonUI } } else if(model.isSelected()) { if(b.isRolloverEnabled() && model.isRollover()) { - altIcon = (Icon) b.getRolloverSelectedIcon(); + altIcon = b.getRolloverSelectedIcon(); if (altIcon == null) { - altIcon = (Icon) b.getSelectedIcon(); + altIcon = b.getSelectedIcon(); } } else { - altIcon = (Icon) b.getSelectedIcon(); + altIcon = b.getSelectedIcon(); } } else if(b.isRolloverEnabled() && model.isRollover()) { - altIcon = (Icon) b.getRolloverIcon(); + altIcon = b.getRolloverIcon(); } if(altIcon == null) { @@ -214,7 +214,7 @@ public class BasicRadioButtonUI extends BasicToggleButtonUI String text = b.getText(); - Icon buttonIcon = (Icon) b.getIcon(); + Icon buttonIcon = b.getIcon(); if(buttonIcon == null) { buttonIcon = getDefaultIcon(); } diff --git a/src/share/classes/javax/swing/plaf/basic/BasicSplitPaneUI.java b/src/share/classes/javax/swing/plaf/basic/BasicSplitPaneUI.java index 28427f7b3..0c7e995f0 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicSplitPaneUI.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicSplitPaneUI.java @@ -106,13 +106,13 @@ public class BasicSplitPaneUI extends SplitPaneUI * Keys to use for forward focus traversal when the JComponent is * managing focus. */ - private static Set managingFocusForwardTraversalKeys; + private static Set managingFocusForwardTraversalKeys; /** * Keys to use for backward focus traversal when the JComponent is * managing focus. */ - private static Set managingFocusBackwardTraversalKeys; + private static Set managingFocusBackwardTraversalKeys; /** @@ -370,7 +370,7 @@ public class BasicSplitPaneUI extends SplitPaneUI // focus forward traversal key if (managingFocusForwardTraversalKeys==null) { - managingFocusForwardTraversalKeys = new HashSet(); + managingFocusForwardTraversalKeys = new HashSet(); managingFocusForwardTraversalKeys.add( KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0)); } @@ -378,7 +378,7 @@ public class BasicSplitPaneUI extends SplitPaneUI managingFocusForwardTraversalKeys); // focus backward traversal key if (managingFocusBackwardTraversalKeys==null) { - managingFocusBackwardTraversalKeys = new HashSet(); + managingFocusBackwardTraversalKeys = new HashSet(); managingFocusBackwardTraversalKeys.add( KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK)); } @@ -2170,7 +2170,7 @@ public class BasicSplitPaneUI extends SplitPaneUI Component focusOn = (direction > 0) ? policy.getComponentAfter(rootAncestor, splitPane) : policy.getComponentBefore(rootAncestor, splitPane); - HashSet focusFrom = new HashSet(); + HashSet focusFrom = new HashSet(); if (splitPane.isAncestorOf(focusOn)) { do { focusFrom.add(focusOn); @@ -2212,7 +2212,7 @@ public class BasicSplitPaneUI extends SplitPaneUI private Component getNextSide(JSplitPane splitPane, Component focus) { Component left = splitPane.getLeftComponent(); Component right = splitPane.getRightComponent(); - Component next = null; + Component next; if (focus!=null && SwingUtilities.isDescendingFrom(focus, left) && right!=null) { next = getFirstAvailableComponent(right); diff --git a/src/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java b/src/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java index 2d0873cfc..0ecd43013 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java @@ -142,9 +142,9 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants { private Component visibleComponent; // PENDING(api): See comment for ContainerHandler - private Vector htmlViews; + private Vector htmlViews; - private Hashtable mnemonicToIndexMap; + private Hashtable mnemonicToIndexMap; /** * InputMap used for mnemonics. Only non-null if the JTabbedPane has @@ -546,7 +546,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants { * Installs the state needed for mnemonics. */ private void initMnemonics() { - mnemonicToIndexMap = new Hashtable(); + mnemonicToIndexMap = new Hashtable(); mnemonicInputMap = new ComponentInputMapUIResource(tabPane); mnemonicInputMap.setParent(SwingUtilities.getUIInputMap(tabPane, JComponent.WHEN_IN_FOCUSED_WINDOW)); @@ -909,10 +909,10 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants { private static final int CROP_SEGMENT = 12; private static Polygon createCroppedTabShape(int tabPlacement, Rectangle tabRect, int cropline) { - int rlen = 0; - int start = 0; - int end = 0; - int ostart = 0; + int rlen; + int start; + int end; + int ostart; switch(tabPlacement) { case LEFT: @@ -1014,7 +1014,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants { tabPane.putClientProperty("html", v); } - SwingUtilities.layoutCompoundLabel((JComponent) tabPane, + SwingUtilities.layoutCompoundLabel(tabPane, metrics, title, icon, SwingUtilities.CENTER, SwingUtilities.CENTER, @@ -1694,7 +1694,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants { */ protected View getTextViewForTab(int tabIndex) { if (htmlViews != null) { - return (View)htmlViews.elementAt(tabIndex); + return htmlViews.elementAt(tabIndex); } return null; } @@ -2230,8 +2230,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants { if (mnemonic >= 'a' && mnemonic <='z') { mnemonic -= ('a' - 'A'); } - Integer index = (Integer)ui.mnemonicToIndexMap. - get(Integer.valueOf(mnemonic)); + Integer index = ui.mnemonicToIndexMap.get(Integer.valueOf(mnemonic)); if (index != null && pane.isEnabledAt(index.intValue())) { pane.setSelectedIndex(index.intValue()); } @@ -2292,8 +2291,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants { for (int i = 0; i < tabPane.getTabCount(); i++) { Component component = tabPane.getComponentAt(i); if (component != null) { - Dimension size = zeroSize; - size = minimum? component.getMinimumSize() : + Dimension size = minimum ? component.getMinimumSize() : component.getPreferredSize(); if (size != null) { @@ -2305,7 +2303,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants { // Add content border insets to minimum size width += cWidth; height += cHeight; - int tabExtent = 0; + int tabExtent; // Calculate how much space the tabs will need, based on the // minimum size required to display largest child + content border @@ -3143,7 +3141,7 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants { Insets tabAreaInsets = getTabAreaInsets(tabPlacement); int fontHeight = metrics.getHeight(); int selectedIndex = tabPane.getSelectedIndex(); - int i, j; + int i; boolean verticalTabRuns = (tabPlacement == LEFT || tabPlacement == RIGHT); boolean leftToRight = BasicGraphicsUtils.isLeftToRight(tabPane); int x = tabAreaInsets.left; @@ -3433,10 +3431,10 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants { } public String toString() { - return new String("viewport.viewSize="+viewport.getViewSize()+"\n"+ + return "viewport.viewSize=" + viewport.getViewSize() + "\n" + "viewport.viewRectangle="+viewport.getViewRect()+"\n"+ "leadingTabIndex="+leadingTabIndex+"\n"+ - "tabViewPosition="+tabViewPosition); + "tabViewPosition=" + tabViewPosition; } } @@ -3788,8 +3786,8 @@ public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants { } } - private Vector createHTMLVector() { - Vector htmlViews = new Vector(); + private Vector createHTMLVector() { + Vector htmlViews = new Vector(); int count = tabPane.getTabCount(); if (count>0) { for (int i=0 ; i storedForwardTraversalKeys = editor. getFocusTraversalKeys(KeyboardFocusManager. FORWARD_TRAVERSAL_KEYS); - Set storedBackwardTraversalKeys = editor. + Set storedBackwardTraversalKeys = editor. getFocusTraversalKeys(KeyboardFocusManager. BACKWARD_TRAVERSAL_KEYS); - Set forwardTraversalKeys = - new HashSet(storedForwardTraversalKeys); - Set backwardTraversalKeys = - new HashSet(storedBackwardTraversalKeys); + Set forwardTraversalKeys = + new HashSet(storedForwardTraversalKeys); + Set backwardTraversalKeys = + new HashSet(storedBackwardTraversalKeys); if (editor.isEditable()) { forwardTraversalKeys. remove(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0)); @@ -1888,7 +1888,7 @@ public abstract class BasicTextUI extends TextUI implements ViewFactory { * * @param e The change notification from the currently associated * document. - * @see DocumentListener#changeUpdate + * @see DocumentListener#changedUpdate(DocumentEvent) */ public final void changedUpdate(DocumentEvent e) { Rectangle alloc = (painted) ? getVisibleEditorRect() : null; @@ -1964,9 +1964,9 @@ public abstract class BasicTextUI extends TextUI implements ViewFactory { } try { rootView.setSize(alloc.width, alloc.height); - Enumeration components = constraints.keys(); + Enumeration components = constraints.keys(); while (components.hasMoreElements()) { - Component comp = (Component) components.nextElement(); + Component comp = components.nextElement(); View v = (View) constraints.get(comp); Shape ca = calculateViewPosition(alloc, v); if (ca != null) { @@ -2009,7 +2009,7 @@ public abstract class BasicTextUI extends TextUI implements ViewFactory { public void addLayoutComponent(Component comp, Object constraint) { if (constraint instanceof View) { if (constraints == null) { - constraints = new Hashtable(7); + constraints = new Hashtable(7); } constraints.put(comp, constraint); } @@ -2060,7 +2060,7 @@ public abstract class BasicTextUI extends TextUI implements ViewFactory { * These are View objects for those components that are represented * by a View in the View tree. */ - private Hashtable constraints; + private Hashtable constraints; private boolean i18nView = false; } @@ -2457,8 +2457,7 @@ public abstract class BasicTextUI extends TextUI implements ViewFactory { JTextComponent c = (JTextComponent)comp; int pos = modeBetween - ? ((JTextComponent.DropLocation)c.getDropLocation()).getIndex() - : c.getCaretPosition(); + ? c.getDropLocation().getIndex() : c.getCaretPosition(); // if we are importing to the same component that we exported from // then don't actually do anything if the drop location is inside diff --git a/src/share/classes/javax/swing/plaf/basic/BasicToggleButtonUI.java b/src/share/classes/javax/swing/plaf/basic/BasicToggleButtonUI.java index 60802d6cc..18daffa59 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicToggleButtonUI.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicToggleButtonUI.java @@ -125,31 +125,31 @@ public class BasicToggleButtonUI extends BasicButtonUI { if(!model.isEnabled()) { if(model.isSelected()) { - icon = (Icon) b.getDisabledSelectedIcon(); + icon = b.getDisabledSelectedIcon(); } else { - icon = (Icon) b.getDisabledIcon(); + icon = b.getDisabledIcon(); } } else if(model.isPressed() && model.isArmed()) { - icon = (Icon) b.getPressedIcon(); + icon = b.getPressedIcon(); if(icon == null) { // Use selected icon - icon = (Icon) b.getSelectedIcon(); + icon = b.getSelectedIcon(); } } else if(model.isSelected()) { if(b.isRolloverEnabled() && model.isRollover()) { - icon = (Icon) b.getRolloverSelectedIcon(); + icon = b.getRolloverSelectedIcon(); if (icon == null) { - icon = (Icon) b.getSelectedIcon(); + icon = b.getSelectedIcon(); } } else { - icon = (Icon) b.getSelectedIcon(); + icon = b.getSelectedIcon(); } } else if(b.isRolloverEnabled() && model.isRollover()) { - icon = (Icon) b.getRolloverIcon(); + icon = b.getRolloverIcon(); } if(icon == null) { - icon = (Icon) b.getIcon(); + icon = b.getIcon(); } icon.paintIcon(b, g, iconRect.x, iconRect.y); diff --git a/src/share/classes/javax/swing/plaf/basic/BasicToolBarUI.java b/src/share/classes/javax/swing/plaf/basic/BasicToolBarUI.java index e039d1b42..2c3eb007b 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicToolBarUI.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicToolBarUI.java @@ -83,8 +83,8 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants private static Border nonRolloverToggleBorder; private boolean rolloverBorders = false; - private HashMap borderTable = new HashMap(); - private Hashtable rolloverTable = new Hashtable(); + private HashMap borderTable = new HashMap(); + private Hashtable rolloverTable = new Hashtable(); /** @@ -171,7 +171,7 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants uninstallKeyboardActions(); // Clear instance vars - if (isFloating() == true) + if (isFloating()) setFloating(false, null); floatingToolBar = null; @@ -273,9 +273,8 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants // Put focus listener on all components in toolbar Component[] components = toolBar.getComponents(); - for ( int i = 0; i < components.length; ++i ) - { - components[ i ].addFocusListener( toolBarFocusListener ); + for (Component component : components) { + component.addFocusListener(toolBarFocusListener); } } } @@ -307,9 +306,8 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants // Remove focus listener from all components in toolbar Component[] components = toolBar.getComponents(); - for ( int i = 0; i < components.length; ++i ) - { - components[ i ].removeFocusListener( toolBarFocusListener ); + for (Component component : components) { + component.removeFocusListener(toolBarFocusListener); } toolBarFocusListener = null; @@ -616,10 +614,10 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants // Put rollover borders on buttons Component[] components = c.getComponents(); - for ( int i = 0; i < components.length; ++i ) { - if ( components[ i ] instanceof JComponent ) { - ( (JComponent)components[ i ] ).updateUI(); - setBorderToRollover( components[ i ] ); + for (Component component : components) { + if (component instanceof JComponent) { + ((JComponent) component).updateUI(); + setBorderToRollover(component); } } } @@ -640,10 +638,10 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants // Put non-rollover borders on buttons. These borders reduce the margin. Component[] components = c.getComponents(); - for ( int i = 0; i < components.length; ++i ) { - if ( components[ i ] instanceof JComponent ) { - ( (JComponent)components[ i ] ).updateUI(); - setBorderToNonRollover( components[ i ] ); + for (Component component : components) { + if (component instanceof JComponent) { + ((JComponent) component).updateUI(); + setBorderToNonRollover(component); } } } @@ -664,8 +662,8 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants // Put back the normal borders on buttons Component[] components = c.getComponents(); - for ( int i = 0; i < components.length; ++i ) { - setBorderToNormal( components[ i ] ); + for (Component component : components) { + setBorderToNormal(component); } } @@ -681,7 +679,7 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants if (c instanceof AbstractButton) { AbstractButton b = (AbstractButton)c; - Border border = (Border)borderTable.get(b); + Border border = borderTable.get(b); if (border == null || border instanceof UIResource) { borderTable.put(b, b.getBorder()); } @@ -721,7 +719,7 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants if (c instanceof AbstractButton) { AbstractButton b = (AbstractButton)c; - Border border = (Border)borderTable.get(b); + Border border = borderTable.get(b); if (border == null || border instanceof UIResource) { borderTable.put(b, b.getBorder()); } @@ -765,10 +763,10 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants if (c instanceof AbstractButton) { AbstractButton b = (AbstractButton)c; - Border border = (Border)borderTable.remove(b); + Border border = borderTable.remove(b); b.setBorder(border); - Boolean value = (Boolean)rolloverTable.remove(b); + Boolean value = rolloverTable.remove(b); if (value != null) { b.setRolloverEnabled(value.booleanValue()); } @@ -785,7 +783,7 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants } public void setFloating(boolean b, Point p) { - if (toolBar.isFloatable() == true) { + if (toolBar.isFloatable()) { boolean visible = false; Window ancestor = SwingUtilities.getWindowAncestor(toolBar); if (ancestor != null) { @@ -953,7 +951,7 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants protected void dragTo(Point position, Point origin) { - if (toolBar.isFloatable() == true) + if (toolBar.isFloatable()) { try { @@ -1003,7 +1001,7 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants protected void floatAt(Point position, Point origin) { - if(toolBar.isFloatable() == true) + if(toolBar.isFloatable()) { try { @@ -1174,7 +1172,7 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants if (!tb.isEnabled()) { return; } - if (isDragging == true) { + if (isDragging) { Point position = evt.getPoint(); if (origin == null) origin = evt.getComponent().getLocationOnScreen(); @@ -1242,7 +1240,7 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants protected class FrameListener extends WindowAdapter { public void windowClosing(WindowEvent w) { - if (toolBar.isFloatable() == true) { + if (toolBar.isFloatable()) { if (dragWindow != null) dragWindow.setVisible(false); floating = false; diff --git a/src/share/classes/javax/swing/plaf/basic/BasicTreeUI.java b/src/share/classes/javax/swing/plaf/basic/BasicTreeUI.java index 56b16ba7c..eee08821e 100644 --- a/src/share/classes/javax/swing/plaf/basic/BasicTreeUI.java +++ b/src/share/classes/javax/swing/plaf/basic/BasicTreeUI.java @@ -1263,7 +1263,7 @@ public class BasicTreeUI extends TreeUI } private Rectangle getDropLineRect(JTree.DropLocation loc) { - Rectangle rect = null; + Rectangle rect; TreePath path = loc.getPath(); int index = loc.getChildIndex(); boolean ltr = leftToRight; @@ -2138,7 +2138,7 @@ public class BasicTreeUI extends TreeUI compositeRequestFocus(editingComponent); boolean selectAll = true; - if(event != null && event instanceof MouseEvent) { + if(event != null) { /* Find the component that will get forwarded all the mouse events until mouseReleased. */ Point componentPoint = SwingUtilities.convertPoint @@ -3125,7 +3125,7 @@ public class BasicTreeUI extends TreeUI private static final TransferHandler defaultTransferHandler = new TreeTransferHandler(); - static class TreeTransferHandler extends TransferHandler implements UIResource, Comparator { + static class TreeTransferHandler extends TransferHandler implements UIResource, Comparator { private JTree tree; @@ -3156,9 +3156,7 @@ public class BasicTreeUI extends TreeUI TreePath lastPath = null; TreePath[] displayPaths = getDisplayOrderPaths(paths); - for (int i = 0; i < displayPaths.length; i++) { - TreePath path = displayPaths[i]; - + for (TreePath path : displayPaths) { Object node = path.getLastPathComponent(); boolean leaf = model.isLeaf(node); String label = getDisplayString(path, true, leaf); @@ -3179,9 +3177,9 @@ public class BasicTreeUI extends TreeUI return null; } - public int compare(Object o1, Object o2) { - int row1 = tree.getRowForPath((TreePath)o1); - int row2 = tree.getRowForPath((TreePath)o2); + public int compare(TreePath o1, TreePath o2) { + int row1 = tree.getRowForPath(o1); + int row2 = tree.getRowForPath(o2); return row1 - row2; } @@ -3200,15 +3198,15 @@ public class BasicTreeUI extends TreeUI */ TreePath[] getDisplayOrderPaths(TreePath[] paths) { // sort the paths to display order rather than selection order - ArrayList selOrder = new ArrayList(); - for (int i = 0; i < paths.length; i++) { - selOrder.add(paths[i]); + ArrayList selOrder = new ArrayList(); + for (TreePath path : paths) { + selOrder.add(path); } Collections.sort(selOrder, this); int n = selOrder.size(); TreePath[] displayPaths = new TreePath[n]; for (int i = 0; i < n; i++) { - displayPaths[i] = (TreePath) selOrder.get(i); + displayPaths[i] = selOrder.get(i); } return displayPaths; } @@ -3321,10 +3319,7 @@ public class BasicTreeUI extends TreeUI InputMap inputMap = tree.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); KeyStroke key = KeyStroke.getKeyStrokeForEvent(event); - if (inputMap != null && inputMap.get(key) != null) { - return true; - } - return false; + return inputMap != null && inputMap.get(key) != null; } diff --git a/src/share/classes/javax/swing/plaf/basic/DragRecognitionSupport.java b/src/share/classes/javax/swing/plaf/basic/DragRecognitionSupport.java index 060019810..be457ccb2 100644 --- a/src/share/classes/javax/swing/plaf/basic/DragRecognitionSupport.java +++ b/src/share/classes/javax/swing/plaf/basic/DragRecognitionSupport.java @@ -73,8 +73,7 @@ class DragRecognitionSupport { * Returns whether or not the event is potentially part of a drag sequence. */ public static boolean mousePressed(MouseEvent me) { - return ((DragRecognitionSupport)getDragRecognitionSupport()). - mousePressedImpl(me); + return getDragRecognitionSupport().mousePressedImpl(me); } /** @@ -82,16 +81,14 @@ class DragRecognitionSupport { * that started the recognition. Otherwise, return null. */ public static MouseEvent mouseReleased(MouseEvent me) { - return ((DragRecognitionSupport)getDragRecognitionSupport()). - mouseReleasedImpl(me); + return getDragRecognitionSupport().mouseReleasedImpl(me); } /** * Returns whether or not a drag gesture recognition is ongoing. */ public static boolean mouseDragged(MouseEvent me, BeforeDrag bd) { - return ((DragRecognitionSupport)getDragRecognitionSupport()). - mouseDraggedImpl(me, bd); + return getDragRecognitionSupport().mouseDraggedImpl(me, bd); } private void clearState() { diff --git a/src/share/classes/javax/swing/plaf/basic/LazyActionMap.java b/src/share/classes/javax/swing/plaf/basic/LazyActionMap.java index f148707a7..e57ff78d2 100644 --- a/src/share/classes/javax/swing/plaf/basic/LazyActionMap.java +++ b/src/share/classes/javax/swing/plaf/basic/LazyActionMap.java @@ -142,7 +142,7 @@ class LazyActionMap extends ActionMapUIResource { Object loader = _loader; _loader = null; - Class klass = (Class)loader; + Class klass = (Class)loader; try { Method method = klass.getDeclaredMethod("loadActionMap", new Class[] { LazyActionMap.class }); diff --git a/src/share/classes/javax/swing/plaf/metal/DefaultMetalTheme.java b/src/share/classes/javax/swing/plaf/metal/DefaultMetalTheme.java index dbb9b346a..96b944d0d 100644 --- a/src/share/classes/javax/swing/plaf/metal/DefaultMetalTheme.java +++ b/src/share/classes/javax/swing/plaf/metal/DefaultMetalTheme.java @@ -387,9 +387,9 @@ public class DefaultMetalTheme extends MetalTheme { * that it is wrapped inside a doPrivileged call. */ protected Font getPrivilegedFont(final int key) { - return (Font)java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { + return java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction() { + public Font run() { return Font.getFont(getDefaultPropertyName(key)); } } diff --git a/src/share/classes/javax/swing/plaf/metal/MetalBumps.java b/src/share/classes/javax/swing/plaf/metal/MetalBumps.java index ec6f0300c..47e379a48 100644 --- a/src/share/classes/javax/swing/plaf/metal/MetalBumps.java +++ b/src/share/classes/javax/swing/plaf/metal/MetalBumps.java @@ -49,7 +49,7 @@ class MetalBumps implements Icon { protected Color shadowColor; protected Color backColor; - protected static Vector buffers = new Vector(); + protected static Vector buffers = new Vector(); protected BumpBuffer buffer; public MetalBumps( Dimension bumpArea ) { @@ -81,10 +81,7 @@ class MetalBumps implements Icon { } BumpBuffer result = null; - Enumeration elements = buffers.elements(); - - while ( elements.hasMoreElements() ) { - BumpBuffer aBuffer = (BumpBuffer)elements.nextElement(); + for (BumpBuffer aBuffer : buffers) { if ( aBuffer.hasSameConfiguration(gc, aTopColor, aShadowColor, aBackColor)) { result = aBuffer; @@ -120,8 +117,7 @@ class MetalBumps implements Icon { public void paintIcon( Component c, Graphics g, int x, int y ) { GraphicsConfiguration gc = (g instanceof Graphics2D) ? - (GraphicsConfiguration)((Graphics2D)g). - getDeviceConfiguration() : null; + ((Graphics2D) g).getDeviceConfiguration() : null; buffer = getBuffer(gc, topColor, shadowColor, backColor); diff --git a/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java b/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java index 3489cd3e4..fd837b9ab 100644 --- a/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java +++ b/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java @@ -782,7 +782,7 @@ public class MetalFileChooserUI extends BasicFileChooserUI { } else if (s.equals("componentOrientation")) { ComponentOrientation o = (ComponentOrientation)e.getNewValue(); JFileChooser cc = (JFileChooser)e.getSource(); - if (o != (ComponentOrientation)e.getOldValue()) { + if (o != e.getOldValue()) { cc.applyComponentOrientation(o); } } else if (s == "FileChooser.useShellFolder") { @@ -927,7 +927,7 @@ public class MetalFileChooserUI extends BasicFileChooserUI { * Data model for a type-face selection combo-box. */ protected class DirectoryComboBoxModel extends AbstractListModel implements ComboBoxModel { - Vector directories = new Vector(); + Vector directories = new Vector(); int[] depths = null; File selectedDirectory = null; JFileChooser chooser = getFileChooser(); @@ -966,7 +966,7 @@ public class MetalFileChooserUI extends BasicFileChooserUI { // Get the canonical (full) path. This has the side // benefit of removing extraneous chars from the path, // for example /foo/bar/ becomes /foo/bar - File canonical = null; + File canonical; try { canonical = ShellFolder.getNormalizedFile(directory); } catch (IOException e) { @@ -979,7 +979,7 @@ public class MetalFileChooserUI extends BasicFileChooserUI { File sf = useShellFolder ? ShellFolder.getShellFolder(canonical) : canonical; File f = sf; - Vector path = new Vector(10); + Vector path = new Vector(10); do { path.addElement(f); } while ((f = f.getParentFile()) != null); @@ -987,7 +987,7 @@ public class MetalFileChooserUI extends BasicFileChooserUI { int pathCount = path.size(); // Insert chain at appropriate place in vector for (int i = 0; i < pathCount; i++) { - f = (File)path.get(i); + f = path.get(i); if (directories.contains(f)) { int topIndex = directories.indexOf(f); for (int j = i-1; j >= 0; j--) { @@ -1006,12 +1006,12 @@ public class MetalFileChooserUI extends BasicFileChooserUI { private void calculateDepths() { depths = new int[directories.size()]; for (int i = 0; i < depths.length; i++) { - File dir = (File)directories.get(i); + File dir = directories.get(i); File parent = dir.getParentFile(); depths[i] = 0; if (parent != null) { for (int j = i-1; j >= 0; j--) { - if (parent.equals((File)directories.get(j))) { + if (parent.equals(directories.get(j))) { depths[i] = depths[j] + 1; break; } @@ -1110,8 +1110,8 @@ public class MetalFileChooserUI extends BasicFileChooserUI { FileFilter currentFilter = getFileChooser().getFileFilter(); boolean found = false; if(currentFilter != null) { - for(int i=0; i < filters.length; i++) { - if(filters[i] == currentFilter) { + for (FileFilter filter : filters) { + if (filter == currentFilter) { found = true; } } diff --git a/src/share/classes/javax/swing/plaf/metal/MetalIconFactory.java b/src/share/classes/javax/swing/plaf/metal/MetalIconFactory.java index 72c2230d1..54721c88a 100644 --- a/src/share/classes/javax/swing/plaf/metal/MetalIconFactory.java +++ b/src/share/classes/javax/swing/plaf/metal/MetalIconFactory.java @@ -598,7 +598,7 @@ public class MetalIconFactory implements Serializable { } // Some calculations that are needed more than once later on. - int oneHalf = (int)(iconSize / 2); // 16 -> 8 + int oneHalf = iconSize / 2; // 16 -> 8 g.translate(x, y); @@ -1502,7 +1502,7 @@ public class MetalIconFactory implements Serializable { // PENDING: Replace this class with CachedPainter. - Vector images = new Vector(1, 1); + Vector images = new Vector(1, 1); ImageGcPair currentImageGcPair; class ImageGcPair { @@ -1514,12 +1514,8 @@ public class MetalIconFactory implements Serializable { } boolean hasSameConfiguration(GraphicsConfiguration newGC) { - if (((newGC != null) && (newGC.equals(gc))) || - ((newGC == null) && (gc == null))) - { - return true; - } - return false; + return ((newGC != null) && (newGC.equals(gc))) || + ((newGC == null) && (gc == null)); } } @@ -1528,9 +1524,7 @@ public class MetalIconFactory implements Serializable { if ((currentImageGcPair == null) || !(currentImageGcPair.hasSameConfiguration(newGC))) { - Enumeration elements = images.elements(); - while (elements.hasMoreElements()) { - ImageGcPair imgGcPair = (ImageGcPair)elements.nextElement(); + for (ImageGcPair imgGcPair : images) { if (imgGcPair.hasSameConfiguration(newGC)) { currentImageGcPair = imgGcPair; return imgGcPair.image; diff --git a/src/share/classes/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java b/src/share/classes/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java index a0b8ada11..6de655d58 100644 --- a/src/share/classes/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java +++ b/src/share/classes/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java @@ -191,7 +191,7 @@ public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane { extends BasicInternalFrameTitlePane.PropertyChangeHandler { public void propertyChange(PropertyChangeEvent evt) { - String prop = (String)evt.getPropertyName(); + String prop = evt.getPropertyName(); if( prop.equals(JInternalFrame.IS_SELECTED_PROPERTY) ) { Boolean b = (Boolean)evt.getNewValue(); iconButton.putClientProperty("paintActive", b); @@ -242,7 +242,7 @@ public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane { } // Compute height. - int height = 0; + int height; if (isPalette) { height = paletteTitleHeight; } else { @@ -410,7 +410,7 @@ public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane { g.drawLine ( width - 1, 0 , width -1, 0); - int titleLength = 0; + int titleLength; int xOffset = leftToRight ? 5 : width - 5; String frameTitle = frame.getTitle(); diff --git a/src/share/classes/javax/swing/plaf/metal/MetalLookAndFeel.java b/src/share/classes/javax/swing/plaf/metal/MetalLookAndFeel.java index 272799409..01cebbf10 100644 --- a/src/share/classes/javax/swing/plaf/metal/MetalLookAndFeel.java +++ b/src/share/classes/javax/swing/plaf/metal/MetalLookAndFeel.java @@ -2208,9 +2208,9 @@ public class MetalLookAndFeel extends BasicLookAndFeel if (methodName == null) { return c.newInstance(); } - Method method = (Method)AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { + Method method = AccessController.doPrivileged( + new PrivilegedAction() { + public Method run() { Method[] methods = c.getDeclaredMethods(); for (int counter = methods.length - 1; counter >= 0; counter--) { @@ -2273,7 +2273,7 @@ public class MetalLookAndFeel extends BasicLookAndFeel } } - static ReferenceQueue queue = new ReferenceQueue(); + static ReferenceQueue queue = new ReferenceQueue(); static void flushUnreferenced() { AATextListener aatl; @@ -2283,7 +2283,7 @@ public class MetalLookAndFeel extends BasicLookAndFeel } static class AATextListener - extends WeakReference implements PropertyChangeListener { + extends WeakReference implements PropertyChangeListener { private String key = SunToolkit.DESKTOPFONTHINTS; @@ -2294,7 +2294,7 @@ public class MetalLookAndFeel extends BasicLookAndFeel } public void propertyChange(PropertyChangeEvent pce) { - LookAndFeel laf = (LookAndFeel)get(); + LookAndFeel laf = get(); if (laf == null || laf != UIManager.getLookAndFeel()) { dispose(); return; @@ -2318,8 +2318,8 @@ public class MetalLookAndFeel extends BasicLookAndFeel private static void updateWindowUI(Window window) { SwingUtilities.updateComponentTreeUI(window); Window ownedWins[] = window.getOwnedWindows(); - for (int i=0; i < ownedWins.length; i++) { - updateWindowUI(ownedWins[i]); + for (Window w : ownedWins) { + updateWindowUI(w); } } @@ -2328,8 +2328,8 @@ public class MetalLookAndFeel extends BasicLookAndFeel */ private static void updateAllUIs() { Frame appFrames[] = Frame.getFrames(); - for (int j=0; j < appFrames.length; j++) { - updateWindowUI(appFrames[j]); + for (Frame frame : appFrames) { + updateWindowUI(frame); } } diff --git a/src/share/classes/javax/swing/plaf/metal/MetalRadioButtonUI.java b/src/share/classes/javax/swing/plaf/metal/MetalRadioButtonUI.java index 1d6882455..ba96b21e6 100644 --- a/src/share/classes/javax/swing/plaf/metal/MetalRadioButtonUI.java +++ b/src/share/classes/javax/swing/plaf/metal/MetalRadioButtonUI.java @@ -164,15 +164,15 @@ public class MetalRadioButtonUI extends BasicRadioButtonUI { } } else if(model.isSelected()) { if(b.isRolloverEnabled() && model.isRollover()) { - altIcon = (Icon) b.getRolloverSelectedIcon(); + altIcon = b.getRolloverSelectedIcon(); if (altIcon == null) { - altIcon = (Icon) b.getSelectedIcon(); + altIcon = b.getSelectedIcon(); } } else { - altIcon = (Icon) b.getSelectedIcon(); + altIcon = b.getSelectedIcon(); } } else if(b.isRolloverEnabled() && model.isRollover()) { - altIcon = (Icon) b.getRolloverIcon(); + altIcon = b.getRolloverIcon(); } if(altIcon == null) { diff --git a/src/share/classes/javax/swing/plaf/metal/MetalToolBarUI.java b/src/share/classes/javax/swing/plaf/metal/MetalToolBarUI.java index eed7d6303..24e4e54f3 100644 --- a/src/share/classes/javax/swing/plaf/metal/MetalToolBarUI.java +++ b/src/share/classes/javax/swing/plaf/metal/MetalToolBarUI.java @@ -61,7 +61,7 @@ public class MetalToolBarUI extends BasicToolBarUI * instances of JToolBars and JMenuBars and is used to find * JToolBars/JMenuBars that border each other. */ - private static java.util.List components = new ArrayList(); + private static List> components = new ArrayList>(); /** * This protected field is implemenation specific. Do not access directly @@ -95,7 +95,7 @@ public class MetalToolBarUI extends BasicToolBarUI // typed to throw an NPE. throw new NullPointerException("JComponent must be non-null"); } - components.add(new WeakReference(c)); + components.add(new WeakReference(c)); } /** @@ -105,8 +105,7 @@ public class MetalToolBarUI extends BasicToolBarUI for (int counter = components.size() - 1; counter >= 0; counter--) { // Search for the component, removing any flushed references // along the way. - WeakReference ref = (WeakReference)components.get(counter); - Object target = ((WeakReference)components.get(counter)).get(); + JComponent target = components.get(counter).get(); if (target == c || target == null) { components.remove(counter); diff --git a/src/share/classes/javax/swing/plaf/synth/DefaultSynthStyleFactory.java b/src/share/classes/javax/swing/plaf/synth/DefaultSynthStyleFactory.java index 93512afb4..bbcbbad81 100644 --- a/src/share/classes/javax/swing/plaf/synth/DefaultSynthStyleFactory.java +++ b/src/share/classes/javax/swing/plaf/synth/DefaultSynthStyleFactory.java @@ -63,7 +63,7 @@ class DefaultSynthStyleFactory extends SynthStyleFactory { /** * Maps from a List (BakedArrayList to be precise) to the merged style. */ - private Map _resolvedStyles; + private Map _resolvedStyles; /** * Used if there are no styles matching a widget. @@ -74,7 +74,7 @@ class DefaultSynthStyleFactory extends SynthStyleFactory { DefaultSynthStyleFactory() { _tmpList = new BakedArrayList(5); _styles = new ArrayList(); - _resolvedStyles = new HashMap(); + _resolvedStyles = new HashMap(); } public synchronized void addStyle(DefaultSynthStyle style, @@ -138,7 +138,7 @@ class DefaultSynthStyleFactory extends SynthStyleFactory { * Fetches any styles that match the passed into arguments into * matches. */ - private void getMatchingStyles(java.util.List matches, JComponent c, + private void getMatchingStyles(List matches, JComponent c, Region id) { String idName = id.getLowerCaseName(); String cName = c.getName(); @@ -166,7 +166,7 @@ class DefaultSynthStyleFactory extends SynthStyleFactory { /** * Caches the specified style. */ - private void cacheStyle(java.util.List styles, SynthStyle style) { + private void cacheStyle(List styles, SynthStyle style) { BakedArrayList cachedStyles = new BakedArrayList(styles); _resolvedStyles.put(cachedStyles, style); @@ -175,11 +175,11 @@ class DefaultSynthStyleFactory extends SynthStyleFactory { /** * Returns the cached style from the passed in arguments. */ - private SynthStyle getCachedStyle(java.util.List styles) { + private SynthStyle getCachedStyle(List styles) { if (styles.size() == 0) { return null; } - return (SynthStyle)_resolvedStyles.get(styles); + return _resolvedStyles.get(styles); } /** @@ -187,7 +187,7 @@ class DefaultSynthStyleFactory extends SynthStyleFactory { * is reverse sorted, that is the most recently added style found to * match will be first. */ - private SynthStyle mergeStyles(java.util.List styles) { + private SynthStyle mergeStyles(List styles) { int size = styles.size(); if (size == 0) { diff --git a/src/share/classes/javax/swing/plaf/synth/ImagePainter.java b/src/share/classes/javax/swing/plaf/synth/ImagePainter.java index b9a02a619..943e91dbd 100644 --- a/src/share/classes/javax/swing/plaf/synth/ImagePainter.java +++ b/src/share/classes/javax/swing/plaf/synth/ImagePainter.java @@ -66,7 +66,7 @@ class ImagePainter extends SynthPainter { Paint9Painter painter; if (cacheRef == null || (painter = cacheRef.get()) == null) { painter = new Paint9Painter(30); - cacheRef = new WeakReference(painter); + cacheRef = new WeakReference(painter); AppContext.getAppContext().put(CACHE_KEY, cacheRef); } return painter; diff --git a/src/share/classes/javax/swing/plaf/synth/Region.java b/src/share/classes/javax/swing/plaf/synth/Region.java index ef9342646..bd144bf68 100644 --- a/src/share/classes/javax/swing/plaf/synth/Region.java +++ b/src/share/classes/javax/swing/plaf/synth/Region.java @@ -67,8 +67,8 @@ import java.util.*; * @author Scott Violet */ public class Region { - private static final Map uiToRegionMap = new HashMap(); - private static final Map lowerCaseNameMap = new HashMap(); + private static final Map uiToRegionMap = new HashMap(); + private static final Map lowerCaseNameMap = new HashMap(); /** * ArrowButton's are special types of buttons that also render a @@ -451,15 +451,11 @@ public class Region { static Region getRegion(JComponent c) { - return (Region)uiToRegionMap.get(c.getUIClassID()); + return uiToRegionMap.get(c.getUIClassID()); } static void registerUIs(UIDefaults table) { - Iterator uis = uiToRegionMap.keySet().iterator(); - - while (uis.hasNext()) { - Object key = uis.next(); - + for (String key : uiToRegionMap.keySet()) { table.put(key, "javax.swing.plaf.synth.SynthLookAndFeel"); } } @@ -521,7 +517,7 @@ public class Region { */ String getLowerCaseName() { synchronized(lowerCaseNameMap) { - String lowerCaseName = (String)lowerCaseNameMap.get(this); + String lowerCaseName = lowerCaseNameMap.get(this); if (lowerCaseName == null) { lowerCaseName = getName().toLowerCase(); lowerCaseNameMap.put(this, lowerCaseName); diff --git a/src/share/classes/javax/swing/plaf/synth/SynthComboBoxUI.java b/src/share/classes/javax/swing/plaf/synth/SynthComboBoxUI.java index 926c31e56..b4b0b9db4 100644 --- a/src/share/classes/javax/swing/plaf/synth/SynthComboBoxUI.java +++ b/src/share/classes/javax/swing/plaf/synth/SynthComboBoxUI.java @@ -336,7 +336,7 @@ class SynthComboBoxUI extends BasicComboBoxUI implements return oldValue; } else { // Must take the value from the editor and get the value and cast it to the new type. - Class cls = oldValue.getClass(); + Class cls = oldValue.getClass(); try { Method method = cls.getMethod("valueOf", new Class[]{String.class}); newValue = method.invoke(oldValue, new Object[] { editor.getText()}); diff --git a/src/share/classes/javax/swing/plaf/synth/SynthContext.java b/src/share/classes/javax/swing/plaf/synth/SynthContext.java index 3b3b0b8e0..f63c3abcf 100644 --- a/src/share/classes/javax/swing/plaf/synth/SynthContext.java +++ b/src/share/classes/javax/swing/plaf/synth/SynthContext.java @@ -39,7 +39,7 @@ import java.util.*; * @author Scott Violet */ public class SynthContext { - private static final Map contextMap; + private static final Map> contextMap; private JComponent component; private Region region; @@ -48,7 +48,7 @@ public class SynthContext { static { - contextMap = new HashMap(); + contextMap = new HashMap>(); } @@ -58,13 +58,13 @@ public class SynthContext { SynthContext context = null; synchronized(contextMap) { - java.util.List instances = (java.util.List)contextMap.get(type); + List instances = contextMap.get(type); if (instances != null) { int size = instances.size(); if (size > 0) { - context = (SynthContext)instances.remove(size - 1); + context = instances.remove(size - 1); } } } @@ -81,11 +81,10 @@ public class SynthContext { static void releaseContext(SynthContext context) { synchronized(contextMap) { - java.util.List instances = (java.util.List)contextMap.get( - context.getClass()); + List instances = contextMap.get(context.getClass()); if (instances == null) { - instances = new ArrayList(5); + instances = new ArrayList(5); contextMap.put(context.getClass(), instances); } instances.add(context); diff --git a/src/share/classes/javax/swing/plaf/synth/SynthEditorPaneUI.java b/src/share/classes/javax/swing/plaf/synth/SynthEditorPaneUI.java index b63ab2a60..f99741a01 100644 --- a/src/share/classes/javax/swing/plaf/synth/SynthEditorPaneUI.java +++ b/src/share/classes/javax/swing/plaf/synth/SynthEditorPaneUI.java @@ -45,8 +45,8 @@ class SynthEditorPaneUI extends BasicEditorPaneUI implements SynthUI { * I would prefer to use UIResource instad of this. * Unfortunately Boolean is a final class */ - private Boolean localTrue = new Boolean(true); - private Boolean localFalse = new Boolean(false); + private Boolean localTrue = Boolean.TRUE; + private Boolean localFalse = Boolean.FALSE; /** * Creates a UI for the JTextPane. @@ -69,7 +69,7 @@ class SynthEditorPaneUI extends BasicEditorPaneUI implements SynthUI { c.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, localTrue); } - updateStyle((JTextComponent)getComponent()); + updateStyle(getComponent()); } protected void uninstallDefaults() { diff --git a/src/share/classes/javax/swing/plaf/synth/SynthGraphicsUtils.java b/src/share/classes/javax/swing/plaf/synth/SynthGraphicsUtils.java index 7d8bade86..62c45ab64 100644 --- a/src/share/classes/javax/swing/plaf/synth/SynthGraphicsUtils.java +++ b/src/share/classes/javax/swing/plaf/synth/SynthGraphicsUtils.java @@ -416,7 +416,7 @@ public class SynthGraphicsUtils { * the SynthIcon with a given SynthContext. */ private static class SynthIconWrapper implements Icon { - private static final java.util.List CACHE = new java.util.ArrayList(1); + private static final java.util.List CACHE = new java.util.ArrayList(1); private SynthIcon synthIcon; private SynthContext context; @@ -425,8 +425,7 @@ public class SynthGraphicsUtils { synchronized(CACHE) { int size = CACHE.size(); if (size > 0) { - SynthIconWrapper wrapper = (SynthIconWrapper)CACHE.remove( - size - 1); + SynthIconWrapper wrapper = CACHE.remove(size - 1); wrapper.reset(icon, context); return wrapper; } diff --git a/src/share/classes/javax/swing/plaf/synth/SynthInternalFrameTitlePane.java b/src/share/classes/javax/swing/plaf/synth/SynthInternalFrameTitlePane.java index 19d218871..353c95c03 100644 --- a/src/share/classes/javax/swing/plaf/synth/SynthInternalFrameTitlePane.java +++ b/src/share/classes/javax/swing/plaf/synth/SynthInternalFrameTitlePane.java @@ -197,18 +197,18 @@ class SynthInternalFrameTitlePane extends BasicInternalFrameTitlePane protected void addSystemMenuItems(JPopupMenu menu) { // PENDING: this should all be localizable! - JMenuItem mi = (JMenuItem)menu.add(restoreAction); + JMenuItem mi = menu.add(restoreAction); mi.setMnemonic('R'); - mi = (JMenuItem)menu.add(moveAction); + mi = menu.add(moveAction); mi.setMnemonic('M'); - mi = (JMenuItem)menu.add(sizeAction); + mi = menu.add(sizeAction); mi.setMnemonic('S'); - mi = (JMenuItem)menu.add(iconifyAction); + mi = menu.add(iconifyAction); mi.setMnemonic('n'); - mi = (JMenuItem)menu.add(maximizeAction); + mi = menu.add(maximizeAction); mi.setMnemonic('x'); menu.add(new JSeparator()); - mi = (JMenuItem)menu.add(closeAction); + mi = menu.add(closeAction); mi.setMnemonic('C'); } diff --git a/src/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java b/src/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java index af3d68771..c9f6f7687 100644 --- a/src/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java +++ b/src/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java @@ -107,7 +107,7 @@ public class SynthLookAndFeel extends BasicLookAndFeel { * Map of defaults table entries. This is populated via the load * method. */ - private Map defaultsMap; + private Map defaultsMap; private Handler _handler; @@ -308,8 +308,8 @@ public class SynthLookAndFeel extends BasicLookAndFeel { children = ((Container)c).getComponents(); } if (children != null) { - for(int i = 0; i < children.length; i++) { - updateStyles(children[i]); + for (Component child : children) { + updateStyles(child); } } } @@ -581,7 +581,7 @@ public class SynthLookAndFeel extends BasicLookAndFeel { } if (defaultsMap == null) { - defaultsMap = new HashMap(); + defaultsMap = new HashMap(); } new SynthParser().parse(input, (DefaultSynthStyleFactory) factory, @@ -611,7 +611,7 @@ public class SynthLookAndFeel extends BasicLookAndFeel { } if (defaultsMap == null) { - defaultsMap = new HashMap(); + defaultsMap = new HashMap(); } InputStream input = url.openStream(); @@ -771,7 +771,7 @@ public class SynthLookAndFeel extends BasicLookAndFeel { */ private static Object getAATextInfo() { String language = Locale.getDefault().getLanguage(); - String desktop = (String) + String desktop = AccessController.doPrivileged(new GetPropertyAction("sun.desktop")); boolean isCjkLocale = (Locale.CHINESE.getLanguage().equals(language) || @@ -786,7 +786,7 @@ public class SynthLookAndFeel extends BasicLookAndFeel { return aaTextInfo; } - private static ReferenceQueue queue = new ReferenceQueue(); + private static ReferenceQueue queue = new ReferenceQueue(); private static void flushUnreferenced() { AATextListener aatl; @@ -796,7 +796,7 @@ public class SynthLookAndFeel extends BasicLookAndFeel { } private static class AATextListener - extends WeakReference implements PropertyChangeListener { + extends WeakReference implements PropertyChangeListener { private String key = SunToolkit.DESKTOPFONTHINTS; AATextListener(LookAndFeel laf) { @@ -812,7 +812,7 @@ public class SynthLookAndFeel extends BasicLookAndFeel { return; } - LookAndFeel laf = (LookAndFeel) get(); + LookAndFeel laf = get(); if (laf == null || laf != UIManager.getLookAndFeel()) { dispose(); return; @@ -835,8 +835,8 @@ public class SynthLookAndFeel extends BasicLookAndFeel { private static void updateWindowUI(Window window) { updateStyles(window); Window ownedWins[] = window.getOwnedWindows(); - for (int i = 0; i < ownedWins.length; i++) { - updateWindowUI(ownedWins[i]); + for (Window w : ownedWins) { + updateWindowUI(w); } } @@ -845,8 +845,8 @@ public class SynthLookAndFeel extends BasicLookAndFeel { */ private static void updateAllUIs() { Frame appFrames[] = Frame.getFrames(); - for (int i = 0; i < appFrames.length; i++) { - updateWindowUI(appFrames[i]); + for (Frame frame : appFrames) { + updateWindowUI(frame); } } @@ -909,7 +909,7 @@ public class SynthLookAndFeel extends BasicLookAndFeel { // register it on the new one. KeyboardFocusManager manager = (KeyboardFocusManager)evt.getSource(); - if (((Boolean)newValue).equals(Boolean.FALSE)) { + if (newValue.equals(Boolean.FALSE)) { manager.removePropertyChangeListener(_handler); } else { diff --git a/src/share/classes/javax/swing/plaf/synth/SynthMenuItemUI.java b/src/share/classes/javax/swing/plaf/synth/SynthMenuItemUI.java index a921f9d4b..39fc82c10 100644 --- a/src/share/classes/javax/swing/plaf/synth/SynthMenuItemUI.java +++ b/src/share/classes/javax/swing/plaf/synth/SynthMenuItemUI.java @@ -106,7 +106,7 @@ class SynthMenuItemUI extends BasicMenuItemUI implements Icon checkIcon, Icon arrowIcon, int defaultTextIconGap, String acceleratorDelimiter) { JMenuItem b = (JMenuItem) c; - Icon icon = (Icon) b.getIcon(); + Icon icon = b.getIcon(); String text = b.getText(); KeyStroke accelerator = b.getAccelerator(); String acceleratorText = ""; @@ -306,15 +306,15 @@ class SynthMenuItemUI extends BasicMenuItemUI implements if(b.getIcon() != null) { Icon icon; if(!model.isEnabled()) { - icon = (Icon) b.getDisabledIcon(); + icon = b.getDisabledIcon(); } else if(model.isPressed() && model.isArmed()) { - icon = (Icon) b.getPressedIcon(); + icon = b.getPressedIcon(); if(icon == null) { // Use default icon - icon = (Icon) b.getIcon(); + icon = b.getIcon(); } } else { - icon = (Icon) b.getIcon(); + icon = b.getIcon(); } if (icon!=null) { diff --git a/src/share/classes/javax/swing/plaf/synth/SynthParser.java b/src/share/classes/javax/swing/plaf/synth/SynthParser.java index 4b7d7994b..5f7a9b6c2 100644 --- a/src/share/classes/javax/swing/plaf/synth/SynthParser.java +++ b/src/share/classes/javax/swing/plaf/synth/SynthParser.java @@ -40,6 +40,7 @@ import java.net.URLClassLoader; import java.text.ParseException; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.Map; import java.util.StringTokenizer; @@ -136,7 +137,7 @@ class SynthParser extends HandlerBase { * Array of state infos for the current style. These are pushed to the * style when is received. */ - private java.util.List _stateInfos; + private List _stateInfos; /** * Current style. @@ -151,7 +152,7 @@ class SynthParser extends HandlerBase { /** * Bindings for the current InputMap */ - private java.util.List _inputMapBindings; + private List _inputMapBindings; /** * ID for the input map. This is cached as @@ -177,30 +178,30 @@ class SynthParser extends HandlerBase { /** * List of ColorTypes. This is populated in startColorType. */ - private java.util.List _colorTypes; + private List _colorTypes; /** * defaultsPropertys are placed here. */ - private Map _defaultsMap; + private Map _defaultsMap; /** * List of SynthStyle.Painters that will be applied to the current style. */ - private java.util.List _stylePainters; + private List _stylePainters; /** * List of SynthStyle.Painters that will be applied to the current state. */ - private java.util.List _statePainters; + private List _statePainters; SynthParser() { _mapping = new HashMap(); - _stateInfos = new ArrayList(); - _colorTypes = new ArrayList(); - _inputMapBindings = new ArrayList(); - _stylePainters = new ArrayList(); - _statePainters = new ArrayList(); + _stateInfos = new ArrayList(); + _colorTypes = new ArrayList(); + _inputMapBindings = new ArrayList(); + _stylePainters = new ArrayList(); + _statePainters = new ArrayList(); } /** @@ -219,7 +220,7 @@ class SynthParser extends HandlerBase { public void parse(InputStream inputStream, DefaultSynthStyleFactory factory, URL urlResourceBase, Class classResourceBase, - Map defaultsMap) + Map defaultsMap) throws ParseException, IllegalArgumentException { if (inputStream == null || factory == null || (urlResourceBase == null && classResourceBase == null)) { @@ -333,7 +334,7 @@ class SynthParser extends HandlerBase { * type type, this will throw an exception. */ private Object lookup(String key, Class type) throws SAXException { - Object value = null; + Object value; if (_handler != null) { if ((value = _handler.lookup(key)) != null) { return checkCast(value, type); @@ -423,15 +424,12 @@ class SynthParser extends HandlerBase { private void endStyle() throws SAXException { int size = _stylePainters.size(); if (size > 0) { - _style.setPainters((ParsedSynthStyle.PainterInfo[]) - _stylePainters.toArray(new ParsedSynthStyle. - PainterInfo[size])); + _style.setPainters(_stylePainters.toArray(new ParsedSynthStyle.PainterInfo[size])); _stylePainters.clear(); } size = _stateInfos.size(); if (size > 0) { - _style.setStateInfo((ParsedSynthStyle.StateInfo[])_stateInfos. - toArray(new ParsedSynthStyle.StateInfo[size])); + _style.setStateInfo(_stateInfos.toArray(new ParsedSynthStyle.StateInfo[size])); _stateInfos.clear(); } _style = null; @@ -501,9 +499,7 @@ class SynthParser extends HandlerBase { private void endState() throws SAXException { int size = _statePainters.size(); if (size > 0) { - _stateInfo.setPainters((ParsedSynthStyle.PainterInfo[]) - _statePainters.toArray(new ParsedSynthStyle. - PainterInfo[size])); + _stateInfo.setPainters(_statePainters.toArray(new ParsedSynthStyle.PainterInfo[size])); _statePainters.clear(); } _stateInfo = null; @@ -684,8 +680,7 @@ class SynthParser extends HandlerBase { int max = 0; for (int counter = _colorTypes.size() - 1; counter >= 0; counter--) { - max = Math.max(max, ((ColorType)_colorTypes.get(counter)). - getID()); + max = Math.max(max, _colorTypes.get(counter).getID()); } if (colors == null || colors.length <= max) { Color[] newColors = new Color[max + 1]; @@ -696,7 +691,7 @@ class SynthParser extends HandlerBase { } for (int counter = _colorTypes.size() - 1; counter >= 0; counter--) { - colors[((ColorType)_colorTypes.get(counter)).getID()] = color; + colors[_colorTypes.get(counter).getID()] = color; } _stateInfo.setColors(colors); } @@ -705,7 +700,7 @@ class SynthParser extends HandlerBase { private void startProperty(AttributeList attributes, Object property) throws SAXException { Object value = null; - Object key = null; + String key = null; // Type of the value: 0=idref, 1=boolean, 2=dimension, 3=insets, // 4=integer,5=string int iType = 0; @@ -1027,7 +1022,7 @@ class SynthParser extends HandlerBase { } } - private void addPainterOrMerge(java.util.List painters, String method, + private void addPainterOrMerge(List painters, String method, SynthPainter painter, int direction) { ParsedSynthStyle.PainterInfo painterInfo; painterInfo = new ParsedSynthStyle.PainterInfo(method, diff --git a/src/share/classes/javax/swing/plaf/synth/SynthSplitPaneUI.java b/src/share/classes/javax/swing/plaf/synth/SynthSplitPaneUI.java index ddbc7ae7e..21466d960 100644 --- a/src/share/classes/javax/swing/plaf/synth/SynthSplitPaneUI.java +++ b/src/share/classes/javax/swing/plaf/synth/SynthSplitPaneUI.java @@ -48,13 +48,13 @@ class SynthSplitPaneUI extends BasicSplitPaneUI implements * Keys to use for forward focus traversal when the JComponent is * managing focus. */ - private static Set managingFocusForwardTraversalKeys; + private static Set managingFocusForwardTraversalKeys; /** * Keys to use for backward focus traversal when the JComponent is * managing focus. */ - private static Set managingFocusBackwardTraversalKeys; + private static Set managingFocusBackwardTraversalKeys; /** * Style for the JSplitPane. @@ -96,7 +96,7 @@ class SynthSplitPaneUI extends BasicSplitPaneUI implements // focus forward traversal key if (managingFocusForwardTraversalKeys==null) { - managingFocusForwardTraversalKeys = new HashSet(); + managingFocusForwardTraversalKeys = new HashSet(); managingFocusForwardTraversalKeys.add( KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0)); } @@ -104,7 +104,7 @@ class SynthSplitPaneUI extends BasicSplitPaneUI implements managingFocusForwardTraversalKeys); // focus backward traversal key if (managingFocusBackwardTraversalKeys==null) { - managingFocusBackwardTraversalKeys = new HashSet(); + managingFocusBackwardTraversalKeys = new HashSet(); managingFocusBackwardTraversalKeys.add( KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK)); } diff --git a/src/share/classes/javax/swing/plaf/synth/SynthStyle.java b/src/share/classes/javax/swing/plaf/synth/SynthStyle.java index c9475f91b..ab9e42b41 100644 --- a/src/share/classes/javax/swing/plaf/synth/SynthStyle.java +++ b/src/share/classes/javax/swing/plaf/synth/SynthStyle.java @@ -53,7 +53,7 @@ public abstract class SynthStyle { /** * Contains the default values for certain properties. */ - private static Map DEFAULT_VALUES; + private static Map DEFAULT_VALUES; /** * Shared SynthGraphics. @@ -715,7 +715,7 @@ public abstract class SynthStyle { private static Object getDefaultValue(Object key) { synchronized(SynthStyle.class) { if (DEFAULT_VALUES == null) { - DEFAULT_VALUES = new HashMap(); + DEFAULT_VALUES = new HashMap(); populateDefaultValues(); } Object value = DEFAULT_VALUES.get(key); diff --git a/src/share/classes/javax/swing/plaf/synth/SynthTextAreaUI.java b/src/share/classes/javax/swing/plaf/synth/SynthTextAreaUI.java index f52d3a68b..d07c4d5ad 100644 --- a/src/share/classes/javax/swing/plaf/synth/SynthTextAreaUI.java +++ b/src/share/classes/javax/swing/plaf/synth/SynthTextAreaUI.java @@ -66,7 +66,7 @@ class SynthTextAreaUI extends BasicTextAreaUI implements SynthUI { protected void installDefaults() { // Installs the text cursor on the component super.installDefaults(); - updateStyle((JTextComponent)getComponent()); + updateStyle(getComponent()); } protected void uninstallDefaults() { diff --git a/src/share/classes/javax/swing/plaf/synth/SynthTextFieldUI.java b/src/share/classes/javax/swing/plaf/synth/SynthTextFieldUI.java index 5b7cbd0a5..28bbdf843 100644 --- a/src/share/classes/javax/swing/plaf/synth/SynthTextFieldUI.java +++ b/src/share/classes/javax/swing/plaf/synth/SynthTextFieldUI.java @@ -232,7 +232,7 @@ class SynthTextFieldUI protected void installDefaults() { // Installs the text cursor on the component super.installDefaults(); - updateStyle((JTextComponent)getComponent()); + updateStyle(getComponent()); getComponent().addFocusListener(this); } diff --git a/src/share/classes/javax/swing/plaf/synth/SynthTreeUI.java b/src/share/classes/javax/swing/plaf/synth/SynthTreeUI.java index 1e12a820e..464b947b0 100644 --- a/src/share/classes/javax/swing/plaf/synth/SynthTreeUI.java +++ b/src/share/classes/javax/swing/plaf/synth/SynthTreeUI.java @@ -390,7 +390,7 @@ class SynthTreeUI extends BasicTreeUI implements PropertyChangeListener, } private Rectangle getDropLineRect(JTree.DropLocation loc) { - Rectangle rect = null; + Rectangle rect; TreePath path = loc.getPath(); int index = loc.getChildIndex(); boolean ltr = tree.getComponentOrientation().isLeftToRight(); @@ -523,7 +523,7 @@ class SynthTreeUI extends BasicTreeUI implements PropertyChangeListener, // Don't paint the renderer if editing this row. boolean selected = tree.isRowSelected(row); - JTree.DropLocation dropLocation = (JTree.DropLocation)tree.getDropLocation(); + JTree.DropLocation dropLocation = tree.getDropLocation(); boolean isDrop = dropLocation != null && dropLocation.getChildIndex() == -1 && path == dropLocation.getPath(); diff --git a/src/share/classes/sun/swing/plaf/synth/DefaultSynthStyle.java b/src/share/classes/sun/swing/plaf/synth/DefaultSynthStyle.java index de209df68..f66692e57 100644 --- a/src/share/classes/sun/swing/plaf/synth/DefaultSynthStyle.java +++ b/src/share/classes/sun/swing/plaf/synth/DefaultSynthStyle.java @@ -44,7 +44,7 @@ import javax.swing.plaf.*; * @author Scott Violet */ public class DefaultSynthStyle extends SynthStyle implements Cloneable { - private static final Object PENDING = new String("Pending"); + private static final String PENDING = "Pending"; /** * Should the component be opaque? @@ -690,8 +690,8 @@ public class DefaultSynthStyle extends SynthStyle implements Cloneable { StateInfo[] states = getStateInfo(); if (states != null) { buf.append("states["); - for (int i = 0; i < states.length; i++) { - buf.append(states[i].toString()).append(','); + for (StateInfo state : states) { + buf.append(state.toString()).append(','); } buf.append(']').append(','); } @@ -888,7 +888,7 @@ public class DefaultSynthStyle extends SynthStyle implements Cloneable { * Returns the number of states that are similar between the * ComponentState this StateInfo represents and val. */ - private final int getMatchCount(int val) { + private int getMatchCount(int val) { // This comes from BigInteger.bitCnt val &= state; val -= (0xaaaaaaaa & val) >>> 1; diff --git a/src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java b/src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java index abd99439e..2721764d1 100644 --- a/src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java +++ b/src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java @@ -735,7 +735,7 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI { * Data model for a type-face selection combo-box. */ protected class DirectoryComboBoxModel extends AbstractListModel implements ComboBoxModel { - Vector directories = new Vector(); + Vector directories = new Vector(); int[] depths = null; File selectedDirectory = null; JFileChooser chooser = getFileChooser(); @@ -778,7 +778,7 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI { // Get the canonical (full) path. This has the side // benefit of removing extraneous chars from the path, // for example /foo/bar/ becomes /foo/bar - File canonical = null; + File canonical; try { canonical = directory.getCanonicalFile(); } catch (IOException e) { @@ -791,7 +791,7 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI { File sf = useShellFolder ? ShellFolder.getShellFolder(canonical) : canonical; File f = sf; - Vector path = new Vector(10); + Vector path = new Vector(10); do { path.addElement(f); } while ((f = f.getParentFile()) != null); @@ -799,7 +799,7 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI { int pathCount = path.size(); // Insert chain at appropriate place in vector for (int i = 0; i < pathCount; i++) { - f = (File)path.get(i); + f = path.get(i); if (directories.contains(f)) { int topIndex = directories.indexOf(f); for (int j = i-1; j >= 0; j--) { @@ -818,12 +818,12 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI { private void calculateDepths() { depths = new int[directories.size()]; for (int i = 0; i < depths.length; i++) { - File dir = (File)directories.get(i); + File dir = directories.get(i); File parent = dir.getParentFile(); depths[i] = 0; if (parent != null) { for (int j = i-1; j >= 0; j--) { - if (parent.equals((File)directories.get(j))) { + if (parent.equals(directories.get(j))) { depths[i] = depths[j] + 1; break; } @@ -940,8 +940,8 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI { FileFilter currentFilter = getFileChooser().getFileFilter(); boolean found = false; if(currentFilter != null) { - for(int i=0; i < filters.length; i++) { - if(filters[i] == currentFilter) { + for (FileFilter filter : filters) { + if (filter == currentFilter) { found = true; } } -- GitLab