Java 8 FileDialog - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 FileDialog class.

This code example shows how to use the following methods:show, getDirectory, getFile, setMode
import java.awt.FileDialog;
public class SobelFilterDemo { 
 
	static File chooseFile() {
		if (Platform.isMac()) { 
			FileDialog d = new FileDialog((java.awt.Frame)null);
			d.setMode(FileDialog.LOAD);
			d.show();
			String f = d.getFile();
			if (f != null)
				return new File(new File(d.getDirectory()), d.getFile());
		} else { 
	        JFileChooser chooser = new JFileChooser();
	        if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
	        	return chooser.getSelectedFile();
		} 
        return null; 
	} 
     public static void main(String[] args) {
        try { 
7
CodeRank
This code example shows how to use the following methods:getToolkit
    verify(windows).markAsShowing(window);
  } 
 
  @Test
  public void shouldProcessEventWithIdEqualToWindowOpenedAndMarkWindowAsReadyIfWindowIsFileDialog() { 
    Window w = new FileDialog(window);
    when(context.storedQueueFor(w)).thenReturn(w.getToolkit().getSystemEventQueue());
    monitor.eventDispatched(new ComponentEvent(w, WINDOW_OPENED));
    verify(context).addContextFor(w);
    verify(windows).attachNewWindowVisibilityMonitor(w);
    verify(windows).markAsShowing(w);
    verify(windows).markAsReady(w);
  } 
 
  @Test
  public void shouldProcessEventWithIdEqualToWindowClosedAndWithRootWindow() { 
    when(context.storedQueueFor(window)).thenReturn(window.getToolkit().getSystemEventQueue());
    monitor.eventDispatched(new ComponentEvent(window, WINDOW_CLOSED));
    verify(context).removeContextFor(window);
    verify(windows).markAsClosed(window);
7
CodeRank
This code example shows how to use the following methods:getDirectory, getFile, setDirectory, setFile
		open(title, path, null);
	} 
 
	void open(String title, String path, String fileName) {
		dialog = new FileDialog((Frame) LSystem.getSystemHandler()
				.getWindow(), title);
		if (path != null) {
			dialog.setDirectory(path);
		} 
		if (fileName != null) {
			dialog.setFile(fileName);
		} 
		fileName = dialog.getFile();
		if (fileName == null) {
			if (LSystem.isMacOS()) { 
				System.setProperty("apple.awt.fileDialogForDirectories",
						"false"); 
			} 
		} else { 
			dirName = dialog.getDirectory();

6
CodeRank
This code example shows how to use the following methods:setVisible, getDirectory, getFile
    } 
 
    public static void saveToFile(final String saveDialogTitle, final String title, final String text) {
        final Frame parent = new Frame();
 
        final FileDialog dialog = new FileDialog(parent, saveDialogTitle, FileDialog.SAVE);
        dialog.setVisible(true);
        final String file = dialog.getFile();
        final String dir = dialog.getDirectory();
 
        parent.dispose();
 
        saveToFile(new File(dir, file), title, text);
    } 
} 
6
CodeRank
This code example shows how to use the following methods:setVisible, getDirectory, getFile
File file = null;
 
			if(args.length == 0)
			{ 
				FileDialog dialog = new FileDialog(new Frame(), "Select file...", FileDialog.LOAD);
				dialog.setVisible(true);
 
				String d = dialog.getDirectory();
				String f = dialog.getFile();
 
				if(d != null && f != null)
				{ 
					args = new String[] { d + f };
				} 
				else 
				{ 
					System.out.println("No file selected... Bye!");
					System.exit(0);
				} 
6
CodeRank
This code example shows how to use the following methods:show, getDirectory, getFile, setFile
    * 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());                
        } 
         
    } 
     
    /** 
     * Write the score to outputStream as a standard MIDI file 
     * @param Score 
     * @param OutputStream outputStream 
6
CodeRank
This code example shows how to use the following methods:setVisible, getDirectory, getFile, setDirectory, setFilenameFilter
        FileDialog fileDialog;
        if (parent instanceof Frame) {
            fileDialog = new FileDialog((Frame) parent, title, FileDialog.LOAD);
        } 
        else { 
            fileDialog = new FileDialog((Dialog) parent, title, FileDialog.LOAD);
        } 
        fileDialog.setFilenameFilter(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                if (extensions.isEmpty()) {
                    return true; 
                } 
                else { 
                    for (String ext : extensions) {
                        if (name.toLowerCase().endsWith(ext.toLowerCase())) {
                            return true; 
                        } 
                    } 
                    return false; 
                } 

5
CodeRank
This code example shows how to use the following methods:show, getDirectory, getFile
		System.out.println("rShowMessage \"" + message + "\"");
	} 
 
	@Override 
	public String rChooseFile(Rengine re, int newFile) {
		FileDialog fd = new FileDialog(new Frame(), (newFile == 0) ? "Select a file"
				: "Select a new file", (newFile == 0) ? FileDialog.LOAD : FileDialog.SAVE);
		fd.show();
		String res = null;
		if (fd.getDirectory() != null)
			res = fd.getDirectory();
		if (fd.getFile() != null)
			res = (res == null) ? fd.getFile() : (res + fd.getFile());
		return res;
	} 
 
	@Override 
	public void rFlushConsole(Rengine re) {
	} 
 
5
CodeRank
This code example shows how to use the following methods:show, getDirectory, getFile
    * Assume the MIDI file name is the same as the score title with .mid appended 
    * prompt for a fileName 
    * @param Score 
    */  
    public static void midi(Score score) {
        FileDialog fd = new FileDialog(new Frame(), 
                                       "Select a MIDI file to open.",  
                                       FileDialog.LOAD);
        fd.show();
        if (fd.getFile() != null) {
            Read.midi(score, fd.getDirectory() + fd.getFile());                
        } 
    } 
     
    /** 
    * Import to a jMusic score a standard MIDI file 
    * @param Score 
    * @param String fileName 
    */  
    public static void midi(Score s, String fileName) {
5
CodeRank
This code example shows how to use the following methods:setTitle, setVisible, getDirectory, getFile, setFile
    } 
 
    @RequestMapping("/open") 
    @ResponseBody 
    public TextFileResult openFile() throws IOException {
        fileDialog.setTitle("Open Javascript File");
        fileDialog.setMode(FileDialog.LOAD);
        fileDialog.setFile("*.js");
        fileDialog.setVisible(true);
        if (fileDialog.getFile() != null) {
            File file = new File(fileDialog.getDirectory(), fileDialog.getFile());
            return new TextFileResult(file);
        } else { 
            throw new CanceledException("Open file operation was cancelled"); 
        } 
    } 
 
    @RequestMapping(value = "/save", method = POST) 
    @ResponseBody 
    public TextFilePathResult save(@RequestBody TextFileResult fileResult) throws IOException {
5
CodeRank
See Code Examples for Java 8 FileDialog Methods: