< prev index next >

src/share/classes/javax/swing/plaf/basic/BasicOptionPaneUI.java

Print this page
rev 1580 : 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 <fbrunnerlist@gmx.ch>

@@ -107,11 +107,11 @@
 
     private Handler handler;
 
 
     static {
-        newline = (String)java.security.AccessController.doPrivileged(
+        newline = java.security.AccessController.doPrivileged(
                                 new GetPropertyAction("line.separator"));
         if (newline == null) {
             newline = "\n";
         }
     }

@@ -260,11 +260,11 @@
      * size that is returned is the maximum of the preferred size of
      * the <code>LayoutManager</code> for the <code>JOptionPane</code>, and
      * <code>getMinimumOptionPaneSize</code>.
      */
     public Dimension getPreferredSize(JComponent c) {
-        if ((JOptionPane)c == optionPane) {
+        if (c == optionPane) {
             Dimension            ourMin = getMinimumOptionPaneSize();
             LayoutManager        lm = c.getLayout();
 
             if (lm != null) {
                 Dimension         lmSize = lm.preferredLayoutSize(c);

@@ -364,12 +364,12 @@
                 hasCustomComponents = true;
             }
 
         } 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) {
             JLabel label = new JLabel( (Icon)msg, SwingConstants.CENTER );
             configureMessageLabel(label);

@@ -379,11 +379,11 @@
             String s = msg.toString();
             int len = s.length();
             if (len <= 0) {
                 return;
             }
-            int nl = -1;
+            int nl;
             int nll = 0;
 
             if ((nl = s.indexOf(newline)) >= 0) {
                 nll = newline.length();
             } else if ((nl = s.indexOf("\r\n")) >= 0) {

@@ -1318,11 +1318,11 @@
                    optionPane.validate();
                 }
                 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);
                     }
                 }
             }
         }

@@ -1416,11 +1416,11 @@
             this.icon = icon;
             this.minimumWidth = minimumWidth;
         }
 
         JButton createButton() {
-            JButton button = null;
+            JButton button;
 
             if (minimumWidth > 0) {
                 button = new ConstrainedButton(text, minimumWidth);
             } else {
                 button = new JButton(text);
< prev index next >