Java 类javax.swing.JFileChooser 实例源码

项目:incubator-netbeans    文件:TemplateSelector.java   
private void onOpen() {
    File file = selectFile(JFileChooser.OPEN_DIALOG, NbBundle.getMessage(TemplateSelector.class, "CTL_Load")); // NOI18N
    if (file == null) {
        return;
    }

    try {
        byte[] bytes = getFileContentsAsByteArray(file);
        if (bytes != null) {
            getPanel().templateTextArea.setText(new String(bytes));
        }
    } catch (IOException ex) {
        Utils.logError(TemplatesPanel.class, ex);
    }
    preferences.put(KEY_TEMPLATE_FILE, file.getAbsolutePath());
}
项目:trashjam2017    文件:SettingsPanel.java   
/**
 * Browse for a particle image and set the value into both the emitter and text field
 * on successful completion
 */
private void browseForImage() {
    if (emitter != null) {
        int resp = chooser.showOpenDialog(this);
        if (resp == JFileChooser.APPROVE_OPTION) {
            File file = chooser.getSelectedFile();
            String path = file.getParentFile().getAbsolutePath();
            String name = file.getName();

            ConfigurableEmitter.setRelativePath(path);
            emitter.setImageName(name);

            imageName.setText(name);
        }
    }
}
项目:incubator-netbeans    文件:SettingsPanel.java   
private void btnDirectoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDirectoryActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle("Select alternate directory");
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setFileHidingEnabled(false);
    String path = txtDirectory.getText();
    if (path == null || path.trim().length() == 0) {
        path = new File(System.getProperty("user.home")).getAbsolutePath(); //NOI18N
    }
    if (path.length() > 0) {
        File f = new File(path);
        if (f.exists()) {
            chooser.setSelectedFile(f);
        }
    }
    if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
        File projectDir = chooser.getSelectedFile();
        txtDirectory.setText(projectDir.getAbsolutePath());
    }

}
项目:JavaGraph    文件:SaveLTSAsDialog.java   
@Override
public void actionPerformed(ActionEvent e) {
    JFileChooser chooser = GrooveFileChooser.getInstance();
    int result = chooser.showOpenDialog(SaveLTSAsDialog.this.simulator.getFrame());
    // now load, if so required
    if (result == JFileChooser.APPROVE_OPTION) {
        SaveLTSAsDialog.this.dirField.setText(chooser.getSelectedFile().getAbsolutePath());
    }
    if (result == JFileChooser.CANCEL_OPTION) {
        // System.out.println("Cancelled");
    }
    if (result == JFileChooser.ERROR_OPTION) {
        // System.out.println("Whooops");
    }

}
项目:plain-text-archiver    文件:UserInterface.java   
/**
 * Creates a {@link JFileChooser} dialog prompting the user to select a directory or .pta file.
 * <p>
 * If a directory or .pta file is selected its details are displayed in the UI, otherwise the application is
 * terminated.
 */
