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.PanMouseInputListener; import org.jxmapviewer.input.ZoomMouseWheelListenerCursor; import de.tu_darmstadt.informatik.tk.scopviz.main.Main; 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.MapViewFunctions; import de.tu_darmstadt.informatik.tk.scopviz.ui.mapView.WorldView; import javafx.application.Platform; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; 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.ComboBox; import javafx.scene.control.Label; import javafx.scene.control.MenuItem; import javafx.scene.control.ScrollPane; 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 centerMap; @FXML public Button defaultMapView; @FXML public Button roadMapView; @FXML public Button satelliteMapView; @FXML public Button hybridMapView; @FXML public Button previousWaypoint; @FXML public Button nextWaypoint; @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 operators; @FXML public MenuItem resetMapping; @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; @FXML public Button resetMappingButton; // 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 VBox leftSide; @FXML public VBox rightSide; @FXML public ComboBox opGraphSelectionBox; // The elements needed for the console window @FXML public ScrollPane consoleScrollPane; @FXML public TextFlow consoleWindow; // 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; // The anchorpane of the reset mapping button @FXML public AnchorPane resetMappingButtonAPane; /** * 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); OperatorManager.initialize(this); GraphDisplayManager.init(this); // Bind all the handlers to their corresponding UI elements initializeZoomButtons(); initializeSymbolLayerButtons(); initializeLayerButton(); initializeOpGraphComboBox(); initializeMenuBar(); initializeSymbolRepToolbox(); initializeDisplayPane(); initializeWorldView(); // Setup the Keyboard Shortcuts KeyboardShortcuts.initialize(Main.getInstance().getPrimaryStage(), this); } 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)); // "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); // bind a context menu to the swing node swingNodeWorldView.setOnContextMenuRequested((event) -> MapViewFunctions.contextMenuRequest(event)); } /** * 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)); operators.setOnAction((event) -> OperatorManager.openOperatorsDialog()); resetMapping.setOnAction((event) -> GraphDisplayManager.initMappingLayer(true)); updateMetricMI.setOnAction((event) -> MetricboxManager.updateMetrics()); updateMetricMI.setDisable(true); about.setOnAction((event) -> MenuBarManager.aboutAction(event)); resetMapping.setDisable(true); } /** * Sets the handlers for the zoomin and zoomout buttons. */ private void initializeZoomButtons() { zoomIn.setOnAction((event) -> ButtonManager.zoomInAction(event)); zoomOut.setOnAction((event) -> ButtonManager.zoomOutAction(event)); } /** * Sets the handlers for the Button that are shown in the symbol layer */ private void initializeSymbolLayerButtons() { centerMap.setOnAction((event) -> ButtonManager.centerMapAction(event)); defaultMapView.setOnAction((event) -> MapViewFunctions.changeMapView("Default")); roadMapView.setOnAction((event) -> MapViewFunctions.changeMapView("Road")); satelliteMapView.setOnAction((event) -> MapViewFunctions.changeMapView("Satellite")); hybridMapView.setOnAction((event) -> MapViewFunctions.changeMapView("Hybrid")); previousWaypoint.setOnAction((event) -> MapViewFunctions.switchToPreviousWaypoint()); nextWaypoint.setOnAction((event) -> MapViewFunctions.switchToNextWaypoint()); centerMap.setVisible(false); defaultMapView.setVisible(false); roadMapView.setVisible(false); satelliteMapView.setVisible(false); hybridMapView.setVisible(false); previousWaypoint.setVisible(false); nextWaypoint.setVisible(false); } /** * 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)); } /** * 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