Preset dialog
This commit is contained in:
parent
1cffc8b58c
commit
871ff23523
@ -124,9 +124,6 @@ PrintDialog.error.preview.title = Unable to open preview
|
||||
PrintDialog.error.preview.desc1 = Unable to open PDF preview.
|
||||
PrintDialog.error.preview.desc2 = Please use the "Save as PDF" option instead.
|
||||
|
||||
! Component Preset Chooser Dialog
|
||||
CompPresetChooser.title = Choose component preset
|
||||
|
||||
!PrintSettingsDialog
|
||||
PrintSettingsDialog.title = Print settings
|
||||
PrintSettingsDialog.lbl.Templatefillcolor = Template fill color:
|
||||
@ -1590,3 +1587,6 @@ CustomFinImport.description = The image will be converted internally to black an
|
||||
PresetModel.lbl.select = Select preset:
|
||||
PresetModel.lbl.database = From database...
|
||||
|
||||
|
||||
! Component Preset Chooser Dialog
|
||||
ComponentPresetChooserDialog.title = Choose component preset
|
||||
|
@ -55,7 +55,6 @@ public class PresetModel extends AbstractListModel implements ComboBoxModel, Com
|
||||
@Override
|
||||
public void setSelectedItem(Object item) {
|
||||
log.user("User selected preset item '" + item + "' for component " + component);
|
||||
System.err.println("**** Setting item: " + item);
|
||||
|
||||
if (item == null) {
|
||||
// FIXME: What to do?
|
||||
@ -83,7 +82,6 @@ public class PresetModel extends AbstractListModel implements ComboBoxModel, Com
|
||||
public void componentChanged(ComponentChangeEvent e) {
|
||||
if (previousPreset != component.getPresetComponent()) {
|
||||
previousPreset = component.getPresetComponent();
|
||||
System.err.println("Firing event");
|
||||
fireContentsChanged(this, 0, getSize());
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import java.awt.Dialog;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
@ -14,26 +15,66 @@ import net.miginfocom.swing.MigLayout;
|
||||
import net.sf.openrocket.gui.util.GUIUtil;
|
||||
import net.sf.openrocket.l10n.Translator;
|
||||
import net.sf.openrocket.preset.ComponentPreset;
|
||||
import net.sf.openrocket.preset.TypedKey;
|
||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
|
||||
public class ComponentPresetChooserDialog extends JDialog {
|
||||
|
||||
// private final ThrustCurveMotorSelectionPanel selectionPanel;
|
||||
private static final Translator trans = Application.getTranslator();
|
||||
|
||||
// private final ThrustCurveMotorSelectionPanel selectionPanel;
|
||||
|
||||
private final RocketComponent component;
|
||||
private final List<ComponentPreset> presets;
|
||||
|
||||
private boolean okClicked = false;
|
||||
private static final Translator trans = Application.getTranslator();
|
||||
|
||||
|
||||
public ComponentPresetChooserDialog(Window owner) {
|
||||
super(owner, trans.get("CompPresetChooser.title"), Dialog.ModalityType.APPLICATION_MODAL);
|
||||
|
||||
public ComponentPresetChooserDialog(Window owner, RocketComponent component, TypedKey<?>... columnKeys) {
|
||||
super(owner, trans.get("title"), Dialog.ModalityType.APPLICATION_MODAL);
|
||||
|
||||
this.component = component;
|
||||
|
||||
// FIXME: Make generic for component type
|
||||
presets = Application.getDaos().getBodyTubePresetDao().listAll();
|
||||
|
||||
|
||||
|
||||
|
||||
JPanel panel = new JPanel(new MigLayout("fill"));
|
||||
|
||||
//selectionPanel = new ThrustCurveMotorSelectionPanel((ThrustCurveMotor) current, delay, diameter);
|
||||
/*
|
||||
Column[] columns = new Column[columnKeys.length];
|
||||
|
||||
for (int i = 0; i < columnKeys.length; i++) {
|
||||
final TypedKey<?> key = columnKeys[i];
|
||||
columns[i] = new Column(trans.get("table.column." + columnKeys[i].getName())) {
|
||||
@Override
|
||||
public Object getValueAt(int row) {
|
||||
if (key.getType() == Double.class && key.getUnitGroup() != null) {
|
||||
return new Value(, null);
|
||||
}
|
||||
|
||||
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
ColumnTableModel tableModel = new ColumnTableModel(columns) {
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
// FIXME Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
//panel.add(selectionPanel, "grow, wrap para");
|
||||
|
||||
|
||||
// OK / Cancel buttons
|
||||
JButton okButton = new JButton(trans.get("dlg.but.ok"));
|
||||
okButton.addActionListener(new ActionListener() {
|
||||
@ -70,7 +111,6 @@ public class ComponentPresetChooserDialog extends JDialog {
|
||||
//selectionPanel.setCloseableDialog(this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the motor selected by this chooser dialog, or <code>null</code> if the selection has been aborted.
|
||||
*
|
||||
|
@ -4,59 +4,70 @@ import net.sf.openrocket.database.Databases;
|
||||
import net.sf.openrocket.material.Material;
|
||||
import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
import net.sf.openrocket.unit.UnitGroup;
|
||||
|
||||
public class TypedKey<T> {
|
||||
|
||||
|
||||
private final String name;
|
||||
private final Class<T> type;
|
||||
private final UnitGroup unitGroup;
|
||||
|
||||
public TypedKey(String name, Class<T> type) {
|
||||
this(name, type, null);
|
||||
}
|
||||
|
||||
public TypedKey(String name, Class<T> type, UnitGroup unitGroup) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.unitGroup = unitGroup;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public Class<T> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Object parseFromString( String value ) {
|
||||
if ( type.equals(Boolean.class) ) {
|
||||
|
||||
public UnitGroup getUnitGroup() {
|
||||
return unitGroup;
|
||||
}
|
||||
|
||||
public Object parseFromString(String value) {
|
||||
if (type.equals(Boolean.class)) {
|
||||
return Boolean.parseBoolean(value);
|
||||
}
|
||||
if ( type.isAssignableFrom(Double.class) ) {
|
||||
if (type.isAssignableFrom(Double.class)) {
|
||||
return Double.parseDouble(value);
|
||||
}
|
||||
if ( type.equals(String.class ) ) {
|
||||
if (type.equals(String.class)) {
|
||||
return value;
|
||||
}
|
||||
if ( type.equals(Finish.class) ) {
|
||||
if (type.equals(Finish.class)) {
|
||||
return Finish.valueOf(value);
|
||||
}
|
||||
if ( type.equals(Material.class) ) {
|
||||
if (type.equals(Material.class)) {
|
||||
// need to translate the value first!
|
||||
String translated_value = Application.getTranslator().get(value);
|
||||
Material material;
|
||||
material = Databases.findMaterial(Material.Type.BULK, translated_value);
|
||||
if ( material != null ) {
|
||||
if (material != null) {
|
||||
return material;
|
||||
}
|
||||
material = Databases.findMaterial(Material.Type.LINE, translated_value);
|
||||
if ( material != null ) {
|
||||
if (material != null) {
|
||||
return material;
|
||||
}
|
||||
material = Databases.findMaterial(Material.Type.SURFACE, translated_value);
|
||||
if ( material != null ) {
|
||||
if (material != null) {
|
||||
return material;
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid material " + value + " in component preset.");
|
||||
}
|
||||
throw new IllegalArgumentException("Inavlid type " + type.getName() + " for component preset parameter " + name);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
@ -65,7 +76,7 @@ public class TypedKey<T> {
|
||||
result = prime * result + ((type == null) ? 0 : type.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
|
Loading…
x
Reference in New Issue
Block a user