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.desc1 = Unable to open PDF preview.
|
||||||
PrintDialog.error.preview.desc2 = Please use the "Save as PDF" option instead.
|
PrintDialog.error.preview.desc2 = Please use the "Save as PDF" option instead.
|
||||||
|
|
||||||
! Component Preset Chooser Dialog
|
|
||||||
CompPresetChooser.title = Choose component preset
|
|
||||||
|
|
||||||
!PrintSettingsDialog
|
!PrintSettingsDialog
|
||||||
PrintSettingsDialog.title = Print settings
|
PrintSettingsDialog.title = Print settings
|
||||||
PrintSettingsDialog.lbl.Templatefillcolor = Template fill color:
|
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.select = Select preset:
|
||||||
PresetModel.lbl.database = From database...
|
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
|
@Override
|
||||||
public void setSelectedItem(Object item) {
|
public void setSelectedItem(Object item) {
|
||||||
log.user("User selected preset item '" + item + "' for component " + component);
|
log.user("User selected preset item '" + item + "' for component " + component);
|
||||||
System.err.println("**** Setting item: " + item);
|
|
||||||
|
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
// FIXME: What to do?
|
// FIXME: What to do?
|
||||||
@ -83,7 +82,6 @@ public class PresetModel extends AbstractListModel implements ComboBoxModel, Com
|
|||||||
public void componentChanged(ComponentChangeEvent e) {
|
public void componentChanged(ComponentChangeEvent e) {
|
||||||
if (previousPreset != component.getPresetComponent()) {
|
if (previousPreset != component.getPresetComponent()) {
|
||||||
previousPreset = component.getPresetComponent();
|
previousPreset = component.getPresetComponent();
|
||||||
System.err.println("Firing event");
|
|
||||||
fireContentsChanged(this, 0, getSize());
|
fireContentsChanged(this, 0, getSize());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import java.awt.Dialog;
|
|||||||
import java.awt.Window;
|
import java.awt.Window;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
@ -14,24 +15,64 @@ import net.miginfocom.swing.MigLayout;
|
|||||||
import net.sf.openrocket.gui.util.GUIUtil;
|
import net.sf.openrocket.gui.util.GUIUtil;
|
||||||
import net.sf.openrocket.l10n.Translator;
|
import net.sf.openrocket.l10n.Translator;
|
||||||
import net.sf.openrocket.preset.ComponentPreset;
|
import net.sf.openrocket.preset.ComponentPreset;
|
||||||
|
import net.sf.openrocket.preset.TypedKey;
|
||||||
|
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
|
|
||||||
public class ComponentPresetChooserDialog extends JDialog {
|
public class ComponentPresetChooserDialog extends JDialog {
|
||||||
|
|
||||||
// private final ThrustCurveMotorSelectionPanel selectionPanel;
|
|
||||||
|
|
||||||
private boolean okClicked = false;
|
|
||||||
private static final Translator trans = Application.getTranslator();
|
private static final Translator trans = Application.getTranslator();
|
||||||
|
|
||||||
|
// private final ThrustCurveMotorSelectionPanel selectionPanel;
|
||||||
|
|
||||||
|
private final RocketComponent component;
|
||||||
|
private final List<ComponentPreset> presets;
|
||||||
|
|
||||||
|
private boolean okClicked = false;
|
||||||
|
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public ComponentPresetChooserDialog(Window owner) {
|
|
||||||
super(owner, trans.get("CompPresetChooser.title"), Dialog.ModalityType.APPLICATION_MODAL);
|
|
||||||
|
|
||||||
JPanel panel = new JPanel(new MigLayout("fill"));
|
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
|
// OK / Cancel buttons
|
||||||
@ -70,7 +111,6 @@ public class ComponentPresetChooserDialog extends JDialog {
|
|||||||
//selectionPanel.setCloseableDialog(this);
|
//selectionPanel.setCloseableDialog(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the motor selected by this chooser dialog, or <code>null</code> if the selection has been aborted.
|
* Return the motor selected by this chooser dialog, or <code>null</code> if the selection has been aborted.
|
||||||
*
|
*
|
||||||
|
@ -4,15 +4,22 @@ import net.sf.openrocket.database.Databases;
|
|||||||
import net.sf.openrocket.material.Material;
|
import net.sf.openrocket.material.Material;
|
||||||
import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish;
|
import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish;
|
||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
|
import net.sf.openrocket.unit.UnitGroup;
|
||||||
|
|
||||||
public class TypedKey<T> {
|
public class TypedKey<T> {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final Class<T> type;
|
private final Class<T> type;
|
||||||
|
private final UnitGroup unitGroup;
|
||||||
|
|
||||||
public TypedKey(String name, Class<T> type) {
|
public TypedKey(String name, Class<T> type) {
|
||||||
|
this(name, type, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TypedKey(String name, Class<T> type, UnitGroup unitGroup) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
this.unitGroup = unitGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@ -23,33 +30,37 @@ public class TypedKey<T> {
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object parseFromString( String value ) {
|
public UnitGroup getUnitGroup() {
|
||||||
if ( type.equals(Boolean.class) ) {
|
return unitGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object parseFromString(String value) {
|
||||||
|
if (type.equals(Boolean.class)) {
|
||||||
return Boolean.parseBoolean(value);
|
return Boolean.parseBoolean(value);
|
||||||
}
|
}
|
||||||
if ( type.isAssignableFrom(Double.class) ) {
|
if (type.isAssignableFrom(Double.class)) {
|
||||||
return Double.parseDouble(value);
|
return Double.parseDouble(value);
|
||||||
}
|
}
|
||||||
if ( type.equals(String.class ) ) {
|
if (type.equals(String.class)) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
if ( type.equals(Finish.class) ) {
|
if (type.equals(Finish.class)) {
|
||||||
return Finish.valueOf(value);
|
return Finish.valueOf(value);
|
||||||
}
|
}
|
||||||
if ( type.equals(Material.class) ) {
|
if (type.equals(Material.class)) {
|
||||||
// need to translate the value first!
|
// need to translate the value first!
|
||||||
String translated_value = Application.getTranslator().get(value);
|
String translated_value = Application.getTranslator().get(value);
|
||||||
Material material;
|
Material material;
|
||||||
material = Databases.findMaterial(Material.Type.BULK, translated_value);
|
material = Databases.findMaterial(Material.Type.BULK, translated_value);
|
||||||
if ( material != null ) {
|
if (material != null) {
|
||||||
return material;
|
return material;
|
||||||
}
|
}
|
||||||
material = Databases.findMaterial(Material.Type.LINE, translated_value);
|
material = Databases.findMaterial(Material.Type.LINE, translated_value);
|
||||||
if ( material != null ) {
|
if (material != null) {
|
||||||
return material;
|
return material;
|
||||||
}
|
}
|
||||||
material = Databases.findMaterial(Material.Type.SURFACE, translated_value);
|
material = Databases.findMaterial(Material.Type.SURFACE, translated_value);
|
||||||
if ( material != null ) {
|
if (material != null) {
|
||||||
return material;
|
return material;
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Invalid material " + value + " in component preset.");
|
throw new IllegalArgumentException("Invalid material " + value + " in component preset.");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user