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.
This commit is contained in:
Enrico Joerns 2014-10-31 00:30:57 +01:00
parent 7c55290c32
commit d99708ba08
5 changed files with 23 additions and 87 deletions

View file

@ -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<Element> getConfigXML() {
return null;
}

View file

@ -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<Element> getConfigXML() {
return null;

View file

@ -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<Element> getConfigXML() {
return null;

View file

@ -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<Element> getConfigXML() {
return null;
}

View file

@ -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) {
}
}