/**
 *
 * Die Zeichenobjekte für das Grafikprogramm
 *
 * @version 1.0 vom 27.05.02
  * @ Xenia Rendtel
  */

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.event.*;
import java.io.*;
import java.lang.*;



abstract class Grafikeindim implements Serializable{

    protected int x1, y1, x2, y2;
    protected Color farbe;  // die Variablem
    protected Color ffarbe;
    protected boolean ausgewaehlt = false;


    public void SetzePos(int x1, int y1) {  // Anfangsposition setzen
        this.x1 = x1;
        this.y1 = y1;

    }

    public void SetzePosrel(int x, int y) { //anfang auf x,y, Verhältnisse aber beibehalten
        this.x2 = this.x2-this.x1+x;
        this.y2 = this.y2-this.y1+y;
        this.x1 = x;
        this.y1 = y;
    }

    public void SetzePositionen(int x1, int y1, int x2, int y2) {
        this.x1 = Math.min(x1, x2);
        this.y1 = Math.min(y1, y2);
        this.x2 = Math.max(x1, x2);
        this.y2 = Math.max(y1, y2);
    }


    // die einzelnen Positionen
    public int LeseX1() {
        return x1;
    }

    public int LeseY1() {
        return y1;
    }

    public int LeseX2() {
        return x2;
    }

    public int LeseY2() {
        return y2;
    }



    // Farben werden gesetzt
    public void SetzeFarbe(Color farbe) {
        this.farbe = farbe;
    }

    public Color LeseFarbe() {
        return this.farbe;
    }



    public abstract void Zeichne(Graphics g);
    public abstract boolean contains(Point p);
}


class Punkt extends Grafikeindim {

    /* in der Zeichne Methode ist auch das zeichnen enthalten,
       was man nutzt, wenn man etwas auswählt */
    public void Zeichne(Graphics g) { // Ein Punkt ist eine Linie ohne Ausdehnung
        g.setColor(farbe);
        g.drawLine(x1, y1, x1, y1);
        if (ausgewaehlt == true) {
            g.setColor(new Color(255,0,255));
            g.drawRect(x1-3, y1-3, 6, 6);            // etwas größer, damit man was sieht
        }
    }



    public boolean contains(Point p) {
        return (new Rectangle(x1-1, y1-1, 3, 3).contains(p));
    }
}




abstract class Grafikzweidim  extends Grafikeindim {

    protected Color ffarbe;



    public void SetzePositionen(int x1, int y1, int x2, int y2) {
        this.x1 = Math.min(x1, x2);
        this.y1 = Math.min(y1, y2);
        this.x2 = Math.max(x1, x2);
        this.y2 = Math.max(y1, y2);
     }





    public void Zeichne(Graphics g) {
            if (ausgewaehlt == true) {
                g.setColor(new Color(255,0,255));
                g.drawRect(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1 - x2),
                           Math.abs(y1 - y2));
            }
    }

     public boolean contains(Point p) {
         return (new Rectangle(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1 - x2),
                               Math.abs(y1 - y2)).contains(p));
     }


}

interface Voll {
    public abstract void SetzeFuellfarbe(Color ffarbe);
    public abstract Color LeseFuellfarbe();
}




class Strecke extends Grafikzweidim {

    public void Zeichne(Graphics g) {
        if (ausgewaehlt == true) {
            g.setColor(new Color(255,0,255));
            g.drawLine(x1+2, y1, x2 +2, y2);
            g.drawLine(x1-2, y1, x2 -2, y2);
            g.drawLine(x1-2, y1, x1 +2, y1);
            g.drawLine(x2-2, y2, x2 +2, y2);
        }
        g.setColor(farbe);
        g.drawLine(x1, y1, x2, y2);
    }


    public boolean contains(Point p) {
        return (new Rectangle(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1 - x2),
                              Math.abs(y1 - y2)).contains(p));
    }
    public void SetzePositionen(int x1, int y1, int x2, int y2) {
        this.x1 = x1;
        this.y1 = y1;
        this.x2 = x2;
        this.y2 = y2;
    }
}


class Rechteck extends Grafikzweidim {

    /* es werden hier die Anfangs und Endpositionen angegeben und nicht
       Höhe und Breite, da man dies später dann als die Mauspositionen
       übergeben kann
       Es gibt hier wie bei Störe meine Kreisenicht vier Fälle, wo die zweite Position
       liegen kann, diese werden im folgenden abgearbeitet.
    */

    public void Zeichne(Graphics g) {
          if (ausgewaehlt == true) {
              g.setColor(new Color(255,0,255));
              g.drawRect(x1-2, y1-2, x2 - x1+4, y2 - y1+4);
          }
          g.setColor(farbe);
          g.drawRect(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1 - x2),
                     Math.abs(y1 - y2));
    }




}



class Rechteckgef extends Rechteck implements Voll {

    public void Zeichne(Graphics g) {
        if (ausgewaehlt == true) {
            g.setColor(new Color(255,0,255));
            g.drawRect(x1-2, y1-2, x2 - x1+4, y2 - y1+4);
        }
        g.setColor(ffarbe);
        g.fillRect(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1 - x2),
                   Math.abs(y1 - y2));
        g.setColor(farbe);
        g.drawRect(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1 - x2),
                   Math.abs(y1 - y2));

    }


       //Setzen der Füllfarbe
    public void SetzeFuellfarbe(Color ffarbe) {
        this.ffarbe = ffarbe;
    }

    public Color LeseFuellfarbe() {
        return this.ffarbe;
    }

}


class Oval extends Grafikzweidim {

      public void Zeichne(Graphics g) {
          if (ausgewaehlt == true) {
              g.setColor(new Color(255,0,255));
              g.drawOval(x1-2, y1-2, x2 - x1+4, y2 - y1+4);
          }
          g.setColor(farbe);
          g.drawOval(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1 - x2),
                     Math.abs(y1 - y2));

      }



}


class Ovalgef extends Oval implements Voll {

    public void Zeichne(Graphics g) {
        if (ausgewaehlt == true) {
            g.setColor(new Color(255,0,255));
            g.drawOval(x1-2, y1-2, x2 - x1+4, y2 - y1+4);
        }
        g.setColor(ffarbe);
        g.fillOval(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1 - x2),
                   Math.abs(y1 - y2));
        g.setColor(farbe);
        g.drawOval(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1 - x2),
                   Math.abs(y1 - y2));

    }

       //Setzen der Füllfarbe
    public void SetzeFuellfarbe(Color ffarbe) {
        this.ffarbe = ffarbe;
    }


    public Color LeseFuellfarbe() {
        return this.ffarbe;
    }


    public boolean contains(Point p) {
        return (new Rectangle(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1 - x2),
                              Math.abs(y1 - y2)).contains(p));
    }


}



