From 87733c176a3bc8289c1100b20e60a275f85d8940 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Thu, 11 Mar 2010 22:11:10 +0000 Subject: [PATCH] added notes plugin, useful for storing simulation notes in the config --- tools/cooja/config/cooja_default.config | 2 +- .../java/se/sics/cooja/plugins/Notes.java | 154 ++++++++++++++++++ 2 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 tools/cooja/java/se/sics/cooja/plugins/Notes.java diff --git a/tools/cooja/config/cooja_default.config b/tools/cooja/config/cooja_default.config index bd57c6a85..8dc6a88a1 100644 --- a/tools/cooja/config/cooja_default.config +++ b/tools/cooja/config/cooja_default.config @@ -3,7 +3,7 @@ se.sics.cooja.contikimote.interfaces.ContikiRadio.RADIO_TRANSMISSION_RATE_kbps = se.sics.cooja.contikimote.ContikiMoteType.MOTE_INTERFACES = se.sics.cooja.interfaces.Position se.sics.cooja.interfaces.Battery se.sics.cooja.contikimote.interfaces.ContikiVib se.sics.cooja.contikimote.interfaces.ContikiMoteID se.sics.cooja.contikimote.interfaces.ContikiRS232 se.sics.cooja.contikimote.interfaces.ContikiBeeper se.sics.cooja.interfaces.RimeAddress se.sics.cooja.contikimote.interfaces.ContikiIPAddress se.sics.cooja.contikimote.interfaces.ContikiRadio se.sics.cooja.contikimote.interfaces.ContikiButton se.sics.cooja.contikimote.interfaces.ContikiPIR se.sics.cooja.contikimote.interfaces.ContikiClock se.sics.cooja.contikimote.interfaces.ContikiLED se.sics.cooja.contikimote.interfaces.ContikiCFS se.sics.cooja.interfaces.Mote2MoteRelations se.sics.cooja.interfaces.MoteAttributes se.sics.cooja.contikimote.ContikiMoteType.C_SOURCES = se.sics.cooja.GUI.MOTETYPES = se.sics.cooja.motes.ImportAppMoteType se.sics.cooja.motes.DisturberMoteType se.sics.cooja.contikimote.ContikiMoteType -se.sics.cooja.GUI.PLUGINS = se.sics.cooja.plugins.Visualizer se.sics.cooja.plugins.LogListener se.sics.cooja.plugins.TimeLine se.sics.cooja.plugins.MoteInformation se.sics.cooja.plugins.MoteInterfaceViewer se.sics.cooja.plugins.VariableWatcher se.sics.cooja.plugins.EventListener se.sics.cooja.plugins.RadioLogger se.sics.cooja.plugins.ScriptRunner +se.sics.cooja.GUI.PLUGINS = se.sics.cooja.plugins.Visualizer se.sics.cooja.plugins.LogListener se.sics.cooja.plugins.TimeLine se.sics.cooja.plugins.MoteInformation se.sics.cooja.plugins.MoteInterfaceViewer se.sics.cooja.plugins.VariableWatcher se.sics.cooja.plugins.EventListener se.sics.cooja.plugins.RadioLogger se.sics.cooja.plugins.ScriptRunner se.sics.cooja.plugins.Notes se.sics.cooja.GUI.IP_DISTRIBUTORS = se.sics.cooja.ipdistributors.RandomIPDistributor se.sics.cooja.ipdistributors.SpatialIPDistributor se.sics.cooja.ipdistributors.IdIPDistributor se.sics.cooja.GUI.POSITIONERS = se.sics.cooja.positioners.RandomPositioner se.sics.cooja.positioners.LinearPositioner se.sics.cooja.positioners.EllipsePositioner se.sics.cooja.positioners.ManualPositioner se.sics.cooja.GUI.RADIOMEDIUMS = se.sics.cooja.radiomediums.UDGM se.sics.cooja.radiomediums.DirectedGraphMedium se.sics.cooja.radiomediums.SilentRadioMedium diff --git a/tools/cooja/java/se/sics/cooja/plugins/Notes.java b/tools/cooja/java/se/sics/cooja/plugins/Notes.java new file mode 100644 index 000000000..9c737969a --- /dev/null +++ b/tools/cooja/java/se/sics/cooja/plugins/Notes.java @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2010, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: Notes.java,v 1.1 2010/03/11 22:11:10 fros4943 Exp $ + */ + +package se.sics.cooja.plugins; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.ArrayList; +import java.util.Collection; + +import javax.swing.JMenuItem; +import javax.swing.JPopupMenu; +import javax.swing.JTextArea; +import javax.swing.SwingUtilities; +import javax.swing.plaf.basic.BasicInternalFrameUI; + +import org.apache.log4j.Logger; +import org.jdom.Element; + +import se.sics.cooja.ClassDescription; +import se.sics.cooja.GUI; +import se.sics.cooja.PluginType; +import se.sics.cooja.Simulation; +import se.sics.cooja.VisPlugin; + +@ClassDescription("Notes") +@PluginType(PluginType.SIM_PLUGIN) +public class Notes extends VisPlugin { + private static final long serialVersionUID = 1L; + private static Logger logger = Logger.getLogger(Visualizer.class); + + private JTextArea notes = new JTextArea("enter simulation notes here"); + private boolean decorationsVisible = true; + + public Notes(Simulation simulation, GUI gui) { + super("Notes", gui); + + add(BorderLayout.CENTER, notes); + + /* Popup menu */ + if (Notes.this.getUI() instanceof BasicInternalFrameUI) { + final JPopupMenu popup = new JPopupMenu(); + JMenuItem headerMenuItem = new JMenuItem("Toggle decorations"); + headerMenuItem.setEnabled(true); + headerMenuItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + setDecorationsVisible(!decorationsVisible); + } + }); + popup.add(headerMenuItem); + notes.addMouseListener(new MouseAdapter() { + public void mousePressed(MouseEvent e) { + if (e.isPopupTrigger()) { + popup.show(Notes.this, e.getX(), e.getY()); + } + } + public void mouseReleased(MouseEvent e) { + if (e.isPopupTrigger()) { + popup.show(Notes.this, e.getX(), e.getY()); + } + } + public void mouseClicked(MouseEvent e) { + if (e.isPopupTrigger()) { + popup.show(Notes.this, e.getX(), e.getY()); + } + } + }); + } + + this.setSize(300, 300); + } + + private void setDecorationsVisible(boolean visible) { + if (!(Notes.this.getUI() instanceof BasicInternalFrameUI)) { + return; + } + BasicInternalFrameUI ui = (BasicInternalFrameUI) Notes.this.getUI(); + + if (visible) { + ui.getNorthPane().setPreferredSize(null); + } else { + ui.getNorthPane().setPreferredSize(new Dimension(0,0)); + } + + Notes.this.revalidate(); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + Notes.this.repaint(); + } + }); + + decorationsVisible = visible; + } + + public Collection getConfigXML() { + ArrayList config = new ArrayList(); + Element element; + + element = new Element("notes"); + element.setText(notes.getText()); + config.add(element); + + element = new Element("decorations"); + element.setText("" + decorationsVisible); + config.add(element); + + return config; + } + + public boolean setConfigXML(Collection configXML, boolean visAvailable) { + for (Element element : configXML) { + if (element.getName().equals("notes")) { + notes.setText(element.getText()); + } + if (element.getName().equals("decorations")) { + decorationsVisible = Boolean.parseBoolean(element.getText()); + setDecorationsVisible(decorationsVisible); + } + } + return true; + } +}