com.webcab.chat.gui
Class CaptionView

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Canvas
              |
              +--com.webcab.chat.gui.CaptionView
All Implemented Interfaces:
javax.accessibility.Accessible, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.io.Serializable

public class CaptionView
extends java.awt.Canvas
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.io.Serializable

The CaptionView is a JavaBeanTM, which creates an active area that reacts like a button to mouse clicks and movements, allowing the user to use images instead of text. There are six positions a caption can have:

The CaptionView bean can resize the images according to the full size of the active area, or can simply use the image without changing its dimensions. The caching is done using ImageCache class which prevents any web-related errors to alter the quality of the display.

At present, the BeanInfo class doesn't return any editable properties, so when added to an IDE, the properties will be set by hand-written code.

See Also:
ImageCache, Serialized Form

Inner classes inherited from class java.awt.Canvas
java.awt.Canvas.AccessibleAWTCanvas
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Field Summary
static int SCALE_FULL
          This constant specifies that the images will be scaled to the maximum in order to fit the active area.
static int SCALE_MINIMUM
          This constant specifies that the images will be scaled to the initial value of their specified dimension.
static int SCALE_NONE
          This constant specifies that no scaling will be done upon the images.
 
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
CaptionView()
          This is the non-zero constructor required by the java.beans.Bean class in order to instantiate the bean.
 
