package com.codegym.task.task32.task3209;
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;
public class Controller {
private View view;
private HTMLDocument document;
private File currentFile;
public Controller(View view) {
this.view = view;
}
public void resetDocument() {
if (document != null) {
document.removeUndoableEditListener(view.getUndoListener());
}
HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
document = (HTMLDocument) htmlEditorKit.createDefaultDocument();
document.addUndoableEditListener(view.getUndoListener());
view.update();
}
public void init() {}
public void exit() {
System.exit(0);
}
public HTMLDocument getDocument() {
return document;
}
public void setPlainText(String text) {
resetDocument();
StringReader stringReader = new StringReader(text);
HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
try {
htmlEditorKit.read(stringReader, document, 0);
} catch (IOException e) {
ExceptionHandler.log(e);
} catch (BadLocationException e) {
ExceptionHandler.log(e);
}
}
public static void main(String[] args) {
View view = new View();
Controller controller = new Controller(view);
view.setController(controller);
view.init();
controller.init();
}
public static class ExceptionHandler {
public static void log(Exception e) {
}
}
}
how to meet last request
Resolved
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Satya Vath
14 April 2020, 12:11solution
Why did you create another ExceptionHandler in Controller Class
Remove it
+2