org.placelab.util.swt
Class GlyphImage

java.lang.Object
  extended byorg.placelab.util.swt.Glyph
      extended byorg.placelab.util.swt.GlyphImage
Direct Known Subclasses:
MapIcon

public class GlyphImage
extends Glyph


Field Summary
protected  org.eclipse.swt.graphics.ImageData data
           
protected  boolean doCaching
           
protected  org.eclipse.swt.graphics.Image image
           
protected  org.eclipse.swt.graphics.Image originalImage
           
protected  java.util.Hashtable zoomCache
           
 
Fields inherited from class org.placelab.util.swt.Glyph
ANCHOR_C, ANCHOR_E, ANCHOR_N, ANCHOR_NE, ANCHOR_NW, ANCHOR_S, ANCHOR_SE, ANCHOR_SW, ANCHOR_W, DISPOSED, IGNORE_TRANSPARENCY, MOUSE_EVENTS, needsTransformRedraw, NONE, transform, transformedImage, transparency, VISIBLE, zoom
 
Constructor Summary
GlyphImage(GlyphComposite parent, int style)
           
GlyphImage(GlyphHolder holder, int style)
           
 
Method Summary
 void clearZoomHistory()
           
 void dispose()
           
protected  org.eclipse.swt.graphics.Rectangle getBoundsImpl()
           
 boolean getCachesZoomHistory()
           
 org.eclipse.swt.graphics.Image getImage()
           
 double getZoom()
           
protected  org.eclipse.swt.graphics.Image getZoomedImage()
           
protected  void paintImpl(org.eclipse.swt.events.PaintEvent e, GlyphGC gc)
          Implement this if you don't want to worry about AffineTransforms.
protected  boolean pointInsideImpl(int x, int y)
          Return if the point is inside your glyph without the AffineTransform applied
 void setCachesZoomHistory(boolean flag)
          When a zoom is requested, the GlyphImage first checks to see if it has a cached version of the image at that size (or one within one one hundredth of a factor) and it returns that.
 void setImage(org.eclipse.swt.graphics.Image image, int x, int y)
           
 void setImage(org.eclipse.swt.graphics.Image image, int x, int y, int anchor)
           
 void setImage(org.eclipse.swt.graphics.Image image, org.eclipse.swt.graphics.Point location)
           
 void setImage(org.eclipse.swt.graphics.Image image, org.eclipse.swt.graphics.Point location, int anchor)
           
 void setZoom(double z)
           
 
Methods inherited from class org.placelab.util.swt.Glyph
addListener, addMouseListener, addPaintListener, areMouseEventsEnabled, enableMouseEvents, enter, getBounds, getCloseEnough, getFlag, getHolder, getLocation, getMaskColor, getNeedsTransformRedraw, getOriginalLocation, getParent, getTransform, getTransparency, handleMouseEvent, isDisposed, isVisible, leave, moveAbove, moveBelow, notifyListeners, paint, pickGlyphAt, pointInside, pointInside, redraw, removeListener, resetFlag, setCloseEnough, setCursor, setFlag, setLocation, setNeedsTransformRedraw, setTransform, setTransparency, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

originalImage

protected org.eclipse.swt.graphics.Image originalImage

image

protected org.eclipse.swt.graphics.Image image

data

protected org.eclipse.swt.graphics.ImageData data

zoomCache

protected java.util.Hashtable zoomCache

doCaching

protected boolean doCaching
Constructor Detail

GlyphImage

public GlyphImage(GlyphComposite parent,
                  int style)

GlyphImage

public GlyphImage(GlyphHolder holder,
                  int style)
Method Detail

setImage

public void setImage(org.eclipse.swt.graphics.Image image,
                     org.eclipse.swt.graphics.Point location)

setImage

public void setImage(org.eclipse.swt.graphics.Image image,
                     int x,
                     int y)

setImage

public void setImage(org.eclipse.swt.graphics.Image image,
                     org.eclipse.swt.graphics.Point location,
                     int anchor)

setImage

public void setImage(org.eclipse.swt.graphics.Image image,
                     int x,
                     int y,
                     int anchor)

getCachesZoomHistory

public boolean getCachesZoomHistory()

setCachesZoomHistory

public void setCachesZoomHistory(boolean flag)
When a zoom is requested, the GlyphImage first checks to see if it has a cached version of the image at that size (or one within one one hundredth of a factor) and it returns that. If not, it will compute the scaled version and cache that for future requests, supposing it caches the zoom history. It turns out that the image scaling takes more than 90% of the time in a zoom operation (the rest goes to redraws and point translation I presume) so this can speed things up significantly. The downside of caching the zoom history is that it requires that the various sizes of the image sit around in memory. You'll want to only alternate between a few different zoom factors so as not to have hundreds of images sitting around taking up space. Setting the zoom history flag to false will ensure that no more scaled images are cached, but it doesn't clear the existing zoom cache

Parameters:
flag - whether or not to cache scaled versions of the image

clearZoomHistory

public void clearZoomHistory()

getImage

public org.eclipse.swt.graphics.Image getImage()

setZoom

public void setZoom(double z)
Overrides:
setZoom in class Glyph

getZoom

public double getZoom()
Overrides:
getZoom in class Glyph

dispose

public void dispose()
Overrides:
dispose in class Glyph

getZoomedImage

protected org.eclipse.swt.graphics.Image getZoomedImage()

paintImpl

protected void paintImpl(org.eclipse.swt.events.PaintEvent e,
                         GlyphGC gc)
Description copied from class: Glyph
Implement this if you don't want to worry about AffineTransforms. Your graphics will be rasterized and have an AffineTransform applied to them

Overrides:
paintImpl in class Glyph

getBoundsImpl

protected org.eclipse.swt.graphics.Rectangle getBoundsImpl()
Specified by:
getBoundsImpl in class Glyph
Returns:
your bounds without having the AffineTransform applied to them

pointInsideImpl

protected boolean pointInsideImpl(int x,
                                  int y)
Description copied from class: Glyph
Return if the point is inside your glyph without the AffineTransform applied

Specified by:
pointInsideImpl in class Glyph