use of javafx.collections.ListChangeListener in project Board-Instrumentation-Framework by intel.
the class Gauge method registerListeners.
private void registerListeners() {
sections.addListener((ListChangeListener<Section>) c -> IntStream.range(0, sections.size()).parallel().forEachOrdered(i -> {
Section section = sections.get(i);
switch(i) {
case 0:
setSectionFill0(section.getColor());
break;
case 1:
setSectionFill1(section.getColor());
break;
case 2:
setSectionFill2(section.getColor());
break;
case 3:
setSectionFill3(section.getColor());
break;
case 4:
setSectionFill4(section.getColor());
break;
case 5:
setSectionFill5(section.getColor());
break;
case 6:
setSectionFill6(section.getColor());
break;
case 7:
setSectionFill7(section.getColor());
break;
case 8:
setSectionFill8(section.getColor());
break;
case 9:
setSectionFill9(section.getColor());
break;
}
}));
areas.addListener((ListChangeListener<Section>) c -> IntStream.range(0, areas.size()).parallel().forEachOrdered(i -> {
Section area = areas.get(i);
switch(i) {
case 0:
setAreaFill0(area.getColor());
break;
case 1:
setAreaFill1(area.getColor());
break;
case 2:
setAreaFill2(area.getColor());
break;
case 3:
setAreaFill3(area.getColor());
break;
case 4:
setAreaFill4(area.getColor());
break;
case 5:
setAreaFill4(area.getColor());
break;
case 6:
setAreaFill4(area.getColor());
break;
case 7:
setAreaFill4(area.getColor());
break;
case 8:
setAreaFill4(area.getColor());
break;
case 9:
setAreaFill4(area.getColor());
break;
}
}));
}
use of javafx.collections.ListChangeListener in project bisq-desktop by bisq-network.
the class MainViewModel method onBasicServicesInitialized.
private void onBasicServicesInitialized() {
log.info("onBasicServicesInitialized");
clock.start();
PaymentMethod.onAllServicesInitialized();
// disputeManager
disputeManager.onAllServicesInitialized();
disputeManager.getDisputesAsObservableList().addListener((ListChangeListener<Dispute>) change -> {
change.next();
onDisputesChangeListener(change.getAddedSubList(), change.getRemoved());
});
onDisputesChangeListener(disputeManager.getDisputesAsObservableList(), null);
// tradeManager
tradeManager.onAllServicesInitialized();
tradeManager.getTradableList().addListener((ListChangeListener<Trade>) c -> updateBalance());
tradeManager.getTradableList().addListener((ListChangeListener<Trade>) change -> onTradesChanged());
onTradesChanged();
// We handle the trade period here as we display a global popup if we reached dispute time
tradesAndUIReady = EasyBind.combine(isSplashScreenRemoved, tradeManager.pendingTradesInitializedProperty(), (a, b) -> a && b);
tradesAndUIReady.subscribe((observable, oldValue, newValue) -> {
if (newValue)
applyTradePeriodState();
});
tradeManager.setTakeOfferRequestErrorMessageHandler(errorMessage -> new Popup<>().warning(Res.get("popup.error.takeOfferRequestFailed", errorMessage)).show());
// walletService
btcWalletService.addBalanceListener(new BalanceListener() {
@Override
public void onBalanceChanged(Coin balance, Transaction tx) {
updateBalance();
}
});
openOfferManager.getObservableList().addListener((ListChangeListener<OpenOffer>) c -> updateBalance());
tradeManager.getTradableList().addListener((ListChangeListener<Trade>) c -> updateBalance());
openOfferManager.onAllServicesInitialized();
removeOffersWithoutAccountAgeWitness();
arbitratorManager.onAllServicesInitialized();
alertManager.alertMessageProperty().addListener((observable, oldValue, newValue) -> displayAlertIfPresent(newValue, false));
privateNotificationManager.privateNotificationProperty().addListener((observable, oldValue, newValue) -> displayPrivateNotification(newValue));
displayAlertIfPresent(alertManager.alertMessageProperty().get(), false);
p2PService.onAllServicesInitialized();
feeService.onAllServicesInitialized();
GUIUtil.setFeeService(feeService);
daoManager.onAllServicesInitialized(errorMessage -> new Popup<>().error(errorMessage).show());
tradeStatisticsManager.onAllServicesInitialized();
accountAgeWitnessService.onAllServicesInitialized();
priceFeedService.setCurrencyCodeOnInit();
filterManager.onAllServicesInitialized();
filterManager.addListener(filter -> {
if (filter != null) {
if (filter.getSeedNodes() != null && !filter.getSeedNodes().isEmpty())
new Popup<>().warning(Res.get("popup.warning.nodeBanned", Res.get("popup.warning.seed"))).show();
if (filter.getPriceRelayNodes() != null && !filter.getPriceRelayNodes().isEmpty())
new Popup<>().warning(Res.get("popup.warning.nodeBanned", Res.get("popup.warning.priceRelay"))).show();
}
});
setupBtcNumPeersWatcher();
setupP2PNumPeersWatcher();
updateBalance();
if (DevEnv.isDevMode()) {
preferences.setShowOwnOffersInOfferBook(true);
setupDevDummyPaymentAccounts();
}
fillPriceFeedComboBoxItems();
setupMarketPriceFeed();
swapPendingOfferFundingEntries();
showAppScreen.set(true);
String key = "remindPasswordAndBackup";
user.getPaymentAccountsAsObservable().addListener((SetChangeListener<PaymentAccount>) change -> {
if (!walletsManager.areWalletsEncrypted() && preferences.showAgain(key) && change.wasAdded()) {
new Popup<>().headLine(Res.get("popup.securityRecommendation.headline")).information(Res.get("popup.securityRecommendation.msg")).dontShowAgainId(key).show();
}
});
checkIfOpenOffersMatchTradeProtocolVersion();
if (walletsSetup.downloadPercentageProperty().get() == 1)
checkForLockedUpFunds();
allBasicServicesInitialized = true;
}
use of javafx.collections.ListChangeListener in project tilesfx by HanSolo.
the class LeaderBoardTileSkin method registerItemListeners.
private void registerItemListeners() {
tile.getLeaderBoardItems().forEach(item -> {
item.setFormatString(formatString);
item.addChartDataEventListener(updateHandler);
EventHandler<MouseEvent> clickHandler = e -> tile.fireTileEvent(new TileEvent(TileEvent.EventType.SELECTED_CHART_DATA, item.getChartData()));
handlerMap.put(item, clickHandler);
item.addEventHandler(MouseEvent.MOUSE_PRESSED, clickHandler);
});
tile.getLeaderBoardItems().addListener(new WeakListChangeListener<>((ListChangeListener<LeaderBoardItem>) change -> {
while (change.next()) {
if (change.wasPermutated()) {
} else if (change.wasUpdated()) {
} else if (change.wasAdded()) {
change.getAddedSubList().forEach(addedItem -> {
addedItem.setFormatString(formatString);
addedItem.addChartDataEventListener(updateHandler);
EventHandler<MouseEvent> clickHandler = e -> tile.fireTileEvent(new TileEvent(TileEvent.EventType.SELECTED_CHART_DATA, addedItem.getChartData()));
handlerMap.put(addedItem, clickHandler);
addedItem.addEventHandler(MouseEvent.MOUSE_PRESSED, clickHandler);
});
} else if (change.wasRemoved()) {
change.getRemoved().forEach(removedItem -> {
removedItem.removeChartDataEventListener(updateHandler);
removedItem.removeEventHandler(MouseEvent.MOUSE_PRESSED, handlerMap.get(removedItem));
});
}
}
}));
}
use of javafx.collections.ListChangeListener in project jvarkit by lindenb.
the class IndexCovJfx method doWork.
@Override
public int doWork(final Stage primaryStage, final List<String> args) {
final Rectangle2D screen = Screen.getPrimary().getVisualBounds();
final Pattern tab = Pattern.compile("[\t]");
BufferedReader r = null;
try {
final File inputFile;
if (args.isEmpty()) {
// open gui
final FileChooser fc = new FileChooser();
inputFile = fc.showOpenDialog(null);
if (inputFile == null) {
return 0;
}
} else if (args.size() == 1) {
inputFile = new File(args.get(0));
} else {
LOG.error("Illegal Number of arguments: " + args);
return -1;
}
r = IOUtils.openFileForBufferedReading(inputFile);
String line = r.readLine();
if (line == null) {
new Alert(AlertType.ERROR, "Cannot read first line of " + inputFile, ButtonType.OK).showAndWait();
return -1;
}
String[] tokens = tab.split(line);
if (tokens.length < 4 || !tokens[0].equals("#chrom") || !tokens[1].equals("start") || !tokens[2].equals("end")) {
new Alert(AlertType.ERROR, "bad first line " + line + " in " + inputFile, ButtonType.OK).showAndWait();
return -1;
}
this.sampleNames.addAll(Arrays.asList(tokens).subList(3, tokens.length).stream().map(S -> new Sample(S)).collect(Collectors.toList()));
this.sampleListView = new ListView<>(this.sampleNames);
final MultipleSelectionModel<Sample> sampleSelectionModel = this.sampleListView.getSelectionModel();
sampleSelectionModel.setSelectionMode(SelectionMode.MULTIPLE);
// this.sampleListView.setPrefWidth(200);
final SmartComparator smartCmp = new SmartComparator();
this.orignalndexCovRows.addAll(r.lines().filter(L -> !StringUtil.isBlank(L)).map(L -> Arrays.asList(tab.split(L))).map(T -> new IndexCovRow(T)).sorted((A, B) -> {
int i = smartCmp.compare(A.getContig(), B.getContig());
if (i != 0)
return i;
return A.getStart() - B.getStart();
}).collect(Collectors.toList()));
this.visibleIndexCovRows.addAll(orignalndexCovRows);
String lastContig = null;
for (final IndexCovRow row : this.visibleIndexCovRows) {
if (lastContig == null || !lastContig.equals(row.getContig())) {
this.contig2color.put(row.getContig(), this.contig2color.size() % 2 == 0 ? gray(0.96) : gray(0.98));
lastContig = row.getContig();
}
}
this.canvas = new Canvas(screen.getWidth() - 400, screen.getHeight() - 200);
this.canvasSrollPane = new ScrollPane(canvas);
this.canvasSrollPane.setFitToHeight(true);
this.canvasSrollPane.setFitToWidth(true);
this.canvasSrollPane.setHbarPolicy(ScrollBarPolicy.ALWAYS);
this.canvasSrollPane.setHmin(0);
// NOT HERE: see adjustScollPane();
// this.canvasSrollPane.setHmax(this.visibleIndexCovRows.size()*CHUNK_WIDTH);
// this.canvasSrollPane.setHvalue(0);
this.canvasSrollPane.hvalueProperty().addListener(E -> repaintCanvas());
final VBox root = new VBox();
final MenuBar menuBar = new MenuBar();
Menu menu = new Menu("Tools");
MenuItem item = new MenuItem("Goto");
item.setOnAction(AE -> askGoto());
item.setAccelerator(new KeyCodeCombination(KeyCode.G, KeyCombination.CONTROL_DOWN));
menu.getItems().add(item);
menu.getItems().add(new SeparatorMenuItem());
//
item = new MenuItem("Cleanup: remove data > DEL && data < DUP");
item.setOnAction(AE -> askCleanup());
menu.getItems().add(item);
//
item = new MenuItem("Cleanup: remove ALL samples <= DEL or ALL samples >= DUP");
item.setOnAction(AE -> askEveryWhere());
menu.getItems().add(item);
//
item = new MenuItem("Cleanup: keep selected samples having <= DEL or ALL samples >= DUP");
item.setOnAction(AE -> filterForSampleSet(false));
menu.getItems().add(item);
//
item = new MenuItem("Cleanup: keep selected samples having <= DEL or ALL samples >= DUP and only those samples.");
item.setOnAction(AE -> filterForSampleSet(true));
menu.getItems().add(item);
//
item = new MenuItem("Filter: Keep data overlapping BED file");
item.setOnAction(AE -> filterBed(false));
menu.getItems().add(item);
//
item = new MenuItem("Filter: Keep data NOT overlapping BED file");
item.setOnAction(AE -> filterBed(true));
menu.getItems().add(item);
//
item = new MenuItem("Revert: Restore original data");
item.setOnAction(AE -> doRestoreOriginalData());
item.setAccelerator(new KeyCodeCombination(KeyCode.R, KeyCombination.CONTROL_DOWN));
menu.getItems().add(item);
menu.getItems().add(new SeparatorMenuItem());
item = new MenuItem("Next Interesting");
item.setOnAction(AE -> goToNextInteresting(1));
item.setAccelerator(new KeyCodeCombination(KeyCode.N, KeyCombination.CONTROL_DOWN));
menu.getItems().add(item);
item = new MenuItem("Previous Interesting");
item.setOnAction(AE -> goToNextInteresting(-1));
item.setAccelerator(new KeyCodeCombination(KeyCode.P, KeyCombination.CONTROL_DOWN));
menu.getItems().add(item);
menu.getItems().add(new SeparatorMenuItem());
item = new MenuItem("Quit");
menu.getItems().add(item);
item.setOnAction(AE -> {
Platform.exit();
});
menuBar.getMenus().add(menu);
root.getChildren().add(menuBar);
final HBox toolboxPane = new HBox();
Label label = new Label("DEL when \u2264 :");
toolboxPane.getChildren().add(label);
this.deletionSpinner = new Spinner<>(0.0, 0.9, DEFAULT_deletionTreshold, 0.05);
label.setLabelFor(this.deletionSpinner);
this.deletionSpinner.valueProperty().addListener((a, b, c) -> repaintCanvas());
toolboxPane.getChildren().add(this.deletionSpinner);
label = new Label("DUP when \u2265 :");
toolboxPane.getChildren().add(label);
this.duplicationSpinner = new Spinner<>(1.1, 10.0, DEFAULT_duplicationTreshold, 0.05);
this.duplicationSpinner.valueProperty().addListener((a, b, c) -> repaintCanvas());
label.setLabelFor(this.duplicationSpinner);
toolboxPane.getChildren().add(this.duplicationSpinner);
label = new Label(" Jump to :");
toolboxPane.getChildren().add(label);
final TextField jumpToTextField = new TextField();
jumpToTextField.setPromptText("chrom:pos");
jumpToTextField.setPrefColumnCount(15);
toolboxPane.getChildren().add(jumpToTextField);
label.setLabelFor(jumpToTextField);
jumpToTextField.setOnAction(AE -> askGoto(jumpToTextField.getText()));
final Button goButton = new Button("Go");
toolboxPane.getChildren().add(goButton);
goButton.setOnAction(AE -> askGoto(jumpToTextField.getText()));
root.getChildren().add(toolboxPane);
// HBox hbox = new HBox(sampleListView,this.canvasSrollPane);
final GridPane grid = new GridPane();
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(5, 5, 5, 5));
grid.add(this.sampleListView, 0, 0, 1, 1);
grid.add(this.canvasSrollPane, 1, 0, 9, 1);
// final StackPane root = new StackPane();
root.getChildren().add(grid);
final Scene scene = new Scene(root);
primaryStage.setTitle(IndexCovJfx.class.getSimpleName() + " " + this.sampleNames.size() + " Sample(s) " + this.visibleIndexCovRows.size() + " Point(s).");
primaryStage.setOnShown(E -> {
adjustScollPane();
this.canvasSrollPane.requestFocus();
repaintCanvas();
if (this.isUnitText()) {
Platform.exit();
}
});
this.canvasSrollPane.setOnKeyPressed(e -> {
if (e.getCode() == KeyCode.LEFT) {
canvasSrollPane.setHvalue(Math.max(canvasSrollPane.getHmin(), canvasSrollPane.getHvalue() - CHUNK_WIDTH));
}
if (e.getCode() == KeyCode.RIGHT) {
canvasSrollPane.setHvalue(Math.min(canvasSrollPane.getHmax(), canvasSrollPane.getHvalue() + CHUNK_WIDTH));
}
});
primaryStage.setScene(scene);
primaryStage.show();
/*sampleSelectionModel.selectedItemProperty().addListener(E->{
repaintCanvas();
});
sampleSelectionModel.selectedItemProperty().addListener(E->repaintCanvas());*/
sampleSelectionModel.getSelectedIndices().addListener(new ListChangeListener<Integer>() {
@Override
public void onChanged(Change<? extends Integer> c) {
repaintCanvas();
}
});
} catch (final Exception err) {
LOG.error(err);
new Alert(AlertType.ERROR, "Error " + err, ButtonType.OK).showAndWait();
return -1;
} finally {
CloserUtil.close(r);
}
return 0;
}
Aggregations