Added more buttons to configuration including broken copy button. Added

tab layout to pane.  Added ignition spec to motor config table but
haven't hooked it up.
This commit is contained in:
kruland2607 2012-10-16 11:04:01 -05:00
parent 25c5dfec49
commit d00dc2ff34
4 changed files with 220 additions and 159 deletions

View File

@ -175,15 +175,17 @@ MotorChooserDialog.title = Select a rocket motor
! Edit Motor configuration dialog ! Edit Motor configuration dialog
edtmotorconfdlg.but.removemotor = Remove motor edtmotorconfdlg.but.removemotor = Remove motor
edtmotorconfdlg.but.Selectmotor = Select motor edtmotorconfdlg.but.Selectmotor = Select motor
edtmotorconfdlg.but.Removeconfiguration = Remove configuration edtmotorconfdlg.but.Removeconfiguration = Remove
edtmotorconfdlg.but.Newconfiguration = New configuration edtmotorconfdlg.but.Renameconfiguration = Rename
edtmotorconfdlg.but.Newconfiguration = New
edtmotorconfdlg.but.Copyconfiguration = Copy
edtmotorconfdlg.lbl.Motormounts = <html><b>Motor mounts:</b> edtmotorconfdlg.lbl.Motormounts = <html><b>Motor mounts:</b>
edtmotorconfdlg.title.Editmotorconf = Edit motor configurations edtmotorconfdlg.title.Editmotorconf = Edit motor configurations
edtmotorconfdlg.selectcomp = <html>Select which components function as motor mounts: edtmotorconfdlg.selectcomp = <html>Select which components function as motor mounts:
edtmotorconfdlg.lbl.Motorconfig = <html><b>Motor configurations:</b> edtmotorconfdlg.lbl.Motorconfig = <html><b>Motor configurations:</b>
edtmotorconfdlg.lbl.Configname = Configuration name: edtmotorconfdlg.lbl.Configname = Configuration name:
edtmotorconfdlg.lbl.Leavenamedefault = Leave name empty for default. edtmotorconfdlg.lbl.Motortab = Motors
edtmotorconfdlg.lbl.Advancemode = Advanced mode
! Example design dialog ! Example design dialog
exdesigndlg.but.open = Open exdesigndlg.but.open = Open
exdesigndlg.lbl.Selectexample = Select example designs to open: exdesigndlg.lbl.Selectexample = Select example designs to open:

View File

