/*     */ package tools;
/*     */ 
/*     */ import java.awt.BasicStroke;
/*     */ import java.awt.Color;
/*     */ import java.awt.Graphics;
/*     */ import java.awt.Graphics2D;
/*     */ import main.ChronoPanel;
/*     */ import signals.Signals;
/*     */ 
/*     */ public class Arrow implements java.io.Serializable
/*     */ {
/*     */   private static final long serialVersionUID = 1L;
/*     */   private ChronoPanel chrono;
/*     */   private Signals fromSignal;
/*     */   private Signals toSignal;
/*     */   private int fromIndex;
/*     */   private int toIndex;
/*     */   private int x0;
/*     */   private int y0;
/*     */   private int x1;
/*     */   private int y1;
/*  22 */   private int l = 9;
/*  23 */   private double offsetAngle = 0.6283185307179586D;
/*  24 */   public boolean selected = false;
/*     */   
/*  26 */   private boolean drawStart = false; private boolean drawEnd = false; private boolean complete = false;
/*     */   
/*     */   public Arrow(ChronoPanel chrono) {
/*  29 */     this.chrono = chrono;
/*  30 */     this.fromIndex = 1;
/*  31 */     this.toIndex = 1;
/*  32 */     this.fromSignal = ((Signals)chrono.signals.get(0));
/*  33 */     this.drawStart = true;
/*     */   }
/*     */   
/*     */   public void setStart(Signals s, int xMouse) {
/*  37 */     this.drawStart = true;
/*  38 */     this.fromSignal = s;
/*  39 */     this.fromIndex = Math.max(1, (int)((xMouse - Signals.leftSpace + s.widthUnit / 4.0F) * 2.0F / s.widthUnit));
/*  40 */     if (s.clkToQdelay) this.fromIndex = Math.max(1, (int)((xMouse - Signals.leftSpace + s.widthUnit / 2 + s.widthUnit / 4.0F) * 2.0F / s.widthUnit));
/*     */   }
/*     */   
/*     */   public void setEnd(Signals s, int xMouse) {
/*  44 */     this.drawStart = false;
/*  45 */     this.drawEnd = true;
/*  46 */     this.toSignal = s;
/*  47 */     this.toIndex = Math.max(1, (int)((xMouse - Signals.leftSpace + s.widthUnit / 4.0F) * 2.0F / s.widthUnit));
/*  48 */     if (s.clkToQdelay) this.toIndex = Math.max(1, (int)((xMouse - Signals.leftSpace + s.widthUnit / 2 + s.widthUnit / 4.0F) * 2.0F / s.widthUnit));
/*     */   }
/*     */   
/*     */   public void done() {
/*  52 */     this.drawEnd = false;
/*  53 */     this.complete = true;
/*     */   }
/*     */   
/*     */   public void draw(Graphics g)
/*     */   {
/*  58 */     if (this.drawStart) {
/*  59 */       updatePositions(true, false);
/*  60 */       g.setColor(Color.BLACK);
/*  61 */       g.fillOval(this.x0 - 2, this.y0 - 2, 5, 5);
/*     */     }
/*  63 */     if (this.drawEnd) {
/*  64 */       updatePositions(false, true);
/*  65 */       g.setColor(Color.BLACK);
/*  66 */       g.fillOval(this.x1 - 2, this.y1 - 2, 5, 5);
/*     */     }
/*  68 */     if ((this.drawEnd) || (this.complete)) {
/*  69 */       if (this.complete) updatePositions(true, true);
/*  70 */       Graphics2D g2 = (Graphics2D)g;
/*  71 */       if ((!this.drawEnd) && (this.selected)) g2.setStroke(new BasicStroke(3.0F)); else {
/*  72 */         g2.setStroke(new BasicStroke(1.0F));
/*     */       }
/*  74 */       g.setColor(new Color(80, 80, 80));
/*  75 */       g.drawLine(this.x0, this.y0, this.x1, this.y1);
/*  76 */       double alpha = -1.5707963267948966D;
/*  77 */       if (this.x1 != this.x0) alpha = Math.atan((this.y1 - this.y0) / (this.x1 - this.x0));
/*  78 */       if (this.x1 < this.x0) alpha += 3.141592653589793D;
/*  79 */       g.drawLine(this.x1, this.y1, (int)(this.x1 - this.l * Math.cos(alpha + this.offsetAngle)), (int)(this.y1 - this.l * Math.sin(alpha + this.offsetAngle)));
/*  80 */       g.drawLine(this.x1, this.y1, (int)(this.x1 - this.l * Math.cos(alpha - this.offsetAngle)), (int)(this.y1 - this.l * Math.sin(alpha - this.offsetAngle)));
/*     */     }
/*     */   }
/*     */   
/*     */   public void updatePositions(boolean start, boolean end)
/*     */   {
/*  86 */     if (start) {
/*  87 */       this.x0 = (Signals.leftSpace + this.fromIndex * this.fromSignal.widthUnit / 2);
/*  88 */       if (this.fromSignal.clkToQdelay) this.x0 -= this.fromSignal.widthUnit / 2;
/*  89 */       this.y0 = (this.chrono.getPosFromId(this.fromSignal.id) * (Signals.heightUnit + Signals.Yspace) + Signals.Yspace);
/*     */       
/*  91 */       if (this.fromIndex % 2 != 0) {
/*  92 */         if (this.fromSignal.wave[(this.fromIndex / 2)] == 0) { this.y0 += Signals.heightUnit;
/*     */         }
/*     */       }
/*  95 */       else if (this.fromSignal.wave[(this.fromIndex / 2 - 1)] != this.fromSignal.wave[(this.fromIndex / 2)]) {
/*  96 */         this.y0 += Signals.heightUnit / 2;
/*     */ 
/*     */       }
/*  99 */       else if (this.fromSignal.wave[(this.fromIndex / 2)] == 0) { this.y0 += Signals.heightUnit;
/*     */       }
/*     */     }
/*     */     
/* 103 */     if (end) {
/* 104 */       this.x1 = (Signals.leftSpace + this.toIndex * this.toSignal.widthUnit / 2);
/* 105 */       if (this.toSignal.clkToQdelay) this.x1 -= this.toSignal.widthUnit / 2;
/* 106 */       this.y1 = (this.chrono.getPosFromId(this.toSignal.id) * (Signals.heightUnit + Signals.Yspace) + Signals.Yspace);
/*     */       
/* 108 */       if (this.toIndex % 2 != 0) {
/* 109 */         if (this.toSignal.wave[(this.toIndex / 2)] == 0) { this.y1 += Signals.heightUnit;
/*     */         }
/*     */       }
/* 112 */       else if (this.toSignal.wave[(this.toIndex / 2 - 1)] != this.toSignal.wave[(this.toIndex / 2)]) {
/* 113 */         this.y1 += Signals.heightUnit / 2;
/*     */ 
/*     */       }
/* 116 */       else if (this.toSignal.wave[(this.toIndex / 2)] == 0) { this.y1 += Signals.heightUnit;
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */   public int getDistance(int xMouse, int yMouse)
/*     */   {
/* 124 */     float a = (this.y1 - this.y0) / (this.x1 - this.x0);
/* 125 */     float b = this.y0 - a * this.x0;
/* 126 */     int distance = (int)(Math.abs(a * xMouse - yMouse + b) / Math.sqrt(1.0F + a * a));
/* 127 */     if (((xMouse < this.x0 - 2) && (xMouse < this.x1 - 2)) || ((xMouse > this.x0 + 2) && (xMouse > this.x1 + 2))) distance = 1000;
/* 128 */     return distance;
/*     */   }
/*     */ }


/* Location:              F:\JAVA\WORKSPACE\chronoEditor_v2.3.jar!\tools\Arrow.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */