-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Ryan Jee] iP #268
base: master
Are you sure you want to change the base?
[Ryan Jee] iP #268
Changes from 23 commits
3eff0e6
5c86aa2
ec54d44
547f05b
cf149a2
7759f9a
56c85b2
6436423
f16618c
d531250
ac57426
01cc9d6
3441df1
a6b6963
0aa6f50
4098bb4
87f89db
3fd6a39
7d8e968
b840512
e2bf38f
d504d49
a2b182e
863e33e
b8850d1
7f28018
422c8c2
ba66524
143a739
d835407
b87cca8
9a5bfc3
2a6fc6d
c5f83fe
39fc04d
d8ed206
10cefb8
abc6c1e
3915318
755ab2a
d7778ee
8408de4
1a5f1d7
98c7115
555468a
65a60a0
23ef9c9
2a3aed8
97b08ed
a4d534c
849c049
5f30f79
bf9699a
b8a111e
6012491
45825ec
fd3ae73
d29d4c1
d12e4b9
7a1e991
cf05170
051cbcd
e5faea7
58bdb2f
eb4cc5e
57e46ab
5141b2f
f33b1eb
36aeb2c
169e64a
c29ae19
eb5f818
2fe3b28
4b2c886
c064d54
a7ce31b
648a0c8
eb7a203
c4dbbad
49526fe
a0ef7ac
b489945
f2387c6
9cdb6a0
b69f01b
b5a5065
1156199
8756858
6aad947
e3b5c8b
93a1ca2
31d8850
5a0c950
c203bb4
8349f95
c47e6d4
39a7210
a692afd
9aa9e90
d9e64d1
7fb2fa8
b56d62f
7f5a2a6
495f432
118f4ae
9a54a07
8da1bee
83cca67
25b32ce
3cbcc61
b2aeeb5
9f8213d
ecf95c1
63bbe1d
f079d43
483cde5
b8e7697
72951de
78ee103
c1109b5
ac94bbe
5eb4386
b18c912
4ddf0b7
66ffb11
ba2d598
b250a17
e2fe5a1
87e7f6b
29e7142
c1bb749
719cc69
5d7692a
f48fa6d
498c1d6
4d79237
493921f
9201104
f65e8d0
bcfbaea
3e769f2
4e0112b
6db33ca
c059910
b0a61cc
b23f294
d369a07
e1a6979
bdc98ad
165bba4
6391b95
e5124f2
7e9c75c
ff26236
05f4e38
5438274
14108f7
06d4a0c
c9babe0
c604ebb
73a662d
038e398
ad92a54
5bc3889
a3d5181
22c5998
1f1fb24
25340b7
b2a1c33
d659477
2b4603b
4f5426e
03d1af8
83d488e
b7e33f3
8cb4d02
51908fa
fd6f680
5fadee5
6b71f4e
55e5ba0
1b5c762
e2e6565
15e08dd
0ae4202
dd20c32
c3c8842
94504f7
53ddf2b
ff5c777
df1f842
baa1c36
756f21f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package duke.command; | ||
|
||
public class Command { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,30 @@ | ||
package duke; | ||
|
||
import java.util.Scanner; | ||
|
||
public class Duke { | ||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
private Storage storage; | ||
private DukeList DukeList; | ||
private Ui ui; | ||
|
||
|
||
public Duke(String filePath){ | ||
ui = new Ui(); | ||
storage = new Storage(filePath); | ||
TaskList = storage.readFile(); | ||
} | ||
|
||
public String getReply (String input){ | ||
Parser parser = new Parser(); | ||
try{ | ||
Command command = parser.parse(input); | ||
String reply = command.execute(ui,taskList, storage); | ||
storage.writeFile(); | ||
assert(reply!=null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good use of assertions! |
||
return reply; | ||
} | ||
catch (DukeException e){ | ||
return e.getMessage(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package duke; | ||
|
||
public class DukeException extends Exception{ | ||
public DukeException (String message){ | ||
super(message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package duke; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class DukeList { | ||
private List<Task> taskList; | ||
|
||
public DukeList(){ | ||
taskList = new ArrayList<>(); | ||
} | ||
|
||
public DukeList(List<Task> taskList){ | ||
this.taskList = taskList; | ||
} | ||
|
||
public List<Task> getTaskList(){ | ||
return taskList; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package duke; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.BufferedWriter; | ||
import java.io.DataInputStream; | ||
import java.io.FileInputStream; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
|
||
import duke.DukeException;; | ||
import duke.DukeList; | ||
import duke.tasktype.Task; | ||
import duke.tasktype.Deadline; | ||
import duke.tasktype.Event; | ||
import duke.tasktype.Todo; | ||
|
||
public class Storage { | ||
private StringBuffer stringBufferOfTasks = new StringBuffer(); | ||
private String filename; | ||
private Path path; | ||
|
||
public Storage (String filename){ | ||
this.filename = new File(filename); | ||
accessTaskListInFileSystem(getCurrentDirectory()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clear and concise naming of method |
||
} | ||
private void taskListinFile (String current){ | ||
String[] parents = filename.split("/"); | ||
String parent = parents[0]; | ||
Path direcPath = Path(current,parent); | ||
Path filePath = Path(current,filename); | ||
boolean directoryExist = Files.exists(direcPath); | ||
boolean fileExist = Files.exists(filePath); | ||
try{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might want to include spacing in between |
||
if(!directoryExist){ | ||
Files.createDirectories(direcPath); | ||
} | ||
if(!fileExist){ | ||
Files.createFile(filePath); | ||
} | ||
} | ||
catch(IOException e){ | ||
System.out.println(e.getMessage()); | ||
} | ||
} | ||
|
||
public DukeList load(){ | ||
DukeList dukeList = new DukeList(); | ||
StringBufferTasks = new StringBuffer(); | ||
try{ | ||
BufferedReader reader = new BufferedReader(new InputStreamReader(new DataInputStream(new FileInputStream(this.filename)))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might have exceeded line limit |
||
String line = reader.readline(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package duke; | ||
|
||
public class Ui { | ||
public String makeDone(String task){ | ||
assert(task!= null); | ||
return String.format("Following task is marked done: \n" + task); | ||
} | ||
|
||
public String showTaskAdded(String task, List<Task> taskList){ | ||
assert(task != null && taskList != null); | ||
return String.format( "Added the following task : \n" + "%s\n" + "You now have %d tasks in your list.\n", task, taskList.size()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might have exceeded line limit |
||
} | ||
|
||
public String showTaskDeleted(String task, List<Task> taskList){ | ||
assert(task != null && taskList != null); | ||
return String.format("The following task has been removed:\n " + "%s\n" + " You now have %d tasks in your list.\n", task, taskList.size()); | ||
} | ||
|
||
public String showList(List<task> taskList){ | ||
assert(taskList != null); | ||
int counter = 1; | ||
Stringbuffer showList = new Stringbuffer(); | ||
showList.append(" These are the tasks in your list:\n"); | ||
for (Task task : taskList){ | ||
showList.append(" " + counter + ". " + task.getStatus() + "'n"); | ||
counter++; | ||
} | ||
return showList.toString; | ||
} | ||
|
||
public String sayGoodbye(){ | ||
return "Goodbye!"; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package duke.gui; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
|
||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
import javafx.fxml.FXML; | ||
import javafx.fxml.FXMLLoader; | ||
import javafx.geometry.Pos; | ||
import javafx.scene.Node; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.image.Image; | ||
import javafx.scene.image.ImageView; | ||
import javafx.scene.layout.HBox; | ||
import javafx.scene.text.Text; | ||
|
||
public class DialogBox extends HBox { | ||
@FXML | ||
private Text dialog; | ||
@FXML | ||
private ImageView displayPicture; | ||
|
||
private DialogBox(String text, Image img){ | ||
try{ | ||
FXMLLoader fxmlLoader = new FXMLLoader(MainWindow.class.getResource("/view/DialogBox.fxml")); | ||
fxmlLoader.setController(this); | ||
fxmlLoader.setRoot(this); | ||
fxmlLoader.load(); | ||
} catch (IOException e){ | ||
e.printStackTrace(); | ||
} | ||
|
||
dialog.setText(text); | ||
displayPicture.setImage(img); | ||
} | ||
|
||
private void flip(){ | ||
ObservableList<Node> tmp = FXCollections.observableArrayList(this.getChildren()); | ||
Collections.reverse(tmp); | ||
getChildren().setAll(tmp); | ||
setAlignment(Pos.TOP_LEFT); | ||
} | ||
|
||
public static DialogBox getUserDialog(String text, Image img) { | ||
return new DialogBox(text, img); | ||
} | ||
|
||
public static DialogBox getBotDialog(String text, Image img) { | ||
var db = new DialogBox(text, img); | ||
db.flip(); | ||
return db; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package duke.gui; | ||
|
||
import javafx.application.Application; | ||
|
||
public class Launcher { | ||
public static void main(String[] args){ | ||
Application.launch(Main.class,args); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package duke.gui; | ||
import javafx.application.Application; | ||
import javafx.fml.FXMLLoader; | ||
import javafx.scene.Scene; | ||
import javafx.stage.Stage; | ||
import javafx.scence.layout.AnchorPane; | ||
import java.io.IOException; | ||
|
||
public class Main extends Application{ | ||
private Duke duke = new Duke("data/duke.txt"); | ||
@Override | ||
public void start(Stage stage){ | ||
MainWindow mainWindow = new MainWindow(duke); | ||
Scene scene = new Scene(mainWindow); | ||
stage.setScene(scene); | ||
stage.show(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package duke.gui; | ||
|
||
import javafx.fml.FXML; | ||
import javafx.scene.control.Button; | ||
import javafx.scene.control.ScrollPane; | ||
import javafx.scene.control.Textfield; | ||
import javafx.scene.image.Image; | ||
import javafx.scene.layout.AnchorPane; | ||
import javafx.scene.layout.Vbox; | ||
import java.io.IOException; | ||
import duke.Duke; | ||
public class MainWindow extends AnchorPane { | ||
@FXML | ||
private ScrollPane scrollPane; | ||
@FXML | ||
private VBox dialogContainer; | ||
@FXML | ||
private TextField userInput; | ||
@FXML | ||
private Button sendButton; | ||
|
||
private Duke duke; | ||
private Image userImage = new Image(this.getClass().getResourceAsStream("/images.Count.jpg")); | ||
private Image botImage = new Image(this.getClass().getResourceAsStream("/images.Duke.jpg")); | ||
private final String startMessage = "Hi there.\n" | ||
+ "These are the stuff you can say.\n" | ||
|
||
public Mainwindow(){ | ||
|
||
} | ||
public void initialize(){ | ||
this.scrollPane.vvalueProperty().bind(this,dialogContainer.heightProperty()); | ||
dialogContainer.getChildren().add(DialogBox.getDukeDialog(startMessage,botImage)); | ||
} | ||
@FXML | ||
private void handleUserInput(){ | ||
String input = userInput.getText(); | ||
String respone = duke.getResponse(input); | ||
dialogContainer.getChildren().addAll(DialogBox.getUserDialog(input,userImage), DialogBox.getDukeDialog(response,botImage)); | ||
userInput.clear(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package duke.tasktype; | ||
|
||
public class Deadline extends Task { | ||
public Deadline (String name){ | ||
super(name); | ||
this.type = "D"; | ||
} | ||
|
||
public Deadline(String name, String dateTime){ | ||
super(name,dateTime); | ||
this.type = "D"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package duke.tasktype; | ||
|
||
public class Event extends Task { | ||
public Event(String name){ | ||
super(name); | ||
this.type = "E"; | ||
} | ||
|
||
public Event(String name, String dateTime){ | ||
super(name, dateTime); | ||
this.type = "E"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package duke.tasktype; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public class Task { | ||
protected String name; | ||
protected boolean isDone; | ||
protected String type; | ||
protected LocalDateTime dateTime; | ||
|
||
public Task(String name){ | ||
this.name = name; | ||
this.isDone = false; | ||
} | ||
|
||
public Task(String name, Stirng dateTime){ | ||
this.name = name; | ||
this.isDone = false; | ||
this.dateTime = LocalDateTime.parse(dateTime, DateTimeFormatter.ofPattern("yyyy-MM-dd kkmm")); | ||
} | ||
|
||
public void setDone(){ | ||
isDone = true; | ||
} | ||
|
||
public String getName(){ | ||
return name; | ||
} | ||
|
||
public String getStatusIcon(){ | ||
return (isDone ? "✓" : "X"); | ||
} | ||
|
||
public String getStatus(){ | ||
if(dateTime == null){ | ||
return " [" + type + "] " + " [" + getStatusIcon() + "] " + getname(); | ||
} | ||
else{ | ||
return " [" + type + "] " + " [" + getStatusIcon() + "] " + getname() + " " + dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd kkmm")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might have exceeded line limit |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package duke.tasktype; | ||
|
||
public class Todo extends Task { | ||
public Todo (String name){ | ||
super(name); | ||
this.type = "T"; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to consider removing extra space(s) between
new Ui()