Changeset 212
- Timestamp:
- 05/12/08 10:41:59 (5 years ago)
- Location:
- bbtracker/branches/map
- Files:
-
- 8 added
- 15 edited
-
.classpath (modified) (1 diff)
-
.eclipseme (modified) (1 diff)
-
.project (modified) (2 diffs)
-
src/org/bbtracker/mobile/BBTracker.java (modified) (3 diffs)
-
src/org/bbtracker/mobile/CompactStream.java (added)
-
src/org/bbtracker/mobile/FileTrackStore.java (modified) (6 diffs)
-
src/org/bbtracker/mobile/IconManager.java (modified) (3 diffs)
-
src/org/bbtracker/mobile/Preferences.java (modified) (6 diffs)
-
src/org/bbtracker/mobile/RMSTrackStore.java (modified) (1 diff)
-
src/org/bbtracker/mobile/TrackManager.java (modified) (1 diff)
-
src/org/bbtracker/mobile/TrackStore.java (modified) (2 diffs)
-
src/org/bbtracker/mobile/config (added)
-
src/org/bbtracker/mobile/config/ConfigFile.java (added)
-
src/org/bbtracker/mobile/gui/MainCanvas.java (modified) (10 diffs)
-
src/org/bbtracker/mobile/gui/MapBackground.java (added)
-
src/org/bbtracker/mobile/gui/OptionsForm.java (modified) (7 diffs)
-
src/org/bbtracker/mobile/gui/PlotterTile.java (modified) (10 diffs)
-
src/org/bbtracker/mobile/gui/TrackPlotter.java (added)
-
src/org/bbtracker/mobile/gui/TrackTile.java (modified) (6 diffs)
-
src/org/bbtracker/mobile/gui/TracksForm.java (modified) (2 diffs)
-
tools (added)
-
tools/checkstyle_config.xml (added)
-
tools/convert.pl (added)
Legend:
- Unmodified
- Added
- Removed
-
bbtracker/branches/map/.classpath
r4 r212 4 4 <classpathentry kind="src" path="res"/> 5 5 <classpathentry kind="con" path="J2MELIB"/> 6 <classpathentry combineaccessrules="false" exported="true"kind="src" path="/bbtracker_common"/>6 <classpathentry combineaccessrules="false" kind="src" path="/bbtracker_common"/> 7 7 <classpathentry kind="output" path="bin"/> 8 8 </classpath> -
bbtracker/branches/map/.eclipseme
r32 r212 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 <eclipsemeMetadata jad="bbtracker.jad" version="1.7. 3">3 <device group="Sun Java(TM) Wireless Toolkit 2.5.1 for CLDC" name=" QwertyDevice"/>2 <eclipsemeMetadata jad="bbtracker.jad" version="1.7.6"> 3 <device group="Sun Java(TM) Wireless Toolkit 2.5.1 for CLDC" name="DefaultGrayPhone"/> 4 4 <signing signProject="false"/> 5 5 </eclipsemeMetadata> -
bbtracker/branches/map/.project
r123 r212 21 21 </arguments> 22 22 </buildCommand> 23 <buildCommand> 24 <name>com.atlassw.tools.eclipse.checkstyle.CheckstyleBuilder</name> 25 <arguments> 26 </arguments> 27 </buildCommand> 23 28 </buildSpec> 24 29 <natures> … … 26 31 <nature>eclipseme.core.nature</nature> 27 32 <nature>antenna.eclipse.preprocessor.appNature</nature> 33 <nature>com.atlassw.tools.eclipse.checkstyle.CheckstyleNature</nature> 28 34 </natures> 29 35 </projectDescription> -
bbtracker/branches/map/src/org/bbtracker/mobile/BBTracker.java
r209 r212 34 34 import javax.microedition.rms.RecordStoreException; 35 35 36 import org.bbtracker. mobile.TrackStore.TrackStoreException;36 import org.bbtracker.TrackStoreException; 37 37 import org.bbtracker.mobile.gps.DummyLocationProvider; 38 38 import org.bbtracker.mobile.gps.Jsr179LocationProvider; … … 155 155 156 156 public void showMainCanvas() { 157 mainCanvas.loadBackgrounds(); 157 158 getDisplay().setCurrent(mainCanvas); 158 159 } … … 233 234 final String fileConnectionVersion = System.getProperty("microedition.io.file.FileConnection.version"); 234 235 fileUrlAvailable = (fileConnectionVersion != null); 236 if (fileConnectionVersion == null) { 237 final String platform = System.getProperty("microedition.platform"); 238 System.out.println(platform); 239 if ("MicroEmulator".equals(platform)) { 240 fileUrlAvailable = true; 241 } 242 } 235 243 addAPI("File", fileUrlAvailable); 236 244 // #endif -
bbtracker/branches/map/src/org/bbtracker/mobile/FileTrackStore.java
r184 r212 13 13 14 14 import org.bbtracker.Track; 15 import org.bbtracker.TrackStoreException; 16 import org.bbtracker.mobile.config.ConfigFile; 15 17 16 18 public class FileTrackStore implements TrackStore { 17 19 18 private static final String EXTENSION = ".bbt"; 20 private static final String BBT_EXTENSION = ".bbt"; 21 private static final String TXT_EXTENSION = ".txt"; 19 22 20 23 public TrackStoreEntry[] getEntries() throws TrackStoreException { … … 24 27 final Vector result = new Vector(); 25 28 connection = (FileConnection) Connector.open("file:///" + dir, Connector.READ); 26 final Enumeration list = connection.list("*" + EXTENSION + "*", true); 27 while (list.hasMoreElements()) { 28 final String file = (String) list.nextElement(); 29 DataInputStream din = null; 30 try { 31 final String fileUrl = connection.getURL() + file; 32 din = Connector.openDataInputStream(fileUrl); 33 final String name = Track.readNameFromStream(din); 34 final Date date = Track.readDateFromStream(din); 35 result.addElement(new FileTrackStoreEntry(name, date, fileUrl)); 36 } catch (final IOException e) { 37 Log.log(this, e, "loading info from " + file); 38 } finally { 39 if (din != null) { 40 try { 41 din.close(); 42 } catch (final IOException e) { 43 Log.log(this, e); 44 } 45 } 29 final Enumeration binList = connection.list("*" + BBT_EXTENSION + "*", true); 30 while (binList.hasMoreElements()) { 31 final String file = (String) binList.nextElement(); 32 FileTrackStoreEntry entry = readBinaryTrack(connection, file); 33 if (entry != null) { 34 result.addElement(entry); 35 } 36 } 37 final Enumeration txtList = connection.list("*" + TXT_EXTENSION + "*", true); 38 while (txtList.hasMoreElements()) { 39 final String file = (String) txtList.nextElement(); 40 FileTrackStoreEntry entry = readTextTrack(connection, file);; 41 if (entry != null) { 42 result.addElement(entry); 46 43 } 47 44 } … … 64 61 } 65 62 63 private FileTrackStoreEntry readTextTrack(FileConnection connection, 64 final String file) { 65 FileTrackStoreEntry entry = null; 66 try { 67 // TODO: Parse only first line 68 String filename = connection.getURL() + file; 69 Vector list = ConfigFile.openList(filename); 70 final String name = (String) list.elementAt(0); 71 if (!isValidName(name)) { 72 return null; 73 } 74 final Date date = new Date(0); 75 entry = new FileTrackStoreEntry(name, date, filename, false); 76 } catch (final Exception e) { 77 Log.log(this, e, "loading text info from " + file); 78 } 79 return entry; 80 } 81 82 private boolean isValidName(final String name) { 83 if (name == null || name.length() <= 0) { 84 return false; 85 } 86 for (int i = 0; i < name.length(); i++) { 87 if (!isValidChar(name.charAt(i))) { 88 return false; 89 } 90 } 91 return true; 92 } 93 94 private boolean isValidChar(final char ch) { 95 final String valid = ".-+=_.,<>:;"; 96 97 return Character.isDigit(ch) || Character.isLowerCase(ch) || Character.isUpperCase(ch) || valid.indexOf(ch) != -1; 98 } 99 100 private FileTrackStoreEntry readBinaryTrack(FileConnection connection, 101 final String file) { 102 DataInputStream din = null; 103 FileTrackStoreEntry entry = null; 104 try { 105 final String fileUrl = connection.getURL() + file; 106 din = Connector.openDataInputStream(fileUrl); 107 final String name = Track.readNameFromStream(din); 108 final Date date = Track.readDateFromStream(din); 109 entry = new FileTrackStoreEntry(name, date, fileUrl, true); 110 } catch (final IOException e) { 111 Log.log(this, e, "loading binary info from " + file); 112 } catch (final TrackStoreException e) { 113 Log.log(this, e, "loading binary info from " + file); 114 } finally { 115 if (din != null) { 116 try { 117 din.close(); 118 } catch (final IOException e) { 119 Log.log(this, e); 120 } 121 } 122 } 123 return entry; 124 } 125 66 126 public void saveTrack(final Track track) throws TrackStoreException { 67 127 final String dir = getTrackDirectory(); … … 69 129 DataOutputStream dout = null; 70 130 try { 71 connection = FileUtil.createFile(dir, track.getName(), EXTENSION); 131 connection = FileUtil.createFile(dir, track.getName(), 132 BBT_EXTENSION); 72 133 dout = connection.openDataOutputStream(); 73 134 track.writeToStream(dout); … … 105 166 final String url; 106 167 107 public FileTrackStoreEntry(final String name, final Date date, final String url) { 168 final boolean binary; 169 170 public FileTrackStoreEntry(final String name, final Date date, final String url, final boolean binary) { 108 171 super(name, date); 109 172 this.url = url; 173 this.binary = binary; 110 174 } 111 175 … … 121 185 122 186 public Track loadTrack() throws TrackStoreException { 187 if (binary) { 188 return loadBinaryTrack(); 189 } else { 190 return loadTextTrack(); 191 } 192 } 193 194 private Track loadTextTrack() throws TrackStoreException { 195 try { 196 Vector list = ConfigFile.openList(url); 197 final Track track = Track.readFromStringList(list); 198 return track; 199 } catch (final Exception e) { 200 Log.log(this, e, "loading track"); 201 throw new TrackStoreException("Failed to load track: " + e.getMessage()); 202 } 203 } 204 205 private Track loadBinaryTrack() throws TrackStoreException { 123 206 DataInputStream din = null; 124 207 try { -
bbtracker/branches/map/src/org/bbtracker/mobile/IconManager.java
r130 r212 33 33 private final int alertSizeIndex; 34 34 35 private static final Object NO_ICON = new Object();35 private static final Image NO_ICON = Image.createImage(1,1); 36 36 37 37 private static IconManager instance; … … 39 39 private IconManager() { 40 40 final Display display = BBTracker.getDisplay(); 41 listSizeIndex = getBestMatchingSizeIndex(display.getBestImageWidth(Display.LIST_ELEMENT), display 42 .getBestImageHeight(Display.LIST_ELEMENT)); 43 choiceGroupSizeIndex = getBestMatchingSizeIndex(display.getBestImageWidth(Display.CHOICE_GROUP_ELEMENT), 44 display.getBestImageHeight(Display.CHOICE_GROUP_ELEMENT)); 45 alertSizeIndex = getBestMatchingSizeIndex(display.getBestImageWidth(Display.ALERT), display 46 .getBestImageHeight(Display.ALERT)); 41 listSizeIndex = 1; 42 choiceGroupSizeIndex = 1; 43 alertSizeIndex = 1; 44 // listSizeIndex = getBestMatchingSizeIndex(display.getBestImageWidth(Display.LIST_ELEMENT), display 45 // .getBestImageHeight(Display.LIST_ELEMENT)); 46 // choiceGroupSizeIndex = getBestMatchingSizeIndex(display.getBestImageWidth(Display.CHOICE_GROUP_ELEMENT), 47 // display.getBestImageHeight(Display.CHOICE_GROUP_ELEMENT)); 48 // alertSizeIndex = getBestMatchingSizeIndex(display.getBestImageWidth(Display.ALERT), display 49 // .getBestImageHeight(Display.ALERT)); 47 50 } 48 51 … … 100 103 icon = getImage(name, sizeIndex - 1); 101 104 } else { 102 icon = null;105 icon = NO_ICON; 103 106 } 104 107 } -
bbtracker/branches/map/src/org/bbtracker/mobile/Preferences.java
r139 r212 115 115 private Font detailsFont; 116 116 117 private String mapDirectory; 118 117 119 private String trackDirectory; 118 120 … … 164 166 } 165 167 168 public String getMapDirectory() { 169 return mapDirectory; 170 } 171 166 172 public String getTrackDirectory() { 167 173 return trackDirectory; … … 180 186 } 181 187 188 public void setMapDirectory(final String mapDirectory) { 189 if (mapDirectory == null || mapDirectory.length() == 0) { 190 this.mapDirectory = null; 191 } else { 192 this.mapDirectory = mapDirectory; 193 if (!this.mapDirectory.endsWith("/")) { 194 this.mapDirectory += "/"; 195 } 196 } 197 } 198 182 199 public void setTrackDirectory(final String trackDirectory) { 183 200 if (trackDirectory == null || trackDirectory.length() == 0) { … … 361 378 } else { 362 379 exportDirectory = null; 380 } 381 if ((dirFlags & 4) != 0) { 382 mapDirectory = in.readUTF(); 383 } else { 384 mapDirectory = null; 363 385 } 364 386 exportFormats = in.readInt(); … … 414 436 out.writeInt(trackNumber); 415 437 416 final byte trackFlags = (byte) ((trackDirectory == null ? 0 : 1) | (exportDirectory == null ? 0 : 2)); 438 final byte trackFlags = (byte) ((trackDirectory == null ? 0 : 1) 439 | (exportDirectory == null ? 0 : 2) 440 | (mapDirectory == null ? 0 : 4)); 417 441 out.writeByte(trackFlags); 418 442 if (trackDirectory != null) { … … 421 445 if (exportDirectory != null) { 422 446 out.writeUTF(exportDirectory); 447 } 448 if (mapDirectory != null) { 449 out.writeUTF(mapDirectory); 423 450 } 424 451 out.writeInt(exportFormats); -
bbtracker/branches/map/src/org/bbtracker/mobile/RMSTrackStore.java
r130 r212 14 14 15 15 import org.bbtracker.Track; 16 import org.bbtracker.TrackStoreException; 16 17 17 18 public class RMSTrackStore implements TrackStore { -
bbtracker/branches/map/src/org/bbtracker/mobile/TrackManager.java
r197 r212 29 29 import org.bbtracker.Track; 30 30 import org.bbtracker.TrackPoint; 31 import org.bbtracker.TrackStoreException; 31 32 import org.bbtracker.Utils; 32 33 import org.bbtracker.mobile.TrackStore.TrackStoreEntry; 33 import org.bbtracker.mobile.TrackStore.TrackStoreException;34 34 import org.bbtracker.mobile.exporter.GpxTrackExporter; 35 35 import org.bbtracker.mobile.exporter.KmlTrackExporter; -
bbtracker/branches/map/src/org/bbtracker/mobile/TrackStore.java
r172 r212 22 22 import org.bbtracker.Comparator; 23 23 import org.bbtracker.Track; 24 import org.bbtracker.TrackStoreException; 24 25 25 26 public interface TrackStore { … … 33 34 34 35 public void saveTrack(final Track track) throws TrackStoreException; 35 36 public static class TrackStoreException extends Exception {37 public TrackStoreException(final Throwable t) {38 super(t.toString());39 }40 41 public TrackStoreException(final String message) {42 super(message);43 }44 }45 36 46 37 public static abstract class TrackStoreEntry { -
bbtracker/branches/map/src/org/bbtracker/mobile/gui/MainCanvas.java
r201 r212 18 18 package org.bbtracker.mobile.gui; 19 19 20 import java.io.IOException; 20 21 import java.util.TimerTask; 22 import java.util.Vector; 21 23 22 24 import javax.microedition.lcdui.Alert; … … 34 36 import org.bbtracker.Track; 35 37 import org.bbtracker.TrackPoint; 38 import org.bbtracker.TrackStoreException; 36 39 import org.bbtracker.Utils; 37 40 import org.bbtracker.mobile.BBTracker; … … 40 43 import org.bbtracker.mobile.TrackListener; 41 44 import org.bbtracker.mobile.TrackManager; 42 import org.bbtracker.mobile. TrackStore.TrackStoreException;45 import org.bbtracker.mobile.config.ConfigFile; 43 46 44 47 public class MainCanvas extends Canvas implements TrackListener, CommandListener { … … 51 54 private final TrackManager manager; 52 55 53 private final T ile trackTile;56 private final TrackTile trackTile; 54 57 55 58 private final Tile elevationProfileTile; … … 92 95 private int tileConfiguration = 0; 93 96 97 private Vector mapBackgrounds = new Vector(); 98 99 private static final int KEYBOARD_DEFAULT = 0; 100 101 private static final int KEYBOARD_PAN = 1; 102 103 private static final int KEYBOARD_ADJUST_MAP = 2; 104 105 /** Current input mode. */ 106 private int keyboardMode; 107 94 108 public MainCanvas(final TrackManager manager) { 95 109 this.manager = manager; 96 110 97 111 trackTile = new TrackTile(manager); 112 trackTile.setMainCanvas(this); 98 113 elevationProfileTile = new ElevationPlotterTile(manager, DataProvider.TIME); 99 114 speedProfileTile = new SpeedPlotterTile(manager, DataProvider.TIME); … … 101 116 detailsTile = new DetailsTile(manager); 102 117 118 loadBackgrounds(); 119 103 120 switchViewCommand = new Command("Switch View", Command.SCREEN, 10); 104 121 markPointCommand = new Command("Mark current Point", Command.ITEM, 0); … … 125 142 126 143 setMainTile(trackTile, true); 144 } 145 146 public void loadBackgrounds() { 147 String mapDirectory = Preferences.getInstance().getMapDirectory(); 148 149 mapBackgrounds = new Vector(); 150 int count = 0; 151 if (mapDirectory != null) { 152 try { 153 Vector list = ConfigFile.openList("file:///" + mapDirectory + "list.txt"); 154 155 for (int i = 0; i < list.size(); i++) { 156 String name = (String) list.elementAt(i); 157 try { 158 mapBackgrounds.addElement(MapBackground.create(mapDirectory, mapDirectory + name)); 159 ++count; 160 } catch (IOException e) { 161 Log.log(this, e, "loadBackground: " + name); 162 } 163 } 164 } catch (IOException e) { 165 Log.log(this, e, "loadBackgrounds"); 166 } 167 } 168 Log.log(this, count + " backgrounds found in " + mapDirectory); 127 169 } 128 170 … … 465 507 setStatusMessage("Continuing..."); 466 508 } 467 509 510 protected void keyRepeated(final int keyCode) { 511 keyReleased(keyCode); 512 } 513 468 514 protected void keyReleased(final int keyCode) { 469 515 final int gameAction = getGameAction(keyCode); 516 switch (keyboardMode) { 517 case KEYBOARD_DEFAULT: 518 handleDefaultKey(keyCode, gameAction); 519 break; 520 case KEYBOARD_PAN: 521 // TODO; 522 break; 523 case KEYBOARD_ADJUST_MAP: 524 handleAdjustMap(keyCode, gameAction); 525 break; 526 default: 527 break; 528 } 529 } 530 531 private void handleAdjustMap(final int keyCode, final int gameAction) { 532 MapBackground mapBackground = trackTile.getMapBackground(); 533 if (mapBackground == null) { 534 keyboardMode = KEYBOARD_DEFAULT; 535 return; 536 } 537 switch (gameAction) { 538 case LEFT: 539 mapBackground.adjustMapPosition(-1, 0); 540 break; 541 case RIGHT: 542 mapBackground.adjustMapPosition(1, 0); 543 break; 544 case DOWN: 545 mapBackground.adjustMapPosition(0, 1); 546 break; 547 case UP: 548 mapBackground.adjustMapPosition(0, -1); 549 break; 550 default: 551 mapBackground.saveConfiguration(); 552 keyboardMode = KEYBOARD_DEFAULT; 553 } 554 } 555 556 private void handleDefaultKey(final int keyCode, final int gameAction) { 470 557 switch (keyCode) { 471 558 case ' ': … … 486 573 case '8': 487 574 markPointAction(); 575 break; 576 case 'z': 577 case '3': 578 changeZoom(1); 579 break; 580 case 'h': 581 case '6': 582 changeZoom(-1); 583 break; 584 case 'a': 585 case '2': 586 keyboardMode = KEYBOARD_ADJUST_MAP; 488 587 break; 489 588 default: … … 505 604 } 506 605 606 private void changeZoom(int direction) { 607 MapBackground current = trackTile.getBackground(); 608 int idx; 609 if (current == null) { 610 if (direction > 0) { 611 idx = -1; 612 } else { 613 idx = mapBackgrounds.size(); 614 } 615 } else { 616 idx = mapBackgrounds.indexOf(current); 617 } 618 idx += direction; 619 MapBackground newBackground; 620 if (idx >= mapBackgrounds.size() || idx < 0) { 621 newBackground = null; 622 } else { 623 newBackground = (MapBackground) mapBackgrounds.elementAt(idx); 624 } 625 trackTile.setMapBackground(newBackground); 626 repaint(); 627 } 628 507 629 private class RepaintTask extends TimerTask { 508 630 public void run() { -
bbtracker/branches/map/src/org/bbtracker/mobile/gui/OptionsForm.java
r191 r212 56 56 57 57 // #ifndef AVOID_FILE_API 58 private final Command browseMapCommand; 59 58 60 private final Command browseTrackCommand; 59 61 … … 75 77 76 78 // #ifndef AVOID_FILE_API 79 private final TextField mapDirectoryField; 80 77 81 private final TextField trackDirectoryField; 78 82 … … 134 138 135 139 // #ifndef AVOID_FILE_API 140 141 mapDirectoryField = new TextField("Map directory: ", pref.getMapDirectory(), 100, TextField.URL); 142 browseMapCommand = new Command("Browse for map", Command.ITEM, 1); 143 addCommand(browseMapCommand); 144 mapDirectoryField.setItemCommandListener(this); 145 addCommand(browseMapCommand); 146 136 147 trackDirectoryField = new TextField("Track directory: ", pref.getTrackDirectory(), 100, TextField.URL); 137 browseTrackCommand = new Command("Browse ", Command.ITEM, 1);138 trackDirectoryField.setDefaultCommand(browseTrackCommand);148 browseTrackCommand = new Command("Browse for track", Command.ITEM, 1); 149 addCommand(browseTrackCommand); 139 150 trackDirectoryField.setItemCommandListener(this); 140 151 141 152 exportDirectoryField = new TextField("Export directory (defaults to track directory): ", pref 142 153 .getExportDirectory(), 100, TextField.URL); 143 browseExportCommand = new Command("Browse ", Command.ITEM, 1);144 exportDirectoryField.setDefaultCommand(browseExportCommand);154 browseExportCommand = new Command("Browse for export", Command.ITEM, 1); 155 addCommand(browseExportCommand); 145 156 exportDirectoryField.setItemCommandListener(this); 146 157 … … 161 172 append(startTypeGroup); 162 173 // #ifndef AVOID_FILE_API 174 append(mapDirectoryField); 163 175 append(trackDirectoryField); 164 176 append(exportDirectoryField); … … 230 242 BBTracker.alert(alert, null); 231 243 } 244 } else if (command == browseTrackCommand) { 245 showDirectoryBrowser("Track Storage Directory", trackDirectoryField); 246 } else if (command == browseMapCommand) { 247 showDirectoryBrowser("Track Storage Directory", mapDirectoryField); 248 } else if (command == browseExportCommand) { 249 showDirectoryBrowser("Track Export Directory", exportDirectoryField); 232 250 } else if (command == GuiUtils.CANCEL_COMMAND) { 233 251 BBTracker.getInstance().showMainCanvas(); … … 316 334 // #ifndef AVOID_FILE_API 317 335 pref.setTrackDirectory(trackDirectoryField.getString()); 336 pref.setMapDirectory(mapDirectoryField.getString()); 318 337 pref.setExportDirectory(exportDirectoryField.getString()); 319 338 Log.initLog(); … … 360 379 } else if (command == browseTrackCommand) { 361 380 showDirectoryBrowser("Track Storage Directory", trackDirectoryField); 381 } else if (command == browseMapCommand) { 382 showDirectoryBrowser("Track Storage Directory", mapDirectoryField); 362 383 } else if (command == browseExportCommand) { 363 384 showDirectoryBrowser("Track Export Directory", exportDirectoryField); -
bbtracker/branches/map/src/org/bbtracker/mobile/gui/PlotterTile.java
r192 r212 18 18 package org.bbtracker.mobile.gui; 19 19 20 import java.util.Enumeration;21 22 20 import javax.microedition.lcdui.Graphics; 23 21 24 22 import org.bbtracker.Track; 25 23 import org.bbtracker.TrackPoint; 26 import org.bbtracker.TrackSegment;27 24 import org.bbtracker.mobile.Preferences; 28 25 import org.bbtracker.mobile.TrackManager; … … 46 43 47 44 private final TrackManager manager; 48 49 private Track track; 50 45 51 46 private final AxisConfiguration xAxis = new AxisConfiguration(); 52 47 53 48 private final AxisConfiguration yAxis = new AxisConfiguration(); 54 49 50 private final boolean linkedScale; 51 52 private int marginLeft = DEFAULT_MARGIN; 53 54 private int marginRight = DEFAULT_MARGIN; 55 56 private int marginTop = DEFAULT_MARGIN; 57 58 private int marginBottom = DEFAULT_MARGIN; 59 55 60 private final DataProvider xData; 56 61 57 62 private final DataProvider yData; 58 63 59 private final boolean linkedScale; 60 61 private int marginLeft = DEFAULT_MARGIN; 62 63 private int marginRight = DEFAULT_MARGIN; 64 65 private int marginTop = DEFAULT_MARGIN; 66 67 private int marginBottom = DEFAULT_MARGIN; 68 64 private TrackPlotter mainTrackPlotter; 65 66 private TrackPlotter extraTrackPlotter; 67 69 68 public PlotterTile(final TrackManager manager, final DataProvider xData, final DataProvider yData, 70 69 final boolean linkedScale) { 71 70 this.manager = manager; 71 this.linkedScale = linkedScale; 72 72 this.xData = xData; 73 73 this.yData = yData; 74 this.linkedScale = linkedScale; 75 track = manager.getTrack(); 74 mainTrackPlotter = new TrackPlotter(); 75 mainTrackPlotter.setTrackColor(0); 76 extraTrackPlotter = new TrackPlotter(); 77 extraTrackPlotter.setTrackColor(0x9090ff); 78 extraTrackPlotter.setTrackStyle(TrackPlotter.WIDE); 79 mainTrackPlotter.setTrack(manager.getTrack()); 76 80 manager.addPointListener(this); 77 81 updateScale(); … … 132 136 } 133 137 138 doPaintBackground(g); 134 139 doPaintPlot(g); 135 140 doPaintAxis(g); … … 137 142 138 143 protected void doPaintPlot(final Graphics g) { 139 TrackPoint prevPoint = null; 140 141 int prevX = -1; 142 int prevY = -1; 143 final Enumeration segments = track.getSegments(); 144 while (segments.hasMoreElements()) { 145 final TrackSegment segment = (TrackSegment) segments.nextElement(); 146 final Enumeration points = segment.getPoints(); 147 boolean newSegment = true; 148 while (points.hasMoreElements()) { 149 final TrackPoint point = (TrackPoint) points.nextElement(); 150 final double xValue = xData.getValue(point); 151 final double yValue = yData.getValue(point); 152 final int x = getMarginLeft() + xAxis.getPosition(xValue); 153 final int y = height - (getMarginBottom() + yAxis.getPosition(yValue)); 154 155 paintConnection(g, prevPoint, prevX, prevY, point, x, y, newSegment); 156 157 prevPoint = point; 158 prevX = x; 159 prevY = y; 160 newSegment = false; 161 } 162 } 163 paintConnection(g, prevPoint, prevX, prevY, null, -1, -1, false); 144 extraTrackPlotter.paint(g, xData, yData, xAxis, yAxis, getMarginLeft(), getMarginTop(), height); 145 146 mainTrackPlotter.paint(g, xData, yData, xAxis, yAxis, getMarginLeft(), getMarginTop(), height); 147 TrackPoint currentPoint = manager.getCurrentPoint(); 148 if (currentPoint != null) { 149 mainTrackPlotter.paintCurrentPoint(g, currentPoint, xData, 150 yData, xAxis, yAxis, getMarginLeft(), getMarginTop(), height); 151 } 152 } 153 154 protected void doPaintBackground(final Graphics g) { 164 155 } 165 156 … … 235 226 236 227 private void updateScale() { 237 if (track == null || track.getPointCount() == 0) { 238 xAxis.scale = Double.NaN; 239 yAxis.scale = Double.NaN; 240 return; 241 } 242 final boolean xChanged = xAxis.updateMinMax(xData, track); 243 final boolean yChanged = yAxis.updateMinMax(yData, track); 244 if (xChanged || yChanged) { 228 if (updateScale(mainTrackPlotter)) { 229 resetScale(); 230 updateScale(mainTrackPlotter); 231 updateScale(extraTrackPlotter); 245 232 onScaleChanged(); 246 233 } 247 234 } 248 235 236 private void resetScale() { 237 xAxis.resetMinMax(); 238 yAxis.resetMinMax(); 239 } 240 241 private boolean updateScale(TrackPlotter plotter) { 242 Track track = plotter.getTrack(); 243 if (track != null && track.getLength() > 0) { 244 final boolean xChanged = xAxis.updateMinMax(xData, track); 245 final boolean yChanged = yAxis.updateMinMax(yData, track); 246 return xChanged || yChanged; 247 } else { 248 return false; 249 } 250 } 251 249 252 protected void onScaleChanged() { 250 253 if (!(xAxis.hasMinMax() && yAxis.hasMinMax())) { … … 268 271 } 269 272 273 protected void onScaleChanged(final double scaleX, final double scaleY, 274 final double centerX, final double centerY) { 275 if (!(xAxis.hasMinMax() && yAxis.hasMinMax())) { 276 xAxis.scale = Double.NaN; 277 yAxis.scale = Double.NaN; 278 return; 279 } 280 281 final int spaceX = width - (getMarginLeft() + getMarginRight()); 282 final int spaceY = height - (getMarginTop() + getMarginBottom()); 283 284 xAxis.scale = scaleX; 285 yAxis.scale = scaleY; 286 287 xAxis.calculateOffset(centerX, spaceX); 288 yAxis.calculateOffset(centerY, spaceY); 289 } 290 270 291 public void currentPointChanged(final TrackPoint newPoint, final int newIndex) { 271 if (manager.getTrack() != track) { 272 track = manager.getTrack(); 273 updateScale(); 274 } 292 // What has this to do with current point change??? 293 checkCurrentTrack(); 275 294 } 276 295 … … 280 299 281 300 public void showNotify() { 282 if (manager.getTrack() != track) { 283 track = manager.getTrack(); 284 } 285 updateScale(); 301 checkCurrentTrack(); 302 } 303 304 private void checkCurrentTrack() { 305 if (manager.getTrack() != mainTrackPlotter.getTrack()) { 306 extraTrackPlotter.setTrack(mainTrackPlotter.getTrack()); 307 mainTrackPlotter.setTrack(manager.getTrack()); 308 resetScale(); 309 updateScale(); 310 } 286 311 } 287 312 … … 301 326 return yData; 302 327 } 303 328 304 329 protected static class AxisConfiguration { 305 double minValue = Double. NaN;306 307 double maxValue = Double. NaN;330 double minValue = Double.MAX_VALUE; 331 332 double maxValue = Double.MIN_VALUE; 308 333 309 334 double scale; … … 312 337 313 338 boolean hasMinMax() { 314 return !(Double.isNaN(minValue) || Double.isNaN(maxValue)); 315 } 316 339 return !(minValue > maxValue); 340 } 341 342 void resetMinMax() { 343 minValue = Double.MAX_VALUE; 344 maxValue = Double.MIN_VALUE; 345 } 346 317 347 boolean updateMinMax(final DataProvider data, final Track track) { 318 348 final double newMin = data.getMinValue(track); 319 349 final double newMax = data.getMaxValue(track); 320 if (newMin != minValue || newMax != maxValue) { 350 boolean update = false; 351 if (newMin < minValue) { 321 352 minValue = newMin; 353 update = true; 354 } 355 if (newMax > maxValue) { 322 356 maxValue = newMax; 323 return true; 324 } else { 325 return false; 357 update = true; 326 358 } 359 return update; 327 360 } 328 361 … … 347 380 } 348 381 382 void calculateOffset(double value, final int space) { 383 offset = value - space * scale / 2; 384 } 385 349 386 int getPosition(final double value) { 350 387 return (int) ((value - offset) / scale); -
bbtracker/branches/map/src/org/bbtracker/mobile/gui/TrackTile.java
r63 r212 21 21 import javax.microedition.lcdui.Graphics; 22 22 23 import org.bbtracker.TrackPoint; 23 24 import org.bbtracker.Utils; 24 25 import org.bbtracker.UnitConverter.ScaleConfiguration; … … 33 34 private ScaleConfiguration scaleConfiguration; 34 35 36 private TrackPoint currentPoint; 37 38 private MapBackground mapBackground; 39 40 private MainCanvas mainCanvas; 41 35 42 public TrackTile(final TrackManager manager) { 36 43 super(manager, DataProvider.LONGITUDE, DataProvider.LATITUDE, true); … … 38 45 39 46 protected void onScaleChanged() { 40 super.onScaleChanged(); 47 if (mapBackground != null && currentPoint != null) { 48 double latitude = DataProvider.LATITUDE.getValue(currentPoint); 49 super.onScaleChanged(mapBackground.getScaleX(), mapBackground.getScaleY(latitude), 50 DataProvider.LONGITUDE.getValue(currentPoint), 51 latitude); 52 } else { 53 super.onScaleChanged(); 54 } 55 41 56 final double widthInMeter = Utils.distance(getYAxis().minValue, getXAxis().maxValue, getYAxis().maxValue, 42 57 getXAxis().maxValue); … … 54 69 55 70 protected void doPaintAxis(final Graphics g) { 56 if (scaleSizeInPixel == 0 ) {71 if (scaleSizeInPixel == 0 || mapBackground != null) { 57 72 return; 58 73 } … … 60 75 final Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL); 61 76 g.setFont(font); 77 g.setColor(0x00000000); 62 78 63 79 final int textBottom = height - 4 - SCALE_HEIGTH; … … 75 91 Graphics.HCENTER); 76 92 } 77 g.setColor(0x00000000);78 93 g.drawRect(left, height - 2 - SCALE_HEIGTH, scaleSizeInPixel, SCALE_HEIGTH); 79 94 g.fillRect(left, height - 2 - SCALE_HEIGTH, scaleSizeInPixel / 2, SCALE_HEIGTH); 80 95 } 96 97 98 public void currentPointChanged(final TrackPoint newPoint, final int newIndex) { 99 super.currentPointChanged(newPoint, newIndex); 100 currentPoint = newPoint; 101 if (mapBackground != null) { 102 // In map background mode, we need to readjust all axis everytime 103 // the current point changes as the current point stays in the 104 // center of the screen. 105 onScaleChanged(); 106 } 107 } 108 109 protected void doPaintBackground(final Graphics g) { 110 if (mapBackground != null) { 111 mapBackground.paint(g, 112 DataProvider.LONGITUDE.getValue(currentPoint), 113 DataProvider.LATITUDE.getValue(currentPoint), 114 (width - getMarginLeft() - getMarginRight())/ 2 + getMarginLeft(), 115 (height - getMarginTop() - getMarginBottom()) / 2 + getMarginTop()); 116 } 117 } 118 119 public void setMapBackground(final MapBackground background) { 120 if (mapBackground != null) { 121 mapBackground.stop(); 122 } 123 if (background != null) { 124 background.setMainCanvas(mainCanvas); 125 background.start(); 126 } 127 mapBackground = background; 128 onScaleChanged(); 129 } 130 131 public MapBackground getBackground() { 132 return mapBackground; 133 } 134 135 public void setMainCanvas(final MainCanvas canvas) { 136 this.mainCanvas = canvas; 137 } 138 139 140 public MapBackground getMapBackground() { 141 return mapBackground; 142 } 81 143 } -
bbtracker/branches/map/src/org/bbtracker/mobile/gui/TracksForm.java
r130 r212 30 30 31 31 import org.bbtracker.Track; 32 import org.bbtracker.TrackStoreException; 32 33 import org.bbtracker.Utils; 33 34 import org.bbtracker.mobile.BBTracker; … … 37 38 import org.bbtracker.mobile.TrackManager; 38 39 import org.bbtracker.mobile.TrackStore.TrackStoreEntry; 39 import org.bbtracker.mobile.TrackStore.TrackStoreException;40 40 41 41 public class TracksForm extends List implements CommandListener {
Note: See TracChangeset
for help on using the changeset viewer.