Refactor MotorMountTable UI currently used in flight configuration

dialog in order to provide reuse.
This commit is contained in:
kruland2607 2013-10-09 12:26:35 -05:00
parent 88ddb86758
commit e091f3341a
3 changed files with 118 additions and 77 deletions

View File

@ -65,23 +65,16 @@ public class MotorConfigurationPanel extends JPanel {
//// Motor Mount selection
JTable table = new JTable(new MotorMountTableModel(this, rocket));
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);
this.add(scroll, "w 200lp, h 150lp, grow");
{
MotorMountConfigurationPanel mountConfigPanel = new MotorMountConfigurationPanel(this,rocket) {
@Override
public void onDataChanged() {
MotorConfigurationPanel.this.fireTableDataChanged();
}
};
this.add(mountConfigPanel, "w 200lp, h 150lp, grow");
}
//// Motor selection table.
configurationTableModel = new MotorConfigurationTableModel(rocket);
@ -107,7 +100,7 @@ public class MotorConfigurationPanel extends JPanel {
}
});
scroll = new JScrollPane(configurationTable);
JScrollPane scroll = new JScrollPane(configurationTable);
this.add(scroll, "w 500lp, h 150lp, grow, wrap");
//// Select motor

View File

@ -0,0 +1,48 @@
package net.sf.openrocket.gui.dialogs.flightconfiguration;
import java.awt.Component;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.rocketcomponent.Rocket;
public abstract class MotorMountConfigurationPanel extends JPanel {
private final Rocket rocket;
private final Component parent;
public MotorMountConfigurationPanel( Component parent, Rocket rocket ) {
super(new MigLayout("") );
this.parent = parent;
this.rocket = rocket;
//// Motor Mount selection
JTable table = new JTable(new MotorMountTableModel(this, rocket));
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);
this.add(scroll, "w 200lp, h 150lp, grow");
}
public abstract void onDataChanged();
}

View File

@ -14,14 +14,14 @@ import net.sf.openrocket.util.ArrayList;
*/
class MotorMountTableModel extends AbstractTableModel {
private final MotorConfigurationPanel motorConfigurationPanel;
private final MotorMountConfigurationPanel motorConfigurationPanel;
private final List<MotorMount> potentialMounts = new ArrayList<MotorMount>();
/**
* @param motorConfigurationPanel
*/
MotorMountTableModel(MotorConfigurationPanel motorConfigurationPanel, Rocket rocket) {
MotorMountTableModel(MotorMountConfigurationPanel motorConfigurationPanel, Rocket rocket) {
this.motorConfigurationPanel = motorConfigurationPanel;
for (RocketComponent c : rocket) {
@ -82,6 +82,6 @@ class MotorMountTableModel extends AbstractTableModel {
MotorMount mount = potentialMounts.get(row);
mount.setMotorMount((Boolean) value);
this.motorConfigurationPanel.fireTableDataChanged();
this.motorConfigurationPanel.onDataChanged();
}
}