Example usage for javax.swing JOptionPane showInputDialog

List of usage examples for javax.swing JOptionPane showInputDialog

Introduction

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

Prototype

@SuppressWarnings("deprecation")
public static Object showInputDialog(Component parentComponent, Object message, String title, int messageType,
        Icon icon, Object[] selectionValues, Object initialSelectionValue) throws HeadlessException 

Source Link

Document

Prompts the user for input in a blocking dialog where the initial selection, possible selections, and all other options can be specified.

Usage

From source file:neembuu.uploader.NeembuuUploader.java

/**
 * This displays a small dialog for user to choose the language from a set
 * of available options/*w w  w.  j  a va2  s  .c  o m*/
 */
static void displayLanguageOptionDialog() {
    NeembuuUploaderLanguages.refresh();
    //This code returns the selected language if and only if the user selects the Ok button
    ThemeCheck.apply(null);
    String selectedlanguage = (String) JOptionPane.showInputDialog(NeembuuUploader.getInstance(),
            "Choose your language: ", "Language", JOptionPane.PLAIN_MESSAGE, null,
            NeembuuUploaderLanguages.getLanguageNames(), NeembuuUploaderLanguages.getUserLanguageName());

    //selectedlanguage will be null if the user clicks the cancel or close button
    //so check for that.
    if (selectedlanguage != null) {
        //Set the language to settings file
        NeembuuUploaderLanguages.setUserLanguageByName(selectedlanguage);
        //Change the GUI to new language.
        Translation.changeLanguage(NeembuuUploaderLanguages.getUserLanguageCode());
    }
}

From source file:org.jets3t.apps.cockpit.Cockpit.java

/**
 * Performs the real work of downloading files by comparing the download candidates against
 * existing files, prompting the user whether to overwrite any pre-existing file versions,
 * and starting {@link S3ServiceMulti#downloadObjects} where the real work is done.
 *
 *///from www.  j av  a  2 s .c o  m
private DownloadPackage[] buildDownloadPackageList(FileComparerResults comparisonResults,
        Map s3DownloadObjectsMap) throws Exception {
    // Determine which files to download, prompting user whether to over-write existing files
    List objectKeysForDownload = new ArrayList();
    objectKeysForDownload.addAll(comparisonResults.onlyOnServerKeys);

    int newFiles = comparisonResults.onlyOnServerKeys.size();
    int unchangedFiles = comparisonResults.alreadySynchronisedKeys.size();
    int changedFiles = comparisonResults.updatedOnClientKeys.size()
            + comparisonResults.updatedOnServerKeys.size();

    if (unchangedFiles > 0 || changedFiles > 0) {
        // Ask user whether to replace existing unchanged and/or existing changed files.
        log.debug(
                "Files for download clash with existing local files, prompting user to choose which files to replace");
        List options = new ArrayList();
        String message = "Of the " + (newFiles + unchangedFiles + changedFiles)
                + " objects being downloaded:\n\n";

        if (newFiles > 0) {
            message += newFiles + " files are new.\n\n";
            options.add(DOWNLOAD_NEW_FILES_ONLY);
        }
        if (changedFiles > 0) {
            message += changedFiles + " files have changed.\n\n";
            options.add(DOWNLOAD_NEW_AND_CHANGED_FILES);
        }
        if (unchangedFiles > 0) {
            message += unchangedFiles + " files already exist and are unchanged.\n\n";
            options.add(DOWNLOAD_ALL_FILES);
        }
        message += "Please choose which files you wish to download:";

        Object response = JOptionPane.showInputDialog(ownerFrame, message, "Replace files?",
                JOptionPane.QUESTION_MESSAGE, null, options.toArray(), DOWNLOAD_NEW_AND_CHANGED_FILES);

        if (response == null) {
            return null;
        }

        if (DOWNLOAD_NEW_FILES_ONLY.equals(response)) {
            // No change required to default objectKeysForDownload list.
        } else if (DOWNLOAD_ALL_FILES.equals(response)) {
            objectKeysForDownload.addAll(comparisonResults.updatedOnClientKeys);
            objectKeysForDownload.addAll(comparisonResults.updatedOnServerKeys);
            objectKeysForDownload.addAll(comparisonResults.alreadySynchronisedKeys);
        } else if (DOWNLOAD_NEW_AND_CHANGED_FILES.equals(response)) {
            objectKeysForDownload.addAll(comparisonResults.updatedOnClientKeys);
            objectKeysForDownload.addAll(comparisonResults.updatedOnServerKeys);
        } else {
            // Download cancelled.
            return null;
        }
    }

    log.debug("Downloading " + objectKeysForDownload.size() + " objects");
    if (objectKeysForDownload.size() == 0) {
        return null;
    }

    // Create array of objects for download.
    S3Object[] objects = new S3Object[objectKeysForDownload.size()];
    int objectIndex = 0;
    for (Iterator iter = objectKeysForDownload.iterator(); iter.hasNext();) {
        objects[objectIndex++] = (S3Object) s3DownloadObjectsMap.get(iter.next());
    }

    Map downloadObjectsToFileMap = new HashMap();
    ArrayList downloadPackageList = new ArrayList();

    // Setup files to write to, creating parent directories when necessary.
    for (int i = 0; i < objects.length; i++) {
        File file = new File(downloadDirectory, objects[i].getKey());

        // Encryption password must be null if no password is set.
        String encryptionPassword = null;
        if (cockpitPreferences.isEncryptionPasswordSet()) {
            encryptionPassword = cockpitPreferences.getEncryptionPassword();
        }

        // Create local directories corresponding to objects flagged as dirs.
        if (objects[i].isDirectoryPlaceholder()) {
            file = new File(downloadDirectory,
                    ObjectUtils.convertDirPlaceholderKeyNameToDirName(objects[i].getKey()));
            file.mkdirs();
        }

        DownloadPackage downloadPackage = ObjectUtils.createPackageForDownload(objects[i], file, true, true,
                encryptionPassword);

        if (downloadPackage != null) {
            downloadObjectsToFileMap.put(objects[i].getKey(), file);
            downloadPackageList.add(downloadPackage);
        }

    }

    return (DownloadPackage[]) downloadPackageList.toArray(new DownloadPackage[downloadPackageList.size()]);
}

