Search in sources :

Example 1 with Platform

use of javafx.application.Platform in project PayFile by mikehearn.

the class ConnectServerController method maybeSettleLastServer.

/**
     * Possibly reconnect to the last paid server and ask it to give us back the money. Note that after 24 hours this
     * channel will expire anyway, so if the server is gone, it's not the end of the world, we'll still get the money
     * back. The returned future completes immediately if nothing needs to be done.
     */
private CompletableFuture<Void> maybeSettleLastServer(HostAndPort newServerName) {
    final HostAndPort lastPaidServer = Settings.getLastPaidServer();
    // If we didn't have a payment channel, or we did but it's with the same server we're connecting to, ignore.
    if (lastPaidServer == null || newServerName.equals(lastPaidServer))
        return CompletableFuture.completedFuture(null);
    BigInteger amountInLastServer = PayFileClient.getBalanceForServer(lastPaidServer.getHostText(), lastPaidServer.getPort(), Main.bitcoin.wallet());
    // If the last server we paid was already settled, ignore.
    if (amountInLastServer.compareTo(BigInteger.ZERO) == 0)
        return CompletableFuture.completedFuture(null);
    // Otherwise we have some money locked up with the last server. Ask for it back.
    final CompletableFuture<Void> future = new CompletableFuture<>();
    titleLabel.setText(String.format("Contacting %s to request early settlement ...", lastPaidServer));
    log.info("Connecting to {}", lastPaidServer);
    Main.connect(lastPaidServer, REFUND_CONNECT_TIMEOUT_MSEC).whenCompleteAsync((client, ex) -> {
        if (ex == null) {
            log.info("Connected. Requesting early settlement.");
            titleLabel.setText("Requesting early settlement ...");
            client.settlePaymentChannel().whenCompleteAsync((v, settleEx) -> {
                if (settleEx == null) {
                    log.info("Settled. Proceeding ...");
                    client.disconnect();
                    future.complete(null);
                } else {
                    crashAlert(settleEx);
                }
            }, Platform::runLater);
        } else {
            log.error("Failed to connect", ex);
            titleLabel.setText(defaultTitle);
            informUserTheyMustWait(lastPaidServer);
        }
    }, Platform::runLater);
    return future;
}
Also used : HostAndPort(com.google.common.net.HostAndPort) CompletableFuture(java.util.concurrent.CompletableFuture) Platform(javafx.application.Platform) BigInteger(java.math.BigInteger)

Example 2 with Platform

use of javafx.application.Platform in project PayFile by mikehearn.

the class Controller method download.

public void download(ActionEvent event) throws Exception {
    File destination = null;
    try {
        final PayFileClient.File downloadingFile = checkNotNull(selectedFile.get());
        if (downloadingFile.getPrice() > getBalance().longValue())
            throw new InsufficientMoneyException(BigInteger.valueOf(downloadingFile.getPrice() - getBalance().longValue()));
        // Ask the user where to put it.
        DirectoryChooser chooser = new DirectoryChooser();
        chooser.setTitle("Select download directory");
        File directory = chooser.showDialog(Main.instance.mainWindow);
        if (directory == null)
            return;
        destination = new File(directory, downloadingFile.getFileName());
        FileOutputStream fileStream = new FileOutputStream(destination);
        final long startTime = System.currentTimeMillis();
        cancelBtn.setVisible(true);
        progressBarLabel.setText("Downloading " + downloadingFile.getFileName());
        // Make the UI update whilst the download is in progress: progress bar and balance label.
        ProgressOutputStream stream = new ProgressOutputStream(fileStream, downloadingFile.getSize());
        progressBar.progressProperty().bind(stream.progressProperty());
        Main.client.setOnPaymentMade((amt) -> Platform.runLater(this::refreshBalanceLabel));
        // Swap in the progress bar with an animation.
        animateSwap();
        // ... and start the download.
        Settings.setLastPaidServer(Main.serverAddress);
        downloadFuture = Main.client.downloadFile(downloadingFile, stream);
        final File fDestination = destination;
        // When we're done ...
        downloadFuture.handleAsync((ok, exception) -> {
            // ... swap widgets back out again
            animateSwap();
            if (exception != null) {
                if (!(exception instanceof CancellationException))
                    crashAlert(exception);
            } else {
                // Otherwise inform the user we're finished and let them open the file.
                int secondsTaken = (int) (System.currentTimeMillis() - startTime) / 1000;
                runAlert((stage, controller) -> controller.withOpenFile(stage, downloadingFile, fDestination, secondsTaken));
            }
            return null;
        }, Platform::runLater);
    } catch (InsufficientMoneyException e) {
        if (destination != null)
            destination.delete();
        final String price = Utils.bitcoinValueToFriendlyString(BigInteger.valueOf(selectedFile.get().getPrice()));
        final String missing = String.valueOf(e.missing);
        informationalAlert("Insufficient funds", "This file costs %s BTC but you can't afford that. You need %s satoshis to complete the transaction.", price, missing);
    }
}
Also used : PayFileClient(net.plan99.payfile.client.PayFileClient) Platform(javafx.application.Platform) CancellationException(java.util.concurrent.CancellationException) FileOutputStream(java.io.FileOutputStream) File(java.io.File) DirectoryChooser(javafx.stage.DirectoryChooser)

Example 3 with Platform

use of javafx.application.Platform in project bitsquare by bitsquare.

the class BitsquareApp method start.

@Override
public void start(Stage stage) throws IOException {
    BitsquareApp.primaryStage = stage;
    String logPath = Paths.get(env.getProperty(AppOptionKeys.APP_DATA_DIR_KEY), "bitsquare").toString();
    Log.setup(logPath);
    log.info("Log files under: " + logPath);
    Version.printVersion();
    Utilities.printSysInfo();
    Log.setLevel(Level.toLevel(env.getRequiredProperty(CommonOptionKeys.LOG_LEVEL_KEY)));
    UserThread.setExecutor(Platform::runLater);
    UserThread.setTimerClass(UITimer.class);
    shutDownHandler = this::stop;
    // setup UncaughtExceptionHandler
    Thread.UncaughtExceptionHandler handler = (thread, throwable) -> {
        // Might come from another thread 
        if (throwable.getCause() != null && throwable.getCause().getCause() != null && throwable.getCause().getCause() instanceof BlockStoreException) {
            log.error(throwable.getMessage());
        } else if (throwable instanceof ClassCastException && "sun.awt.image.BufImgSurfaceData cannot be cast to sun.java2d.xr.XRSurfaceData".equals(throwable.getMessage())) {
            log.warn(throwable.getMessage());
        } else {
            log.error("Uncaught Exception from thread " + Thread.currentThread().getName());
            log.error("throwableMessage= " + throwable.getMessage());
            log.error("throwableClass= " + throwable.getClass());
            log.error("Stack trace:\n" + ExceptionUtils.getStackTrace(throwable));
            throwable.printStackTrace();
            UserThread.execute(() -> showErrorPopup(throwable, false));
        }
    };
    Thread.setDefaultUncaughtExceptionHandler(handler);
    Thread.currentThread().setUncaughtExceptionHandler(handler);
    try {
        Utilities.checkCryptoPolicySetup();
    } catch (NoSuchAlgorithmException | LimitedKeyStrengthException e) {
        e.printStackTrace();
        UserThread.execute(() -> showErrorPopup(e, true));
    }
    Security.addProvider(new BouncyCastleProvider());
    try {
        // Guice
        bitsquareAppModule = new BitsquareAppModule(env, primaryStage);
        injector = Guice.createInjector(bitsquareAppModule);
        injector.getInstance(InjectorViewFactory.class).setInjector(injector);
        Version.setBtcNetworkId(injector.getInstance(BitsquareEnvironment.class).getBitcoinNetwork().ordinal());
        if (Utilities.isLinux())
            System.setProperty("prism.lcdtext", "false");
        Storage.setDatabaseCorruptionHandler((String fileName) -> {
            corruptedDatabaseFiles.add(fileName);
            if (mainView != null)
                mainView.setPersistedFilesCorrupted(corruptedDatabaseFiles);
        });
        // load the main view and create the main scene
        CachingViewLoader viewLoader = injector.getInstance(CachingViewLoader.class);
        mainView = (MainView) viewLoader.load(MainView.class);
        mainView.setPersistedFilesCorrupted(corruptedDatabaseFiles);
        /* Storage.setDatabaseCorruptionHandler((String fileName) -> {
                corruptedDatabaseFiles.add(fileName);
                if (mainView != null)
                    mainView.setPersistedFilesCorrupted(corruptedDatabaseFiles);
            });*/
        //740
        scene = new Scene(mainView.getRoot(), 1200, 700);
        Font.loadFont(getClass().getResource("/fonts/Verdana.ttf").toExternalForm(), 13);
        Font.loadFont(getClass().getResource("/fonts/VerdanaBold.ttf").toExternalForm(), 13);
        Font.loadFont(getClass().getResource("/fonts/VerdanaItalic.ttf").toExternalForm(), 13);
        Font.loadFont(getClass().getResource("/fonts/VerdanaBoldItalic.ttf").toExternalForm(), 13);
        scene.getStylesheets().setAll("/io/bitsquare/gui/bitsquare.css", "/io/bitsquare/gui/images.css", "/io/bitsquare/gui/CandleStickChart.css");
        // configure the system tray
        SystemTray.create(primaryStage, shutDownHandler);
        primaryStage.setOnCloseRequest(event -> {
            event.consume();
            stop();
        });
        scene.addEventHandler(KeyEvent.KEY_RELEASED, keyEvent -> {
            if (new KeyCodeCombination(KeyCode.W, KeyCombination.SHORTCUT_DOWN).match(keyEvent) || new KeyCodeCombination(KeyCode.W, KeyCombination.CONTROL_DOWN).match(keyEvent)) {
                stop();
            } else if (new KeyCodeCombination(KeyCode.Q, KeyCombination.SHORTCUT_DOWN).match(keyEvent) || new KeyCodeCombination(KeyCode.Q, KeyCombination.CONTROL_DOWN).match(keyEvent)) {
                stop();
            } else if (new KeyCodeCombination(KeyCode.E, KeyCombination.SHORTCUT_DOWN).match(keyEvent) || new KeyCodeCombination(KeyCode.E, KeyCombination.CONTROL_DOWN).match(keyEvent)) {
                showEmptyWalletPopup();
            } else if (new KeyCodeCombination(KeyCode.M, KeyCombination.ALT_DOWN).match(keyEvent)) {
                showSendAlertMessagePopup();
            } else if (new KeyCodeCombination(KeyCode.F, KeyCombination.ALT_DOWN).match(keyEvent)) {
                showFilterPopup();
            } else if (new KeyCodeCombination(KeyCode.F, KeyCombination.ALT_DOWN).match(keyEvent)) {
                showFPSWindow();
            } else if (new KeyCodeCombination(KeyCode.J, KeyCombination.ALT_DOWN).match(keyEvent)) {
                WalletService walletService = injector.getInstance(WalletService.class);
                if (walletService.getWallet() != null)
                    new ShowWalletDataWindow(walletService).information("Wallet raw data").show();
                else
                    new Popup<>().warning("The wallet is not initialized yet").show();
            } else if (new KeyCodeCombination(KeyCode.G, KeyCombination.ALT_DOWN).match(keyEvent)) {
                TradeWalletService tradeWalletService = injector.getInstance(TradeWalletService.class);
                WalletService walletService = injector.getInstance(WalletService.class);
                if (walletService.getWallet() != null)
                    new SpendFromDepositTxWindow(tradeWalletService).information("Emergency wallet tool").show();
                else
                    new Popup<>().warning("The wallet is not initialized yet").show();
            } else if (DevFlags.DEV_MODE && new KeyCodeCombination(KeyCode.D, KeyCombination.SHORTCUT_DOWN).match(keyEvent)) {
                showDebugWindow();
            }
        });
        // configure the primary stage
        primaryStage.setTitle(env.getRequiredProperty(APP_NAME_KEY));
        primaryStage.setScene(scene);
        // 1190
        primaryStage.setMinWidth(1000);
        primaryStage.setMinHeight(620);
        // on windows the title icon is also used as task bar icon in a larger size
        // on Linux no title icon is supported but also a large task bar icon is derived from that title icon
        String iconPath;
        if (Utilities.isOSX())
            iconPath = ImageUtil.isRetina() ? "/images/window_icon@2x.png" : "/images/window_icon.png";
        else if (Utilities.isWindows())
            iconPath = "/images/task_bar_icon_windows.png";
        else
            iconPath = "/images/task_bar_icon_linux.png";
        primaryStage.getIcons().add(new Image(getClass().getResourceAsStream(iconPath)));
        // make the UI visible
        primaryStage.show();
        if (!Utilities.isCorrectOSArchitecture()) {
            String osArchitecture = Utilities.getOSArchitecture();
            // We don't force a shutdown as the osArchitecture might in strange cases return a wrong value.
            // Needs at least more testing on different machines...
            new Popup<>().warning("You probably have the wrong Bitsquare version for this computer.\n" + "Your computer's architecture is: " + osArchitecture + ".\n" + "The Bitsquare binary you installed is: " + Utilities.getJVMArchitecture() + ".\n" + "Please shut down and re-install the correct version (" + osArchitecture + ").").show();
        }
        UserThread.runPeriodically(() -> Profiler.printSystemLoad(log), LOG_MEMORY_PERIOD_MIN, TimeUnit.MINUTES);
    } catch (Throwable throwable) {
        showErrorPopup(throwable, false);
    }
}
Also used : StageStyle(javafx.stage.StageStyle) Popup(io.bitsquare.gui.main.overlays.popups.Popup) LoggerFactory(org.slf4j.LoggerFactory) Security(java.security.Security) View(io.bitsquare.gui.common.view.View) StackPane(javafx.scene.layout.StackPane) KeyCombination(javafx.scene.input.KeyCombination) Application(javafx.application.Application) Parent(javafx.scene.Parent) UITimer(io.bitsquare.gui.common.UITimer) TradeWalletService(io.bitsquare.btc.TradeWalletService) ResultHandler(io.bitsquare.common.handlers.ResultHandler) BlockStoreException(org.bitcoinj.store.BlockStoreException) Pane(javafx.scene.layout.Pane) Font(javafx.scene.text.Font) LimitedKeyStrengthException(io.bitsquare.common.util.LimitedKeyStrengthException) FilterManager(io.bitsquare.filter.FilterManager) KeyEvent(javafx.scene.input.KeyEvent) InjectorViewFactory(io.bitsquare.gui.common.view.guice.InjectorViewFactory) Platform(javafx.application.Platform) List(java.util.List) io.bitsquare.gui.main.overlays.windows(io.bitsquare.gui.main.overlays.windows) Logger(ch.qos.logback.classic.Logger) MainViewModel(io.bitsquare.gui.main.MainViewModel) Environment(org.springframework.core.env.Environment) Dialogs(org.controlsfx.dialog.Dialogs) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) EventStreams(org.reactfx.EventStreams) CommonOptionKeys(io.bitsquare.common.CommonOptionKeys) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) Scene(javafx.scene.Scene) MainView(io.bitsquare.gui.main.MainView) DebugView(io.bitsquare.gui.main.debug.DebugView) P2PService(io.bitsquare.p2p.P2PService) ArrayList(java.util.ArrayList) TradeManager(io.bitsquare.trade.TradeManager) CachingViewLoader(io.bitsquare.gui.common.view.CachingViewLoader) WalletService(io.bitsquare.btc.WalletService) SystemTray(io.bitsquare.gui.SystemTray) APP_NAME_KEY(io.bitsquare.app.AppOptionKeys.APP_NAME_KEY) KeyCode(javafx.scene.input.KeyCode) Modality(javafx.stage.Modality) Utilities(io.bitsquare.common.util.Utilities) Label(javafx.scene.control.Label) UserThread(io.bitsquare.common.UserThread) ImageUtil(io.bitsquare.gui.util.ImageUtil) IOException(java.io.IOException) ViewLoader(io.bitsquare.gui.common.view.ViewLoader) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) Injector(com.google.inject.Injector) KeyCodeCombination(javafx.scene.input.KeyCodeCombination) TimeUnit(java.util.concurrent.TimeUnit) Level(ch.qos.logback.classic.Level) Stage(javafx.stage.Stage) Paths(java.nio.file.Paths) OpenOfferManager(io.bitsquare.trade.offer.OpenOfferManager) ArbitratorManager(io.bitsquare.arbitration.ArbitratorManager) Guice(com.google.inject.Guice) Profiler(io.bitsquare.common.util.Profiler) Storage(io.bitsquare.storage.Storage) Image(javafx.scene.image.Image) AlertManager(io.bitsquare.alert.AlertManager) Platform(javafx.application.Platform) TradeWalletService(io.bitsquare.btc.TradeWalletService) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Image(javafx.scene.image.Image) TradeWalletService(io.bitsquare.btc.TradeWalletService) WalletService(io.bitsquare.btc.WalletService) CachingViewLoader(io.bitsquare.gui.common.view.CachingViewLoader) LimitedKeyStrengthException(io.bitsquare.common.util.LimitedKeyStrengthException) Popup(io.bitsquare.gui.main.overlays.popups.Popup) InjectorViewFactory(io.bitsquare.gui.common.view.guice.InjectorViewFactory) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) BlockStoreException(org.bitcoinj.store.BlockStoreException) KeyCodeCombination(javafx.scene.input.KeyCodeCombination) Scene(javafx.scene.Scene) UserThread(io.bitsquare.common.UserThread)

