Java Code Examples for java.awt.FileDialog#setDirectory()
The following examples show how to use
java.awt.FileDialog#setDirectory() .
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: 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 2
Source File: FileDialogForPackages.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Override public void init() { if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) { Sysout.createDialogWithInstructions(new String[]{ "Press PASS, this test is for MacOS X only."}); return; } System.setProperty("apple.awt.use-file-dialog-packages", "true"); setLayout(new GridLayout(1, 1)); fd = new FileDialog(new Frame(), "Open"); fd.setDirectory(APPLICATIONS_FOLDER); showBtn = new Button("Show File Dialog"); showBtn.addActionListener(this); add(showBtn); String[] instructions = { "1) Click on 'Show File Dialog' button. A file dialog will come up.", "2) Navigate to the Applications folder if not already there", "3) Check that the application bundles can be selected and can not be navigated", "4) If it's true then the test passed, otherwise it failed."}; Sysout.createDialogWithInstructions(instructions); }
Example 3
Source File: FileDialogForPackages.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Override public void init() { if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) { Sysout.createDialogWithInstructions(new String[]{ "Press PASS, this test is for MacOS X only."}); return; } System.setProperty("apple.awt.use-file-dialog-packages", "true"); setLayout(new GridLayout(1, 1)); fd = new FileDialog(new Frame(), "Open"); fd.setDirectory(APPLICATIONS_FOLDER); showBtn = new Button("Show File Dialog"); showBtn.addActionListener(this); add(showBtn); String[] instructions = { "1) Click on 'Show File Dialog' button. A file dialog will come up.", "2) Navigate to the Applications folder if not already there", "3) Check that the application bundles can be selected and can not be navigated", "4) If it's true then the test passed, otherwise it failed."}; Sysout.createDialogWithInstructions(instructions); }
Example 4
Source File: FileDialogForPackages.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override public void init() { if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) { Sysout.createDialogWithInstructions(new String[]{ "Press PASS, this test is for MacOS X only."}); return; } System.setProperty("apple.awt.use-file-dialog-packages", "true"); setLayout(new GridLayout(1, 1)); fd = new FileDialog(new Frame(), "Open"); fd.setDirectory(APPLICATIONS_FOLDER); showBtn = new Button("Show File Dialog"); showBtn.addActionListener(this); add(showBtn); String[] instructions = { "1) Click on 'Show File Dialog' button. A file dialog will come up.", "2) Navigate to the Applications folder if not already there", "3) Check that the application bundles can be selected and can not be navigated", "4) If it's true then the test passed, otherwise it failed."}; Sysout.createDialogWithInstructions(instructions); }
Example 5
Source File: FileDialogForPackages.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
@Override public void init() { if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) { Sysout.createDialogWithInstructions(new String[]{ "Press PASS, this test is for MacOS X only."}); return; } System.setProperty("apple.awt.use-file-dialog-packages", "true"); setLayout(new GridLayout(1, 1)); fd = new FileDialog(new Frame(), "Open"); fd.setDirectory(APPLICATIONS_FOLDER); showBtn = new Button("Show File Dialog"); showBtn.addActionListener(this); add(showBtn); String[] instructions = { "1) Click on 'Show File Dialog' button. A file dialog will come up.", "2) Navigate to the Applications folder if not already there", "3) Check that the application bundles can be selected and can not be navigated", "4) If it's true then the test passed, otherwise it failed."}; Sysout.createDialogWithInstructions(instructions); }
Example 6
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 7
Source File: FileDialogForPackages.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@Override public void init() { if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) { Sysout.createDialogWithInstructions(new String[]{ "Press PASS, this test is for MacOS X only."}); return; } System.setProperty("apple.awt.use-file-dialog-packages", "true"); setLayout(new GridLayout(1, 1)); fd = new FileDialog(new Frame(), "Open"); fd.setDirectory(APPLICATIONS_FOLDER); showBtn = new Button("Show File Dialog"); showBtn.addActionListener(this); add(showBtn); String[] instructions = { "1) Click on 'Show File Dialog' button. A file dialog will come up.", "2) Navigate to the Applications folder if not already there", "3) Check that the application bundles can be selected and can not be navigated", "4) If it's true then the test passed, otherwise it failed."}; Sysout.createDialogWithInstructions(instructions); }
Example 8
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 9
Source File: FileDialogForPackages.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@Override public void init() { if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) { Sysout.createDialogWithInstructions(new String[]{ "Press PASS, this test is for MacOS X only."}); return; } System.setProperty("apple.awt.use-file-dialog-packages", "true"); setLayout(new GridLayout(1, 1)); fd = new FileDialog(new Frame(), "Open"); fd.setDirectory(APPLICATIONS_FOLDER); showBtn = new Button("Show File Dialog"); showBtn.addActionListener(this); add(showBtn); String[] instructions = { "1) Click on 'Show File Dialog' button. A file dialog will come up.", "2) Navigate to the Applications folder if not already there", "3) Check that the application bundles can be selected and can not be navigated", "4) If it's true then the test passed, otherwise it failed."}; Sysout.createDialogWithInstructions(instructions); }
Example 10
Source File: FileUtils.java From toxiclibs with GNU Lesser General Public License v2.1 | 6 votes |
/** * Displays a standard AWT file dialog for choosing a file for loading or * saving. * * @param frame * parent frame * @param title * dialog title * @param path * base directory (or null) * @param filter * a FilenameFilter implementation (or null) * @param mode * either FileUtils.LOAD or FileUtils.SAVE * @return path to chosen file or null, if user has canceled */ public static String showFileDialog(final Frame frame, final String title, String path, FilenameFilter filter, final int mode) { String fileID = null; FileDialog fd = new FileDialog(frame, title, mode); if (path != null) { fd.setDirectory(path); } if (filter != null) { fd.setFilenameFilter(filter); } fd.setVisible(true); if (fd.getFile() != null) { fileID = fd.getFile(); fileID = fd.getDirectory() + fileID; } return fileID; }
Example 11
Source File: FileDialogForPackages.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
@Override public void init() { if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) { Sysout.createDialogWithInstructions(new String[]{ "Press PASS, this test is for MacOS X only."}); return; } System.setProperty("apple.awt.use-file-dialog-packages", "true"); setLayout(new GridLayout(1, 1)); fd = new FileDialog(new Frame(), "Open"); fd.setDirectory(APPLICATIONS_FOLDER); showBtn = new Button("Show File Dialog"); showBtn.addActionListener(this); add(showBtn); String[] instructions = { "1) Click on 'Show File Dialog' button. A file dialog will come up.", "2) Navigate to the Applications folder if not already there", "3) Check that the application bundles can be selected and can not be navigated", "4) If it's true then the test passed, otherwise it failed."}; Sysout.createDialogWithInstructions(instructions); }
Example 12
Source File: GameFileSelector.java From triplea with GNU General Public License v3.0 | 5 votes |
/** * Opens up a UI pop-up allowing user to select a game file. Returns nothing if user closes the * pop-up. */ public Optional<File> selectGameFile(final Frame owner) { final FileDialog fileDialog = new FileDialog(owner); fileDialog.setMode(FileDialog.LOAD); fileDialog.setDirectory(ClientSetting.saveGamesFolderPath.getValueOrThrow().toString()); fileDialog.setFilenameFilter((dir, name) -> GameDataFileUtils.isCandidateFileName(name)); fileDialog.setVisible(true); // FileDialog.getFiles() always returns an array // of 1 or 0 items, because FileDialog.multipleMode is false by default return Arrays.stream(fileDialog.getFiles()).findAny().map(this::mapFileResult); }
Example 13
Source File: FileUtils.java From toxiclibs with GNU Lesser General Public License v2.1 | 5 votes |
/** * Displays a standard AWT file dialog for choosing a file for loading or * saving. * * @param frame * parent frame * @param title * dialog title * @param path * base directory (or null) * @param formats * an array of allowed file extensions (or null to allow all) * @param mode * either FileUtils.LOAD or FileUtils.SAVE * @return path to chosen file or null, if user has canceled */ public static String showFileDialog(final Frame frame, final String title, String path, final String[] formats, final int mode) { String fileID = null; FileDialog fd = new FileDialog(frame, title, mode); if (path != null) { fd.setDirectory(path); } if (formats != null) { fd.setFilenameFilter(new FilenameFilter() { public boolean accept(File dir, String name) { boolean isAccepted = false; for (String ext : formats) { if (name.indexOf(ext) != -1) { isAccepted = true; break; } } return isAccepted; } }); } fd.setVisible(true); if (fd.getFile() != null) { fileID = fd.getFile(); fileID = fd.getDirectory() + fileID; } return fileID; }
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: CustomSettingsDialog.java From swingsane with Apache License 2.0 | 5 votes |
private File getLoadFile(String filename, String extension) { FileDialog fd = new FileDialog((JDialog) getRootPane().getTopLevelAncestor(), Localizer.localize("LoadScannerOptionsFromFileTitle"), FileDialog.LOAD); fd.setDirectory("."); FilenameExtensionFilter filter = new FilenameExtensionFilter(); filter.addExtension("xml"); fd.setFilenameFilter(filter); fd.setModal(true); fd.setVisible(true); if (fd.getFile() == null) { return null; } return new File(fd.getDirectory() + File.separator + fd.getFile()); }
Example 18
Source File: Notate.java From jmg with GNU General Public License v2.0 | 5 votes |
/** * Dialog to import a jm XML file */ public void openJMXML() { FileDialog loadjmxml = new FileDialog(this, "Select a jMusic XML score file.", FileDialog.LOAD); loadjmxml.setDirectory( lastDirectory ); loadjmxml.show(); String fileName = loadjmxml.getFile(); if (fileName != null) { Score s = new Score(); lastDirectory = loadjmxml.getDirectory(); Read.xml(s, lastDirectory + fileName); setNewScore(s); } }
Example 19
Source File: MainFrame.java From mpcmaid with GNU Lesser General Public License v2.1 | 5 votes |
public void saveAs() { final FileDialog saveDialog = new FileDialog(this); saveDialog.setDirectory(Preferences.getInstance().getSavePath()); saveDialog.setMode(FileDialog.SAVE); saveDialog.setFilenameFilter(new FilenameFilter() { public boolean accept(File dir, String name) { String[] supportedFiles = { "PGM", "pgm" }; for (int i = 0; i < supportedFiles.length; i++) { if (name.endsWith(supportedFiles[i])) { return true; } } return false; } }); saveDialog.setVisible(true); Preferences.getInstance().setSavePath(saveDialog.getDirectory()); String filename = saveDialog.getFile(); if (saveDialog.getDirectory() != null && filename != null) { if (!filename.toUpperCase().endsWith(".PGM")) { filename += ".PGM"; } String filePath = saveDialog.getDirectory() + filename; System.out.println(filePath); final File file = new File(filePath); setPgmFile(file); program.save(pgmFile); } }
Example 20
Source File: ChatRoomTransferDecorator.java From Spark with Apache License 2.0 | 5 votes |
private void showFilePicker() { SwingWorker worker = new SwingWorker() { @Override public Object construct() { try { Thread.sleep(10); } catch (InterruptedException e1) { Log.error(e1); } return true; } @Override public void finished() { FileDialog fileChooser = SparkManager.getTransferManager().getFileChooser(SparkManager.getChatManager().getChatContainer().getChatFrame(), Res.getString("title.select.file.to.send")); if (SparkManager.getTransferManager().getDefaultDirectory() != null) { fileChooser.setDirectory(SparkManager.getTransferManager().getDefaultDirectory().getAbsolutePath()); } fileChooser.setVisible(true); final File[] files = fileChooser.getFiles(); if ( files.length == 0) { // no selection return; } File file = files[0]; // Single-file selection is used. Using the first array item is safe. if (file.exists()) { SparkManager.getTransferManager().setDefaultDirectory(file.getParentFile()); SparkManager.getTransferManager().sendFile(file, ((ChatRoomImpl)chatRoom).getParticipantJID()); } } }; worker.start(); }