ResourceCardChooser() {
    super();

    none = new JToggleButton("none");
    FontUtils.setFont(none, BUTTON_TEXT_SIZE);
    wood = new JToggleButton("wood");
    FontUtils.setFont(wood, BUTTON_TEXT_SIZE);
    brick = new JToggleButton("brick");
    FontUtils.setFont(brick, BUTTON_TEXT_SIZE);
    sheep = new JToggleButton("sheep");
    FontUtils.setFont(sheep, BUTTON_TEXT_SIZE);
    wheat = new JToggleButton("wheat");
    FontUtils.setFont(wheat, BUTTON_TEXT_SIZE);
    ore = new JToggleButton("ore");
    FontUtils.setFont(ore, BUTTON_TEXT_SIZE);

    this.add(none);
    this.add(wood);
    this.add(brick);
    this.add(sheep);
    this.add(wheat);
    this.add(ore);

    this.setSelected(none.getModel(), true);
  }
  private JToggleButton createDevCardButton(String text, String imageFile) {

    final int BUTTON_TEXT_SIZE = 24;

    BufferedImage image = loadDevCardImage(imageFile);

    JToggleButton button =
        new JToggleButton(text, new ImageIcon(image)) {

          @Override
          public void paintComponent(Graphics g) {

            g.setColor(Color.white);
            g.fillRect(0, 0, this.getWidth(), this.getHeight());

            super.paintComponent(g);
          }
        };

    FontUtils.setFont(button, BUTTON_TEXT_SIZE);
    button.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
    button.setBackground(Color.white);
    button.setContentAreaFilled(false);
    button.setVerticalTextPosition(AbstractButton.BOTTOM);
    button.setHorizontalTextPosition(AbstractButton.CENTER);

    button.addChangeListener(
        new ChangeListener() {
          @Override
          public void stateChanged(ChangeEvent arg) {

            JToggleButton source = (JToggleButton) arg.getSource();
            if (source.isSelected()) {
              source.setBorder(BorderFactory.createLineBorder(Color.black, 3));
            } else {
              source.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
            }
          }
        });

    return button;
  }
Beispiel #3
0
  @Override
  public void setPlayers(PlayerInfo[] value) {
    // set header label indicating how many players are still needed
    String labelText = "";
    if (value.length == NUMBER_OF_PLAYERS) {
      labelText = "This game is ready to go!";
      addAiButton.setEnabled(false);
    } else {
      labelText = ("Waiting for Players: Need " + (NUMBER_OF_PLAYERS - value.length) + " more");
      addAiButton.setEnabled(true);
    }

    label.setText(labelText);

    // the center panel contains the individual player panels
    center.removeAll();

    // build an individual player panel and add it to the center panel
    for (int i = 0; i < value.length; i++) {
      String builtString = (i + 1) + " " + value[i].getName();
      JPanel playerPanel = new JPanel();
      playerPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); // left justify the text in the panel
      playerPanel.setPreferredSize(new Dimension(200, 50));
      playerPanel.setBackground(
          value[i].getColor().getJavaColor()); // set the background color of the player
      JLabel playerLabel = new JLabel(builtString, SwingConstants.LEFT); // justify the text left
      FontUtils.setFont(playerLabel, LABEL_TEXT_SIZE);
      playerPanel.add(playerLabel);
      center.add(playerPanel);

      // add space between player panels
      Dimension minSize = new Dimension(5, 10);
      Dimension prefSize = new Dimension(5, 10);
      Dimension maxSize = new Dimension(Short.MAX_VALUE, 10);
      center.add(new Box.Filler(minSize, prefSize, maxSize));
    }
  }
  public PlayDevCardView() {
    this.setOpaque(true);
    this.setBorder(BorderFactory.createLineBorder(Color.black, BORDER_WIDTH));

    this.setLayout(new BorderLayout());

    // Title Panel (immutable)
    JPanel titlePanel = new JPanel(new BorderLayout());
    title = new JLabel("Development Cards");
    FontUtils.setFont(title, LABEL_TEXT_SIZE);
    titlePanel.add(title, BorderLayout.WEST);
    this.add(titlePanel, BorderLayout.NORTH);

    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));

    // Separator
    mainPanel.add(new JSeparator());

    // Blank space
    mainPanel.add(Box.createRigidArea(new Dimension(0, 10)));

    // Development Card Chooser
    devCards = new DevelopmentCardChooser();
    devCards.setListener(btnGrpPnlListener);
    mainPanel.add(devCards);

    // Blank space
    mainPanel.add(Box.createRigidArea(new Dimension(0, 10)));

    JPanel resPanel = new JPanel();
    resPanel.setLayout(new BoxLayout(resPanel, BoxLayout.Y_AXIS));

    // Resource Card 1
    resCard1 = new ResourceCardChooser();
    resCard1.setEnabled(false);
    resCard1.setListener(btnGrpPnlListener);
    mainPanel.add(resCard1);

    // Blank space
    mainPanel.add(Box.createRigidArea(new Dimension(0, 5)));

    // Resource Card 2
    resCard2 = new ResourceCardChooser();
    resCard2.setEnabled(false);
    resCard2.setListener(btnGrpPnlListener);
    resPanel.add(resCard2);

    mainPanel.add(resPanel);

    // Blank space
    mainPanel.add(Box.createRigidArea(new Dimension(0, 10)));

    // Use Dev Card Button
    JPanel usePanel = new JPanel();
    useButton = new JButton(DEFAULT_USE_BUTTON_LABEL);
    useButton.setEnabled(false);
    FontUtils.setFont(useButton, BUTTON_TEXT_SIZE);
    useButton.addActionListener(actionListener);
    usePanel.add(useButton);
    mainPanel.add(usePanel);

    // Blank space
    mainPanel.add(Box.createRigidArea(new Dimension(0, 10)));

    // Cancel Button
    JPanel cancelPanel = new JPanel();
    cancelButton = new JButton("Cancel");
    FontUtils.setFont(cancelButton, BUTTON_TEXT_SIZE);
    cancelButton.addActionListener(actionListener);
    cancelPanel.add(cancelButton);
    mainPanel.add(cancelPanel);

    this.add(mainPanel, BorderLayout.CENTER);
  }
