Moved the ComponentPresetChooserDialog from the BodyTubeConfig temporary button to the PresetModel drop down.
This commit is contained in:
parent
a64c9e70a6
commit
f92034db56
@ -1,12 +1,15 @@
|
|||||||
package net.sf.openrocket.gui.adaptors;
|
package net.sf.openrocket.gui.adaptors;
|
||||||
|
|
||||||
|
import java.awt.Component;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.AbstractListModel;
|
import javax.swing.AbstractListModel;
|
||||||
import javax.swing.ComboBoxModel;
|
import javax.swing.ComboBoxModel;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
import net.sf.openrocket.database.Database;
|
import net.sf.openrocket.database.Database;
|
||||||
import net.sf.openrocket.database.DatabaseListener;
|
import net.sf.openrocket.database.DatabaseListener;
|
||||||
|
import net.sf.openrocket.gui.dialogs.preset.ComponentPresetChooserDialog;
|
||||||
import net.sf.openrocket.l10n.Translator;
|
import net.sf.openrocket.l10n.Translator;
|
||||||
import net.sf.openrocket.logging.LogHelper;
|
import net.sf.openrocket.logging.LogHelper;
|
||||||
import net.sf.openrocket.preset.ComponentPreset;
|
import net.sf.openrocket.preset.ComponentPreset;
|
||||||
@ -20,16 +23,17 @@ public class PresetModel extends AbstractListModel implements ComboBoxModel, Com
|
|||||||
private static final LogHelper log = Application.getLogger();
|
private static final LogHelper log = Application.getLogger();
|
||||||
private static final Translator trans = Application.getTranslator();
|
private static final Translator trans = Application.getTranslator();
|
||||||
|
|
||||||
private static final String SELECT_PRESET = trans.get("lbl.select");
|
private static final String NONE_SELECTED = "";
|
||||||
private static final String SELECT_DATABASE = trans.get("lbl.database");
|
private static final String SELECT_DATABASE = trans.get("lbl.database");
|
||||||
|
|
||||||
|
private final Component parent;
|
||||||
private final RocketComponent component;
|
private final RocketComponent component;
|
||||||
private ComponentPreset previousPreset;
|
private ComponentPreset previousPreset;
|
||||||
|
|
||||||
private List<ComponentPreset> presets;
|
private List<ComponentPreset> presets;
|
||||||
|
|
||||||
public PresetModel(RocketComponent component) {
|
public PresetModel(Component parent, RocketComponent component) {
|
||||||
|
this.parent = parent;
|
||||||
presets = Application.getComponentPresetDao().listForType(component.getPresetType(), true);
|
presets = Application.getComponentPresetDao().listForType(component.getPresetType(), true);
|
||||||
this.component = component;
|
this.component = component;
|
||||||
previousPreset = component.getPresetComponent();
|
previousPreset = component.getPresetComponent();
|
||||||
@ -44,7 +48,7 @@ public class PresetModel extends AbstractListModel implements ComboBoxModel, Com
|
|||||||
@Override
|
@Override
|
||||||
public Object getElementAt(int index) {
|
public Object getElementAt(int index) {
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
return SELECT_PRESET;
|
return NONE_SELECTED;
|
||||||
}
|
}
|
||||||
if (index == getSize() - 1) {
|
if (index == getSize() - 1) {
|
||||||
return SELECT_DATABASE;
|
return SELECT_DATABASE;
|
||||||
@ -58,10 +62,17 @@ public class PresetModel extends AbstractListModel implements ComboBoxModel, Com
|
|||||||
|
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
// FIXME: What to do?
|
// FIXME: What to do?
|
||||||
} else if (item.equals(SELECT_PRESET)) {
|
} else if (item.equals(NONE_SELECTED)) {
|
||||||
component.clearPreset();
|
component.clearPreset();
|
||||||
} else if (item.equals(SELECT_DATABASE)) {
|
} else if (item.equals(SELECT_DATABASE)) {
|
||||||
// FIXME: Open database dialog
|
// FIXME - when the dialog first appears, the preset drop down still is open and has focus.
|
||||||
|
// we need to force focus to the new dialog.
|
||||||
|
ComponentPresetChooserDialog dialog =
|
||||||
|
new ComponentPresetChooserDialog( SwingUtilities.getWindowAncestor(PresetModel.this.parent),
|
||||||
|
PresetModel.this.component);
|
||||||
|
dialog.setVisible(true);
|
||||||
|
ComponentPreset preset = dialog.getSelectedComponentPreset();
|
||||||
|
setSelectedItem(preset);
|
||||||
} else {
|
} else {
|
||||||
// FIXME: Add undo point here
|
// FIXME: Add undo point here
|
||||||
component.loadPreset((ComponentPreset) item);
|
component.loadPreset((ComponentPreset) item);
|
||||||
@ -72,7 +83,7 @@ public class PresetModel extends AbstractListModel implements ComboBoxModel, Com
|
|||||||
public Object getSelectedItem() {
|
public Object getSelectedItem() {
|
||||||
ComponentPreset preset = component.getPresetComponent();
|
ComponentPreset preset = component.getPresetComponent();
|
||||||
if (preset == null) {
|
if (preset == null) {
|
||||||
return SELECT_PRESET;
|
return NONE_SELECTED;
|
||||||
} else {
|
} else {
|
||||||
return preset;
|
return preset;
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,11 @@
|
|||||||
package net.sf.openrocket.gui.configdialog;
|
package net.sf.openrocket.gui.configdialog;
|
||||||
|
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
import javax.swing.JButton;
|
|
||||||
import javax.swing.JCheckBox;
|
import javax.swing.JCheckBox;
|
||||||
import javax.swing.JComboBox;
|
import javax.swing.JComboBox;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JSpinner;
|
import javax.swing.JSpinner;
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
import net.sf.openrocket.database.ComponentPresetDatabase;
|
import net.sf.openrocket.database.ComponentPresetDatabase;
|
||||||
@ -21,10 +16,8 @@ import net.sf.openrocket.gui.adaptors.DoubleModel;
|
|||||||
import net.sf.openrocket.gui.adaptors.PresetModel;
|
import net.sf.openrocket.gui.adaptors.PresetModel;
|
||||||
import net.sf.openrocket.gui.components.BasicSlider;
|
import net.sf.openrocket.gui.components.BasicSlider;
|
||||||
import net.sf.openrocket.gui.components.UnitSelector;
|
import net.sf.openrocket.gui.components.UnitSelector;
|
||||||
import net.sf.openrocket.gui.dialogs.preset.ComponentPresetChooserDialog;
|
|
||||||
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.ComponentPreset;
|
|
||||||
import net.sf.openrocket.rocketcomponent.BodyTube;
|
import net.sf.openrocket.rocketcomponent.BodyTube;
|
||||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
@ -48,34 +41,11 @@ public class BodyTubeConfig extends RocketComponentConfig {
|
|||||||
//// Body tube template
|
//// Body tube template
|
||||||
// FIXME: Move to proper location
|
// FIXME: Move to proper location
|
||||||
panel.add(new JLabel(trans.get("PresetModel.lbl.select")));
|
panel.add(new JLabel(trans.get("PresetModel.lbl.select")));
|
||||||
presetModel = new PresetModel(component);
|
presetModel = new PresetModel( this, component);
|
||||||
((ComponentPresetDatabase)Application.getComponentPresetDao()).addDatabaseListener(presetModel);
|
((ComponentPresetDatabase)Application.getComponentPresetDao()).addDatabaseListener(presetModel);
|
||||||
presetComboBox = new JComboBox(presetModel);
|
presetComboBox = new JComboBox(presetModel);
|
||||||
presetComboBox.setEditable(false);
|
presetComboBox.setEditable(false);
|
||||||
panel.add(presetComboBox, "wrap para");
|
panel.add(presetComboBox, "wrap para");
|
||||||
//FIXME: temporarily put the select from table button in the config dialog.
|
|
||||||
{
|
|
||||||
JButton opendialog = new JButton("o");
|
|
||||||
opendialog.addActionListener(
|
|
||||||
new ActionListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
ComponentPresetChooserDialog dialog =
|
|
||||||
new ComponentPresetChooserDialog( SwingUtilities.getWindowAncestor(BodyTubeConfig.this),
|
|
||||||
BodyTubeConfig.this.component,
|
|
||||||
ComponentPreset.MANUFACTURER,
|
|
||||||
ComponentPreset.PARTNO,
|
|
||||||
ComponentPreset.OUTER_DIAMETER,
|
|
||||||
ComponentPreset.INNER_DIAMETER,
|
|
||||||
ComponentPreset.LENGTH);
|
|
||||||
dialog.setVisible(true);
|
|
||||||
ComponentPreset preset = dialog.getSelectedComponentPreset();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
panel.add( opendialog, "wrap" );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//// Body tube length
|
//// Body tube length
|
||||||
panel.add(new JLabel(trans.get("BodyTubecfg.lbl.Bodytubelength")));
|
panel.add(new JLabel(trans.get("BodyTubecfg.lbl.Bodytubelength")));
|
||||||
|
@ -31,18 +31,16 @@ public class ComponentPresetChooserDialog extends JDialog {
|
|||||||
|
|
||||||
private static final Translator trans = Application.getTranslator();
|
private static final Translator trans = Application.getTranslator();
|
||||||
|
|
||||||
// private final ThrustCurveMotorSelectionPanel selectionPanel;
|
private final JTable componentSelectionTable;
|
||||||
|
|
||||||
private final RocketComponent component;
|
|
||||||
private final List<ComponentPreset> presets;
|
private final List<ComponentPreset> presets;
|
||||||
|
|
||||||
private boolean okClicked = false;
|
private boolean okClicked = false;
|
||||||
|
|
||||||
|
|
||||||
public ComponentPresetChooserDialog(Window owner, RocketComponent component, final TypedKey<?>... columnKeys) {
|
public ComponentPresetChooserDialog(Window owner, RocketComponent component) {
|
||||||
super(owner, trans.get("title"), Dialog.ModalityType.APPLICATION_MODAL);
|
super(owner, trans.get("title"), Dialog.ModalityType.APPLICATION_MODAL);
|
||||||
|
|
||||||
this.component = component;
|
final TypedKey<?>[] columnKeys = component.getPresetType().getDisplayedColumns();
|
||||||
|
|
||||||
presets = Application.getComponentPresetDao().listAll();
|
presets = Application.getComponentPresetDao().listAll();
|
||||||
|
|
||||||
@ -95,9 +93,9 @@ public class ComponentPresetChooserDialog extends JDialog {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
final JTable table = new JTable( tableModel );
|
componentSelectionTable = new JTable( tableModel );
|
||||||
|
|
||||||
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
componentSelectionTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||||
|
|
||||||
final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableModel);
|
final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableModel);
|
||||||
// FIXME we might need some custom sorters.
|
// FIXME we might need some custom sorters.
|
||||||
@ -105,10 +103,10 @@ public class ComponentPresetChooserDialog extends JDialog {
|
|||||||
TypedKey<?> column = columnKeys[i];
|
TypedKey<?> column = columnKeys[i];
|
||||||
sorter.setComparator(i, column.getComparator());
|
sorter.setComparator(i, column.getComparator());
|
||||||
}*/
|
}*/
|
||||||
table.setRowSorter(sorter);
|
componentSelectionTable.setRowSorter(sorter);
|
||||||
|
|
||||||
JScrollPane scrollpane = new JScrollPane();
|
JScrollPane scrollpane = new JScrollPane();
|
||||||
scrollpane.setViewportView(table);
|
scrollpane.setViewportView(componentSelectionTable);
|
||||||
panel.add(scrollpane, "grow, width :500:, height :300:, spanx, wrap para");
|
panel.add(scrollpane, "grow, width :500:, height :300:, spanx, wrap para");
|
||||||
|
|
||||||
|
|
||||||
@ -156,18 +154,13 @@ public class ComponentPresetChooserDialog extends JDialog {
|
|||||||
public ComponentPreset getSelectedComponentPreset() {
|
public ComponentPreset getSelectedComponentPreset() {
|
||||||
if (!okClicked)
|
if (!okClicked)
|
||||||
return null;
|
return null;
|
||||||
//return selectionPanel.getSelectedMotor();
|
int row = componentSelectionTable.getSelectedRow();
|
||||||
return null;
|
return presets.get(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close(boolean ok) {
|
public void close(boolean ok) {
|
||||||
okClicked = ok;
|
okClicked = ok;
|
||||||
this.setVisible(false);
|
this.setVisible(false);
|
||||||
|
|
||||||
ComponentPreset preset = getSelectedComponentPreset();
|
|
||||||
if (okClicked && preset != null) {
|
|
||||||
//selectionPanel.selectedMotor(selected);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,29 +36,48 @@ public class ComponentPreset implements Comparable<ComponentPreset> {
|
|||||||
private String digest = "";
|
private String digest = "";
|
||||||
|
|
||||||
public enum Type {
|
public enum Type {
|
||||||
BODY_TUBE,
|
BODY_TUBE( new TypedKey<?>[] {
|
||||||
NOSE_CONE;
|
ComponentPreset.MANUFACTURER,
|
||||||
|
ComponentPreset.PARTNO,
|
||||||
|
ComponentPreset.OUTER_DIAMETER,
|
||||||
|
ComponentPreset.INNER_DIAMETER,
|
||||||
|
ComponentPreset.LENGTH} ),
|
||||||
|
|
||||||
|
NOSE_CONE( new TypedKey<?>[] {
|
||||||
|
ComponentPreset.MANUFACTURER,
|
||||||
|
ComponentPreset.PARTNO,
|
||||||
|
ComponentPreset.OUTER_DIAMETER,
|
||||||
|
ComponentPreset.INNER_DIAMETER,
|
||||||
|
ComponentPreset.LENGTH} ) ;
|
||||||
|
|
||||||
Type[] compatibleTypes;
|
Type[] compatibleTypes;
|
||||||
|
TypedKey<?>[] displayedColumns;
|
||||||
|
|
||||||
Type () {
|
Type( TypedKey<?>[] displayedColumns) {
|
||||||
compatibleTypes = new Type[1];
|
compatibleTypes = new Type[1];
|
||||||
compatibleTypes[0] = this;
|
compatibleTypes[0] = this;
|
||||||
|
this.displayedColumns = displayedColumns;
|
||||||
}
|
}
|
||||||
|
|
||||||
Type( Type ... t ) {
|
Type( Type[] t, TypedKey<?>[] displayedColumns ) {
|
||||||
|
|
||||||
compatibleTypes = new Type[t.length+1];
|
compatibleTypes = new Type[t.length+1];
|
||||||
compatibleTypes[0] = this;
|
compatibleTypes[0] = this;
|
||||||
for( int i=0; i<t.length; i++ ) {
|
for( int i=0; i<t.length; i++ ) {
|
||||||
compatibleTypes[i+1] = t[i];
|
compatibleTypes[i+1] = t[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.displayedColumns = displayedColumns;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Type[] getCompatibleTypes() {
|
public Type[] getCompatibleTypes() {
|
||||||
return compatibleTypes;
|
return compatibleTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TypedKey<?>[] getDisplayedColumns() {
|
||||||
|
return displayedColumns;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static TypedKey<Manufacturer> MANUFACTURER = new TypedKey<Manufacturer>("Manufacturer", Manufacturer.class);
|
public final static TypedKey<Manufacturer> MANUFACTURER = new TypedKey<Manufacturer>("Manufacturer", Manufacturer.class);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user