Example usage for javafx.scene.input MouseEvent MOUSE_RELEASED

List of usage examples for javafx.scene.input MouseEvent MOUSE_RELEASED

Introduction

In this page you can find the example usage for javafx.scene.input MouseEvent MOUSE_RELEASED.

Prototype

EventType MOUSE_RELEASED

To view the source code for javafx.scene.input MouseEvent MOUSE_RELEASED.

Click Source Link

Document

This event occurs when mouse button is released.

Usage

From source file:Main.java

public static java.awt.event.MouseEvent toAwt(final MouseEvent event) {
    final EventType type = event.getEventType();
    if (null == type) {
        return null;
    }/* ww  w .  j ava  2  s . c o m*/

    final int id;
    if (MouseEvent.MOUSE_MOVED.equals(type)) {
        id = java.awt.event.MouseEvent.MOUSE_MOVED;
    } else if (MouseEvent.MOUSE_DRAGGED.equals(type)) {
        id = java.awt.event.MouseEvent.MOUSE_DRAGGED;
    } else if (MouseEvent.MOUSE_CLICKED.equals(type)) {
        id = java.awt.event.MouseEvent.MOUSE_CLICKED;
    } else if (MouseEvent.MOUSE_PRESSED.equals(type)) {
        id = java.awt.event.MouseEvent.MOUSE_PRESSED;
    } else if (MouseEvent.MOUSE_RELEASED.equals(type)) {
        id = java.awt.event.MouseEvent.MOUSE_RELEASED;
    } else if (MouseEvent.MOUSE_ENTERED.equals(type)) {
        id = java.awt.event.MouseEvent.MOUSE_ENTERED;
    } else if (MouseEvent.MOUSE_EXITED.equals(type)) {
        id = java.awt.event.MouseEvent.MOUSE_EXITED;
    } else {
        return null;
    }

    final int button;
    if (event.isPrimaryButtonDown()) {
        button = java.awt.event.MouseEvent.BUTTON1;
    } else if (event.isMiddleButtonDown()) {
        button = java.awt.event.MouseEvent.BUTTON2;
    } else if (event.isSecondaryButtonDown()) {
        button = java.awt.event.MouseEvent.BUTTON3;
    } else {
        button = java.awt.event.MouseEvent.NOBUTTON;
    }

    final long when = -1;
    final int modifiers = modifiers(event);
    final int x = (int) event.getX();
    final int y = (int) event.getY();
    final int xAbs = Integer.MAX_VALUE;
    final int yAbs = Integer.MAX_VALUE;
    final int count = event.getClickCount();
    boolean popup = event.isPopupTrigger();
    if (MouseEvent.MOUSE_CLICKED.equals(type) && event.isMetaDown()) {
        // mack books use meta flag for right-clicks
        popup = true;
    }
    return new java.awt.event.MouseEvent(empty, id, when, modifiers, x, y, xAbs, yAbs, count, popup, button);
}

From source file:ijfx.ui.plugin.panel.OverlayPanel.java

public OverlayPanel() throws IOException {
    super();//from  w w  w  .ja v  a 2  s  .  co m

    FXUtilities.injectFXML(this);

    keyColumn.setCellValueFactory(new PropertyValueFactory("name"));
    valueColumn.setCellValueFactory(new PropertyValueFactory("value"));

    tableView.setItems(entries);

    entries.add(new MyEntry("nothing", 0d));

    overlayNameField.setPromptText(EMPTY_FIELD);
    overlayNameField.textProperty().addListener(this::onOverlayNameChanged);

    overlayProperty.addListener(this::onOverlaySelectionChanged);

    chartVBox.getChildren().removeAll(areaChart, lineChart);

    overlayOptions = new OverlayOptions();

    optionsPane = new PopOver(overlayOptions);
    optionsPane.setArrowLocation(PopOver.ArrowLocation.RIGHT_TOP);
    optionsPane.setDetachable(true);
    optionsPane.setAutoHide(false);
    optionsPane.titleProperty().setValue("Overlay settings");
    optionsPane.setConsumeAutoHidingEvents(false);

    gearIcon = GlyphsDude.createIcon(FontAwesomeIcon.GEAR, "15");
    gearIcon.setOpacity(BASAL_OPACITY);
    gearIcon.setOnMouseEntered(e -> gearIcon.setOpacity(1.0));
    gearIcon.setOnMouseExited(e -> gearIcon.setOpacity(BASAL_OPACITY));
    gearIcon.addEventHandler(MouseEvent.MOUSE_CLICKED, this::onGearClicked);
    gearIcon.addEventHandler(MouseEvent.MOUSE_PRESSED, e -> {
        e.consume();
    });
    gearIcon.addEventHandler(MouseEvent.MOUSE_RELEASED, e -> {
        e.consume();
    });

    chartTitledPane.setGraphic(gearIcon);
    chartTitledPane.setContentDisplay(ContentDisplay.RIGHT);
    chartTitledPane.graphicTextGapProperty().setValue(TEXT_GAP);
}

From source file:ijfx.ui.plugin.overlay.OverlayPanel.java

