From e24ecd959e9bf481ca9541973b0e2f9706b82720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Natha=C3=ABl=20NOGU=C3=88S?= Date: Wed, 27 Jul 2016 10:26:36 +0200 Subject: [PATCH] DEV refs #31 : Added StrategySelectionView and dynamic view change ability --- .../fr/axonic/avek/gui/view/AbstractView.java | 40 +++++++++ .../avek/gui/view/EstablishEffectView.java | 25 ++---- .../axonic/avek/gui/view/GeneralizedView.java | 25 ++---- .../fr/axonic/avek/gui/view/MainFrame.java | 14 ++- .../avek/gui/view/StrategySelectionView.java | 89 +++++++++++++++++++ .../fr/axonic/avek/gui/view/TreatView.java | 25 ++---- ...fectView.fxml => EstablishEffectView.fxml} | 0 .../fxml/views/StrategySelectionView.fxml | 21 +++++ 8 files changed, 181 insertions(+), 58 deletions(-) create mode 100644 avek-gui/src/main/java/fr/axonic/avek/gui/view/StrategySelectionView.java rename avek-gui/src/main/resources/fxml/views/{EtablishEffectView.fxml => EstablishEffectView.fxml} (100%) create mode 100644 avek-gui/src/main/resources/fxml/views/StrategySelectionView.fxml diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/view/AbstractView.java b/avek-gui/src/main/java/fr/axonic/avek/gui/view/AbstractView.java index 5cabc0d..6f45d33 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/view/AbstractView.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/view/AbstractView.java @@ -1,11 +1,51 @@ package fr.axonic.avek.gui.view; +import javafx.fxml.FXMLLoader; import javafx.scene.layout.BorderPane; +import org.apache.log4j.Logger; + +import java.io.IOException; +import java.net.URL; /** * Created by Nathaƫl N on 26/07/16. */ public abstract class AbstractView extends BorderPane { + private final static Logger logger = Logger.getLogger(AbstractView.class); + + private boolean loaded; + + public AbstractView() { + loaded = false; + } + + public boolean isLoaded() { + return loaded; + } + public final void load() { + if(loaded) + return; + + this.onLoad(); + } + protected abstract void onLoad(); + protected final void load(String path) { + if(loaded) + return; + + URL fxml = AbstractView.class.getClassLoader() + .getResource(path); + + FXMLLoader fxmlLoader = new FXMLLoader(fxml); + fxmlLoader.setController(this); + fxmlLoader.setRoot(this); + try { + fxmlLoader.load(); + loaded = true; + } catch (IOException | RuntimeException e) { + logger.fatal("Impossible to load FXML", e); + } + } } diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/view/EstablishEffectView.java b/avek-gui/src/main/java/fr/axonic/avek/gui/view/EstablishEffectView.java index da511da..c56eacf 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/view/EstablishEffectView.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/view/EstablishEffectView.java @@ -9,17 +9,12 @@ import fr.axonic.avek.model.base.engine.AList; import javafx.event.ActionEvent; import javafx.fxml.FXML; -import javafx.fxml.FXMLLoader; import javafx.scene.control.Button; import org.apache.log4j.Logger; -import java.io.IOException; -import java.net.URL; - public class EstablishEffectView extends AbstractView { private final static Logger logger = Logger.getLogger(EstablishEffectView.class); - private final static URL FXML - = EstablishEffectView.class.getClassLoader().getResource("fxml/views/GeneralizedView.fxml"); + private final static String FXML = "fxml/views/EstablishEffectView.fxml"; @FXML private Button btnStrategy; @@ -30,19 +25,11 @@ public class EstablishEffectView extends AbstractView { @FXML private JellyBeansSelector jellyBeansSelector; - // Should be public - public EstablishEffectView() { - FXMLLoader fxmlLoader = new FXMLLoader(FXML); - fxmlLoader.setController(this); - fxmlLoader.setRoot(this); - - logger.info("Loading EstablishEffectView... (fxml)"); - try { - fxmlLoader.load(); - logger.debug("EstablishEffectView loaded."); - } catch (IOException e) { - logger.fatal("Impossible to load FXML for EstablishEffectView", e); - } + @Override + protected void onLoad() { + logger.info("Loading TreatView..."); + super.load(FXML); + logger.debug("TreatView loaded."); } @FXML diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/view/GeneralizedView.java b/avek-gui/src/main/java/fr/axonic/avek/gui/view/GeneralizedView.java index bf6c7e8..0d9155c 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/view/GeneralizedView.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/view/GeneralizedView.java @@ -9,17 +9,12 @@ import fr.axonic.avek.model.base.engine.AList; import javafx.event.ActionEvent; import javafx.fxml.FXML; -import javafx.fxml.FXMLLoader; import javafx.scene.control.Button; import org.apache.log4j.Logger; -import java.io.IOException; -import java.net.URL; - public class GeneralizedView extends AbstractView { private final static Logger logger = Logger.getLogger(GeneralizedView.class); - private final static URL FXML - = GeneralizedView.class.getClassLoader().getResource("fxml/views/GeneralizedView.fxml"); + private final static String FXML = "fxml/views/GeneralizedView.fxml"; @FXML private Button btnStrategy; @@ -30,19 +25,11 @@ public class GeneralizedView extends AbstractView { @FXML private JellyBeansSelector jellyBeansSelector; - // Should be public - public GeneralizedView() { - FXMLLoader fxmlLoader = new FXMLLoader(FXML); - fxmlLoader.setController(this); - fxmlLoader.setRoot(this); - - logger.info("Loading GeneralizedView... (fxml)"); - try { - fxmlLoader.load(); - logger.debug("GeneralizedView loaded."); - } catch (IOException e) { - logger.fatal("Impossible to load FXML for GeneralizedView", e); - } + @Override + protected void onLoad() { + logger.info("Loading GeneralizedView..."); + super.load(FXML); + logger.debug("GeneralizedView loaded."); } @FXML diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/view/MainFrame.java b/avek-gui/src/main/java/fr/axonic/avek/gui/view/MainFrame.java index 7714300..acdd1ce 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/view/MainFrame.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/view/MainFrame.java @@ -43,13 +43,25 @@ public MainFrame() { @FXML private void onClicStrategyButton(ActionEvent event) { + AbstractView ancientview = view; + StrategySelectionView ssv = new StrategySelectionView(); + setView(ssv); + ssv.setAvailableChoices( + ancientview instanceof TreatView?ancientview:new TreatView(), + ancientview instanceof EstablishEffectView?ancientview:new EstablishEffectView(), + ancientview instanceof GeneralizedView?ancientview:new GeneralizedView()); + ssv.setOnCancel(ancientview); + ssv.onSetView(this::setView); + + btnStrategy.setDisable(true); } public void setView(AbstractView view) { setCenter(view); // remove abstract view currently loaded this.view = view; + view.load(); + btnStrategy.setDisable(false); } - } diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/view/StrategySelectionView.java b/avek-gui/src/main/java/fr/axonic/avek/gui/view/StrategySelectionView.java new file mode 100644 index 0000000..f554288 --- /dev/null +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/view/StrategySelectionView.java @@ -0,0 +1,89 @@ +package fr.axonic.avek.gui.view; + +import fr.axonic.avek.gui.components.MonitoredSystemPane; +import fr.axonic.avek.gui.components.parameters.GeneralizedParametersPane; +import fr.axonic.avek.gui.components.results.JellyBeansSelector; +import fr.axonic.avek.gui.model.json.Jsonifier; +import fr.axonic.avek.gui.model.structure.ExpEffect; +import fr.axonic.avek.model.MonitoredSystem; +import fr.axonic.avek.model.base.engine.AEntity; +import fr.axonic.avek.model.base.engine.AList; +import javafx.collections.FXCollections; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.control.Button; +import javafx.scene.control.ComboBox; +import javafx.scene.control.ListCell; +import javafx.scene.control.ListView; +import javafx.util.Callback; +import org.apache.log4j.Logger; + +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; + +public class StrategySelectionView extends AbstractView { + private final static Logger logger = Logger.getLogger(StrategySelectionView.class); + private final static String FXML = "fxml/views/StrategySelectionView.fxml"; + + @FXML + private Button submit; + @FXML + private Button cancel; + @FXML + private ComboBox comboBox; + + private AbstractView onCancelView; + private Consumer onSetViewMethod; + + @Override + protected void onLoad() { + logger.info("Loading StrategySelectionView..."); + super.load(FXML); + logger.debug("StrategySelectionView loaded."); + } + + @FXML + void onSubmit(ActionEvent event) { + onSetView(comboBox.getValue().view); + } + @FXML + void onCancel(ActionEvent event) { + onSetView(onCancelView); + } + + void setAvailableChoices(AbstractView... views) { + List lpov = new ArrayList<>(); + for(AbstractView av : views) + lpov.add(new PointerOnView(av)); + + comboBox.setItems(FXCollections.observableArrayList(lpov)); + } + void setOnCancel(AbstractView view) { + onCancelView = view; + } + + private void onSetView(AbstractView view) { + onSetViewMethod.accept(view); + } + void onSetView(Consumer onSetViewMethod) { + this.onSetViewMethod = onSetViewMethod; + } + + private class PointerOnView { + final AbstractView view; + + private PointerOnView(AbstractView view) { + this.view = view; + } + + @Override + public String toString() { + return view.getClass().getSimpleName(); + } + } +} + diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/view/TreatView.java b/avek-gui/src/main/java/fr/axonic/avek/gui/view/TreatView.java index e6dc620..dac91f3 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/view/TreatView.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/view/TreatView.java @@ -8,17 +8,12 @@ import fr.axonic.avek.model.base.engine.AList; import javafx.event.ActionEvent; import javafx.fxml.FXML; -import javafx.fxml.FXMLLoader; import javafx.scene.control.Button; import org.apache.log4j.Logger; -import java.io.IOException; -import java.net.URL; - public class TreatView extends AbstractView { private final static Logger logger = Logger.getLogger(TreatView.class); - private final static URL FXML - = TreatView.class.getClassLoader().getResource("fxml/views/GeneralizedView.fxml"); + private final static String FXML = "fxml/views/TreatView.fxml"; @FXML private Button btnStrategy; @@ -27,19 +22,11 @@ public class TreatView extends AbstractView { @FXML private MonitoredSystemPane monitoredSystemPane; - // Should be public - public TreatView() { - FXMLLoader fxmlLoader = new FXMLLoader(FXML); - fxmlLoader.setController(this); - fxmlLoader.setRoot(this); - - logger.info("Loading TreatView... (fxml)"); - try { - fxmlLoader.load(); - logger.debug("TreatView loaded."); - } catch (IOException e) { - logger.fatal("Impossible to load FXML for TreatView", e); - } + @Override + protected void onLoad() { + logger.info("Loading TreatView..."); + super.load(FXML); + logger.debug("TreatView loaded."); } @FXML diff --git a/avek-gui/src/main/resources/fxml/views/EtablishEffectView.fxml b/avek-gui/src/main/resources/fxml/views/EstablishEffectView.fxml similarity index 100% rename from avek-gui/src/main/resources/fxml/views/EtablishEffectView.fxml rename to avek-gui/src/main/resources/fxml/views/EstablishEffectView.fxml diff --git a/avek-gui/src/main/resources/fxml/views/StrategySelectionView.fxml b/avek-gui/src/main/resources/fxml/views/StrategySelectionView.fxml new file mode 100644 index 0000000..6e22803 --- /dev/null +++ b/avek-gui/src/main/resources/fxml/views/StrategySelectionView.fxml @@ -0,0 +1,21 @@ + + + + + + + + + +
+ + + + + + + + +
+