1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package triptracker.client.map.ui;
21
22 import java.awt.CardLayout;
23 import java.awt.Color;
24 import java.awt.Container;
25 import java.util.ArrayList;
26 import java.util.List;
27
28 import javax.swing.JApplet;
29
30 import triptracker.client.net.MapSocket;
31 import triptracker.client.ui.Form;
32 import triptracker.client.ui.FormManager;
33
34 /***
35 * An Applet-GUI for the map client.
36 */
37 @SuppressWarnings("serial")
38 public class MapClientGui extends JApplet implements FormManager {
39 private final MapSocket model;
40
41 private final CardLayout cardLayout;
42 private final Container mainPane;
43
44 private Form currentForm;
45 private List<Form> forms = new ArrayList<Form>();
46
47 TabbedForm tabbedForm;
48 LoginForm loginForm;
49
50 public MapClientGui() {
51 this(new MapSocket());
52 }
53
54 /***
55 * Default constructor.
56 */
57 public MapClientGui(MapSocket model) {
58 super();
59
60 this.model = model;
61
62 mainPane = getContentPane();
63
64 cardLayout = new CardLayout();
65 mainPane.setLayout(cardLayout);
66
67
68
69
70
71
72
73
74 tabbedForm = new TabbedForm(this, "tabbed", model);
75 loginForm = new LoginForm(this, model);
76
77 }
78
79 @Override
80 public void init() {
81
82 String bgColor = getParameter("bgcolor");
83 if (bgColor != null) {
84
85 String[] rgb = bgColor.split(",");
86 if (rgb.length == 3) {
87 try {
88 Color color = new Color(Integer.parseInt(rgb[0]), Integer
89 .parseInt(rgb[1]), Integer.parseInt(rgb[2]));
90 tabbedForm.getFormComponent().setBackground(color);
91 loginForm.getFormComponent().setBackground(color);
92 } catch (NumberFormatException e) {
93 }
94 }
95 }
96
97 showForm(getLoginForm());
98 }
99
100 public void register(Form form) {
101 forms.add(form);
102 mainPane.add(form.getFormComponent(), form.getName());
103
104 if (currentForm == null) {
105 currentForm = form;
106 }
107 }
108
109 public void deregister(Form form) {
110 if (currentForm == form) {
111 currentForm = null;
112 }
113
114 forms.remove(form);
115 }
116
117 public void showForm(Form form) {
118
119 currentForm = form;
120 currentForm.refreshView();
121 cardLayout.show(mainPane, currentForm.getName());
122 }
123
124 public TabbedForm getTabbedForm() {
125 return tabbedForm;
126 }
127
128 /*** Returns loginForm */
129 public LoginForm getLoginForm() {
130 return loginForm;
131 }
132
133 public MapSocket getModel() {
134 return model;
135 }
136 }