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:ffx.ui.MainPanel.java

/**
 * <p>//  w ww . j a v  a  2s. c o  m
 * createKeyFile</p>
 *
 * @param system a {@link ffx.ui.FFXSystem} object.
 * @return a boolean.
 */
public boolean createKeyFile(FFXSystem system) {
    String message = new String("Please select a parameter file " + "and a TINKER Key file will be created.");
    String params = (String) JOptionPane.showInputDialog(this, message, "Parameter File",
            JOptionPane.QUESTION_MESSAGE, null, keywordPanel.getParamFiles(), null);
    if (params != null) {
        if (params.equalsIgnoreCase("Use an existing TINKER Key file")) {
            JFileChooser fc = resetFileChooser();
            fc.setDialogTitle("Choose a KEY File");
            fc.setCurrentDirectory(pwd);
            fc.setSelectedFile(null);
            fc.setFileFilter(keyFileFilter);
            int result = fc.showOpenDialog(this);
            if (result == JFileChooser.APPROVE_OPTION) {
                File keyfile = fc.getSelectedFile();
                if (keyfile.exists()) {
                    Hashtable<String, Keyword> keywordHash = KeyFilter.open(keyfile);
                    if (keywordHash != null) {
                        system.setKeywords(keywordHash);
                    } else {
                        return false;
                    }
                    system.setKeyFile(keyfile);
                    system.setForceField(null);
                    return true;
                }
            }
        } else {
            File tempFile = system.getFile();
            if (tempFile.getParentFile().canWrite()) {
                String path = system.getFile().getParent() + File.separatorChar;
                String keyFileName = system.getName() + ".key";
                File keyfile = new File(path + keyFileName);
                try {
                    FileWriter fw = new FileWriter(keyfile);
                    BufferedWriter bw = new BufferedWriter(fw);
                    bw.write("\n");
                    bw.write("# Force Field Selection\n");
                    String tempParm = keywordPanel.getParamPath(params);
                    if (tempParm.indexOf(" ") > 0) {
                        tempParm = "\"" + keywordPanel.getParamPath(params) + "\"";
                    }
                    bw.write("PARAMETERS        " + tempParm + "\n");
                    bw.close();
                    fw.close();
                    Hashtable<String, Keyword> keywordHash = KeyFilter.open(keyfile);
                    if (keywordHash != null) {
                        system.setKeywords(keywordHash);
                    } else {
                        return false;
                    }
                    system.setKeyFile(keyfile);
                    system.setForceField(null);
                    return true;
                } catch (Exception e) {
                    logger.warning("" + e);
                    message = new String("There was an error creating " + keyfile.getAbsolutePath());
                    JOptionPane.showMessageDialog(this, message);
                }
            } else {
                message = new String(
                        "Could not create a Key file because " + pwd.getAbsolutePath() + " is not writable");
                JOptionPane.showMessageDialog(this, message);
            }
        }
    }
    return false;
}

From source file:com.mirth.connect.client.ui.browsers.message.MessageBrowser.java

/**
 * Constructs the MessageFilter (this.filter) based on the current form selections
 *//*w  ww  .j a va  2s.c o m*/