From source file:ru.apertum.qsystem.client.forms.FAdmin.java

@Action
    public void getTicket() {
        final QService service = (QService) treeServices.getLastSelectedPathComponent();
        if (service != null && service.isLeaf()) {
            //? ?    ,    ?    
            String inputData = null;
            if (service.getInput_required()) {
                inputData = (String) JOptionPane.showInputDialog(this,
                        service.getInput_caption().replaceAll("<[^>]*>", ""), "***", 3, null, null, "");
                if (inputData == null || inputData.isEmpty()) {
                    return;
                }/* ww w.  j a  v a 2s  .  co  m*/
            }

            final QCustomer customer;
            try {
                customer = NetCommander.standInService(new ServerNetProperty(), service.getId(), "1", 1, inputData);
            } catch (Exception ex) {
                throw new ClientException(getLocaleMessage("admin.print_ticket_error") + " " + ex);
            }
            FWelcome.printTicket(customer, ((QService) treeServices.getModel().getRoot()).getName());
            String pref = customer.getPrefix();
            pref = "".equals(pref) ? "" : pref + "-";
            JOptionPane.showMessageDialog(this,
                    getLocaleMessage("admin.print_ticket.title") + " \"" + service.getName() + "\". "
                            + getLocaleMessage("admin.print_ticket.title_1") + " \"" + pref + customer.getNumber()
                            + "\".",
                    getLocaleMessage("admin.print_ticket.caption"), JOptionPane.INFORMATION_MESSAGE);
        }
    }

From source file:org.jets3t.apps.cockpit.Cockpit.java

