Метод сохраняет файл, валик ругается. Почему?
![]()

package com.javarush.task.task32.task3209;
import com.javarush.task.task32.task3209.listeners.FrameListener;
import com.javarush.task.task32.task3209.listeners.TabbedPaneChangeListener;
import com.javarush.task.task32.task3209.listeners.UndoListener;
import javax.swing.*;
import javax.swing.undo.UndoManager;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class View extends JFrame implements ActionListener {
private Controller controller;
private JTabbedPane tabbedPane = new JTabbedPane();
private JTextPane htmlTextPane = new JTextPane();
private JEditorPane plainTextPane = new JEditorPane();
private UndoManager undoManager = new UndoManager();
private UndoListener undoListener = new UndoListener(undoManager);
public View() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException e) {
ExceptionHandler.log(e);
} catch (InstantiationException e) {
ExceptionHandler.log(e);
} catch (IllegalAccessException e) {
ExceptionHandler.log(e);
} catch (UnsupportedLookAndFeelException e) {
ExceptionHandler.log(e);
}
}
public boolean isHtmlTabSelected() {
boolean isHtmlTabSelected = (this.tabbedPane.getSelectedIndex() == 0) ? true : false;
return isHtmlTabSelected;
}
public void selectHtmlTab() {
this.tabbedPane.setSelectedIndex(0);
this.resetUndo();
}
public void resetUndo() {
undoManager.discardAllEdits();
}
public void update() {
this.htmlTextPane.setDocument(controller.getDocument());
}
public void showAbout() {
JOptionPane.showMessageDialog(this,
"Версия 0.9",
"О программе", JOptionPane.INFORMATION_MESSAGE);
}
public UndoListener getUndoListener() {
return undoListener;
}
public void undo() {
try {
undoManager.undo();
} catch (Exception e) {
ExceptionHandler.log(e);
}
}
public void redo() {
try {
undoManager.redo();
} catch (Exception e) {
ExceptionHandler.log(e);
}
}
@Override
public void actionPerformed(ActionEvent e) {
switch (e.getActionCommand()) {
case "Новый": {
controller.createNewDocument();
break;
}
case "Открыть": {
controller.openDocument();
break;
}
case "Сохранить": {
controller.saveDocument();
break;
}
case "Сохранить как...": {
controller.saveDocumentAs();
break;
}
case "Выход": {
controller.exit();
break;
}
case "О программе": {
this.showAbout();
break;
}
}
}
public void initMenuBar() {
JMenuBar jMenuBar = new JMenuBar();
MenuHelper.initFileMenu(this, jMenuBar);
MenuHelper.initEditMenu(this, jMenuBar);
MenuHelper.initStyleMenu(this, jMenuBar);
MenuHelper.initAlignMenu(this, jMenuBar);
MenuHelper.initColorMenu(this, jMenuBar);
MenuHelper.initFontMenu(this, jMenuBar);
MenuHelper.initHelpMenu(this, jMenuBar);
getContentPane().add(jMenuBar, BorderLayout.NORTH);
}
public boolean canUndo() {
return undoManager.canUndo();
}
public boolean canRedo() {
return undoManager.canRedo();
}
public void initEditor() {
htmlTextPane.setContentType("text/html");
JScrollPane scrollPaneHtml = new JScrollPane(htmlTextPane);
tabbedPane.addTab("HTML", scrollPaneHtml);
JScrollPane scrollPaneText = new JScrollPane(plainTextPane);
tabbedPane.addTab("Текст", scrollPaneText);
TabbedPaneChangeListener listener = new TabbedPaneChangeListener(this);
tabbedPane.addChangeListener(listener);
tabbedPane.setPreferredSize(new Dimension(500, 400));
getContentPane().add(tabbedPane, BorderLayout.CENTER);
}
public void initGui() {
initEditor();
initMenuBar();
this.pack();
}
public void selectedTabChanged() {
switch (this.tabbedPane.getSelectedIndex()) {
case 0: {
controller.setPlainText(this.plainTextPane.getText());
break;
}
case 1: {
this.plainTextPane.setText(controller.getPlainText());
break;
}
}
this.resetUndo();
}
public void exit() {
controller.exit();
}
public void init() {
initGui();
FrameListener frameListener = new FrameListener(this);
this.addWindowListener(frameListener);
this.setVisible(true);
}
public Controller getController() {
return controller;
}
public void setController(Controller controller) {
this.controller = controller;
}
}