@ -12,13 +12,14 @@ import java.util.List;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JComboBox; import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog; import javax.swing.JDialog;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable; import javax.swing.JTable;
import javax.swing.ListSelectionModel; import javax.swing.ListSelectionModel;
import javax.swing.event.ListDataEvent;
import javax.swing.table.TableColumn; import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel; import javax.swing.table.TableColumnModel;
@ -35,60 +36,59 @@ import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Application;
public class FlightConfigurationDialog extends JDialog { public class FlightConfigurationDialog extends JDialog {
final Rocket rocket; final Rocket rocket;
final MotorMount[] mounts; final MotorMount[] mounts;
private final JTable configurationTable; MotorConfigurationTableModel configurationTableModel;
final MotorConfigurationTableModel configurationTableModel; FlightConfigurationModel flightConfigurationModel;
final FlightConfigurationModel flightConfigurationModel;
private final JButton renameConfButton, removeConfButton; private final JButton renameConfButton, removeConfButton, copyConfButton;
private final JButton selectMotorButton, removeMotorButton; private JButton selectMotorButton, removeMotorButton;
String currentID = null; String currentID = null;
private MotorMount currentMount = null; private MotorMount currentMount = null;
static final Translator trans = Application.getTranslator(); static final Translator trans = Application.getTranslator();
public FlightConfigurationDialog(final Rocket rocket, Window parent) { public FlightConfigurationDialog(final Rocket rocket, Window parent) {
//// Edit motor configurations //// Edit motor configurations
super(parent, trans.get("edtmotorconfdlg.title.Editmotorconf")); super(parent, trans.get("edtmotorconfdlg.title.Editmotorconf"));
currentID = rocket.getDefaultConfiguration().getMotorConfigurationID(); currentID = rocket.getDefaultConfiguration().getMotorConfigurationID();
if (parent != null) if (parent != null)
this.setModalityType(ModalityType.DOCUMENT_MODAL); this.setModalityType(ModalityType.DOCUMENT_MODAL);
else else
this.setModalityType(ModalityType.APPLICATION_MODAL); this.setModalityType(ModalityType.APPLICATION_MODAL);
this.rocket = rocket; this.rocket = rocket;
mounts = getPotentialMotorMounts(); mounts = getPotentialMotorMounts();
JPanel panel = new JPanel(new MigLayout("fill, wrap 5")); JPanel panel = new JPanel(new MigLayout("fill"));
JLabel label = new JLabel("Selected Configuration: "); JLabel label = new JLabel("Selected Configuration: ");
panel.add(label,"gapbottom para"); panel.add(label);
flightConfigurationModel = new FlightConfigurationModel(rocket.getDefaultConfiguration()); flightConfigurationModel = new FlightConfigurationModel(rocket.getDefaultConfiguration());
JComboBox configSelector = new JComboBox(flightConfigurationModel); JComboBox configSelector = new JComboBox(flightConfigurationModel);
panel.add(configSelector,"gapright para"); panel.add(configSelector,"gapright para");
JButton newConfButton = new JButton(trans.get("edtmotorconfdlg.but.Newconfiguration")); JButton newConfButton = new JButton(trans.get("edtmotorconfdlg.but.Newconfiguration"));
newConfButton.addActionListener( new ActionListener() { newConfButton.addActionListener( new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
FlightConfigurationDialog.this.addConfiguration(); FlightConfigurationDialog.this.addConfiguration();
} }
}); });
panel.add(newConfButton); panel.add(newConfButton);
renameConfButton = new JButton("Rename Configuration"); renameConfButton = new JButton(trans.get("edtmotorconfdlg.but.Renameconfiguration"));
renameConfButton.addActionListener( new ActionListener() { renameConfButton.addActionListener( new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@ -96,7 +96,7 @@ public class FlightConfigurationDialog extends JDialog {
} }
}); });
panel.add(renameConfButton); panel.add(renameConfButton);
//// Remove configuration //// Remove configuration
removeConfButton = new JButton(trans.get("edtmotorconfdlg.but.Removeconfiguration")); removeConfButton = new JButton(trans.get("edtmotorconfdlg.but.Removeconfiguration"));
removeConfButton.addActionListener(new ActionListener() { removeConfButton.addActionListener(new ActionListener() {
@ -105,87 +105,26 @@ public class FlightConfigurationDialog extends JDialog {
removeConfiguration(); removeConfiguration();
} }
}); });
panel.add(removeConfButton,"wrap"); panel.add(removeConfButton);
//// Motor mount selection //// Copy configuration
//// <html><b>Motor mounts:</b> copyConfButton = new JButton(trans.get("edtmotorconfdlg.but.Copyconfiguration"));
label = new JLabel(trans.get("edtmotorconfdlg.lbl.Motormounts")); copyConfButton.addActionListener(new ActionListener() {
panel.add(label, "gapbottom para");
//// Motor selection
//// <html><b>Motor configurations:</b>
label = new JLabel(trans.get("edtmotorconfdlg.lbl.Motorconfig"));
panel.add(label, "span 4, gapbottom para");
//// <html>Select which components function as motor mounts:
label = new JLabel(trans.get("edtmotorconfdlg.selectcomp"));
panel.add(label, "ay 100%, w 1px, growx, wrap");
//// Motor Mount selection
JTable table = new JTable(new MotorMountTableModel(this));
table.setTableHeader(null);
table.setShowVerticalLines(false);
table.setRowSelectionAllowed(false);
table.setColumnSelectionAllowed(false);
TableColumnModel columnModel = table.getColumnModel();
TableColumn col0 = columnModel.getColumn(0);
int w = table.getRowHeight() + 2;
col0.setMinWidth(w);
col0.setPreferredWidth(w);
col0.setMaxWidth(w);
table.addMouseListener(new GUIUtil.BooleanTableClickListener(table));
JScrollPane scroll = new JScrollPane(table);
panel.add(scroll, "w 200lp, h 150lp, grow");
//// Motor selection table.
configurationTableModel = new MotorConfigurationTableModel(this);
configurationTable = new JTable(configurationTableModel);
configurationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
configurationTable.setCellSelectionEnabled(true);
configurationTable.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 1) {
// Single click updates selection
updateButtonState();
} else if (e.getClickCount() == 2) {
// Double-click edits motor
selectMotor();
}
}
});
scroll = new JScrollPane(configurationTable);
panel.add(scroll, "span 4, w 500lp, h 150lp, grow");
//// Select motor
selectMotorButton = new JButton(trans.get("edtmotorconfdlg.but.Selectmotor"));
selectMotorButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
selectMotor(); // FIXME - !
} }
}); });
panel.add(selectMotorButton, "sizegroup button"); panel.add(copyConfButton,"wrap");
//// Remove motor button
removeMotorButton = new JButton(trans.get("edtmotorconfdlg.but.removemotor")); //// Tabs for advanced view.
removeMotorButton.addActionListener(new ActionListener() { JTabbedPane tabs = new JTabbedPane();
@Override
public void actionPerformed(ActionEvent e) { //// Motor tabs
removeMotor(); JComponent motorTab = makeMotorTab();
} tabs.add(trans.get("edtmotorconfdlg.lbl.Motortab"), motorTab);
}); panel.add( tabs, "spanx, w 700lp, h 500lp, wrap");
panel.add(removeMotorButton,"sizegroup button, wrap");
//// Close button //// Close button
JButton close = new JButton(trans.get("dlg.but.close")); JButton close = new JButton(trans.get("dlg.but.close"));
@ -196,16 +135,16 @@ public class FlightConfigurationDialog extends JDialog {
} }
}); });
panel.add(close, "spanx, right"); panel.add(close, "spanx, right");
this.add(panel); this.add(panel);
this.validate(); this.validate();
this.pack(); this.pack();
updateButtonState(); updateButtonState();
this.setLocationByPlatform(true); this.setLocationByPlatform(true);
GUIUtil.setDisposableDialogOptions(this, close); GUIUtil.setDisposableDialogOptions(this, close);
// Undo description // Undo description
final OpenRocketDocument document = BasicFrame.findDocument(rocket); final OpenRocketDocument document = BasicFrame.findDocument(rocket);
if (document != null) { if (document != null) {
@ -219,8 +158,7 @@ public class FlightConfigurationDialog extends JDialog {
}); });
} }
} }
private MotorMount[] getPotentialMotorMounts() { private MotorMount[] getPotentialMotorMounts() {
List<MotorMount> list = new ArrayList<MotorMount>(); List<MotorMount> list = new ArrayList<MotorMount>();
for (RocketComponent c : rocket) { for (RocketComponent c : rocket) {
@ -237,7 +175,7 @@ public class FlightConfigurationDialog extends JDialog {
configurationTableModel.fireTableDataChanged(); configurationTableModel.fireTableDataChanged();
updateButtonState(); updateButtonState();
} }
public void addConfiguration() { public void addConfiguration() {
currentID = rocket.newMotorConfigurationID(); currentID = rocket.newMotorConfigurationID();
rocket.getDefaultConfiguration().setMotorConfigurationID(currentID); rocket.getDefaultConfiguration().setMotorConfigurationID(currentID);
@ -245,13 +183,13 @@ public class FlightConfigurationDialog extends JDialog {
flightConfigurationModel.fireContentsUpdated(); flightConfigurationModel.fireContentsUpdated();
updateButtonState(); updateButtonState();
} }
public void changeConfigurationName( String newName ) { public void changeConfigurationName( String newName ) {
rocket.setMotorConfigurationName(currentID, newName); rocket.setMotorConfigurationName(currentID, newName);
configurationTableModel.fireTableDataChanged(); configurationTableModel.fireTableDataChanged();
flightConfigurationModel.fireContentsUpdated(); flightConfigurationModel.fireContentsUpdated();
} }
public void removeConfiguration() { public void removeConfiguration() {
if (currentID == null) if (currentID == null)
return; return;
@ -261,55 +199,53 @@ public class FlightConfigurationDialog extends JDialog {
flightConfigurationModel.fireContentsUpdated(); flightConfigurationModel.fireContentsUpdated();
updateButtonState(); updateButtonState();
} }
void updateButtonState() { void updateButtonState() {
removeConfButton.setEnabled(currentID != null); removeConfButton.setEnabled(currentID != null);
renameConfButton.setEnabled(currentID != null); renameConfButton.setEnabled(currentID != null);
selectMotorButton.setEnabled(currentMount != null && currentID != null); selectMotorButton.setEnabled(currentMount != null && currentID != null);
removeMotorButton.setEnabled(currentMount != null && currentID != null); removeMotorButton.setEnabled(currentMount != null && currentID != null);
} }
private void selectMotor() { private void selectMotor() {
if (currentID == null || currentMount == null) if (currentID == null || currentMount == null)
return; return;
MotorChooserDialog dialog = new MotorChooserDialog(currentMount.getMotor(currentID), MotorChooserDialog dialog = new MotorChooserDialog(currentMount.getMotor(currentID),
currentMount.getMotorDelay(currentID), currentMount.getMotorMountDiameter(), this); currentMount.getMotorDelay(currentID), currentMount.getMotorMountDiameter(), this);
dialog.setVisible(true); dialog.setVisible(true);
Motor m = dialog.getSelectedMotor(); Motor m = dialog.getSelectedMotor();
double d = dialog.getSelectedDelay(); double d = dialog.getSelectedDelay();
if (m != null) { if (m != null) {
currentMount.setMotor(currentID, m); currentMount.setMotor(currentID, m);
currentMount.setMotorDelay(currentID, d); currentMount.setMotorDelay(currentID, d);
} }
int row = configurationTable.getSelectedRow(); configurationTableModel.fireTableDataChanged();
configurationTableModel.fireTableRowsUpdated(row, row);
updateButtonState(); updateButtonState();
} }
private void removeMotor() { private void removeMotor() {
if (currentID == null || currentMount == null) if (currentID == null || currentMount == null)
return; return;
currentMount.setMotor(currentID, null); currentMount.setMotor(currentID, null);
int row = configurationTable.getSelectedRow(); configurationTableModel.fireTableDataChanged();
configurationTableModel.fireTableRowsUpdated(row, row);
updateButtonState(); updateButtonState();
} }
String findID(int row) { String findID(int row) {
return rocket.getMotorConfigurationIDs()[row + 1]; return rocket.getMotorConfigurationIDs()[row + 1];
} }
MotorMount findMount(int column) { MotorMount findMount(int column) {
MotorMount mount = null; MotorMount mount = null;
int count = column; int count = column;
for (MotorMount m : mounts) { for (MotorMount m : mounts) {
if (m.isMotorMount()) if (m.isMotorMount())
@ -319,11 +255,108 @@ public class FlightConfigurationDialog extends JDialog {
break; break;
} }
} }
if (mount == null) { if (mount == null) {
throw new IndexOutOfBoundsException("motor mount not found, column=" + column); throw new IndexOutOfBoundsException("motor mount not found, column=" + column);
} }
return mount; return mount;
} }
private JComponent makeMotorTab( ) {
JPanel panel = new JPanel(new MigLayout("fill"));
//// Motor mount selection
//// <html><b>Motor mounts:</b>
JLabel label = new JLabel(trans.get("edtmotorconfdlg.lbl.Motormounts"));
panel.add(label, "gapbottom para");
//// Motor selection
//// <html><b>Motor configurations:</b>
label = new JLabel(trans.get("edtmotorconfdlg.lbl.Motorconfig"));
panel.add(label, "gapbottom para, wrap");
//// <html>Select which components function as motor mounts:
label = new JLabel(trans.get("edtmotorconfdlg.selectcomp"));
panel.add(label, "ay 100%, w 1px, growx, wrap");
//// Motor Mount selection
JTable table = new JTable(new MotorMountTableModel(this));
table.setTableHeader(null);
table.setShowVerticalLines(false);
table.setRowSelectionAllowed(false);
table.setColumnSelectionAllowed(false);
TableColumnModel columnModel = table.getColumnModel();
TableColumn col0 = columnModel.getColumn(0);
int w = table.getRowHeight() + 2;
col0.setMinWidth(w);
col0.setPreferredWidth(w);
col0.setMaxWidth(w);
table.addMouseListener(new GUIUtil.BooleanTableClickListener(table));
JScrollPane scroll = new JScrollPane(table);
panel.add(scroll, "w 200lp, h 150lp, grow");
//// Motor selection table.
configurationTableModel = new MotorConfigurationTableModel(this, true);
final JTable configurationTable = new JTable(configurationTableModel);
configurationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
configurationTable.setCellSelectionEnabled(true);
configurationTable.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
JTable table = (JTable) e.getComponent();
int row = configurationTable.getSelectedRow();
int column = configurationTable.getSelectedColumn();
if ( row >= 0 & column == 1) {
currentMount = findMount(row);
} else {
currentMount = null;
}
if (e.getClickCount() == 1) {
// Single click updates selection
updateButtonState();
} else if (e.getClickCount() == 2) {
// Double-click edits motor
selectMotor();
}
}
});
scroll = new JScrollPane(configurationTable);
panel.add(scroll, "w 500lp, h 150lp, grow, wrap");
//// Select motor
selectMotorButton = new JButton(trans.get("edtmotorconfdlg.but.Selectmotor"));
selectMotorButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
selectMotor();
}
});
panel.add(selectMotorButton, "skip, split, sizegroup button");
//// Remove motor button
removeMotorButton = new JButton(trans.get("edtmotorconfdlg.but.removemotor"));
removeMotorButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
removeMotor();
}
});
panel.add(removeMotorButton,"sizegroup button, wrap");
return panel;
}
} }

