Java Code Examples for java.awt.FileDialog#setFile()
The following examples show how to use
java.awt.FileDialog#setFile() .
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: TestingPanel.java From EchoSim with Apache License 2.0 | 6 votes |
private void doLoad() { FileDialog fd = new FileDialog(getFrame(), "Load History File", FileDialog.LOAD); fd.setDirectory(RuntimeLogic.getProp("history.file.dir")); fd.setFile(RuntimeLogic.getProp("history.file.file")); fd.setVisible(true); if (fd.getDirectory() == null) return; String historyFile = fd.getDirectory()+System.getProperty("file.separator")+fd.getFile(); if ((historyFile == null) || (historyFile.length() == 0)) return; try { RuntimeLogic.loadHistory(mRuntime, new File(historyFile)); RuntimeLogic.setProp("history.file.dir", fd.getDirectory()); RuntimeLogic.setProp("history.file.file", fd.getFile()); } catch (IOException e) { JOptionPane.showMessageDialog(this, e.getLocalizedMessage(), "Error reading "+historyFile, JOptionPane.ERROR_MESSAGE); } }
Example 2
Source File: TestingPanel.java From EchoSim with Apache License 2.0 | 6 votes |
private void doSave() { FileDialog fd = new FileDialog(getFrame(), "Save History File", FileDialog.SAVE); fd.setDirectory(RuntimeLogic.getProp("history.file.dir")); fd.setFile(RuntimeLogic.getProp("history.file.file")); fd.setVisible(true); if (fd.getDirectory() == null) return; String historyFile = fd.getDirectory()+System.getProperty("file.separator")+fd.getFile(); if ((historyFile == null) || (historyFile.length() == 0)) return; try { RuntimeLogic.saveHistory(mRuntime, new File(historyFile)); RuntimeLogic.setProp("history.file.dir", fd.getDirectory()); RuntimeLogic.setProp("history.file.file", fd.getFile()); } catch (IOException e) { JOptionPane.showMessageDialog(this, e.getLocalizedMessage(), "Error reading "+historyFile, JOptionPane.ERROR_MESSAGE); } }
Example 3
Source File: ApplicationPanel.java From EchoSim with Apache License 2.0 | 6 votes |
protected void doUtteranceLoadFile() { FileDialog fd = new FileDialog(getFrame(), "Load Utterance File", FileDialog.LOAD); fd.setDirectory(RuntimeLogic.getProp("utterance.file.dir")); fd.setFile(RuntimeLogic.getProp("utterance.file.file")); fd.setVisible(true); if (fd.getDirectory() == null) return; String intentFile = fd.getDirectory()+System.getProperty("file.separator")+fd.getFile(); if ((intentFile == null) || (intentFile.length() == 0)) return; try { RuntimeLogic.readUtterances(mRuntime, (new File(intentFile)).toURI()); RuntimeLogic.setProp("utterance.file.dir", fd.getDirectory()); RuntimeLogic.setProp("utterance.file.file", fd.getFile()); } catch (IOException e) { JOptionPane.showMessageDialog(this, e.getLocalizedMessage(), "Error reading "+intentFile, JOptionPane.ERROR_MESSAGE); } }
Example 4
Source File: ApplicationPanel.java From EchoSim with Apache License 2.0 | 6 votes |
protected void doIntentLoadFile() { FileDialog fd = new FileDialog(getFrame(), "Load Intent File", FileDialog.LOAD); fd.setDirectory(RuntimeLogic.getProp("intent.file.dir")); fd.setFile(RuntimeLogic.getProp("intent.file.file")); fd.setVisible(true); if (fd.getDirectory() == null) return; String intentFile = fd.getDirectory()+System.getProperty("file.separator")+fd.getFile(); if ((intentFile == null) || (intentFile.length() == 0)) return; try { RuntimeLogic.readIntents(mRuntime, (new File(intentFile)).toURI()); RuntimeLogic.setProp("intent.file.dir", fd.getDirectory()); RuntimeLogic.setProp("intent.file.file", fd.getFile()); } catch (IOException e) { JOptionPane.showMessageDialog(this, e.getLocalizedMessage(), "Error reading "+intentFile, JOptionPane.ERROR_MESSAGE); } }
Example 5
Source File: ScriptPanel.java From EchoSim with Apache License 2.0 | 6 votes |
private void doSaveDisk() { FileDialog fd = new FileDialog(getFrame(), "Save Script", FileDialog.SAVE); fd.setDirectory(RuntimeLogic.getProp("script.file.dir")); fd.setFile(RuntimeLogic.getProp("script.file.file")); fd.setVisible(true); if (fd.getDirectory() == null) return; String historyFile = fd.getDirectory()+System.getProperty("file.separator")+fd.getFile(); if ((historyFile == null) || (historyFile.length() == 0)) return; try { ScriptLogic.saveScript(mRuntime, new File(historyFile)); RuntimeLogic.setProp("script.file.dir", fd.getDirectory()); RuntimeLogic.setProp("script.file.file", fd.getFile()); } catch (IOException e) { JOptionPane.showMessageDialog(this, e.getLocalizedMessage(), "Error reading "+historyFile, JOptionPane.ERROR_MESSAGE); } }
Example 6
Source File: SaveGameFileChooser.java From triplea with GNU General Public License v3.0 | 6 votes |
/** * Displays a file chooser dialog for the user to select the file to which the current game should * be saved. * * @param frame The owner of the file chooser dialog; may be {@code null}. * @return The file to which the current game should be saved or {@code null} if the user * cancelled the operation. */ public static File getSaveGameLocation(final Frame frame, final GameData gameData) { final FileDialog fileDialog = new FileDialog(frame); fileDialog.setMode(FileDialog.SAVE); fileDialog.setDirectory(ClientSetting.saveGamesFolderPath.getValueOrThrow().toString()); fileDialog.setFilenameFilter((dir, name) -> GameDataFileUtils.isCandidateFileName(name)); fileDialog.setFile(getSaveGameName(gameData)); fileDialog.setVisible(true); final String fileName = fileDialog.getFile(); if (fileName == null) { return null; } // If the user selects a filename that already exists, // the AWT Dialog will ask the user for confirmation return new File(fileDialog.getDirectory(), GameDataFileUtils.addExtensionIfAbsent(fileName)); }
Example 7
Source File: ScriptPanel.java From EchoSim with Apache License 2.0 | 6 votes |
private void doLoadDisk() { FileDialog fd = new FileDialog(getFrame(), "Load Script", FileDialog.LOAD); fd.setDirectory(RuntimeLogic.getProp("script.file.dir")); fd.setFile(RuntimeLogic.getProp("script.file.file")); fd.setVisible(true); if (fd.getDirectory() == null) return; String historyFile = fd.getDirectory()+System.getProperty("file.separator")+fd.getFile(); if ((historyFile == null) || (historyFile.length() == 0)) return; try { ScriptLogic.load(mRuntime, new File(historyFile)); RuntimeLogic.setProp("script.file.dir", fd.getDirectory()); RuntimeLogic.setProp("script.file.file", fd.getFile()); } catch (IOException e) { JOptionPane.showMessageDialog(this, e.getLocalizedMessage(), "Error reading "+historyFile, JOptionPane.ERROR_MESSAGE); } }
Example 8
Source File: SuitePanel.java From EchoSim with Apache License 2.0 | 6 votes |
private void doLoadDisk() { FileDialog fd = new FileDialog(getFrame(), "Load Test Suite", FileDialog.LOAD); fd.setDirectory(RuntimeLogic.getProp("suite.file.dir")); fd.setFile(RuntimeLogic.getProp("suite.file.file")); fd.setVisible(true); if (fd.getDirectory() == null) return; String historyFile = fd.getDirectory()+System.getProperty("file.separator")+fd.getFile(); if ((historyFile == null) || (historyFile.length() == 0)) return; try { SuiteLogic.load(mRuntime, new File(historyFile)); RuntimeLogic.setProp("suite.file.dir", fd.getDirectory()); RuntimeLogic.setProp("suite.file.file", fd.getFile()); } catch (IOException e) { JOptionPane.showMessageDialog(this, e.getLocalizedMessage(), "Error reading "+historyFile, JOptionPane.ERROR_MESSAGE); } }
Example 9
Source File: SuitePanel.java From EchoSim with Apache License 2.0 | 6 votes |
private void doSaveDisk() { FileDialog fd = new FileDialog(getFrame(), "Save Suite", FileDialog.SAVE); fd.setDirectory(RuntimeLogic.getProp("suite.file.dir")); fd.setFile(RuntimeLogic.getProp("suite.file.file")); fd.setVisible(true); if (fd.getDirectory() == null) return; String historyFile = fd.getDirectory()+System.getProperty("file.separator")+fd.getFile(); if ((historyFile == null) || (historyFile.length() == 0)) return; try { SuiteLogic.save(mRuntime, new File(historyFile)); RuntimeLogic.setProp("suite.file.dir", fd.getDirectory()); RuntimeLogic.setProp("suite.file.file", fd.getFile()); } catch (IOException e) { JOptionPane.showMessageDialog(this, e.getLocalizedMessage(), "Error reading "+historyFile, JOptionPane.ERROR_MESSAGE); } }
Example 10
Source File: MainGui.java From OpenID-Attacker with GNU General Public License v2.0 | 5 votes |
private void loadItemActionPerformed(ActionEvent evt) {//GEN-FIRST:event_loadItemActionPerformed FileDialog fd = new FileDialog(this, "Choose a file", FileDialog.LOAD); fd.setFile("*.xml"); fd.setVisible(true); File[] files = fd.getFiles(); if (files.length > 0) { File loadFile = files[0]; try { ToolConfiguration currentToolConfig = new ToolConfiguration(); currentToolConfig.setAttackerConfig(controller.getAttackerConfig()); currentToolConfig.setAnalyzerConfig(controller.getAnalyzerConfig()); XmlPersistenceHelper.mergeConfigFileToConfigObject(loadFile, currentToolConfig); } catch (XmlPersistenceError ex) { Logger.getLogger(MainGui.class.getName()).log(Level.SEVERE, null, ex); } } /*int returnVal = loadFileChooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File loadFile = loadFileChooser.getSelectedFile(); try { XmlPersistenceHelper.mergeConfigFileToConfigObject(loadFile, controller.getConfig()); } catch (XmlPersistenceError ex) { Logger.getLogger(MainGui.class.getName()).log(Level.SEVERE, null, ex); } }*/ }
Example 11
Source File: MainFrame.java From lizzie with GNU General Public License v3.0 | 5 votes |
public void openFile() { JSONObject filesystem = Lizzie.config.persisted.getJSONObject("filesystem"); FileDialog fileDialog = new FileDialog(this, resourceBundle.getString("LizzieFrame.openFile")); fileDialog.setLocationRelativeTo(this); fileDialog.setDirectory(filesystem.getString("last-folder")); fileDialog.setFile("*.sgf;*.gib;*.SGF;*.GIB"); fileDialog.setMultipleMode(false); fileDialog.setMode(0); fileDialog.setVisible(true); File[] file = fileDialog.getFiles(); if (file.length > 0) loadFile(file[0]); }
Example 12
Source File: Export.java From BART with MIT License | 5 votes |
private File chooseFile() { JFrame mainFrame = (JFrame) WindowManager.getDefault().getMainWindow(); FileDialog fileDialog = new FileDialog(mainFrame, new File(System.getProperty("user.home")).toString()); fileDialog.setTitle("Export changes in cvs file"); fileDialog.setFile("expected.csv"); fileDialog.setMode(FileDialog.SAVE); fileDialog.setFilenameFilter(new ExtFileFilter("csv")); fileDialog.setVisible(true); String filename = fileDialog.getFile(); if (filename == null){ return null; } String dir = fileDialog.getDirectory(); return new File(dir + File.separator + filename); }
Example 13
Source File: PacketTool.java From megamek with GNU General Public License v2.0 | 5 votes |
/** * Load a board from a file. */ public void boardLoad() { FileDialog fd = new FileDialog(this, "Load Board...", FileDialog.LOAD); fd.setDirectory("data" + File.separator + "boards"); if (boardName.getText().length() > 0) { fd.setFile(boardName.getText()); } fd.setLocation(this.getLocation().x + 150, this.getLocation().y + 100); fd.setVisible(true); if (fd.getFile() == null) { // I want a file, y'know! return; } String curpath = fd.getDirectory(); String curfile = fd.getFile(); // load! try { InputStream is = new FileInputStream(new File(curpath, curfile)); board.load(is); // okay, done! is.close(); // Record the file's name. boardName.setText(curfile); // Enable the send button. butSend.setEnabled(true); } catch (IOException ex) { System.err.println("error opening file to save!"); System.err.println(ex); } }
Example 14
Source File: CFileChooser.java From binnavi with Apache License 2.0 | 5 votes |
private static int showNativeFileDialog(final JFileChooser chooser) { final FileDialog result = new FileDialog((Frame) chooser.getParent()); result.setDirectory(chooser.getCurrentDirectory().getPath()); final File selected = chooser.getSelectedFile(); result.setFile(selected == null ? "" : selected.getPath()); result.setFilenameFilter(new FilenameFilter() { @Override public boolean accept(final File dir, final String name) { return chooser.getFileFilter().accept(new File(dir.getPath() + File.pathSeparator + name)); } }); if (chooser.getDialogType() == SAVE_DIALOG) { result.setMode(FileDialog.SAVE); } else { // The native dialog only support Open and Save result.setMode(FileDialog.LOAD); } if (chooser.getFileSelectionMode() == DIRECTORIES_ONLY) { System.setProperty("apple.awt.fileDialogForDirectories", "true"); } // Display dialog result.setVisible(true); System.setProperty("apple.awt.fileDialogForDirectories", "false"); if (result.getFile() == null) { return CANCEL_OPTION; } final String selectedDir = result.getDirectory(); chooser .setSelectedFile(new File(FileUtils.ensureTrailingSlash(selectedDir) + result.getFile())); return APPROVE_OPTION; }
Example 15
Source File: PreviewPanel.java From swingsane with Apache License 2.0 | 5 votes |
private File getSaveFile(String filename, String extension) { FileDialog fd = new FileDialog((Frame) getRootPane().getTopLevelAncestor(), Localizer.localize("SaveImagesToFileTittle"), FileDialog.SAVE); fd.setDirectory("."); FilenameExtensionFilter filter = new FilenameExtensionFilter(); filter.addExtension(extension); fd.setFilenameFilter(filter); fd.setFile(filename + "." + extension); fd.setModal(true); fd.setVisible(true); return new File(fd.getDirectory() + File.separator + fd.getFile()); }
Example 16
Source File: CustomSettingsDialog.java From swingsane with Apache License 2.0 | 5 votes |
private File getSaveFile(String filename, String extension) { FileDialog fd = new FileDialog((JDialog) getRootPane().getTopLevelAncestor(), Localizer.localize("SaveScannerOptionsToFileTitle"), FileDialog.SAVE); fd.setDirectory("."); FilenameExtensionFilter filter = new FilenameExtensionFilter(); filter.addExtension("xml"); fd.setFilenameFilter(filter); fd.setFile(filename + "." + extension); fd.setModal(true); fd.setVisible(true); if (fd.getFile() == null) { return null; } return new File(fd.getDirectory() + File.separator + fd.getFile()); }
Example 17
Source File: FileDialogUtils.java From pumpernickel with MIT License | 5 votes |
/** * Show a save FileDialog. * * @param f * the frame that owns the FileDialog. * @param title * the dialog title * @param filename * the optional default filename shown in the file dialog. * @param extension * the file extension ("xml", "png", etc.) * @return a File the user chose. */ public static File showSaveDialog(Frame f, String title, String filename, String extension) { if (extension.startsWith(".")) extension = extension.substring(1); FileDialog fd = new FileDialog(f, title); fd.setMode(FileDialog.SAVE); if (filename != null) fd.setFile(filename); fd.setFilenameFilter(new SuffixFilenameFilter(extension)); fd.pack(); fd.setLocationRelativeTo(null); fd.setVisible(true); String s = fd.getFile(); if (s == null) return null; if (s.toLowerCase().endsWith("." + extension)) { return new File(fd.getDirectory() + s); } // TODO: show a 'are you sure you want to replace' dialog here, if we // change the filename // native FileDialogs don't always show the right warning dialog IF the // file extension // isn't present return new File(fd.getDirectory() + fd.getFile() + "." + extension); }
Example 18
Source File: Write.java From jmg with GNU General Public License v2.0 | 5 votes |
/** * Save the jMusic score as a standard MIDI file * Prompt user for a filename * @param Score */ public static void midi(Score score) { FileDialog fd = new FileDialog(new Frame(), "Save as a MIDI file ...", FileDialog.SAVE); fd.setFile("jMusic_composition.mid"); fd.show(); if (fd.getFile() != null) { Write.midi(score, fd.getDirectory() + fd.getFile()); } }
Example 19
Source File: Notate.java From jmg with GNU General Public License v2.0 | 5 votes |
/** * Dialog to import a MIDI file */ public void openMidi() { Score s = new Score(); FileDialog loadMidi = new FileDialog(this, "Select a MIDI file.", FileDialog.LOAD); loadMidi.setDirectory( lastDirectory ); loadMidi.setFile( lastFileName ); loadMidi.show(); String fileName = loadMidi.getFile(); if (fileName != null) { lastFileName = fileName; lastDirectory = loadMidi.getDirectory(); Read.midi(s, lastDirectory + fileName); setNewScore(s); } }
Example 20
Source File: SourceTab.java From FoxTelem with GNU General Public License v3.0 | 4 votes |
public SourceTab(MainWindow mw) { mainWindow = mw; setLayout(new BorderLayout(3, 3)); JPanel bottomPanel = new JPanel(); buildBottomPanel(this, BorderLayout.CENTER, bottomPanel); JPanel optionsRowPanel = new JPanel(); buildOptionsRow(this, BorderLayout.SOUTH, optionsRowPanel); JPanel topPanel = new JPanel(); topPanel.setLayout(new BorderLayout(3, 3)); add(topPanel, BorderLayout.NORTH); JPanel rightPanel = new JPanel(); buildRightPanel(topPanel, BorderLayout.EAST, rightPanel); //if (Config.useNativeFileChooser) { fd = new FileDialog(MainWindow.frame, "Select Wav file",FileDialog.LOAD); fd.setFile("*.wav"); //} else { fc = new JFileChooser(); // initialize the file chooser FileNameExtensionFilter filter = new FileNameExtensionFilter( "Wav files", "wav", "wave"); fc.setFileFilter(filter); //} sourcePanel = new JPanel(); buildLeftPanel(topPanel, BorderLayout.CENTER, sourcePanel); enableSourceModeSelectionComponents(!Config.retuneCenterFrequency); if (soundCardComboBox.getSelectedIndex() != 0) { if (Config.startButtonPressed) { // Wait for the database to be ready then press the start button while (!Config.payloadStore.initialized()) { Log.println("Waiting for Payload store before hitting start..."); try { Thread.sleep(10); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } processStartButtonClick(); } } showFilters(Config.showFilters); // hide the filters because we have calculated the optimal matched filters showSourceOptions(Config.showSourceOptions); showAudioOptions(Config.showAudioOptions); }