use of javafx.stage.FileChooser in project POL-POM-5 by PlayOnLinux.
the class StepRepresentationBrowse method dragPane.
private Node dragPane() {
final Text textLabel = new Text(textToShow);
final Text dragLabel = new Text("Please click here, or drag a file to me.");
textLabel.getStyleClass().add("boldLabel");
dragLabel.getStyleClass().addAll("normalLabel");
final VBox dragTarget = new VBox();
dragTarget.getChildren().addAll(textLabel, dragLabel);
dragTarget.setOnDragOver(event -> {
if (event.getGestureSource() != dragTarget && event.getDragboard().hasFiles()) {
event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
}
event.consume();
});
dragTarget.setOnDragDropped(event -> {
Dragboard db = event.getDragboard();
boolean success = false;
if (db.hasFiles()) {
this.selectFile(db.getFiles().get(0));
success = true;
}
event.setDropCompleted(success);
event.consume();
});
dragTarget.setPrefSize(660, 308);
dragTarget.getStyleClass().addAll("dragAndDropBox");
dragTarget.setOnMouseClicked(event -> {
final FileChooser fileChooser = new FileChooser();
if (extensions != null) {
fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter(tr("Allowed files"), extensions));
}
fileChooser.setInitialDirectory(browseDirectory);
File dialogResult = fileChooser.showOpenDialog(null);
if (dialogResult != null) {
selectFile(dialogResult);
}
});
return dragTarget;
}
use of javafx.stage.FileChooser in project trex-stateless-gui by cisco-system-traffic-generator.
the class TrafficProfileDialogController method handleLoadProfileBtnClick.
/**
* Handle load profile button click
*
* @param event
*/
@FXML
public void handleLoadProfileBtnClick(MouseEvent event) {
String loadFileName = "";
try {
FileChooser fileChooser = FileChooserFactory.get();
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("YAML Files (*.yaml)", "*.yaml");
FileChooser.ExtensionFilter allFilesFilter = new FileChooser.ExtensionFilter("All files ", "*.*");
fileChooser.getExtensionFilters().add(extFilter);
fileChooser.getExtensionFilters().add(allFilesFilter);
fileChooser.setTitle("Load Profile File");
String loadFolderPath = PreferencesManager.getInstance().getLoadLocation();
if (!Util.isNullOrEmpty(loadFolderPath) && new File(loadFolderPath).exists()) {
fileChooser.setInitialDirectory(new File(loadFolderPath));
}
File loadedFile = fileChooser.showOpenDialog(((Button) (event.getSource())).getScene().getWindow());
if (loadedFile != null) {
loadFileName = loadedFile.getName();
// check if exists in list or not
if (!ProfileManager.getInstance().isFileExists(loadedFile.getName())) {
// Read Selected File.
Profile[] yamlTrafficProfile = trafficProfile.getTrafficProfile(loadedFile);
// make a copy of selected file
File localFile = trafficProfile.convertTrafficProfileToYamlFile(yamlTrafficProfile, loadedFile.getName());
// add it to list
profileListView.getItems().add(localFile.getName());
// save the new selected profile
ProfileManager.getInstance().updateProfilesList(localFile, true);
}
profileListView.getSelectionModel().select(loadedFile.getName());
// enaprofileListView.getSelectionModel().select(localFile.getName());ble delete profile btn
disableProfileFunctionBtn(false);
}
} catch (IOException ex) {
Alert alert = Util.getAlert(AlertType.ERROR);
alert.setContentText("Error loading file " + loadFileName);
alert.showAndWait();
LOG.error("Error loading the profile", ex);
}
}
use of javafx.stage.FileChooser in project jgnash by ccavanaugh.
the class SaveAsTask method start.
public static void start() {
final ResourceBundle resources = ResourceUtils.getBundle();
final File current = new File(EngineFactory.getActiveDatabase());
final FileChooser fileChooser = FileChooserFactory.getDataStoreChooser();
fileChooser.setInitialDirectory(current.getParentFile());
fileChooser.setTitle(resources.getString("Title.SaveAs"));
final File newFile = fileChooser.showSaveDialog(MainView.getPrimaryStage());
if (newFile != null) {
final SaveAsTask saveAsTask = new SaveAsTask(newFile);
new Thread(saveAsTask).start();
StaticUIMethods.displayTaskProgress(saveAsTask);
}
}
use of javafx.stage.FileChooser in project jgnash by ccavanaugh.
the class FileChooserFactory method getDataStoreChooser.
/**
* Returns a {@code FileChooser} configured to filter the supplied jGnash file types
*
* @param types {@code DataStoreType} to filter on
* @return a configured FileChooser
*/
public static FileChooser getDataStoreChooser(final DataStoreType... types) {
final FileChooser fileChooser = new FileChooser();
final String[] ext = new String[types.length];
final StringBuilder description = new StringBuilder(ResourceUtils.getString("Label.jGnashFiles") + " (");
for (int i = 0; i < types.length; i++) {
ext[i] = "*" + types[i].getDataStore().getFileExt();
description.append("*");
description.append(types[i].getDataStore().getFileExt());
if (i < types.length - 1) {
description.append(", ");
}
}
description.append(')');
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter(description.toString(), ext));
return fileChooser;
}
use of javafx.stage.FileChooser in project jgnash by ccavanaugh.
the class ReportActions method exportProfitLossReport.
public static void exportProfitLossReport() {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
final CurrencyNode baseCommodity = engine.getDefaultCurrency();
final FXMLUtils.Pair<DateRangeDialogController> pair = FXMLUtils.load(DateRangeDialogController.class.getResource("DateRangeDialog.fxml"), ResourceUtils.getString("Title.ReportOptions"));
pair.getStage().setResizable(false);
pair.getStage().showAndWait();
final Optional<LocalDate[]> optional = pair.getController().getDates();
optional.ifPresent(localDates -> {
final Preferences preferences = Preferences.userNodeForPackage(ReportActions.class);
final String lastDir = preferences.get(LAST_DIR, null);
final FileChooser fileChooser = new FileChooser();
fileChooser.setTitle(ResourceUtils.getString("Title.SaveFile"));
if (lastDir != null) {
fileChooser.setInitialDirectory(new File(lastDir));
}
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("TXT", "*.txt"));
final File file = fileChooser.showSaveDialog(MainView.getPrimaryStage());
if (file != null) {
preferences.put(LAST_DIR, file.getParent());
final ProfitLossTextReport report = new ProfitLossTextReport(file.getAbsolutePath(), localDates[0], localDates[1], baseCommodity, AccountBalanceDisplayManager::convertToSelectedBalanceMode);
report.run();
}
});
}
Aggregations