javafx.stage.FileChooser Java Examples

The following examples show how to use javafx.stage.FileChooser. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImageManufacturePaneController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
@FXML
public void selectOutlineFile() {
    try {
        final FileChooser fileChooser = new FileChooser();
        File path = AppVariables.getUserConfigPath(sourcePathKey);
        if (path.exists()) {
            fileChooser.setInitialDirectory(path);
        }
        fileChooser.getExtensionFilters().addAll(CommonFxValues.AlphaImageExtensionFilter);
        final File file = fileChooser.showOpenDialog(getMyStage());
        if (file == null) {
            return;
        }
        recordFileOpened(file);
        loadOutlineSource(file);
    } catch (Exception e) {
        logger.error(e.toString());
    }
}
 
Example #2
Source File: SettingsController.java    From Schillsaver with MIT License 6 votes vote down vote up
/**
 * Opens a file chooser for the user to select the FFMPEG executable.
 *
 * @return
 *          The file path.
 */
private String selectFfmpegExecutablePath() {
    final var fileChooser = new FileChooser();
    fileChooser.setTitle("FFMPEG Executable Selection");
    fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));

    final File selectedFile = fileChooser.showOpenDialog(SceneManager.getInstance().getStage());

    if (selectedFile != null) {
        if (selectedFile.exists()) {
            return selectedFile.getPath();
        }
    }

    return "";
}
 
Example #3
Source File: NewDrawingTest.java    From latexdraw with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void commonCanDoFixture() {
	final SystemUtils utils = Mockito.mock(SystemUtils.class);
	Mockito.when(utils.getPathTemplatesDirUser()).thenReturn("");
	SystemUtils.setSingleton(utils);
	ui = Mockito.mock(JfxUI.class);
	statusWidget = Mockito.mock(Label.class);
	progressBar = Mockito.mock(ProgressBar.class);
	mainstage = Mockito.mock(Stage.class);
	file = Mockito.mock(File.class);
	modifiedAlert = Mockito.mock(Alert.class);
	openSaveManager = Mockito.mock(OpenSaver.class);
	fileChooser = Mockito.mock(FileChooser.class);
	currentFolder = Optional.empty();

	cmd = new NewDrawing(file, openSaveManager, progressBar, statusWidget, ui, fileChooser, currentFolder, mainstage, modifiedAlert);
}
 
Example #4
Source File: App.java    From java-ml-projects with Apache License 2.0 6 votes vote down vote up
private Parent buildUI() {
	fc = new FileChooser();
	fc.getExtensionFilters().clear();
	ExtensionFilter jpgFilter = new ExtensionFilter("JPG, JPEG images", "*.jpg", "*.jpeg", "*.JPG", ".JPEG");
	fc.getExtensionFilters().add(jpgFilter);
	fc.setSelectedExtensionFilter(jpgFilter);
	fc.setTitle("Select a JPG image");
	lstLabels = new ListView<>();
	lstLabels.setPrefHeight(200);
	Button btnLoad = new Button("Select an Image");
	btnLoad.setOnAction(e -> validateUrlAndLoadImg());

	HBox hbBottom = new HBox(10, btnLoad);
	hbBottom.setAlignment(Pos.CENTER);

	loadedImage = new ImageView();
	loadedImage.setFitWidth(300);
	loadedImage.setFitHeight(250);
	
	Label lblTitle = new Label("Label image using TensorFlow");
	lblTitle.setFont(Font.font(Font.getDefault().getFamily(), FontWeight.BOLD, 40));
	VBox root = new VBox(10,lblTitle, loadedImage, new Label("Results:"), lstLabels, hbBottom);
	root.setAlignment(Pos.TOP_CENTER);
	return root;
}
 
Example #5
Source File: OutputPanel.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void onOutputSheetEqSetButton(final ActionEvent actionEvent)
{
	FileChooser fileChooser = new FileChooser();
	fileChooser.setTitle(LanguageBundle.getString("in_Prefs_templateEqSetTitle"));
	fileChooser.setInitialDirectory(new File(ConfigurationSettings.getOutputSheetsDir()));
	fileChooser.setInitialFileName(SettingsHandler.getSelectedEqSetTemplate());
	File newTemplate = GuiUtility.runOnJavaFXThreadNow(() -> fileChooser.showOpenDialog(null));

	if (newTemplate != null)
	{
		if (newTemplate.getName().startsWith("eqsheet"))
		{
			SettingsHandler.setSelectedEqSetTemplate(newTemplate.getAbsolutePath());
		}
		else
		{
			ShowMessageDelegate.showMessageDialog(
					LanguageBundle.getString("in_Prefs_templateEqSetError"), //$NON-NLS-1$
					Constants.APPLICATION_NAME, MessageType.ERROR
			);
		}
	}

	outputSheetEqSet.setText(String.valueOf(SettingsHandler.getSelectedEqSetTemplate()));
}
 
