|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.Canvas | +--com.jthomas.util.ImageLabel
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 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 { ImageLabel duke, javaMug; public void init() { duke = new ImageLabel("http://java.sun.com/lib/images/duke.gif"); javaMug = new ImageLabel("http://java.sun.com/lib/images/JAVA.85.GIF"); add(duke); add(javaMug); } }
The latest version of the source code is http://www.apl.jhu.edu/~hall/java/ImageLabel/ImageLabel.java. The latest version of the documentation is at .../ImageLabel.html, and a small example can be found at .../ImageLabelTest.html.
No warranty of any kind is provided. Permission is granted to use and/or modify for any purpose.
7/96 Marty Hall:
Icon
,
ImageButton
,
Serialized FormNested Class Summary |
Nested classes inherited from class java.awt.Canvas |
java.awt.Canvas.AccessibleAWTCanvas |
Nested classes inherited from class java.awt.Component |
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
Field Summary | |
boolean |
debug
Turn this on to get verbose debugging messages. |
static java.lang.String |
defaultImageString
A String corresponding to the URL of the image you will get if you call the constructor with no arguments. |
protected boolean |
explicitSize
Determines if it will be sized automatically. |
protected int |
height
Width and height of the Canvas. |
protected java.awt.Image |
image
The actual Image drawn on the canvas. |
protected java.lang.String |
imageString
The URL of the image. |
protected int |
margin
Amount of extra space around the image. |
protected java.awt.Color |
marginColor
margin color if there is a non-zero margin. |
protected int |
width
Width and height of the Canvas. |
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 | |
ImageLabel()
Create an ImageLabel with the default image. |
|
ImageLabel(java.awt.Image image)
Create an ImageLabel using the image specified. |
|
ImageLabel(java.lang.String imageURLString)
Create an ImageLabel using the image at URL specified by the string. |
|
ImageLabel(java.net.URL imageURL)
Create an ImageLabel using the image at URL specified. |
Method Summary | |
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. |
boolean |
contains(int x,
int y)
Determines if the x and y (in the Icon's own coordinate system) is inside the Icon. |
protected void |
debug(java.lang.String message)
Calls System.out.println if the debug variable is true, does nothing otherwise. |
protected void |
drawRect(java.awt.Graphics g,
int left,
int top,
int width,
int height,
int lineThickness,
java.awt.Color rectangleColor)
Draws a rectangle with the specified OUTSIDE left, top, width, and height. |
java.awt.Dimension |
getMinimumSize()
Used by layout managers to calculate the smallest size allocated for the Component. |
java.awt.Dimension |
getPreferredSize()
Used by layout managers to calculate the usual size allocated for the Component. |
void |
paint(java.awt.Graphics g)
Draws the image. |
void |
setBounds(int x,
int y,
int width,
int height)
Reshapes the ImageLabel. |
void |
setSize(int width,
int height)
Resizes the ImageLabel. |
void |
waitForImage(boolean doLayout)
Makes sure that the Image associated with the Canvas is done loading before returning. |
Methods inherited from class java.awt.Canvas |
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy, update |
Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected java.awt.Image image
public static java.lang.String defaultImageString
protected java.lang.String imageString
public boolean debug
protected int margin
protected java.awt.Color marginColor
protected int width
protected int height
protected boolean explicitSize
Constructor Detail |
public ImageLabel()
defaultImageString
public ImageLabel(java.lang.String imageURLString)
imageURLString
- A String specifying the URL of the image.public ImageLabel(java.net.URL imageURL)
imageURL
- The URL of the image.public ImageLabel(java.awt.Image image)
image
- The imageMethod Detail |
public void waitForImage(boolean doLayout)
doLayout
- Determines if the Container should be re-layed 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.public void centerAt(int x, int y)
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.
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)Component.move(int, int)
public boolean contains(int x, int y)
contains
in class java.awt.Component
public void paint(java.awt.Graphics g)
paint
in class java.awt.Canvas
public java.awt.Dimension getPreferredSize()
getPreferredSize
in class java.awt.Component
public java.awt.Dimension getMinimumSize()
getMinimumSize
in class java.awt.Component
public void setSize(int width, int height)
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.
setSize
in class java.awt.Component
Component.reshape(int, int, int, int)
public void setBounds(int x, int y, int width, int height)
Note that if you resize/reshape explicitly, you must do it before the ImageLabel is added to the Container. In such a case, the explicit size overrides.
setBounds
in class java.awt.Component
Component.resize(int, int)
protected void drawRect(java.awt.Graphics g, int left, int top, int width, int height, int lineThickness, java.awt.Color rectangleColor)
protected void debug(java.lang.String message)
message
- The String to be printed.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |