org.openjump.core.rasterimage
Class RasterImageLayer

java.lang.Object
  extended by com.vividsolutions.jump.workbench.model.AbstractLayerable
      extended by org.openjump.core.rasterimage.RasterImageLayer
All Implemented Interfaces:
Layerable, ObjectContainingMetaInformation

public class RasterImageLayer
extends AbstractLayerable
implements ObjectContainingMetaInformation

Layer representing a georeferenced raster image (e.g. an areal photography) in OpenJump.

Version:
$Rev: 2509 $ modified: [sstein]: 16.Feb.2009 changed logger-entries to comments, used frame.warnUser
Author:
Ole Rahn

FH Osnabrück - University of Applied Sciences Osnabrück,
Project: PIROL (2006),
Subproject: Daten- und Wissensmanagement

Field Summary
protected  java.awt.Rectangle alterBildAusschnitt
           
protected static long availRAM
           
protected  java.awt.Rectangle bildAusschnitt
           
protected static Blackboard blackboard
           
protected static java.lang.String BLACKBOARD_KEY_PLUGINCONTEXT
           
protected static java.lang.String BLACKBOARD_KEY_WORKBENCHCONTEXT
           
protected  com.vividsolutions.jts.geom.Envelope envelope
           
protected  boolean firingAppearanceEvents
          Flag to decide, if events are fired automatically, if the appearance (envelope, etc.) changes.
protected static double freeRamFactor
           
protected  javax.media.jai.PlanarImage image
           
protected  java.lang.String imageFileName
           
protected  javax.media.jai.PlanarImage imageProcessingStep1
           
protected  javax.media.jai.PlanarImage imageProcessingStep2
           
protected  boolean imageSet
           
protected  int lastImgProcessingMode
           
protected static int maxPixelsForFastDisplayMode
           
protected  MetaDataMap metaInformation
           
protected static double minRamToKeepFree
           
protected static int MODE_CLIPPINGFIRST
           
protected static int MODE_FASTDISPLAY
           
protected static int MODE_NONE
           
protected static int MODE_SCALINGFIRST
           
protected  boolean needToKeepImage
          Flag to control if the image should be deleted from RAM as soon as possible to save RAM or if it should be keeped e.g. because it was generated dynamically and can not be loaded from a file again, once it was deleted.
protected static java.awt.Point nullpunkt
           
protected  double oldScaleXImg2Canvas
           
protected  int origImageHeight
           
protected  int origImageWidth
           
protected  double scaleXImg2Canvas
           
protected  double scaleYImg2Canvas
           
protected  boolean transparencyColorNeedsToBeApplied
           
protected  double transparencyLevel
           
protected  java.awt.Color transparentColor
           
protected  com.vividsolutions.jts.geom.Envelope visibleEnv
           
protected  java.awt.Rectangle visibleRect
           
protected  int xOffset
           
protected  int yOffset
           
 
Constructor Summary
RasterImageLayer()
          for java2xml
RasterImageLayer(java.lang.String name, LayerManager layerManager, java.awt.image.RenderedImage image, com.vividsolutions.jts.geom.Envelope envelope)
          Constructor to be used in case the image was not loaded from a file, so there is no file name, but an image
RasterImageLayer(java.lang.String name, LayerManager layerManager, java.lang.String imageFileName, java.awt.image.RenderedImage image, com.vividsolutions.jts.geom.Envelope envelope)
           
 
Method Summary
 boolean clearImage(boolean garbageCollect)
          deletes image from RAM (if it is not to be keeped and if the RAM consumption is high) and calls the garbage collector, if the garbageCollect is true.
 java.lang.Object clone()
           
 java.awt.image.BufferedImage createImage(LayerViewPanel layerViewPanel)
          Creates the image to draw
protected  javax.media.jai.PlanarImage createOneColorImage()
           
protected  void finalize()
           
 void flushImages(boolean garbageCollect)
          flushes all images from the RAM.
protected  void forceTotalRepaint()
          After this method was invoked, the image will be completely re-rendered (not using caches) the next time.
static long getAvailRAM()
           
 Blackboard getBlackboard()
           
 java.awt.Rectangle getDrawingRectangle(double imgWidth, double imgHeight, com.vividsolutions.jts.geom.Envelope imageEnv, Viewport viewport)
           
 com.vividsolutions.jts.geom.Envelope getEnvelope()
           
 com.vividsolutions.jts.geom.Polygon getEnvelopeAsGeometry()
          Method to change the coordinates of the image and later apply the changes to the RasterImageLayer by using setGeometryAsEnvelope(Geometry).
