use of javafx.stage.FileChooser in project trex-stateless-gui by cisco-system-traffic-generator.
the class FileManager method getSelectedFile.
/**
* Return selected file
*
* @param windowTitle
* @param fileName
* @param window
* @param type
* @param filePath
* @param isExport
* @return
*/
public static File getSelectedFile(String windowTitle, String fileName, Window window, FileType type, String filePath, boolean isExport) {
FileChooser fileChooser = FileChooserFactory.get();
fileChooser.setTitle(windowTitle);
fileChooser.setInitialFileName(fileName);
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter(type.getFilterDescription(), type.getFilterExtension());
fileChooser.getExtensionFilters().add(extFilter);
FileChooser.ExtensionFilter allFilesFilter = new FileChooser.ExtensionFilter("All files ", "*.*");
fileChooser.getExtensionFilters().add(allFilesFilter);
if (!Util.isNullOrEmpty(filePath) && new File(filePath).exists()) {
fileChooser.setInitialDirectory(new File(filePath));
}
if (isExport) {
return fileChooser.showSaveDialog(window);
} else {
return fileChooser.showOpenDialog(window);
}
}
use of javafx.stage.FileChooser in project jgnash by ccavanaugh.
the class MenuBarController method handleApplyStyleAction.
@FXML
private void handleApplyStyleAction() {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle(resources.getString("Title.Open"));
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter(resources.getString("Label.CssFiles"), "*.css"));
final File file = fileChooser.showOpenDialog(MainView.getPrimaryStage());
if (file != null && FileUtils.getFileExtension(file.toString()).equalsIgnoreCase("css")) {
if (ThemeManager.setUserStyle(file.toPath())) {
JavaFXUtils.runLater(() -> StaticUIMethods.displayMessage(resources.getString("Message.Info.RestartToApply")));
}
}
}
use of javafx.stage.FileChooser in project jgnash by ccavanaugh.
the class StaticAccountsMethods method exportAccountTree.
static void exportAccountTree() {
final ResourceBundle resources = ResourceUtils.getBundle();
final Preferences pref = Preferences.userNodeForPackage(StaticAccountsMethods.class);
final FileChooser fileChooser = new FileChooser();
final File initialDirectory = new File(pref.get(EXPORT_DIR, System.getProperty("user.home")));
// Protect against an IllegalArgumentException
if (initialDirectory.isDirectory()) {
fileChooser.setInitialDirectory(initialDirectory);
}
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter(resources.getString("Label.CsvFiles") + " (*.csv)", "*.csv"), new FileChooser.ExtensionFilter(resources.getString("Label.SpreadsheetFiles") + " (*.xls)", "*.xls"), new FileChooser.ExtensionFilter(resources.getString("Label.SpreadsheetFiles") + " (*.xlsx)", "*.xlsx"));
final File file = fileChooser.showSaveDialog(MainView.getPrimaryStage());
final File exportFile;
if (file != null) {
if (!FileUtils.fileHasExtension(file.getName())) {
// fix up the file name if the user did not specify it
final String fileExtension = fileChooser.getSelectedExtensionFilter().getExtensions().get(0).substring(1);
exportFile = new File(FileUtils.stripFileExtension(file.getAbsolutePath()) + fileExtension);
} else {
exportFile = file;
}
pref.put(EXPORT_DIR, exportFile.getParentFile().getAbsolutePath());
final Task<Void> exportTask = new Task<>() {
@Override
protected Void call() {
updateMessage(resources.getString("Message.PleaseWait"));
updateProgress(-1, Long.MAX_VALUE);
if (FileUtils.getFileExtension(exportFile.getName()).contains(XLS)) {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
final AbstractReportTableModel reportTableModel = new ListOfAccountsReport.AccountListModel(engine.getAccountList(), engine.getDefaultCurrency());
Workbook.export(reportTableModel, exportFile);
} else {
CsvExport.exportAccountTree(EngineFactory.getEngine(EngineFactory.DEFAULT), exportFile.toPath());
}
return null;
}
};
new Thread(exportTask).start();
StaticUIMethods.displayTaskProgress(exportTask);
}
}
use of javafx.stage.FileChooser in project jgnash by ccavanaugh.
the class ReportActions method exportBalanceByMonthCSVReport.
public static void exportBalanceByMonthCSVReport() {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
final Preferences preferences = Preferences.userNodeForPackage(ReportActions.class);
final FXMLUtils.Pair<BalanceByMonthOptionsDialogController> pair = FXMLUtils.load(BalanceByMonthOptionsDialogController.class.getResource("BalanceByMonthOptionsDialog.fxml"), ResourceUtils.getString("Title.ReportOptions"));
pair.getController().forceDefaultCurrencyProperty().set(preferences.getBoolean(FORCE_CURRENCY, false));
pair.getStage().setResizable(false);
pair.getStage().showAndWait();
final boolean vertical = pair.getController().isVertical();
final boolean forceCurrency = pair.getController().forceDefaultCurrencyProperty().get();
final Optional<LocalDate[]> optional = pair.getController().getDates();
optional.ifPresent(localDates -> {
final String lastDir = preferences.get(LAST_DIR, null);
preferences.putBoolean(FORCE_CURRENCY, forceCurrency);
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("CSV", "*.csv"));
final File file = fileChooser.showSaveDialog(MainView.getPrimaryStage());
if (file != null) {
preferences.put(LAST_DIR, file.getParent());
final BalanceByMonthCSVReport report;
if (forceCurrency) {
report = new BalanceByMonthCSVReport(file.getAbsolutePath(), localDates[0], localDates[1], engine.getDefaultCurrency(), vertical, AccountBalanceDisplayManager::convertToSelectedBalanceMode);
} else {
report = new BalanceByMonthCSVReport(file.getAbsolutePath(), localDates[0], localDates[1], null, vertical, AccountBalanceDisplayManager::convertToSelectedBalanceMode);
}
report.run();
}
});
}
use of javafx.stage.FileChooser in project jgnash by ccavanaugh.
the class ReportViewerDialogController method handleSaveAction.
@FXML
private void handleSaveAction() {
final Preferences pref = Preferences.userNodeForPackage(ReportViewerDialogController.class);
final FileChooser fileChooser = new FileChooser();
fileChooser.setTitle(ResourceUtils.getString("Title.SaveFile"));
final File initialDirectory = new File(pref.get(LAST_DIR, System.getProperty("user.home")));
// Protect against an IllegalArgumentException
if (initialDirectory.isDirectory()) {
fileChooser.setInitialDirectory(initialDirectory);
}
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter(resources.getString("Label.PDFFiles") + " (.pdf)", "*.pdf", "*.PDF"), new FileChooser.ExtensionFilter(resources.getString("Label.SpreadsheetFiles") + " (*.xls, *.xlsx)", "*.xls", "*.xlsx"));
final File file = fileChooser.showSaveDialog(MainView.getPrimaryStage());
if (file != null) {
pref.put(LAST_DIR, file.getParent());
final String extension = FileUtils.getFileExtension(file.getAbsolutePath()).toLowerCase(Locale.ROOT);
switch(extension) {
case "pdf":
try {
report.get().saveToFile(file.toPath());
} catch (final IOException ex) {
StaticUIMethods.displayException(ex);
}
break;
case "xls":
case "xlsx":
final AbstractReportTableModel model = reportController.createReportModel();
Workbook.export(model, file);
break;
default:
break;
}
}
}
Aggregations