removed log data string caches (reduces memory usage), added mote highlighting by clicking on Mote column

This commit is contained in:
fros4943 2010-10-13 08:33:22 +00:00
parent 9a4d17fe7c
commit 8c3f4859b4

View file

@ -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: LogListener.java,v 1.34 2010/10/12 10:56:25 fros4943 Exp $ * $Id: LogListener.java,v 1.35 2010/10/13 08:33:22 fros4943 Exp $
*/ */
package se.sics.cooja.plugins; package se.sics.cooja.plugins;
@ -204,13 +204,13 @@ public class LogListener extends VisPlugin {
public Object getValueAt(int row, int col) { public Object getValueAt(int row, int col) {
LogData log = logs.get(row); LogData log = logs.get(row);
if (col == COLUMN_TIME) { if (col == COLUMN_TIME) {
return log.strTime; return log.getTime();
} else if (col == COLUMN_FROM) { } else if (col == COLUMN_FROM) {
return log.strID; return log.getID();
} else if (col == COLUMN_DATA) { } else if (col == COLUMN_DATA) {
return log.ev.getMessage(); return log.ev.getMessage();
} else if (col == COLUMN_CONCAT) { } else if (col == COLUMN_CONCAT) {
return log.strID + ' ' + log.ev.getMessage(); return log.getID() + ' ' + log.ev.getMessage();
} }
return null; return null;
} }
@ -266,7 +266,7 @@ public class LogListener extends VisPlugin {
if (backgroundColors) { if (backgroundColors) {
LogData d = logs.get(logTable.getRowSorter().convertRowIndexToModel(row)); LogData d = logs.get(logTable.getRowSorter().convertRowIndexToModel(row));
char last = d.strID.charAt(d.strID.length()-1); char last = d.getID().charAt(d.getID().length()-1);
if (last >= '0' && last <= '9') { if (last >= '0' && last <= '9') {
setBackground(BG_COLORS[last - '0']); setBackground(BG_COLORS[last - '0']);
} else { } else {
@ -310,7 +310,23 @@ public class LogListener extends VisPlugin {
return; return;
} }
formatTimeString = !formatTimeString; formatTimeString = !formatTimeString;
recacheAllTimeStrings(); repaintTimeColumn();
}
});
logTable.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int colIndex = logTable.columnAtPoint(e.getPoint());
int columnIndex = logTable.convertColumnIndexToModel(colIndex);
if (columnIndex != COLUMN_FROM) {
return;
}
int rowIndex = logTable.rowAtPoint(e.getPoint());
LogData d = logs.get(logTable.getRowSorter().convertRowIndexToModel(rowIndex));
if (d == null) {
return;
}
simulation.getGUI().signalMoteHighlight(d.ev.getMote());
} }
}); });
@ -352,7 +368,7 @@ public class LogListener extends VisPlugin {
for (LogOutputEvent historyEv: history) { for (LogOutputEvent historyEv: history) {
if (!hasHours && historyEv.getTime() > TIME_HOUR) { if (!hasHours && historyEv.getTime() > TIME_HOUR) {
hasHours = true; hasHours = true;
recacheAllTimeStrings(); repaintTimeColumn();
} }
LogData data = new LogData(historyEv); LogData data = new LogData(historyEv);
logs.add(data); logs.add(data);
@ -389,7 +405,7 @@ public class LogListener extends VisPlugin {
/* Display new log output */ /* Display new log output */
if (!hasHours && ev.getTime() > TIME_HOUR) { if (!hasHours && ev.getTime() > TIME_HOUR) {
hasHours = true; hasHours = true;
recacheAllTimeStrings(); repaintTimeColumn();
} }
logUpdateAggregator.add(new LogData(ev)); logUpdateAggregator.add(new LogData(ev));
} }
@ -440,10 +456,7 @@ public class LogListener extends VisPlugin {
setLocation(0, gui.getDesktopPane().getHeight() - 300); setLocation(0, gui.getDesktopPane().getHeight() - 300);
} }
private void recacheAllTimeStrings() { private void repaintTimeColumn() {
for (LogData ld: logs) {
ld.recacheTimeString();
}
logTable.getColumnModel().getColumn(COLUMN_TIME).setHeaderValue( logTable.getColumnModel().getColumn(COLUMN_TIME).setHeaderValue(
logTable.getModel().getColumnName(COLUMN_TIME)); logTable.getModel().getColumnName(COLUMN_TIME));
repaint(); repaint();
@ -494,7 +507,7 @@ public class LogListener extends VisPlugin {
colorCheckbox.setSelected(true); colorCheckbox.setSelected(true);
} else if ("formatted_time".equals(name)) { } else if ("formatted_time".equals(name)) {
formatTimeString = true; formatTimeString = true;
recacheAllTimeStrings(); repaintTimeColumn();
} }
} }
@ -544,16 +557,15 @@ public class LogListener extends VisPlugin {
private class LogData { private class LogData {
public final LogOutputEvent ev; public final LogOutputEvent ev;
public final String strID; /* cached value */
public String strTime; /* cached value */
public LogData(LogOutputEvent ev) { public LogData(LogOutputEvent ev) {
this.ev = ev; this.ev = ev;
this.strID = "ID:" + ev.getMote().getID();
recacheTimeString();
} }
public void recacheTimeString() { public String getID() {
return "ID:" + ev.getMote().getID();
}
public String getTime() {
if (formatTimeString) { if (formatTimeString) {
long t = ev.getTime(); long t = ev.getTime();
long h = (t / TIME_HOUR); long h = (t / TIME_HOUR);
@ -564,12 +576,12 @@ public class LogListener extends VisPlugin {
t -= (t / TIME_SECOND)*TIME_SECOND; t -= (t / TIME_SECOND)*TIME_SECOND;
long ms = t / Simulation.MILLISECOND; long ms = t / Simulation.MILLISECOND;
if (hasHours) { if (hasHours) {
this.strTime = String.format("%d:%02d:%02d.%03d", h,m,s,ms); return String.format("%d:%02d:%02d.%03d", h,m,s,ms);
} else { } else {
this.strTime = String.format("%02d:%02d.%03d", m,s,ms); return String.format("%02d:%02d.%03d", m,s,ms);
} }
} else { } else {
this.strTime = "" + ev.getTime() / Simulation.MILLISECOND; return "" + ev.getTime() / Simulation.MILLISECOND;
} }
} }
} }
@ -608,8 +620,8 @@ public class LogListener extends VisPlugin {
PrintWriter outStream = new PrintWriter(new FileWriter(saveFile)); PrintWriter outStream = new PrintWriter(new FileWriter(saveFile));
for(LogData data : logs) { for(LogData data : logs) {
outStream.println( outStream.println(
data.strTime + "\t" + data.getTime() + "\t" +
data.strID + "\t" + data.getID() + "\t" +
data.ev.getMessage()); data.ev.getMessage());
} }
outStream.close(); outStream.close();
@ -710,9 +722,9 @@ public class LogListener extends VisPlugin {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for(LogData data : logs) { for(LogData data : logs) {
sb.append(data.strTime); sb.append(data.getTime());
sb.append("\t"); sb.append("\t");
sb.append(data.strID); sb.append(data.getID());
sb.append("\t"); sb.append("\t");
sb.append(data.ev.getMessage()); sb.append(data.ev.getMessage());
sb.append("\n"); sb.append("\n");