[#960] Add OK/Cancel button in component config + modified symbol

This commit is contained in:
SiboVG 2023-01-08 01:37:48 +01:00
parent 94d376540a
commit 0120ba7bcc
22 changed files with 166 additions and 39 deletions

View File

@ -979,6 +979,12 @@ RocketCompCfg.tab.Outside = Outside
RocketCompCfg.tab.Inside = Inside
RocketCompCfg.tab.RightSide = Right Side
RocketCompCfg.tab.LeftSide = Left Side
RocketCompCfg.btn.OK.ttip = Keep changes and close the dialog
RocketCompCfg.btn.Cancel.ttip = Discard changes and close the dialog
RocketCompCfg.CancelOperation.msg.discardChanges = <html>Are you sure you want to <b>discard</b> your <b>changes</b> to this component?</html>
RocketCompCfg.CancelOperation.msg.undoAdd = <html>Are you sure you want to <b>undo adding</b> this component?</html>
RocketCompCfg.CancelOperation.title = Cancel operation
RocketCompCfg.CancelOperation.checkbox.dontAskAgain = Don't ask me again
! BulkheadConfig
BulkheadCfg.tab.Diameter = Diameter:

View File

@ -16,7 +16,6 @@ import net.sf.openrocket.gui.components.StyledLabel;
import net.sf.openrocket.gui.components.StyledLabel.Style;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.AxialStage;
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration;
import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration.SeparationEvent;
@ -38,7 +37,9 @@ public class AxialStageConfig extends ComponentAssemblyConfig {
}
// Apply the custom focus travel policy to this config dialog
order.add(closeButton); // Make sure the close button is the last component
//// Make sure the cancel & ok button is the last component
order.add(cancelButton);
order.add(okButton);
CustomFocusTraversalPolicy policy = new CustomFocusTraversalPolicy(order);
parent.setFocusTraversalPolicy(policy);
}

View File

@ -121,7 +121,9 @@ public class BodyTubeConfig extends RocketComponentConfig {
trans.get("BodyTubecfg.tab.Motormountconf"), 1);
// Apply the custom focus travel policy to this config dialog
order.add(closeButton); // Make sure the close button is the last component
//// Make sure the cancel & ok button is the last component
order.add(cancelButton);
order.add(okButton);
CustomFocusTraversalPolicy policy = new CustomFocusTraversalPolicy(order);
parent.setFocusTraversalPolicy(policy);
}

View File

@ -29,7 +29,9 @@ public class BulkheadConfig extends RingComponentConfig {
tabbedPane.setSelectedIndex(0);
// Apply the custom focus travel policy to this panel
order.add(closeButton); // Make sure the close button is the last component
//// Make sure the cancel & ok button is the last component
order.add(cancelButton);
order.add(okButton);
CustomFocusTraversalPolicy policy = new CustomFocusTraversalPolicy(order);
parent.setFocusTraversalPolicy(policy);
}

View File

@ -31,7 +31,9 @@ public class CenteringRingConfig extends RingComponentConfig {
tabbedPane.setSelectedIndex(0);
// Apply the custom focus travel policy to this panel
order.add(closeButton); // Make sure the close button is the last component
//// Make sure the cancel & ok button is the last component
order.add(cancelButton);
order.add(okButton);
CustomFocusTraversalPolicy policy = new CustomFocusTraversalPolicy(order);
parent.setFocusTraversalPolicy(policy);
}

View File

