mirror of
https://github.com/klmp200/PQT_Gestionnaire_vente_stock.git
synced 2024-11-25 18:44:16 +00:00
Module Client : correction du bug de mise à jour des éléments; ajout des clss/interfaces IFXFrame, FrameManager et FrameScene
This commit is contained in:
parent
aad90bb989
commit
ee9b4428a8
@ -1,5 +1,6 @@
|
||||
package com.pqt.client;
|
||||
|
||||
import com.pqt.client.gui.FrameManager;
|
||||
import com.pqt.client.gui.main_frame.MainFrame;
|
||||
import com.pqt.client.gui.main_frame.listeners.IMainFrameModelListener;
|
||||
import com.pqt.client.gui.modules.account_screen.AccountScreen;
|
||||
@ -26,56 +27,6 @@ public class Main extends Application{
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
|
||||
ClientBackEndModuleManager moduleManager = new ClientBackEndModuleManager(null);
|
||||
|
||||
|
||||
MainFrame mainFrame = new MainFrame(moduleManager.getAccountService());
|
||||
mainFrame.addModule(new SaleScreen(moduleManager.getAccountService(), moduleManager.getStockService(), moduleManager.getSaleService()), true);
|
||||
mainFrame.addModule(new StockScreen(moduleManager.getStockService(), moduleManager.getAccountService()));
|
||||
mainFrame.addModule(new StatScreen(moduleManager.getStatService()));
|
||||
mainFrame.addModule(new AccountScreen(moduleManager.getAccountService()));
|
||||
Scene mainFrameScene = initScene(mainFrame.getPane());
|
||||
|
||||
StartupFrame startupFrame = new StartupFrame(moduleManager.getAccountService(), moduleManager.getNetworkService());
|
||||
Scene startupFrameScene = initScene(startupFrame.getPane());
|
||||
|
||||
mainFrame.addFrameModelListener(getMainFrameListener(primaryStage, startupFrameScene));
|
||||
startupFrame.addFrameModelListener(getStartupFrameListener(primaryStage, mainFrameScene));
|
||||
|
||||
ToastFactory.init(primaryStage);
|
||||
primaryStage.setTitle(GUIStringTool.getAppTitle());
|
||||
primaryStage.setScene(startupFrameScene);
|
||||
primaryStage.show();
|
||||
}
|
||||
|
||||
private Scene initScene(Pane pane){
|
||||
Scene scene = new Scene(pane);
|
||||
scene.getStylesheets().clear();
|
||||
scene.getStylesheets().addAll(getClass().getResource(GUICssTool.getCssFilePath()).toExternalForm());
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
private IStartupFrameModelListener getStartupFrameListener(Stage primaryStage, Scene sceneToDisplay){
|
||||
return () -> {
|
||||
Platform.runLater(()->trySwitchScene(primaryStage, sceneToDisplay, true));
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private IMainFrameModelListener getMainFrameListener(Stage primaryStage, Scene sceneToDisplay){
|
||||
return () -> trySwitchScene(primaryStage, sceneToDisplay, false);
|
||||
}
|
||||
|
||||
private void trySwitchScene(Stage primaryStage, Scene sceneToDisplay, boolean maximize){
|
||||
if(sceneToDisplay!=null) {
|
||||
primaryStage.hide();
|
||||
primaryStage.setScene(sceneToDisplay);
|
||||
primaryStage.setMaximized(maximize);
|
||||
primaryStage.show();
|
||||
}else{
|
||||
Platform.exit();
|
||||
}
|
||||
new FrameManager(primaryStage).show();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,71 @@
|
||||
package com.pqt.client.gui;
|
||||
|
||||
import com.pqt.client.gui.main_frame.MainFrame;
|
||||
import com.pqt.client.gui.main_frame.listeners.IMainFrameModelListener;
|
||||
import com.pqt.client.gui.modules.account_screen.AccountScreen;
|
||||
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.toast.ToastFactory;
|
||||
import com.pqt.client.gui.ressources.strings.GUIStringTool;
|
||||
import com.pqt.client.gui.startup_frame.StartupFrame;
|
||||
import com.pqt.client.gui.startup_frame.listeners.frame.IStartupFrameModelListener;
|
||||
import com.pqt.client.module.ClientBackEndModuleManager;
|
||||
import javafx.application.Platform;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class FrameManager {
|
||||
|
||||
private FrameScene mainFrameScene;
|
||||
private FrameScene startupFrameScene;
|
||||
private Stage stage;
|
||||
|
||||
public FrameManager(Stage stage) {
|
||||
this.stage = stage;
|
||||
|
||||
ClientBackEndModuleManager moduleManager = new ClientBackEndModuleManager(null);
|
||||
|
||||
MainFrame mainFrame = new MainFrame(moduleManager.getAccountService());
|
||||
mainFrame.addModule(new SaleScreen(moduleManager.getAccountService(), moduleManager.getStockService(), moduleManager.getSaleService()), true);
|
||||
mainFrame.addModule(new StockScreen(moduleManager.getStockService(), moduleManager.getAccountService()));
|
||||
mainFrame.addModule(new StatScreen(moduleManager.getStatService()));
|
||||
mainFrame.addModule(new AccountScreen(moduleManager.getAccountService()));
|
||||
mainFrameScene = new FrameScene(mainFrame);
|
||||
|
||||
StartupFrame startupFrame = new StartupFrame(moduleManager.getAccountService(), moduleManager.getNetworkService());
|
||||
startupFrameScene = new FrameScene(startupFrame);
|
||||
|
||||
mainFrame.addFrameModelListener(getMainFrameListener());
|
||||
startupFrame.addFrameModelListener(getStartupFrameListener());
|
||||
|
||||
ToastFactory.init(this.stage);
|
||||
this.stage.setTitle(GUIStringTool.getAppTitle());
|
||||
this.stage.setScene(startupFrameScene);
|
||||
this.stage.show();
|
||||
}
|
||||
|
||||
public void show(){
|
||||
stage.show();
|
||||
}
|
||||
|
||||
private IStartupFrameModelListener getStartupFrameListener(){
|
||||
return () -> Platform.runLater(()->trySwitchScene(stage, mainFrameScene, true));
|
||||
}
|
||||
|
||||
|
||||
private IMainFrameModelListener getMainFrameListener(){
|
||||
return () -> Platform.runLater(()->trySwitchScene(stage, startupFrameScene, false));
|
||||
}
|
||||
|
||||
private void trySwitchScene(Stage stage, FrameScene sceneToDisplay, boolean maximize){
|
||||
if(sceneToDisplay!=null) {
|
||||
stage.hide();
|
||||
stage.setScene(sceneToDisplay);
|
||||
stage.setMaximized(maximize);
|
||||
stage.show();
|
||||
sceneToDisplay.requestFrameUpdate();
|
||||
}else{
|
||||
Platform.exit();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.pqt.client.gui;
|
||||
|
||||
import com.pqt.client.gui.ressources.components.generics.frames.IFXFrame;
|
||||
import com.pqt.client.gui.ressources.css.GUICssTool;
|
||||
import javafx.scene.Scene;
|
||||
|
||||
public class FrameScene extends Scene {
|
||||
|
||||
private IFXFrame frame;
|
||||
|
||||
public FrameScene(IFXFrame frame) {
|
||||
super(frame.getPane());
|
||||
|
||||
this.frame = frame;
|
||||
|
||||
getStylesheets().clear();
|
||||
getStylesheets().addAll(getClass().getResource(GUICssTool.getCssFilePath()).toExternalForm());
|
||||
}
|
||||
|
||||
public void requestFrameUpdate(){
|
||||
frame.requestFrameUpdate();
|
||||
}
|
||||
}
|
@ -3,11 +3,12 @@ package com.pqt.client.gui.main_frame;
|
||||
import com.pqt.client.gui.main_frame.listeners.IMainFrameModelListener;
|
||||
import com.pqt.client.gui.modules.IGuiModule;
|
||||
import com.pqt.client.gui.ressources.components.generics.IFXComponent;
|
||||
import com.pqt.client.gui.ressources.components.generics.frames.IFXFrame;
|
||||
import com.pqt.client.gui.startup_frame.listeners.frame.IStartupFrameModelListener;
|
||||
import com.pqt.client.module.account.AccountService;
|
||||
import javafx.scene.layout.Pane;
|
||||
|
||||
public class MainFrame implements IFXComponent {
|
||||
public class MainFrame implements IFXFrame {
|
||||
|
||||
private MainFrameView view;
|
||||
private MainFrameController ctrl;
|
||||
@ -35,6 +36,9 @@ public class MainFrame implements IFXComponent {
|
||||
model.addListener(l);
|
||||
}
|
||||
|
||||
public void requestFrameUpdate(){
|
||||
ctrl.updateView();
|
||||
}
|
||||
@Override
|
||||
public Pane getPane() {
|
||||
return view.getPane();
|
||||
|
@ -0,0 +1,7 @@
|
||||
package com.pqt.client.gui.ressources.components.generics.frames;
|
||||
|
||||
import com.pqt.client.gui.ressources.components.generics.IFXComponent;
|
||||
|
||||
public interface IFXFrame extends IFXComponent{
|
||||
void requestFrameUpdate();
|
||||
}
|
@ -1,19 +1,21 @@
|
||||
package com.pqt.client.gui.startup_frame;
|
||||
|
||||
import com.pqt.client.gui.ressources.components.generics.IFXComponent;
|
||||
import com.pqt.client.gui.ressources.components.generics.frames.IFXFrame;
|
||||
import com.pqt.client.gui.startup_frame.listeners.frame.IStartupFrameModelListener;
|
||||
import com.pqt.client.module.account.AccountService;
|
||||
import com.pqt.client.module.network.NetworkService;
|
||||
import javafx.scene.layout.Pane;
|
||||
|
||||
public class StartupFrame implements IFXComponent{
|
||||
public class StartupFrame implements IFXFrame{
|
||||
|
||||
private StartupFrameView view;
|
||||
private StartupFrameController ctrl;
|
||||
private StartupFrameModel model;
|
||||
|
||||
public StartupFrame(AccountService accountService, NetworkService networkService) {
|
||||
model = new StartupFrameModel(accountService, networkService);
|
||||
StartupFrameController ctrl = new StartupFrameController(model);
|
||||
ctrl = new StartupFrameController(model);
|
||||
model.addListener(ctrl);
|
||||
|
||||
view = new StartupFrameView(ctrl);
|
||||
@ -29,4 +31,9 @@ public class StartupFrame implements IFXComponent{
|
||||
public Pane getPane() {
|
||||
return view.getPane();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestFrameUpdate() {
|
||||
ctrl.updateView();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user