private static void promptForFile() {
    // Hide the UI.
    frame.setVisible(false);

    // Prompt the user for a directory/file.
    int result = fileChooser.showDialog(frame, FILE_SELECT_LABEl);
    if (result == JFileChooser.APPROVE_OPTION) {
        // If a directory/file is chosen display its details.
        File selectedFile = fileChooser.getSelectedFile();
        if (selectedFile.isDirectory()) {
            displayDirectory(selectedFile);
        } else {
            displayArchive(selectedFile);
        }
    } else {
        // Otherwise terminate the application.
        System.exit(0);
    }
}
项目:jaer    文件:YuhuangBoundingboxDisplay.java   
synchronized public void doLoadGroundTruthFromTXT() {
    JFileChooser c = new JFileChooser(gtFilename);
    c.setDialogTitle("Choose ground truth bounding box file");
    FileFilter filt = new FileNameExtensionFilter("TXT File", "txt");
    c.addChoosableFileFilter(filt);
    c.setFileFilter(filt);
    c.setSelectedFile(new File(gtFilename));
    int ret = c.showOpenDialog(chip.getAeViewer());
    if (ret != JFileChooser.APPROVE_OPTION) {
        return;
    }
    gtFilename = c.getSelectedFile().toString();
    putString("GTFilename", gtFilename);
    gtFilenameShort = gtFilename.substring(0, 5) + "..." + gtFilename.substring(gtFilename.lastIndexOf(File.separator));
    try {
        this.loadBoundingBoxes(c.getSelectedFile());
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(chip.getAeViewer().getFilterFrame(), "Couldn't read bounding box file" + ex + ". See console for logging.", "Bad bounding box file", JOptionPane.WARNING_MESSAGE);
    }

}
项目:jaer    文件:StereoCalibrationDualViewFilter.java   
synchronized public void doSaveCalibration() {
    if (!calibrated) {
        JOptionPane.showMessageDialog(null, "No calibration yet");
        return;
    }
    JFileChooser j = new JFileChooser();
    j.setCurrentDirectory(new File(dirPath));
    j.setApproveButtonText("Select folder");
    j.setDialogTitle("Select a folder to store calibration XML files");
    j.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // let user specify a base filename
    int ret = j.showSaveDialog(null);
    if (ret != JFileChooser.APPROVE_OPTION) {
        return;
    }
    dirPath = j.getSelectedFile().getPath();
    putString("dirPath", dirPath);
    serializeMat(dirPath, "cameraMatrix", cameraMatrix);
    serializeMat(dirPath, "distortionCoefs", distortionCoefs);
    saved = true;
    generateCalibrationString();
}
项目:jaer    文件:DavisDeepLearnCnnProcessor_HJ.java   
/**
 * Loads a convolutional neural network (CNN) trained using DeapLearnToolbox
 * for Matlab (https://github.com/rasmusbergpalm/DeepLearnToolbox) that was
 * exported using Danny Neil's XML Matlab script cnntoxml.m.
 *
 */
synchronized public void doLoadApsDvsNetworkFromXML() {
    JFileChooser c = new JFileChooser(lastApsDvsNetXMLFilename);
    FileFilter filt = new FileNameExtensionFilter("XML File", "xml");
    c.addChoosableFileFilter(filt);
    c.setFileFilter(filt);
    c.setSelectedFile(new File(lastApsDvsNetXMLFilename));
    int ret = c.showOpenDialog(chip.getAeViewer());
    if (ret != JFileChooser.APPROVE_OPTION) {
        return;
    }
    lastApsDvsNetXMLFilename = c.getSelectedFile().toString();
    putString("lastAPSNetXMLFilename", lastApsDvsNetXMLFilename);
    try {
        apsDvsNet.loadFromXMLFile(c.getSelectedFile());
        dvsSubsampler = new DvsFramerSingleFrame(chip);
        dvsSubsampler.setFromNetwork(apsDvsNet);
    } catch (Exception ex) {
        Logger.getLogger(DavisDeepLearnCnnProcessor_HJ.class.getName()).log(Level.SEVERE, null, ex);
        JOptionPane.showMessageDialog(chip.getAeViewer().getFilterFrame(), "Couldn't load net from this file, caught exception " + ex + ". See console for logging.", "Bad network file", JOptionPane.WARNING_MESSAGE);
    }

}
项目:school-game    文件:DialogEditor.java   
private void loadLevel()
{
    JFileChooser chooser = new JFileChooser(lastDir == null ? PathHelper.getDialogDirIfFound() : lastDir);
    chooser.addChoosableFileFilter(filter);
    chooser.setAcceptAllFileFilterUsed(true);
    chooser.setMultiSelectionEnabled(false);

    int result = chooser.showOpenDialog(this);

    if (result == JFileChooser.APPROVE_OPTION)
    {
        saveButton.setEnabled(false);
        replaceView(createLevelPanel);
        level = null;
        File selectedFile = chooser.getSelectedFile();
        try {
            level = DialogDataHelper.getDialogRoot(selectedFile);
            lastDir = selectedFile.getParentFile();
            saveButton.setEnabled(true);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Beim Laden ist ein Fehler aufgetreten!\n" + e.getMessage(), "Fehler!", JOptionPane.OK_OPTION);
        }
        rebuildTree();
    }
}
项目:zooracle    文件:FileUtils.java   
public static String selectDirectory(Component component, String choosertitle)
{
    JFileChooser chooser = new JFileChooser(); 
    chooser.setCurrentDirectory(new java.io.File("."));
    chooser.setDialogTitle(choosertitle);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setAcceptAllFileFilterUsed(false);

    if (chooser.showOpenDialog(component) == JFileChooser.APPROVE_OPTION) { 
      System.out.println("getCurrentDirectory(): "  +  chooser.getCurrentDirectory());
      System.out.println("getSelectedFile() : "  +  chooser.getSelectedFile());
      return chooser.getSelectedFile().toString();
      }
    else {
      System.out.println("No Selection ");
      return null;
      }

}
项目:incubator-netbeans    文件:OpenFileAction.java   
/**
 * Creates and initializes a file chooser.
 *
 * @return  the initialized file chooser
 */
