List of usage examples for javafx.stage FileChooser FileChooser
FileChooser
From source file:view.EditorView.java
@FXML void menuItemOpenOnAction(@SuppressWarnings("unused") ActionEvent event) { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Open a game file"); File file = fileChooser.showOpenDialog(stage); if (file != null) { // if file == null the action was aborted try {/*from www. j a v a2s . c om*/ loadGame(file); } catch (IOException | ClassNotFoundException e) { FOKLogger.log(MainWindow.class.getName(), Level.SEVERE, "Failed to open game " + file.toString(), e); new Alert(Alert.AlertType.ERROR, "Could not open the game file: \n\n" + ExceptionUtils.getRootCauseMessage(e)).show(); } } }
From source file:dpfmanager.shell.interfaces.gui.component.dessign.DessignController.java
public void performImportConfigAction() { File file;/*w w w .j a va 2s . c om*/ String value = GuiWorkbench.getTestParams("import"); if (value != null) { //Test mode file = new File(value); } else { //Ask for file String configDir = DPFManagerProperties.getDefaultDirConfig(); FileChooser fileChooser = new FileChooser(); fileChooser.setTitle(getBundle().getString("openConfig")); fileChooser.setInitialDirectory(new File(configDir)); FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter( getBundle().getString("dpfConfigFiles"), "*.dpf"); fileChooser.getExtensionFilters().add(extFilter); file = fileChooser.showOpenDialog(GuiWorkbench.getMyStage()); } addConfigFile(file, true); }
From source file:model.Modele.java
/** * Methode qui importe un fichier de donne de la machine local (sans * internet)/*w w w .j av a 2 s. com*/ * * @param event * @return le nom du fichier pour l'afficher dans la rubrique des donnes * @throws IOException * @throws InterruptedException */ public String import_file(ActionEvent event) throws IOException, InterruptedException { FileChooser filechooser = new FileChooser(); filechooser.setTitle("Ouvrir un fichier"); File file = filechooser.showOpenDialog(null); if (file != null) { String[] extensions = { "txt", "csv", "gz" }; for (String extension : extensions) { if (file.getName().toLowerCase().endsWith("." + extension)) { if (extension.equals("gz")) { final String fileName = file.toURI().toString(); String fileNamelast = null; for (String retval : fileName.split("/")) { fileNamelast = retval; } File filex = new File(fileNamelast + ".txt"); boolean success = file.renameTo(filex); file = filex; } nom_fichier = Save_data(file); } } } return nom_fichier; }
From source file:fr.amap.commons.javafx.chart.ChartViewer.java
/** * A handler for the export to SVG option in the context menu. *//*from w w w .j a v a 2s.c o m*/ private void handleExportToSVG() { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Export to SVG"); fileChooser.setSelectedExtensionFilter( new FileChooser.ExtensionFilter("Scalable Vector Graphics (SVG)", "svg")); File file = fileChooser.showSaveDialog(stage); if (file != null) { CanvasPositionsAndSize canvasPositionAndSize = getCanvasPositionAndSize(); SVGGraphics2D sVGGraphics2D = new SVGGraphics2D((int) canvasPositionAndSize.totalWidth, (int) canvasPositionAndSize.totalHeight); Graphics2D graphics2D = (Graphics2D) sVGGraphics2D.create(); int index = 0; for (ChartCanvas canvas : chartCanvasList) { ((Drawable) canvas.chart).draw(graphics2D, canvasPositionAndSize.positionsAndSizes.get(index)); index++; } try { SVGUtils.writeToSVG(file, sVGGraphics2D.getSVGElement()); } catch (IOException ex) { Logger.getLogger(ChartViewer.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.esri.geoevent.test.performance.ui.OrchestratorController.java
/** * Displays a file chooser to select a file to open *//*from w w w . ja v a 2 s . c o m*/ private void openFixturesFile() { File currentDir = Paths.get("").toAbsolutePath().toFile(); FileChooser fileChooser = new FileChooser(); fileChooser.setTitle(UIMessages.getMessage("UI_OPEN_FILE_CHOOSER_TITLE")); fileChooser.setInitialDirectory(currentDir); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("XML", "*.xml")); fileChooser.setInitialFileName(DEFAULT_FIXTURES_FILE); File file = fileChooser.showOpenDialog(stage); if (file != null) { try { loadFile(file); setupTabs(); } catch (Exception error) { //TODO: Improve error handling and reporting error.printStackTrace(); } } }
From source file:ch.unibas.charmmtools.gui.step1.mdAssistant.CHARMM_GUI_InputAssistant.java
/** * Handles the event when one of the 3 button_open_XXX is pressed button_generate is enabled only when the 3 files * have been loaded/*from w w w. j a v a 2 s.c o m*/ * * @param event */ @FXML protected void OpenButtonPressed(ActionEvent event) { Window myParent = button_generate.getScene().getWindow(); FileChooser chooser = new FileChooser(); chooser.setInitialDirectory(new File(".")); File selectedFile = null; chooser.setTitle("Open File"); if (event.getSource().equals(button_open_PAR)) { chooser.getExtensionFilters().add( new FileChooser.ExtensionFilter("CHARMM FF parameters file (*.par,*.prm)", "*.par", "*.prm")); selectedFile = chooser.showOpenDialog(myParent); if (selectedFile != null) { textfield_PAR.setText(selectedFile.getAbsolutePath()); PAR_selected = true; } } else if (event.getSource().equals(button_open_RTF)) { chooser.getExtensionFilters().add( new FileChooser.ExtensionFilter("CHARMM FF topology file (*.top,*.rtf)", "*.top", "*.rtf")); selectedFile = chooser.showOpenDialog(myParent); if (selectedFile != null) { textfield_RTF.setText(selectedFile.getAbsolutePath()); RTF_selected = true; } } else if (event.getSource().equals(button_open_COR_gas)) { chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Coordinates file (*.pdb)", "*.pdb")); selectedFile = chooser.showOpenDialog(myParent); if (selectedFile != null) { textfield_COR_gas.setText(selectedFile.getAbsolutePath()); COR_selected_gas = true; } } else if (event.getSource().equals(button_open_COR_liquid)) { chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Coordinates file (*.pdb)", "*.pdb")); selectedFile = chooser.showOpenDialog(myParent); if (selectedFile != null) { textfield_COR_liquid.setText(selectedFile.getAbsolutePath()); COR_selected_liquid = true; } } else if (event.getSource().equals(button_open_COR_solv)) { chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Coordinates file (*.pdb)", "*.pdb")); selectedFile = chooser.showOpenDialog(myParent); if (selectedFile != null) { textfield_COR_solv.setText(selectedFile.getAbsolutePath()); COR_selected_solv = true; } } else if (event.getSource().equals(button_open_LPUN)) { chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("LPUN file", "*.lpun")); selectedFile = chooser.showOpenDialog(myParent); if (selectedFile != null) { textfield_LPUN.setText(selectedFile.getAbsolutePath()); LPUN_selected = true; } } else { throw new UnknownError("Unknown Event in OpenButtonPressed(ActionEvent event)"); } this.validateButtonGenerate(); }
From source file:de.hs.mannheim.modUro.controller.diagram.fx.ChartViewer.java
/** * A handler for the export to PNG option in the context menu. */// w w w. j ava 2 s.co m private void handleExportToPNG() { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Export to PNG"); fileChooser.setSelectedExtensionFilter( new FileChooser.ExtensionFilter("Portable Network Graphics (PNG)", "png")); File file = fileChooser.showSaveDialog(this.getScene().getWindow()); if (file != null) { try { ExportUtils.writeAsPNG(this.chart, (int) getWidth(), (int) getHeight(), file); } catch (IOException ex) { // FIXME: show a dialog with the error } } }
From source file:de.pixida.logtest.designer.MainWindow.java
private FileChooser createFileDialog(final Type type, final String actionName) { final FileChooser fileChooser = new FileChooser(); fileChooser.setTitle(actionName + " " + type.getName()); fileChooser.getExtensionFilters()/* w ww . j a va2 s . c o m*/ .add(new FileChooser.ExtensionFilter(type.getFileDescription(), type.getFileMask())); final Editor currentEditor = this.getCurrentEditor(); if (currentEditor != null && currentEditor.isDocumentAssignedToFile()) { fileChooser.setInitialDirectory(currentEditor.getDirectoryOfAssignedFile()); } else { if (this.lastFolderForOpenOrSaveAsFileDialog != null) { fileChooser.setInitialDirectory(this.lastFolderForOpenOrSaveAsFileDialog); } } return fileChooser; }
From source file:org.beryx.viewreka.fxapp.ProjectLibs.java
public void addUncatalogedLibs() { FileChooser libChooser = new FileChooser(); libChooser.setTitle("Select libraries"); libChooser.getExtensionFilters().addAll( new FileChooser.ExtensionFilter("jar and vbundle files", "*.jar", "*.vbundle"), new FileChooser.ExtensionFilter("All files", "*.*")); GuiSettings guiSettings = guiSettingsManager.getSettings(); File initialDir = guiSettings.getMostRecentProjectDir(); String lastLibDirPath = guiSettings.getProperty(PROP_LAST_LIBRARY_DIR, null, true); if (lastLibDirPath != null) { try {// ww w . j av a 2 s . com File dir = new File(lastLibDirPath); if (dir.isDirectory()) { initialDir = dir; } } catch (Exception e) { log.warn("Cannot retrieve last library path", e); } } libChooser.setInitialDirectory(initialDir); List<File> libFiles = libChooser.showOpenMultipleDialog(getScene().getWindow()); if (libFiles != null && !libFiles.isEmpty()) { guiSettings.setProperty(PROP_LAST_LIBRARY_DIR, libFiles.get(0).getParent()); Stream<String> libStream = libFiles.stream().map(f -> f.getAbsolutePath()) .filter(s -> (s != null && !s.isEmpty())).filter(s -> lstLib.getItems().stream() .map(entry -> entry.getCellText()).noneMatch(txt -> txt.equals(s))); libStream.forEach(s -> lstLib.getItems().add(LibListEntry.forFilePath(s))); } }
From source file:eu.mihosoft.vrl.fxscad.MainController.java
@FXML private void onExportAsSTLFile(ActionEvent e) { if (csgObject == null) { Action response = Dialogs.create().title("Error").message("Cannot export STL. There is no geometry :(") .lightweight().showError(); return;//from w w w . j ava 2 s . c om } FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Export STL File"); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("STL files (*.stl)", "*.stl")); File f = fileChooser.showSaveDialog(null); if (f == null) { return; } String fName = f.getAbsolutePath(); if (!fName.toLowerCase().endsWith(".stl")) { fName += ".stl"; } try { eu.mihosoft.vrl.v3d.FileUtil.write(Paths.get(fName), csgObject.toStlString()); } catch (IOException ex) { Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex); } }