Example #6
Source File: MainController.java    From KorgPackage with GNU General Public License v3.0 6 votes vote down vote up
public void savePkgAction() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setInitialDirectory(lastFileChooserPath);
    fileChooser.setTitle("Save PKG/UPD File");
    fileChooser.getExtensionFilters().addAll(
            new FileChooser.ExtensionFilter("PKG/UPD file", "*.pkg", "*.upd"),
            new FileChooser.ExtensionFilter("All files", "*.*")
    );
    File file = fileChooser.showSaveDialog(stage);
    if (file != null) {
        lastFileChooserPath = file.getParentFile();
        PackageWriter packageWriter = new PackageWriter(file);
        List<Chunk> chunks = new ArrayList<>(chunksListView.getItems());
        packageWriter.save(chunks);
        statusLabel.setText("Finished saving package");
    }
}
 
Example #7
Source File: HomeController.java    From TelegramClone with MIT License 6 votes vote down vote up
@FXML
void attachFile(MouseEvent event) {
    try {
        FileChooser fileChooser = new FileChooser();
        File imageFile = fileChooser.showOpenDialog(new Stage());
        BufferedImage bufferedImage = ImageIO.read(imageFile);
        Image image = SwingFXUtils.toFXImage(bufferedImage, null);
        currentlySelectedUser.messagesList.add(new MessageViewModel("", getCurrentTime(), false, true, image));
        messagesListView.scrollTo(currentlySelectedUser.messagesList.size());

    } catch (IOException e) {
        e.printStackTrace();
    }


}
 
Example #8
Source File: ControlUtil.java    From pmd-designer with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static void saveToFileButton(Button button, Stage popupStage, Supplier<String> content, ApplicationComponent owner, Supplier<String> initialFileName) {
    button.setOnAction(e -> {

        FileChooser chooser = new FileChooser();
        chooser.setInitialFileName(initialFileName.get());
        chooser.setTitle("Write to a file");
        File file = chooser.showSaveDialog(popupStage);

        if (file != null) {

            try (OutputStream is = Files.newOutputStream(file.toPath());
                 Writer out = new BufferedWriter(new OutputStreamWriter(is))) {

                out.write(content.get());
                SimplePopups.showActionFeedback(button, AlertType.CONFIRMATION, "File saved");

            } catch (IOException ex) {
                owner.logUserException(ex, Category.TEST_EXPORT_EXCEPTION);
            }
        }
    });
}
 
Example #9
Source File: ProjectParametersImporter.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
private File chooseFile() {
  FileChooser fileChooser = new FileChooser();
  fileChooser.setTitle("Please select a file containing project parameter values for files.");
  fileChooser.getExtensionFilters().addAll(
          new FileChooser.ExtensionFilter("All Files","*.*"),
          new FileChooser.ExtensionFilter("text","*.txt"),
          new FileChooser.ExtensionFilter("csv","*.csv")
          );

  File currentFile = currentProject.getProjectFile();
  if (currentFile != null) {
    File currentDir = currentFile.getParentFile();
    if ((currentDir != null) && (currentDir.exists()))
      fileChooser.setInitialDirectory(currentDir);
  }
  return fileChooser.showOpenDialog(currentStage.getScene().getWindow());
}
 
Example #10
Source File: PortraitInfoPane.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e)
{
	FileChooser fileChooser = new FileChooser();
	fileChooser.setInitialDirectory(new File(PCGenSettings.getPortraitsDir()));
	fileChooser.setTitle(LanguageBundle.getString("in_loadPortrait"));

	// TODO: set extension filter - list of supported images

	File file = GuiUtility.runOnJavaFXThreadNow(() ->
			fileChooser.showOpenDialog(null));
	if (file != null)
	{
		character.setPortrait(file);
	}
}
 
