1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package triptracker.client.gps.ui;
21
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.io.FileNotFoundException;
25 import java.io.IOException;
26 import java.util.TooManyListenersException;
27
28 import gnu.io.PortInUseException;
29 import gnu.io.UnsupportedCommOperationException;
30
31 import triptracker.client.gps.core.GPSClientModel;
32
33 public class GPSSettingsController implements ActionListener {
34 private final GPSClientModel model;
35 private final GPSSettingsForm view;
36
37 public GPSSettingsController(GPSClientModel model, GPSSettingsForm view) {
38 this.model = model;
39 this.view = view;
40
41
42 view.addBtnListener(this);
43 }
44
45 public void actionPerformed(ActionEvent event) {
46
47
48 if (event.getSource() == view.saveButton) {
49
50 view.showMain();
51 model.setCompression(view.getCompression());
52
53
54
55 if (!view.getPort().equals(model.getPort())) {
56 view.setStatusMsg("Closing " + model.getPort() + ", and opening " + view.getPort());
57 model.closeGPSPort();
58 model.setPort(view.getPort());
59 try {
60 model.openGPSPort();
61 } catch (PortInUseException e) {
62 view.setStatusMsg(model.getPort() + " is already in use.");
63 } catch (TooManyListenersException e) {
64 view.setStatusMsg(model.getPort() + " has too many listeners.");
65 } catch (UnsupportedCommOperationException e) {
66 view.setStatusMsg("Unsupported comm operation");
67 } catch (IOException e) {
68 view.setStatusMsg("Comm error");
69 }
70 }
71
72 if (view.getAutoTransfer()) {
73 view.showRoutes();
74 }
75
76 model.autoTransfer(view.getAutoTransfer());
77
78
79 if (model.isConnected() && view.getAutoTransfer()
80 && model.bufferFileExists()) {
81 try {
82 model.transferTmpCoords();
83 } catch (FileNotFoundException e) {
84 view.setStatusMsg("Buffer file was not found");
85 } catch (IllegalStateException e) {
86 view.setStatusMsg("Illegal state");
87 } catch (IOException e) {
88 view.setStatusMsg("Error occured buffering");
89 }
90 view.setStatusMsg("Transferred buffered coordinates");
91 }
92 }
93
94
95 if (event.getSource() == view.cancelButton) {
96 view.showMain();
97 }
98 }
99 }