import javax.swing.Icon;
import javax.swing.ImageIcon;
+import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.BodyTube;
import net.sf.openrocket.rocketcomponent.Bulkhead;
import net.sf.openrocket.rocketcomponent.CenteringRing;
import net.sf.openrocket.rocketcomponent.Transition;
import net.sf.openrocket.rocketcomponent.TrapezoidFinSet;
import net.sf.openrocket.rocketcomponent.TubeCoupler;
+import net.sf.openrocket.startup.Application;
public class ComponentIcons {
+ private static final Translator trans = Application.getTranslator();
private static final String ICON_DIRECTORY = "pix/componenticons/";
private static final String SMALL_SUFFIX = "-small.png";
private static final String LARGE_SUFFIX = "-large.png";
- private static final HashMap<Class<?>,ImageIcon> SMALL_ICONS =
- new HashMap<Class<?>,ImageIcon>();
- private static final HashMap<Class<?>,ImageIcon> LARGE_ICONS =
- new HashMap<Class<?>,ImageIcon>();
- private static final HashMap<Class<?>,ImageIcon> DISABLED_ICONS =
- new HashMap<Class<?>,ImageIcon>();
-
+ private static final HashMap<Class<?>, ImageIcon> SMALL_ICONS =
+ new HashMap<Class<?>, ImageIcon>();
+ private static final HashMap<Class<?>, ImageIcon> LARGE_ICONS =
+ new HashMap<Class<?>, ImageIcon>();
+ private static final HashMap<Class<?>, ImageIcon> DISABLED_ICONS =
+ new HashMap<Class<?>, ImageIcon>();
+
static {
- load("nosecone", "Nose cone", NoseCone.class);
- load("bodytube", "Body tube", BodyTube.class);
- load("transition", "Transition", Transition.class);
- load("trapezoidfin", "Trapezoidal fin set", TrapezoidFinSet.class);
- load("ellipticalfin", "Elliptical fin set", EllipticalFinSet.class);
- load("freeformfin", "Freeform fin set", FreeformFinSet.class);
- load("launchlug", "Launch lug", LaunchLug.class);
- load("innertube", "Inner tube", InnerTube.class);
- load("tubecoupler", "Tube coupler", TubeCoupler.class);
- load("centeringring", "Centering ring", CenteringRing.class);
- load("bulkhead", "Bulk head", Bulkhead.class);
- load("engineblock", "Engine block", EngineBlock.class);
- load("parachute", "Parachute", Parachute.class);
- load("streamer", "Streamer", Streamer.class);
- load("shockcord", "Shock cord", ShockCord.class);
- load("mass", "Mass component", MassComponent.class);
+ //// Nose cone
+ load("nosecone", trans.get("ComponentIcons.Nosecone"), NoseCone.class);
+ //// Body tube
+ load("bodytube", trans.get("ComponentIcons.Bodytube"), BodyTube.class);
+ //// Transition
+ load("transition", trans.get("ComponentIcons.Transition"), Transition.class);
+ //// Trapezoidal fin set
+ load("trapezoidfin", trans.get("ComponentIcons.Trapezoidalfinset"), TrapezoidFinSet.class);
+ //// Elliptical fin set
+ load("ellipticalfin", trans.get("ComponentIcons.Ellipticalfinset"), EllipticalFinSet.class);
+ //// Freeform fin set
+ load("freeformfin", trans.get("ComponentIcons.Freeformfinset"), FreeformFinSet.class);
+ //// Launch lug
+ load("launchlug", trans.get("ComponentIcons.Launchlug"), LaunchLug.class);
+ //// Inner tube
+ load("innertube", trans.get("ComponentIcons.Innertube"), InnerTube.class);
+ //// Tube coupler
+ load("tubecoupler", trans.get("ComponentIcons.Tubecoupler"), TubeCoupler.class);
+ //// Centering ring
+ load("centeringring", trans.get("ComponentIcons.Centeringring"), CenteringRing.class);
+ //// Bulk head
+ load("bulkhead", trans.get("ComponentIcons.Bulkhead"), Bulkhead.class);
+ //// Engine block
+ load("engineblock", trans.get("ComponentIcons.Engineblock"), EngineBlock.class);
+ //// Parachute
+ load("parachute", trans.get("ComponentIcons.Parachute"), Parachute.class);
+ //// Streamer
+ load("streamer", trans.get("ComponentIcons.Streamer"), Streamer.class);
+ //// Shock cord
+ load("shockcord", trans.get("ComponentIcons.Shockcord"), ShockCord.class);
+ //// Mass component
+ load("mass", trans.get("ComponentIcons.Masscomponent"), MassComponent.class);
}
private static void load(String filename, String name, Class<?> componentClass) {
}
-
+ /**
+ * Return the small icon for a component type.
+ *
+ * @param c the component class.
+ * @return the icon, or <code>null</code> if none available.
+ */
public static Icon getSmallIcon(Class<?> c) {
return SMALL_ICONS.get(c);
}
+
+ /**
+ * Return the large icon for a component type.
+ *
+ * @param c the component class.
+ * @return the icon, or <code>null</code> if none available.
+ */
public static Icon getLargeIcon(Class<?> c) {
return LARGE_ICONS.get(c);
}
+
+ /**
+ * Return the large disabled icon for a component type.
+ *
+ * @param c the component class.
+ * @return the icon, or <code>null</code> if none available.
+ */
public static Icon getLargeDisabledIcon(Class<?> c) {
return DISABLED_ICONS.get(c);
}
-
-
+
+
private static ImageIcon loadSmall(String file, String desc) {
URL url = ClassLoader.getSystemResource(file);
- if (url==null) {
- System.err.println("ERROR: Couldn't find file: " + file);
+ if (url == null) {
+ ExceptionHandler.handleErrorCondition("ERROR: Couldn't find file: " + file);
return null;
}
return new ImageIcon(url, desc);
ImageIcon[] icons = new ImageIcon[2];
URL url = ClassLoader.getSystemResource(file);
- if (url != null) {
- BufferedImage bi,bi2;
- try {
+ if (url != null) {
+ BufferedImage bi, bi2;
+ try {
bi = ImageIO.read(url);
- bi2 = ImageIO.read(url); // How the fsck can one duplicate a BufferedImage???
+ bi2 = ImageIO.read(url); // How the fsck can one duplicate a BufferedImage???
} catch (IOException e) {
- System.err.println("ERROR: Couldn't read file: "+file);
- e.printStackTrace();
- return new ImageIcon[]{null,null};
+ ExceptionHandler.handleErrorCondition("ERROR: Couldn't read file: " + file, e);
+ return new ImageIcon[] { null, null };
}
- icons[0] = new ImageIcon(bi,desc);
+ icons[0] = new ImageIcon(bi, desc);
// Create disabled icon
- if (false) { // Fade using alpha
-
- int rgb[] = bi2.getRGB(0,0,bi2.getWidth(),bi2.getHeight(),null,0,bi2.getWidth());
- for (int i=0; i<rgb.length; i++) {
- final int alpha = (rgb[i]>>24)&0xFF;
- rgb[i] = (rgb[i]&0xFFFFFF) | (alpha/3)<<24;
+ if (false) { // Fade using alpha
+
+ int rgb[] = bi2.getRGB(0, 0, bi2.getWidth(), bi2.getHeight(), null, 0, bi2.getWidth());
+ for (int i = 0; i < rgb.length; i++) {
+ final int alpha = (rgb[i] >> 24) & 0xFF;
+ rgb[i] = (rgb[i] & 0xFFFFFF) | (alpha / 3) << 24;
//rgb[i] = (rgb[i]&0xFFFFFF) | ((rgb[i]>>1)&0x3F000000);
}
bi2.setRGB(0, 0, bi2.getWidth(), bi2.getHeight(), rgb, 0, bi2.getWidth());
-
- } else { // Raster alpha
-
- for (int x=0; x < bi.getWidth(); x++) {
- for (int y=0; y < bi.getHeight(); y++) {
- if ((x+y)%2 == 0) {
+
+ } else { // Raster alpha
+
+ for (int x = 0; x < bi.getWidth(); x++) {
+ for (int y = 0; y < bi.getHeight(); y++) {
+ if ((x + y) % 2 == 0) {
bi2.setRGB(x, y, 0);
}
}
}
- icons[1] = new ImageIcon(bi2,desc + " (disabled)");
-
- return icons;
- } else {
- System.err.println("ERROR: Couldn't find file: " + file);
- return new ImageIcon[]{null,null};
- }
+ //// (disabled)
+ icons[1] = new ImageIcon(bi2, desc + " " + trans.get("ComponentIcons.disabled"));
+
+ return icons;
+ } else {
+ ExceptionHandler.handleErrorCondition("ERROR: Couldn't find file: " + file);
+ return new ImageIcon[] { null, null };
+ }
}
}