~mchaten/gg/main

« back to all changes in this revision

Viewing changes to main/client/src/net/sf/goodgame/client/gui/Main.java

  • Committer: mchaten
  • Date: 2009-04-22 04:42:26 UTC
  • Revision ID: mchaten@gmail.com-20090422044226-y80omaqtdxk5bcx8
Login Screen initial implementation

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
import java.awt.BorderLayout;
17
17
import java.awt.CardLayout;
18
18
import java.awt.Color;
 
19
import java.awt.Component;
19
20
import java.awt.Dimension;
20
21
import java.awt.Font;
21
22
import java.awt.Graphics;
25
26
import java.awt.image.BufferedImage;
26
27
import java.io.File;
27
28
import java.io.IOException;
28
 
import java.io.InputStream;
29
29
import java.net.InetSocketAddress;
30
30
import java.net.MalformedURLException;
31
31
import java.net.URL;
41
41
import javax.swing.JLayeredPane;
42
42
import javax.swing.JOptionPane;
43
43
import javax.swing.JPanel;
44
 
import javax.swing.JPasswordField;
45
44
import javax.swing.JProgressBar;
46
45
import javax.swing.JScrollPane;
47
46
import javax.swing.JTextArea;
48
 
import javax.swing.JTextField;
49
47
import javax.swing.OverlayLayout;
50
48
import javax.swing.UIManager;
51
49
import net.sf.goodgame.client.game.GameClient;
94
92
    private LobbyList lobbyList;
95
93
    private GameList gameList;
96
94
    private JPanel userActions;
97
 
    private String LOGGEDIN_PANEL = "LIP";
98
 
    private String NOTLOGGEDIN_PANEL = "NLIP";
 
95
    private String NOT_LOGGED_IN_LOOK = "NL";
99
96
    private String LOBBY_LOOK = "LL";
100
97
    private String GAME_LOOK = "GL";
101
98
    private Player myPlayer;
106
103
    private FriendsListGUI friendsListGUI;
107
104
    private GamesTableModel model;
108
105
    private UserType myType;
 
106
    
109
107
    static {
110
108
 
111
109
        Font serif = new Font("SansSerif", Font.PLAIN, 12);
162
160
        lobbyChatBox = new ChatBox("Null", io.getOutgoingConnection(), false);
163
161
 
164
162
        userList = new UserListGUI(privateChatController, io.getOutgoingConnection());
165
 
        JButton loginbutton = new TranslucentJButton("Login", 0.8f);
166
 
        loginbutton.setActionCommand("login");
167
 
        loginbutton.addActionListener(new ActionListener() {
168
 
 
169
 
            public void actionPerformed(ActionEvent e) {
170
 
                getLoginInformation();
171
 
            }
172
 
        });
173
 
 
174
 
        JButton registerbutton = new TranslucentJButton("Register", 0.8f);
175
 
        registerbutton.addActionListener(new ActionListener() {
176
 
 
177
 
            public void actionPerformed(ActionEvent e) {
178
 
                register();
179
 
            }
180
 
        });
181
 
 
 
163
        
182
164
        JButton logoutButton = new TranslucentJButton("Logout", 0.8f);
183
165
        logoutButton.addActionListener(new ActionListener() {
184
166
 
197
179
            }
198
180
        });
199
181
        userActions = new TranslucentJPanel(0.0f);
200
 
        CardLayout cardlayout = new CardLayout();
201
 
        userActions.setLayout(cardlayout);
202
 
 
203
 
        JPanel notloggedinPanel = new JPanel();
204
 
        notloggedinPanel.setOpaque(false);
205
 
        notloggedinPanel.add(loginbutton);
206
 
        notloggedinPanel.add(registerbutton);
207
 
 
208
 
        JPanel loggedinPanel = new JPanel();
209
 
        loggedinPanel.setOpaque(false);
210
 
        loggedinPanel.add(logoutButton);
211
 
        loggedinPanel.add(friends);
212
 
        //  loggedinPanel.add(editmyinfoButton);
213
 
        userActions.add(notloggedinPanel, NOTLOGGEDIN_PANEL);
214
 
        userActions.add(loggedinPanel, LOGGEDIN_PANEL);
 
182
 
 
183
        userActions.add(logoutButton);
 
184
        userActions.add(friends);
215
185
 
216
186
        userList.getComponent().add(userActions, BorderLayout.SOUTH);
217
187
        userList.getComponent().setPreferredSize(new Dimension(200, bottom.getSize().height));
253
223
        guiLayout = new CardLayout();
254
224
        setLayout(guiLayout);
255
225
        add(lobbyLook, LOBBY_LOOK);
256
 
        guiLayout.show(this, LOBBY_LOOK);
 
226
 
 
227
        Component notLoggedInLook = new LoginPanel(this,io).getComponent();
 
