Skip to content

Commit

Permalink
Merge pull request #35 from jcksndfrd/feature/timeanddate
Browse files Browse the repository at this point in the history
Time and date feature, resolves #22
  • Loading branch information
jcksndfrd committed Aug 4, 2021
2 parents 4a14920 + 70446b6 commit 7a86699
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/main/java/nz/ac/massey/cs/flackpad/MenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.awt.event.*;
import javax.swing.*;

@SuppressWarnings("serial")
class MenuBar extends JMenuBar {

private ActionListener menuListener;
Expand Down
26 changes: 22 additions & 4 deletions src/main/java/nz/ac/massey/cs/flackpad/MenuListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,46 @@ class MenuListener implements ActionListener {
public void actionPerformed(ActionEvent e) {

switch (e.getActionCommand()) {
//File menu
case "New":
window.newDoc();
break;

case "New Window":
// Load a new text editor instance
new Window();
break;

case "Open":
FileIO.open(window);
break;

case "Save":
FileIO.save(window);
break;

case "Save As":
FileIO.saveAs(window);
break;
case "Print":
break;
case "Exit":
window.exit();
break;

//Edit menu
case "Cut":
break;
case "Copy":
break;
case "Paste":
break;
case "Delete":
break;
case "Find":
break;
case"Time and Date":
window.getTextArea().addTimeAndDate();

//Help menu
case "About":
break;
}
}
}
18 changes: 18 additions & 0 deletions src/main/java/nz/ac/massey/cs/flackpad/TextArea.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
package nz.ac.massey.cs.flackpad;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import javax.swing.BorderFactory;
import javax.swing.JTextArea;
import javax.swing.text.BadLocationException;

@SuppressWarnings("serial")
class TextArea extends JTextArea {

Window window;

TextArea(Window window) {
super();
this.window = window;
this.setBorder(BorderFactory.createCompoundBorder(this.getBorder(), BorderFactory.createEmptyBorder(5, 5, 5, 5)));
this.getDocument().addDocumentListener(new DocListener(window));
}

void addTimeAndDate() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm dd/MM/yyyy");
try {
this.getDocument().insertString(0, formatter.format(LocalDateTime.now()) + "\n", null);
} catch (BadLocationException e) {
Dialogs.error("Something went wrong when getting the time and date", window);
}
}

}
7 changes: 4 additions & 3 deletions src/main/java/nz/ac/massey/cs/flackpad/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import java.io.File;
import javax.swing.*;

@SuppressWarnings("serial")
class Window extends JFrame {
private String name = "FlackPad";
private JFrame frame;
private WindowListener winListener;

private JMenuBar menuBar;
private JTextArea textArea;
private MenuBar menuBar;
private TextArea textArea;

private boolean saved = true;
private File file;
Expand Down Expand Up @@ -65,7 +66,7 @@ void exit() {
JFrame getFrame() {
return frame;
}
JTextArea getTextArea() {
TextArea getTextArea() {
return textArea;
}

Expand Down

0 comments on commit 7a86699

Please sign in to comment.