home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 October / PCO1097.ISO / FilesBBS / FREI / DIGSIM.EXE / DigSim.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-05-21  |  18.8 KB  |  887 lines

  1. import java.applet.Applet;
  2. import java.awt.Button;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Container;
  6. import java.awt.Event;
  7. import java.awt.FlowLayout;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.io.InputStream;
  11. import java.net.URL;
  12.  
  13. public class DigSim extends Applet implements Runnable {
  14.    DigSimFrame frame;
  15.    ControlPanel MyControlPanel;
  16.    StatusPanel MyStatusPanel;
  17.    SchematicPanel MySchematicPanel;
  18.    Button displayb;
  19.    Button disposeb;
  20.    Thread killme;
  21.    String SchematicName;
  22.    Schematic MySchematic;
  23.    Pin[][] PinGrid;
  24.    String message;
  25.    static final int MaxXPoints = 100;
  26.    static final int MaxYPoints = 100;
  27.    Image GridImage;
  28.    Image ImageBuffer;
  29.    Graphics ibg;
  30.    int OffScreenWidth;
  31.    int OffScreenHeight;
  32.    static final Color BackGroundColor;
  33.    static final Color GridColor;
  34.    static final int GridStep = 8;
  35.    static final int hgs = 4;
  36.    boolean SchematicPanelPainted = false;
  37.    boolean HelpWanted = false;
  38.    String TextFileRequested;
  39.    boolean EnableFileOperations = false;
  40.    ExamplesFrame MyExamplesFrame;
  41.    String RequestedText;
  42.    boolean RequestedTextFileRead = false;
  43.    boolean RequestedTextFileError = false;
  44.    OptionsFrame MyOptionsFrame;
  45.    AnalyzerFrame MyAnalyzerFrame;
  46.    int SimulationSpeed = 10;
  47.    boolean StopAtShortCircuit = true;
  48.    boolean StopAtLoop = true;
  49.    boolean AnalyzerAutoPopUp = true;
  50.  
  51.    public void init() {
  52.       ((Container)this).setLayout(new FlowLayout());
  53.       ((Container)this).add(this.displayb = new Button("Display simulator"));
  54.       ((Container)this).add(this.disposeb = new Button("Dispose simulator"));
  55.       this.OffScreenWidth = 400;
  56.       this.OffScreenHeight = 300;
  57.       this.SchematicName = ((Applet)this).getParameter("schematic");
  58.       String var1 = ((Applet)this).getParameter("fileop");
  59.       if (var1 != null) {
  60.          if (var1.equals("true")) {
  61.             this.EnableFileOperations = true;
  62.          } else {
  63.             this.EnableFileOperations = false;
  64.          }
  65.       } else {
  66.          this.EnableFileOperations = false;
  67.       }
  68.  
  69.       this.PinGrid = new Pin[100][100];
  70.       this.InitPinGrids();
  71.       this.SetUpImages();
  72.       this.doFrame();
  73.       this.StatusMessage("Please wait.");
  74.    }
  75.  
  76.    public void start() {
  77.       if (this.killme == null) {
  78.          this.killme = new Thread(this);
  79.          this.killme.start();
  80.       }
  81.  
  82.    }
  83.  
  84.    public void stop() {
  85.       this.killme = null;
  86.    }
  87.  
  88.    public void run() {
  89.       InputStream var1 = null;
  90.       Object var2 = null;
  91.       byte var3 = 100;
  92.       int var5 = 0;
  93.       char[] var4 = new char[var3];
  94.  
  95.       try {
  96.          Thread.currentThread().setPriority(1);
  97.          if (this.SchematicName != null) {
  98.             var1 = (new URL(((Applet)this).getDocumentBase(), this.SchematicName)).openStream();
  99.             this.MySchematic = new Schematic(this.PinGrid, var1);
  100.          }
  101.       } catch (Exception var13) {
  102.          String var15 = ((Throwable)var13).toString();
  103.          String[] var9 = new String[]{"OK"};
  104.          new SimpleDialog(this.frame, "Reading inital schematic", var15, var9, 1, 0, 0, 1);
  105.       }
  106.  
  107.       try {
  108.          if (var1 != null) {
  109.             var1.close();
  110.          }
  111.       } catch (Exception var12) {
  112.       }
  113.  
  114.       ((Component)this).repaint();
  115.       if (this.MySchematic == null) {
  116.          this.MySchematic = new Schematic();
  117.          this.frame.setTitle("Digital Simulator [untitled]");
  118.       } else {
  119.          this.frame.setTitle("Digital Simulator [" + this.SchematicName + "]");
  120.          this.MySchematic.FileDir = "";
  121.          this.MySchematic.FileName = this.SchematicName;
  122.       }
  123.  
  124.       while(this.killme != null) {
  125.          try {
  126.             Thread.sleep((long)this.SimulationSpeed);
  127.          } catch (InterruptedException var11) {
  128.          }
  129.  
  130.          if (this.TextFileRequested != null) {
  131.             var5 = 0;
  132.             String var7 = "";
  133.  
  134.             try {
  135.                Thread.currentThread().setPriority(1);
  136.                var1 = (new URL(((Applet)this).getDocumentBase(), this.TextFileRequested)).openStream();
  137.  
  138.                int var6;
  139.                while((var6 = var1.read()) != -1) {
  140.                   var4[var5++] = (char)var6;
  141.                   if (var5 >= var3) {
  142.                      var7 = var7 + new String(var4, 0, var3);
  143.                      var5 = 0;
  144.                   }
  145.                }
  146.  
  147.                var7 = var7 + new String(var4, 0, var5);
  148.             } catch (Exception var14) {
  149.                var7 = var7 + ((Throwable)var14).toString();
  150.                this.RequestedText = var7;
  151.                this.RequestedTextFileError = true;
  152.             }
  153.  
  154.             try {
  155.                if (var1 != null) {
  156.                   var1.close();
  157.                }
  158.             } catch (Exception var10) {
  159.                var7 = var7 + ((Throwable)var10).toString();
  160.                this.RequestedText = var7;
  161.                this.RequestedTextFileError = true;
  162.             }
  163.  
  164.             if (!this.RequestedTextFileError) {
  165.                this.RequestedText = var7;
  166.                this.RequestedTextFileRead = true;
  167.             }
  168.          }
  169.  
  170.          if (!this.SchematicPanelPainted && this.ImagesReady()) {
  171.             this.SchematicPanelPainted = true;
  172.             this.MySchematicPanel.repaint();
  173.             if (this.MyControlPanel != null) {
  174.                this.MyControlPanel.EnableAllButtons();
  175.                this.frame.EnableAllMenus();
  176.                this.StatusMessage("DigSim initialized. Make a choice or select a component.");
  177.             }
  178.          }
  179.  
  180.          if (this.MyStatusPanel.SimulationRunning) {
  181.             this.SimulateCycle();
  182.          }
  183.       }
  184.  
  185.       this.killme = null;
  186.    }
  187.  
  188.    public void InitPinGrids() {
  189.       for(int var1 = 0; var1 < 100; ++var1) {
  190.          for(int var2 = 0; var2 < 100; ++var2) {
  191.             this.PinGrid[var1][var2] = new Pin();
  192.          }
  193.       }
  194.  
  195.    }
  196.  
  197.    public void SetUpImages() {
  198.       this.ImageBuffer = ((Component)this).createImage(this.OffScreenWidth, this.OffScreenHeight);
  199.       this.ibg = this.ImageBuffer.getGraphics();
  200.       this.GridImage = ((Component)this).createImage(this.OffScreenWidth, this.OffScreenHeight);
  201.       Graphics var3 = this.GridImage.getGraphics();
  202.       var3.setColor(BackGroundColor);
  203.       var3.fillRect(0, 0, this.OffScreenWidth, this.OffScreenHeight);
  204.       var3.setColor(GridColor);
  205.  
  206.       for(int var1 = 1; var1 <= 100; ++var1) {
  207.          for(int var2 = 1; var2 <= 100; ++var2) {
  208.             var3.drawLine(var1 * 8, var2 * 8, var1 * 8, var2 * 8);
  209.          }
  210.       }
  211.  
  212.    }
  213.  
  214.    public void destroyFrame() {
  215.       if (this.SimulateRunning()) {
  216.          this.SimulateStop();
  217.       }
  218.  
  219.       if (this.MyAnalyzerFrame != null) {
  220.          this.MyAnalyzerFrame.dispose();
  221.          this.MyAnalyzerFrame = null;
  222.       }
  223.  
  224.       if (this.MyExamplesFrame != null) {
  225.          this.MyExamplesFrame.dispose();
  226.          this.MyExamplesFrame = null;
  227.       }
  228.  
  229.       if (this.MyOptionsFrame != null) {
  230.          this.MyOptionsFrame.dispose();
  231.          this.MyOptionsFrame = null;
  232.       }
  233.  
  234.       if (this.frame != null) {
  235.          this.frame.dispose();
  236.          this.frame = null;
  237.          this.displayb.enable(true);
  238.          this.disposeb.enable(false);
  239.       }
  240.  
  241.    }
  242.  
  243.    void doFrame() {
  244.       this.displayb.enable(false);
  245.       this.disposeb.enable(true);
  246.       this.frame = new DigSimFrame(this);
  247.       this.frame.EnableAllMenus();
  248.    }
  249.  
  250.    public boolean action(Event var1, Object var2) {
  251.       if (var1.target instanceof Button) {
  252.          String var3 = (String)var2;
  253.          if (var3.equals("Display simulator")) {
  254.             this.doFrame();
  255.             this.MyControlPanel.EnableAllButtons();
  256.          } else if (var3.equals("Dispose simulator")) {
  257.             this.destroyFrame();
  258.          }
  259.  
  260.          return true;
  261.       } else {
  262.          return false;
  263.       }
  264.    }
  265.  
  266.    public void SimulateSetUp() {
  267.       for(int var1 = 0; var1 < 100; ++var1) {
  268.          for(int var2 = 0; var2 < 100; ++var2) {
  269.             if (this.PinGrid[var1][var2] != null) {
  270.                this.PinGrid[var1][var2].SimulateSetUp(var1, var2);
  271.             }
  272.          }
  273.       }
  274.  
  275.    }
  276.  
  277.    public void SimulateStart() {
  278.       this.StatusMessage("Please wait. Initializing simulation.");
  279.       this.MyStatusPanel.repaint();
  280.       if (!this.MyStatusPanel.SimulationInitializeInProgress) {
  281.          if (this.AnalyzerAutoPopUp && this.MyAnalyzerFrame == null && this.MySchematic.ProbesInSchematic()) {
  282.             this.MyAnalyzerFrame = new AnalyzerFrame(this);
  283.          }
  284.  
  285.          this.MySchematicPanel.SelectSchematic.RemoveAllComponents();
  286.          this.MyStatusPanel.SimulationInitializeInProgress = true;
  287.          this.MyStatusPanel.repaint();
  288.          this.SimulateSetUp();
  289.          this.MyStatusPanel.SimulationInitializeInProgress = false;
  290.          this.MyStatusPanel.SimulationRunning = true;
  291.          this.StatusMessage("Simulation running. press 'Simulate' button again to stop or press a component in the schematic");
  292.       }
  293.    }
  294.  
  295.    public void SimulateStop() {
  296.       this.MyStatusPanel.SimulationRunning = false;
  297.       this.StatusMessage("Simulation stoppped. Make a choice above or change the schematic.");
  298.       this.MyStatusPanel.repaint();
  299.    }
  300.  
  301.    public boolean IsSimulating() {
  302.       return this.MyStatusPanel.SimulationRunning || this.MyStatusPanel.SimulationInitializeInProgress;
  303.    }
  304.  
  305.    public void SimulateCycle() {
  306.       this.MySchematic.InitBeforeSimulate();
  307.  
  308.       for(int var2 = 0; var2 < 4; ++var2) {
  309.          this.MySchematic.Simulate();
  310.       }
  311.  
  312.       if (this.StopAtShortCircuit) {
  313.          ElectronicComponent var1 = this.MySchematic.TestShortCircuit();
  314.          if (var1 != null) {
  315.             String[] var6 = new String[]{"OK"};
  316.             String var7 = "Short circuit detected at " + var1.getName() + " pos. " + var1.Pos.x + ", " + var1.Pos.y;
  317.             new SimpleDialog(this.frame, "Short circuit detected", var7, var6, 1, 0, 0, 1);
  318.             this.UserWantsSimulate();
  319.             this.MySchematicPanel.repaint();
  320.             this.MyStatusPanel.repaint();
  321.             return;
  322.          }
  323.       }
  324.  
  325.       if (this.StopAtLoop) {
  326.          ElectronicComponent var5 = this.MySchematic.TestLoop();
  327.          if (var5 != null) {
  328.             String[] var3 = new String[]{"OK"};
  329.             String var4 = "Loop detected at " + var5.getName() + " pos. " + var5.Pos.x + ", " + var5.Pos.y;
  330.             new SimpleDialog(this.frame, "Loop detected", var4, var3, 1, 0, 0, 1);
  331.             this.UserWantsSimulate();
  332.             this.MySchematicPanel.repaint();
  333.             this.MyStatusPanel.repaint();
  334.             return;
  335.          }
  336.       }
  337.  
  338.       if (this.MyAnalyzerFrame != null && this.MyAnalyzerFrame.MyAnalyzerPanel != null) {
  339.          this.MyAnalyzerFrame.MyAnalyzerPanel.update();
  340.       }
  341.  
  342.       this.MySchematicPanel.repaint();
  343.       this.MyStatusPanel.repaint();
  344.    }
  345.  
  346.    public void addComponent(ElectronicComponent var1) {
  347.       if (this.MySchematic != null) {
  348.          this.MySchematicPanel.SelectSchematic.RemoveAllComponents();
  349.          this.MySchematic.addComponent(var1);
  350.          if (!(var1 instanceof Wire)) {
  351.             this.UserWantsPointer();
  352.          }
  353.  
  354.          this.MySchematicPanel.repaint();
  355.       }
  356.    }
  357.  
  358.    public void addComponent(String var1) {
  359.       if (this.MySchematicPanel != null) {
  360.          if ("Wire".equals(var1)) {
  361.             this.UserWantsWireDrawing();
  362.          } else if ("Junction".equals(var1)) {
  363.             this.UserWantsJunctionDrawing();
  364.          } else {
  365.             if ("Vcc".equals(var1)) {
  366.                this.addComponent((ElectronicComponent)(new Vcc(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  367.             } else if ("GND".equals(var1)) {
  368.                this.addComponent((ElectronicComponent)(new GND(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  369.             } else if ("Switch".equals(var1)) {
  370.                this.addComponent((ElectronicComponent)(new Switch(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  371.             } else if ("Push button".equals(var1)) {
  372.                this.addComponent((ElectronicComponent)(new PushButton(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  373.             } else if ("Buffer".equals(var1)) {
  374.                this.addComponent((ElectronicComponent)(new Buffer(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  375.             } else if ("Inverter".equals(var1)) {
  376.                this.addComponent((ElectronicComponent)(new Inverter(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  377.             } else if ("2-input AND port".equals(var1)) {
  378.                this.addComponent((ElectronicComponent)(new TwoAndPort(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  379.             } else if ("3-input AND port".equals(var1)) {
  380.                this.addComponent((ElectronicComponent)(new ThreeAndPort(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  381.             } else if ("2-input OR port".equals(var1)) {
  382.                this.addComponent((ElectronicComponent)(new TwoOrPort(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  383.             } else if ("3-input OR port".equals(var1)) {
  384.                this.addComponent((ElectronicComponent)(new ThreeOrPort(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  385.             } else if ("2-input XOR port".equals(var1)) {
  386.                this.addComponent((ElectronicComponent)(new TwoXorPort(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  387.             } else if ("2-input NAND port".equals(var1)) {
  388.                this.addComponent((ElectronicComponent)(new TwoNandPort(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  389.             } else if ("3-input NAND port".equals(var1)) {
  390.                this.addComponent((ElectronicComponent)(new ThreeNandPort(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  391.             } else if ("2-input NOR port".equals(var1)) {
  392.                this.addComponent((ElectronicComponent)(new TwoNorPort(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  393.             } else if ("3-input NOR port".equals(var1)) {
  394.                this.addComponent((ElectronicComponent)(new ThreeNorPort(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  395.             } else if ("2-input XNOR port".equals(var1)) {
  396.                this.addComponent((ElectronicComponent)(new TwoXnorPort(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  397.             } else if ("SR-latch".equals(var1)) {
  398.                this.addComponent((ElectronicComponent)(new SRLatch(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  399.             } else if ("Gated SR-latch".equals(var1)) {
  400.                this.addComponent((ElectronicComponent)(new GatedSRLatch(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  401.             } else if ("D-latch".equals(var1)) {
  402.                this.addComponent((ElectronicComponent)(new DLatch(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  403.             } else if ("D-flipflop".equals(var1)) {
  404.                this.addComponent((ElectronicComponent)(new DFlipFlop(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  405.             } else if ("JK-flipflop".equals(var1)) {
  406.                this.addComponent((ElectronicComponent)(new JKFlipFlop(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  407.             } else if ("Edge-triggered T-flipflop".equals(var1)) {
  408.                this.addComponent((ElectronicComponent)(new EdgeTriggeredTFlipFlop(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  409.             } else if ("T-flipflop".equals(var1)) {
  410.                this.addComponent((ElectronicComponent)(new TFlipFlop(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  411.             } else if ("Octal D-flipflop".equals(var1)) {
  412.                this.addComponent((ElectronicComponent)(new OctalDFlipFlop(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  413.             } else if ("Octal latch".equals(var1)) {
  414.                this.addComponent((ElectronicComponent)(new OctalLatch(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  415.             } else if ("Red LED".equals(var1)) {
  416.                this.addComponent((ElectronicComponent)(new LED(this.PinGrid, Color.red, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  417.             } else if ("Green LED".equals(var1)) {
  418.                this.addComponent((ElectronicComponent)(new LED(this.PinGrid, Color.green, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  419.             } else if ("Yellow LED".equals(var1)) {
  420.                this.addComponent((ElectronicComponent)(new LED(this.PinGrid, Color.yellow, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  421.             } else if ("Bi-color LED".equals(var1)) {
  422.                this.addComponent((ElectronicComponent)(new BiColorLED(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  423.             } else if ("7-segment display".equals(var1)) {
  424.                this.addComponent((ElectronicComponent)(new SevenSegmentDisplay(this.PinGrid, Color.red, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  425.             } else if ("Oscilator".equals(var1)) {
  426.                this.addComponent((ElectronicComponent)(new Oscilator(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  427.             } else if ("Analyzer probe".equals(var1)) {
  428.                this.addComponent((ElectronicComponent)(new Probe(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  429.                this.updateAnalyzer();
  430.             } else if ("BCD to 7-segment decoder".equals(var1)) {
  431.                this.addComponent((ElectronicComponent)(new BCDToSevenSegDecoder(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  432.             } else if ("3- to 8-line decoder".equals(var1)) {
  433.                this.addComponent((ElectronicComponent)(new ThreeToEightLineDecoder(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  434.             } else if ("4-bit binary counter".equals(var1)) {
  435.                this.addComponent((ElectronicComponent)(new FourBitBinaryCounter(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  436.             } else if ("8-bit serial in shift register".equals(var1)) {
  437.                this.addComponent((ElectronicComponent)(new EightBitSerInShiftReg(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  438.             } else if ("8-bit parallel in shift register".equals(var1)) {
  439.                this.addComponent((ElectronicComponent)(new EightBitParInShiftReg(this.PinGrid, this.MySchematicPanel.GridXOffset, this.MySchematicPanel.GridYOffset)));
  440.             }
  441.  
  442.             this.MySchematicPanel.WireDrawing = false;
  443.             this.MySchematicPanel.JunctionDrawing = false;
  444.             this.StatusMessage("Click and hold the mouse button in the body of the new " + var1 + " to move it.");
  445.          }
  446.       }
  447.    }
  448.  
  449.    public boolean ImagesReady() {
  450.       return this.ibg != null && this.GridImage != null && this.ImageBuffer != null && this.MySchematic != null;
  451.    }
  452.  
  453.    public void StatusMessage(String var1) {
  454.       this.MyStatusPanel.StatusMessage(var1);
  455.    }
  456.  
  457.    public boolean SimulateRunning() {
  458.       return this.MyStatusPanel.SimulateRunning();
  459.    }
  460.  
  461.    public String getAppletInfo() {
  462.       return "DigSim v 0.01 (c) 1996 Iwan van Rienen\nE-mail: ivr@bart.nl\nHomepage: http://www.bart.nl/~ivr/";
  463.    }
  464.  
  465.    public String[][] getParameterInfo() {
  466.       String[][] var1 = new String[][]{{"schematic", "String", "Initial schematic to load"}, {"fileop", "Boolean", "Local file operations enable"}};
  467.       return var1;
  468.    }
  469.  
  470.    public void UserWantsPointer() {
  471.       this.HelpWanted = false;
  472.       if (this.MyControlPanel != null) {
  473.          this.MyControlPanel.SelectButton("Pointer");
  474.          this.MyControlPanel.UnselectButton("Wire");
  475.          this.MyControlPanel.UnselectButton("Junction");
  476.          this.MyControlPanel.UnselectButton("Text");
  477.          this.MyControlPanel.UnselectButton("Help");
  478.          this.MyControlPanel.UnselectButton("Simulate");
  479.          this.MyControlPanel.UnselectButton("New");
  480.          this.MyControlPanel.UnselectButton("Open");
  481.          this.MyControlPanel.UnselectButton("Save");
  482.       }
  483.  
  484.       if (this.MySchematicPanel != null) {
  485.          this.MySchematicPanel.WireDrawing = false;
  486.          this.MySchematicPanel.JunctionDrawing = false;
  487.          this.StatusMessage("Move the cursor to a component body or wire-end and press a mouse button.");
  488.       }
  489.  
  490.    }
  491.  
  492.    public void UserWantsWireDrawing() {
  493.       if (this.HelpWanted) {
  494.          new HelpDialog(this.frame, "Wire");
  495.          this.UserWantsPointer();
  496.       } else {
  497.          if (this.MyControlPanel != null) {
  498.             this.MyControlPanel.UnselectButton("Pointer");
  499.             this.MyControlPanel.SelectButton("Wire");
  500.             this.MyControlPanel.UnselectButton("Junction");
  501.             this.MyControlPanel.UnselectButton("Text");
  502.             this.MyControlPanel.UnselectButton("Help");
  503.             this.MyControlPanel.UnselectButton("Simulate");
  504.             this.MyControlPanel.UnselectButton("New");
  505.             this.MyControlPanel.UnselectButton("Open");
  506.             this.MyControlPanel.UnselectButton("Save");
  507.          }
  508.  
  509.          if (this.MySchematicPanel != null) {
  510.             this.StatusMessage("Move the mouse to the desired position, click and hold the mouse button to draw a wire.");
  511.             this.MySchematicPanel.WireDrawing = true;
  512.             this.MySchematicPanel.JunctionDrawing = false;
  513.             this.MySchematicPanel.SelectSchematic.RemoveAllComponents();
  514.             this.MySchematicPanel.repaint();
  515.          }
  516.  
  517.       }
  518.    }
  519.  
  520.    public void UserWantsJunctionDrawing() {
  521.       if (this.HelpWanted) {
  522.          new HelpDialog(this.frame, "Junction");
  523.          this.UserWantsPointer();
  524.       } else {
  525.          if (this.MyControlPanel != null) {
  526.             this.MyControlPanel.UnselectButton("Pointer");
  527.             this.MyControlPanel.UnselectButton("Wire");
  528.             this.MyControlPanel.SelectButton("Junction");
  529.             this.MyControlPanel.UnselectButton("Text");
  530.             this.MyControlPanel.UnselectButton("Help");
  531.             this.MyControlPanel.UnselectButton("Simulate");
  532.             this.MyControlPanel.UnselectButton("New");
  533.             this.MyControlPanel.UnselectButton("Open");
  534.             this.MyControlPanel.UnselectButton("Save");
  535.          }
  536.  
  537.          if (this.MySchematicPanel != null) {
  538.             this.MySchematicPanel.WireDrawing = false;
  539.             this.MySchematicPanel.JunctionDrawing = true;
  540.             this.StatusMessage("Move the mouse to the desired position, and click the mouse button to add a junction.");
  541.             this.MySchematicPanel.SelectSchematic.RemoveAllComponents();
  542.             this.MySchematicPanel.repaint();
  543.          }
  544.  
  545.       }
  546.    }
  547.  
  548.    public void UserWantsTextDrawing() {
  549.       if (this.HelpWanted) {
  550.          new HelpDialog(this.frame, "Text");
  551.          this.UserWantsPointer();
  552.       } else {
  553.          if (this.MyControlPanel != null) {
  554.             this.MyControlPanel.UnselectButton("Pointer");
  555.             this.MyControlPanel.UnselectButton("Wire");
  556.             this.MyControlPanel.UnselectButton("Junction");
  557.             this.MyControlPanel.SelectButton("Text");
  558.             this.MyControlPanel.UnselectButton("Help");
  559.             this.MyControlPanel.UnselectButton("Simulate");
  560.             this.MyControlPanel.UnselectButton("New");
  561.             this.MyControlPanel.UnselectButton("Open");
  562.             this.MyControlPanel.UnselectButton("Save");
  563.          }
  564.  
  565.          if (this.frame != null) {
  566.             if (this.frame.MyTextDialog == null) {
  567.                this.frame.MyTextDialog = new TextDialog(this.frame, "", 5);
  568.             }
  569.  
  570.             this.StatusMessage("Please type a new text.");
  571.             this.UserWantsPointer();
  572.          }
  573.  
  574.       }
  575.    }
  576.  
  577.    public void UserWantsHelp() {
  578.       if (this.MyControlPanel != null) {
  579.          this.MyControlPanel.UnselectButton("Pointer");
  580.          this.MyControlPanel.UnselectButton("Wire");
  581.          this.MyControlPanel.UnselectButton("Junction");
  582.          this.MyControlPanel.UnselectButton("Text");
  583.          this.MyControlPanel.SelectButton("Help");
  584.          this.MyControlPanel.UnselectButton("Simulate");
  585.          this.MyControlPanel.UnselectButton("New");
  586.          this.MyControlPanel.UnselectButton("Open");
  587.          this.MyControlPanel.UnselectButton("Save");
  588.       }
  589.  
  590.       if (this.HelpWanted) {
  591.          new HelpDialog(this.frame, "Help");
  592.       } else {
  593.          this.StatusMessage("Choose a component, menu or button to get help about it.");
  594.          this.HelpWanted = true;
  595.       }
  596.    }
  597.  
  598.    public void UserWantsSimulate() {
  599.       if (this.MyControlPanel != null) {
  600.          this.MyControlPanel.UnselectButton("Pointer");
  601.          this.MyControlPanel.UnselectButton("Wire");
  602.          this.MyControlPanel.UnselectButton("Junction");
  603.          this.MyControlPanel.UnselectButton("Text");
  604.          this.MyControlPanel.UnselectButton("Help");
  605.          this.MyControlPanel.SelectButton("Simulate");
  606.          this.MyControlPanel.UnselectButton("New");
  607.          this.MyControlPanel.UnselectButton("Open");
  608.          this.MyControlPanel.UnselectButton("Save");
  609.       }
  610.  
  611.       if (this.HelpWanted) {
  612.          new HelpDialog(this.frame, "Simulate");
  613.          this.UserWantsPointer();
  614.       } else if (!this.IsSimulating()) {
  615.          if (this.MyControlPanel != null) {
  616.             this.MyControlPanel.DisableButton("Pointer");
  617.             this.MyControlPanel.DisableButton("Wire");
  618.             this.MyControlPanel.DisableButton("Junction");
  619.             this.MyControlPanel.DisableButton("Text");
  620.             this.MyControlPanel.DisableButton("New");
  621.             this.MyControlPanel.DisableButton("Open");
  622.             this.MyControlPanel.DisableButton("Save");
  623.          }
  624.  
  625.          this.frame.DisableAllMenus();
  626.          this.frame.StartMenuItem.disable();
  627.          this.frame.StopMenuItem.enable();
  628.          this.SimulateStart();
  629.          ((Component)this).repaint();
  630.       } else {
  631.          if (this.MyControlPanel != null) {
  632.             this.MyControlPanel.EnableButton("Pointer");
  633.             this.MyControlPanel.EnableButton("Wire");
  634.             this.MyControlPanel.EnableButton("Junction");
  635.             this.MyControlPanel.EnableButton("Text");
  636.             this.MyControlPanel.EnableButton("New");
  637.             if (this.EnableFileOperations) {
  638.                this.MyControlPanel.EnableButton("Open");
  639.                this.MyControlPanel.EnableButton("Save");
  640.             }
  641.          }
  642.  
  643.          this.frame.EnableAllMenus();
  644.          this.frame.StopMenuItem.disable();
  645.          this.frame.StartMenuItem.enable();
  646.          this.SimulateStop();
  647.          this.UserWantsPointer();
  648.          ((Component)this).repaint();
  649.       }
  650.    }
  651.  
  652.    public void UserWantsNewSchematic() {
  653.       if (this.MySchematic != null) {
  654.          if (this.MyControlPanel != null) {
  655.             this.MyControlPanel.UnselectButton("Pointer");
  656.             this.MyControlPanel.UnselectButton("Wire");
  657.             this.MyControlPanel.UnselectButton("Junction");
  658.             this.MyControlPanel.UnselectButton("Text");
  659.             this.MyControlPanel.UnselectButton("Help");
  660.             this.MyControlPanel.UnselectButton("Simulate");
  661.             this.MyControlPanel.SelectButton("New");
  662.             this.MyControlPanel.UnselectButton("Open");
  663.             this.MyControlPanel.UnselectButton("Save");
  664.          }
  665.  
  666.          if (this.HelpWanted) {
  667.             new HelpDialog(this.frame, "New");
  668.             this.UserWantsPointer();
  669.          } else {
  670.             if (this.MySchematic.Modified) {
  671.                if (this.frame.NewDialog == null) {
  672.                   String[] var1 = new String[]{"OK", "Cancel"};
  673.                   this.frame.NewDialog = new SimpleDialog(this.frame, "New schematic", "Discard changes?", var1, 2, 1, 2, 2);
  674.                   this.UserWantsPointer();
  675.                   return;
  676.                }
  677.             } else {
  678.                this.MySchematic.DestroyComponents(this.PinGrid);
  679.                this.frame.setTitle("Digital Simulator [untitled]");
  680.                this.MySchematic.FileName = null;
  681.                this.MySchematic.Modified = false;
  682.                this.MySchematicPanel.repaint();
  683.                this.UserWantsPointer();
  684.                this.updateAnalyzer();
  685.             }
  686.  
  687.          }
  688.       }
  689.    }
  690.  
  691.    public void UserWantsOpenSchematic() {
  692.       if (this.MySchematic != null) {
  693.          if (this.MyControlPanel != null) {
  694.             this.MyControlPanel.UnselectButton("Pointer");
  695.             this.MyControlPanel.UnselectButton("Wire");
  696.             this.MyControlPanel.UnselectButton("Junction");
  697.             this.MyControlPanel.UnselectButton("Text");
  698.             this.MyControlPanel.UnselectButton("Help");
  699.             this.MyControlPanel.UnselectButton("Simulate");
  700.             this.MyControlPanel.UnselectButton("New");
  701.             this.MyControlPanel.SelectButton("Open");
  702.             this.MyControlPanel.UnselectButton("Save");
  703.          }
  704.  
  705.          if (this.HelpWanted) {
  706.             new HelpDialog(this.frame, "Open");
  707.             this.UserWantsPointer();
  708.          } else {
  709.             if (this.MySchematic.Modified) {
  710.                if (this.frame.OpenDialog == null) {
  711.                   String[] var2 = new String[]{"OK", "Cancel"};
  712.                   this.frame.OpenDialog = new SimpleDialog(this.frame, "Open schematic", "Discard changes?", var2, 2, 1, 3, 2);
  713.                   this.UserWantsPointer();
  714.                   return;
  715.                }
  716.             } else {
  717.                Schematic var1 = this.frame.DoFileOpenDialog(this.PinGrid, "Open schematic");
  718.                if (var1 != null) {
  719.                   this.MySchematic = var1;
  720.                   this.frame.setTitle("Digital Simulator [" + this.MySchematic.FileName + "]");
  721.                   this.MySchematicPanel.repaint();
  722.                }
  723.  
  724.                this.UserWantsPointer();
  725.             }
  726.  
  727.          }
  728.       }
  729.    }
  730.  
  731.    public void UserWantsOpenExample(String var1) {
  732.       if (this.MySchematic != null) {
  733.          if (this.MySchematic.Modified) {
  734.             if (this.frame.OpenExampleDialog == null) {
  735.                String[] var2 = new String[]{"OK", "Cancel"};
  736.                this.frame.ExampleFileName = var1;
  737.                this.frame.OpenExampleDialog = new SimpleDialog(this.frame, "Open example", "Discard changes?", var2, 2, 1, 7, 2);
  738.                this.UserWantsPointer();
  739.                return;
  740.             }
  741.          } else {
  742.             this.frame.LoadExample(var1);
  743.             this.UserWantsPointer();
  744.          }
  745.  
  746.       }
  747.    }
  748.  
  749.    public void UserWantsSaveSchematic() {
  750.       if (this.MySchematic != null) {
  751.          if (this.MyControlPanel != null) {
  752.             this.MyControlPanel.UnselectButton("Pointer");
  753.             this.MyControlPanel.UnselectButton("Wire");
  754.             this.MyControlPanel.UnselectButton("Junction");
  755.             this.MyControlPanel.UnselectButton("Text");
  756.             this.MyControlPanel.UnselectButton("Help");
  757.             this.MyControlPanel.UnselectButton("Simulate");
  758.             this.MyControlPanel.UnselectButton("New");
  759.             this.MyControlPanel.UnselectButton("Open");
  760.             this.MyControlPanel.SelectButton("Save");
  761.          }
  762.  
  763.          if (this.HelpWanted) {
  764.             new HelpDialog(this.frame, "Save");
  765.             this.UserWantsPointer();
  766.          } else {
  767.             if (this.MySchematic.FileName != null && this.MySchematic.FileDir != null) {
  768.                this.frame.DoFileSaveDialog(this.MySchematic, false, "Save schematic");
  769.             } else {
  770.                this.frame.DoFileSaveDialog(this.MySchematic, false, "Save schematic as");
  771.             }
  772.  
  773.             this.frame.setTitle("Digital Simulator [" + this.MySchematic.FileName + "]");
  774.             this.MySchematicPanel.repaint();
  775.             this.UserWantsPointer();
  776.          }
  777.       }
  778.    }
  779.  
  780.    public void UserWantsCopySchematic() {
  781.       if (this.HelpWanted) {
  782.          new HelpDialog(this.frame, "Copy");
  783.       } else {
  784.          this.MySchematicPanel.Copy();
  785.          this.frame.PasteMenuItem.enable();
  786.          this.MyControlPanel.EnableButton("Paste");
  787.       }
  788.  
  789.       this.MyControlPanel.UnselectButton("Copy");
  790.       this.UserWantsPointer();
  791.    }
  792.  
  793.    public void UserWantsPasteSchematic() {
  794.       if (this.HelpWanted) {
  795.          new HelpDialog(this.frame, "Paste");
  796.       } else {
  797.          this.MySchematicPanel.Paste();
  798.       }
  799.  
  800.       this.MyControlPanel.UnselectButton("Paste");
  801.       this.UserWantsPointer();
  802.    }
  803.  
  804.    public void UserWantsCutSchematic() {
  805.       if (this.HelpWanted) {
  806.          new HelpDialog(this.frame, "Cut");
  807.       } else {
  808.          this.MySchematicPanel.Cut();
  809.          this.frame.CutMenuItem.disable();
  810.          this.frame.CopyMenuItem.disable();
  811.          this.frame.PasteMenuItem.enable();
  812.          this.MyControlPanel.DisableButton("Cut");
  813.          this.MyControlPanel.DisableButton("Copy");
  814.          this.MyControlPanel.EnableButton("Paste");
  815.       }
  816.  
  817.       this.MyControlPanel.UnselectButton("Cut");
  818.       this.UserWantsPointer();
  819.    }
  820.  
  821.    public void UserWantsOpenExample() {
  822.       if (this.HelpWanted) {
  823.          new HelpDialog(this.frame, "Open example");
  824.       } else {
  825.          if (this.MyExamplesFrame == null) {
  826.             this.MyExamplesFrame = new ExamplesFrame(this);
  827.          }
  828.  
  829.       }
  830.    }
  831.  
  832.    public void UserWantsCopyToSchematic() {
  833.       if (this.HelpWanted) {
  834.          new HelpDialog(this.frame, "CopyTo");
  835.       } else {
  836.          this.MySchematicPanel.CopyTo();
  837.          this.frame.PasteMenuItem.enable();
  838.          this.MyControlPanel.EnableButton("Paste");
  839.       }
  840.  
  841.       this.UserWantsPointer();
  842.    }
  843.  
  844.    public void UserWantsPasteFromSchematic() {
  845.       if (this.HelpWanted) {
  846.          new HelpDialog(this.frame, "PasteFrom");
  847.       } else {
  848.          this.MySchematicPanel.PasteFrom();
  849.       }
  850.  
  851.       this.UserWantsPointer();
  852.    }
  853.  
  854.    public void UserWantsOptions() {
  855.       if (this.HelpWanted) {
  856.          new HelpDialog(this.frame, "Options");
  857.       } else if (this.MyOptionsFrame == null) {
  858.          this.MyOptionsFrame = new OptionsFrame(this);
  859.       }
  860.  
  861.       this.UserWantsPointer();
  862.    }
  863.  
  864.    public void UserWantsAnalyzer() {
  865.       if (this.HelpWanted) {
  866.          new HelpDialog(this.frame, "Analyzer");
  867.       } else {
  868.          if (this.MyAnalyzerFrame == null) {
  869.             this.MyAnalyzerFrame = new AnalyzerFrame(this);
  870.          }
  871.  
  872.       }
  873.    }
  874.  
  875.    public void updateAnalyzer() {
  876.       if (this.MyAnalyzerFrame != null) {
  877.          this.MyAnalyzerFrame.repaint();
  878.       }
  879.  
  880.    }
  881.  
  882.    static {
  883.       BackGroundColor = Color.black;
  884.       GridColor = Color.green;
  885.    }
  886. }
  887.