es.prodevelop.gvsig.mobile.fmap.util
Class Utils

java.lang.Object
  extended byes.prodevelop.gvsig.mobile.fmap.util.Utils

public class Utils
extends java.lang.Object

Utility static methods.

Author:
jcarras, jldominguez
See Also:
FalseByteBuffer

Field Summary
static java.lang.String CACHED_FILES_EXT
           
static java.lang.String DATE_FORMAT
           
static java.lang.String gif
           
static java.awt.GraphicsConfiguration graphConfig
          Device-dependant graphics configuration object
static java.awt.geom.AffineTransform IDENTITY_AT
           
static java.lang.String jpeg
           
static java.lang.String jpg
           
static long LAST_EXECUTION_INTERVAL
          Interval used to check if the application can be launched or not
static java.lang.String png
           
static java.lang.String tif
           
static java.lang.String tiff
           
static java.awt.Color TILE_PROBLEM_403_COLOR
           
static java.awt.Color TILE_PROBLEM_COLOR
           
static java.awt.Font TILE_PROBLEM_FONT
           
static java.lang.String TILE_PROBLEM_MSG_403
           
static java.lang.String TILE_PROBLEM_MSG_ERROR
           
static java.lang.String TILE_PROBLEM_MSG_NODATA
           
static int TILE_PROBLEM_X_OFFSET
           
static int TILE_PROBLEM_Y_OFFSET
           
static boolean USING_PDA
          Whether the PDA is being used (false when running a PC)
 
Constructor Summary
Utils()
           
 
Method Summary
static void addAttributesToList(com.hardcode.gdbms.engine.values.Value[] atts, java.lang.String[] fieldnames, java.util.ArrayList gdata, java.util.ArrayList al)
          Adds field names and vaklues to an array of data that will afterwards used to show info by point n a dialog
static java.awt.image.BufferedImage createBufferedImage(int w, int h)
          Creates a buffered image
static java.awt.image.BufferedImage createBufferedImage(int w, int h, int type)
          Creates a buffered image
static void createWorkspaceFolder(java.lang.String folder_name)
          Creates a workspace folder
static java.util.Date dateFromString(java.lang.String date)
          Instantiates a Date object from a string
static java.lang.String dateToString(java.util.Date date)
          Gets string representation of a date
static boolean executionAllowed(java.lang.String path, long currtime)
          This method finds out if the application is already running.
static java.lang.String getExtension(java.io.File f)
          Get the extension of a file.
static java.awt.geom.Rectangle2D getExtent(java.awt.geom.AffineTransform at, int iw, int ih)
          gets the extent for a given rectangle and affine transform
static java.lang.String getFormattedDouble(double d, int decimals)
          Gets a double as a formatted string
static java.io.File getHashCacheFileForUrl(java.net.URL u, java.lang.String cacheFolder, java.lang.String folder, java.lang.String ext)
          gets the cache file path (using hash function) for a given URL
static java.awt.geom.Rectangle2D getScaledCenteredRectangle(java.awt.geom.Rectangle2D r, double d)
          Gets a scaled version of a given rectangle centered in the same point
static java.lang.String hashString(java.lang.String str)
          Apply a hash function to s string
static FalseByteBuffer loadFileInputStream(java.io.FileInputStream in, int size)
          Loads a file into a byte buffer
 int minCommon(java.lang.String a, java.lang.String b)
          Finds out the index until which two strings are equal
static byte[] readFileIntoByteArray(java.io.File f)
          reads file into byte array
static java.awt.geom.AffineTransform readWldFile(java.io.File imageFile, java.lang.String[] valid_ext)
          Reads the affine transform from a WLD file
static java.awt.event.MouseEvent recreateMouseEvent(java.awt.Component src, int x, int y)
           
static boolean rectanglesItersect(java.awt.geom.Rectangle2D r_1, java.awt.geom.Rectangle2D r_2)
          Returns whether these rectangles intersect (this was necessary because the original metod behaves in a strabge way)
static java.lang.String relPath(java.lang.String projectPath, java.lang.String absPath)
           
static java.lang.String replaceAllString(java.lang.String original, java.lang.String match_old, java.lang.String match_new)
          Replaces all occurrences of a string
static double smallerDouble(double a, double f, double minimum)
           
static int smallerInteger(int a, double f, int minimum)
          Performs a product and returns the maximum
static java.lang.String[] splitString(java.lang.String input, java.lang.String sep)
          Splits string into an array of strings
static void swap(java.util.ArrayList _list, int firstInd, int secondInd)
          Swap objects in a list
static java.lang.String time()
           
static void touch()
          Utility methos to force the execution of the static section
static java.lang.StringBuffer toXML(java.lang.String name, boolean obj)
          Gets XML text description of booelan value
static java.lang.StringBuffer toXML(java.lang.String name, double obj)
          Gets XML text description of a double value
static java.lang.StringBuffer toXML(java.lang.String name, int obj)
          Gets XML text description of a int value
static java.lang.StringBuffer toXML(java.lang.String name, java.lang.Object obj)
          Gets XML text description of an object
static boolean writeBytesToFile(byte[] data, java.lang.String path)
          Writes byte array to file
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USING_PDA

public static boolean USING_PDA
Whether the PDA is being used (false when running a PC)


jpeg

public static final java.lang.String jpeg
See Also:
Constant Field Values

jpg

public static final java.lang.String jpg
See Also:
Constant Field Values

gif

public static final java.lang.String gif
See Also:
Constant Field Values

tiff

public static final java.lang.String tiff
See Also:
Constant Field Values

tif

public static final java.lang.String tif
See Also:
Constant Field Values

png

public static final java.lang.String png
See Also:
Constant Field Values

DATE_FORMAT

public static final java.lang.String DATE_FORMAT
See Also:
Constant Field Values

CACHED_FILES_EXT

public static final java.lang.String CACHED_FILES_EXT
See Also:
Constant Field Values

IDENTITY_AT

public static final java.awt.geom.AffineTransform IDENTITY_AT

TILE_PROBLEM_FONT

public static final java.awt.Font TILE_PROBLEM_FONT

TILE_PROBLEM_MSG_403

public static final java.lang.String TILE_PROBLEM_MSG_403
See Also:
Constant Field Values

TILE_PROBLEM_MSG_ERROR

public static final java.lang.String TILE_PROBLEM_MSG_ERROR
See Also:
Constant Field Values

TILE_PROBLEM_MSG_NODATA

public static final java.lang.String TILE_PROBLEM_MSG_NODATA
See Also:
Constant Field Values

TILE_PROBLEM_403_COLOR

public static final java.awt.Color TILE_PROBLEM_403_COLOR

TILE_PROBLEM_COLOR

public static final java.awt.Color TILE_PROBLEM_COLOR

TILE_PROBLEM_X_OFFSET

public static final int TILE_PROBLEM_X_OFFSET
See Also:
Constant Field Values

TILE_PROBLEM_Y_OFFSET

public static final int TILE_PROBLEM_Y_OFFSET
See Also:
Constant Field Values

graphConfig

public static java.awt.GraphicsConfiguration graphConfig
Device-dependant graphics configuration object


LAST_EXECUTION_INTERVAL

public static long LAST_EXECUTION_INTERVAL
Interval used to check if the application can be launched or not

Constructor Detail

Utils

public Utils()
Method Detail

touch

public static void touch()
Utility methos to force the execution of the static section


getExtension

public static java.lang.String getExtension(java.io.File f)
Get the extension of a file.


splitString

public static java.lang.String[] splitString(java.lang.String input,
                                             java.lang.String sep)
Splits string into an array of strings

Parameters:
input - input string
sep - separator string
Returns:
an array of strings

replaceAllString

public static java.lang.String replaceAllString(java.lang.String original,
                                                java.lang.String match_old,
                                                java.lang.String match_new)
Replaces all occurrences of a string

Parameters:
original - input string
match_old - string to be replaced
match_new - new string to be written instead of the replaced string
Returns:
input string with replacements done

loadFileInputStream

public static FalseByteBuffer loadFileInputStream(java.io.FileInputStream in,
                                                  int size)
                                           throws java.io.IOException
Loads a file into a byte buffer

Parameters:
in - input stream
size - file size
Returns:
a byte buffer
Throws:
java.io.IOException

time

public static java.lang.String time()
Returns:
current time as a string

rectanglesItersect

public static boolean rectanglesItersect(java.awt.geom.Rectangle2D r_1,
                                         java.awt.geom.Rectangle2D r_2)
Returns whether these rectangles intersect (this was necessary because the original metod behaves in a strabge way)

Parameters:
r_1 -
r_2 -
Returns:
whether these rectangles intersect

getFormattedDouble

public static java.lang.String getFormattedDouble(double d,
                                                  int decimals)
Gets a double as a formatted string

Parameters:
d - value
decimals - number of decimal
Returns:
the formatted string

addAttributesToList

public static void addAttributesToList(com.hardcode.gdbms.engine.values.Value[] atts,
                                       java.lang.String[] fieldnames,
                                       java.util.ArrayList gdata,
                                       java.util.ArrayList al)
Adds field names and vaklues to an array of data that will afterwards used to show info by point n a dialog

Parameters:
atts - the atts to be added
fieldnames - the field names
gdata - the geographic data (this is added as is)
al - the list to be expanded

getScaledCenteredRectangle

public static java.awt.geom.Rectangle2D getScaledCenteredRectangle(java.awt.geom.Rectangle2D r,
                                                                   double d)
