Example usage for java.awt FileDialog LOAD

List of usage examples for java.awt FileDialog LOAD

Introduction

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

Prototype

int LOAD

To view the source code for java.awt FileDialog LOAD.

Click Source Link

Document

This constant value indicates that the purpose of the file dialog window is to locate a file from which to read.

Usage

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

/**
 * /*from ww  w  .jav  a2 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   www.  ja va  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: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");
        }//www.java 2s. c  om

    });
    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()
    }
}

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

/**
 * //from  w ww  . ja v  a  2  s  .  c  o  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: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);//from   w ww .  ja  v a  2 s.  c o m
                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");
                    }
                });
                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:base.BasePlayer.Main.java

public void actionPerformed(ActionEvent e) {
    //Logo.frame.setVisible(false);
    if (e.getSource() == pleiadesButton) {
        gotoURL("http://kaptah.local.lab.helsinki.fi/pleiades/");

    } else if (e.getSource() == manage) {

        if (VariantHandler.frame == null) {
            VariantHandler.main(argsit);
        }/*w w w  .  j  ava  2s  .co  m*/
        VariantHandler.frame.setLocation(
                frame.getLocationOnScreen().x + frame.getWidth() / 2 - VariantHandler.frame.getWidth() / 2,
                frame.getLocationOnScreen().y + frame.getHeight() / 6);

        VariantHandler.frame.setState(JFrame.NORMAL);
        VariantHandler.frame.setVisible(true);
        Draw.calculateVars = true;
        Draw.updatevars = true;
        drawCanvas.repaint();

    } else if (e.getSource() == tbrowser) {
        tablebrowser.frame.setLocation(
                frame.getLocationOnScreen().x + frame.getWidth() / 2 - VariantCaller.frame.getWidth() / 2,
                frame.getLocationOnScreen().y + frame.getHeight() / 6);
        tablebrowser.frame.setState(JFrame.NORMAL);

        tablebrowser.frame.setVisible(true);
    } else if (e.getSource() == bconvert) {
        bedconverter.frame.setLocation(
                frame.getLocationOnScreen().x + frame.getWidth() / 2 - VariantCaller.frame.getWidth() / 2,
                frame.getLocationOnScreen().y + frame.getHeight() / 6);
        bedconverter.frame.setState(JFrame.NORMAL);

        bedconverter.frame.setVisible(true);
    } else if (e.getSource() == peakCaller) {
        if (PeakCaller.frame == null) {

            PeakCaller.main(argsit);

        }
        PeakCaller.frame.setLocation(
                frame.getLocationOnScreen().x + frame.getWidth() / 2 - VariantCaller.frame.getWidth() / 2,
                frame.getLocationOnScreen().y + frame.getHeight() / 6);
        PeakCaller.frame.setState(JFrame.NORMAL);
        PeakCaller.frame.setVisible(true);
    } else if (e.getSource() == variantCaller) {

        //FileRead.checkSamples();

        if (VariantCaller.frame == null) {

            VariantCaller.main(argsit);

        }
        VariantCaller.frame.setLocation(
                frame.getLocationOnScreen().x + frame.getWidth() / 2 - VariantCaller.frame.getWidth() / 2,
                frame.getLocationOnScreen().y + frame.getHeight() / 6);
        VariantCaller.frame.setState(JFrame.NORMAL);
        VariantCaller.frame.setVisible(true);
    } else if (e.getSource() == average) {
        if (Average.frame == null) {
            Average.createAndShowGUI();
        }
        Average.setSamples();

        Average.frame.setLocation(
                frame.getLocationOnScreen().x + frame.getWidth() / 2 - Average.frame.getWidth() / 2,
                frame.getLocationOnScreen().y + frame.getHeight() / 6);

        Average.frame.setState(JFrame.NORMAL);
        Average.frame.setVisible(true);
    } else if (e.getSource() == errorlog) {

        ErrorLog.frame.setLocation(
                frame.getLocationOnScreen().x + frame.getWidth() / 2 - ErrorLog.frame.getWidth() / 2,
                frame.getLocationOnScreen().y + frame.getHeight() / 6);

        //      VariantHandler.frame.setAlwaysOnTop(true);   
        ErrorLog.frame.setState(JFrame.NORMAL);
        ErrorLog.frame.setVisible(true);

    }
    /*   else if(e.getSource() == help) {
          JOptionPane.showMessageDialog(Main.chromDraw, "This is pre-release version of BasePlayer\nContact: help@baseplayer.fi\nUniversity of Helsinki", "Help", JOptionPane.INFORMATION_MESSAGE);
       }*/
    else if (e.getSource() == settings) {

        Settings.frame.setLocation(
                frame.getLocationOnScreen().x + frame.getWidth() / 2 - Settings.frame.getWidth() / 2,
                frame.getLocationOnScreen().y + frame.getHeight() / 6);

        Settings.frame.setState(JFrame.NORMAL);
        Settings.frame.setVisible(true);
    } else if (e.getSource() == update) {
        try {
            Updater update = new Updater();
            update.execute();

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

    } else if (e.getSource() == clearMemory) {
        FileRead.nullifyVarNodes();

        //FileRead.removeNonListVariants();f
        System.gc();
        chromDraw.repaint();
    } else if (e.getSource() == zoomout) {

        zoomout();
    } else if (e.getSource() == dosomething) {

        BedNode currentbed = bedCanvas.bedTrack.get(0).getHead().getNext();
        VarNode currentvar = FileRead.head.getNext();

        while (currentbed != null) {

            while (currentvar != null && currentvar.getPosition() < currentbed.getPosition()) {
                currentvar = currentvar.getNext();
            }
            while (currentbed != null
                    && currentvar.getPosition() > currentbed.getPosition() + currentbed.getLength()) {
                currentbed = currentbed.getNext();
            }

            if (currentvar != null && currentvar.getPosition() >= currentbed.getPosition()
                    && currentvar.getPosition() < currentbed.getPosition() + currentbed.getLength()) {
                currentvar.setBedhit(true);
                currentvar = currentvar.getNext();
            }
            if (currentvar == null) {
                break;
            }
            currentbed = currentbed.getNext();
        }

    } else if (e.getSource() == clear) {
        clearData();
    } else if (e.getSource() == exit) {

        System.exit(0);
    } else if (e.getSource() == openbams) {
        try {
            if (!checkGenome())
                return;
            if (VariantHandler.frame != null) {
                VariantHandler.frame.setState(Frame.ICONIFIED);
            }

            FileDialog fc = new FileDialog(frame, "Choose BAM file(s)", FileDialog.LOAD);
            fc.setDirectory(path);
            fc.setFile("*.bam;*.cram;*.link");
            fc.setFilenameFilter(new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    return name.toLowerCase().endsWith(".bam") || name.toLowerCase().endsWith(".cram")
                            || name.toLowerCase().endsWith(".link");
                }
            });
            fc.setMultipleMode(true);
            fc.setVisible(true);
            File[] openfiles = fc.getFiles();

            if (openfiles != null && openfiles.length > 0) {

                path = openfiles[0].getParent();
                writeToConfig("DefaultDir=" + path);
                FileRead filereader = new FileRead(openfiles);

                filereader.start = (int) drawCanvas.selectedSplit.start;
                filereader.end = (int) drawCanvas.selectedSplit.end;
                filereader.readBAM = true;
                filereader.execute();

            } else {
                //Main.showError("File(s) does not exist.", "Error");
            }

        } catch (Exception ex) {
            Main.showError(ex.getMessage(), "Error");
        }
    } else if (e.getSource() == openvcfs) {
        try {
            if (!checkGenome())
                return;
            if (VariantHandler.frame != null) {
                VariantHandler.frame.setState(Frame.ICONIFIED);
            }

            FileDialog fc = new FileDialog(frame, "Choose VCF file(s)", FileDialog.LOAD);
            fc.setDirectory(path);
            fc.setFile("*.vcf");
            fc.setFilenameFilter(new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    return name.toLowerCase().endsWith(".vcf") || name.toLowerCase().endsWith(".vcf.gz");
                }
            });

            fc.setMultipleMode(true);
            fc.setVisible(true);
            File[] openfiles = fc.getFiles();

            if (openfiles != null && openfiles.length > 0) {

                path = openfiles[0].getParent();
                writeToConfig("DefaultDir=" + path);
                FileRead filereader = new FileRead(openfiles);

                filereader.start = (int) drawCanvas.selectedSplit.start;
                filereader.end = (int) drawCanvas.selectedSplit.end;
                filereader.readVCF = true;
                filereader.execute();

            } else {
                //Main.showError("File(s) does not exist.", "Error");
            }

            if (1 == 1) {
                return;
            }

            JFileChooser chooser = new JFileChooser(path);
            getText(chooser.getComponents());
            chooser.setMultiSelectionEnabled(true);
            //chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            chooser.setAcceptAllFileFilterUsed(false);
            chooser.addChoosableFileFilter(vcfFilter);
            chooser.addChoosableFileFilter(bamFilter);
            chooser.addChoosableFileFilter(linkFilter);
            if (defaultSelectType == "vcf") {
                chooser.setFileFilter(vcfFilter);
            } else if (defaultSelectType == "bam") {
                chooser.setFileFilter(bamFilter);
            } else {
                chooser.setFileFilter(linkFilter);
            }
            chooser.setDialogTitle("Add samples");
            chooser.setPreferredSize(
                    new Dimension((int) screenSize.getWidth() / 3, (int) screenSize.getHeight() / 3));
            int returnVal = chooser.showOpenDialog((Component) this.getParent());

            if (returnVal == JFileChooser.APPROVE_OPTION) {

                File vcffiles[] = chooser.getSelectedFiles();
                if (vcffiles.length == 1 && !vcffiles[0].exists() && pleiades) {

                    if (Main.chooserText.contains("`")) {
                        Main.chooserText.replace("`", "?");
                    }
                    if (Main.chooserText.contains(" ")) {
                        Main.chooserText.replace(" ", "%20");
                    }
                    if (Main.chooserText.contains("pleiades")) {
                        try {
                            URL url = new URL(Main.chooserText);
                            //System.out.println(Main.chooserText);
                            HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
                            httpConn.connect();

                            int responseCode = httpConn.getResponseCode();

                            if (responseCode == HttpsURLConnection.HTTP_OK) {

                                String loading = drawCanvas.loadingtext;
                                InputStream inputStream = httpConn.getInputStream();
                                BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
                                Main.drawCanvas.loadingtext = loading + " 0MB";
                                String line;
                                StringBuffer buffer = new StringBuffer("");
                                while ((line = reader.readLine()) != null) {

                                    buffer.append(line);

                                }
                                inputStream.close();
                                reader.close();
                                String split2;
                                String[] split = buffer.toString().split("dataUnit");
                                String location;
                                ArrayList<File> array = new ArrayList<File>();
                                File[] paths;
                                FileSystemView fsv = FileSystemView.getFileSystemView();
                                paths = File.listRoots();
                                String loc = "/mnt";
                                boolean missingfiles = false;
                                for (File path : paths) {
                                    if (fsv.getSystemDisplayName(path).contains("merit")) {
                                        loc = path.getCanonicalPath();
                                    }
                                }

                                for (int i = 0; i < split.length; i++) {

                                    if (!split[i].contains("lastLocation")) {

                                        continue;
                                    }

                                    split2 = split[i].split("\"lastLocation\":\"")[1];
                                    location = split2.substring(0, split2.indexOf("\"}"));
                                    String filename = "";
                                    String testloc = location.replace("/mnt", loc) + "/wgspipeline/";
                                    File testDir = new File(testloc);
                                    if (testDir.exists() && testDir.isDirectory()) {
                                        if (chooser.getFileFilter()
                                                .equals(chooser.getChoosableFileFilters()[1])) {
                                            File[] addDir = testDir.listFiles(new FilenameFilter() {
                                                public boolean accept(File dir, String name) {
                                                    return name.toLowerCase().endsWith(".bam")
                                                            || name.toLowerCase().endsWith(".cram");
                                                }
                                            });
                                            if (addDir.length > 0) {
                                                filename = addDir[0].getName();
                                            }
                                        } else {
                                            File[] addDir = testDir.listFiles(new FilenameFilter() {
                                                public boolean accept(File dir, String name) {
                                                    return name.toLowerCase().endsWith(".vcf.gz");
                                                }
                                            });
                                            if (addDir.length > 0) {
                                                filename = addDir[0].getName();
                                            }
                                        }
                                    }

                                    location = testloc + "/" + filename;

                                    if (!new File(location).exists()) {

                                        if (!new File(location).exists()) {
                                            missingfiles = true;
                                            ErrorLog.addError("No sample files found in " + testloc);

                                        } else {
                                            array.add(new File(location));
                                        }
                                    } else {

                                        array.add(new File(location));
                                    }
                                }

                                File[] files = new File[array.size()];
                                for (int i = 0; i < files.length; i++) {

                                    files[i] = array.get(i);
                                }
                                FileRead filereader = new FileRead(files);
                                filereader.start = (int) drawCanvas.selectedSplit.start;
                                filereader.end = (int) drawCanvas.selectedSplit.end;
                                if (chooser.getFileFilter().equals(chooser.getChoosableFileFilters()[1])) {
                                    filereader.readBAM = true;
                                } else {
                                    filereader.readVCF = true;
                                }
                                filereader.execute();
                                if (missingfiles) {
                                    JOptionPane.showMessageDialog(Main.drawScroll,
                                            "Missing files. Check Tools->View log", "Note",
                                            JOptionPane.INFORMATION_MESSAGE);
                                }

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

                    return;
                }

                if (vcffiles.length > 0) {
                    path = vcffiles[0].getParent();
                    writeToConfig("DefaultDir=" + path);
                    FileRead filereader = new FileRead(vcffiles);

                    if (chooser.getFileFilter().equals(chooser.getChoosableFileFilters()[0])) {
                        defaultSelectType = "vcf";
                        filereader.start = (int) drawCanvas.selectedSplit.start;
                        filereader.end = (int) drawCanvas.selectedSplit.end;
                        filereader.readVCF = true;
                        filereader.execute();
                    } else if (chooser.getFileFilter().equals(chooser.getChoosableFileFilters()[1])) {
                        defaultSelectType = "bam";
                        filereader.readBAM = true;
                        filereader.execute();
                    } else if (chooser.getFileFilter().equals(chooser.getChoosableFileFilters()[2])) {

                        defaultSelectType = "link";
                        filereader.readBAM = true;
                        filereader.execute();
                    }
                } else {

                    JOptionPane.showMessageDialog(Main.drawScroll,
                            "The file does not exist. The file link may be broken.\nThe problem may also be the Java run time version in Linux.",
                            "Note", JOptionPane.INFORMATION_MESSAGE);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    } else if (e.getSource() == addcontrols) {
        if (!checkGenome())
            return;
        if (VariantHandler.frame != null) {
            VariantHandler.frame.setState(Frame.ICONIFIED);
        }
        FileDialog fc = new FileDialog(frame, "Choose control file(s)", FileDialog.LOAD);
        fc.setDirectory(Main.controlDir);
        fc.setFile("*.vcf.gz");
        fc.setFilenameFilter(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return name.toLowerCase().endsWith(".vcf.gz");
            }
        });
        fc.setMultipleMode(true);
        fc.setVisible(true);
        File[] openfiles = fc.getFiles();

        if (openfiles != null && openfiles.length > 0) {

            controlDir = openfiles[0].getParent();
            writeToConfig("DefaultControlDir=" + controlDir);

            Control.addFiles(openfiles);
        }
        if (1 == 1) {
            return;
        }
        JFileChooser chooser = new JFileChooser(controlDir);
        //        JFileChooser chooser = new JFileChooser(path);            
        chooser.setMultiSelectionEnabled(true);
        chooser.setAcceptAllFileFilterUsed(false);
        Control.MyFilter vcfFilter = new Control.MyFilter();
        chooser.addChoosableFileFilter(vcfFilter);

        chooser.setDialogTitle("Add controls");
        chooser.setPreferredSize(
                new Dimension((int) screenSize.getWidth() / 3, (int) screenSize.getHeight() / 3));
        int returnVal = chooser.showOpenDialog((Component) this.getParent());

        if (returnVal == JFileChooser.APPROVE_OPTION) {

            File vcffiles[] = chooser.getSelectedFiles();
            controlDir = vcffiles[0].getParent();
            writeToConfig("DefaultControlDir=" + controlDir);

            if (chooser.getFileFilter().equals(chooser.getChoosableFileFilters()[0])) {
                Control.addFiles(vcffiles);
            }
        }
    } else if (e.getSource() == addtracks) {
        if (!checkGenome())
            return;
        try {
            if (!checkGenome())
                return;
            if (VariantHandler.frame != null) {
                VariantHandler.frame.setState(Frame.ICONIFIED);
            }

            FileDialog fc = new FileDialog(frame, "Choose track file(s)", FileDialog.LOAD);
            fc.setDirectory(Main.trackDir);
            fc.setFile(
                    "*.bed;*.bedgraph.gz;*.gff.gz;*.gff3.gz;*.bigwig;*.bw;*.bigbed;*.bb;*.tsv.gz;*.tsv.bgz;*.txt");
            fc.setFilenameFilter(new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    return name.toLowerCase().endsWith(".bed") || name.toLowerCase().endsWith(".bed.gz")
                            || name.toLowerCase().endsWith(".bedgraph.gz")
                            || name.toLowerCase().endsWith(".bedgraph.gz")
                            || name.toLowerCase().endsWith(".bedgraph.gz")
                            || name.toLowerCase().endsWith(".gff.gz") || name.toLowerCase().endsWith(".gff3.gz")
                            || name.toLowerCase().endsWith(".bigwig") || name.toLowerCase().endsWith(".bw")
                            || name.toLowerCase().endsWith(".bigbed") || name.toLowerCase().endsWith(".bb")
                            || name.toLowerCase().endsWith(".tsv.gz") || name.toLowerCase().endsWith(".tsv.bgz")
                            || name.toLowerCase().endsWith(".txt");
                }
            });
            fc.setMultipleMode(true);
            fc.setVisible(true);
            File[] openfiles = fc.getFiles();

            if (openfiles != null && openfiles.length > 0) {

                trackDir = openfiles[0].getParent();
                writeToConfig("DefaultTrackDir=" + trackDir);
                FileRead filereader = new FileRead(openfiles);
                filereader.readBED = true;
                filereader.execute();

            } else {
                //Main.showError("File(s) does not exist.", "Error");
            }

        } catch (Exception ex) {
            Main.showError(ex.getMessage(), "Error");
        }
        if (1 == 1) {
            return;
        }
        if (VariantHandler.frame != null) {
            VariantHandler.frame.setState(Frame.ICONIFIED);
        }
        JFileChooser chooser = new JFileChooser(Main.trackDir);
        getText(chooser.getComponents());
        chooser.setMultiSelectionEnabled(true);
        chooser.setAcceptAllFileFilterUsed(false);
        MyFilterBED bedFilter = new MyFilterBED();
        MyFilterTXT txtFilter = new MyFilterTXT();
        chooser.addChoosableFileFilter(bedFilter);
        chooser.addChoosableFileFilter(txtFilter);
        chooser.setDialogTitle("Add tracks");
        chooser.setPreferredSize(
                new Dimension((int) screenSize.getWidth() / 3, (int) screenSize.getHeight() / 3));
        int returnVal = chooser.showOpenDialog((Component) this.getParent());

        try {

            if (returnVal == JFileChooser.APPROVE_OPTION) {

                File bedfiles[] = chooser.getSelectedFiles();
                if (bedfiles[0].exists()) {

                    trackDir = bedfiles[0].getParent();
                    writeToConfig("DefaultTrackDir=" + trackDir);
                    FileRead filereader = new FileRead(bedfiles);
                    filereader.readBED(bedfiles);

                } else {

                    if (Main.chooserText.length() > 5 && Main.chooserText.endsWith(".bed.gz")
                            || Main.chooserText.endsWith(".gff.gz") || Main.chooserText.endsWith(".gff3.gz")
                            || Main.chooserText.endsWith(".bedgraph.gz")) {

                        if (Main.chooserText.startsWith("http://") || Main.chooserText.startsWith("ftp://")) {

                            URL url = new URL(Main.chooserText);
                            SeekableStream stream = SeekableStreamFactory.getInstance().getStreamFor(url);
                            TabixReader tabixReader = null;
                            String index = null;

                            try {
                                tabixReader = new TabixReader(Main.chooserText, Main.chooserText + ".tbi",
                                        stream);
                                index = Main.chooserText + ".tbi";
                            } catch (Exception ex) {
                                try {
                                    tabixReader = new TabixReader(Main.chooserText,
                                            Main.chooserText.substring(0, Main.chooserText.indexOf(".gz"))
                                                    + ".tbi",
                                            stream);
                                    index = Main.chooserText.substring(0, Main.chooserText.indexOf(".gz"))
                                            + ".tbi";
                                } catch (Exception exc) {
                                    exc.printStackTrace();
                                }
                            }
                            if (tabixReader != null && index != null) {

                                FileRead filereader = new FileRead(bedfiles);
                                filereader.readBED(Main.chooserText, index, false);

                                tabixReader.close();
                            }
                        }
                    } else {
                        if (Main.chooserText.contains("://")) {

                            try {
                                //        bbreader = new BBFileReader(Main.chooserText, stream);

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

                            //  if(bbreader != null) {

                            FileRead filereader = new FileRead(bedfiles);
                            filereader.readBED(Main.chooserText, "nan", false);

                            //     }
                            //     stream.close();
                        }
                    }
                }
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else if (e.getSource() == openProject) {
        if (!checkGenome())
            return;
        if (VariantHandler.frame != null) {
            VariantHandler.frame.setState(Frame.ICONIFIED);
        }
        openProject();
    } else if (e.getSource() == saveProjectAs) {
        if (VariantHandler.frame != null) {
            VariantHandler.frame.setState(Frame.ICONIFIED);
        }
        try {
            File savefile = null;
            FileDialog fs = new FileDialog(frame, "Save project as...", FileDialog.SAVE);
            fs.setDirectory(projectDir);
            fs.setFile("*.ses");
            fs.setFilenameFilter(new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    return name.toLowerCase().endsWith(".ses");
                }
            });
            fs.setVisible(true);

            while (true) {
                String filename = fs.getFile();

                if (filename != null) {
                    savefile = new File(fs.getDirectory() + "/" + filename);
                    projectDir = fs.getDirectory();
                    writeToConfig("DefaultProjectDir=" + projectDir);

                    /* if(!Files.isWritable(Paths.get(savefile.getParent()))) {
                       Main.showError("No permission to write.", "Error");
                       continue;
                     }*/

                    if (!savefile.getAbsolutePath().endsWith(".ses")) {
                        savefile = new File(savefile.getAbsolutePath() + ".ses");
                    }

                    Serializer ser = new Serializer();
                    ser.serialize(savefile);
                    break;
                } else {
                    break;
                }
            }
            if (1 == 1) {
                return;
            }
            JFileChooser chooser = new JFileChooser();
            chooser.setAcceptAllFileFilterUsed(false);
            MyFilterSES sesFilter = new MyFilterSES();
            chooser.addChoosableFileFilter(sesFilter);
            chooser.setDialogTitle("Save project as...");
            int returnVal = chooser.showSaveDialog((Component) this.getParent());

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File outfile = chooser.getSelectedFile();
                if (!outfile.getAbsolutePath().endsWith(".ses")) {
                    outfile = new File(outfile.getAbsolutePath() + ".ses");
                }

                Serializer ser = new Serializer();
                ser.serialize(outfile);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    } else if (e.getSource() == saveProject) {
        if (drawCanvas.drawVariables.projectName.equals("Untitled")) {
            saveProjectAs.doClick();
        } else {

            Serializer ser = new Serializer();
            ser.serialize(drawCanvas.drawVariables.projectFile);
        }
    }
    /*      else if(e.getSource() == welcome) {
             WelcomeScreen.main(args);
             WelcomeScreen.frame.setVisible(true);
             WelcomeScreen.frame.setLocation(frame.getLocationOnScreen().x+frame.getWidth()/2 - WelcomeScreen.frame.getWidth()/2, frame.getLocationOnScreen().y+frame.getHeight()/6);
                     
          }*/
}

From source file:base.BasePlayer.Main.java

void openProject() {

    /*JFileChooser chooser = new JFileChooser(Main.projectDir);   
            /*  ww  w  .  j a  v  a2 s . c  om*/
    chooser.setAcceptAllFileFilterUsed(false);
      MyFilterSES sesFilter = new MyFilterSES();            
      chooser.addChoosableFileFilter(sesFilter);
      chooser.setDialogTitle("Open project");
      chooser.setPreferredSize(new Dimension((int)screenSize.getWidth()/3, (int)screenSize.getHeight()/3));
     int returnVal = chooser.showOpenDialog((Component)this.getParent());                        
     */
    FileRead.asked = false;

    FileDialog fc = new FileDialog(frame, "Choose project file", FileDialog.LOAD);
    fc.setDirectory(Main.projectDir);
    fc.setFile("*.ses");
    fc.setFilenameFilter(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".ses");
        }
    });
    fc.setMultipleMode(false);
    fc.setVisible(true);
    String openfile = fc.getFile();

    if (openfile != null) {
        File addfile = new File(fc.getDirectory() + "/" + openfile);
        projectDir = fc.getDirectory();
        writeToConfig("DefaultProjectDir=" + projectDir);
        clearData();
        OpenProject opener = new OpenProject(addfile);
        opener.execute();
    }
    /* if (returnVal == JFileChooser.APPROVE_OPTION) {
                   
           projectDir = chooser.getSelectedFile().getParent();       
         writeToConfig("DefaultProjectDir=" +projectDir);
         OpenProject opener = new OpenProject(chooser.getSelectedFile());
         opener.execute();
     }*/
}

