Enhance component tree tooltip
This commit is contained in:
parent
d8a4372ecd
commit
3a1fe0332d
@ -9,6 +9,7 @@ import javax.swing.tree.DefaultTreeCellRenderer;
|
|||||||
|
|
||||||
import net.sf.openrocket.gui.main.ComponentIcons;
|
import net.sf.openrocket.gui.main.ComponentIcons;
|
||||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||||
|
import net.sf.openrocket.unit.UnitGroup;
|
||||||
import net.sf.openrocket.util.TextUtil;
|
import net.sf.openrocket.util.TextUtil;
|
||||||
|
|
||||||
public class ComponentTreeRenderer extends DefaultTreeCellRenderer {
|
public class ComponentTreeRenderer extends DefaultTreeCellRenderer {
|
||||||
@ -21,25 +22,38 @@ public class ComponentTreeRenderer extends DefaultTreeCellRenderer {
|
|||||||
boolean expanded,
|
boolean expanded,
|
||||||
boolean leaf,
|
boolean leaf,
|
||||||
int row,
|
int row,
|
||||||
boolean hasFocus) {
|
boolean hasFocus1) {
|
||||||
|
|
||||||
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
|
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus1);
|
||||||
|
|
||||||
// Set icon
|
// Set icon
|
||||||
setIcon(ComponentIcons.getSmallIcon(value.getClass()));
|
setIcon(ComponentIcons.getSmallIcon(value.getClass()));
|
||||||
|
|
||||||
// Set tooltip
|
// Set tooltip
|
||||||
RocketComponent c = (RocketComponent) value;
|
RocketComponent c = (RocketComponent) value;
|
||||||
String comment = c.getComment().trim();
|
this.setToolTipText(getToolTip(c));
|
||||||
if (comment.length() > 0) {
|
|
||||||
comment = TextUtil.htmlEncode(comment);
|
|
||||||
comment = "<html>" + comment.replace("\n", "<br>");
|
|
||||||
this.setToolTipText(comment);
|
|
||||||
} else {
|
|
||||||
this.setToolTipText(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String getToolTip(RocketComponent c) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("<html>");
|
||||||
|
|
||||||
|
sb.append("<b>").append(c.getName()).append("</b>");
|
||||||
|
if (c.isMassive()) {
|
||||||
|
sb.append(" (").append(UnitGroup.UNITS_MASS.toStringUnit(c.getMass())).append(")");
|
||||||
|
}
|
||||||
|
|
||||||
|
String comment = c.getComment().trim();
|
||||||
|
if (comment.length() > 0) {
|
||||||
|
comment = TextUtil.htmlEncode(comment);
|
||||||
|
comment = comment.replace("\n", "<br>");
|
||||||
|
sb.append("<br>").append(comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user