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 triptracker.client.net.MapSocket;
23  
24  import java.awt.event.ActionEvent;
25  import java.awt.event.ActionListener;
26  import java.awt.event.ItemEvent;
27  import java.awt.event.ItemListener;
28  
29  import javax.swing.event.ChangeEvent;
30  import javax.swing.event.ChangeListener;
31  
32  public class ConfigController {
33  	private final MapSocket model;
34  	private final ConfigPanel view;
35  	
36  	public ConfigController(MapSocket model, ConfigPanel view) {
37  		this.model = model;
38  		this.view = view;
39  		
40  		// Add listeners to the view.
41  		view.addGetUserBtnListener(new getUserBtnListener());
42  		view.addConfigBtnListener(new configBtnListener());
43  		view.addUserBoxListener(new UserBoxListener());
44  		view.addRouteBoxListener(new RouteBoxListener());
45  		
46  		view.addNrBoxListener(new nrBoxListener());
47  		view.addDotBoxListener(new dotBoxListener());
48  		view.addMapBoxListener(new mapBoxListener());
49  		view.addThickSpinnerListener(new thickBoxListener());
50  	}
51  	
52  	/***
53  	 * Actionlistener for getUser button
54  	 * Will add users to userBox
55  	 */
56  	private class getUserBtnListener implements ActionListener {
57  		public void actionPerformed(ActionEvent e) {
58      	  		model.getUsers();  
59  		}
60  	}
61  	
62  	/***
63  	 * Actionlistener for gotoMap button
64  	 * Will change viewed panel in tabbedForm
65  	 */
66  	private class configBtnListener implements ActionListener {
67  		public void actionPerformed(ActionEvent e) {
68  			view.getBoxUser();
69  			view.getBoxRoute();
70  //			model.setRoute(view.getRoute());
71  			view.gotoMap();
72  		}
73  	}
74  	
75  	/***
76  	 * Listener for user ComboBox
77  	 * Shows routes for selected user in userBox
78  	 */
79  	private class UserBoxListener implements ItemListener {
80  		public void itemStateChanged(ItemEvent e) {
81  			if (e.getStateChange() == ItemEvent.SELECTED) {
82  				view.getBoxUser();
83  				if (view.getUser().getUserId() == 0) {
84  					model.getRealtimeRoutes();
85  				} else {
86  					// TODO Make it use userID
87  					model.getRoutes(view.getUser().getUsername());  
88  				}
89  			}
90  		}
91  	}
92  	
93  	/***
94  	 * Listener for route JComboBox
95  	 *
96  	 */
97  	private class RouteBoxListener implements ItemListener {
98  		public void itemStateChanged(ItemEvent e) {
99  			if (e.getStateChange() == ItemEvent.SELECTED) {
100 				view.updateRouteInfo();
101 				if (view.getUser().getUserId() == 0) {
102 					view.realtime = true;
103 				}
104 				else 
105 					view.realtime = false;
106 			}
107 		}
108 	}
109 	
110 	private class nrBoxListener implements ItemListener{
111 		public void itemStateChanged(ItemEvent e) {
112 
113 		}
114 	}
115 	
116 	private class dotBoxListener implements ItemListener{
117 		public void itemStateChanged(ItemEvent e) {
118 			
119 		}
120 	}
121 	
122 	private class mapBoxListener implements ItemListener{
123 		public void itemStateChanged(ItemEvent e) {
124 			
125 		}
126 	}
127 	
128 	private class thickBoxListener implements ChangeListener{
129 		public void stateChanged(ChangeEvent e) {
130 			 view.getBorder();
131 		}
132 	}
133 	
134 }