NGP.Graphics
Class Image

java.lang.Object
  extended byNGP.Graphics.Image
All Implemented Interfaces:
EventListener, Graphic, Locatable, MouseListener, MouseMotionListener, Reactor, Rotatable, Sizeable

public class Image
extends Object
implements Graphic, Locatable, Sizeable

An image that knows how to draw itself on the screen.

Author:
Matt Chotin (mhc)

Constructor Summary
Image(DrawingPanel dp, String file)
          Create an image from a filename.
Image(DrawingPanel dp, URL url)
          Create an image from a URL.
 
Method Summary
 boolean contains(Point p)
          See if this Image contains the Point
 void drag(MouseEvent e)
          Override to do something useful.
 Image getAWTImage()
          Get the AWT Image that we are using, not necessary for most users.
 Rectangle getBounds()
          Get the rectangle that indicates the bounds of this Image
 Point getCenterLocation()
          Return the Point that represents the center of the bounding rectangle of this shape.
 Dimension getDimension()
          Get the dimensions of this Image
 DrawingPanel getDrawingPanel()
          Get the DrawingPanel for this Image
 Point getLocation()
          Get the location of this Image
 int getRotation()
          Get the rotation for this Image
 void hide()
          Hide the Image so it won't paint
 boolean intersects(Graphic g)
          Determine whether the passed in Graphic intersects with this Image.
 void mouseClicked(MouseEvent e)
          Called when the Panel detects that the mouse was clicked.
 void mouseDragged(MouseEvent e)
          Called when the Panel detects that the mouse was dragged.
 void mouseEntered(MouseEvent e)
          Called when the Panel detects that the mouse entered.
 void mouseExited(MouseEvent e)
          Called when the Panel detects that the mouse exited.
 void mouseMoved(MouseEvent e)
          Called when the Panel detects that the mouse was moved.
 void mousePressed(MouseEvent e)
          Called when the Panel detects that the mouse was pressed.
 void mouseReleased(MouseEvent e)
          Called when the Panel detects that the mouse was released.
 void paint(Graphics2D g)
          Normal users need not use this!
 void react()
          Override to do something useful.
 void setCenterLocation(Point p)
          Set the location of the Image so that its center point is at the specified location.
 void setDimension(Dimension d)
          Set the dimensions of this Image
 void setDrawingPanel(DrawingPanel dp)
          Set the DrawingPanel for this Image
 void setLocation(Point p)
          Set the location of this Image
 void setRotation(int degrees)
          Set the rotation for this Image
protected  void setup(DrawingPanel dp)
          Normal users need not use this!
 void show()
          Show the Image so it paints
 void unwrap()
          Set this image so that it will does not necessarily display in its DrawingPanel
 void wrap()
          Set this image so that it will always display in its DrawingPanel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Image

public Image(DrawingPanel dp,
             String file)
Create an image from a filename.

Parameters:
dp - the DrawingPanel for this image
file - the filename to take this image form (gif or jpg)

Image

public Image(DrawingPanel dp,
             URL url)
Create an image from a URL.

Parameters:
dp - the DrawingPanel for this image
url - the URL to take this image form (gif or jpg)
See Also:
createURL
Method Detail

setup

protected void setup(DrawingPanel dp)
Normal users need not use this!

Use the media tracker to load the image, then initialize everything else.


setDimension

public void setDimension(Dimension d)
Set the dimensions of this Image

Specified by:
setDimension in interface Sizeable
Parameters:
d - the new Dimension for this Image
See Also:
getDimension

getDimension

public Dimension getDimension()
Get the dimensions of this Image

Specified by:
getDimension in interface Sizeable
Returns:
the Dimension for this Image
See Also:
setDimension

setLocation

public void setLocation(Point p)
Set the location of this Image

Specified by:
setLocation in interface Locatable
Parameters:
p - the new Point for this Image
See Also:
getLocation

setCenterLocation

public void setCenterLocation(Point p)
Set the location of the Image so that its center point is at the specified location.

Parameters:
p - the new Point for the center of this Image

getLocation

public Point getLocation()
Get the location of this Image

Specified by:
getLocation in interface Locatable
Returns:
the Point for this Image
See Also:
setLocation

