8055254: Address source incompatability of JSlider generification
Reviewed-by: anthony, serb
--- a/jdk/src/share/classes/javax/swing/JSlider.java Fri Aug 15 11:33:13 2014 -0700
+++ b/jdk/src/share/classes/javax/swing/JSlider.java Mon Aug 18 09:51:52 2014 -0700
@@ -138,8 +138,11 @@
/**
* {@code Dictionary} of what labels to draw at which values
*/
- private Dictionary<Integer, ? extends JComponent> labelTable;
-
+ @SuppressWarnings("rawtypes")
+ private Dictionary labelTable;
+ // For better source compatibility, the labelTable field and
+ // associated getter and setter methods are being left as raw
+ // types.
/**
* The changeListener (no suffix) is the listener we add to the
@@ -773,10 +776,10 @@
}
// Check that there is a label with such image
- Enumeration<? extends JComponent> elements = labelTable.elements();
+ Enumeration<?> elements = labelTable.elements();
while (elements.hasMoreElements()) {
- JComponent component = elements.nextElement();
+ Component component = (Component) elements.nextElement();
if (component instanceof JLabel) {
JLabel label = (JLabel) component;
@@ -797,7 +800,8 @@
* @return the <code>Dictionary</code> containing labels and
* where to draw them
*/
- public Dictionary<Integer, ? extends JComponent> getLabelTable() {
+ @SuppressWarnings("rawtypes")
+ public Dictionary getLabelTable() {
/*
if ( labelTable == null && getMajorTickSpacing() > 0 ) {
setLabelTable( createStandardLabels( getMajorTickSpacing() ) );
@@ -830,8 +834,9 @@
* attribute: visualUpdate true
* description: Specifies what labels will be drawn for any given value.
*/
- public void setLabelTable( Dictionary<Integer, ? extends JComponent> labels ) {
- Dictionary<Integer, ? extends JComponent> oldTable = labelTable;
+ @SuppressWarnings("rawtypes")
+ public void setLabelTable( Dictionary labels ) {
+ Dictionary oldTable = labelTable;
labelTable = labels;
updateLabelUIs();
firePropertyChange("labelTable", oldTable, labelTable );
@@ -852,25 +857,27 @@
* @see JComponent#updateUI
*/
protected void updateLabelUIs() {
- Dictionary<Integer, ? extends JComponent> labelTable = getLabelTable();
+ @SuppressWarnings("rawtypes")
+ Dictionary labelTable = getLabelTable();
if (labelTable == null) {
return;
}
- Enumeration<Integer> labels = labelTable.keys();
+ Enumeration<?> labels = labelTable.keys();
while ( labels.hasMoreElements() ) {
- JComponent component = labelTable.get(labels.nextElement());
+ JComponent component = (JComponent) labelTable.get(labels.nextElement());
component.updateUI();
component.setSize(component.getPreferredSize());
}
}
private void updateLabelSizes() {
- Dictionary<Integer, ? extends JComponent> labelTable = getLabelTable();
+ @SuppressWarnings("rawtypes")
+ Dictionary labelTable = getLabelTable();
if (labelTable != null) {
- Enumeration<? extends JComponent> labels = labelTable.elements();
+ Enumeration<?> labels = labelTable.elements();
while (labels.hasMoreElements()) {
- JComponent component = labels.nextElement();
+ JComponent component = (JComponent) labels.nextElement();
component.setSize(component.getPreferredSize());
}
}
@@ -982,13 +989,13 @@
if ( e.getPropertyName().equals( "minimum" ) ||
e.getPropertyName().equals( "maximum" ) ) {
- Enumeration<Integer> keys = getLabelTable().keys();
+ Enumeration<?> keys = getLabelTable().keys();
Hashtable<Integer, JComponent> hashtable = new Hashtable<>();
// Save the labels that were added by the developer
while ( keys.hasMoreElements() ) {
- Integer key = keys.nextElement();
- JComponent value = labelTable.get(key);
+ Integer key = (Integer) keys.nextElement();
+ JComponent value = (JComponent) labelTable.get(key);
if ( !(value instanceof LabelUIResource) ) {
hashtable.put( key, value );
}
@@ -1000,7 +1007,7 @@
// Add the saved labels
keys = hashtable.keys();
while ( keys.hasMoreElements() ) {
- Integer key = keys.nextElement();
+ Integer key = (Integer) keys.nextElement();
put( key, hashtable.get( key ) );
}
@@ -1017,7 +1024,8 @@
SmartHashtable table = new SmartHashtable( increment, start );
- Dictionary<Integer, ? extends JComponent> labelTable = getLabelTable();
+ @SuppressWarnings("rawtypes")
+ Dictionary labelTable = getLabelTable();
if (labelTable != null && (labelTable instanceof PropertyChangeListener)) {
removePropertyChangeListener((PropertyChangeListener) labelTable);
--- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicSliderUI.java Fri Aug 15 11:33:13 2014 -0700
+++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicSliderUI.java Mon Aug 18 09:51:52 2014 -0700
@@ -397,13 +397,14 @@
protected boolean labelsHaveSameBaselines() {
if (!checkedLabelBaselines) {
checkedLabelBaselines = true;
- Dictionary<Integer, ? extends JComponent> dictionary = slider.getLabelTable();
+ @SuppressWarnings("rawtypes")
+ Dictionary dictionary = slider.getLabelTable();
if (dictionary != null) {
sameLabelBaselines = true;
- Enumeration<? extends JComponent> elements = dictionary.elements();
+ Enumeration<?> elements = dictionary.elements();
int baseline = -1;
while (elements.hasMoreElements()) {
- JComponent label = elements.nextElement();
+ JComponent label = (JComponent) elements.nextElement();
Dimension pref = label.getPreferredSize();
int labelBaseline = label.getBaseline(pref.width,
pref.height);
@@ -758,12 +759,13 @@
}
protected int getWidthOfWidestLabel() {
- Dictionary<?, ? extends JComponent> dictionary = slider.getLabelTable();
+ @SuppressWarnings("rawtypes")
+ Dictionary dictionary = slider.getLabelTable();
int widest = 0;
if ( dictionary != null ) {
Enumeration<?> keys = dictionary.keys();
while ( keys.hasMoreElements() ) {
- JComponent label = dictionary.get(keys.nextElement());
+ JComponent label = (JComponent) dictionary.get(keys.nextElement());
widest = Math.max( label.getPreferredSize().width, widest );
}
}
@@ -771,12 +773,13 @@
}
protected int getHeightOfTallestLabel() {
- Dictionary<?, ? extends JComponent> dictionary = slider.getLabelTable();
+ @SuppressWarnings("rawtypes")
+ Dictionary dictionary = slider.getLabelTable();
int tallest = 0;
if ( dictionary != null ) {
Enumeration<?> keys = dictionary.keys();
while ( keys.hasMoreElements() ) {
- JComponent label = dictionary.get(keys.nextElement());
+ JComponent label = (JComponent) dictionary.get(keys.nextElement());
tallest = Math.max( label.getPreferredSize().height, tallest );
}
}
@@ -847,18 +850,19 @@
* @since 1.6
*/
protected Integer getHighestValue() {
- Dictionary<Integer, ?> dictionary = slider.getLabelTable();
+ @SuppressWarnings("rawtypes")
+ Dictionary dictionary = slider.getLabelTable();
if (dictionary == null) {
return null;
}
- Enumeration<Integer> keys = dictionary.keys();
+ Enumeration<?> keys = dictionary.keys();
Integer max = null;
while (keys.hasMoreElements()) {
- Integer i = keys.nextElement();
+ Integer i = (Integer) keys.nextElement();
if (max == null || i > max) {
max = i;
@@ -876,18 +880,19 @@
* @since 1.6
*/
protected Integer getLowestValue() {
- Dictionary<Integer, ? extends JComponent> dictionary = slider.getLabelTable();
+ @SuppressWarnings("rawtypes")
+ Dictionary dictionary = slider.getLabelTable();
if (dictionary == null) {
return null;
}
- Enumeration<Integer> keys = dictionary.keys();
+ Enumeration<?> keys = dictionary.keys();
Integer min = null;
while (keys.hasMoreElements()) {
- Integer i = keys.nextElement();
+ Integer i = (Integer) keys.nextElement();
if (min == null || i < min) {
min = i;
@@ -1134,17 +1139,18 @@
public void paintLabels( Graphics g ) {
Rectangle labelBounds = labelRect;
- Dictionary<Integer, ? extends JComponent> dictionary = slider.getLabelTable();
+ @SuppressWarnings("rawtypes")
+ Dictionary dictionary = slider.getLabelTable();
if ( dictionary != null ) {
- Enumeration<Integer> keys = dictionary.keys();
+ Enumeration<?> keys = dictionary.keys();
int minValue = slider.getMinimum();
int maxValue = slider.getMaximum();
boolean enabled = slider.isEnabled();
while ( keys.hasMoreElements() ) {
- Integer key = keys.nextElement();
+ Integer key = (Integer)keys.nextElement();
int value = key.intValue();
if (value >= minValue && value <= maxValue) {
- JComponent label = dictionary.get(key);
+ JComponent label = (JComponent) dictionary.get(key);
label.setEnabled(enabled);
if (label instanceof JLabel) {
--- a/jdk/src/share/classes/javax/swing/plaf/synth/SynthSliderUI.java Fri Aug 15 11:33:13 2014 -0700
+++ b/jdk/src/share/classes/javax/swing/plaf/synth/SynthSliderUI.java Mon Aug 18 09:51:52 2014 -0700
@@ -269,7 +269,7 @@
centerY += valueHeight + 2;
centerY += trackHeight + trackInsets.top + trackInsets.bottom;
centerY += tickHeight + 2;
- JComponent label = slider.getLabelTable().elements().nextElement();
+ JComponent label = (JComponent) slider.getLabelTable().elements().nextElement();
Dimension pref = label.getPreferredSize();
return centerY + label.getBaseline(pref.width, pref.height);
}
@@ -291,7 +291,7 @@
int trackHeight = contentHeight - valueHeight;
int yPosition = yPositionForValue(value.intValue(), trackY,
trackHeight);
- JComponent label = slider.getLabelTable().get(value);
+ JComponent label = (JComponent) slider.getLabelTable().get(value);
Dimension pref = label.getPreferredSize();
return yPosition - pref.height / 2 +
label.getBaseline(pref.width, pref.height);
@@ -392,7 +392,8 @@
trackRect.x = insetCache.left;
trackRect.width = contentRect.width;
- Dictionary<Integer, ? extends JComponent> dictionary = slider.getLabelTable();
+ @SuppressWarnings("rawtypes")
+ Dictionary dictionary = slider.getLabelTable();
if (dictionary != null) {
int minValue = slider.getMinimum();
int maxValue = slider.getMaximum();
@@ -402,9 +403,9 @@
// slider range.
int firstLblIdx = Integer.MAX_VALUE;
int lastLblIdx = Integer.MIN_VALUE;
- for (Enumeration<Integer> keys = dictionary.keys();
+ for (Enumeration<?> keys = dictionary.keys();
keys.hasMoreElements(); ) {
- int keyInt = keys.nextElement().intValue();
+ int keyInt = ((Integer)keys.nextElement()).intValue();
if (keyInt >= minValue && keyInt < firstLblIdx) {
firstLblIdx = keyInt;
}
@@ -517,7 +518,7 @@
private int getPadForLabel(int i) {
int pad = 0;
- JComponent c = slider.getLabelTable().get(i);
+ JComponent c = (JComponent) slider.getLabelTable().get(i);
if (c != null) {
int centerX = xPositionForValue(i);
int cHalfWidth = c.getPreferredSize().width / 2;