script highlighting fixed 2

This commit is contained in:
2014-12-05 17:45:51 +01:00
parent efafd6b896
commit a69484a003
2 changed files with 24 additions and 21 deletions
@@ -36,32 +36,36 @@ import jsyntaxpane.SyntaxDocument;
*/
public class UndoFixedEditorPane extends JEditorPane {
private static final Object setTextLock = new Object();
@Override
public void setText(String t) {
setText(t, getContentType());
}
public synchronized void setText(String t, String contentType) {
if (!t.equals(getText())) {
boolean plain = t.length() > Configuration.syntaxHighlightLimit.get();
if (plain) {
contentType = "text/plain";
public void setText(String t, String contentType) {
synchronized (setTextLock) {
if (!t.equals(getText())) {
boolean plain = t.length() > Configuration.syntaxHighlightLimit.get();
if (plain) {
contentType = "text/plain";
}
try {
setContentType(contentType);
Document doc = getDocument();
setDocument(new SyntaxDocument(null));
doc.remove(0, doc.getLength());
Reader r = new StringReader(t);
EditorKit kit = createEditorKitForContentType(contentType);
kit.read(r, doc, 0);
setDocument(doc);
} catch (BadLocationException | IOException ex) {
Logger.getLogger(UndoFixedEditorPane.class.getName()).log(Level.SEVERE, null, ex);
}
clearUndos();
}
try {
setContentType(contentType);
Document doc = getDocument();
setDocument(new SyntaxDocument(null));
doc.remove(0, doc.getLength());
Reader r = new StringReader(t);
EditorKit kit = createEditorKitForContentType(contentType);
kit.read(r, doc, 0);
setDocument(doc);
} catch (BadLocationException | IOException ex) {
Logger.getLogger(UndoFixedEditorPane.class.getName()).log(Level.SEVERE, null, ex);
}
clearUndos();
}
}