classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: MetalIconFactory


From: David Gilbert
Subject: [cp-patches] FYI: MetalIconFactory
Date: Wed, 12 Oct 2005 14:44:16 +0000
User-agent: Mozilla Thunderbird 1.0.6 (X11/20050728)

Some tests I am working on for the JFileChooser/BasicFileChooserUI/MetalFileChooserUI classes depend on some of the methods of MetalIconFactory returning the same icon reference each time they are called. In many cases, Classpath is returning a new icon instance for each call. I wrote Mauve tests for each method to confirm the correct behaviour, and updated MetalIconFactory with the patch below (committed). I also fixed the getIconHeight() methods in FileIcon16 and FolderIcon16 which must add the value returned by getAdditionalHeight():

2005-10-12  David Gilbert  <address@hidden>

        * javax/swing/plaf/metal/MetalIconFactory.java
        (FileIcon16.getIconHeight): add result of getAdditionalHeight(),
        (FolderIcon16.getIconHeight): add result of getAdditionalHeight(),
        (checkBoxIcon): new private field,
        (checkBoxMenuItemIcon): likewise,
        (fileChooserDetailViewIcon): likewise,
        (fileChooserHomeFolderIcon): likewise,
        (fileChooserListViewIcon): likewise,
        (fileChooserNewFolderIcon): likewise,
        (fileChooserUpFolderIcon): likewise,
        (radioButtonMenuItemIcon): likewise,
        (internalFrameDefaultMenuIcon): likewise,
        (treeComputerIcon): likewise,
        (treeFloppyDriveIcon): likewise,
        (treeHardDriveIcon): likewise,
        (getCheckBoxIcon): return single instance,
        (getCheckBoxMenuItemIcon): likewise,
        (getFileChooserDetailViewIcon): likewise,
        (getFileChooserHomeFolderIcon): likewise,
        (getFileChooserListViewIcon): likewise,
        (getFileChooserNewFolderIcon): likewise,
        (getFileChooserUpFolderIcon): likewise,
        (getRadioButtonMenuItemIcon): likewise,
        (getInternalFrameDefaultMenuIcon): likewise,
        (getTreeComputerIcon): likewise,
        (getTreeFloppyDriveIcon): likewise,
        (getTreeHardDriveIcon): likewise.

Regards,

Dave
Index: javax/swing/plaf/metal/MetalIconFactory.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalIconFactory.java,v
retrieving revision 1.16
diff -u -r1.16 MetalIconFactory.java
--- javax/swing/plaf/metal/MetalIconFactory.java        28 Sep 2005 10:29:17 
-0000      1.16
+++ javax/swing/plaf/metal/MetalIconFactory.java        12 Oct 2005 13:27:33 
-0000
@@ -531,13 +531,15 @@
     }
 
     /**
-     * Returns the height of the icon, in pixels.
+     * Returns the height of the icon, in pixels.  The height returned is 
+     * <code>16</code> plus the value returned by 
+     * address@hidden #getAdditionalHeight()}.
      * 
      * @return The height of the icon.
      */
     public int getIconHeight() 
     {
-      return 16;
+      return 16 + getAdditionalHeight();
     }
     
     /**
@@ -570,9 +572,11 @@
     }
     
     /**
-     * Returns the additional height (???).
+     * Returns the additional height for the icon.  The 
+     * address@hidden #getIconHeight()} method adds this value to the icon 
height it
+     * returns.  Subclasses can override this method to adjust the icon height.
      * 
-     * @return The additional height.
+     * @return The additional height (<code>0</code> unless overridden).
      */
     public int getAdditionalHeight() 
     {
@@ -606,13 +610,15 @@
     }
     
     /**
-     * Returns the height of the icon, in pixels.
+     * Returns the height of the icon, in pixels.  The height returned is 
+     * <code>16</code> plus the value returned by 
+     * address@hidden #getAdditionalHeight()}.
      * 
      * @return The height of the icon.
      */
     public int getIconHeight() 
     {
-      return 16;
+      return 16 + getAdditionalHeight();
     }
 
     /**
@@ -643,9 +649,11 @@
     }
     
     /**
-     * Returns the additional height (???).
+     * Returns the additional height for the icon.  The 
+     * address@hidden #getIconHeight()} method adds this value to the icon 
height it
+     * returns.  Subclasses can override this method to adjust the icon height.
      * 
-     * @return The additional height.
+     * @return The additional height (<code>0</code> unless overridden).
      */
     public int getAdditionalHeight() 
     {
@@ -1816,9 +1824,10 @@
     }
     
     /**
-     * Returns the additional height (???).
+     * Returns the additional height for this icon, in this case <code>2</code>
+     * pixels.
      * 
-     * @return The additional height.
+     * @return <code>2</code>.
      */
     public int getAdditionalHeight() 
     {
@@ -1849,9 +1858,10 @@
     }
     
     /**
-     * Returns the additional height (???).
+     * Returns the additional height for this icon, in this case <code>4</code>
+     * pixels.
      * 
-     * @return The additional height.
+     * @return <code>4</code>.
      */
     public int getAdditionalHeight() 
     {
@@ -2125,9 +2135,45 @@
     }        
   }  
     
