String getNewCollection(Collection<AbstractComponent> sourceComponents) {
    Frame frame = null;
    for (Frame f : Frame.getFrames()) {
      if (f.isActive() || f.isFocused()) {
        frame = f;
      }
    }

    assert frame != null : "Active frame cannot be null.";

    PlaceObjectsInCollectionDialog dialog =
        new PlaceObjectsInCollectionDialog(frame, getSelectedComponentNames(sourceComponents));
    return dialog.getConfirmedTelemetryGroupName();
  }
Exemple #2
0
    @Override
    public void actionPerformed(ActionEvent arg0) {
      for (Frame f : Frame.getFrames()) if (f.isActive()) parent_frame = (JFrame) f;
      if (arg0.getActionCommand().equalsIgnoreCase("Exit")) {
        parent_frame.dispatchEvent(new WindowEvent(parent_frame, WindowEvent.WINDOW_CLOSING));
      } else if (arg0.getActionCommand().equalsIgnoreCase("NEWUSER")) {
        showNewUserDialog(parent_frame);
      } else if (arg0.getActionCommand().equals("START")) {
        TableUI this_game = games.get("MainGame");
        if (this_game != null) {
          this_game.start();
          game_start_menu.setEnabled(false);
        }
      } else if (arg0.getActionCommand().equals("HOST")) {
        game_host_menu.setEnabled(false);
        game_join_menu.setEnabled(false);
        game_start_menu.setEnabled(true);
        GUITable.this.hostGame("MainGame");
      } else if (arg0.getActionCommand().equals("JOIN")) {
        Matcher m = null;
        Object options[] = {"Connect", "Cancel"};
        String host_str = null;
        JOptionPane jp =
            new JOptionPane(
                "Enter host information",
                JOptionPane.QUESTION_MESSAGE,
                JOptionPane.OK_CANCEL_OPTION,
                null,
                options,
                options[0]);
        jp.setWantsInput(true);
        JDialog jd = jp.createDialog(parent_frame.getContentPane(), "Join Game");
        do {
          jd.setVisible(true);
          Object selection = jp.getValue();
          if ((selection == null) || (selection == options[1])) break;

          host_str = (String) jp.getInputValue();
          for (int i = 0; i < connect_str.length; i++) {
            m = connect_str[i].matcher(host_str);
            if (m.matches()) break;
          }

          if ((m != null) && m.matches()) break;
          JOptionPane.showConfirmDialog(
              parent_frame.getContentPane(),
              "Enter valid format for host information",
              "Error",
              JOptionPane.OK_OPTION,
              JOptionPane.ERROR_MESSAGE);
          m = null;
        } while (m == null);

        if (m != null) {
          game_host_menu.setEnabled(false);
          game_join_menu.setEnabled(false);
          game_start_menu.setEnabled(true);
          GUITable.this.joinGame(host_str, "MainGame");
        }
      }
    }