public void actionPerformed(ActionEvent actionEvent) {
String s = actionEvent.getActionCommand();
switch (s) {
case "New":
controller.createNewDocument();
break;
case "Open":
controller.openDocument();
break;
case "Save":
controller.saveDocument();
break;
case "Save As...":
controller.saveDocumentAs();
break;
case "Exit":
controller.exit();
break;
case "About":
showAbout();
}
}
package com.codegym.task.task32.task3209;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
import java.io.File;
import java.io.StringReader;
import java.io.StringWriter;
public class Controller {
private View view;
private HTMLDocument document;
private File currentFile;
public static void main(String[] args){
View view = new View();
Controller controller = new Controller(view);
view.setController(controller);
view.init();
controller.init();
}
public Controller(View view) {
this.view = view;
}
public void init(){
}
public void exit(){
System.exit(0);
}
public HTMLDocument getDocument() {
return document;
}
public void resetDocument(){
if(document != null) {
document.removeUndoableEditListener(view.getUndoListener());
}
document = (HTMLDocument) new HTMLEditorKit().createDefaultDocument();
document.addUndoableEditListener(view.getUndoListener());
view.update();
}
public void setPlainText(String text){
resetDocument();
try {
StringReader sr = new StringReader(text);
new HTMLEditorKit().read(sr, document, 0);
}
catch (Exception e){
ExceptionHandler.log(e);
}
}
public String getPlainText(){
String result = "";
try {
StringWriter sw = new StringWriter();
new HTMLEditorKit().write(sw, document, 0, document.getLength());
result = sw.toString();
}
catch(Exception e){
ExceptionHandler.log(e);
}
return result;
}
public void createNewDocument(){
}
public void openDocument(){
}
public void saveDocument(){
}
public void saveDocumentAs(){
}
}