ensure mouse-triggered event popups are not outside screen, updated to use new watchpoint interface

This commit is contained in:
Fredrik Osterlind 2012-03-21 16:59:42 +01:00
parent dcd0460e0b
commit 042c75e52c

View file

@ -88,11 +88,12 @@ import se.sics.cooja.GUI;
import se.sics.cooja.Mote; import se.sics.cooja.Mote;
import se.sics.cooja.Plugin; import se.sics.cooja.Plugin;
import se.sics.cooja.PluginType; import se.sics.cooja.PluginType;
import se.sics.cooja.SimEventCentral.MoteCountListener;
import se.sics.cooja.Simulation; import se.sics.cooja.Simulation;
import se.sics.cooja.VisPlugin; import se.sics.cooja.VisPlugin;
import se.sics.cooja.Watchpoint; import se.sics.cooja.Watchpoint;
import se.sics.cooja.WatchpointMote; import se.sics.cooja.WatchpointMote;
import se.sics.cooja.SimEventCentral.MoteCountListener; import se.sics.cooja.WatchpointMote.WatchpointListener;
import se.sics.cooja.interfaces.LED; import se.sics.cooja.interfaces.LED;
import se.sics.cooja.interfaces.Radio; import se.sics.cooja.interfaces.Radio;
import se.sics.cooja.interfaces.Radio.RadioEvent; import se.sics.cooja.interfaces.Radio.RadioEvent;
@ -850,7 +851,7 @@ public class TimeLine extends VisPlugin {
if (popupLocation == null) { if (popupLocation == null) {
return; return;
} }
long time = (long) ((double)popupLocation.x*currentPixelDivisor); long time = (long) (popupLocation.x*currentPixelDivisor);
Plugin[] plugins = simulation.getGUI().getStartedPlugins(); Plugin[] plugins = simulation.getGUI().getStartedPlugins();
for (Plugin p: plugins) { for (Plugin p: plugins) {
@ -870,7 +871,7 @@ public class TimeLine extends VisPlugin {
if (popupLocation == null) { if (popupLocation == null) {
return; return;
} }
long time = (long) ((double)popupLocation.x*currentPixelDivisor); long time = (long) (popupLocation.x*currentPixelDivisor);
Plugin[] plugins = simulation.getGUI().getStartedPlugins(); Plugin[] plugins = simulation.getGUI().getStartedPlugins();
for (Plugin p: plugins) { for (Plugin p: plugins) {
@ -929,7 +930,7 @@ public class TimeLine extends VisPlugin {
private Mote mote; private Mote mote;
private WatchpointMote watchpointMote; /* XXX */ private WatchpointMote watchpointMote; /* XXX */
private ActionListener watchpointListener; /* XXX */ private WatchpointListener watchpointListener; /* XXX */
public MoteObservation(Mote mote, Observable observable, Observer observer) { public MoteObservation(Mote mote, Observable observable, Observer observer) {
this.mote = mote; this.mote = mote;
@ -938,7 +939,7 @@ public class TimeLine extends VisPlugin {
} }
/* XXX Special case, should be generalized */ /* XXX Special case, should be generalized */
public MoteObservation(Mote mote, WatchpointMote watchpointMote, ActionListener listener) { public MoteObservation(Mote mote, WatchpointMote watchpointMote, WatchpointListener listener) {
this.mote = mote; this.mote = mote;
this.watchpointMote = watchpointMote; this.watchpointMote = watchpointMote;
this.watchpointListener = listener; this.watchpointListener = listener;
@ -1110,18 +1111,22 @@ public class TimeLine extends VisPlugin {
/* XXX Experimental: Watchpoints */ /* XXX Experimental: Watchpoints */
if (mote instanceof WatchpointMote) { if (mote instanceof WatchpointMote) {
final WatchpointMote watchpointMote = ((WatchpointMote)mote); final WatchpointMote watchpointMote = ((WatchpointMote)mote);
ActionListener listener = new ActionListener() { WatchpointListener listener = new WatchpointListener() {
public void actionPerformed(ActionEvent e) { public void watchpointTriggered(Watchpoint watchpoint) {
if (watchpointMote.getLastWatchpoint() == null) { WatchpointEvent ev = new WatchpointEvent(simulation.getSimulationTime(), watchpoint);
return;
if (executionDetails && mote instanceof AbstractEmulatedMote) {
String details = ((AbstractEmulatedMote) mote).getExecutionDetails();
if (details != null) {
details = "<br>" + details.replace("\n", "<br>");
ev.details = details;
}
} }
WatchpointEvent ev = new WatchpointEvent(
simulation.getSimulationTime(),
watchpointMote.getLastWatchpoint()
);
moteEvents.addWatchpoint(ev); moteEvents.addWatchpoint(ev);
} }
public void watchpointsChanged() {
}
}; };
watchpointMote.addWatchpointListener(listener); watchpointMote.addWatchpointListener(listener);
@ -1417,7 +1422,7 @@ public class TimeLine extends VisPlugin {
popupLocation = e.getPoint(); popupLocation = e.getPoint();
showInAllAction.actionPerformed(null); showInAllAction.actionPerformed(null);
long time = (long) ((double)popupLocation.x*currentPixelDivisor); long time = (long) (popupLocation.x*currentPixelDivisor);
Plugin[] plugins = simulation.getGUI().getStartedPlugins(); Plugin[] plugins = simulation.getGUI().getStartedPlugins();
for (Plugin p: plugins) { for (Plugin p: plugins) {
if (!(p instanceof TimeLine)) { if (!(p instanceof TimeLine)) {
@ -1524,7 +1529,34 @@ public class TimeLine extends VisPlugin {
if (t.getTipText() == null || t.getTipText().equals("")) { if (t.getTipText() == null || t.getTipText().equals("")) {
return; return;
} }
popUpToolTip = PopupFactory.getSharedInstance().getPopup(timeline, t, e.getXOnScreen(), e.getYOnScreen()); t.validate();
/* Check tooltip width */
Rectangle screenBounds = timeline.getGraphicsConfiguration().getBounds();
int x;
{
int tooltip = e.getLocationOnScreen().x + t.getPreferredSize().width;
int screen = screenBounds.x + screenBounds.width;
if (tooltip > screen) {
x = e.getLocationOnScreen().x - (tooltip-screen);
} else {
x = e.getLocationOnScreen().x;
}
}
/* Check tooltip height */
int y;
{
int tooltip = e.getLocationOnScreen().y + t.getPreferredSize().height;
int screen = screenBounds.y + screenBounds.height;
if (tooltip > screen) {
y = e.getLocationOnScreen().y - (tooltip-screen);
} else {
y = e.getLocationOnScreen().y;
}
}
popUpToolTip = PopupFactory.getSharedInstance().getPopup(null, t, x, y);
popUpToolTip.show(); popUpToolTip.show();
} }
} }
@ -1680,12 +1712,12 @@ public class TimeLine extends VisPlugin {
while (time <= end) { while (time <= end) {
if (time % (100*Simulation.MILLISECOND) == 0) { if (time % (100*Simulation.MILLISECOND) == 0) {
g.drawLine( g.drawLine(
(int) (time/currentPixelDivisor), (int)0, (int) (time/currentPixelDivisor), 0,
(int) (time/currentPixelDivisor), (int)TIME_MARKER_PIXEL_HEIGHT); (int) (time/currentPixelDivisor), TIME_MARKER_PIXEL_HEIGHT);
} else { } else {
g.drawLine( g.drawLine(
(int) (time/currentPixelDivisor), (int)0, (int) (time/currentPixelDivisor), 0,
(int) (time/currentPixelDivisor), (int)TIME_MARKER_PIXEL_HEIGHT/2); (int) (time/currentPixelDivisor), TIME_MARKER_PIXEL_HEIGHT/2);
} }
time += (10*Simulation.MILLISECOND); time += (10*Simulation.MILLISECOND);
} }
@ -1693,8 +1725,8 @@ public class TimeLine extends VisPlugin {
private void drawMouseTime(Graphics g, long start, long end) { private void drawMouseTime(Graphics g, long start, long end) {
if (mousePixelPositionX >= 0) { if (mousePixelPositionX >= 0) {
long time = (long) ((double)mousePixelPositionX*currentPixelDivisor); long time = (long) (mousePixelPositionX*currentPixelDivisor);
long diff = (long) ((double)Math.abs(mouseDownPixelPositionX-mousePixelPositionX)*currentPixelDivisor); long diff = (long) (Math.abs(mouseDownPixelPositionX-mousePixelPositionX)*currentPixelDivisor);
String str = String str =
"Time (ms): " + (double)time/Simulation.MILLISECOND + "Time (ms): " + (double)time/Simulation.MILLISECOND +
" (" + (double)diff/Simulation.MILLISECOND + ")"; " (" + (double)diff/Simulation.MILLISECOND + ")";
@ -2333,7 +2365,7 @@ public class TimeLine extends VisPlugin {
Rectangle visibleRectangle = timeline.getVisibleRect(); Rectangle visibleRectangle = timeline.getVisibleRect();
boolean isTracking = visibleRectangle.x + visibleRectangle.width >= timeline.getWidth(); boolean isTracking = visibleRectangle.x + visibleRectangle.width >= timeline.getWidth();
int newHeight = (int) (FIRST_MOTE_PIXEL_OFFSET + paintedMoteHeight * allMoteEvents.size()); int newHeight = (FIRST_MOTE_PIXEL_OFFSET + paintedMoteHeight * allMoteEvents.size());
timeline.setPreferredSize(new Dimension( timeline.setPreferredSize(new Dimension(
newWidth, newWidth,
newHeight newHeight