package ITUannotation;

import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.geom.QuadCurve2D;
import java.awt.geom.Rectangle2D;

import javax.swing.JComponent;

public class Arrow extends JComponent {
	
	public Arrow() {
	}

	public Arrow(int x1, int y1, int x2, int y2, int height, String str) {
		SourceX = orjSourceX = x1;
		SourceY = orjSourceY = y1;
		DestX= orjDestX = x2;
		DestY = orjDestY = y2;
		TopX = orjTopX = orjSourceX + (orjDestX - orjSourceX) / 2; // tepe noktasi elipse olmasini										// saglamak icin
		TopY = orjTopY = (orjSourceY - 25) - (height * 20);
		this.height = height;

		relation = new Font(str, Font.PLAIN, 12);

		FontMetrics metrics = new FontMetrics(relation) {
		};
		Rectangle2D bounds = metrics.getStringBounds("string", null);
		widthInPixels = (int) bounds.getWidth();

		relationX = orjTopX - (widthInPixels / 2);
		relationY = orjTopY + 33;

		triangleP1 = new Point(orjDestX - 15, orjDestY + 1);
		triangleP2 = new Point(orjDestX - 7, orjDestY - 8);
		triangleP3 = new Point(orjDestX + 1, orjDestY + 1);

		int[] xs = { triangleP1.x, triangleP2.x, triangleP3.x };
		int[] ys = { triangleP1.y, triangleP2.y, triangleP3.y };

		triangle = new Polygon(xs, ys, xs.length);

		q = new QuadCurve2D.Float(orjSourceX, orjSourceY, orjTopX, orjTopY, orjDestX, orjDestY);

	}
	public void setRel(String str){
		relation = new Font(str, Font.PLAIN, 12);
	}
	public int getSourceX() {
		return orjSourceX;
	}

	public int getSourceY() {
		return orjSourceY;
	}
	public void setSourceY(int sy) {
		orjSourceY=sy;
	}
	public void setDestY(int dy) {
		orjDestY=dy;
	}

	public int getDestX() {
		return orjDestX;
	}

	public int getDestY() {
		return orjDestY;
	}

	public int getTopX() {
		return orjTopX;
	}

	public int getTopY() {
		return orjTopY;
	}
	
	public int getChangeTopY(){ // after scrollbar change
		return TopY;
	}

	public Point getTriangleP1() {
		return triangleP1;
	}

	public Point getTriangleP2() {
		return triangleP2;
	}

	public Point getTriangleP3() {
		return triangleP3;
	}

	public QuadCurve2D getQ() {
		return q;
	}

	public Polygon getTriangle() {
		return triangle;
	}

	public QuadCurve2D getQuadCurve() {
		return q;
	}

	public String getRelation() {
		return relation.getName();
	}

	public int getRelationX() {
		return relationX;
	}

	public int getRelationY() {
		return relationY;
	}

	public void setsource(int lnum, int x1, int y1) {
		this.orjSourceX = x1;
		this.orjSourceY = y1;
		this.sourcelabel = lnum;

	}

	public void setdest(int lnum, int cnum, int x2, int y2, String str) {
		this.destlabel = lnum;
		this.destcbox = cnum;
		this.orjDestX = x2;
		orjDestY = y2;
		relation = new Font(str, Font.PLAIN, 12);
	}

	public int getsourcelablnum() {
		return sourcelabel;
	}

	public int getdestlablnum() {
		return destlabel;
	}

	public int getdestcbox() {
		return destcbox;
	}
	public void setdestcbox(int i) {
		destcbox=i;
	}


	public void setRelationY(int relationY) {
		this.relationY = relationY;
	}

	public QuadCurve2D getQuadra() {
		return q;
	}

	public void setStartCheckBoxIndex(int i) {
		startCheckBoxIndex = i;
	}

	public void setfirstClickedCheckBox(int i) {
		startCheckBoxIndex = i;
	}

	public int getFirstClickedCheckBox() {
		return startCheckBoxIndex;
	}
	public void drawArc( int a, int a2) { // a = horizontal scrollbar,, a2 = vertical scrollbar
		if(a!=0||a2 != 0){
			DestX = orjDestX;
			SourceX = orjSourceX ;
			SourceY = orjSourceY;
			DestY= orjDestY;
			if(a!=0)
			{
				DestX = orjDestX - a;
				SourceX = orjSourceX - a;
			}
			if(a2!=0){
				SourceY = orjSourceY - a2;
				DestY= orjDestY - a2;
			}

		TopX = SourceX + (DestX - SourceX) / 2; 								
		TopY = (SourceY - 25) - (height * 20);
		relationX = TopX - (widthInPixels / 2);
		relationY = TopY + 33;
		triangleP1 = new Point(DestX - 15,DestY + 1);
		triangleP2 = new Point(DestX - 7, DestY - 8);
		triangleP3 = new Point(DestX + 1, DestY + 1);
		
		int[] xs = { triangleP1.x, triangleP2.x, triangleP3.x };
		int[] ys = { triangleP1.y, triangleP2.y, triangleP3.y };

		triangle = new Polygon(xs, ys, xs.length);
		
		q = new QuadCurve2D.Float(SourceX, SourceY, TopX, TopY, DestX, DestY);
		}
		else{
			triangleP1 = new Point(orjDestX - 15, orjDestY + 1);
			triangleP2 = new Point(orjDestX - 7, orjDestY - 8);
			triangleP3 = new Point(orjDestX + 1, orjDestY + 1);
			
			int[] xs = { triangleP1.x, triangleP2.x, triangleP3.x };
			int[] ys = { triangleP1.y, triangleP2.y, triangleP3.y };

			triangle = new Polygon(xs, ys, xs.length);
			relationX = orjTopX - (widthInPixels / 2);
			relationY = orjTopY + 33;
			q = new QuadCurve2D.Float(orjSourceX, orjSourceY, orjTopX, orjTopY, orjDestX, orjDestY);
		}
	}
	private int SourceY;
	private int DestY;
	private int SourceX;
	private int DestX;
	private int TopX;
	private int TopY;
	
	private int orjSourceX;
	private int orjSourceY;
	private int orjDestX;
	private int orjDestY;
	private int orjTopX;
	private int orjTopY;
	private Font relation;
	private int relationX;
	private int relationY;
	private Point triangleP1;
	private Point triangleP2;
	private Point triangleP3;
	private Polygon triangle;
	private QuadCurve2D q;

	private int sourcelabel;
	private int destlabel;
	private int destcbox;
	private int startCheckBoxIndex;
	private int height;
	private int widthInPixels;
	public void setQuadCurve() {
		q = new QuadCurve2D.Float(SourceX, orjSourceY, TopX, TopY, DestX, orjDestY);
		
	}

}
