Package microsim.gui.space
Class LayerIntGridDrawer
- java.lang.Object
-
- microsim.gui.space.LayerIntGridDrawer
-
- All Implemented Interfaces:
ILayerDrawer
,ILayerMouseListener
public class LayerIntGridDrawer extends java.lang.Object implements ILayerDrawer
It is able to draw an IntGrid on a LayeredSurfaceFrame using a ColorMap to render the values contained by the cell with a specific color.
This class builds an image when created and every time is updated it modifies the parts of the images that are changed. It is very fast when images do not change to frequently. In order to let the painter to go faster it is useful to reduce the number of color gradients in the ColorMap.Title: JAS
Description: Java Agent-based Simulation library
Copyright (C) 2002 Michele Sonnessa
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.- Author:
- Michele Sonnessa
-
-
Constructor Summary
Constructors Constructor Description LayerIntGridDrawer(java.lang.String name, int[] matrix, int width, int height, ColorMap colorRange)
Create a double layer drawer using values taken from an array of integers and a given IColorMap.LayerIntGridDrawer(java.lang.String name, int[] matrix, int width, int height, ColorMap colorRange, java.awt.Color trasparentColor)
Create a double layer drawer using values taken from an array of integers and a given IColorMap.LayerIntGridDrawer(java.lang.String name, microsim.space.IntSpace matrix, ColorMap colorRange)
Create a double layer drawer using values taken from an IntGrid matrix and a given IColorMap.LayerIntGridDrawer(java.lang.String name, microsim.space.IntSpace matrix, ColorMap colorRange, java.awt.Color trasparentColor)
Create a double layer drawer using values using values taken from an IntGrid matrix and a given IColorMap.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getDescription()
Return the name of the layer.boolean
isDisplayed()
Return if the layer is currently displayed on the LayeredSurfaceFrame.void
paint(java.awt.Graphics g, int cellLen)
Draw the layer using the given cell length.boolean
performDblClickActionAt(int atX, int atY)
If a mouse listener has been defined the double-click event, it is passed to it, otherwise it is shown a message box with the value contained by the clicked cell.boolean
performMouseMovedFromTo(int fromX, int fromY, int toX, int toY)
If a mouse listener has been defined the mouse dragging event, it is passed to it, otherwise it is returned false.boolean
performRightClickActionAt(int atX, int atY)
If a mouse listener has been defined the right-click event, it is passed to it, otherwise it is returned false.void
setDisplay(boolean display)
Decide if layer has to be painted or not.void
setMouseListener(ILayerMouseListener listener)
Set a manager for mouse events.
-
-
-
Constructor Detail
-
LayerIntGridDrawer
public LayerIntGridDrawer(java.lang.String name, int[] matrix, int width, int height, ColorMap colorRange)
Create a double layer drawer using values taken from an array of integers and a given IColorMap.- Parameters:
name
- The string describing the layer.matrix
- An array of integers of width * height length.width
- The width of the grid.height
- The height of the grid.colorRange
- The IColorMap used to map values to colors.
-
LayerIntGridDrawer
public LayerIntGridDrawer(java.lang.String name, microsim.space.IntSpace matrix, ColorMap colorRange)
Create a double layer drawer using values taken from an IntGrid matrix and a given IColorMap.- Parameters:
name
- The string describing the layer.matrix
- An IntGrid object.colorRange
- The IColorMap used to map values to colors.
-
LayerIntGridDrawer
public LayerIntGridDrawer(java.lang.String name, int[] matrix, int width, int height, ColorMap colorRange, java.awt.Color trasparentColor)
Create a double layer drawer using values taken from an array of integers and a given IColorMap. It allows to define a trasparency color. Every time the drawer has to plot the trasparentColor it stops drawing, so the cell of underneath layer becomes visible.- Parameters:
name
- The string describing the layer.matrix
- An array of integers of width * height length.width
- The width of the grid.height
- The height of the grid.colorRange
- The IColorMap used to map values to colors.trasparentColor
- A color
-
LayerIntGridDrawer
public LayerIntGridDrawer(java.lang.String name, microsim.space.IntSpace matrix, ColorMap colorRange, java.awt.Color trasparentColor)
Create a double layer drawer using values using values taken from an IntGrid matrix and a given IColorMap. It allows to define a trasparency color. Every time the drawer has to plot the trasparentColor it stops drawing, so the cell of underneath layer becomes visible.- Parameters:
name
- The string describing the layer.matrix
- An IntGrid object.colorRange
- The IColorMap used to map values to colors.trasparentColor
- A color
-
-
Method Detail
-
paint
public void paint(java.awt.Graphics g, int cellLen)
Draw the layer using the given cell length.- Specified by:
paint
in interfaceILayerDrawer
- Parameters:
g
- The graphic context passed by container.cellLen
- The length of a cell in pixels.
-
isDisplayed
public boolean isDisplayed()
Return if the layer is currently displayed on the LayeredSurfaceFrame.- Specified by:
isDisplayed
in interfaceILayerDrawer
- Returns:
- True if it is currently painted, false otherwise.
-
setDisplay
public void setDisplay(boolean display)
Decide if layer has to be painted or not.- Specified by:
setDisplay
in interfaceILayerDrawer
- Parameters:
display
- True if you want the layer to be painted, false otherwise.
-
getDescription
public java.lang.String getDescription()
Return the name of the layer.- Specified by:
getDescription
in interfaceILayerDrawer
- Returns:
- The name passed to the constructor.
-
setMouseListener
public void setMouseListener(ILayerMouseListener listener)
Set a manager for mouse events. If not defined, mouse events are managed by the class itself.- Parameters:
listener
- A ILayerMouseListener object.
-
performDblClickActionAt
public boolean performDblClickActionAt(int atX, int atY)
If a mouse listener has been defined the double-click event, it is passed to it, otherwise it is shown a message box with the value contained by the clicked cell.- Specified by:
performDblClickActionAt
in interfaceILayerMouseListener
- Parameters:
atX
- The x coordinate of the clicked cell.atY
- The y coordinate of the clicked cell.- Returns:
- always true if no mouse listener is defined. This value is used by caller to know if the layer wants to manage the event.
-
performRightClickActionAt
public boolean performRightClickActionAt(int atX, int atY)
If a mouse listener has been defined the right-click event, it is passed to it, otherwise it is returned false.- Specified by:
performRightClickActionAt
in interfaceILayerMouseListener
- Parameters:
atX
- The x coordinate of the clicked cell.atY
- The y coordinate of the clicked cell.- Returns:
- always false if no mouse listener is defined. This value is used by caller to know if the layer wants to manage the event.
-
performMouseMovedFromTo
public boolean performMouseMovedFromTo(int fromX, int fromY, int toX, int toY)
If a mouse listener has been defined the mouse dragging event, it is passed to it, otherwise it is returned false.- Specified by:
performMouseMovedFromTo
in interfaceILayerMouseListener
- Parameters:
fromX
- The x coordinate of the starting cell.fromY
- The y coordinate of the starting cell.toX
- The x coordinate of the last dragged cell.toY
- The y coordinate of the last dragged cell.- Returns:
- always false if no mouse listener is defined. This value is used by caller to know if the layer wants to manage the event.
-
-