Example #11
Source File: ProjectLoaderParameters.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public ExitCode showSetupDialog(boolean valueCheckRequired) {

  FileChooser fileChooser = new FileChooser();
  fileChooser.setTitle("Open MZmine project");
  fileChooser.getExtensionFilters().addAll(filters);

  File currentFile = getParameter(projectFile).getValue();
  if (currentFile != null) {
    File currentDir = currentFile.getParentFile();
    if ((currentDir != null) && (currentDir.exists()))
      fileChooser.setInitialDirectory(currentDir);
  }

  File selectedFile = fileChooser.showOpenDialog(null);
  if (selectedFile == null)
    return ExitCode.CANCEL;
  getParameter(projectFile).setValue(selectedFile);

  return ExitCode.OK;

}
 
Example #12
Source File: DetailPCController.java    From FlyingAgent with Apache License 2.0 6 votes vote down vote up
@FXML
private void onExport() {
    if(areaMoreInfo.getText() == null || areaMoreInfo.getText().trim().isEmpty())
        return;

    FileChooser fileChooser = new FileChooser();
    FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("Text files (*.txt)", "*.txt");
    fileChooser.getExtensionFilters().add(extFilter);

    File selectedFile = fileChooser.showSaveDialog(areaMoreInfo.getScene().getWindow());
    if(selectedFile != null) {
        try {
            FileWriter fileWriter = new FileWriter(selectedFile);
            fileWriter.write(areaMoreInfo.getText().trim());
            fileWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
Example #13
Source File: CurrentProjectEditorUIImpl.java    From tcMenu with Apache License 2.0 6 votes vote down vote up
@Override
public Optional<String> findFileNameFromUser(boolean open) {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Choose a Menu File");
    fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Embedded menu", "*.emf"));
    installer.getArduinoDirectory().ifPresent(path-> fileChooser.setInitialDirectory(path.toFile()));
    File f;
    if (open) {
        f = fileChooser.showOpenDialog(mainStage);
    } else {
        f = fileChooser.showSaveDialog(mainStage);
    }

    if (f != null) {
        return Optional.of(f.getPath());
    }
    return Optional.empty();
}
 
Example #14
Source File: SystemFileEditController.java    From KorgPackage with GNU General Public License v3.0 6 votes vote down vote up
public void importDataAction() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Open File");
    fileChooser.getExtensionFilters().addAll(
            new FileChooser.ExtensionFilter("All files", "*.*")
    );
    File file = fileChooser.showOpenDialog(stage);
    if (file != null) {
        try {
            FileInputStream fileInputStream = new FileInputStream(file);
            data = new byte[(int) file.length()];
            fileInputStream.read(data, 0, (int) file.length());
            fileInputStream.close();
        } catch (IOException e) {
            System.err.println(e.getMessage());
        }
    }
}
 
Example #15
Source File: RootFSEditController.java    From KorgPackage with GNU General Public License v3.0 6 votes vote down vote up
public void importDataAction() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Open File");
    fileChooser.getExtensionFilters().addAll(
            new FileChooser.ExtensionFilter("All files", "*.*")
    );
    File file = fileChooser.showOpenDialog(stage);
    if (file != null) {
        try {
            FileInputStream fileInputStream = new FileInputStream(file);
            data = new byte[(int) file.length()];
            fileInputStream.read(data, 0, (int) file.length());
            fileInputStream.close();
        } catch (IOException e) {
            System.err.println(e.getMessage());
        }
    }
}
 
Example #16
Source File: FileUtils.java    From Notebook with Apache License 2.0 6 votes vote down vote up
public static File chooseFile(){

		FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle("��ѡ���ļ�");
        if(justVisitedDir == null) {
        	// ���ó�ʼĿ¼
            fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
        } else {
            fileChooser.setInitialDirectory(justVisitedDir);
        }

        fileChooser.getExtensionFilters().addAll(new ExtensionFilter[]{new ExtensionFilter("Image Files", new String[]{"*.png", "*.jpg", "*.jpeg", "*.gif", "*.bmp"}), new ExtensionFilter("JPG", new String[]{"*.jpg"}), new ExtensionFilter("JPEG", new String[]{"*.jpeg"}), new ExtensionFilter("BMP", new String[]{"*.bmp"}), new ExtensionFilter("PNG", new String[]{"*.png"}), new ExtensionFilter("GIF", new String[]{"*.gif"})});
        File file = fileChooser.showOpenDialog(null);
        if(file != null){
        	justVisitedDir = file.getParentFile();
        }
        return file;
	}
 
Example #17
Source File: PortraitInfoPane.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e)
{
	FileChooser fileChooser = new FileChooser();
	fileChooser.setInitialDirectory(new File(PCGenSettings.getPortraitsDir()));
	fileChooser.setTitle(LanguageBundle.getString("in_loadPortrait"));

	// TODO: set extension filter - list of supported images

	File file = GuiUtility.runOnJavaFXThreadNow(() ->
			fileChooser.showOpenDialog(null));
	if (file != null)
	{
		character.setPortrait(file);
	}
}
 
