Example usage for javax.swing JOptionPane QUESTION_MESSAGE

List of usage examples for javax.swing JOptionPane QUESTION_MESSAGE

Introduction

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

Prototype

int QUESTION_MESSAGE

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

Click Source Link

Document

Used for questions.

Usage

From source file:GUI.MainWindow.java

private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed
    System.out.println("Export to excel clicked");
    DefaultTreeModel dtm = (DefaultTreeModel) this.VulnTree.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) dtm.getRoot();
    System.out.println("Child Count: " + root.getChildCount());
    if (root.getChildCount() == 0) {
        System.out.println("No vulns in tree. Halting the export");
        return;//from w  w  w. j  a  v  a2  s .co m
    }

    // If we get here then there are some vulns.
    // Prompt for an export file.
    boolean proceed = true;
    int returnVal = this.fileChooser.showSaveDialog(this);

    if (returnVal == JFileChooser.APPROVE_OPTION) {

        File save_file = fileChooser.getSelectedFile();
        System.out.println(save_file);

        if (save_file.exists() == true) {

            int response = JOptionPane.showConfirmDialog(null,
                    "Are you sure you want to replace existing file?", "Confirm", JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE);
            if (response == JOptionPane.NO_OPTION) {
                proceed = false;
            }
        }

        if (proceed == true) {

            ExportToExcel excelOut = new ExportToExcel();
            try {
                excelOut.writeExcel(save_file, root);
            } catch (IOException ex) {
                ex.printStackTrace();
                JOptionPane.showMessageDialog(null, ex);
            } catch (WriteException ex) {
                ex.printStackTrace();
                JOptionPane.showMessageDialog(null, ex);
            }

        }

    }

}

From source file:com.itemanalysis.jmetrik.gui.Jmetrik.java

/**
 * Saving file happen in its own thread//from   w  ww . j  a v a  2  s .c  o m
 */
