+ }
+
+ private synchronized void trimBuffer(boolean clear)
+ {
+ // trim the buffer
+ if (clear || lines > lim)
+ {
+ try
+ {
+ if (lines > 5)
+ {
+ // minimum length for truncation/clearing
+ String header = textArea.getText(0, textArea.getLineEndOffset(5))
+ + "\n..Truncated..\n"; // keep first 5 lines for startup info
+ int truncate;
+ if (!clear)
+ {
+ truncate = textArea.getLineEndOffset(lines - lim - 7);
+ textArea.setText(header
+ + textArea.getText(truncate, textArea.getText()
+ .length()
+ - truncate));
+ }
+ else
+ {
+ textArea.setText(header);
+ }
+ }
+
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ lines = textArea.getLineCount();
+ }