org.eclipse.ohf.stem.ui.views.map
Class MapCanvas

java.lang.Object
  extended by org.eclipse.swt.widgets.Widget
      extended by org.eclipse.swt.widgets.Control
          extended by org.eclipse.swt.widgets.Scrollable
              extended by org.eclipse.swt.widgets.Composite
                  extended by org.eclipse.swt.widgets.Canvas
                      extended by org.eclipse.ohf.stem.ui.views.map.MapCanvas
All Implemented Interfaces:
org.eclipse.swt.graphics.Drawable

public class MapCanvas
extends org.eclipse.swt.widgets.Canvas

MapCanvas is a subclass of Canvas suitable for map drawings, It has some additional properties, such as access to the colors of the polygons and background. It also contains a PaintListener which will make the canvas draw itself whenever a change is done in the graphics. It also contains the "draw" method which gets the MapCanvas' list of polygons and puts them, using another adapter class (Graphics2DRenderer), on the MapCanvas.


Field Summary
static java.lang.String DEFAULT_BACKGROUND_COLOR_STRING
          The default background color string.
static java.lang.String DEFAULT_BORDER_COLOR_STRING
          The default border color string.
static boolean DEFAULT_DRAW_POLYGON_BORDERS
          The default value for drawing polygon borders.
static double DEFAULT_GAIN_FACTOR
          The default value for the initial gain factor.
static double DEFAULT_GUI_SCALING_FACTOR
          This is the default scaling factor
static int DEFAULT_INITIAL_X_TRANSLATION
          The default value for the intial translation of the map in the x-axis
static int DEFAULT_INITIAL_Y_TRANSLATION
          The default value for the intial translation of the map in the y-axis
static boolean DEFAULT_LOGSCALE
          The default value for displaying with a logrithmic scale.
static java.lang.String DEFAULT_POLYGON_COLOR_RELATIVE_VALUE_ZERO_STRING
          The default polygon color string.
static java.lang.String DEFAULT_POLYGON_COLOR_STRING
          The default polygon color string.
static double DEFAULT_SCALING_FACTOR_ON_ZOOM_RULER
          The default value for the zoom factor of the displays scale
 
Fields inherited from class org.eclipse.swt.widgets.Control
handle
 
Constructor Summary
MapCanvas(org.eclipse.swt.widgets.Composite parent, int style)
          Constructor.
 
