mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 03:50:02 +02:00
Merge remote-tracking branch 'origin/GP-1-dragonmacher-window-size-issue--SQUASHED'
This commit is contained in:
commit
eb7dbaa04f
3 changed files with 91 additions and 93 deletions
|
@ -37,13 +37,12 @@ import ghidra.util.bean.GGlassPane;
|
|||
class DetachedWindowNode extends WindowNode {
|
||||
|
||||
private Window window;
|
||||
//private String title;
|
||||
private Node child;
|
||||
private Rectangle bounds;
|
||||
private StatusBar statusBar;
|
||||
private JComponent childComp;
|
||||
private DropTargetHandler dropTargetHandler;
|
||||
private DropTargetFactory dropTargetFactory;
|
||||
private Rectangle restoreBounds = new Rectangle();
|
||||
|
||||
/**
|
||||
* Constructs a new WindowNode
|
||||
|
@ -59,7 +58,6 @@ class DetachedWindowNode extends WindowNode {
|
|||
this.child = child;
|
||||
this.dropTargetFactory = factory;
|
||||
child.parent = this;
|
||||
bounds = new Rectangle(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,20 +74,20 @@ class DetachedWindowNode extends WindowNode {
|
|||
this.parent = parent;
|
||||
this.dropTargetFactory = factory;
|
||||
|
||||
//title = elem.getAttributeValue("TITLE");
|
||||
int x = Integer.parseInt(elem.getAttributeValue("X_POS"));
|
||||
int y = Integer.parseInt(elem.getAttributeValue("Y_POS"));
|
||||
int width = Integer.parseInt(elem.getAttributeValue("WIDTH"));
|
||||
int height = Integer.parseInt(elem.getAttributeValue("HEIGHT"));
|
||||
bounds = new Rectangle(x, y, width, height);
|
||||
restoreBounds = new Rectangle(x, y, width, height);
|
||||
Element childElement = (Element) elem.getChildren().get(0);
|
||||
child = processChildElement(childElement, mgr, this, list);
|
||||
|
||||
}
|
||||
|
||||
void setInitialLocation(int x, int y) {
|
||||
bounds.x = x;
|
||||
bounds.y = y;
|
||||
void setInitialBounds(Rectangle r) {
|
||||
if (r == null) {
|
||||
r = new Rectangle();
|
||||
}
|
||||
restoreBounds = r;
|
||||
}
|
||||
|
||||
void updateTitle() {
|
||||
|
@ -366,32 +364,51 @@ class DetachedWindowNode extends WindowNode {
|
|||
}
|
||||
});
|
||||
|
||||
adjustBounds();
|
||||
|
||||
Rectangle bounds = getNewBounds(window);
|
||||
window.setBounds(bounds);
|
||||
window.setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the bounds of this window have a valid location and size
|
||||
*/
|
||||
private void adjustBounds() {
|
||||
private Rectangle getNewBounds(Window newWindow) {
|
||||
|
||||
if (bounds.height == 0 || bounds.width == 0) {
|
||||
Rectangle updatedBounds = new Rectangle(restoreBounds);
|
||||
if (updatedBounds.isEmpty()) {
|
||||
// No bounds to restore; pick something reasonable
|
||||
window.pack();
|
||||
Dimension d = window.getSize();
|
||||
bounds.height = d.height;
|
||||
bounds.width = d.width;
|
||||
Dimension d = newWindow.getSize();
|
||||
updatedBounds.height = d.height;
|
||||
updatedBounds.width = d.width;
|
||||
}
|
||||
else {
|
||||
|
||||
// Update the desired window bounds for the size of the component. The window size
|
||||
// has to account for things like the menu and toolbars. These value were picked
|
||||
// through trial-and-error.
|
||||
int nonComponentWidth = 12;
|
||||
int nonComponentHeight = 120;
|
||||
|
||||
updatedBounds.width += nonComponentWidth;
|
||||
updatedBounds.height += nonComponentHeight;
|
||||
}
|
||||
|
||||
ensureValidLocation(updatedBounds);
|
||||
|
||||
WindowUtilities.ensureEntirelyOnScreen(newWindow, updatedBounds);
|
||||
|
||||
return updatedBounds;
|
||||
}
|
||||
|
||||
private void ensureValidLocation(Rectangle r) {
|
||||
|
||||
Window activeWindow = winMgr.getActiveWindow();
|
||||
Point p = bounds.getLocation();
|
||||
Point p = r.getLocation();
|
||||
if (p.x == 0 && p.y == 0) {
|
||||
p = WindowUtilities.centerOnScreen(activeWindow, bounds.getSize());
|
||||
bounds.setLocation(p);
|
||||
// assume that 0,0 means that we have not yet been placed at any preferred location
|
||||
p = WindowUtilities.centerOnScreen(activeWindow, r.getSize());
|
||||
r.setLocation(p);
|
||||
}
|
||||
|
||||
WindowUtilities.ensureOnScreen(activeWindow, bounds);
|
||||
WindowUtilities.ensureOnScreen(activeWindow, r);
|
||||
}
|
||||
|
||||
private JFrame createFrame() {
|
||||
|
@ -434,7 +451,7 @@ class DetachedWindowNode extends WindowNode {
|
|||
void updateDialog() {
|
||||
|
||||
if (window != null && childComp != null) {
|
||||
bounds = window.getBounds();
|
||||
restoreBounds = window.getBounds();
|
||||
winMgr.getMainWindow().requestFocus();
|
||||
getContentPane().remove(childComp);
|
||||
window.dispose();
|
||||
|
@ -465,7 +482,7 @@ class DetachedWindowNode extends WindowNode {
|
|||
}
|
||||
}
|
||||
else if (window != null) {
|
||||
bounds = window.getBounds();
|
||||
restoreBounds = window.getBounds();
|
||||
window.setVisible(false);
|
||||
window.dispose();
|
||||
window = null;
|
||||
|
@ -557,14 +574,14 @@ class DetachedWindowNode extends WindowNode {
|
|||
@Override
|
||||
Element saveToXML() {
|
||||
if (window != null) {
|
||||
bounds = window.getBounds();
|
||||
restoreBounds = window.getBounds();
|
||||
}
|
||||
|
||||
Element root = new Element("WINDOW_NODE");
|
||||
root.setAttribute("X_POS", "" + bounds.x);
|
||||
root.setAttribute("Y_POS", "" + bounds.y);
|
||||
root.setAttribute("WIDTH", "" + bounds.width);
|
||||
root.setAttribute("HEIGHT", "" + bounds.height);
|
||||
root.setAttribute("X_POS", "" + restoreBounds.x);
|
||||
root.setAttribute("Y_POS", "" + restoreBounds.y);
|
||||
root.setAttribute("WIDTH", "" + restoreBounds.width);
|
||||
root.setAttribute("HEIGHT", "" + restoreBounds.height);
|
||||
root.addContent(child.saveToXML());
|
||||
return root;
|
||||
|
||||
|
|
|
@ -150,9 +150,7 @@ class RootNode extends WindowNode {
|
|||
void setToolName(String toolName) {
|
||||
this.toolName = toolName;
|
||||
windowWrapper.setTitle(toolName);
|
||||
Iterator<DetachedWindowNode> it = detachedWindows.iterator();
|
||||
while (it.hasNext()) {
|
||||
DetachedWindowNode windowNode = it.next();
|
||||
for (DetachedWindowNode windowNode : detachedWindows) {
|
||||
windowNode.updateTitle();
|
||||
}
|
||||
|
||||
|
@ -186,9 +184,7 @@ class RootNode extends WindowNode {
|
|||
void setIcon(ImageIcon icon) {
|
||||
Image iconImage = icon.getImage();
|
||||
setFrameIcon(windowWrapper.getParentFrame(), iconImage);
|
||||
Iterator<DetachedWindowNode> it = detachedWindows.iterator();
|
||||
while (it.hasNext()) {
|
||||
DetachedWindowNode windowNode = it.next();
|
||||
for (DetachedWindowNode windowNode : detachedWindows) {
|
||||
windowNode.setIcon(iconImage);
|
||||
}
|
||||
}
|
||||
|
@ -206,9 +202,7 @@ class RootNode extends WindowNode {
|
|||
WindowUtilities.ensureOnScreen(mainWindow);
|
||||
}
|
||||
|
||||
Iterator<DetachedWindowNode> it = detachedWindows.iterator();
|
||||
while (it.hasNext()) {
|
||||
DetachedWindowNode windowNode = it.next();
|
||||
for (DetachedWindowNode windowNode : detachedWindows) {
|
||||
windowNode.setVisible(state);
|
||||
}
|
||||
}
|
||||
|
@ -224,14 +218,31 @@ class RootNode extends WindowNode {
|
|||
* @param loc the location for the new window.
|
||||
*/
|
||||
void addToNewWindow(ComponentPlaceholder placeholder, Point loc) {
|
||||
DockableComponent component = placeholder.getComponent();
|
||||
Dimension placeholderSize = null;
|
||||
if (component != null) {
|
||||
Dimension size = component.getSize();
|
||||
Dimension preferredSize = component.getPreferredSize();
|
||||
|
||||
placeholderSize = new Dimension(size);
|
||||
int area = size.width * size.height;
|
||||
int preferredArea = preferredSize.width * preferredSize.height;
|
||||
if (preferredArea > area) {
|
||||
placeholderSize.width = preferredSize.width;
|
||||
placeholderSize.height = preferredSize.height;
|
||||
}
|
||||
}
|
||||
|
||||
ComponentNode node = new ComponentNode(winMgr);
|
||||
placeholder.setNode(node);
|
||||
node.parent = this;
|
||||
DetachedWindowNode windowNode =
|
||||
new DetachedWindowNode(winMgr, this, node, dropTargetFactory);
|
||||
if (loc != null) {
|
||||
windowNode.setInitialLocation(loc.x, loc.y);
|
||||
}
|
||||
|
||||
Point location = loc == null ? new Point() : loc;
|
||||
Dimension size = placeholderSize == null ? new Dimension() : placeholderSize;
|
||||
windowNode.setInitialBounds(new Rectangle(location, size));
|
||||
|
||||
detachedWindows.add(windowNode);
|
||||
placeholder.getNode().add(placeholder);
|
||||
placeholder.requestFocusWhenReady();
|
||||
|
@ -302,9 +313,7 @@ class RootNode extends WindowNode {
|
|||
if (child != null && child.contains(info)) {
|
||||
return windowWrapper.getWindow();
|
||||
}
|
||||
Iterator<DetachedWindowNode> iter = detachedWindows.iterator();
|
||||
while (iter.hasNext()) {
|
||||
DetachedWindowNode winNode = iter.next();
|
||||
for (DetachedWindowNode winNode : detachedWindows) {
|
||||
if (winNode.contains(info)) {
|
||||
return winNode.getWindow();
|
||||
}
|
||||
|
@ -319,9 +328,7 @@ class RootNode extends WindowNode {
|
|||
if (invalid) {
|
||||
clearContextTypes();
|
||||
updateChild();
|
||||
Iterator<DetachedWindowNode> it = detachedWindows.iterator();
|
||||
while (it.hasNext()) {
|
||||
DetachedWindowNode windowNode = it.next();
|
||||
for (DetachedWindowNode windowNode : detachedWindows) {
|
||||
windowNode.update();
|
||||
}
|
||||
invalid = false;
|
||||
|
@ -332,9 +339,7 @@ class RootNode extends WindowNode {
|
|||
}
|
||||
|
||||
void updateDialogs() {
|
||||
Iterator<DetachedWindowNode> it = detachedWindows.iterator();
|
||||
while (it.hasNext()) {
|
||||
DetachedWindowNode windowNode = it.next();
|
||||
for (DetachedWindowNode windowNode : detachedWindows) {
|
||||
windowNode.updateDialog();
|
||||
}
|
||||
}
|
||||
|
@ -438,9 +443,7 @@ class RootNode extends WindowNode {
|
|||
if (child != null) {
|
||||
root.addContent(child.saveToXML());
|
||||
}
|
||||
Iterator<DetachedWindowNode> it = detachedWindows.iterator();
|
||||
while (it.hasNext()) {
|
||||
DetachedWindowNode windowNode = it.next();
|
||||
for (DetachedWindowNode windowNode : detachedWindows) {
|
||||
root.addContent(windowNode.saveToXML());
|
||||
}
|
||||
return root;
|
||||
|
@ -555,9 +558,7 @@ class RootNode extends WindowNode {
|
|||
rootDropTargetHandler.dispose();
|
||||
}
|
||||
|
||||
Iterator<DetachedWindowNode> it = detachedWindows.iterator();
|
||||
while (it.hasNext()) {
|
||||
DetachedWindowNode windowNode = it.next();
|
||||
for (DetachedWindowNode windowNode : detachedWindows) {
|
||||
notifyWindowRemoved(windowNode);
|
||||
windowNode.dispose();
|
||||
}
|
||||
|
@ -571,9 +572,7 @@ class RootNode extends WindowNode {
|
|||
if (child != null && child.contains(info)) {
|
||||
return true;
|
||||
}
|
||||
Iterator<DetachedWindowNode> iter = detachedWindows.iterator();
|
||||
while (iter.hasNext()) {
|
||||
DetachedWindowNode winNode = iter.next();
|
||||
for (DetachedWindowNode winNode : detachedWindows) {
|
||||
if (winNode.contains(info)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -606,9 +605,7 @@ class RootNode extends WindowNode {
|
|||
|
||||
statusBar.clearStatusMessages();
|
||||
|
||||
Iterator<DetachedWindowNode> iter = detachedWindows.iterator();
|
||||
while (iter.hasNext()) {
|
||||
DetachedWindowNode winNode = iter.next();
|
||||
for (DetachedWindowNode winNode : detachedWindows) {
|
||||
winNode.clearStatusMessages();
|
||||
}
|
||||
}
|
||||
|
@ -620,9 +617,7 @@ class RootNode extends WindowNode {
|
|||
|
||||
statusBar.setStatusText(text);
|
||||
|
||||
Iterator<DetachedWindowNode> iter = detachedWindows.iterator();
|
||||
while (iter.hasNext()) {
|
||||
DetachedWindowNode winNode = iter.next();
|
||||
for (DetachedWindowNode winNode : detachedWindows) {
|
||||
winNode.setStatusText(text);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue