下面列出了org.apache.commons.io.filefilter.WildcardFileFilter#javafx.beans.binding.Bindings 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void init() {
Bindings.bindBidirectional(tooltipText, tooltipProperty(), new StringConverter<Tooltip>() {
@Override
public String toString(Tooltip tooltip) {
if (tooltip == null) {
return null;
}
return tooltip.getText();
}
@Override
public Tooltip fromString(String string) {
if (string == null) {
return null;
}
return new Tooltip(string);
}
});
iconPath.addListener((observable, oldValue, newValue) ->
graphicProperty().set(new ImageView(new Image(getClass().getResourceAsStream(newValue)))));
}
/**
* Create the {@link ComboBox} containing the known themes
*
* @return A {@link ComboBox} containing the known themes
*/
private ComboBox<Theme> createThemeSelection() {
final ComboBox<Theme> themeSelection = new ComboBox<>();
Bindings.bindContent(themeSelection.getItems(), getControl().getThemes());
themeSelection.valueProperty().bindBidirectional(getControl().selectedThemeProperty());
themeSelection.setConverter(new StringConverter<>() {
@Override
public String toString(Theme theme) {
return theme.getName();
}
@Override
public Theme fromString(String themeName) {
final Optional<Theme> foundTheme = getControl().getThemes().stream()
.filter(theme -> themeName.equals(theme.getName()))
.findFirst();
return foundTheme.orElseThrow(
() -> new IllegalArgumentException("Couldn't find theme with name \"" + themeName + "\""));
}
});
return themeSelection;
}
@Override
public TableRow<DownloadInfo> call(TableView<DownloadInfo> view) {
final TableRow<DownloadInfo> row = new TableRow<>();
DownloadInfo info = view.getSelectionModel().getSelectedItem();
initListeners(view, info);
row.contextMenuProperty().bind(
Bindings.when(Bindings.isNotNull(row.itemProperty())).then(rowMenu).otherwise((ContextMenu) null));
row.addEventFilter(MouseEvent.MOUSE_PRESSED, event -> {
final int index = row.getIndex();
if (!event.isPrimaryButtonDown())
return; // no action if it is not primary button
if (index >= view.getItems().size() || view.getSelectionModel().isSelected(index)) {
view.getSelectionModel().clearSelection();
event.consume();
}
});
return row;
}
public void initialize() {
edition.setShowTransitionFactory(BounceInRightTransition::new);
edition.showingProperty().addListener((obs, oldValue, newValue) -> {
if (newValue) {
AppBar appBar = getApp().getAppBar();
appBar.setNavIcon(MaterialDesignIcon.MENU.button(e ->
getApp().getDrawer().open()));
appBar.setTitleText("Edition");
}
});
submit.disableProperty().bind(Bindings.createBooleanBinding(() -> {
return authorText.textProperty().isEmpty()
.or(commentsText.textProperty().isEmpty()).get();
}, authorText.textProperty(), commentsText.textProperty()));
}
public void bindEnds (DraggableNode source, DraggableNode target) {
node_link.startXProperty().bind(
Bindings.add(source.layoutXProperty(), (source.getWidth() / 2.0)));
node_link.startYProperty().bind(
Bindings.add(source.layoutYProperty(), (source.getWidth() / 2.0)));
node_link.endXProperty().bind(
Bindings.add(target.layoutXProperty(), (target.getWidth() / 2.0)));
node_link.endYProperty().bind(
Bindings.add(target.layoutYProperty(), (target.getWidth() / 2.0)));
source.registerLink (getId());
target.registerLink (getId());
}
/**
* Creates the {@link EnginesSidebarToggleGroup} which contains all known engine categories
*/
private EnginesSidebarToggleGroup createSidebarToggleGroup() {
final FilteredList<EngineCategoryDTO> filteredEngineCategories = getControl().getItems()
.filtered(getControl().getFilter()::filter);
filteredEngineCategories.predicateProperty().bind(
Bindings.createObjectBinding(() -> getControl().getFilter()::filter,
getControl().searchTermProperty(),
getControl().showInstalledProperty(),
getControl().showNotInstalledProperty()));
final EnginesSidebarToggleGroup categoryView = new EnginesSidebarToggleGroup(tr("Engines"),
filteredEngineCategories);
getControl().selectedEngineCategoryProperty().bind(categoryView.selectedElementProperty());
return categoryView;
}
/**
* @param cellFactory
* Set a custom cell factory for the suggestions.
*/
public AutoCompletePopupSkin2(AutoCompletePopup<T> control, Callback<ListView<T>, ListCell<T>> cellFactory) {
this.control = control;
suggestionList = new ListView<>(control.getSuggestions());
suggestionList.getStyleClass().add(AutoCompletePopup.DEFAULT_STYLE_CLASS);
suggestionList.getStylesheets().add(AutoCompletionBinding.class
.getResource("autocompletion.css").toExternalForm()); //$NON-NLS-1$
/**
* Here we bind the prefHeightProperty to the minimum height between the max visible rows and the current items list. We also add an
* arbitrary 5 number because when we have only one item we have the vertical scrollBar showing for no reason.
*/
suggestionList.prefHeightProperty().bind(
Bindings.min(control.visibleRowCountProperty(), Bindings.size(suggestionList.getItems()))
.multiply(LIST_CELL_HEIGHT).add(18));
suggestionList.setCellFactory(cellFactory);
// Allowing the user to control ListView width.
suggestionList.prefWidthProperty().bind(control.prefWidthProperty());
suggestionList.maxWidthProperty().bind(control.maxWidthProperty());
suggestionList.minWidthProperty().bind(control.minWidthProperty());
registerEventListener();
}
public AutoCompleteItem() {
name = new Label();
name.setAlignment(Pos.CENTER_LEFT);
name.setStyle("-fx-font-weight: bold;");
path = new Label();
path.setMaxWidth(Double.POSITIVE_INFINITY);
HBox.setHgrow(path, Priority.ALWAYS);
HBox.setMargin(path, new Insets(0, 8, 0, 0));
path.setAlignment(Pos.CENTER_RIGHT);
path.setTextOverrun(OverrunStyle.CENTER_ELLIPSIS);
graphic = new ImageView();
graphic.setPreserveRatio(true);
graphic.fitHeightProperty().bind(Bindings.createDoubleBinding(() -> name.getFont().getSize() * 1.2, name.fontProperty()));
setText(null);
setGraphic(new HBox(2, graphic, name, path));
setPrefWidth(0);
}
@Override
public void initializeNext() {
try {
startButton.disableProperty().bind(Bindings.isEmpty(targetPathInput.textProperty())
.or(targetPathInput.styleProperty().isEqualTo(badStyle))
.or(Bindings.isEmpty(tableView.getItems()))
.or(leftXInput.styleProperty().isEqualTo(badStyle))
.or(leftYInput.styleProperty().isEqualTo(badStyle))
.or(rightXInput.styleProperty().isEqualTo(badStyle))
.or(rightYInput.styleProperty().isEqualTo(badStyle))
.or(centerWidthInput.styleProperty().isEqualTo(badStyle))
.or(centerHeightInput.styleProperty().isEqualTo(badStyle))
);
} catch (Exception e) {
logger.debug(e.toString());
}
}
/**
* Creates a {@link ContainersSidebarToggleGroup} object containing all installed containers
*/
private ContainersSidebarToggleGroup createSidebarToggleGroup() {
final FilteredList<ContainerCategoryDTO> filteredContainerCategories = getControl().getItems()
.filtered(getControl().getFilter()::filter);
filteredContainerCategories.predicateProperty().bind(
Bindings.createObjectBinding(() -> getControl().getFilter()::filter,
getControl().searchTermProperty(),
getControl().selectedContainerCategoryProperty()));
final ContainersSidebarToggleGroup sidebarToggleGroup = new ContainersSidebarToggleGroup(tr("Containers"),
filteredContainerCategories);
getControl().selectedContainerCategoryProperty().bind(sidebarToggleGroup.selectedElementProperty());
return sidebarToggleGroup;
}
@Override
public void initializeNext() {
try {
super.initializeNext();
startButton.disableProperty().unbind();
startButton.disableProperty().bind(
Bindings.isEmpty(tableView.getItems())
.or(Bindings.isEmpty(targetPathInput.textProperty()))
.or(targetPathInput.styleProperty().isEqualTo(badStyle))
.or(jpegBox.styleProperty().isEqualTo(badStyle))
.or(thresholdInput.styleProperty().isEqualTo(badStyle))
.or(Bindings.isEmpty(tableView.getItems()))
);
} catch (Exception e) {
logger.debug(e.toString());
}
}
RectangularImageViewSkin(RectangularImageView control) {
super(control);
clip = new Rectangle(getWidthToFit(), getHeightToFit());
imageView = new ImageView();
imageView.setSmooth(true);
imageView.setClip(clip);
imageView.imageProperty().bind(
Bindings.createObjectBinding(() -> getImage(getSkinnable().getImageURL()),
getSkinnable().imageURLProperty()));
getSkinnable().imageSizeProperty().addListener((observable, oldValue, newValue) -> {
clip.setWidth(getWidthToFit());
clip.setHeight(getHeightToFit());
getSkinnable().requestLayout();
});
getChildren().add(imageView);
}
private final void setupPath(final Path path) {
final MoveTo moveTo = pathProducer.createMoveTo(0d, 0d);
moveTo.xProperty().bind(Bindings.createDoubleBinding(() -> model.getPtAt(0).getX() + model.getWidth() / 2d,
model.getPtAt(0).xProperty(), model.getPtAt(1).xProperty()));
moveTo.yProperty().bind(model.getPtAt(0).yProperty());
path.getElements().add(moveTo);
LineTo lineTo = pathProducer.createLineTo(0d, 0d);
lineTo.xProperty().bind(model.getPtAt(2).xProperty());
lineTo.yProperty().bind(model.getPtAt(2).yProperty());
path.getElements().add(lineTo);
lineTo = pathProducer.createLineTo(0d, 0d);
lineTo.xProperty().bind(model.getPtAt(3).xProperty());
lineTo.yProperty().bind(model.getPtAt(3).yProperty());
path.getElements().add(lineTo);
path.getElements().add(pathProducer.createClosePath());
}
public BatchRunnerResult() {
reportRow().add(new ReadOnlyStringWrapper("Batch run"));
StringBinding successOrNot = Bindings.when(completelySuccessful())
.then(ApplicationState.getMessage(COMPLETED_SUCCESSFUL))
.otherwise(ApplicationState.getMessage(COMPLETED_UNSUCCESSFUL));
StringBinding successMessageBinding = Bindings.when(completed())
.then(successOrNot).otherwise(ApplicationState.getMessage(INCOMPLETE));
reportRow().add(successMessageBinding);
reportRow().add(percentCompleteString().concat(" complete"));
reportRow().add(percentSuccessString().concat(" success"));
reportRow().add(getDuration());
allBindings.add(successOrNot);
allBindings.add(successMessageBinding);
}
/**
* {@inheritDoc}
*/
@Override
public void setupBindings() {
super.setupBindings();
editableArea.visibleProperty().bind(Bindings.and(field.editableProperty(),
field.multilineProperty()));
editableField.visibleProperty().bind(Bindings.and(field.editableProperty(),
field.multilineProperty().not()));
readOnlyLabel.visibleProperty().bind(field.editableProperty().not());
editableField.textProperty().bindBidirectional(field.userInputProperty());
editableArea.textProperty().bindBidirectional(field.userInputProperty());
readOnlyLabel.textProperty().bind(field.userInputProperty());
editableField.promptTextProperty().bind(field.placeholderProperty());
editableArea.promptTextProperty().bind(field.placeholderProperty());
editableArea.managedProperty().bind(editableArea.visibleProperty());
editableField.managedProperty().bind(editableField.visibleProperty());
}
/**
* Creates a {@link FilteredList} object of the engine versions by applying the {@link EnginesFilter} known to the
* control
*
* @return A filtered list of the engine versions
*/
private ObservableList<EngineVersionDTO> createFilteredEngineVersions() {
final EnginesFilter filter = getControl().getFilter();
final EngineCategoryDTO engineCategory = getControl().getEngineCategory();
final EngineSubCategoryDTO engineSubCategory = getControl().getEngineSubCategory();
final FilteredList<EngineVersionDTO> filteredEngineVersions = FXCollections
.observableArrayList(engineSubCategory.getPackages())
.sorted(EngineSubCategoryDTO.comparator().reversed())
.filtered(filter.createFilter(engineCategory, engineSubCategory));
filteredEngineVersions.predicateProperty().bind(
Bindings.createObjectBinding(() -> filter.createFilter(engineCategory, engineSubCategory),
filter.searchTermProperty(),
filter.selectedEngineCategoryProperty(),
filter.showInstalledProperty(),
filter.showNotInstalledProperty()));
return filteredEngineVersions;
}
/**
* Creates the view.
* @param sh The model.
*/
ViewDot(final Dot sh, final PathElementProducer pathProducer) {
super(sh);
this.pathProducer = pathProducer;
path = new Path();
dot = new Ellipse();
getChildren().addAll(dot, path);
model.styleProperty().addListener(updateDot);
model.getPosition().xProperty().addListener(updateDot);
model.getPosition().yProperty().addListener(updateDot);
model.diametreProperty().addListener(updateDot);
model.fillingColProperty().addListener(updateDot);
model.lineColourProperty().addListener(updateStrokeFill);
rotateProperty().bind(Bindings.createDoubleBinding(() -> Math.toDegrees(model.getRotationAngle()), model.rotationAngleProperty()));
updateDot();
}
private void setupBindings() {
welcomeLbl.textProperty().bind(rootPane.welcomeText);
brightnessLbl.textProperty().bind(rootPane.brightness.asString().concat("%"));
nightModeLbl.textProperty().bind(rootPane.nightMode.asString());
scalingLbl.textProperty().bind(rootPane.scaling.asString());
screenNameLbl.textProperty().bind(rootPane.screenName);
resolutionLbl.textProperty().bind(rootPane.resolutionSelection);
orientationLbl.textProperty().bind(rootPane.orientationSelection);
favoritesLbl.textProperty().bind(Bindings.createStringBinding(
() -> rootPane.favoritesSelection.stream().collect(Collectors.joining(", ")),
rootPane.favoritesSelection
));
fontSizeLbl.textProperty().bind(rootPane.fontSize.asString());
lineSpacingLbl.textProperty().bind(rootPane.lineSpacing.asString());
favoriteNumberLbl.textProperty().bind(rootPane.customControlProperty.asString());
}
@Override
public void initializeNext() {
try {
startButton.disableProperty().unbind();
startButton.disableProperty().bind(Bindings.isEmpty(targetPathInput.textProperty())
.or(targetPathInput.styleProperty().isEqualTo(badStyle))
.or(Bindings.isEmpty(tableView.getItems()))
.or(marginWidthBox.getEditor().styleProperty().isEqualTo(badStyle))
.or(marginsTopCheck.styleProperty().isEqualTo(badStyle))
);
} catch (Exception e) {
logger.debug(e.toString());
}
}
public RunnerResult() {
durationBinding = Bindings.createLongBinding(() -> {
if (startTime.get() == -1) {
return 0L;
} else if (endTime.get() == -1) {
return System.currentTimeMillis() - startTime.get();
} else {
return endTime.get() - startTime.get();
}
}, startTime, endTime);
started.addListener((prop, oldVal, newVal) -> {
if (newVal && startTime.get() < 0) {
startTime.set(System.currentTimeMillis());
}
invalidateBindings();
});
completed().addListener(((prop, oldVal, newVal) -> {
if (newVal && endTime.get() < 0) {
endTime.set(System.currentTimeMillis());
}
invalidateBindings();
}));
}
@Override
public void initializeNext() {
try {
startButton.disableProperty().unbind();
startButton.disableProperty().bind(Bindings.isEmpty(targetPathInput.textProperty())
.or(targetPathInput.styleProperty().isEqualTo(badStyle))
.or(Bindings.isEmpty(tableView.getItems()))
.or(Bindings.isEmpty(waterInput.textProperty()))
.or(waterXInput.styleProperty().isEqualTo(badStyle))
.or(waterYInput.styleProperty().isEqualTo(badStyle))
.or(marginInput.styleProperty().isEqualTo(badStyle))
);
} catch (Exception e) {
logger.debug(e.toString());
}
}
public MeshExporterDialog(final MeshInfo<T> meshInfo)
{
super();
this.meshInfo = meshInfo;
this.dirPath = new TextField();
this.setTitle("Export mesh");
this.isError = (Bindings.createBooleanBinding(() -> dirPath.getText().isEmpty(), dirPath.textProperty()));
final MeshSettings settings = meshInfo.getMeshSettings();
this.scale = new TextField(Integer.toString(settings.getFinestScaleLevel()));
UIUtils.setNumericTextField(scale, settings.getNumScaleLevels() - 1);
setResultConverter(button -> {
if (button.getButtonData().isCancelButton()) { return null; }
return new MeshExportResult(
meshExporter,
filePath,
Integer.parseInt(scale.getText())
);
});
createDialog();
}
/**
* @param value
* Item value
*/
public FilterableTreeItem(T value) {
super(value);
// Support filtering by using a filtered list backing.
// - Apply predicate to items
FilteredList<TreeItem<T>> filteredChildren = new FilteredList<>(sourceChildren);
filteredChildren.predicateProperty().bind(Bindings.createObjectBinding(() -> child -> {
if(child instanceof FilterableTreeItem)
((FilterableTreeItem<T>) child).predicateProperty().set(predicate.get());
if(predicate.get() == null || !child.getChildren().isEmpty())
return true;
return predicate.get().test(child);
}, predicate));
// Reflection hackery
setUnderlyingChildren(filteredChildren);
}
@Override
public void initializeNext() {
try {
startButton.disableProperty().unbind();
startButton.disableProperty().bind(Bindings.isEmpty(targetPathInput.textProperty())
.or(targetPathInput.styleProperty().isEqualTo(badStyle))
.or(Bindings.isEmpty(tableView.getItems()))
.or(customWidthInput.styleProperty().isEqualTo(badStyle))
.or(customHeightInput.styleProperty().isEqualTo(badStyle))
.or(keepWidthInput.styleProperty().isEqualTo(badStyle))
.or(keepHeightInput.styleProperty().isEqualTo(badStyle))
.or(scaleBox.getEditor().styleProperty().isEqualTo(badStyle)));
} catch (Exception e) {
logger.debug(e.toString());
}
}
@Override
public void initializeNext() {
try {
initDirTab();
initConditionTab();
startButton.disableProperty().bind(
Bindings.isEmpty(sourcePathInput.textProperty())
.or(Bindings.isEmpty(targetPathInput.textProperty()))
.or(sourcePathInput.styleProperty().isEqualTo(badStyle))
.or(targetPathInput.styleProperty().isEqualTo(badStyle))
);
operationBarController.openTargetButton.disableProperty().bind(
startButton.disableProperty()
);
} catch (Exception e) {
logger.debug(e.toString());
}
}
private void bindProperties() {
ObjectMapper mapper = AppUtils.createJSONMapper();
try {
if (!Settings.getToolCOCOJson().isBlank()) {
coco = mapper.readValue(Settings.getToolCOCOJson(), COCO.class);
}
if (coco == null) {
coco = new COCO();
}
// Fields that can only accept numbers
txtInfoYear.setTextFormatter(AppUtils.createNumberTextFormatter());
txtLicenseId.setTextFormatter(AppUtils.createNumberTextFormatter());
// COCO info section
Bindings.bindBidirectional(txtInfoYear.textProperty(), coco.info.yearProperty, new NumberStringConverter("#"));
txtInfoVersion.textProperty().bindBidirectional(coco.info.versionProperty);
txtInfoDescription.textProperty().bindBidirectional(coco.info.descriptionProperty);
txtInfoContributor.textProperty().bindBidirectional(coco.info.contributorProperty);
txtInfoUrl.textProperty().bindBidirectional(coco.info.urlProperty);
datePicker.valueProperty().bindBidirectional(coco.info.dateCreatedProperty);
// COCO images
rbUsePathInXml.selectedProperty().bindBidirectional(coco.usePathInXmlProperty);
rbNameAsId.selectedProperty().bindBidirectional(coco.nameAsIdProperty);
dirMedia.disableProperty().bindBidirectional(coco.usePathInXmlProperty);
// COCO license section
Bindings.bindBidirectional(txtLicenseId.textProperty(), coco.license.idProperty, new NumberStringConverter("#"));
txtLicenseName.textProperty().bindBidirectional(coco.license.nameProperty);
txtLicenseUrl.textProperty().bindBidirectional(coco.license.urlProperty);
// Output
chkFormatJSON.selectedProperty().bindBidirectional(coco.formatJSONProperty);
fileOutput.textProperty().bindBidirectional(coco.outputProperty);
} catch (Exception ex) {
LOG.log(Level.WARNING, "Unable to initialize COCO info section", ex);
}
}
private void bindRotationTransformation(final Supplier<Double> pivotX, final Supplier<Double> pivotY) {
shapeRotation = new Rotate();
border.getTransforms().add(shapeRotation);
shapeRotation.angleProperty().bind(Bindings.createDoubleBinding(() -> Math.toDegrees(model.getRotationAngle()), model.rotationAngleProperty()));
shapeRotation.pivotXProperty().bind(Bindings.createDoubleBinding(() -> pivotX.get(), model.rotationAngleProperty(),
border.boundsInLocalProperty()));
shapeRotation.pivotYProperty().bind(Bindings.createDoubleBinding(() -> pivotY.get(), model.rotationAngleProperty(),
border.boundsInLocalProperty()));
}
@FXML
public void initialize() {
searchField.setTooltip(new Tooltip(Messages.SearchAvailableItems));
searchField.textProperty().addListener((changeListener, oldVal, newVal) -> {
searchAvailableItemsForSubstring(newVal);
});
add.setTooltip(new Tooltip(Messages.Add_Tooltip));
add.setGraphic(ImageCache.getImageView(ImageCache.class, ADD_ICON));
remove.setTooltip(new Tooltip(Messages.Remove_Tooltip));
remove.setGraphic(ImageCache.getImageView(ImageCache.class, REMOVE_ICON));
clear.setTooltip(new Tooltip(Messages.Clear_Tooltip));
clear.setGraphic(ImageCache.getImageView(ImageCache.class, CLEAR_ICON));
Platform.runLater(() -> {
add.disableProperty().bind(Bindings.isEmpty(availableItems.getSelectionModel().getSelectedItems()));
remove.disableProperty().bind(Bindings.isEmpty(selectedItems.getSelectionModel().getSelectedItems()));
clear.disableProperty().bind(Bindings.isEmpty(selectedItems.getItems()));
});
// Double click to add..
availableItems.setOnMouseClicked(event -> {
if (event.getClickCount() < 2)
return;
addSelected();
event.consume();
});
// .. or remove items
selectedItems.setOnMouseClicked(event -> {
if (event.getClickCount() < 2)
return;
removeSelected();
event.consume();
});
refresh();
}
@Override
public ObjectBinding<?> createBinding(BindingsType bind, ModularFeatureListRow row) {
// get all properties of all features
@SuppressWarnings("unchecked")
Property<Range<Double>>[] prop =
row.streamFeatures().map(f -> f.get(this)).toArray(Property[]::new);
switch (bind) {
case RANGE:
return Bindings.createObjectBinding(() -> {
Range<Double> result = null;
for (Property<Range<Double>> p : prop) {
if (p.getValue() != null) {
if (result == null)
result = p.getValue();
else
result = result.span(p.getValue());
}
}
return result;
}, prop);
case AVERAGE:
case MIN:
case MAX:
case SUM:
case COUNT:
default:
throw new UndefinedRowBindingException(this, bind);
}
}
@Override
public ObjectBinding<?> createBinding(BindingsType bind, ModularFeatureListRow row) {
// get all properties of all features
@SuppressWarnings("unchecked")
Property<Range<Integer>>[] prop =
row.streamFeatures().map(f -> f.get(this)).toArray(Property[]::new);
switch (bind) {
case RANGE:
return Bindings.createObjectBinding(() -> {
Range<Integer> result = null;
for (Property<Range<Integer>> p : prop) {
if (p.getValue() != null) {
if (result == null)
result = p.getValue();
else
result = result.span(p.getValue());
}
}
return result;
}, prop);
case AVERAGE:
case MIN:
case MAX:
case SUM:
case COUNT:
default:
throw new UndefinedRowBindingException(this, bind);
}
}