Method Summary
 void dispose()
          Disposes the Color objects
 void draw(org.eclipse.swt.graphics.GC gc, int x, int y, int width, int height)
          The method which gets the MapCanvas' polygons list, and draws it on the MapCanvas.
 java.awt.geom.AffineTransform getAffineTransform()
           
 java.awt.Color getBackgroundColorAWT()
          Gets the background color of the MapCanvas (in AWT).
 org.eclipse.swt.graphics.RGB getBackgroundColorRGB()
           
 org.eclipse.swt.graphics.Color getBackgroundColorSWT()
           
 java.awt.Color getBorderColorAWT()
          Gets the border color (in AWT).
 org.eclipse.swt.graphics.Color getBorderColorSWT()
          Gets the polygons base color of the MapCanvas (in SWT).
 double getDataScalingFactorInXaxis()
           
 double getDataScalingFactorInYaxis()
           
 boolean getDrawPolygonsBorders()
          Determins whether the polygons borders will be drawn.
 org.eclipse.swt.graphics.Color getForegroundColorSWT()
           
 double getGainFactor()
          Gets the gain factor for the displayed colors
 double getGuiScalingFactorInXaxis()
           
 double getGuiScalingFactorInYaxis()
           
 StemPolygonsList getPolygons()
           
 java.awt.Color getPolygonsColorAWT()
          Gets the polygons base color of the MapCanvas (in AWT).
 java.awt.Color getPolygonsColorRelativeValueZeroAWT()
          Gets the polygons base color of the MapCanvas (in AWT) when the relative value is zero.
 org.eclipse.swt.graphics.RGB getPolygonsColorRelativeValueZeroRGB()
           
 org.eclipse.swt.graphics.Color getPolygonsColorRelativeValueZeroSWT()
           
 org.eclipse.swt.graphics.RGB getPolygonsColorRGB()
          Gets the polygons base color of the MapCanvas (in RGB).
 org.eclipse.swt.graphics.Color getPolygonsColorSWT()
          Gets the polygons base color of the MapCanvas (in SWT).
 double getScalingFactorInYaxis()
           
 double getScalingFactorOnZoomRuler()
          Get the scaling factor which was saved in the zoom scale in the view.
 double getTranslateX()
           
 double getTranslateY()
           
 java.lang.String getWhichProjection()
           
 double getZoomFactorInXaxis()
          Gets the scaling factor of the map (zoom in/out).
 double getZoomFactorInYaxis()
          Gets the scaling factor of the map (zoom in/out).
 float multiplyByGainFactor(float val)
          Multiplies the relative value which is going to be displayed by the gain factor required by the user.
 float performLogScaling(float v)
          Perform a log scale to a specific value
 void produceIntCoordinates()
          Performs the projection on the MapCanvas' polygons list.
 void setAffineTransform(java.awt.geom.AffineTransform affineTransform)
          Set the affine transform
 void setBackgroundColorRGB(org.eclipse.swt.graphics.RGB bgRGB)
          Sets the background color.
 void setBorderColorRGB(org.eclipse.swt.graphics.RGB borderRGB)
          Sets the polygons base color of the polygons.
 void setDataScalingFactorInXaxis(double dataScalingFactorInXaxis)
          Set the X axis data scaling factor
 void setDataScalingFactorInYaxis(double dataScalingFactorInYaxis)
          Set the Y axis data scaling factor
 void setDrawPolygonBorders(boolean drawBordersFlag)
          Determins whether the polygons borders will be drawn.
 void setGainFactor(double gainVal)
          Sets the gain factor for the displayed colors
 void setGuiScalingFactorInXaxis(double scalingFactorInXaxis)
          Set the X axis scaling factor
 void setGuiScalingFactorInYaxis(double guiScalingFactorInYaxis)
          Set the Y axis Gui scaling factor
 void setPolygons(StemPolygonsList polygonsList)
          Sets the polygons list of the MapCanvas.
 void setPolygonsCentersConnections(StemPolygonsList polygonsCentersConnectionsList)
          Sets the polygons that connects the nodes
 void setPolygonsColorRelativeValueZeroRGB(org.eclipse.swt.graphics.RGB polygonsColorRelativeValueZeroRGB)
           
 void setPolygonsColorRelativeValueZeroSWT(org.eclipse.swt.graphics.Color polygonsColorRelativeValueZeroSWT)
           
 void setPolygonsColorRGB(org.eclipse.swt.graphics.RGB polyRGB)
          Sets the polygons base color of the polygons.
 void setScalingFactorInYaxis(double scalingFactorInYaxis)
          Set the Y axis scaling factor
 void setScalingFactorOnZoomRuler(double val)
          Sets the scaling factor (the one that appears on the zoom ruler).
 void setTranslate(double valX, double valY)
          Sets the offset needed for the coordinates in order to draw the map on the canvas.
 void setWhichProjection(java.lang.String whichProjection)
           
 void toggleDisplayPolygonsNames()
          Switch the option of displaying the polygons titles.
 void toggleDrawPolygonsBordersChoice()
          Switch the option of drawing the borders of polygons on the map.
 void toggleDrawPolygonsCentersConnections()
          Switch the option of drawing the edges connecting every two polygons.
 void toggleLogScaleChoice()
          Switch the option of displaying the polygons titles.
 void zoom(double zoomX, double zoomY)
          Sets the scaling factor of the map (zoom in/out).
 
Methods inherited from class org.eclipse.swt.widgets.Canvas
drawBackground, getCaret, scroll, setCaret, setFont
 