Example 4 with Platform

use of javafx.application.Platform in project jvarkit by lindenb.

the class BamStage method createReadGroupPane.

private Tab createReadGroupPane(final SAMFileHeader header) {
    final TableView<SAMReadGroupRecord> table = new TableView<>(header == null ? FXCollections.observableArrayList() : FXCollections.observableArrayList(header.getReadGroups()));
    table.getColumns().add(makeColumn("ID", G -> G.getId()));
    table.getColumns().add(makeColumn("Sample", G -> G.getSample()));
    table.getColumns().add(makeColumn("Center", G -> G.getSequencingCenter()));
    table.getColumns().add(makeColumn("Platform", G -> G.getPlatform()));
    table.getColumns().add(makeColumn("PlatformModel", G -> G.getPlatformModel()));
    table.getColumns().add(makeColumn("PlatformUnit", G -> G.getPlatformUnit()));
    table.getColumns().add(makeColumn("MedianInsertSize", G -> G.getPredictedMedianInsertSize()));
    table.getColumns().add(makeColumn("Desc", G -> G.getDescription()));
    table.getColumns().add(makeColumn("PU", G -> G.getPlatformUnit()));
    table.getColumns().add(makeColumn("Lib", G -> G.getLibrary()));
    table.getColumns().add(makeColumn("Run-Date", G -> G.getRunDate()));
    final Tab tab = new Tab("ReadGroups", table);
    tab.setClosable(false);
    table.setPlaceholder(new Label("No BAM read-greoup."));
    return tab;
}
Also used : Arrays(java.util.Arrays) VCFHeader(htsjdk.variant.vcf.VCFHeader) CigarOperator(htsjdk.samtools.CigarOperator) ChartFactory(com.github.lindenb.jvarkit.tools.vcfviewgui.chart.ChartFactory) VariantContextChartFactory(com.github.lindenb.jvarkit.tools.vcfviewgui.chart.VariantContextChartFactory) ScrollPane(javafx.scene.control.ScrollPane) TabPane(javafx.scene.control.TabPane) Map(java.util.Map) Hershey(com.github.lindenb.jvarkit.util.Hershey) CigarOpPerPositionChartFactory(com.github.lindenb.jvarkit.tools.vcfviewgui.chart.CigarOpPerPositionChartFactory) ScriptException(javax.script.ScriptException) CloserUtil(htsjdk.samtools.util.CloserUtil) Rectangle2D(javafx.geometry.Rectangle2D) SplitPane(javafx.scene.control.SplitPane) SAMTagUtil(htsjdk.samtools.SAMTagUtil) GraphicsContext(javafx.scene.canvas.GraphicsContext) SAMRecordIterator(htsjdk.samtools.SAMRecordIterator) Event(javafx.event.Event) Set(java.util.Set) SAMFileWriter(htsjdk.samtools.SAMFileWriter) Screen(javafx.stage.Screen) SAMTagAndValue(htsjdk.samtools.SAMRecord.SAMTagAndValue) FastqRecord(htsjdk.samtools.fastq.FastqRecord) Platform(javafx.application.Platform) Separator(javafx.scene.control.Separator) Stream(java.util.stream.Stream) SAMReadGroupRecord(htsjdk.samtools.SAMReadGroupRecord) FlowPane(javafx.scene.layout.FlowPane) SAMFlag(htsjdk.samtools.SAMFlag) BorderPane(javafx.scene.layout.BorderPane) SamFlagsChartFactory(com.github.lindenb.jvarkit.tools.vcfviewgui.chart.SamFlagsChartFactory) CloseableIterator(htsjdk.samtools.util.CloseableIterator) FXCollections(javafx.collections.FXCollections) LogCloseableIterator(com.github.lindenb.jvarkit.tools.vcfviewgui.NgsStage.LogCloseableIterator) TextFlow(javafx.scene.text.TextFlow) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Color(javafx.scene.paint.Color) SAMFileWriterFactory(htsjdk.samtools.SAMFileWriterFactory) StringWriter(java.io.StringWriter) CheckBox(javafx.scene.control.CheckBox) IOException(java.io.IOException) File(java.io.File) Menu(javafx.scene.control.Menu) FileChooser(javafx.stage.FileChooser) SamInputResource(htsjdk.samtools.SamInputResource) TreeMap(java.util.TreeMap) Tab(javafx.scene.control.Tab) CompiledScript(javax.script.CompiledScript) ObservableValue(javafx.beans.value.ObservableValue) EventHandler(javafx.event.EventHandler) Button(javafx.scene.control.Button) CigarElement(htsjdk.samtools.CigarElement) CheckMenuItem(javafx.scene.control.CheckMenuItem) OverrunStyle(javafx.scene.control.OverrunStyle) VBox(javafx.scene.layout.VBox) SAMFileHeader(htsjdk.samtools.SAMFileHeader) BasesPerPositionChartFactory(com.github.lindenb.jvarkit.tools.vcfviewgui.chart.BasesPerPositionChartFactory) ComboBox(javafx.scene.control.ComboBox) AlertType(javafx.scene.control.Alert.AlertType) ContextMenu(javafx.scene.control.ContextMenu) WindowEvent(javafx.stage.WindowEvent) TableView(javafx.scene.control.TableView) ReadLengthChartFactory(com.github.lindenb.jvarkit.tools.vcfviewgui.chart.ReadLengthChartFactory) Orientation(javafx.geometry.Orientation) Alert(javafx.scene.control.Alert) MenuItem(javafx.scene.control.MenuItem) Predicate(java.util.function.Predicate) Logger(com.github.lindenb.jvarkit.util.log.Logger) Font(javafx.scene.text.Font) Chart(javafx.scene.chart.Chart) Collectors(java.util.stream.Collectors) SAMRecord(htsjdk.samtools.SAMRecord) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) Text(javafx.scene.text.Text) SimpleBindings(javax.script.SimpleBindings) QualityPerPositionChartFactory(com.github.lindenb.jvarkit.tools.vcfviewgui.chart.QualityPerPositionChartFactory) List(java.util.List) SAMProgramRecord(htsjdk.samtools.SAMProgramRecord) Optional(java.util.Optional) VariantContext(htsjdk.variant.variantcontext.VariantContext) Pattern(java.util.regex.Pattern) SamReaderFactory(htsjdk.samtools.SamReaderFactory) FastqReader(htsjdk.samtools.fastq.FastqReader) ReadQualityChartFactory(com.github.lindenb.jvarkit.tools.vcfviewgui.chart.ReadQualityChartFactory) Cigar(htsjdk.samtools.Cigar) Scene(javafx.scene.Scene) SequenceUtil(htsjdk.samtools.util.SequenceUtil) SAMUtils(htsjdk.samtools.SAMUtils) TextArea(javafx.scene.control.TextArea) ButtonType(javafx.scene.control.ButtonType) HashMap(java.util.HashMap) GCPercentChartFactory(com.github.lindenb.jvarkit.tools.vcfviewgui.chart.GCPercentChartFactory) MapqChartFactory(com.github.lindenb.jvarkit.tools.vcfviewgui.chart.MapqChartFactory) Function(java.util.function.Function) ValidationStringency(htsjdk.samtools.ValidationStringency) SAMTextHeaderCodec(htsjdk.samtools.SAMTextHeaderCodec) TableColumn(javafx.scene.control.TableColumn) HashSet(java.util.HashSet) Interval(htsjdk.samtools.util.Interval) TableCell(javafx.scene.control.TableCell) Insets(javafx.geometry.Insets) Tooltip(javafx.scene.control.Tooltip) Locatable(htsjdk.samtools.util.Locatable) Label(javafx.scene.control.Label) MenuBar(javafx.scene.control.MenuBar) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) ReadChartFactory(com.github.lindenb.jvarkit.tools.vcfviewgui.chart.ReadChartFactory) SamReader(htsjdk.samtools.SamReader) ScrollEvent(javafx.scene.input.ScrollEvent) ActionEvent(javafx.event.ActionEvent) Stage(javafx.stage.Stage) SpinnerValueFactory(javafx.scene.control.SpinnerValueFactory) ChangeListener(javafx.beans.value.ChangeListener) ExtensionFilter(javafx.stage.FileChooser.ExtensionFilter) Collections(java.util.Collections) ScrollBar(javafx.scene.control.ScrollBar) Tab(javafx.scene.control.Tab) SAMReadGroupRecord(htsjdk.samtools.SAMReadGroupRecord) Label(javafx.scene.control.Label) TableView(javafx.scene.control.TableView)

Example 5 with Platform

use of javafx.application.Platform in project dwoss by gg-net.

the class FileChooserBuilder method open.

/**
 * Opens a file chooser and returns the selected file or empty.
 *
 * @return the selected file or empty.
 */
// TODO: This is the only time we us a javafx component in all modes. It should be considered, that in the swing mode, the JFileChoser should be used.
public Result<File> open() {
    SwingCore.ensurePlatformIsRunning();
    return new Result<>(CompletableFuture.supplyAsync(() -> {
        FileChooser fileChooser = new FileChooser();
        if (title == null)
            fileChooser.setTitle("Open File");
        else
            fileChooser.setTitle(title);
        File result = fileChooser.showOpenDialog(null);
        if (result == null)
            throw new UiWorkflowBreak(NULL_RESULT);
        return result;
    }, Platform::runLater).thenApplyAsync(r -> r, // the last Apply is for the thread change only
    UiCore.getExecutor()));
}
Also used : Platform(javafx.application.Platform) FileChooser(javafx.stage.FileChooser) Setter(lombok.Setter) SwingCore(eu.ggnet.saft.core.ui.SwingCore) Accessors(lombok.experimental.Accessors) NULL_RESULT(eu.ggnet.saft.core.ui.builder.UiWorkflowBreak.Type.NULL_RESULT) CompletableFuture(java.util.concurrent.CompletableFuture) File(java.io.File) UiCore(eu.ggnet.saft.UiCore) Platform(javafx.application.Platform) FileChooser(javafx.stage.FileChooser) File(java.io.File)

Aggregations

Platform (javafx.application.Platform)11 Scene (javafx.scene.Scene)7 IOException (java.io.IOException)6 Stage (javafx.stage.Stage)6 File (java.io.File)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Label (javafx.scene.control.Label)5 Parent (javafx.scene.Parent)4 Level (ch.qos.logback.classic.Level)3 Logger (ch.qos.logback.classic.Logger)3 Guice (com.google.inject.Guice)3 Injector (com.google.inject.Injector)3 Application (javafx.application.Application)3 StackPane (javafx.scene.layout.StackPane)3 LoggerFactory (org.slf4j.LoggerFactory)3 Key (com.google.inject.Key)2 Names (com.google.inject.name.Names)2 URL (java.net.URL)2 Paths (java.nio.file.Paths)2