Example usage for javax.swing JOptionPane NO_OPTION

List of usage examples for javax.swing JOptionPane NO_OPTION

Introduction

In this page you can find the example usage for javax.swing JOptionPane NO_OPTION.

Prototype

int NO_OPTION

To view the source code for javax.swing JOptionPane NO_OPTION.

Click Source Link

Document

Return value from class method if NO is chosen.

Usage

From source file:org.apache.jmeter.gui.action.Save.java

@Override
public void doAction(ActionEvent e) throws IllegalUserActionException {
    HashTree subTree = null;/*from   w ww  . jav  a  2 s  .c om*/
    boolean fullSave = false; // are we saving the whole tree?
    if (!commands.contains(e.getActionCommand())) {
        throw new IllegalUserActionException("Invalid user command:" + e.getActionCommand());
    }
    if (e.getActionCommand().equals(ActionNames.SAVE_AS)) {
        JMeterTreeNode[] nodes = GuiPackage.getInstance().getTreeListener().getSelectedNodes();
        if (nodes.length > 1) {
            JMeterUtils.reportErrorToUser(JMeterUtils.getResString("save_as_error"), // $NON-NLS-1$
                    JMeterUtils.getResString("save_as")); // $NON-NLS-1$
            return;
        }
        subTree = GuiPackage.getInstance().getCurrentSubTree();
    } else if (e.getActionCommand().equals(ActionNames.SAVE_AS_TEST_FRAGMENT)) {
        JMeterTreeNode[] nodes = GuiPackage.getInstance().getTreeListener().getSelectedNodes();
        if (checkAcceptableForTestFragment(nodes)) {
            subTree = GuiPackage.getInstance().getCurrentSubTree();
            // Create Test Fragment node
            TestElement element = GuiPackage.getInstance()
                    .createTestElement(TestFragmentControllerGui.class.getName());
            HashTree hashTree = new ListedHashTree();
            HashTree tfTree = hashTree.add(new JMeterTreeNode(element, null));
            for (JMeterTreeNode node : nodes) {
                // Clone deeply current node
                TreeCloner cloner = new TreeCloner(false);
                GuiPackage.getInstance().getTreeModel().getCurrentSubTree(node).traverse(cloner);
                // Add clone to tfTree
                tfTree.add(cloner.getClonedTree());
            }

            subTree = hashTree;

        } else {
            JMeterUtils.reportErrorToUser(JMeterUtils.getResString("save_as_test_fragment_error"), // $NON-NLS-1$
                    JMeterUtils.getResString("save_as_test_fragment")); // $NON-NLS-1$
            return;
        }
    } else {
        fullSave = true;
        HashTree testPlan = GuiPackage.getInstance().getTreeModel().getTestPlan();
        // If saveWorkBench 
        if (isWorkbenchSaveable()) {
            HashTree workbench = GuiPackage.getInstance().getTreeModel().getWorkBench();
            testPlan.add(workbench);
        }
        subTree = testPlan;
    }

    String updateFile = GuiPackage.getInstance().getTestPlanFile();
    if (!ActionNames.SAVE.equals(e.getActionCommand()) || updateFile == null) {
        JFileChooser chooser = FileDialoger.promptToSaveFile(updateFile == null
                ? GuiPackage.getInstance().getTreeListener().getCurrentNode().getName() + JMX_FILE_EXTENSION
                : updateFile);
        if (chooser == null) {
            return;
        }
        updateFile = chooser.getSelectedFile().getAbsolutePath();
        // Make sure the file ends with proper extension
        if (FilenameUtils.getExtension(updateFile).isEmpty()) {
            updateFile = updateFile + JMX_FILE_EXTENSION;
        }
        // Check if the user is trying to save to an existing file
        File f = new File(updateFile);
        if (f.exists()) {
            int response = JOptionPane.showConfirmDialog(GuiPackage.getInstance().getMainFrame(),
                    JMeterUtils.getResString("save_overwrite_existing_file"), // $NON-NLS-1$
                    JMeterUtils.getResString("save?"), // $NON-NLS-1$
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            if (response == JOptionPane.CLOSED_OPTION || response == JOptionPane.NO_OPTION) {
                return; // Do not save, user does not want to overwrite
            }
        }

        if (!e.getActionCommand().equals(ActionNames.SAVE_AS)) {
            GuiPackage.getInstance().setTestPlanFile(updateFile);
        }
    }

    // backup existing file according to jmeter/user.properties settings
    List<File> expiredBackupFiles = EMPTY_FILE_LIST;
    File fileToBackup = new File(updateFile);
    try {
        expiredBackupFiles = createBackupFile(fileToBackup);
    } catch (Exception ex) {
        log.error("Failed to create a backup for " + fileToBackup.getName(), ex); //$NON-NLS-1$
    }

    try {
        convertSubTree(subTree);
    } catch (Exception err) {
        log.warn("Error converting subtree " + err);
    }

    FileOutputStream ostream = null;
    try {
        ostream = new FileOutputStream(updateFile);
        SaveService.saveTree(subTree, ostream);
        if (fullSave) { // Only update the stored copy of the tree for a full save
            subTree = GuiPackage.getInstance().getTreeModel().getTestPlan(); // refetch, because convertSubTree affects it
            if (isWorkbenchSaveable()) {
                HashTree workbench = GuiPackage.getInstance().getTreeModel().getWorkBench();
                subTree.add(workbench);
            }
            ActionRouter.getInstance()
                    .doActionNow(new ActionEvent(subTree, e.getID(), ActionNames.SUB_TREE_SAVED));
        }

        // delete expired backups : here everything went right so we can
        // proceed to deletion
        for (File expiredBackupFile : expiredBackupFiles) {
            try {
                FileUtils.deleteQuietly(expiredBackupFile);
            } catch (Exception ex) {
                log.warn("Failed to delete backup file " + expiredBackupFile.getName()); //$NON-NLS-1$
            }
        }
    } catch (Throwable ex) {
        log.error("Error saving tree:", ex);
        if (ex instanceof Error) {
            throw (Error) ex;
        }
        if (ex instanceof RuntimeException) {
            throw (RuntimeException) ex;
        }
        throw new IllegalUserActionException("Couldn't save test plan to file: " + updateFile, ex);
    } finally {
        JOrphanUtils.closeQuietly(ostream);
    }
    GuiPackage.getInstance().updateCurrentGui();
}

From source file:org.apache.pdfbox.debugger.PDFDebugger.java

/**
 * This will parse a document./*  ww w  . j  a  v  a2s .c om*/
 *
 * @param file The file addressing the document.
 * @throws IOException If there is an error parsing the document.
 */
private void parseDocument(File file, String password) throws IOException {
    while (true) {
        try {
            document = PDDocument.load(file, password);
        } catch (InvalidPasswordException ipe) {
            // https://stackoverflow.com/questions/8881213/joptionpane-to-get-password
            JPanel panel = new JPanel();
            JLabel label = new JLabel("Password:");
            JPasswordField pass = new JPasswordField(10);
            panel.add(label);
            panel.add(pass);
            String[] options = new String[] { "OK", "Cancel" };
            int option = JOptionPane.showOptionDialog(null, panel, "Enter password", JOptionPane.NO_OPTION,
                    JOptionPane.PLAIN_MESSAGE, null, options, "");
            if (option == 0) {
                password = new String(pass.getPassword());
                continue;
            }
            throw ipe;
        }
        break;
    }
    printMenuItem.setEnabled(true);
    reopenMenuItem.setEnabled(true);
}

From source file:org.archiviststoolkit.mydomain.DomainTableWorkSurface.java

/**
 * on insert display a blank editor and insert the results.
 *//*from   www.j ava2  s.  co  m*/

public final void onInsert() {
    // see if to load a plugin editor instead of using the one built into the AT
    if (usePluginDomainEditor(null, null)) {
        return; // custom editor was used to view/edit this record so just return
    }

    ApplicationFrame.editorOpen = true;

    Object instance = null;
    boolean done = false;
    boolean createNewInstance = true;
    DomainEditor dialog = DomainEditorFactory.getInstance().getDialog(clazz);
    dialog.disableNavigationButtons();
    dialog.clearRecordPositionText();
    dialog.setNewRecord(true);
    int returnStatus;

    while (!done) {
        boolean createObject = true;
        if (createNewInstance) {
            try {
                instance = clazz.newInstance();
            } catch (InstantiationException instantiationException) {
                new ErrorDialog(dialog, "Error creating new record.", instantiationException).showDialog();
            } catch (IllegalAccessException illegalAccessException) {
                new ErrorDialog(dialog, "Error creating new record.", illegalAccessException).showDialog();
            }
            if (clazz == Names.class) {
                String nameType = Names.selectNameType(rootComponent);
                if ((nameType != null) && (nameType.length() > 0)) {
                    ((Names) instance).setNameType(nameType);
                } else {
                    createObject = false;
                    done = true;
                }

            } else if (clazz == Accessions.class) {
                ((Accessions) instance)
                        .setRepository(ApplicationFrame.getInstance().getCurrentUserRepository());
            } else if (clazz == Resources.class) {
                ((Resources) instance).setRepository(ApplicationFrame.getInstance().getCurrentUserRepository());
                ((Resources) instance).markRecordAsNew();
            } else if (clazz == DigitalObjects.class) {
                ((DigitalObjects) instance)
                        .setRepository(ApplicationFrame.getInstance().getCurrentUserRepository());
            }
        } else {
            createNewInstance = true;
        }

        if (createObject) {

            dialog.setModel((DomainObject) instance, null);
            returnStatus = dialog.showDialog();
            int choice = dialog.getConfirmDialogReturn();
            Boolean savedNewRecord = dialog.getSavedNewRecord();

            try {
                if (returnStatus == javax.swing.JOptionPane.OK_OPTION) {
                    if (choice == JOptionPane.YES_OPTION) {
                        DomainAccessObject access = DomainAccessObjectFactory.getInstance()
                                .getDomainAccessObject(clazz);
                        if (!savedNewRecord) {
                            access.add((DomainObject) instance);
                        } else { // just update the record
                            access.updateLongSession((DomainObject) instance);
                        }

                        table.getEventList().add((DomainObject) instance);
                        updateRowCount();
                        addToPickers((DomainObject) instance);
                        done = true;
                    }
                } else if (returnStatus == StandardEditor.OK_AND_ANOTHER_OPTION) {
                    DomainAccessObject access = DomainAccessObjectFactory.getInstance()
                            .getDomainAccessObject(clazz);
                    if (!savedNewRecord) {
                        access.add(dialog.getModel());
                    } else {
                        access.updateLongSession((DomainObject) instance);
                    }
                    table.getEventList().add((DomainObject) instance);
                    updateRowCount();
                    addToPickers((DomainObject) instance);
                    dialog.setNewRecord(true);
                } else if (choice == JOptionPane.YES_OPTION) { // called when window is closed and data validated
                    DomainAccessObject access = DomainAccessObjectFactory.getInstance()
                            .getDomainAccessObject(clazz);
                    if (!savedNewRecord) {
                        access.add((DomainObject) instance);
                    } else {
                        access.updateLongSession((DomainObject) instance);
                    }

                    table.getEventList().add((DomainObject) instance);
                    updateRowCount();
                    addToPickers((DomainObject) instance);
                    done = true;
                } else if (choice == JOptionPane.NO_OPTION) {
                    if (savedNewRecord) { // already saved a new record so remove it
                        try {
                            DomainAccessObject access = DomainAccessObjectFactory.getInstance()
                                    .getDomainAccessObject(clazz);
                            access.closeLongSessionRollback();
                        } catch (SQLException e) {
                            new ErrorDialog(dialog, "Error canceling record.", e).showDialog();
                        }

                        //table.getEventList().add((DomainObject) instance);
                        long id = ((DomainObject) instance).getIdentifier();
                        table.getEventList().add(getSimpleDomainObject(id));
                        updateRowCount();
                        addToPickers((DomainObject) instance);
                    }
                    done = true;
                } else {
                    done = true;
                }

                // reset the savedNew field to false;
                dialog.setSavedNewRecord(false);

                // remove any record locks that may have been created
                clearCurrentRecordLock();
            } catch (ConstraintViolationException persistenceException) {
                String message = "Can't save, duplicate record " + instance;
                JOptionPane.showMessageDialog(ApplicationFrame.getInstance(), message);
                logger.error(message, persistenceException);
                ((DomainObject) instance).removeIdAndAuditInfo();
                createNewInstance = false;
            } catch (PersistenceException persistenceException) {
                if (persistenceException.getCause() instanceof ConstraintViolationException) {
                    String message = "Can't save, duplicate record " + instance;
                    JOptionPane.showMessageDialog(ApplicationFrame.getInstance(), message);
                    logger.error(message, persistenceException);
                    ((DomainObject) instance).removeIdAndAuditInfo();
                    createNewInstance = false;
                } else {
                    done = true;
                    new ErrorDialog(dialog, "Error saving new record.", persistenceException).showDialog();
                }
            } /*catch (DeleteException deleteException) {
              done = true;
              new ErrorDialog(dialog, "Error deleting saved record.", deleteException).showDialog();
              }*/
        }
    }
    dialog.setNewRecord(false);

    ApplicationFrame.editorOpen = false;
}

From source file:org.bibsonomy.plugin.jabref.worker.ImportPostsByCriteriaWorker.java

public void run() {

    dialog.setVisible(true);//from w w w  . jav a  2  s  .  co  m
    dialog.setProgress(0, 0);

    int numberOfPosts = 0, start = 0, end = PluginProperties.getNumberOfPostsPerRequest(), cycle = 0,
            numberOfPostsPerRequest = PluginProperties.getNumberOfPostsPerRequest();
    boolean continueFetching = false;
    do {
        numberOfPosts = 0;

        List<String> tags = null;
        String search = null;
        switch (type) {
        case TAGS:
            if (criteria.contains(" ")) {
                tags = Arrays.asList(criteria.split("\\s"));
            } else {
                tags = Arrays.asList(new String[] { criteria });
            }
            break;
        case FULL_TEXT:
            search = criteria;
            break;
        }

        try {

            final Collection<Post<BibTex>> result = getLogic().getPosts(BibTex.class, grouping, groupingValue,
                    tags, null, search, null, null, null, null, start, end);
            for (Post<? extends Resource> post : result) {
                dialog.setProgress(numberOfPosts++, numberOfPostsPerRequest);
                BibtexEntry entry = JabRefModelConverter.convertPost(post);

                // clear fields if the fetched posts does not belong to the
                // user
                if (!PluginProperties.getUsername().equals(entry.getField("username"))) {
                    entry.clearField("intrahash");
                    entry.clearField("interhash");
                    entry.clearField("file");
                    entry.clearField("owner");
                }
                dialog.addEntry(entry);
            }

            if (!continueFetching) {
                if (!ignoreRequestSize) {

                    if (!PluginProperties.getIgnoreMorePostsWarning()) {

                        if (numberOfPosts == numberOfPostsPerRequest) {
                            int status = JOptionPane.showOptionDialog(dialog,
                                    "<html>There are probably more than "
                                            + PluginProperties.getNumberOfPostsPerRequest()
                                            + " posts available. Continue importing?<br>You can stop importing entries by hitting the Stop button on the import dialog.",
                                    "More posts available", JOptionPane.YES_NO_OPTION,
                                    JOptionPane.WARNING_MESSAGE, null, null, JOptionPane.YES_OPTION);

                            switch (status) {
                            case JOptionPane.YES_OPTION:
                                continueFetching = true;
                                break;

                            case JOptionPane.NO_OPTION:
                                this.stopFetching();
                                break;
                            default:
                                break;
                            }
                        }
                    }
                }
            }
            start = ((cycle + 1) * numberOfPostsPerRequest);
            end = ((cycle + 2) * numberOfPostsPerRequest);

            cycle++;
        } catch (AuthenticationException ex) {
            (new ShowSettingsDialogAction((JabRefFrame) dialog.getOwner())).actionPerformed(null);
        } catch (Exception ex) {
            LOG.error("Failed to import posts", ex);
        }
    } while (fetchNext() && numberOfPosts >= numberOfPostsPerRequest);

    dialog.entryListComplete();
}

From source file:org.bigwiv.blastgraph.gui.BlastGraphFrame.java

private void refreshSubGraphView() {
    int count = curGraph.getVertexCount();
    int maxCount = Integer.parseInt(Global.SETTING.get("MAX_VERTICES"));
    if (count != 0) {
        graphStatisticsPanel.setGraph(curGraph);
        int edgeCount = curGraph.getEdgeCount();
        int vertexCount = curGraph.getVertexCount();
        double acc = 0;

        if (vertexCount != 1) {
            Map<HitVertex, Double> ccs = Metrics.clusteringCoefficients(curGraph);

            for (double cc : ccs.values()) {
                acc += cc;/*from   w  w  w  .  j  a v a 2s  . co m*/
            }

            acc = acc / ccs.size();
        }
        currentVertexCountLabel.setText("" + vertexCount);
        currentEdgeCountLabel.setText("" + edgeCount);
        currentAccLabel.setText(String.format("%1$.2f", acc));
        int option;
        if (count > maxCount) {
            option = JOptionPane.showConfirmDialog(this,
                    "Too large(" + count + " vertices>" + maxCount
                            + ") to be displayed.Are you sure to display it?",
                    "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
        } else {
            option = JOptionPane.YES_OPTION;
        }

        if (option == JOptionPane.NO_OPTION) {
            layout.setGraph(emptyGraph);
            vv.setGraphLayout(layout);
            vv.repaint();
            return;
        }

        vvPanel.setEnabled(true);
        tabbedPane.setEnabled(true);
        saveCurGraphMenu.setEnabled(true);
        modeMenu.setEnabled(true);
        layoutMenu.setEnabled(true);
        modeBox.setEnabled(true);
        layoutBox.setEnabled(true);
        graphStatisticsPanel.setEnabled(true);
    } else {
        vvPanel.setEnabled(false);
        tabbedPane.setEnabled(false);
        saveCurGraphMenu.setEnabled(false);
        currentVertexCountLabel.setText("0");
        currentEdgeCountLabel.setText("0");
        currentAccLabel.setText("0");
        selectedVertexCountLabel.setText("0");
        selectedEdgeCountLabel.setText("0");
        modeMenu.setEnabled(false);
        layoutMenu.setEnabled(false);
        modeBox.setEnabled(false);
        layoutBox.setEnabled(false);
        graphStatisticsPanel.setEnabled(false);

        int annotCount = annotationToolBar.getComponentCount();
        for (int i = 0; i < annotCount; i++) {
            annotationToolBar.getComponent(i).setEnabled(false);
        }
    }

    layout.setGraph(curGraph);
    vv.setGraphLayout(layout);
    vv.repaint();
}

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

private JMenuBar createMenuBar(final JPanel hiCPanel) {

    JMenuBar menuBar = new JMenuBar();

    //======== fileMenu ========
    JMenu fileMenu = new JMenu("File");

    //---- loadMenuItem ----
    JMenuItem loadMenuItem = new JMenuItem();
    loadMenuItem.setText("Load...");
    loadMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            loadMenuItemActionPerformed(e);
        }//from  www.  j  av  a  2  s . c  o m
    });
    fileMenu.add(loadMenuItem);

    //---- loadFromURL ----
    JMenuItem loadFromURL = new JMenuItem();
    JMenuItem getEigenvector = new JMenuItem();
    final JCheckBoxMenuItem viewDNAseI;

    loadFromURL.setText("Load from URL ...");
    loadFromURL.setName("loadFromURL");
    loadFromURL.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            loadFromURLActionPerformed(e);
        }
    });
    fileMenu.add(loadFromURL);
    fileMenu.addSeparator();

    // Pre-defined datasets.  TODO -- generate from a file
    addPredefinedLoadItems(fileMenu);

    JMenuItem saveToImage = new JMenuItem();
    saveToImage.setText("Save to image");
    saveToImage.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            BufferedImage image = (BufferedImage) createImage(1000, 1000);
            Graphics g = image.createGraphics();
            hiCPanel.paint(g);

            JFileChooser fc = new JFileChooser();
            fc.setSelectedFile(new File("image.png"));
            int actionDialog = fc.showSaveDialog(null);
            if (actionDialog == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                if (file.exists()) {
                    actionDialog = JOptionPane.showConfirmDialog(null, "Replace existing file?");
                    if (actionDialog == JOptionPane.NO_OPTION || actionDialog == JOptionPane.CANCEL_OPTION)
                        return;
                }
                try {
                    // default if they give no format or invalid format
                    String fmt = "jpg";
                    int ind = file.getName().indexOf(".");
                    if (ind != -1) {
                        String ext = file.getName().substring(ind + 1);
                        String[] strs = ImageIO.getWriterFormatNames();
                        for (String aStr : strs)
                            if (ext.equals(aStr))
                                fmt = ext;
                    }
                    ImageIO.write(image.getSubimage(0, 0, 600, 600), fmt, file);
                } catch (IOException ie) {
                    System.err.println("Unable to write " + file + ": " + ie);
                }
            }
        }
    });
    fileMenu.add(saveToImage);
    getEigenvector = new JMenuItem("Get principal eigenvector");
    getEigenvector.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            getEigenvectorActionPerformed(e);
        }
    });
    fileMenu.add(getEigenvector);
    //---- exit ----
    JMenuItem exit = new JMenuItem();
    exit.setText("Exit");
    exit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            exitActionPerformed(e);
        }
    });
    fileMenu.add(exit);

    menuBar.add(fileMenu);

    //======== Tracks menu ========

    JMenu tracksMenu = new JMenu("Tracks");

    viewEigenvector = new JCheckBoxMenuItem("View Eigenvector...");
    viewEigenvector.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (viewEigenvector.isSelected()) {
                if (eigenvectorTrack == null) {
                    eigenvectorTrack = new EigenvectorTrack("eigen", "Eigenvectors");
                }
                updateEigenvectorTrack();
            } else {
                trackPanel.setEigenvectorTrack(null);
                if (HiCTrackManager.getLoadedTracks().isEmpty()) {
                    trackPanel.setVisible(false);
                }
            }
        }
    });
    viewEigenvector.setEnabled(false);
    tracksMenu.add(viewEigenvector);

    JMenuItem loadItem = new JMenuItem("Load...");
    loadItem.addActionListener(new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            HiCTrackManager.loadHostedTrack(MainWindow.this);
        }

    });
    tracksMenu.add(loadItem);

    JMenuItem loadFromFileItem = new JMenuItem("Load from file...");
    loadFromFileItem.addActionListener(new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            HiCTrackManager.loadTrackFromFile(MainWindow.this);
        }

    });
    tracksMenu.add(loadFromFileItem);

    menuBar.add(tracksMenu);

    //======== Extras menu ========
    JMenu extrasMenu = new JMenu("Extras");

    JMenuItem dumpPearsons = new JMenuItem("Dump pearsons matrix ...");
    dumpPearsons.addActionListener(new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            BasicMatrix pearsons = hic.zd.getPearsons();
            try {
                String chr1 = hic.getChromosomes()[hic.zd.getChr1()].getName();
                String chr2 = hic.getChromosomes()[hic.zd.getChr2()].getName();
                int binSize = hic.zd.getBinSize();
                File initFile = new File("pearsons_" + chr1 + "_" + "_" + chr2 + "_" + binSize + ".bin");
                File f = FileDialogUtils.chooseFile("Save pearsons", null, initFile, FileDialogUtils.SAVE);
                if (f != null) {
                    ScratchPad.dumpPearsonsBinary(pearsons, chr1, chr2, hic.zd.getBinSize(), f);
                }
            } catch (IOException e) {
                e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
            }
        }

    });

    JMenuItem dumpEigenvector = new JMenuItem("Dump eigenvector ...");
    dumpEigenvector.addActionListener(new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            try {
                ScratchPad.dumpEigenvector(hic);
            } catch (IOException e) {
                e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
            }
        }

    });
    extrasMenu.add(dumpEigenvector);

    JMenuItem readPearsons = new JMenuItem("Read pearsons...");
    readPearsons.addActionListener(new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            try {
                File f = FileDialogUtils.chooseFile("Pearsons file (Yunfan format)");
                if (f != null) {
                    BasicMatrix bm = ScratchPad.readPearsons(f.getAbsolutePath());

                    hic.zd.setPearsons(bm);
                }
            } catch (IOException e) {
                e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
            }
        }

    });
    extrasMenu.add(readPearsons);

    extrasMenu.add(dumpPearsons);
    menuBar.add(extrasMenu);

    return menuBar;
}

