All Packages Class Hierarchy This Package Previous Next Index
Class com.ibm.jmf.MultiPlayer.ImageLabel
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Canvas
|
+----com.ibm.jmf.MultiPlayer.ImageLabel
- public class ImageLabel
- extends Canvas
A class for displaying images. It places the Image
into a canvas so that it can moved around by layout
managers, will get repainted automatically, etc.
No mouseXXX or action events are defined, so it is
most similar to the Label Component.
By default, with FlowLayout the ImageLabel takes
its minimum size (just enclosing the image). The
default with BorderLayout is to expand to fill
the region in width (North/South), height
(East/West) or both (Center). This is the same
behavior as with the builtin Label class. If you
give an explicit resize or
reshape call before adding the
ImageLabel to the Container, this size will
override the defaults.
Here is an example of its use:
public class ShowImages extends Applet {
private ImageLabel image1, image2;
public void init() {
image1 = new ImageLabel(getCodeBase(),
"some-image.gif");
image2 = new ImageLabel(getCodeBase(),
"other-image.jpg");
add(image1);
add(image2);
}
}
- See Also:
- Icon, ImageButton
-
border
- Amount of extra space around the image.
-
borderColor
- If there is a non-zero border, what color should
it be? Default is to use the background color
of the Container.
-
defaultImageString
-
-
doneLoading
-
-
explicitSize
- Determines if it will be sized automatically.
-
height
-
-
image
-
-
newEventsOnly
-
-
width
-
-
ImageLabel()
- Create an ImageLabel with the default image.
-
ImageLabel(Image)
- Create an ImageLabel using the image specified.
-
ImageLabel(String)
- Create an ImageLabel using the image at URL
specified by the string.
-
ImageLabel(URL)
- Create an ImageLabel using the image at URL
specified.
-
ImageLabel(URL, String)
- Create an ImageLabel using the image in the file
in the specified directory.
-
centerAt(int, int)
- Moves the image so that it is centered at
the specified location, as opposed to the move
method of Component which places the top left
corner at the specified location.
-
debug(String)
- Calls System.out.println if the debug variable
is true; does nothing otherwise.
-
drawRect(Graphics, int, int, int, int, int, Color)
- Draws a rectangle with the specified OUTSIDE
left, top, width, and height.
-
getBorder()
- Gets the border width.
-
getBorderColor()
- Gets the border color.
-
getDefaultImageString()
- Returns the string representing the URL that
will be used if none is supplied in the
constructor.
-
getHeight()
- Gets the height (image height plus 2x border).
-
getImage()
- The Image associated with the ImageLabel.
-
getImageString()
- Returns the string representing the URL
of image.
-
getWidth()
- Gets the width (image width plus twice border).
-
hasExplicitSize()
- Has the ImageLabel been given an explicit size?
This is used to decide if the image should be
stretched or not.
-
inside(int, int)
- Determines if the x and y (in the ImageLabel's
own coordinate system) is inside the
ImageLabel.
-
isDebugging()
- Is the debugging flag set?
-
minimumSize()
- Used by layout managers to calculate the smallest
size allocated for the Component.
-
paint(Graphics)
- Draws the image.
-
preferredSize()
- Used by layout managers to calculate the usual
size allocated for the Component.
-
reshape(int, int, int, int)
- Resizes the ImageLabel.
-
resize(int, int)
- Resizes the ImageLabel.
-
setBorder(int)
- Sets the border thickness.
-
setBorderColor(Color)
- Sets the border color.
-
setDefaultImageString(String)
- Sets the string representing the URL that
will be used if none is supplied in the
constructor.
-
setIsDebugging(boolean)
- Set the debugging flag.
-
waitForImage(boolean)
- Makes sure that the Image associated with the
Canvas is done loading before returning, since
loadImage spins off a separate thread to do the
loading.
image
protected Image image
defaultImageString
protected static String defaultImageString
border
protected int border
- Amount of extra space around the image.
borderColor
protected Color borderColor
- If there is a non-zero border, what color should
it be? Default is to use the background color
of the Container.
width
protected int width
height
protected int height
explicitSize
protected boolean explicitSize
- Determines if it will be sized automatically.
If the user issues a resize() or reshape()
call before adding the label to the Container,
or if the LayoutManager resizes before
drawing (as with BorderLayout), then those sizes
override the default, which is to make the label
the same size as the image it holds (after
reserving space for the border, if any).
This flag notes this, so subclasses that
override ImageLabel need to check this flag, and
if it is true, and they draw modified image,
then they need to draw them based on the width
height variables, not just blindly drawing them
full size.
doneLoading
protected boolean doneLoading
newEventsOnly
boolean newEventsOnly
ImageLabel
public ImageLabel()
- Create an ImageLabel with the default image.
- See Also:
- getDefaultImageString, setDefaultImageString
ImageLabel
public ImageLabel(String imageURLString)
- Create an ImageLabel using the image at URL
specified by the string.
- Parameters:
- imageURLString - A String specifying the
URL of the image.
ImageLabel
public ImageLabel(URL imageURL)
- Create an ImageLabel using the image at URL
specified.
- Parameters:
- imageURL - The URL of the image.
ImageLabel
public ImageLabel(URL imageDirectory,
String file)
- Create an ImageLabel using the image in the file
in the specified directory.
- Parameters:
- imageDirectory - Directory containing image
- file - Filename of image
ImageLabel
public ImageLabel(Image image)
- Create an ImageLabel using the image specified.
The other constructors eventually call this one,
but you may want to call it directly if you
already have an image (e.g. created via
createImage).
- Parameters:
- image - The image
waitForImage
public void waitForImage(boolean doLayout)
- Makes sure that the Image associated with the
Canvas is done loading before returning, since
loadImage spins off a separate thread to do the
loading. Once you get around to drawing the
image, this will make sure it is loaded,
waiting if not. The user does not need to call
this at all, but if several ImageLabels are used
in the same Container, this can cause
several repeated layouts, so users might want to
explicitly call this themselves before adding
the ImageLabel to the Container. Another
alternative is to start asynchronous loading by
calling prepareImage on the ImageLabel's
image (see getImage).
- Parameters:
- doLayout - Determines if the Container
should be re-laid out after you are finished
waiting. This should be true when called
from user functions, but is set to false
when called from preferredSize to avoid an
infinite loop. This is needed when
using BorderLayout, which calls preferredSize
before calling paint.
centerAt
public void centerAt(int x,
int y)
- Moves the image so that it is centered at
the specified location, as opposed to the move
method of Component which places the top left
corner at the specified location.
Note: The effects of this could be undone
by the LayoutManager of the parent Container, if
it is using one. So this is normally only used
in conjunction with a null LayoutManager.
- Parameters:
- x - The X coord of center of the image
(in parent's coordinate system)
- y - The Y coord of center of the image
(in parent's coordinate system)
- See Also:
- move
inside
public synchronized boolean inside(int x,
int y)
- Determines if the x and y (in the ImageLabel's
own coordinate system) is inside the
ImageLabel. Put here because Netscape 2.02 has
a bug in which it doesn't process inside() and
locate() tests correctly.
- Overrides:
- inside in class Component
paint
public void paint(Graphics g)
- Draws the image. If you override this in a
subclass, be sure to call super.paint.
- Overrides:
- paint in class Canvas
preferredSize
public Dimension preferredSize()
- Used by layout managers to calculate the usual
size allocated for the Component. Since some
layout managers (e.g. BorderLayout) may
call this before paint is called, you need to
make sure that the image is done loading, which
will force a resize, which determines the values
returned.
- Overrides:
- preferredSize in class Component
minimumSize
public Dimension minimumSize()
- Used by layout managers to calculate the smallest
size allocated for the Component. Since some
layout managers (e.g. BorderLayout) may
call this before paint is called, you need to
make sure that the image is done loading, which
will force a resize, which determines the values
returned.
- Overrides:
- minimumSize in class Component
resize
public void resize(int width,
int height)
- Resizes the ImageLabel. If you don't resize the
label explicitly, then what happens depends on
the layout manager. With FlowLayout, as with
FlowLayout for Labels, the ImageLabel takes its
minimum size, just enclosing the image. With
BorderLayout, as with BorderLayout for Labels,
the ImageLabel is expanded to fill the
section. Stretching GIF/JPG files does not always
result in clear looking images. So just as
with builtin Labels and Buttons, don't
use FlowLayout if you don't want the Buttons to
get resized. If you don't use any
LayoutManager, then the ImageLabel will also
just fit the image.
Note that if you resize explicitly, you must do
it before the ImageLabel is added to the
Container. In such a case, the explicit size
overrides the image dimensions.
- Overrides:
- resize in class Component
- See Also:
- reshape
reshape
public void reshape(int x,
int y,
int width,
int height)
- Resizes the ImageLabel. If you don't resize the
label explicitly, then what happens depends on
the layout manager. With FlowLayout, as with
FlowLayout for Labels, the ImageLabel takes its
minimum size, just enclosing the image. With
BorderLayout, as with BorderLayout for Labels,
the ImageLabel is expanded to fill the
section. Stretching GIF/JPG files does not always
result in clear looking images. So just as
with builtin Labels and Buttons, don't
use FlowLayout if you don't want the Buttons to
get resized. If you don't use any
LayoutManager, then the ImageLabel will also
just fit the image.
Note that if you resize explicitly, you must do
it before the ImageLabel is added to the
Container. In such a case, the explicit size
overrides the image dimensions.
- Overrides:
- reshape in class Component
- See Also:
- resize
drawRect
protected void drawRect(Graphics g,
int left,
int top,
int width,
int height,
int lineThickness,
Color rectangleColor)
- Draws a rectangle with the specified OUTSIDE
left, top, width, and height.
Used to draw the border.
debug
protected void debug(String message)
- Calls System.out.println if the debug variable
is true; does nothing otherwise.
- Parameters:
- message - The String to be printed.
getImage
public Image getImage()
- The Image associated with the ImageLabel.
getBorder
public int getBorder()
- Gets the border width.
setBorder
public void setBorder(int border)
- Sets the border thickness.
getBorderColor
public Color getBorderColor()
- Gets the border color.
setBorderColor
public void setBorderColor(Color borderColor)
- Sets the border color.
getWidth
public int getWidth()
- Gets the width (image width plus twice border).
getHeight
public int getHeight()
- Gets the height (image height plus 2x border).
hasExplicitSize
protected boolean hasExplicitSize()
- Has the ImageLabel been given an explicit size?
This is used to decide if the image should be
stretched or not. This will be true if you
call resize or reshape on the ImageLabel before
adding it to a Container. It will be false
otherwise.
getDefaultImageString
public static String getDefaultImageString()
- Returns the string representing the URL that
will be used if none is supplied in the
constructor.
setDefaultImageString
public static void setDefaultImageString(String file)
- Sets the string representing the URL that
will be used if none is supplied in the
constructor. Note that this is static,
so is shared by all ImageLabels. Using this
might be convenient in testing, but "real"
applications should avoid it.
getImageString
protected String getImageString()
- Returns the string representing the URL
of image.
isDebugging
public boolean isDebugging()
- Is the debugging flag set?
setIsDebugging
public void setIsDebugging(boolean debug)
- Set the debugging flag. Verbose messages
will be printed to System.out if this is true.
All Packages Class Hierarchy This Package Previous Next Index