private void save(JmetrikTextFile textFile, JmetrikTab tab) {
    File f = null;
    if (!textFile.hasFile()) {
        f = fileUtils.chooseFileToSave(Jmetrik.this, textFile.getFile());
        if (f != null) {
            Toolkit.getDefaultToolkit().beep();
            int question = JOptionPane.showConfirmDialog(Jmetrik.this,
                    f.getName() + " already fileExists. Do you want to overwrite it?", "File Exists",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            if (question == JOptionPane.YES_OPTION) {
                textFile.fileSave(f, tab);
            }
        }
    } else {
        textFile.fileSave(tab);
    }
}

From source file:com.archivas.clienttools.arcmover.gui.panels.ProfilePanel.java

public void mkdirActionAux() {
    try {//from   ww  w. jav a 2  s. co  m
        String newDirName;
        String newDirPath = null;

        do {
            // get new directory name from user
            newDirName = (String) JOptionPane.showInputDialog(this.getParent(), "Name of new directory",
                    "New Directory", JOptionPane.QUESTION_MESSAGE, null, null, "directory name");

            // check if user pressed 'cancel' button
            if (newDirName == null) {
                LOG.info("Mkdir cancelled\n");
                return;
            }

            /**
             * Validate the new directory name TODO: Complete validation based to target OS The
             * forward slash is never valid. On a local file system the file separator is
             * invalid.
             */
            ProfileType type = getSelectedProfile().getType();
            if (newDirName.contains("/")
                    || (type == ProfileType.FILESYSTEM && newDirName.contains(File.separator))
                    || (type == ProfileType.HCAP2 && newDirName.contains("&"))) {
                JOptionPane.showMessageDialog(this.getParent(), "Invalid directory name", "Error",
                        JOptionPane.WARNING_MESSAGE);
                newDirName = null;
                continue;
            }

            // build new directory path from current directory and user supplied name. We must
            // encode the part just entered by the user
            String encodedDirName = newDirName;
            try {
                encodedDirName = profileModel.getSelectedProfile().encode(newDirName);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(this.getParent(), "An error occurred encoding the directory name",
                        "Error", JOptionPane.WARNING_MESSAGE);
                LOG.log(Level.WARNING, String.format("An error occurred encoding directory <%s>", newDirName));
                newDirName = null;
                continue;
            }

            newDirPath = FileUtil.resolvePath(currentDir.getPath(), encodedDirName,
                    profileModel.getSelectedProfile().getPathSeparator());
        } while (newDirName == null || newDirName.length() <= 0 || newDirPath == null);

        LOG.info("Creating new directory " + newDirPath);
        try {
            if (!arcMoverEngine.mkdir(profileModel.getSelectedProfile(), newDirPath)) {
                String msg = "Could not create directory: Permission Denied";
                throw new IOException(msg);
            }
            final ArcMoverDirectory dir = profileModel.getProfileAdapter().getDirectory(newDirPath);
            GUIHelper.invokeAndWait(new Runnable() {
                public void run() {
                    refreshPathAndFileList();
                    // refresh the other panel if necessary, but it won't do this panel because
                    // we are currently locked
                    HCPDataMigrator.getInstance().refreshMatchingPanels(profileModel.getSelectedProfile(),
                            currentDir);
                }
            }, "refresh after creating new directory");
        } catch (Exception e) {
            String uiErrorMsg;
            String logErrorMsg;

            if (e instanceof StorageAdapterException) {
                logErrorMsg = e.getMessage();
                uiErrorMsg = e.getMessage();
            } else {
                logErrorMsg = "Could not create directory: " + newDirPath;
                uiErrorMsg = DBUtils.getErrorMessage(
                        "Error creating directory " + profileModel.getSelectedProfile().decode(newDirPath), e);
            }
            LOG.log(Level.WARNING, logErrorMsg, e);
            GUIHelper.showMessageDialog(this.getParent(), uiErrorMsg, "Create Directory Error",
                    JOptionPane.ERROR_MESSAGE);
        }
    } catch (RuntimeException e1) {
        // TODO: Implement Proper Error Handling
        LOG.log(Level.WARNING, "Unexpected Exception", e1);
        throw e1;
    }
}

From source file:com.monead.semantic.workbench.SemanticWorkbench.java

/**
 * Edit the list of filters.//from  w  w  w  .j  a v a  2  s.  c  o m
 * 
 * @param filterMap
 *          The map whose entries are being edited
 */
private void editFilterMap(Map<String, String> filterMap) {
    final List<String> filteredItems = new ArrayList<String>(filterMap.keySet());
    int[] selectedIndices;

    Collections.sort(filteredItems);
    final JList jListOfItems = new JList(filteredItems.toArray(new String[filteredItems.size()]));
    JOptionPane.showMessageDialog(this, jListOfItems, "Select Items to Remove", JOptionPane.QUESTION_MESSAGE);

    selectedIndices = jListOfItems.getSelectedIndices();
    if (selectedIndices.length > 0) {
        LOGGER.debug(
                "Items to remove from the filter map: " + Arrays.toString(jListOfItems.getSelectedValues()));
        LOGGER.trace("Filtered list size before removal: " + filteredItems.size());
        for (int index = 0; index < selectedIndices.length; ++index) {
            LOGGER.trace("Remove filtered item: " + filteredItems.get(selectedIndices[index]));
            filterMap.remove(filteredItems.get(selectedIndices[index]));
        }
        LOGGER.trace("Filtered list size after removal: " + filteredItems.size());
    } else {
        LOGGER.debug("No items removed from filter map");
    }
}

From source file:com.itemanalysis.jmetrik.gui.Jmetrik.java

private void saveAs(JmetrikTextFile textFile, JmetrikTab tab) {
    File f = fileUtils.chooseFileToSave(Jmetrik.this, textFile.getFile());
    if (f != null) {
        if (f.exists()) {
            Toolkit.getDefaultToolkit().beep();
            int question = JOptionPane.showConfirmDialog(Jmetrik.this,
                    f.getName() + " already fileExists. Do you want to overwrite it?", "File Exists",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            if (question == JOptionPane.YES_OPTION) {
                textFile.fileSave(f, tab);
            }// w w w  .jav a  2 s  . co  m
        } else {
            textFile.fileSave(f, tab);
        }

    }
}

From source file:eu.apenet.dpt.standalone.gui.DataPreparationToolGUI.java

private void createOptionPaneForCountryCode() {
    String currentResult = retrieveFromDb.retrieveCountryCode();
    String explanation = labels.getString("enterCountryCode") + ((currentResult != null)
            ? "\n" + labels.getString("currentCountryCode") + ": '" + currentResult + "'"
            : "");
    int i = 0;/*from  ww  w  . j  a  v a2  s . c  om*/
    String result;
    do {
        if (i == 1) {
            explanation += "\n" + labels.getString("options.pleaseFollowRules");
        }
        result = (String) JOptionPane.showInputDialog(getContentPane(), explanation,
                labels.getString("chooseCountryCode"), JOptionPane.QUESTION_MESSAGE, Utilities.icon, null,
                null);
        if (result == null) {
            if (currentResult == null)
                System.exit(0);
            break;
        }
        i++;
    } while (dateNormalization.checkForCountrycode(result) == null);
    if (result != null) {
        retrieveFromDb.saveCountryCode(result);
    }
}

From source file:eu.apenet.dpt.standalone.gui.DataPreparationToolGUI.java

private void createOptionPaneForRepositoryCode() {
    String currentResult = retrieveFromDb.retrieveRepositoryCode();
    String explanation = labels.getString("enterIdentifier") + ((currentResult != null)
            ? "\n" + labels.getString("currentRepositoryCode") + ": '" + currentResult + "'"
            : "");
    int i = 0;/*from ww w .  j  a va 2 s  .co  m*/
    String result;
    do {
        if (i == 1) {
            explanation += "\n" + labels.getString("options.pleaseFollowRules");
        }
        result = (String) JOptionPane.showInputDialog(getContentPane(), explanation,
                labels.getString("chooseRepositoryCode"), JOptionPane.QUESTION_MESSAGE, Utilities.icon, null,
                null);
        if (result == null) {
            if (currentResult == null)
                System.exit(0);
            break;
        }
        i++;
    } while (dateNormalization.checkForMainagencycode(result) == null);
    if (result != null) {
        retrieveFromDb.saveRepositoryCode(result);
    }
}

From source file:de.huxhorn.lilith.swing.MainFrame.java

public void importFile(File importFile) {
    if (logger.isInfoEnabled())
        logger.info("Import file: {}", importFile.getAbsolutePath());

    File parentFile = importFile.getParentFile();
    String inputName = importFile.getName();
    if (!importFile.isFile()) {
        String message = "'" + importFile.getAbsolutePath() + "' is not a file!";
        JOptionPane.showMessageDialog(this, message, "Can't import file...", JOptionPane.ERROR_MESSAGE);
        return;//www.  j a v  a  2  s.com
    }
    if (!importFile.canRead()) {
        String message = "Can't read from '" + importFile.getAbsolutePath() + "'!";
        JOptionPane.showMessageDialog(this, message, "Can't import file...", JOptionPane.ERROR_MESSAGE);
        return;
    }

    File dataFile = new File(parentFile, inputName + FileConstants.FILE_EXTENSION);
    File indexFile = new File(parentFile, inputName + FileConstants.INDEX_FILE_EXTENSION);

    // check if file exists and warn in that case
    if (dataFile.isFile()) {
        // check if file is already open
        ViewContainer<?> viewContainer = resolveViewContainer(dataFile);
        if (viewContainer != null) {
            showView(viewContainer);
            String message = "File '" + dataFile.getAbsolutePath() + "' is already open.";
            JOptionPane.showMessageDialog(this, message, "File is already open...",
                    JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        String dialogTitle = "Reimport file?";
        String message = "Data file does already exist!\nReimport data file right now?";
        int result = JOptionPane.showConfirmDialog(this, message, dialogTitle, JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.QUESTION_MESSAGE);
        if (JOptionPane.OK_OPTION != result) {
            return;
        }

        if (dataFile.delete()) {
            if (logger.isInfoEnabled())
                logger.info("Deleted file '{}'.", dataFile.getAbsolutePath());
        }
    }
    if (indexFile.isFile()) {
        if (indexFile.delete()) {
            if (logger.isInfoEnabled())
                logger.info("Deleted file '{}'.", indexFile.getAbsolutePath());
        }
    }

    Map<String, String> metaData = new HashMap<String, String>();
    metaData.put(FileConstants.CONTENT_FORMAT_KEY, FileConstants.CONTENT_FORMAT_VALUE_PROTOBUF);
    metaData.put(FileConstants.CONTENT_TYPE_KEY, FileConstants.CONTENT_TYPE_VALUE_LOGGING);
    metaData.put(FileConstants.COMPRESSION_KEY, FileConstants.COMPRESSION_VALUE_GZIP);

    FileBuffer<EventWrapper<LoggingEvent>> buffer = loggingFileBufferFactory.createBuffer(dataFile, indexFile,
            metaData);

    ImportType type = resolveType(importFile);
    if (type == ImportType.LOG4J) {
        String name = "Importing Log4J XML file";
        String description = "Importing Log4J XML file '" + importFile.getAbsolutePath() + "'...";
        Task<Long> task = longTaskManager.startTask(new Log4jImportCallable(importFile, buffer), name,
                description);
        if (logger.isInfoEnabled())
            logger.info("Task-Name: {}", task.getName());
        return;
    }
    if (type == ImportType.JUL) {
        String name = "Importing java.util.logging XML file";
        String description = "Importing java.util.logging XML file '" + importFile.getAbsolutePath() + "'...";
        Task<Long> task = longTaskManager.startTask(new JulImportCallable(importFile, buffer), name,
                description);
        if (logger.isInfoEnabled())
            logger.info("Task-Name: {}", task.getName());
        return;
    }

    // show warning "Unknown type"
    String message = "Couldn't detect type of file '" + importFile.getAbsolutePath()
            + "'.\nFile is unsupported.";
    JOptionPane.showMessageDialog(this, message, "Unknown file type...", JOptionPane.WARNING_MESSAGE);
}

From source file:eu.apenet.dpt.standalone.gui.DataPreparationToolGUI.java

private void createOptionPaneForChecksLoadingFiles() {
    String currentResult = retrieveFromDb.retrieveCurrentLoadingChecks();
    String explanation = labels.getString("options.loadFilesExplanationYes") + "\n"
            + labels.getString("options.loadFilesExplanationNo") + "\n"
            + labels.getString("options.currentLoadFiles") + " '" + currentResult + "'";
    if (JOptionPane.showConfirmDialog(getContentPane(), explanation,
            labels.getString("options.howLoadNewFiles"), JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE, Utilities.icon) == JOptionPane.YES_OPTION) {
        retrieveFromDb.saveLoadingChecks("YES");
    } else {/* ww w. j a v  a  2s  .  c  o m*/
        retrieveFromDb.saveLoadingChecks("NO");
    }
}

From source file:base.BasePlayer.FileRead.java

static void checkMulti(Sample sample) {
    try {/*www . j  av a  2 s  . c  o m*/
        Sample addSample;
        BufferedReader reader = null;
        GZIPInputStream gzip = null;
        FileReader freader = null;
        String line;
        Boolean somatic = Main.drawCanvas.drawVariables.somatic;
        String[] split;
        if (somatic != null && somatic) {
            asked = true;
        }
        if (sample.getTabixFile().endsWith(".gz")) {
            try {
                gzip = new GZIPInputStream(new FileInputStream(sample.getTabixFile()));
                reader = new BufferedReader(new InputStreamReader(gzip));
            } catch (Exception e) {
                Main.showError("Could not read the file: " + sample.getTabixFile()
                        + "\nCheck that you have permission to read the file or try to bgzip and recreate the index file.",
                        "Error");
                Main.drawCanvas.sampleList.remove(sample);
                Main.varsamples--;
                Main.samples--;

            }
        } else {
            freader = new FileReader(sample.getTabixFile());
            reader = new BufferedReader(freader);
        }

        line = reader.readLine();

        if (!sample.multipart && line != null) {

            while (line != null) {
                try {

                    if (line.startsWith("##INFO")) {
                        if (line.contains("Type=Float") || line.contains("Type=Integer")
                                || line.contains("Number=")) {
                            VariantHandler.addMenuComponents(line);
                        }
                    }
                    if (line.startsWith("##FILTER")) {
                        if (line.contains("ID=") || line.contains("Description=") || line.contains("Number=")) {
                            VariantHandler.addMenuComponents(line);
                        }
                    }
                    if (line.startsWith("##FORMAT")) {
                        if (line.contains("Type=Float") || line.contains("Type=Integer")
                                || line.contains("Number=")) {
                            VariantHandler.addMenuComponents(line);
                        }
                    }
                    if (line.toLowerCase().contains("#chrom")) {
                        headersplit = line.split("\t+");

                        if (headersplit.length > 10) {
                            if (headersplit.length == 11 && !asked) {
                                if (JOptionPane.showConfirmDialog(Main.drawScroll, "Is this somatic project?",
                                        "Somatic?", JOptionPane.YES_NO_OPTION,
                                        JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
                                    somatic = true;
                                    Main.drawCanvas.drawVariables.somatic = true;
                                }
                                asked = true;
                            }
                            if (!somatic) {
                                sample.multiVCF = true;
                                Main.varsamples--;
                                for (int h = 9; h < headersplit.length; h++) {
                                    addSample = new Sample(headersplit[h], (short) (Main.samples), null);
                                    addSample.multipart = true;
                                    Main.drawCanvas.sampleList.add(addSample);
                                    Main.samples++;
                                    Main.varsamples++;
                                    if (sampleString == null) {
                                        sampleString = new StringBuffer("");
                                    }
                                    sampleString.append(addSample.getName() + ";");

                                }
                                VariantHandler.commonSlider.setMaximum(Main.varsamples);
                                VariantHandler.commonSlider.setUpperValue(Main.varsamples);
                                VariantHandler.geneSlider.setMaximum(Main.varsamples);
                                Main.drawCanvas.drawVariables.visiblesamples = (short) (Main.drawCanvas.sampleList
                                        .size());
                                Main.drawCanvas.checkSampleZoom();
                                Main.drawCanvas.resizeCanvas(Main.drawScroll.getViewport().getWidth(),
                                        Main.drawScroll.getViewport().getHeight());
                            }
                        }
                        line = reader.readLine();
                        break;
                    }
                    split = line.split("\t");
                    if (split.length > 2 && split[1].matches("\\d+")) {
                        break;
                    }

                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                line = reader.readLine();
            }
            /*
            VariantHandler.menu.setPreferredSize(new Dimension(300,500));
            VariantHandler.menuPanel.setPreferredSize(new Dimension(300,500));*/
            VariantHandler.menuScroll.setPreferredSize(new Dimension(250, 500));
            VariantHandler.menuScrollIndel.setPreferredSize(new Dimension(250, 500));
            if (line == null) {
                return;
            }

            while (line != null && line.startsWith("#")) {
                line = reader.readLine();
            }
            split = line.split("\t");
            if (line.contains("\"")) {
                sample.oddchar = "\"";
            }
            if (split != null && split.length == 8) {
                sample.annoTrack = true;
            }
            if (line != null) {

                if (line.startsWith("chr")) {
                    sample.vcfchr = "chr";
                }
            }
            if (somatic != null && somatic) {
                line = reader.readLine();
                if (line != null) {

                    headersplit = line.split("\t");

                    if (headersplit.length == 11) {

                        if (headersplit[10].startsWith("0:")
                                || (headersplit[10].charAt(0) == '0' && headersplit[10].charAt(2) == '0')) {
                            sample.somaticColumn = 9;
                        } else {
                            sample.somaticColumn = 10;
                        }
                    }

                }
            }
            checkSamples();
            line = null;
            if (freader != null) {
                freader.close();
            }
            reader.close();
            if (gzip != null) {
                gzip.close();
            }
        } else {
            reader.close();
            if (gzip != null) {
                gzip.close();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}