Skip to content

Commit

Permalink
Remove unused methods and improved styling
Browse files Browse the repository at this point in the history
  • Loading branch information
khor-jingqian committed Sep 1, 2020
1 parent a364291 commit f41131f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 170 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test {
}

application {
mainClassName = "logic.Duke"
mainClassName = "logic.Launcher"
}

shadowJar {
Expand Down
2 changes: 1 addition & 1 deletion data/tasks.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[T][✓] kiwis
[T][✘] oranges
[T][✘] kiwi
[E][✘] kiwis (at: 18:00 Sep 30 2020)
[T][✘] oranges
22 changes: 21 additions & 1 deletion src/main/java/logic/DialogBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Insets;
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.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;

/**
*
Expand Down Expand Up @@ -48,12 +53,27 @@ private void flip() {
}

public static DialogBox getUserDialog(String text, Image img) {
return new DialogBox(text, img);
DialogBox db = new DialogBox(text, img);
db.getLabel().setBackground(new Background(new BackgroundFill(
Color.rgb(101, 247, 245),
new CornerRadii(5.0),
new Insets(-5.0)
)));
return db;
}

public Label getLabel() {
return this.dialog;
}

public static DialogBox getDukeDialog(String text, Image img) {
var db = new DialogBox(text, img);
db.flip();
db.getLabel().setBackground(new Background(new BackgroundFill(
Color.rgb(152, 251, 152),
new CornerRadii(5.0),
new Insets(-5.0)
)));
return db;
}
}
142 changes: 1 addition & 141 deletions src/main/java/logic/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,19 @@
import command.Command;
import exception.DukeException;
import exception.InvalidSaveFileException;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import tasks.TaskList;

/**
* Represents a logic.Duke object. Handles all the logic running
* of logic.Duke
*/

public class Duke extends Application {
public class Duke {

private String fileLocation;
private Ui ui;
private Storage storage;
private TaskList taskList;
// private ScrollPane scrollPane;
// private VBox dialogContainer;
// private TextField userInput;
// private Button sendButton;
// private Scene scene;
// private Image user = new Image(this.getClass().getResourceAsStream("/images/DaUser.png"));
// private Image duke = new Image(this.getClass().getResourceAsStream("/images/DaDuke.png"));

/**
* Constructor to create a Duke object.
Expand All @@ -54,129 +36,11 @@ public Duke(String fileLocation) {
public Duke() {
}

/**
* Driving method of logic.Duke, handles all the running process
*
*/
public void run() {
ui.showGreeting();
boolean isExit = false;
while (!isExit) {
try {
String fullCommand = ui.readCommand();
ui.showLine(); // show the divider line ("_______")
Command c = Parser.parse(fullCommand);
c.execute(taskList, ui, storage);
isExit = c.isExit();
} catch (DukeException e) {
ui.showError(e.getMessage());
} finally {
ui.showLine();
}
}
}

@Override
public void start(Stage primaryStage) throws Exception {
//// //Step 1. Setting up required components
////
//// //The container for the content of the chat to scroll.
//// scrollPane = new ScrollPane();
//// dialogContainer = new VBox();
//// scrollPane.setContent(dialogContainer);
////
//// userInput = new TextField();
//// sendButton = new Button("Send");
////
//// AnchorPane mainLayout = new AnchorPane();
//// mainLayout.getChildren().addAll(scrollPane, userInput, sendButton);
////
//// scene = new Scene(mainLayout);
////
//// //Step 2. Formatting the window to look as expected
//// primaryStage.setTitle("Duke");
//// primaryStage.setResizable(false);
//// primaryStage.setMinHeight(600.0);
//// primaryStage.setMinWidth(400.0);
////
//// mainLayout.setPrefSize(400.0, 600.0);
////
//// scrollPane.setPrefSize(385, 535);
//// scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
//// scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);
////
//// scrollPane.setVvalue(1.0);
//// scrollPane.setFitToWidth(true);
////
//// // You will need to import `javafx.scene.layout.Region` for this.
//// dialogContainer.setPrefHeight(Region.USE_COMPUTED_SIZE);
////
//// userInput.setPrefWidth(325.0);
////
//// sendButton.setPrefWidth(55.0);
////
//// AnchorPane.setTopAnchor(scrollPane, 1.0);
////
//// AnchorPane.setBottomAnchor(sendButton, 1.0);
//// AnchorPane.setRightAnchor(sendButton, 1.0);
////
//// AnchorPane.setLeftAnchor(userInput , 1.0);
//// AnchorPane.setBottomAnchor(userInput, 1.0);
////
//// sendButton.setOnMouseClicked((event) -> {
//// handleUserInput();
//// });
////
//// userInput.setOnAction((event) -> {
//// handleUserInput();
//// });
////
//// dialogContainer.heightProperty().addListener((observable) -> scrollPane.setVvalue(1.0));
////
//// primaryStage.setScene(scene);
//// primaryStage.show();
}

/**
* Iteration 1:
* Creates a label with the specified text and adds it to the dialog container.
* @param text String containing text to add
* @return a label with the specified text that has word wrap enabled.
*/
// private Label getDialogLabel(String text) {
// // You will need to import `javafx.scene.control.Label`.
// Label textToAdd = new Label(text);
// textToAdd.setWrapText(true);
//
// return textToAdd;
// }

/**
* Iteration 2:
* Creates two dialog boxes, one echoing user input and the other containing Duke's reply and then appends them to
* the dialog container. Clears the user input after processing.
*/
// private void handleUserInput() {
// Label userText = new Label(userInput.getText());
// Label dukeText = new Label(getResponse(userInput.getText()));
// dialogContainer.getChildren().addAll(
// DialogBox.getUserDialog(userInput.getText(), user),
// DialogBox.getDukeDialog(getResponse(userInput.getText()), duke)
// );
// userInput.clear();
// }

/**
* You should have your own function to generate a response to user input.
* Replace this stub with your completed method.
*/
protected String getResponse(String input) {
// return "Duke heard: " + input;
try {
Command fullCommand = Parser.parse(input);
String dukeResponse = fullCommand.execute(taskList, ui, storage);
return dukeResponse;

} catch (DukeException e) {
return e.getMessage();
}
Expand All @@ -185,8 +49,4 @@ protected String getResponse(String input) {
protected String showGreeting() {
return ui.showGreeting();
}

public static void main(String[] args) {
new Duke("data/tasks.txt").run();
}
}
29 changes: 3 additions & 26 deletions src/main/java/logic/Ui.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,20 @@
package logic;

import java.util.Scanner;

/**
* Handles what the user will be seeing when running logic.Duke.
*/
public class Ui {

private Scanner sc;
public Ui() {
sc = new Scanner(System.in);
}
public void showLine() {
System.out.println("\t______________________________________________________");
}
public Ui() {}

/**
* Show user the greeting message.
*/
public String showGreeting() {
String result = "";
String logo = "\n ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
result += "Hello from" + logo;
result += "\t__________________________________________________\n";
result += "\t________________________________________________\n";
result += "\tHello! I'm Duke\n\tWhat can I do for you?\n";
result += "\t__________________________________________________\n";
result += "\t________________________________________________\n";
return result;
}

Expand All @@ -41,15 +27,6 @@ public void showError(String errorMsg) {
System.out.println(errorMsg);
}

/**
* Reads in the next input line from user.
*
* @return The next input from user.
*/
public String readCommand() {
return sc.nextLine();
}

/**
* Print the message according to the input given.
*
Expand Down

0 comments on commit f41131f

Please sign in to comment.