home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / ed8n1t2i / schematicpanel.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  28.3 KB  |  648 lines

  1. //****************************************************************************
  2. // ---- version information ----
  3. //
  4. // SchematicPanel.java   v 1.00 b3
  5. // Written by:           I. van Rienen / E-mail ivr@bart.nl
  6. // URL:                  http://www/bart.nl/~ivr
  7. // Initial release:           v 1.00b1 01-03-1996
  8. //                            v 1.00b3 26-03-1996 Scrollbar bug fixed on other platforms than Win95/NT
  9. // Released in public domain: v 1.00b1 01-03-1996
  10. // Released in public domain:
  11. //
  12. // ---- Description ----
  13. // Java class containing methods for creating and handling the main
  14. // schematic panel.
  15. //
  16. // This program and the Java source is in the public domain.
  17. // Permission to use, copy, modify, and distribute this software
  18. // and its documentation for NON-COMMERCIAL purposes and
  19. // without fee is hereby granted.
  20. //
  21. //    Copyright 1996
  22. //
  23. //    Iwan van Rienen
  24. //    Joan Maetsuyckerstr. 145
  25. //    2593 ZG  The Hague
  26. //    The Netherlands
  27. //
  28. // I am not responsible for any bugs in this program and
  29. // possible damage to hard- or software when using this program.
  30. //****************************************************************************
  31. import java.applet.Applet;
  32. import java.awt.*;
  33. import java.util.Vector;
  34.  
  35. class SchematicPanel extends Panel {
  36.     protected Scrollbar myHorizontal;
  37.     protected Scrollbar myVertical;
  38.     DigSim applet;
  39.     static final int GridStep = 8;
  40.     static final int hgs = GridStep / 2;
  41.     Wire NewWire = null;
  42.     ElectronicComponent ComponentPressed = null;
  43.     ElectronicComponent PrevSelectedComponent = null;
  44.     int OldMouseX = 0, OldMouseY = 0;
  45.     boolean WireDrawing = false;
  46.     boolean JunctionDrawing = false;
  47.     protected Font SchematicFont;
  48.     protected FontMetrics SchematicFontMetrics;
  49.     static final Color BorderColor = Color.red;
  50.     int GridXOffset = 0, GridYOffset = 0;
  51.     boolean SelectBox = false;
  52.     int SelectBoxX1, SelectBoxY1;
  53.     int SelectBoxX2, SelectBoxY2;
  54.     Schematic SelectSchematic;
  55.     Schematic CopySchematic = null;
  56.     static final Color JunctionColor = Color.white;
  57.     boolean AutoJunction = true;
  58.  
  59. //----------------------------------------------------------------------------
  60. // The constructor of a new Schematic Panel.
  61. //----------------------------------------------------------------------------
  62.     public SchematicPanel(DigSim app) {
  63.         applet = app;
  64.         SelectSchematic = new Schematic();
  65.         setLayout( new BorderLayout());
  66.         SchematicFont = new Font("TimesRoman",Font.PLAIN, 20);
  67.         SchematicFontMetrics = getFontMetrics(SchematicFont);
  68.         setFont(SchematicFont);
  69.         super.setLayout( new BorderLayout());
  70.         myVertical = new Scrollbar(Scrollbar.VERTICAL);
  71.         add( "East", myVertical);
  72.         myHorizontal = new Scrollbar(Scrollbar.HORIZONTAL);
  73.         add( "South", myHorizontal);
  74.         repaint();
  75.     }
  76.  
  77. //----------------------------------------------------------------------------
  78. // handle the Events in this Panel.
  79. //----------------------------------------------------------------------------
  80.     public boolean handleEvent(Event e) {
  81.         if (e.target instanceof Scrollbar) {
  82. //          System.out.println ("Scrollbar hit!");
  83.             repaint();
  84.             return true;
  85.         }
  86.         super.handleEvent(e);
  87.         return false;
  88.     }
  89.  
  90. //----------------------------------------------------------------------------
  91. // Cut the selected components from the schematic.
  92. //----------------------------------------------------------------------------
  93.     public void Cut() {
  94.         applet.MySchematic.RemoveSameElements(applet.PinGrid, SelectSchematic);
  95.         CopySchematic = new Schematic(SelectSchematic);
  96.         SelectSchematic.RemoveAllComponents();
  97.         applet.updateAnalyzer();
  98.         repaint();
  99.     }
  100.  
  101. //----------------------------------------------------------------------------
  102. // Copy the selected components to a buffer
  103. //----------------------------------------------------------------------------
  104.     public void Copy() {
  105.         CopySchematic = new Schematic(SelectSchematic);
  106.     }
  107.  
  108. //----------------------------------------------------------------------------
  109. // Paste the components in the buffer to the schematic.
  110. //----------------------------------------------------------------------------
  111.     public void Paste() {
  112.         if (CopySchematic != null) {    // Should not be null
  113.             SelectSchematic.RemoveAllComponents();  // remove old selected components
  114.             SelectSchematic = applet.MySchematic.PasteSchematic(applet.PinGrid, CopySchematic, GridXOffset, GridYOffset);
  115.             applet.frame.CutMenuItem.enable();
  116.             applet.frame.CopyMenuItem.enable();
  117.             if (applet.EnableFileOperations) {
  118.                 applet.frame.CopyDiskMenuItem.enable();
  119.             }
  120.             applet.MyControlPanel.EnableButton ("Cut");
  121.             applet.MyControlPanel.EnableButton ("Copy");
  122.             applet.updateAnalyzer();
  123.             repaint();
  124.         }
  125.     }
  126.  
  127. //----------------------------------------------------------------------------
  128. // Copy the selected components to disk.
  129. //----------------------------------------------------------------------------
  130.     public void CopyTo() {
  131.         applet.frame.DoFileSaveDialog(SelectSchematic, true, "Copy to");
  132.     }
  133.  
  134. //----------------------------------------------------------------------------
  135. // Load components from disk and put it in the copy buffer.
  136. //----------------------------------------------------------------------------
  137.     public void PasteFrom() {
  138.         Schematic LoadSchematic;
  139.  
  140.         LoadSchematic = applet.frame.DoFileOpenDialog(null, "Paste from");
  141.         if (LoadSchematic != null) {
  142.             SelectSchematic.RemoveAllComponents();  // remove old selected components
  143.             SelectSchematic = applet.MySchematic.PasteSchematic(applet.PinGrid, LoadSchematic, GridXOffset, GridYOffset);
  144.  
  145.             applet.frame.CutMenuItem.enable();
  146.             applet.frame.CopyMenuItem.enable();
  147.             if (applet.EnableFileOperations) {
  148.                 applet.frame.CopyDiskMenuItem.enable();
  149.             }
  150.             applet.MyControlPanel.EnableButton ("Cut");
  151.             applet.MyControlPanel.EnableButton ("Copy");
  152.             applet.updateAnalyzer();
  153.             repaint();
  154.         }
  155.     }
  156.  
  157. //----------------------------------------------------------------------------
  158. // Select all components in the schematic
  159. //----------------------------------------------------------------------------
  160.     public void SelectAll() {
  161.         SelectSchematic = new Schematic(applet.MySchematic);
  162.         if (SelectSchematic.size() > 0) {
  163.             SelectSchematic.SetAllComponentsSelected();
  164.             applet.frame.CutMenuItem.enable();
  165.             applet.frame.CopyMenuItem.enable();
  166.             applet.frame.PasteMenuItem.enable();
  167.             if (applet.EnableFileOperations) {
  168.                 applet.frame.CopyDiskMenuItem.enable();
  169.             }
  170.             applet.MyControlPanel.EnableButton ("Cut");
  171.             applet.MyControlPanel.EnableButton ("Copy");
  172.             applet.MyControlPanel.EnableButton ("Paste");
  173.         } else {
  174.             applet.frame.CutMenuItem.disable();
  175.             applet.frame.CopyMenuItem.disable();
  176.             applet.frame.PasteMenuItem.disable();
  177.             if (applet.EnableFileOperations) {
  178.                 applet.frame.CopyDiskMenuItem.disable();
  179.             }
  180.             applet.MyControlPanel.DisableButton ("Cut");
  181.             applet.MyControlPanel.DisableButton ("Copy");
  182.             applet.MyControlPanel.DisableButton ("Paste");
  183.         }
  184.         repaint();
  185.     }
  186.  
  187. //----------------------------------------------------------------------------
  188. // Check the dimensions of this Panel and adjust scrollbars if needed
  189. //----------------------------------------------------------------------------
  190.     public void CheckDimensions() {
  191.         int width = size().width;
  192.         int height = size().height;
  193.  
  194. //      System.out.println ("SchematicPanel CheckDimensions()");
  195.         int VisibleXGridPoints = (width / applet.GridStep) - 1;
  196.         int VisibleYGridPoints = (height / applet.GridStep) - 1;
  197.         int XOverlap = VisibleXGridPoints + GridXOffset - applet.MaxXPoints - 1;
  198.         int YOverlap = VisibleYGridPoints + GridYOffset - applet.MaxYPoints - 1;
  199. //      System.out.println ("XOverlap: " + XOverlap );
  200. //      System.out.println ("YOverlap: " + YOverlap );
  201.         if (XOverlap > 0) {
  202.             GridXOffset -= XOverlap;
  203.             if (GridXOffset < 0) GridXOffset = 0; // should not occure
  204.             myHorizontal.setValue(GridXOffset);
  205.         }
  206.         if (YOverlap > 0) {
  207.             GridYOffset -= YOverlap;
  208.             if (GridYOffset < 0) GridYOffset = 0; // should not occure
  209.             myVertical.setValue(GridYOffset);
  210.         }
  211.     }
  212.  
  213. //----------------------------------------------------------------------------
  214. // Set new values of the Scrollbars according to the visible area
  215. //----------------------------------------------------------------------------
  216.     public void AdjustScrollbars() {
  217.         String OSName;
  218.         GridXOffset = myHorizontal.getValue();
  219.         GridYOffset = myVertical.getValue();
  220. //      System.out.println ("Scrollbar XY offset = " + GridXOffset + ", " + GridYOffset);
  221.         int VisibleXGridPoints = (size().width / applet.GridStep) - 1;
  222.         int VisibleYGridPoints = (size().height / applet.GridStep) - 1;
  223. //      System.out.println ("Visible XY in this panel = " + VisibleXGridPoints + ", " + VisibleYGridPoints);
  224.  
  225.         // Determine OS because of scrollbar implementation differences
  226.         // between Win95/NT and other operating systems.
  227.         OSName = System.getProperty("os.name");
  228.         if (OSName.equals ("Windows 95") ||
  229.             OSName.equals ("Windows NT")) {
  230.             myVertical.setValues(GridYOffset, VisibleYGridPoints, 0, applet.MaxYPoints + 1);
  231.             myHorizontal.setValues(GridXOffset, VisibleXGridPoints, 0, applet.MaxXPoints + 1);
  232.         } else {
  233.             myVertical.setValues(GridYOffset, VisibleYGridPoints, 0, applet.MaxYPoints + 1 - VisibleYGridPoints);
  234.             myHorizontal.setValues(GridXOffset, VisibleXGridPoints, 0, applet.MaxXPoints + 1 - VisibleXGridPoints);
  235.         }
  236.     }
  237.  
  238. //----------------------------------------------------------------------------
  239. // Draw a border around the schematic.
  240. //----------------------------------------------------------------------------
  241.     public void DrawBorder (Graphics g) {
  242.         g.setColor (BorderColor);
  243.         g.drawRect ( (-GridXOffset) * GridStep + GridStep / 2, (-GridYOffset) * GridStep + GridStep / 2,
  244.                 (applet.MaxXPoints -1 ) * GridStep , (applet.MaxYPoints -1 ) * GridStep );
  245.         // Delete the grid points behind right- and under bottom border
  246.         g.setColor (applet.BackGroundColor);
  247.         // draw line behind right border
  248.         g.drawLine ((applet.MaxXPoints - GridXOffset) * GridStep, 0,
  249.                     (applet.MaxXPoints - GridXOffset) * GridStep,
  250.                     (applet.MaxYPoints - GridYOffset) * GridStep);
  251.         // draw line under bottom border
  252.         g.drawLine (0,(applet.MaxYPoints - GridYOffset) * GridStep,
  253.                     (applet.MaxXPoints - GridXOffset) * GridStep,
  254.                     (applet.MaxYPoints - GridYOffset) * GridStep);
  255.  
  256.     }
  257.  
  258. //----------------------------------------------------------------------------
  259. // Display a message when Images are not yet ready.
  260. //----------------------------------------------------------------------------
  261.     public void TellNotReady (Graphics g) {
  262.         String msg = "Please wait, I'm preparing the image";
  263.         g.setColor (Color.green);
  264.         g.fillRect (0, 0, size().width, size().height);
  265.         g.setColor (Color.black);
  266.         g.drawString(msg, size().width / 2 - SchematicFontMetrics.stringWidth(msg) / 2,
  267.                           size().height / 2);
  268.     }
  269.  
  270. //----------------------------------------------------------------------------
  271. // Paint the ImageBuffer
  272. //----------------------------------------------------------------------------
  273.     public synchronized void paint(Graphics g) {
  274.         CheckDimensions();
  275.         if (applet.OffScreenWidth < size().width ||
  276.             applet.OffScreenHeight < size().height) {
  277.                 update(g);
  278.         }
  279.         if (applet.ImagesReady())  {
  280.             g.drawImage (applet.ImageBuffer, 0, 0, this);
  281.         } else {
  282.             // System.out.println ("update Not ready");
  283.             TellNotReady (g);
  284.         }
  285.     }
  286.  
  287.  
  288. //----------------------------------------------------------------------------
  289. // Redraw the whole schematic and put it to the screen
  290. //----------------------------------------------------------------------------
  291.     public synchronized void update(Graphics g) {
  292.         CheckDimensions();
  293.         if (applet.OffScreenWidth < size().width ||
  294.             applet.OffScreenHeight < size().height) {
  295.                 // System.out.println ("Image need resize");
  296.                 applet.OffScreenHeight = size().height;
  297.                 applet.OffScreenWidth = size().width;
  298.                 applet.SetUpImages();
  299.         }
  300.         AdjustScrollbars();
  301.         if (applet.ImagesReady())  {
  302.             applet.ibg.drawImage (applet.GridImage, 0, 0, this);
  303.             DrawBorder(applet.ibg);
  304.  
  305.             applet.MySchematic.draw(applet.ibg, GridXOffset, GridYOffset, GridStep);
  306.             if (NewWire != null) {
  307.                 NewWire.draw(applet.ibg, GridXOffset, GridYOffset, GridStep);  // Draw new Wire prototype
  308.             }
  309.             if (SelectBox) DrawSelectBox();
  310.             DrawJunctions (applet.PinGrid, applet.ibg, GridXOffset, GridYOffset, GridStep);
  311.             g.drawImage (applet.ImageBuffer, 0, 0, this);
  312.         } else {
  313.             // System.out.println ("paint Not ready");
  314.             TellNotReady (g);
  315.         }
  316.     }
  317.  
  318. //----------------------------------------------------------------------------
  319. // Draw all junctions
  320. //----------------------------------------------------------------------------
  321.     public void DrawJunctions(Pin PinGrid[][], Graphics g, int xo, int yo, int gs) {
  322.         int x, y, cCnt;
  323.  
  324.         // calculate end x,y
  325.         int xe = (size().width / applet.GridStep) + xo - 1;
  326.         int ye = (size().height / applet.GridStep) + yo - 1 ;
  327.  
  328.         // Should not occure, but make sure we don't exceed array dimension
  329.         if (xe >= applet.MaxXPoints) xe = applet.MaxXPoints - 1;
  330.         if (ye >= applet.MaxYPoints) ye = applet.MaxYPoints - 1;
  331.  
  332.         // Paint any junctions in visible area
  333.         g.setColor (JunctionColor);
  334.         for (x = xo; x < xe; x++) {
  335.             for (y = yo; y < ye; y++) {
  336.                 cCnt = PinGrid[x][y].Components.size();
  337.                 if ((( cCnt == 2) &&
  338.                    ((ElectronicComponent)PinGrid[x][y].Components.elementAt(0)) instanceof Wire &&
  339.                    ((ElectronicComponent)PinGrid[x][y].Components.elementAt(1)) instanceof Wire) ||
  340.                    cCnt > 2) {
  341.                         g.drawLine ( (x - xo) * gs - 1, (y - yo) * gs,
  342.                                      (x - xo) * gs + 1, (y - yo) * gs );
  343.                         g.drawLine ( (x - xo) * gs, (y - yo) * gs - 1,
  344.                                      (x - xo) * gs, (y - yo) * gs + 1 );
  345.                 }
  346.             }
  347.         }
  348.     }
  349.  
  350. //----------------------------------------------------------------------------
  351. // Draw the select box
  352. //----------------------------------------------------------------------------
  353.     public void DrawSelectBox () {
  354.         int w = Math.abs (SelectBoxX2 - SelectBoxX1);
  355.         int h = Math.abs (SelectBoxY2 - SelectBoxY1);
  356.         int x = (SelectBoxX1 < SelectBoxX2) ? SelectBoxX1 : SelectBoxX2;
  357.         int y = (SelectBoxY1 < SelectBoxY2) ? SelectBoxY1 : SelectBoxY2;
  358.         applet.ibg.setColor (Color.white);
  359.         applet.ibg.drawRect (x, y, w, h);
  360.     }
  361.  
  362. //----------------------------------------------------------------------------
  363. // Get the XCoord of the mouse pointer
  364. //----------------------------------------------------------------------------
  365.     public int GetXCoord(int x) {
  366.         int xc = ((x + hgs) / GridStep) + GridXOffset;
  367.         if (xc < 1) xc = 1;
  368.         if (xc >= applet.MaxXPoints) xc = applet.MaxXPoints - 1;
  369.         return xc;
  370.     }
  371.  
  372. //----------------------------------------------------------------------------
  373. // Get the YCoord of the mouse pointer
  374. //----------------------------------------------------------------------------
  375.     public int GetYCoord(int y) {
  376.         int yc = ((y + hgs) / GridStep) + GridYOffset;
  377.         if (yc < 1) yc = 1;
  378.         if (yc >= applet.MaxYPoints) yc = applet.MaxYPoints - 1;
  379.         return yc;
  380.     }
  381.  
  382. //----------------------------------------------------------------------------
  383. // User wants to draw a new wire
  384. //----------------------------------------------------------------------------
  385.     public void WireMouseDown (int x, int y) {
  386.         StatusMessage("Move to the desired end position and release the mouse button.");
  387.         NewWire = new Wire (applet.PinGrid, GetXCoord(x), GetYCoord(y));
  388.         NewWire.Set2ndCoord(applet.PinGrid, GetXCoord(x), GetYCoord(y)); // Avoid (0, 0) proto drawing
  389.     }
  390.  
  391. //----------------------------------------------------------------------------
  392. // User wants to place a new junction
  393. //----------------------------------------------------------------------------
  394.     public void JunctionMouseDown (int x, int y) {
  395.         if (!applet.MySchematic.PlaceJunction(applet.PinGrid, GetXCoord(x), GetYCoord(y), GridStep)) {
  396.             StatusMessage("Sorry, can't place a junction here. Try again.");
  397.         } else {
  398.             StatusMessage("Click again to add another junction.");
  399.             repaint();
  400.         }
  401.     }
  402.  
  403. //----------------------------------------------------------------------------
  404. // Select the 2nd coord of the new Wire
  405. //----------------------------------------------------------------------------
  406.     public void WireMouseDrag (int x, int y) {
  407.         StatusMessage("Release mouse button to add the wire here.");
  408.         if (NewWire != null) {
  409.             NewWire.Set2ndCoord(applet.PinGrid, GetXCoord(x), GetYCoord(y));
  410.             repaint();
  411.         }
  412.     }
  413.  
  414. //----------------------------------------------------------------------------
  415. // User released the mouse-button at wire drawing
  416. //----------------------------------------------------------------------------
  417.     public void WireMouseUp (int x, int y) {
  418.         if (NewWire != null) {
  419.             if (NewWire.x1 == GetXCoord(x) && NewWire.y1 == GetYCoord(y)) {
  420.                 StatusMessage("Sorry - can't place wire. Length must be minimal one gridpoint.");
  421.                 NewWire = null;
  422.                 return;
  423.             }
  424.             StatusMessage("Choose a position for the next wire and press the mouse button.");
  425.  
  426.             NewWire.Set2ndCoord(applet.PinGrid, GetXCoord(x), GetYCoord(y));
  427.             applet.addComponent(NewWire);
  428.             NewWire.CheckPosition();
  429.             NewWire.PlacePinsHere(applet.PinGrid);
  430.             if (AutoJunction) {
  431.                 applet.MySchematic.PlaceJunction(applet.PinGrid, NewWire.x1, NewWire.y1, GridStep);
  432.                 applet.MySchematic.PlaceJunction(applet.PinGrid, NewWire.x2, NewWire.y2, GridStep);
  433.             }
  434.  
  435.             NewWire = null;
  436.             repaint();
  437.         }
  438.     }
  439.  
  440. //----------------------------------------------------------------------------
  441. // User clicked the mouse when the simulation is running.
  442. // Check if there is an interactive component such as a Switch or Push Button
  443. //----------------------------------------------------------------------------
  444.     public void MouseDownSimulateRunning(int x, int y) {
  445.         ComponentPressed = applet.MySchematic.CheckIfComponentClicked(GetXCoord(x), GetYCoord(y));
  446.         if (ComponentPressed != null) {
  447.             if (!ComponentPressed.SimMouseDown()) {
  448.                 StatusMessage("Sorry, cannot move component while simulating. Press 'simulate' again to stop.");
  449.             }
  450.         } else {
  451.             StatusMessage("Can't find a component here. Try again please.");
  452.         }
  453.     }
  454.  
  455. //----------------------------------------------------------------------------
  456. // User released the mouse button when the simulation is running.
  457. // Check if there is an interactive component such as a Switch or Push Button
  458. //----------------------------------------------------------------------------
  459.     public void MouseUpSimulateRunning(int x, int y) {
  460.         if (ComponentPressed != null) {
  461.             ComponentPressed.SimMouseUp();
  462.         }
  463.     }
  464.  
  465. //----------------------------------------------------------------------------
  466. // User dragged the mouse when the simulation is running.
  467. //----------------------------------------------------------------------------
  468.     public void MouseDragSimulateRunning(int x, int y) {
  469.     }
  470.  
  471. //----------------------------------------------------------------------------
  472. // User clicked a mouse button
  473. //----------------------------------------------------------------------------
  474.     public synchronized boolean mouseDown(Event evt, int x, int y) {
  475.         ElectronicComponent SelectedComponent;
  476.         ElectronicComponent TempComponent;
  477.  
  478.         SelectBox = false;
  479.         if (applet.SimulateRunning()) {
  480.             MouseDownSimulateRunning(x, y);
  481.             return true;
  482.         }
  483.         if (WireDrawing) {
  484.             WireMouseDown(x, y);
  485.             return true;
  486.         }
  487.         if (JunctionDrawing) {
  488.             JunctionMouseDown(x, y);
  489.             return true;
  490.         }
  491.  
  492.         SelectedComponent = applet.MySchematic.CheckIfComponentClicked(GetXCoord(x), GetYCoord(y));
  493.         if (SelectedComponent != null) {
  494.             if (evt.clickCount == 2 && SelectedComponent instanceof Caption && SelectedComponent == PrevSelectedComponent) {
  495.                 Caption ChangeCaption = (Caption)SelectedComponent;
  496.                 if (applet.frame.MyTextChangeDialog == null) {
  497.                     applet.frame.MyTextChangeDialog = new TextDialog(applet.frame, ChangeCaption, applet.frame.CHANGETEXTDIALOG_ID);
  498.                 }
  499.             }
  500.             if (evt.clickCount == 2 && SelectedComponent instanceof Probe && SelectedComponent == PrevSelectedComponent) {
  501.                 Probe ChangeProbe = (Probe)SelectedComponent;
  502.                 if (applet.frame.MyTextProbeChangeDialog == null) {
  503.                     applet.frame.MyTextProbeChangeDialog = new TextDialog(applet.frame, ChangeProbe, applet.frame.CHANGETEXTPROBEDIALOG_ID);
  504.                 }
  505.             }
  506.             PrevSelectedComponent = SelectedComponent;
  507.             if (SelectSchematic.size() > 0 && !SelectSchematic.InSchematic(SelectedComponent)) {
  508.                 // The user selected another component which is not in already selected component list.
  509.                 if (evt.shiftDown()) {
  510.                     SelectedComponent.Selected = true;
  511.                     SelectSchematic.addComponent(SelectedComponent);
  512.                 } else {
  513.                     SelectSchematic.RemoveAllComponents();
  514.                 }
  515.                 repaint();
  516.             }
  517.             if (SelectSchematic.size() > 0) {
  518.                 SelectSchematic.RemovePinsGrid(applet.PinGrid);
  519.                 if (SelectSchematic.size() > 1) {
  520.                     StatusMessage("Move all components to the desired position and release the mouse button.");
  521.                 } else {
  522.                     TempComponent = (ElectronicComponent) SelectSchematic.Components.elementAt(0);
  523.                     StatusMessage("Move this " + TempComponent.getName() +
  524.                                   " to the desired position and release the mouse button.");
  525.                 }
  526.             } else {
  527.                 SelectedComponent.Selected = true;
  528.                 SelectSchematic.addComponent (SelectedComponent);
  529.                 StatusMessage("Move this " + SelectedComponent.getName() +
  530.                               " to the desired position and release the mouse button.");
  531.                 SelectedComponent.RemovePinsGrid(applet.PinGrid);
  532.                 repaint();
  533.             }
  534.             OldMouseX = x; OldMouseY = y;
  535.         } else {
  536.             SelectSchematic.RemoveAllComponents();
  537.             SelectBox = true;
  538.             SelectBoxX1 = SelectBoxX2 = x;
  539.             SelectBoxY1 = SelectBoxY2 = y;
  540.             repaint();
  541.         }
  542.  
  543.         return true;
  544.     }
  545.  
  546. //----------------------------------------------------------------------------
  547. // User released the mouse button
  548. //----------------------------------------------------------------------------
  549.     public synchronized boolean mouseUp(Event evt, int x, int y) {
  550.         ElectronicComponent HelpComponent;
  551.  
  552.         if (applet.HelpWanted) {
  553.             if ((HelpComponent = applet.MySchematic.CheckIfComponentClicked(GetXCoord(x), GetYCoord(y))) != null) {
  554.                 HelpDialog MyHelpDialog = new HelpDialog(applet.frame, HelpComponent.ComponentName);
  555.             } else {
  556.                 HelpDialog MyHelpDialog = new HelpDialog(applet.frame, "Schematic");
  557.             }
  558.  
  559.             return true;
  560.         }
  561.  
  562.         if (applet.SimulateRunning()) {
  563.             MouseUpSimulateRunning(x, y);
  564.             return true;
  565.         }
  566.         if (WireDrawing) {
  567.             WireMouseUp(x, y);
  568.             return true;
  569.         }
  570.         if (JunctionDrawing) return true;
  571.  
  572.         if (SelectSchematic.size() > 0) {
  573.             SelectSchematic.CheckPosition();
  574.             SelectSchematic.PlacePinsHere (applet.PinGrid);
  575.             StatusMessage("Ready. Select another component or make a choice.");
  576.             repaint();
  577.         } else if (SelectBox) {
  578.             SelectBox = false;
  579.             applet.MySchematic.CheckIfComponentsInSelectBox(SelectSchematic,
  580.                             GetXCoord(SelectBoxX1), GetYCoord(SelectBoxY1),
  581.                             GetXCoord(SelectBoxX2), GetYCoord(SelectBoxY2)  );
  582.             if (SelectSchematic.size() > 0) {
  583.                 repaint();
  584.             }
  585.         }
  586.         if (SelectSchematic.size() > 0) {
  587.             applet.frame.CutMenuItem.enable();
  588.             applet.frame.CopyMenuItem.enable();
  589.             if (applet.EnableFileOperations) {
  590.                 applet.frame.CopyDiskMenuItem.enable();
  591.             }
  592.             applet.MyControlPanel.EnableButton ("Cut");
  593.             applet.MyControlPanel.EnableButton ("Copy");
  594.         } else {
  595.             applet.frame.CutMenuItem.disable();
  596.             applet.frame.CopyMenuItem.disable();
  597.             if (applet.EnableFileOperations) {
  598.                 applet.frame.CopyDiskMenuItem.disable();
  599.             }
  600.             applet.MyControlPanel.DisableButton ("Cut");
  601.             applet.MyControlPanel.DisableButton ("Copy");
  602.         }
  603.         return true;
  604.     }
  605.  
  606. //----------------------------------------------------------------------------
  607. // User dragged the mouse (mouse button is down)
  608. //----------------------------------------------------------------------------
  609.     public synchronized boolean mouseDrag(Event evt, int x, int y) {
  610.         int xChange, yChange;
  611.         if (x == -1 || y == -1) return true;
  612.         if (applet.SimulateRunning()) {
  613.             MouseDragSimulateRunning(x, y);
  614.             return true;
  615.         }
  616.         if (WireDrawing) {
  617.             WireMouseDrag(x, y);
  618.             return true;
  619.         }
  620.         if (JunctionDrawing) return true;
  621.  
  622.         if (SelectSchematic.size() > 0) {
  623.             xChange = (x - OldMouseX) / GridStep;
  624.             yChange = (y - OldMouseY) / GridStep;
  625.             if (xChange != 0 || yChange != 0) {
  626.                 OldMouseX = x - (x - OldMouseX) % GridStep;
  627.                 OldMouseY = y - (y - OldMouseY) % GridStep;
  628.                 SelectSchematic.AdjustPosition (applet.PinGrid, xChange, yChange );
  629.                 applet.MySchematic.Modified = true;
  630.                 repaint();
  631.             }
  632.         } else if (SelectBox) {
  633.             SelectBoxX2 = x; SelectBoxY2 = y;
  634.             repaint();
  635.         }
  636.  
  637.         return true;
  638.     }
  639.  
  640. //----------------------------------------------------------------------------
  641. // Display a status message in the status panel
  642. //----------------------------------------------------------------------------
  643.     public void StatusMessage(String msg) {
  644.         applet.StatusMessage(msg);
  645.     }
  646.  
  647.  
  648. }