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

  1. import java.awt.BorderLayout;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.Dimension;
  6. import java.awt.Event;
  7. import java.awt.Font;
  8. import java.awt.FontMetrics;
  9. import java.awt.Frame;
  10. import java.awt.Graphics;
  11. import java.awt.Image;
  12. import java.awt.MediaTracker;
  13. import java.awt.Panel;
  14. import java.awt.Scrollbar;
  15. import java.util.Vector;
  16.  
  17. class AnalyzerPanel extends Panel {
  18.    static final int CHANNEL_HEIGHT = 50;
  19.    static final int DISPLAY_OFFSET = 5;
  20.    static final int CLOCK_WIDTH = 10;
  21.    static final int LINE_OFFSET = 5;
  22.    static final int BUTTON_X_OFFSET = 5;
  23.    static final int BUTTON_Y_OFFSET = 22;
  24.    static final int BUTTON_CLOCK_NONE = 48;
  25.    static final int BUTTON_CLOCK_NONE_PRESSED = 24;
  26.    static final int BUTTON_CLOCK_UP_PRESSED = 72;
  27.    static final int BUTTON_CLOCK_UP_SELECTED = 96;
  28.    static final int BUTTON_CLOCK_DN_PRESSED = 120;
  29.    static final int BUTTON_CLOCK_DN_SELECTED = 144;
  30.    static final Color TextColor;
  31.    static final Color BackGroundColor;
  32.    protected Scrollbar myVertical;
  33.    DigSim applet;
  34.    Image OffScreenImage;
  35.    Image ImageBuffer;
  36.    Image CopyImage;
  37.    Graphics cig;
  38.    int ButtonOffset;
  39.    // $FF: renamed from: og java.awt.Graphics
  40.    Graphics field_0;
  41.    Dimension ImageSize;
  42.    protected Font AnalyzerFont;
  43.    protected FontMetrics AnalyzerFontMetrics;
  44.    Vector probes;
  45.    boolean ImageButtonsDisabled = false;
  46.    Probe PressedProbe;
  47.    Probe DragProbe;
  48.    int CurrentCol;
  49.    boolean ImageUpdated = false;
  50.    Frame frame;
  51.  
  52.    public AnalyzerPanel(DigSim var1, Frame var2) {
  53.       this.applet = var1;
  54.       this.frame = var2;
  55.       ((Container)this).setLayout(new BorderLayout());
  56.       this.AnalyzerFont = new Font("TimesRoman", 0, 14);
  57.       this.AnalyzerFontMetrics = ((Component)this).getFontMetrics(this.AnalyzerFont);
  58.       super.setLayout(new BorderLayout());
  59.       this.LoadButtonsImage();
  60.       this.myVertical = new Scrollbar(1);
  61.       ((Container)this).add("East", this.myVertical);
  62.       this.ImageSize = new Dimension(400, 250);
  63.       this.CheckOffScreenImage();
  64.       ((Component)this).repaint();
  65.    }
  66.  
  67.    public void AdjustScrollbar() {
  68.       if (this.probes != null) {
  69.          int var2 = 50 * this.probes.size();
  70.          int var3 = ((Component)this).size().height;
  71.          int var4 = var2 - var3;
  72.          if (var4 < 0) {
  73.             var4 = 0;
  74.          }
  75.  
  76.          String var1 = System.getProperty("os.name");
  77.          if (!var1.equals("Windows 95") && !var1.equals("Windows NT")) {
  78.             this.myVertical.setValues(this.myVertical.getValue(), var3, 0, var4);
  79.          } else {
  80.             this.myVertical.setValues(this.myVertical.getValue(), var3, 0, var4 + var3);
  81.          }
  82.       }
  83.    }
  84.  
  85.    public void CheckOffScreenImage() {
  86.       if (this.OffScreenImage == null) {
  87.          this.PrepareOffScreenImage();
  88.       } else {
  89.          if (((Component)this).size().width > this.ImageSize.width || ((Component)this).size().height > this.ImageSize.height) {
  90.             this.ImageSize.width = ((Component)this).size().width;
  91.             this.ImageSize.height = ((Component)this).size().height;
  92.             this.PrepareOffScreenImage();
  93.          }
  94.  
  95.       }
  96.    }
  97.  
  98.    public void PrepareOffScreenImage() {
  99.       this.OffScreenImage = this.applet.createImage(this.ImageSize.width, this.ImageSize.height);
  100.       this.field_0 = this.OffScreenImage.getGraphics();
  101.       this.field_0.setFont(this.AnalyzerFont);
  102.       ((Component)this).repaint();
  103.    }
  104.  
  105.    public void SelectButton(int var1) {
  106.       this.cig.copyArea(0, var1, 24, 24, 0, -var1);
  107.    }
  108.  
  109.    public void ButtonPressed(int var1) {
  110.       Probe var2 = (Probe)this.probes.elementAt(var1);
  111.       this.PressedProbe = var2;
  112.       if (var2.clockup_probe) {
  113.          var2.clockup_probe = false;
  114.          var2.clockdn_probe = true;
  115.       } else if (var2.clockdn_probe) {
  116.          var2.clockup_probe = false;
  117.          var2.clockdn_probe = false;
  118.       } else {
  119.          var2.clockup_probe = true;
  120.          var2.clockdn_probe = false;
  121.       }
  122.  
  123.       for(int var3 = 0; var3 < this.probes.size(); ++var3) {
  124.          if (var1 != var3) {
  125.             var2 = (Probe)this.probes.elementAt(var3);
  126.             var2.clockup_probe = false;
  127.             var2.clockdn_probe = false;
  128.          }
  129.       }
  130.  
  131.       ((Component)this).repaint();
  132.    }
  133.  
  134.    public boolean mouseDown(Event var1, int var2, int var3) {
  135.       this.PressedProbe = null;
  136.       this.DragProbe = null;
  137.  
  138.       for(int var5 = 0; var5 < this.probes.size(); ++var5) {
  139.          int var6 = var5 * 50 + 22 - this.myVertical.getValue();
  140.          if (var2 >= 5 && var2 <= 29 && var3 >= var6 && var3 <= var6 + 24) {
  141.             this.ButtonPressed(var5);
  142.          }
  143.       }
  144.  
  145.       for(int var7 = 0; var7 < this.probes.size(); ++var7) {
  146.          Probe var4 = (Probe)this.probes.elementAt(var7);
  147.          if (var2 >= var4.ChannelPos.x && var3 >= var4.ChannelPos.y && var2 <= var4.ChannelPos.x + var4.ChannelDim.width && var3 <= var4.ChannelPos.y + var4.ChannelDim.height) {
  148.             this.DragProbe = var4;
  149.             ((Component)this).repaint();
  150.             return true;
  151.          }
  152.       }
  153.  
  154.       return true;
  155.    }
  156.  
  157.    public boolean mouseUp(Event var1, int var2, int var3) {
  158.       if (this.DragProbe != null) {
  159.          this.DragProbe = null;
  160.          ((Component)this).repaint();
  161.       }
  162.  
  163.       if (this.PressedProbe != null) {
  164.          this.PressedProbe = null;
  165.          ((Component)this).repaint();
  166.       }
  167.  
  168.       return true;
  169.    }
  170.  
  171.    public boolean mouseDrag(Event var1, int var2, int var3) {
  172.       if (this.DragProbe != null) {
  173.          for(int var5 = 0; var5 < this.probes.size(); ++var5) {
  174.             Probe var4 = (Probe)this.probes.elementAt(var5);
  175.             if (var2 >= var4.ChannelPos.x && var3 >= var4.ChannelPos.y && var2 <= var4.ChannelPos.x + var4.ChannelDim.width && var3 <= var4.ChannelPos.y + var4.ChannelDim.height && var4 != this.DragProbe) {
  176.                this.applet.MySchematic.SwapComponents(var4, this.DragProbe);
  177.                ((Component)this).repaint();
  178.                return true;
  179.             }
  180.          }
  181.       }
  182.  
  183.       return true;
  184.    }
  185.  
  186.    public void DrawProbeHistory(Graphics var1, Probe var2) {
  187.       var1.setColor(Color.green);
  188.  
  189.       for(int var3 = 0; var3 < 100; ++var3) {
  190.          if (var3 > 0 && var2.LevelHistory[var3 - 1] != var2.LevelHistory[var3]) {
  191.             this.field_0.drawLine(var2.ChannelPos.x + var3 * 10, var2.ChannelPos.y + 5, var2.ChannelPos.x + var3 * 10, var2.ChannelPos.y + var2.ChannelDim.height - 5);
  192.          }
  193.  
  194.          if (var2.LevelHistory[var3] == 5) {
  195.             var1.setColor(Color.green);
  196.             var1.drawLine(var2.ChannelPos.x + var3 * 10, var2.ChannelPos.y + 5, var2.ChannelPos.x + (var3 + 1) * 10, var2.ChannelPos.y + 5);
  197.          } else {
  198.             var1.setColor(Color.green);
  199.             var1.drawLine(var2.ChannelPos.x + var3 * 10, var2.ChannelPos.y + var2.ChannelDim.height - 5, var2.ChannelPos.x + (var3 + 1) * 10, var2.ChannelPos.y + var2.ChannelDim.height - 5);
  200.          }
  201.       }
  202.  
  203.    }
  204.  
  205.    public void DrawNoProbes(Graphics var1) {
  206.       String var2 = "There are no probes to display.";
  207.       int var3 = this.AnalyzerFontMetrics.stringWidth(var2);
  208.       int var4 = (((Component)this).size().width - var3) / 2;
  209.       var1.setColor(Color.black);
  210.       var1.drawString(var2, var4, ((Component)this).size().height / 2);
  211.    }
  212.  
  213.    public void DrawEmptyProbes(Graphics var1) {
  214.       this.probes = this.applet.MySchematic.getProbes();
  215.       int var5 = 30;
  216.       int var6 = this.myVertical.getValue();
  217.       var1.setColor(Color.lightGray);
  218.       var1.fillRect(0, 0, this.ImageSize.width, this.ImageSize.height);
  219.       if (this.probes.size() == 0) {
  220.          this.DrawNoProbes(var1);
  221.       } else {
  222.          for(int var7 = 0; var7 < this.probes.size(); ++var7) {
  223.             Probe var2 = (Probe)this.probes.elementAt(var7);
  224.             int var4 = this.AnalyzerFontMetrics.stringWidth(var2.IPin[0].getName());
  225.             if (var4 > var5) {
  226.                var5 = var4;
  227.             }
  228.          }
  229.  
  230.          for(int var8 = 0; var8 < this.probes.size(); ++var8) {
  231.             Probe var10 = (Probe)this.probes.elementAt(var8);
  232.             int var3 = var8 * 50 - var6;
  233.             var1.setColor(TextColor);
  234.             var1.drawString(var10.IPin[0].getName(), 5, var3 + 16);
  235.             var1.setColor(Color.gray);
  236.             var1.drawLine(0, var3 + 50 - 2, ((Component)this).size().width, var3 + 50 - 2);
  237.             var1.setColor(Color.white);
  238.             var1.drawLine(0, var3 + 50 - 1, ((Component)this).size().width, var3 + 50 - 1);
  239.             var10.ChannelPos.x = 5 + var5 + 5;
  240.             var10.ChannelPos.y = 5 + var3;
  241.             var10.ChannelDim.width = ((Component)this).size().width - (5 + var5 + 20);
  242.             var10.ChannelDim.height = 40;
  243.             var1.setColor(BackGroundColor);
  244.             var1.fillRect(var10.ChannelPos.x, var10.ChannelPos.y + 1, var10.ChannelDim.width, var10.ChannelDim.height - 1);
  245.             if (var10.clockup_probe) {
  246.                if (var10 == this.PressedProbe) {
  247.                   this.SelectButton(72);
  248.                } else {
  249.                   this.SelectButton(96);
  250.                }
  251.             } else if (var10.clockdn_probe) {
  252.                if (var10 == this.PressedProbe) {
  253.                   this.SelectButton(120);
  254.                } else {
  255.                   this.SelectButton(144);
  256.                }
  257.             } else if (var10 == this.PressedProbe) {
  258.                this.SelectButton(24);
  259.             } else {
  260.                this.SelectButton(48);
  261.             }
  262.  
  263.             this.DrawProbeHistory(var1, var10);
  264.             Graphics var9 = this.ImageBuffer.getGraphics();
  265.             var9.drawImage(this.CopyImage, 0, 0, this);
  266.             var1.drawImage(this.ImageBuffer, 5, 22 + var3, this);
  267.          }
  268.  
  269.          if (this.DragProbe != null) {
  270.             var1.setColor(Color.red);
  271.             var1.drawRect(this.DragProbe.ChannelPos.x, this.DragProbe.ChannelPos.y, this.DragProbe.ChannelDim.width, this.DragProbe.ChannelDim.height);
  272.          }
  273.  
  274.       }
  275.    }
  276.  
  277.    public synchronized void paint(Graphics var1) {
  278.       if (this.OffScreenImage != null) {
  279.          this.AdjustScrollbar();
  280.          if (this.probes != null && ((Component)this).size().height >= 50 * this.probes.size()) {
  281.             this.update(var1);
  282.          } else if (!this.ImageUpdated) {
  283.             this.update(var1);
  284.          } else {
  285.             var1.drawImage(this.OffScreenImage, 0, 0, this);
  286.          }
  287.       }
  288.    }
  289.  
  290.    public synchronized void update(Graphics var1) {
  291.       this.AdjustScrollbar();
  292.       this.CheckOffScreenImage();
  293.       if (this.OffScreenImage != null) {
  294.          this.DrawEmptyProbes(this.field_0);
  295.          var1.drawImage(this.OffScreenImage, 0, 0, this);
  296.          this.ImageUpdated = true;
  297.       }
  298.    }
  299.  
  300.    public boolean handleEvent(Event var1) {
  301.       if (var1.target instanceof Scrollbar) {
  302.          ((Component)this).repaint();
  303.          return true;
  304.       } else {
  305.          return super.handleEvent(var1);
  306.       }
  307.    }
  308.  
  309.    public boolean action(Event var1, Object var2) {
  310.       return false;
  311.    }
  312.  
  313.    public void update(Probe var1) {
  314.       int var2 = this.CurrentCol * 10;
  315.       if (var2 >= var1.ChannelDim.width) {
  316.          if (var1.clockup_probe && var1.OldLevel == 0 && var1.IPin[0].getLevel() == 5) {
  317.             this.CurrentCol = 0;
  318.             return;
  319.          }
  320.  
  321.          if (var1.clockdn_probe && var1.OldLevel == 5 && var1.IPin[0].getLevel() == 0) {
  322.             this.CurrentCol = 0;
  323.          }
  324.       }
  325.  
  326.    }
  327.  
  328.    public void drawLevel(Probe var1) {
  329.       int var2 = this.CurrentCol * 10;
  330.       if (var2 < var1.ChannelDim.width) {
  331.          if (this.CurrentCol == 0) {
  332.             this.field_0.setColor(BackGroundColor);
  333.             this.field_0.fillRect(var1.ChannelPos.x + var2, var1.ChannelPos.y + 1, 11, var1.ChannelDim.height - 1);
  334.          }
  335.  
  336.          this.field_0.setColor(BackGroundColor);
  337.          this.field_0.fillRect(var1.ChannelPos.x + var2 + 1, var1.ChannelPos.y + 1, 10, var1.ChannelDim.height - 1);
  338.          if (this.CurrentCol > 0 && var1.IPin[0].getLevel() != var1.OldLevel) {
  339.             this.field_0.setColor(Color.green);
  340.             this.field_0.drawLine(var1.ChannelPos.x + var2, var1.ChannelPos.y + 5, var1.ChannelPos.x + var2, var1.ChannelPos.y + var1.ChannelDim.height - 5);
  341.          }
  342.  
  343.          if (this.CurrentCol < 100) {
  344.             var1.LevelHistory[this.CurrentCol] = var1.IPin[0].getLevel();
  345.          }
  346.  
  347.          if (var1.IPin[0].getLevel() == 5) {
  348.             this.field_0.setColor(Color.green);
  349.             this.field_0.drawLine(var1.ChannelPos.x + var2, var1.ChannelPos.y + 5, var1.ChannelPos.x + var2 + 10, var1.ChannelPos.y + 5);
  350.          } else {
  351.             this.field_0.setColor(Color.green);
  352.             this.field_0.drawLine(var1.ChannelPos.x + var2, var1.ChannelPos.y + var1.ChannelDim.height - 5, var1.ChannelPos.x + var2 + 10, var1.ChannelPos.y + var1.ChannelDim.height - 5);
  353.          }
  354.  
  355.          this.paint(((Component)this).getGraphics());
  356.       }
  357.    }
  358.  
  359.    public void update() {
  360.       if (this.probes != null) {
  361.          for(int var2 = 0; var2 < this.probes.size(); ++var2) {
  362.             Probe var1 = (Probe)this.probes.elementAt(var2);
  363.             this.update(var1);
  364.          }
  365.  
  366.          for(int var4 = 0; var4 < this.probes.size(); ++var4) {
  367.             Probe var3 = (Probe)this.probes.elementAt(var4);
  368.             this.drawLevel(var3);
  369.             var3.OldLevel = var3.IPin[0].getLevel();
  370.          }
  371.  
  372.          this.paint(((Component)this).getGraphics());
  373.          ++this.CurrentCol;
  374.       }
  375.    }
  376.  
  377.    public void LoadButtonsImage() {
  378.       MediaTracker var2 = new MediaTracker(this);
  379.       Image var1 = this.applet.getImage(this.applet.getDocumentBase(), "images/all_analyzer.gif");
  380.       var2.addImage(var1, 0);
  381.  
  382.       try {
  383.          Thread.currentThread().setPriority(1);
  384.          var2.waitForAll();
  385.       } catch (Exception var6) {
  386.          String var4 = ((Throwable)var6).toString();
  387.          String[] var5 = new String[]{"OK"};
  388.          new SimpleDialog((DigSimFrame)null, "Reading imagebuttons", var4, var5, 1, 0, 0, 1);
  389.          return;
  390.       }
  391.  
  392.       if (var2.isErrorAny()) {
  393.          this.ImageButtonsDisabled = true;
  394.          String var3 = "Can't read images/all_analyzer.gif ImageButtons will be disabled";
  395.          String[] var7 = new String[]{"OK"};
  396.          new SimpleDialog((DigSimFrame)null, "Error while reading imagebuttons", var3, var7, 1, 0, 0, 1);
  397.       } else {
  398.          this.ImageBuffer = this.applet.createImage(var1.getWidth(this), 24);
  399.          this.CopyImage = this.applet.createImage(var1.getWidth(this), var1.getHeight(this));
  400.          this.cig = this.CopyImage.getGraphics();
  401.          this.cig.drawImage(var1, 0, 0, this);
  402.       }
  403.    }
  404.  
  405.    static {
  406.       TextColor = Color.black;
  407.       BackGroundColor = Color.black;
  408.    }
  409. }
  410.