Example #18
Source File: TrainingInterfaceController.java    From FakeImageDetection with GNU General Public License v3.0 6 votes vote down vote up
@FXML
private void loadNeuralNetwork(ActionEvent event) {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Open Resource File");

    fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter("Neural Nets", "*.nnet"));
    nnFile = fileChooser.showOpenDialog(rootPane.getScene().getWindow());

    if (nnFile == null) {
        Calert.showAlert("Error", "Not a valid neural network", Alert.AlertType.ERROR);
        return;
    }

    System.out.println("Training Neural " + nnFile.getAbsolutePath());
    nnIndicator.setSelected(true);
}
 
Example #19
Source File: ImageManufactureController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
@FXML
    public void selectReference() {
        try {
            final FileChooser fileChooser = new FileChooser();
            File path = AppVariables.getUserConfigPath(sourcePathKey);
            if (path.exists()) {
                fileChooser.setInitialDirectory(path);
            }
            fileChooser.getExtensionFilters().addAll(sourceExtensionFilter);
            File file = fileChooser.showOpenDialog(getMyStage());
            if (file == null) {
                return;
            }
            referenceSelected(file);

        } catch (Exception e) {
//            logger.error(e.toString());
        }
    }
 
Example #20
Source File: PCGenFrame.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
void showOpenPartyChooser()
{
	PropertyContext context = PCGenSettings.getInstance();
	FileChooser fileChooser = new FileChooser();
	fileChooser.setTitle("Open PCGen Party File");
	fileChooser.setInitialDirectory(new File(context.getProperty(PCGenSettings.PCP_SAVE_PATH)));

	FileChooser.ExtensionFilter extensionFilter = new FileChooser.ExtensionFilter(
			"party files only", "*.pcp"
	);
	fileChooser.getExtensionFilters().add(extensionFilter);
	fileChooser.setSelectedExtensionFilter(extensionFilter);

	File file = GuiUtility.runOnJavaFXThreadNow(() ->
			fileChooser.showOpenDialog(null));
	if (file != null)
	{
		loadPartyFromFile(file);
	}
}
 
Example #21
Source File: DirectoryService.java    From AsciidocFX with Apache License 2.0 6 votes vote down vote up
@Autowired
public DirectoryService(final ApplicationController controller, final FileBrowseService fileBrowser, final Current current, PathResolverService pathResolver, StoredConfigBean storedConfigBean, FileWatchService fileWatchService, ThreadService threadService, PathMapper pathMapper) {
    this.controller = controller;
    this.fileBrowser = fileBrowser;
    this.current = current;
    this.pathResolver = pathResolver;
    this.storedConfigBean = storedConfigBean;
    this.fileWatchService = fileWatchService;
    this.threadService = threadService;
    this.pathMapper = pathMapper;

    pathSaveSupplier = () -> {
        final FileChooser chooser = newFileChooser("Save Document");
        chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Asciidoc", "*.adoc", "*.asciidoc", "*.asc", "*.ad", "*.txt", "*.*"));
        chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Markdown", "*.md", "*.markdown", "*.txt", "*.*"));
        File file = chooser.showSaveDialog(null);
        return Objects.nonNull(file) ? file.toPath() : null;
    };

}
 
Example #22
Source File: EditorController.java    From FXTutorials with MIT License 6 votes vote down vote up
@FXML
private void onLoad() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setInitialDirectory(new File("./"));
    File file = fileChooser.showOpenDialog(null);
    if (file != null) {
        IOResult<TextFile> io = model.load(file.toPath());

        if (io.isOk() && io.hasData()) {
            currentTextFile = io.getData();

            areaText.clear();
            currentTextFile.getContent().forEach(line -> areaText.appendText(line + "\n"));
        } else {
            System.out.println("Failed");
        }
    }
}
 
