Example usage for javafx.scene.control ToggleButton setOnAction

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

Introduction

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

Prototype

public final void setOnAction(EventHandler<ActionEvent> value) 

Source Link

Usage

From source file:be.makercafe.apps.makerbench.editors.JFXMillEditor.java

/**
 * Creates the toolBar for the editor./*ww w  . ja v a  2s.  c  o m*/
 *
 * @return
 */

private ToolBar createToolBar() {

    ToolBar toolBar = new ToolBar();
    toolBar.setOrientation(Orientation.HORIZONTAL);

    Button btnSave = GlyphsDude.createIconButton(MaterialDesignIcon.FLOPPY, "Save");
    btnSave.setOnAction(this::handleSaveButton);

    Button btnExportSTL = GlyphsDude.createIconButton(MaterialDesignIcon.EXPORT, "Export GCODE");

    btnExportSTL.setOnAction(this::handleExportAsGCodeFile);

    Button btnExportPNG = GlyphsDude.createIconButton(MaterialDesignIcon.CAMERA, "Export PNG");
    btnExportPNG.setOnAction(this::handleExportAsPngFile);

    Button btnRun = GlyphsDude.createIconButton(MaterialDesignIcon.RUN, "Run");
    btnRun.setOnAction(this::handleCompileAndRun);

    ToggleButton btnAutoCompile = GlyphsDude.createIconToggleButton(MaterialDesignIcon.AUTO_FIX,
            "Automatic run", null, ContentDisplay.LEFT);
    btnAutoCompile.setOnAction(this::handleAutoCompile);
    btnAutoCompile.setSelected(false);

    ToggleButton btn3DNav = GlyphsDude.createIconToggleButton(MaterialDesignIcon.ROTATE_3D, "3D Navigation ",
            null, ContentDisplay.LEFT);
    btn3DNav.setSelected(false);

    ComboBox cbxSourceExamples = new ComboBox();
    cbxSourceExamples.getItems().addAll("TestCut");
    this.cbxSourceExamples = cbxSourceExamples; // TODO: maybe cleaner way
    // to do this ?

    Button btnPasteSource = GlyphsDude.createIconButton(MaterialDesignIcon.CONTENT_PASTE, "Paste source");
    btnPasteSource.setOnAction(this::handlePasteSource);

    toolBar.getItems().addAll(btnSave, btnExportSTL, btnExportPNG, new Separator(), btnRun, new Separator(),
            btnAutoCompile, new Separator(), cbxSourceExamples, btnPasteSource);

    return toolBar;

}

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 va  2s.c  o 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);
}