static double getFreeRamFactor()
           
 javax.media.jai.PlanarImage getImage()
          returns the image
static java.awt.Point getImageDimensions(WorkbenchContext context, java.lang.String filenameOrURL)
          Returns the dimensions (width and height in px) of the image as a Point object.
 java.lang.String getImageFileName()
           
static int getMaxPixelsForFastDisplayMode()
           
 MetaDataMap getMetaInformation()
           
static double getMinRamToKeepFree()
           
 int getOrigImageHeight()
           
 int getOrigImageWidth()
           
protected  javax.media.jai.PlanarImage getScaledImageMatchingVisible(javax.media.jai.PlanarImage toBeScaled, double XscaleImg2Canvas, double YscaleImg2Canvas)
           
 java.awt.image.BufferedImage getTileAsImage(com.vividsolutions.jts.geom.Envelope wantedEnvelope)
           
 double getTransparencyLevel()
          Returns the transparency level of the image.
 java.awt.Color getTransparentColor()
          Gets the color which will be drawn with a zero opacity in the Jump map
 java.lang.String getTransparentColorAsString()
          for java2xml
protected  java.awt.Rectangle getVisibleImageCoordinatesOfImage(double imgWidth, double imgHeight, com.vividsolutions.jts.geom.Envelope visible, com.vividsolutions.jts.geom.Envelope imageEnv)
           
protected  java.awt.Rectangle getVisibleImageCoordinatesOfImage(javax.media.jai.PlanarImage img, com.vividsolutions.jts.geom.Envelope visible, com.vividsolutions.jts.geom.Envelope imageEnv)
           
protected  javax.media.jai.PlanarImage getVisiblePartOfTheImage(javax.media.jai.PlanarImage img, java.awt.Rectangle desiredImageArea)
           
protected  WorkbenchContext getWorkbenchContext()
           
 java.lang.String getXmlEnvelope()
          for java2xml
 int getXOffset()
           
 int getYOffset()
           
 boolean isFiringAppearanceEvents()
           
 boolean isImageNull()
           
 boolean isImageSet()
           
 boolean isNeedToKeepImage()
          check, if image will be keeped in RAM or if it will be reloaded from a file if needed
static javax.media.jai.PlanarImage loadImage(WorkbenchContext context, java.lang.String filenameOrURL)
           
static java.awt.image.BufferedImage makeBufferedImage(java.awt.Image im)
          creates a BufferedImage out of an Image
 void reLoadImage()
           
protected  javax.media.jai.PlanarImage scaleImage(javax.media.jai.PlanarImage im, float xScale, float yScale)
          apply a scale operation to the image and return the new image.
 void setEnvelope(com.vividsolutions.jts.geom.Envelope envelope)
          Sets the Envelope object containing the real world coordinates (e.g.
 void setFiringAppearanceEvents(boolean firingAppearanceEvents)
           
static void setFreeRamFactor(double freeRamFactor)
           
 void setGeometryAsEnvelope(com.vividsolutions.jts.geom.Geometry geometry)
          Method to set the coordinates of the image, e.g. after changing them after using getEnvelopeAsGeometry().
 void setImage(javax.media.jai.PlanarImage image)
          Sets the image that will be shown in the map (also sets some interally used flags)
 void setImageFileName(java.lang.String imageFileName)
          Sets the image's files name (if image is not to be keeped) - this needs to be set!
 void setImageSet(boolean imageSet)
           
 void setMetaInformation(MetaDataMap metaInformation)
           
 void setNeedToKeepImage(boolean needToKeepImage)
          toogle, if image will be keeped in RAM or if it will be reloaded from a file if needed
 void setOrigImageHeight(int origImageHeight)
          for java2xml
 void setOrigImageWidth(int origImageWidth)
          for java2xml
 void setTransparencyLevel(double transparencyLevel)
          Sets the transparency level of the image.
 void setTransparencyLevelInPercent(int transparencyInPercent)
          Sets the transparency level of the image.
 void setTransparentColor(java.awt.Color transparentColor)
          Sets the color which will be drawn with a zero opacity in the Jump map
 void setTransparentColorAsString(java.lang.String hexColorString)
          for java2xml
 void setVisible(boolean visible)
          shows or hides the image in the Jump map
static void setWorkbenchContext(WorkbenchContext wContext)
           
 void setXmlEnvelope(java.lang.String envStr)
          for java2xml
 
Methods inherited from class com.vividsolutions.jump.workbench.model.AbstractLayerable
fireAppearanceChanged, fireLayerChanged, getLayerManager, getMaxScale, getMinScale, getName, getTask, isScaleDependentRenderingEnabled, isVisible, setLayerManager, setMaxScale, setMinScale, setName, setScaleDependentRenderingEnabled, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

blackboard

protected static Blackboard blackboard

BLACKBOARD_KEY_PLUGINCONTEXT

protected static final java.lang.String BLACKBOARD_KEY_PLUGINCONTEXT

BLACKBOARD_KEY_WORKBENCHCONTEXT

protected static final java.lang.String BLACKBOARD_KEY_WORKBENCHCONTEXT

lastImgProcessingMode

protected int lastImgProcessingMode

MODE_NONE

protected static final int MODE_NONE
See Also:
Constant Field Values

MODE_SCALINGFIRST

protected static final int MODE_SCALINGFIRST
See Also:
Constant Field Values

MODE_CLIPPINGFIRST

protected static final int MODE_CLIPPINGFIRST
See Also:
Constant Field Values

MODE_FASTDISPLAY

protected static final int MODE_FASTDISPLAY
See Also:
Constant Field Values

bildAusschnitt

protected java.awt.Rectangle bildAusschnitt

alterBildAusschnitt

protected java.awt.Rectangle alterBildAusschnitt

visibleRect

protected java.awt.Rectangle visibleRect

scaleXImg2Canvas

protected double scaleXImg2Canvas

oldScaleXImg2Canvas

protected double oldScaleXImg2Canvas

scaleYImg2Canvas

protected double scaleYImg2Canvas

xOffset

protected int xOffset

yOffset

protected int yOffset

transparencyLevel

protected double transparencyLevel

availRAM

protected static long availRAM

freeRamFactor

protected static double freeRamFactor

minRamToKeepFree

protected static double minRamToKeepFree

maxPixelsForFastDisplayMode

protected static int maxPixelsForFastDisplayMode

imageFileName

protected java.lang.String imageFileName

origImageWidth

protected int origImageWidth

origImageHeight

protected int origImageHeight

imageSet

protected boolean imageSet

image

protected javax.media.jai.PlanarImage image

imageProcessingStep1

protected javax.media.jai.PlanarImage imageProcessingStep1

imageProcessingStep2

protected javax.media.jai.PlanarImage imageProcessingStep2

envelope

protected com.vividsolutions.jts.geom.Envelope envelope

visibleEnv

protected com.vividsolutions.jts.geom.Envelope visibleEnv

firingAppearanceEvents

protected boolean firingAppearanceEvents
Flag to decide, if events are fired automatically, if the appearance (envelope, etc.) changes.
default: true


needToKeepImage

protected boolean needToKeepImage
Flag to control if the image should be deleted from RAM as soon as possible to save RAM or if it should be keeped e.g. because it was generated dynamically and can not be loaded from a file again, once it was deleted.


nullpunkt

protected static final java.awt.Point nullpunkt

transparentColor

protected java.awt.Color transparentColor

transparencyColorNeedsToBeApplied

protected boolean transparencyColorNeedsToBeApplied

metaInformation

protected MetaDataMap metaInformation
Constructor Detail

RasterImageLayer

public RasterImageLayer()
for java2xml


RasterImageLayer

public RasterImageLayer(java.lang.String name,
                        LayerManager layerManager,
                        java.lang.String imageFileName,
                        java.awt.image.RenderedImage image,
                        com.vividsolutions.jts.geom.Envelope envelope)
Parameters:
name - name of the layer
layerManager -
image - the image (if already loaded) or null
envelope - real-world coordinates of the image

RasterImageLayer

public RasterImageLayer(java.lang.String name,
                        LayerManager layerManager,
                        java.awt.image.RenderedImage image,
                        com.vividsolutions.jts.geom.Envelope envelope)
Constructor to be used in case the image was not loaded from a file, so there is no file name, but an image

Parameters:
name - name of the layer
layerManager -
image - the image
envelope - real-world coordinates of the image
Method Detail

getBlackboard

public Blackboard getBlackboard()
Specified by:
getBlackboard in interface Layerable

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

scaleImage

protected javax.media.jai.PlanarImage scaleImage(javax.media.jai.PlanarImage im,
                                                 float xScale,
                                                 float yScale)
apply a scale operation to the image and return the new image.


createOneColorImage

protected javax.media.jai.PlanarImage createOneColorImage()

createImage

public java.awt.image.BufferedImage createImage(LayerViewPanel layerViewPanel)
Creates the image to draw


clearImage

public boolean clearImage(boolean garbageCollect)
deletes image from RAM (if it is not to be keeped and if the RAM consumption is high) and calls the garbage collector, if the garbageCollect is true.

Parameters:
garbageCollect - if true the garbage collector will be called (this parameter may be overridden, if there is not enough RAM available...)

flushImages

public void flushImages(boolean garbageCollect)
flushes all images from the RAM.

Parameters:
garbageCollect - if true the garbage collector will be called (this parameter may be overridden, if there is not enough RAM available...)

reLoadImage

public void reLoadImage()

getImageDimensions

public static java.awt.Point getImageDimensions(WorkbenchContext context,
                                                java.lang.String filenameOrURL)
Returns the dimensions (width and height in px) of the image as a Point object. The clue is that only the image file's header is read to get this information, so it's quite fast, because the image was not entirely read.

Parameters:
context - the WorkbenchContext
filenameOrURL - the image file's name or URL
Returns:
a point which's x is the image's width and y is the height

loadImage

public static final javax.media.jai.PlanarImage loadImage(WorkbenchContext context,
                                                          java.lang.String filenameOrURL)

getEnvelope

public com.vividsolutions.jts.geom.Envelope getEnvelope()
Returns:
Envelope with the real world coordinates of the image

setEnvelope

public void setEnvelope(com.vividsolutions.jts.geom.Envelope envelope)
Sets the Envelope object containing the real world coordinates (e.g. WGS84) of the image - this needs to be set (if it wasn't given to the constructor)!

Parameters:
envelope - the Envelope

getXmlEnvelope

public java.lang.String getXmlEnvelope()
for java2xml

Returns:
the Envelope as string

setXmlEnvelope

public void setXmlEnvelope(java.lang.String envStr)
for java2xml

Parameters:
envStr - the Envelope as string

getEnvelopeAsGeometry

public com.vividsolutions.jts.geom.Polygon getEnvelopeAsGeometry()
Method to change the coordinates of the image and later apply the changes to the RasterImageLayer by using setGeometryAsEnvelope(Geometry).

Returns:
return the envelope (= bounding box) as a geometry,

setGeometryAsEnvelope

public void setGeometryAsEnvelope(com.vividsolutions.jts.geom.Geometry geometry)
Method to set the coordinates of the image, e.g. after changing them after using getEnvelopeAsGeometry().


makeBufferedImage

public static final java.awt.image.BufferedImage makeBufferedImage(java.awt.Image im)
creates a BufferedImage out of an Image

Parameters:
im - the Image
Returns:
the BufferedImage

getScaledImageMatchingVisible

protected javax.media.jai.PlanarImage getScaledImageMatchingVisible(javax.media.jai.PlanarImage toBeScaled,
                                                                    double XscaleImg2Canvas,
                                                                    double YscaleImg2Canvas)

getTileAsImage

public java.awt.image.BufferedImage getTileAsImage(com.vividsolutions.jts.geom.Envelope wantedEnvelope)

getWorkbenchContext

protected WorkbenchContext getWorkbenchContext()

setWorkbenchContext

public static void setWorkbenchContext(WorkbenchContext wContext)

getDrawingRectangle

public java.awt.Rectangle getDrawingRectangle(double imgWidth,
                                              double imgHeight,
                                              com.vividsolutions.jts.geom.Envelope imageEnv,
                                              Viewport viewport)
                                       throws java.awt.geom.NoninvertibleTransformException
Throws:
java.awt.geom.NoninvertibleTransformException

getVisibleImageCoordinatesOfImage

protected java.awt.Rectangle getVisibleImageCoordinatesOfImage(double imgWidth,
                                                               double imgHeight,
                                                               com.vividsolutions.jts.geom.Envelope visible,
                                                               com.vividsolutions.jts.geom.Envelope imageEnv)

getVisibleImageCoordinatesOfImage

protected java.awt.Rectangle getVisibleImageCoordinatesOfImage(javax.media.jai.PlanarImage img,
                                                               com.vividsolutions.jts.geom.Envelope visible,
                                                               com.vividsolutions.jts.geom.Envelope imageEnv)

getVisiblePartOfTheImage

protected javax.media.jai.PlanarImage getVisiblePartOfTheImage(javax.media.jai.PlanarImage img,
                                                               java.awt.Rectangle desiredImageArea)

setImage

public void setImage(javax.media.jai.PlanarImage image)
Sets the image that will be shown in the map (also sets some interally used flags)

Parameters:
image - image that will be shown in the map

setImageSet

public void setImageSet(boolean imageSet)

isImageNull

public boolean isImageNull()

getImage

public javax.media.jai.PlanarImage getImage()
returns the image

Returns:
the image

isImageSet

public boolean isImageSet()
Returns:
true, if the image object was set at least once, else false

getTransparencyLevel

public double getTransparencyLevel()
Returns the transparency level of the image. The transparencyLevel controlls the transparency level of the whole image (all pixels). It is independent of the transparency color, that replaces a certain color in the image. The transparencyLevel is expressed as a float within a range from 0.0 (no transparency) to 1.0 (full transparency).

Returns:
the transparency level of the image

setTransparencyLevel

public void setTransparencyLevel(double transparencyLevel)
Sets the transparency level of the image. This controlls the transparency level of the whole image (all pixels). It is independent of the transparency color, that replaces a certain color in the image. The transparencyLevel is expressed as a float within a range from 0.0 (no transparency) to 1.0 (full transparency).

Parameters:
transparencyLevel - the transparency level of the image

setTransparencyLevelInPercent

public void setTransparencyLevelInPercent(int transparencyInPercent)
Sets the transparency level of the image. This controlls the transparency level of the whole image (all pixels). It is independent of the transparency color, that replaces a certain color in the image. The transparencyLevel is expressed as a percentage within a range from 0 (no transparency) to 100 (full transparency).

Parameters:
transparencyInPercent - the transparency level of the image

getTransparentColor

public java.awt.Color getTransparentColor()
Gets the color which will be drawn with a zero opacity in the Jump map

Returns:
color that will be replaced with transparent pixels

getTransparentColorAsString

public java.lang.String getTransparentColorAsString()
for java2xml


setTransparentColorAsString

public void setTransparentColorAsString(java.lang.String hexColorString)
for java2xml


setTransparentColor

public void setTransparentColor(java.awt.Color transparentColor)
Sets the color which will be drawn with a zero opacity in the Jump map

Parameters:
transparentColor - the color for transparency

forceTotalRepaint

protected void forceTotalRepaint()
After this method was invoked, the image will be completely re-rendered (not using caches) the next time.


getXOffset

public int getXOffset()
Returns:
the current offset (to the viewport's (0,0)) in x direction

getYOffset

public int getYOffset()
Returns:
the current offset (to the viewport's (0,0)) in y direction

getFreeRamFactor

public static double getFreeRamFactor()

setFreeRamFactor

public static void setFreeRamFactor(double freeRamFactor)

getAvailRAM

public static long getAvailRAM()

getMaxPixelsForFastDisplayMode

public static int getMaxPixelsForFastDisplayMode()

getMinRamToKeepFree

public static double getMinRamToKeepFree()

setImageFileName

public void setImageFileName(java.lang.String imageFileName)
Sets the image's files name (if image is not to be keeped) - this needs to be set!

Parameters:
imageFileName - the file name of the image

getImageFileName

public java.lang.String getImageFileName()
Returns:
the file name of the image represented by this instance of the RasterImageLayer

isNeedToKeepImage

public boolean isNeedToKeepImage()
check, if image will be keeped in RAM or if it will be reloaded from a file if needed

Returns:
true if image will be keeped in RAM, else false

setNeedToKeepImage

public void setNeedToKeepImage(boolean needToKeepImage)
toogle, if image will be keeped in RAM or if it will be reloaded from a file if needed

Parameters:
needToKeepImage - true if image is supposed be keeped in RAM, else false

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

getOrigImageHeight

public int getOrigImageHeight()
Returns:
the height of the source image

getOrigImageWidth

public int getOrigImageWidth()
Returns:
the width of the source image

setOrigImageHeight

public void setOrigImageHeight(int origImageHeight)
for java2xml

Parameters:
origImageHeight -

setOrigImageWidth

public void setOrigImageWidth(int origImageWidth)
for java2xml

Parameters:
origImageWidth -

setVisible

public void setVisible(boolean visible)
shows or hides the image in the Jump map

Specified by:
setVisible in interface Layerable
Overrides:
setVisible in class AbstractLayerable
Parameters:
visible -

isFiringAppearanceEvents

public boolean isFiringAppearanceEvents()
Returns:
true if appearance events are fired automatically, false if not
See Also:
firingAppearanceEvents

setFiringAppearanceEvents

public void setFiringAppearanceEvents(boolean firingAppearanceEvents)
Parameters:
firingAppearanceEvents - true if appearance events are to be fired automatically, false if not
See Also:
firingAppearanceEvents

getMetaInformation

public MetaDataMap getMetaInformation()
Specified by:
getMetaInformation in interface ObjectContainingMetaInformation

setMetaInformation

public void setMetaInformation(MetaDataMap metaInformation)
Specified by:
setMetaInformation in interface ObjectContainingMetaInformation