Have the MotorMountTableModel listen to changes in the Rocket
configuration to automatically update when the rocket is modified.
This commit is contained in:
parent
8221dd7e06
commit
0778f9117a
@ -4,6 +4,8 @@ import java.util.List;
|
|||||||
|
|
||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
|
|
||||||
|
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
|
||||||
|
import net.sf.openrocket.rocketcomponent.ComponentChangeListener;
|
||||||
import net.sf.openrocket.rocketcomponent.MotorMount;
|
import net.sf.openrocket.rocketcomponent.MotorMount;
|
||||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||||
@ -12,18 +14,27 @@ 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 {
|
class MotorMountTableModel extends AbstractTableModel implements ComponentChangeListener {
|
||||||
|
|
||||||
private final MotorMountConfigurationPanel motorConfigurationPanel;
|
private final MotorMountConfigurationPanel motorConfigurationPanel;
|
||||||
|
|
||||||
private final List<MotorMount> potentialMounts = new ArrayList<MotorMount>();
|
private final List<MotorMount> potentialMounts = new ArrayList<MotorMount>();
|
||||||
|
|
||||||
|
private final Rocket rocket;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param motorConfigurationPanel
|
* @param motorConfigurationPanel
|
||||||
*/
|
*/
|
||||||
MotorMountTableModel(MotorMountConfigurationPanel motorConfigurationPanel, Rocket rocket) {
|
MotorMountTableModel(MotorMountConfigurationPanel motorConfigurationPanel, Rocket rocket) {
|
||||||
this.motorConfigurationPanel = motorConfigurationPanel;
|
this.motorConfigurationPanel = motorConfigurationPanel;
|
||||||
|
this.rocket = rocket;
|
||||||
|
|
||||||
|
initialize();
|
||||||
|
rocket.addComponentChangeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initialize() {
|
||||||
|
potentialMounts.clear();
|
||||||
for (RocketComponent c : rocket) {
|
for (RocketComponent c : rocket) {
|
||||||
if (c instanceof MotorMount) {
|
if (c instanceof MotorMount) {
|
||||||
potentialMounts.add((MotorMount) c);
|
potentialMounts.add((MotorMount) c);
|
||||||
@ -31,6 +42,14 @@ class MotorMountTableModel extends AbstractTableModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void componentChanged(ComponentChangeEvent e) {
|
||||||
|
if ( e.isMotorChange() || e.isTreeChange() ) {
|
||||||
|
initialize();
|
||||||
|
fireTableStructureChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getColumnCount() {
|
public int getColumnCount() {
|
||||||
return 2;
|
return 2;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user