1 package net.sourceforge.simplegamenet.connectaline;
2
3 import java.awt.*;
4 import javax.swing.*;
5 import net.sourceforge.simplegamenet.specs.tools.ColorIcon;
6 import net.sourceforge.simplegamenet.util.proportionlayout.ProportionConstraints;
7 import net.sourceforge.simplegamenet.util.proportionlayout.ProportionLayout;
8
9 public class CALPlayerPanel extends JPanel {
10
11 private JLabel titleLabel = new JLabel("Player order:");
12 private JLabel[] numberLabel = new JLabel[6];
13 private JLabel[] playerLabel = new JLabel[6];
14 private Color[] colors;
15 private ColorIcon[] colorIcon;
16 private CALPlayerClient cALPlayerClient;
17 private Integer[] participantsOrder;
18
19 CALPlayerPanel(CALPlayerClient cALPlayerClient) {
20 this.cALPlayerClient = cALPlayerClient;
21 ProportionLayout layout = new ProportionLayout();
22 layout.appendColumn(10);
23 layout.appendColumn(0, ProportionLayout.NO_PROPORTION);
24 layout.appendColumn(10);
25 layout.appendColumn(0, 1.0);
26 layout.appendColumn(10);
27 layout.appendRow(10);
28 layout.appendRow(0, ProportionLayout.NO_PROPORTION);
29 for (int i = 0; i < numberLabel.length; i++) {
30 layout.appendRow(10);
31 layout.appendRow(0, ProportionLayout.NO_PROPORTION);
32 }
33 setLayout(layout);
34
35 add(titleLabel, new ProportionConstraints(1, 1, 3, 1, 3, 1));
36 for (int i = 0; i < numberLabel.length; i++) {
37 numberLabel[i] = new JLabel(" ");
38 playerLabel[i] = new JLabel(" ");
39 playerLabel[i].setIcon(new ColorIcon(null));
40 add(numberLabel[i], new ProportionConstraints(1, (2 * i) + 3));
41 add(playerLabel[i], new ProportionConstraints(3, (2 * i) + 3));
42 }
43 }
44
45 public void setCALPlayer() {
46 participantsOrder = cALPlayerClient.getParticipantsOrder();
47 colors = cALPlayerClient.getColors();
48 colorIcon = new ColorIcon[participantsOrder.length];
49 for (int i = 0; i < participantsOrder.length; i++) {
50 colorIcon[i] = new ColorIcon(colors[i]);
51 numberLabel[i].setText(Integer.toString(i + 1) + ".");
52 playerLabel[i].setIcon(colorIcon[i]);
53 playerLabel[i].setText(cALPlayerClient
54 .getCALPlayerNickname(participantsOrder[i]));
55 }
56 }
57
58 public void nextCALPlayer() {
59 participantsOrder = cALPlayerClient.getParticipantsOrder();
60 Integer[] tempParticipantsOrder = new Integer[participantsOrder.length];
61 int currentParticipantsOrderIndex = 0;
62 Color[] tempColorOrder = new Color[participantsOrder.length];
63 for (int i = 0; i < participantsOrder.length; i++) {
64 if (cALPlayerClient.getParticipantAtTurnPlayerID()
65 .equals(participantsOrder[i])) {
66 tempParticipantsOrder[0] = cALPlayerClient
67 .getParticipantAtTurnPlayerID();
68 tempColorOrder[0] = cALPlayerClient.getColors()[i];
69 currentParticipantsOrderIndex = i;
70 }
71 }
72 for (int i = 1; i < participantsOrder.length; i++) {
73 tempParticipantsOrder[i] =
74 participantsOrder[(currentParticipantsOrderIndex + i)
75 % participantsOrder.length];
76 tempColorOrder[i] =
77 cALPlayerClient.getColors()[(currentParticipantsOrderIndex + i)
78 % participantsOrder.length];
79 }
80 for (int i = 0; i < participantsOrder.length; i++) {
81 numberLabel[i].setText(Integer.toString(i + 1) + ".");
82 playerLabel[i].setText(" " + cALPlayerClient
83 .getCALPlayerNickname(tempParticipantsOrder[i]));
84 playerLabel[i].setIcon(new ColorIcon(tempColorOrder[i]));
85 }
86 }
87
88 public void removePlayerLabels() {
89 for (int i = 0; i < participantsOrder.length; i++) {
90 numberLabel[i].setText(" ");
91 playerLabel[i].setIcon(new ColorIcon(null));
92 playerLabel[i].setText(" ");
93 }
94 }
95 }