~ubuntu-branches/ubuntu/precise/triplea/precise

« back to all changes in this revision

Viewing changes to src/games/strategy/engine/lobby/server/ui/LobbyAdminStatPanel.java

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2011-11-11 21:40:11 UTC
  • Revision ID: package-import@ubuntu.com-20111111214011-sehf2rwat36o2xqf
Tags: upstream-1.3.2.2
ImportĀ upstreamĀ versionĀ 1.3.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This program is free software; you can redistribute it and/or modify
 
3
 * it under the terms of the GNU General Public License as published by
 
4
 * the Free Software Foundation; either version 2 of the License, or
 
5
 * (at your option) any later version.
 
6
 * This program is distributed in the hope that it will be useful,
 
7
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
8
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
9
 * GNU General Public License for more details.
 
10
 * You should have received a copy of the GNU General Public License
 
11
 * along with this program; if not, write to the Free Software
 
12
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
13
 */
 
14
 
 
15
package games.strategy.engine.lobby.server.ui;
 
16
 
 
17
import java.awt.GridLayout;
 
18
import java.util.Date;
 
19
 
 
20
import games.strategy.net.*;
 
21
import games.strategy.triplea.ui.MemoryLabel;
 
22
 
 
23
import javax.swing.*;
 
24
 
 
25
public class LobbyAdminStatPanel extends JPanel
 
26
{
 
27
 
 
28
    private JLabel m_upSince;
 
29
    private JLabel m_maxPlayersLabel;
 
30
    private JLabel m_totalLoginsLabel;
 
31
    private JLabel m_currentLoginsLabel;
 
32
    private int m_maxPlayers;
 
33
    private int m_totalLogins;
 
34
    private int m_currentLogins;
 
35
    private final IMessenger m_messenger;
 
36
    
 
37
    public LobbyAdminStatPanel(IMessenger messenger)
 
38
    {
 
39
        m_messenger = messenger;
 
40
        createComponents();
 
41
        layoutComponents();
 
42
        setupListeners();
 
43
        setWidgetActivation();
 
44
    }
 
45
 
 
46
    private void createComponents()
 
47
    {
 
48
        m_currentLoginsLabel = new JLabel("Current Players: -----");
 
49
        m_maxPlayersLabel = new JLabel("Max Concurrent Players : ----");
 
50
        m_totalLoginsLabel = new JLabel("Total Logins : ------");
 
51
        m_upSince = new JLabel("Up since " + new Date());
 
52
        
 
53
    }
 
54
 
 
55
    private void layoutComponents()
 
56
    {
 
57
        setLayout(new GridLayout(5,1));
 
58
        add(m_currentLoginsLabel);
 
59
        add(m_totalLoginsLabel);
 
60
        add(m_maxPlayersLabel);
 
61
        add(m_upSince);
 
62
        add(new MemoryLabel());
 
63
    }
 
64
 
 
65
    private void setupListeners()
 
66
    {
 
67
        ((IServerMessenger) m_messenger).addConnectionChangeListener(new IConnectionChangeListener()
 
68
        {
 
69
        
 
70
            public void connectionRemoved(INode to)
 
71
            {
 
72
                SwingUtilities.invokeLater(new Runnable()
 
73
                {
 
74
                
 
75
                    public void run()
 
76
                    {
 
77
                        m_currentLogins--;
 
78
                        m_currentLoginsLabel.setText("Current Players: " + m_currentLogins);
 
79
                    }
 
80
                
 
81
                });
 
82
        
 
83
            }
 
84
        
 
85
            public void connectionAdded(INode to)
 
86
            {
 
87
                SwingUtilities.invokeLater(new Runnable()
 
88
                {
 
89
                
 
90
                    public void run()
 
91
                    {
 
92
                        m_currentLogins++;
 
93
                        m_currentLoginsLabel.setText("Current Players: " + m_currentLogins);
 
94
                        
 
95
                        if(m_currentLogins > m_maxPlayers)
 
96
                        {
 
97
                            m_maxPlayers = m_currentLogins;
 
98
                            m_maxPlayersLabel.setText("Max Concurrent Players : " + m_maxPlayers);
 
99
                        }
 
100
                        m_totalLogins++;
 
101
                        m_totalLoginsLabel.setText("Total Logins : " + m_totalLogins);
 
102
                        
 
103
                    }
 
104
                
 
105
                });
 
106
 
 
107
        
 
108
            }
 
109
        
 
110
        });
 
111
        
 
112
    }
 
113
 
 
114
    private void setWidgetActivation()
 
115
    {
 
116
 
 
117
    }
 
118
}