minor changes: methods that allow other plugins, e.g. the timeline, to learn about the currently used mote

output filter, make mote-specific coloring on by default
This commit is contained in:
Fredrik Osterlind 2013-08-14 12:28:18 +02:00
parent 37ebe133e9
commit bda04947e7

View File

@ -108,6 +108,19 @@ public class LogListener extends VisPlugin implements HasQuickHelp {
private static final long serialVersionUID = 3294595371354857261L; private static final long serialVersionUID = 3294595371354857261L;
private static Logger logger = Logger.getLogger(LogListener.class); private static Logger logger = Logger.getLogger(LogListener.class);
private final Color[] BG_COLORS = new Color[] {
new Color(200, 200, 200),
new Color(200, 200, 255),
new Color(200, 255, 200),
new Color(200, 255, 255),
new Color(255, 200, 200),
new Color(255, 255, 200),
new Color(255, 255, 255),
new Color(255, 220, 200),
new Color(220, 255, 220),
new Color(255, 200, 255),
};
private final static int COLUMN_TIME = 0; private final static int COLUMN_TIME = 0;
private final static int COLUMN_FROM = 1; private final static int COLUMN_FROM = 1;
private final static int COLUMN_DATA = 2; private final static int COLUMN_DATA = 2;
@ -119,11 +132,11 @@ public class LogListener extends VisPlugin implements HasQuickHelp {
"#" "#"
}; };
private static final long TIME_SECOND = 1000*Simulation.MILLISECOND; public static final long TIME_SECOND = 1000*Simulation.MILLISECOND;
private static final long TIME_MINUTE = 60*TIME_SECOND; public static final long TIME_MINUTE = 60*TIME_SECOND;
private static final long TIME_HOUR = 60*TIME_MINUTE; public static final long TIME_HOUR = 60*TIME_MINUTE;
private boolean formatTimeString = false; private boolean formatTimeString = true;
private boolean hasHours = false; private boolean hasHours = false;
private final JTable logTable; private final JTable logTable;
@ -140,7 +153,7 @@ public class LogListener extends VisPlugin implements HasQuickHelp {
private LogOutputListener logOutputListener; private LogOutputListener logOutputListener;
private boolean backgroundColors = false; private boolean backgroundColors = true;
private JCheckBoxMenuItem colorCheckbox; private JCheckBoxMenuItem colorCheckbox;
private boolean inverseFilter = false; private boolean inverseFilter = false;
@ -219,7 +232,7 @@ public class LogListener extends VisPlugin implements HasQuickHelp {
appendCheckBox = new JCheckBoxMenuItem(appendAction); appendCheckBox = new JCheckBoxMenuItem(appendAction);
fileMenu.add(appendCheckBox); fileMenu.add(appendCheckBox);
colorCheckbox = new JCheckBoxMenuItem("Mote-specific coloring"); colorCheckbox = new JCheckBoxMenuItem("Mote-specific coloring", backgroundColors);
showMenu.add(colorCheckbox); showMenu.add(colorCheckbox);
colorCheckbox.addActionListener(new ActionListener() { colorCheckbox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@ -309,18 +322,6 @@ public class LogListener extends VisPlugin implements HasQuickHelp {
}; };
DefaultTableCellRenderer cellRenderer = new DefaultTableCellRenderer() { DefaultTableCellRenderer cellRenderer = new DefaultTableCellRenderer() {
private static final long serialVersionUID = -340743275865216182L; private static final long serialVersionUID = -340743275865216182L;
private final Color[] BG_COLORS = new Color[] {
new Color(200, 200, 200),
new Color(200, 200, 255),
new Color(200, 255, 200),
new Color(200, 255, 255),
new Color(255, 200, 200),
new Color(255, 255, 200),
new Color(255, 255, 255),
new Color(255, 220, 200),
new Color(220, 255, 220),
new Color(255, 200, 255),
};
public Component getTableCellRendererComponent(JTable table, public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row, Object value, boolean isSelected, boolean hasFocus, int row,
int column) { int column) {
@ -331,12 +332,8 @@ public class LogListener extends VisPlugin implements HasQuickHelp {
if (backgroundColors) { if (backgroundColors) {
LogData d = logs.get(logTable.getRowSorter().convertRowIndexToModel(row)); LogData d = logs.get(logTable.getRowSorter().convertRowIndexToModel(row));
char last = d.getID().charAt(d.getID().length()-1); int color = (10+d.ev.getMote().getID())%10;
if (last >= '0' && last <= '9') { setBackground(BG_COLORS[color]);
setBackground(BG_COLORS[last - '0']);
} else {
setBackground(null);
}
} else { } else {
setBackground(null); setBackground(null);
} }
@ -674,7 +671,7 @@ public class LogListener extends VisPlugin implements HasQuickHelp {
} }
RowFilter<Object, Object> wrapped = new RowFilter<Object, Object>() { RowFilter<Object, Object> wrapped = new RowFilter<Object, Object>() {
public boolean include(RowFilter.Entry<? extends Object, ? extends Object> entry) { public boolean include(RowFilter.Entry<? extends Object, ? extends Object> entry) {
if (regexp != null) { if (regexp != null) {
boolean pass = regexp.include(entry); boolean pass = regexp.include(entry);
if (inverseFilter && pass) { if (inverseFilter && pass) {
return false; return false;
@ -698,6 +695,7 @@ public class LogListener extends VisPlugin implements HasQuickHelp {
filterTextField.setBackground(Color.red); filterTextField.setBackground(Color.red);
filterTextField.setToolTipText("Syntax error in regular expression: " + e.getMessage()); filterTextField.setToolTipText("Syntax error in regular expression: " + e.getMessage());
} }
simulation.getGUI().getDesktopPane().repaint();
} }
public void trySelectTime(final long time) { public void trySelectTime(final long time) {
@ -732,19 +730,7 @@ public class LogListener extends VisPlugin implements HasQuickHelp {
public String getTime() { public String getTime() {
if (formatTimeString) { if (formatTimeString) {
long t = ev.getTime(); return getFormattedTime(ev.getTime());
long h = (t / TIME_HOUR);
t -= (t / TIME_HOUR)*TIME_HOUR;
long m = (t / TIME_MINUTE);
t -= (t / TIME_MINUTE)*TIME_MINUTE;
long s = (t / TIME_SECOND);
t -= (t / TIME_SECOND)*TIME_SECOND;
long ms = t / Simulation.MILLISECOND;
if (hasHours) {
return String.format("%d:%02d:%02d.%03d", h,m,s,ms);
} else {
return String.format("%02d:%02d.%03d", m,s,ms);
}
} else { } else {
return "" + ev.getTime() / Simulation.MILLISECOND; return "" + ev.getTime() / Simulation.MILLISECOND;
} }
@ -1031,4 +1017,60 @@ public class LogListener extends VisPlugin implements HasQuickHelp {
"<br><br>^ID:[2-5] Contiki<br><i>logs from motes 2 to 5 starting with 'Contiki'</i>"; "<br><br>^ID:[2-5] Contiki<br><i>logs from motes 2 to 5 starting with 'Contiki'</i>";
} }
/* Experimental feature: let other plugins learn if a log output would be filtered or not */
public boolean filterWouldAccept(LogOutputEvent ev) {
RowFilter<? super TableModel, ? super Integer> rowFilter = logFilter.getRowFilter();
if (rowFilter == null) {
/* No filter */
return true;
}
final LogData ld = new LogData(ev);
RowFilter.Entry<? extends TableModel, ? extends Integer> entry = new RowFilter.Entry<TableModel, Integer>() {
public TableModel getModel() {
return model;
}
public int getValueCount() {
return model.getColumnCount();
}
public Object getValue(int index) {
if (index == COLUMN_TIME) {
return ld.getTime();
} else if (index == COLUMN_FROM) {
return ld.getID();
} else if (index == COLUMN_DATA) {
return ld.ev.getMessage();
} else if (index == COLUMN_CONCAT) {
return ld.getID() + ' ' + ld.ev.getMessage();
}
return null;
}
public Integer getIdentifier() {
return null;
}
};
boolean show;
show = rowFilter.include(entry);
return show;
}
public Color getColorOfEntry(LogOutputEvent logEvent) {
int color = (10+logEvent.getMote().getID())%10;
return BG_COLORS[color];
}
public static String getFormattedTime(long t) {
long h = (t / LogListener.TIME_HOUR);
t -= (t / TIME_HOUR)*TIME_HOUR;
long m = (t / TIME_MINUTE);
t -= (t / TIME_MINUTE)*TIME_MINUTE;
long s = (t / TIME_SECOND);
t -= (t / TIME_SECOND)*TIME_SECOND;
long ms = t / Simulation.MILLISECOND;
if (h > 0) {
return String.format("%d:%02d:%02d.%03d", h,m,s,ms);
} else {
return String.format("%02d:%02d.%03d", m,s,ms);
}
}
} }