protected JFileChooser prepareFileChooser() {
    FileChooserBuilder fcb = new FileChooserBuilder(OpenFileAction.class);
    fcb.setSelectionApprover(new OpenFileSelectionApprover());
    fcb.setFilesOnly(true);
    fcb.addDefaultFileFilters();
    for (OpenFileDialogFilter filter :
            Lookup.getDefault().lookupAll(OpenFileDialogFilter.class)) {
        fcb.addFileFilter(filter);
    }
    JFileChooser chooser = fcb.createFileChooser();
    chooser.setMultiSelectionEnabled(true);
    chooser.getCurrentDirectory().listFiles(); //preload
    chooser.setCurrentDirectory(getCurrentDirectory());
    if (currentFileFilter != null) {
        for (FileFilter ff : chooser.getChoosableFileFilters()) {
            if (currentFileFilter.equals(ff.getDescription())) {
                chooser.setFileFilter(ff);
                break;
            }
        }
    }
    HelpCtx.setHelpIDString(chooser, getHelpCtx().getHelpID());
    return chooser;
}
项目:incubator-netbeans    文件:JFXRunPanel.java   
private void buttonWorkDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonWorkDirActionPerformed
        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(null);
        chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
        chooser.setMultiSelectionEnabled(false);

        String workDir = textFieldWorkDir.getText();
        if (workDir.equals("")) {
            workDir = FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath();
        }
        chooser.setSelectedFile(new File(workDir));
        chooser.setDialogTitle(NbBundle.getMessage(JFXRunPanel.class, "JFXConfigurationProvider_Run_Working_Directory_Browse_Title")); // NOI18N
        if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { //NOI18N
            File file = FileUtil.normalizeFile(chooser.getSelectedFile());
            textFieldWorkDir.setText(file.getAbsolutePath());
        }
}
项目:incubator-netbeans    文件:JFXIconsPanel.java   
private void nativeIconButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nativeIconButtonActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(null);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(false);
    chooser.setFileFilter(new IconFileFilter(false));
    String current = nativeIconTextField.getText();
    File lastFolder = current!=null ? getFileFromPath(current) : null;
    if (lastFolder != null) {
        chooser.setSelectedFile(lastFolder);
    } else if (lastImageFolder != null) {
        chooser.setSelectedFile(lastImageFolder);
    } else { // ???
        // workDir = FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath();
        // chooser.setSelectedFile(new File(workDir));
    }
    chooser.setDialogTitle(NbBundle.getMessage(JFXIconsPanel.class, "LBL_Select_Icon_Image")); // NOI18N
    if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
        File file = FileUtil.normalizeFile(chooser.getSelectedFile());
        String relPath = JFXProjectUtils.getRelativePath(project.getProjectDirectory(), FileUtil.toFileObject(file));
        nativeIconTextField.setText(relPath);
        lastImageFolder = file;
    }
}
项目:jaer    文件:BiasgenFrame.java   
/**
 * Shows a file dialog from which to import preferences for biases from the
 * tree.
 */
