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:lu.fisch.unimozer.Diagram.java

@Override
public void actionPerformed(ActionEvent e) {

    if (isEnabled()) {
        if (e.getSource() instanceof JMenuItem) {
            JMenuItem item = (JMenuItem) e.getSource();
            if (item.getText().equals("Compile")) {
                compile();//from  ww w  . j  av  a 2  s  . c om
            } else if (item.getText().equals("Remove class") && mouseClass != null) {
                int answ = JOptionPane.showConfirmDialog(frame,
                        "Are you sure to remove the class " + mouseClass.getFullName() + "",
                        "Remove a class", JOptionPane.YES_NO_OPTION);
                if (answ == JOptionPane.YES_OPTION) {
                    cleanAll();// clean(mouseClass);
                    removedClasses.add(mouseClass.getFullName());
                    classes.remove(mouseClass.getFullName());
                    mouseClass = null;
                    updateEditor();
                    repaint();
                    objectizer.repaint();
                }
            } else if (mouseClass.getName().contains("abstract")) {
                JOptionPane.showMessageDialog(frame, "Can't create an object of an abstract class ...",
                        "Instatiation error", JOptionPane.ERROR_MESSAGE, Unimozer.IMG_ERROR);
            } else if (item.getText().startsWith("new")) // we have constructor
            {
                Logger.getInstance().log("Click on <new> registered");
                // get full signature
                String fSign = item.getText();
                if (fSign.startsWith("new"))
                    fSign = fSign.substring(3).trim();
                // get signature
                final String fullSign = fSign;
                Logger.getInstance().log("fullSign = " + fSign);
                final String sign = mouseClass.getSignatureByFullSignature(fullSign);
                Logger.getInstance().log("sign = " + sign);

                Logger.getInstance().log("Creating runnable ...");
                Runnable r = new Runnable() {
                    @Override
                    public void run() {
                        //System.out.println("Calling method (full): "+fullSign);
                        //System.out.println("Calling method       : "+sign);
                        try {
                            Logger.getInstance().log("Loading the class <" + mouseClass.getName() + ">");
                            Class<?> cla = Runtime5.getInstance().load(mouseClass.getFullName()); //mouseClass.load();
                            Logger.getInstance().log("Loaded!");

                            // check if we need to specify a generic class
                            boolean cont = true;
                            String generics = "";
                            TypeVariable[] tv = cla.getTypeParameters();
                            Logger.getInstance().log("Got TypeVariables with length = " + tv.length);
                            if (tv.length > 0) {
                                LinkedHashMap<String, String> gms = new LinkedHashMap<String, String>();
                                for (int i = 0; i < tv.length; i++) {
                                    gms.put(tv[i].getName(), "");
                                }
                                MethodInputs gi = new MethodInputs(frame, gms, "Generic type declaration",
                                        "Please specify the generic types");
                                cont = gi.OK;

                                // build the string
                                generics = "<";
                                Object[] keys = gms.keySet().toArray();
                                mouseClass.generics.clear();
                                for (int in = 0; in < keys.length; in++) {
                                    String kname = (String) keys[in];
                                    // save generic type to myClass
                                    mouseClass.generics.put(kname, gi.getValueFor(kname));
                                    generics += gi.getValueFor(kname) + ",";
                                }
                                generics = generics.substring(0, generics.length() - 1);
                                generics += ">";
                            }

                            if (cont == true) {
                                Logger.getInstance().log("Getting the constructors.");

                                Constructor[] constr = cla.getConstructors();
                                for (int c = 0; c < constr.length; c++) {
                                    // get signature
                                    String full = objectizer.constToFullString(constr[c]);
                                    Logger.getInstance().log("full = " + full);
                                    /*
                                    String full = constr[c].getName();
                                    full+="(";
                                    Class<?>[] tvm = constr[c].getParameterTypes();
                                    for(int t=0;t<tvm.length;t++)
                                    {
                                        String sn = tvm[t].toString();
                                        sn=sn.substring(sn.lastIndexOf('.')+1,sn.length());
                                        if(sn.startsWith("class")) sn=sn.substring(5).trim();
                                        // array is shown as ";"  ???
                                        if(sn.endsWith(";"))
                                        {
                                            sn=sn.substring(0,sn.length()-1)+"[]";
                                        }
                                        full+= sn+", ";
                                    }
                                    if(tvm.length>0) full=full.substring(0,full.length()-2);
                                    full+= ")";
                                    */
                                    /*System.out.println("Loking for S : "+sign);
                                    System.out.println("Loking for FS: "+fullSign);
                                    System.out.println("Found: "+full);*/

                                    if (full.equals(sign) || full.equals(fullSign)) {
                                        Logger.getInstance().log("We are in!");
                                        //editor.setEnabled(false);
                                        //Logger.getInstance().log("Editor disabled");
                                        String name;
                                        Logger.getInstance().log("Ask user for a name.");
                                        do {
                                            String propose = mouseClass.getShortName().substring(0, 1)
                                                    .toLowerCase() + mouseClass.getShortName().substring(1);
                                            int count = 0;
                                            String prop = propose + count;
                                            while (objectizer.hasObject(prop) == true) {
                                                count++;
                                                prop = propose + count;
                                            }

                                            name = (String) JOptionPane.showInputDialog(frame,
                                                    "Please enter the name for you new instance of "
                                                            + mouseClass.getShortName() + "",
                                                    "Create object", JOptionPane.QUESTION_MESSAGE, null, null,
                                                    prop);
                                            if (Java.isIdentifierOrNull(name) == false) {
                                                JOptionPane.showMessageDialog(frame,
                                                        "" + name + " is not a correct identifier.",
                                                        "Error", JOptionPane.ERROR_MESSAGE, Unimozer.IMG_ERROR);
                                            } else if (objectizer.hasObject(name) == true) {
                                                JOptionPane.showMessageDialog(frame,
                                                        "An object with the name " + name
                                                                + " already exists.\nPlease choose another name ...",
                                                        "Error", JOptionPane.ERROR_MESSAGE, Unimozer.IMG_ERROR);
                                            }
                                        } while (Java.isIdentifierOrNull(name) == false
                                                || objectizer.hasObject(name) == true);
                                        Logger.getInstance().log("name = " + name);

                                        if (name != null) {
                                            Logger.getInstance().log("Need to get inputs ...");
                                            LinkedHashMap<String, String> inputs = mouseClass
                                                    .getInputsBySignature(sign);
                                            if (inputs.size() == 0)
                                                inputs = mouseClass.getInputsBySignature(fullSign);

                                            //System.out.println("1) "+sign);
                                            //System.out.println("2) "+fullSign);

                                            MethodInputs mi = null;
                                            boolean go = true;
                                            if (inputs.size() > 0) {
                                                mi = new MethodInputs(frame, inputs, full,
                                                        mouseClass.getJavaDocBySignature(sign));
                                                go = mi.OK;
                                            }
                                            Logger.getInstance().log("go = " + go);
                                            if (go == true) {
                                                Logger.getInstance().log("Building string ...");
                                                //Object arglist[] = new Object[inputs.size()];
                                                String constructor = "new " + mouseClass.getFullName()
                                                        + generics + "(";
                                                if (inputs.size() > 0) {
                                                    Object[] keys = inputs.keySet().toArray();
                                                    for (int in = 0; in < keys.length; in++) {
                                                        String kname = (String) keys[in];
                                                        //String type = inputs.get(kname);

                                                        //if(type.equals("int"))  { arglist[in] = Integer.valueOf(mi.getValueFor(kname)); }
                                                        //else if(type.equals("short"))  { arglist[in] = Short.valueOf(mi.getValueFor(kname)); }
                                                        //else if(type.equals("byte"))  { arglist[in] = Byte.valueOf(mi.getValueFor(kname)); }
                                                        //else if(type.equals("long"))  { arglist[in] = Long.valueOf(mi.getValueFor(kname)); }
                                                        //else if(type.equals("float"))  { arglist[in] = Float.valueOf(mi.getValueFor(kname)); }
                                                        //else if(type.equals("double"))  { arglist[in] = Double.valueOf(mi.getValueFor(kname)); }
                                                        //else if(type.equals("boolean"))  { arglist[in] = Boolean.valueOf(mi.getValueFor(kname)); }
                                                        //else arglist[in] = mi.getValueFor(kname);

                                                        String val = mi.getValueFor(kname);
                                                        if (val.equals(""))
                                                            val = "null";
                                                        else {
                                                            String type = mi.getTypeFor(kname);
                                                            if (type.toLowerCase().equals("byte"))
                                                                constructor += "Byte.valueOf(\"" + val + "\"),";
                                                            else if (type.toLowerCase().equals("short"))
                                                                constructor += "Short.valueOf(\"" + val
                                                                        + "\"),";
                                                            else if (type.toLowerCase().equals("float"))
                                                                constructor += "Float.valueOf(\"" + val
                                                                        + "\"),";
                                                            else if (type.toLowerCase().equals("long"))
                                                                constructor += "Long.valueOf(\"" + val + "\"),";
                                                            else if (type.toLowerCase().equals("double"))
                                                                constructor += "Double.valueOf(\"" + val
                                                                        + "\"),";
                                                            else if (type.toLowerCase().equals("char"))
                                                                constructor += "'" + val + "',";
                                                            else
                                                                constructor += val + ",";
                                                        }

                                                        //constructor+=mi.getValueFor(kname)+",";
                                                    }
                                                    constructor = constructor.substring(0,
                                                            constructor.length() - 1);
                                                }
                                                //System.out.println(arglist);
                                                constructor += ")";
                                                //System.out.println(constructor);
                                                Logger.getInstance().log("constructor = " + constructor);

                                                //LOAD: 
                                                //addLibs();
                                                Object obj = Runtime5.getInstance().getInstance(name,
                                                        constructor); //mouseClass.getInstance(name, constructor);
                                                Logger.getInstance().log("Objet is now instantiated!");
                                                //Runtime.getInstance().interpreter.getNameSpace().i
                                                //System.out.println(obj.getClass().getSimpleName());
                                                //Object obj = constr[c].newInstance(arglist);
                                                MyObject myo = objectizer.addObject(name, obj);
                                                myo.setMyClass(mouseClass);
                                                obj = null;
                                                cla = null;
                                            }

                                            objectizer.repaint();
                                            Logger.getInstance().log("Objectizer repainted ...");
                                            repaint();
                                            Logger.getInstance().log("Diagram repainted ...");
                                        }
                                        //editor.setEnabled(true);
                                        //Logger.getInstance().log("Editor enabled again ...");

                                    }
                                }
                            }
                        } catch (Exception ex) {
                            //ex.printStackTrace();
                            MyError.display(ex);
                            JOptionPane.showMessageDialog(frame, ex.toString(), "Instantiation error",
                                    JOptionPane.ERROR_MESSAGE, Unimozer.IMG_ERROR);
                        }
                    }
                };
                Thread t = new Thread(r);
                t.start();
            } else // we have a static method
            {
                try {
                    // get full signature
                    String fullSign = ((JMenuItem) e.getSource()).getText();
                    // get signature
                    String sign = mouseClass.getSignatureByFullSignature(fullSign).replace(", ", ",");
                    String complete = mouseClass.getCompleteSignatureBySignature(sign).replace(", ", ",");

                    /*System.out.println("Calling method (full): "+fullSign);
                    System.out.println("Calling method       : "+sign);
                    System.out.println("Calling method (comp): "+complete);/**/

                    // find method
                    Class c = Runtime5.getInstance().load(mouseClass.getFullName());
                    Method m[] = c.getMethods();
                    for (int i = 0; i < m.length; i++) {
                        /*String full = "";
                        full+= m[i].getReturnType().getSimpleName();
                        full+=" ";
                        full+= m[i].getName();
                        full+= "(";
                        Class<?>[] tvm = m[i].getParameterTypes();
                        LinkedHashMap<String,String> genericInputs = new LinkedHashMap<String,String>();
                        for(int t=0;t<tvm.length;t++)
                        {
                        String sn = tvm[t].toString();
                        //System.out.println(sn);
                        if(sn.startsWith("class")) sn=sn.substring(5).trim();
                        sn=sn.substring(sn.lastIndexOf('.')+1,sn.length());
                        // array is shown as ";"  ???
                        if(sn.endsWith(";"))
                        {
                            sn=sn.substring(0,sn.length()-1)+"[]";
                        }
                        full+= sn+", ";
                        genericInputs.put("param"+t,sn);
                        }
                        if(tvm.length>0) full=full.substring(0,full.length()-2);
                        full+= ")";*/
                        String full = objectizer.toFullString(m[i]);
                        LinkedHashMap<String, String> genericInputs = objectizer.getInputsReplaced(m[i], null);

                        /*System.out.println("Looking for S : "+sign);
                        System.out.println("Looking for FS: "+fullSign);
                        System.out.println("Found         : "+full);*/

                        if (full.equals(sign) || full.equals(fullSign)) {
                            LinkedHashMap<String, String> inputs = mouseClass.getInputsBySignature(sign);
                            //Objectizer.printLinkedHashMap("inputs", inputs);
                            if (inputs.size() != genericInputs.size()) {
                                inputs = genericInputs;
                            }
                            //Objectizer.printLinkedHashMap("inputs", inputs);
                            MethodInputs mi = null;
                            boolean go = true;
                            if (inputs.size() > 0) {
                                mi = new MethodInputs(frame, inputs, full,
                                        mouseClass.getJavaDocBySignature(sign));
                                go = mi.OK;
                            }
                            if (go == true) {
                                try {
                                    String method = mouseClass.getFullName() + "." + m[i].getName() + "(";
                                    if (inputs.size() > 0) {
                                        Object[] keys = inputs.keySet().toArray();
                                        //int cc = 0;
                                        for (int in = 0; in < keys.length; in++) {
                                            String name = (String) keys[in];
                                            String val = mi.getValueFor(name);

                                            if (val.equals(""))
                                                method += val + "null,";
                                            else {
                                                String type = mi.getTypeFor(name);
                                                if (type.toLowerCase().equals("byte"))
                                                    method += "Byte.valueOf(\"" + val + "\"),";
                                                else if (type.toLowerCase().equals("short"))
                                                    method += "Short.valueOf(\"" + val + "\"),";
                                                else if (type.toLowerCase().equals("float"))
                                                    method += "Float.valueOf(\"" + val + "\"),";
                                                else if (type.toLowerCase().equals("long"))
                                                    method += "Long.valueOf(\"" + val + "\"),";
                                                else if (type.toLowerCase().equals("double"))
                                                    method += "Double.valueOf(\"" + val + "\"),";
                                                else if (type.toLowerCase().equals("char"))
                                                    method += "'" + val + "',";
                                                else
                                                    method += val + ",";
                                            }

                                            //if (val.equals("")) val="null";
                                            //method+=val+",";
                                        }
                                        if (!method.endsWith("("))
                                            method = method.substring(0, method.length() - 1);
                                    }
                                    method += ")";

                                    //System.out.println(method);

                                    // Invoke method in a new thread
                                    final String myMeth = method;
                                    Runnable r = new Runnable() {
                                        public void run() {
                                            try {
                                                Object retobj = Runtime5.getInstance().executeMethod(myMeth);
                                                if (retobj != null)
                                                    JOptionPane.showMessageDialog(frame, retobj.toString(),
                                                            "Result", JOptionPane.INFORMATION_MESSAGE,
                                                            Unimozer.IMG_INFO);
                                            } catch (EvalError ex) {
                                                JOptionPane.showMessageDialog(frame, ex.toString(),
                                                        "Invokation error", JOptionPane.ERROR_MESSAGE,
                                                        Unimozer.IMG_ERROR);
                                                MyError.display(ex);
                                            }
                                        }
                                    };
                                    Thread t = new Thread(r);
                                    t.start();

                                    //System.out.println(method);
                                    //Object retobj = Runtime5.getInstance().executeMethod(method);
                                    //if(retobj!=null) JOptionPane.showMessageDialog(frame, retobj.toString(), "Result", JOptionPane.INFORMATION_MESSAGE,Unimozer.IMG_INFO);
                                } catch (Throwable ex) {
                                    JOptionPane.showMessageDialog(frame, ex.toString(), "Execution error",
                                            JOptionPane.ERROR_MESSAGE, Unimozer.IMG_ERROR);
                                    MyError.display(ex);
                                }
                            }
                        }
                    }
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(frame, ex.toString(), "Execution error",
                            JOptionPane.ERROR_MESSAGE, Unimozer.IMG_ERROR);
                    MyError.display(ex);
                }
            }
        }
    }
}

