package DDrawing;


import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.image.ImageObserver;


/**
 * @author  mkron
 */
public class DImage extends DRectangle{
  Image image;
  ImageObserver observer;

  public DImage( double x, double y, double width, double height, ImageObserver observer ){
    super( x, y, width, height );
    this.observer = observer;
  }

  public void paint( DMeasures m ){
    Graphics g = m.getGraphics();
    DParent parent = getDParent();
    Point p1 = m.getPoint( x, y ),
          p2 = m.getPoint( x + width, y + height );
    if( image == null ) g.drawRect( p1.x, p2.y, p2.x - p1.x, p1.y - p2.y );
    else g.drawImage( image, p1.x, p2.y, p2.x - p1.x, p1.y - p2.y, observer );
  }

  public void setImage( Image img ){
    if( img.equals( image ) ) return;
    image = img;
    repaint();
  }
}