Gets a scaled version of a given rectangle centered in the same point

Parameters:
r - input rectangle
d - scale
Returns:
a scaled version of a given rectangle centered in the same point

smallerInteger

public static int smallerInteger(int a,
                                 double f,
                                 int minimum)
Performs a product and returns the maximum


smallerDouble

public static double smallerDouble(double a,
                                   double f,
                                   double minimum)

swap

public static void swap(java.util.ArrayList _list,
                        int firstInd,
                        int secondInd)
Swap objects in a list

Parameters:
_list - input list
firstInd - index
secondInd - index

readWldFile

public static java.awt.geom.AffineTransform readWldFile(java.io.File imageFile,
                                                        java.lang.String[] valid_ext)
Reads the affine transform from a WLD file

Parameters:
imageFile - image file
valid_ext - valid extensions for WLD files
Returns:
the affine transform from a WLD file

toXML

public static java.lang.StringBuffer toXML(java.lang.String name,
                                           boolean obj)
Gets XML text description of booelan value

Parameters:
name - element name
obj - boolean value
Returns:
the XML text description of booelan value

toXML

public static java.lang.StringBuffer toXML(java.lang.String name,
                                           int obj)
Gets XML text description of a int value

Parameters:
name - element name
obj - int value
Returns:
the XML text description of a int value

toXML

public static java.lang.StringBuffer toXML(java.lang.String name,
                                           double obj)
Gets XML text description of a double value

Parameters:
name - element name
obj - double value
Returns:
the XML text description of a double value

toXML

public static java.lang.StringBuffer toXML(java.lang.String name,
                                           java.lang.Object obj)
Gets XML text description of an object

Parameters:
name - element name
obj -
Returns:
the XML text description of an object

getExtent

public static java.awt.geom.Rectangle2D getExtent(java.awt.geom.AffineTransform at,
                                                  int iw,
                                                  int ih)
gets the extent for a given rectangle and affine transform

Parameters:
at - teh affinte transform
iw - image width
ih - image height
Returns:
the extent in map units

createBufferedImage

public static java.awt.image.BufferedImage createBufferedImage(int w,
                                                               int h)
Creates a buffered image

Parameters:
w - width
h - height
Returns:
a buffered image

createBufferedImage

public static java.awt.image.BufferedImage createBufferedImage(int w,
                                                               int h,
                                                               int type)
Creates a buffered image

Parameters:
w - width
h - height
type - the image type
Returns:
a buffered image

readFileIntoByteArray

public static byte[] readFileIntoByteArray(java.io.File f)
reads file into byte array

Parameters:
f - the file
Returns:
a byte array with the same data

relPath

public static java.lang.String relPath(java.lang.String projectPath,
                                       java.lang.String absPath)
Parameters:
projectPath -
absPath -
Returns:
Path relative to find absPath from projectPath

minCommon

public int minCommon(java.lang.String a,
                     java.lang.String b)
Finds out the index until which two strings are equal

Parameters:
a -
b -
Returns:
the index until which two strings are equal

createWorkspaceFolder

public static void createWorkspaceFolder(java.lang.String folder_name)
Creates a workspace folder

Parameters:
folder_name -

writeBytesToFile

public static boolean writeBytesToFile(byte[] data,
                                       java.lang.String path)
Writes byte array to file

Parameters:
data -
path - file path
Returns:
whether the writing was successful

executionAllowed

public static boolean executionAllowed(java.lang.String path,
                                       long currtime)
This method finds out if the application is already running. Used to prevent double application instantiation

Parameters:
path - path of the exe log file
currtime - current time in miliseconds
Returns:
whether the application can be launched

dateToString

public static java.lang.String dateToString(java.util.Date date)
Gets string representation of a date

Parameters:
date -
Returns:
string representation of a date

dateFromString

public static java.util.Date dateFromString(java.lang.String date)
                                     throws java.text.ParseException
Instantiates a Date object from a string

Parameters:
date - date as a sring
Returns:
a Date object
Throws:
java.text.ParseException

hashString

public static java.lang.String hashString(java.lang.String str)
Apply a hash function to s string

Parameters:
str - input string
Returns:
hash function output

getHashCacheFileForUrl

public static java.io.File getHashCacheFileForUrl(java.net.URL u,
                                                  java.lang.String cacheFolder,
                                                  java.lang.String folder,
                                                  java.lang.String ext)
gets the cache file path (using hash function) for a given URL

Parameters:
u - URL
cacheFolder - cache files folder
folder - cache subfolder
ext - cached file extension
Returns:
the file object where the resource will be stored

recreateMouseEvent

public static java.awt.event.MouseEvent recreateMouseEvent(java.awt.Component src,
                                                           int x,
                                                           int y)