Method Summary
 void addCaptionViewListener(CaptionViewListener l)
          Adds a new listener to notify whenever an important event occurs.
 void addNotify()
           
 void flush()
          Disposes all the resources held by this component.
 boolean getAnimated()
          Get the animated flag value.
 java.awt.Dimension getCaptionSize()
          Gets the size of this caption.
 java.lang.String[] getImageNames()
          This method returns the array of strings corresponding to each image in the six states.
 java.awt.Dimension getMinimumSize()
          Returns the minimum size this caption can have.
 java.awt.Dimension getPreferredSize()
          Returns the preferred size of this caption.
 int getScaleFlag()
          Gets the scaling method for this caption.
 void mouseClicked(java.awt.event.MouseEvent e)
          MouseListener interface
 void mouseDragged(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mouseMoved(java.awt.event.MouseEvent e)
          MouseMotionListener methods
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
 void paint(java.awt.Graphics g)
           
 void removeCaptionViewListener(CaptionViewListener l)
          Removes the specified listener.
 void removeNotify()
           
 void setAnimated(boolean animated)
          Sets the animated flag to true or false.
 void setBounds(int x, int y, int w, int h)
          Sets the dimension of this caption.
 void setCaptionSize(java.awt.Dimension captionSize)
          Defines the size of the caption.
 void setImageNames(java.lang.String[] imageNames)
          This method defines all of the six images which will be displayed according to the caption's state: normal, over, pressed, visited, visited over and visited pressed.
 void setScaleFlag(int flag)
          Sets the style of render, when changes of size occur to the bean.
 void update(java.awt.Graphics g)
           
 
Methods inherited from class java.awt.Canvas
getAccessibleContext
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, 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, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SCALE_NONE

public static final int SCALE_NONE
This constant specifies that no scaling will be done upon the images. Note that in this case the active area is restricted to a fixed dimension.
See Also:
setScaleFlag(int), getScaleFlag()

SCALE_MINIMUM

public static final int SCALE_MINIMUM
This constant specifies that the images will be scaled to the initial value of their specified dimension.
See Also:
setScaleFlag(int), getScaleFlag()

SCALE_FULL

public static final int SCALE_FULL
This constant specifies that the images will be scaled to the maximum in order to fit the active area.
See Also:
setScaleFlag(int), getScaleFlag()
Constructor Detail

CaptionView

public CaptionView()
This is the non-zero constructor required by the java.beans.Bean class in order to instantiate the bean.
Method Detail

addCaptionViewListener

public void addCaptionViewListener(CaptionViewListener l)
Adds a new listener to notify whenever an important event occurs.
Parameters:
l - The listener to be added
See Also:
removeCaptionViewListener(com.webcab.chat.gui.CaptionViewListener), CaptionViewListener

removeCaptionViewListener

public void removeCaptionViewListener(CaptionViewListener l)
Removes the specified listener.
Parameters:
l - The listener to be removed
See Also:
addCaptionViewListener(com.webcab.chat.gui.CaptionViewListener), CaptionViewListener

setCaptionSize

public void setCaptionSize(java.awt.Dimension captionSize)
Defines the size of the caption. The active area acts according to the set/getScaleFlag method. If one of the width or height is -1, then at the next resize or at the next setImageNames invocation the corresponding dimension will be replaced.
Parameters:
captionSize - the caption's dimension
See Also:
getCaptionSize()

getCaptionSize

public java.awt.Dimension getCaptionSize()
Gets the size of this caption.
Returns:
the caption's dimension
See Also:
setCaptionSize(java.awt.Dimension)

setImageNames

public void setImageNames(java.lang.String[] imageNames)
This method defines all of the six images which will be displayed according to the caption's state: normal, over, pressed, visited, visited over and visited pressed. The images are specified in a string array containing the URL addresses of each image. If any of the URLs corresponding to a visited image is null, the normal image will be used instead. This is a good way to prevent delays when resizing the component.
Parameters:
imageNames - the array of string containing the image URLs
See Also:
getImageNames(), ImageCache

getImageNames

public java.lang.String[] getImageNames()
This method returns the array of strings corresponding to each image in the six states.
Returns:
An array of strings containing the URL addresses for all the images
See Also:
setImageNames(java.lang.String[])

setScaleFlag

public void setScaleFlag(int flag)
Sets the style of render, when changes of size occur to the bean. The three possible choices are: SCALE_NONE, SCALE_MINIMUM, SCALE_FULL.
Parameters:
flag - One of the three possible scaling flags.
See Also:
getScaleFlag(), SCALE_NONE, SCALE_MINIMUM, SCALE_FULL

getScaleFlag

public int getScaleFlag()
Gets the scaling method for this caption.
Returns:
One of the three scaling flags: SCALE_NONE, SCALE_MINIMUM, SCALE_FULL.
See Also:
setScaleFlag(int), SCALE_NONE, SCALE_MINIMUM, SCALE_FULL

setAnimated

public void setAnimated(boolean animated)
Sets the animated flag to true or false. If the animated flag is true, the caption can display animated gifs under the SCALE_FULL flag. If the animated flag is false, then animated gifs are not properly displayed, but static gifs get an improved performance and speed.
Parameters:
animated - the animated flag. By default, this is false.
See Also:
getAnimated()

getAnimated

public boolean getAnimated()
Get the animated flag value. If false, animated gifs might display incorrect. Fine for static images, though.
Returns:
the animated flag
See Also:
setAnimated(boolean)

getPreferredSize

public java.awt.Dimension getPreferredSize()
Returns the preferred size of this caption.
Overrides:
getPreferredSize in class java.awt.Component
See Also:
getMinimumSize(), getCaptionSize()

getMinimumSize

public java.awt.Dimension getMinimumSize()
Returns the minimum size this caption can have.
Overrides:
getMinimumSize in class java.awt.Component
See Also:
getPreferredSize(), getCaptionSize()

setBounds

public void setBounds(int x,
                      int y,
                      int w,
                      int h)
Sets the dimension of this caption. If the scaling flag is SCALE_FULL, this method sets the size of the active area to the same dimension.
Overrides:
setBounds in class java.awt.Component
See Also:
setCaptionSize(java.awt.Dimension)

addNotify

public void addNotify()
Overrides:
addNotify in class java.awt.Canvas

removeNotify

public void removeNotify()
Overrides:
removeNotify in class java.awt.Component

update

public void update(java.awt.Graphics g)
Overrides:
update in class java.awt.Component

paint

public void paint(java.awt.Graphics g)
Overrides:
paint in class java.awt.Canvas

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
MouseListener interface
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
MouseMotionListener methods
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

flush

public void flush()
Disposes all the resources held by this component.