[fixes #969] Use comboBox for edges

This commit is contained in:
Sibo Van Gool 2021-08-04 21:14:35 +02:00
parent e18bc1ad95
commit 6b67aac739
6 changed files with 68 additions and 51 deletions

View File

@ -809,14 +809,12 @@ AppearanceCfg.lbl.texture.offset = Offset:
AppearanceCfg.lbl.texture.center = Center: AppearanceCfg.lbl.texture.center = Center:
AppearanceCfg.lbl.texture.rotation = Rotation: AppearanceCfg.lbl.texture.rotation = Rotation:
AppearanceCfg.lbl.texture.repeat = Repeat: AppearanceCfg.lbl.texture.repeat = Repeat:
AppearanceCfg.lbl.InsideSameAsOutside = Use separate appearance for outside and inside AppearanceCfg.lbl.separateInsideOutside = Use separate appearance for outside and inside
AppearanceCfg.lbl.LeftSideSameAsRightSide = Use separate appearance for left and right side(s) AppearanceCfg.lbl.separateLeftSideRightSide = Use separate appearance for left and right side(s)
AppearanceCfg.lbl.ttip.InsideSameAsOutside = Use a separate appearance for outside and inside AppearanceCfg.lbl.ttip.separateInsideOutside = Use a separate appearance for outside and inside
AppearanceCfg.lbl.ttip.LeftSideSameAsRightSide = Use a separate appearance for left and right side(s) AppearanceCfg.lbl.ttip.separateLeftSideRightSide = Use a separate appearance for left and right side(s)
AppearanceCfg.lbl.EdgesSameAsInside = Use inside appearance for edges AppearanceCfg.lbl.AppearanceEdges = Appearance for edges:
AppearanceCfg.lbl.EdgesSameAsRightSide = Use right side appearance for edges AppearanceCfg.lbl.ttip.AppearanceEdges = Select the appearance that should be used for the edges
AppearanceCfg.lbl.ttip.EdgesSameAsInside = Use the inside appearance (checked) or outside appearance (unchecked) for the edges
AppearanceCfg.lbl.ttip.EdgesSameAsRightSide = Use the right side appearance (checked) or left side appearance (unchecked) for the edges
! Texture Wrap Modes ! Texture Wrap Modes
TextureWrap.Repeat = Repeat TextureWrap.Repeat = Repeat

View File

@ -30,7 +30,7 @@ public class InsideAppearanceHandler extends AppearanceHandler {
if ("insideSameAsOutside".equals(element)) { if ("insideSameAsOutside".equals(element)) {
boolean insideSameAsOutside = Boolean.parseBoolean(content); boolean insideSameAsOutside = Boolean.parseBoolean(content);
if (component instanceof InsideColorComponent) if (component instanceof InsideColorComponent)
((InsideColorComponent)component).getInsideColorComponentHandler().setInsideSameAsOutside(insideSameAsOutside); ((InsideColorComponent)component).getInsideColorComponentHandler().setSeparateInsideOutside(insideSameAsOutside);
return; return;
} }

View File

@ -58,7 +58,7 @@ public class RocketComponentSaver {
if (ap_in != null) { if (ap_in != null) {
elements.add("<inside-appearance>"); elements.add("<inside-appearance>");
elements.add("<edgesSameAsInside>" + handler.isEdgesSameAsInside() + "</edgesSameAsInside>"); elements.add("<edgesSameAsInside>" + handler.isEdgesSameAsInside() + "</edgesSameAsInside>");
elements.add("<insideSameAsOutside>" + handler.isInsideSameAsOutside() + "</insideSameAsOutside>"); elements.add("<insideSameAsOutside>" + handler.isSeparateInsideOutside() + "</insideSameAsOutside>");
buildAppearanceElements(elements, ap_in); buildAppearanceElements(elements, ap_in);
elements.add("</inside-appearance>"); elements.add("</inside-appearance>");
} }

View File

@ -14,7 +14,7 @@ import java.util.EventObject;
public class InsideColorComponentHandler { public class InsideColorComponentHandler {
private final RocketComponent component; private final RocketComponent component;
private Appearance insideAppearance = null; private Appearance insideAppearance = null;
private boolean insideSameAsOutside = true; private boolean separateInsideOutside = false; // Flag for separate inside and outside appearance
private boolean edgesSameAsInside = true; private boolean edgesSameAsInside = true;
public InsideColorComponentHandler(RocketComponent component) { public InsideColorComponentHandler(RocketComponent component) {
@ -76,22 +76,21 @@ public class InsideColorComponentHandler {
} }
/** /**
* Checks whether the component should use the same appearance for the inside as the outside (return true) or as the * Checks whether the component should use a separate appearance for the inside and outside.
* outside (return false)
* *
* @return true if edges should use the same appearance as the inside, * @return true if a separate inside and outside appearance should be used,
* false if edges should use the same appearance as the outside * false if the inside should have the outside appearance
*/ */
public boolean isInsideSameAsOutside() { public boolean isSeparateInsideOutside() {
return this.insideSameAsOutside; return this.separateInsideOutside;
} }
/** /**
* Sets the new state for insideSameAsOutside to newState * Sets the new state for separateInsideOutside to newState
* *
* @param newState new edgesUseInsideAppearance value * @param newState new separateInsideOutside value
*/ */
public void setInsideSameAsOutside(boolean newState) { public void setSeparateInsideOutside(boolean newState) {
this.insideSameAsOutside = newState; this.separateInsideOutside = newState;
} }
} }

View File

@ -81,7 +81,6 @@ public class AppearancePanel extends JPanel {
private Appearance defaultAppearance = null; private Appearance defaultAppearance = null;
private JTabbedPane outsideInsidePane = null; private JTabbedPane outsideInsidePane = null;
private JCheckBox edgesCheckbox = null;
private JCheckBox customInside = null; private JCheckBox customInside = null;
@ -322,38 +321,42 @@ public class AppearancePanel extends JPanel {
InsideColorComponentHandler handler = ((InsideColorComponent)c).getInsideColorComponentHandler(); InsideColorComponentHandler handler = ((InsideColorComponent)c).getInsideColorComponentHandler();
// Get translator keys // Get translator keys
String tr_outside, tr_inside, tr_edges, tr_edges_ttip, tr_insideOutside, tr_insideOutside_ttip; String tr_outside, tr_inside, tr_insideOutside, tr_insideOutside_ttip;
if (c instanceof FinSet) { if (c instanceof FinSet) {
tr_outside = "RocketCompCfg.tab.LeftSide"; tr_outside = "RocketCompCfg.tab.LeftSide";
tr_inside = "RocketCompCfg.tab.RightSide"; tr_inside = "RocketCompCfg.tab.RightSide";
tr_edges = "AppearanceCfg.lbl.EdgesSameAsRightSide"; tr_insideOutside = "AppearanceCfg.lbl.separateLeftSideRightSide";
tr_edges_ttip = "AppearanceCfg.lbl.ttip.EdgesSameAsRightSide"; tr_insideOutside_ttip = "AppearanceCfg.lbl.ttip.separateLeftSideRightSide";
tr_insideOutside = "AppearanceCfg.lbl.LeftSideSameAsRightSide";
tr_insideOutside_ttip = "AppearanceCfg.lbl.ttip.LeftSideSameAsRightSide";
} }
else { else {
tr_outside = "RocketCompCfg.tab.Outside"; tr_outside = "RocketCompCfg.tab.Outside";
tr_inside = "RocketCompCfg.tab.Inside"; tr_inside = "RocketCompCfg.tab.Inside";
tr_edges = "AppearanceCfg.lbl.EdgesSameAsInside"; tr_insideOutside = "AppearanceCfg.lbl.separateInsideOutside";
tr_edges_ttip = "AppearanceCfg.lbl.ttip.EdgesSameAsInside"; tr_insideOutside_ttip = "AppearanceCfg.lbl.ttip.separateInsideOutside";
tr_insideOutside = "AppearanceCfg.lbl.InsideSameAsOutside";
tr_insideOutside_ttip = "AppearanceCfg.lbl.ttip.InsideSameAsOutside";
} }
// Checkbox for using separate outside/inside appearance // Checkbox for using separate outside/inside appearance
BooleanModel b_customInside = new BooleanModel(handler.isInsideSameAsOutside()); BooleanModel b_customInside = new BooleanModel(handler.isSeparateInsideOutside());
this.customInside = new JCheckBox(b_customInside); this.customInside = new JCheckBox(b_customInside);
customInside.setText(trans.get(tr_insideOutside)); customInside.setText(trans.get(tr_insideOutside));
customInside.setToolTipText(trans.get(tr_insideOutside_ttip)); customInside.setToolTipText(trans.get(tr_insideOutside_ttip));
add(customInside, "wrap"); add(customInside, "span 2");
// Checkbox to set edges the same as inside/outside // Checkbox to set edges the same as inside/outside
BooleanModel b = new BooleanModel(!handler.isEdgesSameAsInside()); JPanel edgesPanel = new JPanel(new MigLayout());
edgesCheckbox = new JCheckBox(b); JLabel edgesText = new JLabel(trans.get("AppearanceCfg.lbl.AppearanceEdges"));
edgesCheckbox.setText(trans.get(tr_edges)); edgesPanel.add(edgesText);
edgesCheckbox.setToolTipText(trans.get(tr_edges_ttip)); String[] options = new String[] {trans.get(tr_outside), trans.get(tr_inside)};
edgesCheckbox.doClick(); JComboBox edgesComboBox = new JComboBox(options);
add(edgesCheckbox, "wrap"); if (handler.isEdgesSameAsInside()) {
edgesComboBox.setSelectedItem(trans.get(tr_inside));
}
else {
edgesComboBox.setSelectedItem(trans.get(tr_outside));
}
edgesPanel.add(edgesComboBox);
edgesPanel.setToolTipText(trans.get("AppearanceCfg.lbl.ttip.AppearanceEdges"));
add(edgesPanel, "span 2, wrap");
outsideInsidePane = new JTabbedPane(); outsideInsidePane = new JTabbedPane();
JPanel outsidePanel = new JPanel(new MigLayout("fill", "[150][grow][150][grow]")); JPanel outsidePanel = new JPanel(new MigLayout("fill", "[150][grow][150][grow]"));
@ -368,19 +371,11 @@ public class AppearancePanel extends JPanel {
"Inside Tool Tip"); "Inside Tool Tip");
add(outsideInsidePane, "span 4, growx, wrap"); add(outsideInsidePane, "span 4, growx, wrap");
edgesCheckbox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
handler.setEdgesSameAsInside(edgesCheckbox.isSelected());
c.fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
}
});
// Show the outside/inside tabbed display when customInside is selected // Show the outside/inside tabbed display when customInside is selected
customInside.addActionListener(new ActionListener() { customInside.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
handler.setInsideSameAsOutside(!customInside.isSelected()); handler.setSeparateInsideOutside(customInside.isSelected());
c.fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE); c.fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
if (customInside.isSelected()) { if (customInside.isSelected()) {
remove(outsidePanel); remove(outsidePanel);
@ -393,11 +388,32 @@ public class AppearancePanel extends JPanel {
remove(outsideInsidePane); remove(outsideInsidePane);
add(outsidePanel, "span 4, growx, wrap"); add(outsidePanel, "span 4, growx, wrap");
} }
edgesText.setEnabled(customInside.isSelected());
edgesComboBox.setEnabled(customInside.isSelected());
updateUI(); updateUI();
} }
}); });
// Change the edge appearance upon item selection
edgesComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (edgesComboBox.getSelectedItem() == null) return;
if (edgesComboBox.getSelectedItem().equals(trans.get(tr_outside))) {
handler.setEdgesSameAsInside(false);
}
else if (edgesComboBox.getSelectedItem().equals(trans.get(tr_inside))) {
handler.setEdgesSameAsInside(true);
}
else {
return;
}
c.fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
}
});
customInside.getActionListeners()[0].actionPerformed(null); customInside.getActionListeners()[0].actionPerformed(null);
edgesComboBox.getActionListeners()[0].actionPerformed(null);
} }
else else
appearanceSection(document, c, false, this); appearanceSection(document, c, false, this);