From source file:edu.harvard.i2b2.patientMapping.ui.PatientMappingJPanel.java

private String getKey() {
    String path = null;//w  w  w.  j  a v a  2  s . co  m
    key = UserInfoBean.getInstance().getKey();
    if (key == null) {
        if ((path = getNoteKeyDrive()) == null) {
            Object[] possibleValues = { "Type in the key", "Browse to find the file containing the key" };
            String selectedValue = (String) JOptionPane.showInputDialog(this,

                    "The data you have selected to view contains protected \n"
                            + "health information and has been encrypted.\n"
                            + "In order to view this information you must enter \n"
                            + "the decryption key for this project. \n"
                            + "The key can be entered by either manually entering \n"
                            + "the key or selecting the file that contains the key.",
                    "Decryption Key", JOptionPane.QUESTION_MESSAGE, null, possibleValues, possibleValues[0]);
            if (selectedValue == null) {
                return "canceled";
            }
            if (selectedValue.equalsIgnoreCase("Type in the key")) {
                key = JOptionPane.showInputDialog(this, "Please input the decryption key");
                if (key == null) {
                    return "canceled";
                }
            } else {
                JFileChooser chooser = new JFileChooser();
                int returnVal = chooser.showOpenDialog(this);
                if (returnVal == JFileChooser.CANCEL_OPTION) {
                    return "canceled";
                }

                File f = null;
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    f = chooser.getSelectedFile();
                    System.out.println("Open this file: " + f.getAbsolutePath());

                    BufferedReader in = null;
                    try {
                        in = new BufferedReader(new FileReader(f.getAbsolutePath()));
                        String line = null;
                        while ((line = in.readLine()) != null) {
                            if (line.length() > 0) {
                                key = line.substring(line.indexOf("\"") + 1, line.lastIndexOf("\""));
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        if (in != null) {
                            try {
                                in.close();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
            }
        } else {
            System.out.println("Found key file: " + path);
            BufferedReader in = null;
            try {
                in = new BufferedReader(new FileReader(path));
                String line = null;
                while ((line = in.readLine()) != null) {
                    if (line.length() > 0) {
                        key = line.substring(line.indexOf("\"") + 1, line.lastIndexOf("\""));
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }

    if (key == null) {
        return null;
    } else {
        UserInfoBean.getInstance().setKey(key);
    }
    return key;
}

From source file:edu.ku.brc.af.ui.forms.FormViewObj.java

/**
 * Save any changes to the current object
 *//*from  ww w .  ja  v a2s . c  om*/
protected void askToRemoveObject() {
    boolean addSearch = mvParent != null
            && MultiView.isOptionOn(mvParent.getOptions(), MultiView.ADD_SEARCH_BTN);

    Object[] delBtnLabels = { getResourceString(addSearch ? "Remove" : "Delete"), getResourceString("CANCEL") };
    String title = dataObj instanceof FormDataObjIFace ? ((FormDataObjIFace) dataObj).getIdentityTitle()
            : tableInfo.getTitle();

    int rv = JOptionPane.showOptionDialog(UIRegistry.getTopWindow(),
            UIRegistry.getLocalizedMessage(addSearch ? "ASK_REMOVE" : "ASK_DELETE", title),
            getResourceString(addSearch ? "Remove" : "Delete"), JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, delBtnLabels, delBtnLabels[1]);
    if (rv != JOptionPane.YES_OPTION) {
        return;
    }

    // We do this because the process of determining whether something can be deleted might take a while.

    if (addSearch) {
        doDeleteDataObj(dataObj, session, true);

    } else if (businessRules != null) {
        UIRegistry.getStatusBar().setIndeterminate(STATUSBAR_NAME, true);
        final SwingWorker worker = new SwingWorker() {
            public Object construct() {
                businessRules.okToDelete(dataObj, session, FormViewObj.this);
                return null;
            }

            //Runs on the event-dispatching thread.
            public void finished() {
                UIRegistry.getStatusBar().setProgressDone(STATUSBAR_NAME);
                if (session != null) {
                    session.close();
                }
            }
        };
        worker.start();

    } else // No Business Rules
    {
        doDeleteDataObj(dataObj, session, true);
    }
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.wbuploader.Uploader.java

public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals(UploadMainPanel.VALIDATE_CONTENT)) {
        validateData(true);//from ww  w  . j  a v  a  2 s .c om
    } else if (e.getActionCommand().equals(UploadMainPanel.DO_UPLOAD)) {
        if (isUpdateUpload()) {
            if (!isValidUpdateUpload()) {
                UIRegistry.showError("This dataset contains mappings which are not updateable");
                return;
            }
            if (!UIRegistry.displayConfirm("Ready to Update",
                    "This update cannot be undone. Are you sure you want to continue?", "Yes", "No",
                    JOptionPane.WARNING_MESSAGE)) {
                return;
            }
        }
        uploadIt(true);
    } else if (e.getActionCommand().equals(UploadMainPanel.VIEW_UPLOAD)) {
        if (currentOp.equals(Uploader.SUCCESS) || currentOp.equals(Uploader.SUCCESS_PARTIAL)) {
            viewAllObjectsCreatedByUpload();
        }
    } else if (e.getActionCommand().equals(UploadMainPanel.VIEW_SETTINGS)) {
        showSettings();
        if (currentOp.equals(Uploader.READY_TO_UPLOAD) && !resolver.isResolved()) {
            setCurrentOp(Uploader.USER_INPUT);
        } else if (currentOp.equals(Uploader.USER_INPUT) && resolver.isResolved()) {
            setCurrentOp(Uploader.READY_TO_UPLOAD);
        }
    } else if (e.getActionCommand().equals(UploadMainPanel.CLOSE_UI)) {
        if (aboutToShutdown(null)) {
            closeMainForm(true);
        }
    } else if (e.getActionCommand().equals(UploadMainPanel.UNDO_UPLOAD)) {
        if (UIRegistry.displayConfirm(getResourceString("WB_UPLOAD_FORM_TITLE"),
                getResourceString("WB_UNDO_UPLOAD_MSG"), getResourceString("OK"), getResourceString("CANCEL"),
                JOptionPane.QUESTION_MESSAGE)) {
            undoUpload(true, false, true);
        }
    } else if (e.getActionCommand().equals(UploadMainPanel.TBL_DBL_CLICK)) {
        mainPanel.getViewUploadBtn().setEnabled(canViewUpload(currentOp));
        if (currentOp.equals(Uploader.SUCCESS) || currentOp.equals(Uploader.SUCCESS_PARTIAL)) {
            viewAllObjectsCreatedByUpload();
        }
    } else if (e.getActionCommand().equals(UploadMainPanel.TBL_CLICK)) {
        mainPanel.getViewUploadBtn().setEnabled(canViewUpload(currentOp));
    } else if (e.getActionCommand().equals(UploadMainPanel.MSG_CLICK)) {
        goToMsgWBCell((Component) e.getSource(), false);
    } else if (e.getActionCommand().equals(UploadMainPanel.PRINT_INVALID)) {
        printInvalidValReport();
    } else if (e.getActionCommand().equals(UploadMainPanel.CANCEL_OPERATION)) {
        if (currentTask != null && currentTask.isCancellable()) {
            cancelTask(currentTask);
        } else {
            log.info("ignoring action: " + e.getActionCommand());
        }
    } else
        log.error("Unrecognized action: " + e.getActionCommand());
}

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * A Two button prompt to ask the user for a decision.
 * @param yesLabelKey the I18N label for the Yes button
 * @param noLabelKey the I18N label for the No button
 * @param titleKey I18N key for title/*from  w w w.  ja va 2s.  com*/
 * @param msg (not localized)
 * @return
 */
public static boolean promptForAction(final String yesLabelKey, final String noLabelKey, final String titleKey,
        final String msg) {
    Object[] options = { getResourceString(yesLabelKey), getResourceString(noLabelKey) };

    int userChoice = JOptionPane.showOptionDialog(UIRegistry.getTopWindow(), msg, getResourceString(titleKey),
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
    return userChoice == JOptionPane.YES_OPTION;
}

From source file:CSSDFarm.UserInterface.java

private void btnAddFieldStationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddFieldStationActionPerformed
    JTextField id = new JTextField();
    JTextField name = new JTextField();
    //Space is needed to expand dialog
    JLabel verified = new JLabel(" ");
    JButton okButton = new JButton("Ok");
    JButton cancelButton = new JButton("Cancel");
    okButton.setEnabled(false);//from  w w w  .  jav  a2 s.co  m
    okButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            String idText = id.getText();
            String nameText = name.getText();
            addFieldStation(id.getText(), name.getText());
            JOptionPane.getRootFrame().dispose();
            listUserStations.setSelectedValue(server.getFieldStation(idText), false);
        }
    });

    cancelButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            JOptionPane.getRootFrame().dispose();
        }
    });

    id.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent key) {
            boolean theid = id.getText().equals("");
            boolean thename = name.getText().equals("");
            if (server.verifyFieldStation(id.getText()) && !theid && !thename) {
                verified.setText(" Verified");
                verified.setForeground(new Color(0, 102, 0));
                okButton.setEnabled(true);
            } else {
                verified.setText(" Not Verified");
                verified.setForeground(Color.RED);
                okButton.setEnabled(false);
            }
        }
    });
    name.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent key) {
            boolean theid = id.getText().equals("");
            boolean thename = name.getText().equals("");
            if (server.verifyFieldStation(id.getText()) && !theid && !thename) {
                verified.setText(" Verified");
                verified.setForeground(new Color(0, 102, 0));
                okButton.setEnabled(true);
            } else {
                verified.setText(" Not Verified");
                verified.setForeground(Color.RED);
                okButton.setEnabled(false);
            }
        }
    });

    Object[] message = { "Field Station ID:", id, "Field Station Name:", name, verified };
    int inputFields = JOptionPane.showOptionDialog(null, message, "Add Field Station",
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null,
            new Object[] { okButton, cancelButton }, null);
    if (inputFields == JOptionPane.OK_OPTION) {
        System.out.print("Added Field Station!");
    }
}

