Example usage for java.awt FileDialog getFile

List of usage examples for java.awt FileDialog getFile

Introduction

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

Prototype

public String getFile() 

Source Link

Document

Gets the selected file of this file dialog.

Usage

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 ww w .  j av a2s .c om
    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:org.apache.pdfbox.debugger.PDFDebugger.java

private void openMenuItemActionPerformed(ActionEvent evt) {
    try {/*w  ww  .j  a v  a 2  s .  c  o  m*/
        if (IS_MAC_OS) {
            FileDialog openDialog = new FileDialog(this, "Open");
            openDialog.setFilenameFilter(new FilenameFilter() {
                @Override
                public boolean accept(File file, String s) {
                    return file.getName().toLowerCase().endsWith(".pdf");
                }
            });
            openDialog.setVisible(true);
            if (openDialog.getFile() != null) {
                readPDFFile(openDialog.getFile(), "");
            }
        } else {
            String[] extensions = new String[] { "pdf", "PDF" };
            FileFilter pdfFilter = new ExtensionFileFilter(extensions, "PDF Files (*.pdf)");
            FileOpenSaveDialog openDialog = new FileOpenSaveDialog(this, pdfFilter);

            File file = openDialog.openFile();
            if (file != null) {
                readPDFFile(file, "");
            }
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

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. ja v  a 2  s .  c  o  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  ava  2  s .  c  o  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:edu.ku.brc.af.core.db.MySQLBackupService.java

@Override
public void doRestore() {
    AppPreferences remotePrefs = AppPreferences.getLocalPrefs();
    final String mysqlLoc = remotePrefs.get(MYSQL_LOC, getDefaultMySQLLoc());
    final String backupLoc = remotePrefs.get(MYSQLBCK_LOC, getDefaultBackupLoc());

    if (!(new File(mysqlLoc)).exists()) {
        UIRegistry.showLocalizedError("MySQLBackupService.MYSQL_NO_RESTORE", mysqlLoc);
        return;//ww w .  jav a2 s.c  om
    }

    File backupDir = new File(backupLoc);
    if (!backupDir.exists()) {
        if (!backupDir.mkdir()) {
            UIRegistry.showLocalizedError("MySQLBackupService.MYSQL_NO_BK_DIR", backupDir.getAbsoluteFile());
            return;
        }
    }

    FileDialog dlg = new FileDialog(((Frame) UIRegistry.getTopWindow()), getResourceString("Open"),
            FileDialog.LOAD);
    dlg.setDirectory(backupLoc);
    dlg.setVisible(true);

    String dirStr = dlg.getDirectory();
    String fileName = dlg.getFile();
    if (StringUtils.isEmpty(dirStr) || StringUtils.isEmpty(fileName)) {
        return;
    }

    errorMsg = null;

    final String path = dirStr + fileName;

    final JStatusBar statusBar = UIRegistry.getStatusBar();
    statusBar.setIndeterminate(STATUSBAR_NAME, true);

    String databaseName = DBConnection.getInstance().getDatabaseName();
    SimpleGlassPane glassPane = UIRegistry
            .writeSimpleGlassPaneMsg(getLocalizedMessage("MySQLBackupService.RESTORING", databaseName), 24);

    doCompareBeforeRestore(path, glassPane);
}

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

/**
 * /*  w w w.  ja  v a 2  s  . co  m*/
 */
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

/**
 * Handles 'Save As' for a sketch./*from   w ww  . ja v a  2 s . co  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   ww  w . j  a  v  a  2  s. c  om*/
 */
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//from   w ww  . j  a  v a 2 s  . com
 *            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;
}

From source file:edu.ku.brc.specify.tasks.ReportsBaseTask.java

protected void importReport() {
    FileDialog fileDialog = new FileDialog((Frame) UIRegistry.get(UIRegistry.FRAME),
            getResourceString("CHOOSE_WORKBENCH_IMPORT_FILE"), FileDialog.LOAD);
    //Really shouldn't override workbench prefs with report stuff???
    fileDialog.setDirectory(WorkbenchTask.getDefaultDirPath(WorkbenchTask.IMPORT_FILE_PATH));
    fileDialog.setFilenameFilter(new java.io.FilenameFilter() {
        public boolean accept(File dir, String filename) {
            return FilenameUtils.getExtension(filename).equalsIgnoreCase("jrxml");
        }//from  ww  w .j a v  a2 s. c  o  m

    });
    UIHelper.centerAndShow(fileDialog);
    fileDialog.dispose();

    String fileName = fileDialog.getFile();
    String path = fileDialog.getDirectory();
    if (StringUtils.isNotEmpty(path)) {
        AppPreferences localPrefs = AppPreferences.getLocalPrefs();
        localPrefs.put(WorkbenchTask.IMPORT_FILE_PATH, path);
    }

    File file;
    if (StringUtils.isNotEmpty(fileName) && StringUtils.isNotEmpty(path)) {
        file = new File(path + File.separator + fileName);
    } else {
        return;
    }

    if (file.exists()) {
        if (MainFrameSpecify.importJasperReport(file, true, null)) {
            refreshCommands();
        }
        //else -- assume feedback during importJasperReport()
    }
}