Changeset 7
- Timestamp:
- 07/25/07 00:07:45 (6 years ago)
- Files:
-
- 4 added
- 13 edited
-
bbtracker/trunk/bbtracker.jad (modified) (1 diff)
-
bbtracker/trunk/src/org/bbtracker/mobile/BBTracker.java (modified) (6 diffs)
-
bbtracker/trunk/src/org/bbtracker/mobile/Preferences.java (modified) (9 diffs)
-
bbtracker/trunk/src/org/bbtracker/mobile/TrackManager.java (modified) (4 diffs)
-
bbtracker/trunk/src/org/bbtracker/mobile/TrackStore.java (modified) (8 diffs)
-
bbtracker/trunk/src/org/bbtracker/mobile/exporter (added)
-
bbtracker/trunk/src/org/bbtracker/mobile/exporter/KmlTrackExporter.java (added)
-
bbtracker/trunk/src/org/bbtracker/mobile/exporter/TrackExporter.java (added)
-
bbtracker/trunk/src/org/bbtracker/mobile/gui/BrowseForm.java (added)
-
bbtracker/trunk/src/org/bbtracker/mobile/gui/MainCanvas.java (modified) (3 diffs)
-
bbtracker/trunk/src/org/bbtracker/mobile/gui/NewTrackForm.java (modified) (1 diff)
-
bbtracker/trunk/src/org/bbtracker/mobile/gui/OptionsForm.java (modified) (5 diffs)
-
bbtracker/trunk/src/org/bbtracker/mobile/gui/TrackTile.java (modified) (7 diffs)
-
bbtracker/trunk/src/org/bbtracker/mobile/gui/TracksForm.java (modified) (6 diffs)
-
bbtracker_common/trunk/.classpath (modified) (1 diff)
-
bbtracker_common/trunk/src/org/bbtracker/Track.java (modified) (1 diff)
-
bbtracker_common/trunk/src/org/bbtracker/Utils.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
bbtracker/trunk/bbtracker.jad
r4 r7 1 MIDlet-1: BBTracker,bbtracker.png,org. dyndns.rentar.bbtracker.mobile.BBTracker1 MIDlet-1: BBTracker,bbtracker.png,org.bbtracker.mobile.BBTracker 2 2 MIDlet-Jar-URL: bbtracker.jar 3 3 MIDlet-Name: BBTracker 4 MIDlet-Permissions: javax.microedition.location.Location, javax.microedition.location.Orientation 4 MIDlet-Permissions: javax.microedition.location.Location, javax.microedition.location.Orientation, javax.microedition.io.Connector.file.read, javax.microedition.io.Connector.file.write 5 5 MIDlet-Vendor: Joachim Sauer 6 MIDlet-Version: 0.1. 56 MIDlet-Version: 0.1.9 7 7 MicroEdition-Configuration: CLDC-1.1 8 8 MicroEdition-Profile: MIDP-2.0 -
bbtracker/trunk/src/org/bbtracker/mobile/BBTracker.java
r4 r7 3 3 import javax.microedition.lcdui.Alert; 4 4 import javax.microedition.lcdui.AlertType; 5 import javax.microedition.lcdui.Command; 6 import javax.microedition.lcdui.CommandListener; 5 7 import javax.microedition.lcdui.Display; 6 8 import javax.microedition.lcdui.Displayable; 9 import javax.microedition.lcdui.Form; 7 10 import javax.microedition.location.LocationException; 8 11 import javax.microedition.midlet.MIDlet; 9 12 import javax.microedition.midlet.MIDletStateChangeException; 13 import javax.microedition.rms.RecordStoreException; 10 14 11 15 import org.bbtracker.mobile.gui.MainCanvas; … … 23 27 private final TrackManager trackManager; 24 28 25 private MainCanvas mainCanvas;29 private final MainCanvas mainCanvas; 26 30 27 31 private boolean firstStart = true; … … 35 39 trackManager = new TrackManager(); 36 40 41 mainCanvas = new MainCanvas(trackManager); 42 37 43 try { 38 44 switch (Preferences.getInstance().getStartAction()) { … … 45 51 } 46 52 } catch (final LocationException e) { 47 nonFatal(e, "Initializing Location Provider" );53 nonFatal(e, "Initializing Location Provider", mainCanvas); 48 54 } 49 55 } 50 56 51 public void shutdown( ) {57 public void shutdown(final boolean destroy) { 52 58 if (trackManager != null) { 53 59 trackManager.shutdown(); 54 60 } 55 Preferences.getInstance().store(); 56 notifyDestroyed(); 61 try { 62 Preferences.getInstance().store(); 63 } catch (final RecordStoreException ignored) { 64 // ignore 65 } 66 if (destroy) { 67 notifyDestroyed(); 68 } 57 69 } 58 70 59 71 protected void destroyApp(final boolean arg0) throws MIDletStateChangeException { 60 shutdown( );72 shutdown(true); 61 73 } 62 74 63 75 protected void pauseApp() { 64 mainCanvas = null;65 76 } 66 77 … … 77 88 } 78 89 79 }80 81 public static void alert(final Alert alert) {82 final Display d = getDisplay();83 Displayable next = d.getCurrent();84 if (next == null) {85 final BBTracker i = getInstance();86 if (i.mainCanvas == null) {87 i.mainCanvas = new MainCanvas(i.trackManager);88 }89 next = i.mainCanvas;90 }91 d.setCurrent(alert, next);92 90 } 93 91 … … 112 110 } 113 111 114 public static void nonFatal(final Throwable t, final String action) { 115 t.printStackTrace(); 116 alert(new Alert("Non-fatal Exception", "Non-fatal Exception while " + action + ": " + t.getMessage(), null, 117 AlertType.WARNING)); 112 public static void nonFatal(final Throwable t, final String action, final Displayable next) { 113 log(t); 114 final Alert alert = new Alert("Non-fatal Exception", "Non-fatal Exception while " + action + ": " + 115 t.getMessage(), null, AlertType.WARNING); 116 alert(alert, next); 117 } 118 119 public static void alert(final Alert alert, final Displayable next) { 120 getDisplay().setCurrent(alert, next != null ? next : getInstance().mainCanvas); 118 121 } 119 122 120 123 public static void fatal(final Throwable t, final String action) { 121 // TODO 122 getInstance().shutdown(); 124 log(t); 125 final BBTracker i = getInstance(); 126 i.shutdown(false); 127 final Form errorForm = new Form("Fatal Exception!"); 128 errorForm.append("Fatal Exception while " + action + ":"); 129 errorForm.append(t.toString()); 130 errorForm.addCommand(new Command("Exit", Command.EXIT, 0)); 131 errorForm.setCommandListener(new CommandListener() { 132 133 public void commandAction(final Command cmd, final Displayable displayable) { 134 i.notifyDestroyed(); 135 } 136 }); 137 getDisplay().setCurrent(errorForm); 123 138 } 124 139 125 140 public void showMainCanvas() { 126 if (mainCanvas == null) {127 mainCanvas = new MainCanvas(trackManager);128 }129 141 getDisplay().setCurrent(mainCanvas); 130 142 } 143 144 public static void log(final Throwable e) { 145 // used only for debugging 146 e.printStackTrace(); 147 } 148 149 public static void log(final String m) { 150 // used only for debugging 151 System.err.println(m); 152 } 131 153 } -
bbtracker/trunk/src/org/bbtracker/mobile/Preferences.java
r4 r7 29 29 if (instance == null) { 30 30 instance = new Preferences(); 31 instance.load(); 31 try { 32 instance.load(); 33 } catch (final RecordStoreException ignored) { 34 // ignore 35 } 32 36 } 33 37 return instance; … … 41 45 42 46 private int trackNumber = 1; 47 48 private String exportDirectory; 43 49 44 50 private Preferences() { … … 65 71 } 66 72 67 private void load() {73 private void load() throws RecordStoreException { 68 74 RecordStore rs = null; 69 75 try { … … 89 95 sampleInterval = in.readInt(); 90 96 trackNumber = in.readInt(); 97 if (in.readByte() != 0) { 98 exportDirectory = in.readUTF(); 99 } 91 100 92 101 in.close(); … … 95 104 } catch (final InvalidRecordIDException e) { 96 105 // ignore, don't load anything 97 } catch (final RecordStoreException e) {98 BBTracker.nonFatal(e, "loading preferences");99 e.printStackTrace();100 106 } catch (final IOException e) { 101 BBTracker.nonFatal(e, "loading preferences"); 102 e.printStackTrace(); 107 throw new RecordStoreException(e.getMessage()); 103 108 } finally { 104 109 if (rs != null) { … … 112 117 } 113 118 114 public void store() {119 public void store() throws RecordStoreException { 115 120 RecordStore rs = null; 116 121 try { … … 123 128 out.writeInt(sampleInterval); 124 129 out.writeInt(trackNumber); 130 if (exportDirectory == null) { 131 out.writeByte(0); 132 } else { 133 out.writeByte(1); 134 out.writeUTF(exportDirectory); 135 } 125 136 126 137 out.close(); … … 139 150 enumerateRecords.destroy(); 140 151 } 141 } catch (final RecordStoreException e) {142 BBTracker.nonFatal(e, "storing preferences");143 e.printStackTrace();144 152 } catch (final IOException e) { 145 BBTracker.nonFatal(e, "storing preferences"); 146 e.printStackTrace(); 153 throw new RecordStoreException(e.getMessage()); 147 154 } finally { 148 155 if (rs != null) { … … 155 162 } 156 163 } 164 165 public String getExportDirectory() { 166 return exportDirectory; 167 } 168 169 public void setExportDirectory(final String exportDirectory) { 170 this.exportDirectory = exportDirectory; 171 } 157 172 } -
bbtracker/trunk/src/org/bbtracker/mobile/TrackManager.java
r6 r7 14 14 import org.bbtracker.Track; 15 15 import org.bbtracker.TrackPoint; 16 import org.bbtracker.TrackSegment;17 16 18 17 public class TrackManager implements LocationListener { … … 165 164 } catch (final IllegalArgumentException e) { 166 165 provider.setLocationListener(TrackManager.this, -1, -1, -1); 167 BBTracker. nonFatal(e, "Trying to set sample interval " + sampleInterval);166 BBTracker.log(e); 168 167 } 169 168 } … … 173 172 state = STATE_STATIC; 174 173 track = newTrack; 175 if (track == null ) {174 if (track == null || track.getPointCount() == 0) { 176 175 currentPoint = null; 177 176 } else { 178 if (track.getSegmentCount() > 0) { 179 final TrackSegment seg = track.getSegment(0); 180 if (seg.getPointCount() > 0) { 181 currentPoint = seg.getPoint(0); 182 } 183 } 177 currentPoint = track.getPoint(0); 184 178 } 185 179 } … … 219 213 TrackStore.getInstance().store(track); 220 214 } catch (final RecordStoreException e) { 221 BBTracker. nonFatal(e, "Storing track");215 BBTracker.log(e); 222 216 } 223 217 } -
bbtracker/trunk/src/org/bbtracker/mobile/TrackStore.java
r4 r7 10 10 import javax.microedition.rms.RecordStore; 11 11 import javax.microedition.rms.RecordStoreException; 12 import javax.microedition.rms.RecordStoreNotFoundException; 12 13 13 14 import org.bbtracker.Track; … … 36 37 } 37 38 38 public String[] getTrackNames() {39 public String[] getTrackNames() throws RecordStoreException { 39 40 if (names == null) { 40 41 RecordStore rs = null; … … 63 64 } 64 65 enumeration.destroy(); 65 } catch (final RecordStoreException e) { 66 e.printStackTrace(); 66 } catch (final RecordStoreNotFoundException e) { 67 names = new String[0]; 68 indices = new int[0]; 67 69 } finally { 68 70 if (rs != null) { … … 78 80 } 79 81 80 public Track getTrack(final int index) {82 public Track getTrack(final int index) throws RecordStoreException { 81 83 if (indices == null) { 82 84 throw new IllegalStateException("Must not call getTrack() without calling getTrackNames() before!"); … … 93 95 return track; 94 96 } catch (final IOException e) { 95 BBTracker.nonFatal(e, "Loading Track"); 96 } catch (final RecordStoreException e) { 97 BBTracker.nonFatal(e, "Loading Track"); 97 throw new RecordStoreException(e.getMessage()); 98 98 } finally { 99 99 if (rs != null) { … … 112 112 } 113 113 } 114 return null;115 114 } 116 115 … … 150 149 } 151 150 152 public void deleteTrack(final int selectedIndex) {151 public void deleteTrack(final int selectedIndex) throws RecordStoreException { 153 152 RecordStore rs = null; 154 153 try { … … 159 158 indices = null; 160 159 names = null; 161 } catch (final RecordStoreException e) {162 BBTracker.nonFatal(e, "deleting track");163 160 } finally { 164 161 if (rs != null) { -
bbtracker/trunk/src/org/bbtracker/mobile/gui/MainCanvas.java
r4 r7 7 7 import javax.microedition.lcdui.Font; 8 8 import javax.microedition.lcdui.Graphics; 9 import javax.microedition.rms.RecordStoreException; 9 10 10 11 import org.bbtracker.Track; … … 86 87 87 88 public void newPoint(final TrackPoint newPoint, final boolean boundsChanged, final boolean newSegment) { 89 trackTile.setCurrentPoint(newPoint); 88 90 if (boundsChanged) { 89 91 trackTile.onResize(); // XXX Make that nicer … … 129 131 nextDisplayable = new NewTrackForm(manager); 130 132 } else if (command == tracksCommand) { 131 nextDisplayable = new TracksForm(manager); 133 try { 134 nextDisplayable = new TracksForm(manager); 135 } catch (final RecordStoreException e) { 136 BBTracker.nonFatal(e, "getting list of stored tracks", this); 137 } 132 138 } else if (command == exitCommand) { 133 BBTracker.getInstance().shutdown( );139 BBTracker.getInstance().shutdown(true); 134 140 return; 135 141 } -
bbtracker/trunk/src/org/bbtracker/mobile/gui/NewTrackForm.java
r4 r7 41 41 try { 42 42 trackManager.newTrack(nameField.getString()); 43 BBTracker.getInstance().showMainCanvas(); 43 44 } catch (final LocationException e) { 44 BBTracker.nonFatal(e, "Starting new track" );45 BBTracker.nonFatal(e, "Starting new track", null); 45 46 } 47 } else if (command == cancelCommand) { 48 BBTracker.getInstance().showMainCanvas(); 46 49 } 47 BBTracker.getInstance().showMainCanvas();48 50 } 49 51 } -
bbtracker/trunk/src/org/bbtracker/mobile/gui/OptionsForm.java
r4 r7 5 5 import javax.microedition.lcdui.Command; 6 6 import javax.microedition.lcdui.CommandListener; 7 import javax.microedition.lcdui.Display; 7 8 import javax.microedition.lcdui.Displayable; 8 9 import javax.microedition.lcdui.Form; 10 import javax.microedition.lcdui.Item; 11 import javax.microedition.lcdui.ItemCommandListener; 9 12 import javax.microedition.lcdui.TextField; 13 import javax.microedition.rms.RecordStoreException; 10 14 11 15 import org.bbtracker.mobile.BBTracker; … … 13 17 import org.bbtracker.mobile.TrackManager; 14 18 15 public class OptionsForm extends Form implements CommandListener {19 public class OptionsForm extends Form implements CommandListener, ItemCommandListener { 16 20 private final TrackManager trackManager; 17 21 18 private final Command okCommand = new Command("OK", Command.OK, 0);22 private final Command okCommand; 19 23 20 private final Command cancelCommand = new Command("Cancel", Command.CANCEL, 1); 24 private final Command cancelCommand; 25 26 private final Command browseCommand; 21 27 22 28 private final TextField sampleField; 23 29 24 30 private final ChoiceGroup startTypeGroup; 31 32 private final TextField directoryField; 25 33 26 34 public OptionsForm(final TrackManager trackManager) { … … 35 43 startTypeGroup = new ChoiceGroup("Startup action: ", Choice.EXCLUSIVE, Preferences.START_ACTIONS, null); 36 44 startTypeGroup.setSelectedIndex(pref.getStartAction(), true); 45 directoryField = new TextField("Export directory: ", pref.getExportDirectory(), 100, TextField.URL); 46 browseCommand = new Command("Browse", Command.ITEM, 1); 47 directoryField.addCommand(browseCommand); 48 directoryField.setItemCommandListener(this); 37 49 38 50 append(sampleField); 39 51 append(startTypeGroup); 52 append(directoryField); 40 53 54 okCommand = new Command("OK", Command.OK, 0); 41 55 addCommand(okCommand); 56 cancelCommand = new Command("Cancel", Command.CANCEL, 1); 42 57 addCommand(cancelCommand); 43 58 setCommandListener(this); … … 51 66 pref.setSampleInterval(sampleInterval); 52 67 pref.setStartAction(startTypeGroup.getSelectedIndex()); 68 pref.setExportDirectory(directoryField.getString()); 53 69 54 70 pref.store(); 55 71 } catch (final NumberFormatException e) { 56 72 // should not happen 73 } catch (final RecordStoreException e) { 74 BBTracker.nonFatal(e, "storing preferences", null); 57 75 } 58 76 … … 61 79 BBTracker.getInstance().showMainCanvas(); 62 80 } 81 82 public void commandAction(final Command command, final Item item) { 83 if (command == browseCommand) { 84 final BrowseForm browser = new BrowseForm("Save Directory", directoryField.getString()); 85 final Display display = BBTracker.getDisplay(); 86 browser.setCallback(new Runnable() { 87 88 public void run() { 89 final String selectedPath = browser.getPath(); 90 if (selectedPath != null) { 91 directoryField.setString(selectedPath); 92 } 93 display.setCurrent(OptionsForm.this); 94 } 95 96 }); 97 display.setCurrent(browser); 98 System.out.println(browser.getPath()); 99 } 100 } 63 101 } -
bbtracker/trunk/src/org/bbtracker/mobile/gui/TrackTile.java
r4 r7 12 12 13 13 public class TrackTile extends Tile { 14 private static final int POINT_COLOR = 0x00bbbbbb;15 16 14 private static final int MARKED_POINT_COLOR = 0x00bb0000; 17 15 … … 20 18 private static final int LAST_MARKED_POINT_COLOR = 0x00550000; 21 19 22 private static final int LINK_COLOR = 0x0000 8800;20 private static final int LINK_COLOR = 0x00003300; 23 21 24 22 private static final int SEGMENT_LINK_COLOR = 0x00aaaaaa; … … 37 35 38 36 private final Track track; 37 38 private TrackPoint currentPoint; 39 39 40 40 private int scaleSizeInPixel; … … 47 47 minimumLongitude = minimumLatitude = Double.NaN; 48 48 scale = Float.NaN; 49 } 50 51 public void setCurrentPoint(final TrackPoint currentPoint) { 52 this.currentPoint = currentPoint; 53 } 54 55 public TrackPoint getCurrentPoint() { 56 return currentPoint; 49 57 } 50 58 … … 130 138 final TrackSegment segment = (TrackSegment) segments.nextElement(); 131 139 final Enumeration points = segment.getPoints(); 140 TrackPoint prev = null; 132 141 while (points.hasMoreElements()) { 133 142 final TrackPoint point = (TrackPoint) points.nextElement(); … … 137 146 138 147 g.drawLine(prevX, prevY, curX, curY); 139 drawPoint(g, prevX, prevY, prevIsWaypoint, false);148 drawPoint(g, prevX, prevY, prevIsWaypoint, prev == currentPoint); 140 149 if (newSegment) { 141 150 g.setColor(SEGMENT_LINK_COLOR); … … 147 156 prevX = curX; 148 157 prevY = curY; 158 prev = point; 149 159 } 150 drawPoint(g, prevX, prevY, prevIsWaypoint, true); 151 } 152 } 153 154 private void drawPoint(final Graphics g, final int x, final int y, final boolean waypoint, final boolean last) { 155 final int color = last ? (waypoint ? LAST_MARKED_POINT_COLOR : LAST_POINT_COLOR) 156 : (waypoint ? MARKED_POINT_COLOR : POINT_COLOR); 157 g.setColor(color); 158 g.drawLine(x - 2, y - 2, x + 2, y + 2); 159 g.drawLine(x - 2, y + 2, x + 2, y - 2); 160 drawPoint(g, prevX, prevY, prevIsWaypoint, prev == currentPoint); 161 } 162 } 163 164 private void drawPoint(final Graphics g, final int x, final int y, final boolean waypoint, final boolean current) { 165 if (!(waypoint || current)) { 166 return; 167 } 168 if (current) { 169 g.setColor(waypoint ? LAST_MARKED_POINT_COLOR : LAST_POINT_COLOR); 170 g.drawLine(x, y - 3, x + 3, y); 171 g.drawLine(x + 3, y, x, y + 3); 172 g.drawLine(x, y + 3, x - 3, y); 173 g.drawLine(x - 3, y, x, y - 3); 174 175 } else { 176 g.setColor(MARKED_POINT_COLOR); 177 g.drawLine(x - 2, y - 2, x + 2, y + 2); 178 g.drawLine(x - 2, y + 2, x + 2, y - 2); 179 } 160 180 } 161 181 -
bbtracker/trunk/src/org/bbtracker/mobile/gui/TracksForm.java
r4 r7 1 1 package org.bbtracker.mobile.gui; 2 2 3 import java.io.IOException; 4 import java.io.OutputStream; 5 6 import javax.microedition.io.Connector; 7 import javax.microedition.io.file.FileConnection; 8 import javax.microedition.lcdui.Alert; 9 import javax.microedition.lcdui.AlertType; 3 10 import javax.microedition.lcdui.Choice; 4 11 import javax.microedition.lcdui.Command; … … 6 13 import javax.microedition.lcdui.Displayable; 7 14 import javax.microedition.lcdui.List; 15 import javax.microedition.rms.RecordStoreException; 8 16 9 17 import org.bbtracker.Track; 10 18 import org.bbtracker.mobile.BBTracker; 19 import org.bbtracker.mobile.Preferences; 11 20 import org.bbtracker.mobile.TrackManager; 12 21 import org.bbtracker.mobile.TrackStore; 22 import org.bbtracker.mobile.exporter.KmlTrackExporter; 23 import org.bbtracker.mobile.exporter.TrackExporter; 13 24 14 25 public class TracksForm extends List implements CommandListener { … … 17 28 private final Command selectCommand; 18 29 30 private final Command exportCommand; 31 19 32 private final Command deleteCommand; 20 33 21 34 private final Command cancelCommand; 22 35 23 public TracksForm(final TrackManager trackManager) {36 public TracksForm(final TrackManager trackManager) throws RecordStoreException { 24 37 super("Tracks", Choice.IMPLICIT); 25 38 … … 28 41 selectCommand = new Command("Select", Command.OK, 0); 29 42 addCommand(selectCommand); 43 44 exportCommand = new Command("Export", Command.ITEM, 2); 45 addCommand(exportCommand); 30 46 31 47 deleteCommand = new Command("Delete", Command.ITEM, 3); … … 44 60 } 45 61 46 private void loadNames() {62 private void loadNames() throws RecordStoreException { 47 63 deleteAll(); 48 64 final TrackStore store = TrackStore.getInstance(); … … 54 70 55 71 public void commandAction(final Command command, final Displayable displayable) { 56 if (command == selectCommand) { 57 final Track track = TrackStore.getInstance().getTrack(getSelectedIndex()); 58 trackManager.setTrack(track); 59 BBTracker.getInstance().showMainCanvas(); 60 } else if (command == deleteCommand) { 61 TrackStore.getInstance().deleteTrack(getSelectedIndex()); 62 loadNames(); 72 if (command == deleteCommand) { 73 try { 74 TrackStore.getInstance().deleteTrack(getSelectedIndex()); 75 loadNames(); 76 } catch (final RecordStoreException e) { 77 BBTracker.nonFatal(e, "deleting track", null); 78 return; 79 } 80 return; 63 81 } else if (command == cancelCommand) { 64 82 BBTracker.getInstance().showMainCanvas(); 83 } else { 84 final Track track; 85 try { 86 track = TrackStore.getInstance().getTrack(getSelectedIndex()); 87 } catch (final RecordStoreException e) { 88 BBTracker.nonFatal(e, "loading track", this); 89 return; 90 } 91 if (command == selectCommand) { 92 trackManager.setTrack(track); 93 BBTracker.getInstance().showMainCanvas(); 94 } else if (command == exportCommand) { 95 final Preferences preferences = Preferences.getInstance(); 96 final String dir = preferences.getExportDirectory(); 97 if (dir == null) { 98 final Alert alert = new Alert("No export directory defined!", 99 "Please define an export directory in the options screen.", null, AlertType.WARNING); 100 BBTracker.alert(alert, null); 101 return; 102 } 103 try { 104 exportTrack(dir, track); 105 } catch (final IOException e) { 106 BBTracker.nonFatal(e, "exporting track", this); 107 return; 108 } 109 110 final Alert alert = new Alert("Finished exporting", "The track " + track.getName() + 111 " has been exported successfully!", null, AlertType.INFO); 112 BBTracker.alert(alert, null); 113 } 114 } 115 } 116 117 private void exportTrack(final String dir, final Track track) throws IOException { 118 final TrackExporter exporter = new KmlTrackExporter(); 119 final String fileName = exporter.getFileName(track); 120 final String fullName = dir.endsWith("/") ? dir + fileName : dir + "/" + fileName; 121 FileConnection connection = null; 122 OutputStream out = null; 123 try { 124 connection = (FileConnection) Connector.open("file:///" + fullName, Connector.READ_WRITE); 125 connection.create(); 126 out = connection.openOutputStream(); 127 exporter.export(out, track); 128 } finally { 129 if (out != null) { 130 try { 131 out.close(); 132 } catch (final IOException ignored) { 133 // ignore 134 } 135 } 136 if (connection != null) { 137 try { 138 connection.close(); 139 } catch (final IOException ignored) { 140 // ignore 141 } 142 } 65 143 } 66 144 } -
bbtracker_common/trunk/.classpath
r4 r7 2 2 <classpath> 3 3 <classpathentry kind="src" path="src"/> 4 <classpathentry kind="src" path="tests"/>5 4 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/CDC-1.1%Foundation-1.1"/> 6 5 <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/> -
bbtracker_common/trunk/src/org/bbtracker/Track.java
r5 r7 53 53 public int getPointCount() { 54 54 return pointCount; 55 } 56 57 public TrackPoint getPoint(final int nr) { 58 if (nr < 0 || nr > pointCount) { 59 throw new IndexOutOfBoundsException("no such point: " + nr + ", must be >= 0 and < " + pointCount); 60 } 61 int i = nr; 62 final Enumeration segs = segments.elements(); 63 while (segs.hasMoreElements()) { 64 final TrackSegment seg = (TrackSegment) segs.nextElement(); 65 final int count = seg.getPointCount(); 66 if (i < count) { 67 return seg.getPoint(i); 68 } else { 69 i -= count; 70 } 71 } 72 throw new IllegalStateException("pointCount corrupt!"); 55 73 } 56 74 -
bbtracker_common/trunk/src/org/bbtracker/Utils.java
r5 r7 153 153 return orig.substring(0, 20) + orig.substring(size - 4, size); 154 154 } 155 156 public static String escapeXml(final String xml) { 157 final StringBuffer escaped = new StringBuffer(xml.length() + 4); 158 final char[] chars = xml.toCharArray(); 159 for (int i = 0; i < chars.length; i++) { 160 final char c = chars[i]; 161 switch (c) { 162 case '<': 163 escaped.append("<"); 164 break; 165 case '&': 166 escaped.append("&"); 167 break; 168 default: 169 escaped.append(c); 170 } 171 } 172 return escaped.toString(); 173 } 155 174 }
Note: See TracChangeset
for help on using the changeset viewer.