net.lucidviews.util.gui.swing
Class FloatingImage

java.lang.Object
  extended by net.lucidviews.util.gui.swing.FloatingImage
All Implemented Interfaces:
MouseListener, EventListener

public class FloatingImage
extends Object
implements MouseListener

An image that can be positioned at any given co-ordinate.
Once created you will need to explicitly call paint, usually from within the paint method of the parent component.
e.g.

public class MyPanel extends JPanel
 {

   ...
   protected static final Image THE_IMAGE
            = Toolkit.getDefaultToolkit().createImage( "some/file/path.gif" );
   ...

   public MyPanel()
   {
     ...
     _floatingImage = new FloatingImage( THE_IMAGE, this );
     ...
   }

   ...

   public void paint( Graphics g )
   {
     super.paint( g );

     // paint the floating image, which is a non-standard component
     _floatingImage.paint( g );
   }

 }
 


Since:
1.0
Version:
$Revision: 1.3 $
Author:
Stephen Battey

Field Summary
protected  boolean _displayed
          A flag indicating if this image is to be rendered.
protected  Image _image
          The image to be displayed.
protected  Collection _mouseListeners
          A collection of MouseListeners listening for events from this object.
protected  Component _parentComponent
          The UI component that this image component is contained within.
protected  int _xPos
          The x position of the left edge of the image, relative to the Graphics context passed to the paint method.
protected  int _yPos
          The y position of the top edge of the image, relative to the Graphics context passed to the paint method.
protected static int DEFAULT_X_POS
          The initial _xPos value.
protected static int DEFAULT_Y_POS
          The initial _yPos value.
 
Constructor Summary
FloatingImage(Image image, Component parentComponent)
          Create a floating image to be displayed at the top-left corner of the specified parent component.
FloatingImage(Image image, int xPos, int yPos, Component parentComponent)
          Create a floating image to be displayed at a given position, relative to the specified parent component.
FloatingImage(Image image, Point location, Component parentComponent)
          Create a floating image to be displayed at a given position, relative to the specified parent component.
 
Method Summary
 void addMouseListener(MouseListener listener)
          Register a listener that wants to be notified of mouse events on the floating image.
 int getHeight()
           
 Point getPosition()
           
 int getWidth()
           
 int getXPosition()
           
 int getYPosition()
           
 boolean isAtLocation(Point location)
          Determines if the image sits over a particular point.
 void mouseClicked(MouseEvent e)
           
 void mouseEntered(MouseEvent e)
           
 void mouseExited(MouseEvent e)
           
 void mousePressed(MouseEvent e)
           
 void mouseReleased(MouseEvent e)
           
 void paint(Graphics g)
          Render the image.
 void removeMouseListener(MouseListener listener)
          Un-register a listener that does not want to be notified of mouse events on the floating image.
 void setDisplayed(boolean display)
          Set the display status of the image.
 void setPosition(int xPos, int yPos)
          Move the image to a given location.
 void setPosition(Point position)
           
 void setXPosition(int xPos)
           
 void setYPosition(int yPos)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_X_POS

protected static final int DEFAULT_X_POS
The initial _xPos value.

See Also:
Constant Field Values

DEFAULT_Y_POS

protected static final int DEFAULT_Y_POS
The initial _yPos value.

See Also:
Constant Field Values

_image

protected Image _image
The image to be displayed.


_xPos

protected int _xPos
The x position of the left edge of the image, relative to the Graphics context passed to the paint method.


_yPos

protected int _yPos
The y position of the top edge of the image, relative to the Graphics context passed to the paint method.


_parentComponent

protected Component _parentComponent
The UI component that this image component is contained within.


_displayed

protected boolean _displayed
A flag indicating if this image is to be rendered.


_mouseListeners

protected Collection _mouseListeners
A collection of MouseListeners listening for events from this object.

Constructor Detail

FloatingImage

public FloatingImage(Image image,
                     int xPos,
                     int yPos,
                     Component parentComponent)
Create a floating image to be displayed at a given position, relative to the specified parent component.

Parameters:
image - the image to be rendered
xPos - the x co-ordinate of the left edge of the image, relative to the left edge of the parent component
yPos - the y co-ordinate of the top edge of the image, relative to the top edge of the parent component
parentComponent - the parent component

FloatingImage

public FloatingImage(Image image,
                     Point location,
                     Component parentComponent)
Create a floating image to be displayed at a given position, relative to the specified parent component.

Parameters:
image - the image to be rendered
location - the co-ordinates of the top-left corner of the image, relative to the top-left corner of the parent component
parentComponent - the parent component

FloatingImage

public FloatingImage(Image image,
                     Component parentComponent)
Create a floating image to be displayed at the top-left corner of the specified parent component.

Parameters:
image - the image to be rendered
parentComponent - the parent component
Method Detail

mouseClicked

public void mouseClicked(MouseEvent e)
Specified by:
mouseClicked in interface MouseListener

mousePressed

public void mousePressed(MouseEvent e)
Specified by:
mousePressed in interface MouseListener

mouseReleased

public void mouseReleased(MouseEvent e)
Specified by:
mouseReleased in interface MouseListener

mouseEntered

public void mouseEntered(MouseEvent e)
Specified by:
mouseEntered in interface MouseListener

mouseExited

public void mouseExited(MouseEvent e)
Specified by:
mouseExited in interface MouseListener

addMouseListener

public void addMouseListener(MouseListener listener)
Register a listener that wants to be notified of mouse events on the floating image.

Parameters:
listener - object that is to receive notifications

removeMouseListener

public void removeMouseListener(MouseListener listener)
Un-register a listener that does not want to be notified of mouse events on the floating image.

Parameters:
listener - object that is no longer to receive notifications

setPosition

public void setPosition(Point position)

setXPosition

public void setXPosition(int xPos)

setYPosition

public void setYPosition(int yPos)

getPosition

public Point getPosition()

getXPosition

public int getXPosition()

getYPosition

public int getYPosition()

getWidth

public int getWidth()

getHeight

public int getHeight()

isAtLocation

public boolean isAtLocation(Point location)
Determines if the image sits over a particular point.
The point should be relative to the top-left corner of the parent component.

Parameters:
location - a Point on the parent component
Returns:
a flag indicating if the image can be found at the given location

setPosition

public void setPosition(int xPos,
                        int yPos)
Move the image to a given location.

Parameters:
xPos - the x co-ordinate of the left edge of the image, relative to the left edge of the parent component
yPos - the y co-ordinate of the top edge of the image, relative to the top edge of the parent component

setDisplayed

public void setDisplayed(boolean display)
Set the display status of the image.

Parameters:
display - indicates if the image is to be displayed

paint

public void paint(Graphics g)
Render the image.

Parameters:
g - the graphics context onto which the image is to be drawn