From 407d31f0eacbb99a75dd4b891441df66ade0bc78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Natha=C3=ABl=20NOGU=C3=88S?= Date: Wed, 13 Jul 2016 17:18:26 +0200 Subject: [PATCH] DEV refs #9 : Showing levels of subParameters --- .../axonic/avek/gui/view/MainController.java | 9 +- .../gui/view/parameters/ExpParameter.java | 69 ++++---- .../view/parameters/ExpParameterGroup.java | 80 ---------- .../gui/view/parameters/IExpParameter.java | 8 +- .../parameters/IExpParameterContainer.java | 6 - .../avek/gui/view/parameters/LevelMark.java | 47 ++++++ .../view/parameters/ParametersGridPane.java | 81 ---------- .../gui/view/parameters/ParametersPane.java | 151 ++++++++++++++++-- avek-gui/src/main/resources/fxml/gui.fxml | 5 +- .../fxml/parameters/parametersPane.fxml | 25 --- 10 files changed, 224 insertions(+), 257 deletions(-) delete mode 100644 avek-gui/src/main/java/fr/axonic/avek/gui/view/parameters/ExpParameterGroup.java delete mode 100644 avek-gui/src/main/java/fr/axonic/avek/gui/view/parameters/IExpParameterContainer.java create mode 100644 avek-gui/src/main/java/fr/axonic/avek/gui/view/parameters/LevelMark.java delete mode 100644 avek-gui/src/main/java/fr/axonic/avek/gui/view/parameters/ParametersGridPane.java delete mode 100644 avek-gui/src/main/resources/fxml/parameters/parametersPane.fxml diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/view/MainController.java b/avek-gui/src/main/java/fr/axonic/avek/gui/view/MainController.java index 7d8904b..a63e593 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/view/MainController.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/view/MainController.java @@ -17,6 +17,7 @@ import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.control.Button; +import javafx.scene.control.ScrollPane; import java.io.File; import java.io.IOException; @@ -32,10 +33,12 @@ public class MainController { private static Parent root; @FXML private Button btnStrategy; - @FXML private ParametersPane paneExpParameters; + @FXML private ScrollPane paneParameters; @FXML private ExpSubject expSubject; @FXML private JellyBeansSelector jellyBeansSelector; + private ParametersPane paneExpParameters; + private String getFileContent(String path) throws IOException, URISyntaxException { String res = ""; File f = new File(getClass().getClassLoader() @@ -49,6 +52,10 @@ private String getFileContent(String path) throws IOException, URISyntaxExceptio @FXML protected void initialize() throws Exception { + paneExpParameters = new ParametersPane(); + paneParameters.setContent(paneExpParameters); + + // TODO MOCK ONLY ↓↓↓ //////////////////////////////////////////////// String monitoredSystemJson = getFileContent("files/subjectFile.json"); diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/view/parameters/ExpParameter.java b/avek-gui/src/main/java/fr/axonic/avek/gui/view/parameters/ExpParameter.java index 0c2565d..8fe69cd 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/view/parameters/ExpParameter.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/view/parameters/ExpParameter.java @@ -3,69 +3,59 @@ import fr.axonic.avek.model.base.engine.AVar; import fr.axonic.avek.model.base.engine.FormatType; import javafx.event.ActionEvent; +import javafx.scene.Node; import javafx.scene.control.CheckBox; -import javafx.scene.control.Control; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import java.util.HashSet; import java.util.Set; -import java.util.function.Consumer; /** * Created by Nathaël N on 04/07/16. */ class ExpParameter implements IExpParameter { - // GUI Component private CheckBox markedUtil; - private Label paramName; + private LevelMark levelMark; + private Label paramTitle; private Label paramValue; private TextField minEquivRange; private TextField maxEquivRange; - public ExpParameter(AVar paramValue) { + ExpParameter(AVar paramValue, int level) { // Init elements markedUtil = new CheckBox(); markedUtil.setSelected(true); + markedUtil.setOnAction(this::onClickMarkedUtil); + GridPane.setColumnIndex(markedUtil, 0); - this.paramName = new Label(paramValue.getLabel()); - this.paramValue = new Label(" : "+paramValue.getValue().toString()); - if(paramValue.getFormat().getType() == FormatType.NUMBER) { - minEquivRange = new TextField(paramValue.getValue().toString()); - maxEquivRange = new TextField(paramValue.getValue().toString()); - } + levelMark = new LevelMark(level); + GridPane.setColumnIndex(levelMark, 1); - // Dispose on line - GridPane.setColumnIndex(markedUtil, 0); - GridPane.setColumnIndex(this.paramName, 1); - GridPane.setColumnIndex(this.paramValue, 2); - if(minEquivRange != null) - GridPane.setColumnIndex(minEquivRange, 3); - if(maxEquivRange != null) - GridPane.setColumnIndex(maxEquivRange, 4); + this.paramTitle = new Label(paramValue.getLabel()); + GridPane.setColumnIndex(this.paramTitle, 2); - // Linking action listeners - markedUtil.setOnAction(this::onClickMarkedUtil); - } - public void setParamName(String paramName) { - this.paramName.setText(paramName); - } + this.paramValue = new Label(" : "+paramValue.getValue().toString()); + GridPane.setColumnIndex(this.paramValue, 3); - public void setParamValue(String paramValue) { - this.paramValue.setText(paramValue); - } + if(paramValue.getFormat().getType() == FormatType.NUMBER) { + minEquivRange = new TextField(paramValue.getValue().toString()); + minEquivRange.setMaxWidth(70); + GridPane.setColumnIndex(minEquivRange, 4); - public boolean isMakedUtil() { - return !markedUtil.isIndeterminate() && markedUtil.isSelected(); + maxEquivRange = new TextField(paramValue.getValue().toString()); + maxEquivRange.setMaxWidth(70); + GridPane.setColumnIndex(maxEquivRange, 5); + } } private void onClickMarkedUtil(ActionEvent event) { boolean b = markedUtil.isSelected(); - paramName.setDisable(!b); + paramTitle.setDisable(!b); paramValue.setDisable(!b); if(minEquivRange != null) minEquivRange.setDisable(!b); @@ -73,24 +63,23 @@ private void onClickMarkedUtil(ActionEvent event) { maxEquivRange.setDisable(!b); } - @Override - public Set getElements() { - Set elts = new HashSet<>(); - elts.add(paramName); - elts.add(paramValue); + Set getElements() { + Set elts = new HashSet<>(); + elts.add(markedUtil); + elts.add(paramTitle); + elts.add(levelMark); + elts.add(paramValue); if(minEquivRange != null) elts.add(minEquivRange); - if(maxEquivRange != null) elts.add(maxEquivRange); - elts.add(markedUtil); - return elts; } + @Override public String getName() { - return paramName.getText(); + return paramTitle.getText(); } } diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/view/parameters/ExpParameterGroup.java b/avek-gui/src/main/java/fr/axonic/avek/gui/view/parameters/ExpParameterGroup.java deleted file mode 100644 index c828cf9..0000000 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/view/parameters/ExpParameterGroup.java +++ /dev/null @@ -1,80 +0,0 @@ -package fr.axonic.avek.gui.view.parameters; - -import fr.axonic.avek.model.base.engine.AList; -import fr.axonic.avek.model.base.engine.AVar; -import javafx.event.ActionEvent; -import javafx.scene.control.*; -import javafx.scene.layout.GridPane; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.function.Consumer; - -/** - * Created by Nathaël N on 04/07/16. - */ -class ExpParameterGroup implements IExpParameter, IExpParameterContainer { - // Graphical elements - private CheckBox markedUtil; - private Accordion accordion; - - // Util - private List expParameters; - private ParametersGridPane grid; - - public ExpParameterGroup(AList paramValue) { - // Init variables - this.expParameters = new ArrayList<>(); - - // Init elements - markedUtil = new CheckBox(); - markedUtil.setSelected(true); - - accordion = new Accordion(); - grid = new ParametersGridPane(); - TitledPane tp = new TitledPane(paramValue.getLabel(), grid); - accordion.getPanes().add(tp); - - // Dispose on line - GridPane.setColumnIndex(markedUtil, 0); - GridPane.setColumnIndex(accordion, 1); - GridPane.setColumnSpan(accordion, 4); - - // Linking action listeners - markedUtil.setOnAction(this::onClickMarkedUtil); - - paramValue.getEntities().forEach(this::addExpParameter); - } - - private boolean isMarkedUtil() { - return !markedUtil.isIndeterminate() && markedUtil.isSelected(); - } - private void onClickMarkedUtil(ActionEvent event) { - boolean newValue = isMarkedUtil(); - markedUtil.setSelected(newValue); - accordion.setDisable(!newValue); - - if(!newValue && accordion.getExpandedPane() != null) - accordion.getExpandedPane().setExpanded(false); - } - - public void addExpParameter(AVar avar) { - grid.addExpParameter(avar); - } - - - @Override - public Set getElements() { - Set elts = new HashSet<>(); - elts.add(accordion); - elts.add(markedUtil); - return elts; - } - - @Override - public String getName() { - return accordion.getPanes().get(0).getText(); - } -} diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/view/parameters/IExpParameter.java b/avek-gui/src/main/java/fr/axonic/avek/gui/view/parameters/IExpParameter.java index 6c35613..cf84852 100644 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/view/parameters/IExpParameter.java +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/view/parameters/IExpParameter.java @@ -1,14 +1,8 @@ package fr.axonic.avek.gui.view.parameters; -import javafx.scene.control.Control; - -import java.util.Set; -import java.util.function.Consumer; - /** - * Created by Nathaël N on 04/07/16. + * Created by Nathaël N on 13/07/16. */ public interface IExpParameter { - Set getElements(); String getName(); } diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/view/parameters/IExpParameterContainer.java b/avek-gui/src/main/java/fr/axonic/avek/gui/view/parameters/IExpParameterContainer.java deleted file mode 100644 index 81f4331..0000000 --- a/avek-gui/src/main/java/fr/axonic/avek/gui/view/parameters/IExpParameterContainer.java +++ /dev/null @@ -1,6 +0,0 @@ -package fr.axonic.avek.gui.view.parameters; - -/** - * Created by Nathaël N on 13/07/16. - */ -public interface IExpParameterContainer {} diff --git a/avek-gui/src/main/java/fr/axonic/avek/gui/view/parameters/LevelMark.java b/avek-gui/src/main/java/fr/axonic/avek/gui/view/parameters/LevelMark.java new file mode 100644 index 0000000..3de2664 --- /dev/null +++ b/avek-gui/src/main/java/fr/axonic/avek/gui/view/parameters/LevelMark.java @@ -0,0 +1,47 @@ +package fr.axonic.avek.gui.view.parameters; + +import javafx.scene.control.Label; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.HBox; +import javafx.scene.layout.Pane; +import javafx.scene.layout.Priority; +import javafx.scene.text.Text; + +/** + * Created by Nathaël N on 13/07/16. + */ +public class LevelMark extends HBox { + private final String TRANSPARENT = "-fx-background-color: #fff0"; + private final String BLUE = "-fx-background-color: #2f25"; + private final String ARROW = "-fx-background-color: #2fa5"; + + public LevelMark(int level) { + this(level, false); + } + public LevelMark(int level, boolean withArrow) { + for(int i=0; i expParameters; - - ParametersGridPane() { - expParameters = new ArrayList<>(); - } - - public boolean addExpParameter(AList alist) { - int i = expParameters.size(); - - ExpParameterGroup epg = new ExpParameterGroup(alist); - - // Adding graphical elements to the GUI - for (Control c : epg.getElements()) { - GridPane.setRowIndex(c, i); - this.getChildren().add(c); - } - - // Adding to the list - return expParameters.add(epg); - } - public boolean addExpParameter(AVar avar) { - int i = expParameters.size(); - - ExpParameter ep = new ExpParameter(avar); - - // Adding graphical elements to the GUI - for (Control c : ep.getElements()) { - GridPane.setRowIndex(c, i); - this.getChildren().add(c); - } - - // Adding to the list - return expParameters.add(ep); - } - - public synchronized IExpParameter rmParameter(String name) { - // searching parameter index - int i = -1; - - // int j=0+1 because of title line at index 0 - for (int j = 1; j < expParameters.size(); j++) - if (expParameters.get(j).getName().equals(name)) { - i = j; - break; - } - - if(i==-1) - return null; - - // Removing parameter from view - for(Control c : expParameters.get(i).getElements()) { - c.setDisable(true); - this.getChildren().remove(c); - } - - // Decal following parameters - for(int j=i+1; j expParameters; - expParameters.add(null); + /** + * Define a sub ParametersGrid + * @param level Deep level of this parameter grid (= his parent level+1) + * @param title Title of the ParametersGrid + */ + private ParametersPane(final int level, final String title) { + expParameters = new ArrayList<>(); + this.level = level+1; + + /* + [ checkbox ][ Levelmark ][ Title & ... ] + [] ↓ Main ParametersGrid's title + [] |↓ ParametersGrid's title + [] || A subelement : value ... + [] || A subelement : value ... + [] | Another element : value ... + */ + + // Generating GUI component + markedUtil = new CheckBox(); + markedUtil.setSelected(true); + markedUtil.setOnAction(this::onClickMarkedUtil); + GridPane.setColumnIndex(markedUtil, 0); + GridPane.setRowIndex(markedUtil, 0); + + levelMark = new LevelMark(level, true); + GridPane.setColumnIndex(levelMark, 1); + GridPane.setRowIndex(levelMark, 0); + + label = new Label(); + label.setText(title); + GridPane.setColumnIndex(label, 2); + //GridPane.setColumnSpan(label, 4); + GridPane.setRowIndex(label, 0); + + // Adding GUI component + getChildren().add(markedUtil); + getChildren().add(levelMark); + getChildren().add(label); + } + + + /** + * Define a ParametersPane as Root + */ + public ParametersPane() { + this(0, ""); + markedUtil.setVisible(false); + levelMark.setVisible(false); + label.setVisible(false); + } + + public boolean addExpParameter(AList alist) { + ParametersPane epg = new ParametersPane(level, alist.getLabel()); + + // Adding sub elements + alist.getEntities().forEach(epg::addExpParameter); + + // Adding to the GUI + GridPane.setColumnSpan(epg, 6); + GridPane.setRowIndex(epg, expParameters.size()+1); // +1 because of title line + this.getChildren().add(epg); + + // Adding to the list + return expParameters.add(epg); + } + public boolean addExpParameter(AVar avar) { + ExpParameter ep = new ExpParameter(avar, level); + + int i = expParameters.size()+1; // +1 because of title line + + // Adding graphical elements to the GUI + for (Node n : ep.getElements()) { + GridPane.setRowIndex(n, i); + this.getChildren().add(n); + } + + // Adding to the list + return expParameters.add(ep); + } + + synchronized IExpParameter rmParameter(String name) { + // searching parameter index + int indexToRm = -1; + + // int j=0+1 because of title line at index 0 + for (int j = 1; j < expParameters.size(); j++) + if (expParameters.get(j).getName().equals(name)) { + indexToRm = j; + break; + } + + if(indexToRm==-1) + return null; + + // Removing from view & shift view + for(Node n : new ArrayList<>(getChildren())) { + int index = GridPane.getRowIndex(n); + + if(indexToRm == index) + getChildren().remove(n); + else if(index > indexToRm) + GridPane.setRowIndex(n, index-1); + } + + // Removing parameter from list + return expParameters.remove(indexToRm); + } + + private void onClickMarkedUtil(ActionEvent event) { + boolean b = markedUtil.isSelected(); + + // Removing from view & shift view + for(Node n : getChildren()) { + int index = GridPane.getRowIndex(n); + + if (index > 0) { + n.setVisible(b); + n.setManaged(b); + } + } + } + + @Override + public String getName() { + return null; } } diff --git a/avek-gui/src/main/resources/fxml/gui.fxml b/avek-gui/src/main/resources/fxml/gui.fxml index 1faa166..6d9cab6 100644 --- a/avek-gui/src/main/resources/fxml/gui.fxml +++ b/avek-gui/src/main/resources/fxml/gui.fxml @@ -1,6 +1,5 @@ - @@ -19,9 +18,7 @@
- - - +