Merge pull request #1444 from SiboVG/issue-974

[#974] Add component edit window tab remembrance
This commit is contained in:
SiboVG 2022-06-14 21:08:36 +02:00 committed by GitHub
commit 3730f78a7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 112 additions and 6 deletions

View File

@ -289,6 +289,8 @@ pref.dlg.lbl.PositiontoinsertStages = Position to insert new stages:
pref.dlg.lbl.Confirmdeletion = Confirm deletion of simulations. pref.dlg.lbl.Confirmdeletion = Confirm deletion of simulations.
pref.dlg.checkbox.Runsimulations = Run out-dated simulations when you open the simulation tab. pref.dlg.checkbox.Runsimulations = Run out-dated simulations when you open the simulation tab.
pref.dlg.checkbox.Updateestimates = Update estimated flight parameters in design window pref.dlg.checkbox.Updateestimates = Update estimated flight parameters in design window
pref.dlg.checkbox.AlwaysOpenLeftmost = Always open leftmost tab when opening a component edit dialog
pref.dlg.checkbox.AlwaysOpenLeftmost.ttip = <html>If checked, a component edit dialog will always pop up with the first tab selected.<br>If unchecked, the previous selected tab will be used.</html>
pref.dlg.lbl.User-definedthrust = User-defined thrust curves: pref.dlg.lbl.User-definedthrust = User-defined thrust curves:
pref.dlg.lbl.Windspeed = Wind speed pref.dlg.lbl.Windspeed = Wind speed
pref.dlg.Allthrustcurvefiles = All thrust curve files (*.eng; *.rse; *.zip; directories) pref.dlg.Allthrustcurvefiles = All thrust curve files (*.eng; *.rse; *.zip; directories)

View File

@ -67,6 +67,7 @@ public abstract class Preferences implements ChangeSource {
// Node names // Node names
public static final String PREFERRED_THRUST_CURVE_MOTOR_NODE = "preferredThrustCurveMotors"; public static final String PREFERRED_THRUST_CURVE_MOTOR_NODE = "preferredThrustCurveMotors";
private static final String AUTO_OPEN_LAST_DESIGN = "AUTO_OPEN_LAST_DESIGN"; private static final String AUTO_OPEN_LAST_DESIGN = "AUTO_OPEN_LAST_DESIGN";
private static final String OPEN_LEFTMOST_DESIGN_TAB = "OPEN_LEFTMOST_DESIGN_TAB";
private static final String SHOW_ROCKSIM_FORMAT_WARNING = "SHOW_ROCKSIM_FORMAT_WARNING"; private static final String SHOW_ROCKSIM_FORMAT_WARNING = "SHOW_ROCKSIM_FORMAT_WARNING";
//Preferences related to 3D graphics //Preferences related to 3D graphics
@ -453,6 +454,22 @@ public abstract class Preferences implements ChangeSource {
return this.getBoolean(AUTO_OPEN_LAST_DESIGN, false); return this.getBoolean(AUTO_OPEN_LAST_DESIGN, false);
} }
/**
* Enable/Disable the opening the leftmost tab on the component design panel, or using the tab that was opened last time.
*/
public final void setAlwaysOpenLeftmostTab(boolean enabled) {
this.putBoolean(OPEN_LEFTMOST_DESIGN_TAB, enabled);
}
/**
* Answer if the always open leftmost tab is enabled.
*
* @return true if the application should always open the leftmost tab in the component design panel.
*/
public final boolean isAlwaysOpenLeftmostTab() {
return this.getBoolean(OPEN_LEFTMOST_DESIGN_TAB, false);
}
/** /**
* Return the OpenRocket unique ID. * Return the OpenRocket unique ID.
* *

View File

@ -12,6 +12,7 @@ import javax.swing.JDialog;
import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent; import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
import net.sf.openrocket.rocketcomponent.ComponentChangeListener; import net.sf.openrocket.rocketcomponent.ComponentChangeListener;
@ -40,6 +41,8 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
private RocketComponent component = null; private RocketComponent component = null;
private RocketComponentConfig configurator = null; private RocketComponentConfig configurator = null;
private static String previousSelectedTab = null; // Name of the previous selected tab
private final Window parent; private final Window parent;
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
@ -103,6 +106,9 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
this.setContentPane(configurator); this.setContentPane(configurator);
configurator.updateFields(); configurator.updateFields();
// Set the selected tab
configurator.setSelectedTab(previousSelectedTab);
//// configuration //// configuration
setTitle(trans.get("ComponentCfgDlg.configuration1") + " " + component.getComponentName() + " " + trans.get("ComponentCfgDlg.configuration")); setTitle(trans.get("ComponentCfgDlg.configuration1") + " " + component.getComponentName() + " " + trans.get("ComponentCfgDlg.configuration"));
@ -204,11 +210,18 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
* @param document the document to configure. * @param document the document to configure.
* @param component the component to configure. * @param component the component to configure.
* @param listeners config listeners for the component * @param listeners config listeners for the component
* @param rememberPreviousTab if true, the previous tab will be remembered and used for the new dialog
*/ */
public static void showDialog(Window parent, OpenRocketDocument document, public static void showDialog(Window parent, OpenRocketDocument document,
RocketComponent component, List<RocketComponent> listeners) { RocketComponent component, List<RocketComponent> listeners, boolean rememberPreviousTab) {
if (dialog != null) if (dialog != null) {
previousSelectedTab = dialog.getSelectedTabName();
dialog.dispose(); dialog.dispose();
}
final SwingPreferences preferences = (SwingPreferences) Application.getPreferences();
if (preferences.isAlwaysOpenLeftmostTab() || !rememberPreviousTab) {
previousSelectedTab = null;
}
dialog = new ComponentConfigDialog(parent, document, component, listeners); dialog = new ComponentConfigDialog(parent, document, component, listeners);
dialog.setVisible(true); dialog.setVisible(true);
@ -220,19 +233,51 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
/** /**
* A singleton configuration dialog. Will create and show a new dialog if one has not * A singleton configuration dialog. Will create and show a new dialog if one has not
* previously been used, or update the dialog and show it if a previous one exists. * previously been used, or update the dialog and show it if a previous one exists.
* By default, the previous tab is remembered.
*
* @param document the document to configure.
* @param component the component to configure.
* @param listeners config listeners for the component
*/
public static void showDialog(Window parent, OpenRocketDocument document,
RocketComponent component, List<RocketComponent> listeners) {
ComponentConfigDialog.showDialog(parent, document, component, listeners, true);
}
/**
* A singleton configuration dialog. Will create and show a new dialog if one has not
* previously been used, or update the dialog and show it if a previous one exists.
*
* @param document the document to configure.
* @param component the component to configure.
* @param rememberPreviousTab if true, the previous tab will be remembered and used for the new dialog
*/
public static void showDialog(Window parent, OpenRocketDocument document,
RocketComponent component, boolean rememberPreviousTab) {
ComponentConfigDialog.showDialog(parent, document, component, null, rememberPreviousTab);
}
/**
* A singleton configuration dialog. Will create and show a new dialog if one has not
* previously been used, or update the dialog and show it if a previous one exists.
* By default, the previous tab is remembered.
* *
* @param document the document to configure. * @param document the document to configure.
* @param component the component to configure. * @param component the component to configure.
*/ */
public static void showDialog(Window parent, OpenRocketDocument document, public static void showDialog(Window parent, OpenRocketDocument document,
RocketComponent component) { RocketComponent component) {
ComponentConfigDialog.showDialog(parent, document, component, null); ComponentConfigDialog.showDialog(parent, document, component, null, true);
}
static void showDialog(RocketComponent component, List<RocketComponent> listeners, boolean rememberPreviousTab) {
showDialog(dialog.parent, dialog.document, component, listeners, rememberPreviousTab);
} }
/* package */ /* package */
static void showDialog(RocketComponent component, List<RocketComponent> listeners) { static void showDialog(RocketComponent component, List<RocketComponent> listeners) {
showDialog(dialog.parent, dialog.document, component, listeners); showDialog(dialog.parent, dialog.document, component, listeners, true);
} }
/* package */ /* package */
@ -257,4 +302,12 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
return (dialog != null) && (dialog.isVisible()); return (dialog != null) && (dialog.isVisible());
} }
public String getSelectedTabName() {
if (configurator != null) {
return configurator.getSelectedTabName();
} else {
return null;
}
}
} }

