Skip to content

Commit

Permalink
Machine Setup Panel Tabs per class restoring and out of bounds bugfix.
Browse files Browse the repository at this point in the history
  • Loading branch information
markmaker committed May 3, 2020
1 parent e61af78 commit 53e7875
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/main/java/org/openpnp/gui/MachineSetupPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.prefs.Preferences;

Expand Down Expand Up @@ -90,7 +91,7 @@ public class MachineSetupPanel extends JPanel implements WizardContainer {
*/
private boolean disableLastSelectedListener = false;
private Object lastSelectedNode = null;
private int lastSelectedTabIndex = 0;
private HashMap<Class, Integer> lastSelectedTabIndex = new HashMap<>();

public MachineSetupPanel() {
setLayout(new BorderLayout(0, 0));
Expand Down Expand Up @@ -159,10 +160,12 @@ public void propertyChange(PropertyChangeEvent evt) {

tabbedPane.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
if (disableLastSelectedListener) {
return;
if (lastSelectedNode != null) {
if (disableLastSelectedListener) {
return;
}
lastSelectedTabIndex.put(lastSelectedNode.getClass(), tabbedPane.getSelectedIndex());
}
lastSelectedTabIndex = tabbedPane.getSelectedIndex();
}
});

Expand Down Expand Up @@ -203,9 +206,11 @@ public void valueChanged(TreeSelectionEvent e) {
}
}

if (lastSelectedNode != null) {
if (lastSelectedNode.getClass().equals(node.obj.getClass())) {
tabbedPane.setSelectedIndex(lastSelectedTabIndex);
if (node.obj != null) {
if (lastSelectedTabIndex.get(node.obj.getClass()) != null) {
// Sometimes when clicking around quickly, the lastSelectedTabIndex update seems to be wrong,
// resulting in an IndexOutOfBoundsException. Therefore we check the tab count too. This covers variable per class Wizards too.
tabbedPane.setSelectedIndex(Math.min(tabbedPane.getTabCount()-1, lastSelectedTabIndex.get(node.obj.getClass())));
}
}

Expand Down

0 comments on commit 53e7875

Please sign in to comment.