コード例 #1
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;
 }
コード例 #2
0
ファイル: Utils.java プロジェクト: tacolalab/forstudents
  /**
   * 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;
  }
コード例 #3
0
ファイル: APropos.java プロジェクト: sipi/memento
 @Override
 public void actionPerformed(ActionEvent arg0) {
   window.dispose();
 }
コード例 #4
0
ファイル: APropos.java プロジェクト: sipi/memento
    @Override
    public void actionPerformed(ActionEvent e) {

      licence_text =
          new String(
              "This program is free software: you can redistribute it and/or modify\n"
                  + "it under the terms of the GNU General Public License as published by\n"
                  + "the Free Software Foundation, either version 3 of the License, or\n"
                  + "(at your option) any later version.\n"
                  + "\n"
                  + "This program is distributed in the hope that it will be useful,\n"
                  + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
                  + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
                  + "GNU General Public License for more details.\n"
                  + "\n"
                  + "You should have received a copy of the GNU General Public License\n"
                  + "along with this program.  If not, see <http://www.gnu.org/licenses/>.\n"
                  + "\n\n\n");

      try {
        InputStream ips = new FileInputStream(getClass().getResource("COPYING").getPath());
        InputStreamReader ipsr = new InputStreamReader(ips);
        BufferedReader br = new BufferedReader(ipsr);

        String line;
        while ((line = br.readLine()) != null) {
          licence_text += line + '\n';
        }
        br.close();
      } catch (Exception e1) {
      }

      Dimension dimension = new Dimension(600, 400);

      JDialog licence = new JDialog(memento, "Licence");

      JTextPane text_pane = new JTextPane();
      text_pane.setEditable(false);
      text_pane.setPreferredSize(dimension);
      text_pane.setSize(dimension);

      StyledDocument doc = text_pane.getStyledDocument();

      Style justified =
          doc.addStyle(
              "justified",
              StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE));
      StyleConstants.setAlignment(justified, StyleConstants.ALIGN_JUSTIFIED);

      try {
        doc.insertString(0, licence_text, justified);
      } catch (BadLocationException ble) {
        System.err.println("Couldn't insert initial text into text pane.");
      }
      Style logicalStyle = doc.getLogicalStyle(0);
      doc.setParagraphAttributes(0, licence_text.length(), justified, false);
      doc.setLogicalStyle(0, logicalStyle);

      JScrollPane paneScrollPane = new JScrollPane(text_pane);
      paneScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
      paneScrollPane.setPreferredSize(dimension);
      paneScrollPane.setMinimumSize(dimension);

      JPanel pan = new JPanel();
      LayoutManager layout = new BorderLayout();
      pan.setLayout(layout);

      pan.add(new JScrollPane(paneScrollPane), BorderLayout.CENTER);
      JButton close = new JButton("Fermer");
      close.addActionListener(new ButtonCloseActionListener(licence));
      JPanel button_panel = new JPanel();
      FlowLayout button_panel_layout = new FlowLayout(FlowLayout.RIGHT, 20, 20);
      button_panel.setLayout(button_panel_layout);

      button_panel.add(close);
      pan.add(button_panel, BorderLayout.SOUTH);

      licence.add(pan);

      licence.pack();
      licence.setLocationRelativeTo(memento);
      licence.setVisible(true);
    }