net.landspurg.map
Class BufferImage

java.lang.Object
  extended by net.landspurg.map.BufferImage

public class BufferImage
extends java.lang.Object

This classe manage the download of tiles

Internally a linked list is used, and first entry in the list is removed first, and when we use a tile, we put it on top of the list. So least used tile should be at the end of the list....
You probably don't need to deal with this classe in most of the time!


Field Summary
 java.lang.String debugString
           
static java.lang.String GOOGLE_MAP_VERSION
           
static java.lang.String GOOGLE_SAT_VERSION
           
 javax.microedition.lcdui.Image ima
          if not null, an image is associated to this tile
static MapCustomOverlay m_customOverlay
           
static int m_dataDownloadCounter
           
static boolean m_doNotUseNetwork
           
static boolean m_modePacked
          TRUE is several requests are packed in one request.... exploratory only
static boolean m_useFileAPI
           
static boolean m_useProxy
          True if the download process use a proxy server to convert images from jpg to png
static boolean m_useRMS
           
 java.lang.Object my_data
          Object that can be initialized by the user of the classe
protected static javax.microedition.lcdui.Image nullIma
           
protected  int rmsId
           
static java.lang.String ROOT_DIR
           
static int ST_IN_RMS
          This tile is not loaded in memory, but is in RMS
static int ST_LOADED
          This tile has been loaded
static int ST_LOADING
          This tile is being loaded
static int ST_NONE
          Undefined state
static int ST_NOTFOUND
          This tile has not been found on the server
static int ST_TO_DELETE
          This tile has to be deleted
static int ST_TOLOAD
          This tile has to be loaded
 int state
          Current state of the tile...
 
Constructor Summary
protected BufferImage(int px, int py, int zoom, int typeSat, int inSize)
          Should be only used internally...
 
Method Summary
protected static java.lang.String changeCar(java.lang.String res)
          Used to change the URL into an HTTP post compliant one, by changing & into %26 mostly
static boolean checkBuffer()
           
protected  void checkFile()
           
static void cleanBuffer()
          Remove all "waiting" URL, those who are in the toLoad list but that have not yet been started to load
 void delete()
           
 void delete(boolean doDelete)
           
static void deleteCache()
          Delete completely the cache
protected static boolean deleteLast()
          Delete the last element of the list...
static void dumpState()
          debuging function who display the current content of the buffer.
static void fetcher(java.util.Vector fileList)
          Fetch several tiles at a time...
 java.lang.String getCacheName()
           
static java.lang.String getDump()
           
protected static BufferImage getFirst()
          Return the first image of the list...
protected  boolean getFromRMS()
          Load from RMS the content of a tile.
static BufferImage getImage(int px, int py, int zoom, int inNumSat, int size)
          Get a tile according to his position/zoom factor/satelitte number

if tiles is in RMS, he will be loaded, if not, it will be loaded asynchronously from the sever
static BufferImage getImage(int px, int py, int zoom, int inNumSat, int size, boolean loadIt)
          Get a tile according to his position/zoom factor/satelitte number

if tiles is in RMS, he will be loaded, if not, it will be loaded asynchronously from the sever
protected static int getNum(byte[] tab, int offset, int length)
           
static int getPending()
          Return the number of files waiting to be downloaded...
protected  java.lang.String getSatURL(int x, int y, int z, int inNumSat)
           
protected  void ImagecreateImage(java.io.InputStream is, int size)
          Create an image for an input stream saved in RMS.
static void initBuffer()
          Initialize the image buffering queue.....
protected static void initRms()
          Initialise rms.
protected static BufferImage pop()
          Extract the first image of the list, and reduce the number of images in the queue by one...
static void provideDisplay(javax.microedition.lcdui.Display display, javax.microedition.lcdui.Displayable displayable)
          Small dirty hack, used to get a display and a displayable in order to show a warning message in case of low memory...
protected static void push(BufferImage inIma)
          Push an image into the list...
protected static void remove(BufferImage inIma)
          Remove an arbitrary element of the list..
protected static BufferImage removeLast()
          Remove the last element of the list, but do not delete it...
static void removeRMS()
          Totally clean up RMS used for caching
static void reset()
           
protected  void saveOneFile()
           
protected  void saveOneRms()
           
static void setBufferSize(int inSize)
          Set the size of the list...
static void setImageListener(BufferImageListener inListen)
          Set the function to be called when an image is started to be loaded, loaded, or in error, depending of the state attribate of the image.
static void setVisibleSize(int inSize)
           
static void stop()
          Stop the thread
 java.lang.String toString()
           
protected static void writeInt(java.io.ByteArrayOutputStream bo, int val, int length)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ima

public javax.microedition.lcdui.Image ima
if not null, an image is associated to this tile


ST_NONE

public static final int ST_NONE
Undefined state

See Also:
Constant Field Values

ST_TOLOAD

public static final int ST_TOLOAD
This tile has to be loaded

See Also:
Constant Field Values

ST_LOADING

public static final int ST_LOADING
This tile is being loaded

See Also:
Constant Field Values

ST_LOADED

public static final int ST_LOADED
This tile has been loaded

See Also:
Constant Field Values

ST_NOTFOUND

public static final int ST_NOTFOUND
This tile has not been found on the server

See Also:
Constant Field Values

ST_IN_RMS

public static final int ST_IN_RMS
This tile is not loaded in memory, but is in RMS

See Also:
Constant Field Values

ST_TO_DELETE

public static final int ST_TO_DELETE
This tile has to be deleted

See Also:
Constant Field Values

state

public int state
Current state of the tile...


rmsId

protected int rmsId

nullIma

protected static javax.microedition.lcdui.Image nullIma

my_data

