View Javadoc

1   /*
2    * Trip Tracker, a real-time position tracking system for the Internet.
3    * Copyright (C) 2006  Team Trip Tracker
4    *
5    * This program is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU General Public License as published by the
7    * Free Software Foundation; either version 2 of the License, or (at your
8    * option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful, but
11   * WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13   * General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License along
16   * with this program; if not, write to the Free Software Foundation, Inc.,
17   * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
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  //		layer.addComponentListener(new ComponentAdapter() {
68  //			@Override
69  //            public void componentResized(ComponentEvent evt) {
70  //                 userPassPanel.setSize(mainPanel.getSize());
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  		// Set background color from HTML param.
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 //		currentForm.updateModel(model);
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 }