Commit 21d28eee authored by Ivan Dages's avatar Ivan Dages
Browse files

ui for linking components and controllers

parent c8bdccaf
......@@ -142,6 +142,9 @@ public class Nomad3DEditor extends Application {
}
Logger.getLogger("nomad-3d").info("Starting " + TITLE + "...");
// TODO DEBUG
// NomadLinker.getInstance().displayProperties();
model = null;
this.scene = null;
......
package fr.ill.ics.n3d.gui;
import java.text.DecimalFormat;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Optional;
......@@ -11,11 +13,14 @@ import fr.ill.ics.n3d.model.Axis;
import fr.ill.ics.n3d.model.Component;
import fr.ill.ics.n3d.model.ConfigParams;
import fr.ill.ics.n3d.model.Axis.Type;
import fr.ill.ics.n3d.link.Nomad3DController;
import fr.ill.ics.n3d.link.NomadLinker;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.transformation.SortedList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
......@@ -30,6 +35,8 @@ import javafx.scene.control.CheckMenuItem;
import javafx.scene.control.ColorPicker;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
......@@ -43,7 +50,7 @@ import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
......@@ -396,26 +403,33 @@ public class EditorMenuBar extends MenuBar {
TabPane scenePane = new TabPane();
Scene displayScene = new Scene(scenePane);
Stage displayStage = new Stage(StageStyle.UTILITY);
displayStage.setTitle(displayAxisItem.getText());
displayStage.setTitle(displayAxisItem.getText() + " - " + selectedComponent.getName());
displayStage.setScene(displayScene);
displayStage.initOwner(Nomad3DEditor.getInstance().getStage());
GridPane nomad3DPane = new GridPane();
nomad3DPane.setPrefSize(500, 200);
nomad3DPane.setPrefSize(250, 200);
nomad3DPane.setVgap(5);
nomad3DPane.setHgap(10);
nomad3DPane.setAlignment(Pos.CENTER);
scenePane.getTabs().add(new Tab("Nomad 3D", nomad3DPane));
GridPane.setMargin(nomad3DPane, new Insets(10));
DecimalFormat df = new DecimalFormat("#.##");
String dirStr = "(" + df.format(selectedAxis.getDirection().getX()) + ", "
+ df.format(selectedAxis.getDirection().getY()) + ", "
+ df.format(selectedAxis.getDirection().getZ()) + ")";
String posStr = "(" + df.format(selectedAxis.getPosition().getX()) + ", "
+ df.format(selectedAxis.getPosition().getY()) + ", "
+ df.format(selectedAxis.getPosition().getZ()) + ")";
int i = 0;
nomad3DPane.addRow(i++, new Label("Type :"), new Label(selectedAxis.getType().toString()));
nomad3DPane.addRow(i++, new Label("Method :"), new Label(selectedAxis.getMethod().toString()));
nomad3DPane.addRow(i++, new Label("Direction :"), new Label(selectedAxis.getDirection().toString()));
nomad3DPane.addRow(i++, new Label("Position :"), new Label(selectedAxis.getPosition().toString()));
nomad3DPane.addRow(i++, new Label("Min value :"), new Label(Double.toString(selectedAxis.getMinValue())));
nomad3DPane.addRow(i++, new Label("Median value :"), new Label(Double.toString(selectedAxis.getMedianValue())));
nomad3DPane.addRow(i++, new Label("Max value :"), new Label(Double.toString(selectedAxis.getMaxValue())));
nomad3DPane.addRow(i++, new Label("Direction :"), new Label(dirStr));
nomad3DPane.addRow(i++, new Label("Position :"), new Label(posStr));
nomad3DPane.addRow(i++, new Label("Min value :"), new Label(df.format(selectedAxis.getMinValue())));
nomad3DPane.addRow(i++, new Label("Median value :"), new Label(df.format(selectedAxis.getMedianValue())));
nomad3DPane.addRow(i++, new Label("Max value :"), new Label(df.format(selectedAxis.getMaxValue())));
GridPane nomadPane = new GridPane();
nomadPane.setVgap(5);
......@@ -423,13 +437,94 @@ public class EditorMenuBar extends MenuBar {
nomadPane.setAlignment(Pos.CENTER);
scenePane.getTabs().add(new Tab("Nomad", nomadPane));
GridPane.setMargin(nomadPane, new Insets(10));
// TODO
nomadPane.addRow(0, new Label("TODO"));
Nomad3DController selectedController = selectedComponent.getController();
if (selectedController == null) {
Label noLinkText = new Label("No controller associated with\n" + selectedComponent.getName());
noLinkText.setTextAlignment(TextAlignment.CENTER);
nomadPane.addColumn(0, noLinkText);
} else {
i = 0;
nomadPane.addRow(i++, new Label("Name :"), new Label(selectedController.getName()));
nomadPane.addRow(i++, new Label("Type :"), new Label(selectedController.getType().toString()));
nomadPane.addRow(i++, new Label("Actual position :"), new Label(Double.toString(selectedController.getActualPosition())));
nomadPane.addRow(i++, new Label("Offset position :"), new Label(Double.toString(selectedController.getOffsetPosition())));
nomadPane.addRow(i++, new Label("Wanted position :"), new Label(Double.toString(selectedController.getWantedPosition())));
nomadPane.addRow(i++, new Label("Min position :"), new Label(Double.toString(selectedController.getMinPosition())));
nomadPane.addRow(i++, new Label("Max position :"), new Label(Double.toString(selectedController.getMaxPosition())));
}
displayStage.show();
});
axisMenu.getItems().addAll(addAxisItem, calibrateAxisItem, displayAxisItem);
MenuItem linkAxisItem = new MenuItem("Link axis");
linkAxisItem.setOnAction(event -> {
if (Nomad3DEditor.getInstance().getModel() == null || Nomad3DEditor.getInstance().getRoot() == null) {
return;
}
final Component selectedComponent = selectComponent(calibrateAxisItem.getText());
final Axis selectedAxis = (selectedComponent == null) ? null : selectedComponent.getAxis();
if (selectedAxis == null) {
// Error alert already display in selectComponent(String)
return;
}
GridPane scenePane = new GridPane();
scenePane.setAlignment(Pos.CENTER);
scenePane.setVgap(5);
scenePane.setHgap(10);
Scene linkScene = new Scene(scenePane);
Stage linkStage = new Stage(StageStyle.UTILITY);
linkStage.setTitle(linkAxisItem.getText());
linkStage.setScene(linkScene);
linkStage.initOwner(Nomad3DEditor.getInstance().getStage());
ListView<Nomad3DController> controllersList = new ListView<>();
for (Nomad3DController controller : NomadLinker.getInstance().getControllers()) {
controllersList.getItems().add(controller);
}
controllersList.setItems(new SortedList<>(controllersList.getItems(),
(Nomad3DController o1, Nomad3DController o2) -> {
return o1.getName().compareTo(o2.getName());
}
));
scenePane.addRow(0, controllersList);
controllersList.setPrefWidth(200);
GridPane.setColumnSpan(controllersList, GridPane.REMAINING);
Button selectButton = new Button("Select");
selectButton.setPrefWidth(100);
selectButton.setDefaultButton(true);
selectButton.setOnAction(selEvent -> {
Nomad3DController selectedController = controllersList.getSelectionModel().getSelectedItem();
linkStage.close();
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle(addAxisItem.getText());
alert.setContentText("Link component \"" + selectedComponent.getName() + "\" to " + selectedController + " ?");
Optional<ButtonType> res = alert.showAndWait();
if (res.isPresent()) {
if (res.get() == ButtonType.OK) {
selectedComponent.setController(selectedController);
selectedController.setComponent(selectedComponent);
}
}
});
Button cancelButton = new Button("Cancel");
cancelButton.setPrefWidth(100);
cancelButton.setCancelButton(true);
cancelButton.setOnAction(cancelEvent -> {
linkStage.close();
});
scenePane.addRow(1, selectButton, cancelButton);
GridPane.setMargin(scenePane, new Insets(10));
linkStage.show();
});
axisMenu.getItems().addAll(addAxisItem, calibrateAxisItem, linkAxisItem, displayAxisItem);
MenuItem modifyMaterialItem = new MenuItem("Modify material");
modifyMaterialItem.setOnAction(new EventHandler<ActionEvent>() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment