[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.rotation = Rotation:
AppearanceCfg.lbl.texture.repeat = Repeat:
AppearanceCfg.lbl.InsideSameAsOutside = Use separate appearance for outside and inside
AppearanceCfg.lbl.LeftSideSameAsRightSide = Use separate appearance for left and right side(s)
AppearanceCfg.lbl.ttip.InsideSameAsOutside = Use a separate appearance for outside and inside
AppearanceCfg.lbl.ttip.LeftSideSameAsRightSide = Use a separate appearance for left and right side(s)
AppearanceCfg.lbl.EdgesSameAsInside = Use inside appearance for edges
AppearanceCfg.lbl.EdgesSameAsRightSide = Use right side appearance for 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
AppearanceCfg.lbl.separateInsideOutside = Use separate appearance for outside and inside
AppearanceCfg.lbl.separateLeftSideRightSide = Use separate appearance for left and right side(s)
AppearanceCfg.lbl.ttip.separateInsideOutside = Use a separate appearance for outside and inside
AppearanceCfg.lbl.ttip.separateLeftSideRightSide = Use a separate appearance for left and right side(s)
AppearanceCfg.lbl.AppearanceEdges = Appearance for edges:
AppearanceCfg.lbl.ttip.AppearanceEdges = Select the appearance that should be used for the edges
! Texture Wrap Modes
TextureWrap.Repeat = Repeat

View File

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

View File

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

View File

@ -14,7 +14,7 @@ import java.util.EventObject;
public class InsideColorComponentHandler {
private final RocketComponent component;
private Appearance insideAppearance = null;
private boolean insideSameAsOutside = true;
private boolean separateInsideOutside = false; // Flag for separate inside and outside appearance
private boolean edgesSameAsInside = true;
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
* outside (return false)
* Checks whether the component should use a separate appearance for the inside and outside.
*
* @return true if edges should use the same appearance as the inside,
* false if edges should use the same appearance as the outside
* @return true if a separate inside and outside appearance should be used,
* false if the inside should have the outside appearance
*/
public boolean isInsideSameAsOutside() {
return this.insideSameAsOutside;
public boolean isSeparateInsideOutside() {
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) {
this.insideSameAsOutside = newState;
public void setSeparateInsideOutside(boolean newState) {
this.separateInsideOutside = newState;
}
}

View File

@ -81,7 +81,6 @@ public class AppearancePanel extends JPanel {
private Appearance defaultAppearance = null;
private JTabbedPane outsideInsidePane = null;
private JCheckBox edgesCheckbox = null;
private JCheckBox customInside = null;
@ -322,38 +321,42 @@ public class AppearancePanel extends JPanel {
InsideColorComponentHandler handler = ((InsideColorComponent)c).getInsideColorComponentHandler();
// 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) {
tr_outside = "RocketCompCfg.tab.LeftSide";
tr_inside = "RocketCompCfg.tab.RightSide";
tr_edges = "AppearanceCfg.lbl.EdgesSameAsRightSide";
tr_edges_ttip = "AppearanceCfg.lbl.ttip.EdgesSameAsRightSide";
tr_insideOutside = "AppearanceCfg.lbl.LeftSideSameAsRightSide";
tr_insideOutside_ttip = "AppearanceCfg.lbl.ttip.LeftSideSameAsRightSide";
tr_insideOutside = "AppearanceCfg.lbl.separateLeftSideRightSide";
tr_insideOutside_ttip = "AppearanceCfg.lbl.ttip.separateLeftSideRightSide";
}
else {
tr_outside = "RocketCompCfg.tab.Outside";
tr_inside = "RocketCompCfg.tab.Inside";
tr_edges = "AppearanceCfg.lbl.EdgesSameAsInside";
tr_edges_ttip = "AppearanceCfg.lbl.ttip.EdgesSameAsInside";
tr_insideOutside = "AppearanceCfg.lbl.InsideSameAsOutside";
tr_insideOutside_ttip = "AppearanceCfg.lbl.ttip.InsideSameAsOutside";
tr_insideOutside = "AppearanceCfg.lbl.separateInsideOutside";
tr_insideOutside_ttip = "AppearanceCfg.lbl.ttip.separateInsideOutside";
}
// 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);
customInside.setText(trans.get(tr_insideOutside));
customInside.setToolTipText(trans.get(tr_insideOutside_ttip));
add(customInside, "wrap");
add(customInside, "span 2");
// Checkbox to set edges the same as inside/outside
BooleanModel b = new BooleanModel(!handler.isEdgesSameAsInside());
edgesCheckbox = new JCheckBox(b);
edgesCheckbox.setText(trans.get(tr_edges));
edgesCheckbox.setToolTipText(trans.get(tr_edges_ttip));
edgesCheckbox.doClick();
add(edgesCheckbox, "wrap");
JPanel edgesPanel = new JPanel(new MigLayout());
JLabel edgesText = new JLabel(trans.get("AppearanceCfg.lbl.AppearanceEdges"));
edgesPanel.add(edgesText);
String[] options = new String[] {trans.get(tr_outside), trans.get(tr_inside)};
JComboBox edgesComboBox = new JComboBox(options);
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();
JPanel outsidePanel = new JPanel(new MigLayout("fill", "[150][grow][150][grow]"));
@ -368,19 +371,11 @@ public class AppearancePanel extends JPanel {
"Inside Tool Tip");
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
customInside.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
handler.setInsideSameAsOutside(!customInside.isSelected());
handler.setSeparateInsideOutside(customInside.isSelected());
c.fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
if (customInside.isSelected()) {
remove(outsidePanel);
@ -393,11 +388,32 @@ public class AppearancePanel extends JPanel {
remove(outsideInsidePane);
add(outsidePanel, "span 4, growx, wrap");
}
edgesText.setEnabled(customInside.isSelected());
edgesComboBox.setEnabled(customInside.isSelected());
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);
edgesComboBox.getActionListeners()[0].actionPerformed(null);
}
else
appearanceSection(document, c, false, this);

View File

@ -95,13 +95,17 @@ public class RealisticRenderer extends RocketRenderer {
Appearance app = getAppearance(c);
if (c instanceof InsideColorComponent) {
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);
if (((InsideColorComponent) c).getInsideColorComponentHandler().isEdgesSameAsInside())
if (((InsideColorComponent) c).getInsideColorComponentHandler().isEdgesSameAsInside()) {
render(gl, geom, Surface.EDGES, innerApp, true, alpha);
else
}
else {
render(gl, geom, Surface.EDGES, app, true, alpha);
}
}
else {
render(gl, geom, Surface.INSIDE, app, true, alpha);