mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-06-02 20:54:39 +08:00
Merge remote-tracking branch
'origin/GP-3958_dragonmacher_PR-5890_M-a-r-k_patch-1' (Closes #5890, Closes #5879)
This commit is contained in:
@@ -28,6 +28,7 @@ import org.jdom.Element;
|
|||||||
import generic.util.WindowUtilities;
|
import generic.util.WindowUtilities;
|
||||||
import ghidra.framework.OperatingSystem;
|
import ghidra.framework.OperatingSystem;
|
||||||
import ghidra.framework.Platform;
|
import ghidra.framework.Platform;
|
||||||
|
import ghidra.util.Swing;
|
||||||
import ghidra.util.bean.GGlassPane;
|
import ghidra.util.bean.GGlassPane;
|
||||||
import ghidra.util.datastruct.WeakDataStructureFactory;
|
import ghidra.util.datastruct.WeakDataStructureFactory;
|
||||||
import ghidra.util.datastruct.WeakSet;
|
import ghidra.util.datastruct.WeakSet;
|
||||||
@@ -427,12 +428,13 @@ class RootNode extends WindowNode {
|
|||||||
Element saveToXML() {
|
Element saveToXML() {
|
||||||
Element root = new Element(ROOT_NODE_ELEMENT_NAME);
|
Element root = new Element(ROOT_NODE_ELEMENT_NAME);
|
||||||
JFrame frame = windowWrapper.getParentFrame();
|
JFrame frame = windowWrapper.getParentFrame();
|
||||||
Rectangle r = frame.getBounds();
|
Rectangle r = getSaveableBounds();
|
||||||
root.setAttribute("X_POS", "" + r.x);
|
root.setAttribute("X_POS", "" + r.x);
|
||||||
root.setAttribute("Y_POS", "" + r.y);
|
root.setAttribute("Y_POS", "" + r.y);
|
||||||
root.setAttribute("WIDTH", "" + r.width);
|
root.setAttribute("WIDTH", "" + r.width);
|
||||||
root.setAttribute("HEIGHT", "" + r.height);
|
root.setAttribute("HEIGHT", "" + r.height);
|
||||||
root.setAttribute("EX_STATE", "" + frame.getExtendedState());
|
root.setAttribute("EX_STATE", "" + frame.getExtendedState());
|
||||||
|
|
||||||
if (child != null) {
|
if (child != null) {
|
||||||
root.addContent(child.saveToXML());
|
root.addContent(child.saveToXML());
|
||||||
}
|
}
|
||||||
@@ -444,6 +446,18 @@ class RootNode extends WindowNode {
|
|||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Rectangle getSaveableBounds() {
|
||||||
|
|
||||||
|
Rectangle bounds = windowWrapper.getLastBounds();
|
||||||
|
if (bounds != null) {
|
||||||
|
return bounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This implies the user has never maximized the window; just use the window bounds.
|
||||||
|
JFrame frame = windowWrapper.getParentFrame();
|
||||||
|
return frame.getBounds();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restores the component hierarchy from the given XML JDOM element.
|
* Restores the component hierarchy from the given XML JDOM element.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -474,7 +488,15 @@ class RootNode extends WindowNode {
|
|||||||
Rectangle bounds = new Rectangle(x, y, width, height);
|
Rectangle bounds = new Rectangle(x, y, width, height);
|
||||||
WindowUtilities.ensureOnScreen(frame, bounds);
|
WindowUtilities.ensureOnScreen(frame, bounds);
|
||||||
frame.setBounds(bounds);
|
frame.setBounds(bounds);
|
||||||
|
windowWrapper.setLastBounds(bounds);
|
||||||
|
|
||||||
|
Swing.runLater(() -> {
|
||||||
|
// On some systems setting the bounds will interfere with setting the extended state.
|
||||||
|
// Run this later to ensure the extended state is applied after setting the bounds.
|
||||||
|
// Executing in this order allows the bounds we set above to be used when the user
|
||||||
|
// transitions out of the maximized state.
|
||||||
frame.setExtendedState(extendedState);
|
frame.setExtendedState(extendedState);
|
||||||
|
});
|
||||||
|
|
||||||
List<ComponentPlaceholder> restoredPlaceholders = new ArrayList<>();
|
List<ComponentPlaceholder> restoredPlaceholders = new ArrayList<>();
|
||||||
Iterator<?> elementIterator = rootNodeElement.getChildren().iterator();
|
Iterator<?> elementIterator = rootNodeElement.getChildren().iterator();
|
||||||
@@ -607,29 +629,64 @@ class RootNode extends WindowNode {
|
|||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
|
|
||||||
/** Interface to wrap JDialog and JFrame so that they can be used by one handle */
|
/** Interface to wrap JDialog and JFrame so that they can be used by one handle */
|
||||||
private interface SwingWindowWrapper {
|
private abstract class SwingWindowWrapper {
|
||||||
boolean isVisible();
|
|
||||||
|
|
||||||
boolean isModal();
|
/**
|
||||||
|
* The last known non-maximized window bounds
|
||||||
|
*/
|
||||||
|
private Rectangle lastBounds;
|
||||||
|
|
||||||
void validate();
|
abstract boolean isVisible();
|
||||||
|
|
||||||
Container getContentPane();
|
abstract boolean isModal();
|
||||||
|
|
||||||
void setJMenuBar(JMenuBar menuBar);
|
abstract void validate();
|
||||||
|
|
||||||
void dispose();
|
abstract Container getContentPane();
|
||||||
|
|
||||||
Window getWindow();
|
abstract void setJMenuBar(JMenuBar menuBar);
|
||||||
|
|
||||||
JFrame getParentFrame();
|
abstract void dispose();
|
||||||
|
|
||||||
void setTitle(String title);
|
abstract Window getWindow();
|
||||||
|
|
||||||
String getTitle();
|
abstract JFrame getParentFrame();
|
||||||
|
|
||||||
|
abstract void setTitle(String title);
|
||||||
|
|
||||||
|
abstract String getTitle();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores the given bounds if they are not the maximized bounds
|
||||||
|
* @param bounds the bounds
|
||||||
|
*/
|
||||||
|
public void setLastBounds(Rectangle bounds) {
|
||||||
|
Rectangle screenBounds = WindowUtilities.getScreenBounds(getWindow());
|
||||||
|
if (screenBounds == null) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class JDialogWindowWrapper implements SwingWindowWrapper {
|
Rectangle boundsSize = new Rectangle(bounds.getSize());
|
||||||
|
Rectangle screenSize = new Rectangle(screenBounds.getSize());
|
||||||
|
if (boundsSize.contains(screenSize)) {
|
||||||
|
// This can happen when the bounds being set are the full screen bounds. We only
|
||||||
|
// wish to save the non-maximized bounds.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.lastBounds = bounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the last non-maximized frame bounds
|
||||||
|
* @return the bounds
|
||||||
|
*/
|
||||||
|
public Rectangle getLastBounds() {
|
||||||
|
return lastBounds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class JDialogWindowWrapper extends SwingWindowWrapper {
|
||||||
|
|
||||||
private final JDialog wrappedDialog;
|
private final JDialog wrappedDialog;
|
||||||
private final SwingWindowWrapper parentFrame;
|
private final SwingWindowWrapper parentFrame;
|
||||||
@@ -659,9 +716,16 @@ class RootNode extends WindowNode {
|
|||||||
public void windowActivated(WindowEvent e) {
|
public void windowActivated(WindowEvent e) {
|
||||||
winMgr.setActive(wrappedDialog, true);
|
winMgr.setActive(wrappedDialog, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void windowStateChanged(WindowEvent e) {
|
||||||
|
// this is called when transitioning in and out of the full-screen state
|
||||||
|
setLastBounds(wrappedDialog.getBounds());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
dialog.addWindowListener(windowListener);
|
dialog.addWindowListener(windowListener);
|
||||||
|
dialog.addWindowStateListener(windowListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -682,6 +746,11 @@ class RootNode extends WindowNode {
|
|||||||
return wrappedDialog;
|
return wrappedDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JFrame getParentFrame() {
|
||||||
|
return parentFrame.getParentFrame();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isVisible() {
|
public boolean isVisible() {
|
||||||
return wrappedDialog.isVisible();
|
return wrappedDialog.isVisible();
|
||||||
@@ -697,11 +766,6 @@ class RootNode extends WindowNode {
|
|||||||
wrappedDialog.validate();
|
wrappedDialog.validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public JFrame getParentFrame() {
|
|
||||||
return parentFrame.getParentFrame();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTitle(String title) {
|
public void setTitle(String title) {
|
||||||
wrappedDialog.setTitle(title);
|
wrappedDialog.setTitle(title);
|
||||||
@@ -718,7 +782,7 @@ class RootNode extends WindowNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class JFrameWindowWrapper implements SwingWindowWrapper {
|
private class JFrameWindowWrapper extends SwingWindowWrapper {
|
||||||
|
|
||||||
private final JFrame wrappedFrame;
|
private final JFrame wrappedFrame;
|
||||||
private WindowAdapter windowListener;
|
private WindowAdapter windowListener;
|
||||||
@@ -759,8 +823,16 @@ class RootNode extends WindowNode {
|
|||||||
public void windowDeiconified(WindowEvent e) {
|
public void windowDeiconified(WindowEvent e) {
|
||||||
winMgr.deIconify();
|
winMgr.deIconify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void windowStateChanged(WindowEvent e) {
|
||||||
|
// this is called when transitioning in and out of the full-screen state
|
||||||
|
setLastBounds(wrappedFrame.getBounds());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
wrappedFrame.addWindowListener(windowListener);
|
wrappedFrame.addWindowListener(windowListener);
|
||||||
|
wrappedFrame.addWindowStateListener(windowListener);
|
||||||
|
|
||||||
wrappedFrame.setSize(800, 400);
|
wrappedFrame.setSize(800, 400);
|
||||||
}
|
}
|
||||||
@@ -782,6 +854,11 @@ class RootNode extends WindowNode {
|
|||||||
return wrappedFrame;
|
return wrappedFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JFrame getParentFrame() {
|
||||||
|
return wrappedFrame;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isVisible() {
|
public boolean isVisible() {
|
||||||
return wrappedFrame.isVisible();
|
return wrappedFrame.isVisible();
|
||||||
@@ -797,11 +874,6 @@ class RootNode extends WindowNode {
|
|||||||
wrappedFrame.validate();
|
wrappedFrame.validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public JFrame getParentFrame() {
|
|
||||||
return wrappedFrame;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTitle(String title) {
|
public void setTitle(String title) {
|
||||||
wrappedFrame.setTitle(title);
|
wrappedFrame.setTitle(title);
|
||||||
@@ -816,7 +888,6 @@ class RootNode extends WindowNode {
|
|||||||
public boolean isModal() {
|
public boolean isModal() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDockingWindowListener(DockingWindowListener listener) {
|
public void addDockingWindowListener(DockingWindowListener listener) {
|
||||||
|
|||||||
Reference in New Issue
Block a user