org.formaria.swing
Class CaptionedImage

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by org.formaria.swing.Panel
                      extended by org.formaria.swing.CaptionedImage
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, ContentHolder, PersistentState, StateListener

public class CaptionedImage
extends Panel
implements ContentHolder, StateListener, java.awt.event.MouseListener

An extension of the Image component that adds a caption to the image and an optional border

Copyright (c) Formaria Ltd., 2008, This software is licensed under the GNU Public License (GPL), please see license.txt for more details. If you make commercial use of this software you must purchase a commercial license from Formaria.

$Revision: 1.21 $

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  int borders
           
protected  Label caption
           
protected  ClickListener clickListener
           
protected  Project currentProject
          The owner project and the context in which this object operates.
protected  Image image
           
protected  java.lang.String imgName
           
protected  java.util.ArrayList listeners
           
protected  int maxHeight
           
protected  int maxWidth
           
protected  int minHeight
           
protected  int minWidth
           
protected  int padding
           
protected  int prefHeight
           
protected  int prefWidth
           
protected  boolean shadow
           
 
Fields inherited from class org.formaria.swing.Panel
arc, BORDER_BEVEL, BORDER_FLAT, BORDER_NONE, drawBorder, translucent, usesLaf
 
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
CaptionedImage()
          Creates a new instance of CaptionedImage
 
Method Summary
 void add(java.lang.Object c, java.lang.Object constraint)
          Add a child component
 void addCaptionListener(java.awt.event.MouseListener l)
          Adds a mouse listener to this component to listen for mouse events.
 int findCurrentResponse(int x, int y)
          Find the response corresponding to the current point
protected  void fireActionPerformed(java.awt.event.MouseEvent event)
          Notifies all mouse listeners that have registered interest for notification on mouse event types.
 int getAlignment()
          Get the alignment style constant
 int getBorders()
          Gets the border flag value.
 java.lang.String getCaption()
          Get the caption
 java.lang.String getCaptionStyle()
          Get the caption style
 java.lang.Object getChildComponent(int i)
          Get a child component
 boolean getFillBorder()
          Gets the fill border flag value.
 Image getImage()
          Returns the Image instance used by ths class.
 java.lang.String getImageName()
          Gets the name of the image being displayed.
 java.lang.String getImageStyle()
          Get the image style
 java.awt.Insets getInsets()
          Get the insets
 java.awt.Dimension getMaximumSize()
          Get the maximum component size
 int getMinHeight()
          Get the minimum height of the component
 java.awt.Dimension getMinimumSize()
          Get the minimum component size
 int getMinWidth()
          Get the minimum width of the component
 boolean getOpaque()
          Get the opaque property
 int getPadding()
          Get the padding
 java.awt.Dimension getPreferredSize()
          Get the preferred component size
 boolean getShadow()
          Gets the shadow flag value.
 void mouseClicked(java.awt.event.MouseEvent e)
          Fired when a mouse is clicked on this component.
 void mouseEntered(java.awt.event.MouseEvent e)
          Fired when a mouse enters this component.
 void mouseExited(java.awt.event.MouseEvent e)
          Fired when a mouse exited this component.
 void mousePressed(java.awt.event.MouseEvent e)
          Fired when a mouse is pressed on this component.
 void mouseReleased(java.awt.event.MouseEvent e)
          Fired when a mouse is released on this component.
 void paintComponent(java.awt.Graphics g)
          Update the panel by erasing and then rendering the frame if any
 void paintStates()
          Repaint the responses
 void remove(java.lang.Object c)
          Remove a child component
 void removeCaptionListener(java.awt.event.MouseListener l)
          Removes a mouse listener to this component.
 boolean respond()
          Called by ClickListener to check if a response event should be sent to the parent form.
 void setAlignment(int align)
          Set the alignment attribute
 void setAlignmentString(java.lang.String align)
          Set the alignment attribute
 void setAntiAlias(boolean mode)
          Set the anti-alias mode
 void setArc(int value)
          Set the arc size
 void setBorders(int bv)
          Sets the border flag value.
 void setBuffered(boolean value)
          Set the double buffering on or off
 void setCaption(java.lang.String s)
          Set the caption
 void setCaptionStyle(java.lang.String newStyle)
          Set the caption style
 void setContent(java.lang.String content)
          Set the component content - the image name
 void setDragEnabled(boolean value)
          Set the image as drag enabled
 void setDragInfo(java.lang.Object info)
          Set the drag information
 void setEnabled(boolean state)
          Set the enabled state
 void setImage(java.lang.String value)
          Set the relative path of the image to display
 void setImageName(java.lang.String name)
          Gets the name of the image being displayed.
 void setImageStyle(java.lang.String newStyle)
          Set the image style
 void setMaxHeight(int value)
          Set the maximum height of the component
 void setMaxWidth(int value)
          Set the maximum width of the component
 void setMinHeight(int value)
          Set the minimum height of the component
 void setMinWidth(int value)
          Set the minimum width of the component
 void setName(java.lang.String value)
          Sets the Image instance to have the same name as the instansiating class.
 void setNextAttributes(java.lang.Object attribs)
          Set the attributes for the next component being added
 void setOpaque(boolean value)
          Set the opaque property
 void setPadding(int pad)
          Set the padding
 void setPreferredHeight(int value)
          Set the preferred height of the component
 void setPreferredWidth(int value)
          Set the preferred width of the component
 void setShadow(boolean value)
          Turn on/off the drop shadow
 boolean setState(int x, int y, int defResponse)
          Find a response
 void setStretch(int mode)
          Set the drag information
 void setTooltip(java.lang.String value)
          Set the opaque property
 void setup(java.lang.String name, int preferredWidth, int preferredHeight, java.util.Hashtable params)
          Setup the container
 void updateSelectedState()
          Does nothing in this instance
 