Beispiel #5
0
  public PlayerWaitingView() {

    this.setOpaque(true);
    this.setLayout(new BorderLayout());
    this.setBorder(BorderFactory.createLineBorder(Color.black, BORDER_WIDTH));

    // set the heading at the top of the pane
    label = new JLabel("Player Waiting View");
    FontUtils.setFont(label, LABEL_TEXT_SIZE);
    this.add(label, BorderLayout.NORTH);

    // create the center panel that displays player info
    center = new JPanel();
    center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS));
    this.add(center, BorderLayout.CENTER);

    // create the AI panel for the bottom of the pane
    aiPanel = new JPanel();
    aiPanel.setLayout(new BoxLayout(aiPanel, BoxLayout.Y_AXIS));

    // create the AI type panel
    JPanel aiTypePanel = new JPanel();
    aiTypePanel.setLayout(new BoxLayout(aiTypePanel, BoxLayout.X_AXIS));

    aiTypePanel.add(Box.createHorizontalGlue());

    JLabel aiTypeLabel = new JLabel("Select AI Type:");
    FontUtils.setFont(aiTypeLabel, AI_TEXT_SIZE);
    aiTypePanel.add(aiTypeLabel);

    aiTypePanel.add(Box.createRigidArea(new Dimension(5, 0)));

    aiModel = new SpinnerListModel();
    aiChoices = new JSpinner(aiModel);
    ((JSpinner.DefaultEditor) aiChoices.getEditor()).getTextField().setEditable(false);
    FontUtils.setFont(aiChoices, AI_TEXT_SIZE);
    aiTypePanel.add(aiChoices);

    aiTypePanel.add(Box.createHorizontalGlue());

    aiPanel.add(aiTypePanel);

    aiPanel.add(Box.createRigidArea(new Dimension(0, 10)));

    // create the AI button panel
    JPanel aiButtonPanel = new JPanel();
    aiButtonPanel.setLayout(new BoxLayout(aiButtonPanel, BoxLayout.X_AXIS));

    aiButtonPanel.add(Box.createHorizontalGlue());

    addAiButton = new JButton("Add a computer player");
    addAiButton.addActionListener(actionListener);
    FontUtils.setFont(addAiButton, BUTTON_TEXT_SIZE);
    aiButtonPanel.add(addAiButton);

    aiButtonPanel.add(Box.createHorizontalGlue());

    aiPanel.add(aiButtonPanel);

    aiPanel.add(Box.createRigidArea(new Dimension(0, 10)));

    // add the AI panel
    this.add(aiPanel, BorderLayout.SOUTH);
  }