Example usage for java.awt FileDialog FileDialog

List of usage examples for java.awt FileDialog FileDialog

Introduction

In this page you can find the example usage for java.awt FileDialog FileDialog.

Prototype

public FileDialog(Dialog parent, String title, int mode) 

Source Link

Document

Creates a file dialog window with the specified title for loading or saving a file.

Usage

From source file:edu.ucla.stat.SOCR.analyses.util.moduls.frm.Panels.Jpan_btn.java

private FitxerDades getFitxerDades(final String sPath) {
    final FileDialog fd = new FileDialog(fDialog, Language.getLabel(9), FileDialog.LOAD);
    FitxerDades fitx;// w w  w.  j a  v  a  2  s .c o  m

    fitx = new FitxerDades();
    fd.setDirectory(sPath);
    fd.setVisible(true);
    if (fd.getFile() == null) {
        fitx = null;
    } else {
        fitx.setNom(fd.getFile());
        fitx.setPath(fd.getDirectory());
    }
    return fitx;
}

From source file:wsattacker.sso.openid.attacker.gui.MainGui.java

private void loadItemActionPerformed(ActionEvent evt) {//GEN-FIRST:event_loadItemActionPerformed
    FileDialog fd = new FileDialog(this, "Choose a file", FileDialog.LOAD);
    fd.setFile("*.xml");
    fd.setVisible(true);// www .  j a v a  2 s . c  o  m
    File[] files = fd.getFiles();

    if (files.length > 0) {
        File loadFile = files[0];

        try {
            ToolConfiguration currentToolConfig = new ToolConfiguration();
            currentToolConfig.setAttackerConfig(controller.getAttackerConfig());
            currentToolConfig.setAnalyzerConfig(controller.getAnalyzerConfig());

            XmlPersistenceHelper.mergeConfigFileToConfigObject(loadFile, currentToolConfig);
        } catch (XmlPersistenceError ex) {
            Logger.getLogger(MainGui.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /*int returnVal = loadFileChooser.showOpenDialog(this);
                
    if (returnVal == JFileChooser.APPROVE_OPTION) {
    File loadFile = loadFileChooser.getSelectedFile();
    try {
        XmlPersistenceHelper.mergeConfigFileToConfigObject(loadFile, controller.getConfig());
    } catch (XmlPersistenceError ex) {
        Logger.getLogger(MainGui.class.getName()).log(Level.SEVERE, null, ex);
    }
    }*/
}

From source file:processing.app.Sketch.java

/**
 * Handles 'Save As' for a sketch.//from   w  w w  . j  av  a 2s . c  o m
 * <P>
 * This basically just duplicates the current sketch folder to
 * a new location, and then calls 'Save'. (needs to take the current
 * state of the open files and save them to the new folder..
 * but not save over the old versions for the old sketch..)
 * <P>
 * Also removes the previously-generated .class and .jar files,
 * because they can cause trouble.
 */
protected boolean saveAs() throws IOException {
    // get new name for folder
    FileDialog fd = new FileDialog(editor, tr("Save sketch folder as..."), FileDialog.SAVE);
    if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())
            || isUntitled()) {
        // default to the sketchbook folder
        fd.setDirectory(BaseNoGui.getSketchbookFolder().getAbsolutePath());
    } else {
        // default to the parent folder of where this was
        // on macs a .getParentFile() method is required

        fd.setDirectory(data.getFolder().getParentFile().getAbsolutePath());
    }
    String oldName = data.getName();
    fd.setFile(oldName);

    fd.setVisible(true);
    String newParentDir = fd.getDirectory();
    String newName = fd.getFile();

    // user canceled selection
    if (newName == null)
        return false;
    newName = Sketch.checkName(newName);

    File newFolder = new File(newParentDir, newName);

    // make sure there doesn't exist a .cpp file with that name already
    // but ignore this situation for the first tab, since it's probably being
    // resaved (with the same name) to another location/folder.
    for (int i = 1; i < data.getCodeCount(); i++) {
        SketchCode code = data.getCode(i);
        if (newName.equalsIgnoreCase(code.getPrettyName())) {
            Base.showMessage(tr("Error"), I18n.format(tr("You can't save the sketch as \"{0}\"\n"
                    + "because the sketch already has a file with that name."), newName));
            return false;
        }
    }

    // check if the paths are identical
    if (newFolder.equals(data.getFolder())) {
        // just use "save" here instead, because the user will have received a
        // message (from the operating system) about "do you want to replace?"
        return save();
    }

    // check to see if the user is trying to save this sketch inside itself
    try {
        String newPath = newFolder.getCanonicalPath() + File.separator;
        String oldPath = data.getFolder().getCanonicalPath() + File.separator;

        if (newPath.indexOf(oldPath) == 0) {
            Base.showWarning(tr("How very Borges of you"), tr(
                    "You cannot save the sketch into a folder\n" + "inside itself. This would go on forever."),
                    null);
            return false;
        }
    } catch (IOException e) {
        //ignore
    }

    // if the new folder already exists, then need to remove
    // its contents before copying everything over
    // (user will have already been warned)
    if (newFolder.exists()) {
        Base.removeDir(newFolder);
    }
    // in fact, you can't do this on windows because the file dialog
    // will instead put you inside the folder, but it happens on osx a lot.

    // now make a fresh copy of the folder
    newFolder.mkdirs();

    // grab the contents of the current tab before saving
    // first get the contents of the editor text area
    if (current.getCode().isModified()) {
        current.getCode().setProgram(editor.getText());
    }

    // save the other tabs to their new location
    for (SketchCode code : data.getCodes()) {
        if (data.indexOfCode(code) == 0)
            continue;
        File newFile = new File(newFolder, code.getFileName());
        code.saveAs(newFile);
    }

    // re-copy the data folder (this may take a while.. add progress bar?)
    if (data.getDataFolder().exists()) {
        File newDataFolder = new File(newFolder, "data");
        Base.copyDir(data.getDataFolder(), newDataFolder);
    }

    // re-copy the code folder
    if (data.getCodeFolder().exists()) {
        File newCodeFolder = new File(newFolder, "code");
        Base.copyDir(data.getCodeFolder(), newCodeFolder);
    }

    // copy custom applet.html file if one exists
    // http://dev.processing.org/bugs/show_bug.cgi?id=485
    File customHtml = new File(data.getFolder(), "applet.html");
    if (customHtml.exists()) {
        File newHtml = new File(newFolder, "applet.html");
        Base.copyFile(customHtml, newHtml);
    }

    // save the main tab with its new name
    File newFile = new File(newFolder, newName + ".ino");
    data.getCode(0).saveAs(newFile);

    editor.handleOpenUnchecked(newFile, currentIndex, editor.getSelectionStart(), editor.getSelectionStop(),
            editor.getScrollPosition());

    // Name changed, rebuild the sketch menus
    //editor.sketchbook.rebuildMenusAsync();
    editor.base.rebuildSketchbookMenus();

    // Make sure that it's not an untitled sketch
    setUntitled(false);

    // let Editor know that the save was successful
    return true;
}

From source file:edu.ku.brc.specify.config.ResourceImportExportDlg.java

/**
 * //from www.j a  v  a2s .c  om
 */
protected void exportResource() {

    int index = levelCBX.getSelectedIndex();
    if (index > -1) {
        String exportedName = null;

        String data = null;
        String fileName = null;
        AppResourceIFace appRes = null;
        if (tabbedPane.getSelectedComponent() == viewsPanel) {
            if (viewSetsList.getSelectedIndex() > -1) {
                SpViewSetObj vso = (SpViewSetObj) viewSetsList.getSelectedValue();
                exportedName = vso.getName();
                fileName = FilenameUtils.getName(vso.getFileName());
                data = vso.getDataAsString(true);
            }
        } else {
            JList theList = tabbedPane.getSelectedComponent() == repPanel ? repList : resList;
            if (theList.getSelectedIndex() > 0) {
                appRes = (AppResourceIFace) theList.getSelectedValue();
                exportedName = appRes.getName();
                fileName = FilenameUtils.getName(exportedName);
                data = appRes.getDataAsString();

            }
        }

        if (StringUtils.isNotEmpty(data)) {
            final String EXP_DIR_PREF = "RES_LAST_EXPORT_DIR";
            String initalExportDir = AppPreferences.getLocalPrefs().get(EXP_DIR_PREF, getUserHomeDir());

            FileDialog fileDlg = new FileDialog(this, getResourceString("RIE_ExportResource"), FileDialog.SAVE);

            File expDir = new File(initalExportDir);
            if (StringUtils.isNotEmpty(initalExportDir) && expDir.exists()) {
                fileDlg.setDirectory(initalExportDir);
            }

            fileDlg.setFile(fileName);

            UIHelper.centerAndShow(fileDlg);

            String dirStr = fileDlg.getDirectory();
            fileName = fileDlg.getFile();

            if (StringUtils.isNotEmpty(dirStr) && StringUtils.isNotEmpty(fileName)) {
                AppPreferences.getLocalPrefs().put(EXP_DIR_PREF, dirStr);

                File expFile = new File(dirStr + File.separator + fileName);
                try {
                    if (isReportResource((SpAppResource) appRes)
                            && isSpReportResource((SpAppResource) appRes)) {
                        writeSpReportResToZipFile(expFile, data, appRes);
                    } else {
                        FileUtils.writeStringToFile(expFile, data);
                    }

                } catch (FileNotFoundException ex) {
                    showLocalizedMsg("RIE_NOFILEPERM");

                } catch (Exception ex) {
                    ex.printStackTrace();
                    edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                    edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ResourceImportExportDlg.class,
                            ex);
                }
            }
        }

        if (exportedName != null) {
            getStatusBar().setText(getLocalizedMessage("RIE_RES_EXPORTED", exportedName));
        }
    }
}