public OverlayPanel() throws IOException {
    super();// w  ww .j a va 2 s  .  c om

    FXUtilities.injectFXML(this);

    keyColumn.setCellValueFactory(new PropertyValueFactory("name"));
    valueColumn.setCellValueFactory(new PropertyValueFactory("value"));

    tableView.setItems(entries);

    entries.add(new MyEntry("nothing", 0d));

    overlayNameField.setPromptText(EMPTY_FIELD);
    overlayNameField.textProperty().addListener(this::onOverlayNameChanged);

    overlayProperty.addListener(this::onOverlaySelectionChanged);

    chartVBox.getChildren().removeAll(areaChart, lineChart);

    overlayOptions = new OverlayOptions();

    optionsPane = new PopOver(overlayOptions);
    optionsPane.setArrowLocation(PopOver.ArrowLocation.RIGHT_TOP);
    optionsPane.setDetachable(true);
    optionsPane.setAutoHide(false);
    optionsPane.titleProperty().setValue("Overlay settings");
    optionsPane.setConsumeAutoHidingEvents(false);

    gearIcon = GlyphsDude.createIcon(FontAwesomeIcon.GEAR, "15");
    gearIcon.setOpacity(BASAL_OPACITY);
    gearIcon.setOnMouseEntered(e -> gearIcon.setOpacity(1.0));
    gearIcon.setOnMouseExited(e -> gearIcon.setOpacity(BASAL_OPACITY));
    gearIcon.addEventHandler(MouseEvent.MOUSE_CLICKED, this::onGearClicked);
    gearIcon.addEventHandler(MouseEvent.MOUSE_PRESSED, e -> {
        e.consume();
    });
    gearIcon.addEventHandler(MouseEvent.MOUSE_RELEASED, e -> {
        e.consume();
    });

    chartTitledPane.setGraphic(gearIcon);
    chartTitledPane.setContentDisplay(ContentDisplay.RIGHT);
    chartTitledPane.graphicTextGapProperty().setValue(TEXT_GAP);

    // channeling all the DataViewUpdatedEvent so it updates the
    // current selected overlay
    eventBus.getStream(OverlayUpdatedEvent.class)
            .filter(event -> event.getObject().equals(overlayProperty.getValue()))
            .subscribe(event -> Platform.runLater(this::updateStats));

    eventBus.getStream(DataViewUpdatedEvent.class).map(event -> event.getView())
            .filter(view -> view instanceof OverlayView).cast(OverlayView.class)
            .filter(view -> view.isSelected()).throttleWithTimeout(1000, TimeUnit.MILLISECONDS)
            .subscribe(overlay -> {
                overlayProperty.setValue(overlay.getData());
            });

    eventBus.getStream(DataViewUpdatedEvent.class).filter(event -> event.getView() instanceof DatasetView)
            .map(event -> event.getView()).cast(DatasetView.class).map(view -> {
                return view;
            }).filter(view -> currentDisplay().contains(view)).throttleWithTimeout(100, TimeUnit.MILLISECONDS)
            .subscribe(event -> Platform.runLater(this::updateStats));
    eventBus.getStream(DisplayUpdatedEvent.class).filter(event -> event.getDisplay() instanceof ImageDisplay)
            .subscribe(this::checkCurrentOverlay);
}

From source file:com.panemu.tiwulfx.control.skin.LookupFieldSkin.java

private void createPopup() {
    popup = new PopupControl() {
        {/*  www.  j  a  va2s .com*/
            setSkin(new Skin() {
                @Override
                public Skinnable getSkinnable() {
                    return LookupFieldSkin.this.lookupField;
                }

                @Override
                public Node getNode() {
                    return listView;
                }

                @Override
                public void dispose() {
                }
            });
        }
    };
    popup.setAutoHide(true);
    popup.setAutoFix(true);
    popup.setHideOnEscape(true);
    popup.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent t) {
            popup.hide();
        }
    });

    listView.setCellFactory(new Callback() {
        @Override
        public Object call(Object p) {
            return new PropertyListCell(lookupField.getPropertyName());
        }
    });

    /**
     * Taken from
     * {@link com.sun.javafx.scene.control.skin.ComboBoxListViewSkin}
     */
    listView.addEventFilter(MouseEvent.MOUSE_RELEASED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent t) {
            // RT-18672: Without checking if the user is clicking in the 
            // scrollbar area of the ListView, the comboBox will hide. Therefore,
            // we add the check below to prevent this from happening.
            EventTarget target = t.getTarget();
            if (target instanceof Parent) {
                List<String> s = ((Parent) target).getStyleClass();
                if (s.contains("thumb") || s.contains("track") || s.contains("decrement-arrow")
                        || s.contains("increment-arrow")) {
                    return;
                }
            }
            needValidation = false;
            lookupField.setValue(listView.getSelectionModel().getSelectedItem());
            popup.hide();
        }
    });

    listView.setOnKeyPressed(new EventHandler<KeyEvent>() {
        @Override
        public void handle(KeyEvent t) {
            if (t.getCode() == KeyCode.ENTER) {
                needValidation = false;
                lookupField.setValue(listView.getSelectionModel().getSelectedItem());
                popup.hide();
            } else if (t.getCode() == KeyCode.ESCAPE) {
                popup.hide();
            }
        }
    });

}

From source file:edu.kit.trufflehog.view.jung.visualization.FXVisualizationViewer.java