Methods inherited from class org.formaria.swing.Panel
addNotify, getArc, getDrawBorder, getPainter, getUsesLaf, restoreState, saveState, setBlend, setBorder, setBounds, setDrawBorder, setPad, setPainter, setSwingBorder, setTitle, setTitlePos, setTitlePosition, setTitleStyle, setToolTip, setTranslucent, setUsesLaf, update
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getListeners, getLocation, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.formaria.aria.ContentHolder
doLayout, getName
 

Field Detail

image

protected Image image

caption

protected Label caption

imgName

protected java.lang.String imgName

padding

protected int padding

minWidth

protected int minWidth

minHeight

protected int minHeight

maxWidth

protected int maxWidth

maxHeight

protected int maxHeight

prefWidth

protected int prefWidth

prefHeight

protected int prefHeight

borders

protected int borders

shadow

protected boolean shadow

clickListener

protected ClickListener clickListener

listeners

protected java.util.ArrayList listeners

currentProject

protected Project currentProject
The owner project and the context in which this object operates.

Constructor Detail

CaptionedImage

public CaptionedImage()
Creates a new instance of CaptionedImage

Method Detail

setup

public void setup(java.lang.String name,
                  int preferredWidth,
                  int preferredHeight,
                  java.util.Hashtable params)
Setup the container

Specified by:
setup in interface ContentHolder
Parameters:
name - set the container name
preferredWidth - the desired width
preferredHeight - the desired height
params - a table of extra properties

getChildComponent

public java.lang.Object getChildComponent(int i)
Get a child component

Specified by:
getChildComponent in interface ContentHolder
Parameters:
i - the index of the child within the container
Returns:
the child component

add

public void add(java.lang.Object c,
                java.lang.Object constraint)
Add a child component

Specified by:
add in interface ContentHolder
Parameters:
c - the child component
constraint - the layout constraint

remove

public void remove(java.lang.Object c)
Remove a child component

