-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEV refs #31 : Added StrategySelectionView and dynamic view change ab…
…ility
- Loading branch information
Nathaël NOGUÈS
committed
Jul 27, 2016
1 parent
360eec3
commit e24ecd9
Showing
8 changed files
with
181 additions
and
58 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
avek-gui/src/main/java/fr/axonic/avek/gui/view/AbstractView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
avek-gui/src/main/java/fr/axonic/avek/gui/view/StrategySelectionView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
21 changes: 21 additions & 0 deletions
21
avek-gui/src/main/resources/fxml/views/StrategySelectionView.fxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |