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 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
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
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
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 }