6771030: Code improvement and warnings removing from the com.sun.java.swing.plaf.gtk package
authorrupashka
Mon, 17 Nov 2008 17:36:27 +0300
changeset 1837 efd004b550b7
parent 1836 e9844be2c663
child 1838 3bd2ef9cbefb
6771030: Code improvement and warnings removing from the com.sun.java.swing.plaf.gtk package Summary: Removed unnecessary castings and other warnings Reviewed-by: malenkov
jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKColorChooserPanel.java
jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKEngine.java
jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKFileChooserUI.java
jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKPainter.java
jdk/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java
--- a/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKColorChooserPanel.java	Thu Oct 30 13:12:54 2008 +0900
+++ b/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKColorChooserPanel.java	Mon Nov 17 17:36:27 2008 +0300
@@ -799,9 +799,9 @@
             Graphics g = triangleImage.getGraphics();
             g.setColor(new Color(0, 0, 0, 0));
             g.fillRect(0, 0, a, a);
-            g.translate((int)(a / 2), 0);
+            g.translate(a / 2, 0);
             paintTriangle(g, triangleSize, getColor());
-            g.translate((int)(-a / 2), 0);
+            g.translate(-a / 2, 0);
             g.dispose();
 
             g = wheelImage.getGraphics();
@@ -897,7 +897,7 @@
                 return false;
             }
             // Rotate to origin and and verify x is valid.
