java.awt.FileDialog Java Examples

The following examples show how to use java.awt.FileDialog. 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: FileUtils.java    From toxiclibs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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 #2
Source File: FileDialogForPackages.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@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: StateSpaceLoader.java    From PIPE with MIT License 6 votes vote down vote up
/**
 * @param temporary path to copy to new location
 * @param message   displayed message in save file dialog pop up
 */
private void copyFile(Path temporary, String message) {
    loadDialog.setMode(FileDialog.SAVE);
    loadDialog.setTitle(message);
    loadDialog.setVisible(true);

    File[] files = loadDialog.getFiles();
    if (files.length > 0) {
        File file = files[0];
        Path path = Paths.get(file.toURI());
        try {
            Files.copy(temporary, path, StandardCopyOption.REPLACE_EXISTING);
        } catch (IOException e) {
            LOGGER.log(Level.SEVERE, e.getMessage());
        }
    }
}
 
Example #4
Source File: GtkFileDialogPeer.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private void showNativeDialog() {
    String dirname = fd.getDirectory();
    // File path has a priority against directory path.
    String filename = fd.getFile();
    if (filename != null) {
        final File file = new File(filename);
        if (fd.getMode() == FileDialog.LOAD
            && dirname != null
            && file.getParent() == null) {
            // File path for gtk_file_chooser_set_filename.
            filename = dirname + (dirname.endsWith(File.separator) ? "" :
                                          File.separator) + filename;
        }
        if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
            // Filename for gtk_file_chooser_set_current_name.
            filename = file.getName();
            // Directory path for gtk_file_chooser_set_current_folder.
            dirname = file.getParent();
        }
    }
    run(fd.getTitle(), fd.getMode(), dirname, filename,
        fd.getFilenameFilter(), fd.isMultipleMode(), fd.getX(), fd.getY());
}
 
Example #5
Source File: GtkFileDialogPeer.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private void showNativeDialog() {
    String dirname = fd.getDirectory();
    // File path has a priority against directory path.
    String filename = fd.getFile();
    if (filename != null) {
        final File file = new File(filename);
        if (fd.getMode() == FileDialog.LOAD
            && dirname != null
            && file.getParent() == null) {
            // File path for gtk_file_chooser_set_filename.
            filename = dirname + (dirname.endsWith(File.separator) ? "" :
                                          File.separator) + filename;
        }
        if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
            // Filename for gtk_file_chooser_set_current_name.
            filename = file.getName();
            // Directory path for gtk_file_chooser_set_current_folder.
            dirname = file.getParent();
        }
    }
    GtkFileDialogPeer.this.run(fd.getTitle(), fd.getMode(), dirname,
                               filename, fd.getFilenameFilter(),
                               fd.isMultipleMode(), fd.getX(), fd.getY());
}
 
Example #6
Source File: FileDialogForPackages.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@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 #7
Source File: FileDialogForDirectories.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@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.fileDialogForDirectories", "true");

    setLayout(new GridLayout(1, 1));

    fd = new FileDialog(new Frame(), "Open");

    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) Check that files can't be selected.",
            "3) Check that directories can be selected.",
            "4) Repeat steps 1 - 3 a few times for different files and directories.",
            "5) If it's true then the test passed, otherwise it failed."};
    Sysout.createDialogWithInstructions(instructions);
}
 
Example #8
Source File: GtkFileDialogPeer.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private void showNativeDialog() {
    String dirname = fd.getDirectory();
    // File path has a priority against directory path.
    String filename = fd.getFile();
    if (filename != null) {
        final File file = new File(filename);
        if (fd.getMode() == FileDialog.LOAD
            && dirname != null
            && file.getParent() == null) {
            // File path for gtk_file_chooser_set_filename.
            filename = dirname + (dirname.endsWith(File.separator) ? "" :
                                          File.separator) + filename;
        }
        if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
            // Filename for gtk_file_chooser_set_current_name.
            filename = file.getName();
            // Directory path for gtk_file_chooser_set_current_folder.
            dirname = file.getParent();
        }
    }
    run(fd.getTitle(), fd.getMode(), dirname, filename,
        fd.getFilenameFilter(), fd.isMultipleMode(), fd.getX(), fd.getY());
}
 
