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.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  		// Add listeners to the view.
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  //		 1 = Don't follow, 2 = Always inside, 3 = Center on last
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  }