diff --git a/tools/cooja/java/org/contikios/cooja/Cooja.java b/tools/cooja/java/org/contikios/cooja/Cooja.java index c9c2bad7a..4d1770b6b 100644 --- a/tools/cooja/java/org/contikios/cooja/Cooja.java +++ b/tools/cooja/java/org/contikios/cooja/Cooja.java @@ -1659,7 +1659,6 @@ public class Cooja extends Observable { return false; } - int nrFrames = myDesktopPane.getAllFrames().length; myDesktopPane.add(pluginFrame); /* Set size if not already specified by plugin */ @@ -1667,11 +1666,9 @@ public class Cooja extends Observable { pluginFrame.setSize(FRAME_STANDARD_WIDTH, FRAME_STANDARD_HEIGHT); } - /* Set location if not already visible */ + /* Set location if not already set */ if (pluginFrame.getLocation().x <= 0 && pluginFrame.getLocation().y <= 0) { - pluginFrame.setLocation( - nrFrames * FRAME_NEW_OFFSET, - nrFrames * FRAME_NEW_OFFSET); + pluginFrame.setLocation(determineNewPluginLocation()); } pluginFrame.setVisible(true); @@ -1690,6 +1687,29 @@ public class Cooja extends Observable { }.invokeAndWait(); } + /** + * Determines suitable location for placing new plugin. + *
+ * If possible, this is below right of the second last activated + * internfal frame (offset is determined by FRAME_NEW_OFFSET). + * + * @return Resulting placement position + */ + private Point determineNewPluginLocation() { + Point topFrameLoc; + JInternalFrame[] iframes = myDesktopPane.getAllFrames(); + if (iframes.length > 1) { + topFrameLoc = iframes[1].getLocation(); + } else { + topFrameLoc = new Point( + myDesktopPane.getSize().width / 2, + myDesktopPane.getSize().height / 2); + } + return new Point( + topFrameLoc.x + FRAME_NEW_OFFSET, + topFrameLoc.y + FRAME_NEW_OFFSET); + } + /** * Close all mote plugins for given mote. *