Add file chooser.
This commit is contained in:
parent
f466729fe0
commit
3a9b843c9a
@ -1,23 +1,27 @@
|
||||
package net.sf.openrocket.gui.configdialog;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.EventListener;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.EventObject;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JColorChooser;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.JSpinner;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import net.sf.openrocket.appearance.Appearance;
|
||||
import net.sf.openrocket.appearance.AppearanceBuilder;
|
||||
import net.sf.openrocket.appearance.Decal.EdgeMode;
|
||||
import net.sf.openrocket.gui.SpinnerEditor;
|
||||
@ -28,15 +32,13 @@ import net.sf.openrocket.gui.adaptors.IntegerModel;
|
||||
import net.sf.openrocket.gui.components.BasicSlider;
|
||||
import net.sf.openrocket.gui.components.ColorIcon;
|
||||
import net.sf.openrocket.gui.components.StyledLabel;
|
||||
import net.sf.openrocket.gui.components.UnitSelector;
|
||||
import net.sf.openrocket.gui.components.StyledLabel.Style;
|
||||
import net.sf.openrocket.gui.components.UnitSelector;
|
||||
import net.sf.openrocket.gui.util.ColorConversion;
|
||||
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 java.awt.Color;
|
||||
import net.sf.openrocket.util.LineStyle;
|
||||
import net.sf.openrocket.util.StateChangeListener;
|
||||
|
||||
public class AppearancePanel extends JPanel {
|
||||
@ -44,6 +46,8 @@ public class AppearancePanel extends JPanel {
|
||||
|
||||
private AppearanceBuilder ab;
|
||||
|
||||
private static File lastImageDir = null;
|
||||
|
||||
private class ColorActionListener implements ActionListener {
|
||||
private final String valueName;
|
||||
private final Object o;
|
||||
@ -90,6 +94,9 @@ public class AppearancePanel extends JPanel {
|
||||
final JButton ambientColorButton = new JButton(new ColorIcon(ab.getAmbient()));
|
||||
final JButton specularColorButton = new JButton(new ColorIcon(ab.getSpecular()));
|
||||
|
||||
final JTextField uriTextField = new JTextField(ab.getImage() != null ? ab.getImage().toString() : "");
|
||||
uriTextField.setEditable(false);
|
||||
|
||||
ab.addChangeListener(new StateChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(EventObject e) {
|
||||
@ -98,6 +105,7 @@ public class AppearancePanel extends JPanel {
|
||||
ambientColorButton.setIcon(new ColorIcon(ab.getAmbient()));
|
||||
specularColorButton.setIcon(new ColorIcon(ab.getSpecular()));
|
||||
c.setAppearance(ab.getAppearance());
|
||||
uriTextField.setText(ab.getImage() != null ? ab.getImage().toString() : "");
|
||||
}
|
||||
});
|
||||
|
||||
@ -113,31 +121,80 @@ public class AppearancePanel extends JPanel {
|
||||
ambientColorButton.addActionListener(new ColorActionListener(ab, "Ambient"));
|
||||
specularColorButton.addActionListener(new ColorActionListener(ab, "Specular"));
|
||||
|
||||
BooleanModel mDefault = new BooleanModel(false);
|
||||
|
||||
{// Style Header Row
|
||||
add(new StyledLabel("Figure Style", Style.BOLD));
|
||||
add(new JCheckBox(), "split 2");
|
||||
add(new JLabel("Use default"));
|
||||
add(new JButton("Set Default"), "span 2, align right, wrap");
|
||||
}
|
||||
|
||||
{// Figure Color
|
||||
add(new JLabel("Figure Color:"));
|
||||
add(figureColorButton);
|
||||
}
|
||||
|
||||
{// Line Style
|
||||
add(new JLabel("Line Style:"));
|
||||
add(new JLabel("[Default Style [v]]"), "wrap");
|
||||
}
|
||||
|
||||
add(new JSeparator(SwingConstants.HORIZONTAL), "span, wrap, growx");
|
||||
|
||||
BooleanModel mDefault = new BooleanModel(false);
|
||||
|
||||
{// Texture Header Row
|
||||
add(new StyledLabel("Appearance", Style.BOLD));
|
||||
add(new JCheckBox(mDefault), "split 2");
|
||||
add(new JLabel("Use default"));
|
||||
JButton setMDefault = new JButton("Set Default");
|
||||
mDefault.addEnableComponent(setMDefault, false);
|
||||
add(setMDefault, "span 2, align right, wrap");
|
||||
}
|
||||
|
||||
{// Texture File
|
||||
JButton choose;
|
||||
add(new JLabel("Texture:"));
|
||||
add(new JLabel("[Filename]"));
|
||||
JPanel p = new JPanel(new MigLayout("fill, ins 0", "[grow][]"));
|
||||
p.add(uriTextField, "grow");
|
||||
p.add(choose = new JButton("Choose"));
|
||||
mDefault.addEnableComponent(uriTextField, false);
|
||||
mDefault.addEnableComponent(choose, false);
|
||||
add(p, "span 3, growx, wrap");
|
||||
choose.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
URL u = ab.getImage();
|
||||
File current = lastImageDir;
|
||||
if (u != null && u.getProtocol().equals("file")) {
|
||||
try {
|
||||
current = new File(u.toURI()).getParentFile();
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
lastImageDir = current;
|
||||
|
||||
JFileChooser fc = new JFileChooser(current);
|
||||
if (fc.showOpenDialog(AppearancePanel.this) == JFileChooser.APPROVE_OPTION) {
|
||||
try {
|
||||
ab.setImage(fc.getSelectedFile().toURI().toURL());
|
||||
} catch (MalformedURLException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
{ // Diffuse
|
||||
add(new JLabel("Diffuse Color:"));
|
||||
mDefault.addEnableComponent(diffuseColorButton, false);
|
||||
add(diffuseColorButton);
|
||||
}
|
||||
|
||||
{ // Scale
|
||||
add(new JLabel("Scale:"));
|
||||
|
||||
add(new JLabel("x:"), "split 4");
|
||||
@ -151,11 +208,15 @@ public class AppearancePanel extends JPanel {
|
||||
scaleV.setEditor(new SpinnerEditor(scaleV));
|
||||
mDefault.addEnableComponent(scaleV, false);
|
||||
add(scaleV, "wrap, w 40");
|
||||
}
|
||||
|
||||
add(new JLabel("Diffuse Color:"));
|
||||
mDefault.addEnableComponent(diffuseColorButton, false);
|
||||
add(diffuseColorButton);
|
||||
{ // Ambient
|
||||
add(new JLabel("Ambient Color:"));
|
||||
mDefault.addEnableComponent(ambientColorButton, false);
|
||||
add(ambientColorButton);
|
||||
}
|
||||
|
||||
{ // Offset
|
||||
add(new JLabel("Offset:"));
|
||||
|
||||
add(new JLabel("x:"), "split 4");
|
||||
@ -169,11 +230,15 @@ public class AppearancePanel extends JPanel {
|
||||
offsetV.setEditor(new SpinnerEditor(offsetV));
|
||||
mDefault.addEnableComponent(offsetV, false);
|
||||
add(offsetV, "wrap, w 40");
|
||||
}
|
||||
|
||||
add(new JLabel("Ambient Color:"));
|
||||
mDefault.addEnableComponent(ambientColorButton, false);
|
||||
add(ambientColorButton);
|
||||
{ // Specular
|
||||
add(new JLabel("Specular Color:"));
|
||||
mDefault.addEnableComponent(specularColorButton, false);
|
||||
add(specularColorButton);
|
||||
}
|
||||
|
||||
{ // Center
|
||||
add(new JLabel("Center:"));
|
||||
|
||||
add(new JLabel("x:"), "split 4");
|
||||
@ -187,11 +252,17 @@ public class AppearancePanel extends JPanel {
|
||||
centerV.setEditor(new SpinnerEditor(centerV));
|
||||
mDefault.addEnableComponent(centerV, false);
|
||||
add(centerV, "wrap, w 40");
|
||||
}
|
||||
|
||||
add(new JLabel("Specular Color:"));
|
||||
mDefault.addEnableComponent(specularColorButton, false);
|
||||
add(specularColorButton);
|
||||
{ // Shine
|
||||
add(new JLabel("Shine:"));
|
||||
IntegerModel shineModel = new IntegerModel(ab, "Shininess", 0, 128);
|
||||
JSpinner shine = new JSpinner(shineModel.getSpinnerModel());
|
||||
mDefault.addEnableComponent(shine, false);
|
||||
add(shine, "w 50");
|
||||
}
|
||||
|
||||
{ // Rotation
|
||||
add(new JLabel("Rotation:"));
|
||||
DoubleModel rotationModel = new DoubleModel(ab, "Rotation", UnitGroup.UNITS_ANGLE);
|
||||
JSpinner rotation = new JSpinner(rotationModel.getSpinnerModel());
|
||||
@ -202,20 +273,20 @@ public class AppearancePanel extends JPanel {
|
||||
BasicSlider bs = new BasicSlider(rotationModel.getSliderModel(-Math.PI, Math.PI));
|
||||
mDefault.addEnableComponent(bs, false);
|
||||
add(bs, "w 100, wrap");
|
||||
}
|
||||
|
||||
{// Placeholder
|
||||
add(new JLabel(""), "span 2");
|
||||
}
|
||||
|
||||
add(new JLabel("Shine:"));
|
||||
IntegerModel shineModel = new IntegerModel(ab, "Shininess", 0, 128);
|
||||
JSpinner shine = new JSpinner(shineModel.getSpinnerModel());
|
||||
mDefault.addEnableComponent(shine, false);
|
||||
add(shine, "w 40");
|
||||
|
||||
{ // Repeat
|
||||
add(new JLabel("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