From 56e2536884205338ea2a4938f44475e0f19892a3 Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Fri, 18 Apr 2014 03:42:01 +0200 Subject: [PATCH] [cooja] plugins/Visualizer: Simple mote tooltip Shows a motes type identifier and filename of firmware/sourcecode running on it --- .../contikios/cooja/plugins/Visualizer.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java b/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java index 733bafa6f..8ce3db299 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/Visualizer.java @@ -87,6 +87,7 @@ import javax.swing.KeyStroke; import javax.swing.MenuElement; import javax.swing.SwingUtilities; import javax.swing.Timer; +import javax.swing.ToolTipManager; import javax.swing.event.MenuEvent; import javax.swing.event.MenuListener; import javax.swing.plaf.basic.BasicInternalFrameUI; @@ -319,6 +320,10 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { canvas = new JPanel() { private static final long serialVersionUID = 1L; + { + ToolTipManager.sharedInstance().registerComponent(this); + } + @Override public void paintComponent(Graphics g) { super.paintComponent(g); @@ -338,6 +343,35 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { } selection.drawSelection(g); } + + @Override + public String getToolTipText(MouseEvent event) { + Mote[] motes = findMotesAtPosition(event.getX(), event.getY()); + if (motes == null) { + return null; + } + File file = motes[0].getType().getContikiSourceFile(); + if (file == null) { + file = motes[0].getType().getContikiFirmwareFile(); + } + String fileName; + if (file == null) { + fileName = ""; + } else { + fileName = file.getName(); + } + StringBuilder sb = new StringBuilder() + .append("") + .append("") + .append("") + .append("
Type:") + .append(motes[0].getType().getIdentifier()) + .append("
Runs:") + .append(fileName) + .append("
"); + return sb.toString(); + } + }; canvas.setBackground(Color.WHITE); viewportTransform = new AffineTransform();