private boolean generateMessageFilter() {
    messageFilter = new MessageFilter();

    // set start/end date
    try {
        messageFilter.setStartDate(getCalendar(mirthDatePicker1, mirthTimePicker1));
        Calendar endCalendar = getCalendar(mirthDatePicker2, mirthTimePicker2);

        if (endCalendar != null && !mirthTimePicker2.isEnabled()) {
            // If the end time picker is disabled, it will be set to 00:00:00 of the day provided.
            // Since our query is using <= instead of <, we add one day and then subtract a millisecond 
            // in order to set the time to the last millisecond of the day we want to search on
            endCalendar.add(Calendar.DATE, 1);
            endCalendar.add(Calendar.MILLISECOND, -1);
        }
        messageFilter.setEndDate(endCalendar);
    } catch (ParseException e) {
        parent.alertError(parent, "Invalid date.");
        return false;
    }

    Calendar startDate = messageFilter.getStartDate();
    Calendar endDate = messageFilter.getEndDate();

    if (startDate != null && endDate != null && startDate.getTimeInMillis() > endDate.getTimeInMillis()) {
        parent.alertError(parent, "Start date cannot be after the end date.");
        return false;
    }

    // Set text search
    String textSearch = StringUtils.trim(textSearchField.getText());

    if (textSearch.length() > 0) {
        messageFilter.setTextSearch(textSearch);
        List<String> textSearchMetaDataColumns = new ArrayList<String>();

        for (MetaDataColumn metaDataColumn : getMetaDataColumns()) {
            if (metaDataColumn.getType() == MetaDataColumnType.STRING) {
                textSearchMetaDataColumns.add(metaDataColumn.getName());
            }
        }

        messageFilter.setTextSearchMetaDataColumns(textSearchMetaDataColumns);
    }

    if (regexTextSearchCheckBox.isSelected()) {
        messageFilter.setTextSearchRegex(true);
    }

    // set status
    Set<Status> statuses = new HashSet<Status>();

    if (statusBoxReceived.isSelected()) {
        statuses.add(Status.RECEIVED);
    }

    if (statusBoxTransformed.isSelected()) {
        statuses.add(Status.TRANSFORMED);
    }

    if (statusBoxFiltered.isSelected()) {
        statuses.add(Status.FILTERED);
    }

    if (statusBoxSent.isSelected()) {
        statuses.add(Status.SENT);
    }

    if (statusBoxError.isSelected()) {
        statuses.add(Status.ERROR);
    }

    if (statusBoxQueued.isSelected()) {
        statuses.add(Status.QUEUED);
    }

    if (!statuses.isEmpty()) {
        messageFilter.setStatuses(statuses);
    }

    if (StringUtils.isNotEmpty(textSearch)
            && Preferences.userNodeForPackage(Mirth.class).getBoolean("textSearchWarning", true)) {
        JCheckBox dontShowTextSearchWarningCheckBox = new JCheckBox(
                "Don't show this message again in the future");

        String textSearchWarning = "<html>Text searching may take a long time, depending on the amount of messages being searched.<br/>Are you sure you want to proceed?</html>";
        String textRegexSearchWarning = "<html>Regular expression pattern matching may take a long time and be a costly operation, depending on the amount of messages being searched.<br/>Are you sure you want to proceed?</html>";
        String searchWarning = (regexTextSearchCheckBox.isSelected()) ? textRegexSearchWarning
                : textSearchWarning;
        Object[] params = new Object[] { searchWarning, dontShowTextSearchWarningCheckBox };
        int result = JOptionPane.showConfirmDialog(this, params, "Select an Option", JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE);
        Preferences.userNodeForPackage(Mirth.class).putBoolean("textSearchWarning",
                !dontShowTextSearchWarningCheckBox.isSelected());

        if (result != JOptionPane.YES_OPTION) {
            return false;
        }
    }

    advancedSearchPopup.applySelectionsToFilter(messageFilter);
    selectedMetaDataIds = messageFilter.getIncludedMetaDataIds();

    if (messageFilter.getMaxMessageId() == null) {
        try {
            Long maxMessageId = parent.mirthClient.getMaxMessageId(channelId);
            messageFilter.setMaxMessageId(maxMessageId);
        } catch (ClientException e) {
            parent.alertThrowable(parent, e);
            return false;
        }
    }

    return true;
}

From source file:UserInterface.FinanceRole.DonateToPoorPeopleJPanel.java