+  /** The icon returned by address@hidden #getCheckBoxIcon()}. */
+  private static Icon checkBoxIcon;
+  
+  /** The icon returned by address@hidden #getCheckBoxMenuItemIcon()}. */
+  private static Icon checkBoxMenuItemIcon;
+  
+  /** The icon returned by address@hidden #getFileChooserDetailViewIcon()}. */
+  private static Icon fileChooserDetailViewIcon;
+
+  /** The icon returned by address@hidden #getFileChooserHomeFolderIcon()}. */
+  private static Icon fileChooserHomeFolderIcon;
+
+  /** The icon returned by address@hidden #getFileChooserListViewIcon()}. */
+  private static Icon fileChooserListViewIcon;
+
+  /** The icon returned by address@hidden #getFileChooserNewFolderIcon()}. */
+  private static Icon fileChooserNewFolderIcon;
+
+  /** The icon returned by address@hidden #getFileChooserUpFolderIcon()}. */
+  private static Icon fileChooserUpFolderIcon;
+
   /** The cached RadioButtonIcon instance. */
   private static RadioButtonIcon radioButtonIcon;
 
+  /** The icon returned by address@hidden #getRadioButtonMenuItemIcon()}. */
+  private static Icon radioButtonMenuItemIcon;
+
+  /** The icon returned by address@hidden #getInternalFrameDefaultMenuIcon()}. 
*/
+  private static Icon internalFrameDefaultMenuIcon;
+
+  /** The icon returned by address@hidden #getTreeComputerIcon()}. */
+  private static Icon treeComputerIcon;
+  
+  /** The icon instance returned by address@hidden #getTreeFloppyDriveIcon()}. 
*/
+  private static Icon treeFloppyDriveIcon;
+  
+  /** The icon instance returned by address@hidden #getTreeHardDriveIcon()}. */
+  private static Icon treeHardDriveIcon;
+  
   /**
    * Creates a new instance.  All the methods are static, so creating an 
    * instance isn't necessary.
@@ -2145,7 +2191,9 @@
    */
   public static Icon getCheckBoxIcon() 
   {
-    return new MetalCheckBoxIcon();
+    if (checkBoxIcon == null)
+      checkBoxIcon = new MetalCheckBoxIcon();
+    return checkBoxIcon;
   }
   
   /**
@@ -2156,7 +2204,9 @@
    */
   public static Icon getCheckBoxMenuItemIcon() 
   {
-    return new CheckBoxMenuItemIcon();
+    if (checkBoxMenuItemIcon == null)
+      checkBoxMenuItemIcon = new CheckBoxMenuItemIcon();
+    return checkBoxMenuItemIcon;
   }
 
   /**
@@ -2166,7 +2216,9 @@
    */
   public static Icon getFileChooserDetailViewIcon() 
   {
-    return new FileChooserDetailViewIcon();
+    if (fileChooserDetailViewIcon == null)
+      fileChooserDetailViewIcon = new FileChooserDetailViewIcon();
+    return fileChooserDetailViewIcon;
   }
     
   /**
@@ -2176,7 +2228,9 @@
    */
   public static Icon getFileChooserHomeFolderIcon() 
   {
-    return new FileChooserHomeFolderIcon();        
+    if (fileChooserHomeFolderIcon == null)
+      fileChooserHomeFolderIcon = new FileChooserHomeFolderIcon();
+    return fileChooserHomeFolderIcon;        
   }
     
   /**
@@ -2186,7 +2240,9 @@
    */
   public static Icon getFileChooserListViewIcon() 
   {
-    return new FileChooserListViewIcon();
+    if (fileChooserListViewIcon == null)
+      fileChooserListViewIcon = new FileChooserListViewIcon();
+    return fileChooserListViewIcon;
   }
     
   /**
@@ -2196,7 +2252,9 @@
    */
   public static Icon getFileChooserNewFolderIcon() 
   {
-    return new FileChooserNewFolderIcon();
+    if (fileChooserNewFolderIcon == null)
+      fileChooserNewFolderIcon = new FileChooserNewFolderIcon();
+    return fileChooserNewFolderIcon;
   }
     
   /**
@@ -2206,7 +2264,9 @@
    */
   public static Icon getFileChooserUpFolderIcon() 
   {
-    return new FileChooserUpFolderIcon();
+    if (fileChooserUpFolderIcon == null)
+      fileChooserUpFolderIcon = new FileChooserUpFolderIcon();
+    return fileChooserUpFolderIcon;
   }
 
   /**
@@ -2228,7 +2288,9 @@
    */
   public static Icon getRadioButtonMenuItemIcon() 
   {
-    return new RadioButtonMenuItemIcon();
+    if (radioButtonMenuItemIcon == null)
+      radioButtonMenuItemIcon = new RadioButtonMenuItemIcon();
+    return radioButtonMenuItemIcon;
   }
 
   /**
@@ -2263,7 +2325,9 @@
    */
   public static Icon getInternalFrameDefaultMenuIcon() 
   {
-    return new InternalFrameDefaultMenuIcon();
+    if (internalFrameDefaultMenuIcon == null)
+      internalFrameDefaultMenuIcon = new InternalFrameDefaultMenuIcon();
+    return internalFrameDefaultMenuIcon;
   }
   
   /**
@@ -2359,7 +2423,9 @@
    */
   public static Icon getTreeComputerIcon() 
   {
-    return new TreeComputerIcon();        
+    if (treeComputerIcon == null)
+      treeComputerIcon = new TreeComputerIcon();
+    return treeComputerIcon;        
   }
     
   /**
@@ -2369,7 +2435,9 @@
    */
   public static Icon getTreeFloppyDriveIcon() 
   {
-    return new TreeFloppyDriveIcon();
+    if (treeFloppyDriveIcon == null)
+      treeFloppyDriveIcon = new TreeFloppyDriveIcon();
+    return treeFloppyDriveIcon;
   }
     
   /**
@@ -2379,7 +2447,9 @@
    */
   public static Icon getTreeHardDriveIcon() 
   {
-    return new TreeHardDriveIcon();
+    if (treeHardDriveIcon == null)
+      treeHardDriveIcon = new TreeHardDriveIcon();
+    return treeHardDriveIcon;
   }
 
 }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]