mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-22 10:30:13 +00:00
updated example plugin
This commit is contained in:
parent
9e928313cb
commit
59ed193e58
23
tools/cooja/examples/project_new_plugin/build.xml
Normal file
23
tools/cooja/examples/project_new_plugin/build.xml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<project name="Plugin example" default="compile" basedir=".">
|
||||||
|
<property name="src" location="java"/>
|
||||||
|
<property name="build" location="java"/>
|
||||||
|
|
||||||
|
<property name="cooja" location="../.."/>
|
||||||
|
<property name="cooja_jar" value="${cooja}/dist/cooja.jar"/>
|
||||||
|
|
||||||
|
<target name="init">
|
||||||
|
<tstamp/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="compile" depends="init">
|
||||||
|
<mkdir dir="${build}"/>
|
||||||
|
<javac srcdir="${src}" destdir="${build}" debug="on">
|
||||||
|
<classpath>
|
||||||
|
<pathelement location="${cooja_jar}"/>
|
||||||
|
</classpath>
|
||||||
|
</javac>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
</project>
|
@ -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: MyDummyPlugin.java,v 1.1 2007/03/23 23:33:55 fros4943 Exp $
|
* $Id: MyDummyPlugin.java,v 1.2 2008/10/28 16:22:35 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
@ -37,28 +37,28 @@ import org.apache.log4j.Logger;
|
|||||||
import se.sics.cooja.*;
|
import se.sics.cooja.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is an simple example plugin.
|
* This is a simple example plugin.
|
||||||
* It is a simulation plugin, which means that it depends on a single simulation.
|
* It is a simulation plugin (SIM_PLUGIN): it depends on a single simulation.
|
||||||
*
|
*
|
||||||
* @author Fredrik Osterlind
|
* @author Fredrik Österlind
|
||||||
*/
|
*/
|
||||||
@ClassDescription("Dummy Plugin")
|
@ClassDescription("Dummy Plugin") /* Description shown in menu */
|
||||||
@PluginType(PluginType.SIM_PLUGIN)
|
@PluginType(PluginType.SIM_PLUGIN)
|
||||||
public class MyDummyPlugin extends VisPlugin {
|
public class MyDummyPlugin extends VisPlugin {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private static Logger logger = Logger.getLogger(MyDummyPlugin.class);
|
private static Logger logger = Logger.getLogger(MyDummyPlugin.class);
|
||||||
private Simulation mySimulation;
|
private Simulation mySimulation;
|
||||||
private Observer tickObserver;
|
private Observer tickObserver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new dummy plugin.
|
* Creates a new dummy plugin.
|
||||||
*
|
*
|
||||||
* @param simulationToVisualize Simulation to visualize
|
* @param simulationToVisualize Simulation to visualize
|
||||||
*/
|
*/
|
||||||
public MyDummyPlugin(Simulation simulationToVisualize, GUI gui) {
|
public MyDummyPlugin(Simulation simulationToVisualize, GUI gui) {
|
||||||
super("This is my title!", gui);
|
super("This is my title!", gui);
|
||||||
mySimulation = simulationToVisualize;
|
mySimulation = simulationToVisualize;
|
||||||
|
|
||||||
// Create and add a button
|
// Create and add a button
|
||||||
JButton button = new JButton("dummy button");
|
JButton button = new JButton("dummy button");
|
||||||
button.addActionListener(new ActionListener() {
|
button.addActionListener(new ActionListener() {
|
||||||
@ -67,27 +67,26 @@ public class MyDummyPlugin extends VisPlugin {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
add(button);
|
add(button);
|
||||||
|
|
||||||
// Register as tickobserver
|
// Register as tickobserver
|
||||||
mySimulation.addTickObserver(tickObserver = new Observer() {
|
mySimulation.addTickObserver(tickObserver = new Observer() {
|
||||||
public void update(Observable obs, Object obj) {
|
public void update(Observable obs, Object obj) {
|
||||||
logger.info("Another tick loop completed - simulation time is now:\t" + mySimulation.getSimulationTime());
|
logger.info("Another tick loop completed - simulation time is now:\t" + mySimulation.getSimulationTime());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
setSize(300,100); // Set an initial size of this plugin
|
setSize(300,100); // Set an initial size of this plugin
|
||||||
|
|
||||||
// Tries to select this plugin
|
// Tries to select this plugin
|
||||||
try {
|
try {
|
||||||
setSelected(true);
|
setSelected(true);
|
||||||
} catch (java.beans.PropertyVetoException e) {
|
} catch (java.beans.PropertyVetoException e) {
|
||||||
// Could not select
|
// Could not select
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closePlugin() {
|
public void closePlugin() {
|
||||||
mySimulation.deleteTickObserver(tickObserver);
|
mySimulation.deleteTickObserver(tickObserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user