diff --git a/Guify/src/controllers/NotepadController.java b/Guify/src/controllers/NotepadController.java index 57b5aac..ca57941 100644 --- a/Guify/src/controllers/NotepadController.java +++ b/Guify/src/controllers/NotepadController.java @@ -11,6 +11,7 @@ public class NotepadController { private INotepadFrame notepadFrame = null; private FindAndReplaceController myFindAndReplaceController; private boolean unsaved = false; + private String initialText = null; public boolean isUnsaved() { return unsaved; @@ -24,12 +25,15 @@ public class NotepadController { return this.filePath; } + public String getInitialText() { + return this.initialText; + } + public NotepadController(String filePath) { this.filePath = filePath; - String contentToDisplay = SshEngine.readFile(filePath); + initialText = SshEngine.readFile(filePath); try { notepadFrame = (INotepadFrame) JFrameFactory.createJFrame(IFrameFactory.NOTEPAD, this); - notepadFrame.displayContent(contentToDisplay); } catch (Exception e) { e.printStackTrace(); return; diff --git a/Guify/src/views/Notepad.java b/Guify/src/views/Notepad.java index fb4efef..8354763 100644 --- a/Guify/src/views/Notepad.java +++ b/Guify/src/views/Notepad.java @@ -31,9 +31,6 @@ public class Notepad extends JFrame implements INotepadFrame { private boolean jtextAreaShouldListenForChanges = true; private JTextArea textArea; - /** - * Create the application. - */ public Notepad(Object controller) { this.controller = (NotepadController) controller; setTitle(this.controller.getFilePath()); @@ -50,6 +47,7 @@ public class Notepad extends JFrame implements INotepadFrame { textArea.setTabSize(4); textArea.setFont(new Font("Monospaced", Font.PLAIN, 14)); textArea.setCaretPosition(0); + textArea.setText(((NotepadController)controller).getInitialText()); textArea.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { @@ -165,15 +163,4 @@ public class Notepad extends JFrame implements INotepadFrame { } }); } - - /** - * Sets text in the JTextArea without triggering - * a text changed action - */ - public void displayContent(String content) { - jtextAreaShouldListenForChanges = false; - textArea.setText(content); - jtextAreaShouldListenForChanges = true; - } - } diff --git a/Guify/src/views/interfaces/INotepadFrame.java b/Guify/src/views/interfaces/INotepadFrame.java index 2bea330..44eea9f 100644 --- a/Guify/src/views/interfaces/INotepadFrame.java +++ b/Guify/src/views/interfaces/INotepadFrame.java @@ -2,7 +2,6 @@ package views.interfaces; public interface INotepadFrame { void setVisible(boolean visible); - void displayContent(String content); int getX(); int getY(); int getWidth();