Search in sources :

Example 1 with DirectoryChooser

use of javafx.stage.DirectoryChooser 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 2 with DirectoryChooser

use of javafx.stage.DirectoryChooser in project DistributedFractalNetwork by Budder21.

the class NetworkCreationTool method createNetwork.

/**
	 * This method, when called, will bring the user through a series of menus helping them
	 * configure the Network they wish to set up.
	 * @return whether or not the network was successfully created.
	 */
public boolean createNetwork() {
    File[] fractals = new File(Constants.FRACTAL_FILEPATH).listFiles();
    List<String> choices = new ArrayList<>();
    for (File f : fractals) {
        if (!f.getName().equals("palettes"))
            choices.add(f.getName());
    }
    ChoiceDialog<String> dialog1 = null;
    try {
        dialog1 = new ChoiceDialog<>(choices.get(0), choices);
    } catch (IndexOutOfBoundsException e) {
        AlertMenu alarm = new AlertMenu("Cannot create network: no fractal found on this computer.", "Fractals are searched for in the fractals folder. Please save a fractal to that folder and try again.");
    }
    dialog1.setTitle("Create Network");
    dialog1.setHeaderText("Step 1");
    dialog1.setContentText("Choose a fractal:");
    System.out.println("here...");
    RenderManager fractal = null;
    try {
        fractal = new RenderManager(dialog1.showAndWait().get());
    } catch (Exception e) {
        return false;
    }
    Pair<Integer, Integer> dimension = displayDialog2();
    if (dimension == null)
        return false;
    fractal.setScreenResolution(new Dimension(dimension.getKey(), dimension.getValue()));
    Pair<Double, Double> params = getParams();
    if (params == null)
        return false;
    if (params.getKey() == null)
        return false;
    if (params.getValue() == null)
        return false;
    fractal.setZoom(params.getKey());
    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.setTitle("Create Network");
    alert.setHeaderText("Step 4");
    alert.setContentText("Choose a directory:");
    ButtonType buttonTypeOne = new ButtonType("Choose");
    ButtonType buttonTypeCancel = new ButtonType("Cancel", ButtonData.CANCEL_CLOSE);
    alert.getButtonTypes().setAll(buttonTypeOne, buttonTypeCancel);
    Optional<ButtonType> result = alert.showAndWait();
    String directory = "";
    if (result.get() == buttonTypeOne) {
        DirectoryChooser directoryChooser = new DirectoryChooser();
        File selectedDirectory = directoryChooser.showDialog(null);
        if (selectedDirectory == null) {
            return false;
        } else {
            directory = selectedDirectory.getPath();
        }
    } else {
        return false;
    }
    this.server = new Server(fractal, params.getValue(), directory);
    return true;
}
Also used : Server(server.Server) ArrayList(java.util.ArrayList) Dimension(java.awt.Dimension) Alert(javafx.scene.control.Alert) File(java.io.File) RenderManager(fractal.RenderManager) ButtonType(javafx.scene.control.ButtonType) DirectoryChooser(javafx.stage.DirectoryChooser)

Example 3 with DirectoryChooser

use of javafx.stage.DirectoryChooser in project Entitas-Java by Rubentxu.

the class CodeGeneratorJFX method handleGeneratedFolder.

@FXML
public void handleGeneratedFolder(ActionEvent event) {
    final DirectoryChooser directoryChooser = new DirectoryChooser();
    final File selectedDirectory = directoryChooser.showDialog(stage);
    if (selectedDirectory != null) {
        fieldGeneratedFolder.setText(selectedDirectory.getAbsolutePath());
        if (props != null)
            props.setProperty("fieldGeneratedFolder", selectedDirectory.getAbsolutePath());
    }
}
Also used : CodeGenFile(ilargia.entitas.codeGeneration.data.CodeGenFile) DirectoryChooser(javafx.stage.DirectoryChooser) FXML(javafx.fxml.FXML)

Example 4 with DirectoryChooser

use of javafx.stage.DirectoryChooser in project Entitas-Java by Rubentxu.

the class CodeGeneratorJFX method handleComponentsFolder.

@FXML
public void handleComponentsFolder(ActionEvent event) {
    final DirectoryChooser directoryChooser = new DirectoryChooser();
    final File selectedDirectory = directoryChooser.showDialog(stage);
    if (selectedDirectory != null) {
        fieldComponentFolder.setText(selectedDirectory.getAbsolutePath());
        if (props != null)
            props.setProperty("fieldComponentFolder", selectedDirectory.getAbsolutePath());
    }
}
Also used : CodeGenFile(ilargia.entitas.codeGeneration.data.CodeGenFile) DirectoryChooser(javafx.stage.DirectoryChooser) FXML(javafx.fxml.FXML)

Example 5 with DirectoryChooser

use of javafx.stage.DirectoryChooser in project Entitas-Java by Rubentxu.

the class VisualDebbuger method handleComponentsFolder.

@FXML
public void handleComponentsFolder(ActionEvent event) {
    final DirectoryChooser directoryChooser = new DirectoryChooser();
    final File selectedDirectory = directoryChooser.showDialog(stage);
    if (selectedDirectory != null) {
        fieldComponentFolder.setText(selectedDirectory.getAbsolutePath());
        if (props != null)
            props.setProperty("fieldComponentFolder", selectedDirectory.getAbsolutePath());
    }
}
Also used : DirectoryChooser(javafx.stage.DirectoryChooser) FXML(javafx.fxml.FXML)

Aggregations

DirectoryChooser (javafx.stage.DirectoryChooser)15 File (java.io.File)7 FXML (javafx.fxml.FXML)6 CodeGenFile (ilargia.entitas.codeGeneration.data.CodeGenFile)4 RenderManager (fractal.RenderManager)1 Popup (io.bitsquare.gui.main.overlays.popups.Popup)1 Dimension (java.awt.Dimension)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 CancellationException (java.util.concurrent.CancellationException)1 Platform (javafx.application.Platform)1 Alert (javafx.scene.control.Alert)1 ButtonType (javafx.scene.control.ButtonType)1 PayFileClient (net.plan99.payfile.client.PayFileClient)1 Server (server.Server)1