Search in sources :

Example 41 with FileChooser

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;
}
Also used : FileChooser(javafx.stage.FileChooser) Preferences(java.util.prefs.Preferences) File(java.io.File)

Example 42 with 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;
}
Also used : FileChooser(javafx.stage.FileChooser) Preferences(java.util.prefs.Preferences) File(java.io.File)

Example 43 with 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());
    }
}
Also used : FileChooser(javafx.stage.FileChooser) File(java.io.File) InjectFXML(jgnash.uifx.util.InjectFXML) FXML(javafx.fxml.FXML)

Example 44 with FileChooser

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();
            }
        }
    }
}
Also used : Palette(fractal.Palette) FileChooser(javafx.stage.FileChooser) Point(java.awt.Point) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) TextInputDialog(javafx.scene.control.TextInputDialog)

Example 45 with FileChooser

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;
    }
}
Also used : Insets(javafx.geometry.Insets) Label(javafx.scene.control.Label) Dialog(javafx.scene.control.Dialog) FileChooser(javafx.stage.FileChooser) TextField(javafx.scene.control.TextField) ButtonType(javafx.scene.control.ButtonType) Pair(javafx.util.Pair) GridPane(javafx.scene.layout.GridPane) Dimension(java.awt.Dimension) Alert(javafx.scene.control.Alert) File(java.io.File)

Aggregations

FileChooser (javafx.stage.FileChooser)65 File (java.io.File)60 Preferences (java.util.prefs.Preferences)21 IOException (java.io.IOException)17 ResourceBundle (java.util.ResourceBundle)11 FXML (javafx.fxml.FXML)11 FileOutputStream (java.io.FileOutputStream)5 ArrayList (java.util.ArrayList)5 Alert (javafx.scene.control.Alert)5 Button (javafx.scene.control.Button)5 Popup (io.bitsquare.gui.main.overlays.popups.Popup)3 List (java.util.List)3 GargoyleFileAlreadyExistException (com.kyj.fx.voeditor.visual.exceptions.GargoyleFileAlreadyExistException)2 Palette (fractal.Palette)2 Path (java.nio.file.Path)2 ObservableList (javafx.collections.ObservableList)2 FilteredList (javafx.collections.transformation.FilteredList)2 SortedList (javafx.collections.transformation.SortedList)2 Task (javafx.concurrent.Task)2 Insets (javafx.geometry.Insets)2