Ticket #47: bbtracker_src_0415.txt

File bbtracker_src_0415.txt, 34.4 kB (added by sibion, 1 year ago)
Line 
1 Index: C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/BBTracker.java
2 ===================================================================
3 --- C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/BBTracker.java (revision 109)
4 +++ C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/BBTracker.java (working copy)
5 @@ -132,6 +132,15 @@
6         public static Timer getTimer() {
7                 return instance.timer;
8         }
9 +       
10 +       public void resetApp(){
11 +               firstStart = true;
12 +               try {
13 +                       startApp();
14 +               } catch (MIDletStateChangeException e) {
15 +                       e.printStackTrace();
16 +               }
17 +       }
18  
19         public static void nonFatal(final Throwable t, final String action, final Displayable next) {
20                 log(BBTracker.class, t, "non-fatal " + action);
21 Index: C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/FileTrackStore.java
22 ===================================================================
23 --- C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/FileTrackStore.java    (revision 109)
24 +++ C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/FileTrackStore.java    (working copy)
25 @@ -139,7 +139,9 @@
26         }
27  
28         private String getTrackDirectory() throws TrackStoreException {
29 +               //Updated 2007 SIB to store in BBT Directory
30                 final String dir = Preferences.getInstance().getTrackDirectory();
31 +               //End Update 2007 SIB
32                 if (dir == null) {
33                         throw new TrackStoreException("No track directory set, please configure it on the options screen!");
34                 }
35 Index: C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/Preferences.java
36 ===================================================================
37 --- C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/Preferences.java       (revision 109)
38 +++ C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/Preferences.java       (working copy)
39 @@ -95,6 +95,10 @@
40         private int detailsFontSize = Font.SIZE_MEDIUM;
41  
42         private String trackDirectory;
43 +       
44 +       //Added 2007 SIB
45 +       private String exportDirectory;
46 +       //End Added 2007 SIB
47  
48         private UnitConverter unitConverter;
49  
50 @@ -120,6 +124,12 @@
51         public String getTrackDirectory() {
52                 return trackDirectory;
53         }
54 +       
55 +       //Added 2007 SIB
56 +       public String getExportDirectory() {
57 +               return exportDirectory;
58 +       }
59 +       //End Added 2007 SIB
60  
61         public void setTrackDirectory(final String trackDirectory) {
62                 if (trackDirectory == null || trackDirectory.length() == 0) {
63 @@ -131,6 +141,19 @@
64                         }
65                 }
66         }
67 +       
68 +       //Added 2007 SIB
69 +       public void setExportDirectory(final String exportDirectory) {
70 +               if (exportDirectory == null || exportDirectory.length() == 0) {
71 +                       this.exportDirectory = null;
72 +               } else {
73 +                       this.exportDirectory = exportDirectory;
74 +                       if (!this.exportDirectory.endsWith("/")) {
75 +                               this.exportDirectory += "/";
76 +                       }
77 +               }
78 +       }
79 +       //End Added 2007 SIB
80  
81         public void setExportFormat(final int index, final boolean value) {
82                 if (index >= EXPORT_FORMATS.length || index < 0) {
83 @@ -220,11 +243,18 @@
84                                 startAction = in.readShort();
85                                 sampleInterval = in.readInt();
86                                 trackNumber = in.readInt();
87 -                               if (in.readByte() != 0) {
88 +                               if (in.readByte() == 1) {
89                                         trackDirectory = in.readUTF();
90                                 } else {
91                                         trackDirectory = null;
92                                 }
93 +                               //Added 2007 SIB
94 +                               if (in.readByte() == 3) {
95 +                                       exportDirectory = in.readUTF();
96 +                               } else {
97 +                                       exportDirectory = null;
98 +                               }
99 +                               //End Added 2007 SIB
100                                 exportFormats = in.readInt();
101                                 units = in.readInt();
102                                 statusFontSize = in.readInt();
103 @@ -268,11 +298,24 @@
104                         out.writeShort(startAction);
105                         out.writeInt(sampleInterval);
106                         out.writeInt(trackNumber);
107 -                       if (trackDirectory == null) {
108 -                               out.writeByte(0);
109 -                       } else {
110 +                       if (trackDirectory == null && exportDirectory != null){
111                                 out.writeByte(1);
112 +                               out.writeUTF(exportDirectory);
113 +                               out.writeByte(3);
114 +                               out.writeUTF(exportDirectory);
115 +                       } else if (trackDirectory != null & exportDirectory == null){
116 +                               out.writeByte(1);
117                                 out.writeUTF(trackDirectory);
118 +                               out.writeByte(3);
119 +                               out.writeUTF(trackDirectory);
120 +                       } else if (trackDirectory != null && exportDirectory != null){
121 +                               out.writeByte(1);
122 +                               out.writeUTF(trackDirectory);
123 +                               out.writeByte(3);
124 +                               out.writeUTF(exportDirectory);
125 +                       } else {
126 +                               out.writeByte(0);
127 +                               out.writeByte(2);
128                         }
129                         out.writeInt(exportFormats);
130                         out.writeInt(units);
131 Index: C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/gui/StatusTile.java
132 ===================================================================
133 --- C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/gui/StatusTile.java    (revision 109)
134 +++ C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/gui/StatusTile.java    (working copy)
135 @@ -67,6 +67,7 @@
136  
137         private int pointWidth;
138  
139 +
140         private boolean twoLineLayout = true;
141  
142         public StatusTile(final TrackManager manager) {
143 @@ -123,6 +124,7 @@
144                 float courseValue = Float.NaN;
145                 float elevationValue = Float.NaN;
146                 double lengthValue = Double.NaN;
147 +               String timeString = "-";
148                 if (p != null) {
149                         lonValue = p.getLongitude();
150                         latValue = p.getLatitude();
151 @@ -132,8 +134,12 @@
152                 }
153                 if (track != null) {
154                         lengthValue = track.getLength();
155 +                       if (p != null) {
156 +                               final long offset = track.getPointOffset(p);
157 +                               timeString = Utils.durationToString(offset);
158 +                       }
159                 }
160 -
161 +               
162                 final String lon = Utils.longitudeToString(lonValue);
163                 final String lat = Utils.latitudeToString(latValue);
164                 final String course = Utils.courseToHeadingString(courseValue);
165 @@ -170,20 +176,28 @@
166                 int lengthY;
167                 final int pointX;
168                 int pointY;
169 +               int timeY;
170  
171                 if (twoLineLayout) {
172                         lengthX = width - MARGIN;
173                         lengthY = line1;
174                         pointX = lengthX;
175                         pointY = line2;
176 +                       timeY = line2;
177                 } else {
178                         lengthX = width / 2;
179                         lengthY = line2 + font.getHeight();
180                         pointX = width - MARGIN;
181                         pointY = lengthY;
182 +                       //Added 2007 SIB
183 +                       timeY = lengthY;
184 +                       //End Added 2007 SIB
185                 }
186                 g.drawString(length, lengthX, lengthY, Graphics.TOP | Graphics.RIGHT);
187                 g.drawString(point, pointX, pointY, Graphics.TOP | Graphics.RIGHT);
188 +               //Added 2007 SIB
189 +               g.drawString(timeString, 1, timeY, Graphics.TOP | Graphics.LEFT);
190 +               //End Added 2007 SIB
191         }
192  
193         public void showNotify() {
194 Index: C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/gui/DetailsTile.java
195 ===================================================================
196 --- C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/gui/DetailsTile.java   (revision 109)
197 +++ C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/gui/DetailsTile.java   (working copy)
198 @@ -45,6 +45,8 @@
199         private static final String DISTANCE_LABEL = "Distance: ";
200  
201         private static final String SPEED_LABEL = "Speed: ";
202 +       
203 +       private static final String PACE_LABEL = "Pace: ";
204  
205         private static final String POINT_LABEL = "Point: ";
206  
207 @@ -74,6 +76,7 @@
208                 updateLabeWidth(SPEED_LABEL);
209                 updateLabeWidth(POINT_LABEL);
210                 updateLabeWidth(NAME_LABEL);
211 +               updateLabeWidth(PACE_LABEL);
212         }
213  
214         private void updateLabeWidth(final String label) {
215 Index: C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/gui/TracksForm.java
216 ===================================================================
217 --- C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/gui/TracksForm.java    (revision 109)
218 +++ C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/gui/TracksForm.java    (working copy)
219 @@ -135,7 +135,7 @@
220                                 BBTracker.getInstance().showMainCanvas();
221                         } else if (command == exportCommand) {
222                                 final Preferences preferences = Preferences.getInstance();
223 -                               final String dir = preferences.getTrackDirectory();
224 +                               final String dir = preferences.getExportDirectory();
225                                 if (dir == null) {
226                                         final Alert alert = new Alert("No track directory defined!",
227                                                         "Please define an export directory in the options screen.", null, AlertType.WARNING);
228 Index: C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/gui/SummaryTile.java
229 ===================================================================
230 --- C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/gui/SummaryTile.java   (revision 0)
231 +++ C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/gui/SummaryTile.java   (revision 0)
232 @@ -0,0 +1,196 @@
233 +/*
234 + * Copyright 2007 SIB
235 + * Copyright 2007 Joachim Sauer
236 + *
237 + * This file is part of bbTracker.
238 + *
239 + * bbTracker is free software; you can redistribute it and/or modify
240 + * it under the terms of the GNU General Public License version 2 as
241 + * published by the Free Software Foundation.
242 + *
243 + * bbTracker is distributed in the hope that it will be useful,
244 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
245 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
246 + * GNU General Public License for more details.
247 + *
248 + * You should have received a copy of the GNU General Public License
249 + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
250 + */
251 +package org.bbtracker.mobile.gui;
252 +
253 +import java.util.Date;
254 +
255 +import javax.microedition.lcdui.Font;
256 +import javax.microedition.lcdui.Graphics;
257 +
258 +import org.bbtracker.Track;
259 +import org.bbtracker.TrackPoint;
260 +import org.bbtracker.UnitConverter;
261 +import org.bbtracker.Utils;
262 +import org.bbtracker.mobile.Preferences;
263 +import org.bbtracker.mobile.TrackManager;
264 +
265 +public class SummaryTile extends Tile {
266 +
267 +       private static final String MAX_ELEVATION_LABEL = "Max Elev: ";
268 +       
269 +       private static final String MIN_ELEVATION_LABEL = "Min Elev: ";
270 +       
271 +       private static final String GAIN_ELEVATION_LABEL = "Total Gain: ";
272 +
273 +       private static final String TIME_LABEL = "Time: ";
274 +       
275 +       private static final String START_TIME_LABEL = "Start Time: ";
276 +       
277 +       private static final String END_TIME_LABEL = "End Time: ";
278 +
279 +       private static final String DISTANCE_LABEL = "Distance: ";
280 +
281 +       private static final String MAX_SPEED_LABEL = "Max Speed: ";
282 +       
283 +       private static final String AVG_SPEED_LABEL = "Avg Speed: ";
284 +       
285 +       private static final String POINTS_LABEL = "Points: ";
286 +
287 +       private static final String NAME_LABEL = "Name: ";
288 +
289 +       private static final int MARGIN = 2;
290 +
291 +       private final TrackManager manager;
292 +
293 +       private Font font;
294 +
295 +       private int labelWidth;
296 +
297 +       public SummaryTile(final TrackManager manager) {
298 +               this.manager = manager;
299 +               setFontSize(Font.SIZE_SMALL);
300 +       }
301 +
302 +       private void setFontSize(final int fontSize) {
303 +               font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, fontSize);
304 +               labelWidth = 0;
305 +               updateLabeWidth(MAX_ELEVATION_LABEL);
306 +               updateLabeWidth(MIN_ELEVATION_LABEL);
307 +               updateLabeWidth(GAIN_ELEVATION_LABEL);
308 +               updateLabeWidth(TIME_LABEL);
309 +               updateLabeWidth(START_TIME_LABEL);
310 +               updateLabeWidth(END_TIME_LABEL);
311 +               updateLabeWidth(DISTANCE_LABEL);
312 +               updateLabeWidth(MAX_SPEED_LABEL);
313 +               updateLabeWidth(AVG_SPEED_LABEL);
314 +               updateLabeWidth(POINTS_LABEL);
315 +               updateLabeWidth(NAME_LABEL);
316 +       }
317 +
318 +       private void updateLabeWidth(final String label) {
319 +               final int w = font.stringWidth(label);
320 +               if (w > labelWidth) {
321 +                       labelWidth = w;
322 +               }
323 +       }
324 +
325 +       protected void doPaint(final Graphics g) {
326 +               final Track track = manager.getTrack();
327 +
328 +               g.setColor(0x00ffffff);
329 +               g.fillRect(0, 0, width, height);
330 +               g.setColor(0x00000000);
331 +               g.setFont(font);
332 +
333 +               float avgspeedValue = Float.NaN;
334 +               float avgmovingspeedValue = Float.NaN;
335 +               float maxspeedValue = Float.NaN;
336 +               float maxelevationValue = Float.NaN;
337 +               float minelevationValue = Float.NaN;
338 +               float gainelevationValue = Float.NaN;
339 +               double lengthValue = Double.NaN;
340 +               int pointcountValue = 0;
341 +               int pointcountEndTime = 0;
342 +               String timeString = "-";
343 +               String pointendTime = "-";
344 +               String pointstartTime = "-";
345 +               String points = "-";
346 +               if (track != null) {
347 +                       lengthValue = track.getLength();
348 +                       maxspeedValue = track.getMaxSpeed();
349 +                       avgspeedValue = track.getAvgSpeed();
350 +                       avgmovingspeedValue = track.getAvgMovingSpeed();
351 +                       maxelevationValue = track.getMaxElevation();
352 +                       minelevationValue = track.getMinElevation();
353 +                       gainelevationValue = track.getElevationGain();
354 +                       pointcountValue = track.getPointCount();
355 +                       points = pointcountValue + "";
356 +                       if (track.getPointCount() > 0) {
357 +                               final TrackPoint lastPoint = track.getPoint(track.getPointCount() - 1);
358 +                               final long duration = track.getPointOffset(lastPoint);
359 +                               timeString = Utils.durationToString(duration);
360 +                               pointcountEndTime = track.getPointCount() - 1;
361 +                               TrackPoint pEnd = track.getPoint(pointcountEndTime);
362 +                               pointendTime = new Date(pEnd.getTimestamp()).toString().substring(11, 19);
363 +                               TrackPoint pStart = track.getPoint(0);
364 +                               pointstartTime = new Date(pStart.getTimestamp()).toString().substring(11, 19);
365 +                       }
366 +               }
367 +               
368 +               final String trackName;
369 +               if (track == null) {
370 +                       trackName = "-";
371 +               } else {
372 +                       if (manager.getState() == TrackManager.STATE_STATIC) {
373 +                               trackName = track.getName() + " (static)";
374 +                       } else {
375 +                               trackName = track.getName();
376 +                       }
377 +               }
378 +               
379 +               final UnitConverter unit = Preferences.getInstance().getUnitsConverter();
380 +               final String maxspeed = unit.speedToString(maxspeedValue);
381 +               final String avgspeed = unit.speedToString(avgspeedValue) + " (" + unit.speedToString(avgmovingspeedValue) + ")";
382 +               final String maxelevation = unit.elevationToString(maxelevationValue);
383 +               final String minelevation = unit.elevationToString(minelevationValue);
384 +               final String gainelevation = unit.elevationToString(gainelevationValue);
385 +               final String length = unit.distanceToString(lengthValue);
386 +
387 +               final int fontHeight = font.getHeight();
388 +               final int x = MARGIN + labelWidth;
389 +               int y = MARGIN;
390 +
391 +               g.drawString(NAME_LABEL, MARGIN, y, Graphics.TOP | Graphics.LEFT);
392 +               g.drawString(trackName, x, y, Graphics.TOP | Graphics.LEFT);
393 +               y += fontHeight;
394 +               g.drawString(POINTS_LABEL, MARGIN, y, Graphics.TOP | Graphics.LEFT);
395 +               g.drawString(points, x, y, Graphics.TOP | Graphics.LEFT);
396 +               y += fontHeight;
397 +               g.drawString(DISTANCE_LABEL, MARGIN, y, Graphics.TOP | Graphics.LEFT);
398 +               g.drawString(length, x, y, Graphics.TOP | Graphics.LEFT);
399 +               y += fontHeight;
400 +               g.drawString(START_TIME_LABEL, MARGIN, y, Graphics.TOP | Graphics.LEFT);
401 +               g.drawString(pointstartTime, x, y, Graphics.TOP | Graphics.LEFT);
402 +               y += fontHeight;
403 +               g.drawString(END_TIME_LABEL, MARGIN, y, Graphics.TOP | Graphics.LEFT);
404 +               g.drawString(pointendTime, x, y, Graphics.TOP | Graphics.LEFT);
405 +               y += fontHeight;
406 +               g.drawString(TIME_LABEL, MARGIN, y, Graphics.TOP | Graphics.LEFT);
407 +               g.drawString(timeString, x, y, Graphics.TOP | Graphics.LEFT);
408 +               y += fontHeight * 2;
409 +               g.drawString(MAX_SPEED_LABEL, MARGIN, y, Graphics.TOP | Graphics.LEFT);
410 +               g.drawString(maxspeed, x, y, Graphics.TOP | Graphics.LEFT);
411 +               y += fontHeight;
412 +               g.drawString(AVG_SPEED_LABEL, MARGIN, y, Graphics.TOP | Graphics.LEFT);
413 +               g.drawString(avgspeed, x, y, Graphics.TOP | Graphics.LEFT);
414 +               y += fontHeight * 2;
415 +               g.drawString(MAX_ELEVATION_LABEL, MARGIN, y, Graphics.TOP | Graphics.LEFT);
416 +               g.drawString(maxelevation, x, y, Graphics.TOP | Graphics.LEFT);
417 +               y += fontHeight;
418 +               g.drawString(MIN_ELEVATION_LABEL, MARGIN, y, Graphics.TOP | Graphics.LEFT);
419 +               g.drawString(minelevation, x, y, Graphics.TOP | Graphics.LEFT);
420 +               y += fontHeight;
421 +               g.drawString(GAIN_ELEVATION_LABEL, MARGIN, y, Graphics.TOP | Graphics.LEFT);
422 +               g.drawString(gainelevation, x, y, Graphics.TOP | Graphics.LEFT);
423 +               }
424 +
425 +       public void showNotify() {
426 +               setFontSize(Preferences.getInstance().getDetailsFontSize());
427 +       }
428 +}
429 \ No newline at end of file
430 Index: C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/gui/OptionsForm.java
431 ===================================================================
432 --- C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/gui/OptionsForm.java   (revision 109)
433 +++ C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/gui/OptionsForm.java   (working copy)
434 @@ -50,13 +50,19 @@
435         private final Command cancelCommand;
436  
437         private final Command browseCommand;
438 +       
439 +       //Added 2007 SIB
440 +       private final Command browseExportCommand;
441  
442 +       private final TextField exportdirectoryField;
443 +       //End Added 2007 SIB
444 +
445         private final TextField sampleField;
446  
447         private final ChoiceGroup startTypeGroup;
448  
449         private final TextField directoryField;
450 -
451 +               
452         private final ChoiceGroup exportFormatGroup;
453  
454         private final ChoiceGroup unitsGroup;
455 @@ -97,11 +103,18 @@
456                 browseCommand = new Command("Browse", Command.ITEM, 1);
457                 directoryField.setDefaultCommand(browseCommand);
458                 directoryField.setItemCommandListener(this);
459 -
460 +               
461                 exportFormatGroup = new ChoiceGroup("Export to: ", Choice.MULTIPLE, Preferences.EXPORT_FORMATS, null);
462                 for (int i = 0; i < Preferences.EXPORT_FORMATS.length; i++) {
463                         exportFormatGroup.setSelectedIndex(i, pref.getExportFormat(i));
464                 }
465 +               
466 +               //Added 2007 SIB
467 +               exportdirectoryField = new TextField("Export directory: ", pref.getExportDirectory(), 100, TextField.URL);
468 +               browseExportCommand = new Command("Browse", Command.ITEM, 1);
469 +               exportdirectoryField.setDefaultCommand(browseExportCommand);
470 +               exportdirectoryField.setItemCommandListener(this);
471 +               //End Added 2007 SIB
472  
473                 append(sampleField);
474                 append(unitsGroup);
475 @@ -109,8 +122,13 @@
476                 append(detailsFontSizeGroup);
477                 append(startTypeGroup);
478                 append(directoryField);
479 +               //Added 2007 SIB
480 +               append("");
481 +               append(exportdirectoryField);
482 +               append("");
483 +               //End Added 2007 SIB
484                 append(exportFormatGroup);
485 -
486 +               
487                 okCommand = new Command("OK", Command.OK, 0);
488                 cancelCommand = new Command("Cancel", Command.CANCEL, 1);
489  
490 @@ -185,9 +203,26 @@
491  
492         private String validatePreferences() {
493                 final String trackDir = directoryField.getString();
494 +               //Added 2007 SIB
495 +               final String exportDir = exportdirectoryField.getString();
496 +               //End Added 2007 SIB
497                 if (trackDir == null || trackDir.length() == 0) {
498 -                       return "No track directory has been selected!";
499 -               } else {
500 +                       if (exportDir == null || exportDir.length()== 0){
501 +                               return "No directories have been selected!";
502 +                       } else {
503 +                               return "No Track Directory has been selected! The Export Directory will be used! (" + exportDir + ")";
504 +                       }
505 +               //Added 2007 SIB
506 +               }else if (exportDir == null || exportDir.length()== 0){
507 +                       if (trackDir == null || trackDir.length() == 0){
508 +                               return "No directories have been selected!";
509 +                       } else {
510 +                               return "No Export Directory has been selected! The Track Directory will be used! (" + trackDir + ")";
511 +                       }
512 +               // End Added 2007 SIB
513 +               // Updated 2007 SIB
514 +               } else if (trackDir != null){
515 +               // End Updated 2007 SIB
516                         FileConnection connection = null;
517                         try {
518                                 connection = (FileConnection) Connector.open("file:///" + trackDir, Connector.READ);
519 @@ -211,7 +246,33 @@
520                                         }
521                                 }
522                         }
523 +               //Added 2007 SIB
524 +               } else if (exportDir != null){
525 +                       FileConnection connection = null;
526 +                       try {
527 +                               connection = (FileConnection) Connector.open("file:///" + exportDir, Connector.READ);
528 +                               if (!connection.exists()) {
529 +                                       return "The directory identified by <" + exportDir + "> does not exist.";
530 +                               } else if (!connection.isDirectory()) {
531 +                                       return "The file identified by <" + exportDir + "> is not a directory.";
532 +                               } else if (!connection.canWrite()) {
533 +                                       return "The directory identified by <" + exportDir + "> is not writeable.";
534 +                               }
535 +                       } catch (final IOException e) {
536 +                               return "Could not verify track directory <" + exportDir + ">: " + e.getMessage();
537 +                       } catch (final IllegalArgumentException e) {
538 +                               return "Malformed track directory <" + exportDir + ">!";
539 +                       } finally {
540 +                               if (connection != null) {
541 +                                       try {
542 +                                               connection.close();
543 +                                       } catch (final IOException ignored) {
544 +                                               // ignore
545 +                                       }
546 +                               }
547 +                       }
548                 }
549 +               //End Added 2007 SIB
550                 return null;
551         }
552  
553 @@ -228,6 +289,7 @@
554                         }
555                         pref.setStartAction(startTypeGroup.getSelectedIndex());
556                         pref.setTrackDirectory(directoryField.getString());
557 +                       pref.setExportDirectory(exportdirectoryField.getString());
558                         BBTracker.initLog();
559  
560                         for (int i = 0; i < Preferences.EXPORT_FORMATS.length; i++) {
561 @@ -251,7 +313,7 @@
562  
563         public void commandAction(final Command command, final Item item) {
564                 if (command == browseCommand) {
565 -                       final BrowseForm browser = new BrowseForm("Save Directory", directoryField.getString());
566 +                       final BrowseForm browser = new BrowseForm("Save Track Directory", directoryField.getString());
567                         final Display display = BBTracker.getDisplay();
568                         browser.setCallback(new Runnable() {
569  
570 @@ -266,5 +328,23 @@
571                         });
572                         display.setCurrent(browser);
573                 }
574 +               //Added 2007 SIB
575 +               if (command == browseExportCommand) {
576 +                       final BrowseForm browser = new BrowseForm("Save Export Directory", exportdirectoryField.getString());
577 +                       final Display display = BBTracker.getDisplay();
578 +                       browser.setCallback(new Runnable() {
579 +
580 +                               public void run() {
581 +                                       final String selectedPath = browser.getPath();
582 +                                       if (selectedPath != null) {
583 +                                               exportdirectoryField.setString(selectedPath);
584 +                                       }
585 +                                       display.setCurrent(OptionsForm.this);
586 +                               }
587 +
588 +                       });
589 +                       display.setCurrent(browser);
590 +               }
591 +               //End Add 2007 SIB
592         }
593  }
594 Index: C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/gui/MainCanvas.java
595 ===================================================================
596 --- C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/gui/MainCanvas.java    (revision 109)
597 +++ C:/Projects/bbTracker/stable/0412/bbtracker/src/org/bbtracker/mobile/gui/MainCanvas.java    (working copy)
598 @@ -17,8 +17,12 @@
599   */
600  package org.bbtracker.mobile.gui;
601  
602 +import java.io.IOException;
603 +import java.io.OutputStream;
604  import java.util.TimerTask;
605  
606 +import javax.microedition.io.Connector;
607 +import javax.microedition.io.file.FileConnection;
608  import javax.microedition.lcdui.Alert;
609  import javax.microedition.lcdui.AlertType;
610  import javax.microedition.lcdui.Canvas;
611 @@ -28,11 +32,16 @@
612  import javax.microedition.lcdui.Font;
613  import javax.microedition.lcdui.Graphics;
614  
615 +import org.bbtracker.Track;
616  import org.bbtracker.TrackPoint;
617  import org.bbtracker.mobile.BBTracker;
618 +import org.bbtracker.mobile.Preferences;
619  import org.bbtracker.mobile.TrackListener;
620  import org.bbtracker.mobile.TrackManager;
621  import org.bbtracker.mobile.TrackStore.TrackStoreException;
622 +import org.bbtracker.mobile.exporter.GpxTrackExporter;
623 +import org.bbtracker.mobile.exporter.KmlTrackExporter;
624 +import org.bbtracker.mobile.exporter.TrackExporter;
625  
626  public class MainCanvas extends Canvas implements TrackListener, CommandListener {
627         private static final int DEFAULT_STATUS_TIMEOUT = 5 * 1000;
628 @@ -44,13 +53,15 @@
629         private final TrackManager manager;
630  
631         private final Tile trackTile;
632 +       
633 +       private final Tile paceTile;
634  
635         private final Tile elevationProfileTile;
636  
637         private final Tile speedProfileTile;
638  
639         private final StatusTile statusTile;
640 -
641 +       
642         private final Tile detailsTile;
643  
644         private final Command newTrackCommand;
645 @@ -66,6 +77,18 @@
646         private final Command aboutCommand;
647  
648         private final Command exitCommand;
649 +       
650 +       //Added 2007 SIB       
651 +       private final Tile summaryTile;
652 +       
653 +       private final Command exportCommand;
654 +       
655 +       private int canvasView = 0;
656 +       
657 +       private final Command detailsViewCommand;
658 +       
659 +       private final Command plotterViewCommand;
660 +       //End Added 2007 SIB
661  
662         private String statusMessage = null;
663  
664 @@ -81,14 +104,21 @@
665                 speedProfileTile = new SpeedPlotterTile(manager, DataProvider.TIME);
666                 statusTile = new StatusTile(manager);
667                 detailsTile = new DetailsTile(manager);
668 +               summaryTile = new SummaryTile(manager);
669 +               paceTile = new PaceTile(manager);
670  
671 -               switchViewCommand = new Command("Switch View", Command.SCREEN, 0);
672 -               newTrackCommand = new Command("New Track", Command.SCREEN, 1);
673 -               stopTrackingCommand = new Command("Stop tracking", Command.STOP, 2);
674 -               tracksCommand = new Command("Track Manager", Command.SCREEN, 3);
675 +               switchViewCommand = new Command("Switch View", Command.SCREEN, 11);
676 +               newTrackCommand = new Command("Start Track", Command.SCREEN, 1);
677 +               stopTrackingCommand = new Command("Stop Track", Command.STOP, 2);
678 +               tracksCommand = new Command("Tracks", Command.SCREEN, 3);
679                 optionsCommand = new Command("Options", Command.SCREEN, 4);
680                 aboutCommand = new Command("About", Command.SCREEN, 5);
681 -               exitCommand = new Command("Exit", Command.EXIT, 6);
682 +               //Added 2007 SIB
683 +               exportCommand = new Command("Export Track", Command.SCREEN, 0);
684 +               detailsViewCommand = new Command("Details View", Command.SCREEN, 9);
685 +               plotterViewCommand = new Command("Plotter View", Command.SCREEN, 9);
686 +               //End Added 2007 SIB
687 +               exitCommand = new Command("Exit", Command.EXIT, 11);
688  
689                 addCommand(switchViewCommand);
690                 addCommand(newTrackCommand);
691 @@ -96,6 +126,7 @@
692                 addCommand(optionsCommand);
693                 addCommand(aboutCommand);
694                 addCommand(exitCommand);
695 +               addCommand(detailsViewCommand);
696  
697                 setCommandListener(this);
698  
699 @@ -181,8 +212,17 @@
700         public void stateChanged(final int newState) {
701                 if (newState == TrackManager.STATE_TRACKING) {
702                         addCommand(stopTrackingCommand);
703 +               //Added 2007 SIB
704 +                       removeCommand(exportCommand);
705 +               } else if (newState == TrackManager.STATE_STATIC){
706 +                       removeCommand(stopTrackingCommand);
707 +                       addCommand(exportCommand);
708 +               //End Added 2007 SIB
709                 } else {
710                         removeCommand(stopTrackingCommand);
711 +                       //Added 2007 SIB
712 +                       removeCommand(exportCommand);
713 +                       //End Added 2007 SIB
714                 }
715                 updateStatusText(newState);
716                 for (int i = 0; i < visibleTiles.length && visibleTiles[i] != null; i++) {
717 @@ -203,24 +243,42 @@
718         }
719  
720         private void nextTileConfiguration() {
721 -               tileConfiguration = (tileConfiguration + 1) % 4;
722 -               switch (tileConfiguration) {
723 -               case 0:
724 -                       setMainTile(trackTile, true);
725 -                       setStatusMessage("Track view");
726 -                       break;
727 -               case 1:
728 -                       setMainTile(elevationProfileTile, true);
729 -                       setStatusMessage("Elevation over time");
730 -                       break;
731 -               case 2:
732 -                       setMainTile(speedProfileTile, true);
733 -                       setStatusMessage("Speed over time");
734 -                       break;
735 -               case 3:
736 -                       setMainTile(detailsTile, false);
737 -                       setStatusMessage("Details");
738 -                       break;
739 +               if (canvasView == 1){
740 +                       addCommand(plotterViewCommand);
741 +                       removeCommand(detailsViewCommand);
742 +                       tileConfiguration = (tileConfiguration + 1) % 3;
743 +                       switch (tileConfiguration) {
744 +                       case 0:
745 +                               setMainTile(detailsTile, false);
746 +                               setStatusMessage("Details");
747 +                               break;
748 +                       case 1:
749 +                               setMainTile(summaryTile, false);
750 +                               setStatusMessage("Summary");
751 +                               break;
752 +                       case 2:
753 +                               setMainTile(paceTile, false);
754 +                               setStatusMessage("Pace");
755 +                               break;
756 +                       }
757 +               } else {
758 +                       removeCommand(plotterViewCommand);
759 +                       addCommand(detailsViewCommand);
760 +                       tileConfiguration = (tileConfiguration + 1) % 3;
761 +                       switch (tileConfiguration) {
762 +                       case 0:
763 +                               setMainTile(trackTile, true);
764 +                               setStatusMessage("Track view");
765 +                               break;
766 +                       case 1:
767 +                               setMainTile(elevationProfileTile, true);
768 +                               setStatusMessage("Elevation over time");
769 +                               break;
770 +                       case 2:
771 +                               setMainTile(speedProfileTile, true);
772 +                               setStatusMessage("Speed over time");
773 +                               break;
774 +                       }
775                 }
776         }
777  
778 @@ -239,8 +297,15 @@
779                 final int state = manager.getState();
780                 if (state == TrackManager.STATE_TRACKING) {
781                         addCommand(stopTrackingCommand);
782 -               } else {
783 +               //Added 2007 SIB
784 +                       removeCommand(exportCommand);
785 +               } else if (state == TrackManager.STATE_STATIC){
786                         removeCommand(stopTrackingCommand);
787 +                       addCommand(exportCommand);
788 +               //End Added 2007 SIB
789 +               }else {
790 +                       removeCommand(stopTrackingCommand);
791 +                       removeCommand(exportCommand);
792                 }
793                 updateStatusText(state);
794         }
795 @@ -249,7 +314,37 @@
796                 if (command == exitCommand) {
797                         exitAction();
798                 } else if (command == switchViewCommand) {
799 -                       nextTileConfiguration();
800 +                       nextTileConfiguration();
801 +               } else if (command == detailsViewCommand) {
802 +                       canvasView = 1;
803 +                       setMainTile(detailsTile, false);
804 +                       setStatusMessage("Details");
805 +               } else if (command == plotterViewCommand) {
806 +                       canvasView = 0;
807 +                       setMainTile(trackTile, true);
808 +                       setStatusMessage("Track view");
809 +               //Added 2007 SIB
810 +               }else if (command == exportCommand){
811 +                       final Preferences preferences = Preferences.getInstance();
812 +                       final String dir = preferences.getExportDirectory();
813 +                       final Track track = manager.getTrack();
814 +                       if (dir == null) {
815 +                               final Alert alert = new Alert("No track directory defined!",
816 +                                               "Please define an export directory in the options screen.", null, AlertType.WARNING);
817 +                               BBTracker.alert(alert, this);
818 +                               return;
819 +                       }
820 +                       int count;
821 +                       try {
822 +                               count = exportTrack(dir, track);
823 +                       } catch (final IOException e) {
824 +                               BBTracker.nonFatal(e, "exporting track", this);
825 +                               return;
826 +                       }
827 +                       final Alert alert = new Alert("Finished exporting", "The track " + track.getName() +
828 +                                       " has been exported successfully to " + count + " formats!", null, AlertType.INFO);
829 +                       BBTracker.alert(alert, this);
830 +               //End Added 2007 SIB
831                 } else {
832                         final Displayable nextDisplayable;
833                         if (command == aboutCommand) {
834 @@ -381,4 +476,48 @@
835                         MainCanvas.this.repaint();
836                 }
837         }
838 +       
839 +       //Added 2007 SIB from code on TracksForm
840 +       private int exportTrack(final String dir, final Track track) throws IOException {
841 +               final Preferences pref = Preferences.getInstance();
842 +               int exportCount = 0;
843 +               if (pref.getExportFormat(0)) {
844 +                       export(dir, track, new KmlTrackExporter());
845 +                       exportCount++;
846 +               }
847 +               if (pref.getExportFormat(1)) {
848 +                       export(dir, track, new GpxTrackExporter());
849 +                       exportCount++;
850 +               }
851 +               return exportCount;
852 +       }
853 +
854 +       private void export(final String dir, final Track track, final TrackExporter exporter) throws IOException {
855 +               final String fileName = exporter.getFileName(track);
856 +               final String fullName = dir.endsWith("/") ? dir + fileName : dir + "/" + fileName;
857 +               FileConnection connection = null;
858 +               OutputStream out = null;
859 +               try {
860 +                       connection = (FileConnection) Connector.open("file:///" + fullName, Connector.READ_WRITE);
861 +                       connection.create();
862 +                       out = connection.openOutputStream();
863 +                       exporter.export(out, track);
864 +               } finally {
865 +                       if (out != null) {
866 +                               try {
867 +                                       out.close();
868 +                               } catch (final IOException ignored) {
869 +                                       // ignore
870 +                               }
871