提交 62cf36ae 编写于 作者: R rupashka

6776095: Code improvement and warnings removing from swing packages

Reviewed-by: malenkov
Contributed-by: NFlorian Brunner <fbrunnerlist@gmx.ch>
上级 8325c78b
...@@ -263,13 +263,13 @@ class GTKFileChooserUI extends SynthFileChooserUI { ...@@ -263,13 +263,13 @@ class GTKFileChooserUI extends SynthFileChooserUI {
ListSelectionModel sm = directoryList.getSelectionModel(); ListSelectionModel sm = directoryList.getSelectionModel();
if (sm instanceof DefaultListSelectionModel) { if (sm instanceof DefaultListSelectionModel) {
((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0); ((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0);
((DefaultListSelectionModel)sm).setAnchorSelectionIndex(0); sm.setAnchorSelectionIndex(0);
} }
fileList.clearSelection(); fileList.clearSelection();
sm = fileList.getSelectionModel(); sm = fileList.getSelectionModel();
if (sm instanceof DefaultListSelectionModel) { if (sm instanceof DefaultListSelectionModel) {
((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0); ((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0);
((DefaultListSelectionModel)sm).setAnchorSelectionIndex(0); sm.setAnchorSelectionIndex(0);
} }
File currentDirectory = getFileChooser().getCurrentDirectory(); File currentDirectory = getFileChooser().getCurrentDirectory();
...@@ -1073,7 +1073,7 @@ class GTKFileChooserUI extends SynthFileChooserUI { ...@@ -1073,7 +1073,7 @@ class GTKFileChooserUI extends SynthFileChooserUI {
* Data model for a type-face selection combo-box. * Data model for a type-face selection combo-box.
*/ */
protected class DirectoryComboBoxModel extends AbstractListModel implements ComboBoxModel { protected class DirectoryComboBoxModel extends AbstractListModel implements ComboBoxModel {
Vector directories = new Vector(); Vector<File> directories = new Vector<File>();
File selectedDirectory = null; File selectedDirectory = null;
JFileChooser chooser = getFileChooser(); JFileChooser chooser = getFileChooser();
FileSystemView fsv = chooser.getFileSystemView(); FileSystemView fsv = chooser.getFileSystemView();
...@@ -1215,7 +1215,7 @@ class GTKFileChooserUI extends SynthFileChooserUI { ...@@ -1215,7 +1215,7 @@ class GTKFileChooserUI extends SynthFileChooserUI {
ListSelectionModel sm = fileList.getSelectionModel(); ListSelectionModel sm = fileList.getSelectionModel();
if (sm instanceof DefaultListSelectionModel) { if (sm instanceof DefaultListSelectionModel) {
((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0); ((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0);
((DefaultListSelectionModel)sm).setAnchorSelectionIndex(0); sm.setAnchorSelectionIndex(0);
} }
rescanCurrentDirectory(getFileChooser()); rescanCurrentDirectory(getFileChooser());
return; return;
......
...@@ -1470,7 +1470,7 @@ public class GTKLookAndFeel extends SynthLookAndFeel { ...@@ -1470,7 +1470,7 @@ public class GTKLookAndFeel extends SynthLookAndFeel {
aaTextInfo = SwingUtilities2.AATextInfo.getAATextInfo(gtkAAFontSettingsCond); aaTextInfo = SwingUtilities2.AATextInfo.getAATextInfo(gtkAAFontSettingsCond);
} }
static ReferenceQueue queue = new ReferenceQueue(); static ReferenceQueue<GTKLookAndFeel> queue = new ReferenceQueue<GTKLookAndFeel>();
private static void flushUnreferenced() { private static void flushUnreferenced() {
WeakPCL pcl; WeakPCL pcl;
...@@ -1480,12 +1480,12 @@ public class GTKLookAndFeel extends SynthLookAndFeel { ...@@ -1480,12 +1480,12 @@ public class GTKLookAndFeel extends SynthLookAndFeel {
} }
} }
static class WeakPCL extends WeakReference implements static class WeakPCL extends WeakReference<GTKLookAndFeel> implements
PropertyChangeListener { PropertyChangeListener {
private Toolkit kit; private Toolkit kit;
private String key; private String key;
WeakPCL(Object target, Toolkit kit, String key) { WeakPCL(GTKLookAndFeel target, Toolkit kit, String key) {
super(target, queue); super(target, queue);
this.kit = kit; this.kit = kit;
this.key = key; this.key = key;
...@@ -1494,7 +1494,7 @@ public class GTKLookAndFeel extends SynthLookAndFeel { ...@@ -1494,7 +1494,7 @@ public class GTKLookAndFeel extends SynthLookAndFeel {
public String getKey() { return key; } public String getKey() { return key; }
public void propertyChange(final PropertyChangeEvent pce) { public void propertyChange(final PropertyChangeEvent pce) {
final GTKLookAndFeel lnf = (GTKLookAndFeel)get(); final GTKLookAndFeel lnf = get();
if (lnf == null || UIManager.getLookAndFeel() != lnf) { if (lnf == null || UIManager.getLookAndFeel() != lnf) {
// The property was GC'ed, we're no longer interested in // The property was GC'ed, we're no longer interested in
......
...@@ -86,7 +86,7 @@ public class ImageIcon implements Icon, Serializable, Accessible { ...@@ -86,7 +86,7 @@ public class ImageIcon implements Icon, Serializable, Accessible {
static { static {
component = new Component() {}; component = new Component() {};
AccessController.doPrivileged(new PrivilegedAction() { AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() { public Object run() {
try { try {
// 6482575 - clear the appContext field so as not to leak it // 6482575 - clear the appContext field so as not to leak it
......
...@@ -78,7 +78,7 @@ import javax.swing.text.*; ...@@ -78,7 +78,7 @@ import javax.swing.text.*;
* @author James Gosling * @author James Gosling
* @author Lynn Monsanto (accessibility) * @author Lynn Monsanto (accessibility)
*/ */
public class ProgressMonitor extends Object implements Accessible public class ProgressMonitor implements Accessible
{ {
private ProgressMonitor root; private ProgressMonitor root;
private JDialog dialog; private JDialog dialog;
...@@ -186,7 +186,7 @@ public class ProgressMonitor extends Object implements Accessible ...@@ -186,7 +186,7 @@ public class ProgressMonitor extends Object implements Accessible
} }
if (window instanceof SwingUtilities.SharedOwnerFrame) { if (window instanceof SwingUtilities.SharedOwnerFrame) {
WindowListener ownerShutdownListener = WindowListener ownerShutdownListener =
(WindowListener)SwingUtilities.getSharedOwnerFrameShutdownListener(); SwingUtilities.getSharedOwnerFrameShutdownListener();
dialog.addWindowListener(ownerShutdownListener); dialog.addWindowListener(ownerShutdownListener);
} }
Container contentPane = dialog.getContentPane(); Container contentPane = dialog.getContentPane();
...@@ -273,7 +273,7 @@ public class ProgressMonitor extends Object implements Accessible ...@@ -273,7 +273,7 @@ public class ProgressMonitor extends Object implements Accessible
if (dT >= millisToDecideToPopup) { if (dT >= millisToDecideToPopup) {
int predictedCompletionTime; int predictedCompletionTime;
if (nv > min) { if (nv > min) {
predictedCompletionTime = (int)((long)dT * predictedCompletionTime = (int)(dT *
(max - min) / (max - min) /
(nv - min)); (nv - min));
} }
...@@ -691,10 +691,7 @@ public class ProgressMonitor extends Object implements Accessible ...@@ -691,10 +691,7 @@ public class ProgressMonitor extends Object implements Accessible
* object does not have an Accessible parent * object does not have an Accessible parent
*/ */
public Accessible getAccessibleParent() { public Accessible getAccessibleParent() {
if (dialog != null) { return dialog;
return (Accessible)dialog;
}
return null;
} }
/* /*
...@@ -768,7 +765,7 @@ public class ProgressMonitor extends Object implements Accessible ...@@ -768,7 +765,7 @@ public class ProgressMonitor extends Object implements Accessible
if (myBar != null) { if (myBar != null) {
Component c = myBar.getParent(); Component c = myBar.getParent();
if (c instanceof Accessible) { if (c instanceof Accessible) {
return ((Accessible)c).getAccessibleContext(); return c.getAccessibleContext();
} }
} }
return null; return null;
......
...@@ -282,7 +282,7 @@ public abstract class SwingWorker<T, V> implements RunnableFuture<T> { ...@@ -282,7 +282,7 @@ public abstract class SwingWorker<T, V> implements RunnableFuture<T> {
* is finished. * is finished.
*/ */
DONE DONE
}; }
/** /**
* Constructs this {@code SwingWorker}. * Constructs this {@code SwingWorker}.
...@@ -825,7 +825,7 @@ public abstract class SwingWorker<T, V> implements RunnableFuture<T> { ...@@ -825,7 +825,7 @@ public abstract class SwingWorker<T, V> implements RunnableFuture<T> {
} }
private static class DoSubmitAccumulativeRunnable private static class DoSubmitAccumulativeRunnable
extends AccumulativeRunnable<Runnable> implements ActionListener { extends AccumulativeRunnable<Runnable> implements ActionListener {
private final static int DELAY = (int) (1000 / 30); private final static int DELAY = 1000 / 30;
@Override @Override
protected void run(List<Runnable> args) { protected void run(List<Runnable> args) {
for (Runnable runnable : args) { for (Runnable runnable : args) {
......
...@@ -128,8 +128,7 @@ public class DefaultColorSelectionModel implements ColorSelectionModel, Serializ ...@@ -128,8 +128,7 @@ public class DefaultColorSelectionModel implements ColorSelectionModel, Serializ
* @since 1.4 * @since 1.4
*/ */
public ChangeListener[] getChangeListeners() { public ChangeListener[] getChangeListeners() {
return (ChangeListener[])listenerList.getListeners( return listenerList.getListeners(ChangeListener.class);
ChangeListener.class);
} }
/** /**
......
...@@ -190,7 +190,7 @@ public class DefaultTableColumnModel implements TableColumnModel, ...@@ -190,7 +190,7 @@ public class DefaultTableColumnModel implements TableColumnModel,
fireColumnMoved(new TableColumnModelEvent(this, columnIndex, newIndex)); fireColumnMoved(new TableColumnModelEvent(this, columnIndex, newIndex));
return; return;
} }
aColumn = (TableColumn)tableColumns.elementAt(columnIndex); aColumn = tableColumns.elementAt(columnIndex);
tableColumns.removeElementAt(columnIndex); tableColumns.removeElementAt(columnIndex);
boolean selected = selectionModel.isSelectedIndex(columnIndex); boolean selected = selectionModel.isSelectedIndex(columnIndex);
...@@ -291,7 +291,7 @@ public class DefaultTableColumnModel implements TableColumnModel, ...@@ -291,7 +291,7 @@ public class DefaultTableColumnModel implements TableColumnModel,
* at <code>columnIndex</code> * at <code>columnIndex</code>
*/ */
public TableColumn getColumn(int columnIndex) { public TableColumn getColumn(int columnIndex) {
return (TableColumn)tableColumns.elementAt(columnIndex); return tableColumns.elementAt(columnIndex);
} }
/** /**
...@@ -504,8 +504,7 @@ public class DefaultTableColumnModel implements TableColumnModel, ...@@ -504,8 +504,7 @@ public class DefaultTableColumnModel implements TableColumnModel,
* @since 1.4 * @since 1.4
*/ */
public TableColumnModelListener[] getColumnModelListeners() { public TableColumnModelListener[] getColumnModelListeners() {
return (TableColumnModelListener[])listenerList.getListeners( return listenerList.getListeners(TableColumnModelListener.class);
TableColumnModelListener.class);
} }
// //
......
...@@ -84,7 +84,7 @@ import java.util.*; ...@@ -84,7 +84,7 @@ import java.util.*;
* *
* @author Rob Davis * @author Rob Davis
*/ */
public class DefaultMutableTreeNode extends Object implements Cloneable, public class DefaultMutableTreeNode implements Cloneable,
MutableTreeNode, Serializable MutableTreeNode, Serializable
{ {
private static final long serialVersionUID = -4298474751201349152L; private static final long serialVersionUID = -4298474751201349152L;
...@@ -1251,7 +1251,7 @@ public class DefaultMutableTreeNode extends Object implements Cloneable, ...@@ -1251,7 +1251,7 @@ public class DefaultMutableTreeNode extends Object implements Cloneable,
* @return a copy of this node * @return a copy of this node
*/ */
public Object clone() { public Object clone() {
DefaultMutableTreeNode newNode = null; DefaultMutableTreeNode newNode;
try { try {
newNode = (DefaultMutableTreeNode)super.clone(); newNode = (DefaultMutableTreeNode)super.clone();
...@@ -1297,24 +1297,22 @@ public class DefaultMutableTreeNode extends Object implements Cloneable, ...@@ -1297,24 +1297,22 @@ public class DefaultMutableTreeNode extends Object implements Cloneable,
userObject = tValues[1]; userObject = tValues[1];
} }
final class PreorderEnumeration implements Enumeration<TreeNode> { private final class PreorderEnumeration implements Enumeration<TreeNode> {
protected Stack stack; private final Stack<Enumeration> stack = new Stack<Enumeration>();
public PreorderEnumeration(TreeNode rootNode) { public PreorderEnumeration(TreeNode rootNode) {
super(); super();
Vector v = new Vector(1); Vector<TreeNode> v = new Vector<TreeNode>(1);
v.addElement(rootNode); // PENDING: don't really need a vector v.addElement(rootNode); // PENDING: don't really need a vector
stack = new Stack();
stack.push(v.elements()); stack.push(v.elements());
} }
public boolean hasMoreElements() { public boolean hasMoreElements() {
return (!stack.empty() && return (!stack.empty() && stack.peek().hasMoreElements());
((Enumeration)stack.peek()).hasMoreElements());
} }
public TreeNode nextElement() { public TreeNode nextElement() {
Enumeration enumer = (Enumeration)stack.peek(); Enumeration enumer = stack.peek();
TreeNode node = (TreeNode)enumer.nextElement(); TreeNode node = (TreeNode)enumer.nextElement();
Enumeration children = node.children(); Enumeration children = node.children();
...@@ -1353,8 +1351,7 @@ public class DefaultMutableTreeNode extends Object implements Cloneable, ...@@ -1353,8 +1351,7 @@ public class DefaultMutableTreeNode extends Object implements Cloneable,
if (subtree.hasMoreElements()) { if (subtree.hasMoreElements()) {
retval = subtree.nextElement(); retval = subtree.nextElement();
} else if (children.hasMoreElements()) { } else if (children.hasMoreElements()) {
subtree = new PostorderEnumeration( subtree = new PostorderEnumeration(children.nextElement());
(TreeNode)children.nextElement());
retval = subtree.nextElement(); retval = subtree.nextElement();
} else { } else {
retval = root; retval = root;
...@@ -1373,7 +1370,7 @@ public class DefaultMutableTreeNode extends Object implements Cloneable, ...@@ -1373,7 +1370,7 @@ public class DefaultMutableTreeNode extends Object implements Cloneable,
public BreadthFirstEnumeration(TreeNode rootNode) { public BreadthFirstEnumeration(TreeNode rootNode) {
super(); super();
Vector v = new Vector(1); Vector<TreeNode> v = new Vector<TreeNode>(1);
v.addElement(rootNode); // PENDING: don't really need a vector v.addElement(rootNode); // PENDING: don't really need a vector
queue = new Queue(); queue = new Queue();
queue.enqueue(v.elements()); queue.enqueue(v.elements());
......
...@@ -59,7 +59,7 @@ public class CompoundEdit extends AbstractUndoableEdit { ...@@ -59,7 +59,7 @@ public class CompoundEdit extends AbstractUndoableEdit {
super.undo(); super.undo();
int i = edits.size(); int i = edits.size();
while (i-- > 0) { while (i-- > 0) {
UndoableEdit e = (UndoableEdit)edits.elementAt(i); UndoableEdit e = edits.elementAt(i);
e.undo(); e.undo();
} }
} }
...@@ -85,7 +85,7 @@ public class CompoundEdit extends AbstractUndoableEdit { ...@@ -85,7 +85,7 @@ public class CompoundEdit extends AbstractUndoableEdit {
protected UndoableEdit lastEdit() { protected UndoableEdit lastEdit() {
int count = edits.size(); int count = edits.size();
if (count > 0) if (count > 0)
return (UndoableEdit)edits.elementAt(count-1); return edits.elementAt(count-1);
else else
return null; return null;
} }
...@@ -98,7 +98,7 @@ public class CompoundEdit extends AbstractUndoableEdit { ...@@ -98,7 +98,7 @@ public class CompoundEdit extends AbstractUndoableEdit {
int size = edits.size(); int size = edits.size();
for (int i = size-1; i >= 0; i--) 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 " + // System.out.println("CompoundEdit(" + i + "): Discarding " +
// e.getUndoPresentationName()); // e.getUndoPresentationName());
e.die(); e.die();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册