Focus on design tables when tab switches

This commit is contained in:
SiboVG 2022-07-28 20:03:29 +02:00
parent 10231e3676
commit 65b824adcb
6 changed files with 66 additions and 18 deletions

View File

@ -4,9 +4,7 @@ import java.awt.*;
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;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
@ -19,16 +17,12 @@ import java.net.URL;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultTreeSelectionModel;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;
@ -68,13 +62,11 @@ import net.sf.openrocket.gui.util.Icons;
import net.sf.openrocket.gui.util.OpenFileWorker;
import net.sf.openrocket.gui.util.SaveFileWorker;
import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.gui.widgets.SelectColorButton;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.logging.Markers;
import net.sf.openrocket.rocketcomponent.AxialStage;
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
import net.sf.openrocket.rocketcomponent.ComponentChangeListener;
import net.sf.openrocket.rocketcomponent.PodSet;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.startup.Application;
@ -107,8 +99,8 @@ public class BasicFrame extends JFrame {
public static final int SHIFT_SHORTCUT_KEY = Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx() |
SHIFT_DOWN_MASK;
public static final int COMPONENT_TAB = 0;
public static final int CONFIGURATION_TAB = 1;
public static final int DESIGN_TAB = 0;
public static final int FLIGHT_CONFIGURATION_TAB = 1;
public static final int SIMULATION_TAB = 2;
@ -1075,7 +1067,7 @@ public class BasicFrame extends JFrame {
/**
* Select the tab on the main pane.
*
* @param tab one of {@link #COMPONENT_TAB} or {@link #SIMULATION_TAB}.
* @param tab one of {@link #DESIGN_TAB}, {@link #FLIGHT_CONFIGURATION_TAB} or {@link #SIMULATION_TAB}.
*/
public void selectTab(int tab) {
tabbedPane.setSelectedIndex(tab);
@ -1759,8 +1751,17 @@ public class BasicFrame extends JFrame {
public void stateChanged(ChangeEvent e) {
JTabbedPane tabSource = (JTabbedPane) e.getSource();
int tab = tabSource.getSelectedIndex();
if (tab == SIMULATION_TAB) {
simulationPanel.activating();
switch (tab) {
case DESIGN_TAB:
designPanel.takeTheSpotlight();
break;
case FLIGHT_CONFIGURATION_TAB:
flightConfigurationPanel.takeTheSpotlight();
break;
case SIMULATION_TAB:
simulationPanel.takeTheSpotlight();
simulationPanel.activating();
break;
}
}

View File

@ -28,6 +28,7 @@ import javax.swing.border.TitledBorder;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.TreePath;
import java.awt.Component;
import java.awt.Font;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
@ -48,11 +49,13 @@ import static net.sf.openrocket.gui.main.BasicFrame.SHORTCUT_KEY;
*/
public class DesignPanel extends JSplitPane {
private static final Translator trans = Application.getTranslator();
private final Component tree;
public DesignPanel(final BasicFrame parent, final RocketPanel rocketpanel, final OpenRocketDocument document,
final ComponentTree tree) {
super(JSplitPane.HORIZONTAL_SPLIT, true);
setResizeWeight(0.5);
this.tree = tree;
// Upper-left segment, component tree
JPanel panel = new JPanel(new MigLayout("fill, flowy", "[grow][grow 0]","[grow]"));
@ -225,4 +228,11 @@ public class DesignPanel extends JSplitPane {
this.setRightComponent(panel);
}
/**
* Focus on the component tree.
*/
public void takeTheSpotlight() {
tree.requestFocusInWindow();
}
}

View File

@ -119,12 +119,15 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
switch (tabs.getSelectedIndex()) {
case MOTOR_TAB_INDEX:
motorConfigurationPanel.updateButtonState();
motorConfigurationPanel.takeTheSpotlight();
break;
case RECOVERY_TAB_INDEX:
recoveryConfigurationPanel.updateButtonState();
motorConfigurationPanel.takeTheSpotlight();
break;
case SEPARATION_TAB_INDEX:
separationConfigurationPanel.updateButtonState();
motorConfigurationPanel.takeTheSpotlight();
break;
}
}
@ -368,4 +371,21 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
newOrDuplicateConfigAction(true);
}
}
/**
* Focus on the table of the config panel that is currently opened.
*/
public void takeTheSpotlight() {
switch (tabs.getSelectedIndex()) {
case MOTOR_TAB_INDEX:
motorConfigurationPanel.takeTheSpotlight();
break;
case RECOVERY_TAB_INDEX:
recoveryConfigurationPanel.takeTheSpotlight();
break;
case SEPARATION_TAB_INDEX:
separationConfigurationPanel.takeTheSpotlight();
break;
}
}
}

View File

@ -578,7 +578,7 @@ public class RocketActions {
parentFrame.selectTab(BasicFrame.SIMULATION_TAB);
} else {
deleteComponentAction.actionPerformed(e);
parentFrame.selectTab(BasicFrame.COMPONENT_TAB);
parentFrame.selectTab(BasicFrame.DESIGN_TAB);
}
}
@ -632,7 +632,7 @@ public class RocketActions {
OpenRocketClipboard.setClipboard(copiedComponents);
delete(components);
parentFrame.selectTab(BasicFrame.COMPONENT_TAB);
parentFrame.selectTab(BasicFrame.DESIGN_TAB);
} else if (isSimulationSelected()) {
Simulation[] simsCopy = new Simulation[sims.length];
@ -689,7 +689,7 @@ public class RocketActions {
List<RocketComponent> copiedComponents = new LinkedList<>(copyComponentsMaintainParent(components));
OpenRocketClipboard.setClipboard(copiedComponents);
parentFrame.selectTab(BasicFrame.COMPONENT_TAB);
parentFrame.selectTab(BasicFrame.DESIGN_TAB);
} else if (sims != null && sims.length > 0) {
Simulation[] simsCopy = new Simulation[sims.length];
for (int i=0; i < sims.length; i++) {
@ -769,7 +769,7 @@ public class RocketActions {
selectionModel.setSelectedComponents(successfullyPasted);
parentFrame.selectTab(BasicFrame.COMPONENT_TAB);
parentFrame.selectTab(BasicFrame.DESIGN_TAB);
} else if (sims != null) {
@ -866,7 +866,7 @@ public class RocketActions {
selectionModel.setSelectedComponents(duplicateComponents);
parentFrame.selectTab(BasicFrame.COMPONENT_TAB);
parentFrame.selectTab(BasicFrame.DESIGN_TAB);
} else if (sims != null && sims.length > 0) {
ArrayList<Simulation> copySims = new ArrayList<Simulation>();

View File

@ -958,4 +958,14 @@ public class SimulationPanel extends JPanel {
}
}
/**
* Focus on the simulation table
*/
public void takeTheSpotlight() {
simulationTable.requestFocusInWindow();
if (simulationTable.getRowCount() > 0) {
simulationTable.setRowSelectionInterval(0, 0);
}
}
}

View File

@ -331,4 +331,11 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
}
/**
* Focus on the table
*/
public void takeTheSpotlight() {
table.requestFocusInWindow();
}
}