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 net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
|
||||
import net.sf.openrocket.rocketcomponent.ComponentChangeListener;
|
||||
import net.sf.openrocket.rocketcomponent.MotorMount;
|
||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||
@ -12,25 +14,42 @@ import net.sf.openrocket.util.ArrayList;
|
||||
/**
|
||||
* 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 List<MotorMount> potentialMounts = new ArrayList<MotorMount>();
|
||||
|
||||
private final Rocket rocket;
|
||||
|
||||
/**
|
||||
* @param motorConfigurationPanel
|
||||
*/
|
||||
MotorMountTableModel(MotorMountConfigurationPanel motorConfigurationPanel, Rocket rocket) {
|
||||
this.motorConfigurationPanel = motorConfigurationPanel;
|
||||
this.rocket = rocket;
|
||||
|
||||
initialize();
|
||||
rocket.addComponentChangeListener(this);
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
potentialMounts.clear();
|
||||
for (RocketComponent c : rocket) {
|
||||
if (c instanceof MotorMount) {
|
||||
potentialMounts.add((MotorMount) c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void componentChanged(ComponentChangeEvent e) {
|
||||
if ( e.isMotorChange() || e.isTreeChange() ) {
|
||||
initialize();
|
||||
fireTableStructureChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return 2;
|
||||
|
Loading…
x
Reference in New Issue
Block a user