Create a simpler appearance builder for a simplified UI.
This commit is contained in:
parent
5a8833738c
commit
ee95d6998a
@ -0,0 +1,77 @@
|
|||||||
|
package net.sf.openrocket.appearance;
|
||||||
|
|
||||||
|
import net.sf.openrocket.util.Color;
|
||||||
|
|
||||||
|
public class SimpleAppearanceBuilder extends AppearanceBuilder {
|
||||||
|
|
||||||
|
public SimpleAppearanceBuilder() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleAppearanceBuilder(Appearance a) {
|
||||||
|
super(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color getColor() {
|
||||||
|
return getDiffuse();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColor(final Color c) {
|
||||||
|
batch(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
setAmbient(c);
|
||||||
|
setDiffuse(c);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShine(final int s) {
|
||||||
|
batch(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
setShininess(s);
|
||||||
|
int c = (int) (s * 2.55);
|
||||||
|
setSpecular(new net.sf.openrocket.util.Color(c, c, c));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getShine() {
|
||||||
|
return getShininess();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Color oldColor = null;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setImage(final String image) {
|
||||||
|
batch(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (getImage() == null && image != null) {
|
||||||
|
oldColor = getColor();
|
||||||
|
setColor(new Color(255, 255, 255));
|
||||||
|
} else if (getImage() != null && image == null && oldColor != null) {
|
||||||
|
setColor(oldColor);
|
||||||
|
}
|
||||||
|
SimpleAppearanceBuilder.super.setImage(image);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getScaleX() {
|
||||||
|
return 1.0 / super.getScaleU();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScaleX(double scaleU) {
|
||||||
|
super.setScaleU(1.0 / scaleU);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getScaleY() {
|
||||||
|
return 1.0 / super.getScaleV();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScaleY(double scaleV) {
|
||||||
|
super.setScaleV(1.0 / scaleV);
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@ import java.awt.event.ActionListener;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.EventObject;
|
import java.util.EventObject;
|
||||||
|
|
||||||
|
import javax.swing.DefaultBoundedRangeModel;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JCheckBox;
|
import javax.swing.JCheckBox;
|
||||||
import javax.swing.JColorChooser;
|
import javax.swing.JColorChooser;
|
||||||
@ -14,19 +15,21 @@ import javax.swing.JDialog;
|
|||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JSeparator;
|
import javax.swing.JSeparator;
|
||||||
|
import javax.swing.JSlider;
|
||||||
import javax.swing.JSpinner;
|
import javax.swing.JSpinner;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
|
import javax.swing.event.ChangeEvent;
|
||||||
|
import javax.swing.event.ChangeListener;
|
||||||
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
import net.sf.openrocket.appearance.AppearanceBuilder;
|
|
||||||
import net.sf.openrocket.appearance.Decal.EdgeMode;
|
import net.sf.openrocket.appearance.Decal.EdgeMode;
|
||||||
|
import net.sf.openrocket.appearance.SimpleAppearanceBuilder;
|
||||||
import net.sf.openrocket.document.OpenRocketDocument;
|
import net.sf.openrocket.document.OpenRocketDocument;
|
||||||
import net.sf.openrocket.gui.SpinnerEditor;
|
import net.sf.openrocket.gui.SpinnerEditor;
|
||||||
import net.sf.openrocket.gui.adaptors.BooleanModel;
|
import net.sf.openrocket.gui.adaptors.BooleanModel;
|
||||||
import net.sf.openrocket.gui.adaptors.DecalModel;
|
import net.sf.openrocket.gui.adaptors.DecalModel;
|
||||||
import net.sf.openrocket.gui.adaptors.DoubleModel;
|
import net.sf.openrocket.gui.adaptors.DoubleModel;
|
||||||
import net.sf.openrocket.gui.adaptors.EnumModel;
|
import net.sf.openrocket.gui.adaptors.EnumModel;
|
||||||
import net.sf.openrocket.gui.adaptors.IntegerModel;
|
|
||||||
import net.sf.openrocket.gui.components.BasicSlider;
|
import net.sf.openrocket.gui.components.BasicSlider;
|
||||||
import net.sf.openrocket.gui.components.ColorIcon;
|
import net.sf.openrocket.gui.components.ColorIcon;
|
||||||
import net.sf.openrocket.gui.components.StyledLabel;
|
import net.sf.openrocket.gui.components.StyledLabel;
|
||||||
@ -46,7 +49,7 @@ import net.sf.openrocket.util.StateChangeListener;
|
|||||||
public class AppearancePanel extends JPanel {
|
public class AppearancePanel extends JPanel {
|
||||||
private static final Translator trans = Application.getTranslator();
|
private static final Translator trans = Application.getTranslator();
|
||||||
|
|
||||||
private AppearanceBuilder ab;
|
private SimpleAppearanceBuilder ab;
|
||||||
|
|
||||||
private final static UnitGroup UNIT_FOR_SCALES = new UnitGroup();
|
private final static UnitGroup UNIT_FOR_SCALES = new UnitGroup();
|
||||||
static {
|
static {
|
||||||
@ -108,16 +111,19 @@ public class AppearancePanel extends JPanel {
|
|||||||
public AppearancePanel(final OpenRocketDocument document, final RocketComponent c) {
|
public AppearancePanel(final OpenRocketDocument document, final RocketComponent c) {
|
||||||
super(new MigLayout("fill", "[150][grow][150][grow]"));
|
super(new MigLayout("fill", "[150][grow][150][grow]"));
|
||||||
|
|
||||||
ab = new AppearanceBuilder(c.getAppearance());
|
ab = new SimpleAppearanceBuilder(c.getAppearance());
|
||||||
|
|
||||||
net.sf.openrocket.util.Color figureColor = c.getColor();
|
net.sf.openrocket.util.Color figureColor = c.getColor();
|
||||||
if (figureColor == null) {
|
if (figureColor == null) {
|
||||||
figureColor = Application.getPreferences().getDefaultColor(c.getClass());
|
figureColor = Application.getPreferences().getDefaultColor(c.getClass());
|
||||||
}
|
}
|
||||||
final JButton figureColorButton = new JButton(new ColorIcon(figureColor));
|
final JButton figureColorButton = new JButton(new ColorIcon(figureColor));
|
||||||
final JButton diffuseColorButton = new JButton(new ColorIcon(ab.getDiffuse()));
|
|
||||||
|
/*final JButton diffuseColorButton = new JButton(new ColorIcon(ab.getDiffuse()));
|
||||||
final JButton ambientColorButton = new JButton(new ColorIcon(ab.getAmbient()));
|
final JButton ambientColorButton = new JButton(new ColorIcon(ab.getAmbient()));
|
||||||
final JButton specularColorButton = new JButton(new ColorIcon(ab.getSpecular()));
|
final JButton specularColorButton = new JButton(new ColorIcon(ab.getSpecular()));*/
|
||||||
|
|
||||||
|
final JButton colorButton = new JButton(new ColorIcon(ab.getAmbient()));
|
||||||
|
|
||||||
final JComboBox textureDropDown = new JComboBox( new DecalModel(this,document,ab));;
|
final JComboBox textureDropDown = new JComboBox( new DecalModel(this,document,ab));;
|
||||||
|
|
||||||
@ -125,9 +131,10 @@ public class AppearancePanel extends JPanel {
|
|||||||
@Override
|
@Override
|
||||||
public void stateChanged(EventObject e) {
|
public void stateChanged(EventObject e) {
|
||||||
figureColorButton.setIcon(new ColorIcon(c.getColor()));
|
figureColorButton.setIcon(new ColorIcon(c.getColor()));
|
||||||
diffuseColorButton.setIcon(new ColorIcon(ab.getDiffuse()));
|
/*diffuseColorButton.setIcon(new ColorIcon(ab.getDiffuse()));
|
||||||
ambientColorButton.setIcon(new ColorIcon(ab.getAmbient()));
|
ambientColorButton.setIcon(new ColorIcon(ab.getAmbient()));
|
||||||
specularColorButton.setIcon(new ColorIcon(ab.getSpecular()));
|
specularColorButton.setIcon(new ColorIcon(ab.getSpecular()));*/
|
||||||
|
colorButton.setIcon(new ColorIcon(ab.getColor()));
|
||||||
c.setAppearance(ab.getAppearance());
|
c.setAppearance(ab.getAppearance());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -144,9 +151,10 @@ public class AppearancePanel extends JPanel {
|
|||||||
});
|
});
|
||||||
|
|
||||||
figureColorButton.addActionListener(new ColorActionListener(c, "Color"));
|
figureColorButton.addActionListener(new ColorActionListener(c, "Color"));
|
||||||
diffuseColorButton.addActionListener(new ColorActionListener(ab, "Diffuse"));
|
colorButton.addActionListener(new ColorActionListener(ab, "Color"));
|
||||||
|
/*diffuseColorButton.addActionListener(new ColorActionListener(ab, "Diffuse"));
|
||||||
ambientColorButton.addActionListener(new ColorActionListener(ab, "Ambient"));
|
ambientColorButton.addActionListener(new ColorActionListener(ab, "Ambient"));
|
||||||
specularColorButton.addActionListener(new ColorActionListener(ab, "Specular"));
|
specularColorButton.addActionListener(new ColorActionListener(ab, "Specular"));*/
|
||||||
|
|
||||||
BooleanModel mDefault = new BooleanModel(c.getAppearance() == null);
|
BooleanModel mDefault = new BooleanModel(c.getAppearance() == null);
|
||||||
BooleanModel fDefault = new BooleanModel(c.getColor() == null);
|
BooleanModel fDefault = new BooleanModel(c.getColor() == null);
|
||||||
@ -213,7 +221,7 @@ public class AppearancePanel extends JPanel {
|
|||||||
add(new JSeparator(SwingConstants.HORIZONTAL), "span, wrap, growx");
|
add(new JSeparator(SwingConstants.HORIZONTAL), "span, wrap, growx");
|
||||||
|
|
||||||
{// Texture Header Row
|
{// Texture Header Row
|
||||||
add(new StyledLabel(trans.get("AppearanceCfg.lbl.Appearance"), Style.BOLD));
|
add(new StyledLabel(trans.get("AppearanceCfg.lbl.Appearance"), Style.BOLD), "wrap");
|
||||||
|
|
||||||
final JCheckBox materialDefault = new JCheckBox(mDefault);
|
final JCheckBox materialDefault = new JCheckBox(mDefault);
|
||||||
materialDefault.addActionListener(new ActionListener() {
|
materialDefault.addActionListener(new ActionListener() {
|
||||||
@ -226,11 +234,6 @@ public class AppearancePanel extends JPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
materialDefault.setText(trans.get("AppearanceCfg.lbl.Usedefault"));
|
|
||||||
add(materialDefault);
|
|
||||||
JButton setMDefault = new JButton(trans.get("AppearanceCfg.but.savedefault"));
|
|
||||||
mDefault.addEnableComponent(setMDefault, false);
|
|
||||||
add(setMDefault, "span 2, align right, wrap");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{// Texture File
|
{// Texture File
|
||||||
@ -241,34 +244,49 @@ public class AppearancePanel extends JPanel {
|
|||||||
add(p, "span 3, growx, wrap");
|
add(p, "span 3, growx, wrap");
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // Diffuse
|
/*{ // Diffuse
|
||||||
add(new JLabel(trans.get("AppearanceCfg.lbl.color.diffuse")));
|
add(new JLabel(trans.get("AppearanceCfg.lbl.color.diffuse")));
|
||||||
mDefault.addEnableComponent(diffuseColorButton, false);
|
mDefault.addEnableComponent(diffuseColorButton, false);
|
||||||
add(diffuseColorButton);
|
add(diffuseColorButton);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
{ // Color
|
||||||
|
add(new JLabel("Color"));
|
||||||
|
mDefault.addEnableComponent(colorButton, false);
|
||||||
|
add(colorButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // Scale
|
{ // Scale
|
||||||
add(new JLabel(trans.get("AppearanceCfg.lbl.texture.scale")));
|
add(new JLabel(trans.get("AppearanceCfg.lbl.texture.scale")));
|
||||||
|
|
||||||
add(new JLabel("x:"), "split 4");
|
add(new JLabel("x:"), "split 4");
|
||||||
JSpinner scaleU = new JSpinner(new DoubleModel(ab, "ScaleU",UNIT_FOR_SCALES).getSpinnerModel());
|
JSpinner scaleU = new JSpinner(new DoubleModel(ab, "ScaleX",UNIT_FOR_SCALES).getSpinnerModel());
|
||||||
scaleU.setEditor(new SpinnerEditor(scaleU));
|
scaleU.setEditor(new SpinnerEditor(scaleU));
|
||||||
mDefault.addEnableComponent(scaleU, false);
|
mDefault.addEnableComponent(scaleU, false);
|
||||||
add(scaleU, "w 40");
|
add(scaleU, "w 40");
|
||||||
|
|
||||||
add(new JLabel("y:"));
|
add(new JLabel("y:"));
|
||||||
JSpinner scaleV = new JSpinner(new DoubleModel(ab, "ScaleV",UNIT_FOR_SCALES).getSpinnerModel());
|
JSpinner scaleV = new JSpinner(new DoubleModel(ab, "ScaleY",UNIT_FOR_SCALES).getSpinnerModel());
|
||||||
scaleV.setEditor(new SpinnerEditor(scaleV));
|
scaleV.setEditor(new SpinnerEditor(scaleV));
|
||||||
mDefault.addEnableComponent(scaleV, false);
|
mDefault.addEnableComponent(scaleV, false);
|
||||||
add(scaleV, "wrap, w 40");
|
add(scaleV, "wrap, w 40");
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // Ambient
|
{// Placeholder
|
||||||
add(new JLabel(trans.get("AppearanceCfg.lbl.color.ambient")));
|
add(new JLabel(trans.get("AppearanceCfg.lbl.shine")));
|
||||||
mDefault.addEnableComponent(ambientColorButton, false);
|
JSlider shine = new JSlider(new DefaultBoundedRangeModel(ab.getShine(), 0, 0, 100){{
|
||||||
add(ambientColorButton);
|
addChangeListener(new ChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void stateChanged(final ChangeEvent e) {
|
||||||
|
ab.setShine( ((DefaultBoundedRangeModel)e.getSource()).getValue());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}});
|
||||||
|
mDefault.addEnableComponent(shine, false);
|
||||||
|
add(shine, "w 100");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
{ // Offset
|
{ // Offset
|
||||||
add(new JLabel(trans.get("AppearanceCfg.lbl.texture.offset")));
|
add(new JLabel(trans.get("AppearanceCfg.lbl.texture.offset")));
|
||||||
|
|
||||||
@ -285,35 +303,15 @@ public class AppearancePanel extends JPanel {
|
|||||||
add(offsetV, "wrap, w 40");
|
add(offsetV, "wrap, w 40");
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // Specular
|
{ // Repeat
|
||||||
add(new JLabel(trans.get("AppearanceCfg.lbl.color.specular")));
|
add(new JLabel(trans.get("AppearanceCfg.lbl.texture.repeat")));
|
||||||
mDefault.addEnableComponent(specularColorButton, false);
|
EdgeMode[] list = new EdgeMode[EdgeMode.values().length + 1];
|
||||||
add(specularColorButton);
|
System.arraycopy(EdgeMode.values(), 0, list, 1, EdgeMode.values().length);
|
||||||
|
JComboBox combo = new JComboBox(new EnumModel<EdgeMode>(ab, "EdgeMode", list));
|
||||||
|
mDefault.addEnableComponent(combo, false);
|
||||||
|
add(combo);
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // Center
|
|
||||||
add(new JLabel(trans.get("AppearanceCfg.lbl.texture.center")));
|
|
||||||
|
|
||||||
add(new JLabel("x:"), "split 4");
|
|
||||||
JSpinner centerU = new JSpinner(new DoubleModel(ab, "CenterU").getSpinnerModel());
|
|
||||||
centerU.setEditor(new SpinnerEditor(centerU));
|
|
||||||
mDefault.addEnableComponent(centerU, false);
|
|
||||||
add(centerU, "w 40");
|
|
||||||
|
|
||||||
add(new JLabel("y:"));
|
|
||||||
JSpinner centerV = new JSpinner(new DoubleModel(ab, "CenterV").getSpinnerModel());
|
|
||||||
centerV.setEditor(new SpinnerEditor(centerV));
|
|
||||||
mDefault.addEnableComponent(centerV, false);
|
|
||||||
add(centerV, "wrap, w 40");
|
|
||||||
}
|
|
||||||
|
|
||||||
{ // Shine
|
|
||||||
add(new JLabel(trans.get("AppearanceCfg.lbl.shine")));
|
|
||||||
IntegerModel shineModel = new IntegerModel(ab, "Shininess", 0, 128);
|
|
||||||
JSpinner shine = new JSpinner(shineModel.getSpinnerModel());
|
|
||||||
mDefault.addEnableComponent(shine, false);
|
|
||||||
add(shine, "w 50");
|
|
||||||
}
|
|
||||||
|
|
||||||
{ // Rotation
|
{ // Rotation
|
||||||
add(new JLabel(trans.get("AppearanceCfg.lbl.texture.rotation")));
|
add(new JLabel(trans.get("AppearanceCfg.lbl.texture.rotation")));
|
||||||
@ -328,18 +326,6 @@ public class AppearancePanel extends JPanel {
|
|||||||
add(bs, "w 100, wrap");
|
add(bs, "w 100, wrap");
|
||||||
}
|
}
|
||||||
|
|
||||||
{// Placeholder
|
|
||||||
add(new JLabel(""), "span 2");
|
|
||||||
}
|
|
||||||
|
|
||||||
{ // Repeat
|
|
||||||
add(new JLabel(trans.get("AppearanceCfg.lbl.texture.repeat")));
|
|
||||||
EdgeMode[] list = new EdgeMode[EdgeMode.values().length + 1];
|
|
||||||
System.arraycopy(EdgeMode.values(), 0, list, 1, EdgeMode.values().length);
|
|
||||||
JComboBox combo = new JComboBox(new EnumModel<EdgeMode>(ab, "EdgeMode", list));
|
|
||||||
mDefault.addEnableComponent(combo, false);
|
|
||||||
add(combo);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user