use of javafx.stage.FileChooser in project jgnash by ccavanaugh.
the class ImportAccountsAction method configureFileChooser.
private static FileChooser configureFileChooser() {
final Preferences pref = Preferences.userNodeForPackage(ImportAccountsAction.class);
final FileChooser fileChooser = new FileChooser();
fileChooser.setInitialDirectory(new File(pref.get(LAST_DIR, System.getProperty("user.home"))));
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter(ResourceUtils.getString("Label.XMLFiles") + " (*.xml)", "*.xml", "*.XML"));
return fileChooser;
}
use of javafx.stage.FileChooser in project jgnash by ccavanaugh.
the class ImportOfxAction method configureFileChooser.
private static FileChooser configureFileChooser() {
final Preferences pref = Preferences.userNodeForPackage(ImportOfxAction.class);
final FileChooser fileChooser = new FileChooser();
fileChooser.setInitialDirectory(new File(pref.get(LAST_DIR, System.getProperty("user.home"))));
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("OFX Files (*.ofx,*.qfx)", "*.ofx", "*.qfx", "*.OFX", "*.QFX"), new FileChooser.ExtensionFilter("All Files (*.*)", "*.*"));
return fileChooser;
}
use of javafx.stage.FileChooser in project jgnash by ccavanaugh.
the class ChangeDatabasePasswordDialogController method handleDatabaseButtonAction.
@FXML
private void handleDatabaseButtonAction() {
final FileChooser fileChooser = FileChooserFactory.getDataStoreChooser(DataStoreType.H2_DATABASE, DataStoreType.HSQL_DATABASE);
fileChooser.setTitle(resources.getString("Title.SelFile"));
final File file = fileChooser.showOpenDialog(MainView.getPrimaryStage());
if (file != null && file.exists()) {
databaseTextField.setText(file.getAbsolutePath());
}
}
use of javafx.stage.FileChooser in project DistributedFractalNetwork by Budder21.
the class Window method mouseClicked.
/**
* Called when the mouse has been clicked. It determines what to do with the
* event.
*/
public void mouseClicked(MouseEvent e) {
for (ArrowButton b : palette.getOpacityList()) System.out.println(b.getData());
Point p = e.getPoint();
repaint();
if (selectedButton == null) {
if (bgButton.isClicked(p)) {
// TODO: create a color menu for the inside part of the fractal
// and store the color like this: bgButton.setData(newColor);
// this.repaint();
} else if (saveButton.isClicked(p)) {
Platform.runLater(() -> {
TextInputDialog dialog = new TextInputDialog("");
dialog.setTitle("");
dialog.setHeaderText(null);
dialog.setContentText("Save Palette As:");
// Traditional way to get the response value.
try {
String result = dialog.showAndWait().get();
if (!result.equals(""))
palette.writeTo(result);
} catch (Exception e5) {
}
});
} else if (loadButton.isClicked(p)) {
Platform.runLater(new Runnable() {
public void run() {
FileChooser chooser = new FileChooser();
chooser.setTitle("Open Palette");
File f1 = new File("fractals/palettes");
if (!f1.exists()) {
f1.mkdirs();
try {
f1.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
chooser.setInitialDirectory(f1);
FileChooser.ExtensionFilter filter = new FileChooser.ExtensionFilter("Palettes (*.palette)", "*.palette");
chooser.getExtensionFilters().add(filter);
File f = chooser.showOpenDialog(null);
if (f != null) {
palette = new Palette(f.getPath(), false);
repaint();
layer.setColorPalette(palette);
}
}
});
} else if (colorRect.contains(p)) {
addColorButton(p.x);
repaint();
} else if (opacityRect.contains(p)) {
addOpacityButton(p.x);
repaint();
}
} else {
if (selectedButton.isSquareClicked(p)) {
if (selectedButton.isDown()) {
// TODO: create a opacity menu for the selected button and
// store the value like this:
// selectedButton.setData(newValue); this.repaint();
// NOTE: the value should be between 0 and 1.0
Platform.runLater(() -> {
selectedButton.setData(OpacityBox.display(selectedButton));
this.repaint();
});
} else {
// TODO: create a color menu for the selected button and
// store the color like this:
// selectedButton.setData(newColor); this.repaint();
}
}
}
}
use of javafx.stage.FileChooser in project DistributedFractalNetwork by Budder21.
the class ExportImageTool method exportImage.
/**
* This method is where the actual menus and user interaction happens. First, a window appears allowing the user to specify the
* resolution of the image. After that, the user chooses a directory and a file name and exports it as an image.
* When the image is done rendering and saving, a final menu will pop up informing the user that the image was succesfully
* exported
* @param fractal the fractal to be exported as an image
*/
public void exportImage(RenderManager fractal) {
Dimension initRes = fractal.getScreenResolution();
Dialog<Pair<String, String>> dialog = new Dialog<>();
dialog.setTitle("Export Fractal");
dialog.setHeaderText("Step 1");
dialog.setContentText("Choose a resolution:");
ButtonType loginButtonType = new ButtonType("Continue", ButtonData.OK_DONE);
dialog.getDialogPane().getButtonTypes().addAll(loginButtonType, ButtonType.CANCEL);
GridPane grid = new GridPane();
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(20, 150, 10, 10));
TextField widthField = new TextField("1600");
widthField.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
if (!newValue.matches("\\d*")) {
widthField.setText(newValue.replaceAll("[^\\d]", ""));
}
}
});
TextField heightField = new TextField("1600");
heightField.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
if (!newValue.matches("\\d*")) {
heightField.setText(newValue.replaceAll("[^\\d]", ""));
}
}
});
grid.add(new Label("Width:"), 0, 0);
grid.add(widthField, 1, 0);
grid.add(new Label("Height:"), 0, 1);
grid.add(heightField, 1, 1);
dialog.getDialogPane().setContent(grid);
dialog.setResultConverter(dialogButton -> {
if (dialogButton == loginButtonType)
return new Pair<String, String>(widthField.getText(), heightField.getText());
return null;
});
Optional<Pair<String, String>> result = dialog.showAndWait();
int width = 0;
int height = 0;
try {
width = Integer.valueOf(result.get().getKey());
height = Integer.valueOf(result.get().getValue());
} catch (NumberFormatException e) {
AlertMenu aMenu = new AlertMenu("INVALID INPUT: Must be an integer.", "INVALID INPUT: Must be an integer.");
exportImage(fractal);
} catch (Exception e) {
e.printStackTrace();
return;
}
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Export Fractal");
alert.setHeaderText("Step 2");
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> result2 = alert.showAndWait();
if (result2.get() == buttonTypeOne) {
FileChooser fileChooser = new FileChooser();
fileChooser.setInitialFileName("My Fractal.png");
fileChooser.setTitle("Select File Destination");
FileChooser.ExtensionFilter filter = new FileChooser.ExtensionFilter("Images (*.png, *.jpg)", "*.png", "*.jpg");
fileChooser.getExtensionFilters().add(filter);
File file = fileChooser.showSaveDialog(null);
String formatName = file.getName().substring(file.getName().indexOf(".") + 1);
if (file != null) {
try {
file.createNewFile();
fractal.setScreenResolution(new Dimension(width, height));
ImageIO.write(fractal.getImage(), formatName, file);
Alert alert2 = new Alert(AlertType.INFORMATION);
alert2.setTitle("Export Fractal");
alert2.setHeaderText(null);
alert2.setContentText("Image Succesfully Saved.");
alert2.showAndWait();
fractal.setScreenResolution(initRes);
} catch (Exception e) {
fractal.setScreenResolution(initRes);
}
}
} else {
return;
}
}
Aggregations