6776095: Code improvement and warnings removing from swing packages
Reviewed-by: malenkov
Contributed-by: Florian Brunner <fbrunnerlist@gmx.ch>
--- a/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKFileChooserUI.java Wed Nov 26 19:38:46 2008 +0300
+++ b/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKFileChooserUI.java Thu Nov 27 17:55:36 2008 +0300
@@ -263,13 +263,13 @@
ListSelectionModel sm = directoryList.getSelectionModel();
if (sm instanceof DefaultListSelectionModel) {
((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0);
- ((DefaultListSelectionModel)sm).setAnchorSelectionIndex(0);
+ sm.setAnchorSelectionIndex(0);
}
fileList.clearSelection();
sm = fileList.getSelectionModel();
if (sm instanceof DefaultListSelectionModel) {
((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0);
- ((DefaultListSelectionModel)sm).setAnchorSelectionIndex(0);
+ sm.setAnchorSelectionIndex(0);
}
File currentDirectory = getFileChooser().getCurrentDirectory();
@@ -1073,7 +1073,7 @@
* Data model for a type-face selection combo-box.
*/
protected class DirectoryComboBoxModel extends AbstractListModel implements ComboBoxModel {
- Vector directories = new Vector();
+ Vector<File> directories = new Vector<File>();
File selectedDirectory = null;
JFileChooser chooser = getFileChooser();
FileSystemView fsv = chooser.getFileSystemView();
@@ -1215,7 +1215,7 @@
ListSelectionModel sm = fileList.getSelectionModel();
if (sm instanceof DefaultListSelectionModel) {
((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0);
- ((DefaultListSelectionModel)sm).setAnchorSelectionIndex(0);
+ sm.setAnchorSelectionIndex(0);
}
rescanCurrentDirectory(getFileChooser());
return;
--- a/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKLookAndFeel.java Wed Nov 26 19:38:46 2008 +0300
+++ b/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKLookAndFeel.java Thu Nov 27 17:55:36 2008 +0300
@@ -1470,7 +1470,7 @@
aaTextInfo = SwingUtilities2.AATextInfo.getAATextInfo(gtkAAFontSettingsCond);
}
- static ReferenceQueue queue = new ReferenceQueue();
+ static ReferenceQueue<GTKLookAndFeel> queue = new ReferenceQueue<GTKLookAndFeel>();
private static void flushUnreferenced() {
WeakPCL pcl;
@@ -1480,12 +1480,12 @@
}
}
- static class WeakPCL extends WeakReference implements
+ static class WeakPCL extends WeakReference<GTKLookAndFeel> implements
PropertyChangeListener {
private Toolkit kit;
private String key;
- WeakPCL(Object target, Toolkit kit, String key) {
+ WeakPCL(GTKLookAndFeel target, Toolkit kit, String key) {
super(target, queue);
this.kit = kit;
this.key = key;
@@ -1494,7 +1494,7 @@
public String getKey() { return key; }
public void propertyChange(final PropertyChangeEvent pce) {
- final GTKLookAndFeel lnf = (GTKLookAndFeel)get();
+ final GTKLookAndFeel lnf = get();
if (lnf == null || UIManager.getLookAndFeel() != lnf) {
// The property was GC'ed, we're no longer interested in
--- a/jdk/src/share/classes/javax/swing/ImageIcon.java Wed Nov 26 19:38:46 2008 +0300
+++ b/jdk/src/share/classes/javax/swing/ImageIcon.java Thu Nov 27 17:55:36 2008 +0300
@@ -86,7 +86,7 @@
static {
component = new Component() {};
- AccessController.doPrivileged(new PrivilegedAction() {
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
try {
// 6482575 - clear the appContext field so as not to leak it
--- a/jdk/src/share/classes/javax/swing/ProgressMonitor.java Wed Nov 26 19:38:46 2008 +0300
+++ b/jdk/src/share/classes/javax/swing/ProgressMonitor.java Thu Nov 27 17:55:36 2008 +0300
@@ -78,7 +78,7 @@
* @author James Gosling
* @author Lynn Monsanto (accessibility)
*/
-public class ProgressMonitor extends Object implements Accessible
+public class ProgressMonitor implements Accessible
{
private ProgressMonitor root;
private JDialog dialog;
@@ -186,7 +186,7 @@
}
if (window instanceof SwingUtilities.SharedOwnerFrame) {
WindowListener ownerShutdownListener =
- (WindowListener)SwingUtilities.getSharedOwnerFrameShutdownListener();
+ SwingUtilities.getSharedOwnerFrameShutdownListener();
dialog.addWindowListener(ownerShutdownListener);
}
Container contentPane = dialog.getContentPane();
@@ -273,7 +273,7 @@
if (dT >= millisToDecideToPopup) {
int predictedCompletionTime;
if (nv > min) {
- predictedCompletionTime = (int)((long)dT *
+ predictedCompletionTime = (int)(dT *
(max - min) /
(nv - min));
}
@@ -691,10 +691,7 @@
* object does not have an Accessible parent
*/
public Accessible getAccessibleParent() {
- if (dialog != null) {
- return (Accessible)dialog;
- }
- return null;
+ return dialog;
}
/*
@@ -768,7 +765,7 @@
if (myBar != null) {
Component c = myBar.getParent();
if (c instanceof Accessible) {
- return ((Accessible)c).getAccessibleContext();
+ return c.getAccessibleContext();
}
}
return null;
--- a/jdk/src/share/classes/javax/swing/SwingWorker.java Wed Nov 26 19:38:46 2008 +0300
+++ b/jdk/src/share/classes/javax/swing/SwingWorker.java Thu Nov 27 17:55:36 2008 +0300
@@ -282,7 +282,7 @@
* is finished.
*/
DONE
- };
+ }
/**
* Constructs this {@code SwingWorker}.
@@ -825,7 +825,7 @@
}
private static class DoSubmitAccumulativeRunnable
extends AccumulativeRunnable<Runnable> implements ActionListener {
- private final static int DELAY = (int) (1000 / 30);
+ private final static int DELAY = 1000 / 30;
@Override
protected void run(List<Runnable> args) {
for (Runnable runnable : args) {
--- a/jdk/src/share/classes/javax/swing/colorchooser/DefaultColorSelectionModel.java Wed Nov 26 19:38:46 2008 +0300
+++ b/jdk/src/share/classes/javax/swing/colorchooser/DefaultColorSelectionModel.java Thu Nov 27 17:55:36 2008 +0300
@@ -128,8 +128,7 @@
* @since 1.4
*/
public ChangeListener[] getChangeListeners() {
- return (ChangeListener[])listenerList.getListeners(
- ChangeListener.class);
+ return listenerList.getListeners(ChangeListener.class);
}
/**
--- a/jdk/src/share/classes/javax/swing/table/DefaultTableColumnModel.java Wed Nov 26 19:38:46 2008 +0300
+++ b/jdk/src/share/classes/javax/swing/table/DefaultTableColumnModel.java Thu Nov 27 17:55:36 2008 +0300
@@ -190,7 +190,7 @@
fireColumnMoved(new TableColumnModelEvent(this, columnIndex, newIndex));
return;
}
- aColumn = (TableColumn)tableColumns.elementAt(columnIndex);
+ aColumn = tableColumns.elementAt(columnIndex);
tableColumns.removeElementAt(columnIndex);
boolean selected = selectionModel.isSelectedIndex(columnIndex);
@@ -291,7 +291,7 @@
* at <code>columnIndex</code>
*/
public TableColumn getColumn(int columnIndex) {
- return (TableColumn)tableColumns.elementAt(columnIndex);
+ return tableColumns.elementAt(columnIndex);
}
/**
@@ -504,8 +504,7 @@
* @since 1.4
*/
public TableColumnModelListener[] getColumnModelListeners() {
- return (TableColumnModelListener[])listenerList.getListeners(
- TableColumnModelListener.class);
+ return listenerList.getListeners(TableColumnModelListener.class);
}
//
--- a/jdk/src/share/classes/javax/swing/tree/DefaultMutableTreeNode.java Wed Nov 26 19:38:46 2008 +0300
+++ b/jdk/src/share/classes/javax/swing/tree/DefaultMutableTreeNode.java Thu Nov 27 17:55:36 2008 +0300
@@ -84,7 +84,7 @@
*
* @author Rob Davis
*/
-public class DefaultMutableTreeNode extends Object implements Cloneable,
+public class DefaultMutableTreeNode implements Cloneable,
MutableTreeNode, Serializable
{
private static final long serialVersionUID = -4298474751201349152L;
@@ -1251,7 +1251,7 @@
* @return a copy of this node
*/
public Object clone() {
- DefaultMutableTreeNode newNode = null;
+ DefaultMutableTreeNode newNode;
try {
newNode = (DefaultMutableTreeNode)super.clone();
@@ -1297,24 +1297,22 @@
userObject = tValues[1];
}
- final class PreorderEnumeration implements Enumeration<TreeNode> {
- protected Stack stack;
+ private final class PreorderEnumeration implements Enumeration<TreeNode> {
+ private final Stack<Enumeration> stack = new Stack<Enumeration>();
public PreorderEnumeration(TreeNode rootNode) {
super();
- Vector v = new Vector(1);
+ Vector<TreeNode> v = new Vector<TreeNode>(1);
v.addElement(rootNode); // PENDING: don't really need a vector
- stack = new Stack();
stack.push(v.elements());
}
public boolean hasMoreElements() {
- return (!stack.empty() &&
- ((Enumeration)stack.peek()).hasMoreElements());
+ return (!stack.empty() && stack.peek().hasMoreElements());
}
public TreeNode nextElement() {
- Enumeration enumer = (Enumeration)stack.peek();
+ Enumeration enumer = stack.peek();
TreeNode node = (TreeNode)enumer.nextElement();
Enumeration children = node.children();
@@ -1353,8 +1351,7 @@
if (subtree.hasMoreElements()) {
retval = subtree.nextElement();
} else if (children.hasMoreElements()) {
- subtree = new PostorderEnumeration(
- (TreeNode)children.nextElement());
+ subtree = new PostorderEnumeration(children.nextElement());
retval = subtree.nextElement();
} else {
retval = root;
@@ -1373,7 +1370,7 @@
public BreadthFirstEnumeration(TreeNode rootNode) {
super();
- Vector v = new Vector(1);
+ Vector<TreeNode> v = new Vector<TreeNode>(1);
v.addElement(rootNode); // PENDING: don't really need a vector
queue = new Queue();
queue.enqueue(v.elements());
--- a/jdk/src/share/classes/javax/swing/undo/CompoundEdit.java Wed Nov 26 19:38:46 2008 +0300
+++ b/jdk/src/share/classes/javax/swing/undo/CompoundEdit.java Thu Nov 27 17:55:36 2008 +0300
@@ -59,7 +59,7 @@
super.undo();
int i = edits.size();
while (i-- > 0) {
- UndoableEdit e = (UndoableEdit)edits.elementAt(i);
+ UndoableEdit e = edits.elementAt(i);
e.undo();
}
}
@@ -85,7 +85,7 @@
protected UndoableEdit lastEdit() {
int count = edits.size();
if (count > 0)
- return (UndoableEdit)edits.elementAt(count-1);
+ return edits.elementAt(count-1);
else
return null;
}
@@ -98,7 +98,7 @@
int size = edits.size();
for (int i = size-1; i >= 0; i--)
{
- UndoableEdit e = (UndoableEdit)edits.elementAt(i);
+ UndoableEdit e = edits.elementAt(i);
// System.out.println("CompoundEdit(" + i + "): Discarding " +
// e.getUndoPresentationName());
e.die();