View Javadoc

1   /*
2    * AI Soccer Project - network gaming environment for AI warriors.
3    * Copyright (C) 2001-2004  Marcin Werla, Pawel Widera
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, you can find it here:
17   * http://www.gnu.org/licenses/gpl.html
18   */
19  
20  package aigames.soccer.observer;
21  
22  import java.awt.Component;
23  import java.awt.Dimension;
24  
25  import javax.swing.Box;
26  import javax.swing.BoxLayout;
27  import javax.swing.JPanel;
28  
29  
30  /***
31   * The observer player data panel class.
32   * @version $Id: PlayerPanel.java,v 1.5 2004/05/08 21:55:28 mwerla Exp $
33   */
34  public class PlayerPanel extends JPanel {
35      private static java.awt.Color bgColor = new java.awt.Color(204, 255, 204);
36      private javax.swing.JLabel playerName = null;
37      private javax.swing.JLabel time = null;
38      private javax.swing.JLabel movesTotal = null;
39      private javax.swing.JLabel movesAverage = null;
40      private JPanel topPanel = null;
41      private JPanel bottomPanel = null;
42  
43      /***
44       * This is the default constructor.
45       */
46      public PlayerPanel() {
47          super();
48          initialize();
49      }
50  
51      /***
52       * This method initializes this.
53       */
54      private void initialize() {
55          this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
56          this.add(getTopPanel(), null);
57          this.add(getBottomPanel(), null);
58          this.setBackground(bgColor);
59          this.setBorder(javax.swing.BorderFactory.createLineBorder(
60                  new java.awt.Color(0, 153, 0), 2));
61  
62          Dimension size = this.getPreferredSize();
63          this.setBounds(0, 0, size.width, size.height);
64      }
65  
66      private JPanel getTopPanel() {
67          if (topPanel == null) {
68              topPanel = new JPanel();
69              topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.PAGE_AXIS));
70              topPanel.add(getPlayerName(), null);
71              topPanel.add(Box.createRigidArea(new Dimension(0, 5)));
72              topPanel.add(getTime(), null);
73              topPanel.add(Box.createRigidArea(new Dimension(0, 2)));
74              topPanel.setBackground(bgColor);
75          }
76  
77          return topPanel;
78      }
79  
80      private JPanel getBottomPanel() {
81          if (bottomPanel == null) {
82              bottomPanel = new JPanel();
83              bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.LINE_AXIS));
84              bottomPanel.add(Box.createRigidArea(new Dimension(15, 0)));
85              bottomPanel.add(getMovesTotal(), null);
86              bottomPanel.add(Box.createHorizontalGlue());
87              bottomPanel.add(getMovesAverage(), null);
88              bottomPanel.add(Box.createRigidArea(new Dimension(15, 0)));
89              bottomPanel.setBackground(bgColor);
90          }
91  
92          return bottomPanel;
93      }
94  
95      /***
96       * This method initializes playerName.
97       * @return javax.swing.JLabel
98       */
99      private javax.swing.JLabel getPlayerName() {
100         if (playerName == null) {
101             playerName = new javax.swing.JLabel();
102             playerName.setText("PlayerName");
103             playerName.setForeground(new java.awt.Color(0, 102, 204));
104             playerName.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD,
105                     14));
106             playerName.setAlignmentX(Component.CENTER_ALIGNMENT);
107         }
108 
109         return playerName;
110     }
111 
112     /***
113      * This method initializes time.
114      * @return javax.swing.JLabel
115      */
116     private javax.swing.JLabel getTime() {
117         if (time == null) {
118             time = new javax.swing.JLabel();
119             time.setText("0:00.00");
120             time.setAlignmentX(Component.CENTER_ALIGNMENT);
121         }
122 
123         return time;
124     }
125 
126     /***
127      * This method initializes movesTotal.
128      * @return javax.swing.JLabel
129      */
130     private javax.swing.JLabel getMovesTotal() {
131         if (movesTotal == null) {
132             movesTotal = new javax.swing.JLabel();
133             movesTotal.setText("00");
134             movesTotal.setForeground(new java.awt.Color(255, 153, 0));
135         }
136 
137         return movesTotal;
138     }
139 
140     /***
141      * This method initializes movesAverage.
142      * @return javax.swing.JLabel
143      */
144     private javax.swing.JLabel getMovesAverage() {
145         if (movesAverage == null) {
146             movesAverage = new javax.swing.JLabel();
147             movesAverage.setText("00.0");
148             movesAverage.setForeground(new java.awt.Color(204, 0, 153));
149         }
150 
151         return movesAverage;
152     }
153 
154     /***
155      * Setter for the average moves number.
156      * @param number average moves count
157      */
158     public void setMovesAverage(float number) {
159         movesAverage.setText(Float.toString(number));
160     }
161 
162     /***
163      * Setter for the total moves number.
164      * @param number total moves count
165      */
166     public void setMovesTotal(int number) {
167         movesTotal.setText(Integer.toString(number));
168     }
169 
170     /***
171      * Setter for the player name.
172      * @param name player name
173      */
174     public void setPlayerName(String name) {
175         playerName.setText(name);
176     }
177 
178     /***
179      * Setter for a player play time.
180      * @param time player play time
181      */
182     public void setTime(String time) {
183         this.time.setText(time);
184     }
185 }