SafetyMutex and rocket optimization updates
[debian/openrocket] / src / net / sf / openrocket / util / Icons.java
index 69a7b8a52f99bee796d2b6910783c3e10624ed2e..446044df35c16d686f15cceead7f781e233ff282 100644 (file)
@@ -9,10 +9,18 @@ import javax.swing.Icon;
 import javax.swing.ImageIcon;
 
 import net.sf.openrocket.document.Simulation;
+import net.sf.openrocket.gui.main.ExceptionHandler;
+import net.sf.openrocket.logging.LogHelper;
+import net.sf.openrocket.startup.Application;
 
 
 public class Icons {
-
+       private static final LogHelper log = Application.getLogger();
+       
+       static {
+               log.debug("Starting to load icons");
+       }
+       
        /**
         * Icons used for showing the status of a simulation (up to date, out of date, etc).
         */
@@ -33,12 +41,14 @@ public class Icons {
                SIMULATION_LISTENER_OK = SIMULATION_STATUS_ICON_MAP.get(Simulation.Status.UPTODATE);
                SIMULATION_LISTENER_ERROR = SIMULATION_STATUS_ICON_MAP.get(Simulation.Status.OUTDATED);
        }
-
+       
 
        public static final Icon FILE_NEW = loadImageIcon("pix/icons/document-new.png", "New document");
        public static final Icon FILE_OPEN = loadImageIcon("pix/icons/document-open.png", "Open document");
+       public static final Icon FILE_OPEN_EXAMPLE = loadImageIcon("pix/icons/document-open-example.png", "Open example document");
        public static final Icon FILE_SAVE = loadImageIcon("pix/icons/document-save.png", "Save document");
        public static final Icon FILE_SAVE_AS = loadImageIcon("pix/icons/document-save-as.png", "Save document as");
+       public static final Icon FILE_PRINT = loadImageIcon("pix/icons/document-print.png", "Print document");
        public static final Icon FILE_CLOSE = loadImageIcon("pix/icons/document-close.png", "Close document");
        public static final Icon FILE_QUIT = loadImageIcon("pix/icons/application-exit.png", "Quit OpenRocket");
        
@@ -48,18 +58,35 @@ public class Icons {
        public static final Icon EDIT_COPY = loadImageIcon("pix/icons/edit-copy.png", "Copy");
        public static final Icon EDIT_PASTE = loadImageIcon("pix/icons/edit-paste.png", "Paste");
        public static final Icon EDIT_DELETE = loadImageIcon("pix/icons/edit-delete.png", "Delete");
-
+       
        public static final Icon ZOOM_IN = loadImageIcon("pix/icons/zoom-in.png", "Zoom in");
        public static final Icon ZOOM_OUT = loadImageIcon("pix/icons/zoom-out.png", "Zoom out");
-
+       
        public static final Icon PREFERENCES = loadImageIcon("pix/icons/preferences.png", "Preferences");
-
        
+       public static final Icon DELETE = loadImageIcon("pix/icons/delete.png", "Delete");
        
-       private static ImageIcon loadImageIcon(String file, String name) {
+       static {
+               log.debug("Icons loaded");
+       }
+       
+       /**
+        * Load an ImageIcon from the specified file.  The file is obtained as a system
+        * resource from the normal classpath.  If the file cannot be loaded a bug dialog
+        * is opened and <code>null</code> is returned.
+        * 
+        * @param file  the file to load.
+        * @param name  the description of the icon.
+        * @return              the ImageIcon, or null if could not be loaded (after the user closes the dialog)
+        */
+       public static ImageIcon loadImageIcon(String file, String name) {
+               if (System.getProperty("openrocket.unittest") != null) {
+                       return new ImageIcon();
+               }
+               
                URL url = ClassLoader.getSystemResource(file);
                if (url == null) {
-                       System.err.println("Resource "+file+" not found!  Ignoring...");
+                       ExceptionHandler.handleErrorCondition("Image file " + file + " not found, ignoring.");
                        return null;
                }
                return new ImageIcon(url, name);