Esempio n. 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;
  }
 /**
  * Method used by the SystemIO class to get interactive user input requested by a running MIPS
  * program (e.g. syscall #5 to read an integer). SystemIO knows whether simulator is being run at
  * command line by the user, or by the GUI. If run at command line, it gets input from System.in
  * rather than here.
  *
  * <p>This is an overloaded method. This version, with the String parameter, is used to get input
  * from a popup dialog.
  *
  * @param prompt Prompt to display to the user.
  * @return User input.
  */
 public String getInputString(String prompt) {
   String input;
   JOptionPane pane =
       new JOptionPane(prompt, JOptionPane.QUESTION_MESSAGE, JOptionPane.DEFAULT_OPTION);
   pane.setWantsInput(true);
   JDialog dialog = pane.createDialog(Globals.getGui(), "MIPS Keyboard Input");
   dialog.setVisible(true);
   input = (String) pane.getInputValue();
   this.postRunMessage(Globals.userInputAlert + input + "\n");
   return input;
 }