# HG changeset patch # User rupashka # Date 1226932587 -10800 # Node ID efd004b550b7f51f190b9a77f624f6e649eb5b8d # Parent e9844be2c6634eb4cccf15646cc8684e01de4534 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 diff -r e9844be2c663 -r efd004b550b7 jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKColorChooserPanel.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; } } diff -r e9844be2c663 -r efd004b550b7 jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKEngine.java --- 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 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(50); regionToWidgetTypeMap.put(Region.ARROW_BUTTON, new WidgetType[] { WidgetType.SPINNER_ARROW_BUTTON, WidgetType.COMBO_BOX_ARROW_BUTTON, diff -r e9844be2c663 -r efd004b550b7 jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKFileChooserUI.java --- 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 result = new Vector(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 fList = new ArrayList(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 forwardTraversalKeys = fileNameTextField.getFocusTraversalKeys( KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS); - forwardTraversalKeys = new HashSet(forwardTraversalKeys); + forwardTraversalKeys = new HashSet(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 fileComparator = new Comparator() { + 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; } } diff -r e9844be2c663 -r efd004b550b7 jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKPainter.java --- 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); diff -r e9844be2c663 -r efd004b550b7 jdk/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java --- 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(); 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>(); 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 gm = new HashMap(); + HashMap gm = new HashMap(); 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 { 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 images = new HashMap(); + private HashMap images = new HashMap(); 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() { + 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 list = new ArrayList(); + ArrayList list = new ArrayList(); 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) {