From source file:processing.app.Sketch.java

/**
 * Prompt the user for a new file to the sketch, then call the
 * other addFile() function to actually add it.
 *//*from www .j av a 2s.  co  m*/
public void handleAddFile() {
    // make sure the user didn't hide the sketch folder
    ensureExistence();

    // if read-only, give an error
    if (isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
        // if the files are read-only, need to first do a "save as".
        Base.showMessage(tr("Sketch is Read-Only"), tr("Some files are marked \"read-only\", so you'll\n"
                + "need to re-save the sketch in another location,\n" + "and try again."));
        return;
    }

    // get a dialog, select a file to add to the sketch
    FileDialog fd = new FileDialog(editor, tr("Select an image or other data file to copy to your sketch"),
            FileDialog.LOAD);
    fd.setVisible(true);

    String directory = fd.getDirectory();
    String filename = fd.getFile();
    if (filename == null)
        return;

    // copy the file into the folder. if people would rather
    // it move instead of copy, they can do it by hand
    File sourceFile = new File(directory, filename);

    // now do the work of adding the file
    boolean result = addFile(sourceFile);

    if (result) {
        editor.statusNotice(tr("One file added to the sketch."));
        PreferencesData.set("last.folder", sourceFile.getAbsolutePath());
    }
}

From source file:edu.ku.brc.specify.utilapps.sp5utils.Sp5Forms.java