From source file:no.java.swing.SingleSelectionFileDialog.java

private Result showNativeDialog(Component target, boolean open) {
    Window window = target == null ? null : (Frame) SwingUtilities.getWindowAncestor(target);
    FileDialog dialog;//from   w w w.j a  v  a2s  .co  m
    if (window instanceof Frame) {
        dialog = new FileDialog((Frame) window);
    } else if (window instanceof Dialog) {
        dialog = new FileDialog((Dialog) window);
    } else {
        throw new IllegalStateException("Unknown window type");
    }
    dialog.setDirectory(previousDirectory.getAbsolutePath());
    dialog.setMode(open ? FileDialog.LOAD : FileDialog.SAVE);
    dialog.setVisible(true);
    if (rememberPreviousLocation) {
        previousDirectory = new File(dialog.getDirectory());
    }
    if (dialog.getFile() == null) {
        return Result.CANCEL;
    }
    selected = new File(dialog.getFile());
    return Result.APPROVE;
}

From source file:org.broad.igv.hic.MainWindow.java

private void loadMenuItemActionPerformed(ActionEvent e) {
    FileDialog dlg = new FileDialog(this);
    dlg.setMode(FileDialog.LOAD);
    dlg.setVisible(true);/*from  w w w  . jav  a2s.c  om*/
    String file = dlg.getFile();
    if (file != null) {
        try {
            File f = new File(dlg.getDirectory(), dlg.getFile());
            load(f.getAbsolutePath());
        } catch (IOException e1) {
            e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }
    }
}

From source file:org.jivesoftware.spark.plugin.fileupload.ChatRoomDecorator.java

private void getUploadUrl(ChatRoom room, Message.Type type) {
    FileDialog fd = new FileDialog((Frame) null, "Choose a file to upload", FileDialog.LOAD);
    fd.setMultipleMode(true);//from  w w w . j  a  v  a2s  .  co m
    fd.setVisible(true);
    File files[] = fd.getFiles();

    for (File file : files) {
        handleUpload(file, room, type);
    }
}