synchronized private void initEdge(IConnection edge) {

    final Pair<INode> pair = this.layout.getGraph().getEndpoints(edge);

    if (pair.getSecond().getAddress().isMulticast()) {

        // TODO check or do something with this (generify the getShape command?)
        final Circle destCircle = (Circle) pair.getFirst().getComponent(ViewComponent.class).getRenderer()
                .getShape();/*from  ww w.j a va2  s .  c  o  m*/
        final Shape shape = edge.getComponent(ViewComponent.class).getRenderer().getShape();
        shape.layoutXProperty().bind(destCircle.layoutXProperty());
        shape.layoutYProperty().bind(destCircle.layoutYProperty());
        canvas.getChildren().add(shape);
        shape.setPickOnBounds(false);
        shape.setMouseTransparent(true);
        return;
    }

    // source and destination shape
    final Shape srcShape = pair.getFirst().getComponent(ViewComponent.class).getRenderer().getShape();
    final Shape destShape = pair.getSecond().getComponent(ViewComponent.class).getRenderer().getShape();

    // the positions of the shapes
    final DoubleBinding srcX = srcShape.layoutXProperty().add(srcShape.translateXProperty());
    final DoubleBinding srcY = srcShape.layoutYProperty().add(srcShape.translateYProperty());
    final DoubleBinding destX = destShape.layoutXProperty().add(destShape.translateXProperty());
    final DoubleBinding destY = destShape.layoutYProperty().add(destShape.translateYProperty());

    // the direction vector from source to destination (deltaX, deltaY)
    final DoubleBinding deltaX = destX.subtract(srcX);
    final DoubleBinding deltaY = destY.subtract(srcY);

    // the length of the direction vector
    final DoubleBinding length = MyBindings
            .sqrt(Bindings.add(MyBindings.pow2(deltaX), MyBindings.pow2(deltaY)));

    // the normalized direction vector
    final DoubleBinding normalX = deltaX.divide(length);
    final DoubleBinding normalY = deltaY.divide(length);

    // cast the shapes to circles (because right now i know they are circles) //TODO make this for arbitrary shapes
    final Circle destCircle = (Circle) destShape;
    final Circle srcCircle = (Circle) srcShape;

    // get the real source by multiplying the normal with the radius and the scale of the shape
    final DoubleBinding realSoureX = srcX
            .add(normalX.multiply(srcCircle.radiusProperty().multiply(srcShape.scaleXProperty())));
    final DoubleBinding realSoureY = srcY
            .add(normalY.multiply(srcCircle.radiusProperty().multiply(srcShape.scaleYProperty())));

    // get the real destination by multipling the normal vector with the length minus the radius and scale of the destination shape
    final DoubleBinding realDestX = srcX.add(normalX
            .multiply(length.subtract(destCircle.radiusProperty().multiply(destShape.scaleXProperty()))));
    final DoubleBinding realDestY = srcY.add(normalY
            .multiply(length.subtract(destCircle.radiusProperty().multiply(destShape.scaleYProperty()))));

    final IEdgeRenderer edgeRenderer = (IEdgeRenderer) edge.getComponent(ViewComponent.class).getRenderer();

    edgeRenderer.getArrowShape().layoutXProperty().bind(realDestX);
    edgeRenderer.getArrowShape().layoutYProperty().bind(realDestY);

    final QuadCurve curve = edgeRenderer.getLine();
    curve.setCacheHint(CacheHint.SPEED);

    curve.addEventFilter(MouseEvent.MOUSE_PRESSED, edgeGestures.getOnMousePressedEventHandler(edge));
    curve.addEventFilter(MouseEvent.MOUSE_RELEASED, edgeGestures.getOnMouseReleasedEventHandler(edge));
    edgeRenderer.getArrowShape().addEventFilter(MouseEvent.MOUSE_PRESSED,
            edgeGestures.getOnMousePressedEventHandler(edge));
    edgeRenderer.getArrowShape().addEventFilter(MouseEvent.MOUSE_RELEASED,
            edgeGestures.getOnMouseReleasedEventHandler(edge));

    /*        // make the edge clickable
            curve.setOnMouseClicked(e -> {
            
    if (e.getButton() != MouseButton.PRIMARY) {
        return;
    }
            
    logger.debug(edge.getSrc().getComponent(NodeInfoComponent.class).toString() + " --[" + edge.getComponent(EdgeStatisticsComponent.class).getTraffic() +
            "]-->" + edge.getDest().getComponent(NodeInfoComponent.class).toString());
            
    //            edge.getComponent(ViewComponent.class).getRenderer().togglePicked();
            });
            
            edgeRenderer.getArrowShape().setOnMouseClicked(e -> {
            
    if (e.getButton() != MouseButton.PRIMARY) {
        return;
    }
            
    logger.debug(edge.getSrc().getComponent(NodeInfoComponent.class).toString() + " --[" + edge.getComponent(EdgeStatisticsComponent.class).getTraffic() +
    "]-->" + edge.getDest().getComponent(NodeInfoComponent.class).toString());
            
    //            edge.getComponent(ViewComponent.class).getRenderer().togglePicked();
            
            
            });*/

    //get the edge size binding by dividing the total traffic with the local traffic
    DoubleBinding edgeSize = MyBindings
            .divideIntToDouble(edge.getComponent(EdgeStatisticsComponent.class).getTrafficProperty(),
                    port.getMaxConnectionSizeProperty())
            .multiply(8).add(2);
    curve.strokeWidthProperty().bind(edgeSize.multiply(edgeRenderer.edgeWidthMultiplierProperty()));

    // bind the ending to the real destionaion point
    curve.endXProperty().bind(realDestX);
    curve.endYProperty().bind(realDestY);

    // bind the source to the real source point
    curve.startXProperty().bind(realSoureX);
    curve.startYProperty().bind(realSoureY);

    NumberBinding normalVectorX = Bindings.subtract(realDestY, realSoureY).negate();
    NumberBinding normalVectorY = Bindings.subtract(realDestX, realSoureX);

    NumberBinding centerPointX = Bindings.divide(Bindings.add(curve.endXProperty(), curve.startXProperty()), 2);
    NumberBinding centerPointY = Bindings.divide(Bindings.add(curve.endYProperty(), curve.startYProperty()), 2);

    NumberBinding normalLength = MyBindings
            .sqrt(Bindings.add(normalVectorX.multiply(normalVectorX), normalVectorY.multiply(normalVectorY)));

    NumberBinding normalizedNVX = normalVectorX.divide(normalLength);
    NumberBinding normalizedNVY = normalVectorY.divide(normalLength);

    NumberBinding bezierPointOffset = length.multiply(.1);

    curve.controlXProperty().bind(Bindings.add(centerPointX, normalizedNVX.multiply(bezierPointOffset)));
    curve.controlYProperty().bind(Bindings.add(centerPointY, normalizedNVY.multiply(bezierPointOffset)));

    // TODO do this in component
    curve.setFill(null);

    canvas.getChildren().add(edgeRenderer.getArrowShape());
    // add the edge to the canvas
    canvas.getChildren().add(curve);
}