private void autoDonateJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_autoDonateJButtonActionPerformed

    objWorldEnterprise.getObjTransactionDirectory().updateTransactionAccount();

    BigDecimal worldDonation = AutoDonate.donationCheck(objWorldEnterprise, objUserAccount);
    BigDecimal worldBalance = objWorldEnterprise.getObjTransactionDirectory().getAvailableVirtualBalance();
    System.out.println(worldDonation);

    System.out.println(objWorldEnterprise.getObjTransactionDirectory().getAvailableRealBalance());
    System.out.println(objWorldEnterprise.getObjTransactionDirectory().getAvailableVirtualBalance());

    int positiveWorldBalance = worldBalance.compareTo(worldDonation);

    if (positiveWorldBalance >= 1) {
        //JDialog.setDefaultLookAndFeelDecorated(true);

        int response = JOptionPane.showConfirmDialog(null,
                "Total donation of $ " + worldDonation + "/- Do you want to Donate?", "Confirm",
                JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (response == JOptionPane.YES_OPTION) {
            System.out.println("Yes button clicked");
            worldDonation = AutoDonate.donationConfirm(objWorldEnterprise, objUserAccount);

            JOptionPane.showMessageDialog(null, "$ " + worldDonation + "/- donated successfully");
        }/*from  www  .j a va 2  s  .c  o m*/
    } else {
        JOptionPane.showMessageDialog(null, "World Balance is low");
    }
}

From source file:com.pironet.tda.TDA.java

private void saveSession() {
    initSessionFc();//from  www.j a v  a  2s  .c  o  m
    int returnVal = sessionFc.showSaveDialog(this.getRootPane());
    sessionFc.setPreferredSize(sessionFc.getSize());

    PrefManager.get().setPreferredSizeFileChooser(sessionFc.getSize());

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = sessionFc.getSelectedFile();
        // check if file has a suffix
        if (!file.getName().contains(".")) {
            file = new File(file.getAbsolutePath() + ".tsf");
        }
        int selectValue = 0;
        if (file.exists()) {
            Object[] options = { "Overwrite", "Cancel" };
            selectValue = JOptionPane.showOptionDialog(null,
                    "<html><body>File exists<br><b>" + file + "</b></body></html>", "Confirm overwrite",
                    JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
        }
        if (selectValue == 0) {
            ObjectOutputStream oos = null;
            try {
                oos = new ObjectOutputStream(new GZIPOutputStream(new FileOutputStream(file)));

                oos.writeObject(dumpFile);
                oos.writeObject(topNodes);
                oos.writeObject(dumpStore);
            } catch (IOException ex) {
                ex.printStackTrace();
            } finally {
                IOUtils.closeQuietly(oos);

            }
            PrefManager.get().addToRecentSessions(file.getAbsolutePath());
        }
    }
}

From source file:DialogDemo.java

/** Creates the reusable dialog. */
public CustomDialog(Frame aFrame, String aWord, DialogDemo parent) {
    super(aFrame, true);
    dd = parent;/* ww w . j  a  v a  2 s  .  c  om*/

    magicWord = aWord.toUpperCase();
    setTitle("Quiz");

    textField = new JTextField(10);

    // Create an array of the text and components to be displayed.
    String msgString1 = "What was Dr. SEUSS's real last name?";
    String msgString2 = "(The answer is \"" + magicWord + "\".)";
    Object[] array = { msgString1, msgString2, textField };

    // Create an array specifying the number of dialog buttons
    // and their text.
    Object[] options = { btnString1, btnString2 };

    // Create the JOptionPane.
    optionPane = new JOptionPane(array, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options,
            options[0]);

    // Make this dialog display it.
    setContentPane(optionPane);

    // Handle window closing correctly.
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent we) {
            /*
             * Instead of directly closing the window, we're going to change the
             * JOptionPane's value property.
             */
            optionPane.setValue(new Integer(JOptionPane.CLOSED_OPTION));
        }
    });

    // Ensure the text field always gets the first focus.
    addComponentListener(new ComponentAdapter() {
        public void componentShown(ComponentEvent ce) {
            textField.requestFocusInWindow();
        }
    });

    // Register an event handler that puts the text into the option pane.
    textField.addActionListener(this);

    // Register an event handler that reacts to option pane state changes.
    optionPane.addPropertyChangeListener(this);
}

