Java 类java.awt.FileDialog 实例源码

项目:incubator-netbeans    文件:FileChooserBuilder.java   
private File showFileDialog( FileDialog fileDialog, int mode ) {
    String oldFileDialogProp = System.getProperty("apple.awt.fileDialogForDirectories"); //NOI18N
    if( dirsOnly ) {
        System.setProperty("apple.awt.fileDialogForDirectories", "true"); //NOI18N
    }
    fileDialog.setMode( mode );
    fileDialog.setVisible(true);
    if( dirsOnly ) {
        if( null != oldFileDialogProp ) {
            System.setProperty("apple.awt.fileDialogForDirectories", oldFileDialogProp); //NOI18N
        } else {
            System.clearProperty("apple.awt.fileDialogForDirectories"); //NOI18N
        }
    }
    if( fileDialog.getDirectory() != null && fileDialog.getFile() != null ) {
        String selFile = fileDialog.getFile();
        File dir = new File( fileDialog.getDirectory() );
        return new File( dir, selFile );
    }
    return null;
}
项目:incubator-netbeans    文件:FileChooserBuilder.java   
/**
 * 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;
    }

}
项目:incubator-netbeans    文件:FileChooserBuilder.java   
/**
 * Show a save dialog with the 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 showSaveDialog() {
    JFileChooser chooser = createFileChooser();
    if( Boolean.getBoolean("nb.native.filechooser") ) { //NOI18N
        FileDialog fileDialog = createFileDialog( chooser.getCurrentDirectory() );
        if( null != fileDialog ) {
            return showFileDialog( fileDialog, FileDialog.SAVE );
        }
    }
    int result = chooser.showSaveDialog(findDialogParent());
    if (JFileChooser.APPROVE_OPTION == result) {
        return chooser.getSelectedFile();
    } else {
        return null;
    }
}
项目:incubator-netbeans    文件:FileChooserBuilder.java   
private FileDialog createFileDialog( File currentDirectory ) {
    if( badger != null )
        return null;
    if( !Boolean.getBoolean("nb.native.filechooser") )
        return null;
    if( dirsOnly && !BaseUtilities.isMac() )
        return null;
    Component parentComponent = findDialogParent();
    Frame parentFrame = (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parentComponent);
    FileDialog fileDialog = new FileDialog(parentFrame);
    if (title != null) {
        fileDialog.setTitle(title);
    }
    if( null != currentDirectory )
        fileDialog.setDirectory(currentDirectory.getAbsolutePath());
    return fileDialog;
}
项目:VASSAL-src    文件:FileChooser.java   
public int showOpenDialog(Component parent) {
  final FileDialog fd = awt_file_dialog_init(parent);
  fd.setMode(FileDialog.LOAD);
  System.setProperty("apple.awt.fileDialogForDirectories",
                     String.valueOf(mode == DIRECTORIES_ONLY));
  fd.setVisible(true);

  final int value;
  if (fd.getFile() != null) {
    cur = new File(fd.getDirectory(), fd.getFile());
    value = FileChooser.APPROVE_OPTION;
  }
  else {
    value = FileChooser.CANCEL_OPTION;
  }
  updateDirectoryPreference();
  return value;
}
项目:VASSAL-src    文件:FileChooser.java   
public int showSaveDialog(Component parent) {
  final FileDialog fd = awt_file_dialog_init(parent);
  fd.setMode(FileDialog.SAVE);
  fd.setVisible(true);

  final int value;
  if (fd.getFile() != null) {
    cur = new File(fd.getDirectory(), fd.getFile());
    value = FileChooser.APPROVE_OPTION;
  }
  else {
    value = FileChooser.CANCEL_OPTION;
  }
  updateDirectoryPreference();
  return value;
}
项目:vexillo    文件:ExportMenuItem.java   
public ExportMenuItem(final FlagFrame frame) {
    setText("Export...");
    if (!OSUtils.isMacOS()) setMnemonic(KeyEvent.VK_E);
    setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputUtils.META_MASK));
    if (frame == null) {
        setEnabled(false);
    } else {
        addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                FileDialog fd = new FileDialog(frame, "Export", FileDialog.SAVE);
                fd.setVisible(true);
                if (fd.getDirectory() == null || fd.getFile() == null) return;
                File file = new File(fd.getDirectory(), fd.getFile());
                new ExportDialog(
                    frame, frame.getParentFile(), frame.getFlag(), file,
                    frame.getViewerWidth(), frame.getViewerHeight(), frame.getGlaze()
                ).setVisible(true);
            }
        });
    }
}
项目:vexillo    文件:OpenMenuItem.java   
public OpenMenuItem() {
    setText("Open...");
    if (!OSUtils.isMacOS()) setMnemonic(KeyEvent.VK_O);
    setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputUtils.META_MASK));
    addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            FileDialog fd = new FileDialog(new Frame(), "Open", FileDialog.LOAD);
            fd.setVisible(true);
            if (fd.getDirectory() == null || fd.getFile() == null) return;
            File file = new File(fd.getDirectory(), fd.getFile());
            try {
                FileInputStream in = new FileInputStream(file);
                Flag flag = FlagParser.parse(file.getName(), in);
                in.close();
                String title = file.getName();
                if (flag.getName() != null) title += ": " + flag.getName();
                FlagFrame frame = new FlagFrame(title, file, flag);
                frame.setVisible(true);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Error: " + e.getMessage(), "Open", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
}
项目:OpenJSharp    文件:GtkFileDialogPeer.java   
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());
}
项目:jdk8u-jdk    文件:GtkFileDialogPeer.java   
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());
}
项目:jdk8u-jdk    文件:FileDialogForPackages.java   
@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);
}
项目:jdk8u-jdk    文件:FileDialogForDirectories.java   
@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);
}
项目:openjdk-jdk10    文件:GtkFileDialogPeer.java   
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());
    }
}
项目:openjdk-jdk10    文件:FileDialogForPackages.java   
@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);
}
项目:openjdk-jdk10    文件:FileDialogForDirectories.java   
@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);
}
项目:myster    文件:DownloaderThread.java   
private static String[] askUser(ProgressWindow progress, String dp, String initialFileName, String a) {
    String ask = (a == null ? "What do you want to call this file?" : a);

    String[] s = new String[2];
    FileDialog dialog = new FileDialog(progress, ask, FileDialog.SAVE);
    dialog.setSize(400, 300);

    dialog.setDirectory(dp);
    dialog.setFile(initialFileName);
    dialog.show();
    String temppath = dialog.getDirectory();
    String chosenFileName = dialog.getFile();
    if (chosenFileName == null) {
        progress.setText("User Cancelled", FileProgressWindow.BAR_1);
        return null;
    }
    s[0] = temppath;
    s[1] = chosenFileName;

    return s;
}
项目:openjdk9    文件:GtkFileDialogPeer.java   
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());
    }
}
项目:openjdk9    文件:FileDialogForPackages.java   
@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);
}
项目:openjdk9    文件:FileDialogForDirectories.java   
@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);
}
项目:MySnakeGame    文件:SnakeGameFrame.java   
public void actionPerformed(ActionEvent event) {
    FileDialog dialog = new FileDialog(SnakeGameFrame.this, "Open",
            FileDialog.LOAD);
    dialog.setVisible(true);
    String dir = dialog.getDirectory();
    String fileName = dialog.getFile();
    String filePath = dir + fileName;

    if (fileName != null && fileName.trim().length() != 0) {
        File file = new File(filePath);
        panel.loadGameDataFromFile(file);
        startMI.setEnabled(false);
        pauseMI.setEnabled(true);
    } else {
        JOptionPane.showConfirmDialog(SnakeGameFrame.this,
                "�ļ���Ϊ��\nװ����Ϸ����ʧ��", "̰������Ϸ", JOptionPane.DEFAULT_OPTION);
    }

}
项目:MySnakeGame    文件:SnakeGameFrame.java   
public void actionPerformed(ActionEvent event) {
    if (panel.getGameState() == GameState.INITIALIZE) {
        JOptionPane.showConfirmDialog(SnakeGameFrame.this,
                        "��Ϸû������\n���ܱ�����Ϸ����", "̰������Ϸ",
                        JOptionPane.DEFAULT_OPTION);
        return;
    }

    FileDialog dialog = new FileDialog(SnakeGameFrame.this, "Save",FileDialog.SAVE);
    dialog.setVisible(true);
    String dir = dialog.getDirectory();
    String fileName = dialog.getFile();//��ȡ����������������ġ�Ҫ������ļ�����
    String filePath = dir + fileName;
    if (fileName != null && fileName.trim().length() != 0) {
        File file = new File(filePath);
        panel.saveGameDataToFile(file);
    } else {
        JOptionPane.showConfirmDialog(SnakeGameFrame.this,
                "�ļ���Ϊ��\n������Ϸ����ʧ��", "̰������Ϸ", JOptionPane.DEFAULT_OPTION);
    }

}
项目:pumpernickel    文件:FileDialogUtils.java   
public static File showSaveDialog(Frame f,String title,String extension) {
    if(extension.startsWith("."))
        extension = extension.substring(1);

    FileDialog fd = new FileDialog(f, title);
    fd.setMode(FileDialog.SAVE);
    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);
    }

    return new File(fd.getDirectory() + fd.getFile()+"."+extension);
}
项目:pumpernickel    文件:AudioPlayerUI.java   
protected 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);
    }
}
项目:pumpernickel    文件:ScreenCaptureDemo.java   
protected File showSaveDialog() {
    FileDialog fd = new FileDialog(frame);
    fd.setMode(FileDialog.SAVE);
    fd.setFilenameFilter(new SuffixFilenameFilter("mov"));
    fd.setTitle("Save MOV File");
    fd.pack();
    fd.setLocationRelativeTo(frame);
    fd.setVisible(true);
    if(fd.getFile()==null)
        throw new UserCancelledException();
    String filepath = fd.getDirectory() + fd.getFile();
    if(!filepath.toLowerCase().endsWith(".mov")) {
        filepath += ".mov";
    }
    return new File(filepath);
}
项目:pumpernickel    文件:ImageQuantizationDemo.java   
/** 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());
}
项目:pumpernickel    文件:FileIcon.java   
/** This captures a File's icon and saves it as a PNG.
 * This is tested on Mac; I'm not sure how it will perform
 * on Windows. You may need to modify the icon size. As of this
 * writing on Mac: you can pass most any Dimension object and
 * the icon will scale upwards safely.
 */
