From 517ac8bdeb92a28b61916b7bf083062ca9f57ee6 Mon Sep 17 00:00:00 2001 From: Notmoo Date: Tue, 15 Aug 2017 21:46:48 +0200 Subject: [PATCH] =?UTF-8?q?Module=20Client=20:=20ajout=20=C3=A9cran=20stat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/pqt/client/Main.java | 4 ++ .../gui/modules/stat_screen/StatScreen.java | 29 +++++++++++ .../stat_screen/StatScreenController.java | 22 ++++++++ .../modules/stat_screen/StatScreenModel.java | 38 ++++++++++++++ .../modules/stat_screen/StatScreenView.java | 52 +++++++++++++++++++ .../listeners/IStatScreenModelListener.java | 7 +++ .../gui/ressources/strings/GUIStringTool.java | 4 ++ .../client/src/main/resources/dark-theme.css | 11 +++- 8 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatScreen.java create mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatScreenController.java create mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatScreenModel.java create mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatScreenView.java create mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/listeners/IStatScreenModelListener.java diff --git a/Workspace/client/src/main/java/com/pqt/client/Main.java b/Workspace/client/src/main/java/com/pqt/client/Main.java index f552abf4..8e364c0f 100644 --- a/Workspace/client/src/main/java/com/pqt/client/Main.java +++ b/Workspace/client/src/main/java/com/pqt/client/Main.java @@ -2,6 +2,7 @@ package com.pqt.client; import com.pqt.client.gui.main_frame.MainFrame; import com.pqt.client.gui.modules.sale_screen.SaleScreen; +import com.pqt.client.gui.modules.stat_screen.StatScreen; import com.pqt.client.gui.modules.stock_screen.StockScreen; import com.pqt.client.gui.ressources.components.generics.others.SideBar; import com.pqt.client.gui.ressources.components.generics.others.listeners.ISideBarListener; @@ -9,6 +10,7 @@ import com.pqt.client.gui.ressources.css.GUICssTool; import com.pqt.client.gui.ressources.strings.GUIStringTool; import com.pqt.client.module.account.AccountService; import com.pqt.client.module.sale.SaleService; +import com.pqt.client.module.stat.StatService; import com.pqt.client.module.stock.StockService; import javafx.application.Application; import javafx.scene.Scene; @@ -25,10 +27,12 @@ public class Main extends Application{ SaleService saleService = new SaleService(); StockService stockService = new StockService(); AccountService accountService = new AccountService(); + StatService statService = new StatService(); MainFrame mainFrame = new MainFrame(accountService); mainFrame.addModule(new SaleScreen(accountService, stockService, saleService)); mainFrame.addModule(new StockScreen(stockService)); + mainFrame.addModule(new StatScreen(statService)); Scene scene = new Scene(mainFrame.getPane(), 800, 600); scene.getStylesheets().clear(); diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatScreen.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatScreen.java new file mode 100644 index 00000000..3634cc8b --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatScreen.java @@ -0,0 +1,29 @@ +package com.pqt.client.gui.modules.stat_screen; + +import com.pqt.client.gui.modules.IGuiModule; +import com.pqt.client.gui.ressources.strings.GUIStringTool; +import com.pqt.client.module.stat.StatService; +import javafx.scene.layout.Pane; + +public class StatScreen implements IGuiModule { + + private StatScreenView view; + + public StatScreen(StatService statService) { + StatScreenModel model = new StatScreenModel(statService); + StatScreenController ctrl = new StatScreenController(model); + view = new StatScreenView(); + + ctrl.setView(view); + } + + @Override + public String getModuleName() { + return GUIStringTool.getStatGuiModuleName(); + } + + @Override + public Pane getPane() { + return view.getPane(); + } +} diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatScreenController.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatScreenController.java new file mode 100644 index 00000000..5f2510e3 --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatScreenController.java @@ -0,0 +1,22 @@ +package com.pqt.client.gui.modules.stat_screen; + +import com.pqt.client.gui.modules.stat_screen.listeners.IStatScreenModelListener; + +class StatScreenController implements IStatScreenModelListener{ + + private StatScreenModel model; + private StatScreenView view; + + StatScreenController(StatScreenModel model) { + this.model = model; + } + + void setView(StatScreenView view) { + this.view = view; + } + + @Override + public void onStatisticsChangedEvent() { + view.display(model.getStatistics()); + } +} diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatScreenModel.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatScreenModel.java new file mode 100644 index 00000000..2add8f38 --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatScreenModel.java @@ -0,0 +1,38 @@ +package com.pqt.client.gui.modules.stat_screen; + +import com.pqt.client.gui.modules.stat_screen.listeners.IStatScreenModelListener; +import com.pqt.client.module.stat.StatService; +import com.pqt.client.module.stat.listeners.IStatListener; +import com.pqt.client.module.stat.listeners.StatListenerAdapter; + +import javax.swing.event.EventListenerList; +import java.util.Arrays; +import java.util.Map; + +class StatScreenModel { + private EventListenerList listenerList; + private StatService statService; + + StatScreenModel(StatService statService) { + this.statService = statService; + listenerList = new EventListenerList(); + this.statService.addListener(new StatListenerAdapter() { + @Override + public void onGetStatSuccess() { + Arrays.stream(listenerList.getListeners(IStatScreenModelListener.class)).forEach(IStatScreenModelListener::onStatisticsChangedEvent); + } + }); + } + + Map getStatistics() { + return statService.getStats(); + } + + void addListener(IStatScreenModelListener l){ + listenerList.add(IStatScreenModelListener.class, l); + } + + void removeListener(IStatScreenModelListener l){ + listenerList.remove(IStatScreenModelListener.class, l); + } +} diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatScreenView.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatScreenView.java new file mode 100644 index 00000000..5fd5485d --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/StatScreenView.java @@ -0,0 +1,52 @@ +package com.pqt.client.gui.modules.stat_screen; + +import com.pqt.client.gui.ressources.components.generics.IFXComponent; +import com.sun.deploy.util.StringUtils; +import javafx.application.Platform; +import javafx.scene.control.TextArea; +import javafx.scene.layout.Pane; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +class StatScreenView implements IFXComponent { + + private TextArea statTextArea; + private Pane mainPane; + + StatScreenView() { + initGui(); + } + + private void initGui() { + mainPane = new Pane(); + mainPane.getStyleClass().add("main-module-pane"); + + statTextArea = new TextArea(); + mainPane.getChildren().add(statTextArea); + statTextArea.setId("stat-screen-text-area"); + statTextArea.setWrapText(true); + statTextArea.setEditable(false); + statTextArea.prefWidthProperty().bind(mainPane.widthProperty()); + statTextArea.prefHeightProperty().bind(mainPane.heightProperty()); + } + + void display(Map statistics){ + List lines = new ArrayList<>(); + + if(statistics!=null) + lines.addAll(statistics.keySet() + .stream() + .map(key->String.format(" * %s : %s", key, statistics.get(key))) + .collect(Collectors.toList())); + + Platform.runLater(()->statTextArea.setText(StringUtils.join(lines, "\n"))); + } + + @Override + public Pane getPane() { + return mainPane; + } +} diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/listeners/IStatScreenModelListener.java b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/listeners/IStatScreenModelListener.java new file mode 100644 index 00000000..c02c49f8 --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/gui/modules/stat_screen/listeners/IStatScreenModelListener.java @@ -0,0 +1,7 @@ +package com.pqt.client.gui.modules.stat_screen.listeners; + +import java.util.EventListener; + +public interface IStatScreenModelListener extends EventListener { + void onStatisticsChangedEvent(); +} diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/ressources/strings/GUIStringTool.java b/Workspace/client/src/main/java/com/pqt/client/gui/ressources/strings/GUIStringTool.java index c70207f8..4dcb8bd3 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/ressources/strings/GUIStringTool.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/ressources/strings/GUIStringTool.java @@ -214,6 +214,10 @@ public class GUIStringTool { public static IObjectStringRenderer getBooleanRenderer() { return bool->bool?"Oui":"Non"; } + + public static String getStatGuiModuleName() { + return "Statistiques"; + } } diff --git a/Workspace/client/src/main/resources/dark-theme.css b/Workspace/client/src/main/resources/dark-theme.css index 5049497a..4e154cd3 100644 --- a/Workspace/client/src/main/resources/dark-theme.css +++ b/Workspace/client/src/main/resources/dark-theme.css @@ -114,7 +114,7 @@ -fx-background-color: black; } -.text-field, .password-field, .choice-box { +.text-field, .password-field, .choice-box, .text-area { -fx-font-size: 12pt; -fx-font-family: "Segoe UI Semibold"; -fx-pref-width: 125; @@ -127,6 +127,15 @@ -fx-text-fill: #d8d8d8; } +.text-area .content { + -fx-background-color: #1d1d1d; + -fx-padding: 15 15 15 15; +} + +#stat-screen-text-area { + -fx-border-width: 0; +} + .button { -fx-padding: 5 22 5 22; -fx-border-color: #e2e2e2;