Only reset edit dialog position at startup
This commit is contained in:
parent
0b7b4d7bc7
commit
a4b13a7ee3
@ -15,6 +15,7 @@ import java.util.List;
|
||||
import javax.swing.JDialog;
|
||||
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.gui.main.BasicFrame;
|
||||
import net.sf.openrocket.gui.util.GUIUtil;
|
||||
import net.sf.openrocket.gui.util.SwingPreferences;
|
||||
import net.sf.openrocket.gui.util.WindowLocationUtil;
|
||||
@ -261,7 +262,9 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
|
||||
|
||||
dialog = new ComponentConfigDialog(parent, document, component);
|
||||
dialog.setVisible(true);
|
||||
WindowLocationUtil.moveIfOutsideOfParentMonitor(dialog, parent);
|
||||
if (parent instanceof BasicFrame && BasicFrame.getStartupFrame() == parent) {
|
||||
WindowLocationUtil.moveIfOutsideOfParentMonitor(dialog, parent);
|
||||
}
|
||||
|
||||
////Modify
|
||||
if (component.getConfigListeners().size() == 0) {
|
||||
|
@ -116,6 +116,7 @@ public class BasicFrame extends JFrame {
|
||||
* it is time to exit the application.
|
||||
*/
|
||||
private static final ArrayList<BasicFrame> frames = new ArrayList<BasicFrame>();
|
||||
private static BasicFrame startupFrame = null; // the frame that was created at startup
|
||||
|
||||
|
||||
/**
|
||||
@ -1200,6 +1201,19 @@ public class BasicFrame extends JFrame {
|
||||
return menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the frame that was created at the application's startup.
|
||||
*/
|
||||
public static BasicFrame getStartupFrame() {
|
||||
return startupFrame;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the frame that is created at the application's startup.
|
||||
*/
|
||||
public static void setStartupFrame(BasicFrame startupFrame) {
|
||||
BasicFrame.startupFrame = startupFrame;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select the tab on the main pane.
|
||||
@ -1242,7 +1256,7 @@ public class BasicFrame extends JFrame {
|
||||
|
||||
for (File file : files) {
|
||||
log.info("Opening file: " + file);
|
||||
if (open(file, parent)) {
|
||||
if (open(file, parent) != null) {
|
||||
MRUDesignFile opts = MRUDesignFile.getInstance();
|
||||
opts.addFile(file.getAbsolutePath());
|
||||
}
|
||||
@ -1272,7 +1286,7 @@ public class BasicFrame extends JFrame {
|
||||
|
||||
for (File file : files) {
|
||||
log.info("Opening file: " + file);
|
||||
if (open(file, this)) {
|
||||
if (open(file, this) != null) {
|
||||
MRUDesignFile opts = MRUDesignFile.getInstance();
|
||||
opts.addFile(file.getAbsolutePath());
|
||||
}
|
||||
@ -1342,9 +1356,9 @@ public class BasicFrame extends JFrame {
|
||||
*
|
||||
* @param file the file to open.
|
||||
* @param parent the parent component for which a progress dialog is opened.
|
||||
* @return whether the file was successfully loaded and opened.
|
||||
* @return the BasicFrame that was created, or null if not created successfully.
|
||||
*/
|
||||
public static boolean open(File file, Window parent) {
|
||||
public static BasicFrame open(File file, Window parent) {
|
||||
OpenFileWorker worker = new OpenFileWorker(file);
|
||||
return open(worker, file.getName(), parent, false);
|
||||
}
|
||||
@ -1357,15 +1371,15 @@ public class BasicFrame extends JFrame {
|
||||
* @param displayName the file name to display in dialogs.
|
||||
* @param parent
|
||||
* @param openRocketConfigDialog if true, will open the configuration dialog of the rocket. This is useful for examples.
|
||||
* @return
|
||||
* @return the BasicFrame that was created, or null if not created successfully.
|
||||
*/
|
||||
private static boolean open(OpenFileWorker worker, String displayName, Window parent, boolean openRocketConfigDialog) {
|
||||
private static BasicFrame open(OpenFileWorker worker, String displayName, Window parent, boolean openRocketConfigDialog) {
|
||||
//// Open the file in a Swing worker thread
|
||||
log.info("Starting OpenFileWorker");
|
||||
if (!SwingWorkerDialog.runWorker(parent, "Opening file", "Reading " + displayName + "...", worker)) {
|
||||
// // User cancelled the operation
|
||||
log.info("User cancelled the OpenFileWorker");
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
//// Handle the document
|
||||
@ -1384,7 +1398,7 @@ public class BasicFrame extends JFrame {
|
||||
JOptionPane.showMessageDialog(parent,
|
||||
"File not found: " + displayName,
|
||||
"Error opening file", JOptionPane.ERROR_MESSAGE);
|
||||
return false;
|
||||
return null;
|
||||
|
||||
} else if (cause instanceof RocketLoadException) {
|
||||
|
||||
@ -1393,7 +1407,7 @@ public class BasicFrame extends JFrame {
|
||||
"Unable to open file '" + displayName + "': "
|
||||
+ cause.getMessage(),
|
||||
"Error opening file", JOptionPane.ERROR_MESSAGE);
|
||||
return false;
|
||||
return null;
|
||||
|
||||
} else {
|
||||
|
||||
@ -1437,7 +1451,7 @@ public class BasicFrame extends JFrame {
|
||||
ComponentConfigDialog.showDialog(frame, doc, doc.getRocket());
|
||||
}
|
||||
|
||||
return true;
|
||||
return frame;
|
||||
}
|
||||
|
||||
|
||||
@ -1743,24 +1757,27 @@ public class BasicFrame extends JFrame {
|
||||
/**
|
||||
* Opens a new design file or the last design file, if set in the preferences.
|
||||
* Can be used for reopening the application or opening it the first time.
|
||||
* @return the BasicFrame that was created
|
||||
*/
|
||||
public static void reopen() {
|
||||
public static BasicFrame reopen() {
|
||||
if (!Application.getPreferences().isAutoOpenLastDesignOnStartupEnabled()) {
|
||||
BasicFrame.newAction();
|
||||
return BasicFrame.newAction();
|
||||
} else {
|
||||
String lastFile = MRUDesignFile.getInstance().getLastEditedDesignFile();
|
||||
if (lastFile != null) {
|
||||
log.info("Opening last design file: " + lastFile);
|
||||
if (!BasicFrame.open(new File(lastFile), null)) {
|
||||
BasicFrame frame = BasicFrame.open(new File(lastFile), null);
|
||||
if (frame == null) {
|
||||
MRUDesignFile.getInstance().removeFile(lastFile);
|
||||
BasicFrame.newAction();
|
||||
return BasicFrame.newAction();
|
||||
}
|
||||
else {
|
||||
MRUDesignFile.getInstance().addFile(lastFile);
|
||||
return frame;
|
||||
}
|
||||
}
|
||||
else {
|
||||
BasicFrame.newAction();
|
||||
return BasicFrame.newAction();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1768,8 +1785,9 @@ public class BasicFrame extends JFrame {
|
||||
|
||||
/**
|
||||
* Open a new design window with a basic rocket+stage.
|
||||
* @return the BasicFrame that was created
|
||||
*/
|
||||
public static void newAction() {
|
||||
public static BasicFrame newAction() {
|
||||
log.info("New action initiated");
|
||||
|
||||
OpenRocketDocument doc = OpenRocketDocumentFactory.createNewRocket();
|
||||
@ -1777,6 +1795,7 @@ public class BasicFrame extends JFrame {
|
||||
BasicFrame frame = new BasicFrame(doc);
|
||||
frame.replaceable = true;
|
||||
frame.setVisible(true);
|
||||
return frame;
|
||||
}
|
||||
|
||||
|
||||
|
@ -73,7 +73,7 @@ public final class MRUDesignFileAction extends JMenu {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String command = e.getActionCommand();
|
||||
if (BasicFrame.open(new File(command), parent)) {
|
||||
if (BasicFrame.open(new File(command), parent) != null) {
|
||||
MRUDesignFile.getInstance().addFile(command);
|
||||
}
|
||||
else {
|
||||
|
@ -223,7 +223,8 @@ public class SwingStartup {
|
||||
// Starting action (load files or open new document)
|
||||
log.info("Opening main application window");
|
||||
if (!handleCommandLine(args)) {
|
||||
BasicFrame.reopen();
|
||||
BasicFrame startupFrame = BasicFrame.reopen();
|
||||
BasicFrame.setStartupFrame(startupFrame);
|
||||
}
|
||||
|
||||
// Check whether update info has been fetched or whether it needs more time
|
||||
@ -298,7 +299,7 @@ public class SwingStartup {
|
||||
// Check command-line for files
|
||||
boolean opened = false;
|
||||
for (String file : args) {
|
||||
if (BasicFrame.open(new File(file), null)) {
|
||||
if (BasicFrame.open(new File(file), null) != null) {
|
||||
opened = true;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user