pathfinder
Class JPFMap

java.lang.Object
  extended by pathfinder.JPFMap

public class JPFMap
extends java.lang.Object

Data structure holding map information


Constructor Summary
JPFMap()
          Creates a new instance of JPFMap
JPFMap(java.io.File selFile)
          Creates a new instance of JPFMap
 
Method Summary
 void blockRoad(int roadId)
          Blocks road roadId
 JMapPanel drawMap(int width, int height)
          draws the map
 void drawPath(int city1, int city2)
          draws path (=line) between 2 m_cityList using global path color
 void drawPath(int city1, int city2, java.awt.Color col)
          draws path (=line) between 2 m_cityList using given path color
 java.awt.Color getCityColor()
          returns color of the city symbol
 int[] getCityCoords(int city)
          returns city coordinates
 int getCityCount()
           
 double getCityDistance(int city1, int city2)
          returns double distance of given two m_cityList
 java.util.ArrayList<java.lang.String[]> getCityList()
          returns list of m_cityList in the map
 int[] getCityNeighbours(int city)
          returns array of city neighbours
 int getNearestCity(float x, float y)
          Returns id of the city that is nearest to given position
 int[] getNearestRoad(float x, float y, float minDist)
          Returns id of the cities that are connected by road nearest to given position
 java.awt.Color getPathColor()
          gets path highlight color
 java.util.ArrayList<java.lang.String[]> getRoadList()
          returns list of m_roadList in the map
 int getRoadSpeed(int city1, int city2)
          returns road type (=max. allowed speed) between two m_cityList
 void highlightCities(int[] cities)
          highlights given array of m_cityList
 void highlightCities(int[] cities, java.awt.Color col)
          highlights given array of m_cityList
 void loadMapFromFile(java.io.File selFile)
          Loads map from given csv file
protected  void processCoords(java.lang.String[] csvFields)
          a function utilised for drawing purposes
protected  int[] remapCoords(double[] coords, double windowW, double windowH)
          a function utilised for drawing purposes
protected  int[] remapCoords(int[] coords, double windowW, double windowH)
          a function utilised for drawing purposes
protected  int[] remapCoordsBack(double[] windowCoords, double windowW, double windowH)
          a function utilised for drawing purposes
 int[] remapCoordsBack(int[] windowCoords, double windowW, double windowH)
          a function utilised for drawing purposes to map from panel to JPFMap
protected  double[] remapCoordsToDouble(double[] coords, double windowW, double windowH)
          a function utilised for drawing purposes
 void setCityColor(java.awt.Color col)
          sets color of the city symbol
 void setCityHeight(int h)
          Sets height of the city symbol
 void setCityWidth(int w)
          Sets width of the city symbol
 void setPathColor(java.awt.Color P)
          Sets the path color used for drawing paths in the map
 void setRoadColors(java.awt.Color Hi, java.awt.Color Mid, java.awt.Color Lo)
          Sets colors of the m_roadList
 void unblockRoads()
          Removes road blocks
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JPFMap

public JPFMap()
Creates a new instance of JPFMap


JPFMap

public JPFMap(java.io.File selFile)
Creates a new instance of JPFMap

Parameters:
selFile - csv file with map data
Method Detail

getCityCount

public int getCityCount()
Returns:
number of cities in the map

loadMapFromFile

public void loadMapFromFile(java.io.File selFile)
Loads map from given csv file

Parameters:
selFile - - csv file containing the map

drawMap

public JMapPanel drawMap(int width,
                         int height)
draws the map

Parameters:
width - - width of the output
height - - height of the output

setCityWidth

public void setCityWidth(int w)
Sets width of the city symbol

Parameters:
w - - width of the symbol

setCityHeight

public void setCityHeight(int h)
Sets height of the city symbol

Parameters:
h - - height of the symbol

setRoadColors

public void setRoadColors(java.awt.Color Hi,
                          java.awt.Color Mid,
                          java.awt.Color Lo)