228
        add(notLoggedInLook,NOT_LOGGED_IN_LOOK);
 
229
        
 
230
        guiLayout.show(this, NOT_LOGGED_IN_LOOK);
257
231
        io.getIncomingConnection().setPrivateChatController(privateChatController);
258
232
        io.getIncomingConnection().setChatListener(lobbyChatBox);
259
233
        io.getIncomingConnection().setGameClient(null);
359
333
 
360
334
    @Override
361
335
    public void login(String name, UserType type) {
 
336
        if(type == UserType.guest) return;
362
337
        myPlayer = new Player(name);
363
338
        myType = type;
364
 
        if (type.equals(UserType.guest)) {
365
 
            ((CardLayout) userActions.getLayout()).show(userActions, NOTLOGGEDIN_PANEL);
366
 
        } else {
367
 
            friendsList = new FriendsList();
368
 
            io.getIncomingConnection().setFriendsListener(friendsList);
369
 
            friendsListGUI.setFriendsList(friendsList);
370
 
            ((CardLayout) userActions.getLayout()).show(userActions, LOGGEDIN_PANEL);
371
 
 
372
 
        }
 
339
        friendsList = new FriendsList();
 
340
        io.getIncomingConnection().setFriendsListener(friendsList);
 
341
        friendsListGUI.setFriendsList(friendsList);
 
342
        CardLayout layout = this.guiLayout;
 
343
        layout.show(this, LOBBY_LOOK);
373
344
    }
374
345
 
375
346
    public UserType getMyType() {
379
350
    public FriendsList getFriendsList() {
380
351
        return friendsList;
381
352
    }
382
 
 
383
 
 
384
 
 
385
 
    private void getLoginInformation() {
386
 
        String username;
387
 
        String password;
388
 
        Object[] message = new Object[4];
389
 
        message[0] = "Username";
390
 
        message[1] = new JTextField();
391
 
        message[2] = "Password";
392
 
        message[3] = new JPasswordField();
393
 
 
394
 
        String[] options = {"OK", "Cancel"};
395
 
 
396
 
        int result = JOptionPane.showOptionDialog(this, message, "Login",
397
 
                JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
398
 
        if (result == JOptionPane.OK_OPTION) {
399
 
            username = ((JTextField) message[1]).getText();
400
 
            password = new String(((JPasswordField) message[3]).getPassword());
401
 
            io.getOutgoingConnection().login(username, password);
402
 
        }
403
 
    }
404
 
 
 
353
    
405
354
    private void logout() {
406
355
        io.getOutgoingConnection().logout();
 
356
        guiLayout.show(this,NOT_LOGGED_IN_LOOK);
407
357
    }
408
358
 
409
359
    @Override
574
524
        getRootPane().getLayeredPane().add(loadingbox, JLayeredPane.MODAL_LAYER);
575
525
    }
576
526
 
577
 
    private void register() {
578
 
 
579
 
        String username = "";
580
 
        String email = "";
581
 
        String password1 = "";
582
 
        String password2 = "";
583
 
 
584
 
 
585
 
        Object[] message = new Object[9];
586
 
        message[0] = "user name:";
587
 
        message[1] = new JTextField(username);
588
 
        message[2] = "email:";
589
 
        message[3] = new JTextField(email);
590
 
        message[4] = "password:";
591
 
        message[5] = new JPasswordField(password1);
592
 
        message[6] = "retype password:";
593
 
        message[7] = new JPasswordField(password2);
594
 
 
595
 
        String[] options = {
596
 
            "OK",
597
 
            "cancel"
598
 
        };
599
 
 
600
 
        int result = JOptionPane.showOptionDialog(
601
 
                this, // the parent that the dialog blocks 
602
 
                message, // the dialog message array 
603
 
                "Register", // the title of the dialog window 
604
 
                JOptionPane.OK_CANCEL_OPTION, // option type 
605
 
                JOptionPane.QUESTION_MESSAGE, // message type 
606
 
                null, // optional icon, use null to use the default icon 
607
 
                options, // options string array, will be made into buttons 
608
 
                options[0] // option that should be made into a default button 
609
 
                );
610
 
 
611
 
        if (result == JOptionPane.OK_OPTION) {
612
 
 
613
 
            username = ((JTextField) message[1]).getText();
614
 
            email = ((JTextField) message[3]).getText();
615
 
            password1 = new String(((JPasswordField) message[5]).getPassword());
616
 
            password2 = new String(((JPasswordField) message[7]).getPassword());
617
 
            if (!password1.equals(password2)) {
618
 
                this.showError("Passwords do not match");
619
 
            } else {
620
 
                io.getOutgoingConnection().register(username, password1, email);
621
 
            }
622
 
        }
623
 
    }
 
527
    
624
528
    public static URL getCodeBase() {
625
529
 
626
530
        return codebase;