From source file:de.main.sessioncreator.DesktopApplication1View.java

private void btnWizardNext(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnWizardNext
    int selTab = wizardtabp.getSelectedIndex();
    int maxTab = wizardtabp.getTabCount();
    try {/*from w w  w  .  j a  v  a 2 s .  c o m*/
        wizardbtnBack.setEnabled(true);
        wizardbtntopBack.setEnabled(true);
        wizardtabp.setSelectedIndex(selTab + 1);

        if (wizardtabp.getTitleAt(wizardtabp.getSelectedIndex()).contains("Charter")) {
            wizardChckBxNewCharter.addActionListener(new chckBxNewCharterListener());
            swingHelper.setTab1EnableAt(wizardtabp, 1);
            progressBar.setVisible(true);
            progressBar.setIndeterminate(true);
            wizardbtnBack.setEnabled(false);
            wizardbtntopBack.setEnabled(false);
            wizardbtnNext.setEnabled(false);
            wizardbtntopNext.setEnabled(false);
            mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            wizardCmbxCharter.removeAllItems();
            fileHelper.charterList.clear();
            final File directory = new File(wizardTfPathTodo.getText());
            worker = new SwingWorker<String, Void>() {

                @Override
                protected String doInBackground() {
                    return getCharterBackgroundW(directory);
                }

                @Override
                protected void done() {
                    try {
                        if (!worker.get().contains("no")) {
                            progressBar.setIndeterminate(false);
                            progressBar.setVisible(false);
                            wizardbtnBack.setEnabled(true);
                            wizardbtntopBack.setEnabled(true);
                            wizardbtnNext.setEnabled(true);
                            wizardbtntopNext.setEnabled(true);
                            int no = wizardCmbxCharter.getItemCount();
                            wizardLblChooseCharter.setText("Please select one of " + no + " Charter");
                            mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                        } else {
                            progressBar.setIndeterminate(false);
                            progressBar.setVisible(false);
                            wizardbtnBack.setEnabled(true);
                            wizardbtntopBack.setEnabled(true);
                            wizardbtnNext.setEnabled(false);
                            wizardbtntopNext.setEnabled(false);
                            mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                        }
                    } catch (InterruptedException ex) {
                        Logger.getLogger(DesktopApplication1View.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (ExecutionException ex) {
                        Logger.getLogger(DesktopApplication1View.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            };
            worker.execute();
        }
        if (wizardtabp.getTitleAt(wizardtabp.getSelectedIndex()).contains("Areas")) {
            swingHelper.setTab1EnableAt(wizardtabp, 2);
            progressBar.setVisible(true);
            progressBar.setIndeterminate(true);
            wizardbtnBack.setEnabled(false);
            wizardbtntopBack.setEnabled(false);
            wizardbtnNext.setEnabled(false);
            wizardbtntopNext.setEnabled(false);
            wizardbtnAddAreas.setEnabled(false);
            if (wizardtaChoosenAreas.getDocument().getLength() == 0) {
                wizardbtnRemoveArea.setEnabled(false);
            } else {
                wizardbtnRemoveArea.setEnabled(true);
            }

            wizardtaChoosenAreas.getDocument().addDocumentListener(new choosenAreaListener());
            wizardtabpAreas.removeAll();
            final File coverageini = new File(wizardtfCoverageini.getText());
            getAreasBacgroundW(coverageini);
            wizardbtnBack.setEnabled(true);
            wizardbtntopBack.setEnabled(true);
            wizardbtnNext.setEnabled(true);
            wizardbtntopNext.setEnabled(true);
            if (wizardChckBxNewCharter.isSelected()) {
                wizardbtnSaveTodo.setEnabled(true);
            }
            wizardbtnNext.setText("Create Testsession");
            progressBar.setIndeterminate(false);
            progressBar.setVisible(false);
            if (!wizardChckBxNewCharter.isSelected()) {
                String todo = ChoosenCharter.substring(ChoosenCharter.indexOf("(" + wizardTfPathTodo.getText()))
                        .replace("(", "").replace(")", "");
                final File todocheckliste = new File(todo);
                String msg = "Import all Areas from the Todo-Session?";
                fileHelper.getAreasChecklist(todocheckliste);
                fileHelper.areaChecklist.remove(0);
                if (!fileHelper.areaChecklist.get(0).isEmpty()) {
                    if (JOptionPane.showConfirmDialog(wizardtabpAreas, msg, "Import?",
                            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == 0) {
                        wizardtaChoosenAreas.setText("");
                        for (String s : fileHelper.areaChecklist) {
                            wizardtaChoosenAreas.append(s + "\n");
                        }
                        wizardtaChoosenAreas.setCaretPosition(0);
                    }
                }
            }
        }
        if (wizardtabp.getTitleAt(wizardtabp.getSelectedIndex()).contains("Testsession")) {
            swingHelper.setTab1EnableAt(wizardtabp, 3);
            wizardbtnNext.setVisible(false);
            wizardbtntopNext.setEnabled(false);
            wizardbtnStart.addActionListener(new ButtonListenerStart());
            wizardbtntopStart.addActionListener(new ButtonListenerStart());
            wizardbtnStop.addActionListener(new ButtonListenerStop());
            wizardbtntopStop.addActionListener(new ButtonListenerStop());
            if (wizardChckBxNewCharter.isSelected()) {
                wizardtaCharterdynamic.setText(wizardtaNewCharter.getText().trim());
            } else {
                wizardtaCharterdynamic.setText(
                        ChoosenCharter.substring(0, ChoosenCharter.indexOf("(" + wizardTfPathTodo.getText())));
            }
            statusMessageLabel.setText("");
            wizardbtnStart.setVisible(true);
            wizardbtnStart.setEnabled(true);
            wizardbtntopStart.setEnabled(true);
            wizardbtnStop.setVisible(true);
            wizardbtnStop.setEnabled(false);
            wizardbtntopStop.setEnabled(false);
            final JPopupMenu popupMenu = new JPopupMenu();
            final File coverageini = new File(wizardtfCoverageini.getText());
            swingHelper.getAreastoPopupMenu(popupMenu, coverageini, new alBugsIssue());
            popupListener2 = new PopupListener(popupMenu);
            wizardtaTestsessionAreas.addMouseListener(popupListener2);
            wizardtaTestsessionAreas.setText(wizardtaChoosenAreas.getText());
            wizardtaTestsessionAreas.setCaretPosition(0);
            wizardtaCharterdynamic.setCaretPosition(0);
            if (wizardChckBxSecondTester.isSelected()) {
                TesterRealname = wizardCmbxTester.getSelectedItem().toString();
                wizardtfNameOfTester.setText(TesterRealname.substring(4) + " "
                        + wizardCmbxMoreTester.getSelectedItem().toString().substring(4));
            } else {
                TesterRealname = wizardCmbxTester.getSelectedItem().toString();
                wizardtfNameOfTester.setText(TesterRealname.substring(4));
            }
        }
        if (wizardtabp.getSelectedIndex() == maxTab) {
            wizardbtnNext.setEnabled(false);
            wizardbtntopNext.setEnabled(false);
        }
    } catch (IndexOutOfBoundsException ex) {
        statusMessageLabel.setText(ex.getMessage());
    }
}

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

/**
 * Set the maximum number of individuals to display for each class in the tree
 * view of the model//from   w w  w . j  av  a2s .c  om
 */
private void setMaximumIndividualsPerClassInTree() {
    final String currentValue = properties
            .getProperty(ConfigurationProperty.MAX_INDIVIDUALS_PER_CLASS_IN_TREE.key(), "0");
    final String maximumChildNodes = JOptionPane.showInputDialog(this,
            "Enter the maximum number of individuals to be displayed\n"
                    + "under each class in the tree view of the model.\n\n"
                    + "Enter the value 0 (zero) to allow all the individuals\n" + "to be shown.\n\n"
                    + "The current setting is: " + currentValue,
            "Limit Individuals Displayed Per Class in the Tree View", JOptionPane.QUESTION_MESSAGE);

    if (maximumChildNodes != null && maximumChildNodes.trim().length() > 0) {
        try {
            final int maxNodes = Integer.parseInt(maximumChildNodes);
            if (maxNodes >= 0) {
                properties.setProperty(ConfigurationProperty.MAX_INDIVIDUALS_PER_CLASS_IN_TREE.key(),
                        maxNodes + "");
            } else {
                JOptionPane.showMessageDialog(this,
                        "The value entered for the maximum number of individuals\n"
                                + "was less than 0. The original setting is unchanged.",
                        "Negative Value Entered", JOptionPane.ERROR_MESSAGE);
            }
        } catch (Throwable throwable) {
            JOptionPane.showMessageDialog(this,
                    "The value entered for the maximum number of individuals\n"
                            + "was not a number. The original setting is unchanged.",
                    "Non-numeric Value Entered", JOptionPane.ERROR_MESSAGE);
        }
    }

}

From source file:org.forester.archaeopteryx.TreePanel.java

final private void pasteSubtree(final PhylogenyNode node) {
    if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED) {
        errorMessageNoCutCopyPasteInUnrootedDisplay();
        return;/*from ww  w.jav  a2  s .  co m*/
    }
    if ((getCutOrCopiedTree() == null) || getCutOrCopiedTree().isEmpty()) {
        JOptionPane.showMessageDialog(this, "No tree in buffer (need to copy or cut a subtree first)",
                "Attempt to paste with empty buffer", JOptionPane.ERROR_MESSAGE);
        return;
    }
    final String label = getASimpleTextRepresentationOfANode(getCutOrCopiedTree().getRoot());
    final Object[] options = { "As sibling", "As descendant", "Cancel" };
    final int r = JOptionPane.showOptionDialog(this, "How to paste subtree" + label + "?", "Paste Subtree",
            JOptionPane.CLOSED_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]);
    boolean paste_as_sibling = true;
    if (r == 1) {
        paste_as_sibling = false;
    } else if (r != 0) {
        return;
    }
    final Phylogeny buffer_phy = getCutOrCopiedTree().copy();
    buffer_phy.setAllNodesToNotCollapse();
    buffer_phy.preOrderReId();
    if (paste_as_sibling) {
        if (node.isRoot()) {
            JOptionPane.showMessageDialog(this, "Cannot paste sibling to root",
                    "Attempt to paste sibling to root", JOptionPane.ERROR_MESSAGE);
            return;
        }
        buffer_phy.addAsSibling(node);
    } else {
        buffer_phy.addAsChild(node);
    }
    if (getCopiedAndPastedNodes() == null) {
        setCopiedAndPastedNodes(new HashSet<PhylogenyNode>());
    }
    getCopiedAndPastedNodes().addAll(PhylogenyMethods.obtainAllNodesAsSet(buffer_phy));
    _phylogeny.externalNodesHaveChanged();
    _phylogeny.hashIDs();
    _phylogeny.recalculateNumberOfExternalDescendants(true);
    resetNodeIdToDistToLeafMap();
    setEdited(true);
    repaint();
}

From source file:com.peterbochs.PeterBochsDebugger.java

private void jAddBreakpointButtonActionPerformed(ActionEvent evt) {
    jAddBreakpointButton.setEnabled(false);
    String type = (String) JOptionPane.showInputDialog(this, null, "Add breakpoint",
            JOptionPane.QUESTION_MESSAGE, null, new Object[] { MyLanguage.getString("Physical_address"),
                    MyLanguage.getString("Linear_address"), MyLanguage.getString("Virtual_address") },
            MyLanguage.getString("Physical_address"));
    if (type != null) {
        String address = JOptionPane.showInputDialog(this, "Please input breakpoint address", "Add breakpoint",
                JOptionPane.QUESTION_MESSAGE);
        if (address != null) {
            if (type.equals(MyLanguage.getString("Physical_address"))) {
                sendCommand("pb " + address);
            } else if (type.equals(MyLanguage.getString("Linear_address"))) {
                sendCommand("lb " + address);
            } else {
                sendCommand("vb " + address);
            }//from   w  w w . j av a2  s  .c o  m
            updateBreakpoint();
            updateBreakpointTableColor();
        }
    }
    jAddBreakpointButton.setEnabled(true);
}