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

- adds change theme feature #153

Merged
merged 5 commits into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 30 additions & 3 deletions src/main/java/seedu/address/commons/core/GuiSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,43 @@ public class GuiSettings implements Serializable {

private static final double DEFAULT_HEIGHT = 600;
private static final double DEFAULT_WIDTH = 900;
private static final String DEFAULT_STYLESHEET = "view/DarkTheme.css";

private final double windowWidth;
private final double windowHeight;
private String styleSheet;
private final Point windowCoordinates;

public GuiSettings() {
windowWidth = DEFAULT_WIDTH;
windowHeight = DEFAULT_HEIGHT;
styleSheet = DEFAULT_STYLESHEET;
windowCoordinates = null; // null represent no coordinates
}

public GuiSettings(double windowWidth, double windowHeight, int xPosition, int yPosition) {
public GuiSettings(double windowWidth, double windowHeight,
int xPosition, int yPosition,
String styleSheet) {
this.windowWidth = windowWidth;
this.windowHeight = windowHeight;
windowCoordinates = new Point(xPosition, yPosition);
this.styleSheet = styleSheet;
}

public GuiSettings(double windowWidth, double windowHeight,
int xPosition, int yPosition) {
this.windowWidth = windowWidth;
this.windowHeight = windowHeight;
windowCoordinates = new Point(xPosition, yPosition);
this.styleSheet = DEFAULT_STYLESHEET;
}

public String getStyleSheets() {
return styleSheet;
}

public void setStyleSheet(String styleSheet) {
this.styleSheet = styleSheet;
}

public double getWindowWidth() {
Expand Down Expand Up @@ -54,7 +76,8 @@ public boolean equals(Object other) {

return windowWidth == o.windowWidth
&& windowHeight == o.windowHeight
&& Objects.equals(windowCoordinates, o.windowCoordinates);
&& Objects.equals(windowCoordinates, o.windowCoordinates)
&& styleSheet.equals(o.getStyleSheets());
}

@Override
Expand All @@ -67,7 +90,11 @@ public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Width : " + windowWidth + "\n");
sb.append("Height : " + windowHeight + "\n");
sb.append("Position : " + windowCoordinates);
sb.append("Position : " + windowCoordinates + "\n");
sb.append("Stylesheet: " + styleSheet);
return sb.toString();
}



}
1 change: 1 addition & 0 deletions src/main/java/seedu/address/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class Messages {
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_FLASHCARD_DISPLAYED_INDEX = "The flashcard index provided is invalid";
public static final String MESSAGE_INVALID_DEADLINE_DISPLAYED_INDEX = "The deadline index provided is invalid";
public static final String MESSAGE_INVALID_THEME = "The theme is not available. Existing theme: light, dark";
public static final String MESSAGE_FLASHCARD_LISTED_OVERVIEW = "%1$d flash cards listed!";
public static final String MESSAGE_UNKNOWN_TEST_COMMAND = "Unknown test command";
public static final String MESSAGE_EXPORT_IO_EXCEPTION = "There was an error in writing to the file.\n"
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@


/**
* Adds a flashCard to the address book.
* Adds a flashCard to the storage.
*/
public class AddCommand extends Command {

public static final String COMMAND_WORD = "add";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a flashCard to the address book. "
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a flashCard to the Application. "
+ "Parameters: "
+ PREFIX_QUESTION + "QUESTION "
+ PREFIX_ANSWER + "ANSWER "
+ PREFIX_RATING + "RATING "
+ "[" + PREFIX_CATEGORY + "TAG]...\n"
+ "[" + PREFIX_CATEGORY + "CATEGORY]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_QUESTION + "End-to-end delay "
+ PREFIX_ANSWER + "2L/R (assuming no other delay) "
Expand Down
59 changes: 59 additions & 0 deletions src/main/java/seedu/address/logic/commands/SetThemeCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//@@author shutingy
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.ui.MainWindow;
import seedu.address.ui.ResultDisplay;

/**
* Change the theme of the GUI
*/
public class SetThemeCommand extends Command {

public static final String COMMAND_WORD = "theme";

public static final String MESSAGE_SUCCESS = "Theme changed to %s";

private String styleSheet;
private String color;
/**
* Creates a SetThemeCommand to change the theme of the gui
*/
public SetThemeCommand(String styleSheet, String color) {
this.styleSheet = styleSheet;
this.color = color;
}

@Override
public CommandResult execute(Model model) throws CommandException {
/* todo: gui version
System.out.println(Main.class.getResourceAsStream("/images/Light.png"));
Image light = new Image(Main.class.getResourceAsStream("/images/Light.png"));
Image dark = new Image(Main.class.getResourceAsStream("/images/Dark.png"));
System.out.println(light.getUrl());
ImageView iv = new ImageView();
AnchorPane an = new AnchorPane();
an.getChildren().add(iv);
Scene scene = new Scene(an);
Scene scene = new Scene(new ThemeWindow().getView());
Stage stage = new Stage();
stage.setTitle("Theme");
stage.show();

GuiSettings guiSettings = model.getGuiSettings();
GuiSettings newGuiSettings = new GuiSettings(guiSettings.getWindowWidth(),
guiSettings.getWindowHeight(), guiSettings.getWindowCoordinates().x,
guiSettings.getWindowCoordinates().y, styleSheet);
model.setGuiSettings(newGuiSettings);

*/
Comment on lines +34 to +54
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to remove in the final release

requireNonNull(model);
MainWindow.setStylesheet(styleSheet);
ResultDisplay.setColor(color);
model.setStyleSheet(styleSheet);
return new CommandResult(String.format(MESSAGE_SUCCESS, styleSheet));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.RateQuestionCommand;
import seedu.address.logic.commands.RemoveCommand;
import seedu.address.logic.commands.SetThemeCommand;
import seedu.address.logic.commands.ShowAnswerCommand;
import seedu.address.logic.commands.StartCommand;
import seedu.address.logic.commands.StatsCommand;
Expand Down Expand Up @@ -153,6 +154,8 @@ private Command parseNormalCommand(Matcher matcher) throws ParseException {
case ExportCommand.COMMAND_WORD:
return new ExportCommandParser().parse(arguments);

case SetThemeCommand.COMMAND_WORD:
return new SetThemeCommandParser().parse(arguments);
default:
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//@@author shutingy
package seedu.address.logic.parser;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_THEME;

import seedu.address.logic.commands.SetThemeCommand;
import seedu.address.logic.parser.exceptions.ParseException;

/**
* Parses input arguments and creates a new SetThemeCommand object
*/
public class SetThemeCommandParser implements Parser<SetThemeCommand> {

@Override
public SetThemeCommand parse(String userInput) throws ParseException {
String styleSheet = null;
String color = null;
String trimedInput = userInput.trim();
if (trimedInput.equals("light")) {
color = "black";
styleSheet = "view/LightTheme.css";
} else if (trimedInput.equals("dark")) {
color = "white";
styleSheet = "view/DarkTheme.css";
}
if (styleSheet.isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_THEME));
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider rearranging the if conditions to handle exceptions first, and use else if for the 3rd one for slightly better readability


return new SetThemeCommand(styleSheet, color);
}
}
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public interface Model {
*/
void setGuiSettings(GuiSettings guiSettings);

void setStyleSheet(String string);

/**
* Returns the user prefs' address book file path.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public void setGuiSettings(GuiSettings guiSettings) {
userPrefs.setGuiSettings(guiSettings);
}

public void setStyleSheet(String styleSheet) {
userPrefs.setStyleSheet(styleSheet);
}

@Override
public Path getKeyboardFlashCardsFilePath() {
return userPrefs.getKeyboardFlashCardsFilePath();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/model/UserPrefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public void setGuiSettings(GuiSettings guiSettings) {
this.guiSettings = guiSettings;
}

public void setStyleSheet(String styleSheet) {
guiSettings.setStyleSheet(styleSheet);
}
public Path getKeyboardFlashCardsFilePath() {
return keyboardFlashCardsFilePath;
}
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/seedu/address/model/flashcard/FlashCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,14 @@ public int hashCode() {
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append(getQuestion())
builder.append("Question: ")
.append(getQuestion())
.append(" Answer: ")
.append(getAnswer())
.append(" Categories: ");
getCategories().forEach(builder::append);
.append(getAnswer());
if (!getCategories().isEmpty()) {
builder.append(" Categories: ");
getCategories().forEach(builder::append);
}
return builder.toString();
}

}
22 changes: 18 additions & 4 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
*/
public class MainWindow extends UiPart<Stage> {

private static String stylesheet;
private static final String FXML = "MainWindow.fxml";
private static Stage primaryStage;

private final Logger logger = LogsCenter.getLogger(getClass());

private Stage primaryStage;
private Logic logic;

// Independent Ui parts residing in this Ui container
Expand Down Expand Up @@ -66,10 +67,10 @@ public MainWindow(Stage primaryStage, Logic logic) {
// Set dependencies
this.primaryStage = primaryStage;
this.logic = logic;

//primaryStage.getScene().getStylesheets().add("view/LightTheme.css");
// Configure the UI
setWindowDefaultSize(logic.getGuiSettings());

setStyleSheet(logic.getGuiSettings());
setAccelerators();

helpWindow = new HelpWindow();
Expand Down Expand Up @@ -147,6 +148,18 @@ private void setWindowDefaultSize(GuiSettings guiSettings) {
primaryStage.setY(guiSettings.getWindowCoordinates().getY());
}
}
//@@ author shutingy
public static void setStyleSheet(GuiSettings guiSettings) {
stylesheet = guiSettings.getStyleSheets();
primaryStage.getScene().getStylesheets().add(stylesheet);
}
//@@ author shutingy
public static void setStylesheet(String newStylesheet) {
primaryStage.getScene().getStylesheets().remove(stylesheet);
stylesheet = newStylesheet;
primaryStage.getScene().getStylesheets().add(stylesheet);
}


/**
* Opens the help window or focuses on it if it's already opened.
Expand All @@ -170,7 +183,8 @@ void show() {
@FXML
private void handleExit() {
GuiSettings guiSettings = new GuiSettings(primaryStage.getWidth(), primaryStage.getHeight(),
(int) primaryStage.getX(), (int) primaryStage.getY());
(int) primaryStage.getX(), (int) primaryStage.getY(),
stylesheet);
logic.setGuiSettings(guiSettings);
helpWindow.hide();
primaryStage.hide();
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/seedu/address/ui/ResultDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,35 @@
import static java.util.Objects.requireNonNull;

import javafx.fxml.FXML;
import javafx.scene.control.TextArea;
import javafx.scene.layout.Region;
import javafx.scene.paint.Paint;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;

/**
* A ui for the status bar that is displayed at the header of the application.
*/
public class ResultDisplay extends UiPart<Region> {

private static final String FXML = "ResultDisplay.fxml";

private static String color = "white";
@FXML
private TextArea resultDisplay;
private TextFlow resultDisplay;

public ResultDisplay() {
super(FXML);
}

public static void setColor(String newColor) {
color = newColor;
}

public void setFeedbackToUser(String feedbackToUser) {
requireNonNull(feedbackToUser);
resultDisplay.setText(feedbackToUser);
Text text = new Text(feedbackToUser);
text.setFill(Paint.valueOf(color));
resultDisplay.getChildren().clear();
resultDisplay.getChildren().add(text);
}

}
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/ui/UiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class UiManager implements Ui {

private static final Logger logger = LogsCenter.getLogger(UiManager.class);
private static final String ICON_APPLICATION = "/images/icon.png";

private static String theme = "view/DarkTheme.css";
private Logic logic;
private MainWindow mainWindow;

Expand Down Expand Up @@ -63,7 +63,7 @@ void showAlertDialogAndWait(Alert.AlertType type, String title, String headerTex
private static void showAlertDialogAndWait(Stage owner, AlertType type, String title, String headerText,
String contentText) {
final Alert alert = new Alert(type);
alert.getDialogPane().getStylesheets().add("view/DarkTheme.css");
alert.getDialogPane().getStylesheets().add(theme);
alert.initOwner(owner);
alert.setTitle(title);
alert.setHeaderText(headerText);
Expand Down
Binary file added src/main/resources/images/Dark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/images/Light.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/main/resources/view/CategoryListPanel.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
</center>
</BorderPane>

<ListView fx:id="categoryListView" VBox.vgrow="ALWAYS" />
<ListView fx:id="categoryListView" prefHeight="20" VBox.vgrow="ALWAYS" />

</VBox>