Constrain preset editor on existing files to only use populated Materials; minor other cleanup.
This commit is contained in:
parent
00696ce7a3
commit
ed629bd227
@ -5,3 +5,7 @@ Spiral/Glassine,lb/ft3,53,,,,1,1,1,1,0,1,0,0,1,1,1,1,1,1,,,,,,,,None,0,0
|
|||||||
Fiber,lb/ft3,41,,,,1,0,0,0,0,0,0,0,0,1,1,0,0,0,,,,,,,,None,0,0
|
Fiber,lb/ft3,41,,,,1,0,0,0,0,0,0,0,0,1,1,0,0,0,,,,,,,,None,0,0
|
||||||
lite ply,lb/ft3,22,,,Composite,1,0,1,0,0,0,0,0,0,1,1,1,0,0,,,,,,,,None,0,0
|
lite ply,lb/ft3,22,,,Composite,1,0,1,0,0,0,0,0,0,1,1,1,0,0,,,,,,,,None,0,0
|
||||||
Paper,lb/ft3,70,,,,1,1,1,1,0,1,0,1,1,1,1,1,1,1,,,,,,,,None,0,0
|
Paper,lb/ft3,70,,,,1,1,1,1,0,1,0,1,1,1,1,1,1,1,,,,,,,,None,0,0
|
||||||
|
Polyethylene LDPE,lb/ft3,57.7,,,,1,0,0,0,0,0,1,1,0,0,0,0,0,0,,,,,,,,None,0,0
|
||||||
|
Rip stop nylon,g/cm2,0.006685,,,,1,0,0,0,0,0,1,1,0,0,0,0,0,0,,,,,,,,None,0,0
|
||||||
|
30 Lb. kevlar,g/cm,0.00178,,,,1,0,0,0,1,0,0,0,0,0,0,0,0,0,,,,,,,,None,0,0
|
||||||
|
1/16 In. braided nylon,g/cm,0.0102,,,,1,0,0,0,1,0,0,0,0,0,0,0,0,0,,,,,,,,None,0,0
|
||||||
|
|||||||
|
@ -60,12 +60,12 @@ public class ComponentPresetEditor extends JPanel implements PresetResultListene
|
|||||||
/**
|
/**
|
||||||
* State variable to keep track of which file was opened, in case it needs to be saved back to that file.
|
* State variable to keep track of which file was opened, in case it needs to be saved back to that file.
|
||||||
*/
|
*/
|
||||||
private File openedFile = null;
|
// private File openedFile = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Last directory; file chooser is set here so user doesn't have to keep navigating to a common area.
|
* Last directory; file chooser is set here so user doesn't have to keep navigating to a common area.
|
||||||
*/
|
*/
|
||||||
private File lastDirectory = null;
|
// private File lastDirectory = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The table of presets.
|
* The table of presets.
|
||||||
@ -80,7 +80,9 @@ public class ComponentPresetEditor extends JPanel implements PresetResultListene
|
|||||||
/**
|
/**
|
||||||
* Flag that indicates if an existing Preset is currently being edited.
|
* Flag that indicates if an existing Preset is currently being edited.
|
||||||
*/
|
*/
|
||||||
private boolean editingSelected = false;
|
// private boolean editingSelected = false;
|
||||||
|
|
||||||
|
private final OpenedFileContext editContext = new OpenedFileContext();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
trans = new ResourceBundleTranslator("l10n.messages");
|
trans = new ResourceBundleTranslator("l10n.messages");
|
||||||
@ -131,8 +133,9 @@ public class ComponentPresetEditor extends JPanel implements PresetResultListene
|
|||||||
else {
|
else {
|
||||||
if (e.getClickCount() == 2) {
|
if (e.getClickCount() == 2) {
|
||||||
int row = target.getSelectedRow();
|
int row = target.getSelectedRow();
|
||||||
editingSelected = true;
|
editContext.setEditingSelected(true);
|
||||||
new PresetEditorDialog(ComponentPresetEditor.this, (ComponentPreset) model.getAssociatedObject(row)).setVisible(true);
|
new PresetEditorDialog(ComponentPresetEditor.this,
|
||||||
|
(ComponentPreset) model.getAssociatedObject(row), editContext.getMaterialsLoaded()).setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -216,7 +219,7 @@ public class ComponentPresetEditor extends JPanel implements PresetResultListene
|
|||||||
addBtn.addMouseListener(new MouseAdapter() {
|
addBtn.addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent arg0) {
|
public void mouseClicked(MouseEvent arg0) {
|
||||||
editingSelected = false;
|
editContext.setEditingSelected(false);
|
||||||
new PresetEditorDialog(ComponentPresetEditor.this).setVisible(true);
|
new PresetEditorDialog(ComponentPresetEditor.this).setVisible(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -237,7 +240,7 @@ public class ComponentPresetEditor extends JPanel implements PresetResultListene
|
|||||||
//Is this a new preset?
|
//Is this a new preset?
|
||||||
String description = preset.has(ComponentPreset.DESCRIPTION) ? preset.get(ComponentPreset.DESCRIPTION) :
|
String description = preset.has(ComponentPreset.DESCRIPTION) ? preset.get(ComponentPreset.DESCRIPTION) :
|
||||||
preset.getPartNo();
|
preset.getPartNo();
|
||||||
if (!editingSelected) {
|
if (!editContext.isEditingSelected()|| table.getSelectedRow() == -1) {
|
||||||
model.addRow(new Object[]{preset.getManufacturer().getDisplayName(), preset.getType().name(),
|
model.addRow(new Object[]{preset.getManufacturer().getDisplayName(), preset.getType().name(),
|
||||||
preset.getPartNo(), description, Icons.EDIT_DELETE}, preset);
|
preset.getPartNo(), description, Icons.EDIT_DELETE}, preset);
|
||||||
}
|
}
|
||||||
@ -251,7 +254,7 @@ public class ComponentPresetEditor extends JPanel implements PresetResultListene
|
|||||||
model.associated.set(row, preset);
|
model.associated.set(row, preset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
editingSelected = false;
|
editContext.setEditingSelected(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -331,8 +334,8 @@ public class ComponentPresetEditor extends JPanel implements PresetResultListene
|
|||||||
chooser.addChoosableFileFilter(FileHelper.CSV_FILE_FILTER);
|
chooser.addChoosableFileFilter(FileHelper.CSV_FILE_FILTER);
|
||||||
chooser.setFileFilter(FileHelper.OPEN_ROCKET_COMPONENT_FILTER);
|
chooser.setFileFilter(FileHelper.OPEN_ROCKET_COMPONENT_FILTER);
|
||||||
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
|
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
|
||||||
if (lastDirectory != null) {
|
if (editContext.getLastDirectory() != null) {
|
||||||
chooser.setCurrentDirectory(lastDirectory);
|
chooser.setCurrentDirectory(editContext.getLastDirectory());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
chooser.setCurrentDirectory(((SwingPreferences) Application.getPreferences()).getDefaultDirectory());
|
chooser.setCurrentDirectory(((SwingPreferences) Application.getPreferences()).getDefaultDirectory());
|
||||||
@ -340,7 +343,7 @@ public class ComponentPresetEditor extends JPanel implements PresetResultListene
|
|||||||
|
|
||||||
int option = chooser.showOpenDialog(ComponentPresetEditor.this);
|
int option = chooser.showOpenDialog(ComponentPresetEditor.this);
|
||||||
if (option != JFileChooser.APPROVE_OPTION) {
|
if (option != JFileChooser.APPROVE_OPTION) {
|
||||||
openedFile = null;
|
editContext.setOpenedFile(null);
|
||||||
log.user("User decided not to open, option=" + option);
|
log.user("User decided not to open, option=" + option);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -352,7 +355,8 @@ public class ComponentPresetEditor extends JPanel implements PresetResultListene
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastDirectory = file.getParentFile();
|
editContext.setLastDirectory(file.getParentFile());
|
||||||
|
editContext.setMaterialsLoaded(null);
|
||||||
List<ComponentPreset> presets = null;
|
List<ComponentPreset> presets = null;
|
||||||
|
|
||||||
if (file.getName().toLowerCase().endsWith(".orc")) {
|
if (file.getName().toLowerCase().endsWith(".orc")) {
|
||||||
@ -364,19 +368,20 @@ public class ComponentPresetEditor extends JPanel implements PresetResultListene
|
|||||||
}
|
}
|
||||||
presets = new ArrayList<ComponentPreset>();
|
presets = new ArrayList<ComponentPreset>();
|
||||||
MaterialHolder materialHolder = RocksimComponentFileTranslator.loadAll(presets, file);
|
MaterialHolder materialHolder = RocksimComponentFileTranslator.loadAll(presets, file);
|
||||||
|
editContext.setMaterialsLoaded(materialHolder);
|
||||||
}
|
}
|
||||||
if (presets != null) {
|
if (presets != null) {
|
||||||
for (ComponentPreset next : presets) {
|
for (ComponentPreset next : presets) {
|
||||||
notifyResult(next);
|
notifyResult(next);
|
||||||
}
|
}
|
||||||
openedFile = file;
|
editContext.setOpenedFile(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
|
||||||
JOptionPane.showMessageDialog(ComponentPresetEditor.this, "Unable to open OpenRocket component file: " +
|
JOptionPane.showMessageDialog(ComponentPresetEditor.this, "Unable to open OpenRocket component file: " +
|
||||||
file.getName() + " Invalid format. " + e.getMessage());
|
file.getName() + " Invalid format. " + e.getMessage());
|
||||||
openedFile = null;
|
editContext.setOpenedFile(null);
|
||||||
|
editContext.setEditingSelected(false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -408,8 +413,8 @@ public class ComponentPresetEditor extends JPanel implements PresetResultListene
|
|||||||
chooser.addChoosableFileFilter(FileHelper.OPEN_ROCKET_COMPONENT_FILTER);
|
chooser.addChoosableFileFilter(FileHelper.OPEN_ROCKET_COMPONENT_FILTER);
|
||||||
|
|
||||||
chooser.setFileFilter(FileHelper.OPEN_ROCKET_COMPONENT_FILTER);
|
chooser.setFileFilter(FileHelper.OPEN_ROCKET_COMPONENT_FILTER);
|
||||||
if (openedFile != null) {
|
if (editContext.getOpenedFile() != null) {
|
||||||
chooser.setSelectedFile(openedFile);
|
chooser.setSelectedFile(editContext.getOpenedFile());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
chooser.setCurrentDirectory(((SwingPreferences) Application.getPreferences()).getDefaultDirectory());
|
chooser.setCurrentDirectory(((SwingPreferences) Application.getPreferences()).getDefaultDirectory());
|
||||||
@ -444,4 +449,56 @@ public class ComponentPresetEditor extends JPanel implements PresetResultListene
|
|||||||
|
|
||||||
return FileHelper.confirmWrite(file, this) && new OpenRocketComponentSaver().save(file, materials, presets);
|
return FileHelper.confirmWrite(file, this) && new OpenRocketComponentSaver().save(file, materials, presets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class OpenedFileContext {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* State variable to keep track of which file was opened, in case it needs to be saved back to that file.
|
||||||
|
*/
|
||||||
|
private File openedFile = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Last directory; file chooser is set here so user doesn't have to keep navigating to a common area.
|
||||||
|
*/
|
||||||
|
private File lastDirectory = null;
|
||||||
|
|
||||||
|
private boolean editingSelected = false;
|
||||||
|
|
||||||
|
private MaterialHolder materialsLoaded = null;
|
||||||
|
|
||||||
|
OpenedFileContext() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getOpenedFile() {
|
||||||
|
return openedFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOpenedFile(final File theOpenedFile) {
|
||||||
|
openedFile = theOpenedFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getLastDirectory() {
|
||||||
|
return lastDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastDirectory(final File theLastDirectory) {
|
||||||
|
lastDirectory = theLastDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEditingSelected() {
|
||||||
|
return editingSelected;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEditingSelected(final boolean theEditingSelected) {
|
||||||
|
editingSelected = theEditingSelected;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MaterialHolder getMaterialsLoaded() {
|
||||||
|
return materialsLoaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaterialsLoaded(final MaterialHolder theMaterialsLoaded) {
|
||||||
|
materialsLoaded = theMaterialsLoaded;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import net.sf.openrocket.database.Databases;
|
|||||||
import net.sf.openrocket.gui.dialogs.CustomMaterialDialog;
|
import net.sf.openrocket.gui.dialogs.CustomMaterialDialog;
|
||||||
import net.sf.openrocket.l10n.Translator;
|
import net.sf.openrocket.l10n.Translator;
|
||||||
import net.sf.openrocket.material.Material;
|
import net.sf.openrocket.material.Material;
|
||||||
|
import net.sf.openrocket.preset.loader.MaterialHolder;
|
||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
|
|
||||||
import javax.swing.DefaultComboBoxModel;
|
import javax.swing.DefaultComboBoxModel;
|
||||||
@ -27,9 +28,16 @@ public class MaterialModel extends DefaultComboBoxModel implements DatabaseListe
|
|||||||
|
|
||||||
private Component parent;
|
private Component parent;
|
||||||
|
|
||||||
public MaterialModel(Component theParent, Material.Type type) {
|
public MaterialModel(Component theParent, Material.Type theType, Database<Material> materials) {
|
||||||
parent = theParent;
|
parent = theParent;
|
||||||
this.type = type;
|
type = theType;
|
||||||
|
database = materials;
|
||||||
|
database.addDatabaseListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MaterialModel(Component theParent, Material.Type theType) {
|
||||||
|
parent = theParent;
|
||||||
|
type = theType;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case LINE:
|
case LINE:
|
||||||
@ -123,4 +131,8 @@ public class MaterialModel extends DefaultComboBoxModel implements DatabaseListe
|
|||||||
public Material.Type getType() {
|
public Material.Type getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeListener() {
|
||||||
|
database.removeChangeListener(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,12 +11,15 @@ import net.sf.openrocket.motor.Manufacturer;
|
|||||||
import net.sf.openrocket.preset.ComponentPreset;
|
import net.sf.openrocket.preset.ComponentPreset;
|
||||||
import net.sf.openrocket.preset.ComponentPresetFactory;
|
import net.sf.openrocket.preset.ComponentPresetFactory;
|
||||||
import net.sf.openrocket.preset.InvalidComponentPresetException;
|
import net.sf.openrocket.preset.InvalidComponentPresetException;
|
||||||
|
import net.sf.openrocket.preset.TypedKey;
|
||||||
import net.sf.openrocket.preset.TypedPropertyMap;
|
import net.sf.openrocket.preset.TypedPropertyMap;
|
||||||
|
import net.sf.openrocket.preset.loader.MaterialHolder;
|
||||||
import net.sf.openrocket.rocketcomponent.Transition;
|
import net.sf.openrocket.rocketcomponent.Transition;
|
||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
import net.sf.openrocket.unit.UnitGroup;
|
import net.sf.openrocket.unit.UnitGroup;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.swing.ComboBoxModel;
|
||||||
import javax.swing.DefaultComboBoxModel;
|
import javax.swing.DefaultComboBoxModel;
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.InputVerifier;
|
import javax.swing.InputVerifier;
|
||||||
@ -74,7 +77,8 @@ public class PresetEditorDialog extends JDialog implements ItemListener {
|
|||||||
private final JPanel contentPanel = new JPanel();
|
private final JPanel contentPanel = new JPanel();
|
||||||
private DeselectableComboBox typeCombo;
|
private DeselectableComboBox typeCombo;
|
||||||
private JTextField mfgTextField;
|
private JTextField mfgTextField;
|
||||||
private JComboBox materialChooser;
|
private MaterialChooser materialChooser;
|
||||||
|
private MaterialHolder holder = null;
|
||||||
|
|
||||||
private JTextField ncPartNoTextField;
|
private JTextField ncPartNoTextField;
|
||||||
private JTextField ncDescTextField;
|
private JTextField ncDescTextField;
|
||||||
@ -171,7 +175,7 @@ public class PresetEditorDialog extends JDialog implements ItemListener {
|
|||||||
private JTextField pcLineCount;
|
private JTextField pcLineCount;
|
||||||
private DoubleModel pcDiameter;
|
private DoubleModel pcDiameter;
|
||||||
private DoubleModel pcLineLength;
|
private DoubleModel pcLineLength;
|
||||||
private JComboBox pcLineMaterialChooser;
|
private MaterialChooser pcLineMaterialChooser;
|
||||||
private DoubleModel pcMass;
|
private DoubleModel pcMass;
|
||||||
private ImageIcon pcImage;
|
private ImageIcon pcImage;
|
||||||
private JButton pcImageBtn;
|
private JButton pcImageBtn;
|
||||||
@ -215,7 +219,7 @@ public class PresetEditorDialog extends JDialog implements ItemListener {
|
|||||||
* @param theCallback the listener that gets the results of editing the presets
|
* @param theCallback the listener that gets the results of editing the presets
|
||||||
*/
|
*/
|
||||||
public PresetEditorDialog(PresetResultListener theCallback) {
|
public PresetEditorDialog(PresetResultListener theCallback) {
|
||||||
this(theCallback, null);
|
this(theCallback, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -223,8 +227,9 @@ public class PresetEditorDialog extends JDialog implements ItemListener {
|
|||||||
*
|
*
|
||||||
* @param theCallback the listener that gets the results of editing the presets
|
* @param theCallback the listener that gets the results of editing the presets
|
||||||
* @param toEdit the ComponentPreset to be edited; or null if a new one is being added
|
* @param toEdit the ComponentPreset to be edited; or null if a new one is being added
|
||||||
|
* @param matHolder the set of materials; if null then use system materials
|
||||||
*/
|
*/
|
||||||
public PresetEditorDialog(PresetResultListener theCallback, ComponentPreset toEdit) {
|
public PresetEditorDialog(PresetResultListener theCallback, ComponentPreset toEdit, MaterialHolder matHolder) {
|
||||||
resultListener = theCallback;
|
resultListener = theCallback;
|
||||||
getContentPane().setMinimumSize(new Dimension(200, 200));
|
getContentPane().setMinimumSize(new Dimension(200, 200));
|
||||||
setBounds(100, 100, 825, 610);
|
setBounds(100, 100, 825, 610);
|
||||||
@ -255,7 +260,7 @@ public class PresetEditorDialog extends JDialog implements ItemListener {
|
|||||||
JLabel bhMaterialLabel = new JLabel("Material:");
|
JLabel bhMaterialLabel = new JLabel("Material:");
|
||||||
contentPanel.add(bhMaterialLabel, "cell 2 2, alignx left");
|
contentPanel.add(bhMaterialLabel, "cell 2 2, alignx left");
|
||||||
|
|
||||||
materialChooser = new JComboBox(new MaterialModel(this, Material.Type.BULK));
|
materialChooser = new MaterialChooser(new MaterialModel(this, Material.Type.BULK));
|
||||||
|
|
||||||
contentPanel.add(materialChooser, "cell 3 2,growx");
|
contentPanel.add(materialChooser, "cell 3 2,growx");
|
||||||
|
|
||||||
@ -413,7 +418,7 @@ public class PresetEditorDialog extends JDialog implements ItemListener {
|
|||||||
spin = new JSpinner(trAftDia.getSpinnerModel());
|
spin = new JSpinner(trAftDia.getSpinnerModel());
|
||||||
spin.setEditor(new SpinnerEditor(spin));
|
spin.setEditor(new SpinnerEditor(spin));
|
||||||
trPanel.add(spin, "cell 1 3, growx");
|
trPanel.add(spin, "cell 1 3, growx");
|
||||||
trPanel.add(new UnitSelector(trAftDia));
|
trPanel.add(new UnitSelector(trAftDia), "growx");
|
||||||
|
|
||||||
JLabel trForeDiaLabel = new JLabel("Fore Dia.:");
|
JLabel trForeDiaLabel = new JLabel("Fore Dia.:");
|
||||||
trPanel.add(trForeDiaLabel, "cell 3 3,alignx left");
|
trPanel.add(trForeDiaLabel, "cell 3 3,alignx left");
|
||||||
@ -1028,7 +1033,6 @@ public class PresetEditorDialog extends JDialog implements ItemListener {
|
|||||||
JPanel pcPanel = new JPanel();
|
JPanel pcPanel = new JPanel();
|
||||||
componentOverlayPanel.add(pcPanel, "PARACHUTE");
|
componentOverlayPanel.add(pcPanel, "PARACHUTE");
|
||||||
pcPanel.setLayout(new MigLayout("", "[][157.00,grow 79][65.00][grow][][]", "[][][][][][]"));
|
pcPanel.setLayout(new MigLayout("", "[][157.00,grow 79][65.00][grow][][]", "[][][][][][]"));
|
||||||
//pcPanel.setLayout(new MigLayout("", "[][grow][][grow]", "[][][][]"));
|
|
||||||
JLabel pcPartNoLabel = new JLabel("Part No:");
|
JLabel pcPartNoLabel = new JLabel("Part No:");
|
||||||
pcPanel.add(pcPartNoLabel, "cell 0 0,alignx left");
|
pcPanel.add(pcPartNoLabel, "cell 0 0,alignx left");
|
||||||
|
|
||||||
@ -1089,7 +1093,7 @@ public class PresetEditorDialog extends JDialog implements ItemListener {
|
|||||||
JLabel pcLineMaterialLabel = new JLabel("Line Material:");
|
JLabel pcLineMaterialLabel = new JLabel("Line Material:");
|
||||||
pcPanel.add(pcLineMaterialLabel, "cell 3 4,alignx left, aligny top, pad 7 0 0 0 ");
|
pcPanel.add(pcLineMaterialLabel, "cell 3 4,alignx left, aligny top, pad 7 0 0 0 ");
|
||||||
|
|
||||||
pcLineMaterialChooser = new JComboBox();
|
pcLineMaterialChooser = new MaterialChooser();
|
||||||
pcLineMaterialChooser.setModel(new MaterialModel(PresetEditorDialog.this, Material.Type.LINE));
|
pcLineMaterialChooser.setModel(new MaterialModel(PresetEditorDialog.this, Material.Type.LINE));
|
||||||
pcPanel.add(pcLineMaterialChooser, "cell 4 4, span 3 1, growx, aligny top");
|
pcPanel.add(pcLineMaterialChooser, "cell 4 4, span 3 1, growx, aligny top");
|
||||||
|
|
||||||
@ -1151,8 +1155,9 @@ public class PresetEditorDialog extends JDialog implements ItemListener {
|
|||||||
buttonPane.add(cancelButton, "cell 6 0,alignx right,aligny top");
|
buttonPane.add(cancelButton, "cell 6 0,alignx right,aligny top");
|
||||||
|
|
||||||
if (toEdit != null) {
|
if (toEdit != null) {
|
||||||
fillEditor(toEdit);
|
fillEditor(toEdit, matHolder);
|
||||||
}
|
}
|
||||||
|
holder = matHolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1187,17 +1192,6 @@ public class PresetEditorDialog extends JDialog implements ItemListener {
|
|||||||
chooser.addPropertyChangeListener(preview);
|
chooser.addPropertyChangeListener(preview);
|
||||||
chooser.setAcceptAllFileFilterUsed(false);
|
chooser.setAcceptAllFileFilterUsed(false);
|
||||||
chooser.addChoosableFileFilter(new FileNameExtensionFilter("Image Files", "png", "jpg", "jpeg"));
|
chooser.addChoosableFileFilter(new FileNameExtensionFilter("Image Files", "png", "jpg", "jpeg"));
|
||||||
/*{
|
|
||||||
@Override
|
|
||||||
public boolean accept(final File f) {
|
|
||||||
return f.getName().endsWith(".png") || f.getName().endsWith(".jpg");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDescription() {
|
|
||||||
return "Image Files";
|
|
||||||
}
|
|
||||||
});*/
|
|
||||||
return chooser;
|
return chooser;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1206,12 +1200,11 @@ public class PresetEditorDialog extends JDialog implements ItemListener {
|
|||||||
*
|
*
|
||||||
* @param preset the preset to edit
|
* @param preset the preset to edit
|
||||||
*/
|
*/
|
||||||
private void fillEditor(ComponentPreset preset) {
|
private void fillEditor(ComponentPreset preset, MaterialHolder holder) {
|
||||||
ComponentPreset.Type t = preset.getType();
|
ComponentPreset.Type t = preset.getType();
|
||||||
|
|
||||||
mfgTextField.setText(preset.get(ComponentPreset.MANUFACTURER).getDisplayName());
|
mfgTextField.setText(preset.get(ComponentPreset.MANUFACTURER).getDisplayName());
|
||||||
materialChooser.setModel(new MaterialModel(PresetEditorDialog.this, Material.Type.BULK));
|
setMaterial(materialChooser, preset, holder, Material.Type.BULK, ComponentPreset.MATERIAL);
|
||||||
materialChooser.getModel().setSelectedItem(preset.get(ComponentPreset.MATERIAL));
|
|
||||||
switch (t) {
|
switch (t) {
|
||||||
case BODY_TUBE:
|
case BODY_TUBE:
|
||||||
typeCombo.setSelectedItem(trans.get(BODY_TUBE_KEY));
|
typeCombo.setSelectedItem(trans.get(BODY_TUBE_KEY));
|
||||||
@ -1443,8 +1436,7 @@ public class PresetEditorDialog extends JDialog implements ItemListener {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PARACHUTE:
|
case PARACHUTE:
|
||||||
materialChooser.setModel(new MaterialModel(PresetEditorDialog.this, Material.Type.SURFACE));
|
setMaterial(materialChooser, preset, holder, Material.Type.SURFACE, ComponentPreset.MATERIAL);
|
||||||
materialChooser.getModel().setSelectedItem(preset.get(ComponentPreset.MATERIAL));
|
|
||||||
typeCombo.setSelectedItem(trans.get(PARACHUTE_KEY));
|
typeCombo.setSelectedItem(trans.get(PARACHUTE_KEY));
|
||||||
pcDescTextField.setText(preset.get(ComponentPreset.DESCRIPTION));
|
pcDescTextField.setText(preset.get(ComponentPreset.DESCRIPTION));
|
||||||
if (preset.has(ComponentPreset.LINE_COUNT)) {
|
if (preset.has(ComponentPreset.LINE_COUNT)) {
|
||||||
@ -1470,11 +1462,13 @@ public class PresetEditorDialog extends JDialog implements ItemListener {
|
|||||||
pcImage = new ImageIcon(byteArrayToImage(preset.get(ComponentPreset.IMAGE)));
|
pcImage = new ImageIcon(byteArrayToImage(preset.get(ComponentPreset.IMAGE)));
|
||||||
pcImageBtn.setIcon(pcImage);
|
pcImageBtn.setIcon(pcImage);
|
||||||
}
|
}
|
||||||
pcLineMaterialChooser.getModel().setSelectedItem(preset.get(ComponentPreset.LINE_MATERIAL));
|
setMaterial(pcLineMaterialChooser, preset, holder, Material.Type.LINE, ComponentPreset.LINE_MATERIAL);
|
||||||
|
// pcLineMaterialChooser.setModel(new MaterialModel(PresetEditorDialog.this, Material.Type.LINE));
|
||||||
|
|
||||||
|
// pcLineMaterialChooser.getModel().setSelectedItem(preset.get(ComponentPreset.LINE_MATERIAL));
|
||||||
break;
|
break;
|
||||||
case STREAMER:
|
case STREAMER:
|
||||||
materialChooser.setModel(new MaterialModel(PresetEditorDialog.this, Material.Type.SURFACE));
|
setMaterial(materialChooser, preset, holder, Material.Type.SURFACE, ComponentPreset.MATERIAL);
|
||||||
materialChooser.getModel().setSelectedItem(preset.get(ComponentPreset.MATERIAL));
|
|
||||||
typeCombo.setSelectedItem(trans.get(STREAMER_KEY));
|
typeCombo.setSelectedItem(trans.get(STREAMER_KEY));
|
||||||
stDescTextField.setText(preset.get(ComponentPreset.DESCRIPTION));
|
stDescTextField.setText(preset.get(ComponentPreset.DESCRIPTION));
|
||||||
if (preset.has(ComponentPreset.LENGTH)) {
|
if (preset.has(ComponentPreset.LENGTH)) {
|
||||||
@ -1503,6 +1497,20 @@ public class PresetEditorDialog extends JDialog implements ItemListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setMaterial(final JComboBox chooser, final ComponentPreset preset, final MaterialHolder holder,
|
||||||
|
final Material.Type theType, final TypedKey key) {
|
||||||
|
if (holder == null) {
|
||||||
|
chooser.setModel(new MaterialModel(PresetEditorDialog.this, theType));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
chooser.setModel(new MaterialModel(PresetEditorDialog.this, theType,
|
||||||
|
holder.asDatabase(theType)));
|
||||||
|
}
|
||||||
|
if (preset != null) {
|
||||||
|
chooser.getModel().setSelectedItem(preset.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract the preset data from the UI fields, create a ComponentPreset instance, and notify the listener.
|
* Extract the preset data from the UI fields, create a ComponentPreset instance, and notify the listener.
|
||||||
*/
|
*/
|
||||||
@ -2053,12 +2061,12 @@ public class PresetEditorDialog extends JDialog implements ItemListener {
|
|||||||
if (materialChooser != null && evt.getStateChange() == ItemEvent.SELECTED) {
|
if (materialChooser != null && evt.getStateChange() == ItemEvent.SELECTED) {
|
||||||
if (item.equals(trans.get(PARACHUTE_KEY)) || item.equals(trans.get(STREAMER_KEY))) {
|
if (item.equals(trans.get(PARACHUTE_KEY)) || item.equals(trans.get(STREAMER_KEY))) {
|
||||||
if (!((MaterialModel) materialChooser.getModel()).getType().equals(Material.Type.SURFACE)) {
|
if (!((MaterialModel) materialChooser.getModel()).getType().equals(Material.Type.SURFACE)) {
|
||||||
materialChooser.setModel(new MaterialModel(PresetEditorDialog.this, Material.Type.SURFACE));
|
setMaterial(materialChooser, null, holder, Material.Type.SURFACE, ComponentPreset.MATERIAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!((MaterialModel) materialChooser.getModel()).getType().equals(Material.Type.BULK)) {
|
if (!((MaterialModel) materialChooser.getModel()).getType().equals(Material.Type.BULK)) {
|
||||||
materialChooser.setModel(new MaterialModel(PresetEditorDialog.this, Material.Type.BULK));
|
setMaterial(materialChooser, null, holder, Material.Type.BULK, ComponentPreset.MATERIAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2191,4 +2199,30 @@ public class PresetEditorDialog extends JDialog implements ItemListener {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MaterialChooser extends JComboBox {
|
||||||
|
|
||||||
|
public MaterialChooser() {
|
||||||
|
}
|
||||||
|
public MaterialChooser(MaterialModel model) {
|
||||||
|
super(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the data model that the <code>JComboBox</code> uses to obtain the list of items.
|
||||||
|
*
|
||||||
|
* @param aModel the <code>ComboBoxModel</code> that provides the displayed list of items
|
||||||
|
*
|
||||||
|
* @beaninfo bound: true description: Model that the combo box uses to get data to display.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setModel(final ComboBoxModel aModel) {
|
||||||
|
if (getModel() instanceof MaterialModel) {
|
||||||
|
MaterialModel old = (MaterialModel) getModel();
|
||||||
|
old.removeListener();
|
||||||
|
}
|
||||||
|
super.setModel(aModel);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
package net.sf.openrocket.gui.print;
|
package net.sf.openrocket.gui.print;
|
||||||
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.print.PageFormat;
|
import java.awt.print.PageFormat;
|
||||||
@ -71,7 +70,7 @@ public class PrintableComponent extends JPanel implements Printable {
|
|||||||
/**
|
/**
|
||||||
* Set the offset this component will be printed to the page
|
* Set the offset this component will be printed to the page
|
||||||
* @param x X offset to print at.
|
* @param x X offset to print at.
|
||||||
* @param x Y offset to print at.
|
* @param y Y offset to print at.
|
||||||
*/
|
*/
|
||||||
public void setPrintOffset(int x, int y) {
|
public void setPrintOffset(int x, int y) {
|
||||||
offsetX = x;
|
offsetX = x;
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import java.util.HashMap;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.sf.openrocket.database.Database;
|
||||||
import net.sf.openrocket.material.Material;
|
import net.sf.openrocket.material.Material;
|
||||||
import net.sf.openrocket.unit.UnitGroup;
|
import net.sf.openrocket.unit.UnitGroup;
|
||||||
|
|
||||||
@ -87,4 +88,20 @@ public class MaterialHolder {
|
|||||||
return allMats;
|
return allMats;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Database<Material> asDatabase(Material.Type theType) {
|
||||||
|
Database<Material> result = new Database<Material>();
|
||||||
|
switch (theType) {
|
||||||
|
case LINE:
|
||||||
|
result.addAll(lineMaterials.values());
|
||||||
|
break;
|
||||||
|
case SURFACE:
|
||||||
|
result.addAll(surfaceMaterials.values());
|
||||||
|
break;
|
||||||
|
case BULK:
|
||||||
|
default:
|
||||||
|
result.addAll(bulkMaterials.values());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user