/*     */ package signals;
/*     */ 
/*     */ import java.awt.BasicStroke;
/*     */ import java.awt.Color;
/*     */ import java.awt.FontMetrics;
/*     */ import java.awt.Graphics;
/*     */ import java.awt.Graphics2D;
/*     */ import java.awt.Stroke;
/*     */ import java.awt.geom.Rectangle2D;
/*     */ import java.awt.geom.Rectangle2D.Float;
/*     */ import java.io.Serializable;
/*     */ import main.ChronoPanel;
/*     */ 
/*     */ public abstract class Signals
/*     */   implements Serializable
/*     */ {
/*     */   private static final long serialVersionUID = 1L;
/*  18 */   public static int leftSpace = 80;
/*  19 */   public static int Yspace = 20;
/*  20 */   public static int heightUnit = 25;
/*  21 */   private static int idBank = 0;
/*     */   
/*  23 */   public int id = -1;
/*  24 */   public int widthUnit = 20;
/*     */   public String name;
/*  26 */   public int setUpTime = 0;
/*  27 */   public boolean bus = false;
/*  28 */   public boolean clock = false;
/*  29 */   public boolean dependsOnClk = false;
/*  30 */   public float ratio = 1.0F;
/*     */   public int clockDomainId;
/*  32 */   public boolean selected_for_edit = false;
/*  33 */   public boolean clkToQdelay = false;
/*  34 */   public boolean displayRisingEdges = false;
/*  35 */   public boolean bold = false;
/*  36 */   public Color color = Color.black;
/*     */   
/*  38 */   public transient boolean selected = false;
/*     */   
/*  40 */   public int[] wave = new int['Ǵ'];
/*  41 */   protected String[] busNames = new String['Ǵ'];
/*  42 */   protected boolean[] busFill = new boolean['Ǵ'];
/*     */   
/*     */   public abstract void generate(boolean paramBoolean);
/*     */   
/*     */   public static void resetIdBank() {
/*  47 */     idBank = 0;
/*     */   }
/*     */   
/*     */   public static void setIdBank(int id) {
/*  51 */     idBank = id;
/*     */   }
/*     */   
/*     */   protected void setId() {
/*  55 */     this.id = idBank;
/*  56 */     idBank += 1;
/*     */   }
/*     */   
/*     */   public void setWave(int x, boolean toggle) {
/*  60 */     int newValue = 0;
/*  61 */     if (this.clkToQdelay) x += this.widthUnit / 2;
/*  62 */     if (!this.clock) {
/*  63 */       int value = this.wave[((x - leftSpace) / this.widthUnit)];
/*  64 */       if (value == 0) newValue = 1;
/*  65 */       if (value == 1) newValue = 0;
/*  66 */       int i = 0;
/*     */       do
/*     */       {
/*  69 */         this.wave[((x - leftSpace) / this.widthUnit + i)] = newValue;
/*  70 */         i++;
/*  71 */       } while (((x - leftSpace) / this.widthUnit + i < 500) && (this.wave[((x - leftSpace) / this.widthUnit + i)] == value) && (toggle));
/*     */       
/*  73 */       if (this.bus) {
    
/*  74 */         if (this.busNames[((x - leftSpace) / this.widthUnit)] != null) 
                    {   setBusName(x, this.busNames[((x - leftSpace) / this.widthUnit)]);
                    
                    }
/*  75 */         if (this.busFill[((x - leftSpace) / this.widthUnit)] != false) 
{
    setBusFill(x, false);
}
/*  76 */         while ((x - leftSpace) / this.widthUnit + i < 500) {
/*  77 */           if (this.wave[((x - leftSpace) / this.widthUnit + i)] == 0) {
/*  78 */             this.wave[((x - leftSpace) / this.widthUnit + i)] = 1;
/*     */           }
/*  80 */           else if (this.wave[((x - leftSpace) / this.widthUnit + i)] == 1) {
/*  81 */             this.wave[((x - leftSpace) / this.widthUnit + i)] = 0;
/*     */           }
/*  83 */           i++;
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public void setBusName(int x, String s) {
/*  90 */     int indice = (x - leftSpace) / this.widthUnit;
/*  91 */     for (int i = getFirstChange(x); i < getNextChange(indice); i++) this.busNames[i] = null;
/*  92 */     this.busNames[getFirstChange(x)] = s;
/*     */   }
/*     */   
/*     */   public void setBusFill(int x, boolean clean) {
/*  96 */     int indice = (x - leftSpace) / this.widthUnit;
/*  97 */     if (!clean) 
{
/*  98 */       boolean mem = this.busFill[getFirstChange(x)];
/*  99 */       for (int i = getFirstChange(x); i < getNextChange(indice); i++) this.busFill[i] = false;
/* 100 */      

                    //this.busFill[getFirstChange(x)] = (mem ? 0 : true);
/*     */     }
/*     */     else {
/* 103 */       for (int i = getFirstChange(x); i < getNextChange(indice); i++) this.busFill[i] = false;
/*     */     }
/*     */   }
/*     */   
/*     */   public int getFirstChange(int x) {
/* 108 */     int indice = (x - leftSpace) / this.widthUnit;
/*     */     
/* 110 */     while ((indice > 0) && (this.wave[(indice - 1)] == this.wave[indice])) {
/* 111 */       indice--;
/*     */     }
/*     */     
/* 114 */     return indice;
/*     */   }
/*     */   
/*     */   public int getIndex(int x) {
/* 118 */     return (x - leftSpace) / this.widthUnit;
/*     */   }
/*     */   
/*     */   public int getNextChange(int offset) {
/* 122 */     int indice = offset;
/*     */     
/* 124 */     while ((indice < 199) && (this.wave[(indice + 1)] == this.wave[indice])) {
/* 125 */       indice++;
/*     */     }
/*     */     
/* 128 */     return indice;
/*     */   }
/*     */   
/*     */   public int getLastDisplayed(int maxWidth) {
/* 132 */     int res = 0;
/* 133 */     for (int i = 0; i < 200; i++) {
/* 134 */       if (leftSpace + (i + 1) * this.widthUnit < maxWidth - 10) {
/* 135 */         res++;
/*     */       }
/*     */     }
/* 138 */     return leftSpace + res * this.widthUnit;
/*     */   }
/*     */   
/*     */   public void draw(Graphics g, ChronoPanel chrono, int nbr, int maxWidth)
/*     */   {
/* 143 */     Graphics2D g2 = (Graphics2D)g;
/* 144 */     float[] dash1 = { 5.0F };
/* 145 */     float thickness = 1.0F;
/* 146 */     g.setFont(ChronoPanel.myFont);
/*     */     
/* 148 */     if (this.bold) {
/* 149 */       g.setFont(ChronoPanel.myBoldFont);
/* 150 */       thickness = 3.0F;
/*     */     }
/*     */     
/* 153 */     Stroke dashed = new BasicStroke(thickness, 0, 0, 10.0F, dash1, 0.0F);
/*     */     
/*     */ 
/*     */ 
/* 157 */     if (this.selected) {
/* 158 */       g.setColor(new Color(215, 215, 235));
/* 159 */       g.fillRect(0, nbr * (heightUnit + Yspace) + Yspace / 2, maxWidth - 15, heightUnit + Yspace);
/*     */     }
/*     */     
/* 162 */     g.setColor(this.color);
/* 163 */     g.translate(0, nbr * (heightUnit + Yspace) + Yspace);
/* 164 */     g.drawString(this.name, leftSpace - (ChronoPanel.metrics.stringWidth(this.name) + 8), heightUnit - 1);
/*     */     
/*     */ 
/* 167 */     g.translate(leftSpace, 0);
/*     */     
/*     */ 
/* 170 */     g2.setStroke(new BasicStroke(thickness));
/*     */     
/*     */ 
/* 173 */     if (this.bus) { drawBusFillOptions(g, 0, maxWidth - 15 - leftSpace);
/*     */     }
/*     */     
/* 176 */     if ((chrono != null) && (chrono.nbrTimeLapse > 0)) {
/* 177 */       drawSignalsInInterval(g, 0, chrono.timeLapse[0][0]);
/* 178 */       drawSignalsInInterval(g, chrono.timeLapse[(chrono.nbrTimeLapse - 1)][3], maxWidth - 15 - leftSpace);
/*     */     }
/*     */     else {
/* 181 */       drawSignalsInInterval(g, 0, maxWidth - 15 - leftSpace);
/*     */     }
/* 183 */     if (chrono != null) {
/* 184 */       for (int i = 0; i < chrono.nbrTimeLapse; i++) {
/* 185 */         for (int j = 0; j < 3; j++) {
/* 186 */           if ((j == 0) || (j == 2)) {
/* 187 */             g2.setStroke(dashed);
/* 188 */             drawSignalsInInterval(g, chrono.timeLapse[i][j], chrono.timeLapse[i][(j + 1)]);
/* 189 */             g2.setStroke(new BasicStroke(thickness));
/*     */           }
/*     */         }
/* 192 */         if (i < chrono.nbrTimeLapse - 1) { drawSignalsInInterval(g, chrono.timeLapse[i][3], chrono.timeLapse[(i + 1)][0]);
/*     */         }
/*     */       }
/*     */     }
/* 196 */     g.translate(-leftSpace, 0);
/* 197 */     g2.setStroke(new BasicStroke());
/* 198 */     g.setFont(ChronoPanel.myFont);
/* 199 */     g.translate(0, -(nbr * (heightUnit + Yspace) + Yspace));
/*     */   }
/*     */   
/*     */ 
/*     */   public void drawSignalsInInterval(Graphics g, int min, int max)
/*     */   {
/* 205 */     Rectangle2D drawArea = new Rectangle2D.Float(min, -1.0F, max - min, heightUnit + 3);
/* 206 */     int limit = max / this.widthUnit + 2;
/* 207 */     g.setClip(drawArea);
/*     */     
/*     */ 
/*     */ 
/* 211 */     if (this.bus) g.translate(-this.setUpTime / 2, 0);
/* 212 */     if (this.clkToQdelay) { g.translate(-this.widthUnit / 2, 0);
/*     */     }
/* 214 */     for (int i = 0; i < limit; i++)
/*     */     {
/* 216 */       if ((i > 0) && (this.wave[(i - 1)] != this.wave[i])) {
/* 217 */         if ((this.wave[i] == 0) || (this.bus)) g.drawLine(i * this.widthUnit, 0, i * this.widthUnit + this.setUpTime, heightUnit);
/* 218 */         if ((this.wave[i] == 1) || (this.bus)) { g.drawLine(i * this.widthUnit, heightUnit, i * this.widthUnit + this.setUpTime, 0);
/*     */         }
/*     */         
/*     */       }
/* 222 */       else if ((this.setUpTime > 0) || (this.bus)) {
/* 223 */         if ((this.wave[i] == 0) || (this.bus)) g.drawLine(i * this.widthUnit, heightUnit, i * this.widthUnit + this.setUpTime - 1, heightUnit);
/* 224 */         if ((this.wave[i] == 1) || (this.bus)) { g.drawLine(i * this.widthUnit, 0, i * this.widthUnit + this.setUpTime - 1, 0);
/*     */         }
/*     */       }
/*     */       
/* 228 */       if ((this.wave[i] == 0) || (this.bus)) g.drawLine(i * this.widthUnit + this.setUpTime, heightUnit, (i + 1) * this.widthUnit - 1, heightUnit);
/* 229 */       if ((this.wave[i] == 1) || (this.bus)) { g.drawLine(i * this.widthUnit + this.setUpTime, 0, (i + 1) * this.widthUnit - 1, 0);
/*     */       }
/*     */     }
/* 232 */     if (this.bus) g.translate(this.setUpTime / 2, 0);
/* 233 */     if (this.clkToQdelay) { g.translate(this.widthUnit / 2, 0);
/*     */     }
/* 235 */     g.setClip(null);
/*     */   }
/*     */   
/*     */   public void drawBusFillOptions(Graphics g, int min, int max) {
/* 239 */     Rectangle2D drawArea = new Rectangle2D.Float(min, 0.0F, max - min, heightUnit + 1);
/* 240 */     g.setClip(drawArea);
/*     */     
/*     */ 
/* 243 */     if (this.bus) g.translate(-this.setUpTime / 2, 0);
/* 244 */     if (this.clkToQdelay) { g.translate(-this.widthUnit / 2, 0);
/*     */     }
/* 246 */     for (int i = 0; i < 200; i++) {
/* 247 */       int left = i * this.widthUnit + this.setUpTime;
/* 248 */       if (i == 0) left = 0;
/* 249 */       int endData = (getNextChange(i) + 1) * this.widthUnit;
/*     */       
/* 251 */       //if (this.busFill[i] != 0)
/*     */       
                if (this.busFill[i] != false)
/*     */       
                {
/* 253 */         g.setColor(new Color(Math.min(this.color.getRed() + 150, 255), Math.min(this.color.getGreen() + 150, 255), Math.min(this.color.getBlue() + 150, 255)));
/* 254 */         g.fillRect(left, 0, endData - left, heightUnit);
/*     */         
/*     */ 
/* 257 */         int start = this.setUpTime / 2;
/*     */         
/* 259 */         if ((left != 0) && (this.setUpTime != 0)) {
/* 260 */           for (int j = 0; j < start; j++) {
/* 261 */             g.drawLine(left - start + j, heightUnit / 2 - j * heightUnit / (2 * start), left - start + j, heightUnit / 2 + j * heightUnit / (2 * start));
/*     */           }
/*     */         }
/*     */         
/* 265 */         if ((endData != getLastDisplayed(max)) && (this.setUpTime != 0)) {
/* 266 */           for (int j = start; j >= 0; j--) {
/* 267 */             g.drawLine(endData + start - j, heightUnit / 2 - j * heightUnit / (2 * start), endData + start - j, heightUnit / 2 + j * heightUnit / (2 * start));
/*     */           }
/*     */         }
/* 270 */         g.setColor(this.color);
/*     */       }
/*     */       
/* 273 */       if (this.busNames[i] != null) {
/* 274 */         endData = Math.min((getNextChange(i) + 1) * this.widthUnit, getLastDisplayed(max));
/* 275 */         g.drawString(this.busNames[i], (left + endData) / 2 - ChronoPanel.metrics.stringWidth(this.busNames[i]) / 2, heightUnit - 8);
/*     */       }
/*     */     }
/*     */     
/* 279 */     if (this.bus) g.translate(this.setUpTime / 2, 0);
/* 280 */     if (this.clkToQdelay) { g.translate(this.widthUnit / 2, 0);
/*     */     }
/* 282 */     g.setClip(null);
/*     */   }
/*     */ }


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