Example #9
Source File: FileDialogForDirectories.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@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.fileDialogForDirectories", "true");

    setLayout(new GridLayout(1, 1));

    fd = new FileDialog(new Frame(), "Open");

    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) Check that files can't be selected.",
            "3) Check that directories can be selected.",
            "4) Repeat steps 1 - 3 a few times for different files and directories.",
            "5) If it's true then the test passed, otherwise it failed."};
    Sysout.createDialogWithInstructions(instructions);
}
 
Example #10
Source File: FileDialogForPackages.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@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 #11
Source File: MainFrame.java    From mpcmaid with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void open() {
	final FileDialog openDialog = new FileDialog(this);
	openDialog.setDirectory(Preferences.getInstance().getOpenPath());
	openDialog.setMode(FileDialog.LOAD);
	openDialog.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;
		}
	});
	openDialog.setVisible(true);
	Preferences.getInstance().setOpenPath(openDialog.getDirectory());
	if (openDialog.getDirectory() != null && openDialog.getFile() != null) {
		String filePath = openDialog.getDirectory() + openDialog.getFile();
		System.out.println(filePath);
		final File pgmFile = new File(filePath);
		final MainFrame newFrame = new MainFrame(pgmFile);
		newFrame.show();
	}
}
 
Example #12
Source File: SparkTransferManager.java    From Spark with Apache License 2.0 6 votes vote down vote up
public void sendFileTo(ContactItem item) {
    FileDialog fileChooser = getFileChooser(SparkManager.getMainWindow(), Res.getString("title.select.file.to.send"));
    if (defaultDirectory != null)
    {
        fileChooser.setDirectory( defaultDirectory.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()) {
        defaultDirectory = file.getParentFile();
        sendFile( file, item.getJid() );
    }

}
 
Example #13
Source File: GtkFileDialogPeer.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private void showNativeDialog() {
    String dirname = fd.getDirectory();
    // File path has a priority against directory path.
    String filename = fd.getFile();
    if (filename != null) {
        final File file = new File(filename);
        if (fd.getMode() == FileDialog.LOAD
            && dirname != null
            && file.getParent() == null) {
            // File path for gtk_file_chooser_set_filename.
            filename = dirname + (dirname.endsWith(File.separator) ? "" :
                                          File.separator) + filename;
        }
        if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
            // Filename for gtk_file_chooser_set_current_name.
            filename = file.getName();
            // Directory path for gtk_file_chooser_set_current_folder.
            dirname = file.getParent();
        }
    }
    GtkFileDialogPeer.this.run(fd.getTitle(), fd.getMode(), dirname,
                               filename, fd.getFilenameFilter(),
                               fd.isMultipleMode(), fd.getX(), fd.getY());
}
 
Example #14
Source File: ImageQuantizationDemo.java    From pumpernickel with MIT License 6 votes vote down vote up
/**
 * If invoked from within a Frame: this pulls up a FileDialog to browse for
 * a file. If this is invoked from a secure applet: then this will throw an
 * exception.
 * 
 * @param ext
 *            an optional list of extensions
 * @return a File, or null if the user declined to select anything.
 */
public File browseForFile(String... ext) {
	Window w = SwingUtilities.getWindowAncestor(this);
	if (!(w instanceof Frame))
		throw new IllegalStateException();
	Frame frame = (Frame) w;
	FileDialog fd = new FileDialog(frame);
	if (ext != null && ext.length > 0
			&& (!(ext.length == 1 && ext[0] == null)))
		fd.setFilenameFilter(new SuffixFilenameFilter(ext));
	fd.pack();
	fd.setLocationRelativeTo(null);
	fd.setVisible(true);
	String d = fd.getFile();
	if (d == null)
		return null;
	return new File(fd.getDirectory() + fd.getFile());
}
 
