removed log data string caches (reduces memory usage), added mote highlighting by clicking on Mote column
This commit is contained in:
parent
9a4d17fe7c
commit
8c3f4859b4
1 changed files with 54 additions and 42 deletions
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* 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;
|
||||
|
@ -204,13 +204,13 @@ public class LogListener extends VisPlugin {
|
|||
public Object getValueAt(int row, int col) {
|
||||
LogData log = logs.get(row);
|
||||
if (col == COLUMN_TIME) {
|
||||
return log.strTime;
|
||||
return log.getTime();
|
||||
} else if (col == COLUMN_FROM) {
|
||||
return log.strID;
|
||||
return log.getID();
|
||||
} else if (col == COLUMN_DATA) {
|
||||
return log.ev.getMessage();
|
||||
} else if (col == COLUMN_CONCAT) {
|
||||
return log.strID + ' ' + log.ev.getMessage();
|
||||
return log.getID() + ' ' + log.ev.getMessage();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -266,7 +266,7 @@ public class LogListener extends VisPlugin {
|
|||
|
||||
if (backgroundColors) {
|
||||
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') {
|
||||
setBackground(BG_COLORS[last - '0']);
|
||||
} else {
|
||||
|
@ -310,7 +310,23 @@ public class LogListener extends VisPlugin {
|
|||
return;
|
||||
}
|
||||
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) {
|
||||
if (!hasHours && historyEv.getTime() > TIME_HOUR) {
|
||||
hasHours = true;
|
||||
recacheAllTimeStrings();
|
||||
repaintTimeColumn();
|
||||
}
|
||||
LogData data = new LogData(historyEv);
|
||||
logs.add(data);
|
||||
|
@ -389,7 +405,7 @@ public class LogListener extends VisPlugin {
|
|||
/* Display new log output */
|
||||
if (!hasHours && ev.getTime() > TIME_HOUR) {
|
||||
hasHours = true;
|
||||
recacheAllTimeStrings();
|
||||
repaintTimeColumn();
|
||||
}
|
||||
logUpdateAggregator.add(new LogData(ev));
|
||||
}
|
||||
|
@ -440,10 +456,7 @@ public class LogListener extends VisPlugin {
|
|||
setLocation(0, gui.getDesktopPane().getHeight() - 300);
|
||||
}
|
||||
|
||||
private void recacheAllTimeStrings() {
|
||||
for (LogData ld: logs) {
|
||||
ld.recacheTimeString();
|
||||
}
|
||||
private void repaintTimeColumn() {
|
||||
logTable.getColumnModel().getColumn(COLUMN_TIME).setHeaderValue(
|
||||
logTable.getModel().getColumnName(COLUMN_TIME));
|
||||
repaint();
|
||||
|
@ -494,7 +507,7 @@ public class LogListener extends VisPlugin {
|
|||
colorCheckbox.setSelected(true);
|
||||
} else if ("formatted_time".equals(name)) {
|
||||
formatTimeString = true;
|
||||
recacheAllTimeStrings();
|
||||
repaintTimeColumn();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -544,34 +557,33 @@ public class LogListener extends VisPlugin {
|
|||
|
||||
private class LogData {
|
||||
public final LogOutputEvent ev;
|
||||
public final String strID; /* cached value */
|
||||
public String strTime; /* cached value */
|
||||
|
||||
public LogData(LogOutputEvent ev) {
|
||||
this.ev = ev;
|
||||
this.strID = "ID:" + ev.getMote().getID();
|
||||
recacheTimeString();
|
||||
}
|
||||
|
||||
public void recacheTimeString() {
|
||||
if (formatTimeString) {
|
||||
long t = 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) {
|
||||
this.strTime = String.format("%d:%02d:%02d.%03d", h,m,s,ms);
|
||||
} else {
|
||||
this.strTime = String.format("%02d:%02d.%03d", m,s,ms);
|
||||
}
|
||||
} else {
|
||||
this.strTime = "" + ev.getTime() / Simulation.MILLISECOND;
|
||||
}
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return "ID:" + ev.getMote().getID();
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
if (formatTimeString) {
|
||||
long t = 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 {
|
||||
return "" + ev.getTime() / Simulation.MILLISECOND;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Action saveAction = new AbstractAction("Save to file") {
|
||||
|
@ -608,8 +620,8 @@ public class LogListener extends VisPlugin {
|
|||
PrintWriter outStream = new PrintWriter(new FileWriter(saveFile));
|
||||
for(LogData data : logs) {
|
||||
outStream.println(
|
||||
data.strTime + "\t" +
|
||||
data.strID + "\t" +
|
||||
data.getTime() + "\t" +
|
||||
data.getID() + "\t" +
|
||||
data.ev.getMessage());
|
||||
}
|
||||
outStream.close();
|
||||
|
@ -710,9 +722,9 @@ public class LogListener extends VisPlugin {
|
|||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(LogData data : logs) {
|
||||
sb.append(data.strTime);
|
||||
sb.append(data.getTime());
|
||||
sb.append("\t");
|
||||
sb.append(data.strID);
|
||||
sb.append(data.getID());
|
||||
sb.append("\t");
|
||||
sb.append(data.ev.getMessage());
|
||||
sb.append("\n");
|
||||
|
|
Loading…
Reference in a new issue