Example usage for javafx.scene.control ToggleButton getOnAction

List of usage examples for javafx.scene.control ToggleButton getOnAction

Introduction

In this page you can find the example usage for javafx.scene.control ToggleButton getOnAction.

Prototype

public final EventHandler<ActionEvent> getOnAction() 

Source Link

Usage

From source file:com.jscriptive.moneyfx.ui.chart.ChartFrame.java

private void reEnactToggleSelection() {
    ToggleButton selectedToggle = (ToggleButton) chartToggleGroup.getSelectedToggle();
    if (selectedToggle == null) {
        return;//from  ww w  .  ja  va 2  s  .  c  o  m
    }
    EventHandler<ActionEvent> onAction = selectedToggle.getOnAction();
    onAction.handle(new ActionEvent(selectedToggle, selectedToggle));
}

From source file:cz.lbenda.gui.tableView.FilterMenuItem.java

/** Prepare buttons to button bar */
private void prepareBars() {
    ToggleButton sortAsc = new ToggleButton(msgSortAsc,
            IconFactory.getInstance().imageView(this, ICON_SORT_ASC, IconFactory.IconLocation.LOCAL_TOOLBAR));
    ToggleButton sortDsc = new ToggleButton(msgSortDsc,
            IconFactory.getInstance().imageView(this, ICON_SORT_DSC, IconFactory.IconLocation.LOCAL_TOOLBAR));

    //noinspection unchecked
    final StringConverter converter = filterableTableView.stringConverter(tableColumn);

    comparatorAsc = (o1, o2) -> {/*from  w  w w .  j a v  a2s  .  co m*/
        //noinspection unchecked
        Object value1 = filterableTableView.valueForColumn(o1, tableColumn);
        //noinspection unchecked
        Object value2 = filterableTableView.valueForColumn(o2, tableColumn);
        if (value1 == null) {
            if (value2 == null) {
                return 0;
            } else {
                return 1;
            }
        } else if (value2 == null) {
            return -1;
        }
        if (value1 instanceof Comparable) {
            //noinspection unchecked
            return ((Comparable) value1).compareTo(value2);
        }
        //noinspection unchecked
        return converter.toString(value1).compareTo(converter.toString(value2));
    };
    comparatorDsc = comparatorAsc.reversed();

    sortToggleGroup.getToggles().addAll(sortAsc, sortDsc);

    sortAsc.setOnAction(event -> {
        Toggle tg = sortToggleGroup.getSelectedToggle();
        if (tg == sortDsc) {
            //noinspection unchecked
            filterableTableView.sortProperty().setValue(comparatorDsc);
        } else if (tg == sortAsc) {
            //noinspection unchecked
            filterableTableView.sortProperty().setValue(comparatorAsc);
        } else {
            //noinspection unchecked
            filterableTableView.sortProperty().setValue(null);
        }
    });
    sortDsc.setOnAction(sortAsc.getOnAction());
    buttonBar.getChildren().addAll(sortAsc, sortDsc);
}