diff --git a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorMountConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorMountConfigurationPanel.java index 35231e3cc..527fe69fc 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorMountConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorMountConfigurationPanel.java @@ -13,19 +13,14 @@ import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.rocketcomponent.Rocket; @SuppressWarnings("serial") -public abstract class MotorMountConfigurationPanel extends JPanel { - - private final Rocket rocket; - private final Component parent; +public class MotorMountConfigurationPanel extends JPanel { 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)); + //// Motor Mount selection + MotorMountTableModel model = new MotorMountTableModel( rocket); + JTable table = new JTable( model ); table.setTableHeader(null); table.setShowVerticalLines(false); table.setRowSelectionAllowed(false); @@ -43,6 +38,4 @@ public abstract class MotorMountConfigurationPanel extends JPanel { this.add(scroll, "w 200lp, h 150lp, grow"); } - - public abstract void onDataChanged(); } diff --git a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorMountTableModel.java b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorMountTableModel.java index fe9fbbd8c..4dd515e48 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorMountTableModel.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorMountTableModel.java @@ -17,18 +17,16 @@ import net.sf.openrocket.util.ArrayList; * The table model for selecting whether components are motor mounts or not. */ class MotorMountTableModel extends AbstractTableModel implements ComponentChangeListener { - - private final MotorMountConfigurationPanel motorConfigurationPanel; - - private final List potentialMounts = new ArrayList(); + private static final long serialVersionUID = 1956400848559941228L; + + private final List potentialMounts = new ArrayList(); private final Rocket rocket; /** * @param motorConfigurationPanel */ - MotorMountTableModel(MotorMountConfigurationPanel motorConfigurationPanel, Rocket rocket) { - this.motorConfigurationPanel = motorConfigurationPanel; + MotorMountTableModel( Rocket rocket) { this.rocket = rocket; initialize(); @@ -101,7 +99,7 @@ class MotorMountTableModel extends AbstractTableModel implements ComponentChange throw new IllegalArgumentException("column=" + column + ", value=" + value); } - Log.warn("this method is no longer useful....: setValueAt(obj,int,int):104"); - //this.motorConfigurationPanel.onDataChanged(); + MotorMount mount = potentialMounts.get(row); + mount.setMotorMount((Boolean) value); } } \ No newline at end of file diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java index 301b6fb80..83ddfb1f9 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java @@ -60,13 +60,7 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel JLabel label = new StyledLabel(trans.get("lbl.motorMounts"), Style.BOLD); subpanel.add(label, "wrap"); - MotorMountConfigurationPanel mountConfigPanel = new MotorMountConfigurationPanel(this,rocket) { - - @Override - public void onDataChanged() { - MotorConfigurationPanel.this.fireTableDataChanged(); - } - }; + MotorMountConfigurationPanel mountConfigPanel = new MotorMountConfigurationPanel(this,rocket); subpanel.add(mountConfigPanel, "grow"); this.add(subpanel, "split, w 200lp, growy"); } diff --git a/swing/src/net/sf/openrocket/gui/util/GUIUtil.java b/swing/src/net/sf/openrocket/gui/util/GUIUtil.java index e3525963e..d4cf3b322 100644 --- a/swing/src/net/sf/openrocket/gui/util/GUIUtil.java +++ b/swing/src/net/sf/openrocket/gui/util/GUIUtil.java @@ -372,7 +372,7 @@ public class GUIUtil { for (int col = 0; col < columns; col++) { - System.err.println("Setting column " + col + " to width " + widths[col]); + //System.err.println("Setting column " + col + " to width " + widths[col]); table.getColumnModel().getColumn(col).setPreferredWidth(Math.min(widths[col], max) * 100); } } @@ -576,6 +576,7 @@ public class GUIUtil { public static class BooleanTableClickListener extends MouseAdapter { private final JTable table; + // these are different because the MouseEvent and the model use different indexing (0- vs 1-) private final int clickColumn; private final int booleanColumn; @@ -596,34 +597,35 @@ public class GUIUtil { if (e.getButton() != MouseEvent.BUTTON1) return; - Point p = e.getPoint(); - int col = table.columnAtPoint(p); - if (col < 0) + final Point p = e.getPoint(); + final int tableColumn = table.columnAtPoint(p); + if (tableColumn < 0) return; - col = table.convertColumnIndexToModel(col); - if (col != clickColumn) + + final int modelColumn= table.convertColumnIndexToModel(tableColumn); + if (modelColumn != clickColumn) return; - - int row = table.rowAtPoint(p); - if (row < 0) + + final int tableRow = table.rowAtPoint(p); + if (tableRow < 0) return; - row = table.convertRowIndexToModel(row); - if (row < 0) + + final int modelRow = table.convertRowIndexToModel(tableRow); + if ( modelRow < 0) return; - + TableModel model = table.getModel(); - Object value = model.getValueAt(row, booleanColumn); - - if (!(value instanceof Boolean)) { - throw new IllegalStateException("Table value at row=" + row + " col=" + + final Object value = model.getValueAt(modelRow, booleanColumn); + if (!(value instanceof Boolean)) { + throw new IllegalStateException("Table value at row=" + modelRow + " col=" + booleanColumn + " is not a Boolean, value=" + value); } - Boolean b = (Boolean) value; - b = !b; - model.setValueAt(b, row, booleanColumn); + final Boolean oldValue = (Boolean) value; + final Boolean newValue = !oldValue; + model.setValueAt(newValue, tableRow, booleanColumn); if (model instanceof AbstractTableModel) { - ((AbstractTableModel) model).fireTableCellUpdated(row, booleanColumn); + ((AbstractTableModel) model).fireTableCellUpdated(tableRow, booleanColumn); } }