Skip to content

Commit

Permalink
Merge pull request #639 from ejoerns/pull-req/cooja-plugin-pos
Browse files Browse the repository at this point in the history
[Cooja] Set location of newly created plugins relative to second last activated plugin
  • Loading branch information
fros4943 committed Apr 15, 2014
2 parents 3a08f77 + 055c70b commit d3b9954
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions tools/cooja/java/org/contikios/cooja/Cooja.java
Expand Up @@ -1659,19 +1659,16 @@ public Boolean work() {
return false;
}

int nrFrames = myDesktopPane.getAllFrames().length;
myDesktopPane.add(pluginFrame);

/* Set size if not already specified by plugin */
if (pluginFrame.getWidth() <= 0 || pluginFrame.getHeight() <= 0) {
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);
Expand All @@ -1690,6 +1687,29 @@ public Boolean work() {
}.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.
*
Expand Down

0 comments on commit d3b9954

Please sign in to comment.