org.jvnet.substance.watermark
Class SubstanceImageWatermark

java.lang.Object
  extended by org.jvnet.substance.watermark.SubstanceImageWatermark
All Implemented Interfaces:
SubstanceTrait, SubstanceWatermark

public class SubstanceImageWatermark
extends java.lang.Object
implements SubstanceWatermark

Implementation of SubstanceWatermark, drawing specified image as watermark. This class is part of officially supported API.

Author:
Kirill Grouchnikov, Chris Hall, Mark Haag

Field Summary
protected  java.awt.image.BufferedImage origImage
          The original image (as read from the disk / HTTP connection).
protected  java.lang.String origImageLocation
          The original image location.
protected  java.awt.Image watermarkImage
          Watermark image (screen-sized).
 
Constructor Summary
SubstanceImageWatermark(java.io.InputStream inputStream)
          Creates an instance from the specified input stream.
SubstanceImageWatermark(java.lang.String imageLocation)
          Creates an instance with specified image.
 
Method Summary
 void dispose()
          Disposes the memory associated with this watermark.
 void drawWatermarkImage(java.awt.Graphics graphics, java.awt.Component c, int x, int y, int width, int height)
          Draws the watermark on the specified graphics context in the specified region.
 java.lang.String getDisplayName()
          Returns the display name of this trait.
 SubstanceConstants.ImageWatermarkKind getKind()
          Returns the image watermark kind.
 float getOpacity()
          Returns the image watermark opacity.
 java.lang.String getOrigImageLocation()
          Returns the location of the original image.
 void previewWatermark(java.awt.Graphics g, int x, int y, int width, int height)
          Draws the preview of the watermark image.
 void setKind(SubstanceConstants.ImageWatermarkKind kind)
          Sets image watermark kind.
 void setOpacity(float opacity)
          Sets image watermark opacity.
 boolean updateWatermarkImage(SubstanceSkin skin)
          Updates the current watermark image.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

watermarkImage

protected java.awt.Image watermarkImage
Watermark image (screen-sized).


origImage

protected java.awt.image.BufferedImage origImage
The original image (as read from the disk / HTTP connection).


origImageLocation

protected java.lang.String origImageLocation
The original image location.

Constructor Detail

SubstanceImageWatermark

public SubstanceImageWatermark(java.lang.String imageLocation)
Creates an instance with specified image.

Parameters:
imageLocation - Image location. Can point to a local file or HTTP URL (needs to start with http in the later case).

SubstanceImageWatermark

public SubstanceImageWatermark(java.io.InputStream inputStream)
Creates an instance from the specified input stream.

Parameters:
inputStream - Input stream.
Method Detail

drawWatermarkImage

public void drawWatermarkImage(java.awt.Graphics graphics,
                               java.awt.Component c,
                               int x,
                               int y,
                               int width,
                               int height)
Description copied from interface: SubstanceWatermark
Draws the watermark on the specified graphics context in the specified region.

Specified by:
drawWatermarkImage in interface SubstanceWatermark
Parameters:
graphics - Graphics context.
c - Component that is painted.
x - Left X of the region.
y - Top Y of the region.
width - Region width.
height - Region height.

previewWatermark

public void previewWatermark(java.awt.Graphics g,
                             int x,
                             int y,
                             int width,
                             int height)
Description copied from interface: SubstanceWatermark
Draws the preview of the watermark image.

Specified by:
previewWatermark in interface SubstanceWatermark
Parameters:
g - Graphic context.
x - the x coordinate of the watermark to be drawn.
y - The y coordinate of the watermark to be drawn.
width - The width of the watermark to be drawn.
height - The height of the watermark to be drawn.

updateWatermarkImage

public boolean updateWatermarkImage(SubstanceSkin skin)
Description copied from interface: SubstanceWatermark
Updates the current watermark image.

Specified by:
updateWatermarkImage in interface SubstanceWatermark
Parameters:
skin - Skin for the watermark.
Returns:
true if the watermark has been updated successfully, false otherwise.

getDisplayName

public java.lang.String getDisplayName()
Description copied from interface: SubstanceTrait
Returns the display name of this trait. This method is part of officially supported API.

Specified by:
getDisplayName in interface SubstanceTrait
Returns:
The display name of this trait.

dispose

public void dispose()
Description copied from interface: SubstanceWatermark
Disposes the memory associated with this watermark.

Specified by:
dispose in interface SubstanceWatermark

getOrigImageLocation

public java.lang.String getOrigImageLocation()
Returns the location of the original image.

Returns:
The location of the original image.

setKind

public void setKind(SubstanceConstants.ImageWatermarkKind kind)
Sets image watermark kind.

Parameters:
kind - Image watermark kind.

getKind

public SubstanceConstants.ImageWatermarkKind getKind()
Returns the image watermark kind.

Returns:
Image watermark kind.

getOpacity

public float getOpacity()
Returns the image watermark opacity.

Returns:
Image watermark opacity.

setOpacity

public void setOpacity(float opacity)
Sets image watermark opacity.

Parameters:
opacity - Image watermark opacity.
Throws:
java.lang.IllegalArgumentException - if the argument is not in 0.0-1.0 range.