Methods inherited from class org.eclipse.swt.widgets.Composite
changed, computeSize, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
 
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getVerticalBar
 
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addDragDetectListener, addFocusListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTraverseListener, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getParent, getShell, getSize, getToolTipText, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTraverseListener, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setForeground, setLayoutData, setLocation, setLocation, setMenu, setParent, setRedraw, setSize, setSize, setToolTipText, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, update
 
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, getData, getData, getDisplay, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, setData, setData, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_BACKGROUND_COLOR_STRING

public static final java.lang.String DEFAULT_BACKGROUND_COLOR_STRING
The default background color string. Value: 28,3,141 (Blue)

See Also:
Constant Field Values

DEFAULT_POLYGON_COLOR_STRING

public static final java.lang.String DEFAULT_POLYGON_COLOR_STRING
The default polygon color string. Value: 255,0,0 (Red)

See Also:
Constant Field Values

DEFAULT_POLYGON_COLOR_RELATIVE_VALUE_ZERO_STRING

public static final java.lang.String DEFAULT_POLYGON_COLOR_RELATIVE_VALUE_ZERO_STRING
The default polygon color string. Value: 183,164,106 (Brown)

See Also:
Constant Field Values

DEFAULT_BORDER_COLOR_STRING

public static final java.lang.String DEFAULT_BORDER_COLOR_STRING
The default border color string. Value: 4,136,21 (dark green)

See Also:
Constant Field Values

DEFAULT_GUI_SCALING_FACTOR

public static final double DEFAULT_GUI_SCALING_FACTOR
This is the default scaling factor

See Also:
Constant Field Values

DEFAULT_INITIAL_X_TRANSLATION

public static final int DEFAULT_INITIAL_X_TRANSLATION
The default value for the intial translation of the map in the x-axis

See Also:
Constant Field Values

DEFAULT_INITIAL_Y_TRANSLATION

public static final int DEFAULT_INITIAL_Y_TRANSLATION
The default value for the intial translation of the map in the y-axis

See Also:
Constant Field Values

DEFAULT_GAIN_FACTOR

public static final double DEFAULT_GAIN_FACTOR
The default value for the initial gain factor.

See Also:
setGainFactor(double), Constant Field Values

DEFAULT_DRAW_POLYGON_BORDERS

public static final boolean DEFAULT_DRAW_POLYGON_BORDERS
The default value for drawing polygon borders. Value: true

See Also:
toggleDisplayPolygonsNames(), Constant Field Values

DEFAULT_LOGSCALE

public static final boolean DEFAULT_LOGSCALE
The default value for displaying with a logrithmic scale. Value: false

See Also:
toggleLogScaleChoice(), Constant Field Values

DEFAULT_SCALING_FACTOR_ON_ZOOM_RULER

public static final double DEFAULT_SCALING_FACTOR_ON_ZOOM_RULER
The default value for the zoom factor of the displays scale

See Also:
setScalingFactorOnZoomRuler(double), Constant Field Values
Constructor Detail

MapCanvas

public MapCanvas(org.eclipse.swt.widgets.Composite parent,
                 int style)
Constructor.

Parameters:
parent -
style -
Method Detail

setPolygons

public void setPolygons(StemPolygonsList polygonsList)
Sets the polygons list of the MapCanvas.

Parameters:
polygonsList -

getPolygons

public StemPolygonsList getPolygons()
Returns:
the polygons list of the MapCanvas

setPolygonsCentersConnections

public void setPolygonsCentersConnections(StemPolygonsList polygonsCentersConnectionsList)
Sets the polygons that connects the nodes

Parameters:
polygonsCentersConnectionsList -

setBackgroundColorRGB

public void setBackgroundColorRGB(org.eclipse.swt.graphics.RGB bgRGB)
Sets the background color. It gets an RGB and sets both the RGB and the matching SWT colors of the MapCanvas.

Parameters:
bgRGB -

getBackgroundColorRGB

public org.eclipse.swt.graphics.RGB getBackgroundColorRGB()
Returns:
the background color of the MapCanvas (in RGB).

getBackgroundColorSWT

public org.eclipse.swt.graphics.Color getBackgroundColorSWT()
Returns:
the background color of the MapCanvas (in SWT).

getForegroundColorSWT

public org.eclipse.swt.graphics.Color getForegroundColorSWT()
Returns:
the foreground color of the MapCanvas (in SWT).

