Java Code Examples for javafx.util.Callback#call()

The following examples show how to use javafx.util.Callback#call() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DisplayableListCell.java    From Quelea with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Provide a callback that sets the given context menu on each cell, if and
 * only if the constraint given passes. If the constraint is null, it will
 * always pass.
 * <p/>
 * @param <T> the generic type of the cell.
 * @param contextMenu the context menu to show.
 * @param cellFactory the cell factory to use.
 * @param constraint the constraint placed on showing the context menu - it
 * will only be shown if this constraint passes, or it is null.
 * @return a callback that sets the given context menu on each cell.
 */
public static <T> Callback<ListView<T>, ListCell<T>> forListView(final ContextMenu contextMenu, final Callback<ListView<T>, ListCell<T>> cellFactory,
        final Constraint<T> constraint) {
    return new Callback<ListView<T>, ListCell<T>>() {
        @Override
        public ListCell<T> call(ListView<T> listView) {
            final ListCell<T> cell = cellFactory == null ? new DefaultListCell<T>() : cellFactory.call(listView);
            cell.itemProperty().addListener(new ChangeListener<T>() {
                @Override
                public void changed(ObservableValue<? extends T> ov, T oldVal, T newVal) {
                    if(newVal == null || (constraint != null && !constraint.isTrue(newVal))) {
                        cell.setContextMenu(null);
                    }
                    else {
                        cell.setContextMenu(contextMenu);
                    }
                }
            });
            return cell;
        }
    };
}
 
Example 2
Source File: JavaFXCheckBoxTreeTableCell.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public String _getValue() {
    CheckBoxTreeTableCell cell = (CheckBoxTreeTableCell) node;
    Callback selectedStateCallback = cell.getSelectedStateCallback();
    String cbText;
    if (selectedStateCallback != null) {
        ObservableValue<Boolean> call = (ObservableValue<Boolean>) selectedStateCallback.call(cell.getItem());
        int selection = call.getValue() ? 2 : 0;
        cbText = JavaFXCheckBoxElement.states[selection];
    } else {
        Node cb = cell.getGraphic();
        JavaFXElement comp = (JavaFXElement) JavaFXElementFactory.createElement(cb, driver, window);
        cbText = comp._getValue();

    }
    String cellText = cell.getText();
    if (cellText == null) {
        cellText = "";
    }
    String text = cellText + ":" + cbText;
    return text;
}
 
Example 3
Source File: JavaFXCheckBoxTableCellElement.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public String _getValue() {
    CheckBoxTableCell cell = (CheckBoxTableCell) node;
    Callback selectedStateCallback = cell.getSelectedStateCallback();
    String cbText;
    if (selectedStateCallback != null) {
        ObservableValue<Boolean> call = (ObservableValue<Boolean>) selectedStateCallback.call(cell.getItem());
        int selection = call.getValue() ? 2 : 0;
        cbText = JavaFXCheckBoxElement.states[selection];
    } else {
        Node cb = cell.getGraphic();
        JavaFXElement comp = (JavaFXElement) JavaFXElementFactory.createElement(cb, driver, window);
        cbText = comp._getValue();

    }
    String cellText = cell.getText();
    if (cellText == null) {
        cellText = "";
    }
    String text = cellText + ":" + cbText;
    return text;
}
 
Example 4
Source File: RFXCheckBoxTreeTableCell.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public String _getValue() {
    CheckBoxTreeTableCell cell = (CheckBoxTreeTableCell) node;
    Callback selectedStateCallback = cell.getSelectedStateCallback();
    String cbText;
    if (selectedStateCallback != null) {
        ObservableValue<Boolean> call = (ObservableValue<Boolean>) selectedStateCallback.call(cell.getItem());
        int selection = call.getValue() ? 2 : 0;
        cbText = JavaFXCheckBoxElement.states[selection];
    } else {
        Node cb = cell.getGraphic();
        RFXComponent comp = getFinder().findRawRComponent(cb, null, null);
        cbText = comp._getValue();

    }
    return cbText;
}
 