From source file:com.brainflow.application.toplevel.Brainflow.java

private void register(IImageDataSource limg) {
    DataSourceManager manager = DataSourceManager.getInstance();
    boolean alreadyRegistered = manager.isRegistered(limg);

    if (alreadyRegistered) {
        StringBuffer sb = new StringBuffer();
        sb.append("Image " + limg.getDataFile().getName().getBaseName());
        sb.append(" has already been loaded, would you like to reload from disk?");
        Integer ret = JOptionPane.showConfirmDialog(brainFrame, sb.toString(), "Image Already Loaded",
                JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        log.info("return value is: " + ret);

        if (ret == JOptionPane.YES_OPTION) {
            limg.releaseData();/*w w w  . j av a 2  s .  c  o  m*/
        }
    } else {
        manager.register(limg);
    }

}

From source file:org.fhaes.jsea.JSEAFrame.java

private void launchLagMap() {

    Object[] options = { "Yes", "No", "Cancel" };
    int n = JOptionPane.showOptionDialog(this,
            "LagMap is an interactive web application written by Wendy Gross and run within your web browser.\nWould you like to continue?",
            "Lauch LagMap", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options,
            options[2]);//from w w  w  .  j  a  v a  2 s .co  m

    if (n == JOptionPane.YES_OPTION)
        Platform.browseWebpage(RemoteHelp.LAUNCH_LAG_MAP, this);

}

From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_multicastDemand.java

private static void createMulticastDemandGUI(final NetworkElementType networkElementType,
        final IVisualizationCallback callback) {
    final NetPlan netPlan = callback.getDesign();

    JTextField textFieldIngressNodeId = new JTextField(20);
    JTextField textFieldEgressNodeIds = new JTextField(20);

    JPanel pane = new JPanel();
    pane.add(new JLabel("Ingress node id: "));
    pane.add(textFieldIngressNodeId);//www . ja v a2  s .com
    pane.add(Box.createHorizontalStrut(15));
    pane.add(new JLabel("Egress node ids (space separated): "));
    pane.add(textFieldEgressNodeIds);

    while (true) {
        int result = JOptionPane.showConfirmDialog(null, pane,
                "Please enter multicast demand ingress node and set of egress nodes",
                JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (result != JOptionPane.OK_OPTION)
            return;

        try {
            if (textFieldIngressNodeId.getText().isEmpty())
                throw new Exception("Please, insert the ingress node id");
            if (textFieldEgressNodeIds.getText().isEmpty())
                throw new Exception("Please, insert the set of egress node ids");

            String ingressNodeId_st = textFieldIngressNodeId.getText();
            String egressNodeId_st = textFieldEgressNodeIds.getText();

            final long ingressNode = Long.parseLong(ingressNodeId_st);
            if (netPlan.getNodeFromId(ingressNode) == null)
                throw new Exception("Not a valid ingress node id: " + ingressNodeId_st);
            Set<Node> egressNodes = new HashSet<Node>();
            for (String egressNodeIdString : StringUtils.split(egressNodeId_st)) {
                final long nodeId = Long.parseLong(egressNodeIdString);
                final Node node = netPlan.getNodeFromId(nodeId);
                if (node == null)
                    throw new Exception("Not a valid egress node id: " + egressNodeIdString);
                egressNodes.add(node);
            }
            netPlan.addMulticastDemand(netPlan.getNodeFromId(ingressNode), egressNodes, 0, null);
            callback.getVisualizationState().resetPickedState();
            callback.updateVisualizationAfterChanges(
                    Collections.singleton(NetworkElementType.MULTICAST_DEMAND));
            callback.getUndoRedoNavigationManager().addNetPlanChange();
            break;
        } catch (Throwable ex) {
            ErrorHandling.addErrorOrException(ex, AdvancedJTable_multicastDemand.class);
            ErrorHandling.showErrorDialog("Error adding the multicast demand");
        }
    }
}

From source file:DragDropTreeExample.java

protected void transferFile(int action, File srcFile, File targetDirectory, FileTree.FileTreeNode targetNode) {
    DnDUtils.debugPrintln((action == DnDConstants.ACTION_COPY ? "Copy" : "Move") + " file "
            + srcFile.getAbsolutePath() + " to " + targetDirectory.getAbsolutePath());

    // Create a File entry for the target
    String name = srcFile.getName();
    File newFile = new File(targetDirectory, name);
    if (newFile.exists()) {
        // Already exists - is it the same file?
        if (newFile.equals(srcFile)) {
            // Exactly the same file - ignore
            return;
        }/*from w ww.jav a  2s  . c  o  m*/
        // File of this name exists in this directory
        if (copyOverExistingFiles == false) {
            int res = JOptionPane.showOptionDialog(tree,
                    "A file called\n   " + name + "\nalready exists in the directory\n   "
                            + targetDirectory.getAbsolutePath() + "\nOverwrite it?",
                    "File Exists", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                    new String[] { "Yes", "Yes to All", "No", "Cancel" }, "No");
            switch (res) {
            case 1: // Yes to all
                copyOverExistingFiles = true;
            case 0: // Yes
                break;
            case 2: // No
                return;
            default: // Cancel
                throw new IllegalStateException("Cancelled");
            }
        }
    } else {
        // New file - create it
        try {
            newFile.createNewFile();
        } catch (IOException e) {
            JOptionPane.showMessageDialog(tree, "Failed to create new file\n  " + newFile.getAbsolutePath(),
                    "File Creation Failed", JOptionPane.ERROR_MESSAGE);
            return;
        }
    }

    // Copy the data and close file.
    BufferedInputStream is = null;
    BufferedOutputStream os = null;

    try {
        is = new BufferedInputStream(new FileInputStream(srcFile));
        os = new BufferedOutputStream(new FileOutputStream(newFile));
        int size = 4096;
        byte[] buffer = new byte[size];
        int len;
        while ((len = is.read(buffer, 0, size)) > 0) {
            os.write(buffer, 0, len);
        }
    } catch (IOException e) {
        JOptionPane.showMessageDialog(tree,
                "Failed to copy file\n  " + name + "\nto directory\n  " + targetDirectory.getAbsolutePath(),
                "File Copy Failed", JOptionPane.ERROR_MESSAGE);
        return;
    } finally {
        try {
            if (is != null) {
                is.close();
            }
            if (os != null) {
                os.close();
            }
        } catch (IOException e) {
        }
    }

    // Remove the source if this is a move operation.
    if (action == DnDConstants.ACTION_MOVE && System.getProperty("DnDExamples.allowRemove") != null) {
        srcFile.delete();
    }

    // Update the tree display
    if (targetNode != null) {
        tree.addNode(targetNode, name);
    }
}

From source file:edu.ku.brc.specify.tools.ireportspecify.MainFrameSpecify.java

/**
 * @param appResName//from w ww .j a  v a  2  s.c o  m
 * @param tableid
 * @return AppResource with the provided name.
 * 
 * If a resource named appResName exists it will be returned, else a new resource is created.
 */
private static AppResAndProps getAppRes(final String appResName, final Integer tableid,
        final boolean confirmOverwrite) {
    AppResourceIFace resApp = AppContextMgr.getInstance().getResource(appResName);
    if (resApp != null) {
        if (!confirmOverwrite) {
            return new AppResAndProps(resApp, null);
        }
        //else
        int option = JOptionPane.showOptionDialog(UIRegistry.getTopWindow(),
                String.format(UIRegistry.getResourceString("REP_CONFIRM_IMP_OVERWRITE"), resApp.getName()),
                UIRegistry.getResourceString("REP_CONFIRM_IMP_OVERWRITE_TITLE"), JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE, null, null, JOptionPane.NO_OPTION);

        if (option == JOptionPane.YES_OPTION) {
            return new AppResAndProps(resApp, null);
        }
        //else
        return null;
    }
    //else
    return createAppResAndProps(appResName, tableid, null);
}