Skip to content

Commit

Permalink
Fix all checkstyle problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Caiyi34777 committed Sep 17, 2020
1 parent 9d07008 commit 52d8544
Show file tree
Hide file tree
Showing 24 changed files with 159 additions and 61 deletions.
5 changes: 4 additions & 1 deletion src/main/java/duke/Converter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package duke;

import duke_exceptions.IllegalTaskTypeException;
import duke.exceptions.IllegalTaskTypeException;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -42,6 +42,9 @@ public static String by(String s) {

/**
* Returns a Task object specified by the input string.
* Since this method is ensured to be called properly
* (by implementation in class Parser),
* it will not invoke exception thrown and terminate the program.
*
* @param s input message string
* @return a Task object
Expand Down
1 change: 1 addition & 0 deletions src/main/java/duke/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* A <code>Deadline</code> object corresponds to
* a task associated a date as deadline
*/

public class Deadline extends Task {
/** Constructor.
* Initialises message.
Expand Down
28 changes: 22 additions & 6 deletions src/main/java/duke/DialogBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@
import javafx.scene.shape.Circle;
import javafx.scene.text.Font;

@SuppressWarnings("CheckStyle")
public class DialogBox extends HBox {
@SuppressWarnings("CanBeFinal")
protected Label text;
// The label containing text to be added in DialogBox.
private Label text;

public DialogBox(Label l, Circle c) {
text = l;
/** Constructor for DialogBox.
*
* @param label label containing text
* @param circle circle-shaped image
*/
public DialogBox(Label label, Circle circle) {
text = label;

@SuppressWarnings("SpellCheckingInspection")
Font font = new Font("Baskerville", 14);
Expand All @@ -25,16 +32,25 @@ public DialogBox(Label l, Circle c) {
text.setWrapText(true);

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

/**
* Flips the dialog box such that the ImageView is on the left and text on the right.
* Flips the dialog box such that the ImageView is on the left and
* text on the right.
*/
protected void flip() {
this.setAlignment(Pos.TOP_LEFT);
ObservableList<Node> tmp = FXCollections.observableArrayList(this.getChildren());
ObservableList<Node> tmp = FXCollections
.observableArrayList(this.getChildren());
FXCollections.reverse(tmp);
this.getChildren().setAll(tmp);
}

/**
* Returns the label instance named text;
*/
protected Label getText() {
return text;
}
}
28 changes: 20 additions & 8 deletions src/main/java/duke/DialogBoxDuke.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,29 @@
import javafx.scene.shape.Circle;

public class DialogBoxDuke extends DialogBox {
public DialogBoxDuke(Label l, Circle c) {
super(l, c);
Color color = Color.rgb(238,160,178);
/** Constructor for DialogBoxDuke.
*
* @param label label containing text
* @param circle circle-shaped image
*/
public DialogBoxDuke(Label label, Circle circle) {
super(label, circle);
Color color = Color.rgb(238, 160, 178);
CornerRadii corn = new CornerRadii(10);
Insets insets = new Insets(-2,0,-2,3);
Background background = new Background(new BackgroundFill(color, corn, insets));
text.setBackground(background);
Insets insets = new Insets(-2, 0, -2, 3);
Background background = new Background(
new BackgroundFill(color, corn, insets));
getText().setBackground(background);
}

public static DialogBox getDukeDialog(Label l, Circle c) {
DialogBoxDuke db = new DialogBoxDuke(l, c);
/** Creates a new Duke DialogBox.
*
* @param label label containing text
* @param circle circle-shaped image
* @return a Duke DialogBox
*/
public static DialogBox getDukeDialog(Label label, Circle circle) {
DialogBoxDuke db = new DialogBoxDuke(label, circle);
db.flip();
return db;
}
Expand Down
28 changes: 20 additions & 8 deletions src/main/java/duke/DialogBoxUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,28 @@

public class DialogBoxUser extends DialogBox {

public DialogBoxUser(Label l, Circle c) {
super(l, c);
Color col = Color.rgb(190,231,223);
/** Constructor for DialogBoxDuke.
*
* @param label label containing text
* @param circle circle-shaped image
*/
public DialogBoxUser(Label label, Circle circle) {
super(label, circle);
Color col = Color.rgb(190, 231, 223);
CornerRadii corn = new CornerRadii(10);
Insets insets = new Insets(-2,1,-2,0);
Background background = new Background(new BackgroundFill(col, corn, insets));
text.setBackground(background);
Insets insets = new Insets(-2, 1, -2, 0);
Background background = new Background(
new BackgroundFill(col, corn, insets));
getText().setBackground(background);
}

public static DialogBox getUserDialog(Label l, Circle c) {
return new DialogBoxUser(l, c);
/** Creates a new User DialogBox.
*
* @param label label containing text
* @param circle circle-shaped image
* @return a User DialogBox
*/
public static DialogBox getUserDialog(Label label, Circle circle) {
return new DialogBoxUser(label, circle);
}
}
2 changes: 1 addition & 1 deletion src/main/java/duke/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public String getPrintMessage() {
}

/**
* Returns the message of this event
* Returns the message of this event.
* @return message
*/
@Override
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/duke/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import javafx.application.Application;

public class Launcher {
/** Empty constructor. */
private Launcher() { }
/** Launches the Ui.
* @param args input string (not used)
*/
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/duke/MainWithUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.layout.*;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.ImagePattern;
import javafx.scene.shape.Circle;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.scene.image.Image;


@SuppressWarnings("ALL")
public class MainWithUi extends Application {
private ScrollPane scrollPane;
private VBox dialogContainer;
Expand Down
34 changes: 21 additions & 13 deletions src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package duke;

import duke_exceptions.*;
import duke.exceptions.*;

public class Parser {
// constant SPACE and LINE for format purposes
Expand All @@ -23,7 +23,6 @@ public static String format(String input) {
private final int EXTRA = 1;

// current command: the whole line
@SuppressWarnings("CanBeFinal")
private String command;

/**
Expand All @@ -47,6 +46,7 @@ private String handleBye() {
/**
* Returns the list message called by user input "list".
*
* @param lst the task list to be handled
* @return formatted list message
*/
private String handleList(TaskList lst) {
Expand All @@ -57,13 +57,15 @@ private String handleList(TaskList lst) {
/**
* Returns a raw list without any formatting.
*
* @param lst the task list to be printed
* @return a raw list string
*/
private String taskPrint(TaskList lst) {
StringBuilder listContent = new StringBuilder();
int counter = 1;
for (Task task : lst.getLst()) {
listContent.append(INDENT).append(counter).append(".").append(task.print()).append("\n");
listContent.append(INDENT).append(counter).append(".")
.append(task.print()).append("\n");
counter++;
}
return listContent.toString();
Expand All @@ -73,6 +75,7 @@ private String taskPrint(TaskList lst) {
* Returns a formatted list message.
*
* @param content the raw list
* @param message the opening statement for print a list
* @return a formatted string of "content"
*/
private String formatList(String content, String message) {
Expand Down Expand Up @@ -136,7 +139,7 @@ private boolean isValid(String command) {
}

/**
* Returns a response string for "done" command
* Returns a response string for "done" command.
*
* @param lst the task list
* @param command the command to be processed
Expand Down Expand Up @@ -171,7 +174,7 @@ private String handleDone(TaskList lst, String command) {
}

/**
* Returns a response string for "delete" command
* Returns a response string for "delete" command.
*
* @param lst the task list
* @param command the command to be processed
Expand Down Expand Up @@ -200,22 +203,25 @@ private String handleDelete(TaskList lst, String command) {
lst.delete(index);

String messageDelete = "Noted. I've removed this task:\n";
return format(messageDelete + MORE_INDENT + task.print() + getListCountMessage(lst));
return format(messageDelete
+ MORE_INDENT + task.print() + getListCountMessage(lst));

}

/**
* Returns a string listing all tasks in the task list
* Returns a string listing all tasks in the task list.
*
* @param lst the task list
* @return a string listing all tasks in lst
*/
private String getListCountMessage(TaskList lst) {
return "\n" + INDENT + "Now you have " + lst.size() + " task(s) in the list.";
return "\n" + INDENT + "Now you have " + lst.size()
+ " task(s) in the list.";
}

/**
* Returns a response string listing all tasks containing the searching string
* Returns a response string
* listing all tasks containing the searching string.
*
* @param lst the task list
* @param command the command to be processed
Expand Down Expand Up @@ -243,7 +249,7 @@ private String handleFind(TaskList lst, String command) {
}

/**
* Returns a response string for a new task command
* Returns a response string for a new task command.
*
* @param lst the task list
* @param command the command to be processed
Expand All @@ -262,18 +268,20 @@ private String handleAdd(TaskList lst, String command, TaskType taskType) {
return format(new DeadlineEmptyBodyException().toString());
case E:
return format(new EventEmptyBodyException().toString());
default:
}
return format(new UnknownCommandException().toString());
}

lst.addOfType(description, taskType);
// a message to be printed when invoking a todo, event, or deadline
String messageAdded = "Got it. I've added this task:\n";
return format(messageAdded + MORE_INDENT + getMostRecentTask(lst).print() + getListCountMessage(lst));
return format(messageAdded + MORE_INDENT
+ getMostRecentTask(lst).print() + getListCountMessage(lst));
}

/**
* Returns the most recent task in the task list
* Returns the most recent task in the task list.
*
* @param lst the task list
* @return the most recent task
Expand All @@ -292,7 +300,7 @@ private String handleHelp() {
}

/**
* Returns respond message to be printed generated from user input
* Returns respond message to be printed generated from user input.
*
* @param lst the task list
* @return respond message by Duke
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/duke/Storage.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package duke;

import duke_exceptions.IllegalTaskTypeException;
import duke.exceptions.IllegalTaskTypeException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
Expand All @@ -13,7 +13,7 @@
* Represents a storage and deals with loading tasks from
* the file and saving tasks in the file.
*/
@SuppressWarnings("ALL")

public class Storage {
private File file;
Storage(Path path) {
Expand Down

0 comments on commit 52d8544

Please sign in to comment.