Add Edit Decal dialog available from Appearance tab. Added preference
to control which editor is opened.
This commit is contained in:
parent
56be31cfd2
commit
177d40104e
@ -250,6 +250,7 @@ pref.dlg.tab.Materials = Materials
|
||||
pref.dlg.tab.Custommaterials = Custom materials
|
||||
pref.dlg.tab.Options = Options
|
||||
pref.dlg.tab.Miscellaneousoptions = Miscellaneous options
|
||||
pref.dlg.tab.DecalEditor = Graphics Editor
|
||||
pref.dlg.lbl.Positiontoinsert = Position to insert new body components:
|
||||
pref.dlg.lbl.Confirmdeletion = Confirm deletion of simulations:
|
||||
pref.dlg.lbl.User-definedthrust = User-defined thrust curves:
|
||||
@ -722,6 +723,7 @@ MotorDbLoadDlg.Loadingmotors = Loading motors...
|
||||
! AppearanceConfig
|
||||
AppearanceCfg.lbl.Appearance = Appearance
|
||||
AppearanceCfg.lbl.Usedefault = Use default
|
||||
AppearanceCfg.but.edit = Edit
|
||||
AppearanceCfg.but.savedefault = Save as default appearance
|
||||
AppearanceCfg.lbl.Texture = Texture:
|
||||
AppearanceCfg.lbl.shine = Shine:
|
||||
@ -1802,4 +1804,14 @@ table.column.LineCount = Line Count
|
||||
table.column.LineLength = Line Length
|
||||
table.column.LineMaterial = Line Material
|
||||
|
||||
! Edit Decal Dialog
|
||||
EditDecalDialog.title = Edit decal
|
||||
EditDecalDialog.lbl.prompt = Show Prompt
|
||||
EditDecalDialog.lbl.select = Select Editor
|
||||
EditDecalDialog.lbl.system = Use Default Editor
|
||||
EditDecalDialog.lbl.cmdline = Command Line
|
||||
EditDecalDialog.lbl.cmdline.help = The filename will be subsituted for ''%%''
|
||||
EditDecalDialog.lbl.always = Always use these settings
|
||||
EditDecalDialog.btn.chooser = Select Graphics Editor Program
|
||||
|
||||
|
||||
|
@ -23,7 +23,7 @@ public class DecalModel extends AbstractListModel implements ComboBoxModel {
|
||||
private final Component parent;
|
||||
private final AppearanceBuilder ab;
|
||||
|
||||
private File lastImageDir = null;
|
||||
private static File lastImageDir = null;
|
||||
|
||||
private String[] decals;
|
||||
|
||||
|
@ -3,6 +3,7 @@ package net.sf.openrocket.gui.configdialog;
|
||||
import java.awt.Color;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.EventObject;
|
||||
|
||||
@ -17,6 +18,7 @@ import javax.swing.JSeparator;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.JSpinner;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import net.sf.openrocket.appearance.Decal.EdgeMode;
|
||||
@ -34,6 +36,7 @@ import net.sf.openrocket.gui.components.StyledLabel;
|
||||
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.gui.util.EditDecalHelper;
|
||||
import net.sf.openrocket.gui.util.SwingPreferences;
|
||||
import net.sf.openrocket.l10n.Translator;
|
||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||
@ -41,6 +44,7 @@ import net.sf.openrocket.startup.Application;
|
||||
import net.sf.openrocket.unit.GeneralUnit;
|
||||
import net.sf.openrocket.unit.Unit;
|
||||
import net.sf.openrocket.unit.UnitGroup;
|
||||
import net.sf.openrocket.util.BugException;
|
||||
import net.sf.openrocket.util.LineStyle;
|
||||
import net.sf.openrocket.util.StateChangeListener;
|
||||
|
||||
@ -220,6 +224,27 @@ public class AppearancePanel extends JPanel {
|
||||
JPanel p = new JPanel(new MigLayout("fill, ins 0", "[grow][]"));
|
||||
p.add(textureDropDown, "grow");
|
||||
add(p, "span 3, growx, wrap");
|
||||
final JButton editBtn = new JButton(trans.get("AppearanceCfg.but.edit"));
|
||||
editBtn.setEnabled( ab.getImage() != null );
|
||||
ab.addChangeListener(new StateChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(EventObject e) {
|
||||
editBtn.setEnabled(ab.getImage() == null);
|
||||
}
|
||||
});
|
||||
editBtn.addActionListener( new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
EditDecalHelper.editDecal(SwingUtilities.getWindowAncestor(AppearancePanel.this), document, ab.getImage());
|
||||
} catch (IOException ex) {
|
||||
throw new BugException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
p.add(editBtn);
|
||||
}
|
||||
|
||||
{ // Color
|
||||
|
175
core/src/net/sf/openrocket/gui/dialogs/EditDecalDialog.java
Normal file
175
core/src/net/sf/openrocket/gui/dialogs/EditDecalDialog.java
Normal file
@ -0,0 +1,175 @@
|
||||
package net.sf.openrocket.gui.dialogs;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import net.sf.openrocket.gui.util.GUIUtil;
|
||||
import net.sf.openrocket.l10n.Translator;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
|
||||
public class EditDecalDialog extends JDialog {
|
||||
|
||||
private static final Translator trans = Application.getTranslator();
|
||||
|
||||
private JRadioButton systemRadio;
|
||||
private JRadioButton commandRadio;
|
||||
private JTextArea commandText;
|
||||
|
||||
private JCheckBox savePref;
|
||||
|
||||
private boolean isCancel = false;
|
||||
|
||||
public EditDecalDialog(final Window owner) {
|
||||
super(owner, trans.get("EditDecalDialog.title"), Dialog.ModalityType.APPLICATION_MODAL);
|
||||
|
||||
JPanel panel = new JPanel(new MigLayout("fill, ins para"));
|
||||
|
||||
JLabel selectLbl = new JLabel(trans.get("EditDecalDialog.lbl.select"));
|
||||
panel.add(selectLbl, "gapright, wrap");
|
||||
|
||||
ButtonGroup execGroup = new ButtonGroup();
|
||||
|
||||
if (Desktop.getDesktop().isSupported(Desktop.Action.EDIT) ) {
|
||||
|
||||
systemRadio = new JRadioButton(trans.get("EditDecalDialog.lbl.system"));
|
||||
systemRadio.setSelected(false);
|
||||
panel.add(systemRadio,"wrap");
|
||||
execGroup.add(systemRadio);
|
||||
|
||||
commandRadio = new JRadioButton(trans.get("EditDecalDialog.lbl.cmdline"));
|
||||
commandRadio.setSelected(false);
|
||||
panel.add(commandRadio,"wrap");
|
||||
execGroup.add(commandRadio);
|
||||
|
||||
commandText = new JTextArea();
|
||||
commandText.setEnabled(false);
|
||||
panel.add(commandText, "growx, wrap");
|
||||
|
||||
final JButton chooser = new JButton(trans.get("EditDecalDialog.btn.chooser"));
|
||||
chooser.setEnabled(false);
|
||||
chooser.addActionListener( new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JFileChooser fc = new JFileChooser();
|
||||
int action = fc.showOpenDialog(owner);
|
||||
if ( action == JFileChooser.APPROVE_OPTION) {
|
||||
commandText.setText(fc.getSelectedFile().getAbsolutePath());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
panel.add(chooser, "growx, wrap");
|
||||
|
||||
|
||||
commandRadio.addChangeListener( new ChangeListener() {
|
||||
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
boolean enabled = commandRadio.isSelected();
|
||||
commandText.setEnabled(enabled);
|
||||
chooser.setEnabled(enabled);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
} else {
|
||||
commandText = new JTextArea();
|
||||
commandText.setEnabled(false);
|
||||
panel.add(commandText, "growx, wrap");
|
||||
|
||||
final JButton chooser = new JButton(trans.get("EditDecalDialog.btn.chooser"));
|
||||
chooser.setEnabled(false);
|
||||
chooser.addActionListener( new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JFileChooser fc = new JFileChooser();
|
||||
int action = fc.showOpenDialog(owner);
|
||||
if ( action == JFileChooser.APPROVE_OPTION) {
|
||||
commandText.setText(fc.getSelectedFile().getAbsolutePath());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
panel.add(chooser, "growx, wrap");
|
||||
|
||||
}
|
||||
|
||||
savePref = new JCheckBox(trans.get("EditDecalDialog.lbl.always"));
|
||||
panel.add(savePref,"wrap");
|
||||
|
||||
// OK / Cancel buttons
|
||||
JButton okButton = new JButton(trans.get("dlg.but.ok"));
|
||||
okButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ok();
|
||||
}
|
||||
});
|
||||
panel.add(okButton, "tag ok, spanx, split");
|
||||
|
||||
//// Cancel button
|
||||
JButton cancelButton = new JButton(trans.get("dlg.but.cancel"));
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
close();
|
||||
}
|
||||
});
|
||||
panel.add(cancelButton, "tag cancel");
|
||||
|
||||
this.add(panel);
|
||||
|
||||
GUIUtil.rememberWindowSize(this);
|
||||
GUIUtil.setDisposableDialogOptions(this, okButton);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public boolean isCancel() {
|
||||
return isCancel;
|
||||
}
|
||||
|
||||
public boolean isSavePreferences() {
|
||||
return savePref.isSelected();
|
||||
}
|
||||
|
||||
public boolean isUseSystemEditor() {
|
||||
return systemRadio!= null && systemRadio.isSelected();
|
||||
}
|
||||
|
||||
public String getCommandLine() {
|
||||
return commandText.getText();
|
||||
}
|
||||
|
||||
public void ok() {
|
||||
isCancel = false;
|
||||
this.setVisible(false);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
isCancel = true;
|
||||
this.setVisible(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
package net.sf.openrocket.gui.dialogs.preferences;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.File;
|
||||
@ -13,6 +16,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.swing.AbstractListModel;
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.ComboBoxModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
@ -23,9 +27,14 @@ import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.Timer;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
|
||||
@ -37,8 +46,8 @@ import net.sf.openrocket.gui.components.StyledLabel;
|
||||
import net.sf.openrocket.gui.components.StyledLabel.Style;
|
||||
import net.sf.openrocket.gui.dialogs.UpdateInfoDialog;
|
||||
import net.sf.openrocket.gui.util.GUIUtil;
|
||||
import net.sf.openrocket.gui.util.SwingPreferences;
|
||||
import net.sf.openrocket.gui.util.SimpleFileFilter;
|
||||
import net.sf.openrocket.gui.util.SwingPreferences;
|
||||
import net.sf.openrocket.l10n.L10N;
|
||||
import net.sf.openrocket.l10n.Translator;
|
||||
import net.sf.openrocket.logging.LogHelper;
|
||||
@ -58,6 +67,8 @@ public class PreferencesDialog extends JDialog {
|
||||
|
||||
private File defaultDirectory = null;
|
||||
private static final Translator trans = Application.getTranslator();
|
||||
|
||||
private final SwingPreferences preferences = (SwingPreferences) Application.getPreferences();
|
||||
|
||||
private PreferencesDialog(Window parent) {
|
||||
//// Preferences
|
||||
@ -77,7 +88,9 @@ public class PreferencesDialog extends JDialog {
|
||||
//// Options and Miscellaneous options
|
||||
tabbedPane.addTab(trans.get("pref.dlg.tab.Options"), null, optionsPane(),
|
||||
trans.get("pref.dlg.tab.Miscellaneousoptions"));
|
||||
|
||||
//// Decal Editor selection
|
||||
tabbedPane.addTab(trans.get("pref.dlg.tab.DecalEditor"), decalEditorPane());
|
||||
|
||||
//// Close button
|
||||
JButton close = new JButton(trans.get("dlg.but.close"));
|
||||
close.addActionListener(new ActionListener() {
|
||||
@ -96,7 +109,7 @@ public class PreferencesDialog extends JDialog {
|
||||
this.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosed(WindowEvent e) {
|
||||
((SwingPreferences) Application.getPreferences()).storeDefaultUnits();
|
||||
preferences.storeDefaultUnits();
|
||||
}
|
||||
});
|
||||
|
||||
@ -111,7 +124,7 @@ public class PreferencesDialog extends JDialog {
|
||||
//// Language selector
|
||||
Locale userLocale = null;
|
||||
{
|
||||
String locale = Application.getPreferences().getString("locale", null);
|
||||
String locale = preferences.getString("locale", null);
|
||||
userLocale = L10N.toLocale(locale);
|
||||
}
|
||||
List<Named<Locale>> locales = new ArrayList<Named<Locale>>();
|
||||
@ -133,7 +146,7 @@ public class PreferencesDialog extends JDialog {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Named<Locale> selection = (Named<Locale>) languageCombo.getSelectedItem();
|
||||
Locale l = selection.get();
|
||||
Application.getPreferences().putString(Preferences.USER_LOCAL, l == null ? null : l.toString());
|
||||
preferences.putString(Preferences.USER_LOCAL, l == null ? null : l.toString());
|
||||
}
|
||||
});
|
||||
panel.add(new JLabel(trans.get("lbl.language")), "gapright para");
|
||||
@ -163,7 +176,7 @@ public class PreferencesDialog extends JDialog {
|
||||
//// User-defined thrust curves:
|
||||
panel.add(new JLabel(trans.get("pref.dlg.lbl.User-definedthrust")), "spanx, wrap");
|
||||
final JTextField field = new JTextField();
|
||||
List<File> files = ((SwingPreferences) Application.getPreferences()).getUserThrustCurveFiles();
|
||||
List<File> files = preferences.getUserThrustCurveFiles();
|
||||
String str = "";
|
||||
for (File file : files) {
|
||||
if (str.length() > 0) {
|
||||
@ -197,7 +210,7 @@ public class PreferencesDialog extends JDialog {
|
||||
list.add(new File(s));
|
||||
}
|
||||
}
|
||||
((SwingPreferences) Application.getPreferences()).setUserThrustCurveFiles(list);
|
||||
preferences.setUserThrustCurveFiles(list);
|
||||
}
|
||||
});
|
||||
panel.add(field, "w 100px, gapright unrel, spanx, growx, split");
|
||||
@ -252,8 +265,8 @@ public class PreferencesDialog extends JDialog {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// First one sets to the default, but does not un-set the pref
|
||||
field.setText(((SwingPreferences)Application.getPreferences()).getDefaultUserThrustCurveFile().getAbsolutePath());
|
||||
((SwingPreferences) Application.getPreferences()).setUserThrustCurveFiles(null);
|
||||
field.setText(preferences.getDefaultUserThrustCurveFile().getAbsolutePath());
|
||||
preferences.setUserThrustCurveFiles(null);
|
||||
}
|
||||
});
|
||||
panel.add(button, "wrap");
|
||||
@ -268,11 +281,11 @@ public class PreferencesDialog extends JDialog {
|
||||
//// Check for software updates at startup
|
||||
final JCheckBox softwareUpdateBox =
|
||||
new JCheckBox(trans.get("pref.dlg.checkbox.Checkupdates"));
|
||||
softwareUpdateBox.setSelected( Application.getPreferences().getCheckUpdates());
|
||||
softwareUpdateBox.setSelected( preferences.getCheckUpdates());
|
||||
softwareUpdateBox.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Application.getPreferences().setCheckUpdates(softwareUpdateBox.isSelected());
|
||||
preferences.setCheckUpdates(softwareUpdateBox.isSelected());
|
||||
}
|
||||
});
|
||||
panel.add(softwareUpdateBox);
|
||||
@ -290,17 +303,17 @@ public class PreferencesDialog extends JDialog {
|
||||
panel.add(button, "right, wrap");
|
||||
|
||||
|
||||
final JCheckBox autoOpenDesignFile = new JCheckBox(trans.get("pref.dlg.but.openlast"));
|
||||
autoOpenDesignFile.setSelected(Application.getPreferences().isAutoOpenLastDesignOnStartupEnabled());
|
||||
autoOpenDesignFile.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Application.getPreferences().setAutoOpenLastDesignOnStartup(autoOpenDesignFile.isSelected());
|
||||
}
|
||||
});
|
||||
panel.add(autoOpenDesignFile);
|
||||
final JCheckBox autoOpenDesignFile = new JCheckBox(trans.get("pref.dlg.but.openlast"));
|
||||
autoOpenDesignFile.setSelected(preferences.isAutoOpenLastDesignOnStartupEnabled());
|
||||
autoOpenDesignFile.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
preferences.setAutoOpenLastDesignOnStartup(autoOpenDesignFile.isSelected());
|
||||
}
|
||||
});
|
||||
panel.add(autoOpenDesignFile);
|
||||
|
||||
return panel;
|
||||
return panel;
|
||||
}
|
||||
|
||||
private JPanel unitsPane() {
|
||||
@ -456,6 +469,105 @@ public class PreferencesDialog extends JDialog {
|
||||
}
|
||||
|
||||
|
||||
private JPanel decalEditorPane() {
|
||||
|
||||
JPanel panel = new JPanel(new MigLayout("fillx, ins 30lp n n n"));
|
||||
|
||||
ButtonGroup execGroup = new ButtonGroup();
|
||||
|
||||
JRadioButton showPrompt = new JRadioButton(trans.get("EditDecalDialog.lbl.prompt"));
|
||||
showPrompt.setSelected(!preferences.isDecalEditorPreferenceSet());
|
||||
showPrompt.addItemListener( new ItemListener() {
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
if ( ((JRadioButton) e.getItem()).isSelected() ) {
|
||||
preferences.clearDecalEditorPreference();
|
||||
}
|
||||
}
|
||||
});
|
||||
panel.add(showPrompt,"wrap");
|
||||
execGroup.add(showPrompt);
|
||||
|
||||
if (Desktop.getDesktop().isSupported(Desktop.Action.EDIT) ) {
|
||||
|
||||
JRadioButton systemRadio = new JRadioButton(trans.get("EditDecalDialog.lbl.system"));
|
||||
systemRadio.setSelected( preferences.isDecalEditorPreferenceSystem() );
|
||||
systemRadio.addItemListener( new ItemListener() {
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
if ( ((JRadioButton) e.getItem()).isSelected() ) {
|
||||
preferences.setDecalEditorPreference(true, null);
|
||||
}
|
||||
}
|
||||
});
|
||||
panel.add(systemRadio,"wrap");
|
||||
execGroup.add(systemRadio);
|
||||
|
||||
}
|
||||
|
||||
boolean commandLineIsSelected = preferences.isDecalEditorPreferenceSet() && ! preferences.isDecalEditorPreferenceSystem();
|
||||
final JRadioButton commandRadio = new JRadioButton(trans.get("EditDecalDialog.lbl.cmdline"));
|
||||
commandRadio.setSelected(commandLineIsSelected);
|
||||
panel.add(commandRadio,"wrap");
|
||||
execGroup.add(commandRadio);
|
||||
|
||||
final JTextArea commandText = new JTextArea();
|
||||
commandText.setEnabled(commandLineIsSelected);
|
||||
commandText.setText( commandLineIsSelected ? preferences.getDecalEditorCommandLine() : "" );
|
||||
commandText.getDocument().addDocumentListener( new DocumentListener() {
|
||||
|
||||
@Override
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
preferences.setDecalEditorPreference(false, commandText.getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUpdate(DocumentEvent e) {
|
||||
preferences.setDecalEditorPreference(false, commandText.getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
preferences.setDecalEditorPreference(false, commandText.getText());
|
||||
}
|
||||
|
||||
});
|
||||
panel.add(commandText, "growx, wrap");
|
||||
|
||||
final JButton chooser = new JButton(trans.get("EditDecalDialog.btn.chooser"));
|
||||
chooser.setEnabled(commandLineIsSelected);
|
||||
chooser.addActionListener( new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JFileChooser fc = new JFileChooser();
|
||||
int action = fc.showOpenDialog(SwingUtilities.windowForComponent(PreferencesDialog.this));
|
||||
if ( action == JFileChooser.APPROVE_OPTION) {
|
||||
String commandLine = fc.getSelectedFile().getAbsolutePath();
|
||||
commandText.setText(commandLine);
|
||||
preferences.setDecalEditorPreference(false, commandLine);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
panel.add(chooser, "growx, wrap");
|
||||
|
||||
|
||||
commandRadio.addChangeListener( new ChangeListener() {
|
||||
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
boolean enabled = commandRadio.isSelected();
|
||||
commandText.setEnabled(enabled);
|
||||
chooser.setEnabled(enabled);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -514,7 +626,7 @@ public class PreferencesDialog extends JDialog {
|
||||
|
||||
@Override
|
||||
public Object getSelectedItem() {
|
||||
return descriptions[Application.getPreferences().getChoice(preference, descriptions.length, 0)];
|
||||
return descriptions[preferences.getChoice(preference, descriptions.length, 0)];
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -535,7 +647,7 @@ public class PreferencesDialog extends JDialog {
|
||||
throw new IllegalArgumentException("Illegal argument " + item);
|
||||
}
|
||||
|
||||
Application.getPreferences().putChoice(preference, index);
|
||||
preferences.putChoice(preference, index);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -565,7 +677,7 @@ public class PreferencesDialog extends JDialog {
|
||||
|
||||
@Override
|
||||
public Object getSelectedItem() {
|
||||
if (Application.getPreferences().getBoolean(preference, def)) {
|
||||
if (preferences.getBoolean(preference, def)) {
|
||||
return trueDesc;
|
||||
} else {
|
||||
return falseDesc;
|
||||
@ -583,9 +695,9 @@ public class PreferencesDialog extends JDialog {
|
||||
}
|
||||
|
||||
if (trueDesc.equals(item)) {
|
||||
Application.getPreferences().putBoolean(preference, true);
|
||||
preferences.putBoolean(preference, true);
|
||||
} else if (falseDesc.equals(item)) {
|
||||
Application.getPreferences().putBoolean(preference, false);
|
||||
preferences.putBoolean(preference, false);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Illegal argument " + item);
|
||||
}
|
||||
@ -683,9 +795,9 @@ public class PreferencesDialog extends JDialog {
|
||||
UpdateInfoDialog infoDialog = new UpdateInfoDialog(info);
|
||||
infoDialog.setVisible(true);
|
||||
if (infoDialog.isReminderSelected()) {
|
||||
Application.getPreferences().putString(SwingPreferences.LAST_UPDATE, "");
|
||||
preferences.putString(SwingPreferences.LAST_UPDATE, "");
|
||||
} else {
|
||||
Application.getPreferences().putString(SwingPreferences.LAST_UPDATE, info.getLatestVersion());
|
||||
preferences.putString(SwingPreferences.LAST_UPDATE, info.getLatestVersion());
|
||||
}
|
||||
}
|
||||
|
||||
|
94
core/src/net/sf/openrocket/gui/util/EditDecalHelper.java
Normal file
94
core/src/net/sf/openrocket/gui/util/EditDecalHelper.java
Normal file
@ -0,0 +1,94 @@
|
||||
package net.sf.openrocket.gui.util;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.awt.Window;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.gui.dialogs.EditDecalDialog;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
|
||||
public class EditDecalHelper {
|
||||
|
||||
// FIXME - need to have a specific set of localizable exceptions come out of this instead of generic IOException;
|
||||
// perhaps - unable to create file,
|
||||
// unable to open system editor
|
||||
// unable to fork process
|
||||
|
||||
private static final SwingPreferences prefs = ((SwingPreferences)Application.getPreferences());
|
||||
|
||||
public static void editDecal( Window parent, OpenRocketDocument document, String decalId ) throws IOException {
|
||||
|
||||
// Create Temp File.
|
||||
int dotlocation = decalId.lastIndexOf('.');
|
||||
String extension = "tmp";
|
||||
if ( dotlocation > 0 && dotlocation < decalId.length() ) {
|
||||
extension = decalId.substring(dotlocation);
|
||||
}
|
||||
File tmpFile = File.createTempFile("OR_graphics", extension);
|
||||
|
||||
document.getDecalRegistry().exportDecal(decalId, tmpFile);
|
||||
|
||||
//First Check preferences
|
||||
if ( prefs.isDecalEditorPreferenceSet() ) {
|
||||
|
||||
// FIXME - need this one or all dialog.
|
||||
|
||||
if ( prefs.isDecalEditorPreferenceSystem() ) {
|
||||
launchSystemEditor( tmpFile );
|
||||
} else {
|
||||
String commandTemplate = prefs.getDecalEditorCommandLine();
|
||||
launchCommandEditor(commandTemplate, tmpFile);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Preference not set, launch dialog
|
||||
EditDecalDialog dialog = new EditDecalDialog(parent);
|
||||
dialog.setVisible(true);
|
||||
|
||||
if( dialog.isCancel() ) {
|
||||
// FIXME - delete tmpfile?
|
||||
return;
|
||||
}
|
||||
|
||||
boolean saveToPrefs = dialog.isSavePreferences();
|
||||
|
||||
if ( dialog.isUseSystemEditor() ) {
|
||||
if ( saveToPrefs ) {
|
||||
prefs.setDecalEditorPreference(true, null);
|
||||
}
|
||||
launchSystemEditor( tmpFile );
|
||||
} else {
|
||||
String commandLine = dialog.getCommandLine();
|
||||
if( saveToPrefs ) {
|
||||
prefs.setDecalEditorPreference(false, commandLine);
|
||||
}
|
||||
launchCommandEditor( commandLine, tmpFile );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void launchSystemEditor( File tmpFile ) throws IOException {
|
||||
|
||||
Desktop.getDesktop().edit(tmpFile);
|
||||
|
||||
}
|
||||
|
||||
private static void launchCommandEditor( String commandTemplate, File tmpFile ) throws IOException {
|
||||
|
||||
String filename = tmpFile.getAbsolutePath();
|
||||
|
||||
String command;
|
||||
if( commandTemplate.contains("%%")) {
|
||||
command = commandTemplate.replace("%%", filename);
|
||||
} else {
|
||||
command = commandTemplate + " " + filename;
|
||||
}
|
||||
|
||||
Runtime.getRuntime().exec(command);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -573,7 +573,9 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences {
|
||||
|
||||
return materials;
|
||||
}
|
||||
|
||||
|
||||
//// Preset Component Favorites
|
||||
|
||||
@Override
|
||||
public void setComponentFavorite(ComponentPreset preset, ComponentPreset.Type type, boolean favorite) {
|
||||
Preferences prefs = PREFNODE.node("favoritePresets").node(type.name());
|
||||
@ -595,6 +597,35 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences {
|
||||
}
|
||||
return collection;
|
||||
}
|
||||
//// Helper methods
|
||||
|
||||
//// Decal Editor Setting
|
||||
private final static String DECAL_EDITOR_PREFERNCE_NODE = "decalEditorPreference";
|
||||
private final static String DECAL_EDITOR_USE_SYSTEM_DEFAULT = "<SYSTEM>";
|
||||
|
||||
public void clearDecalEditorPreference( ) {
|
||||
putString(DECAL_EDITOR_PREFERNCE_NODE,null);
|
||||
}
|
||||
public void setDecalEditorPreference(boolean useSystem, String commandLine) {
|
||||
if ( useSystem ) {
|
||||
putString(DECAL_EDITOR_PREFERNCE_NODE,DECAL_EDITOR_USE_SYSTEM_DEFAULT);
|
||||
} else if ( commandLine != null ) {
|
||||
putString(DECAL_EDITOR_PREFERNCE_NODE, commandLine);
|
||||
} else {
|
||||
clearDecalEditorPreference();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDecalEditorPreferenceSet() {
|
||||
String s = getString(DECAL_EDITOR_PREFERNCE_NODE,null);
|
||||
return s != null;
|
||||
}
|
||||
|
||||
public boolean isDecalEditorPreferenceSystem() {
|
||||
String s = getString(DECAL_EDITOR_PREFERNCE_NODE,null);
|
||||
return DECAL_EDITOR_USE_SYSTEM_DEFAULT.equals(s);
|
||||
}
|
||||
public String getDecalEditorCommandLine() {
|
||||
return getString(DECAL_EDITOR_PREFERNCE_NODE,null);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user