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

generel dashboard pane #8

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
39 changes: 39 additions & 0 deletions src/main/java/org/anjeyy/soba/common/DummyView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.anjeyy.soba.common;

import com.jfoenix.controls.JFXMasonryPane;
import java.util.Random;
import javafx.scene.Parent;
import javafx.scene.control.Label;

public class DummyView implements CustomStyleSheet, MainView {

private static final Random RANDOM = new Random();

private final JFXMasonryPane mainContainer;

public DummyView() {
this.mainContainer = createMainContainer();
}

private JFXMasonryPane createMainContainer() {
JFXMasonryPane root = new JFXMasonryPane();
root.setId("dummyView");
for (int i = 0; i < 100; i++) {
Label label = new Label(i + "");
label.setPrefSize(RANDOM.nextInt(100), RANDOM.nextInt(100));
label.setStyle(
"-fx-background-color:rgb(" +
RANDOM.nextInt(255) + ","
+ RANDOM.nextInt(255) + ","
+ RANDOM.nextInt(255) +
")");
root.getChildren().add(label);
}
return root;
}

@Override
public Parent asParent() {
return mainContainer;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.anjeyy.soba.dashboard;

public class DashboardController {
}
69 changes: 69 additions & 0 deletions src/main/java/org/anjeyy/soba/dashboard/DashboardModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package org.anjeyy.soba.dashboard;

import javafx.beans.binding.DoubleBinding;
import javafx.beans.property.ReadOnlyDoubleProperty;
import javafx.beans.property.ReadOnlyDoubleWrapper;
import javafx.geometry.Insets;
import org.anjeyy.soba.screen.ScreenModel;

public class DashboardModel {

private final Insets masonryRegionPadding;
private final ReadOnlyDoubleWrapper yearButtonWidth;
private final ReadOnlyDoubleWrapper yearButtonHeight;

public DashboardModel(ScreenModel screenModel) {
this.masonryRegionPadding = initMasonryPanePadding(screenModel);
this.yearButtonWidth = initYearButtonWrapper(screenModel);
this.yearButtonHeight = initYearButtonHeightWrapper(screenModel);
bindYearButtonScalingSize(screenModel);
}

private static Insets initMasonryPanePadding(ScreenModel screenModel) {
double initialHeight = screenModel.getInitialHeight() * 0.1;
return new Insets(initialHeight);
}

private static ReadOnlyDoubleWrapper initYearButtonWrapper(ScreenModel screenModel) {
DoubleBinding widthScaledProperty = scaleLogoWidthProperty(screenModel);
return new ReadOnlyDoubleWrapper(widthScaledProperty.get());
}

private static ReadOnlyDoubleWrapper initYearButtonHeightWrapper(ScreenModel screenModel) {
DoubleBinding heightScaledProperty = scaleLogoHeightProperty(screenModel);
return new ReadOnlyDoubleWrapper(heightScaledProperty.get());
}

private void bindYearButtonScalingSize(ScreenModel screenModel) {
DoubleBinding scaledWidth = scaleLogoWidthProperty(screenModel);
yearButtonWidth.bind(scaledWidth);
DoubleBinding scaledHeight = scaleLogoHeightProperty(screenModel);
yearButtonHeight.bind(scaledHeight);
}

private static DoubleBinding scaleLogoWidthProperty(ScreenModel screenModel) {
ReadOnlyDoubleProperty widthProperty = screenModel.widthProperty();
return scaleLogoProperty(widthProperty);
}

private static DoubleBinding scaleLogoHeightProperty(ScreenModel screenModel) {
ReadOnlyDoubleProperty heightProperty = screenModel.heightProperty();
return scaleLogoProperty(heightProperty);
}

private static DoubleBinding scaleLogoProperty(ReadOnlyDoubleProperty readOnlyDoubleProperty) {
return readOnlyDoubleProperty.divide(8);
}

public Insets masonryRegionPadding() {
return masonryRegionPadding;
}

public ReadOnlyDoubleWrapper yearButtonWidthProperty() {
return yearButtonWidth;
}

public ReadOnlyDoubleWrapper yearButtonHeightProperty() {
return yearButtonHeight;
}
}
93 changes: 73 additions & 20 deletions src/main/java/org/anjeyy/soba/dashboard/DashboardView.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,90 @@
package org.anjeyy.soba.dashboard;

import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXButton.ButtonType;
import com.jfoenix.controls.JFXMasonryPane;
import java.util.Random;
import com.jfoenix.svg.SVGGlyph;
import java.util.ArrayList;
import java.util.List;
import javafx.beans.binding.Bindings;
import javafx.geometry.Pos;
import javafx.scene.Parent;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import org.anjeyy.soba.common.CustomStyleSheet;
import org.anjeyy.soba.common.MainView;

public class DashboardView implements CustomStyleSheet, MainView {

private static final Random RANDOM = new Random();

private final DashboardController dashboardController;
private final DashboardModel dashboardModel;
private final List<StackPane> yearButtons;
private final JFXMasonryPane mainContainer;

public DashboardView() {
this.mainContainer = createMainContainer();

public DashboardView(DashboardController dashboardController, DashboardModel dashboardModel) {
this.dashboardController = dashboardController;
this.dashboardModel = dashboardModel;
this.yearButtons = createYearButtons();
this.mainContainer = createMasonryPane();
}

private JFXMasonryPane createMainContainer() {
JFXMasonryPane root = new JFXMasonryPane();
root.setId("dashBoardMainContainer");
for (int i = 0; i < 100; i++) {
Label label = new Label(i + "");
label.setPrefSize(RANDOM.nextInt(100), RANDOM.nextInt(100));
label.setStyle(
"-fx-background-color:rgb(" +
RANDOM.nextInt(255) + ","
+ RANDOM.nextInt(255) + ","
+ RANDOM.nextInt(255) +
")");
root.getChildren().add(label);
private List<StackPane> createYearButtons() {
List<StackPane> result = new ArrayList<>();
//loaded from model
for (int i = 2021; i > 2010; i--) {
String s = String.valueOf(i);
JFXButton yearLabel = new JFXButton(s);
yearLabel.setId("year" + s);
yearLabel.prefWidthProperty().bind(dashboardModel.yearButtonWidthProperty());
yearLabel.prefHeightProperty().bind(dashboardModel.yearButtonHeightProperty());

//ToDo: upper & middle green with year button
// lower is red to indicate expense/cost intention
VBox vBox = new VBox(yearLabel);
vBox.setAlignment(Pos.CENTER);

//ToDo: upper & middle layout with fancy button
JFXButton signalButton = new JFXButton("~");
signalButton.setButtonType(ButtonType.RAISED);
signalButton.setStyle("-fx-background-radius: 40");
signalButton.setScaleX(0);
signalButton.setScaleY(0);
SVGGlyph glyph = new SVGGlyph(-1,
"test",
"M1008 6.286q18.857 13.714 15.429 36.571l-146.286 877.714q-2.857 16.571-18.286 25.714-8 4.571-17.714 4.571-6.286 "
+ "0-13.714-2.857l-258.857-105.714-138.286 168.571q-10.286 13.143-28 13.143-7.429 "
+ "0-12.571-2.286-10.857-4-17.429-13.429t-6.571-20.857v-199.429l493.714-605.143-610.857 "
+ "528.571-225.714-92.571q-21.143-8-22.857-31.429-1.143-22.857 18.286-33.714l950.857-548.571q8.571-5.143 18.286-5.143"
+ " 11.429 0 20.571 6.286z",
Color.WHITE);
glyph.setSize(20, 20);
signalButton.setGraphic(glyph);
signalButton.translateYProperty()
.bind(
Bindings.createDoubleBinding(
() -> vBox.getBoundsInParent().getHeight() - signalButton.getHeight() / 2,
signalButton.boundsInParentProperty(),
signalButton.heightProperty())
);

StackPane yearContainer = new StackPane();
yearContainer.getChildren().addAll(vBox, signalButton);

result.add(yearContainer);
}
return root;
return result;
}

private JFXMasonryPane createMasonryPane() {
JFXMasonryPane jfxMasonryPane = new JFXMasonryPane();
jfxMasonryPane.setId("dashBoardMainContainer");
jfxMasonryPane.setPadding(dashboardModel.masonryRegionPadding());
jfxMasonryPane.setCenterShape(true);
CustomStyleSheet.super.add(jfxMasonryPane, "year-button");
jfxMasonryPane.getChildren().addAll(yearButtons);
return jfxMasonryPane;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ final boolean isInsideBottomBorder(MouseEvent event) {

final boolean isInsideLeftBorder(MouseEvent event) {
double xMousePos = event.getX();
double leftResizeBorder = stage.getX() + RESIZE_BORDER;
return xMousePos < leftResizeBorder;
return xMousePos < RESIZE_BORDER;
}

abstract void handleMouseRelease(MouseEvent event);
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/org/anjeyy/soba/scene/DashboardScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import javafx.scene.Parent;
import org.anjeyy.soba.common.MainView;
import org.anjeyy.soba.dashboard.DashboardController;
import org.anjeyy.soba.dashboard.DashboardModel;
import org.anjeyy.soba.dashboard.DashboardView;
import org.anjeyy.soba.screen.ScreenModel;

public class DashboardScene implements SceneView {

Expand All @@ -13,7 +16,10 @@ private DashboardScene() {
}

private DashboardView createDashboardView() {
return new DashboardView();
ScreenModel screenModel = ScreenModel.INSTANCE;
DashboardController dashboardController = new DashboardController();
DashboardModel dashboardModel = new DashboardModel(screenModel);
return new DashboardView(dashboardController, dashboardModel);
}

static DashboardScene create() {
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/org/anjeyy/soba/scene/DummyScene.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.anjeyy.soba.scene;

import javafx.scene.Parent;
import org.anjeyy.soba.common.DummyView;
import org.anjeyy.soba.common.MainView;

public class DummyScene implements SceneView {

private final DummyView dashboardView;

private DummyScene() {
this.dashboardView = createDummyView();
}

private DummyView createDummyView() {
return new DummyView();
}

static DummyScene create() {
return new DummyScene();
}

@Override
public MainView createView() {
return dashboardView;
}

@Override
public Parent asParent() {
return dashboardView.asParent();
}
}
3 changes: 2 additions & 1 deletion src/main/java/org/anjeyy/soba/scene/SceneManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
public enum SceneManager {

ENTRY_SCREEN(WelcomeScene.create()),
DASHBOARD(DashboardScene.create());
DASHBOARD(DashboardScene.create()),
DUMMY(DummyScene.create());

private static final WindowToolbarView mainContainer = createMainWindowContainer();

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/anjeyy/soba/window/WindowToolbarView.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,8 @@ private void loadCssStyle(Scene scene) {
URL mainCssUrl = WindowToolbarView.class.getClassLoader().getResource("css-style/main.css");
scene.getStylesheets()
.add(Objects.requireNonNull(mainCssUrl, "Could not load main.css file.").toExternalForm());
URL dashboardCssUrl = WindowToolbarView.class.getClassLoader().getResource("css-style/dashboard.css");
scene.getStylesheets()
.add(Objects.requireNonNull(dashboardCssUrl, "Could not load dashboard.css file.").toExternalForm());
}
}
13 changes: 13 additions & 0 deletions src/main/resources/css-style/dashboard.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* ToDo shadow for year boxes
*/

.year-button .jfx-button {
-jfx-button-type: RAISED;
-fx-text-fill: rgb(0, 0, 0);
-fx-font-weight: bold;
-fx-alignment: center;
-fx-font-size: 1.25em;
-fx-background-color: rgb(79, 98, 126);
-fx-effect: dropshadow(three-pass-box, rgba(0, 0, 0, 0.8), 10, 0, 0, 0);
}
3 changes: 2 additions & 1 deletion src/main/resources/css-style/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
}

.window-jfx-box {
-fx-background-color: linear-gradient(to bottom left, #525252, #606060);
-fx-background-color: linear-gradient(to bottom left, #4a709f, #4677a9),
radial-gradient(center 50% 50%, radius 50%, #5781a4, rgba(42, 42, 42, 0.2));
-fx-border-color: rgba(35, 35, 35, 0.5);
-fx-border-insets: 0;
-fx-border-width: 1;
Expand Down