Changeset 212


Ignore:
Timestamp:
05/12/08 10:41:59 (5 years ago)
Author:
seb
Message:

map support, read track from gps coordinate text file

Location:
bbtracker/branches/map
Files:
8 added
15 edited

Legend:

Unmodified
Added
Removed
  • bbtracker/branches/map/.classpath

    r4 r212  
    44        <classpathentry kind="src" path="res"/> 
    55        <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"/> 
    77        <classpathentry kind="output" path="bin"/> 
    88</classpath> 
  • bbtracker/branches/map/.eclipseme

    r32 r212  
    11<?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"/> 
    44   <signing signProject="false"/> 
    55</eclipsemeMetadata> 
  • bbtracker/branches/map/.project

    r123 r212  
    2121                        </arguments> 
    2222                </buildCommand> 
     23                <buildCommand> 
     24                        <name>com.atlassw.tools.eclipse.checkstyle.CheckstyleBuilder</name> 
     25                        <arguments> 
     26                        </arguments> 
     27                </buildCommand> 
    2328        </buildSpec> 
    2429        <natures> 
     
    2631                <nature>eclipseme.core.nature</nature> 
    2732                <nature>antenna.eclipse.preprocessor.appNature</nature> 
     33                <nature>com.atlassw.tools.eclipse.checkstyle.CheckstyleNature</nature> 
    2834        </natures> 
    2935</projectDescription> 
  • bbtracker/branches/map/src/org/bbtracker/mobile/BBTracker.java

    r209 r212  
    3434import javax.microedition.rms.RecordStoreException; 
    3535 
    36 import org.bbtracker.mobile.TrackStore.TrackStoreException; 
     36import org.bbtracker.TrackStoreException; 
    3737import org.bbtracker.mobile.gps.DummyLocationProvider; 
    3838import org.bbtracker.mobile.gps.Jsr179LocationProvider; 
     
    155155 
    156156        public void showMainCanvas() { 
     157                mainCanvas.loadBackgrounds(); 
    157158                getDisplay().setCurrent(mainCanvas); 
    158159        } 
     
    233234                        final String fileConnectionVersion = System.getProperty("microedition.io.file.FileConnection.version"); 
    234235                        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                        } 
    235243                        addAPI("File", fileUrlAvailable); 
    236244                        // #endif 
  • bbtracker/branches/map/src/org/bbtracker/mobile/FileTrackStore.java

    r184 r212  
    1313 
    1414import org.bbtracker.Track; 
     15import org.bbtracker.TrackStoreException; 
     16import org.bbtracker.mobile.config.ConfigFile; 
    1517 
    1618public class FileTrackStore implements TrackStore { 
    1719 
    18         private static final String EXTENSION = ".bbt"; 
     20        private static final String BBT_EXTENSION = ".bbt"; 
     21        private static final String TXT_EXTENSION = ".txt"; 
    1922 
    2023        public TrackStoreEntry[] getEntries() throws TrackStoreException { 
     
    2427                        final Vector result = new Vector(); 
    2528                        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); 
    4643                                } 
    4744                        } 
     
    6461        } 
    6562 
     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 
    66126        public void saveTrack(final Track track) throws TrackStoreException { 
    67127                final String dir = getTrackDirectory(); 
     
    69129                DataOutputStream dout = null; 
    70130                try { 
    71                         connection = FileUtil.createFile(dir, track.getName(), EXTENSION); 
     131                        connection = FileUtil.createFile(dir, track.getName(),  
     132                                        BBT_EXTENSION); 
    72133                        dout = connection.openDataOutputStream(); 
    73134                        track.writeToStream(dout); 
     
    105166                final String url; 
    106167 
    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) { 
    108171                        super(name, date); 
    109172                        this.url = url; 
     173                        this.binary = binary; 
    110174                } 
    111175 
     
    121185 
    122186                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 { 
    123206                        DataInputStream din = null; 
    124207                        try { 
  • bbtracker/branches/map/src/org/bbtracker/mobile/IconManager.java

    r130 r212  
    3333        private final int alertSizeIndex; 
    3434 
    35         private static final Object NO_ICON = new Object(); 
     35        private static final Image NO_ICON = Image.createImage(1,1); 
    3636 
    3737        private static IconManager instance; 
     
    3939        private IconManager() { 
    4040                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)); 
    4750        } 
    4851 
     
    100103                                icon = getImage(name, sizeIndex - 1); 
    101104                        } else { 
    102                                 icon = null; 
     105                                icon = NO_ICON; 
    103106                        } 
    104107                } 
  • bbtracker/branches/map/src/org/bbtracker/mobile/Preferences.java

    r139 r212  
    115115        private Font detailsFont; 
    116116 
     117        private String mapDirectory; 
     118         
    117119        private String trackDirectory; 
    118120 
     
    164166        } 
    165167 
     168        public String getMapDirectory() { 
     169                return mapDirectory; 
     170        } 
     171         
    166172        public String getTrackDirectory() { 
    167173                return trackDirectory; 
     
    180186        } 
    181187 
     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         
    182199        public void setTrackDirectory(final String trackDirectory) { 
    183200                if (trackDirectory == null || trackDirectory.length() == 0) { 
     
    361378                                } else { 
    362379                                        exportDirectory = null; 
     380                                } 
     381                                if ((dirFlags & 4) != 0) { 
     382                                        mapDirectory = in.readUTF(); 
     383                                } else { 
     384                                        mapDirectory = null; 
    363385                                } 
    364386                                exportFormats = in.readInt(); 
     
    414436                        out.writeInt(trackNumber); 
    415437 
    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)); 
    417441                        out.writeByte(trackFlags); 
    418442                        if (trackDirectory != null) { 
     
    421445                        if (exportDirectory != null) { 
    422446                                out.writeUTF(exportDirectory); 
     447                        } 
     448                        if (mapDirectory != null) { 
     449                                out.writeUTF(mapDirectory); 
    423450                        } 
    424451                        out.writeInt(exportFormats); 
  • bbtracker/branches/map/src/org/bbtracker/mobile/RMSTrackStore.java

    r130 r212  
    1414 
    1515import org.bbtracker.Track; 
     16import org.bbtracker.TrackStoreException; 
    1617 
    1718public class RMSTrackStore implements TrackStore { 
  • bbtracker/branches/map/src/org/bbtracker/mobile/TrackManager.java

    r197 r212  
    2929import org.bbtracker.Track; 
    3030import org.bbtracker.TrackPoint; 
     31import org.bbtracker.TrackStoreException; 
    3132import org.bbtracker.Utils; 
    3233import org.bbtracker.mobile.TrackStore.TrackStoreEntry; 
    33 import org.bbtracker.mobile.TrackStore.TrackStoreException; 
    3434import org.bbtracker.mobile.exporter.GpxTrackExporter; 
    3535import org.bbtracker.mobile.exporter.KmlTrackExporter; 
  • bbtracker/branches/map/src/org/bbtracker/mobile/TrackStore.java

    r172 r212  
    2222import org.bbtracker.Comparator; 
    2323import org.bbtracker.Track; 
     24import org.bbtracker.TrackStoreException; 
    2425 
    2526public interface TrackStore { 
     
    3334 
    3435        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         } 
    4536 
    4637        public static abstract class TrackStoreEntry { 
  • bbtracker/branches/map/src/org/bbtracker/mobile/gui/MainCanvas.java

    r201 r212  
    1818package org.bbtracker.mobile.gui; 
    1919 
     20import java.io.IOException; 
    2021import java.util.TimerTask; 
     22import java.util.Vector; 
    2123 
    2224import javax.microedition.lcdui.Alert; 
     
    3436import org.bbtracker.Track; 
    3537import org.bbtracker.TrackPoint; 
     38import org.bbtracker.TrackStoreException; 
    3639import org.bbtracker.Utils; 
    3740import org.bbtracker.mobile.BBTracker; 
     
    4043import org.bbtracker.mobile.TrackListener; 
    4144import org.bbtracker.mobile.TrackManager; 
    42 import org.bbtracker.mobile.TrackStore.TrackStoreException; 
     45import org.bbtracker.mobile.config.ConfigFile; 
    4346 
    4447public class MainCanvas extends Canvas implements TrackListener, CommandListener { 
     
    5154        private final TrackManager manager; 
    5255 
    53         private final Tile trackTile; 
     56        private final TrackTile trackTile; 
    5457 
    5558        private final Tile elevationProfileTile; 
     
    9295        private int tileConfiguration = 0; 
    9396 
     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         
    94108        public MainCanvas(final TrackManager manager) { 
    95109                this.manager = manager; 
    96110 
    97111                trackTile = new TrackTile(manager); 
     112                trackTile.setMainCanvas(this); 
    98113                elevationProfileTile = new ElevationPlotterTile(manager, DataProvider.TIME); 
    99114                speedProfileTile = new SpeedPlotterTile(manager, DataProvider.TIME); 
     
    101116                detailsTile = new DetailsTile(manager); 
    102117 
     118                loadBackgrounds(); 
     119                 
    103120                switchViewCommand = new Command("Switch View", Command.SCREEN, 10); 
    104121                markPointCommand = new Command("Mark current Point", Command.ITEM, 0); 
     
    125142 
    126143                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);  
    127169        } 
    128170 
     
    465507                setStatusMessage("Continuing..."); 
    466508        } 
    467  
     509         
     510        protected void keyRepeated(final int keyCode) { 
     511                keyReleased(keyCode); 
     512        } 
     513         
    468514        protected void keyReleased(final int keyCode) { 
    469515                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) { 
    470557                switch (keyCode) { 
    471558                case ' ': 
     
    486573                case '8': 
    487574                        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; 
    488587                        break; 
    489588                default: 
     
    505604        } 
    506605 
     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         
    507629        private class RepaintTask extends TimerTask { 
    508630                public void run() { 
  • bbtracker/branches/map/src/org/bbtracker/mobile/gui/OptionsForm.java

    r191 r212  
    5656 
    5757        // #ifndef AVOID_FILE_API 
     58        private final Command browseMapCommand; 
     59         
    5860        private final Command browseTrackCommand; 
    5961 
     
    7577 
    7678        // #ifndef AVOID_FILE_API 
     79        private final TextField mapDirectoryField; 
     80         
    7781        private final TextField trackDirectoryField; 
    7882 
     
    134138 
    135139                // #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                 
    136147                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); 
    139150                trackDirectoryField.setItemCommandListener(this); 
    140151 
    141152                exportDirectoryField = new TextField("Export directory (defaults to track directory): ", pref 
    142153                                .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); 
    145156                exportDirectoryField.setItemCommandListener(this); 
    146157 
     
    161172                append(startTypeGroup); 
    162173                // #ifndef AVOID_FILE_API 
     174                append(mapDirectoryField); 
    163175                append(trackDirectoryField); 
    164176                append(exportDirectoryField); 
     
    230242                                BBTracker.alert(alert, null); 
    231243                        } 
     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); 
    232250                } else if (command == GuiUtils.CANCEL_COMMAND) { 
    233251                        BBTracker.getInstance().showMainCanvas(); 
     
    316334                        // #ifndef AVOID_FILE_API 
    317335                        pref.setTrackDirectory(trackDirectoryField.getString()); 
     336                        pref.setMapDirectory(mapDirectoryField.getString()); 
    318337                        pref.setExportDirectory(exportDirectoryField.getString()); 
    319338                        Log.initLog(); 
     
    360379                } else if (command == browseTrackCommand) { 
    361380                        showDirectoryBrowser("Track Storage Directory", trackDirectoryField); 
     381                } else if (command == browseMapCommand) { 
     382                        showDirectoryBrowser("Track Storage Directory", mapDirectoryField); 
    362383                } else if (command == browseExportCommand) { 
    363384                        showDirectoryBrowser("Track Export Directory", exportDirectoryField); 
  • bbtracker/branches/map/src/org/bbtracker/mobile/gui/PlotterTile.java

    r192 r212  
    1818package org.bbtracker.mobile.gui; 
    1919 
    20 import java.util.Enumeration; 
    21  
    2220import javax.microedition.lcdui.Graphics; 
    2321 
    2422import org.bbtracker.Track; 
    2523import org.bbtracker.TrackPoint; 
    26 import org.bbtracker.TrackSegment; 
    2724import org.bbtracker.mobile.Preferences; 
    2825import org.bbtracker.mobile.TrackManager; 
     
    4643 
    4744        private final TrackManager manager; 
    48  
    49         private Track track; 
    50  
     45         
    5146        private final AxisConfiguration xAxis = new AxisConfiguration(); 
    5247 
    5348        private final AxisConfiguration yAxis = new AxisConfiguration(); 
    5449 
     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 
    5560        private final DataProvider xData; 
    5661 
    5762        private final DataProvider yData; 
    5863 
    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         
    6968        public PlotterTile(final TrackManager manager, final DataProvider xData, final DataProvider yData, 
    7069                        final boolean linkedScale) { 
    7170                this.manager = manager; 
     71                this.linkedScale = linkedScale; 
    7272                this.xData = xData; 
    7373                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()); 
    7680                manager.addPointListener(this); 
    7781                updateScale(); 
     
    132136                } 
    133137 
     138                doPaintBackground(g); 
    134139                doPaintPlot(g); 
    135140                doPaintAxis(g); 
     
    137142 
    138143        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) { 
    164155        } 
    165156 
     
    235226 
    236227        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); 
    245232                        onScaleChanged(); 
    246233                } 
    247234        } 
    248235 
     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         
    249252        protected void onScaleChanged() { 
    250253                if (!(xAxis.hasMinMax() && yAxis.hasMinMax())) { 
     
    268271        } 
    269272 
     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         
    270291        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(); 
    275294        } 
    276295 
     
    280299 
    281300        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                } 
    286311        } 
    287312 
     
    301326                return yData; 
    302327        } 
    303  
     328         
    304329        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; 
    308333 
    309334                double scale; 
     
    312337 
    313338                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                 
    317347                boolean updateMinMax(final DataProvider data, final Track track) { 
    318348                        final double newMin = data.getMinValue(track); 
    319349                        final double newMax = data.getMaxValue(track); 
    320                         if (newMin != minValue || newMax != maxValue) { 
     350                        boolean update = false; 
     351                        if (newMin < minValue) { 
    321352                                minValue = newMin; 
     353                                update = true; 
     354                        }  
     355                        if (newMax > maxValue) { 
    322356                                maxValue = newMax; 
    323                                 return true; 
    324                         } else { 
    325                                 return false; 
     357                                update = true; 
    326358                        } 
     359                        return update; 
    327360                } 
    328361 
     
    347380                } 
    348381 
     382                void calculateOffset(double value, final int space) { 
     383                        offset = value - space * scale / 2; 
     384                } 
     385                 
    349386                int getPosition(final double value) { 
    350387                        return (int) ((value - offset) / scale); 
  • bbtracker/branches/map/src/org/bbtracker/mobile/gui/TrackTile.java

    r63 r212  
    2121import javax.microedition.lcdui.Graphics; 
    2222 
     23import org.bbtracker.TrackPoint; 
    2324import org.bbtracker.Utils; 
    2425import org.bbtracker.UnitConverter.ScaleConfiguration; 
     
    3334        private ScaleConfiguration scaleConfiguration; 
    3435 
     36        private TrackPoint currentPoint; 
     37         
     38        private MapBackground mapBackground; 
     39 
     40        private MainCanvas mainCanvas; 
     41         
    3542        public TrackTile(final TrackManager manager) { 
    3643                super(manager, DataProvider.LONGITUDE, DataProvider.LATITUDE, true); 
     
    3845 
    3946        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                 
    4156                final double widthInMeter = Utils.distance(getYAxis().minValue, getXAxis().maxValue, getYAxis().maxValue, 
    4257                                getXAxis().maxValue); 
     
    5469 
    5570        protected void doPaintAxis(final Graphics g) { 
    56                 if (scaleSizeInPixel == 0) { 
     71                if (scaleSizeInPixel == 0 || mapBackground != null) { 
    5772                        return; 
    5873                } 
     
    6075                final Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL); 
    6176                g.setFont(font); 
     77                g.setColor(0x00000000); 
    6278 
    6379                final int textBottom = height - 4 - SCALE_HEIGTH; 
     
    7591                                        Graphics.HCENTER); 
    7692                } 
    77                 g.setColor(0x00000000); 
    7893                g.drawRect(left, height - 2 - SCALE_HEIGTH, scaleSizeInPixel, SCALE_HEIGTH); 
    7994                g.fillRect(left, height - 2 - SCALE_HEIGTH, scaleSizeInPixel / 2, SCALE_HEIGTH); 
    8095        } 
     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        } 
    81143} 
  • bbtracker/branches/map/src/org/bbtracker/mobile/gui/TracksForm.java

    r130 r212  
    3030 
    3131import org.bbtracker.Track; 
     32import org.bbtracker.TrackStoreException; 
    3233import org.bbtracker.Utils; 
    3334import org.bbtracker.mobile.BBTracker; 
     
    3738import org.bbtracker.mobile.TrackManager; 
    3839import org.bbtracker.mobile.TrackStore.TrackStoreEntry; 
    39 import org.bbtracker.mobile.TrackStore.TrackStoreException; 
    4040 
    4141public class TracksForm extends List implements CommandListener { 
Note: See TracChangeset for help on using the changeset viewer.