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.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.awt.event.ItemEvent;
25 import java.awt.event.ItemListener;
26 import java.awt.event.MouseEvent;
27 import java.awt.event.MouseListener;
28
29 import triptracker.client.net.MapSocket;
30
31 public class MapViewController {
32 private final MapViewPanel view;
33
34 public MapViewController(MapSocket model, MapViewPanel view) {
35 this.view = view;
36
37
38 view.addZoomInBtnListener(new zoomInListener());
39 view.addZoomOutBtnListener(new zoomOutListener());
40 view.addZoomBtnListener(new ZoomListener());
41 view.addMoveBtnListener(new MoveListener());
42 view.addFollowBtnListener(new FollowListener());
43 view.addResetBtnListener(new ResetListener());
44 }
45
46 private class zoomInListener implements ActionListener {
47 public void actionPerformed(ActionEvent e) {
48 view.getMap().zoomIn();
49 }
50 }
51
52 private class zoomOutListener implements ActionListener {
53 public void actionPerformed(ActionEvent e) {
54 view.getMap().zoomOut();
55 }
56 }
57
58 private class ZoomListener implements MouseListener {
59 public void mouseClicked(MouseEvent arg0) {
60 view.setZoom();
61 }
62 public void mousePressed(MouseEvent arg0) {}
63 public void mouseReleased(MouseEvent arg0) {}
64 public void mouseEntered(MouseEvent arg0) {}
65 public void mouseExited(MouseEvent arg0) {}
66 }
67
68 private class MoveListener implements MouseListener {
69 public void mouseClicked(MouseEvent arg0) {
70 view.setMove();
71 }
72 public void mousePressed(MouseEvent arg0) {}
73 public void mouseReleased(MouseEvent arg0) {}
74 public void mouseEntered(MouseEvent arg0) {}
75 public void mouseExited(MouseEvent arg0) {}
76 }
77
78 private class FollowListener implements ItemListener {
79
80 public void itemStateChanged(ItemEvent arg0) {
81 if (((String) arg0.getItem()).equals("Don't follow"))
82 view.setFollow(1);
83 else if(((String) arg0.getItem()).equals("Always inside"))
84 view.setFollow(2);
85 else
86 view.setFollow(3);
87 }
88 }
89
90 private class ResetListener implements ActionListener {
91 public void actionPerformed(ActionEvent arg0) {
92 view.resetMap();
93 }
94 }
95 }