use of javafx.beans.value.ObservableValue in project jvarkit by lindenb.
the class VcfStage method buildGenotypeTableRow.
/**
* build Genotype table
*/
private TableView<Genotype> buildGenotypeTableRow(final VCFHeader header) {
final TableView<Genotype> table = new TableView<Genotype>();
/* sample */
table.getColumns().add(makeColumn("Sample", G -> G.getSampleName()));
for (final VCFFormatHeaderLine h : header.getFormatHeaderLines()) {
final TableColumn<Genotype, String> newcol = new TableColumn<>(h.getID());
newcol.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Genotype, String>, ObservableValue<String>>() {
@Override
public ObservableValue<String> call(CellDataFeatures<Genotype, String> param) {
final String delim;
Object o;
if (param.getTableColumn().getText().equals(VCFConstants.GENOTYPE_KEY)) {
delim = param.getValue().isPhased() ? "|" : "/";
o = param.getValue().getAlleles().stream().map(A -> allele2stringConverter.apply(A)).collect(Collectors.toList());
} else {
delim = ",";
o = param.getValue().getAnyAttribute(param.getTableColumn().getText());
}
if (o == null) {
return new ReadOnlyObjectWrapper<String>(null);
}
if (o instanceof List) {
List<?> L = (List<?>) o;
o = L.stream().map(S -> String.valueOf(S)).collect(Collectors.joining(delim)).toString();
}
return new ReadOnlyObjectWrapper<String>(String.valueOf(o));
}
});
table.getColumns().add(newcol);
}
/* type */
table.getColumns().add(makeColumn("Type", G -> G.getType().name()));
table.setPlaceholder(new Label("No Genotype."));
return table;
}
use of javafx.beans.value.ObservableValue in project jvarkit by lindenb.
the class VcfStage method buildFilterTable.
/**
* build FILTER table
*/
private TableView<String> buildFilterTable() {
final TableView<String> table = new TableView<>();
final TableColumn<String, String> scol = new TableColumn<>("Filter");
scol.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<String, String>, ObservableValue<String>>() {
@Override
public ObservableValue<String> call(CellDataFeatures<String, String> param) {
return new ReadOnlyObjectWrapper<String>(param.getValue());
}
});
table.getColumns().add(scol);
table.setPlaceholder(new Label("No Variant or Variant contains no Filter"));
return table;
}
use of javafx.beans.value.ObservableValue in project JFoenix by jfoenixadmin.
the class JFXNodeUtils method addDelayedPropertyInvalidationListener.
public static <T> InvalidationListener addDelayedPropertyInvalidationListener(ObservableValue<T> property, Duration delayTime, Consumer<T> justInTimeConsumer, Consumer<T> delayedConsumer) {
Wrapper<T> eventWrapper = new Wrapper<>();
PauseTransition holdTimer = new PauseTransition(delayTime);
holdTimer.setOnFinished(event -> delayedConsumer.accept(eventWrapper.content));
final InvalidationListener invalidationListener = observable -> {
eventWrapper.content = property.getValue();
justInTimeConsumer.accept(eventWrapper.content);
holdTimer.playFromStart();
};
property.addListener(invalidationListener);
return invalidationListener;
}
use of javafx.beans.value.ObservableValue in project JFoenix by jfoenixadmin.
the class JFXNodeUtils method addDelayedPropertyInvalidationListener.
public static <T> InvalidationListener addDelayedPropertyInvalidationListener(ObservableValue<T> property, Duration delayTime, BiConsumer<T, InvalidationListener> consumer) {
Wrapper<T> eventWrapper = new Wrapper<>();
PauseTransition holdTimer = new PauseTransition(delayTime);
final InvalidationListener invalidationListener = observable -> {
eventWrapper.content = property.getValue();
holdTimer.playFromStart();
};
holdTimer.setOnFinished(event -> consumer.accept(eventWrapper.content, invalidationListener));
property.addListener(invalidationListener);
return invalidationListener;
}
use of javafx.beans.value.ObservableValue in project jgnash by ccavanaugh.
the class ReportViewerDialogController method initialize.
@FXML
private void initialize() {
busyPane = new BusyPane();
stackPane.getChildren().add(busyPane);
saveButton.disableProperty().bind(report.isNull());
reportFormatButton.disableProperty().bind(report.isNull());
fontSizeSpinner.disableProperty().bind(report.isNull());
firstButton.disableProperty().bind(report.isNull().or(pageCount.isEqualTo(0)).or(pageIndex.isEqualTo(0)));
previousButton.disableProperty().bind(report.isNull().or(pageCount.isEqualTo(0)).or(pageIndex.isEqualTo(0)));
nextButton.disableProperty().bind(report.isNull().or(pageCount.isEqualTo(0)).or(pageIndex.isEqualTo(pageCount.subtract(1))));
lastButton.disableProperty().bind(report.isNull().or(pageCount.isEqualTo(0)).or(pageIndex.isEqualTo(pageCount.subtract(1))));
fitPageButton.disableProperty().bind(report.isNull());
fitHeightButton.disableProperty().bind(report.isNull());
fitWidthButton.disableProperty().bind(report.isNull());
zoomComboBox.disableProperty().bind(report.isNull());
zoomInButton.disableProperty().bind(report.isNull().or(zoomProperty.greaterThanOrEqualTo(DEFAULT_ZOOMS[DEFAULT_ZOOMS.length - 1] / 100)));
zoomOutButton.disableProperty().bind(report.isNull().or(zoomProperty.lessThanOrEqualTo(DEFAULT_ZOOMS[0] / 100)));
fitPageButton.setSelected(true);
firstButton.prefHeightProperty().bind(saveButton.heightProperty());
previousButton.prefHeightProperty().bind(saveButton.heightProperty());
nextButton.prefHeightProperty().bind(saveButton.heightProperty());
lastButton.prefHeightProperty().bind(saveButton.heightProperty());
zoomInButton.prefHeightProperty().bind(saveButton.heightProperty());
zoomOutButton.prefHeightProperty().bind(saveButton.heightProperty());
fitHeightButton.prefHeightProperty().bind(saveButton.heightProperty());
fitWidthButton.prefHeightProperty().bind(saveButton.heightProperty());
fitPageButton.prefHeightProperty().bind(saveButton.heightProperty());
fontSizeSpinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(5, 15, 7));
// act when the report property has been set or changed
report.addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
fontSizeSpinner.valueFactoryProperty().get().setValue((double) newValue.getBaseFontSize());
}
});
reportControllerPaneProperty.addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
reportControllerPane.getChildren().addAll(newValue);
}
});
fontSizeSpinner.valueProperty().addListener((observable, oldValue, newValue) -> {
report.get().setBaseFontSize(newValue.floatValue());
if (reportController != null) {
reportController.refreshReport();
}
});
pagePane.setSpacing(PAGE_BORDER);
pagePane.setPadding(new Insets(PAGE_BORDER));
pagePane.setAlignment(Pos.CENTER);
scrollPane.viewportBoundsProperty().addListener((observable, oldValue, newValue) -> {
if (fitWidthButton.isSelected()) {
handleFitPageWidthAction();
}
scrollPane.setFitToWidth(pagePane.prefWidth(-1) < newValue.getWidth());
scrollPane.setFitToHeight(pagePane.prefHeight(-1) < newValue.getHeight());
});
scrollPane.vvalueProperty().addListener((ObservableValue<? extends Number> observable, Number oldValue, Number newValue) -> {
final double interval = 1d / pageCount.get();
double low = pageIndex.get() * interval;
double hi = low + interval;
int newPageIndex = pageIndex.get();
if (hi < newValue.doubleValue() && pageIndex.get() < pageCount.get()) {
while (hi < newValue.doubleValue()) {
newPageIndex++;
hi += interval;
}
// increase the page index to match the scroll position
setPageIndex(newPageIndex);
} else if (low > newValue.doubleValue() && pageIndex.get() > 0) {
while (low > newValue.doubleValue()) {
newPageIndex--;
low -= interval;
}
// decrease the page index to match the scroll position
setPageIndex(newPageIndex);
}
});
for (int zoom : DEFAULT_ZOOMS) {
zoomComboBox.getItems().add(zoom + "%");
}
zoomComboBox.getSelectionModel().select(DEFAULT_ZOOM_INDEX);
zoomComboBox.addEventHandler(KeyEvent.KEY_PRESSED, (KeyEvent e) -> {
if (e.getCode() == KeyCode.ENTER) {
handleZoomChangedAction();
}
});
setZoomRatio(1);
// this ensures the report is properly closed when the dialog is closed
parent.addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
parent.get().getWindow().setOnCloseRequest(event -> {
try {
report.get().close();
} catch (IOException e) {
e.printStackTrace();
}
});
}
});
}
Aggregations