From source file:org.docear.plugin.core.CoreConfiguration.java

/**
 * @param file/*from w ww . j  a  v a 2s .  c  o  m*/
 * @throws IOException
 */
private void createFile(File file) throws IOException {
    if (file.getParentFile() == null) {
        LogUtils.warn("missing parent directory for user.settings: " + file);
        LogUtils.warn("user.settings home: " + WorkspaceController.getApplicationSettingsHome());
        int option = JOptionPane.showConfirmDialog(null,
                "Your user settings directory has not been set or is set with the system root directory. \nThis might cause further issues. \n Do you want to continue?",
                "Settings home warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
        if (option == JOptionPane.NO_OPTION) {
            System.exit(1);
        }
    } else if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) {
        return;
    }
    file.createNewFile();
}

From source file:org.domainmath.gui.MainFrame.java

/**
 * It closes a file./*  w ww .j a v a  2  s  .com*/
 * @param selectedIndex 
 */
public void askSave(int selectedIndex) {
    String s = fileTab.getTitleAt(selectedIndex);

    if (s.endsWith("*")) { //modified document.
        String f = s.substring(0, s.lastIndexOf("*"));

        // ask to save file.
        int i = JOptionPane.showConfirmDialog(this, "Do you want to save changes in " + f + " ?",
                "DomainMath IDE", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);

        if (i == JOptionPane.YES_OPTION) { //need to save file

            // add this file to recent menu list.
            File selected_file = new File(fileTab.getToolTipTextAt(selectedIndex));
            recentFileMenu.addEntry(selected_file.getAbsolutePath());

            // save the file.
            save(selected_file, selectedIndex);

            // close the file.
            this.removeFileNameFromList(selectedIndex);
            fileTab.remove(selectedIndex);
            FILE_TAB_INDEX--;

        } else if (i == JOptionPane.NO_OPTION) { // I dont need to save the file.

            // add this file to recent menu list.
            File selected_file = new File(fileTab.getToolTipTextAt(selectedIndex));
            recentFileMenu.addEntry(selected_file.getAbsolutePath());

            // close the file.
            this.removeFileNameFromList(selectedIndex);
            fileTab.remove(selectedIndex);
            FILE_TAB_INDEX--;

        }
    } else { //unmodified file.

        // add this file to recent menu list.
        File selected_file = new File(fileTab.getToolTipTextAt(selectedIndex));
        recentFileMenu.addEntry(selected_file.getAbsolutePath());

        // close the file.
        removeFileNameFromList(selectedIndex);
        fileTab.remove(selectedIndex);
        FILE_TAB_INDEX--;
    }
}

