From d99708ba080b067f81a8127f5fbf1a02290ca3f6 Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Fri, 31 Oct 2014 00:30:57 +0100 Subject: [PATCH] Button: Move common interface visualization to Button class The implementation of a simple JPanel with a JButton was only code duplication accross the several button implementations. --- .../cooja/mspmote/interfaces/ESBButton.java | 22 ----------------- .../cooja/mspmote/interfaces/MspButton.java | 24 ------------------- .../cooja/mspmote/interfaces/SkyButton.java | 21 ---------------- .../contikimote/interfaces/ContikiButton.java | 20 ---------------- .../contikios/cooja/interfaces/Button.java | 23 ++++++++++++++++++ 5 files changed, 23 insertions(+), 87 deletions(-) diff --git a/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/ESBButton.java b/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/ESBButton.java index c722e74eb..def3d207e 100644 --- a/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/ESBButton.java +++ b/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/ESBButton.java @@ -30,11 +30,7 @@ package org.contikios.cooja.mspmote.interfaces; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.util.Collection; -import javax.swing.JButton; -import javax.swing.JPanel; import org.apache.log4j.Logger; import org.jdom.Element; @@ -76,24 +72,6 @@ public class ESBButton extends Button { return false; } - public JPanel getInterfaceVisualizer() { - JPanel panel = new JPanel(); - final JButton clickButton = new JButton("Click button"); - - panel.add(clickButton); - - clickButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - clickButton(); - } - }); - - return panel; - } - - public void releaseInterfaceVisualizer(JPanel panel) { - } - public Collection getConfigXML() { return null; } diff --git a/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/MspButton.java b/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/MspButton.java index 5136485e7..28d4f32b2 100644 --- a/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/MspButton.java +++ b/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/MspButton.java @@ -28,11 +28,7 @@ */ package org.contikios.cooja.mspmote.interfaces; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.util.Collection; -import javax.swing.JButton; -import javax.swing.JPanel; import org.jdom.Element; import org.contikios.cooja.ClassDescription; import org.contikios.cooja.Mote; @@ -87,26 +83,6 @@ public class MspButton extends Button { return button.isPressed(); } - @Override - public JPanel getInterfaceVisualizer() { - final JPanel panel = new JPanel(); - final JButton clickButton = new JButton("Click button"); - - panel.add(clickButton); - - clickButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - clickButton(); - } - }); - - return panel; - } - - @Override - public void releaseInterfaceVisualizer(JPanel panel) { - } - @Override public Collection getConfigXML() { return null; diff --git a/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/SkyButton.java b/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/SkyButton.java index 6b1711b63..04cd767b5 100644 --- a/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/SkyButton.java +++ b/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/SkyButton.java @@ -30,12 +30,8 @@ package org.contikios.cooja.mspmote.interfaces; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.util.Collection; -import javax.swing.JButton; -import javax.swing.JPanel; import org.apache.log4j.Logger; import org.jdom.Element; @@ -103,23 +99,6 @@ public class SkyButton extends Button { return false; } - public JPanel getInterfaceVisualizer() { - JPanel panel = new JPanel(); - final JButton clickButton = new JButton("Click button"); - - panel.add(clickButton); - - clickButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - clickButton(); - } - }); - - return panel; - } - - public void releaseInterfaceVisualizer(JPanel panel) { - } public Collection getConfigXML() { return null; diff --git a/tools/cooja/java/org/contikios/cooja/contikimote/interfaces/ContikiButton.java b/tools/cooja/java/org/contikios/cooja/contikimote/interfaces/ContikiButton.java index 852383a09..f0e9fa359 100644 --- a/tools/cooja/java/org/contikios/cooja/contikimote/interfaces/ContikiButton.java +++ b/tools/cooja/java/org/contikios/cooja/contikimote/interfaces/ContikiButton.java @@ -30,9 +30,7 @@ package org.contikios.cooja.contikimote.interfaces; -import java.awt.event.*; import java.util.Collection; -import javax.swing.*; import org.apache.log4j.Logger; import org.jdom.Element; @@ -164,24 +162,6 @@ public class ContikiButton extends Button implements ContikiMoteInterface { return moteMem.getByteValueOf("simButtonIsDown") == 1; } - public JPanel getInterfaceVisualizer() { - JPanel panel = new JPanel(); - final JButton clickButton = new JButton("Click button"); - - panel.add(clickButton); - - clickButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - clickButton(); - } - }); - - return panel; - } - - public void releaseInterfaceVisualizer(JPanel panel) { - } - public Collection getConfigXML() { return null; } diff --git a/tools/cooja/java/org/contikios/cooja/interfaces/Button.java b/tools/cooja/java/org/contikios/cooja/interfaces/Button.java index 549c5ba65..cb50a16e4 100644 --- a/tools/cooja/java/org/contikios/cooja/interfaces/Button.java +++ b/tools/cooja/java/org/contikios/cooja/interfaces/Button.java @@ -30,6 +30,10 @@ package org.contikios.cooja.interfaces; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JButton; +import javax.swing.JPanel; import org.contikios.cooja.*; /** @@ -62,4 +66,23 @@ public abstract class Button extends MoteInterface { * @return True if button is pressed */ public abstract boolean isPressed(); + + public JPanel getInterfaceVisualizer() { + JPanel panel = new JPanel(); + final JButton clickButton = new JButton("Click button"); + + panel.add(clickButton); + + clickButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + clickButton(); + } + }); + + return panel; + } + + public void releaseInterfaceVisualizer(JPanel panel) { + } + }