private S3Object[] buildUploadObjectsList(FileComparerResults comparisonResults,
        Map<String, String> objectKeyToFilepathMap) throws Exception {
    // Determine which files to upload, prompting user whether to over-write existing files
    List fileKeysForUpload = new ArrayList();
    fileKeysForUpload.addAll(comparisonResults.onlyOnClientKeys);

    int newFiles = comparisonResults.onlyOnClientKeys.size();
    int unchangedFiles = comparisonResults.alreadySynchronisedKeys.size();
    int changedFiles = comparisonResults.updatedOnClientKeys.size()
            + comparisonResults.updatedOnServerKeys.size();

    if (unchangedFiles > 0 || changedFiles > 0) {
        // Ask user whether to replace existing unchanged and/or existing changed files.
        log.debug(// ww  w . ja v a2 s.c o  m
                "Files for upload clash with existing S3 objects, prompting user to choose which files to replace");
        List options = new ArrayList();
        String message = "Of the " + objectKeyToFilepathMap.size() + " files being uploaded:\n\n";

        if (newFiles > 0) {
            message += newFiles + " files are new.\n\n";
            options.add(UPLOAD_NEW_FILES_ONLY);
        }
        if (changedFiles > 0) {
            message += changedFiles + " files have changed.\n\n";
            options.add(UPLOAD_NEW_AND_CHANGED_FILES);
        }
        if (unchangedFiles > 0) {
            message += unchangedFiles + " files already exist and are unchanged.\n\n";
            options.add(UPLOAD_ALL_FILES);
        }
        message += "Please choose which files you wish to upload:";

        Object response = JOptionPane.showInputDialog(ownerFrame, message, "Replace files?",
                JOptionPane.QUESTION_MESSAGE, null, options.toArray(), UPLOAD_NEW_AND_CHANGED_FILES);

        if (response == null) {
            return null;
        }

        if (UPLOAD_NEW_FILES_ONLY.equals(response)) {
            // No change required to default fileKeysForUpload list.
        } else if (UPLOAD_ALL_FILES.equals(response)) {
            fileKeysForUpload.addAll(comparisonResults.updatedOnClientKeys);
            fileKeysForUpload.addAll(comparisonResults.updatedOnServerKeys);
            fileKeysForUpload.addAll(comparisonResults.alreadySynchronisedKeys);
        } else if (UPLOAD_NEW_AND_CHANGED_FILES.equals(response)) {
            fileKeysForUpload.addAll(comparisonResults.updatedOnClientKeys);
            fileKeysForUpload.addAll(comparisonResults.updatedOnServerKeys);
        } else {
            // Upload cancelled.
            stopProgressDialog();
            return null;
        }
    }

    if (fileKeysForUpload.size() == 0) {
        return null;
    }

    final String[] statusText = new String[1];
    statusText[0] = "Prepared 0 of " + fileKeysForUpload.size() + " files for upload";
    startProgressDialog(statusText[0], "", 0, 100, null, null);

    long bytesToProcess = 0;
    for (Iterator iter = fileKeysForUpload.iterator(); iter.hasNext();) {
        File file = new File(objectKeyToFilepathMap.get(iter.next().toString()));
        bytesToProcess += file.length() * (cockpitPreferences.isUploadEncryptionActive()
                || cockpitPreferences.isUploadCompressionActive() ? 3 : 1);
    }

    BytesProgressWatcher progressWatcher = new BytesProgressWatcher(bytesToProcess) {
        @Override
        public void updateBytesTransferred(long byteCount) {
            super.updateBytesTransferred(byteCount);

            String detailsText = formatBytesProgressWatcherDetails(this, false);
            int progressValue = (int) ((double) getBytesTransferred() * 100 / getBytesToTransfer());
            updateProgressDialog(statusText[0], detailsText, progressValue);
        }
    };

    // Populate S3Objects representing upload files with metadata etc.
    final S3Object[] objects = new S3Object[fileKeysForUpload.size()];
    int objectIndex = 0;
    for (Iterator iter = fileKeysForUpload.iterator(); iter.hasNext();) {
        String fileKey = iter.next().toString();
        File file = new File(objectKeyToFilepathMap.get(fileKey));

        S3Object newObject = ObjectUtils.createObjectForUpload(fileKey, file,
                (cockpitPreferences.isUploadEncryptionActive() ? encryptionUtil : null),
                cockpitPreferences.isUploadCompressionActive(), progressWatcher);

        String aclPreferenceString = cockpitPreferences.getUploadACLPermission();
        if (CockpitPreferences.UPLOAD_ACL_PERMISSION_PRIVATE.equals(aclPreferenceString)) {
            // Objects are private by default, nothing more to do.
        } else if (CockpitPreferences.UPLOAD_ACL_PERMISSION_PUBLIC_READ.equals(aclPreferenceString)) {
            newObject.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ);
        } else if (CockpitPreferences.UPLOAD_ACL_PERMISSION_PUBLIC_READ_WRITE.equals(aclPreferenceString)) {
            newObject.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ_WRITE);
        } else {
            log.warn("Ignoring unrecognised upload ACL permission setting: " + aclPreferenceString);
        }

        newObject.setStorageClass(cockpitPreferences.getUploadStorageClass());

        statusText[0] = "Prepared " + (objectIndex + 1) + " of " + fileKeysForUpload.size()
                + " files for upload";

        objects[objectIndex++] = newObject;
    }

    stopProgressDialog();

    return objects;
}

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();/* ww  w.  j a v a 2  s  .  co m*/
            } 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;//from  ww w .j  a  v a2 s .c  o  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:org.jets3t.apps.cockpit.Cockpit.java

private void generateTorrentUrl() {
    final S3Object[] objects = getSelectedObjects();

    if (objects.length != 1) {
        log.warn("Ignoring Generate Public URL object command, can only operate on a single object");
        return;//from w  w w . java 2  s .  c o m
    }
    S3Object currentObject = objects[0];

    // Generate URL
    String torrentUrl = s3ServiceMulti.getS3Service().createTorrentUrl(currentSelectedBucket.getName(),
            currentObject.getKey());

    // Display signed URL
    JOptionPane.showInputDialog(ownerFrame, "Torrent URL for '" + currentObject.getKey() + "'.", "Torrent URL",
            JOptionPane.INFORMATION_MESSAGE, null, null, torrentUrl);
}