@SuppressWarnings({ "unchecked" })
private void openXML() {
    FileDialog fileDlg = new FileDialog((Frame) UIRegistry.getTopWindow(), "", FileDialog.LOAD);

    fileDlg.setFilenameFilter(new FilenameFilter() {
        @Override// w  ww . j a v a  2s .  co m
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".xml");
        }
    });
    fileDlg.setVisible(true);

    String fileName = fileDlg.getFile();
    if (fileName != null) {
        File iFile = new File(fileDlg.getDirectory() + File.separator + fileName);

        XStream xstream = new XStream();
        FormInfo.configXStream(xstream);
        FormFieldInfo.configXStream(xstream);

        try {
            forms = (Vector<FormInfo>) xstream.fromXML(FileUtils.openInputStream(iFile));
            formsTable.setModel(new FormCellModel(forms));

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:processing.app.Base.java

/**
 * Prompt for a sketch to open, and open it in a new window.
 *
 * @throws Exception/*from w  ww.ja va  2 s .c  o m*/
 */
public void handleOpenPrompt() throws Exception {
    // get the frontmost window frame for placing file dialog
    FileDialog fd = new FileDialog(activeEditor, tr("Open an Arduino sketch..."), FileDialog.LOAD);
    File lastFolder = new File(
            PreferencesData.get("last.folder", BaseNoGui.getSketchbookFolder().getAbsolutePath()));
    if (lastFolder.exists() && lastFolder.isFile()) {
        lastFolder = lastFolder.getParentFile();
    }
    fd.setDirectory(lastFolder.getAbsolutePath());

    // Only show .pde files as eligible bachelors
    fd.setFilenameFilter(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".ino") || name.toLowerCase().endsWith(".pde");
        }
    });

    fd.setVisible(true);

    String directory = fd.getDirectory();
    String filename = fd.getFile();

    // User canceled selection
    if (filename == null)
        return;

    File inputFile = new File(directory, filename);

    PreferencesData.set("last.folder", inputFile.getAbsolutePath());
    handleOpen(inputFile);
}

