Example usage for java.awt FileDialog setVisible

List of usage examples for java.awt FileDialog setVisible

Introduction

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

Prototype

public void setVisible(boolean b) 

Source Link

Document

Shows or hides this Dialog depending on the value of parameter b .

Usage

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;/*from   ww w .  java2 s .  co  m*/
    }

    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:processing.app.Sketch.java

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

From source file:base.BasePlayer.AddGenome.java

@Override
public void mousePressed(MouseEvent e) {

    if (e.getSource() == tree) {

        if (selectedNode != null && selectedNode.toString().contains("Add new refe")) {
            try {
                FileDialog fs = new FileDialog(frame, "Select reference fasta-file", FileDialog.LOAD);
                fs.setDirectory(Main.downloadDir);
                fs.setVisible(true);
                String filename = fs.getFile();
                fs.setFile("*.fasta;*.fa");
                fs.setFilenameFilter(new FilenameFilter() {
                    public boolean accept(File dir, String name) {
                        return name.toLowerCase().contains(".fasta") || name.toLowerCase().contains(".fa");
                    }//from  ww w .  ja  v a  2s  . c  om
                });
                if (filename != null) {
                    File addfile = new File(fs.getDirectory() + "/" + filename);

                    if (addfile.exists()) {

                        genomeFile = addfile;
                        Main.downloadDir = genomeFile.getParent();
                        Main.writeToConfig("DownloadDir=" + genomeFile.getParent());
                        OutputRunner runner = new OutputRunner(genomeFile.getName().replace(".fasta", "")
                                .replace(".fa", "").replace(".gz", ""), genomeFile, null);
                        runner.createGenome = true;
                        runner.execute();
                    } else {
                        Main.showError("File does not exists.", "Error", frame);
                    }

                }
                if (1 == 1) {
                    return;
                }
                JFileChooser chooser = new JFileChooser(Main.downloadDir);
                chooser.setMultiSelectionEnabled(false);
                chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                chooser.setAcceptAllFileFilterUsed(false);
                MyFilterFasta fastaFilter = new MyFilterFasta();

                chooser.addChoosableFileFilter(fastaFilter);
                chooser.setDialogTitle("Select reference fasta-file");
                if (Main.screenSize != null) {
                    chooser.setPreferredSize(new Dimension((int) Main.screenSize.getWidth() / 3,
                            (int) Main.screenSize.getHeight() / 3));
                }

                int returnVal = chooser.showOpenDialog((Component) this.getParent());

                if (returnVal == JFileChooser.APPROVE_OPTION) {

                    genomeFile = chooser.getSelectedFile();
                    Main.downloadDir = genomeFile.getParent();
                    Main.writeToConfig("DownloadDir=" + genomeFile.getParent());
                    OutputRunner runner = new OutputRunner(
                            genomeFile.getName().replace(".fasta", "").replace(".gz", ""), genomeFile, null);
                    runner.createGenome = true;
                    runner.execute();

                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } else if (selectedNode != null && selectedNode.isLeaf()
                && selectedNode.toString().contains("Add new anno")) {
            try {
                FileDialog fs = new FileDialog(frame, "Select annotation gff3/gtf-file", FileDialog.LOAD);
                fs.setDirectory(Main.downloadDir);
                fs.setVisible(true);
                String filename = fs.getFile();
                fs.setFile("*.gff3;*.gtf");
                fs.setFilenameFilter(new FilenameFilter() {
                    public boolean accept(File dir, String name) {
                        return name.toLowerCase().contains(".gff3") || name.toLowerCase().contains(".gtf");
                    }
                });

                if (filename != null) {
                    File addfile = new File(fs.getDirectory() + "/" + filename);

                    if (addfile.exists()) {
                        annotationFile = addfile;
                        Main.downloadDir = annotationFile.getParent();
                        Main.writeToConfig("DownloadDir=" + annotationFile.getParent());
                        OutputRunner runner = new OutputRunner(selectedNode.getParent().toString(), null,
                                annotationFile);
                        runner.createGenome = true;
                        runner.execute();
                    } else {
                        Main.showError("File does not exists.", "Error", frame);
                    }

                }
                if (1 == 1) {
                    return;
                }
                JFileChooser chooser = new JFileChooser(Main.downloadDir);
                chooser.setMultiSelectionEnabled(false);
                chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                chooser.setAcceptAllFileFilterUsed(false);
                MyFilterGFF gffFilter = new MyFilterGFF();

                chooser.addChoosableFileFilter(gffFilter);
                chooser.setDialogTitle("Select annotation gff3-file");
                if (Main.screenSize != null) {
                    chooser.setPreferredSize(new Dimension((int) Main.screenSize.getWidth() / 3,
                            (int) Main.screenSize.getHeight() / 3));
                }
                int returnVal = chooser.showOpenDialog((Component) this.getParent());

                if (returnVal == JFileChooser.APPROVE_OPTION) {

                    annotationFile = chooser.getSelectedFile();
                    Main.downloadDir = annotationFile.getParent();

                    Main.writeToConfig("DownloadDir=" + annotationFile.getParent());
                    OutputRunner runner = new OutputRunner(selectedNode.getParent().toString(), null,
                            annotationFile);
                    runner.createGenome = true;
                    runner.execute();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
    if (e.getSource() == genometable) {

        if (new File(".").getFreeSpace()
                / 1048576 < sizeHash.get(genometable.getValueAt(genometable.getSelectedRow(), 0))[0]
                        / 1048576) {
            sizeError.setVisible(true);
            download.setEnabled(false);
            AddGenome.getLinks.setEnabled(false);
        } else {
            sizeError.setVisible(false);
            download.setEnabled(true);
            AddGenome.getLinks.setEnabled(true);
        }
        tree.clearSelection();
        remove.setEnabled(false);
        checkUpdates.setEnabled(false);
    }

}

From source file:com.declarativa.interprolog.gui.ListenerWindow.java

/**
 * */*from  w  w  w  .  jav a2s  .c  o m*/
 * Generates the subgraph and splits the Program in Subgraphs (Graph
 * Analysis)
 */
public void GraphAnalysis2() {
    String fileToLoad, folder;
    File filetoreconsult = null;
    FileDialog d = new FileDialog(this, "Consult file...");
    d.setVisible(true);
    fileToLoad = d.getFile();
    folder = d.getDirectory();
    if (fileToLoad != null) {
        ArgBuildManager manag = new ArgBuildManager();
        manag.GraphAnalysis4Frag(folder, fileToLoad);//Call to the ArgBuildManager!
    }
}

From source file:com.declarativa.interprolog.gui.ListenerWindow.java

void reconsultFile() {
    String nome, directorio;//from   w w w  .  ja v  a 2  s .co  m
    File filetoreconsult = null;
    FileDialog d = new FileDialog(this, "Consult file...");
    d.setVisible(true);
    nome = d.getFile();
    directorio = d.getDirectory();
    if (nome != null) {
        filetoreconsult = new File(directorio, nome);
        if (engine.consultAbsolute(filetoreconsult)) {
            addToReloaders(filetoreconsult, "consult");
        }
    }
}

From source file:com.declarativa.interprolog.gui.ListenerWindow.java

/**
 * */*from w  w  w.  j  a v  a 2s. c o m*/
 * Generates the subgraph and splits the Program in Subgraphs (Graph
 * Analysis)
 */
public void GraphAnalysis() {
    String fileToLoad, folder;
    File filetoreconsult = null;
    FileDialog d = new FileDialog(this, "Consult file...");
    d.setVisible(true);
    fileToLoad = d.getFile();
    folder = d.getDirectory();
    if (fileToLoad != null) {
        ArgBuildManager manag = new ArgBuildManager();
        manag.GraphFileRules(folder, fileToLoad);//Call to the ArgBuildManager!
        /*
         filetoreconsult = new File(folder, fileToLoad);
         if (engine.consultAbsolute(filetoreconsult)) {
         addToReloaders(filetoreconsult, "consult");
         }
         */
        //System.out.println("file:"+filetoreconsult.);

    }
}

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

/**
 * //from  w  w  w.ja  v a2  s  .  co  m
 */
protected void importQueries() {
    UsageTracker.incrUsageCount("QB.IMPORT");
    String path = AppPreferences.getLocalPrefs().get(XML_PATH_PREF, null);

    try {
        FileDialog fDlg = new FileDialog(((Frame) UIRegistry.getTopWindow()), "Open", FileDialog.LOAD);
        if (path != null) {
            fDlg.setDirectory(path);
        }
        fDlg.setVisible(true);

        String dirStr = fDlg.getDirectory();
        String fileName = fDlg.getFile();
        if (StringUtils.isEmpty(dirStr) || StringUtils.isEmpty(fileName)) {
            return;
        }
        path = dirStr + fileName;
        AppPreferences.getLocalPrefs().put(XML_PATH_PREF, path);

        Vector<Pair<SpQuery, Boolean>> queries = getQueriesFromFile(path, getTopLevelNodeSelector());
        ToggleButtonChooserDlg<Pair<SpQuery, Boolean>> dlg = new ToggleButtonChooserDlg<Pair<SpQuery, Boolean>>(
                (Frame) UIRegistry.getMostRecentWindow(), "QY_IMPORT_QUERIES", "QY_SEL_QUERIES_IMP", queries,
                CustomDialog.OKCANCELHELP, ToggleButtonChooserPanel.Type.Checkbox);

        dlg.setAddSelectAll(true);
        dlg.setUseScrollPane(true);
        dlg.setHelpContext("QBImport");
        UIHelper.centerAndShow(dlg);
        List<Pair<SpQuery, Boolean>> queriesList = dlg.getSelectedObjects();
        if (queriesList == null || queriesList.size() == 0) {
            return;
        }

        Vector<String> names = new Vector<String>();

        //For exportschemamappings, mapping name is assumed to be the same as associated query name
        List<Object> nameObjs = BasicSQLUtils.querySingleCol("select name from spquery order by 1");
        for (Object q : nameObjs) {
            names.add((String) q);
        }
        adjustImportedQueryNames(queries, names);

        if (saveImportedQueries(queriesList)) {
            for (Pair<SpQuery, Boolean> query : queriesList) {
                RecordSet rs = new RecordSet();
                rs.initialize();
                rs.set(query.getFirst().getName(), SpQuery.getClassTableId(), RecordSet.GLOBAL);
                rs.addItem(query.getFirst().getSpQueryId());
                addToNavBox(rs);
            }

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

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

/**
 * //  w ww  .  j  a v a  2  s  .c  o  m
 */
protected void exportQueries() {
    UsageTracker.incrUsageCount(getExportUsageKey());
    Vector<String> list = new Vector<String>();
    for (NavBoxItemIFace nbi : navBox.getItems()) {
        list.add(nbi.getTitle());
    }

    List<String> selectedList = null;
    if (list.size() == 0) {
        UIRegistry.showLocalizedMsg(getNothingToExporti18nKey());
        return;
    }
    if (list.size() == 1) {
        selectedList = list;
    } else {
        ToggleButtonChooserDlg<String> dlg = new ToggleButtonChooserDlg<String>(
                (Frame) UIRegistry.getMostRecentWindow(), getExportDlgTitlei18nKey(), getExportDlgMsgi18nKey(),
                list, CustomDialog.OKCANCELHELP, ToggleButtonChooserPanel.Type.Checkbox);
        dlg.setAddSelectAll(true);
        dlg.setUseScrollPane(true);
        dlg.setHelpContext(getExportHelpContext());
        UIHelper.centerAndShow(dlg);
        selectedList = dlg.getSelectedObjects();
        if (dlg.isCancelled() || selectedList.size() == 0) {
            return;
        }
    }

    String path = AppPreferences.getLocalPrefs().get(XML_PATH_PREF, null);

    FileDialog fDlg = new FileDialog(((Frame) UIRegistry.getTopWindow()), UIRegistry.getResourceString("SAVE"),
            FileDialog.SAVE);
    if (path != null) {
        fDlg.setDirectory(path);
    }
    fDlg.setVisible(true);

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

    if (StringUtils.isEmpty(FilenameUtils.getExtension(fileName))) {
        fileName += ".xml";
    }
    path = dirStr + fileName;
    AppPreferences.getLocalPrefs().put(XML_PATH_PREF, path);

    Hashtable<String, Boolean> hash = new Hashtable<String, Boolean>();
    for (String qTitle : selectedList) {
        hash.put(qTitle, true);
    }

    Vector<SpQuery> queries = new Vector<SpQuery>();

    // Persist out to database
    DataProviderSessionIFace session = null;
    try {
        session = DataProviderFactory.getInstance().createSession();
        for (NavBoxItemIFace nbi : navBox.getItems()) {
            if (hash.get(nbi.getTitle()) != null) {
                RecordSetIFace rs = (RecordSetIFace) nbi.getData();
                if (rs != null) {
                    SpQuery query = session.get(SpQuery.class, rs.getOnlyItem().getRecordId());
                    queries.add(query);
                }
            }
        }

        StringBuilder sb = new StringBuilder();
        sb.append(getXMLExportFirstLine());
        for (SpQuery q : queries) {
            q.toXML(sb);
        }
        sb.append(getXMLExportLastLine());
        FileUtils.writeStringToFile(new File(path), sb.toString());

    } catch (Exception ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(QueryTask.class, ex);
        // XXX Error dialog
        ex.printStackTrace();
    } finally {
        if (session != null) {
            session.close();
        }
    }
}

From source file:processing.app.Base.java

/**
 * Prompt for a sketch to open, and open it in a new window.
 *
 * @throws Exception//from   w w  w . j ava  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);
}