View File

@ -269,6 +269,26 @@ public class RocketComponentConfig extends JPanel {
return subPanel; return subPanel;
} }
public String getSelectedTabName() {
if (tabbedPane != null) {
return tabbedPane.getTitleAt(tabbedPane.getSelectedIndex());
} else {
return "";
}
}
public void setSelectedTab(String tabName) {
if (tabbedPane != null) {
for (int i = 0; i < tabbedPane.getTabCount(); i++) {
if (tabbedPane.getTitleAt(i).equals(tabName)) {
tabbedPane.setSelectedIndex(i);
return;
}
}
tabbedPane.setSelectedIndex(0);
}
}
protected JPanel instanceablePanel( Instanceable inst ){ protected JPanel instanceablePanel( Instanceable inst ){
JPanel panel = new JPanel( new MigLayout("fill")); JPanel panel = new JPanel( new MigLayout("fill"));
{ // Instance Count { // Instance Count

View File

@ -90,6 +90,21 @@ public class DesignPreferencesPanel extends PreferencesPanel {
}); });
this.add(autoOpenDesignFile, "wrap, growx, span 2"); this.add(autoOpenDesignFile, "wrap, growx, span 2");
// // Always open leftmost tab when opening a component edit dialog
final JCheckBox alwaysOpenLeftmostTab = new JCheckBox(
trans.get("pref.dlg.checkbox.AlwaysOpenLeftmost"));
alwaysOpenLeftmostTab.setSelected(preferences.isAlwaysOpenLeftmostTab());
alwaysOpenLeftmostTab.setToolTipText(trans.get("pref.dlg.checkbox.AlwaysOpenLeftmost.ttip"));
alwaysOpenLeftmostTab.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
preferences.setAlwaysOpenLeftmostTab(alwaysOpenLeftmostTab
.isSelected());
}
});
this.add(alwaysOpenLeftmostTab, "wrap, growx, span 2");
// // Update flight estimates in the design window // // Update flight estimates in the design window
final JCheckBox updateEstimates = new JCheckBox( final JCheckBox updateEstimates = new JCheckBox(
trans.get("pref.dlg.checkbox.Updateestimates")); trans.get("pref.dlg.checkbox.Updateestimates"));
@ -102,6 +117,5 @@ public class DesignPreferencesPanel extends PreferencesPanel {
} }
}); });
this.add(updateEstimates, "wrap, growx, sg combos "); this.add(updateEstimates, "wrap, growx, sg combos ");
} }
} }

View File

@ -488,7 +488,7 @@ public class ComponentAddButtons extends JPanel implements Scrollable {
} }
} }
ComponentConfigDialog.showDialog(parent, document, component); ComponentConfigDialog.showDialog(parent, document, component, false);
} }
} }