public void importPreferencesDialog() {
    JFileChooser chooser = new JFileChooser();
    XMLFileFilter filter = new XmlAedatFileFilter();

    String lastFilePath = prefs.get("BiasgenFrame.lastFile", defaultFolder);
    lastFile = new File(lastFilePath);
    chooser.setFileFilter(filter);
    chooser.setCurrentDirectory(lastFile);
    int retValue = chooser.showOpenDialog(this);
    if (retValue == JFileChooser.APPROVE_OPTION) {
        try {
            lastFile = chooser.getSelectedFile();
            importPreferencesFromFile(lastFile);
        } catch (Exception fnf) {
            log.warning(fnf.toString());
        }
    }
    //        resend(); // shouldn't be necessary with the batch edit start/end in biasgen.importPreferences
}
项目:zooracle    文件:FileUtils.java   
public static String saveFile(Component component, String choosertitle, String startDirectory)
{
    JFileChooser chooser = new JFileChooser(); 
    chooser.setCurrentDirectory(new java.io.File(startDirectory!=null?".":startDirectory));
    chooser.setDialogTitle(choosertitle);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setAcceptAllFileFilterUsed(false);

    if (chooser.showSaveDialog(component) == JFileChooser.APPROVE_OPTION) { 
        System.out.println("getCurrentDirectory(): "  +  chooser.getCurrentDirectory());
        System.out.println("getSelectedFile() : "  +  chooser.getSelectedFile());
        return chooser.getSelectedFile().toString();
    }
    else {
        System.out.println("No Selection ");
        return null;
    }

}
项目:formatter    文件:FormatUtil.java   
/**
* 
* @Title: openFile 
* @Description: open file to get file content 
* @param @param parent
* @param @param fc
* @param @return 
* @return String
* @throws
 */
