package DDrawing;

import java.awt.* ;


public class DPoint extends DComponent{
  public double x;
  public double y;
  public String label;

  public DPoint( double x, double y ){
    this.x = x;
    this.y = y;
    rectangle = new DRectangle( x, y, 0, 0 );
  }

  public void paint( DMeasures m ){
    Graphics g = m.getGraphics();
    Color old_color = g.getColor();
    if( color != null ) g.setColor( color );
    else g.setColor( DEFAULT_COLOR );
    Point dp = m.getPoint( this );
    g.drawRect( dp.x, dp.y, 1, 1 );
    if( label != null ){
      FontMetrics fm = g.getFontMetrics();
      g.drawString( label,
                    dp.x - fm.stringWidth( label ) / 2,
                    dp.y + fm.getAscent()
      );
    }
    g.setColor( old_color );
  }
  public Object clone(){
    DPoint copy = new DPoint( x, y );
    copy.color = color;
    return copy;
  }
  public String toString(){
    String text = "DPoint[";
    if( label != null ) text += label+", ";
    text += "x: "+x+", y: "+y+", color: "+color+"]";
    return text;
  }
}