Skip to content

Commit

Permalink
Merge pull request #90 from daongochieu2810/v1.2b/better-gui
Browse files Browse the repository at this point in the history
Responsive GUI and JFoenix integration
  • Loading branch information
daongochieu2810 authored Oct 13, 2020
2 parents 54a1314 + 1d7a3f6 commit ae83360
Show file tree
Hide file tree
Showing 12 changed files with 3,504 additions and 50 deletions.
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ dependencies {
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: jUnitVersion

testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: jUnitVersion
compile 'com.jfoenix:jfoenix:9.0.10'
// FontAwesome
// Versions higher than 2.x are for Java 11
compile 'org.kordamp.ikonli:ikonli-javafx:2.4.0'
compile 'org.kordamp.ikonli:ikonli-fontawesome5-pack:2.4.0'
}

shadowJar {
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/seedu/address/ui/IngredientListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import java.util.logging.Logger;

import com.jfoenix.controls.JFXListCell;
import com.jfoenix.controls.JFXListView;

import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.layout.Region;
import seedu.address.commons.core.LogsCenter;
import seedu.address.model.recipe.Ingredient;
Expand All @@ -18,7 +19,7 @@ public class IngredientListPanel extends UiPart<Region> {
private final Logger logger = LogsCenter.getLogger(RecipeListPanel.class);

@FXML
private ListView<Ingredient> ingredientListView;
private JFXListView<Ingredient> ingredientListView;

/**
* Creates a {@code RecipeListPanel} with the given {@code ObservableList}.
Expand All @@ -32,7 +33,7 @@ public IngredientListPanel(ObservableList<Ingredient> ingredientList) {
/**
* Custom {@code ListCell} that displays the graphics of a {@code Recipe} using a {@code RecipeCard}.
*/
class IngredientListViewCell extends ListCell<Ingredient> {
class IngredientListViewCell extends JFXListCell<Ingredient> {
@Override
protected void updateItem(Ingredient ingredient, boolean empty) {
super.updateItem(ingredient, empty);
Expand Down
39 changes: 32 additions & 7 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package seedu.address.ui;

import java.io.IOException;
import java.util.logging.Logger;

import com.jfoenix.assets.JFoenixResources;
import com.jfoenix.controls.JFXDecorator;
import com.jfoenix.svg.SVGGlyph;
import com.jfoenix.svg.SVGGlyphLoader;

import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Scene;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextInputControl;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import seedu.address.commons.core.GuiSettings;
Expand Down Expand Up @@ -39,6 +46,11 @@ public class MainWindow extends UiPart<Stage> {
private ResultDisplay resultDisplay;
private HelpWindow helpWindow;

@FXML
private Scene mainScene;

@FXML
private BorderPane container;
@FXML
private StackPane commandBoxPlaceholder;

Expand All @@ -54,19 +66,14 @@ public class MainWindow extends UiPart<Stage> {
@FXML
private StackPane statusbarPlaceholder;

@FXML
private ImageView fridge;

/**
* Creates a {@code MainWindow} with the given {@code Stage} and {@code Logic}.
*/
public MainWindow(Stage primaryStage, Logic logic) {
super(FXML, primaryStage);

// Set dependencies
this.primaryStage = primaryStage;
this.logic = logic;
this.fridge.setImage(new Image("images/fridge.png"));

// Configure the UI
setWindowDefaultSize(logic.getGuiSettings());
Expand Down Expand Up @@ -168,6 +175,24 @@ public void handleHelp() {
}

void show() {
new Thread(() -> {
try {
SVGGlyphLoader.loadGlyphsFont(MainWindow.class.getResourceAsStream("/fonts/icomoon.svg"),
"icomoon.svg");
} catch (IOException ioExc) {
ioExc.printStackTrace();
}
}).start();

JFXDecorator decorator = new JFXDecorator(primaryStage, container);
decorator.setCustomMaximize(true);
decorator.setGraphic(new SVGGlyph(""));

mainScene.setRoot(decorator);
final ObservableList<String> stylesheets = mainScene.getStylesheets();
stylesheets.addAll(JFoenixResources.load("css/jfoenix-fonts.css").toExternalForm(),
JFoenixResources.load("css/jfoenix-design.css").toExternalForm(),
MainWindow.class.getResource("/css/wishful-shrinking.css").toExternalForm());
primaryStage.show();
}

Expand Down
6 changes: 0 additions & 6 deletions src/main/java/seedu/address/ui/RecipeCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
Expand Down Expand Up @@ -42,8 +40,6 @@ public class RecipeCard extends UiPart<Region> {
private Label instruction;
@FXML
private FlowPane tags;
@FXML
private ImageView recipeImageView;


/**
Expand All @@ -59,8 +55,6 @@ public RecipeCard(Recipe recipe, int displayedIndex) {
//Image image = new Image(recipe.getRecipeImage());
//recipeImageView = new ImageView(image);

recipeImageView.setImage(new Image(recipe.getRecipeImage()));

ingredients.setText(recipe.getIngredient().stream()
.map(item -> item.getQuantity() + " " + item.getValue())
.reduce("", (a, b) -> b.equals("") ? a : b + ", " + a));
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/seedu/address/ui/RecipeListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import java.util.logging.Logger;

import com.jfoenix.controls.JFXListCell;
import com.jfoenix.controls.JFXListView;

import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.layout.Region;
import seedu.address.commons.core.LogsCenter;
import seedu.address.model.recipe.Recipe;
Expand All @@ -18,7 +19,7 @@ public class RecipeListPanel extends UiPart<Region> {
private final Logger logger = LogsCenter.getLogger(RecipeListPanel.class);

@FXML
private ListView<Recipe> recipeListView;
private JFXListView<Recipe> recipeListView;

/**
* Creates a {@code RecipeListPanel} with the given {@code ObservableList}.
Expand All @@ -32,7 +33,7 @@ public RecipeListPanel(ObservableList<Recipe> recipeList) {
/**
* Custom {@code ListCell} that displays the graphics of a {@code Recipe} using a {@code RecipeCard}.
*/
class RecipeListViewCell extends ListCell<Recipe> {
class RecipeListViewCell extends JFXListCell<Recipe> {
@Override
protected void updateItem(Recipe recipe, boolean empty) {
super.updateItem(recipe, empty);
Expand Down
Loading

0 comments on commit ae83360

Please sign in to comment.