~mchaten/gg/main

« back to all changes in this revision

Viewing changes to main/client/src/net/sf/goodgame/client/user/userinfo/UserInfoGUI.java

  • Committer: mchaten
  • Date: 2009-04-22 02:40:45 UTC
  • Revision ID: mchaten@gmail.com-20090422024045-si6svkz6uwv5tie9
New Class GUIDispatcher to execute all things related to the GUI on the event thread.
Put the friend and userinfo classes in their own packages inside of client.user
Remove old debug message in MutableNetworkMessage

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * To change this template, choose Tools | Templates
 
3
 * and open the template in the editor.
 
4
 */
 
5
package net.sf.goodgame.client.user.userinfo;
 
6
 
 
7
import java.util.LinkedHashSet;
 
8
import java.util.List;
 
9
import java.util.Set;
 
10
import java.util.Vector;
 
11
import javax.swing.JComponent;
 
12
import javax.swing.JList;
 
13
import javax.swing.JTabbedPane;
 
14
import net.sf.goodgame.shared.UserInfoElement;
 
15
 
 
16
/**
 
17
 *
 
18
 * @author mchaten
 
19
 */
 
20
public class UserInfoGUI {
 
21
 
 
22
    private final String username;
 
23
    private Set<UserInfoElement> elements;
 
24
    private JTabbedPane root;
 
25
    private JList userSupplied;
 
26
    private JList gameResults;
 
27
 
 
28
    public UserInfoGUI(String username, List<UserInfoElement> elements) {
 
29
        this.username = username;
 
30
        this.elements = new LinkedHashSet<UserInfoElement>();
 
31
        userSupplied = new JList();
 
32
        userSupplied.setCellRenderer(new UserInfoListCellRenderer());
 
33
        gameResults = new JList();
 
34
        gameResults.setCellRenderer(new UserInfoListCellRenderer());
 
35
        root = new JTabbedPane();
 
36
        root.addTab("User Supplied", userSupplied);
 
37
        root.addTab("Game Results", gameResults);
 
38
        setElements(elements);
 
39
    }
 
40
 
 
41
    public JComponent getComponent() {
 
42
        return root;
 
43
    }
 
44
 
 
45
    public void setElements(List<UserInfoElement> newElements) {
 
46
        elements.removeAll(newElements);
 
47
        elements.addAll(newElements); //Replace the old elements with the new.
 
48
        Vector<UserInfoElement> gameResultsElements = new Vector<UserInfoElement>(elements.size());
 
49
        Vector<UserInfoElement> userSuppliedElements = new Vector<UserInfoElement>(elements.size());
 
50
        for (UserInfoElement element : elements) {
 
51
            switch (element.getType()) {
 
52
                case userSupplied:
 
53
                    System.out.println("User Supplied: "+element);
 
54
                    userSuppliedElements.add(element);
 
55
                    break;
 
56
                case gameResults:
 
57
                    System.out.println("Game Result: "+element);
 
58
                    gameResultsElements.add(element);
 
59
                    break;
 
60
                default:
 
61
                    System.out.println("Unknown UserInfoType: " + element.getType());
 
62
                    break;
 
63
            }
 
64
        }
 
65
        userSupplied.setListData(userSuppliedElements);
 
66
        gameResults.setListData(gameResultsElements);
 
67
    }
 
68
 
 
69
    public String getUsername() {
 
70
        return username;
 
71
    }
 
72
}