public static String openFile(Component parent, JFileChooser fc)
{
    String content = StringUtils.EMPTY;
    int retVal = fc.showOpenDialog(parent);
    if (JFileChooser.APPROVE_OPTION != retVal)
    {
        return content;
    }

    try
    {
        File sf = fc.getSelectedFile();
        content = FileUtils.readFileToString(sf, Charsets.UTF_8.getCname());
    }
    catch(IOException e)
    {
        FormatView.getView().getStat().setText("Failed to read file: " + e.getMessage());
    }

    return content;
}
项目:incubator-netbeans    文件:ExportSnapshotAction.java   
private static JFileChooser createFileChooser() {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setDialogTitle(Bundle.ExportSnapshotAction_FileChooserCaption());
    fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
    fileChooser.setApproveButtonText(Bundle.ExportSnapshotAction_ExportButtonText());
    fileChooser.removeChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
    fileChooser.addChoosableFileFilter(new FileFilter() {
        public boolean accept(File f) {
            return f.isDirectory() || f.getName().toLowerCase().endsWith(NPSS_EXT);
        }
        public String getDescription() {
            return Bundle.ExportSnapshotAction_NpssFileFilter(NPSS_EXT);
        }
    });
    return fileChooser;
}
项目:incubator-netbeans    文件:EditClusterPanel.java   
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
    JFileChooser chooser = new JFileChooser(ModuleUISettings.getDefault().getLastUsedClusterLocation());
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int ret = chooser.showOpenDialog(this);
    if (ret == JFileChooser.APPROVE_OPTION) {
        File file = FileUtil.normalizeFile(chooser.getSelectedFile());
        AGAIN: for (;;) {
            if (! file.exists() || file.isFile() || ! ClusterUtils.isValidCluster(file)) {
                if (Clusterize.clusterize(prj, file)) {
                    continue AGAIN;
                }
            } else {
                ModuleUISettings.getDefault().setLastUsedClusterLocation(file.getParentFile().getAbsolutePath());
                String relPath = PropertyUtils.relativizeFile(prjDir, file);
                clusterDirText.setText(relPath != null ? relPath : file.getAbsolutePath());
            }
            break;
        }
    }
}
项目:incubator-netbeans    文件:ConfigurationLinuxPanel.java   
private void certBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_certBrowseButtonActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setFileHidingEnabled(false);
    String text = UiUtils.getValue(certTextField);
    if (text != null) {
        chooser.setSelectedFile(new File(text));
    }
    if (chooser.showOpenDialog(SwingUtilities.getWindowAncestor(this)) == JFileChooser.APPROVE_OPTION) {
        certTextField.setText(chooser.getSelectedFile().getAbsolutePath());
    }
}
项目:incubator-netbeans    文件:PanelProjectLocationVisual.java   
private void browseLocationAction(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseLocationAction
    String command = evt.getActionCommand();

    if ("BROWSE".equals(command)) { //NOI18N
        JFileChooser chooser = new JFileChooser();
        chooser.setDialogTitle(NbBundle.getMessage(PanelProjectLocationVisual.class,"LBL_NWP1_SelectProjectLocation")); //NOI18N
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        String path = projectLocationTextField.getText();
        if (path.length() > 0) {
            File f = new File(path);
            if (f.exists())
                chooser.setSelectedFile(f);
        }
        if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
            File projectDir = chooser.getSelectedFile();
            projectLocationTextField.setText(projectDir.getAbsolutePath());
        }            
        panel.fireChangeEvent();
    }
}
项目:incubator-netbeans    文件:ApisupportAntUIUtils.java   
public static Project chooseProject(Component parent) {
    JFileChooser chooser = ProjectChooser.projectChooser();
    int option = chooser.showOpenDialog(parent);
    Project project = null;
    if (option == JFileChooser.APPROVE_OPTION) {
        File projectDir = chooser.getSelectedFile();
        ApisupportAntUIUtils.setProjectChooserDirParent(projectDir);
        try {
            project = ProjectManager.getDefault().findProject(
                    FileUtil.toFileObject(projectDir));
        } catch (IOException e) {
            ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
        }
    }
    return project;
}
项目:incubator-netbeans    文件:BasicProjectInfoPanel.java   
private void browseProjectFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseProjectFolderActionPerformed
    JFileChooser chooser = new JFileChooser();
    FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
    chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
    if (projectFolder.getText().length() > 0 && getProjectFolder().exists()) {
        chooser.setSelectedFile(getProjectFolder());
    } else if (projectLocation.getText().length() > 0 && getProjectLocation().exists()) {
        chooser.setSelectedFile(getProjectLocation());
    } else {
        chooser.setSelectedFile(ProjectChooser.getProjectsFolder());
    }
    chooser.setDialogTitle(NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_Browse_Project_Folder"));  //NOI18N
    if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
        File projectDir = FileUtil.normalizeFile(chooser.getSelectedFile());
        projectFolder.setText(projectDir.getAbsolutePath());
    }                    
}
项目:ObsidianSuite    文件:FileChooser.java   
private static File getFile(Component parentComponent, File parentDirectory, FileNameExtensionFilter fileExtensionFilter, int fileSelectionMode, boolean saveDialog, String suggestedFileName) throws FileNotChosenException
{
    File file = null;

    if(parentDirectory != null)
        fc.setCurrentDirectory(parentDirectory);

    fc.setSelectedFile(suggestedFileName != null ? new File(suggestedFileName) : new File(""));         
    fc.setFileFilter(fileExtensionFilter);
    fc.setFileSelectionMode(fileSelectionMode);

    int returnVal;
    if(saveDialog)
        returnVal = fc.showSaveDialog(parentComponent);
    else
        returnVal = fc.showOpenDialog(parentComponent);

    if (returnVal == JFileChooser.APPROVE_OPTION) 
        file = fc.getSelectedFile();
    else
        throw new FileNotChosenException();

    return file;
}
项目: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;
    }
}
项目:freecol    文件:SaveDialog.java   
/**
 * Creates a dialog to choose a file to load.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param frame The owner frame.
 * @param directory The directory to display when choosing the file.
 * @param fileFilters The available file filters in the dialog.
 * @param defaultName Name of the default save game file.
 */
