Commit b8b33c4b authored by legoc's avatar legoc
Browse files

Added rename component operation

parent fa8a5c9c
......@@ -25,6 +25,7 @@ import fr.ill.ics.n3d.operations.NewComponentOperation;
import fr.ill.ics.n3d.operations.Operations;
import fr.ill.ics.n3d.operations.OperationsSerializer;
import fr.ill.ics.n3d.operations.RemoveComponentOperation;
import fr.ill.ics.n3d.operations.RenameComponentOperation;
import fr.ill.ics.n3d.operations.SetAxisOperation;
import fr.ill.ics.n3d.operations.SetMaterialOperation;
import javafx.application.Platform;
......@@ -216,9 +217,12 @@ public class EditorMenuBar extends MenuBar {
MenuItem editAxisItem = new MenuItem("Edit Axis");
editAxisItem.setAccelerator(new KeyCodeCombination(KeyCode.E, KeyCombination.CONTROL_DOWN));
editAxisItem.setOnAction(event -> {
// Check the selection.
if (Nomad3DEditor.getInstance().getModel() == null || Nomad3DEditor.getInstance().getModel().getRoot() == null) {
return;
}
HashSet<Component> selectedComponents = Component.excludeComponentsWithParentIn(Nomad3DEditor.getInstance().getModel().getSelection());
if (selectedComponents.isEmpty()) {
Alert alert = new Alert(AlertType.WARNING);
......@@ -227,6 +231,7 @@ public class EditorMenuBar extends MenuBar {
alert.showAndWait();
return;
}
Component modifiedComponent = null;
if (selectedComponents.size() > 1) {
Alert alert = new Alert(AlertType.INFORMATION);
......@@ -1103,6 +1108,150 @@ public class EditorMenuBar extends MenuBar {
updateScene();
});
///////////////////////////////////////////////////////////////////////////////////////
// Rename component menu
MenuItem renameComponentItem = new MenuItem("Rename Component");
renameComponentItem.setOnAction(event -> {
// Check the selection.
if (Nomad3DEditor.getInstance().getModel() == null || Nomad3DEditor.getInstance().getModel().getRoot() == null) {
return;
}
HashSet<Component> selectedComponents = Component.excludeComponentsWithParentIn(Nomad3DEditor.getInstance().getModel().getSelection());
if (selectedComponents.isEmpty()) {
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle(editAxisItem.getText());
alert.setContentText("Empty selection.");
alert.showAndWait();
return;
}
Component modifiedComponent = null;
if (selectedComponents.size() > 1) {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle(editAxisItem.getText());
alert.setContentText("Select only one Component.");
alert.showAndWait();
} else {
modifiedComponent = selectedComponents.iterator().next();
}
if (modifiedComponent == null) {
return;
}
final Component component = modifiedComponent;
///////////////////////////////////////////////////////////////////////////////////
// Name
Label newNameLabel = new Label("New Name : ");
TextField newNameField = new TextField("");
newNameField.setAlignment(Pos.TOP_LEFT);
newNameField.setPrefColumnCount(25);
///////////////////////////////////////////////////////////////////////////////////
// Layout
GridPane scenePane = new GridPane();
scenePane.setAlignment(Pos.CENTER);
Scene scene = new Scene(scenePane);
Stage stage = new Stage(StageStyle.UTILITY);
stage.setTitle("Rename Component");
stage.setScene(scene);
stage.initOwner(Nomad3DEditor.getInstance().getStage());
GridPane mainPane = new GridPane();
mainPane.setVgap(5);
mainPane.setHgap(10);
mainPane.setAlignment(Pos.CENTER);
scenePane.addRow(0, mainPane);
GridPane.setMargin(mainPane, new Insets(10));
GridPane namePane = new GridPane();
namePane.setVgap(5);
namePane.setHgap(10);
namePane.setAlignment(Pos.CENTER);
scenePane.addRow(0, namePane);
GridPane.setMargin(namePane, new Insets(10));
namePane.addRow(0, newNameLabel, newNameField);
Button okButton = new Button("OK");
okButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
// Get the names.
String newComponentName = newNameField.getText();
boolean error = false;
String errorMessage = null;
// Check the name.
if (nameExists(newComponentName)) {
error = true;
errorMessage = "The component name already exists.";
}
if (newComponentName.isEmpty()) {
error = true;
errorMessage = "The name is empty.";
}
// Check the name.
if (error) {
Alert emptyAlert = new Alert(AlertType.WARNING);
emptyAlert.setTitle("Bad name");
emptyAlert.setContentText(errorMessage);
emptyAlert.showAndWait();
return;
}
// Gets the component name.
String componentName = component.getName();
// Set the new name of the component.
component.setName(newComponentName);
// Update the scene.
updateScene();
// Save the operation.
Operations.getInstance().addOperation(new RenameComponentOperation(componentName, newComponentName));
// Change the title.
updateModified(true);
// Close the stage.
stage.close();
}
});
Button cancelButton = new Button("Cancel");
cancelButton.setCancelButton(true);
cancelButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
stage.close();
}
});
GridPane buttonPane = new GridPane();
buttonPane.setHgap(10);
buttonPane.setAlignment(Pos.CENTER);
buttonPane.addRow(0, okButton, cancelButton);
mainPane.addRow(0, namePane);
mainPane.addRow(1, buttonPane);
stage.showAndWait();
});
......@@ -1624,7 +1773,7 @@ public class EditorMenuBar extends MenuBar {
Menu componentsMenu = new Menu("Components");
componentsMenu.getItems().addAll(regroupComponentsItem, subdivideComponentItem, insertComponentItem);
this.edit.getItems().addAll(undoItem, new SeparatorMenuItem(), editAxisItem, displayAxisItem, editMaterialItem, new SeparatorMenuItem(), componentsMenu, addComponentItem, removeComponentsItem);
this.edit.getItems().addAll(undoItem, new SeparatorMenuItem(), editAxisItem, displayAxisItem, editMaterialItem, new SeparatorMenuItem(), componentsMenu, addComponentItem, removeComponentsItem, renameComponentItem);
this.view = new Menu("View");
Menu cameraMenu = new Menu("Camera");
......
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