From 055c70b4552724bcc7c8ed88234825d780c98a66 Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Tue, 15 Apr 2014 00:04:31 +0200 Subject: [PATCH] [cooja] Set location of newly created plugins relative to second last activated plugin. Setting the position based on the number of total inner frames was very inflexible and caused pad positioning for larger number of frames. Setting the location of new plugin frames to the second last activated one tries to meet two requirements: - Avoid covering the last activated plugin frame, i.e. the one that was active when new plugin start was invoked. - Set new plugin near an actively used desktop pane location and allow 'diagonal stacking' --- .../cooja/java/org/contikios/cooja/Cooja.java | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) 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. *