Merge pull request #220 from enderw88/better-tree-icons

Added component tree icons for the new mass types.
This commit is contained in:
kruland2607 2014-12-26 10:59:18 -06:00
commit f0c5476a39
10 changed files with 191 additions and 127 deletions

View File

@ -1401,6 +1401,13 @@ ComponentIcons.Streamer = Streamer
ComponentIcons.Shockcord = Shock cord ComponentIcons.Shockcord = Shock cord
ComponentIcons.Masscomponent = Mass component ComponentIcons.Masscomponent = Mass component
ComponentIcons.disabled = (disabled) ComponentIcons.disabled = (disabled)
ComponentIcons.Altimeter = Altimeter
ComponentIcons.Flightcomputer = Flight computer
ComponentIcons.Battery = Battery
ComponentIcons.Tracker = Tracker
ComponentIcons.Recoveryhardware = Recovery hardware
ComponentIcons.Payload = Payload
ComponentIcons.Deploymentcharge = Deployment charge
! StageAction ! StageAction
StageAction.Stage = Stage StageAction.Stage = Stage

Binary file not shown.

After

Width:  |  Height:  |  Size: 799 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 842 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 871 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 851 B

View File

@ -19,6 +19,7 @@ import net.sf.openrocket.rocketcomponent.FreeformFinSet;
import net.sf.openrocket.rocketcomponent.InnerTube; import net.sf.openrocket.rocketcomponent.InnerTube;
import net.sf.openrocket.rocketcomponent.LaunchLug; import net.sf.openrocket.rocketcomponent.LaunchLug;
import net.sf.openrocket.rocketcomponent.MassComponent; import net.sf.openrocket.rocketcomponent.MassComponent;
import net.sf.openrocket.rocketcomponent.MassComponent.MassComponentType;
import net.sf.openrocket.rocketcomponent.NoseCone; import net.sf.openrocket.rocketcomponent.NoseCone;
import net.sf.openrocket.rocketcomponent.Parachute; import net.sf.openrocket.rocketcomponent.Parachute;
import net.sf.openrocket.rocketcomponent.ShockCord; import net.sf.openrocket.rocketcomponent.ShockCord;
@ -28,7 +29,6 @@ import net.sf.openrocket.rocketcomponent.TrapezoidFinSet;
import net.sf.openrocket.rocketcomponent.TubeCoupler; import net.sf.openrocket.rocketcomponent.TubeCoupler;
import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Application;
public class ComponentIcons { public class ComponentIcons {
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
@ -36,72 +36,117 @@ public class ComponentIcons {
private static final String SMALL_SUFFIX = "-small.png"; private static final String SMALL_SUFFIX = "-small.png";
private static final String LARGE_SUFFIX = "-large.png"; private static final String LARGE_SUFFIX = "-large.png";
private static final HashMap<Class<?>, ImageIcon> SMALL_ICONS = private static final HashMap<Class<?>, ImageIcon> SMALL_ICONS = new HashMap<Class<?>, ImageIcon>();
new HashMap<Class<?>, ImageIcon>(); private static final HashMap<Class<?>, ImageIcon> LARGE_ICONS = new HashMap<Class<?>, ImageIcon>();
private static final HashMap<Class<?>, ImageIcon> LARGE_ICONS = private static final HashMap<Class<?>, ImageIcon> DISABLED_ICONS = new HashMap<Class<?>, ImageIcon>();
new HashMap<Class<?>, ImageIcon>(); private static final HashMap<MassComponentType, ImageIcon> MASS_COMPONENT_SMALL_ICONS = new HashMap<MassComponentType, ImageIcon>();
private static final HashMap<Class<?>, ImageIcon> DISABLED_ICONS =
new HashMap<Class<?>, ImageIcon>();
static { static {
//// Nose cone // // Nose cone
load("nosecone", trans.get("ComponentIcons.Nosecone"), NoseCone.class); load("nosecone", trans.get("ComponentIcons.Nosecone"), NoseCone.class);
//// Body tube // // Body tube
load("bodytube", trans.get("ComponentIcons.Bodytube"), BodyTube.class); load("bodytube", trans.get("ComponentIcons.Bodytube"), BodyTube.class);
//// Transition // // Transition
load("transition", trans.get("ComponentIcons.Transition"), Transition.class); load("transition", trans.get("ComponentIcons.Transition"),
//// Trapezoidal fin set Transition.class);
load("trapezoidfin", trans.get("ComponentIcons.Trapezoidalfinset"), TrapezoidFinSet.class); // // Trapezoidal fin set
//// Elliptical fin set load("trapezoidfin", trans.get("ComponentIcons.Trapezoidalfinset"),
load("ellipticalfin", trans.get("ComponentIcons.Ellipticalfinset"), EllipticalFinSet.class); TrapezoidFinSet.class);
//// Freeform fin set // // Elliptical fin set
load("freeformfin", trans.get("ComponentIcons.Freeformfinset"), FreeformFinSet.class); load("ellipticalfin", trans.get("ComponentIcons.Ellipticalfinset"),
//// Launch lug EllipticalFinSet.class);
load("launchlug", trans.get("ComponentIcons.Launchlug"), LaunchLug.class); // // Freeform fin set
//// Inner tube load("freeformfin", trans.get("ComponentIcons.Freeformfinset"),
load("innertube", trans.get("ComponentIcons.Innertube"), InnerTube.class); FreeformFinSet.class);
//// Tube coupler // // Launch lug
load("tubecoupler", trans.get("ComponentIcons.Tubecoupler"), TubeCoupler.class); load("launchlug", trans.get("ComponentIcons.Launchlug"),
//// Centering ring LaunchLug.class);
load("centeringring", trans.get("ComponentIcons.Centeringring"), CenteringRing.class); // // Inner tube
//// Bulk head 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); load("bulkhead", trans.get("ComponentIcons.Bulkhead"), Bulkhead.class);
//// Engine block // // Engine block
load("engineblock", trans.get("ComponentIcons.Engineblock"), EngineBlock.class); load("engineblock", trans.get("ComponentIcons.Engineblock"),
//// Parachute EngineBlock.class);
load("parachute", trans.get("ComponentIcons.Parachute"), Parachute.class); // // Parachute
//// Streamer load("parachute", trans.get("ComponentIcons.Parachute"),
Parachute.class);
// // Streamer
load("streamer", trans.get("ComponentIcons.Streamer"), Streamer.class); load("streamer", trans.get("ComponentIcons.Streamer"), Streamer.class);
//// Shock cord // // Shock cord
load("shockcord", trans.get("ComponentIcons.Shockcord"), ShockCord.class); load("shockcord", trans.get("ComponentIcons.Shockcord"),
//// Mass component ShockCord.class);
load("mass", trans.get("ComponentIcons.Masscomponent"), MassComponent.class); load("mass", trans.get("ComponentIcons.Masscomponent"),
MassComponent.class);
// // Mass components
loadMassTypeIcon("mass", trans.get("ComponentIcons.Masscomponent"),
MassComponentType.MASSCOMPONENT);
loadMassTypeIcon("altimeter", trans.get("ComponentIcons.Altimeter"),
MassComponentType.ALTIMETER);
loadMassTypeIcon("battery", trans.get("ComponentIcons.Battery"),
MassComponentType.BATTERY);
loadMassTypeIcon("deployment-charge",
trans.get("ComponentIcons.Deploymentcharge"),
MassComponentType.DEPLOYMENTCHARGE);
loadMassTypeIcon("payload", trans.get("ComponentIcons.Payload"),
MassComponentType.PAYLOAD);
loadMassTypeIcon("flight-comp",
trans.get("ComponentIcons.Flightcomputer"),
MassComponentType.FLIGHTCOMPUTER);
loadMassTypeIcon("recovery-hardware",
trans.get("ComponentIcons.Recoveryhardware"),
MassComponentType.RECOVERYHARDWARE);
loadMassTypeIcon("tracker", trans.get("ComponentIcons.Tracker"),
MassComponentType.TRACKER);
} }
private static void load(String filename, String name, Class<?> componentClass) { private static void load(String filename, String name,
ImageIcon icon = loadSmall(ICON_DIRECTORY + filename + SMALL_SUFFIX, name); Class<?> componentClass) {
ImageIcon icon = loadSmall(ICON_DIRECTORY + filename + SMALL_SUFFIX,
name);
SMALL_ICONS.put(componentClass, icon); SMALL_ICONS.put(componentClass, icon);
ImageIcon[] icons = loadLarge(ICON_DIRECTORY + filename + LARGE_SUFFIX, name); ImageIcon[] icons = loadLarge(ICON_DIRECTORY + filename + LARGE_SUFFIX,
name);
LARGE_ICONS.put(componentClass, icons[0]); LARGE_ICONS.put(componentClass, icons[0]);
DISABLED_ICONS.put(componentClass, icons[1]); DISABLED_ICONS.put(componentClass, icons[1]);
} }
private static void loadMassTypeIcon(String filename, String name,
MassComponentType t) {
ImageIcon icon = loadSmall(ICON_DIRECTORY + filename + SMALL_SUFFIX,
name);
MASS_COMPONENT_SMALL_ICONS.put(t, icon);
}
/** /**
* Return the small icon for a component type. * Return the small icon for a component type.
* *
* @param c the component class. * @param c
* the component class.
* @return the icon, or <code>null</code> if none available. * @return the icon, or <code>null</code> if none available.
*/ */
public static Icon getSmallIcon(Class<?> c) { public static Icon getSmallIcon(Class<?> c) {
if (c.isAssignableFrom(MassComponent.class)) {
}
return SMALL_ICONS.get(c); return SMALL_ICONS.get(c);
} }
public static Icon getSmallMassTypeIcon(MassComponentType t) {
return MASS_COMPONENT_SMALL_ICONS.get(t);
}
/** /**
* Return the large icon for a component type. * Return the large icon for a component type.
* *
* @param c the component class. * @param c
* the component class.
* @return the icon, or <code>null</code> if none available. * @return the icon, or <code>null</code> if none available.
*/ */
public static Icon getLargeIcon(Class<?> c) { public static Icon getLargeIcon(Class<?> c) {
@ -111,26 +156,24 @@ public class ComponentIcons {
/** /**
* Return the large disabled icon for a component type. * Return the large disabled icon for a component type.
* *
* @param c the component class. * @param c
* the component class.
* @return the icon, or <code>null</code> if none available. * @return the icon, or <code>null</code> if none available.
*/ */
public static Icon getLargeDisabledIcon(Class<?> c) { public static Icon getLargeDisabledIcon(Class<?> c) {
return DISABLED_ICONS.get(c); return DISABLED_ICONS.get(c);
} }
private static ImageIcon loadSmall(String file, String desc) { private static ImageIcon loadSmall(String file, String desc) {
URL url = ClassLoader.getSystemResource(file); URL url = ClassLoader.getSystemResource(file);
if (url == null) { if (url == null) {
Application.getExceptionHandler().handleErrorCondition("ERROR: Couldn't find file: " + file); Application.getExceptionHandler().handleErrorCondition(
"ERROR: Couldn't find file: " + file);
return null; return null;
} }
return new ImageIcon(url, desc); return new ImageIcon(url, desc);
} }
private static ImageIcon[] loadLarge(String file, String desc) { private static ImageIcon[] loadLarge(String file, String desc) {
ImageIcon[] icons = new ImageIcon[2]; ImageIcon[] icons = new ImageIcon[2];
@ -139,9 +182,11 @@ public class ComponentIcons {
BufferedImage bi, bi2; BufferedImage bi, bi2;
try { try {
bi = ImageIO.read(url); 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) { } catch (IOException e) {
Application.getExceptionHandler().handleErrorCondition("ERROR: Couldn't read file: " + file, e); Application.getExceptionHandler().handleErrorCondition(
"ERROR: Couldn't read file: " + file, e);
return new ImageIcon[] { null, null }; return new ImageIcon[] { null, null };
} }
@ -151,19 +196,24 @@ public class ComponentIcons {
boolean useAlphaFade = false; // don't use fade to alpha yet boolean useAlphaFade = false; // don't use fade to alpha yet
if (useAlphaFade) { // Fade using alpha if (useAlphaFade) { // Fade using alpha
/* TODO This code to do fade using alpha had been dead code inside a "if (false) {" block. /*
* Eclipse would give a build warning about dead code, so this code has been commented out * TODO This code to do fade using alpha had been dead code
* but left here for future use; am assuming it was dead code because it wasn't working correctly * inside a "if (false) {" block. Eclipse would give a build
* but that it will be useful in the future. * warning about dead code, so this code has been commented out
* but left here for future use; am assuming it was dead code
* because it wasn't working correctly but that it will be
* useful in the future.
*/ */
// int rgb[] = bi2.getRGB(0, 0, bi2.getWidth(), bi2.getHeight(), null, 0, bi2.getWidth()); // int rgb[] = bi2.getRGB(0, 0, bi2.getWidth(), bi2.getHeight(),
// null, 0, bi2.getWidth());
// for (int i = 0; i < rgb.length; i++) { // for (int i = 0; i < rgb.length; i++) {
// final int alpha = (rgb[i] >> 24) & 0xFF; // final int alpha = (rgb[i] >> 24) & 0xFF;
// rgb[i] = (rgb[i] & 0xFFFFFF) | (alpha / 3) << 24; // rgb[i] = (rgb[i] & 0xFFFFFF) | (alpha / 3) << 24;
// //
// //rgb[i] = (rgb[i]&0xFFFFFF) | ((rgb[i]>>1)&0x3F000000); // //rgb[i] = (rgb[i]&0xFFFFFF) | ((rgb[i]>>1)&0x3F000000);
// } // }
// bi2.setRGB(0, 0, bi2.getWidth(), bi2.getHeight(), rgb, 0, bi2.getWidth()); // bi2.setRGB(0, 0, bi2.getWidth(), bi2.getHeight(), rgb, 0,
// bi2.getWidth());
} else { // Raster alpha } else { // Raster alpha
@ -177,12 +227,14 @@ public class ComponentIcons {
} }
//// (disabled) // // (disabled)
icons[1] = new ImageIcon(bi2, desc + " " + trans.get("ComponentIcons.disabled")); icons[1] = new ImageIcon(bi2, desc + " "
+ trans.get("ComponentIcons.disabled"));
return icons; return icons;
} else { } else {
Application.getExceptionHandler().handleErrorCondition("ERROR: Couldn't find file: " + file); Application.getExceptionHandler().handleErrorCondition(
"ERROR: Couldn't find file: " + file);
return new ImageIcon[] { null, null }; return new ImageIcon[] { null, null };
} }
} }

View File

@ -1,7 +1,5 @@
package net.sf.openrocket.gui.main.componenttree; package net.sf.openrocket.gui.main.componenttree;
import java.awt.Component; import java.awt.Component;
import java.awt.FlowLayout; import java.awt.FlowLayout;
@ -14,6 +12,8 @@ import javax.swing.tree.DefaultTreeCellRenderer;
import net.sf.openrocket.gui.main.ComponentIcons; import net.sf.openrocket.gui.main.ComponentIcons;
import net.sf.openrocket.gui.util.Icons; import net.sf.openrocket.gui.util.Icons;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.MassComponent;
import net.sf.openrocket.rocketcomponent.MassComponent.MassComponentType;
import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Application;
import net.sf.openrocket.unit.UnitGroup; import net.sf.openrocket.unit.UnitGroup;
@ -24,33 +24,34 @@ public class ComponentTreeRenderer extends DefaultTreeCellRenderer {
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
@Override @Override
public Component getTreeCellRendererComponent( public Component getTreeCellRendererComponent(JTree tree, Object value,
JTree tree, boolean sel, boolean expanded, boolean leaf, int row,
Object value,
boolean sel,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus1) { boolean hasFocus1) {
Component comp = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus1); Component comp = super.getTreeCellRendererComponent(tree, value, sel,
expanded, leaf, row, hasFocus1);
// Set icon // Set icon
setIcon(ComponentIcons.getSmallIcon(value.getClass()));
RocketComponent c = (RocketComponent) value; RocketComponent c = (RocketComponent) value;
if ( c.isMassOverridden() || c.isCGOverridden()) { if (c.getClass().isAssignableFrom(MassComponent.class)) {
JPanel p = new JPanel(); MassComponentType t = ((MassComponent) c).getMassComponentType();
p.setLayout( new FlowLayout( FlowLayout.LEFT, 1,1) ); setIcon(ComponentIcons.getSmallMassTypeIcon(t));
p.setBackground( UIManager.getColor("Tree.textBackground")); } else {
p.setForeground( UIManager.getColor("Tree.textForeground")); setIcon(ComponentIcons.getSmallIcon(value.getClass()));
p.add(comp/*, BorderLayout.WEST*/);
if ( c.isMassOverridden() ) {
p.add( new JLabel( Icons.MASS_OVERRIDE ) );
} }
if ( c.isCGOverridden() ) { if (c.isMassOverridden() || c.isCGOverridden()) {
p.add( new JLabel(Icons.CG_OVERRIDE) ); JPanel p = new JPanel();
p.setLayout(new FlowLayout(FlowLayout.LEFT, 1, 1));
p.setBackground(UIManager.getColor("Tree.textBackground"));
p.setForeground(UIManager.getColor("Tree.textForeground"));
p.add(comp/* , BorderLayout.WEST */);
if (c.isMassOverridden()) {
p.add(new JLabel(Icons.MASS_OVERRIDE));
}
if (c.isCGOverridden()) {
p.add(new JLabel(Icons.CG_OVERRIDE));
} }
p.setToolTipText(getToolTip(c)); p.setToolTipText(getToolTip(c));
comp = p; comp = p;
@ -62,29 +63,33 @@ public class ComponentTreeRenderer extends DefaultTreeCellRenderer {
return comp; return comp;
} }
private static String getToolTip(RocketComponent c) { private static String getToolTip(RocketComponent c) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("<html>"); sb.append("<html>");
sb.append("<b>").append(c.getName()).append("</b>"); sb.append("<b>").append(c.getName()).append("</b>");
if (c.isMassive() || c.isMassOverridden() ) { if (c.isMassive() || c.isMassOverridden()) {
sb.append(" (").append(UnitGroup.UNITS_MASS.toStringUnit(c.getMass())); sb.append(" (").append(
if(c.getChildCount()>0){ UnitGroup.UNITS_MASS.toStringUnit(c.getMass()));
sb.append(" of ").append(UnitGroup.UNITS_MASS.toStringUnit(c.getSectionMass())).append( " total"); if (c.getChildCount() > 0) {
sb.append(" of ")
.append(UnitGroup.UNITS_MASS.toStringUnit(c
.getSectionMass())).append(" total");
} }
sb.append(")"); sb.append(")");
} else { } else {
if((c.getChildCount()>0) && (c.getSectionMass()>0)){ if ((c.getChildCount() > 0) && (c.getSectionMass() > 0)) {
sb.append(" (").append(UnitGroup.UNITS_MASS.toStringUnit(c.getSectionMass())).append( " total)"); sb.append(" (")
.append(UnitGroup.UNITS_MASS.toStringUnit(c
.getSectionMass())).append(" total)");
} }
} }
if ( c.isMassOverridden() ) { if (c.isMassOverridden()) {
sb.append(" ").append(trans.get("ComponentTree.ttip.massoverride")); sb.append(" ").append(trans.get("ComponentTree.ttip.massoverride"));
} }
if ( c.isCGOverridden() ) { if (c.isCGOverridden()) {
sb.append(" ").append(trans.get("ComponentTree.ttip.cgoverride")); sb.append(" ").append(trans.get("ComponentTree.ttip.cgoverride"));
} }