From source file:edu.kit.trufflehog.view.jung.visualization.FXVisualizationViewer.java

synchronized private void initVertex(INode vertex) {

    if (vertex.getAddress().isMulticast()) {
        return;//from   w w w.  ja v a 2s .co  m
    }

    final IRenderer renderer = vertex.getComponent(ViewComponent.class).getRenderer();
    final Shape nodeShape = renderer.getShape();
    //nodeShape.addEventFilter( MouseEvent.MOUSE_PRESSED, nodeGestures.getOnMousePressedEventHandler());
    //nodeShape.addEventFilter( MouseEvent.MOUSE_DRAGGED, nodeGestures.getOnMouseDraggedEventHandler());

    //nodeShape.setCache(false);
    //nodeShape.setCacheHint(CacheHint.);

    final NodeStatisticsComponent nsc = vertex.getComponent(NodeStatisticsComponent.class);

    final DoubleBinding nodeSize = MyBindings
            .divideIntToDouble(nsc.getCommunicationCountProperty(), port.getMaxThroughputProperty()).add(1);

    nodeShape.scaleXProperty().bind(nodeSize);
    nodeShape.scaleYProperty().bind(nodeSize);

    nodeShape.setLayoutX(layout.transform(vertex).getX());
    nodeShape.setLayoutY(layout.transform(vertex).getY());

    ///////////
    // LABEL //
    ///////////

    Label nodeLabel = new Label();

    // cast the shapes to circles (because right now i know they are circles) //TODO make this for arbitrary shapes
    final Circle nodeCircle = (Circle) nodeShape;

    /*        final DoubleProperty labelX = new SimpleDoubleProperty();
            final DoubleProperty labelY = new SimpleDoubleProperty();*/

    //labelX.bind(nodeShape.layoutXProperty().add(nodeCircle.radiusProperty().multiply(nodeShape.scaleXProperty())));
    //labelY.bind(nodeShape.layoutYProperty().add(nodeCircle.radiusProperty().multiply(nodeShape.scaleYProperty())));

    //nodeLabel.layoutXProperty().bindBidirectionalWithOffset(labelX);
    //nodeLabel.layoutYProperty().bindBidirectionalWithOffset(labelY);

    //nodeLabel.layoutXProperty().bind(nodeShape.layoutXProperty().add(nodeCircle.radiusProperty().multiply(nodeShape.scaleXProperty())));

    nodeLabel.textFillProperty().bind(new SimpleObjectProperty<>(Color.WHITE));

    //MyBindings.bindBidirectionalWithOffset(nodeLabel.layoutXProperty(), nodeShape.layoutXProperty(), nodeCircle.radiusProperty().multiply(nodeShape.scaleXProperty()));
    //MyBindings.bindBidirectionalWithOffset(nodeLabel.layoutYProperty(), nodeShape.layoutYProperty(), nodeCircle.radiusProperty().multiply(nodeShape.scaleYProperty()));

    nodeLabel.layoutXProperty().bind(nodeShape.layoutXProperty().add(nodeShape.translateXProperty())
            .add(nodeCircle.radiusProperty().multiply(nodeShape.scaleXProperty())));
    nodeLabel.layoutYProperty().bind(nodeShape.layoutYProperty().add(nodeShape.translateYProperty())
            .add(nodeCircle.radiusProperty().multiply(nodeShape.scaleYProperty())));

    NodeInfoComponent nic = vertex.getComponent(NodeInfoComponent.class);
    if (nic != null) {
        nodeLabel.textProperty().bind(nic.toStringBinding());
    }

    nodeLabel.scaleXProperty().bind(Bindings.divide(1, canvas.scaleXProperty()));
    nodeLabel.scaleYProperty().bind(Bindings.divide(1, canvas.scaleYProperty()));

    nodeLabel.addEventFilter(MouseEvent.MOUSE_PRESSED, nodeGestures.getOnMousePressedEventHandler(vertex));
    nodeLabel.addEventFilter(MouseEvent.MOUSE_DRAGGED, nodeGestures.getOnMouseDraggedEventHandler(vertex));
    nodeLabel.addEventFilter(MouseEvent.MOUSE_RELEASED, nodeGestures.getOnMouseReleasedEventHandler(vertex));

    nodeShape.addEventFilter(MouseEvent.MOUSE_PRESSED, nodeGestures.getOnMousePressedEventHandler(vertex));
    nodeShape.addEventFilter(MouseEvent.MOUSE_DRAGGED, nodeGestures.getOnMouseDraggedEventHandler(vertex));
    nodeShape.addEventFilter(MouseEvent.MOUSE_RELEASED, nodeGestures.getOnMouseReleasedEventHandler(vertex));
    nodeShape.addEventFilter(MouseEvent.MOUSE_CLICKED, nodeGestures.getOnMouseClickedEventHandler(vertex));

    canvas.getChildren().addAll(nodeLabel, nodeShape);
}