Example 5
Source File: RFXCheckBoxTableCell.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public String _getValue() {
    CheckBoxTableCell cell = (CheckBoxTableCell) node;
    Callback selectedStateCallback = cell.getSelectedStateCallback();
    String cbText;
    if (selectedStateCallback != null) {
        ObservableValue<Boolean> call = (ObservableValue<Boolean>) selectedStateCallback.call(cell.getItem());
        int selection = call.getValue() ? 2 : 0;
        cbText = JavaFXCheckBoxElement.states[selection];
    } else {
        Node cb = cell.getGraphic();
        RFXComponent comp = getFinder().findRawRComponent(cb, null, null);
        cbText = comp._getValue();
    }
    return cbText;
}
 
Example 6
Source File: ContextMenuListCell.java    From Quelea with GNU General Public License v3.0 5 votes vote down vote up
public static <T> Callback<ListView<T>, ListCell<T>> forListView(final ContextMenu contextMenu, final Callback<ListView<T>, ListCell<T>> cellFactory) {
    return new Callback<ListView<T>, ListCell<T>>() {
        @Override
        public ListCell<T> call(ListView<T> listView) {
            ListCell<T> cell = cellFactory == null ? new DefaultListCell<T>() : cellFactory.call(listView);
            cell.setContextMenu(contextMenu);
            return cell;
        }
    };
}
 
Example 7
Source File: TextTableExt.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initializes a new table view extension.
 *
 * @param tableView tree table view to extend
 */
public TextTableExt(JFXTreeTableView<StatementItem> treeTableView) {
  this.treeTableView = treeTableView;
  // Callback to monitor row creation and to identify visible screen rows
  final Callback<TreeTableView<StatementItem>, TreeTableRow<StatementItem>> rf = treeTableView.getRowFactory();
  // modify row factory
  final Callback<TreeTableView<StatementItem>, TreeTableRow<StatementItem>> modifiedRowFactory = param -> {
    TreeTableRow<StatementItem> r = rf != null ? rf.call(param) : new TreeTableRow<StatementItem>();
    // Save row, this implementation relies on JaxaFX re-using TableRow efficiently
    rows.add(r);
    return r;
  };
  treeTableView.setRowFactory(modifiedRowFactory);
}
 
Example 8
Source File: TableViewExtra.java    From Recaf with MIT License 5 votes vote down vote up
/**
 * @param tableView
 * 		Table to wrap.
 */
public TableViewExtra(TableView<T> tableView) {
	this.table = tableView;
	// Callback to monitor row creation and to identify visible screen rows
	final Callback<TableView<T>, TableRow<T>> rf = tableView.getRowFactory();
	final Callback<TableView<T>, TableRow<T>> modifiedRowFactory = param -> {
		TableRow<T> r = rf != null ? rf.call(param) : new TableRow<>();
		// Save row, this implementation relies on JaxaFX re-using TableRow efficiently
		rows.add(r);
		return r;
	};
	tableView.setRowFactory(modifiedRowFactory);
}
 
Example 9
Source File: JFXDrawer.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
/**
 * this method is only used in drawers stack component
 *
 * @param callback
 */
void bringToFront(Callback<Void, Void> callback) {
    EventHandler<? super MouseEvent> eventFilter = Event::consume;
    final boolean fillSize = prefSizeProperty.get() == USE_COMPUTED_SIZE;
    // disable mouse events
    this.addEventFilter(MouseEvent.ANY, eventFilter);

    Runnable onFinished = () -> {
        callback.call(null);
        translateTo = 0;
        translateTimer.setOnFinished(() -> {
            if (fillSize) {
                prefSizeProperty.set(USE_COMPUTED_SIZE);
                maxSizeProperty.set(USE_COMPUTED_SIZE);
            }
            // enable mouse events
            this.removeEventFilter(MouseEvent.ANY, eventFilter);
        });
        getCachePolicy().cache(contentHolder);
        translateTimer.start();
    };

    if (sizeProperty.get() > getDefaultDrawerSize()) {
        tempDrawerSize = sizeProperty.get();
    } else {
        tempDrawerSize = getDefaultDrawerSize();
    }
    translateTo = initTranslate.get();
    translateTimer.setOnFinished(onFinished);
    getCachePolicy().cache(contentHolder);
    translateTimer.start();
}