Added legend

This commit is contained in:
nifi 2010-10-12 22:26:56 +00:00
parent a5df3e8d00
commit a292ff9fe6

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: MapPanel.java,v 1.4 2010/10/10 22:39:09 nifi Exp $ * $Id: MapPanel.java,v 1.5 2010/10/12 22:26:56 nifi Exp $
* *
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* *
@ -34,8 +34,8 @@
* *
* Authors : Joakim Eriksson, Niclas Finne * Authors : Joakim Eriksson, Niclas Finne
* Created : 3 jul 2008 * Created : 3 jul 2008
* Updated : $Date: 2010/10/10 22:39:09 $ * Updated : $Date: 2010/10/12 22:26:56 $
* $Revision: 1.4 $ * $Revision: 1.5 $
*/ */
package se.sics.contiki.collect.gui; package se.sics.contiki.collect.gui;
@ -428,18 +428,33 @@ public class MapPanel extends JPanel implements Configurable, Visualizer, Action
@Override @Override
protected void paintComponent(Graphics g) { protected void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g; Graphics2D g2d = (Graphics2D) g;
FontMetrics fm = g.getFontMetrics();
int fnHeight = fm.getHeight();
int fnDescent = fm.getDescent();
int width = getWidth();
int height = getHeight();
g.setColor(getBackground()); g.setColor(getBackground());
g.fillRect(0, 0, getWidth(), getHeight()); g.fillRect(0, 0, width, height);
if (showBackground && isMap) { if (showBackground && isMap) {
mapImage.paintIcon(this, g, 0, 0); mapImage.paintIcon(this, g, 0, 0);
} }
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON); RenderingHints.VALUE_ANTIALIAS_ON);
// Display legend
if (!hideNetwork) {
int legendWidth = fm.stringWidth("ETX");
g.setColor(Color.black);
g.drawString("ETX", width - legendWidth - 10, 10 + fnHeight - fnDescent);
g.drawRect(width - legendWidth - 30, 8, legendWidth + 24, fnHeight + 4);
g.setColor(LINK_COLOR);
g2d.drawLine(width - legendWidth - 25, 10 + fnHeight / 2,
width - legendWidth - 15, 10 + fnHeight / 2);
}
for (MapNode n : getNodeList()) { for (MapNode n : getNodeList()) {
if (!isMap || !hideNetwork) { if (!isMap || !hideNetwork) {
FontMetrics fm = g.getFontMetrics();
int fnHeight = fm.getHeight();
int fnDescent = fm.getDescent();
g.setColor(LINK_COLOR); g.setColor(LINK_COLOR);
for (int j = 0, mu = n.node.getLinkCount(); j < mu; j++) { for (int j = 0, mu = n.node.getLinkCount(); j < mu; j++) {
Link link = n.node.getLink(j); Link link = n.node.getLink(j);
@ -461,7 +476,9 @@ public class MapPanel extends JPanel implements Configurable, Visualizer, Action
if (yn2 < yn1) { if (yn2 < yn1) {
dy += fnHeight - fnDescent; dy += fnHeight - fnDescent;
} }
g.drawString("ETX:" + (((int)(link.getETX() * 100 + 0.5)) / 100.0), dx, dy); g.drawString(
Double.toString(((int) (link.getETX() * 100 + 0.5)) / 100.0),
dx, dy);
} }
} }
} }