Modified the AppearancePanel decal selector to have a combo box which follows the ComponentPreset pattern. The first entry in the combo box contains "none" entry which clears the decal associated with the component. The last entry in the combo box is "choose from file" which opens a file picker to select an image from the file system. The entries in between contain all the decals currently used by components in the document which facilitates reusing decals on the model.
This commit is contained in:
parent
bdca67fb7a
commit
4cdf1e8e87
86
core/src/net/sf/openrocket/gui/adaptors/DecalModel.java
Normal file
86
core/src/net/sf/openrocket/gui/adaptors/DecalModel.java
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
package net.sf.openrocket.gui.adaptors;
|
||||||
|
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import javax.swing.AbstractListModel;
|
||||||
|
import javax.swing.ComboBoxModel;
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
|
import net.sf.openrocket.appearance.AppearanceBuilder;
|
||||||
|
import net.sf.openrocket.document.OpenRocketDocument;
|
||||||
|
import net.sf.openrocket.l10n.Translator;
|
||||||
|
import net.sf.openrocket.startup.Application;
|
||||||
|
|
||||||
|
public class DecalModel extends AbstractListModel implements ComboBoxModel {
|
||||||
|
|
||||||
|
private static final Translator trans = Application.getTranslator();
|
||||||
|
|
||||||
|
private static final String NONE_SELECTED = trans.get("lbl.select");
|
||||||
|
private static final String SELECT_FILE = trans.get("lbl.choose");
|
||||||
|
|
||||||
|
private final Component parent;
|
||||||
|
private final AppearanceBuilder ab;
|
||||||
|
|
||||||
|
private File lastImageDir = null;
|
||||||
|
|
||||||
|
private String[] decals;
|
||||||
|
|
||||||
|
public DecalModel(Component parent, OpenRocketDocument document, AppearanceBuilder ab) {
|
||||||
|
this.parent = parent;
|
||||||
|
this.ab = ab;
|
||||||
|
decals = document.getDecalList().toArray( new String[0] );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSize() {
|
||||||
|
return decals.length + 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getElementAt(int index) {
|
||||||
|
if (index == 0) {
|
||||||
|
return NONE_SELECTED;
|
||||||
|
}
|
||||||
|
if (index == getSize() - 1) {
|
||||||
|
return SELECT_FILE;
|
||||||
|
}
|
||||||
|
return decals[index-1];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSelectedItem(Object item) {
|
||||||
|
|
||||||
|
if (item == null || item.equals(NONE_SELECTED)) {
|
||||||
|
ab.setImage(null);
|
||||||
|
} else if (item.equals(SELECT_FILE)) {
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
File current = lastImageDir;
|
||||||
|
lastImageDir = current;
|
||||||
|
|
||||||
|
JFileChooser fc = new JFileChooser(current);
|
||||||
|
int action = fc.showOpenDialog(SwingUtilities.getWindowAncestor(parent));
|
||||||
|
if ( action == JFileChooser.APPROVE_OPTION) {
|
||||||
|
setSelectedItem(fc.getSelectedFile().getAbsolutePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
ab.setImage( (String) item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getSelectedItem() {
|
||||||
|
String name = ab.getImage();
|
||||||
|
if (name == null) {
|
||||||
|
return NONE_SELECTED;
|
||||||
|
} else {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -3,7 +3,6 @@ package net.sf.openrocket.gui.configdialog;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.io.File;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.EventObject;
|
import java.util.EventObject;
|
||||||
|
|
||||||
@ -12,19 +11,19 @@ import javax.swing.JCheckBox;
|
|||||||
import javax.swing.JColorChooser;
|
import javax.swing.JColorChooser;
|
||||||
import javax.swing.JComboBox;
|
import javax.swing.JComboBox;
|
||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
import javax.swing.JFileChooser;
|
|
||||||
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.JSpinner;
|
import javax.swing.JSpinner;
|
||||||
import javax.swing.JTextField;
|
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
import net.sf.openrocket.appearance.AppearanceBuilder;
|
import net.sf.openrocket.appearance.AppearanceBuilder;
|
||||||
import net.sf.openrocket.appearance.Decal.EdgeMode;
|
import net.sf.openrocket.appearance.Decal.EdgeMode;
|
||||||
|
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.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.adaptors.IntegerModel;
|
||||||
@ -47,8 +46,6 @@ public class AppearancePanel extends JPanel {
|
|||||||
|
|
||||||
private AppearanceBuilder ab;
|
private AppearanceBuilder ab;
|
||||||
|
|
||||||
private static File lastImageDir = null;
|
|
||||||
|
|
||||||
private static final JColorChooser colorChooser = new JColorChooser();
|
private static final JColorChooser colorChooser = new JColorChooser();
|
||||||
|
|
||||||
private class ColorActionListener implements ActionListener {
|
private class ColorActionListener implements ActionListener {
|
||||||
@ -89,7 +86,7 @@ public class AppearancePanel extends JPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public AppearancePanel(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 AppearanceBuilder(c.getAppearance());
|
||||||
@ -103,8 +100,7 @@ public class AppearancePanel extends JPanel {
|
|||||||
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 JTextField uriTextField = new JTextField(ab.getImage() != null ? ab.getImage().toString() : "");
|
final JComboBox textureDropDown = new JComboBox( new DecalModel(this,document,ab));;
|
||||||
uriTextField.setEditable(false);
|
|
||||||
|
|
||||||
ab.addChangeListener(new StateChangeListener() {
|
ab.addChangeListener(new StateChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -114,7 +110,6 @@ public class AppearancePanel extends JPanel {
|
|||||||
ambientColorButton.setIcon(new ColorIcon(ab.getAmbient()));
|
ambientColorButton.setIcon(new ColorIcon(ab.getAmbient()));
|
||||||
specularColorButton.setIcon(new ColorIcon(ab.getSpecular()));
|
specularColorButton.setIcon(new ColorIcon(ab.getSpecular()));
|
||||||
c.setAppearance(ab.getAppearance());
|
c.setAppearance(ab.getAppearance());
|
||||||
uriTextField.setText(ab.getImage() != null ? ab.getImage().toString() : "");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -220,27 +215,11 @@ public class AppearancePanel extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{// Texture File
|
{// Texture File
|
||||||
JButton choose;
|
|
||||||
add(new JLabel(trans.get("AppearanceCfg.lbl.Texture")));
|
add(new JLabel(trans.get("AppearanceCfg.lbl.Texture")));
|
||||||
JPanel p = new JPanel(new MigLayout("fill, ins 0", "[grow][]"));
|
JPanel p = new JPanel(new MigLayout("fill, ins 0", "[grow][]"));
|
||||||
p.add(uriTextField, "grow");
|
mDefault.addEnableComponent(textureDropDown, false);
|
||||||
p.add(choose = new JButton(trans.get("AppearanceCfg.lbl.Choose")));
|
p.add(textureDropDown, "grow");
|
||||||
mDefault.addEnableComponent(uriTextField, false);
|
|
||||||
mDefault.addEnableComponent(choose, false);
|
|
||||||
add(p, "span 3, growx, wrap");
|
add(p, "span 3, growx, wrap");
|
||||||
choose.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
File current = lastImageDir;
|
|
||||||
lastImageDir = current;
|
|
||||||
|
|
||||||
JFileChooser fc = new JFileChooser(current);
|
|
||||||
if (fc.showOpenDialog(AppearancePanel.this) == JFileChooser.APPROVE_OPTION) {
|
|
||||||
ab.setImage(fc.getSelectedFile().getAbsolutePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // Diffuse
|
{ // Diffuse
|
||||||
@ -344,5 +323,5 @@ public class AppearancePanel extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ public class RocketComponentConfig extends JPanel {
|
|||||||
if (component.isMassive())
|
if (component.isMassive())
|
||||||
|
|
||||||
//// Appearance options
|
//// Appearance options
|
||||||
tabbedPane.addTab("Appearance", null, new AppearancePanel(component),
|
tabbedPane.addTab("Appearance", null, new AppearancePanel(document,component),
|
||||||
"Appearance Tool Tip");
|
"Appearance Tool Tip");
|
||||||
|
|
||||||
//// Comment and Specify a comment for the component
|
//// Comment and Specify a comment for the component
|
||||||
|
Loading…
x
Reference in New Issue
Block a user