|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent net.lucidviews.util.gui.swing.JImage
public class JImage
A UI component that displays an image.
To display an image in a GUI, simply create an new instance of
JImage
specifying an Image
or the location of a
file containing an image:
Image logoImage = Toolkit.getDefaultToolkit.createImage( "./icons/logo.gif" ); JImage logoPane = new JImage( logoImage, new Dimension( 80, 50 ) ); JImage localPicture = new JImage( "C:/MyPictures/Photo.jpg", JImage.MAINTAIN_SIZE ); JImage remotePicture = new JImage( new URL( "http://www.mysite.com/Photo.jpg" ), JImage.SHRINK_TO_AREA_MAINTAIN_ASPECT ); JPanel contentPane = ...; contentPane.add( logoPane ); contentPane.add( localPicture ); contentPane.add( remotePicture );
setImage
methods.
Image
objects persist in memory. Using the
setImage( filename )
method will cause each image to load
on every call to setImage
. Holding the Image
object
in memory and calling setImage( Image )
will ensure the image
is loaded just once and provide a smoother display.
Image
,
Toolkit.createImage(java.lang.String)
,
Serialized FormNested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
---|---|
protected Image |
_displayImage
The image that gets displayed (a re-sized copy of _image ) |
protected Point |
_displayPosition
The pixel position of the top-right corner of the image relative to the top-right corner of the available area. |
protected int |
_displayScaling
The algorithm used to scale the original image to the displayed (re-sized) image. |
protected Dimension |
_displaySetting
The algorithm used to determine the size of the displayed image based upon the available area in which to display it. |
protected Dimension |
_displaySize
The size of the rendered image. |
protected Image |
_image
The image to be displayed. |
protected Dimension |
_imageSize
The (original) size of the image. |
protected boolean |
_paintRequested
Flag set when the paint method is called and reset once the image has been successfully painted (i.e. |
protected float |
_xAlignment
Horizontal alignment of the image within the available space (0.0: left; 1.0: right). |
protected float |
_yAlignment
Vertical alignment of the image within the available space (0.0: top; 1.0: bottom) |
static Dimension |
FIT_TO_AREA
|
static Dimension |
FIT_TO_AREA_MAINTAIN_ASPECT
|
static Dimension |
MAINTAIN_SIZE
|
static Dimension |
SHRINK_TO_AREA_MAINTAIN_ASPECT
|
protected static String[] |
SUPPORTED_IMAGE_EXTNS
A list of file extensions supported by the Java Image renderer. |
protected static Dimension |
UNDEFINED_SIZE
Special value used to indicate the image size has not been set. |
protected static Insets |
ZERO_INSET
An Insets object that defines no border. |
Fields inherited from class javax.swing.JComponent |
---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
JImage()
Create a component that displays an image, but leave the image undefined. |
|
JImage(Image image,
Dimension size)
Create a component that displays an image. |
|
JImage(Image image,
Dimension size,
int scalingAlgorithm)
Create a GUI component that displays an image, using the given scaling algorithm, whenever necessary, to adjust the size of the image to fit the available space. |
|
JImage(String filename,
Dimension size)
Create a component that displays an image taken from a given file. |
|
JImage(String filename,
Dimension size,
int scalingAlgorithm)
Create a GUI component that displays an image taken from a given file, using the given scaling algorithm, whenever necessary, to adjust the size of the image to fit the available space. |
Method Summary | |
---|---|
protected Dimension |
computeDisplaySize(int imageWidth,
int imageHeight)
Compute the dimension of the scaled image. |
Insets |
getBorderInsets()
Returns an Insets model that describes the location of the
inner edge of the border around this image component. |
Image |
getImage()
Get the Image object that represents the image being
displayed in this component. |
static boolean |
isSupportedImage(File file)
Checks if a file is an image of a known format. |
static boolean |
isSupportedImage(String fileName)
Checks if a file is an image of a known format. |
void |
paint(Graphics g)
|
void |
setBounds(int x,
int y,
int width,
int height)
|
protected void |
setDisplaySize(Dimension size)
Called to set the dimension of the image that is displayed in the component. |
void |
setImage(byte[] imageData,
Dimension size)
Set the image to be displayed in this component. |
void |
setImage(byte[] imageData,
Dimension size,
boolean repaintNow)
Set the image to be displayed in this component. |
void |
setImage(byte[] imageData,
Dimension size,
int scalingAlgorithm)
Set the image to be displayed in this component. |
void |
setImage(byte[] imageData,
Dimension size,
int scalingAlgorithm,
boolean repaintNow)
Set the image to be displayed in this component. |
void |
setImage(Image image,
Dimension size)
Set the image to be displayed in this component. |
void |
setImage(Image image,
Dimension size,
boolean repaintNow)
Set the image to be displayed in this component. |
void |
setImage(Image image,
Dimension size,
int scalingAlgorithm)
Set the image to be displayed in this component. |
void |
setImage(Image image,
Dimension size,
int scalingAlgorithm,
boolean repaintNow)
Set the image to be displayed in this component. |
void |
setImage(String filename,
Dimension size)
Set the image to be displayed in this component. |
void |
setImage(String filename,
Dimension size,
boolean repaintNow)
Set the image to be displayed in this component. |
void |
setImage(String filename,
Dimension size,
int scalingAlgorithm)
Set the image to be displayed in this component. |
void |
setImage(String filename,
Dimension size,
int scalingAlgorithm,
boolean repaintNow)
Set the image to be displayed in this component. |
void |
setImage(URL imageURL,
Dimension size)
Set the image to be displayed in this component. |
void |
setImage(URL imageURL,
Dimension size,
boolean repaintNow)
Set the image to be displayed in this component. |
void |
setImage(URL imageURL,
Dimension size,
int scalingAlgorithm)
Set the image to be displayed in this component. |
void |
setImage(URL imageURL,
Dimension size,
int scalingAlgorithm,
boolean repaintNow)
Set the image to be displayed in this component. |
void |
setImageAlignment(float xAlignment,
float yAlignment)
Set the alignment of the image within the available space. |
void |
setImageDimension(int imgWidth,
int imgHeight)
Set the size of the original image. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final Dimension MAINTAIN_SIZE
public static final Dimension FIT_TO_AREA
public static final Dimension FIT_TO_AREA_MAINTAIN_ASPECT
public static final Dimension SHRINK_TO_AREA_MAINTAIN_ASPECT
protected static final String[] SUPPORTED_IMAGE_EXTNS
protected static final Dimension UNDEFINED_SIZE
protected static final Insets ZERO_INSET
Insets
object that defines no border.
protected Image _image
protected Dimension _imageSize
protected Dimension _displaySetting
protected Dimension _displaySize
protected int _displayScaling
protected float _xAlignment
protected float _yAlignment
protected Image _displayImage
_image
)
protected Point _displayPosition
protected boolean _paintRequested
Constructor Detail |
---|
public JImage()
setImage
method.
public JImage(Image image, Dimension size)
image
- the image to displaysize
- either an absolute value or one of the constants exported by
JImage
MAINTAIN_SIZE
,
FIT_TO_AREA
,
FIT_TO_AREA_MAINTAIN_ASPECT
,
SHRINK_TO_AREA_MAINTAIN_ASPECT
public JImage(String filename, Dimension size)
filename
- the name of the file that stores the image; the file
must be in one of the supported formats (JPG or GIF)size
- either an absolute value or one of the constants exported by
JImage
MAINTAIN_SIZE
,
FIT_TO_AREA
,
FIT_TO_AREA_MAINTAIN_ASPECT
,
SHRINK_TO_AREA_MAINTAIN_ASPECT
public JImage(Image image, Dimension size, int scalingAlgorithm)
image
- the image to displaysize
- either an absolute value or one of the constants exported by
JImage
scalingAlgorithm
- flags to indicate the type of algorithm to use
for image re-scalingMAINTAIN_SIZE
,
FIT_TO_AREA
,
FIT_TO_AREA_MAINTAIN_ASPECT
,
SHRINK_TO_AREA_MAINTAIN_ASPECT
,
Image.SCALE_DEFAULT
,
Image.SCALE_FAST
,
Image.SCALE_SMOOTH
,
Image.SCALE_REPLICATE
,
Image.SCALE_AREA_AVERAGING
public JImage(String filename, Dimension size, int scalingAlgorithm)
filename
- the name of the file that stores the image; the file
must be in one of the supported formats (JPG or GIF)size
- either an absolute value or one of the constants exported by
JImage
scalingAlgorithm
- flags to indicate the type of algorithm to use
for image re-scalingMAINTAIN_SIZE
,
FIT_TO_AREA
,
FIT_TO_AREA_MAINTAIN_ASPECT
,
SHRINK_TO_AREA_MAINTAIN_ASPECT
,
Image.SCALE_DEFAULT
,
Image.SCALE_FAST
,
Image.SCALE_SMOOTH
,
Image.SCALE_REPLICATE
,
Image.SCALE_AREA_AVERAGING
Method Detail |
---|
public void setImageAlignment(float xAlignment, float yAlignment)
xAlignment
- horizontal alignment (0.0: left; 1.0: right)yAlignment
- vertical alignment (0.0: top; 1.0: bottom)public Image getImage()
Image
object that represents the image being
displayed in this component.
null
if the image has
not been setpublic void setImage(Image image, Dimension size)
size
specified or, if
size
is set to one of the constants exported by this class,
then the image will be re-sized taking into account the space available
for the image.
image
- the image to be displayedsize
- either an absolute value or one of the constants exported by
JImage
MAINTAIN_SIZE
,
FIT_TO_AREA
,
FIT_TO_AREA_MAINTAIN_ASPECT
,
SHRINK_TO_AREA_MAINTAIN_ASPECT
public void setImage(String filename, Dimension size)
size
specified or, if
size
is set to one of the constants exported by this class,
then the image will be re-sized taking into account the space available
for the image.
filename
- the name of the file that stores the image; the file
must be in one of the supported formats (JPG or GIF)size
- either an absolute value or one of the constants exported by
JImage
MAINTAIN_SIZE
,
FIT_TO_AREA
,
FIT_TO_AREA_MAINTAIN_ASPECT
,
SHRINK_TO_AREA_MAINTAIN_ASPECT
public void setImage(URL imageURL, Dimension size)
size
specified or, if
size
is set to one of the constants exported by this class,
then the image will be re-sized taking into account the space available
for the image.
imageURL
- the URL of the file that stores the image; the file
must be in one of the supported formats (JPG or GIF)size
- either an absolute value or one of the constants exported by
JImage
MAINTAIN_SIZE
,
FIT_TO_AREA
,
FIT_TO_AREA_MAINTAIN_ASPECT
,
SHRINK_TO_AREA_MAINTAIN_ASPECT
public void setImage(byte[] imageData, Dimension size)
size
specified or, if
size
is set to one of the constants exported by this class,
then the image will be re-sized taking into account the space available
for the image.
imageData
- the binary data of the image to be displayedsize
- either an absolute value or one of the constants exported by
JImage
MAINTAIN_SIZE
,
FIT_TO_AREA
,
FIT_TO_AREA_MAINTAIN_ASPECT
,
SHRINK_TO_AREA_MAINTAIN_ASPECT
public void setImage(Image image, Dimension size, boolean repaintNow)
size
specified or, if
size
is set to one of the constants exported by this class,
then the image will be re-sized taking into account the space available
for the image.
image
- the image to be displayedsize
- either an absolute value or one of the constants exported by
JImage
repaintNow
- indicates if the component should be refreshed to
ensure the new image is renderedMAINTAIN_SIZE
,
FIT_TO_AREA
,
FIT_TO_AREA_MAINTAIN_ASPECT
,
SHRINK_TO_AREA_MAINTAIN_ASPECT
public void setImage(String filename, Dimension size, boolean repaintNow)
size
specified or, if
size
is set to one of the constants exported by this class,
then the image will be re-sized taking into account the space available
for the image.
filename
- the name of the file that stores the image; the file
must be in one of the supported formats (JPG or GIF)size
- either an absolute value or one of the constants exported by
JImage
repaintNow
- indicates if the component should be refreshed to
ensure the new image is renderedMAINTAIN_SIZE
,
FIT_TO_AREA
,
FIT_TO_AREA_MAINTAIN_ASPECT
,
SHRINK_TO_AREA_MAINTAIN_ASPECT
public void setImage(URL imageURL, Dimension size, boolean repaintNow)
size
specified or, if
size
is set to one of the constants exported by this class,
then the image will be re-sized taking into account the space available
for the image.
imageURL
- the URL of the file that stores the image; the file
must be in one of the supported formats (JPG or GIF)size
- either an absolute value or one of the constants exported by
JImage
repaintNow
- indicates if the component should be refreshed to
ensure the new image is renderedMAINTAIN_SIZE
,
FIT_TO_AREA
,
FIT_TO_AREA_MAINTAIN_ASPECT
,
SHRINK_TO_AREA_MAINTAIN_ASPECT
public void setImage(byte[] imageData, Dimension size, boolean repaintNow)
size
specified or, if
size
is set to one of the constants exported by this class,
then the image will be re-sized taking into account the space available
for the image.
imageData
- the binary data of the image to be displayedsize
- either an absolute value or one of the constants exported by
JImage
repaintNow
- indicates if the component should be refreshed to
ensure the new image is renderedMAINTAIN_SIZE
,
FIT_TO_AREA
,
FIT_TO_AREA_MAINTAIN_ASPECT
,
SHRINK_TO_AREA_MAINTAIN_ASPECT
public void setImage(Image image, Dimension size, int scalingAlgorithm)
size
specified or, if
size
is set to one of the constants exported by this class,
then the image will be re-sized taking into account the space available
for the image.
scalingAlgorithm
(suggested by the bitmap of constants exported by the
java.awt.Image
class) will be used.
image
- the image to be displayedsize
- either an absolute value or one of the constants exported by
JImage
scalingAlgorithm
- flags to indicate the type of algorithm to use
for image re-scalingMAINTAIN_SIZE
,
FIT_TO_AREA
,
FIT_TO_AREA_MAINTAIN_ASPECT
,
SHRINK_TO_AREA_MAINTAIN_ASPECT
,
Image.SCALE_DEFAULT
,
Image.SCALE_FAST
,
Image.SCALE_SMOOTH
,
Image.SCALE_REPLICATE
,
Image.SCALE_AREA_AVERAGING
public void setImage(String filename, Dimension size, int scalingAlgorithm)
size
specified or, if
size
is set to one of the constants exported by this class,
then the image will be re-sized taking into account the space available
for the image.
scalingAlgorithm
(suggested by the bitmap of constants exported by the
java.awt.Image
class) will be used.
filename
- the name of the file that stores the image; the file
must be in one of the supported formats (JPG or GIF)size
- either an absolute value or one of the constants exported by
JImage
scalingAlgorithm
- flags to indicate the type of algorithm to use
for image re-scalingMAINTAIN_SIZE
,
FIT_TO_AREA
,
FIT_TO_AREA_MAINTAIN_ASPECT
,
SHRINK_TO_AREA_MAINTAIN_ASPECT
,
Image.SCALE_DEFAULT
,
Image.SCALE_FAST
,
Image.SCALE_SMOOTH
,
Image.SCALE_REPLICATE
,
Image.SCALE_AREA_AVERAGING
public void setImage(URL imageURL, Dimension size, int scalingAlgorithm)
size
specified or, if
size
is set to one of the constants exported by this class,
then the image will be re-sized taking into account the space available
for the image.
scalingAlgorithm
(suggested by the bitmap of constants exported by the
java.awt.Image
class) will be used.
imageURL
- the URL of the file that stores the image; the file
must be in one of the supported formats (JPG or GIF)size
- either an absolute value or one of the constants exported by
JImage
scalingAlgorithm
- flags to indicate the type of algorithm to use
for image re-scalingMAINTAIN_SIZE
,
FIT_TO_AREA
,
FIT_TO_AREA_MAINTAIN_ASPECT
,
SHRINK_TO_AREA_MAINTAIN_ASPECT
,
Image.SCALE_DEFAULT
,
Image.SCALE_FAST
,
Image.SCALE_SMOOTH
,
Image.SCALE_REPLICATE
,
Image.SCALE_AREA_AVERAGING
public void setImage(byte[] imageData, Dimension size, int scalingAlgorithm)
size
specified or, if
size
is set to one of the constants exported by this class,
then the image will be re-sized taking into account the space available
for the image.
scalingAlgorithm
(suggested by the bitmap of constants exported by the
java.awt.Image
class) will be used.
imageData
- the binary data of the image to be displayedsize
- either an absolute value or one of the constants exported by
JImage
scalingAlgorithm
- flags to indicate the type of algorithm to use
for image re-scalingMAINTAIN_SIZE
,
FIT_TO_AREA
,
FIT_TO_AREA_MAINTAIN_ASPECT
,
SHRINK_TO_AREA_MAINTAIN_ASPECT
,
Image.SCALE_DEFAULT
,
Image.SCALE_FAST
,
Image.SCALE_SMOOTH
,
Image.SCALE_REPLICATE
,
Image.SCALE_AREA_AVERAGING
public void setImage(Image image, Dimension size, int scalingAlgorithm, boolean repaintNow)
size
specified or, if
size
is set to one of the constants exported by this class,
then the image will be re-sized taking into account the space available
for the image.
scalingAlgorithm
(suggested by the bitmap of constants exported by the
java.awt.Image
class) will be used.
image
- the image to be displayedsize
- either an absolute value or one of the constants exported by
JImage
scalingAlgorithm
- flags to indicate the type of algorithm to use
for image re-scalingrepaintNow
- indicates if the component should be refreshed to
ensure the new image is renderedMAINTAIN_SIZE
,
FIT_TO_AREA
,
FIT_TO_AREA_MAINTAIN_ASPECT
,
SHRINK_TO_AREA_MAINTAIN_ASPECT
,
Image.SCALE_DEFAULT
,
Image.SCALE_FAST
,
Image.SCALE_SMOOTH
,
Image.SCALE_REPLICATE
,
Image.SCALE_AREA_AVERAGING
public void setImage(String filename, Dimension size, int scalingAlgorithm, boolean repaintNow)
size
specified or, if
size
is set to one of the constants exported by this class,
then the image will be re-sized taking into account the space available
for the image.
scalingAlgorithm
(suggested by the bitmap of constants exported by the
java.awt.Image
class) will be used.
filename
- the name of the file that stores the image; the file
must be in one of the supported formats (JPG or GIF)size
- either an absolute value or one of the constants exported by
JImage
scalingAlgorithm
- flags to indicate the type of algorithm to use
for image re-scalingrepaintNow
- indicates if the component should be refreshed to
ensure the new image is renderedMAINTAIN_SIZE
,
FIT_TO_AREA
,
FIT_TO_AREA_MAINTAIN_ASPECT
,
SHRINK_TO_AREA_MAINTAIN_ASPECT
,
Image.SCALE_DEFAULT
,
Image.SCALE_FAST
,
Image.SCALE_SMOOTH
,
Image.SCALE_REPLICATE
,
Image.SCALE_AREA_AVERAGING
public void setImage(URL imageURL, Dimension size, int scalingAlgorithm, boolean repaintNow)
size
specified or, if
size
is set to one of the constants exported by this class,
then the image will be re-sized taking into account the space available
for the image.
scalingAlgorithm
(suggested by the bitmap of constants exported by the
java.awt.Image
class) will be used.
imageURL
- the URL of the file that stores the image; the file
must be in one of the supported formats (JPG or GIF)size
- either an absolute value or one of the constants exported by
JImage
scalingAlgorithm
- flags to indicate the type of algorithm to use
for image re-scalingrepaintNow
- indicates if the component should be refreshed to
ensure the new image is renderedMAINTAIN_SIZE
,
FIT_TO_AREA
,
FIT_TO_AREA_MAINTAIN_ASPECT
,
SHRINK_TO_AREA_MAINTAIN_ASPECT
,
Image.SCALE_DEFAULT
,
Image.SCALE_FAST
,
Image.SCALE_SMOOTH
,
Image.SCALE_REPLICATE
,
Image.SCALE_AREA_AVERAGING
public void setImage(byte[] imageData, Dimension size, int scalingAlgorithm, boolean repaintNow)
size
specified or, if
size
is set to one of the constants exported by this class,
then the image will be re-sized taking into account the space available
for the image.
scalingAlgorithm
(suggested by the bitmap of constants exported by the
java.awt.Image
class) will be used.
imageData
- the binary data of the image to be displayedsize
- either an absolute value or one of the constants exported by
JImage
scalingAlgorithm
- flags to indicate the type of algorithm to use
for image re-scalingrepaintNow
- indicates if the component should be refreshed to
ensure the new image is renderedMAINTAIN_SIZE
,
FIT_TO_AREA
,
FIT_TO_AREA_MAINTAIN_ASPECT
,
SHRINK_TO_AREA_MAINTAIN_ASPECT
,
Image.SCALE_DEFAULT
,
Image.SCALE_FAST
,
Image.SCALE_SMOOTH
,
Image.SCALE_REPLICATE
,
Image.SCALE_AREA_AVERAGING
public void setBounds(int x, int y, int width, int height)
setBounds
in class Component
protected Dimension computeDisplaySize(int imageWidth, int imageHeight)
imageWidth
- the width of the original imageimageHeight
- the height of the original image
_displaySetting
public void setImageDimension(int imgWidth, int imgHeight)
setImageDimension
in interface DimensionImageObserver.Listener
imgWidth
- the width of the image to be displayedimgHeight
- the height of the image to be displayedprotected void setDisplaySize(Dimension size)
setImage
method, this
size must be an absolute dimension value (NOT one of the special
constants exported by this class).
size
- the size of the image when it is renderedpublic Insets getBorderInsets()
Insets
model that describes the location of the
inner edge of the border around this image component.
public void paint(Graphics g)
paint
in class JComponent
public static boolean isSupportedImage(File file)
file
- the file to be tested
true
if the file has an known & supported extensionpublic static boolean isSupportedImage(String fileName)
fileName
- the name of the file to be tested
true
if the file has an known & supported extension
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |