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);
}
}
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;
}
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());
}
}
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());
}
}
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());
}
}
Aggregations