Specified by:
remove in interface ContentHolder
Parameters:
c - the child component

paintStates

public void paintStates()
Repaint the responses

Specified by:
paintStates in interface StateListener

setState

public boolean setState(int x,
                        int y,
                        int defResponse)
Find a response

Specified by:
setState in interface StateListener
Parameters:
x - the x coordinate of the mouse click
y - the y coordinate of the mouse click
defResponse - the default response
Returns:
true if a response was found

findCurrentResponse

public int findCurrentResponse(int x,
                               int y)
Find the response corresponding to the current point

Specified by:
findCurrentResponse in interface StateListener
Parameters:
x - the x coordinate of the mouse click
y - the y coordinate of the mouse click
Returns:
the response value if the mouse were click at the specified location, or -1 if not selection is available

updateSelectedState

public void updateSelectedState()
Does nothing in this instance

Specified by:
updateSelectedState in interface StateListener

respond

public boolean respond()
Called by ClickListener to check if a response event should be sent to the parent form. The control can also use this event to do post click processing

Returns:
true if the parent is to be notified

getMinimumSize

public java.awt.Dimension getMinimumSize()
Get the minimum component size

Overrides:
getMinimumSize in class javax.swing.JComponent
Returns:
the minimum size

getMaximumSize

public java.awt.Dimension getMaximumSize()
Get the maximum component size

Overrides:
getMaximumSize in class javax.swing.JComponent
Returns:
the maximum size

getMinWidth

public int getMinWidth()
Get the minimum width of the component

Returns:
the minimum width

getMinHeight

public int getMinHeight()
Get the minimum height of the component

Returns:
the minimum height

setMinWidth

public void setMinWidth(int value)
Set the minimum width of the component

Parameters:
value - the minimum width

setMinHeight

public void setMinHeight(int value)
Set the minimum height of the component

Parameters:
value - the minimum height

setMaxHeight

public void setMaxHeight(int value)
Set the maximum height of the component

Parameters:
value - the minimum height

setMaxWidth

public void setMaxWidth(int value)
Set the maximum width of the component

Parameters:
value - the minimum height

setPreferredHeight

public void setPreferredHeight(int value)
Set the preferred height of the component

Parameters:
value - the minimum height

setPreferredWidth

public void setPreferredWidth(int value)
Set the preferred width of the component

Parameters:
value - the minimum height

getPreferredSize

public java.awt.Dimension getPreferredSize()
Get the preferred component size

Overrides:
getPreferredSize in class Panel
Returns:
the preferrd size

getOpaque

public boolean getOpaque()
Get the opaque property

Returns:
the opaque flag

setContent

public void setContent(java.lang.String content)
Set the component content - the image name

Specified by:
setContent in interface ContentHolder
Parameters:
the - content value

getInsets

public java.awt.Insets getInsets()
Get the insets

Overrides:
getInsets in class Panel
Returns:
the insets

setEnabled

public void setEnabled(boolean state)
Set the enabled state

Overrides:
setEnabled in class javax.swing.JComponent

paintComponent

public void paintComponent(java.awt.Graphics g)
Description copied from class: Panel
Update the panel by erasing and then rendering the frame if any

Overrides:
paintComponent in class Panel
Parameters:
g - the graphics context

getPadding

public int getPadding()
Get the padding

Returns:
the padding

setPadding

public void setPadding(int pad)
Set the padding

Parameters:
the - padding

getAlignment

public int getAlignment()
Get the alignment style constant

Returns:
the alignment value

setAlignment

public void setAlignment(int align)
Set the alignment attribute

Parameters:
align - 1 to right align the text, 0 for left alignment and 2 for centered text

setAlignmentString

public void setAlignmentString(java.lang.String align)
Set the alignment attribute

Parameters:
align - left, right, center

setBuffered

public void setBuffered(boolean value)
Set the double buffering on or off


getCaptionStyle

