com.lizardtech.djvubean
Class DjVuImage

java.lang.Object
  extended by com.lizardtech.djvubean.DjVuImage

public class DjVuImage
extends java.lang.Object

This class is used to represent a DjVuPage object as a Vector of buffered images, for displaying in a viewport.


Field Summary
static java.awt.Color BLACK
          A constant indicating the color blue.
static java.awt.Color BLUE
          A constant indicating the color blue.
static boolean BROKEN_XOR
           
static java.lang.reflect.Constructor colorConstructor
          Test to determine java version.
static int FIT_PAGE
          Magic scale value used to zoom to fit page.
static int FIT_WIDTH
          Magic scale value used to zoom to fit width.
static java.awt.Color WHITE
          A constant indicating the color white.
static int XOR_HILITE
          Special value for XOR HIGHLIGHTING
 
Constructor Summary
DjVuImage(DjVuPage[] djvuPages, boolean favorFast)
          Creates a new DjVuImage object.
DjVuImage(DjVuPage[] djvuPages, boolean favorFast, int zoom, java.awt.Dimension size)
          Creates a new DjVuImage object.
DjVuImage(DjVuPage[] djvuPages, boolean favorFast, int width, int height)
          Creates a new DjVuImage object.
 
Method Summary
 java.awt.Rectangle computeScaledBounds(int zoom, java.awt.Dimension size)
          Compute the page size scaled at the appropriate zoom.
static java.awt.Color createColor(int rgb, int alpha)
          Equivalent to new Color(rgb,hasAlpha).
 void draw(java.awt.Component parent, java.awt.Graphics g, java.awt.image.ImageObserver observer)
          Called to create one or more images to draw to.
 void drawHighlight(java.awt.Graphics g, boolean useXOR)
          Called to paint the highlight areas onto the image.
 void fillRect(java.awt.Graphics g, int color, int opacity, int xmin, int ymin, int xmax, int ymax)
          Set the color as specified and then call g.fillRect.
 java.awt.Dimension getBorderNW()
          Query the north and west border width and height respectively.
 java.awt.Dimension getBorderSE()
          Query the south and east border width and height respectively.
 java.awt.Rectangle getBounds()
          Query the scaled size of this image, with an origin at (0,0).
 DjVuInfo getDjVuInfo(int index)
          Query the size and other page information as indicated in the INFO chunk.
 DjVuPage getDjVuPage(int index)
          Query a DjVuPage being rendered.
 DjVuFilter getFilter(java.awt.Component parent, java.awt.Rectangle bounds, int index)
          Get a segmented image filter.
 java.awt.Rectangle getHighlightBounds()
          Query the bounding rectangle of the area to highlight.
 double getHorizontalScale()
          Query the horizontal scale
 java.awt.Image[] getImage(java.awt.Component parent, java.awt.Rectangle bounds)
          Get a segmented Image.
 int getIndexMax()
          Query the size of the DjVuPage array.
 int getMaxDPI()
          Query the maximum DPI of the pages being displayed.
 java.awt.Rectangle getPageBounds(int index)
          Query the bounds for a particular page.
 DjVuImage getScaledInstance(int scale)
          Create a new instance of this class, scaled to the specified size.
 DjVuImage getScaledInstance(int width, int height)
          Create a new instance of this class, scaled to the specified size.
 java.awt.Dimension getSize()
          Query the scaled size of the DjVuPage.
 Codec getTextCodec(int index, long maxWait)
          Query the DjVuText codec for this page.
 double getVerticalScale()
          Query the vertical scale
 boolean isDecoding()
          Query if decoding is still in progress.
static boolean isDoneDecodingEvent(DjVuImage image, java.beans.PropertyChangeListener listener, java.beans.PropertyChangeEvent event)
          Check if this is a done decoding event.
 boolean isDoneDecodingEvent(java.beans.PropertyChangeListener listener, java.beans.PropertyChangeEvent event)
          Check if this is a done decoding event.
 void setBorder(java.awt.Dimension parentSize, java.awt.Rectangle imageBounds)
          Computes the size of the border.
 void setBufferBounds(java.awt.Component parent, java.awt.Rectangle bounds)
          Sets the bounds for buffering.
 void setBufferBounds(java.awt.Rectangle bounds)
          Sets the bounds for buffering.
 void setHighlightList(int index, java.util.Vector list)
          Take the list of highlighting rectangles and transform it to a list of non-overlapping rectangles covering the same regions.
 void transformRectangle(int index, GRect rect, java.awt.Rectangle scaled)
          Transform the specified coordinates.
 void transformRectangle(int index, java.awt.Rectangle rect, java.awt.Rectangle scaled)
          Transform the specified coordinates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BROKEN_XOR