From source file:pipeline.GUI_utils.ListOfPointsView.java

private void reloadUserFormulasFromFile() {
    FileDialog dialog = new FileDialog(new Frame(), "Choose a tab-separated file to load formulas from.",
            FileDialog.LOAD);//from w  ww  . j a  v a 2 s.  co  m
    dialog.setVisible(true);
    String filePath = dialog.getDirectory();
    if (filePath == null)
        return;
    filePath += "/" + dialog.getFile();

    silenceUpdates.incrementAndGet();

    try (BufferedReader r = new BufferedReader(new FileReader(filePath))) {
        List<Integer> userColumns = getUserColumnList();
        int nUserColumns = userColumns.size();
        int row = 0;
        boolean firstLine = true;// the first line contains column names
        while (true) {
            String line = r.readLine();
            if (line == null)
                break;
            StringTokenizer stok = new java.util.StringTokenizer(line);

            int currentColumn = 0;
            while (stok.hasMoreTokens()) {
                String element = stok.nextToken("\t");
                if (firstLine) {
                    // name columns
                    tableModel.setColumnName(userColumns.get(currentColumn), element);
                    modelForColumnDescriptions.setValueAt(element, 0, userColumns.get(currentColumn));
                } else {
                    SpreadsheetCell cell = (SpreadsheetCell) tableModel.getValueAt(row,
                            userColumns.get(currentColumn));
                    if (cell == null) {
                        cell = new SpreadsheetCell("", "", new Object[] { "", element }, true, this, null);
                        tableModel.setValueAt(cell, row, userColumns.get(currentColumn));
                    } else {
                        cell.setFormula(element);
                    }
                }
                currentColumn++;
                if (currentColumn == nUserColumns) {
                    Utils.log("File has more columns than user columns; discarding remaining columns from file",
                            LogLevel.WARNING);
                    break;
                }
            }
            if (!firstLine)
                row++;
            else
                firstLine = false;
        }
    } catch (IOException e) {
        Utils.printStack(e);
    } finally {
        silenceUpdates.decrementAndGet();
    }

    tableModel.fireTableStructureChanged();
    setSpreadsheetColumnEditorAndRenderer();
}

From source file:edu.ku.brc.specify.config.ResourceImportExportDlg.java

/**
 * /*from w w  w .  j  av  a 2s .c o m*/
 */