@ -1,15 +1,11 @@
package net.sf.openrocket.gui.configdialog;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Window;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.List;
import javax.swing.JDialog;
@ -48,6 +44,8 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
private OpenRocketDocument document = null;
protected RocketComponent component = null;
private RocketComponentConfig configurator = null;
private boolean isModified = false;
private final boolean isNewComponent;
protected static boolean clearConfigListeners = true;
private static String previousSelectedTab = null; // Name of the previous selected tab
@ -55,9 +53,10 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
private final Window parent;
private static final Translator trans = Application.getTranslator();
private ComponentConfigDialog(Window parent, OpenRocketDocument document, RocketComponent component) {
private ComponentConfigDialog(Window parent, OpenRocketDocument document, RocketComponent component, boolean isNewComponent) {
super(parent);
this.parent = parent;
this.isNewComponent = isNewComponent;
setComponent(document, component);
@ -104,8 +103,10 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
this.document = document;
this.component = component;
this.document.getRocket().addComponentChangeListener(this);
this.isModified = false;
configurator = getDialogContents();
configurator.setNewComponent(isNewComponent);
this.setContentPane(configurator);
configurator.updateFields();
@ -172,10 +173,8 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
@Override
public void componentChanged(ComponentChangeEvent e) {
if (e.isTreeChange() || e.isUndoChange()) {
// Hide dialog in case of tree or undo change
disposeDialog();
} else {
/*
* TODO: HIGH: The line below has caused a NullPointerException (without null check)
@ -183,8 +182,13 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
* root cause should be analyzed.
* [Openrocket-bugs] 2009-12-12 19:23:22 Automatic bug report for OpenRocket 0.9.5
*/
if (configurator != null)
if (configurator != null) {
configurator.updateFields();
}
if (!this.isModified) {
setTitle("*" + getTitle());
this.isModified = true;
}
}
}
@ -261,7 +265,7 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
previousSelectedTab = null;
}
dialog = new ComponentConfigDialog(parent, document, component);
dialog = new ComponentConfigDialog(parent, document, component, isNewComponent);
dialog.setVisible(true);
if (parent instanceof BasicFrame && BasicFrame.getStartupFrame() == parent) {
WindowLocationUtil.moveIfOutsideOfParentMonitor(dialog, parent);
@ -335,6 +339,13 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
return (dialog != null) && (dialog.isVisible());
}
/**
* Returns true if the current component has been modified or not.
*/
public boolean isModified() {
return isModified;
}
public int getSelectedTabIndex() {
return configurator.getSelectedTabIndex();
}

View File

@ -201,7 +201,9 @@ public class EllipticalFinSetConfig extends FinSetConfig {
tabbedPane.setSelectedIndex(0);
// Apply the custom focus travel policy to this config dialog
order.add(closeButton); // Make sure the close button is the last component
//// Make sure the cancel & ok button is the last component
order.add(cancelButton);
order.add(okButton);
CustomFocusTraversalPolicy policy = new CustomFocusTraversalPolicy(order);
parent.setFocusTraversalPolicy(policy);
}

View File

@ -107,7 +107,9 @@ public class FreeformFinSetConfig extends FinSetConfig {
addFinSetButtons();
// Apply the custom focus travel policy to this panel
order.add(closeButton); // Make sure the close button is the last component
//// Make sure the cancel & ok button is the last component
order.add(cancelButton);
order.add(okButton);
CustomFocusTraversalPolicy policy = new CustomFocusTraversalPolicy(order);
parent.setFocusTraversalPolicy(policy);
}

View File

@ -207,7 +207,9 @@ public class InnerTubeConfig extends RocketComponentConfig {
tabbedPane.setSelectedIndex(0);
// Apply the custom focus travel policy to this config dialog
order.add(closeButton); // Make sure the close button is the last component
//// Make sure the cancel & ok button is the last component
order.add(cancelButton);
order.add(okButton);
CustomFocusTraversalPolicy policy = new CustomFocusTraversalPolicy(order);
parent.setFocusTraversalPolicy(policy);
}

View File

@ -162,7 +162,9 @@ public class LaunchLugConfig extends RocketComponentConfig {
tabbedPane.setSelectedIndex(0);
// Apply the custom focus travel policy to this config dialog
order.add(closeButton); // Make sure the close button is the last component
//// Make sure the cancel & ok button is the last component
order.add(cancelButton);
order.add(okButton);
CustomFocusTraversalPolicy policy = new CustomFocusTraversalPolicy(order);
parent.setFocusTraversalPolicy(policy);
}

View File

@ -166,7 +166,9 @@ public class MassComponentConfig extends RocketComponentConfig {
tabbedPane.setSelectedIndex(0);
// Apply the custom focus travel policy to this config dialog
order.add(closeButton); // Make sure the close button is the last component
//// Make sure the cancel & ok button is the last component
order.add(cancelButton);
order.add(okButton);
CustomFocusTraversalPolicy policy = new CustomFocusTraversalPolicy(order);
parent.setFocusTraversalPolicy(policy);
}

View File

@ -188,7 +188,9 @@ public class NoseConeConfig extends RocketComponentConfig {
tabbedPane.setSelectedIndex(0);
// Apply the custom focus travel policy to this config dialog
order.add(closeButton); // Make sure the close button is the last component
//// Make sure the cancel & ok button is the last component
order.add(cancelButton);
order.add(okButton);
CustomFocusTraversalPolicy policy = new CustomFocusTraversalPolicy(order);
parent.setFocusTraversalPolicy(policy);
}

View File

@ -290,7 +290,9 @@ public class ParachuteConfig extends RecoveryDeviceConfig {
tabbedPane.setSelectedIndex(0);
// Apply the custom focus travel policy to this config dialog
order.add(closeButton); // Make sure the close button is the last component
//// Make sure the cancel & ok button is the last component
order.add(cancelButton);
order.add(okButton);
CustomFocusTraversalPolicy policy = new CustomFocusTraversalPolicy(order);
parent.setFocusTraversalPolicy(policy);
}

View File

@ -35,7 +35,9 @@ public class RailButtonConfig extends RocketComponentConfig {
tabbedPane.setSelectedIndex(0);
// Apply the custom focus travel policy to this panel
order.add(closeButton); // Make sure the close button is the last component
//// Make sure the cancel & ok button is the last component
order.add(cancelButton);
order.add(okButton);
CustomFocusTraversalPolicy policy = new CustomFocusTraversalPolicy(order);
parent.setFocusTraversalPolicy(policy);
}

View File

@ -9,6 +9,8 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@ -20,6 +22,7 @@ import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
@ -51,18 +54,24 @@ import net.sf.openrocket.preset.ComponentPreset;
import net.sf.openrocket.rocketcomponent.*;
import net.sf.openrocket.rocketcomponent.position.AxialMethod;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.startup.Preferences;
import net.sf.openrocket.unit.UnitGroup;
import net.sf.openrocket.util.Invalidatable;
public class RocketComponentConfig extends JPanel {
private static final long serialVersionUID = -2925484062132243982L;
// Preference key
private static final String IGNORE_DISCARD_EDITING_WARNING = "IgnoreDiscardEditingWarning";
private static final Translator trans = Application.getTranslator();
private static final Preferences preferences = Application.getPreferences();
protected final OpenRocketDocument document;
protected final RocketComponent component;
protected final JTabbedPane tabbedPane;
protected final JDialog parent;
protected final ComponentConfigDialog parent;
protected boolean isNewComponent = false; // Checks whether this config dialog is editing an existing component, or a new one
private final List<Invalidatable> invalidatables = new ArrayList<Invalidatable>();
protected final List<Component> order = new ArrayList<>(); // Component traversal order
@ -76,7 +85,8 @@ public class RocketComponentConfig extends JPanel {
private final TextFieldListener textFieldListener;
private JPanel buttonPanel;
protected JButton closeButton;
protected JButton okButton;
protected JButton cancelButton;
private AppearancePanel appearancePanel = null;
private JLabel infoLabel;
@ -90,7 +100,11 @@ public class RocketComponentConfig extends JPanel {
this.document = document;
this.component = component;
this.parent = parent;
if (parent instanceof ComponentConfigDialog) {
this.parent = (ComponentConfigDialog) parent;
} else {
this.parent = null;
}
// Check the listeners for the same type and massive status
allSameType = true;
@ -196,21 +210,73 @@ public class RocketComponentConfig extends JPanel {
for (JButton b : buttons) {
buttonPanel.add(b, "right, gap para");
}
//// Close button
this.closeButton = new SelectColorButton(trans.get("dlg.but.close"));
closeButton.addActionListener(new ActionListener() {
//// Cancel button
this.cancelButton = new SelectColorButton(trans.get("dlg.but.cancel"));
this.cancelButton.setToolTipText(trans.get("RocketCompCfg.btn.Cancel.ttip"));
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
if (preferences.getBoolean(IGNORE_DISCARD_EDITING_WARNING, false)) {
ComponentConfigDialog.disposeDialog();
document.undo();
return;
}
if (!isNewComponent && parent != null && !parent.isModified()) {
ComponentConfigDialog.disposeDialog();
return;
}
// Yes/No dialog: Are you sure you want to discard your changes?
JPanel msg = createCancelOperationContent();
int resultYesNo = JOptionPane.showConfirmDialog(RocketComponentConfig.this, msg,
trans.get("RocketCompCfg.CancelOperation.title"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
ComponentConfigDialog.disposeDialog();
if (resultYesNo == JOptionPane.YES_OPTION) {
document.undo();
}
}
});
buttonPanel.add(cancelButton, "split 2, right, gapleft 30lp");
//// Ok button
this.okButton = new SelectColorButton(trans.get("dlg.but.ok"));
this.okButton.setToolTipText(trans.get("RocketCompCfg.btn.OK.ttip"));
okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
ComponentConfigDialog.disposeDialog();
}
});
buttonPanel.add(closeButton, "right, gap 30lp");
buttonPanel.add(okButton);
updateFields();
this.add(buttonPanel, "newline, spanx, growx");
}
private JPanel createCancelOperationContent() {
JPanel panel = new JPanel(new MigLayout());
String msg = isNewComponent ? trans.get("RocketCompCfg.CancelOperation.msg.undoAdd") :
trans.get("RocketCompCfg.CancelOperation.msg.discardChanges");
JLabel msgLabel = new JLabel(msg);
JCheckBox dontAskAgain = new JCheckBox(trans.get("RocketCompCfg.CancelOperation.checkbox.dontAskAgain"));
dontAskAgain.setSelected(false);
dontAskAgain.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
preferences.putBoolean(IGNORE_DISCARD_EDITING_WARNING, true);
}
// Unselected state should be impossible
}
});
panel.add(msgLabel, "left, wrap");
panel.add(dontAskAgain, "left, gaptop para");
return panel;
}
/**
@ -783,6 +849,14 @@ public class RocketComponentConfig extends JPanel {
panel.add(sub);
}
/**
* Sets whether this dialog is editing a new component (true), or an existing one (false).
* @param newComponent true if this dialog is editing a new component.
*/
public void setNewComponent(boolean newComponent) {
isNewComponent = newComponent;
}
/*
* Private inner class to handle events in componentNameField.
*/

