Synchronize table selection across motors, recovery & stage
This commit is contained in:
parent
687fb6f6e3
commit
a210661ccd
@ -20,6 +20,7 @@ import net.miginfocom.swing.MigLayout;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.document.Simulation;
|
||||
import net.sf.openrocket.gui.dialogs.flightconfiguration.RenameConfigDialog;
|
||||
import net.sf.openrocket.gui.main.flightconfigpanel.FlightConfigurablePanel;
|
||||
import net.sf.openrocket.gui.main.flightconfigpanel.MotorConfigurationPanel;
|
||||
import net.sf.openrocket.gui.main.flightconfigpanel.RecoveryConfigurationPanel;
|
||||
import net.sf.openrocket.gui.main.flightconfigpanel.SeparationConfigurationPanel;
|
||||
@ -113,23 +114,29 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
|
||||
this.add(duplicateConfButton, "wrap");
|
||||
|
||||
tabs.addChangeListener(new ChangeListener() {
|
||||
private FlightConfigurablePanel<?> previousPanel = null;
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
// Trigger a selection of the motor/recovery/configuration item
|
||||
FlightConfigurablePanel<?> panel = null;
|
||||
switch (tabs.getSelectedIndex()) {
|
||||
case MOTOR_TAB_INDEX:
|
||||
motorConfigurationPanel.updateButtonState();
|
||||
motorConfigurationPanel.takeTheSpotlight();
|
||||
panel = motorConfigurationPanel;
|
||||
break;
|
||||
case RECOVERY_TAB_INDEX:
|
||||
recoveryConfigurationPanel.updateButtonState();
|
||||
motorConfigurationPanel.takeTheSpotlight();
|
||||
panel = recoveryConfigurationPanel;
|
||||
break;
|
||||
case SEPARATION_TAB_INDEX:
|
||||
separationConfigurationPanel.updateButtonState();
|
||||
motorConfigurationPanel.takeTheSpotlight();
|
||||
panel = separationConfigurationPanel;
|
||||
break;
|
||||
}
|
||||
|
||||
// Update the panel selection, focus, and button state
|
||||
if (panel == null) return;
|
||||
synchronizePanelSelection(previousPanel, panel);
|
||||
panel.updateButtonState();
|
||||
panel.takeTheSpotlight();
|
||||
previousPanel = panel;
|
||||
}
|
||||
});
|
||||
|
||||
@ -300,6 +307,16 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
|
||||
|
||||
}
|
||||
|
||||
private void synchronizePanelSelection(FlightConfigurablePanel<?> source, FlightConfigurablePanel<?> target) {
|
||||
if (source == null || target == null) return;
|
||||
List<FlightConfigurationId> fids = source.getSelectedConfigurationIds();
|
||||
if (fids == null || fids.isEmpty()) {
|
||||
target.clearSelection();
|
||||
} else {
|
||||
target.setSelectedConfigurationIds(fids);
|
||||
}
|
||||
}
|
||||
|
||||
private List<FlightConfigurationId> getSelectedConfigurationIds() {
|
||||
switch (tabs.getSelectedIndex()) {
|
||||
case MOTOR_TAB_INDEX:
|
||||
|
@ -175,7 +175,7 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
|
||||
int row = table.rowAtPoint(e.getPoint());
|
||||
int col = table.columnAtPoint(e.getPoint());
|
||||
if (row == -1 || col == -1) {
|
||||
table.clearSelection();
|
||||
clearSelection();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -189,6 +189,10 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
|
||||
*/
|
||||
protected abstract JTable initializeTable();
|
||||
|
||||
public void clearSelection() {
|
||||
table.clearSelection();
|
||||
}
|
||||
|
||||
protected T getSelectedComponent() {
|
||||
|
||||
int col = table.convertColumnIndexToModel(table.getSelectedColumn());
|
||||
@ -269,6 +273,25 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
|
||||
return Ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select the rows of the table that correspond to the given FlightConfigurationIds. The second column of the table
|
||||
* will be used for the selection.
|
||||
* @param fids flight configuration ids to select
|
||||
*/
|
||||
public void setSelectedConfigurationIds(List<FlightConfigurationId> fids) {
|
||||
if (fids == null || fids.isEmpty() || table.getColumnCount() == 0) return;
|
||||
|
||||
for (FlightConfigurationId id : fids) {
|
||||
if (id == FlightConfigurationId.DEFAULT_VALUE_FCID) continue;
|
||||
for (int rowNum = 0; rowNum < table.getRowCount(); rowNum++) {
|
||||
FlightConfigurationId rowFCID = rocket.getId(rowNum );
|
||||
if (rowFCID.equals(id) && !table.isRowSelected(rowNum)) {
|
||||
table.changeSelection(rowNum, 1, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract class FlightConfigurableCellRenderer extends DefaultTableCellRenderer {
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user