public SaveDialog(FreeColClient freeColClient, JFrame frame,
        File directory, FileFilter[] fileFilters, String defaultName) {
    super(freeColClient, frame);

    final JFileChooser fileChooser = new JFileChooser(directory);
    if (fileFilters.length > 0) {
        for (FileFilter fileFilter : fileFilters) {
            fileChooser.addChoosableFileFilter(fileFilter);
        }
        fileChooser.setFileFilter(fileFilters[0]);
        fileChooser.setAcceptAllFileFilterUsed(false);
    }
    fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setFileHidingEnabled(false);
    fileChooser.setSelectedFile(new File(defaultName));
    fileChooser.addActionListener((ActionEvent ae) ->
            setValue((JFileChooser.APPROVE_SELECTION
                    .equals(ae.getActionCommand()))
                ? fileChooser.getSelectedFile() : cancelFile));

    List<ChoiceItem<File>> c = choices();
    initializeDialog(frame, DialogType.QUESTION, true, fileChooser, null, c);
}
项目:nzbupload    文件:UploadDialog.java   
private void changeInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeInputActionPerformed
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setSelectedFile(new File(input.getText()));
    chooser.setDialogTitle("Input folder");
    int returnVal = chooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        try {
            String filename = chooser.getSelectedFile().getAbsolutePath();
            input.setText(filename);
            screenToProps();
        } catch (IOException ex) {
            LOG.log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(this, ex.getMessage(),
                    "Exception was raised", JOptionPane.ERROR_MESSAGE);
        }
    }
}
项目:SimQRI    文件:ReportManager.java   
@SuppressWarnings("unused")
private String selectDirectoryPath() {
    String path = "";
    JFileChooser chooser = new JFileChooser();
    // chooser.setCurrentDirectory(new java.io.File("."));
    chooser.setDialogTitle("Select a destination folder for your reports !");
    chooser.setCurrentDirectory(new File("current workspace ?"));
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setAcceptAllFileFilterUsed(false);

    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)
        path = chooser.getSelectedFile().toString();
    else
        path = "";
    return path;
}
项目:automatic-variants    文件:WizVariant.java   
@Override
   protected void initialize() {
super.initialize();

setQuestionText("Name your new variant and add textures.");

nameField = new LTextField("Variant Name", AV.AVFont, AV.yellow);
nameField.putUnder(question, x, spacing);
nameField.setSize(settingsPanel.getWidth() - 2 * x, 50);
Add(nameField);

varTextures = new SPList<>("Variant Textures", AV.AVFont, AV.yellow);
varTextures.setUnique(true);
varTextures.addEnterButton("Add Texture", new ActionListener() {

    @Override
    public void actionPerformed(ActionEvent e) {
    JFileChooser fd = new JFileChooser(lastQuery);
    fd.setMultiSelectionEnabled(true);
    File[] chosen = new File[0];
    if (fd.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        lastQuery = fd.getSelectedFile().getParentFile();
        chosen = fd.getSelectedFiles();
    }
    for (File f : chosen) {
        if (Ln.isFileType(f, "DDS")) {
        varTextures.addElement(f);
        }
    }
    }
});
varTextures.putUnder(nameField, x, spacing);
varTextures.setSize(settingsPanel.getWidth() - x * 2, 250);
Add(varTextures);

setNext(AV.wizVarSpecPanel);
   }
