[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'
This commit is contained in:
Enrico Joerns 2014-04-15 00:04:31 +02:00
parent 19cd33664d
commit 055c70b455

View file

@ -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.
* <p>
* 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.
*