Fix sim table highlight after tab switch
This commit is contained in:
parent
a210661ccd
commit
68d2236654
@ -102,6 +102,7 @@ public class BasicFrame extends JFrame {
|
||||
public static final int DESIGN_TAB = 0;
|
||||
public static final int FLIGHT_CONFIGURATION_TAB = 1;
|
||||
public static final int SIMULATION_TAB = 2;
|
||||
private int previousTab = DESIGN_TAB;
|
||||
|
||||
|
||||
/**
|
||||
@ -1751,6 +1752,10 @@ public class BasicFrame extends JFrame {
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
JTabbedPane tabSource = (JTabbedPane) e.getSource();
|
||||
int tab = tabSource.getSelectedIndex();
|
||||
if (previousTab == SIMULATION_TAB) {
|
||||
simulationPanel.updatePreviousSelection();
|
||||
}
|
||||
previousTab = tab;
|
||||
switch (tab) {
|
||||
case DESIGN_TAB:
|
||||
designPanel.takeTheSpotlight();
|
||||
|
@ -10,7 +10,6 @@ import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
@ -104,6 +103,8 @@ public class SimulationPanel extends JPanel {
|
||||
private final SimulationAction duplicateSimulationAction;
|
||||
private final SimulationAction deleteSimulationAction;
|
||||
|
||||
private int[] previousSelection = null;
|
||||
|
||||
public SimulationPanel(OpenRocketDocument doc) {
|
||||
super(new MigLayout("fill", "[grow][][][][][][grow]"));
|
||||
|
||||
@ -266,6 +267,10 @@ public class SimulationPanel extends JPanel {
|
||||
updateButtonStates();
|
||||
}
|
||||
|
||||
public void updatePreviousSelection() {
|
||||
this.previousSelection = simulationTable.getSelectedRows();
|
||||
}
|
||||
|
||||
private void newSimulation() {
|
||||
Simulation sim = new Simulation(document.getRocket());
|
||||
sim.setName(document.getNextSimulationName());
|
||||
@ -994,18 +999,17 @@ public class SimulationPanel extends JPanel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Focus on the simulation table
|
||||
* Focus on the simulation table and maintain the previous row selection(s).
|
||||
*/
|
||||
public void takeTheSpotlight() {
|
||||
simulationTable.requestFocusInWindow();
|
||||
int selection = simulationTable.getSelectionModel().getAnchorSelectionIndex();
|
||||
if (selection == -1) {
|
||||
if (simulationTable.getRowCount() > 0) {
|
||||
selection = 0;
|
||||
} else {
|
||||
return;
|
||||
if (previousSelection == null || previousSelection.length == 0) {
|
||||
simulationTable.setRowSelectionInterval(0, 0);
|
||||
} else {
|
||||
simulationTable.clearSelection();
|
||||
for (int row : previousSelection) {
|
||||
simulationTable.addRowSelectionInterval(row, row);
|
||||
}
|
||||
}
|
||||
simulationTable.setRowSelectionInterval(selection, selection);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user