hide

public void hide()
Hide the Image so it won't paint

Specified by:
hide in interface Graphic

show

public void show()
Show the Image so it paints

Specified by:
show in interface Graphic

setDrawingPanel

public void setDrawingPanel(DrawingPanel dp)
Set the DrawingPanel for this Image

Specified by:
setDrawingPanel in interface Graphic
Parameters:
dp - the new DrawingPanel for the Image
See Also:
getDrawingPanel

getDrawingPanel

public DrawingPanel getDrawingPanel()
Get the DrawingPanel for this Image

Specified by:
getDrawingPanel in interface Graphic
Returns:
the DrawingPanel for the Image
See Also:
setDrawingPanel

getAWTImage

public Image getAWTImage()
Get the AWT Image that we are using, not necessary for most users.

Returns:
the real AWT image

contains

public boolean contains(Point p)
See if this Image contains the Point

Specified by:
contains in interface Graphic
Parameters:
p - the Point to test
Returns:
true if the Point is contained, false otherwise

setRotation

public void setRotation(int degrees)
Set the rotation for this Image

Specified by:
setRotation in interface Rotatable
Parameters:
degrees - the degrees (clockwise) that this should rotate
See Also:
getRotation

getRotation

public int getRotation()
Get the rotation for this Image

Specified by:
getRotation in interface Rotatable
Returns:
the degrees (clockwise) that this should rotate
See Also:
setRotation

paint

public void paint(Graphics2D g)
Normal users need not use this!

Rotate the Graphics Context if necessary, the paint, then reset the rotation

Specified by:
paint in interface Graphic
Parameters:
g - the Graphics2D to use when painting

wrap

public void wrap()
Set this image so that it will always display in its DrawingPanel


unwrap

public void unwrap()
Set this image so that it will does not necessarily display in its DrawingPanel


getBounds

public Rectangle getBounds()
Get the rectangle that indicates the bounds of this Image

Specified by:
getBounds in interface Graphic
Returns:
the java.awt.Rectangle that indicates our bounds.

getCenterLocation

public Point getCenterLocation()
Return the Point that represents the center of the bounding rectangle of this shape.

Specified by:
getCenterLocation in interface Graphic
Returns:
the java.awt.Point of the center of this shape

intersects

public boolean intersects(Graphic g)
Determine whether the passed in Graphic intersects with this Image.

Specified by:
intersects in interface Graphic
Parameters:
g - the Graphic to test
Returns:
true if they do intersect, false otherwise
See Also:
getBounds

react

public void react()
Override to do something useful.

Specified by:
react in interface Reactor

drag

public void drag(MouseEvent e)
Override to do something useful.


mouseClicked

public void mouseClicked(MouseEvent e)
Called when the Panel detects that the mouse was clicked. If the click is within this Image, react will be called.

Specified by:
mouseClicked in interface MouseListener

mouseDragged

public void mouseDragged(MouseEvent e)
Called when the Panel detects that the mouse was dragged. If this Image is active, then drag will be called.

Specified by:
mouseDragged in interface MouseMotionListener

mouseEntered

public void mouseEntered(MouseEvent e)
Called when the Panel detects that the mouse entered. Does nothing.

Specified by:
mouseEntered in interface MouseListener

mouseExited

public void mouseExited(MouseEvent e)
Called when the Panel detects that the mouse exited. Does nothing.

Specified by:
mouseExited in interface MouseListener

mousePressed

public void mousePressed(MouseEvent e)
Called when the Panel detects that the mouse was pressed. Sets this Image to be active. This means that if the mouse is subsequently dragged, the drag(MouseEvent e) method of the Image will be called.

Specified by:
mousePressed in interface MouseListener

mouseReleased

public void mouseReleased(MouseEvent e)
Called when the Panel detects that the mouse was released. Makes this image inactive if it is active. Ensures that mouse drags that originate outside of this Image will not invoke the drag(MouseEvent e) method.

Specified by:
mouseReleased in interface MouseListener

mouseMoved

public void mouseMoved(MouseEvent e)
Called when the Panel detects that the mouse was moved. Does nothing.

Specified by:
mouseMoved in interface MouseMotionListener