Пример #1
0
  /**
   * Used to show the message dialogs to the user. @ param parent a reference to the main <code>
   *  Word </code> object @ param msg message to be displayed in the message dialog. @ param type
   * type of the message dialog @ param icon icon to be shown in the message dialog @ param options
   * command options to be displayed in the message dialog @ param selectIndex index of the
   * component to be focused.
   */
  public static int showDialog(
      Component parent,
      String msg,
      int option,
      int type,
      Icon icon,
      Object[] options,
      int selectIndex) {
    // 	Contains the word bundle for the current local
    ResourceBundle wordBundle = Word.wordBundle;
    String messageTitle = wordBundle.getString("MessageTitle");

    String message;

    if (msg.indexOf("RHBD") != -1) // to show "replacement(s) have been done." message.
    message = msg.substring(0, msg.indexOf("RHBD") - 1) + " " + wordBundle.getString("RHBD");
    else message = wordBundle.getString(msg);

    JOptionPane p = new JOptionPane((Object) message, option, type, null, options, options[0]);
    JDialog d = p.createDialog(parent, messageTitle);

    d.setResizable(false);
    d.show();
    Object selectedValue = p.getValue();

    if (selectedValue.equals(new Integer(-1))) {
      d.dispose();
      return JOptionPane.CANCEL_OPTION;
    }

    if (selectedValue == null) {
      d.dispose();
      return JOptionPane.CLOSED_OPTION;
    }

    // If there is not an array of option buttons:
    if (options == null) {
      if (selectedValue instanceof Integer) {
        d.dispose();
        return ((Integer) selectedValue).intValue();
      }
      d.dispose();
      return JOptionPane.CLOSED_OPTION;
    }

    // If there is an array of option buttons:
    for (int counter = 0, maxCounter = options.length; counter < maxCounter; counter++) {
      if (options[counter].equals(selectedValue)) {
        d.dispose();
        return counter;
      }
    }
    d.dispose();
    return 0;
  }