项目:geomapapp    文件:PersTool.java   
void save() {
    if( pi==null||pi.getImage()==null )return;
    JFileChooser chooser = haxby.map.MapApp.getFileChooser();
    String name = "3Dimage.jpg";
    File dir = chooser.getCurrentDirectory();
    chooser.setSelectedFile(new File(dir,name));
    File file = null;
    while( true ) {
        int ok = chooser.showSaveDialog(pi);
        if( ok==chooser.CANCEL_OPTION)return;
        file = chooser.getSelectedFile();
        if( file.exists() ) {
            ok=JOptionPane.showConfirmDialog(
                    pi,
                    "File exists, overwrite?");
            if( ok==JOptionPane.CANCEL_OPTION)return;
            if( ok==JOptionPane.YES_OPTION)break;
        } else {
            break;
        }
    }
    try {
        int sIndex = file.getName().lastIndexOf(".");
        String suffix = sIndex<0
            ? "jpg"
            : file.getName().substring( sIndex+1 );
        if( !ImageIO.getImageWritersBySuffix(suffix).hasNext())suffix = "jpg";
        ImageIO.write( pi.getImage(), suffix, file);
    } catch(Exception ex) {

    }
}
项目:powertext    文件:NewProject.java   
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    int status = folderChooser.showOpenDialog(this);
    if (status == JFileChooser.APPROVE_OPTION) {
        String currentFileDi = folderChooser.getSelectedFile().getAbsolutePath();
        System.out.println(currentFileDi + "\\");
                jTextField2.setText(currentFileDi + "\\");
    }else {
        System.out.println("No Directory Choosen");
    }
}
项目:Proyecto-DASI    文件:VisorControlSimuladorRosace.java   
public boolean setDirectorioPersistencia(String dirPersistencia){
    FileNameExtensionFilter filter = new FileNameExtensionFilter("ficheros xml","xml","txt" );
     jFileChooser1.setFileFilter(filter);
   jFileChooser1.setFileSelectionMode(JFileChooser.FILES_ONLY);
   try {
  jFileChooser1.setCurrentDirectory(new File (dirPersistencia));
  return true;
   } catch (Exception ex) {
       return false;
   }
}
项目:PMDe    文件:Main.java   
private void mnuSaveAsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuSaveAsActionPerformed
    if (RomFile.current == null) return;
    if (!RomFile.current.isLoaded()) return;

    final JFileChooser fc = new JFileChooser() {{
        setDialogTitle("Save ROM file");
        setFileFilter(new FileNameExtensionFilter("GBA files (*.gba)", ".gba", "gba"));
        addChoosableFileFilter(new FileNameExtensionFilter("ROM files (*.rom)", ".rom", "rom"));
    }};

    String lastdir = Preferences.userRoot().get("mystery_lastDir", null);
    if (lastdir != null)
        fc.setSelectedFile(new File(lastdir));
    if (fc.showSaveDialog(this) != JFileChooser.APPROVE_OPTION)
        return;
    String newdir = fc.getSelectedFile().getPath();
    Preferences.userRoot().put("mystery_lastDir", newdir);

    RomFile.current.setFile(new File(newdir));

    try {
        RomFile.current.save();
    }
    catch (IOException ex) {
        System.err.print(ex);
    }
}
项目:asgdrivestrength    文件:RunDrivestrengthPanel.java   
private void constructGeneralPanel(JTabbedPane tabbedPane) {
    PropertiesPanel panel = new PropertiesPanel(parent);
    tabbedPane.addTab("General", null, panel, null);
    GridBagLayout gbl_generalpanel = new GridBagLayout();
    gbl_generalpanel.columnWidths = new int[]{150, 300, 30, 80, 0};
    gbl_generalpanel.columnWeights = new double[]{0.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
    gbl_generalpanel.rowHeights = new int[]{15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0};
    gbl_generalpanel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
    panel.setLayout(gbl_generalpanel);

    panel.addTextEntry(0, TextParam.NetlistFile, "Netlist file to optimize", normalizedPath("netlists/aNetlist.v"),
            true, JFileChooser.FILES_ONLY, false);

    panel.addTextEntry(2, TextParam.LibertyFile, "Liberty file", normalizedPath("cells/cellLibrary.lib"),
            true, JFileChooser.FILES_ONLY, false);

    panel.addTextEntry(3, TextParam.cellInfoJsonFile, "Cell Info JSON file", normalizedPath("cells/cellInfo.json"),
            true, JFileChooser.FILES_ONLY, false);

    panel.addTextEntry(4, TextParam.RemoteConfigFile, "Remote config file", normalizedPath("remoteConfig.json"),
            true, JFileChooser.FILES_ONLY, false);


    addOutSection(panel, 6, "aNetlist_optimized.v", normalizedPath("drivestrength-output"));

    panel.addTextEntry(8, TextParam.OutputConstraintFile, "Output constraints file (SDC)", "constraints.sdc");

    getDataFromPanel(panel);
}
项目:QN-ACTR-Release    文件:ModelLoader.java   
/**
 * Saves specified model into specified file or shows save as window if file is null
 * @param modelData data file where information should be stored. Note that <b>its type
 * must be compatible with defaultFilter chosen in the constructor</b>, otherwise a
 * ClassCastException will be thrown
 * @param parent parent window that will own the save as dialog
 * @param file location where pecified model must be saved or null if save as must be shown
 * @return SUCCESS on success, CANCELLED if loading is cancelled,
 * FAILURE if an error occurs
 * @throws ClassCastException if modelData is not of instance of the correct class
 * @see #getFailureMotivation getFailureMotivation()
 */
public int saveModel(Object modelData, Component parent, File file) {
    if (file == null) {
        // Shows save as window
        int status;
        status = this.showSaveDialog(parent);
        if (status == JFileChooser.CANCEL_OPTION) {
            return CANCELLED;
        } else if (status == JFileChooser.ERROR_OPTION) {
            failureMotivation = "Error selecting output file";
            return FAILURE;
        }
        file = dialog.getSelectedFile();
    } else
    // Check extension to avoid saving over a converted file
    if (!file.getName().endsWith(defaultFilter.getFirstExtension())) {
        int resultValue = JOptionPane.showConfirmDialog(parent, "<html>File <font color=#0000ff>" + file.getName() + "</font> does not have \""
                + defaultFilter.getFirstExtension() + "\" extension.<br>Do you want to replace it anyway?</html>", "JMT - Warning",
                JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
        if (resultValue != JOptionPane.OK_OPTION) {
            return CANCELLED;
        }
    }

    // Now checks to save correct type of model
    try {
        if (defaultFilter == JMODEL || defaultFilter == JSIM) {
            XMLArchiver.saveModel(file, (CommonModel) modelData);
        } else if (defaultFilter == JMVA) {
            xmlutils.saveXML(((ExactModel) modelData).createDocument(), file);
        } else if (defaultFilter == JABA) {
            xmlutils.saveXML(((JabaModel) modelData).createDocument(), file);
        }
    } catch (Exception e) {
        failureMotivation = e.getClass().getName() + ": " + e.getMessage();
        return FAILURE;
    }
    return SUCCESS;
}
项目:geomapapp    文件:OtherDBInputDialog.java   
public void loadFile(){
    type = UnknownDataSet.ASCII_FILE;
    jfc.setFileFilter(null);
    int c = jfc.showOpenDialog(this);
    if (c==JFileChooser.CANCEL_OPTION || c == JFileChooser.ERROR_OPTION) return;
    path = jfc.getSelectedFile().getPath();
    loadFile(jfc.getSelectedFile());
}
项目:openjdk-jdk10    文件:JFileChooserOperator.java   
/**
 * Maps {@code JFileChooser.getIcon(File)} through queue
 */
public Icon getIcon(final File file) {
    return (runMapping(new MapAction<Icon>("getIcon") {
        @Override
        public Icon map() {
            return ((JFileChooser) getSource()).getIcon(file);
        }
    }));
}
项目:cuttlefish    文件:NetworkInitializer.java   
public void initInteractiveCxfNetwork(InteractiveCxfNetwork interactiveCxfNetwork) {
    initCxfNetwork(interactiveCxfNetwork);
    JFileChooser fc = new FileChooser();
    fc.setDialogTitle("Select a CEF file");
    fc.setFileFilter(new FileNameExtensionFilter(".cef files", "cef"));
    int returnVal = fc.showOpenDialog(null);

       if (returnVal == JFileChooser.APPROVE_OPTION) {
           File file = fc.getSelectedFile();
           interactiveCxfNetwork.loadInstructions(file);            
       } else {
           System.out.println("Input cancelled by user");
       }
}
项目:sstore-soft    文件:AbstractViewer.java   
protected String showSaveDialog(String title, String dir, IOFileFilter filter, File defaultFile) throws Exception {
    JFileChooser chooser = new JFileChooser(dir);
    chooser.setFileFilter(filter);
    chooser.setDialogTitle(title);
    if (defaultFile != null) chooser.setSelectedFile(defaultFile);
    int returnVal = chooser.showSaveDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        return (chooser.getSelectedFile().toString());
    }
    return (null);
}
项目:QN-ACTR-Release    文件:MainJwatWizard.java   
public void actionPerformed(ActionEvent e) {
    JwatSession session;
    if (fileSaveF.showOpenDialog(MainJwatWizard.this) == JFileChooser.APPROVE_OPTION) {
        File fFile = fileSaveF.getSelectedFile();
        String fileName = fFile.getAbsolutePath();
        System.out.println(fileName);
        MainJwatWizard.this.session.saveSession(fileName.substring(0, fileName.lastIndexOf("\\")) + "\\", fileName.substring(fileName
                .lastIndexOf("\\") + 1), JwatSession.WORKLOAD_SAVE);
    }
}
项目:Mp3-player    文件:Mp3player.java   
private void OpenbuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OpenbuttonActionPerformed

    JFileChooser filechooser=new JFileChooser();
    int result=filechooser.showOpenDialog(null);
    File selectfile=filechooser.getSelectedFile();
   // System.out.println(selectfile.getAbsolutePath());
   song=new MP3(selectfile.getAbsolutePath());
}