View File

@ -95,13 +95,17 @@ public class RealisticRenderer extends RocketRenderer {
Appearance app = getAppearance(c); Appearance app = getAppearance(c);
if (c instanceof InsideColorComponent) { if (c instanceof InsideColorComponent) {
Appearance innerApp = getInsideAppearance(c); Appearance innerApp = getInsideAppearance(c);
if (((InsideColorComponent) c).getInsideColorComponentHandler().isInsideSameAsOutside()) innerApp = app; if (!((InsideColorComponent) c).getInsideColorComponentHandler().isSeparateInsideOutside()) {
innerApp = app;
}
render(gl, geom, Surface.INSIDE, innerApp, true, alpha); render(gl, geom, Surface.INSIDE, innerApp, true, alpha);
if (((InsideColorComponent) c).getInsideColorComponentHandler().isEdgesSameAsInside()) if (((InsideColorComponent) c).getInsideColorComponentHandler().isEdgesSameAsInside()) {
render(gl, geom, Surface.EDGES, innerApp, true, alpha); render(gl, geom, Surface.EDGES, innerApp, true, alpha);
else }
else {
render(gl, geom, Surface.EDGES, app, true, alpha); render(gl, geom, Surface.EDGES, app, true, alpha);
}
} }
else { else {
render(gl, geom, Surface.INSIDE, app, true, alpha); render(gl, geom, Surface.INSIDE, app, true, alpha);