Beispiel #1
0
  @Override
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == gameSelector.getGameList()) {
      theGame = gameSelector.getSelectedGame();

      for (int i = 0; i < roleLabels.size(); i++) {
        gamePanel.remove(roleLabels.get(i));
        gamePanel.remove(playerFields.get(i));
      }

      roleLabels.clear();
      playerFields.clear();

      validate();
      runButton.setEnabled(false);
      if (theGame == null) return;

      StateMachine stateMachine = new ProverStateMachine();
      stateMachine.initialize(theGame.getRules());
      List<Role> roles = stateMachine.getRoles();

      int newRowCount = 11;
      for (int i = 0; i < roles.size(); i++) {
        roleLabels.add(new JLabel(roles.get(i).getName().toString() + ":"));
        playerFields.add(playerSelector.getPlayerSelectorBox());
        playerFields.get(i).setSelectedIndex(i % playerFields.get(i).getModel().getSize());

        gamePanel.add(
            roleLabels.get(i),
            new GridBagConstraints(
                0,
                newRowCount,
                1,
                1,
                1.0,
                0.0,
                GridBagConstraints.EAST,
                GridBagConstraints.NONE,
                new Insets(1, 5, 1, 5),
                5,
                5));
        gamePanel.add(
            playerFields.get(i),
            new GridBagConstraints(
                1,
                newRowCount++,
                1,
                1,
                0.0,
                0.0,
                GridBagConstraints.WEST,
                GridBagConstraints.HORIZONTAL,
                new Insets(1, 5, 1, 5),
                5,
                5));
      }
      gamePanel.add(
          runButton,
          new GridBagConstraints(
              1,
              newRowCount,
              1,
              1,
              0.0,
              1.0,
              GridBagConstraints.SOUTH,
              GridBagConstraints.HORIZONTAL,
              new Insets(5, 5, 5, 5),
              0,
              0));

      validate();
      runButton.setEnabled(true);
    }
  }