public java.lang.Object my_data
Object that can be initialized by the user of the classe


m_modePacked

public static boolean m_modePacked
TRUE is several requests are packed in one request.... exploratory only


m_customOverlay

public static MapCustomOverlay m_customOverlay

m_useProxy

public static boolean m_useProxy
True if the download process use a proxy server to convert images from jpg to png


m_useRMS

public static boolean m_useRMS

m_doNotUseNetwork

public static boolean m_doNotUseNetwork

m_useFileAPI

public static boolean m_useFileAPI

debugString

public java.lang.String debugString

GOOGLE_SAT_VERSION

public static java.lang.String GOOGLE_SAT_VERSION

GOOGLE_MAP_VERSION

public static java.lang.String GOOGLE_MAP_VERSION

m_dataDownloadCounter

public static int m_dataDownloadCounter

ROOT_DIR

public static java.lang.String ROOT_DIR
Constructor Detail

BufferImage

protected BufferImage(int px,
                      int py,
                      int zoom,
                      int typeSat,
                      int inSize)
Should be only used internally...

Parameters:
px -
py -
zoom -
typeSat -
inSize -
Method Detail

initBuffer

public static void initBuffer()
Initialize the image buffering queue.....
Create the loading thread, and load in background the images....

Parameters:
d - current display, will be used to show error (memory error).

provideDisplay

public static void provideDisplay(javax.microedition.lcdui.Display display,
                                  javax.microedition.lcdui.Displayable displayable)
Small dirty hack, used to get a display and a displayable in order to show a warning message in case of low memory...

Parameters:
display -
displayable -

stop

public static void stop()
Stop the thread


getFirst

protected static BufferImage getFirst()
Return the first image of the list...

Returns:

pop

protected static BufferImage pop()
Extract the first image of the list, and reduce the number of images in the queue by one...

Returns:
the first image in of the list.

push

protected static void push(BufferImage inIma)
Push an image into the list...

Parameters:
inIma -

deleteLast

protected static boolean deleteLast()
Delete the last element of the list...

Returns:
true if an element has been deleted

removeLast

protected static BufferImage removeLast()
Remove the last element of the list, but do not delete it...

Returns:

remove

protected static void remove(BufferImage inIma)
Remove an arbitrary element of the list..

Parameters:
inIma -

setBufferSize

public static void setBufferSize(int inSize)
Set the size of the list...
Extra elements are deleted, both in RMS and in the memory.

Parameters:
inSize -

setVisibleSize

public static void setVisibleSize(int inSize)

setImageListener

public static void setImageListener(BufferImageListener inListen)
Set the function to be called when an image is started to be loaded, loaded, or in error, depending of the state attribate of the image.

Parameters:
inListen -

getPending

public static int getPending()
Return the number of files waiting to be downloaded...

Returns:
the number of pending file to be downloaded.

getCacheName

public java.lang.String getCacheName()

getSatURL

protected java.lang.String getSatURL(int x,
                                     int y,
                                     int z,
                                     int inNumSat)

changeCar

protected static java.lang.String changeCar(java.lang.String res)
Used to change the URL into an HTTP post compliant one, by changing & into %26 mostly

Parameters:
res -
Returns:

cleanBuffer

public static void cleanBuffer()
Remove all "waiting" URL, those who are in the toLoad list but that have not yet been started to load


deleteCache

public static void deleteCache()
Delete completely the cache


getNum

protected static int getNum(byte[] tab,
                            int offset,
                            int length)
Parameters:
tab -
offset -
length -
Returns:

initRms

protected static void initRms()
Initialise rms. Called internally...
Check the RMS, and load all id and position, but do not load the image. Image will be only loaded on demand.


removeRMS

public static void removeRMS()
Totally clean up RMS used for caching


getFromRMS

protected boolean getFromRMS()
Load from RMS the content of a tile. State of the tile is in that case ST_IN_RMS, and should be changed in ST_LOADED after. In case of error (incoherence for instance) then state will be changed back to ST_TO_LOAD and loaded OTA....

Returns:
true if loading was ok, false in case of error

checkFile

protected void checkFile()

saveOneFile

protected void saveOneFile()

saveOneRms

protected void saveOneRms()

writeInt

protected static void writeInt(java.io.ByteArrayOutputStream bo,
                               int val,
                               int length)

ImagecreateImage

protected void ImagecreateImage(java.io.InputStream is,
                                int size)
Create an image for an input stream saved in RMS. Remove the header who contains tiles information

Parameters:
is -

reset

public static void reset()

checkBuffer

public static boolean checkBuffer()
Returns:

fetcher

public static void fetcher(java.util.Vector fileList)
Fetch several tiles at a time...


delete

public void delete()

delete

public void delete(boolean doDelete)

dumpState

public static void dumpState()
debuging function who display the current content of the buffer.


getDump

public static java.lang.String getDump()

getImage

public static BufferImage getImage(int px,
                                   int py,
                                   int zoom,
                                   int inNumSat,
                                   int size)
Get a tile according to his position/zoom factor/satelitte number

if tiles is in RMS, he will be loaded, if not, it will be loaded asynchronously from the sever

Parameters:
px -
py -
zoom -
inNumSat -
size - Size of the tile in pixel
Returns:

getImage

public static BufferImage getImage(int px,
                                   int py,
                                   int zoom,
                                   int inNumSat,
                                   int size,
                                   boolean loadIt)
Get a tile according to his position/zoom factor/satelitte number

if tiles is in RMS, he will be loaded, if not, it will be loaded asynchronously from the sever

Parameters:
px -
py -
zoom -
inNumSat -
size - Size of the tile in pixel
loadIt - if true, load it if not present. If false, return null if tile is not here.
Returns:

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object