Example #15
Source File: FileDialogForPackages.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@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 #16
Source File: FileDialogForDirectories.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@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.fileDialogForDirectories", "true");

    setLayout(new GridLayout(1, 1));

    fd = new FileDialog(new Frame(), "Open");

    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) Check that files can't be selected.",
            "3) Check that directories can be selected.",
            "4) Repeat steps 1 - 3 a few times for different files and directories.",
            "5) If it's true then the test passed, otherwise it failed."};
    Sysout.createDialogWithInstructions(instructions);
}
 
Example #17
Source File: FileDialogForDirectories.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@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.fileDialogForDirectories", "true");

    setLayout(new GridLayout(1, 1));

    fd = new FileDialog(new Frame(), "Open");

    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) Check that files can't be selected.",
            "3) Check that directories can be selected.",
            "4) Repeat steps 1 - 3 a few times for different files and directories.",
            "5) If it's true then the test passed, otherwise it failed."};
    Sysout.createDialogWithInstructions(instructions);
}
 
Example #18
Source File: FileDialogForPackages.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@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 #19
Source File: AudioPlayerUI.java    From pumpernickel with MIT License 6 votes vote down vote up
public void doBrowseForFile(AudioPlayerComponent apc) {
	Window w = SwingUtilities.getWindowAncestor(apc);
	if (!(w instanceof Frame))
		throw new RuntimeException(
				"cannot invoke a FileDialog if the player is not in a java.awt.Frame");
	// the button shouldn't be enabled if w isn't a Frame...
	Frame f = (Frame) w;
	FileDialog fd = new FileDialog(f);
	fd.pack();
	fd.setLocationRelativeTo(null);
	fd.setVisible(true);

	if (fd.getFile() == null)
		throw new UserCancelledException();
	File file = new File(fd.getDirectory() + fd.getFile());
	try {
		apc.setSource(file.toURI().toURL());
	} catch (MalformedURLException e) {
		e.printStackTrace();
		apc.setSource(null);
	}
}
 
Example #20
Source File: GtkFileDialogPeer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void showNativeDialog() {
    String dirname = fd.getDirectory();
    // File path has a priority against directory path.
    String filename = fd.getFile();
    if (filename != null) {
        final File file = new File(filename);
        if (fd.getMode() == FileDialog.LOAD
            && dirname != null
            && file.getParent() == null) {
            // File path for gtk_file_chooser_set_filename.
            filename = dirname + (dirname.endsWith(File.separator) ? "" :
                                          File.separator) + filename;
        }
        if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
            // Filename for gtk_file_chooser_set_current_name.
            filename = file.getName();
            // Directory path for gtk_file_chooser_set_current_folder.
            dirname = file.getParent();
        }
    }
    run(fd.getTitle(), fd.getMode(), dirname, filename,
        fd.getFilenameFilter(), fd.isMultipleMode(), fd.getX(), fd.getY());
}
 
Example #21
Source File: GtkFileDialogPeer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void showNativeDialog() {
    String dirname = fd.getDirectory();
    // File path has a priority against directory path.
    String filename = fd.getFile();
    if (filename != null) {
        final File file = new File(filename);
        if (fd.getMode() == FileDialog.LOAD
            && dirname != null
            && file.getParent() == null) {
            // File path for gtk_file_chooser_set_filename.
            filename = dirname + (dirname.endsWith(File.separator) ? "" :
                                          File.separator) + filename;
        }
        if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
            // Filename for gtk_file_chooser_set_current_name.
            filename = file.getName();
            // Directory path for gtk_file_chooser_set_current_folder.
            dirname = file.getParent();
        }
    }
    run(fd.getTitle(), fd.getMode(), dirname, filename,
        fd.getFilenameFilter(), fd.isMultipleMode(), fd.getX(), fd.getY());
}
 
