Focus most commonly edited parameter after preset selection
This commit is contained in:
parent
c53776c044
commit
b79a6fb852
@ -8,6 +8,7 @@ import javax.swing.ComboBoxModel;
|
|||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
import net.sf.openrocket.database.ComponentPresetDatabase;
|
import net.sf.openrocket.database.ComponentPresetDatabase;
|
||||||
|
import net.sf.openrocket.gui.configdialog.RocketComponentConfig;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -90,6 +91,7 @@ public class PresetModel extends AbstractListModel implements ComboBoxModel, Com
|
|||||||
} else {
|
} else {
|
||||||
document.addUndoPosition("Use Preset " + component.getComponentName());
|
document.addUndoPosition("Use Preset " + component.getComponentName());
|
||||||
component.loadPreset((ComponentPreset) item);
|
component.loadPreset((ComponentPreset) item);
|
||||||
|
((RocketComponentConfig) parent).setFocusElement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@ import javax.swing.JDialog;
|
|||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JSpinner;
|
import javax.swing.JSpinner;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
import net.sf.openrocket.document.OpenRocketDocument;
|
import net.sf.openrocket.document.OpenRocketDocument;
|
||||||
@ -23,6 +25,12 @@ import net.sf.openrocket.rocketcomponent.SymmetricComponent;
|
|||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
import net.sf.openrocket.unit.UnitGroup;
|
import net.sf.openrocket.unit.UnitGroup;
|
||||||
|
|
||||||
|
import java.awt.event.FocusEvent;
|
||||||
|
import java.awt.event.FocusListener;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseListener;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class BodyTubeConfig extends RocketComponentConfig {
|
public class BodyTubeConfig extends RocketComponentConfig {
|
||||||
|
|
||||||
@ -43,6 +51,7 @@ public class BodyTubeConfig extends RocketComponentConfig {
|
|||||||
|
|
||||||
JSpinner spin = new JSpinner(length.getSpinnerModel());
|
JSpinner spin = new JSpinner(length.getSpinnerModel());
|
||||||
spin.setEditor(new SpinnerEditor(spin));
|
spin.setEditor(new SpinnerEditor(spin));
|
||||||
|
focusElement = spin;
|
||||||
panel.add(spin, "growx");
|
panel.add(spin, "growx");
|
||||||
|
|
||||||
panel.add(new UnitSelector(length), "growx");
|
panel.add(new UnitSelector(length), "growx");
|
||||||
|
@ -64,7 +64,6 @@ public class InnerTubeConfig extends RocketComponentConfig {
|
|||||||
super(d, c, parent);
|
super(d, c, parent);
|
||||||
|
|
||||||
//// General and General properties
|
//// General and General properties
|
||||||
JPanel rightPanel = new JPanel(new MigLayout());
|
|
||||||
JPanel panel = new JPanel(new MigLayout("gap rel unrel", "[][65lp::][30lp::][]", ""));
|
JPanel panel = new JPanel(new MigLayout("gap rel unrel", "[][65lp::][30lp::][]", ""));
|
||||||
|
|
||||||
DoubleModel m;
|
DoubleModel m;
|
||||||
@ -86,7 +85,7 @@ public class InnerTubeConfig extends RocketComponentConfig {
|
|||||||
panel.add(spin, "growx");
|
panel.add(spin, "growx");
|
||||||
|
|
||||||
panel.add(new UnitSelector(od), "growx");
|
panel.add(new UnitSelector(od), "growx");
|
||||||
panel.add(new BasicSlider(od.getSliderModel(0, 0.04, 0.2)), "w 100lp, wrap");
|
panel.add(new BasicSlider(od.getSliderModel(0, 0.04, 0.2)), "wmin 100lp, growx, wrap");
|
||||||
|
|
||||||
if (od.isAutomaticAvailable()) {
|
if (od.isAutomaticAvailable()) {
|
||||||
JCheckBox check = new JCheckBox(od.getAutomaticAction());
|
JCheckBox check = new JCheckBox(od.getAutomaticAction());
|
||||||
@ -106,7 +105,7 @@ public class InnerTubeConfig extends RocketComponentConfig {
|
|||||||
panel.add(spin, "growx");
|
panel.add(spin, "growx");
|
||||||
|
|
||||||
panel.add(new UnitSelector(m), "growx");
|
panel.add(new UnitSelector(m), "growx");
|
||||||
panel.add(new BasicSlider(m.getSliderModel(new DoubleModel(0), od)), "w 100lp, wrap");
|
panel.add(new BasicSlider(m.getSliderModel(new DoubleModel(0), od)), "wmin 100lp, growx, wrap");
|
||||||
|
|
||||||
if (m.isAutomaticAvailable()) {
|
if (m.isAutomaticAvailable()) {
|
||||||
JCheckBox check = new JCheckBox(m.getAutomaticAction());
|
JCheckBox check = new JCheckBox(m.getAutomaticAction());
|
||||||
@ -127,7 +126,7 @@ public class InnerTubeConfig extends RocketComponentConfig {
|
|||||||
panel.add(spin, "growx");
|
panel.add(spin, "growx");
|
||||||
|
|
||||||
panel.add(new UnitSelector(m), "growx");
|
panel.add(new UnitSelector(m), "growx");
|
||||||
panel.add(new BasicSlider(m.getSliderModel(0, 0.01)), "w 100lp, wrap");
|
panel.add(new BasicSlider(m.getSliderModel(0, 0.01)), "wmin 100lp, growx, wrap");
|
||||||
|
|
||||||
|
|
||||||
//// Inner tube length
|
//// Inner tube length
|
||||||
@ -138,14 +137,15 @@ public class InnerTubeConfig extends RocketComponentConfig {
|
|||||||
|
|
||||||
spin = new JSpinner(m.getSpinnerModel());
|
spin = new JSpinner(m.getSpinnerModel());
|
||||||
spin.setEditor(new SpinnerEditor(spin));
|
spin.setEditor(new SpinnerEditor(spin));
|
||||||
|
focusElement = spin;
|
||||||
panel.add(spin, "growx");
|
panel.add(spin, "growx");
|
||||||
|
|
||||||
panel.add(new UnitSelector(m), "growx");
|
panel.add(new UnitSelector(m), "growx");
|
||||||
panel.add(new BasicSlider(m.getSliderModel(0, 0.1, 1.0)), "w 100lp, wrap");
|
panel.add(new BasicSlider(m.getSliderModel(0, 0.1, 1.0)), "wmin 100lp, growx, wrap");
|
||||||
|
|
||||||
//// Material
|
//// Material
|
||||||
panel.add(materialPanel(Material.Type.BULK),
|
panel.add(materialPanel(Material.Type.BULK),
|
||||||
"spanx 3, growx, wrap 15lp");
|
"spanx 4, growx, wrap 15lp");
|
||||||
|
|
||||||
|
|
||||||
//// Right side of panel ----
|
//// Right side of panel ----
|
||||||
@ -174,7 +174,7 @@ public class InnerTubeConfig extends RocketComponentConfig {
|
|||||||
panel2.add(new BasicSlider(m.getSliderModel(
|
panel2.add(new BasicSlider(m.getSliderModel(
|
||||||
new DoubleModel(component.getParent(), "Length", -1.0, UnitGroup.UNITS_NONE),
|
new DoubleModel(component.getParent(), "Length", -1.0, UnitGroup.UNITS_NONE),
|
||||||
new DoubleModel(component.getParent(), "Length"))),
|
new DoubleModel(component.getParent(), "Length"))),
|
||||||
"w 100lp, wrap");
|
"wmin 100lp, growx, wrap");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ public class LaunchLugConfig extends RocketComponentConfig {
|
|||||||
|
|
||||||
JSpinner spin = new JSpinner(m.getSpinnerModel());
|
JSpinner spin = new JSpinner(m.getSpinnerModel());
|
||||||
spin.setEditor(new SpinnerEditor(spin));
|
spin.setEditor(new SpinnerEditor(spin));
|
||||||
|
focusElement = spin;
|
||||||
panel.add(spin, "growx");
|
panel.add(spin, "growx");
|
||||||
|
|
||||||
panel.add(new UnitSelector(m), "growx");
|
panel.add(new UnitSelector(m), "growx");
|
||||||
|
@ -138,6 +138,7 @@ public class MassComponentConfig extends RocketComponentConfig {
|
|||||||
m = new DoubleModel(component, "AxialOffset", UnitGroup.UNITS_LENGTH);
|
m = new DoubleModel(component, "AxialOffset", UnitGroup.UNITS_LENGTH);
|
||||||
spin = new JSpinner(m.getSpinnerModel());
|
spin = new JSpinner(m.getSpinnerModel());
|
||||||
spin.setEditor(new SpinnerEditor(spin));
|
spin.setEditor(new SpinnerEditor(spin));
|
||||||
|
focusElement = spin;
|
||||||
panel2.add(spin, "growx");
|
panel2.add(spin, "growx");
|
||||||
|
|
||||||
panel2.add(new UnitSelector(m), "growx");
|
panel2.add(new UnitSelector(m), "growx");
|
||||||
|
@ -163,6 +163,7 @@ public class ParachuteConfig extends RecoveryDeviceConfig {
|
|||||||
m = new DoubleModel(component, "AxialOffset", UnitGroup.UNITS_LENGTH);
|
m = new DoubleModel(component, "AxialOffset", UnitGroup.UNITS_LENGTH);
|
||||||
spin = new JSpinner(m.getSpinnerModel());
|
spin = new JSpinner(m.getSpinnerModel());
|
||||||
spin.setEditor(new SpinnerEditor(spin));
|
spin.setEditor(new SpinnerEditor(spin));
|
||||||
|
focusElement = spin;
|
||||||
panel.add(spin, "growx");
|
panel.add(spin, "growx");
|
||||||
|
|
||||||
panel.add(new UnitSelector(m), "growx");
|
panel.add(new UnitSelector(m), "growx");
|
||||||
|
@ -20,6 +20,7 @@ import net.sf.openrocket.l10n.Translator;
|
|||||||
import net.sf.openrocket.material.Material;
|
import net.sf.openrocket.material.Material;
|
||||||
import net.sf.openrocket.rocketcomponent.EngineBlock;
|
import net.sf.openrocket.rocketcomponent.EngineBlock;
|
||||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||||
|
import net.sf.openrocket.rocketcomponent.ThicknessRingComponent;
|
||||||
import net.sf.openrocket.rocketcomponent.position.AxialMethod;
|
import net.sf.openrocket.rocketcomponent.position.AxialMethod;
|
||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
import net.sf.openrocket.unit.UnitGroup;
|
import net.sf.openrocket.unit.UnitGroup;
|
||||||
@ -116,6 +117,9 @@ public class RingComponentConfig extends RocketComponentConfig {
|
|||||||
|
|
||||||
spin = new JSpinner(m.getSpinnerModel());
|
spin = new JSpinner(m.getSpinnerModel());
|
||||||
spin.setEditor(new SpinnerEditor(spin));
|
spin.setEditor(new SpinnerEditor(spin));
|
||||||
|
if (component instanceof ThicknessRingComponent) {
|
||||||
|
focusElement = spin;
|
||||||
|
}
|
||||||
panel.add(spin, "growx");
|
panel.add(spin, "growx");
|
||||||
|
|
||||||
panel.add(new UnitSelector(m), "growx");
|
panel.add(new UnitSelector(m), "growx");
|
||||||
@ -139,6 +143,9 @@ public class RingComponentConfig extends RocketComponentConfig {
|
|||||||
m = new DoubleModel(component, "AxialOffset", UnitGroup.UNITS_LENGTH);
|
m = new DoubleModel(component, "AxialOffset", UnitGroup.UNITS_LENGTH);
|
||||||
spin = new JSpinner(m.getSpinnerModel());
|
spin = new JSpinner(m.getSpinnerModel());
|
||||||
spin.setEditor(new SpinnerEditor(spin));
|
spin.setEditor(new SpinnerEditor(spin));
|
||||||
|
if (!(component instanceof ThicknessRingComponent)) {
|
||||||
|
focusElement = spin;
|
||||||
|
}
|
||||||
panel.add(spin, "growx");
|
panel.add(spin, "growx");
|
||||||
|
|
||||||
panel.add(new UnitSelector(m), "growx");
|
panel.add(new UnitSelector(m), "growx");
|
||||||
|
@ -22,6 +22,7 @@ import javax.swing.JSpinner;
|
|||||||
import javax.swing.JTabbedPane;
|
import javax.swing.JTabbedPane;
|
||||||
import javax.swing.JTextArea;
|
import javax.swing.JTextArea;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
import net.sf.openrocket.document.OpenRocketDocument;
|
import net.sf.openrocket.document.OpenRocketDocument;
|
||||||
@ -61,6 +62,7 @@ public class RocketComponentConfig extends JPanel {
|
|||||||
|
|
||||||
private JComboBox<?> presetComboBox;
|
private JComboBox<?> presetComboBox;
|
||||||
private PresetModel presetModel;
|
private PresetModel presetModel;
|
||||||
|
protected Component focusElement = null; // Element that will be focused on after a preset is selected
|
||||||
|
|
||||||
protected final JTextField componentNameField;
|
protected final JTextField componentNameField;
|
||||||
protected JTextArea commentTextArea;
|
protected JTextArea commentTextArea;
|
||||||
@ -702,6 +704,24 @@ public class RocketComponentConfig extends JPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Requests focus for the focus element that should be active after a preset is selected.
|
||||||
|
*/
|
||||||
|
public void setFocusElement() {
|
||||||
|
if (focusElement != null) {
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
if (focusElement instanceof JSpinner) {
|
||||||
|
SpinnerEditor ed = (SpinnerEditor) ((JSpinner)focusElement).getEditor();
|
||||||
|
ed.getTextField().requestFocusInWindow();
|
||||||
|
} else {
|
||||||
|
focusElement.requestFocusInWindow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void register(Invalidatable model) {
|
protected void register(Invalidatable model) {
|
||||||
|
@ -80,6 +80,7 @@ public class ShockCordConfig extends RocketComponentConfig {
|
|||||||
m = new DoubleModel(component, "AxialOffset", UnitGroup.UNITS_LENGTH);
|
m = new DoubleModel(component, "AxialOffset", UnitGroup.UNITS_LENGTH);
|
||||||
spin = new JSpinner(m.getSpinnerModel());
|
spin = new JSpinner(m.getSpinnerModel());
|
||||||
spin.setEditor(new SpinnerEditor(spin));
|
spin.setEditor(new SpinnerEditor(spin));
|
||||||
|
focusElement = spin;
|
||||||
panel2.add(spin, "growx");
|
panel2.add(spin, "growx");
|
||||||
|
|
||||||
panel2.add(new UnitSelector(m), "growx");
|
panel2.add(new UnitSelector(m), "growx");
|
||||||
|
@ -149,6 +149,7 @@ public class StreamerConfig extends RecoveryDeviceConfig {
|
|||||||
m = new DoubleModel(component, "AxialOffset", UnitGroup.UNITS_LENGTH);
|
m = new DoubleModel(component, "AxialOffset", UnitGroup.UNITS_LENGTH);
|
||||||
spin = new JSpinner(m.getSpinnerModel());
|
spin = new JSpinner(m.getSpinnerModel());
|
||||||
spin.setEditor(new SpinnerEditor(spin));
|
spin.setEditor(new SpinnerEditor(spin));
|
||||||
|
focusElement = spin;
|
||||||
panel.add(spin, "growx");
|
panel.add(spin, "growx");
|
||||||
|
|
||||||
panel.add(new UnitSelector(m), "growx");
|
panel.add(new UnitSelector(m), "growx");
|
||||||
|
@ -54,6 +54,7 @@ public class TubeFinSetConfig extends RocketComponentConfig {
|
|||||||
|
|
||||||
spin = new JSpinner(m.getSpinnerModel());
|
spin = new JSpinner(m.getSpinnerModel());
|
||||||
spin.setEditor(new SpinnerEditor(spin));
|
spin.setEditor(new SpinnerEditor(spin));
|
||||||
|
focusElement = spin;
|
||||||
panel.add(spin, "growx");
|
panel.add(spin, "growx");
|
||||||
|
|
||||||
panel.add(new UnitSelector(m), "growx");
|
panel.add(new UnitSelector(m), "growx");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user