-            int triangleSize = (int)innerR * 3 / 2;
+            int triangleSize = innerR * 3 / 2;
             double x1 = Math.cos(angle) * x - Math.sin(angle) * y;
             double y1 = Math.sin(angle) * x + Math.cos(angle) * y;
             if (x1 < -(innerR / 2)) {
@@ -960,7 +960,7 @@
          */
         private void setSaturationAndBrightness(float s, float b) {
             int innerR = getTriangleCircumscribedRadius();
-            int triangleSize = (int)innerR * 3 / 2;
+            int triangleSize = innerR * 3 / 2;
             double x = b * triangleSize;
             double maxY = x * Math.tan(Math.toRadians(30.0));
             double y = 2 * maxY * s - maxY;
@@ -1156,7 +1156,7 @@
          * @param x X location to get color for
          * @param y Y location to get color for
          * @param rad Radius from center of color wheel
-         * @param integer with red, green and blue components
+         * @return integer with red, green and blue components
          */
         private int colorWheelLocationToRGB(int x, int y, double rad) {
             double angle = Math.acos((double)x / rad);
@@ -1165,12 +1165,12 @@
             if (angle < PI_3) {
                 if (y < 0) {
                     // FFFF00 - FF0000
-                    rgb = 0xFF0000 | (int)Math.min(255,
+                    rgb = 0xFF0000 | Math.min(255,
                                            (int)(255 * angle / PI_3)) << 8;
                 }
                 else {
                     // FF0000 - FF00FF
-                    rgb = 0xFF0000 | (int)Math.min(255,
+                    rgb = 0xFF0000 | Math.min(255,
                                            (int)(255 * angle / PI_3));
                 }
             }
@@ -1178,12 +1178,12 @@
                 angle -= PI_3;
                 if (y < 0) {
                     // 00FF00 - FFFF00
-                    rgb = 0x00FF00 | (int)Math.max(0, 255 -
+                    rgb = 0x00FF00 | Math.max(0, 255 -
                                            (int)(255 * angle / PI_3)) << 16;
                 }
                 else {
                     // FF00FF - 0000FF
-                    rgb = 0x0000FF | (int)Math.max(0, 255 -
+                    rgb = 0x0000FF | Math.max(0, 255 -
                                            (int)(255 * angle / PI_3)) << 16;
                 }
             }
@@ -1191,12 +1191,12 @@
                 angle -= 2 * PI_3;
                 if (y < 0) {
                     // 00FFFF - 00FF00
-                    rgb = 0x00FF00 | (int)Math.min(255,
+                    rgb = 0x00FF00 | Math.min(255,
                                            (int)(255 * angle / PI_3));
                 }
                 else {
                     // 0000FF - 00FFFF
-                    rgb = 0x0000FF | (int)Math.min(255,
+                    rgb = 0x0000FF | Math.min(255,
                                            (int)(255 * angle / PI_3)) << 8;
                 }
             }
--- a/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKEngine.java	Thu Oct 30 13:12:54 2008 +0900
+++ b/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKEngine.java	Mon Nov 17 17:36:27 2008 +0300
@@ -112,7 +112,7 @@
     }
 
 
-    private static HashMap regionToWidgetTypeMap;
+    private static HashMap<Region, Object> regionToWidgetTypeMap;
     private ImageCache cache = new ImageCache(CACHE_SIZE);
     private int x0, y0, w0, h0;
     private Graphics graphics;
@@ -178,7 +178,7 @@
         Toolkit.getDefaultToolkit();
 
         // Initialize regionToWidgetTypeMap
-        regionToWidgetTypeMap = new HashMap(50);
+        regionToWidgetTypeMap = new HashMap<Region, Object>(50);
         regionToWidgetTypeMap.put(Region.ARROW_BUTTON, new WidgetType[] {
             WidgetType.SPINNER_ARROW_BUTTON,
             WidgetType.COMBO_BOX_ARROW_BUTTON,
--- a/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKFileChooserUI.java	Thu Oct 30 13:12:54 2008 +0900
+++ b/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKFileChooserUI.java	Mon Nov 17 17:36:27 2008 +0300
@@ -148,7 +148,7 @@
             directoryList : fileList;
         Object[] files = list.getSelectedValues();
         int len = files.length;
-        Vector result = new Vector(len + 1);
+        Vector<String> result = new Vector<String>(len + 1);
 
         // we return all selected file names
         for (int i = 0; i < len; i++) {
@@ -425,16 +425,16 @@
                             setDirectorySelected(true);
                             setDirectory(((File)objects[0]));
                         } else {
-                            ArrayList fList = new ArrayList(objects.length);
-                            for (int i = 0; i < objects.length; i++) {
-                                File f = (File)objects[i];
+                            ArrayList<File> fList = new ArrayList<File>(objects.length);
+                            for (Object object : objects) {
+                                File f = (File) object;
                                 if ((chooser.isFileSelectionEnabled() && f.isFile())
                                     || (chooser.isDirectorySelectionEnabled() && f.isDirectory())) {
                                     fList.add(f);
                                 }
                             }
                             if (fList.size() > 0) {
-                                files = (File[])fList.toArray(new File[fList.size()]);
+                                files = fList.toArray(new File[fList.size()]);
                             }
                             setDirectorySelected(false);
                         }
@@ -671,9 +671,9 @@
 
         pathFieldLabel.setLabelFor(fileNameTextField);
 
-        Set forwardTraversalKeys = fileNameTextField.getFocusTraversalKeys(
+        Set<AWTKeyStroke> forwardTraversalKeys = fileNameTextField.getFocusTraversalKeys(
             KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
-        forwardTraversalKeys = new HashSet(forwardTraversalKeys);
+        forwardTraversalKeys = new HashSet<AWTKeyStroke>(forwardTraversalKeys);
         forwardTraversalKeys.remove(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
         fileNameTextField.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forwardTraversalKeys);
 
@@ -895,10 +895,9 @@
 
     private class GTKDirectoryModel extends BasicDirectoryModel {
         FileSystemView fsv;
-        private Comparator fileComparator = new Comparator() {
-            public int compare(Object o, Object o1) {
-                return fsv.getSystemDisplayName((File) o).compareTo
-                      (fsv.getSystemDisplayName((File) o1));
+        private Comparator<File> fileComparator = new Comparator<File>() {
+            public int compare(File o, File o1) {
+                return fsv.getSystemDisplayName(o).compareTo(fsv.getSystemDisplayName(o1));
             }
         };
 
@@ -1352,8 +1351,8 @@
             FileFilter currentFilter = getFileChooser().getFileFilter();
             boolean found = false;
             if (currentFilter != null) {
-                for (int i = 0; i < filters.length; i++) {
-                    if (filters[i] == currentFilter) {
+                for (FileFilter filter : filters) {
+                    if (filter == currentFilter) {
                         found = true;
                     }
                 }
--- a/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKPainter.java	Thu Oct 30 13:12:54 2008 +0900
+++ b/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKPainter.java	Mon Nov 17 17:36:27 2008 +0300
@@ -299,7 +299,7 @@
             // Paint the default indicator
             GTKStyle style = (GTKStyle)context.getStyle();
             if (defaultCapable && !toolButton) {
-                Insets defaultInsets = (Insets)style.getClassSpecificInsetsValue(
+                Insets defaultInsets = style.getClassSpecificInsetsValue(
                         context, "default-border",
                         GTKStyle.BUTTON_DEFAULT_BORDER_INSETS);
 
--- a/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java	Thu Oct 30 13:12:54 2008 +0900
+++ b/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java	Mon Nov 17 17:36:27 2008 +0300
@@ -124,7 +124,7 @@
         }
 
         // Initialize constants
-        variables = new HashMap();
+        variables = new HashMap<String, Integer>();
         NodeList nodes = xmlDoc.getElementsByTagName("constant");
         int n = nodes.getLength();
         for (int i = 0; i < n; i++) {
@@ -144,14 +144,14 @@
         }
 
         // Cache frame geometries
-        frameGeometries = new HashMap();
+        frameGeometries = new HashMap<String, Map<String, Object>>();
         nodes = xmlDoc.getElementsByTagName("frame_geometry");
         n = nodes.getLength();
         for (int i = 0; i < n; i++) {
             Node node = nodes.item(i);
             String name = getStringAttr(node, "name");
             if (name != null) {
-                HashMap<String, Object> gm = new HashMap();
+                HashMap<String, Object> gm = new HashMap<String, Object>();
                 frameGeometries.put(name, gm);
 
                 String parentGM = getStringAttr(node, "parent");
@@ -458,7 +458,7 @@
 
 
 
-    private static class Privileged implements PrivilegedAction {
+    private static class Privileged implements PrivilegedAction<Object> {
         private static int GET_THEME_DIR  = 0;
         private static int GET_USER_THEME = 1;
         private static int GET_IMAGE      = 2;
@@ -598,7 +598,7 @@
         g2.setComposite(oldComp);
     }
 
-    private HashMap<String, Image> images = new HashMap();
+    private HashMap<String, Image> images = new HashMap<String, Image>();
 
     protected Image getImage(String key, Color c) {
         Image image = images.get(key+"-"+c.getRGB());
@@ -1530,8 +1530,8 @@
                 DocumentBuilderFactory.newInstance().newDocumentBuilder();
         }
         InputStream inputStream =
-            (InputStream)AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
+            AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
+                public InputStream run() {
                     try {
                         return new BufferedInputStream(xmlFile.openStream());
                     } catch (IOException ex) {
@@ -1551,7 +1551,7 @@
     protected Node[] getNodesByName(Node parent, String name) {
         NodeList nodes = parent.getChildNodes(); // ElementNode
         int n = nodes.getLength();
-        ArrayList<Node> list = new ArrayList();
+        ArrayList<Node> list = new ArrayList<Node>();
         for (int i=0; i < n; i++) {
             Node node = nodes.item(i);
             if (name.equals(node.getNodeName())) {
@@ -1603,7 +1603,7 @@
                             String aValue = attrs[a * 2 + 1];
                             Node attr = nodeAttrs.getNamedItem(aName);
                             if (attr == null ||
-                                aValue != null && !aValue.equals((String)attr.getNodeValue())) {
+                                aValue != null && !aValue.equals(attr.getNodeValue())) {
                                 matches = false;
                                 break;
                             }
@@ -1642,7 +1642,7 @@
 
     protected String getStringAttr(NamedNodeMap attrs, String name) {
         Node item = attrs.getNamedItem(name);
-        return (item != null) ? (String)item.getNodeValue() : null;
+        return (item != null) ? item.getNodeValue() : null;
     }
 
     protected boolean getBooleanAttr(Node node, String name, boolean fallback) {