protected void importResource() {
    int levelIndex = levelCBX.getSelectedIndex();
    if (levelIndex > -1) {
        String importedName = null;

        final String IMP_DIR_PREF = "RES_LAST_IMPORT_DIR";
        String initalImportDir = AppPreferences.getLocalPrefs().get(IMP_DIR_PREF, getUserHomeDir());

        FileDialog fileDlg = new FileDialog(this, getResourceString("RIE_IMPORT_RES"), FileDialog.LOAD);

        File impDir = new File(initalImportDir);
        if (StringUtils.isNotEmpty(initalImportDir) && impDir.exists()) {
            fileDlg.setDirectory(initalImportDir);
        }

        UIHelper.centerAndShow(fileDlg);

        String dirStr = fileDlg.getDirectory();
        String fileName = fileDlg.getFile();

        if (StringUtils.isNotEmpty(dirStr) && StringUtils.isNotEmpty(fileName)) {
            AppPreferences.getLocalPrefs().put(IMP_DIR_PREF, dirStr);

            String data = null;
            String fullFileName = dirStr + File.separator + fileName;
            File importFile = new File(fullFileName);
            if (importFile.exists()) {
                String repResourceName = getSpReportResourceName(importFile);
                boolean isSpReportRes = repResourceName != null;
                boolean isJRReportRes = false;
                try {
                    data = FileUtils.readFileToString(importFile);
                    isJRReportRes = isJasperReport(data);

                } catch (Exception ex) {
                    ex.printStackTrace();
                    edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                    edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ResourceImportExportDlg.class,
                            ex);
                    return;
                }

                boolean isReportRes = isJRReportRes || isSpReportRes;

                if (tabbedPane.getSelectedComponent() == viewsPanel) {
                    int viewIndex = viewSetsList.getSelectedIndex();
                    if (viewIndex > -1) {
                        boolean isAddItemForImport = viewSetsList.getSelectedValue() instanceof String;
                        boolean isOK = false;
                        SpViewSetObj vso = null;

                        DataProviderSessionIFace session = null;
                        try {
                            session = DataProviderFactory.getInstance().createSession();
                            session.beginTransaction();

                            if (!isAddItemForImport) {
                                vso = (SpViewSetObj) viewSetsList.getSelectedValue();
                                SpAppResourceDir appResDir = vso.getSpAppResourceDir();
                                importedName = vso.getName();

                                if (vso.getSpViewSetObjId() == null) {
                                    appResDir.getSpPersistedViewSets().add(vso);
                                    vso.setSpAppResourceDir(appResDir);
                                }
                                vso.setDataAsString(data, true);
                                session.saveOrUpdate(appResDir);

                            } else {
                                SpAppResourceDir appResDir = dirs.get(levelIndex);
                                vso = new SpViewSetObj();
                                vso.initialize();
                                vso.setLevel((short) levelIndex);
                                vso.setName(FilenameUtils.getBaseName(importFile.getName()));

                                appResDir.getSpPersistedViewSets().add(vso);
                                vso.setSpAppResourceDir(appResDir);

                                vso.setDataAsString(data);
                                session.saveOrUpdate(appResDir);
                            }

                            session.saveOrUpdate(vso);
                            for (SpAppResourceData ard : vso.getSpAppResourceDatas()) {
                                session.saveOrUpdate(ard);
                            }
                            session.commit();
                            session.flush();

                            setHasChanged(true);
                            isOK = true;
                            completeMsg = getLocalizedMessage("RIE_RES_IMPORTED",
                                    importedName == null ? fileName : importedName);

                        } catch (Exception ex) {
                            ex.printStackTrace();

                            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                            edu.ku.brc.exceptions.ExceptionTracker.getInstance()
                                    .capture(ResourceImportExportDlg.class, ex);
                            session.rollback();

                        } finally {
                            try {
                                session.close();

                            } catch (Exception ex) {
                                ex.printStackTrace();
                                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                                edu.ku.brc.exceptions.ExceptionTracker.getInstance()
                                        .capture(ResourceImportExportDlg.class, ex);
                            }
                        }

                        if (isOK) {
                            if (isAddItemForImport) {
                                viewSetsModel.clear();
                                viewSetsModel.addElement(vso);
                            } else {
                                viewSetsModel.remove(viewIndex);
                                viewSetsModel.insertElementAt(vso, viewIndex);
                            }
                            viewSetsList.repaint();
                        }
                    }

                } else {
                    boolean isResourcePanel = tabbedPane.getSelectedComponent() == repPanel;
                    JList theList = isResourcePanel ? repList : resList;
                    int resIndex = theList.getSelectedIndex();
                    Object selObj = theList.getSelectedValue();
                    if (resIndex > -1) {
                        if (resIndex == 0) // means we are adding a new resource
                        {
                            try {
                                SpecifyUser user = contextMgr.getClassObject(SpecifyUser.class);
                                Agent agent = contextMgr.getClassObject(Agent.class);

                                SpAppResourceDir dir = dirs.get(levelIndex);

                                SpAppResource appRes = new SpAppResource();
                                appRes.initialize();
                                appRes.setName(fileName);
                                appRes.setCreatedByAgent(agent);
                                appRes.setSpecifyUser(user);

                                if (dir.getId() == null) {
                                    dir.mergeTransientResourceAndViewSets();
                                }

                                Pair<SpAppResource, String> retValues = checkForOverwriteOrNewName(dir,
                                        isSpReportRes ? repResourceName : fileName, isSpReportRes);
                                if (retValues != null && retValues.first == null && retValues.second == null) {
                                    return; // Dialog was Cancelled
                                }

                                SpAppResource fndAppRes = retValues != null && retValues.first != null
                                        ? retValues.first
                                        : null;
                                String newResName = retValues != null && retValues.second != null
                                        ? retValues.second
                                        : null;

                                if (isReportRes) {
                                    if (fndAppRes != null) {
                                        if (isSpReportRes) {
                                            ReportsBaseTask.deleteReportAndResource(null, fndAppRes.getId());
                                        } else {
                                            //XXX ???????????
                                            if (fndAppRes.getSpAppResourceId() != null) {
                                                contextMgr.removeAppResourceSp(fndAppRes.getSpAppResourceDir(),
                                                        fndAppRes);
                                            }
                                        }
                                    } /*else if (newResName == null)
                                      {
                                      return;
                                      }*/

                                    if (isSpReportRes) {
                                        appRes = importSpReportZipResource(importFile, appRes, dir, newResName);
                                        if (appRes != null) {
                                            importedName = appRes.getName();
                                        }
                                    } else {
                                        if (MainFrameSpecify.importJasperReport(importFile, false,
                                                newResName)) {
                                            importedName = importFile.getName();
                                        } else {
                                            return;
                                        }
                                    }
                                    if (importedName != null) {
                                        CommandDispatcher.dispatch(new CommandAction(ReportsBaseTask.REPORTS,
                                                ReportsBaseTask.REFRESH, null));
                                        CommandDispatcher.dispatch(new CommandAction(QueryTask.QUERY,
                                                QueryTask.REFRESH_QUERIES, null));
                                        levelSelected();
                                    }
                                } else if (fndAppRes != null) // overriding
                                {
                                    appRes.setMetaData(fndAppRes.getMetaData());
                                    appRes.setDescription(fndAppRes.getDescription());
                                    appRes.setFileName(fileName);
                                    appRes.setMimeType(appRes.getMimeType());
                                    appRes.setName(fileName);

                                    appRes.setLevel(fndAppRes.getLevel());

                                } else if (!getMetaInformation(appRes, fileName)) {
                                    return;
                                }

                                if (!isReportRes) {
                                    appRes.setSpAppResourceDir(dir);
                                    dir.getSpAppResources().add(appRes);

                                    appRes.setDataAsString(data);
                                    contextMgr.saveResource(appRes);
                                    completeMsg = getLocalizedMessage("RIE_RES_IMPORTED",
                                            importedName == null ? fileName : importedName);
                                }
                                setHasChanged(true);

                            } catch (Exception e) {
                                e.printStackTrace();
                                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                                edu.ku.brc.exceptions.ExceptionTracker.getInstance()
                                        .capture(ResourceImportExportDlg.class, e);
                            }
                        } else if (selObj instanceof AppResourceIFace) {
                            //if (isResourcePanel) resIndex++;
                            AppResourceIFace fndAppRes = null;
                            for (AppResourceIFace appRes : resources) {
                                if (appRes == selObj) {
                                    fndAppRes = appRes;
                                    break;
                                }
                            }

                            if (fndAppRes != null) {
                                String importedFileName = fndAppRes.getFileName();
                                String fName = FilenameUtils.getName(importedFileName);
                                String dbBaseName = FilenameUtils.getBaseName(fileName);
                                //log.debug("["+fName+"]["+dbBaseName+"]");

                                boolean doOverwrite = true;
                                if (!dbBaseName.equals(fName)) {
                                    String msg = getLocalizedMessage("RIE_OVRDE_MSG", dbBaseName, fName);
                                    doOverwrite = displayConfirm(getResourceString("RIE_OVRDE_TITLE"), msg,
                                            getResourceString("RIE_OVRDE"), getResourceString("CANCEL"),
                                            JOptionPane.QUESTION_MESSAGE);
                                }

                                if (doOverwrite) {
                                    fndAppRes.setDataAsString(data);
                                    contextMgr.saveResource(fndAppRes);
                                    completeMsg = getLocalizedMessage("RIE_RES_IMPORTED",
                                            importedName == null ? fileName : importedName);
                                }
                            } else {
                                UIRegistry.showError("Strange error - Couldn't resource.");
                            }
                        }
                    }
                }

                if (importedName != null) {
                    completeMsg = getLocalizedMessage("RIE_RES_IMPORTED",
                            importedName == null ? fileName : importedName);
                }

                if (hasChanged()) {
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            okBtn.doClick();
                        }
                    });
                }

            } else {
                UIRegistry.showLocalizedError("FILE_NO_EXISTS", fullFileName);
            }
        }

        enableUI();
    }
}