View File

@ -4,32 +4,35 @@ import javax.swing.table.AbstractTableModel;
import net.sf.openrocket.motor.Motor; import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.MotorMount.IgnitionEvent;
import net.sf.openrocket.util.Chars; import net.sf.openrocket.util.Chars;
/** /**
* The table model for selecting and editing the motor configurations. * The table model for selecting and editing the motor configurations.
*/ */
class MotorConfigurationTableModel extends AbstractTableModel { class MotorConfigurationTableModel extends AbstractTableModel {
/** /**
* *
*/ */
private final FlightConfigurationDialog flightConfigurationDialog; private final FlightConfigurationDialog flightConfigurationDialog;
private final boolean advanced;
/** /**
* @param flightConfigurationDialog * @param flightConfigurationDialog
*/ */
MotorConfigurationTableModel( FlightConfigurationDialog flightConfigurationDialog) { MotorConfigurationTableModel( FlightConfigurationDialog flightConfigurationDialog, boolean advanced) {
this.flightConfigurationDialog = flightConfigurationDialog; this.flightConfigurationDialog = flightConfigurationDialog;
this.advanced = advanced;
} }
@Override @Override
public int getColumnCount() { public int getColumnCount() {
int count = 2; int count = (advanced)? 3: 2;
return count; return count;
} }
@Override @Override
public int getRowCount() { public int getRowCount() {
int count = 0; int count = 0;
@ -39,13 +42,15 @@ class MotorConfigurationTableModel extends AbstractTableModel {
} }
return count; return count;
} }
@Override @Override
public Object getValueAt(int row, int column) { public Object getValueAt(int row, int column) {
String id = this.flightConfigurationDialog.currentID; String id = this.flightConfigurationDialog.currentID;
if (column == 0) { switch( column ) {
case 0:
{
MotorMount mount = this.flightConfigurationDialog.findMount(row); MotorMount mount = this.flightConfigurationDialog.findMount(row);
String name = mount.toString(); String name = mount.toString();
int count = mount.getMotorCount(); int count = mount.getMotorCount();
@ -53,31 +58,50 @@ class MotorConfigurationTableModel extends AbstractTableModel {
name = name + " (" + Chars.TIMES + count + ")"; name = name + " (" + Chars.TIMES + count + ")";
} }
return name; return name;
} else {
MotorMount mount = this.flightConfigurationDialog.findMount(row);
Motor motor = mount.getMotor(id);
if (motor == null)
//// None
return "None";
String str = motor.getDesignation(mount.getMotorDelay(id));
int count = mount.getMotorCount();
if (count > 1) {
str = "" + count + Chars.TIMES + " " + str;
} }
return str; case 1:
{
MotorMount mount = this.flightConfigurationDialog.findMount(row);
Motor motor = mount.getMotor(id);
if (motor == null)
//// None
return "None";
String str = motor.getDesignation(mount.getMotorDelay(id));
int count = mount.getMotorCount();
if (count > 1) {
str = "" + count + Chars.TIMES + " " + str;
}
return str;
}
case 2:
{
MotorMount mount = this.flightConfigurationDialog.findMount(row);
Motor motor = mount.getMotor(id);
if (motor == null)
//// None
return "None";
IgnitionEvent ignition = mount.getIgnitionEvent();
return ignition.toString();
}
default:
return "";
} }
} }
@Override @Override
public String getColumnName(int column) { public String getColumnName(int column) {
if (column == 0) { switch (column ) {
case 0:
return "Motor Mount"; return "Motor Mount";
} else { case 1:
return "Motor"; return "Motor";
case 2:
return "Ignition";
default:
return "";
} }
} }
} }

View File

@ -63,6 +63,8 @@ public class RenameConfigDialog extends JDialog {
panel.add( cancel ); panel.add( cancel );
this.setContentPane(panel); this.setContentPane(panel);
this.validate();
this.pack();
} }
} }