Есть какие-то идеи?
package com.javarush.task.task32.task3209;
import com.javarush.task.task32.task3209.listeners.UndoListener;
import javax.swing.text.AbstractDocument;
import javax.swing.text.BadLocationException;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
public class Controller {
private View view;
private HTMLDocument document;
private File currentFile;
public HTMLDocument getDocument() {
return document;
}
public Controller(View view) {
this.view = view;
}
public void init(){
}
public void exit(){
System.exit(0);
}
public void resetDocument(){
UndoListener undoListener = view.getUndoListener();
if (document != null){
document.removeUndoableEditListener(undoListener);
}
document = (HTMLDocument) new HTMLEditorKit().createDefaultDocument();
document.addUndoableEditListener(undoListener);
view.update();
}
public void setPlainText(String text){
resetDocument();
try {
new HTMLEditorKit().read(new StringReader(text), document, document.getTokenThreshold());
} catch (Exception e) {
ExceptionHandler.log(e);
}
}
public String getPlainText() {
StringWriter stringWriter = new StringWriter();
try {
new HTMLEditorKit().write(stringWriter, document, 0, document.getLength());
} catch (Exception e) {
ExceptionHandler.log(e);
}
return stringWriter.toString();
}
public static void main(String[] args) {
View view = new View();
Controller controller = new Controller(view);
view.setController(controller);
view.init();
controller.init();
}
}