From source file:com.jug.MoMA.java

/**
 * Shows a JFileChooser set up to accept the selection of folders. If
 * 'cancel' is pressed this method terminates the MotherMachine app.
 *
 * @param guiFrame//  www .  j  av  a 2s  .c o  m
 *            parent frame
 * @param path
 *            path to the folder to open initially
 * @return an instance of {@link File} pointing at the selected folder.
 */
private File showFolderChooser(final JFrame guiFrame, final String path) {
    File selectedFile = null;

    if (SystemUtils.IS_OS_MAC) {
        // --- ON MAC SYSTEMS --- ON MAC SYSTEMS --- ON MAC SYSTEMS --- ON MAC SYSTEMS --- ON MAC SYSTEMS ---
        System.setProperty("apple.awt.fileDialogForDirectories", "true");
        final FileDialog fd = new FileDialog(guiFrame, "Select folder containing image sequence...",
                FileDialog.LOAD);
        fd.setDirectory(path);
        //         fd.setLocation(50,50);
        fd.setVisible(true);
        selectedFile = new File(fd.getDirectory() + "/" + fd.getFile());
        if (fd.getFile() == null) {
            System.exit(0);
            return null;
        }
        System.setProperty("apple.awt.fileDialogForDirectories", "false");
    } else {
        // --- NOT ON A MAC --- NOT ON A MAC --- NOT ON A MAC --- NOT ON A MAC --- NOT ON A MAC --- NOT ON A MAC ---
        final JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(new java.io.File(path));
        chooser.setDialogTitle("Select folder containing image sequence...");
        chooser.setFileFilter(new FileFilter() {

            @Override
            public final boolean accept(final File file) {
                return file.isDirectory();
            }

            @Override
            public String getDescription() {
                return "We only take directories";
            }
        });
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setAcceptAllFileFilterUsed(false);

        if (chooser.showOpenDialog(guiFrame) == JFileChooser.APPROVE_OPTION) {
            selectedFile = chooser.getSelectedFile();
        } else {
            System.exit(0);
            return null;
        }
    }

    return selectedFile;
}