public static boolean BROKEN_XOR

WHITE

public static java.awt.Color WHITE
A constant indicating the color white.


BLUE

public static java.awt.Color BLUE
A constant indicating the color blue.


BLACK

public static java.awt.Color BLACK
A constant indicating the color blue.


FIT_WIDTH

public static final int FIT_WIDTH
Magic scale value used to zoom to fit width.

See Also:
Constant Field Values

FIT_PAGE

public static final int FIT_PAGE
Magic scale value used to zoom to fit page.

See Also:
Constant Field Values

colorConstructor

public static final java.lang.reflect.Constructor colorConstructor
Test to determine java version.


XOR_HILITE

public static final int XOR_HILITE
Special value for XOR HIGHLIGHTING

See Also:
Constant Field Values
Constructor Detail

DjVuImage

public DjVuImage(DjVuPage[] djvuPages,
                 boolean favorFast)
Creates a new DjVuImage object.

Parameters:
djvuPages - the array of pages to draw at full resolution.
favorFast - true if fast magnifications should be favored.

DjVuImage

public DjVuImage(DjVuPage[] djvuPages,
                 boolean favorFast,
                 int zoom,
                 java.awt.Dimension size)
Creates a new DjVuImage object.

Parameters:
djvuPages - the array of pages to draw at full resolution.
favorFast - true if fast magnifications should be favored.
zoom - factor to scale by as a percentage
size - holder for returning the viewing size

DjVuImage

public DjVuImage(DjVuPage[] djvuPages,
                 boolean favorFast,
                 int width,
                 int height)
Creates a new DjVuImage object.

Parameters:
djvuPages - the array of pages to draw at full resolution.
favorFast - true if fast magnifications should be favored.
width - The width to scale the page to.
height - The height to scale the page to.
Method Detail

createColor

public static java.awt.Color createColor(int rgb,
                                         int alpha)
Equivalent to new Color(rgb,hasAlpha).

Parameters:
rgb - color as an integer
alpha - true if there is an alpha channel
Returns:
the scaled size

getVerticalScale

public double getVerticalScale()
Query the vertical scale


getHorizontalScale

public double getHorizontalScale()
Query the horizontal scale


getMaxDPI

public int getMaxDPI()
Query the maximum DPI of the pages being displayed.


computeScaledBounds

public java.awt.Rectangle computeScaledBounds(int zoom,
                                              java.awt.Dimension size)
Compute the page size scaled at the appropriate zoom.

Parameters:
zoom - scale factor
size - target window size
Returns:
the scaled size

getBorderNW

public java.awt.Dimension getBorderNW()
Query the north and west border width and height respectively.

Returns:
The NW corner border.

getBorderSE

public java.awt.Dimension getBorderSE()
Query the south and east border width and height respectively.

Returns:
The SE corner border.

getPageBounds

public java.awt.Rectangle getPageBounds(int index)
Query the bounds for a particular page.

Parameters:
index - page to query
Returns:
bounding rectangle

isDecoding

public boolean isDecoding()
Query if decoding is still in progress.

Returns:
True if still decoding.

getDjVuPage

public DjVuPage getDjVuPage(int index)
Query a DjVuPage being rendered.

Parameters:
index - page to query
Returns:
The DjVuPages being rendered.

isDoneDecodingEvent

public boolean isDoneDecodingEvent(java.beans.PropertyChangeListener listener,
                                   java.beans.PropertyChangeEvent event)
Check if this is a done decoding event. If done or the event is not for this page remove the listener.

Parameters:
listener - the listener to check
event - the event to check
Returns:
true if a done decoding event

isDoneDecodingEvent

public static boolean isDoneDecodingEvent(DjVuImage image,
                                          java.beans.PropertyChangeListener listener,
                                          java.beans.PropertyChangeEvent event)
Check if this is a done decoding event. If done or the event is not for this page remove the listener.

Parameters:
image - the image to check
listener - the listener to check
event - the event to check
Returns:
true if a done decoding event

setBorder

public void setBorder(java.awt.Dimension parentSize,
                      java.awt.Rectangle imageBounds)
Computes the size of the border.

Parameters:
parentSize - The size of the parent window.
imageBounds - The scaled size of the DjVuPage.

getBounds

public java.awt.Rectangle getBounds()
Query the scaled size of this image, with an origin at (0,0).

Returns:
The segmented rectangle.

setBufferBounds

public void setBufferBounds(java.awt.Component parent,
                            java.awt.Rectangle bounds)
Sets the bounds for buffering. Any image outside these bounds will be removed from the buffer. If full buffering is used, the image buffer will be filled at this time.

Parameters:
parent - The containing component.
bounds - The desired boundrary.

setBufferBounds

public void setBufferBounds(java.awt.Rectangle bounds)
Sets the bounds for buffering. Any image outside these bounds will be removed from the buffer.

Parameters:
bounds - Desired bounds.

getFilter

public DjVuFilter getFilter(java.awt.Component parent,
                            java.awt.Rectangle bounds,
                            int index)
Get a segmented image filter.

Parameters:
parent - Parent component to create the Image in.
bounds - Segmentation bounds.
index - filter to create
Returns:
The newly created filter.

getHighlightBounds

public java.awt.Rectangle getHighlightBounds()
Query the bounding rectangle of the area to highlight.

Returns:
bounding rectangle of the area to highlight.

setHighlightList

public void setHighlightList(int index,
                             java.util.Vector list)
Take the list of highlighting rectangles and transform it to a list of non-overlapping rectangles covering the same regions. (Since we use XOR highlighting, overlapping rectangles "cancel" each other out.)

Parameters:
index - of visible image to highlight
list - of bounds to highlight.

getImage

public java.awt.Image[] getImage(java.awt.Component parent,
                                 java.awt.Rectangle bounds)
Get a segmented Image.

Parameters:
parent - Parent component to create the Image in.
bounds - Segmentation bounds.
Returns:
The newly created Image.

getIndexMax

public final int getIndexMax()
Query the size of the DjVuPage array.


getDjVuInfo

public final DjVuInfo getDjVuInfo(int index)
Query the size and other page information as indicated in the INFO chunk.

Parameters:
index - of the page to query
Returns:
the page information

getScaledInstance

public DjVuImage getScaledInstance(int width,
                                   int height)
Create a new instance of this class, scaled to the specified size.

Parameters:
width - Scaled width.
height - Scaled height.
Returns:
a new instance of this class.

getScaledInstance

public DjVuImage getScaledInstance(int scale)
Create a new instance of this class, scaled to the specified size.

Parameters:
scale - Scaling, relative to DPI.
Returns:
a new instance of this class.

getSize

public java.awt.Dimension getSize()
Query the scaled size of the DjVuPage.

Returns:
the scaled size of the DjVuPage.

getTextCodec

public Codec getTextCodec(int index,
                          long maxWait)
Query the DjVuText codec for this page. Use a maxWait value of 0L to wait until the codec is available, or the document is decoded.

Parameters:
maxWait - The maximum amount of time to wait. (In milliseconds.)
Returns:
the DjVuText codec.

draw

public void draw(java.awt.Component parent,
                 java.awt.Graphics g,
                 java.awt.image.ImageObserver observer)
Called to create one or more images to draw to.

Parameters:
parent - Component being drawn to.
g - Graphics device to draw to.
observer - The ImageObserver monitoring progressive rendering.

transformRectangle

public void transformRectangle(int index,
                               java.awt.Rectangle rect,
                               java.awt.Rectangle scaled)
Transform the specified coordinates.

Parameters:
index - visible image index
rect - rectangle to transform.
scaled - the results of the transform.

transformRectangle

public void transformRectangle(int index,
                               GRect rect,
                               java.awt.Rectangle scaled)
Transform the specified coordinates.

Parameters:
index - visible image to transform from
rect - rectangle to transform.
scaled - the results of the transform.

drawHighlight

public void drawHighlight(java.awt.Graphics g,
                          boolean useXOR)
Called to paint the highlight areas onto the image.

Parameters:
g - graphics object to draw.
useXOR - true if XOR highlighting should be used.

fillRect

public void fillRect(java.awt.Graphics g,
                     int color,
                     int opacity,
                     int xmin,
                     int ymin,
                     int xmax,
                     int ymax)
Set the color as specified and then call g.fillRect.

Parameters:
g - Graphics item to use.
color - RGB color to use
opacity - Level of opacity from 0 to 100.
xmin - left edge
ymin - top edge
xmax - right edge
ymax - bottom edge