package de.tu_darmstadt.informatik.tk.scopviz.ui; import java.net.URL; import java.util.ArrayList; import java.util.ResourceBundle; import javax.swing.JPanel; import javax.swing.event.MouseInputListener; import org.jxmapviewer.JXMapViewer; import org.jxmapviewer.input.CenterMapListener; import org.jxmapviewer.input.PanKeyListener; import org.jxmapviewer.input.PanMouseInputListener; import org.jxmapviewer.input.ZoomMouseWheelListenerCursor; import de.tu_darmstadt.informatik.tk.scopviz.main.Layer; import de.tu_darmstadt.informatik.tk.scopviz.main.Main; import de.tu_darmstadt.informatik.tk.scopviz.metrics.TestMetric; import de.tu_darmstadt.informatik.tk.scopviz.ui.handlers.KeyboardShortcuts; import de.tu_darmstadt.informatik.tk.scopviz.ui.handlers.ResizeListener; import de.tu_darmstadt.informatik.tk.scopviz.ui.mapView.WorldView; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.embed.swing.SwingNode; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.Button; import javafx.scene.control.CheckBox; import javafx.scene.control.ChoiceBox; import javafx.scene.control.Label; import javafx.scene.control.MenuItem; import javafx.scene.control.TableColumn; import javafx.scene.control.TableRow; import javafx.scene.control.TableView; import javafx.scene.control.Tooltip; import javafx.scene.control.cell.CheckBoxTableCell; import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.control.cell.TextFieldTableCell; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.Pane; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import javafx.scene.text.TextFlow; import javafx.util.Pair; /** * Controller class for the various GUI elements, gets instanced and initialized * by the FXML loading process. Can access GUI elements specified in the FXML * file through matching variable name here and id attribute in the FXML, * * @author Dominik Renkel, Jan Enders * @version 1.1 * */ public class GUIController implements Initializable { // The SwingNode and its containing Pane that house the graph viewer @FXML public SwingNode swingNode; @FXML public SwingNode swingNodeWorldView; @FXML public Pane pane; @FXML public StackPane stackPane; // The buttons present in the UI @FXML public Button zoomIn; @FXML public Button zoomOut; @FXML public Button underlayButton; @FXML public Button operatorButton; @FXML public Button mappingButton; @FXML public Button symbolRepButton; // The Toolbar Items @FXML public MenuItem newItem; @FXML public MenuItem open; @FXML public MenuItem add; @FXML public MenuItem save; @FXML public MenuItem saveAs; @FXML public MenuItem preferences; @FXML public MenuItem quit; @FXML public MenuItem delete; @FXML public MenuItem undelete; @FXML public MenuItem updateMetricMI; @FXML public MenuItem about; // The contents of the corresponding ScrollPanes @FXML public TableView> toolbox; @FXML public TableView properties; @FXML public TableView metricbox; // The columns of the toolbox @FXML public TableColumn, String> toolboxStringColumn; @FXML public TableColumn, Object> toolboxObjectColumn; // The columns of the Properties pane // TODO: Fix Generic type arguments for propertiesObjectColumn @FXML public TableColumn propertiesStringColumn; @FXML public TableColumn propertiesObjectColumn; @FXML public TableColumn propertiesTypeColumn; // The columns of the metricbox @FXML public TableColumn metricBoxMetricColumn; @FXML public TableColumn metricBoxValueColumn; @FXML public TableColumn metricBoxUpdateColumn; @FXML public Button updateMetricButton; //The items of the top left box in the symbol visualization layer @FXML public VBox symbolToolVBox; @FXML public CheckBox edgesVisibleCheckbox; @FXML public CheckBox nodeLabelCheckbox; @FXML public CheckBox edgeWeightCheckbox; @FXML public ChoiceBox mapViewChoiceBox; @FXML public TextFlow consoleWindow; @FXML public VBox rightSide; //The anchorpane of the top left box (toolbox, symbol visualization layer box) @FXML public AnchorPane topLeftAPane; //The anchorpane of the metric update button @FXML public AnchorPane updateButtonAPane; /** * Initializes all the references to the UI elements specified in the FXML * file. Gets called during FXML loading. Asserts the correct injection of * all referenced UI elements and initializes them. */ @Override public void initialize(URL arg0, ResourceBundle arg1) { // Assert the correct injection of all references from FXML assertFXMLInjections(); initializeToolbox(); initializeProperties(); initializeMetricbox(); // Remove Header for the toolbox removeHeaderTableView(toolbox); // Initialize the Managers for the various for UI elements ToolboxManager.initializeItems(); PropertiesManager.initializeItems(properties); ConsoleManager.initialize(this); GraphDisplayManager.init(this); // Bind all the handlers to their corresponding UI elements initializeZoomButtons(); initializeLayerButton(); initializeMenuBar(); initializeSymbolRepToolbox(); initializeDisplayPane(); initializeWorldView(); // Setup the Keyboard Shortcuts KeyboardShortcuts.initialize(Main.getInstance().getPrimaryStage()); } private void initializeWorldView() { JXMapViewer mapViewer = new JXMapViewer(); WorldView.initAttributes(mapViewer, this); // center map if double clicked / middle clicked mapViewer.addMouseListener(new CenterMapListener(mapViewer)); // zoom with mousewheel mapViewer.addMouseWheelListener(new ZoomMouseWheelListenerCursor(mapViewer)); // TODO make this work mapViewer.addKeyListener(new PanKeyListener(mapViewer)); // "Drag map around" Listener MouseInputListener mia = new PanMouseInputListener(mapViewer); mapViewer.addMouseListener(mia); mapViewer.addMouseMotionListener(mia); swingNodeWorldView.setContent(mapViewer); // add resize Listener to the stackPane stackPane.heightProperty().addListener(new ResizeListener(swingNode, stackPane)); stackPane.widthProperty().addListener(new ResizeListener(swingNode, stackPane)); swingNodeWorldView.setVisible(false); } /** * Initializes the Menu Bar with all its contents. */ private void initializeMenuBar() { newItem.setOnAction((event) -> MenuBarManager.newAction(event)); open.setOnAction((event) -> MenuBarManager.openAction(event)); add.setOnAction((event) -> MenuBarManager.addAction(event)); add.setDisable(true);; save.setOnAction((event) -> MenuBarManager.saveAction(event)); saveAs.setOnAction((event) -> MenuBarManager.saveAsAction(event)); preferences.setOnAction((event) -> MenuBarManager.preferencesAction(event)); quit.setOnAction((event) -> MenuBarManager.quitAction(event)); delete.setOnAction((event) -> MenuBarManager.deleteAction(event)); undelete.setOnAction((event) -> MenuBarManager.undeleteAction(event)); updateMetricMI.setOnAction((event) -> MetricboxManager.updateMetrics()); updateMetricMI.setDisable(true); about.setOnAction((event) -> MenuBarManager.aboutAction(event)); } /** * Sets the handlers for the zoomin and zoomout buttons. */ private void initializeZoomButtons() { zoomIn.setOnAction((event) -> ButtonManager.zoomInAction(event)); zoomOut.setOnAction((event) -> ButtonManager.zoomOutAction(event)); } /** * Initializes the special Toolbox for the Symbol Representation Layer. */ private void initializeSymbolRepToolbox() { // Hide SymbolRep Toolbox View topLeftAPane.getChildren().remove(symbolToolVBox); edgesVisibleCheckbox.selectedProperty() .addListener((ov, oldVal, newVal) -> ButtonManager.edgeVisibilitySwitcher(ov, oldVal, newVal)); nodeLabelCheckbox.selectedProperty() .addListener((ov, oldVal, newVal) -> ButtonManager.labelVisibilitySwitcher(ov, oldVal, newVal)); edgeWeightCheckbox.selectedProperty() .addListener((ov, oldVal, newVal) -> ButtonManager.edgeWeightVisibilitySwitcher(ov, oldVal, newVal)); mapViewChoiceBox.setItems(FXCollections.observableArrayList("Default", "Road", "Satellite", "Hybrid")); mapViewChoiceBox.getSelectionModel().selectFirst(); mapViewChoiceBox.getSelectionModel().selectedItemProperty() .addListener((ov, oldVal, newVal) -> ButtonManager.mapViewChoiceChange(ov, oldVal, newVal)); } /** * Set the Handlers for the Layer switch Buttons. */ private void initializeLayerButton() { underlayButton.setOnAction((event) -> ButtonManager.underlayAction(event)); operatorButton.setOnAction((event) -> ButtonManager.operatorAction(event)); mappingButton.setOnAction((event) -> ButtonManager.mappingAction(event)); symbolRepButton.setOnAction((event) -> ButtonManager.symbolRepAction(event)); Tooltip tip = new Tooltip(); tip.setText("Underlay"); underlayButton.setTooltip(tip); tip = new Tooltip(); tip.setText("Operator"); operatorButton.setTooltip(tip); tip = new Tooltip(); tip.setText("Mapping"); mappingButton.setTooltip(tip); tip = new Tooltip(); tip.setText("Geographical Visualization"); symbolRepButton.setTooltip(tip); ArrayList