This commit is contained in:
Alessandro Ferro
2023-08-06 22:07:49 +02:00
parent 1cfba5fbb3
commit 2050c061db
3 changed files with 7 additions and 17 deletions

View File

@ -11,6 +11,7 @@ public class NotepadController {
private INotepadFrame notepadFrame = null; private INotepadFrame notepadFrame = null;
private FindAndReplaceController myFindAndReplaceController; private FindAndReplaceController myFindAndReplaceController;
private boolean unsaved = false; private boolean unsaved = false;
private String initialText = null;
public boolean isUnsaved() { public boolean isUnsaved() {
return unsaved; return unsaved;
@ -24,12 +25,15 @@ public class NotepadController {
return this.filePath; return this.filePath;
} }
public String getInitialText() {
return this.initialText;
}
public NotepadController(String filePath) { public NotepadController(String filePath) {
this.filePath = filePath; this.filePath = filePath;
String contentToDisplay = SshEngine.readFile(filePath); initialText = SshEngine.readFile(filePath);
try { try {
notepadFrame = (INotepadFrame) JFrameFactory.createJFrame(IFrameFactory.NOTEPAD, this); notepadFrame = (INotepadFrame) JFrameFactory.createJFrame(IFrameFactory.NOTEPAD, this);
notepadFrame.displayContent(contentToDisplay);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return; return;

View File

@ -31,9 +31,6 @@ public class Notepad extends JFrame implements INotepadFrame {
private boolean jtextAreaShouldListenForChanges = true; private boolean jtextAreaShouldListenForChanges = true;
private JTextArea textArea; private JTextArea textArea;
/**
* Create the application.
*/
public Notepad(Object controller) { public Notepad(Object controller) {
this.controller = (NotepadController) controller; this.controller = (NotepadController) controller;
setTitle(this.controller.getFilePath()); setTitle(this.controller.getFilePath());
@ -50,6 +47,7 @@ public class Notepad extends JFrame implements INotepadFrame {
textArea.setTabSize(4); textArea.setTabSize(4);
textArea.setFont(new Font("Monospaced", Font.PLAIN, 14)); textArea.setFont(new Font("Monospaced", Font.PLAIN, 14));
textArea.setCaretPosition(0); textArea.setCaretPosition(0);
textArea.setText(((NotepadController)controller).getInitialText());
textArea.getDocument().addDocumentListener(new DocumentListener() { textArea.getDocument().addDocumentListener(new DocumentListener() {
@Override @Override
public void insertUpdate(DocumentEvent e) { 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;
}
} }

View File

@ -2,7 +2,6 @@ package views.interfaces;
public interface INotepadFrame { public interface INotepadFrame {
void setVisible(boolean visible); void setVisible(boolean visible);
void displayContent(String content);
int getX(); int getX();
int getY(); int getY();
int getWidth(); int getWidth();