From source file:org.noroomattheinn.visibletesla.App.java

/**
 * Begin watching for user inactivity (keyboard input, mouse movements, etc.)
 * on any of the specified Tabs./*from w  ww.ja  v  a  2s .  com*/
 * @param tabs  Watch for user activity targeted to any of these tabs.
 */
void watchForUserActivity(List<Tab> tabs) {
    for (Tab t : tabs) {
        Node n = t.getContent();
        n.addEventFilter(KeyEvent.ANY, new EventPassThrough());
        n.addEventFilter(MouseEvent.MOUSE_PRESSED, new EventPassThrough());
        n.addEventFilter(MouseEvent.MOUSE_RELEASED, new EventPassThrough());
    }
    ThreadManager.get().launch(new InactivityThread(60L * 1000L * prefs.idleThresholdInMinutes.get()),
            "Inactivity");
}

From source file:org.samcrow.frameviewer.trajectory.ui.FrameController.java

/**
 * Called when a mouse event is received. Subclasses should override
 * this method. The default implementation does nothing.
 * <p>/*  www. j a v  a  2 s. c o m*/
 * @param event The mouse event
 * @param framePosition The position of the event in frame coordinates
 */
public void handleMouseEvent(MouseEvent event, Point2D framePosition) {
    final EventType<? extends Event> type = event.getEventType();
    if (type == MouseEvent.MOUSE_PRESSED) {
        handleMousePressed(event, framePosition);
    } else if (type == MouseEvent.MOUSE_RELEASED) {
        handleMouseReleased(event, framePosition);
    } else if (type == MouseEvent.MOUSE_CLICKED && event.isStillSincePress()) {
        handleMouseClicked(event, framePosition);
    } else if (type == MouseEvent.MOUSE_MOVED) {
        handleMouseMoved(event, framePosition);
    } else if (type == MouseEvent.MOUSE_DRAGGED) {
        handleMouseDragged(event, framePosition);
    }
}

From source file:poe.trade.assist.SearchPane.java

private void setupTableClickListener() {
    searchTable.addEventFilter(MouseEvent.MOUSE_RELEASED, new EventHandler<MouseEvent>() {
        @Override/*from   w w w  .ja va 2 s .c o  m*/
        public void handle(MouseEvent event) {
            if (event.getButton() == MouseButton.SECONDARY) {
                Search search = searchTable.getSelectionModel().getSelectedItem();
                if (search != null) {
                    search.markSeen();
                }
            }
        }
    });
    searchTable.addEventFilter(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            if (event.getClickCount() > 1 && event.getButton() == MouseButton.PRIMARY) {
                Search search = searchTable.getSelectionModel().getSelectedItem();
                if (search != null) {
                    SwingUtil.openUrlViaBrowser(search.getUrl());
                }
            }
        }
    });
}