View File

@ -142,7 +142,9 @@ public class ShockCordConfig extends RocketComponentConfig {
tabbedPane.setSelectedIndex(0);
// Apply the custom focus travel policy to this config dialog
order.add(closeButton); // Make sure the close button is the last component
//// Make sure the cancel & ok button is the last component
order.add(cancelButton);
order.add(okButton);
CustomFocusTraversalPolicy policy = new CustomFocusTraversalPolicy(order);
parent.setFocusTraversalPolicy(policy);
}

View File

@ -31,7 +31,9 @@ public class SleeveConfig extends RingComponentConfig {
tabbedPane.setSelectedIndex(0);
// Apply the custom focus travel policy to this panel
order.add(closeButton); // Make sure the close button is the last component
//// Make sure the cancel & ok button is the last component
order.add(cancelButton);
order.add(okButton);
CustomFocusTraversalPolicy policy = new CustomFocusTraversalPolicy(order);
parent.setFocusTraversalPolicy(policy);
}

View File

@ -277,7 +277,9 @@ public class StreamerConfig extends RecoveryDeviceConfig {
tabbedPane.setSelectedIndex(0);
// Apply the custom focus travel policy to this config dialog
order.add(closeButton); // Make sure the close button is the last component
//// Make sure the cancel & ok button is the last component
order.add(cancelButton);
order.add(okButton);
CustomFocusTraversalPolicy policy = new CustomFocusTraversalPolicy(order);
parent.setFocusTraversalPolicy(policy);
}

