Skip to content

Commit

Permalink
DEV refs #31 : Added StrategySelectionView and dynamic view change ab…
Browse files Browse the repository at this point in the history
…ility
  • Loading branch information
Nathaël NOGUÈS committed Jul 27, 2016
1 parent 360eec3 commit e24ecd9
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 58 deletions.
40 changes: 40 additions & 0 deletions avek-gui/src/main/java/fr/axonic/avek/gui/view/AbstractView.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
14 changes: 13 additions & 1 deletion avek-gui/src/main/java/fr/axonic/avek/gui/view/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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<PointerOnView> comboBox;

private AbstractView onCancelView;
private Consumer<AbstractView> 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<PointerOnView> 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<AbstractView> 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();
}
}
}

25 changes: 6 additions & 19 deletions avek-gui/src/main/java/fr/axonic/avek/gui/view/TreatView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
21 changes: 21 additions & 0 deletions avek-gui/src/main/resources/fxml/views/StrategySelectionView.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.layout.HBox?>
<fx:root xmlns:fx="http://javafx.com/fxml"
type="javafx.scene.layout.BorderPane">
<center>
<VBox>
<Label>Select a Strategy</Label>
<ComboBox fx:id="comboBox"/>
<HBox>
<Button fx:id="cancel" onAction="#onCancel">Cancel</Button>
<Button fx:id="submit" onAction="#onSubmit">Submit</Button>
</HBox>
</VBox>
</center>
</fx:root>

0 comments on commit e24ecd9

Please sign in to comment.