8054360: Refine generification of javax.swing

Reviewed-by: anthony, alexsch, dlsmith
This commit is contained in:
Joe Darcy 2014-08-15 11:33:13 -07:00
parent 03c06e7441
commit 646c399fa2
8 changed files with 56 additions and 42 deletions

View File

@ -138,7 +138,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible {
/** /**
* {@code Dictionary} of what labels to draw at which values * {@code Dictionary} of what labels to draw at which values
*/ */
private Dictionary<Integer, JComponent> labelTable; private Dictionary<Integer, ? extends JComponent> labelTable;
/** /**
@ -773,7 +773,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible {
} }
// Check that there is a label with such image // Check that there is a label with such image
Enumeration<JComponent> elements = labelTable.elements(); Enumeration<? extends JComponent> elements = labelTable.elements();
while (elements.hasMoreElements()) { while (elements.hasMoreElements()) {
JComponent component = elements.nextElement(); JComponent component = elements.nextElement();
@ -797,7 +797,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible {
* @return the <code>Dictionary</code> containing labels and * @return the <code>Dictionary</code> containing labels and
* where to draw them * where to draw them
*/ */
public Dictionary<Integer, JComponent> getLabelTable() { public Dictionary<Integer, ? extends JComponent> getLabelTable() {
/* /*
if ( labelTable == null && getMajorTickSpacing() > 0 ) { if ( labelTable == null && getMajorTickSpacing() > 0 ) {
setLabelTable( createStandardLabels( getMajorTickSpacing() ) ); setLabelTable( createStandardLabels( getMajorTickSpacing() ) );
@ -830,8 +830,8 @@ public class JSlider extends JComponent implements SwingConstants, Accessible {
* attribute: visualUpdate true * attribute: visualUpdate true
* description: Specifies what labels will be drawn for any given value. * description: Specifies what labels will be drawn for any given value.
*/ */
public void setLabelTable( Dictionary<Integer, JComponent> labels ) { public void setLabelTable( Dictionary<Integer, ? extends JComponent> labels ) {
Dictionary<Integer, JComponent> oldTable = labelTable; Dictionary<Integer, ? extends JComponent> oldTable = labelTable;
labelTable = labels; labelTable = labels;
updateLabelUIs(); updateLabelUIs();
firePropertyChange("labelTable", oldTable, labelTable ); firePropertyChange("labelTable", oldTable, labelTable );
@ -852,7 +852,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible {
* @see JComponent#updateUI * @see JComponent#updateUI
*/ */
protected void updateLabelUIs() { protected void updateLabelUIs() {
Dictionary<Integer, JComponent> labelTable = getLabelTable(); Dictionary<Integer, ? extends JComponent> labelTable = getLabelTable();
if (labelTable == null) { if (labelTable == null) {
return; return;
@ -866,9 +866,9 @@ public class JSlider extends JComponent implements SwingConstants, Accessible {
} }
private void updateLabelSizes() { private void updateLabelSizes() {
Dictionary<Integer, JComponent> labelTable = getLabelTable(); Dictionary<Integer, ? extends JComponent> labelTable = getLabelTable();
if (labelTable != null) { if (labelTable != null) {
Enumeration<JComponent> labels = labelTable.elements(); Enumeration<? extends JComponent> labels = labelTable.elements();
while (labels.hasMoreElements()) { while (labels.hasMoreElements()) {
JComponent component = labels.nextElement(); JComponent component = labels.nextElement();
component.setSize(component.getPreferredSize()); component.setSize(component.getPreferredSize());
@ -1017,7 +1017,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible {
SmartHashtable table = new SmartHashtable( increment, start ); SmartHashtable table = new SmartHashtable( increment, start );
Dictionary<Integer, JComponent> labelTable = getLabelTable(); Dictionary<Integer, ? extends JComponent> labelTable = getLabelTable();
if (labelTable != null && (labelTable instanceof PropertyChangeListener)) { if (labelTable != null && (labelTable instanceof PropertyChangeListener)) {
removePropertyChangeListener((PropertyChangeListener) labelTable); removePropertyChangeListener((PropertyChangeListener) labelTable);

View File

@ -670,7 +670,8 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
* @param rowData the data for the new table * @param rowData the data for the new table
* @param columnNames names of each column * @param columnNames names of each column
*/ */
public JTable(Vector<Vector<Object>> rowData, Vector<Object> columnNames) { @SuppressWarnings("rawtypes")
public JTable(Vector<? extends Vector> rowData, Vector<?> columnNames) {
this(new DefaultTableModel(rowData, columnNames)); this(new DefaultTableModel(rowData, columnNames));
} }

View File

@ -397,10 +397,10 @@ public class BasicSliderUI extends SliderUI{
protected boolean labelsHaveSameBaselines() { protected boolean labelsHaveSameBaselines() {
if (!checkedLabelBaselines) { if (!checkedLabelBaselines) {
checkedLabelBaselines = true; checkedLabelBaselines = true;
Dictionary<?, JComponent> dictionary = slider.getLabelTable(); Dictionary<Integer, ? extends JComponent> dictionary = slider.getLabelTable();
if (dictionary != null) { if (dictionary != null) {
sameLabelBaselines = true; sameLabelBaselines = true;
Enumeration<JComponent> elements = dictionary.elements(); Enumeration<? extends JComponent> elements = dictionary.elements();
int baseline = -1; int baseline = -1;
while (elements.hasMoreElements()) { while (elements.hasMoreElements()) {
JComponent label = elements.nextElement(); JComponent label = elements.nextElement();
@ -758,7 +758,7 @@ public class BasicSliderUI extends SliderUI{
} }
protected int getWidthOfWidestLabel() { protected int getWidthOfWidestLabel() {
Dictionary<?, JComponent> dictionary = slider.getLabelTable(); Dictionary<?, ? extends JComponent> dictionary = slider.getLabelTable();
int widest = 0; int widest = 0;
if ( dictionary != null ) { if ( dictionary != null ) {
Enumeration<?> keys = dictionary.keys(); Enumeration<?> keys = dictionary.keys();
@ -771,7 +771,7 @@ public class BasicSliderUI extends SliderUI{
} }
protected int getHeightOfTallestLabel() { protected int getHeightOfTallestLabel() {
Dictionary<?, JComponent> dictionary = slider.getLabelTable(); Dictionary<?, ? extends JComponent> dictionary = slider.getLabelTable();
int tallest = 0; int tallest = 0;
if ( dictionary != null ) { if ( dictionary != null ) {
Enumeration<?> keys = dictionary.keys(); Enumeration<?> keys = dictionary.keys();
@ -876,7 +876,7 @@ public class BasicSliderUI extends SliderUI{
* @since 1.6 * @since 1.6
*/ */
protected Integer getLowestValue() { protected Integer getLowestValue() {
Dictionary<Integer, JComponent> dictionary = slider.getLabelTable(); Dictionary<Integer, ? extends JComponent> dictionary = slider.getLabelTable();
if (dictionary == null) { if (dictionary == null) {
return null; return null;
@ -1134,7 +1134,7 @@ public class BasicSliderUI extends SliderUI{
public void paintLabels( Graphics g ) { public void paintLabels( Graphics g ) {
Rectangle labelBounds = labelRect; Rectangle labelBounds = labelRect;
Dictionary<Integer, JComponent> dictionary = slider.getLabelTable(); Dictionary<Integer, ? extends JComponent> dictionary = slider.getLabelTable();
if ( dictionary != null ) { if ( dictionary != null ) {
Enumeration<Integer> keys = dictionary.keys(); Enumeration<Integer> keys = dictionary.keys();
int minValue = slider.getMinimum(); int minValue = slider.getMinimum();

View File

@ -392,7 +392,7 @@ public class SynthSliderUI extends BasicSliderUI
trackRect.x = insetCache.left; trackRect.x = insetCache.left;
trackRect.width = contentRect.width; trackRect.width = contentRect.width;
Dictionary<Integer, JComponent> dictionary = slider.getLabelTable(); Dictionary<Integer, ? extends JComponent> dictionary = slider.getLabelTable();
if (dictionary != null) { if (dictionary != null) {
int minValue = slider.getMinimum(); int minValue = slider.getMinimum();
int maxValue = slider.getMaximum(); int maxValue = slider.getMaximum();

View File

@ -70,10 +70,18 @@ public class DefaultTableModel extends AbstractTableModel implements Serializabl
* The <code>Vector</code> of <code>Vectors</code> of * The <code>Vector</code> of <code>Vectors</code> of
* <code>Object</code> values. * <code>Object</code> values.
*/ */
protected Vector<Vector<Object>> dataVector; @SuppressWarnings("rawtypes")
protected Vector<Vector> dataVector;
/** The <code>Vector</code> of column identifiers. */ /** The <code>Vector</code> of column identifiers. */
protected Vector<Object> columnIdentifiers; @SuppressWarnings("rawtypes")
protected Vector columnIdentifiers;
// Unfortunately, for greater source compatibility the inner-most
// Vector in the two fields above is being left raw. The Vector is
// read as well as written so using Vector<?> is not suitable and
// using Vector<Object> (without adding copying of input Vectors),
// would disallow existing code that used, say, a Vector<String>
// as an input parameter.
// //
// Constructors // Constructors
@ -121,7 +129,7 @@ public class DefaultTableModel extends AbstractTableModel implements Serializabl
* @see #setDataVector * @see #setDataVector
* @see #setValueAt * @see #setValueAt
*/ */
public DefaultTableModel(Vector<Object> columnNames, int rowCount) { public DefaultTableModel(Vector<?> columnNames, int rowCount) {
setDataVector(newVector(rowCount), columnNames); setDataVector(newVector(rowCount), columnNames);
} }
@ -156,7 +164,8 @@ public class DefaultTableModel extends AbstractTableModel implements Serializabl
* @see #getDataVector * @see #getDataVector
* @see #setDataVector * @see #setDataVector
*/ */
public DefaultTableModel(Vector<Vector<Object>> data, Vector<Object> columnNames) { @SuppressWarnings("rawtypes")
public DefaultTableModel(Vector<? extends Vector> data, Vector<?> columnNames) {
setDataVector(data, columnNames); setDataVector(data, columnNames);
} }
@ -191,7 +200,8 @@ public class DefaultTableModel extends AbstractTableModel implements Serializabl
* @see #newRowsAdded * @see #newRowsAdded
* @see #setDataVector * @see #setDataVector
*/ */
public Vector<Vector<Object>> getDataVector() { @SuppressWarnings("rawtypes")
public Vector<Vector> getDataVector() {
return dataVector; return dataVector;
} }
@ -219,9 +229,10 @@ public class DefaultTableModel extends AbstractTableModel implements Serializabl
* @param columnIdentifiers the names of the columns * @param columnIdentifiers the names of the columns
* @see #getDataVector * @see #getDataVector
*/ */
public void setDataVector(Vector<Vector<Object>> dataVector, @SuppressWarnings({"rawtypes", "unchecked"})
Vector<Object> columnIdentifiers) { public void setDataVector(Vector<? extends Vector> dataVector,
this.dataVector = nonNullVector(dataVector); Vector<?> columnIdentifiers) {
this.dataVector = nonNullVector((Vector<Vector>)dataVector);
this.columnIdentifiers = nonNullVector(columnIdentifiers); this.columnIdentifiers = nonNullVector(columnIdentifiers);
justifyRows(0, getRowCount()); justifyRows(0, getRowCount());
fireTableStructureChanged(); fireTableStructureChanged();
@ -267,7 +278,7 @@ public class DefaultTableModel extends AbstractTableModel implements Serializabl
if (dataVector.elementAt(i) == null) { if (dataVector.elementAt(i) == null) {
dataVector.setElementAt(new Vector<>(), i); dataVector.setElementAt(new Vector<>(), i);
} }
((Vector)dataVector.elementAt(i)).setSize(getColumnCount()); dataVector.elementAt(i).setSize(getColumnCount());
} }
} }
@ -350,7 +361,7 @@ public class DefaultTableModel extends AbstractTableModel implements Serializabl
* *
* @param rowData optional data of the row being added * @param rowData optional data of the row being added
*/ */
public void addRow(Vector<Object> rowData) { public void addRow(Vector<?> rowData) {
insertRow(getRowCount(), rowData); insertRow(getRowCount(), rowData);
} }
@ -374,7 +385,7 @@ public class DefaultTableModel extends AbstractTableModel implements Serializabl
* @param rowData optional data of the row being added * @param rowData optional data of the row being added
* @exception ArrayIndexOutOfBoundsException if the row was invalid * @exception ArrayIndexOutOfBoundsException if the row was invalid
*/ */
public void insertRow(int row, Vector<Object> rowData) { public void insertRow(int row, Vector<?> rowData) {
dataVector.insertElementAt(rowData, row); dataVector.insertElementAt(rowData, row);
justifyRows(row, row+1); justifyRows(row, row+1);
fireTableRowsInserted(row, row); fireTableRowsInserted(row, row);
@ -484,7 +495,7 @@ public class DefaultTableModel extends AbstractTableModel implements Serializabl
* to zero columns * to zero columns
* @see #setNumRows * @see #setNumRows
*/ */
public void setColumnIdentifiers(Vector<Object> columnIdentifiers) { public void setColumnIdentifiers(Vector<?> columnIdentifiers) {
setDataVector(dataVector, columnIdentifiers); setDataVector(dataVector, columnIdentifiers);
} }
@ -550,7 +561,8 @@ public class DefaultTableModel extends AbstractTableModel implements Serializabl
* @param columnName the identifier of the column being added * @param columnName the identifier of the column being added
* @param columnData optional data of the column being added * @param columnData optional data of the column being added
*/ */
public void addColumn(Object columnName, Vector<Object> columnData) { @SuppressWarnings("unchecked") // Adding element to raw columnIdentifiers
public void addColumn(Object columnName, Vector<?> columnData) {
columnIdentifiers.addElement(columnName); columnIdentifiers.addElement(columnName);
if (columnData != null) { if (columnData != null) {
int columnSize = columnData.size(); int columnSize = columnData.size();
@ -652,6 +664,7 @@ public class DefaultTableModel extends AbstractTableModel implements Serializabl
* column was given * column was given
*/ */
public Object getValueAt(int row, int column) { public Object getValueAt(int row, int column) {
@SuppressWarnings("unchecked")
Vector<Object> rowVector = dataVector.elementAt(row); Vector<Object> rowVector = dataVector.elementAt(row);
return rowVector.elementAt(column); return rowVector.elementAt(column);
} }
@ -668,6 +681,7 @@ public class DefaultTableModel extends AbstractTableModel implements Serializabl
* column was given * column was given
*/ */
public void setValueAt(Object aValue, int row, int column) { public void setValueAt(Object aValue, int row, int column) {
@SuppressWarnings("unchecked")
Vector<Object> rowVector = dataVector.elementAt(row); Vector<Object> rowVector = dataVector.elementAt(row);
rowVector.setElementAt(aValue, column); rowVector.setElementAt(aValue, column);
fireTableCellUpdated(row, column); fireTableCellUpdated(row, column);

View File

@ -1317,7 +1317,7 @@ public class DefaultMutableTreeNode implements Cloneable,
} }
private final class PreorderEnumeration implements Enumeration<TreeNode> { private final class PreorderEnumeration implements Enumeration<TreeNode> {
private final Stack<Enumeration<TreeNode>> stack = new Stack<>(); private final Stack<Enumeration<? extends TreeNode>> stack = new Stack<>();
public PreorderEnumeration(TreeNode rootNode) { public PreorderEnumeration(TreeNode rootNode) {
super(); super();
@ -1331,10 +1331,9 @@ public class DefaultMutableTreeNode implements Cloneable,
} }
public TreeNode nextElement() { public TreeNode nextElement() {
Enumeration<TreeNode> enumer = stack.peek(); Enumeration<? extends TreeNode> enumer = stack.peek();
TreeNode node = enumer.nextElement(); TreeNode node = enumer.nextElement();
@SuppressWarnings("unchecked") Enumeration<? extends TreeNode> children = node.children();
Enumeration<TreeNode> children = node.children();
if (!enumer.hasMoreElements()) { if (!enumer.hasMoreElements()) {
stack.pop(); stack.pop();
@ -1351,7 +1350,7 @@ public class DefaultMutableTreeNode implements Cloneable,
final class PostorderEnumeration implements Enumeration<TreeNode> { final class PostorderEnumeration implements Enumeration<TreeNode> {
protected TreeNode root; protected TreeNode root;
protected Enumeration<TreeNode> children; protected Enumeration<? extends TreeNode> children;
protected Enumeration<TreeNode> subtree; protected Enumeration<TreeNode> subtree;
public PostorderEnumeration(TreeNode rootNode) { public PostorderEnumeration(TreeNode rootNode) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -99,5 +99,5 @@ public interface TreeNode
* *
* @return the children of the receiver as an {@code Enumeration} * @return the children of the receiver as an {@code Enumeration}
*/ */
Enumeration<TreeNode> children(); Enumeration<? extends TreeNode> children();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -146,7 +146,7 @@ public class TableSorter extends DefaultTableModel implements MouseListener {
// update row heights in XMBeanAttributes (required by expandable cells) // update row heights in XMBeanAttributes (required by expandable cells)
if (attrs != null) { if (attrs != null) {
for (int i = 0; i < getRowCount(); i++) { for (int i = 0; i < getRowCount(); i++) {
Vector<?> data = (Vector) dataVector.elementAt(i); Vector<?> data = dataVector.elementAt(i);
attrs.updateRowHeight(data.elementAt(1), i); attrs.updateRowHeight(data.elementAt(1), i);
} }
} }
@ -217,17 +217,17 @@ public class TableSorter extends DefaultTableModel implements MouseListener {
} }
} }
private Vector<Object> getRow(int row) { private Vector<?> getRow(int row) {
return dataVector.elementAt(row); return dataVector.elementAt(row);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void setRow(Vector<Object> data, int row) { private void setRow(Vector<?> data, int row) {
dataVector.setElementAt(data,row); dataVector.setElementAt(data,row);
} }
private void swap(int i, int j, int column) { private void swap(int i, int j, int column) {
Vector<Object> data = getRow(i); Vector<?> data = getRow(i);
setRow(getRow(j),i); setRow(getRow(j),i);
setRow(data,j); setRow(data,j);