Beispiel #2
0
  public Server() {
    super(new GridBagLayout());

    runButton = new JButton(runButtonMethod());
    startClockSpinner = new JSpinner(new SpinnerNumberModel(30, 5, 600, 1));
    playClockSpinner = new JSpinner(new SpinnerNumberModel(15, 5, 300, 1));
    repetitionsSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 1000, 1));
    matchesTabbedPane = new JTabbedPane();

    managerPanel = new JPanel(new GridBagLayout());
    gamePanel = new JPanel(new GridBagLayout());
    playersPanel = new JPanel(new GridBagLayout());

    roleLabels = new ArrayList<JLabel>();
    playerFields = new ArrayList<JComboBox<String>>();
    theGame = null;

    shouldScramble = new JCheckBox("Scramble GDL?", true);
    shouldQueue = new JCheckBox("Queue match?", true);
    shouldDetail = new JCheckBox("Show match details?", true);
    shouldSave = new JCheckBox("Save match to disk?", false);
    shouldPublish = new JCheckBox("Publish match to the web?", false);

    runButton.setEnabled(false);

    gameSelector = new GameSelector();
    playerSelector = new PlayerSelector();
    playerSelectorList = playerSelector.getPlayerSelectorList();

    int nRowCount = 0;
    gamePanel.add(
        new JLabelBold("Match Setup"),
        new GridBagConstraints(
            0,
            nRowCount++,
            3,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 25, 5, 25),
            0,
            0));
    gamePanel.add(
        new JLabel("Repository:"),
        new GridBagConstraints(
            0,
            nRowCount,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 1, 5),
            5,
            5));
    gamePanel.add(
        gameSelector.getRepositoryList(),
        new GridBagConstraints(
            1,
            nRowCount++,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 1, 5),
            5,
            5));
    gamePanel.add(
        new JLabel("Game:"),
        new GridBagConstraints(
            0,
            nRowCount,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(1, 5, 5, 5),
            5,
            5));
    gamePanel.add(
        gameSelector.getGameList(),
        new GridBagConstraints(
            1,
            nRowCount++,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL,
            new Insets(1, 5, 5, 5),
            5,
            5));
    gamePanel.add(
        new JLabel("Start Clock:"),
        new GridBagConstraints(
            0,
            nRowCount,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 1, 5),
            5,
            5));
    gamePanel.add(
        startClockSpinner,
        new GridBagConstraints(
            1,
            nRowCount++,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 1, 5),
            5,
            5));
    gamePanel.add(
        new JLabel("Play Clock:"),
        new GridBagConstraints(
            0,
            nRowCount,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(1, 5, 5, 5),
            5,
            5));
    gamePanel.add(
        playClockSpinner,
        new GridBagConstraints(
            1,
            nRowCount++,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL,
            new Insets(1, 5, 5, 5),
            5,
            5));
    gamePanel.add(
        new JLabel("Repetitions:"),
        new GridBagConstraints(
            0,
            nRowCount,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(1, 5, 5, 5),
            5,
            5));
    gamePanel.add(
        repetitionsSpinner,
        new GridBagConstraints(
            1,
            nRowCount++,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL,
            new Insets(1, 5, 5, 5),
            5,
            5));
    gamePanel.add(
        shouldScramble,
        new GridBagConstraints(
            1,
            nRowCount++,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 0, 5),
            5,
            0));
    gamePanel.add(
        shouldQueue,
        new GridBagConstraints(
            1,
            nRowCount++,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 5, 0, 5),
            5,
            0));
    gamePanel.add(
        shouldDetail,
        new GridBagConstraints(
            1,
            nRowCount++,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 5, 0, 5),
            5,
            0));
    gamePanel.add(
        shouldSave,
        new GridBagConstraints(
            1,
            nRowCount++,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 5, 0, 5),
            5,
            0));
    gamePanel.add(
        shouldPublish,
        new GridBagConstraints(
            1,
            nRowCount++,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 5, 5, 5),
            5,
            0));
    gamePanel.add(
        runButton,
        new GridBagConstraints(
            1,
            nRowCount,
            1,
            1,
            0.0,
            1.0,
            GridBagConstraints.SOUTH,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 5, 5),
            0,
            0));

    nRowCount = 0;
    playersPanel.add(
        new JLabelBold("Player List"),
        new GridBagConstraints(
            0,
            nRowCount++,
            3,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 25, 5, 25),
            0,
            0));
    playersPanel.add(
        new JScrollPane(playerSelectorList),
        new GridBagConstraints(
            0,
            nRowCount++,
            3,
            1,
            1.0,
            1.0,
            GridBagConstraints.WEST,
            GridBagConstraints.BOTH,
            new Insets(5, 25, 5, 25),
            0,
            0));
    playersPanel.add(
        new JButton(addPlayerButtonMethod()),
        new GridBagConstraints(
            0,
            nRowCount,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    playersPanel.add(
        new JButton(removePlayerButtonMethod()),
        new GridBagConstraints(
            1,
            nRowCount,
            1,
            1,
            0.0,
            1.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));
    playersPanel.add(
        new JButton(testPlayerButtonMethod()),
        new GridBagConstraints(
            2,
            nRowCount++,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 5, 5),
            0,
            0));

    nRowCount = 0;
    managerPanel.add(
        gamePanel,
        new GridBagConstraints(
            0,
            nRowCount++,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 5, 5),
            5,
            5));
    managerPanel.add(
        new JSeparator(),
        new GridBagConstraints(
            0,
            nRowCount++,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 5, 5),
            5,
            5));
    managerPanel.add(
        playersPanel,
        new GridBagConstraints(
            0,
            nRowCount++,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH,
            new Insets(5, 5, 5, 5),
            5,
            5));

    this.add(
        managerPanel,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.0,
            1.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(5, 5, 5, 5),
            5,
            5));
    this.add(
        matchesTabbedPane,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(5, 5, 5, 5),
            5,
            5));

    gameSelector.getGameList().addActionListener(this);
    gameSelector.repopulateGameList();

    schedulingPanel = new SchedulingPanel();
    leaderboardPanel = new LeaderboardPanel();
    matchesTabbedPane.addTab("Overview", new OverviewPanel());

    scheduler = new Scheduler(matchesTabbedPane, schedulingPanel, leaderboardPanel);
    schedulingPanel.setScheduler(scheduler);
    scheduler.start();
  }