Example #22
Source File: FileDialogForDirectories.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@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.fileDialogForDirectories", "true");

    setLayout(new GridLayout(1, 1));

    fd = new FileDialog(new Frame(), "Open");

    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) Check that files can't be selected.",
            "3) Check that directories can be selected.",
            "4) Repeat steps 1 - 3 a few times for different files and directories.",
            "5) If it's true then the test passed, otherwise it failed."};
    Sysout.createDialogWithInstructions(instructions);
}
 
Example #23
Source File: FileDialogForPackages.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@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 #24
Source File: GtkFileDialogPeer.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void showNativeDialog() {
    String dirname = fd.getDirectory();
    // File path has a priority against directory path.
    String filename = fd.getFile();
    if (filename != null) {
        final File file = new File(filename);
        if (fd.getMode() == FileDialog.LOAD
            && dirname != null
            && file.getParent() == null) {
            // File path for gtk_file_chooser_set_filename.
            filename = dirname + (dirname.endsWith(File.separator) ? "" :
                                          File.separator) + filename;
        }
        if (fd.getMode() == FileDialog.SAVE && file.getParent() != null) {
            // Filename for gtk_file_chooser_set_current_name.
            filename = file.getName();
            // Directory path for gtk_file_chooser_set_current_folder.
            dirname = file.getParent();
        }
    }
    if (!quit) {
        run(fd.getTitle(), fd.getMode(), dirname, filename,
                fd.getFilenameFilter(), fd.isMultipleMode(), fd.getX(), fd.getY());
    }
}
 
Example #25
Source File: SuitePanel.java    From EchoSim with Apache License 2.0 6 votes vote down vote up
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 #26
Source File: FileDialogForPackages.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@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 #27
Source File: ApplicationPanel.java    From EchoSim with Apache License 2.0 6 votes vote down vote up
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 #28
Source File: ApplicationPanel.java    From EchoSim with Apache License 2.0 6 votes vote down vote up
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 #29
Source File: FileChooserBuilder.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Show an open dialog with a file chooser set up according to the
 * parameters of this builder.
 * @return A file if the user clicks the accept button and a file or
 * folder was selected at the time the user clicked cancel.
 */
public File showOpenDialog() {
    JFileChooser chooser = createFileChooser();
    if( Boolean.getBoolean("nb.native.filechooser") ) { //NOI18N
        FileDialog fileDialog = createFileDialog( chooser.getCurrentDirectory() );
        if( null != fileDialog ) {
            return showFileDialog(fileDialog, FileDialog.LOAD );
        }
    }
    chooser.setMultiSelectionEnabled(false);
    int dlgResult = chooser.showOpenDialog(findDialogParent());
    if (JFileChooser.APPROVE_OPTION == dlgResult) {
        File result = chooser.getSelectedFile();
        if (result != null && !result.exists()) {
            result = null;
        }
        return result;
    } else {
        return null;
    }

}
 
Example #30
Source File: StateSpaceLoader.java    From PIPE with MIT License 6 votes vote down vote up
/**
 * Opens the file dialog and saves the selected Petri net into lastLoadedPetriNet
 * for use when calculating the state space exploration
 */
private void loadData() {
    loadDialog.setMode(FileDialog.LOAD);
    loadDialog.setTitle("Select petri net");
    loadDialog.setVisible(true);

    File[] files = loadDialog.getFiles();
    if (files.length > 0) {
        File path = files[0];
        try {
            petriNetNameLabel.setText(path.getName());
            PetriNetReader petriNetIO = new PetriNetIOImpl();
            lastLoadedPetriNet = petriNetIO.read(path.getAbsolutePath());
        } catch (JAXBException | FileNotFoundException e) {
            LOGGER.log(Level.SEVERE, e.getMessage());
        }
    }
}