Java Code Examples for javax.swing.JOptionPane#setOptions()

The following examples show how to use javax.swing.JOptionPane#setOptions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BytecodeViewer.java    From bytecode-viewer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Resets the workspace with optional user input required
 *
 * @param ask if should require user input or not
 */
public static void resetWorkSpace(boolean ask)
{
    if(ask)
    {
        JOptionPane pane = new JOptionPane(
                "Are you sure you want to reset the workspace?\n\rIt will also reset your file navigator and search.");
        Object[] options = new String[]{"Yes", "No"};
        pane.setOptions(options);
        JDialog dialog = pane.createDialog(viewer,
                "Bytecode Viewer - Reset Workspace");
        dialog.setVisible(true);
        Object obj = pane.getValue();
        int result = -1;
        for (int k = 0; k < options.length; k++)
            if (options[k].equals(obj))
                result = k;

        if (result != 0)
            return;
    }

    files.clear();
    LazyNameUtil.reset();
    MainViewerGUI.getComponent(FileNavigationPane.class).resetWorkspace();
    MainViewerGUI.getComponent(WorkPane.class).resetWorkspace();
    MainViewerGUI.getComponent(SearchingPane.class).resetWorkspace();
    the.bytecode.club.bytecodeviewer.api.BytecodeViewer.getClassNodeLoader().clear();
}
 
Example 2
Source File: Desktop.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
void doConnect()
{
  final String[] options = new String[Activator.remoteHosts.size()];
  Activator.remoteHosts.copyInto(options);

  // The selection comp I want in the dialog
  final JComboBox combo = new JComboBox(options);
  combo.setEditable(true);

  // Mindboggling complicate way of creating an option dialog
  // without the auto-generated input field

  final JLabel msg = new JLabel(Strings.get("remote_connect_msg"));
  final JPanel panel = new JPanel(new BorderLayout());

  panel.add(combo, BorderLayout.SOUTH);
  panel.add(msg, BorderLayout.NORTH);

  final JOptionPane optionPane =
    new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE);
  optionPane.setIcon(connectIconLarge);
  optionPane.setOptionType(JOptionPane.OK_CANCEL_OPTION);
  optionPane.setWantsInput(false);
  optionPane.setOptions(new String[] { Strings.get("ok"),
                                      Strings.get("cancel"),
                                      Strings.get("local"), });

  optionPane.selectInitialValue();

  final JDialog dialog =
    optionPane.createDialog(frame, Strings.get("remote_connect_title"));
  dialog.setVisible(true);
  dialog.dispose();

  if (!(optionPane.getValue() instanceof String)) { // We'll get an Integer if
                                                    // the user pressed Esc
    return;
  }

  final String value = (String) optionPane.getValue();

  if (Strings.get("cancel").equals(value)) {
    return;
  }

  String s = (String) combo.getSelectedItem();

  if (Strings.get("local").equals(value)) {
    s = "";
  }

  if (!Activator.remoteHosts.contains(s)) {
    Activator.remoteHosts.addElement(s);
  }

  if ((s != null)) {
    Activator.openRemote(s);
  }
}
 
Example 3
Source File: ZStringArrayDecrypter.java    From bytecode-viewer with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void execute(ArrayList<ClassNode> classNodeList) {
    JOptionPane pane = new JOptionPane(
            "WARNING: This will load the classes into the JVM and execute the initialize function" + BytecodeViewer.nl +
                    "for each class. IF THE FILE YOU'RE LOADING IS MALICIOUS, DO NOT CONTINUE."
    );
    Object[] options = new String[]{"Continue", "Cancel"};
    pane.setOptions(options);
    JDialog dialog = pane.createDialog(BytecodeViewer.viewer,
            "Bytecode Viewer - WARNING");
    dialog.setVisible(true);
    Object obj = pane.getValue();
    int result = -1;
    for (int k = 0; k < options.length; k++)
        if (options[k].equals(obj))
            result = k;

    if (result == 0) {
        boolean needsWarning = false;
        for (Class<?> debug : the.bytecode.club.bytecodeviewer.api.BytecodeViewer.loadClassesIntoClassLoader()) {
            try {
                Field[] fields = debug.getDeclaredFields();
                for (Field field : fields) {
                    if (field.getName().equals("z")) {
                        out.append(debug.getName() + ":" + BytecodeViewer.nl);
                        field.setAccessible(true);
                        if (field.get(null) != null && field.get(null) instanceof String[] && Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) {
                            String[] fieldVal = (String[]) field.get(null);
                            for (int i = 0; i < fieldVal.length; i++) {
                                out.append("  z[" + i + "] = " + fieldVal[i] + BytecodeViewer.nl);
                            }
                        }
                    }
                }
            } catch (NoClassDefFoundError | Exception e) {
                System.err.println("Failed loading class " + debug.getName());
                e.printStackTrace();
                needsWarning = true;
            }
        }

        if (needsWarning) {
            BytecodeViewer.showMessage("Some classes failed to decrypt, if you'd like to decrypt all of them" + BytecodeViewer.nl + "makes sure you include ALL the libraries it requires.");
        }

        gui.setText(out.toString());
        gui.setVisible(true);
    }
}