public java.lang.String getCaptionStyle()
Get the caption style

Returns:
the style name

setCaptionStyle

public void setCaptionStyle(java.lang.String newStyle)
Set the caption style

Parameters:
newStyle - the style name

getImageStyle

public java.lang.String getImageStyle()
Get the image style

Returns:
the style name

setImageStyle

public void setImageStyle(java.lang.String newStyle)
Set the image style

Parameters:
newStyle - the style name

getCaption

public java.lang.String getCaption()
Get the caption

Returns:
the caption text

setCaption

public void setCaption(java.lang.String s)
Set the caption

Parameters:
s - the caption text

getShadow

public boolean getShadow()
Gets the shadow flag value.

Returns:
true if he shadow is drawn

getImageName

public java.lang.String getImageName()
Gets the name of the image being displayed.

Returns:
the image name

setImageName

public void setImageName(java.lang.String name)
Gets the name of the image being displayed.

Overrides:
setImageName in class Panel
Parameters:
name - the new translucency

getFillBorder

public boolean getFillBorder()
Gets the fill border flag value.

Returns:
true if the area within the border is filled

getBorders

public int getBorders()
Gets the border flag value.

Returns:
the border property

setBorders

public void setBorders(int bv)
Sets the border flag value.

Parameters:
bv - the border property

setShadow

public void setShadow(boolean value)
Turn on/off the drop shadow

Parameters:
value - true to turn the sthadow on

setImage

public void setImage(java.lang.String value)
Set the relative path of the image to display

Parameters:
value -

setArc

public void setArc(int value)
Set the arc size

Overrides:
setArc in class Panel
Parameters:
value - the arc size

setOpaque

public void setOpaque(boolean value)
Set the opaque property

Overrides:
setOpaque in class javax.swing.JComponent
Parameters:
value - the opaque value true|false

setTooltip

public void setTooltip(java.lang.String value)
Set the opaque property

Parameters:
value - the opaque value true|false

setDragEnabled

public void setDragEnabled(boolean value)
Set the image as drag enabled

Parameters:
value -

setDragInfo

public void setDragInfo(java.lang.Object info)
Set the drag information

Parameters:
info -

setStretch

public void setStretch(int mode)
Set the drag information

Parameters:
info -

setAntiAlias

public void setAntiAlias(boolean mode)
Set the anti-alias mode

Parameters:
mode -

setName

public void setName(java.lang.String value)
Sets the Image instance to have the same name as the instansiating class.

Overrides:
setName in class java.awt.Component
Parameters:
value - String specifying the name given tos this class.

getImage

public Image getImage()
Returns the Image instance used by ths class.

Returns:
Image instance returned.

addCaptionListener

public void addCaptionListener(java.awt.event.MouseListener l)
Adds a mouse listener to this component to listen for mouse events.

Parameters:
l - the MouseListener that is to be added.

removeCaptionListener

public void removeCaptionListener(java.awt.event.MouseListener l)
Removes a mouse listener to this component.

Parameters:
l - the MouseListener that is to be removed.

setNextAttributes

public void setNextAttributes(java.lang.Object attribs)
Set the attributes for the next component being added

Specified by:
setNextAttributes in interface ContentHolder
Parameters:
attribs - a table of attributes

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Fired when a mouse is clicked on this component.

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
e - the passed MouseEvent instance.

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Fired when a mouse is pressed on this component.

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
e - the passed MouseEvent instance.

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Fired when a mouse is released on this component.

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
e - the passed MouseEvent instance.

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Fired when a mouse enters this component.

Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
e - the passed MouseEvent instance.

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Fired when a mouse exited this component.

Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
e - the passed MouseEvent instance.

fireActionPerformed

protected void fireActionPerformed(java.awt.event.MouseEvent event)
Notifies all mouse listeners that have registered interest for notification on mouse event types. The event instance is lazily created using the event parameter.

Parameters:
event - the MouseEvent object