1 package net.sf.openrocket.gui.util;
4 import java.util.Collections;
5 import java.util.HashMap;
8 import javax.swing.Icon;
9 import javax.swing.ImageIcon;
11 import net.sf.openrocket.document.Simulation;
12 import net.sf.openrocket.l10n.Translator;
13 import net.sf.openrocket.logging.LogHelper;
14 import net.sf.openrocket.startup.Application;
18 private static final LogHelper log = Application.getLogger();
19 private static final Translator trans = Application.getTranslator();
22 log.debug("Starting to load icons");
26 * Icons used for showing the status of a simulation (up to date, out of date, etc).
28 public static final Map<Simulation.Status, Icon> SIMULATION_STATUS_ICON_MAP;
30 HashMap<Simulation.Status, Icon> map = new HashMap<Simulation.Status, Icon>();
31 map.put(Simulation.Status.NOT_SIMULATED, loadImageIcon("pix/spheres/gray-16x16.png", "Not simulated"));
32 map.put(Simulation.Status.UPTODATE, loadImageIcon("pix/spheres/green-16x16.png", "Up to date"));
33 map.put(Simulation.Status.LOADED, loadImageIcon("pix/spheres/yellow-16x16.png", "Loaded from file"));
34 map.put(Simulation.Status.OUTDATED, loadImageIcon("pix/spheres/red-16x16.png", "Out-of-date"));
35 map.put(Simulation.Status.EXTERNAL, loadImageIcon("pix/spheres/blue-16x16.png", "Imported data"));
36 SIMULATION_STATUS_ICON_MAP = Collections.unmodifiableMap(map);
39 public static final Icon SIMULATION_LISTENER_OK;
40 public static final Icon SIMULATION_LISTENER_ERROR;
42 SIMULATION_LISTENER_OK = SIMULATION_STATUS_ICON_MAP.get(Simulation.Status.UPTODATE);
43 SIMULATION_LISTENER_ERROR = SIMULATION_STATUS_ICON_MAP.get(Simulation.Status.OUTDATED);
47 public static final Icon FILE_NEW = loadImageIcon("pix/icons/document-new.png", "New document");
48 public static final Icon FILE_OPEN = loadImageIcon("pix/icons/document-open.png", "Open document");
49 public static final Icon FILE_OPEN_EXAMPLE = loadImageIcon("pix/icons/document-open-example.png", "Open example document");
50 public static final Icon FILE_SAVE = loadImageIcon("pix/icons/document-save.png", "Save document");
51 public static final Icon FILE_SAVE_AS = loadImageIcon("pix/icons/document-save-as.png", "Save document as");
52 public static final Icon FILE_PRINT = loadImageIcon("pix/icons/document-print.png", "Print document");
53 public static final Icon FILE_CLOSE = loadImageIcon("pix/icons/document-close.png", "Close document");
54 public static final Icon FILE_QUIT = loadImageIcon("pix/icons/application-exit.png", "Quit OpenRocket");
56 public static final Icon EDIT_UNDO = loadImageIcon("pix/icons/edit-undo.png", trans.get("Icons.Undo"));
57 public static final Icon EDIT_REDO = loadImageIcon("pix/icons/edit-redo.png", trans.get("Icons.Redo"));
58 public static final Icon EDIT_CUT = loadImageIcon("pix/icons/edit-cut.png", "Cut");
59 public static final Icon EDIT_COPY = loadImageIcon("pix/icons/edit-copy.png", "Copy");
60 public static final Icon EDIT_PASTE = loadImageIcon("pix/icons/edit-paste.png", "Paste");
61 public static final Icon EDIT_DELETE = loadImageIcon("pix/icons/edit-delete.png", "Delete");
62 public static final Icon EDIT_SCALE = loadImageIcon("pix/icons/edit-scale.png", "Scale");
64 public static final Icon HELP_ABOUT = loadImageIcon("pix/icons/help-about.png", "About");
65 public static final Icon HELP_LICENSE = loadImageIcon("pix/icons/help-license.png", "License");
66 public static final Icon HELP_BUG_REPORT = loadImageIcon("pix/icons/help-bug.png", "Bug report");
67 public static final Icon HELP_DEBUG_LOG = loadImageIcon("pix/icons/help-log.png", "Debug log");
68 public static final Icon HELP_TOURS = loadImageIcon("pix/icons/help-tours.png", "Guided tours");
70 public static final Icon ZOOM_IN = loadImageIcon("pix/icons/zoom-in.png", "Zoom in");
71 public static final Icon ZOOM_OUT = loadImageIcon("pix/icons/zoom-out.png", "Zoom out");
73 public static final Icon PREFERENCES = loadImageIcon("pix/icons/preferences.png", "Preferences");
75 public static final Icon DELETE = loadImageIcon("pix/icons/delete.png", "Delete");
78 log.debug("Icons loaded");
82 * Load an ImageIcon from the specified file. The file is obtained as a system
83 * resource from the normal classpath. If the file cannot be loaded a bug dialog
84 * is opened and <code>null</code> is returned.
86 * @param file the file to load.
87 * @param name the description of the icon.
88 * @return the ImageIcon, or null if could not be loaded (after the user closes the dialog)
90 public static ImageIcon loadImageIcon(String file, String name) {
91 if (System.getProperty("openrocket.unittest") != null) {
92 return new ImageIcon();
95 URL url = ClassLoader.getSystemResource(file);
97 Application.getExceptionHandler().handleErrorCondition("Image file " + file + " not found, ignoring.");
100 return new ImageIcon(url, name);