OperatorManager.java 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package de.tu_darmstadt.informatik.tk.scopviz.ui;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
  5. import de.tu_darmstadt.informatik.tk.scopviz.metrics.BasicMappingOperator;
  6. import de.tu_darmstadt.informatik.tk.scopviz.metrics.interfaces.ScopvizGraphOperator;
  7. import javafx.application.Platform;
  8. import javafx.collections.FXCollections;
  9. import javafx.geometry.Insets;
  10. import javafx.scene.control.ButtonBar.ButtonData;
  11. import javafx.scene.control.ButtonType;
  12. import javafx.scene.control.ChoiceBox;
  13. import javafx.scene.control.Dialog;
  14. import javafx.scene.control.Label;
  15. import javafx.scene.layout.GridPane;
  16. public class OperatorManager {
  17. private static HashMap<String, ScopvizGraphOperator> operators = new HashMap<String, ScopvizGraphOperator>();
  18. /**
  19. * Initializes all GraphOperators for employment
  20. *
  21. * ****Central method to add a new metric***** Add line: addOperator(new
  22. * YourMetric()); for using it in the Operatordialog
  23. * **************************************************************
  24. *
  25. */
  26. private static void initializeGraphOperators() {
  27. addOperator(new BasicMappingOperator());
  28. }
  29. /**
  30. * opens a dialog allowing the User to choose which GraphOperator he wants
  31. * to use on the current Graph
  32. */
  33. public static void openOperatorsDialog() {
  34. Dialog<ArrayList<String>> addPropDialog = new Dialog<>();
  35. addPropDialog.setTitle("GraphOperators");
  36. ButtonType addButtonType = new ButtonType("invoke on current graph", ButtonData.OK_DONE);
  37. addPropDialog.getDialogPane().getButtonTypes().addAll(addButtonType, ButtonType.CANCEL);
  38. // create grid
  39. GridPane grid = new GridPane();
  40. grid.setHgap(10);
  41. grid.setVgap(10);
  42. grid.setPadding(new Insets(20, 150, 10, 10));
  43. // set DropDown Menu
  44. ChoiceBox<String> operatorChooser = new ChoiceBox<>();
  45. operatorChooser.setItems(FXCollections.observableArrayList(operators.keySet()));
  46. // adding elements to grid
  47. grid.add(new Label("Please select the operator you want to invoke on the current Gaph"), 0, 0);
  48. grid.add(operatorChooser, 0, 1);
  49. addPropDialog.getDialogPane().setContent(grid);
  50. Platform.runLater(() -> operatorChooser.requestFocus());
  51. // get new property values
  52. addPropDialog.setResultConverter(dialogButton -> {
  53. if (dialogButton == addButtonType) {
  54. operators.get(operatorChooser.getSelectionModel().getSelectedItem())
  55. .calculate(Main.getInstance().getGraphManager());
  56. return null;
  57. } else
  58. return null;
  59. });
  60. addPropDialog.showAndWait();
  61. }
  62. /**
  63. * Adds an Operator to the HashMap
  64. *
  65. * @param op
  66. * the Operator that will be added
  67. */
  68. public static void addOperator(ScopvizGraphOperator op) {
  69. operators.put(op.getName(), op);
  70. }
  71. /**
  72. * initializes the OperatorManager
  73. *
  74. * @param g
  75. * the guiController of the Programm
  76. */
  77. public static void initialize(GUIController g) {
  78. initializeGraphOperators();
  79. }
  80. }