added simple filtering support
This commit is contained in:
parent
b863ef4c92
commit
d59ef75617
1 changed files with 56 additions and 6 deletions
|
@ -26,15 +26,19 @@
|
||||||
* 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: LogListener.java,v 1.2 2006/10/23 16:14:02 fros4943 Exp $
|
* $Id: LogListener.java,v 1.3 2006/12/07 14:26:48 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.plugins;
|
package se.sics.cooja.plugins;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.jdom.Element;
|
||||||
|
|
||||||
import se.sics.cooja.*;
|
import se.sics.cooja.*;
|
||||||
import se.sics.cooja.interfaces.Log;
|
import se.sics.cooja.interfaces.Log;
|
||||||
|
@ -57,6 +61,9 @@ public class LogListener extends VisPlugin {
|
||||||
private Observer logObserver;
|
private Observer logObserver;
|
||||||
private Simulation simulation;
|
private Simulation simulation;
|
||||||
|
|
||||||
|
private String filterText = null;
|
||||||
|
private JTextField filterTextField = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new simulation control panel.
|
* Create a new simulation control panel.
|
||||||
*
|
*
|
||||||
|
@ -73,16 +80,20 @@ public class LogListener extends VisPlugin {
|
||||||
if (logTextArea == null)
|
if (logTextArea == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
logTextArea.append("\n");
|
|
||||||
|
|
||||||
Mote mote = (Mote) obj;
|
Mote mote = (Mote) obj;
|
||||||
Log moteLogInterface = (Log) obs;
|
Log moteLogInterface = (Log) obs;
|
||||||
String outputString = "TIME:" + simulation.getSimulationTime() + "\t";
|
String outputString = "TIME:" + simulation.getSimulationTime() + "\t";
|
||||||
if (mote != null && mote.getInterfaces().getMoteID() != null) {
|
if (mote != null && mote.getInterfaces().getMoteID() != null) {
|
||||||
outputString = outputString.concat("ID:" + mote.getInterfaces().getMoteID().getMoteID() + "\t");
|
outputString = outputString.concat("ID:" + mote.getInterfaces().getMoteID().getMoteID() + "\t");
|
||||||
}
|
}
|
||||||
|
// Match against filter (if any)
|
||||||
|
if (filterText != null && !filterText.equals("") &&
|
||||||
|
!moteLogInterface.getLastLogMessages().contains(filterText))
|
||||||
|
return;
|
||||||
|
|
||||||
outputString = outputString.concat(moteLogInterface.getLastLogMessages());
|
outputString = outputString.concat(moteLogInterface.getLastLogMessages());
|
||||||
|
|
||||||
|
logTextArea.append("\n");
|
||||||
logTextArea.append(outputString);
|
logTextArea.append(outputString);
|
||||||
logTextArea.setCaretPosition(logTextArea.getDocument().getLength());
|
logTextArea.setCaretPosition(logTextArea.getDocument().getLength());
|
||||||
}
|
}
|
||||||
|
@ -102,7 +113,20 @@ public class LogListener extends VisPlugin {
|
||||||
logTextArea.setEditable(false);
|
logTextArea.setEditable(false);
|
||||||
logTextArea.setCursor(null);
|
logTextArea.setCursor(null);
|
||||||
|
|
||||||
setContentPane(new JScrollPane(logTextArea));
|
JPanel filterPanel = new JPanel();
|
||||||
|
filterPanel.setLayout(new BoxLayout(filterPanel, BoxLayout.X_AXIS));
|
||||||
|
filterTextField = new JTextField("");
|
||||||
|
filterPanel.add(new JLabel("Filter on string: "));
|
||||||
|
filterPanel.add(filterTextField);
|
||||||
|
filterTextField.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
filterText = filterTextField.getText();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
getContentPane().add(BorderLayout.CENTER, new JScrollPane(logTextArea));
|
||||||
|
getContentPane().add(BorderLayout.SOUTH, new JScrollPane(filterPanel));
|
||||||
|
|
||||||
setTitle("Log Listener - Listening on " + nrLogs + " mote logs");
|
setTitle("Log Listener - Listening on " + nrLogs + " mote logs");
|
||||||
pack();
|
pack();
|
||||||
|
|
||||||
|
@ -122,4 +146,30 @@ public class LogListener extends VisPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<Element> getConfigXML() {
|
||||||
|
Vector<Element> config = new Vector<Element>();
|
||||||
|
|
||||||
|
Element element;
|
||||||
|
|
||||||
|
// Selected variable name
|
||||||
|
element = new Element("filter");
|
||||||
|
element.setText(filterText);
|
||||||
|
config.add(element);
|
||||||
|
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean setConfigXML(Collection<Element> configXML) {
|
||||||
|
|
||||||
|
for (Element element : configXML) {
|
||||||
|
if (element.getName().equals("filter")) {
|
||||||
|
filterText = element.getText();
|
||||||
|
filterTextField.setText(filterText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue