mirror of
https://github.com/klmp200/PQT_Gestionnaire_vente_stock.git
synced 2024-12-22 15:31:08 +00:00
Module Client : ajout écran stat
This commit is contained in:
parent
eb594e0293
commit
517ac8bdeb
@ -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();
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
@ -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<String, String> getStatistics() {
|
||||
return statService.getStats();
|
||||
}
|
||||
|
||||
void addListener(IStatScreenModelListener l){
|
||||
listenerList.add(IStatScreenModelListener.class, l);
|
||||
}
|
||||
|
||||
void removeListener(IStatScreenModelListener l){
|
||||
listenerList.remove(IStatScreenModelListener.class, l);
|
||||
}
|
||||
}
|
@ -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<String, String> statistics){
|
||||
List<String> 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;
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.pqt.client.gui.modules.stat_screen.listeners;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
public interface IStatScreenModelListener extends EventListener {
|
||||
void onStatisticsChangedEvent();
|
||||
}
|
@ -214,6 +214,10 @@ public class GUIStringTool {
|
||||
public static IObjectStringRenderer<Boolean> getBooleanRenderer() {
|
||||
return bool->bool?"Oui":"Non";
|
||||
}
|
||||
|
||||
public static String getStatGuiModuleName() {
|
||||
return "Statistiques";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user