Merge pull request #198 from kruland2607/override-indicators

Override indicators
This commit is contained in:
kruland2607 2014-05-15 14:56:20 -05:00
commit 4d4acee6de
5 changed files with 44 additions and 6 deletions

View File

@ -1127,7 +1127,8 @@ TCMotorSelPan.btn.close = Close
PlotDialog.CheckBox.Showdatapoints = Show data points
PlotDialog.lbl.Chart = left click drag to zoom area. mouse wheel to zoom. ctrl-mouse wheel to zoom x axis only. ctrl-left click drag to pan. right click drag to zoom dynamically.
ComponentTree.ttip.massoverride = mass override
ComponentTree.ttip.cgoverride = cg override
! "main" prefix is used for the main application dialog
# FIXME: Rename the description keys

Binary file not shown.

After

Width:  |  Height:  |  Size: 345 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 545 B

View File

@ -3,17 +3,26 @@ package net.sf.openrocket.gui.main.componenttree;
import java.awt.Component;
import java.awt.FlowLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.UIManager;
import javax.swing.tree.DefaultTreeCellRenderer;
import net.sf.openrocket.gui.main.ComponentIcons;
import net.sf.openrocket.gui.util.Icons;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.unit.UnitGroup;
import net.sf.openrocket.util.TextUtil;
public class ComponentTreeRenderer extends DefaultTreeCellRenderer {
private static final Translator trans = Application.getTranslator();
@Override
public Component getTreeCellRendererComponent(
JTree tree,
@ -24,28 +33,53 @@ public class ComponentTreeRenderer extends DefaultTreeCellRenderer {
int row,
boolean hasFocus1) {
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus1);
Component comp = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus1);
// Set icon
setIcon(ComponentIcons.getSmallIcon(value.getClass()));
// Set tooltip
RocketComponent c = (RocketComponent) value;
if ( c.isMassOverridden() || c.isCGOverridden()) {
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));
comp = p;
}
// Set tooltip
this.setToolTipText(getToolTip(c));
return this;
return comp;
}
private String getToolTip(RocketComponent c) {
private static String getToolTip(RocketComponent c) {
StringBuilder sb = new StringBuilder();
sb.append("<html>");
sb.append("<b>").append(c.getName()).append("</b>");
if (c.isMassive()) {
if (c.isMassive() || c.isMassOverridden() ) {
sb.append(" (").append(UnitGroup.UNITS_MASS.toStringUnit(c.getMass())).append(")");
}
if ( c.isMassOverridden() ) {
sb.append(" ").append(trans.get("ComponentTree.ttip.massoverride"));
}
if ( c.isCGOverridden() ) {
sb.append(" ").append(trans.get("ComponentTree.ttip.cgoverride"));
}
String comment = c.getComment().trim();
if (comment.length() > 0) {
comment = TextUtil.escapeXML(comment);

View File

@ -83,6 +83,9 @@ public class Icons {
public static final Icon NOT_FAVORITE = loadImageIcon("pix/icons/star_silver.png", "Not favorite");
public static final Icon FAVORITE = loadImageIcon("pix/icons/star_gold.png", "Favorite");
public static final Icon CG_OVERRIDE = loadImageIcon("pix/icons/cg-override.png", "CG Override");
public static final Icon MASS_OVERRIDE = loadImageIcon("pix/icons/mass-override.png", "Mass Override");
static {
log.debug("Icons loaded");