Skip to content
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

Branch a assertions #1

Merged
merged 5 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'java'
id 'application'
id 'checkstyle'
//id 'checkstyle'
id 'com.github.johnrengelman.shadow' version '5.1.0'
}

Expand All @@ -14,6 +14,23 @@ dependencies {
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.5.0'
}

dependencies {
String javaFxVersion = '11'

implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'linux'
implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'linux'
implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'linux'
implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'linux'
}

test {
useJUnitPlatform()

Expand All @@ -29,18 +46,14 @@ test {
}

application {
mainClassName = "seedu.duke.Duke"
mainClassName = "duke.Duke"
}

shadowJar {
archiveBaseName = "duke"
archiveClassifier = null
}

checkstyle {
toolVersion = '8.23'
}

run{
standardInput = System.in
}
2 changes: 1 addition & 1 deletion data/duke.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.[duke.ToDo][✘] hoeword
1.[ToDo][✓] eat
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Fri Sep 04 16:49:21 SGT 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Binary file added lib/javafx-swt.jar
Binary file not shown.
Binary file added lib/javafx.base.jar
Binary file not shown.
Binary file added lib/javafx.controls.jar
Binary file not shown.
Binary file added lib/javafx.fxml.jar
Binary file not shown.
Binary file added lib/javafx.graphics.jar
Binary file not shown.
Binary file added lib/javafx.media.jar
Binary file not shown.
3 changes: 3 additions & 0 deletions lib/javafx.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
javafx.version=11.0.2
javafx.runtime.version=11.0.2+1
javafx.runtime.build=1
Binary file added lib/javafx.swing.jar
Binary file not shown.
Binary file added lib/javafx.web.jar
Binary file not shown.
Binary file added lib/libdecora_sse.dylib
Binary file not shown.
Binary file added lib/libfxplugins.dylib
Binary file not shown.
Binary file added lib/libglass.dylib
Binary file not shown.
Binary file added lib/libglib-lite.dylib
Binary file not shown.
Binary file added lib/libgstreamer-lite.dylib
Binary file not shown.
Binary file added lib/libjavafx_font.dylib
Binary file not shown.
Binary file added lib/libjavafx_iio.dylib
Binary file not shown.
Binary file added lib/libjfxmedia.dylib
Binary file not shown.
Binary file added lib/libjfxmedia_avf.dylib
Binary file not shown.
Binary file added lib/libjfxwebkit.dylib
Binary file not shown.
Binary file added lib/libprism_common.dylib
Binary file not shown.
Binary file added lib/libprism_es2.dylib
Binary file not shown.
Binary file added lib/libprism_sw.dylib
Binary file not shown.
Binary file added lib/src.zip
Binary file not shown.
68 changes: 68 additions & 0 deletions src/main/java/duke/DialogBox.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package duke;

import javafx.geometry.Pos;

import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.layout.HBox;
import javafx.scene.layout.BackgroundImage;
import javafx.scene.layout.BackgroundPosition;
import javafx.scene.layout.BackgroundRepeat;
import javafx.scene.layout.BackgroundSize;
import javafx.scene.layout.Background;
import javafx.scene.paint.ImagePattern;
import javafx.scene.shape.Circle;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

public class DialogBox extends HBox {


public DialogBox(Label l, Image iv, Image background) {
Circle circle = new Circle(40);
circle.setFill(new ImagePattern(iv));
l.setWrapText(true);

// create a background image
BackgroundImage backgroundimage = new BackgroundImage(background,
BackgroundRepeat.NO_REPEAT,
BackgroundRepeat.NO_REPEAT,
BackgroundPosition.DEFAULT,
BackgroundSize.DEFAULT);

// create Background
Background backgroundImage = new Background(backgroundimage);

// set background
this.setBackground(backgroundImage);

this.setAlignment(Pos.TOP_RIGHT);
this.getChildren().addAll(l, circle);
}

/**
* Flips the dialog box such that the ImageView is on the left and text on the right.
*/

private void flip() {
this.setAlignment(Pos.TOP_LEFT);
ObservableList<Node> tmp = FXCollections.observableArrayList(this.getChildren());
FXCollections.reverse(tmp);
this.getChildren().setAll(tmp);
}

public static DialogBox getUserDialog(Label l, Image iv, Image background) {
return new DialogBox(l, iv, background);
}

public static DialogBox getDukeDialog(Label l, Image iv, Image background) {
var db = new DialogBox(l, iv, background);
db.flip();
return db;
}



}
130 changes: 127 additions & 3 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,45 @@
* Follows the coding standard
*/

public class Duke {
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;


public class Duke extends Application {

private Storage storage;
private TaskList tasks;
private Ui ui;
private ScrollPane scrollPane;
private VBox dialogContainer;
private TextField userInput;


private Image user = new Image(this.getClass().getResourceAsStream("/images/Me.png"));
private Image duke = new Image(this.getClass().getResourceAsStream("/images/KaTo.png"));
private Image userBackground = new Image(this.getClass().getResourceAsStream("/images/background2.png"));
private Image dukeBackground = new Image(this.getClass().getResourceAsStream("/images/Sea.png"));

public Duke(){
}
public Duke(String filePath) {
this.ui = new Ui();

this.storage = new Storage(filePath);
if (this.storage.load().isEmpty()) {
this.tasks = new TaskList();

}else{
System.out.println(storage.load());
this.tasks = new TaskList(storage.load());
System.out.println(this.tasks);
}
}

Expand All @@ -33,6 +58,105 @@ private void run() {
}
}

@Override
public void start(Stage stage) {

//The container for the content of the chat to scroll.
scrollPane = new ScrollPane();
dialogContainer = new VBox();
scrollPane.setContent(dialogContainer);

userInput = new TextField();
Button sendButton = new Button("Send");

AnchorPane mainLayout = new AnchorPane();
mainLayout.getChildren().addAll(scrollPane, userInput, sendButton);

Label dukeText = new Label("Hello, Ka To here, how can I serve you?");
dialogContainer.getChildren().addAll(
DialogBox.getDukeDialog(dukeText, duke, dukeBackground)
);

Scene scene = new Scene(mainLayout);
stage.setScene(scene);
stage.show();

stage.setTitle("Duke");
stage.setResizable(false);
stage.setMinHeight(600.0);
stage.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);

dialogContainer.setPrefHeight(Region.USE_COMPUTED_SIZE);
dialogContainer.heightProperty().addListener((observable) -> scrollPane.setVvalue(1.0));

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);


//Part 3. Add functionality to handle user input.
sendButton.setOnMouseClicked((event) -> {
handleUserInput();
});

userInput.setOnAction((event) -> {
handleUserInput();
});

}



/**
* 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("Me :\n" + userInput.getText());
Label dukeText = new Label(getResponse(userInput.getText()));
dialogContainer.getChildren().addAll(
DialogBox.getUserDialog(userText, user, userBackground),
DialogBox.getDukeDialog(dukeText, duke, dukeBackground)
);
userInput.clear();
}
/**
*
*/
private String getResponse(String input) {
String filePath = "./data/duke.txt";
GUI gui = new GUI();
this.storage = new Storage(filePath);
if (this.storage.load().isEmpty()) {
this.tasks = new TaskList();
}else{
this.tasks = new TaskList(storage.load());
}
String output = ParserGUI.processCommand(input, gui, this.tasks, this.storage.filePath);
return "Ka To: \n" + output;
}



public static void main(String[] args) {
String filePath = "./data/duke.txt";
Expand Down
24 changes: 0 additions & 24 deletions src/main/java/duke/FileReader.java

This file was deleted.

Loading