From source file:au.org.ala.delta.intkey.Intkey.java

@Override
public String promptForString(String message, String initialValue, String directiveName) {
    return (String) JOptionPane.showInputDialog(getMainFrame(), message, directiveName,
            JOptionPane.PLAIN_MESSAGE, null, null, initialValue);
}

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 ww w .j a  v a2s  .  c  o m
            updateBreakpoint();
            updateBreakpointTableColor();
        }
    }
    jAddBreakpointButton.setEnabled(true);
}

From source file:lu.fisch.unimozer.Diagram.java

public void run() {
    try {/*from  www. jav  a 2 s.  co m*/
        // compile all
        //doCompilationOnly(null);
        //frame.setCompilationErrors(new Vector<CompilationError>());
        if (compile()) {

            Vector<String> mains = getMains();
            String runnable = null;
            if (mains.size() == 0) {
                JOptionPane.showMessageDialog(frame,
                        "Sorry, but your project does not contain any runnable public class ...", "Error",
                        JOptionPane.ERROR_MESSAGE, Unimozer.IMG_ERROR);
            } else {

                if (mains.size() == 1) {
                    runnable = mains.get(0);
                } else {
                    String[] classNames = new String[mains.size()];
                    for (int c = 0; c < mains.size(); c++)
                        classNames[c] = mains.get(c);
                    runnable = (String) JOptionPane.showInputDialog(frame,
                            "Unimozer detected more than one runnable class.\n"
                                    + "Please select which one you want to run.",
                            "Run", JOptionPane.QUESTION_MESSAGE, Unimozer.IMG_QUESTION, classNames, "");
                }

                // we know now what to run
                MyClass runnClass = classes.get(runnable);

                // set full signature
                String fullSign = "void main(String[] args)";
                if (runnClass.hasMain2())
                    fullSign = "void main(String args[])";

                // get signature
                String sign = runnClass.getSignatureByFullSignature(fullSign);
                String complete = runnClass.getCompleteSignatureBySignature(sign);

                if ((runnClass.hasMain2()) && (sign.equals("void main(String)"))) {
                    sign = "void main(String[])";
                }

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

                // find method
                Class c = Runtime5.getInstance().load(runnClass.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();
                        genericInputs.put("param" + t, sn);
                        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 += ")";

                    //if((full.equals(sign) || full.equals(fullSign)))
                    //    System.out.println("Found: "+full);

                    if ((full.equals(sign) || full.equals(fullSign))) {
                        LinkedHashMap<String, String> inputs = runnClass.getInputsBySignature(sign);
                        //System.out.println(inputs);
                        //System.out.println(genericInputs);
                        if (inputs.size() != genericInputs.size()) {
                            inputs = genericInputs;
                        }
                        MethodInputs mi = null;
                        boolean go = true;
                        if (inputs.size() > 0) {
                            mi = new MethodInputs(frame, inputs, full, runnClass.getJavaDocBySignature(sign));
                            go = mi.OK;
                        }
                        if (go == true) {
                            try {
                                String method = runnClass.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(""))
                                            val = "null";
                                        else if (!val.startsWith("new String[]")) {
                                            String[] pieces = val.split("\\s+");
                                            String inp = "";
                                            for (int iin = 0; iin < pieces.length; iin++) {
                                                if (inp.equals(""))
                                                    inp = pieces[iin];
                                                else
                                                    inp += "\",\"" + pieces[iin].replace("\"", "\\\"");
                                            }
                                            val = "new String[] {\"" + inp + "\"}";
                                        }

                                        method += val + ",";
                                    }
                                    method = method.substring(0, method.length() - 1);
                                }
                                method += ")";

                                // Invoke method in a new thread
                                final String myMeth = method;
                                Console.disconnectAll();
                                System.out.println("Running now: " + myMeth);
                                Console.connectAll();
                                Runnable r = new Runnable() {
                                    public void run() {
                                        Console.cls();
                                        try {
                                            //Console.disconnectAll();
                                            //System.out.println(myMeth);
                                            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(),
                                                    "Execution 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 (ClassNotFoundException ex) {
        JOptionPane.showMessageDialog(frame, "There was an error while running your project ...",
                "Error :: ClassNotFoundException", JOptionPane.ERROR_MESSAGE, Unimozer.IMG_ERROR);
    }
}