home *** CD-ROM | disk | FTP | other *** search
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Point;
- import java.io.PrintStream;
- import java.util.Vector;
-
- class ElectronicComponent {
- protected Point Pos;
- protected Dimension Dim;
- protected String ComponentName;
- protected String ClassName;
- protected Point HitBox;
- protected Dimension HitBoxSize;
- protected InputPin[] IPin;
- protected OutputPin[] OPin;
- protected int Inputs;
- protected int Outputs;
- public boolean Selected = false;
- protected static final Color ComponentColor;
- static final int MAXLOOPS = 100;
-
- public ElectronicComponent() {
- }
-
- public ElectronicComponent(int var1, int var2, int var3, int var4, int var5, int var6, int var7, int var8, int var9, int var10) {
- this.Pos = new Point(var1, var2);
- this.Dim = new Dimension(var3, var4);
- this.HitBox = new Point(var5, var6);
- this.HitBoxSize = new Dimension(var7, var8);
- this.Inputs = var9;
- this.Outputs = var10;
- this.IPin = new InputPin[var9];
- this.OPin = new OutputPin[var10];
- }
-
- public ElectronicComponent(ElectronicComponent var1, int var2, int var3) {
- this.Pos = new Point(var1.Pos.x - var2, var1.Pos.y - var3);
- this.Dim = new Dimension(var1.Dim.width, var1.Dim.height);
- this.HitBox = new Point(var1.HitBox.x, var1.HitBox.y);
- this.HitBoxSize = new Dimension(var1.HitBoxSize.width, var1.HitBoxSize.height);
- this.Inputs = var1.Inputs;
- this.Outputs = var1.Outputs;
- this.ComponentName = var1.ComponentName;
- this.ClassName = var1.ClassName;
- this.IPin = new InputPin[this.Inputs];
- this.OPin = new OutputPin[this.Outputs];
-
- for(int var4 = 0; var4 < this.Inputs; ++var4) {
- this.IPin[var4] = new InputPin(var1.IPin[var4]);
- }
-
- for(int var5 = 0; var5 < this.Outputs; ++var5) {
- this.OPin[var5] = new OutputPin(var1.OPin[var5]);
- }
-
- }
-
- public ElectronicComponent Copy(int var1, int var2) {
- return this;
- }
-
- public String getName() {
- return this.ComponentName;
- }
-
- public void InitBeforeSimulate() {
- for(int var1 = 0; var1 < this.Inputs; ++var1) {
- this.IPin[var1].InitBeforeSimulate();
- }
-
- for(int var2 = 0; var2 < this.Outputs; ++var2) {
- this.OPin[var2].InitBeforeSimulate();
- }
-
- }
-
- public void ReceivePotential(int var1, int var2, int var3, int var4) {
- for(int var6 = 0; var6 < this.Outputs; ++var6) {
- if (var3 == this.OPin[var6].PinPos.x + this.Pos.x && var4 == this.OPin[var6].PinPos.y + this.Pos.y && this.OPin[var6].getLevel() != var2) {
- this.OPin[var6].ShortCircuit = true;
- }
- }
-
- for(int var5 = 0; var5 < this.Inputs; ++var5) {
- if (var3 == this.IPin[var5].PinPos.x + this.Pos.x && var4 == this.IPin[var5].PinPos.y + this.Pos.y) {
- if (var1 == this.IPin[var5].ReceivedSimulationCycleID) {
- if (this.IPin[var5].Level == var2) {
- return;
- }
-
- ++this.IPin[var5].LevelChanged;
- if (this.IPin[var5].LevelChanged > 100) {
- this.IPin[1].Looping = true;
- return;
- }
- }
-
- this.IPin[var5].setLevel(var2);
- this.IPin[var5].ReceivedSimulationCycleID = var1;
- if ((this.IPin[var5].Flags & 4) == 4) {
- this.SimulateLogic();
- this.InformConnectedComponentsOldLevel(var1);
- return;
- }
-
- if ((this.IPin[var5].Flags & 8) != 8) {
- this.SimulateLogic();
- this.InformConnectedComponents(var1);
- }
-
- return;
- }
- }
-
- }
-
- public void SimulateLogic() {
- }
-
- public void Simulate(int var1) {
- }
-
- public void InformConnectedComponents(int var1) {
- for(int var3 = 0; var3 < this.Outputs; ++var3) {
- for(int var4 = 0; var4 < this.OPin[var3].ConnComps.size(); ++var4) {
- ElectronicComponent var2 = (ElectronicComponent)this.OPin[var3].ConnComps.elementAt(var4);
- if (var2 != this) {
- var2.ReceivePotential(var1, this.OPin[var3].getLevel(), this.OPin[var3].PinPos.x + this.Pos.x, this.OPin[var3].PinPos.y + this.Pos.y);
- }
- }
- }
-
- }
-
- public void InformConnectedComponentsOldLevel(int var1) {
- for(int var3 = 0; var3 < this.Outputs; ++var3) {
- for(int var4 = 0; var4 < this.OPin[var3].ConnComps.size(); ++var4) {
- ElectronicComponent var2 = (ElectronicComponent)this.OPin[var3].ConnComps.elementAt(var4);
- if (var2 != this) {
- var2.ReceivePotential(var1, this.OPin[var3].getOldLevel(), this.OPin[var3].PinPos.x + this.Pos.x, this.OPin[var3].PinPos.y + this.Pos.y);
- }
- }
- }
-
- }
-
- public void SimulateSetUp(int var1, int var2, Vector var3) {
- for(int var4 = 0; var4 < this.Inputs; ++var4) {
- if (this.Pos.x + this.IPin[var4].PinPos.x == var1 && this.Pos.y + this.IPin[var4].PinPos.y == var2) {
- this.IPin[var4].ConnComps = var3;
- }
- }
-
- for(int var5 = 0; var5 < this.Outputs; ++var5) {
- if (this.Pos.x + this.OPin[var5].PinPos.x == var1 && this.Pos.y + this.OPin[var5].PinPos.y == var2) {
- this.OPin[var5].ConnComps = var3;
- }
- }
-
- }
-
- public void draw(Graphics var1, int var2, int var3, int var4) {
- if (this.Selected) {
- int var5 = this.Pos.x - var2;
- int var6 = this.Pos.y - var3;
- var1.setColor(Color.white);
- var1.drawRect((int)(((double)(var5 + this.HitBox.x) - (double)0.25F) * (double)var4), (int)(((double)(var6 + this.HitBox.y) - (double)0.25F) * (double)var4), var4 / 2, var4 / 2);
- var1.drawRect((int)(((double)(var5 + this.HitBox.x + this.HitBoxSize.width) - (double)0.25F) * (double)var4), (int)(((double)(var6 + this.HitBox.y) - (double)0.25F) * (double)var4), var4 / 2, var4 / 2);
- var1.drawRect((int)(((double)(var5 + this.HitBox.x) - (double)0.25F) * (double)var4), (int)(((double)(var6 + this.HitBox.y + this.HitBoxSize.height) - (double)0.25F) * (double)var4), var4 / 2, var4 / 2);
- var1.drawRect((int)(((double)(var5 + this.HitBox.x + this.HitBoxSize.width) - (double)0.25F) * (double)var4), (int)(((double)(var6 + this.HitBox.y + this.HitBoxSize.height) - (double)0.25F) * (double)var4), var4 / 2, var4 / 2);
- }
-
- }
-
- public void DrawHitBox(Graphics var1, int var2, int var3, int var4) {
- var1.setColor(Color.gray);
- var1.drawRect((var2 + this.HitBox.x) * var4, (var3 + this.HitBox.y) * var4, this.HitBoxSize.width * var4, this.HitBoxSize.height * var4);
- var1.setColor(Color.pink);
- var1.drawRect(var2 * var4, (var3 + 1) * var4, this.Dim.width * var4, this.Dim.height * var4);
- }
-
- public boolean AdjustPosition(Pin[][] var1, int var2, int var3) {
- Point var10000 = this.Pos;
- var10000.x += var2;
- var10000 = this.Pos;
- var10000.y += var3;
- return true;
- }
-
- public void CheckPosition() {
- if (this.Pos.x < 0) {
- this.Pos.x = 0;
- }
-
- if (this.Pos.y < 0) {
- this.Pos.y = 0;
- }
-
- if (this.Pos.x > 100 - this.Dim.width) {
- this.Pos.x = 100 - this.Dim.width;
- }
-
- if (this.Pos.y > 100 - this.Dim.height) {
- this.Pos.y = 100 - this.Dim.height;
- }
-
- }
-
- public boolean CheckIfComponentInSelectBox(int var1, int var2, int var3, int var4) {
- int var5 = this.Pos.x + this.HitBox.x;
- int var6 = this.Pos.y + this.HitBox.y;
- int var7 = this.Pos.x + this.HitBox.x + this.HitBoxSize.width;
- int var8 = this.Pos.y + this.HitBox.y + this.HitBoxSize.height;
- if (var1 <= var5 && var7 <= var3 && var2 <= var6 && var8 <= var4) {
- this.Selected = true;
- } else {
- this.Selected = false;
- }
-
- return this.Selected;
- }
-
- public boolean CheckIfComponentClicked(int var1, int var2) {
- return this.Pos.x + this.HitBox.x <= var1 && var1 <= this.Pos.x + this.HitBox.x + this.HitBoxSize.width && this.Pos.y + this.HitBox.y <= var2 && var2 <= this.Pos.y + this.HitBox.y + this.HitBoxSize.height;
- }
-
- protected void RegisterPin(Pin var1) {
- var1.AddComponent(this);
- }
-
- public void RegisterPins(Pin[][] var1, int var2, int var3) {
- if (var1 != null) {
- for(int var4 = 0; var4 < this.Inputs; ++var4) {
- int var5 = var2 + this.IPin[var4].PinPos.x;
- int var6 = var3 + this.IPin[var4].PinPos.y;
- this.RegisterPin(var1[var5][var6]);
- }
-
- for(int var7 = 0; var7 < this.Outputs; ++var7) {
- int var8 = var2 + this.OPin[var7].PinPos.x;
- int var9 = var3 + this.OPin[var7].PinPos.y;
- this.RegisterPin(var1[var8][var9]);
- }
-
- }
- }
-
- protected void RemovePin(Pin var1) {
- var1.RemoveComponent(this);
- }
-
- public void RemovePinsGrid(Pin[][] var1) {
- for(int var2 = 0; var2 < this.Inputs; ++var2) {
- int var3 = this.Pos.x + this.IPin[var2].PinPos.x;
- int var4 = this.Pos.y + this.IPin[var2].PinPos.y;
- this.RemovePin(var1[var3][var4]);
- }
-
- for(int var5 = 0; var5 < this.Outputs; ++var5) {
- int var6 = this.Pos.x + this.OPin[var5].PinPos.x;
- int var7 = this.Pos.y + this.OPin[var5].PinPos.y;
- this.RemovePin(var1[var6][var7]);
- }
-
- }
-
- public void PlacePinsHere(Pin[][] var1) {
- this.RegisterPins(var1, this.Pos.x, this.Pos.y);
- }
-
- public boolean SimMouseDown() {
- return false;
- }
-
- public boolean SimMouseUp() {
- return false;
- }
-
- public void DrawInputPins(Graphics var1, int var2, int var3, int var4) {
- for(int var5 = 0; var5 < this.Inputs; ++var5) {
- this.IPin[var5].draw(var1, var2, var3, var4);
- }
-
- }
-
- public void DrawOutputPins(Graphics var1, int var2, int var3, int var4) {
- for(int var5 = 0; var5 < this.Outputs; ++var5) {
- this.OPin[var5].draw(var1, var2, var3, var4);
- }
-
- }
-
- public void Save(PrintStream var1) {
- var1.println("describe component " + this.ClassName);
- var1.println(" pos " + this.Pos.x + " " + this.Pos.y);
- var1.println("end describe");
- }
-
- static {
- ComponentColor = Color.yellow;
- }
- }
-