nl.nn.testtool.echo2.DebugMessagesPane Maven / Gradle / Ivy
/*
* Created on 06-Nov-07
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package nl.nn.testtool.echo2;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import nextapp.echo2.app.CheckBox;
import nextapp.echo2.app.Column;
import nextapp.echo2.app.ContentPane;
import nextapp.echo2.app.Extent;
import nextapp.echo2.app.Font;
import nextapp.echo2.app.Label;
/**
* @author m00f069
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class DebugMessagesPane extends ContentPane {
private Column column = new Column();
private Font font = new Font(Font.MONOSPACE, Font.PLAIN, new Extent(12));
private CheckBox scrollLockCheckBox;
private List messages = new ArrayList();
private long messagesLength = 0;
private boolean even = true;
long messageCounter = 0;
long estimatedMemoryUsage = 0;
SimpleDateFormat simpleDateFormatDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
DebugMessagesPane(CheckBox lockCheckBox) {
super();
this.scrollLockCheckBox = lockCheckBox;
add(column);
}
public void addMessage(String title, String message) {
messageCounter++;
Extent oldVerticalScroll = getVerticalScroll();
if (title == null) {
title = "";
}
title = "[" + simpleDateFormatDateTime.format(new Date()) + "] " + title;
estimatedMemoryUsage = estimatedMemoryUsage + (title.length() * 2);
Label titleLabel = new Label(title);
titleLabel.setFont(font);
titleLabel.setBackground(Echo2Application.getButtonRolloverBackgroundColor());
column.add(titleLabel);
if (message != null) {
estimatedMemoryUsage = estimatedMemoryUsage + (message.length() * 2);
Label messagelabel = new Label(message);
messagelabel.setFont(font);
column.add(messagelabel);
}
if (!scrollLockCheckBox.isSelected()) {
setVerticalScroll(new Extent(-1));
}
while (estimatedMemoryUsage > 1000000) {
Label label = (Label)column.getComponent(0);
column.remove(0);
estimatedMemoryUsage = estimatedMemoryUsage - (label.getText().length() * 2);
}
}
public void removeAllMessages() {
column.removeAll();
}
}