From source file:org.executequery.components.FileChooserDialog.java

public int showSaveDialog(Component parent) throws HeadlessException {
    int result = super.showSaveDialog(parent);
    File file = getSelectedFile();

    if (file == null || result == CANCEL_OPTION) {
        return CANCEL_OPTION;
    }/*  w w  w  .j a v  a 2 s  .  com*/

    if (file.exists()) {
        int _result = GUIUtilities.displayConfirmCancelDialog("Overwrite existing file?");

        if (_result == JOptionPane.CANCEL_OPTION) {
            return CANCEL_OPTION;
        } else if (_result == JOptionPane.NO_OPTION) {
            return showSaveDialog(parent);
        }

    }

    return result;
}

From source file:org.executequery.gui.ExportResultSetPanel.java

public void browse() {

    FileChooserDialog fileChooser = new FileChooserDialog();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setMultiSelectionEnabled(false);

    fileChooser.setDialogTitle("Select Export File Path");
    fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);

    int result = fileChooser.showDialog(GUIUtilities.getInFocusDialogOrWindow(), "Select");
    if (result == JFileChooser.CANCEL_OPTION) {

        return;//from www . j  av a2s  .  com
    }

    File file = fileChooser.getSelectedFile();
    if (file.exists()) {

        result = GUIUtilities.displayConfirmCancelDialog("The selected file exists.\nOverwrite existing file?");

        if (result == JOptionPane.CANCEL_OPTION || result == JOptionPane.NO_OPTION) {

            browse();
            return;
        }

    }

    fileNameField.setText(file.getAbsolutePath());
}