getBackgroundColorAWT

public java.awt.Color getBackgroundColorAWT()
Gets the background color of the MapCanvas (in AWT). Used by the Java2D.

Returns:
Color

setPolygonsColorRGB

public void setPolygonsColorRGB(org.eclipse.swt.graphics.RGB polyRGB)
Sets the polygons base color of the polygons. It gets an RGB and sets both the RGB and the matching SWT colors of the MapCanvas.

Parameters:
polyRGB -

setBorderColorRGB

public void setBorderColorRGB(org.eclipse.swt.graphics.RGB borderRGB)
Sets the polygons base color of the polygons. It gets an RGB and sets both the RGB and the matching SWT colors of the MapCanvas.

Parameters:
borderRGB -

getPolygonsColorRGB

public org.eclipse.swt.graphics.RGB getPolygonsColorRGB()
Gets the polygons base color of the MapCanvas (in RGB).

Returns:
RGB

getPolygonsColorSWT

public org.eclipse.swt.graphics.Color getPolygonsColorSWT()
Gets the polygons base color of the MapCanvas (in SWT).

Returns:
Color

getBorderColorSWT

public org.eclipse.swt.graphics.Color getBorderColorSWT()
Gets the polygons base color of the MapCanvas (in SWT).

Returns:
Color

getPolygonsColorAWT

public java.awt.Color getPolygonsColorAWT()
Gets the polygons base color of the MapCanvas (in AWT).

Returns:
Color

getPolygonsColorRelativeValueZeroAWT

public java.awt.Color getPolygonsColorRelativeValueZeroAWT()
Gets the polygons base color of the MapCanvas (in AWT) when the relative value is zero.

Returns:
Color

getBorderColorAWT

public java.awt.Color getBorderColorAWT()
Gets the border color (in AWT).

Returns:
Color

getGuiScalingFactorInXaxis

public double getGuiScalingFactorInXaxis()
Returns:
the X axis scaling factor

setGuiScalingFactorInXaxis

public void setGuiScalingFactorInXaxis(double scalingFactorInXaxis)
Set the X axis scaling factor

Parameters:
scalingFactorInXaxis -

getScalingFactorInYaxis

public double getScalingFactorInYaxis()
Returns:
the Y axis scaling factor

setScalingFactorInYaxis

public void setScalingFactorInYaxis(double scalingFactorInYaxis)
Set the Y axis scaling factor

Parameters:
scalingFactorInYaxis -

zoom

public void zoom(double zoomX,
                 double zoomY)
Sets the scaling factor of the map (zoom in/out). The value 1.0 means the default size.

Parameters:
zoomX -
zoomY -

getZoomFactorInXaxis

public double getZoomFactorInXaxis()
Gets the scaling factor of the map (zoom in/out). The value 1.0 means the default size.

Returns:
double

getZoomFactorInYaxis

public double getZoomFactorInYaxis()
Gets the scaling factor of the map (zoom in/out). The value 1.0 means the default size.

Returns:
double

getScalingFactorOnZoomRuler

public double getScalingFactorOnZoomRuler()
Get the scaling factor which was saved in the zoom scale in the view.

Returns:
double

setScalingFactorOnZoomRuler

public void setScalingFactorOnZoomRuler(double val)
Sets the scaling factor (the one that appears on the zoom ruler).

Parameters:
val -

setDrawPolygonBorders

public void setDrawPolygonBorders(boolean drawBordersFlag)
Determins whether the polygons borders will be drawn.

Parameters:
drawBordersFlag -

getDrawPolygonsBorders

public boolean getDrawPolygonsBorders()
Determins whether the polygons borders will be drawn.

Returns:
boolean

setGainFactor

public void setGainFactor(double gainVal)
Sets the gain factor for the displayed colors

Parameters:
gainVal -

getGainFactor

public double getGainFactor()
Gets the gain factor for the displayed colors

Returns:
double

toggleDrawPolygonsBordersChoice

public void toggleDrawPolygonsBordersChoice()
Switch the option of drawing the borders of polygons on the map.