View File

@ -33,7 +33,9 @@ public class ThicknessRingComponentConfig extends RingComponentConfig {
tabbedPane.setSelectedIndex(0);
// Apply the custom focus travel policy to this panel
order.add(closeButton); // Make sure the close button is the last component
//// Make sure the cancel & ok button is the last component
order.add(cancelButton);
order.add(okButton);
CustomFocusTraversalPolicy policy = new CustomFocusTraversalPolicy(order);
parent.setFocusTraversalPolicy(policy);
}

View File

@ -24,7 +24,6 @@ import net.sf.openrocket.gui.components.UnitSelector;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.material.Material;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.SymmetricComponent;
import net.sf.openrocket.rocketcomponent.Transition;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.unit.UnitGroup;
@ -206,7 +205,9 @@ public class TransitionConfig extends RocketComponentConfig {
tabbedPane.setSelectedIndex(0);
// Apply the custom focus travel policy to this config dialog
order.add(closeButton); // Make sure the close button is the last component
//// Make sure the cancel & ok button is the last component
order.add(cancelButton);
order.add(okButton);
CustomFocusTraversalPolicy policy = new CustomFocusTraversalPolicy(order);
parent.setFocusTraversalPolicy(policy);
}

View File

@ -252,7 +252,9 @@ public class TrapezoidFinSetConfig extends FinSetConfig {
addFinSetButtons();
// Apply the custom focus travel policy to this config dialog
order.add(closeButton); // Make sure the close button is the last component
//// Make sure the cancel & ok button is the last component
order.add(cancelButton);
order.add(okButton);
CustomFocusTraversalPolicy policy = new CustomFocusTraversalPolicy(order);
parent.setFocusTraversalPolicy(policy);
}

View File

@ -179,7 +179,9 @@ public class TubeFinSetConfig extends RocketComponentConfig {
tabbedPane.setSelectedIndex(0);
// Apply the custom focus travel policy to this config dialog
order.add(closeButton); // Make sure the close button is the last component
//// Make sure the cancel & ok button is the last component
order.add(cancelButton);
order.add(okButton);
CustomFocusTraversalPolicy policy = new CustomFocusTraversalPolicy(order);
parent.setFocusTraversalPolicy(policy);
}