Example #23
Source File: FileTrendController.java    From OEE-Designer with MIT License 6 votes vote down vote up
@FXML
private void onBrowseFile() {
	// show file chooser
	FileChooser fileChooser = new FileChooser();

	if (initialDirectory != null) {
		fileChooser.setInitialDirectory(initialDirectory);
	}
	File selectedFile = fileChooser.showOpenDialog(null);

	if (selectedFile == null) {
		return;
	}
	initialDirectory = selectedFile.getParentFile();

	tfFilePath.setUserData(selectedFile);
	tfFilePath.setText(selectedFile.getAbsolutePath());
}
 
Example #24
Source File: ChartViewer.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * A handler for the export to JPEG option in the context menu.
 */
private void handleExportToJPEG() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export to JPEG");
    fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter(
            "JPEG", "jpg"));
    File file = fileChooser.showSaveDialog(this.getScene().getWindow());
    if (file != null) {
        try {
            ExportUtils.writeAsJPEG(this.chart, (int) getWidth(),
                    (int) getHeight(), file);
        } catch (IOException ex) {
            // FIXME: show a dialog with the error
        }
    }        
}
 
Example #25
Source File: FileSelecter.java    From ApkToolPlus with Apache License 2.0 5 votes vote down vote up
/**
   * 添加文件过滤格式
   *
   * @param exts
   * @return
   */
  public FileSelecter addFilters(final List<String> exts){

      if (exts == null || exts.size() == 0)
          return this;

      List<FileChooser.ExtensionFilter> filters = new ArrayList<>();
      for(String ext : exts){
          filters.add(new FileChooser.ExtensionFilter(ext,"*."+ext));
      }

fileChooser.getExtensionFilters().addAll(filters);
      return this;
  }
 
Example #26
Source File: AuxclasspathSetupController.java    From pmd-designer with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void onSelectFileClicked() {
    FileChooser chooser = new FileChooser();
    chooser.setTitle("Add files to the auxilliary classpath");
    chooser.getExtensionFilters().addAll(
            new FileChooser.ExtensionFilter("Java archives", "*.jar", "*.war", "*.ear"),
            new FileChooser.ExtensionFilter("Java class files", "*.class")
    );
    List<File> files = chooser.showOpenMultipleDialog(designerRoot.getMainStage());
    fileListView.getItems().addAll(files);
}
 
Example #27
Source File: MainApp.java    From Corendon-LostLuggage with MIT License 5 votes vote down vote up
public static File selectFileToSave(String defaultFileName) {

        FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle("Specify filename");

        //todo: provide the file selection dialog to the user
        File file = fileChooser.showSaveDialog(mainStage);

        //File selected? return the file, else return null
        if (file != null) {
            return file;
        } else {
            return null;
        }
    }
 
Example #28
Source File: LaunchScreeenController.java    From FakeImageDetection with GNU General Public License v3.0 5 votes vote down vote up
private static void configureFileChooser(final FileChooser fileChooser) {
    fileChooser.setTitle("View Pictures");
    fileChooser.setInitialDirectory(
            new File(System.getProperty("user.dir"))
    );
    FileChooser.ExtensionFilter extFilter
            = new FileChooser.ExtensionFilter("Image Files", "*.JPG", "*.jpg", "*.jpeg", "*.JPEG");
    fileChooser.getExtensionFilters().addAll(extFilter
    );

}
 
Example #29
Source File: Exporter.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param format The format of the document to export.
 * @return The export dialog to select a path.
 */
protected @NotNull FileChooser getExportDialog(final ExportFormat format) {
	fileChooserExport.getExtensionFilters().clear();
	fileChooserExport.getExtensionFilters().addAll(format.getFilter());

	if(!new File(prefs.getPathExport()).isDirectory()) {
		prefs.getCurrentFile().filter(f -> f.isDirectory()).ifPresent(f -> fileChooserExport.setInitialDirectory(new File(f.getPath()).getParentFile()));
	}else {
		fileChooserExport.setInitialDirectory(new File(prefs.getPathExport()));
	}

	return fileChooserExport;
}
 
Example #30
Source File: CreateNewAccount.java    From ChatRoomFX with MIT License 5 votes vote down vote up
private File showOpenFile(){
    FileChooser fileChooser=new FileChooser();
    fileChooser.setTitle("Student Photo");
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("PNG (*.png)", "*.png"));
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("JPG (*.jpg)", "*.jpg"));
    return fileChooser.showOpenDialog(txtUsername.getScene().getWindow());
}