[Resolves #379] Can now toggle motormounts from the Motor Configuration Tab
- Actual Fix is at MotorMountTableModel:102: re-added callback to the MotorMount component - cleaned up unused variables in the other panels - Tightened up variable re-use in GUIUtil class -- made several intermediate variables separate, uniquely-named, and final.
This commit is contained in:
parent
cfc1715cf4
commit
9bfaf8877e
@ -13,19 +13,14 @@ import net.sf.openrocket.gui.util.GUIUtil;
|
|||||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public abstract class MotorMountConfigurationPanel extends JPanel {
|
public class MotorMountConfigurationPanel extends JPanel {
|
||||||
|
|
||||||
private final Rocket rocket;
|
|
||||||
private final Component parent;
|
|
||||||
|
|
||||||
public MotorMountConfigurationPanel( Component parent, Rocket rocket ) {
|
public MotorMountConfigurationPanel( Component parent, Rocket rocket ) {
|
||||||
super(new MigLayout("") );
|
super(new MigLayout("") );
|
||||||
|
|
||||||
this.parent = parent;
|
|
||||||
this.rocket = rocket;
|
|
||||||
|
|
||||||
//// Motor Mount selection
|
//// Motor Mount selection
|
||||||
JTable table = new JTable(new MotorMountTableModel(this, rocket));
|
MotorMountTableModel model = new MotorMountTableModel( rocket);
|
||||||
|
JTable table = new JTable( model );
|
||||||
table.setTableHeader(null);
|
table.setTableHeader(null);
|
||||||
table.setShowVerticalLines(false);
|
table.setShowVerticalLines(false);
|
||||||
table.setRowSelectionAllowed(false);
|
table.setRowSelectionAllowed(false);
|
||||||
@ -43,6 +38,4 @@ public abstract class MotorMountConfigurationPanel extends JPanel {
|
|||||||
this.add(scroll, "w 200lp, h 150lp, grow");
|
this.add(scroll, "w 200lp, h 150lp, grow");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void onDataChanged();
|
|
||||||
}
|
}
|
||||||
|
@ -17,18 +17,16 @@ import net.sf.openrocket.util.ArrayList;
|
|||||||
* The table model for selecting whether components are motor mounts or not.
|
* The table model for selecting whether components are motor mounts or not.
|
||||||
*/
|
*/
|
||||||
class MotorMountTableModel extends AbstractTableModel implements ComponentChangeListener {
|
class MotorMountTableModel extends AbstractTableModel implements ComponentChangeListener {
|
||||||
|
private static final long serialVersionUID = 1956400848559941228L;
|
||||||
|
|
||||||
private final MotorMountConfigurationPanel motorConfigurationPanel;
|
private final List<MotorMount> potentialMounts = new ArrayList<MotorMount>();
|
||||||
|
|
||||||
private final List<MotorMount> potentialMounts = new ArrayList<MotorMount>();
|
|
||||||
|
|
||||||
private final Rocket rocket;
|
private final Rocket rocket;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param motorConfigurationPanel
|
* @param motorConfigurationPanel
|
||||||
*/
|
*/
|
||||||
MotorMountTableModel(MotorMountConfigurationPanel motorConfigurationPanel, Rocket rocket) {
|
MotorMountTableModel( Rocket rocket) {
|
||||||
this.motorConfigurationPanel = motorConfigurationPanel;
|
|
||||||
this.rocket = rocket;
|
this.rocket = rocket;
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
@ -101,7 +99,7 @@ class MotorMountTableModel extends AbstractTableModel implements ComponentChange
|
|||||||
throw new IllegalArgumentException("column=" + column + ", value=" + value);
|
throw new IllegalArgumentException("column=" + column + ", value=" + value);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.warn("this method is no longer useful....: setValueAt(obj,int,int):104");
|
MotorMount mount = potentialMounts.get(row);
|
||||||
//this.motorConfigurationPanel.onDataChanged();
|
mount.setMotorMount((Boolean) value);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -60,13 +60,7 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
|||||||
JLabel label = new StyledLabel(trans.get("lbl.motorMounts"), Style.BOLD);
|
JLabel label = new StyledLabel(trans.get("lbl.motorMounts"), Style.BOLD);
|
||||||
subpanel.add(label, "wrap");
|
subpanel.add(label, "wrap");
|
||||||
|
|
||||||
MotorMountConfigurationPanel mountConfigPanel = new MotorMountConfigurationPanel(this,rocket) {
|
MotorMountConfigurationPanel mountConfigPanel = new MotorMountConfigurationPanel(this,rocket);
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDataChanged() {
|
|
||||||
MotorConfigurationPanel.this.fireTableDataChanged();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
subpanel.add(mountConfigPanel, "grow");
|
subpanel.add(mountConfigPanel, "grow");
|
||||||
this.add(subpanel, "split, w 200lp, growy");
|
this.add(subpanel, "split, w 200lp, growy");
|
||||||
}
|
}
|
||||||
|
@ -372,7 +372,7 @@ public class GUIUtil {
|
|||||||
|
|
||||||
|
|
||||||
for (int col = 0; col < columns; col++) {
|
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);
|
table.getColumnModel().getColumn(col).setPreferredWidth(Math.min(widths[col], max) * 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -576,6 +576,7 @@ public class GUIUtil {
|
|||||||
public static class BooleanTableClickListener extends MouseAdapter {
|
public static class BooleanTableClickListener extends MouseAdapter {
|
||||||
|
|
||||||
private final JTable table;
|
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 clickColumn;
|
||||||
private final int booleanColumn;
|
private final int booleanColumn;
|
||||||
|
|
||||||
@ -596,34 +597,35 @@ public class GUIUtil {
|
|||||||
if (e.getButton() != MouseEvent.BUTTON1)
|
if (e.getButton() != MouseEvent.BUTTON1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Point p = e.getPoint();
|
final Point p = e.getPoint();
|
||||||
int col = table.columnAtPoint(p);
|
final int tableColumn = table.columnAtPoint(p);
|
||||||
if (col < 0)
|
if (tableColumn < 0)
|
||||||
return;
|
|
||||||
col = table.convertColumnIndexToModel(col);
|
|
||||||
if (col != clickColumn)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int row = table.rowAtPoint(p);
|
final int modelColumn= table.convertColumnIndexToModel(tableColumn);
|
||||||
if (row < 0)
|
if (modelColumn != clickColumn)
|
||||||
return;
|
return;
|
||||||
row = table.convertRowIndexToModel(row);
|
|
||||||
if (row < 0)
|
final int tableRow = table.rowAtPoint(p);
|
||||||
|
if (tableRow < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
final int modelRow = table.convertRowIndexToModel(tableRow);
|
||||||
|
if ( modelRow < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
TableModel model = table.getModel();
|
TableModel model = table.getModel();
|
||||||
Object value = model.getValueAt(row, booleanColumn);
|
final Object value = model.getValueAt(modelRow, booleanColumn);
|
||||||
|
if (!(value instanceof Boolean)) {
|
||||||
if (!(value instanceof Boolean)) {
|
throw new IllegalStateException("Table value at row=" + modelRow + " col=" +
|
||||||
throw new IllegalStateException("Table value at row=" + row + " col=" +
|
|
||||||
booleanColumn + " is not a Boolean, value=" + value);
|
booleanColumn + " is not a Boolean, value=" + value);
|
||||||
}
|
}
|
||||||
|
|
||||||
Boolean b = (Boolean) value;
|
final Boolean oldValue = (Boolean) value;
|
||||||
b = !b;
|
final Boolean newValue = !oldValue;
|
||||||
model.setValueAt(b, row, booleanColumn);
|
model.setValueAt(newValue, tableRow, booleanColumn);
|
||||||
if (model instanceof AbstractTableModel) {
|
if (model instanceof AbstractTableModel) {
|
||||||
((AbstractTableModel) model).fireTableCellUpdated(row, booleanColumn);
|
((AbstractTableModel) model).fireTableCellUpdated(tableRow, booleanColumn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user