Sets colors of the m_roadList

Parameters:
Hi -
Mid -
Lo - - three colors of three road types

setPathColor

public void setPathColor(java.awt.Color P)
Sets the path color used for drawing paths in the map


getPathColor

public java.awt.Color getPathColor()
gets path highlight color

Returns:
highlight color

setCityColor

public void setCityColor(java.awt.Color col)
sets color of the city symbol

Parameters:
col - color

getCityColor

public java.awt.Color getCityColor()
returns color of the city symbol

Returns:
city color

getCityList

public java.util.ArrayList<java.lang.String[]> getCityList()
returns list of m_cityList in the map

Returns:
list of city ids

getRoadList

public java.util.ArrayList<java.lang.String[]> getRoadList()
returns list of m_roadList in the map

Returns:
list of road ids

drawPath

public void drawPath(int city1,
                     int city2)
draws path (=line) between 2 m_cityList using global path color

Parameters:
city1 - id of 1st city
city2 - id of 2nd city

drawPath

public void drawPath(int city1,
                     int city2,
                     java.awt.Color col)
draws path (=line) between 2 m_cityList using given path color

Parameters:
city1 - id of 1st city
city2 - id of 2nd city
col - - highlight color

highlightCities

public void highlightCities(int[] cities)
highlights given array of m_cityList

Parameters:
cities - - array of cities (defined as integers)

highlightCities

public void highlightCities(int[] cities,
                            java.awt.Color col)
highlights given array of m_cityList

Parameters:
cities - - array of cities (defined as integers)
col - - highlighting color

getCityCoords

public int[] getCityCoords(int city)
returns city coordinates

Parameters:
city - - id of the city
Returns:
coordinates of the city defined as array of 2 integers

getCityNeighbours

public int[] getCityNeighbours(int city)
returns array of city neighbours

Parameters:
city - - id of the city
Returns:
coordinates of the city defined as array of 2 integers

getCityDistance

public double getCityDistance(int city1,
                              int city2)
returns double distance of given two m_cityList

Parameters:
city1 - id of 1st city
city2 - id of 2nd city
Returns:
(double) distance

getNearestCity

public int getNearestCity(float x,
                          float y)
Returns id of the city that is nearest to given position

Parameters:
x - x coordinate
y - y coordinate
Returns:
id of the nearest city or -1 if there is no such city

getNearestRoad

public int[] getNearestRoad(float x,
                            float y,
                            float minDist)
Returns id of the cities that are connected by road nearest to given position

Parameters:
x - x coordinate
y - y coordinate
Returns:
id of the road cities or null if there is no such city

blockRoad

public void blockRoad(int roadId)
Blocks road roadId

Parameters:
roadId -

unblockRoads

public void unblockRoads()
Removes road blocks


getRoadSpeed

public int getRoadSpeed(int city1,
                        int city2)
returns road type (=max. allowed speed) between two m_cityList

Parameters:
city1 - id of 1st city
city2 - id of 2nd city
Returns:
(integer) max speed of the road between given 2 m_cityList

processCoords

protected void processCoords(java.lang.String[] csvFields)
a function utilised for drawing purposes


remapCoordsToDouble

protected double[] remapCoordsToDouble(double[] coords,
                                       double windowW,
                                       double windowH)
a function utilised for drawing purposes


remapCoords

protected int[] remapCoords(double[] coords,
                            double windowW,
                            double windowH)
a function utilised for drawing purposes


remapCoords

protected int[] remapCoords(int[] coords,
                            double windowW,
                            double windowH)
a function utilised for drawing purposes


remapCoordsBack

protected int[] remapCoordsBack(double[] windowCoords,
                                double windowW,
                                double windowH)
a function utilised for drawing purposes


remapCoordsBack

public int[] remapCoordsBack(int[] windowCoords,
                             double windowW,
                             double windowH)
a function utilised for drawing purposes to map from panel to JPFMap