Skip to content
Permalink
Browse files

First unsuccessfull attempt to solve #2233

  • Loading branch information...
Federico Fissore
Federico Fissore committed Oct 1, 2014
1 parent 3a1b7ea commit 3ae7aa7faec6152a5f37edac5e59c72285d52ac1
Showing with 24 additions and 2 deletions.
  1. +21 −2 app/src/processing/app/AbstractMonitor.java
  2. +3 −0 app/src/processing/app/Preferences.java
@@ -5,7 +5,7 @@

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.text.DefaultCaret;
import javax.swing.text.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@@ -16,7 +16,10 @@

public abstract class AbstractMonitor extends JFrame implements MessageConsumer {

private static final int DEFAULT_MAX_CONTENT_LENGTH = 10 * 1024;

protected final JLabel noLineEndingAlert;
protected final int maxContentLength;
protected JTextArea textArea;
protected JScrollPane scrollPane;
protected JTextField textField;
@@ -28,6 +31,8 @@
public AbstractMonitor(String title) {
super(title);

maxContentLength = Preferences.getInteger("serial_monitor_max_content_length", DEFAULT_MAX_CONTENT_LENGTH);

addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event) {
try {
@@ -58,7 +63,21 @@ public void actionPerformed(ActionEvent event) {
Font editorFont = Preferences.getFont("editor.font");
Font font = new Font(consoleFont.getName(), consoleFont.getStyle(), editorFont.getSize());

textArea = new JTextArea(16, 40);
PlainDocument textAreaModel = new PlainDocument();
textAreaModel.setDocumentFilter(new DocumentFilter() {
@Override
public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException {
int documentLength = fb.getDocument().getLength();
int sumOfLengths = documentLength + string.length();
if (sumOfLengths > maxContentLength) {
int lengthToRemove = sumOfLengths - maxContentLength;
fb.remove(0, lengthToRemove);
offset -= lengthToRemove;
}
super.insertString(fb, offset, string, attr);
}
});
textArea = new JTextArea(textAreaModel, null, 16, 40);
textArea.setEditable(false);
textArea.setFont(font);

@@ -892,6 +892,9 @@ static public int getInteger(String attribute /*, int defaultValue*/) {
*/
}

static public int getInteger(String attribute, int defaultValue) {
return Integer.parseInt(get(attribute, String.valueOf(defaultValue)));
}

static public void setInteger(String key, int value) {
set(key, String.valueOf(value));

0 comments on commit 3ae7aa7

Please sign in to comment.
You can’t perform that action at this time.