toggleLogScaleChoice

public void toggleLogScaleChoice()
Switch the option of displaying the polygons titles.


toggleDisplayPolygonsNames

public void toggleDisplayPolygonsNames()
Switch the option of displaying the polygons titles.


toggleDrawPolygonsCentersConnections

public void toggleDrawPolygonsCentersConnections()
Switch the option of drawing the edges connecting every two polygons.


draw

public void draw(org.eclipse.swt.graphics.GC gc,
                 int x,
                 int y,
                 int width,
                 int height)
The method which gets the MapCanvas' polygons list, and draws it on the MapCanvas.

Parameters:
gc -
x -
y -
width -
height -

performLogScaling

public float performLogScaling(float v)
Perform a log scale to a specific value

Parameters:
v -
Returns:
float

multiplyByGainFactor

public float multiplyByGainFactor(float val)
Multiplies the relative value which is going to be displayed by the gain factor required by the user. In case the relative value exceeds 1.0 - its value will be 1.0.

Parameters:
val -
Returns:
float

produceIntCoordinates

public void produceIntCoordinates()
Performs the projection on the MapCanvas' polygons list. It does so by calling a similar method on the StemPolygonsList.


setTranslate

public void setTranslate(double valX,
                         double valY)
Sets the offset needed for the coordinates in order to draw the map on the canvas.

Parameters:
valX -
valY -

getTranslateX

public double getTranslateX()
Returns:
the translation factor in X axis

getTranslateY

public double getTranslateY()
Returns:
the translation factor in Y axis

dispose

public void dispose()
Disposes the Color objects

Overrides:
dispose in class org.eclipse.swt.widgets.Widget

getAffineTransform

public java.awt.geom.AffineTransform getAffineTransform()
Returns:
the affine transform

setAffineTransform

public void setAffineTransform(java.awt.geom.AffineTransform affineTransform)
Set the affine transform

Parameters:
affineTransform -

getWhichProjection

public java.lang.String getWhichProjection()
Returns:
the projection

setWhichProjection

public void setWhichProjection(java.lang.String whichProjection)
Parameters:
whichProjection -

getDataScalingFactorInXaxis

public double getDataScalingFactorInXaxis()
Returns:
the X axis data scaling factor

setDataScalingFactorInXaxis

public void setDataScalingFactorInXaxis(double dataScalingFactorInXaxis)
Set the X axis data scaling factor

Parameters:
dataScalingFactorInXaxis -

getDataScalingFactorInYaxis

public double getDataScalingFactorInYaxis()
Returns:
the Y axis data scaling factor

setDataScalingFactorInYaxis

public void setDataScalingFactorInYaxis(double dataScalingFactorInYaxis)
Set the Y axis data scaling factor

Parameters:
dataScalingFactorInYaxis -

getGuiScalingFactorInYaxis

public double getGuiScalingFactorInYaxis()
Returns:
the Y axis Gui scaling factor

setGuiScalingFactorInYaxis

public void setGuiScalingFactorInYaxis(double guiScalingFactorInYaxis)
Set the Y axis Gui scaling factor

Parameters:
guiScalingFactorInYaxis -

getPolygonsColorRelativeValueZeroRGB

public org.eclipse.swt.graphics.RGB getPolygonsColorRelativeValueZeroRGB()
Returns:
the color to use to represent zero values.

setPolygonsColorRelativeValueZeroRGB

public void setPolygonsColorRelativeValueZeroRGB(org.eclipse.swt.graphics.RGB polygonsColorRelativeValueZeroRGB)
Parameters:
polygonsColorRelativeValueZeroRGB -

getPolygonsColorRelativeValueZeroSWT

public org.eclipse.swt.graphics.Color getPolygonsColorRelativeValueZeroSWT()
Returns:
the color to use to represent zero values.

setPolygonsColorRelativeValueZeroSWT

public void setPolygonsColorRelativeValueZeroSWT(org.eclipse.swt.graphics.Color polygonsColorRelativeValueZeroSWT)
Parameters:
polygonsColorRelativeValueZeroSWT -