public static void main(String[] args) throws IOException {
    FileDialog fd = new FileDialog(new Frame());
    fd.pack();
    fd.setVisible(true);
    File f = new File(fd.getDirectory()+fd.getFile());
    Icon icon = getIcon(f);
    icon = new ScaledIcon(icon, 24, 24);
    BufferedImage bi = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = bi.createGraphics();
    icon.paintIcon(null, g, 0, 0);
    g.dispose();
    File f2 = new File(f.getParentFile(), f.getName()+".png");
    if(f2.exists())
        System.exit(1);
    ImageIO.write(bi, "png", f2);
    System.exit(0);;
}
项目:pumpernickel    文件:JarWriterApp.java   
public void loadJar() throws IOException {
    FileDialog fd = new FileDialog(new Frame());
    fd.setFilenameFilter(new SuffixFilenameFilter("jar"));
    fd.pack();
    fd.setVisible(true);
    if(fd.getFile()==null) return;
    File jarFile = new File(fd.getDirectory()+fd.getFile());
    try(ZipFile zf = new ZipFile(jarFile)) {
        try(InputStream in = zf.getInputStream(new ZipEntry(KEY_SETUP_ENTRY))) {
            if(in==null) throw new IOException("This jar does not appear to be built with a recent version of JarWriterApp.");
            ContainerProperties p = new ContainerProperties();
            p.load(in);
            p.install(getContentPane(), null);
        }
        zf.close();
    }
}
项目:pumpernickel    文件:KeyStoreEditor.java   
public static KeyStoreEditor create(Frame parentWindow) {
    KeyStoreEditor editor = new KeyStoreEditor();
    String dialogTitle = "Create Keystore";
    Icon icon = QDialog.getIcon(QDialog.PLAIN_MESSAGE);
    QDialog.showDialog(parentWindow, dialogTitle, icon, editor, editor.footer, true, null, null);
    JComponent button = editor.footer.getLastSelectedComponent();
    if( button==editor.footer.getButton(DialogFooter.OK_OPTION) ) {
        FileDialog fd = new FileDialog(parentWindow, "Create Keystore", FileDialog.SAVE);
        fd.setFilenameFilter(new SuffixFilenameFilter("jks"));
        fd.setFile("keystore.jks");
        fd.pack();
        fd.setLocationRelativeTo(null);
        fd.setVisible(true);
        if(fd.getFile()==null)
            return null;
        editor.jksFile = new File(fd.getDirectory()+fd.getFile());
        editor.create(false);
        return editor;
    } else {
        return null;
    }
}
项目:pumpernickel    文件:WavCopier.java   
@SuppressWarnings("unused")
private static void main(String[] s) {
    try {
        JFrame frame = new JFrame();
        FileDialog fd = new FileDialog(frame);
        fd.setFilenameFilter(new SuffixFilenameFilter("wav", "wave"));
        fd.pack();
        fd.setVisible(true);
        if(fd.getFile()==null) return;
        File wavFile = new File(fd.getDirectory()+fd.getFile());
        FileInputStream in = null;
        try {
            in = new FileInputStream(wavFile);
            System.err.println("length: " + wavFile.length());
            WavCopier r = new WavCopier(in);
        } finally {
            in.close();
        }
        System.exit(0);
    } catch(IOException e) {
        e.printStackTrace();
        System.exit(1);
    }
}
项目:jdk8u_jdk    文件:GtkFileDialogPeer.java   
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());
}
项目:jdk8u_jdk    文件:FileDialogForPackages.java   
@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);
}
项目:jdk8u_jdk    文件:FileDialogForDirectories.java   
@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);
}
项目:JHelioviewer-SWHV    文件:OpenLocalFileAction.java   
@Override
public void actionPerformed(ActionEvent e) {
    FileDialog fileDialog = new FileDialog(ImageViewerGui.getMainFrame(), "Choose a file", FileDialog.LOAD);
    // does not work on Windows
    fileDialog.setFilenameFilter(new AllFilenameFilter());
    fileDialog.setMultipleMode(true);
    fileDialog.setDirectory(Settings.getSingletonInstance().getProperty("default.local.path"));
    fileDialog.setVisible(true);

    String directory = fileDialog.getDirectory();
    File[] fileNames = fileDialog.getFiles();
    if (fileNames.length > 0 && directory != null) {
        // remember the current directory for future
        Settings.getSingletonInstance().setProperty("default.local.path", directory);
        Settings.getSingletonInstance().save("default.local.path");
        for (File fileName : fileNames) {
            if (fileName.isFile())
                Load.image.get(fileName.toURI());
        }
    }
}
项目:JHelioviewer-SWHV    文件:OpenLocalFileAction.java   
@Override
public void actionPerformed(ActionEvent e) {
    FileDialog fileDialog = new FileDialog(ImageViewerGui.getMainFrame(), "Choose a file", FileDialog.LOAD);
    // does not work on Windows
    fileDialog.setFilenameFilter(new JsonFilenameFilter());
    fileDialog.setMultipleMode(true);
    fileDialog.setDirectory(Settings.getSingletonInstance().getProperty("default.local.path"));
    fileDialog.setVisible(true);

    String directory = fileDialog.getDirectory();
    File[] fileNames = fileDialog.getFiles();
    if (fileNames.length > 0 && directory != null) {
        // remember the current directory for future
        Settings.getSingletonInstance().setProperty("default.local.path", directory);
        Settings.getSingletonInstance().save("default.local.path");
        for (File fileName : fileNames) {
            if (fileName.isFile())
                Load.timeline.get(fileName.toURI());
        }
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:GtkFileDialogPeer.java   
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());
}
项目:lookaside_java-1.8.0-openjdk    文件:FileDialogForPackages.java   
@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);
}
项目:lookaside_java-1.8.0-openjdk    文件:FileDialogForDirectories.java   
@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);
}
项目:JavaCL    文件:Utils.java   
public static File chooseFile(File initialFile, boolean load) {
    if (isMac()) {
        FileDialog d = new FileDialog((java.awt.Frame)null);
        d.setMode(load ? FileDialog.LOAD : FileDialog.SAVE);
           if (initialFile != null) {
               d.setDirectory(initialFile.getParent());
               d.setFile(initialFile.getName());
           }
        d.show();
        String f = d.getFile();
        if (f != null)
            return new File(new File(d.getDirectory()), d.getFile());
    } else {
        JFileChooser chooser = new JFileChooser();
           if (initialFile != null)
               chooser.setSelectedFile(initialFile);
        if ((load ? chooser.showOpenDialog(null) : chooser.showSaveDialog(null)) == JFileChooser.APPROVE_OPTION)
                return chooser.getSelectedFile();
    }
       return null;
}
项目:stickes    文件:Files.java   
void loadDialog() {
    FileDialog fd = new FileDialog(visual.frame, "Choose a file", FileDialog.LOAD);
    fd.setFilenameFilter(sf.getLoadFilenameFilter());
    fd.setFile("*");
    fd.setVisible(true);
    if (fd.getFiles().length == 0) {
        return;
    }
    File f = fd.getFiles()[0];
    try {
        if (f.exists()) {
            importFile(f);
            visual.init(2);
        } else {
            JOptionPane.showMessageDialog(visual.frame, f.getName() + " does not exist");
        }
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(visual.frame, "error loading " + f.getName() + ": " + ex);
    }
}
项目:stickes    文件:Files.java   
void saveDialog(String text) {
    try {
        FileDialog fd = new FileDialog(visual.frame, text, FileDialog.SAVE);
        fd.setFilenameFilter(sf.getSaveFilenameFilter());
        fd.setVisible(true);
        if (fd.getFiles().length == 0) {
            return;
        }
        sf.save(fd.getFiles()[0], visual.getStichData());

    } catch (Exception ex) {
        JOptionPane.showMessageDialog(visual.frame, "error during save: " + ex.getMessage());
        Logger
                .getLogger(Visual.class
                        .getName()).log(Level.SEVERE, null, ex);
    }
}