net.sourceforge.jiu.gui.awt

Class ImageCanvas


public class ImageCanvas
extends Canvas

An AWT canvas that displays an java.awt.Image object. Capable to display at arbitrary zooming levels. Does not use rendering hints because they require Java 1.2 or higher (although bilinear and bicubic interpolation usually improve display quality when zooming at the cost of slowing down image drawing).
Author:
Marco Schmidt

Field Summary

private int
height
private Image
image
private ScrollPane
myScrollPane
private int
scaledHeight
private int
scaledWidth
private int
width
private double
zoomFactorX
private double
zoomFactorY
private boolean
zoomToFit

Constructor Summary

ImageCanvas(ScrollPane scrollPane)

Method Summary

void
computeZoomToFitSize()
Dimension
getPreferredSize()
double
getZoomFactorX()
double
getZoomFactorY()
int
getZoomPercentageX()
int
getZoomPercentageY()
void
paint(Graphics g)
Draws image to upper left corner.
void
setImage(Image newImage)
Specifies a new Image object to be displayed in this canvas.
void
setInterpolation(int newType)
Sets the interpolation type used for drawing to the argument (must be one of the INTERPOLATION_xyz constants of EditorState), but does not do a redraw.
void
setOriginalSize()
Sets both zoom factors to 1.0.
void
setZoomFactor(double newZoomFactor)
void
setZoomFactors(double newZoomFactorX, double newZoomFactorY)
void
setZoomToFit(boolean newValue)
void
update(Graphics g)
Simply calls paint(Graphics) with the argument.

Field Details

height

private int height

image

private Image image

myScrollPane

private ScrollPane myScrollPane

scaledHeight

private int scaledHeight

scaledWidth

private int scaledWidth

width

private int width

zoomFactorX

private double zoomFactorX

zoomFactorY

private double zoomFactorY

zoomToFit

private boolean zoomToFit

Constructor Details

ImageCanvas

public ImageCanvas(ScrollPane scrollPane)

Method Details

computeZoomToFitSize

public void computeZoomToFitSize()

getPreferredSize

public Dimension getPreferredSize()

getZoomFactorX

public double getZoomFactorX()

getZoomFactorY

public double getZoomFactorY()

getZoomPercentageX

public int getZoomPercentageX()

getZoomPercentageY

public int getZoomPercentageY()

paint

public void paint(Graphics g)
Draws image to upper left corner.

setImage

public void setImage(Image newImage)
Specifies a new Image object to be displayed in this canvas.
Parameters:
newImage - the new Image object, potentially null

setInterpolation

public void setInterpolation(int newType)
Sets the interpolation type used for drawing to the argument (must be one of the INTERPOLATION_xyz constants of EditorState), but does not do a redraw.

setOriginalSize

public void setOriginalSize()
Sets both zoom factors to 1.0.

setZoomFactor

public void setZoomFactor(double newZoomFactor)

setZoomFactors

public void setZoomFactors(double newZoomFactorX,
                           double newZoomFactorY)

setZoomToFit

public void setZoomToFit(boolean newValue)

update

public void update(Graphics g)
Simply calls paint(Graphics) with the argument.
Parameters:
g - Graphics context