From source file:snpviewer.SnpViewer.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    labelSplitPane.setDividerPositions();
    chromSplitPane.setDividerPositions();
    Pane lpane = (Pane) horizontalSplit.getItems().get(0);
    SplitPane.setResizableWithParent(lpane, false);
    //mnemonics/shortcuts for menus        
    mainMenu.useSystemMenuBarProperty().set(true);
    fileMenu.setMnemonicParsing(true);//  w w w .  j  a v a 2s .c  o  m
    sampleMenu.setMnemonicParsing(true);
    goMenu.setMnemonicParsing(true);
    helpMenu.setMnemonicParsing(true);
    newProjectMenu.setAccelerator(new KeyCodeCombination(KeyCode.N, KeyCombination.SHORTCUT_DOWN));
    loadProjectMenu.setAccelerator(new KeyCodeCombination(KeyCode.L, KeyCombination.SHORTCUT_DOWN));
    addAffSampleMenu.setAccelerator(
            new KeyCodeCombination(KeyCode.A, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN));
    addUnSampleMenu.setAccelerator(
            new KeyCodeCombination(KeyCode.U, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN));
    nextChromMenu.setAccelerator(new KeyCodeCombination(KeyCode.EQUALS, KeyCombination.SHORTCUT_DOWN));
    prevChromMenu.setAccelerator(new KeyCodeCombination(KeyCode.MINUS, KeyCombination.SHORTCUT_DOWN));
    firstChromMenu.setAccelerator(new KeyCodeCombination(KeyCode.DIGIT1, KeyCombination.SHORTCUT_DOWN));
    lastChromMenu.setAccelerator(new KeyCodeCombination(KeyCode.DIGIT0, KeyCombination.SHORTCUT_DOWN));
    redrawMenu.setAccelerator(new KeyCodeCombination(KeyCode.R, KeyCombination.SHORTCUT_DOWN));
    cacheChromsMenu.setAccelerator(
            new KeyCodeCombination(KeyCode.C, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN));
    saveToPngMenu.setAccelerator(
            new KeyCodeCombination(KeyCode.S, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN));
    autoFindRegions.setAccelerator(new KeyCodeCombination(KeyCode.F, KeyCombination.SHORTCUT_DOWN));
    //need to disable hideSavedRegionsMenu accelerator for linux - doesn't work for check menus
    hideSavedRegionsMenu.setAccelerator(
            new KeyCodeCombination(KeyCode.H, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN));
    clearSavedRegionsMenu.setAccelerator(
            new KeyCodeCombination(KeyCode.X, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN));
    displaySavedsRegionsMenu.setAccelerator(new KeyCodeCombination(KeyCode.T, KeyCombination.SHORTCUT_DOWN));
    outputSavedRegionsMenu.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCombination.SHORTCUT_DOWN));
    removeSampleMenu.setAccelerator(
            new KeyCodeCombination(KeyCode.R, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN));
    //set radio menu item toggle group
    ArrayList<RadioMenuItem> callQualityRadios = new ArrayList<>(
            Arrays.asList(noFilteringRadio, filter99, filter95, filter90, filter85));
    ToggleGroup callQualityToggle = new ToggleGroup();
    for (RadioMenuItem r : callQualityRadios) {
        r.setToggleGroup(callQualityToggle);
    }
    noFilteringRadio.setOnAction(new EventHandler() {
        @Override
        public void handle(Event ev) {
            setQualityFilter(null);
        }
    });

    filter99.setOnAction(new EventHandler() {
        @Override
        public void handle(Event ev) {
            setQualityFilter(0.01);
        }
    });

    filter95.setOnAction(new EventHandler() {
        @Override
        public void handle(Event ev) {
            setQualityFilter(0.05);
        }
    });

    filter90.setOnAction(new EventHandler() {
        @Override
        public void handle(Event ev) {
            setQualityFilter(0.10);
        }
    });

    filter85.setOnAction(new EventHandler() {
        @Override
        public void handle(Event ev) {
            setQualityFilter(0.15);
        }
    });

    nextChromMenu.setOnAction(new EventHandler() {
        @Override
        public void handle(Event ev) {
            selectNextChromosome(true);
        }
    });

    prevChromMenu.setOnAction(new EventHandler() {
        @Override
        public void handle(Event ev) {
            selectNextChromosome(false);
        }
    });

    firstChromMenu.setOnAction(new EventHandler() {
        @Override
        public void handle(Event ev) {
            if (!cancelButton.isDisabled()) {
                cancelButton.fire();
            }
            if (!chromosomeSelector.isDisabled()) {

                chromosomeSelector.getSelectionModel().selectFirst();
            }
        }
    });

    lastChromMenu.setOnAction(new EventHandler() {
        @Override
        public void handle(Event ev) {
            if (!cancelButton.isDisabled()) {
                cancelButton.fire();
            }
            if (!chromosomeSelector.isDisabled()) {
                chromosomeSelector.getSelectionModel().selectLast();
            }
        }
    });

    hideSavedRegionsMenu.setOnAction(new EventHandler() {
        @Override
        public void handle(Event ev) {
            showHideSavedRegions();
        }
    });

    colorComp.addAll(Arrays.asList(colorComponants));

    //selection context menu
    final ContextMenu scm = new ContextMenu();
    final MenuItem scmItem1 = new MenuItem("Display Flanking SNP IDs");
    scmItem1.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            /* get coordinates of selection and report back
             * flanking snp ids and coordinates
             */
            displayFlankingSnpIDs(dragSelectRectangle);

        }
    });
    final MenuItem scmItem2 = new MenuItem("Write Selected Region to File");
    scmItem2.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    /* get coordinates of selection and report back
                     * write SNPs in region to file
                     */
                    writeRegionToFile(dragSelectRectangle);
                }
            });
        }
    });
    final MenuItem scmItem3 = new MenuItem("Add To Saved Regions");
    scmItem3.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            /* get coordinates of selection and report back
             * write SNPs in region to file
             */
            saveSelection();
        }
    });
    final MenuItem scmItem4 = new MenuItem("Show/Hide Saved Regions");
    scmItem4.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            /* get coordinates of selection and report back
             * write SNPs in region to file
             */
            hideSavedRegionsMenu.selectedProperty().setValue(!hideSavedRegionsMenu.isSelected());
            hideSavedRegionsMenu.fire();
        }
    });
    final MenuItem scmItem5 = new MenuItem("Zoom Region");
    scmItem5.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    /* get coordinates of selection and report back
                     * write SNPs in region to file
                     */
                    zoomRegion(dragSelectRectangle);
                }
            });
        }
    });
    final MenuItem scmItem6 = new MenuItem("Write Saved Regions to File");
    scmItem6.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    /* get coordinates of selection and report back
                     * write SNPs in region to file
                     */
                    writeSavedRegionsToFile();
                }
            });
        }
    });

    scm.getItems().add(scmItem1);
    scm.getItems().add(scmItem2);
    scm.getItems().add(scmItem3);
    scm.getItems().add(scmItem4);
    scm.getItems().add(scmItem5);
    scm.getItems().add(scmItem6);
    //overlayPane context menu
    ocm = new ContextMenu();
    final MenuItem ocmItem1 = new MenuItem("Save Image to File");
    ocmItem1.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    drawPaneToPng();
                }
            });
        }
    });

    ocm.getItems().add(ocmItem1);
    ocm.getItems().add(scmItem4);
    ocm.getItems().add(scmItem6);

    //color selections
    colorComponantSelector.getItems().clear();
    colorComponantSelector.getItems().add("AA");
    colorComponantSelector.getItems().add("BB");
    colorComponantSelector.getItems().add("AB");
    colorComponantSelector.getItems().add("Selection Outline");
    colorComponantSelector.getItems().add("Selection Fill");
    colorComponantSelector.getItems().add("Saved Region Outline");
    colorComponantSelector.getItems().add("Saved Region Fill");
    colorComponantSelector.getSelectionModel().selectFirst();
    colorPicker.setValue(colorComponants[0]);
    colorComponantSelector.getSelectionModel().selectedIndexProperty()
            .addListener(new ChangeListener<Number>() {
                @Override
                public void changed(ObservableValue ov, Number value, Number new_value) {
                    colorPicker.setValue(colorComp.get(new_value.intValue()));
                    colorPicker.fireEvent(new ActionEvent());
                }
            });
    colorPicker.setOnAction(new EventHandler() {
        @Override
        public void handle(Event t) {
            if (!colorComp.get(colorComponantSelector.getSelectionModel().getSelectedIndex())
                    .equals(colorPicker.getValue())) {
                colorComp.set(colorComponantSelector.getSelectionModel().getSelectedIndex(),
                        colorPicker.getValue());
                saveProject();
                //colorComponants[colorComponantSelector.getSelectionModel().getSelectedIndex()] = colorPicker.getValue();
                if (colorComponantSelector.getSelectionModel().getSelectedIndex() == Colors.fill.value) {
                    dragSelectRectangle.setFill(colorPicker.getValue());
                } else if (colorComponantSelector.getSelectionModel().getSelectedIndex() == Colors.line.value) {
                    dragSelectRectangle.setStroke(colorPicker.getValue());
                } else if (colorComponantSelector.getSelectionModel()
                        .getSelectedIndex() == Colors.saveLine.value) {
                    for (Rectangle r : savedRegionsDisplay) {
                        r.setStroke(colorPicker.getValue());
                    }
                } else if (colorComponantSelector.getSelectionModel()
                        .getSelectedIndex() == Colors.saveFill.value) {
                    for (Rectangle r : savedRegionsDisplay) {
                        r.setFill(colorPicker.getValue());
                    }
                } else {
                    removeSavedChromosomeImages();
                    if (redrawCheckBox.isSelected()) {
                        refreshView(null, true);
                    }
                }
            }
        }
    });

    /*perform appropriate action when user selects a chromosome
     * from the chromosome choice box
     */
    chromosomeSelector.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
        @Override
        public void changed(ObservableValue ov, Number value, Number new_value) {
            chromosomeBoxList = chromosomeSelector.getItems().toArray();

            if (new_value.intValue() > -1) {
                chromosomeSelected((String) chromosomeBoxList[new_value.intValue()]);
            }
        }
    });

    chromosomeSelector.addEventFilter(KeyEvent.ANY, new EventHandler<KeyEvent>() {
        @Override
        public void handle(KeyEvent ke) {
            if (ke.getCode() == KeyCode.UP) {
                ke.consume();
                chromosomeSelector.show();
            }
        }
    });

    selectionOverlayPane.heightProperty().addListener(new ChangeListener<Number>() {
        @Override
        public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneWidth,
                Number newSceneWidth) {
            windowResized(new ActionEvent());

        }
    });

    selectionOverlayPane.widthProperty().addListener(new ChangeListener<Number>() {
        @Override
        public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneWidth,
                Number newSceneWidth) {
            windowResized(new ActionEvent());
        }
    });

    /*upon addition of a new affected file adjust components accordingly
     * i.e. ensure appropriate chromosomes are in the choice box
     * adjust the split panes to fit all files and redisplay
     */

    affObserve.addListener(new ListChangeListener() {
        @Override
        public void onChanged(ListChangeListener.Change change) {
            change.next();/*from the javadoc 
                          * 'Go to the next change. In initial state is invalid a require 
                          * a call to next() before calling other methods. The first 
                          * next() call will make this object represent the first change.
                          */
            if (change.getRemovedSize() > 0) {
                List<SnpFile> both = new ArrayList<>(unFiles);
                both.addAll(affFiles);
                recheckChromosomeSelector(both);//need to check all files again, not just affFiles
            } else if (change.getAddedSize() > 0) {
                addToChromosomeSelector(affFiles);
            }
        }
    });

    /*as above 
     * but for unaffected files
     */
    unObserve.addListener(new ListChangeListener() {
        @Override
        public void onChanged(ListChangeListener.Change change) {
            change.next();
            if (change.getRemovedSize() > 0) {
                List<SnpFile> both = new ArrayList<>(unFiles);
                both.addAll(affFiles);
                recheckChromosomeSelector(both);//need to check all files again, not just unFiles
            } else if (change.getAddedSize() > 0) {
                addToChromosomeSelector(unFiles);
            }

        }
    });

    selectionOverlayPane.addEventHandler(MouseEvent.MOUSE_MOVED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent e) {
            if (!genomeVersion.equals("") && chromosomeSelector.getSelectionModel().getSelectedIndex() > -1) {
                try {
                    ChromosomeLength chromLength = new ChromosomeLength(genomeVersion);
                    String currentChrom = (String) chromosomeBoxList[chromosomeSelector.getSelectionModel()
                            .getSelectedIndex()];
                    double coordinate = chromLength.getLength(currentChrom) / chromSplitPane.getWidth()
                            * e.getX();
                    positionIndicator.setText(nf.format(coordinate));

                } catch (Exception ex) {
                    positionIndicator.setText("Build Error!");
                }

            }
        }
    });
    /*handle mouse dragging and effect on dragSelectRectangle
     * 
     */
    dragSelectRectangle.widthProperty().bind(dragSelectRectX.subtract(dragSelectRectInitX));
    dragSelectRectangle.heightProperty().bind(selectionOverlayPane.heightProperty());
    //dragSelectRectangle.strokeProperty().set(colorComponants[Colors.line.value]);
    dragSelectRectangle.setStrokeWidth(4.0);

    //dragSelectRectangle.setBlendMode(BlendMode.SCREEN);
    dragSelectRectangle.setOpacity(0.45);
    dragSelectRectangle.setVisible(false);
    selectionOverlayPane.getChildren().add(dragSelectRectangle);

    selectionOverlayPane.addEventHandler(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent e) {
            if (scm.isShowing()) {
                scm.hide();
            }
            if (!e.isPrimaryButtonDown()) {
                if (e.isSecondaryButtonDown()) {
                    //check we're not overlapping selection
                    if (e.getX() >= dragSelectRectangle.getX()
                            && e.getX() <= (dragSelectRectangle.getX() + dragSelectRectangle.getWidth())) {
                        return;
                    }
                    //check we're not overlapping saved regions
                    for (Rectangle r : savedRegionsDisplay) {
                        if (r.isVisible() && e.getX() >= r.getX() && e.getX() <= r.getX() + r.getWidth()) {
                            return;
                        }
                    }
                    if (chromosomeSelector.getSelectionModel().isEmpty()) {
                        ocmItem1.setDisable(true);
                    } else {
                        ocmItem1.setDisable(false);
                    }
                    ocm.show(selectionOverlayPane, e.getScreenX(), e.getScreenY());

                    return;
                }
            }
            if (ocm.isShowing()) {
                ocm.hide();
            }

            dragSelectRectangle.strokeProperty().set(colorComp.get(Colors.line.value));
            dragSelectRectangle.fillProperty().set(colorComp.get(Colors.fill.value));
            dragSelectRectX.set(0);
            dragSelectRectangle.setVisible(true);
            dragSelectRectangle.setX(e.getX());
            dragSelectRectangle.setY(0);
            dragSelectRectInitX.set(e.getX());
            anchorInitX.set(e.getX());

        }
    });
    selectionOverlayPane.addEventHandler(MouseEvent.MOUSE_DRAGGED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent e) {
            if (!e.isPrimaryButtonDown()) {
                return;
            }
            dragSelectRectangle.setVisible(true);
            if (e.getX() > anchorInitX.doubleValue()) {//dragging to the right
                if (e.getX() <= selectionOverlayPane.getLayoutX() + selectionOverlayPane.getWidth()) {
                    //mouse is before the edge of the pane
                    dragSelectRectInitX.set(anchorInitX.doubleValue());
                    dragSelectRectX.set(e.getX());
                } else {
                    //mouse is over the edge
                    dragSelectRectX.set(selectionOverlayPane.getWidth());
                }
            } else {
                if (e.getX() > selectionOverlayPane.getLayoutX()) {
                    dragSelectRectInitX.set(e.getX());
                    dragSelectRectangle.setX(e.getX());
                    dragSelectRectX.set(anchorInitX.doubleValue());
                } else {
                    dragSelectRectInitX.set(0);
                    dragSelectRectangle.setX(0);
                    /* the two lines below are just to trigger 
                    * dragSelectRectangle.widthProperty listener 
                    * so that start coordinate changes to 1
                    */
                    dragSelectRectX.set(anchorInitX.doubleValue() + 1);
                    dragSelectRectX.set(anchorInitX.doubleValue() + 1);

                }
            }
        }
    });

    selectionOverlayPane.addEventHandler(MouseEvent.MOUSE_RELEASED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent e) {
            //dragSelectRectX.set(e.getX());
            if (!e.isPrimaryButtonDown()) {
                return;
            }
            dragSelectRectangle.setVisible(true);
            if (dragSelectRectangle.getWidth() == 0) {
                clearDragSelectRectangle();
            }
        }
    });

    dragSelectRectangle.widthProperty().addListener(new ChangeListener() {
        @Override
        public void changed(ObservableValue observableValue, Object oldValue, Object newRectWidth) {
            if (!genomeVersion.equals("") && chromosomeSelector.getSelectionModel().getSelectedIndex() > -1
                    && dragSelectRectangle.getWidth() > 0) {
                try {
                    ChromosomeLength chromLength = new ChromosomeLength(genomeVersion);
                    String currentChrom = (String) chromosomeBoxList[chromosomeSelector.getSelectionModel()
                            .getSelectedIndex()];
                    double startCoordinate = chromLength.getLength(currentChrom)
                            / selectionOverlayPane.getWidth() * dragSelectRectangle.getX();
                    double selectionWidth = chromLength.getLength(currentChrom)
                            / selectionOverlayPane.getWidth() * dragSelectRectangle.getWidth();
                    if (dragSelectRectangle.getX() == 0) {
                        startCoordinate = 1;
                    }
                    selectionIndicator.setText("chr" + currentChrom + ":" + nf.format(startCoordinate) + "-"
                            + nf.format(startCoordinate + selectionWidth));
                } catch (Exception ex) {
                    selectionIndicator.setText("Build Error!");
                }
            } else {
                selectionIndicator.setText("");
            }

        }
    });

    dragSelectRectangle.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent e) {
            if (e.getButton() == MouseButton.SECONDARY) {
                if (chromosomeSelector.getSelectionModel().isEmpty()) {
                    scmItem1.setDisable(true);
                    scmItem2.setDisable(true);
                } else {
                    scmItem1.setDisable(false);
                    scmItem2.setDisable(false);
                }
                if (ocm.isShowing()) {
                    ocm.hide();
                }

                scm.show(selectionOverlayPane, e.getScreenX(), e.getScreenY());
            }
        }
    });

}