// GraphCanvas.java // class GraphCanvas definition import java.awt.*; import java.util.*; class GraphCanvas extends Canvas implements Runnable { boolean Delete_Place = false; // The following flags are for tracing the actions /* set to true, display the action set to false, not display actions */ boolean tracing = true; boolean tracingPlace = false; boolean tracingToken = false; boolean tracingTransition = false; boolean tracingArc = false; /* Prevent (re)painting due to mouseMove before any key or mouse is pressed */ boolean sessionStart = false; // parameters drawing area for the petrinet final int PETRINET = 1; // graph information while running algorithm int step = 0; int d = 0; int n = 0; // Token and transition information public boolean PutDot = false; boolean MoveCycle = false; boolean MoveGroup = false; boolean Grouping = false; boolean DeGrouping=false; boolean tgroup = false; boolean mgroup = false; boolean dgroup = false; LinkedList pList = null; LinkedList tList = null; LinkedList tempArc = null; LinkedList tempArc2 = null; int mousePressX; int mousePressY; Place place; Transition aTransition; Rectangle groupRect; Rectangle box; boolean Replay = false; // replay flag boolean DrawCircle = false; boolean deletePlace = false; boolean deleteToken = false; boolean newEdge = false; boolean newEdgeFromPlace = false; boolean newEdgeFromTransition = false; boolean newCondition = true; int keyValue = -1; public Point thisPoint = new Point(0, 0); // current mouse position public Point lastPoint = new Point(0, 0); // current mouse position public Condition c1 = null ; public UserInterface UI ; // basic transition information public Place start = null; public Place end = null; public Transition startTransition = null; public Transition endTransition = null; // for double buffering private Image offScreenImage; private Graphics offScreenGraphics; private Dimension offScreenSize; LinkedList conditionList = new LinkedList(); // fonts Font roman = new Font("TimesRoman", Font.BOLD, 12); Font helvetica = new Font("Helvetica", Font.BOLD, 15); FontMetrics fmetrics = getFontMetrics(roman); int h = (int)fmetrics.getHeight()/3; // for run option Thread algrthm; // current algorithm, (in case more algorithms are added) int algorithm; // locking the screen while running the algorithm boolean Locked = false; petrinet1 parent; GraphCanvas child; Vector subWindows; GraphCanvas(){} public LinkedList placeList = new LinkedList(); public LinkedList transitionList = new LinkedList(); public LinkedList arcList = new LinkedList(); public Vector vector = new Vector(); public Vector replayVector = new Vector(); /* following are a couple of overloaded constructors */ GraphCanvas(petrinet1 myParent, GraphCanvas g) { parent = myParent; child = g; init(); algorithm = PETRINET; setBackground(Color.white); } // end of constructor1 GraphCanvas(petrinet1 myParent) { parent = myParent; init(); algorithm = PETRINET; setBackground(Color.white); } // end of constructor2 public void lock() { // lock screen while running an algorithm Locked = true; } public void unlock() { Locked = false; } public void start() { if (algrthm != null) algrthm.resume(); } public void init() { //performalg = false; } // removes graph from screen public void clear() { Place.counter = 0; init(); PutDot = false; DrawCircle = false; newEdge = false; newEdgeFromPlace = false; newEdgeFromTransition = false; newCondition = false; c1 = null; sessionStart = false; start = null; end = null; startTransition = null; endTransition = null; placeList.root = null; transitionList.root = null; arcList.root = null; repaint(); if (child != null) child.repaint(); } // end of GraphCanvas.clear() public void stop() { } public void run() { } /****************************************/ // method of trace void Trace(String msg, int sleepDuration) { parent.documentation.docText.append(msg); try { Thread.sleep(sleepDuration); } catch (InterruptedException e) {} } // end of Trace /**************************************/ // method keyDown public boolean keyDown(Event evt, int key) { sessionStart = true; keyValue = key; boolean shiftpressed = (evt.modifiers & Event.SHIFT_MASK) != 0; if ((keyValue != -1) && (shiftpressed) ) { keyValue = -1; UI = new UserInterface("Add Condition", this ); UI.pack(); UI.show(); Trace(" \nUser adding condition", 100); } return true; } // end of keyDown /********************************/ // method to check fire condition --inputPlace has token public boolean checkFireCondition(Transition transition) { boolean hasToken; Element ptr = transition.inputPlace.root; while (ptr != null) { hasToken = ptr.obj.token; if(hasToken == true) ptr = ptr.next; else return false; } return true; } // end of checkFireCondition /******************************/ // method for cyclic checking public void cyclicChecking(GraphCanvas graphcanvas, int iterations) { System.out.println("CyclicChecking called...." + iterations); Element ptrT = transitionList.root; Transition cyclicTransition = (Transition)ptrT.getTransition(); Element ptrC = UI.g.conditionList.root; Condition C = (Condition)ptrC.getCondition(); while (true) { System.out.println("the value of iterations" + iterations); Element ptrPc1 = cyclicTransition.inputPlace.root; Place inPlace = (Place)ptrPc1.getPlace(); Element ptrPc2 = cyclicTransition.outputPlace.root; Place outPlace = (Place)ptrPc2.getPlace(); int trans_flag = 0; boolean fcondition = checkFireCondition(cyclicTransition); boolean ucondition = false; System.out.println("ucondition = " + ucondition); String TransName = C.transitionname; System.out.println("TransName " + TransName); String CondValue = C.conditionvalue; String ChoiceItem = "LogicalStatements"; if (TransName.compareTo(cyclicTransition.id) == 0) { System.out.println("Inside id"); if(CondValue.compareTo("true") == 0) { System.out.println("Inside compare condition"); ucondition = true ; } else ucondition = false; } System.out.println("ucondition" + ucondition); if (fcondition && ucondition) { while ((inPlace != null) && (outPlace != null)) { System.out.println("inside while"); if (tracing) Trace("ANIMATE:" + inPlace.id +" o-------->| ---->o" + outPlace.id, 150); lock(); inPlace.token = false; Arc arc3 = arcList.givenPlaceAndTransition(inPlace, cyclicTransition); FireTransition cyclic1 = new FireTransition(this, cyclicTransition.x, cyclicTransition.y,inPlace.x, inPlace.y, arc3); if (tracing) Trace("FireTransition done", 500); cyclic1.artist(this, (cyclicTransition.id.charAt(1) - '0')); if (tracing) Trace("Artist done", 500); Arc arc4 = arcList.givenPlaceAndTransition(outPlace, cyclicTransition); FireTransition cyclic2 = new FireTransition(this, outPlace.x, outPlace.y, cyclicTransition.x, cyclicTransition.y, arc4); if (tracing) Trace("FireTransition done", 500); cyclic2.artist(this, (cyclicTransition.id.charAt(1) - '0')); if (tracing) Trace("Artist done", 500); outPlace.token = true; PutDot = true; cyclic2.g.setColor(Color.red); cyclic2.g.fillOval(outPlace.x - (Place.radius/10), outPlace.y - (Place.radius/10), Place.radius/5,Place.radius/5); cyclic2.g.setColor(Color.white); cyclic2.g.drawOval(outPlace.x - (Place.radius/10), outPlace.y - (Place.radius/10), Place.radius/5, Place.radius/5); repaint(); if (child != null) child.repaint(); ptrPc2 = ptrPc2.getNext(); if (ptrPc2 == null) break; outPlace = (Place)ptrPc2.getPlace(); if (tracing) Trace("outPlace.id = " + outPlace.id, 150); unlock(); } //end of while(start.........) } //end of if(condition) ptrT = ptrT.getNext(); System.out.println("The value of ucondition " + ucondition); if ((ptrT == null) && (iterations > 0)) { ptrT = transitionList.root; iterations--; System.out.println("the value of count = " + iterations); } else if (iterations <= 0) break; cyclicTransition = (Transition)ptrT.getTransition(); ptrC = ptrC.getNext(); if (ptrC == null) ptrC = UI.g.conditionList.root ; C = (Condition)ptrC.getCondition(); System.out.println("TransName2" + C.transitionname ); if (tracing) Trace("Transition fired", 150); } // end of while(1) } // end of GraphCanvas.cyclicChecking() /**************************************/ // Method getDrawableRect // used for grouping Rectangle getDrawableRect(Rectangle originalRect) { int x = originalRect.x; int y = originalRect.y; int width = originalRect.width; int height = originalRect.height; //Make sure rectangle width and height are positive. if (width < 0) { width = 0 - width; x = x - width + 1; if (x < 0) { width += x; x = 0; } } if (height < 0) { height = 0 - height; y = y - height + 1; if (y < 0) { height += y; y = 0; } } return new Rectangle(x,y,width,height); } // end of getDrawableRect /*****************************************************************/ /************************* MOUSE DOWN ****************************/ // method for mouseDown event. public boolean mouseDown(Event evt, int x, int y) { /* OLD: 1 2 3 4 5 6 7 8 ControlDown T T T T F F F F shiftDown T T F F T T F F enclosed T F T F T F T F --------------------------------------------------------------- ? ? dP ? dToken ? aT aP */ if (deleteToken) //WeiDong { Place enclosingPlace; sessionStart = true; lastPoint = new Point(x, y); enclosingPlace = (Place)placeList.checkIfInCircle(x, y, Place.radius); if (enclosingPlace != null) { if (tracing) Trace("\n D6, DEL TOKEN", 100); placeList.DeleteToken(x, y, Place.radius); if (child != null ) child.placeList.DeleteToken(x, y, Place.radius); placeList.print(); Graphics g = this.getGraphics(); drawPlace(g, enclosingPlace); replayVector.addElement("W"); replayVector.addElement(lastPoint); if (child != null) { child.drawPlace(g, enclosingPlace); child.replayVector.addElement("W"); child.replayVector.addElement(lastPoint); } } } else if(DeGrouping) { pList.DeleteRectangle(box); tList.Deletetran(box); tempArc2.DeletearcCrossRectangle(box); dgroup = true; repaint(); } else if (Grouping) { mousePressX=x; mousePressY=y; groupRect = new Rectangle(x,y,0,0); dgroup=false; } else { if (MoveCycle) { mousePressX = x; mousePressY = y; place = (Place)placeList.checkIfInCircle(x, y, Place.radius); aTransition=transitionList.returnTransitionForXY(x, y); if(box!=null && box.contains(x,y)) { MoveGroup=true; System.out.println("moveGroup is true"); if (tempArc!=null) System.out.println("tempArc is not null"); } /* if (Grouping) { mousePressX = x; mousePressY = y; } else { if (MoveCycle) { mousePressX = x; mousePressY = y; place = (Place)placeList.checkIfInCircle(x, y, Place.radius); aTransition = transitionList.returnTransitionForXY(x, y); if ((groupRect != null) && (groupRect.contains(x, y))) { MoveGroup = true; System.out.println("moveGroup is true"); if (tempArc != null) System.out.println("tempArc is not null"); } */ else if (place != null) tempArc = arcList.outgoingArcs2(place); else tempArc = arcList.outgoingArcs(aTransition); System.out.println("x = " + x + ", y = " + y); } else { Place enclosingPlace; sessionStart = true; lastPoint = new Point(x, y); if (tracing) { Trace("\n D1, mouseDown", 100); // Trace("\n" + String.valueOf(x) + "," + String.valueOf(y) // + "," + String.valueOf(Place.radius), 100); } enclosingPlace = (Place)placeList.checkIfInCircle(x, y, Place.radius); /* if (tracing) { Trace("\n\n\n enclosingPlace computed", 100); if (enclosingPlace == null) Trace("\n NULL PLACE", 100); else Trace("\n NOT NULL PLACE", 100); } */ //if (evt.controlDown()) if (Delete_Place) { if (tracing) Trace("\n D2, CONTROL DOWN", 100); if (enclosingPlace != null) { if (tracing) Trace("\n D3, DEL PLACE", 100); DeleteCircle(enclosingPlace); } else Trace("\n D4, Control Down & clicking nowhere NOT SUPPORTED", 100); } else { if (tracing) Trace("\n D5, NO CONTROL DOWN", 100); if (evt.shiftDown()) { if (enclosingPlace != null) { if (tracing) Trace("\n D6, DEL TOKEN", 100); placeList.DeleteToken(x, y, Place.radius); if (child != null ) child.placeList.DeleteToken(x, y, Place.radius); placeList.print(); repaint(); if (child != null) child.repaint(); } else Trace("\n D7, shiftDown & clicking nowhere NOT SUPPORTED", 1000); } else { if (tracing) Trace("\n D8, Neither CONTROL nor SHIFT down", 100); if (enclosingPlace != null) { // draw a new transition if (!newEdge) { newEdge = true; newEdgeFromPlace = true; setStartPlace (x, y); if (tracing) Trace("\n D9, NEW TRAN " + " FROM " + start.id + ", OR A TOKEN", 100); } else Trace("\n D10, EXCEPTION", 100); } else { if (tracing) Trace("\n D11, COMPUTE TRAN ", 100); setStartTransition(x, y); } // end of else // (!evt.shiftDown() && // !evt.shiftDown() && // (enclosingPlace == null)) } // end of else // (!evt.controlDown() && !evt.shiftDown()) } // end of else (!(evt.controlDown()) ) vector.addElement(placeList); vector.addElement(arcList); vector.addElement(transitionList); } } return true; } // end of GraphCanvas.mouseDown /**************************************************/ //For every mouse move event this method is accesed public boolean mouseMove(Event evt, int x, int y) { /* if (sessionStart) { Place enclosingPlace; parent.documentation.doctext.showline("mouseMove"); try { Thread.sleep(1500); } catch (InterruptedException e) {} if (evt.controlDown() ) { enclosingPlace = Place.placeList.checkIfInCircle(x,y,Place.radius); enclosingPlace = (Place)placeList.checkIfInCircle(x,y,Place.radius); if (enclosingPlace!=null) { parent.documentation.doctext.showline("ADD TOKEN"); try { Thread.sleep(1500); } catch (InterruptedException e) {} enclosingPlace.token = true; PutDot = true; repaint(); } else { parent.documentation.doctext.showline("NOT ADD TOKEN"); try { Thread.sleep(1500); } catch (InterruptedException e) {} } } */ return true; } // end of mouseMove /**************************************************/ //For every mouse drag event this method is accesed public boolean mouseDrag(Event evt, int x, int y) { if (Grouping) { int width = (x - groupRect.x) ; int height = (y - groupRect.y); groupRect.resize(width,height); repaint(); } if (MoveCycle) { if (MoveGroup) { pList.updatePlace(x - mousePressX, y - mousePressY); tList.updateTran(x - mousePressX, y - mousePressY); tempArc2.ArrowHead(); groupRect.translate(x - mousePressX, y - mousePressY); mousePressX = x; mousePressY = y; } else { if (aTransition != null) { aTransition.x = x; aTransition.y = y; tempArc.ArrowHead(); } else { place.x = x; place.y = y; tempArc.ArrowHead(); } } repaint(); if (child != null) child.repaint(); } else { if (newEdge) { if (tracing) Trace("mouseDrag", 100); thisPoint = new Point(x, y); if (tracing) Trace("\n " + "thisPoint.x = " + String.valueOf(x) + ", " + "thisPoint.y = " + String.valueOf(y), 50); sessionStart = true; repaint(); if (child != null) child.repaint(); if (!subWindows.isEmpty()) { for (Enumeration e = subWindows.elements(); e.hasMoreElements();) { ExtendedGraphCanvas eg = (ExtendedGraphCanvas)e.nextElement(); eg.repaint(); } } // end of if (subWindows) if (tracing) Trace("\n\nDRAGGING DONE", 50); } } return true; } // end of GraphCanvas.mouseDrag method /***************************************/ // method Group public void Group(int x, int y) { groupRect = new Rectangle(Math.min(mousePressX, x), Math.min(y, mousePressY), Math.abs(x - mousePressX), Math.abs(y - mousePressY)); pList = placeList.placeWithinRectangle(groupRect); tList = transitionList.tranWithinRectangle(groupRect); tempArc2 = arcList.arcCrossRectangle(groupRect); tgroup = true; repaint(); if (groupRect != null) { offScreenGraphics.setColor(Color.pink); offScreenGraphics.fillRect(groupRect.x, groupRect.y, groupRect.width, groupRect.height); offScreenGraphics.setColor(Color.white); repaint(); } } // end of Group /************************************************/ /**************** MOUSE UP **********************/ //For every mouse up event this method is accesed public boolean mouseUp(Event evt, int x, int y) { if (Grouping) { Group(x, y); Grouping = false; } else { if (MoveCycle) { if (MoveGroup) { groupRect.translate(x - mousePressX, y - mousePressY); pList.updatePlace(x - mousePressX, y - mousePressY); tList.updateTran(x - mousePressX, y - mousePressY); tempArc2.ArrowHead(); MoveGroup = false; } else { if (aTransition != null) { aTransition.x = x; aTransition.y = y; tempArc.ArrowHead(); } else { place.x = x; place.y = y; tempArc.ArrowHead(); } } mgroup = true; repaint(); MoveCycle = false; } else { if (tracing) Trace("\n U1, mouseUp", 100); if (newEdge) { newEdge = false; //xshi setEndPlace (x, y); } // if (newEdge) else { // if (newEdge) if (tracing) Trace("\n U44, ALL ELSE", 100); } // end else vector.addElement(placeList); vector.addElement(arcList); vector.addElement(transitionList); } } return true; } // end of GraphCanvas.mouseUp /**********************************/ // method for deleting a place void DeleteCircle(Place tempPlace) { //Place.placeList.delete(tempPlace); placeList.delete(tempPlace); if (child != null) child.placeList.delete(tempPlace); Place.cardinality--; DrawCircle = true; placeList.print(); repaint(); if (child != null) child.repaint(); } /*********************************/ void DeleteRect (Place tempPlace) { pList.delete(tempPlace); Place.cardinality--; //DeGrouping = true; //Place.placeList.print(); placeList.print(); repaint(); // if(child!=null) //11-08-98 // child.repaint(); } /***********************************/ /* integer to string conversion to draw the string beside the places */ public String intToString(int i) { char c = (char)((int)'a' + i); return "P " + i; } /*******************************************/ // method to draw place public void drawPlace(Graphics g, Place place) { /* draw circle filled with yellow */ g.setColor( Color.yellow); g.fillOval(place.x - (Place.radius)/2, place.y - (Place.radius)/2, Place.radius, Place.radius); if (tracingPlace) Trace("\n **drawPlace, Writing Place ID", 100); /* draw black circles around places, write their names to the screen */ g.setColor(Color.black); g.drawOval(place.x - (Place.radius)/2, place.y - (Place.radius)/2, Place.radius, Place.radius); //Write name of the place on the top left side of the circle. g.setColor(Color.blue); g.setFont(new Font("Helvetica", Font.BOLD, 10)); g.drawString(place.id, place.x - 19, place.y - 19); // Draw the tokens if (PutDot == true) { if (place.token == true) { g.setColor(Color.red); g.fillOval(place.x - (Place.radius)/10, place.y - (Place.radius)/10, Place.radius/5, Place.radius/5); g.setColor(Color.white); g.drawOval(place.x - (Place.radius)/10, place.y - (Place.radius)/10, Place.radius/5, Place.radius/5); if (tracingPlace) Trace("\n **** DRAWING TOKEN *****", 150); } // end if (tempObj.token == true) } // end if (PutDot == true) } // end of draw Place /*******************************************/ // this method draws the transition line public void drawTransition(Graphics g, Transition transition) { // draw transition between place i and place j int x1, x2, x3, y1, y2, y3; float dirx, diry; Point startPt; Point endPt; Point arrowHead; if (tracingTransition) Trace("\n **drawTransition:" + " id = " + transition.id, 100); Arc incomingArc = (Arc)arcList.oneIncomingArc(transition); Arc outgoingArc = (Arc)arcList.oneOutgoingArc(transition); if (incomingArc != null) { // if (tracingTransition) // Trace("\n incomingArc.place = " + incomingArc.place.id, 100); // find the arc between the first arc in dirx = incomingArc.sin_x; diry = incomingArc.cos_x; startPt = new Point(incomingArc.place.x, incomingArc.place.y); endPt = new Point(transition.x, transition.y); arrowHead = incomingArc.arrowHead; } else { // if (tracingTransition) // Trace("\n outgoingArc.place = " + outgoingArc.place.id, 300); // find the arc between the first arc in dirx = outgoingArc.sin_x; diry = outgoingArc.cos_x; startPt = new Point(transition.x, transition.y); endPt = new Point(outgoingArc.place.x, outgoingArc.place.y); arrowHead = outgoingArc.arrowHead; } x3 = (int)(transition.x + 6*dirx); y3 = (int)(transition.y + 6*diry); g.setColor(Color.magenta); g.drawLine((int)(x3 - 1 * dirx + 8 * diry), (int)(y3 - 1 * diry - 8 * dirx), (int)(x3 - 1 * dirx - 8 * diry), (int)(y3 - 1 * diry + 8 * dirx)); g.drawLine((int)(x3 - 2 * dirx + 8 * diry), (int)(y3 - 2 * diry - 8 * dirx), (int)(x3 - 2 * dirx - 8 * diry), (int)(y3 - 2 * diry + 8 * dirx)); // if (tracingTransition) // Trace("\n transition bar drawn", 100); int dx = (int)(Math.abs(7 * diry)); int dy = (int)(Math.abs(7 * dirx)); g.setFont(new Font("Helvetica", Font.BOLD + Font.ITALIC, 10)); if ((startPt.x > endPt.x) && (startPt.y >= endPt.y)) g.drawString(transition.id, transition.x + dx, transition.y - dy); else if ((startPt.x >= endPt.x) && (startPt.y < endPt.y)) { g.drawString(transition.id, transition.x - fmetrics.stringWidth(transition.id) - dx, transition.y - dy); } else if ((startPt.x < endPt.x) && (startPt.y <= endPt.y)) { g.drawString(transition.id, transition.x - fmetrics.stringWidth(transition.id), transition.y + fmetrics.getHeight()); } else if ((startPt.x <= endPt.x) && (startPt.y > endPt.y)) g.drawString(transition.id, transition.x + dx, transition.y + fmetrics.getHeight() ); g.setColor(Color.black); if (tracingTransition) Trace("\n **transition id written", 100); } // end of dwarTransition /***************************************/ // draw an arc public void drawArc(Graphics g, Arc arc) { int x1, x2, x3, y1, y2, y3; Point startPt; Point endPt; if (tracingArc) Trace("\n **drawArc:\n" + arc.place.id + " O----------| " + arc.transition.id, 200); if (arc.direction == Arc.place2Transition) { // if (tracingArc) // Trace("from place 2 trans", 100); startPt = new Point(arc.place.x, arc.place.y); endPt = new Point(arc.transition.x, arc.transition.y); } else // if (arc.direction != Arc.transition2Place) { // if (tracingArc) // Trace("from trans 2 place", 100); startPt = new Point(arc.transition.x, arc.transition.y); endPt = new Point(arc.place.x, arc.place.y); } // if (tracingArc) // Trace("startPt & endPt computed", 100); g.setColor(Color.blue); g.drawLine(startPt.x, startPt.y, endPt.x, endPt.y); // if (tracingArc) // Trace("Arc line drawn\n" + "(" + startPt.x + ", " + startPt.y // + ") ------------- (" + endPt.x + ", " + endPt.y + ")", 100); // calculate arrowHead float dirx = arc.sin_x; float diry = arc.cos_x; // if (tracingArc) // Trace("dirx = " + String.valueOf(dirx) // + ", diry = " + String.valueOf(diry), 100); /* New addition to generate arrow head at the target place */ // calculate transitionHead if (arc.direction == Arc.place2Transition) { x1 = (int)(endPt.x - 3 * dirx + 6 * diry); x2 = (int)(endPt.x - 3 * dirx - 6 * diry); x3 = (int)(endPt.x + 6 * dirx); y1 = (int)(endPt.y - 3 * diry - 6 * dirx); y2 = (int)(endPt.y - 3 * diry + 6 * dirx); y3 = (int)(endPt.y + 6 * diry); } else { x1 = (int)(endPt.x - 27 * dirx + 6 * diry); x2 = (int)(endPt.x - 27 * dirx - 6 * diry); x3 = (int)(endPt.x - 24 * dirx + 6 * dirx); y1 = (int)(endPt.y - 27 * diry - 6 * dirx); y2 = (int)(endPt.y - 27 * diry + 6 * dirx); y3 = (int)(endPt.y - 24 * diry + 6 * diry); } int transitionHead_x[] = {x1, x2, x3, x1}; int transitionHead_y[] = {y1, y2, y3, y1}; // End of New addition to generate arrow head at the target place // draw transition g.fillPolygon(transitionHead_x, transitionHead_y, 4); // if (tracingArc) // Trace("Arc arrow head drawn", 100); // g.fillPolygon(transitionHead_x_End, transitionHead_y_End, 4); // write weight of transition at an appropriate position /**************** Commented out a big section ***************** int dx = (int)(Math.abs(7*diry)); int dy = (int)(Math.abs(7*dirx)); g.setColor(Color.magenta); g.drawLine((int)(x3 - 1*dirx + 8*diry), (int)(y3 - 1*diry - 8*dirx), (int)(x3 - 1*dirx - 8*diry), (int)(y3 - 1*diry + 8*dirx)); g.drawLine((int)(x3 - 2*dirx + 8*diry), (int)(y3 - 2*diry - 8*dirx), (int)(x3 - 2*dirx - 8*diry), (int)(y3 - 2*diry + 8*dirx)); g.drawLine(x3+dy, y3+dx, x3-dy, y3-dy); g.setColor(Color.black); g.setFont(new Font("Helvetica", Font.BOLD + Font.ITALIC, 10)); if ((startPt.x>endPt.x) && (startPt.y>=endPt.y)) g.drawString(current.id, arrowHead.x + dx, arrowHead.y - dy); if ((startPt.x>=endPt.x) && (startPt.yendPt.y)) { g.drawString(current.id, arrowHead.x + dx, arrowHead.y + fmetrics.getHeight() ); } ***************** End of commented out code *********/ g.setColor(Color.green); } /************************************************************** * The update function is used to stored the drawn information * in the buffer. If this method is not there then previously * drawn information will be lost */ public final synchronized void update(Graphics g) { // prepare new image offscreen Dimension d = size(); if ((offScreenImage == null) || (d.width != offScreenSize.width) || (d.height != offScreenSize.height)) { offScreenImage = createImage(d.width, d.height); offScreenSize = d; offScreenGraphics = offScreenImage.getGraphics(); } offScreenGraphics.setColor(Color.white); offScreenGraphics.fillRect(0, 0, d.width, d.height); if ( !dgroup) { if (Grouping ||MoveGroup) { offScreenGraphics.setColor(Color.pink); box = getDrawableRect(groupRect); offScreenGraphics.fillRect( box.x, box.y, box.width,box.height); offScreenGraphics.setColor(Color.white); if(tgroup) { Grouping=false; tgroup=false; } } } // else{ // dgroup=false; // } if(DeGrouping) { offScreenGraphics.setColor(Color.white); offScreenGraphics.fillRect( box.x, box.y, box.width,box.height); DeGrouping=false; } if(mgroup) { MoveGroup=false; mgroup=false; } /* if (groupRect != null) { offScreenGraphics.setColor(Color.pink); offScreenGraphics.fillRect(groupRect.x, groupRect.y, groupRect.width, groupRect.height); offScreenGraphics.setColor(Color.white); } */ paint(offScreenGraphics); g.drawImage(offScreenImage, 0, 0, null); if (tracing) Trace("\n **update**", 100); } // end of update /*******************************************************/ /* this method paints the information on to the applet */ public void paint(Graphics g) { if (tracing) Trace("\n **** PAINT ****", 100); if (Replay) { for (int i = 0; i < replayVector.size(); i++) { if (replayVector.elementAt(i).equals("P")) //WeiDong { Place aPlace= (Place)replayVector.elementAt(i+1); aPlace.token=false; PutDot=false; drawPlace(g, aPlace); } else if (replayVector.elementAt(i).equals("A")) drawArc(g, (Arc)replayVector.elementAt(i+1)); else if (replayVector.elementAt(i).equals("T")) drawTransition(g, (Transition)replayVector.elementAt(i+1)); else if (replayVector.elementAt(i).equals("F")) //WeiDong { Point releasePoint= (Point)replayVector.elementAt(i+1); endTransition = transitionList.returnTransitionForXY (releasePoint.x, releasePoint.y); boolean fireCondition = checkFireCondition(endTransition); transitionFiring(endTransition, fireCondition, releasePoint); } else if (replayVector.elementAt(i).equals("O")) //WeiDong addToken { Place aPlace= (Place)replayVector.elementAt(i+1); aPlace.token = true; PutDot = true; drawPlace(g, aPlace); } else if (replayVector.elementAt(i).equals("W")) //WeiDong deleteToken { Place enclosingPlace; lastPoint = (Point)replayVector.elementAt(i+1); enclosingPlace = (Place)placeList.checkIfInCircle(lastPoint.x, lastPoint.y, Place.radius); if (enclosingPlace != null) { if (tracing) Trace("\n D6, DEL TOKEN", 100); placeList.DeleteToken(lastPoint.x, lastPoint.y, Place.radius); if (child != null ) child.placeList.DeleteToken(lastPoint.x, lastPoint.y, Place.radius); placeList.print(); Graphics tempg = this.getGraphics(); drawPlace(tempg, enclosingPlace); if (child != null) child.drawPlace(tempg, enclosingPlace); } } i++; } // end of for loop } // end of Replay else { if (newEdge) { if (tracing) Trace ("\n ** PAINT: DRAGGING LINE **\n" + "start = " + start.id, 50); g.setColor(Color.blue); g.drawLine(lastPoint.x, lastPoint.y, thisPoint.x, thisPoint.y); // if (tracing) // Trace(" DRAGGING DONE", 150); } // if (tracingArc) // Trace("\n **** start DRAWING ARCS ****", 100); Element ptrArc = arcList.root; while (ptrArc != null) { // if (tracingArc) // Trace("\n\n\nAN ARC EXISTS", 100); Arc tempObj; tempObj = (Arc)ptrArc.getArc(); ptrArc = ptrArc.next; drawArc(g, tempObj); } // if (tracingTransition) // Trace("**** start DRAWING TRANSITIONS****", 100); Element ptr = transitionList.root; while (ptr != null) { if (tracingTransition) Trace("\n\nA TRANSITION EXISTS ", 100); Transition tempObj; tempObj = (Transition)ptr.getTransition(); ptr = ptr.next; drawTransition(g, tempObj); // Element ptrNodeP = tempObj.inputPlace.root; // while ( ptrNodeP != null) // { // Point tempnode; // tempnode = (Point)ptrNodeP.getPoint(); // ptrNodeP = ptrNodeP.next; // drawTransitionNode (g, tempnode, tempObj.middle); // } // Element ptrNode = tempObj.outputPlace.root; // while (ptrNode != null) // { // Point tempnode; // tempnode = (Point)ptrNode.getPoint(); // ptrNode = ptrNode.next; // drawTransitionNode (g, tempObj.middle, tempnode); // } } // end of while loop if (tracingPlace) Trace("\n\n start DRAWING PLACE ****", 100); Element ptrP = placeList.root; while (ptrP != null) { if (tracingPlace) Trace("\n\n\n A PLACE EXISTS", 100); Place tempObj; tempObj = (Place)ptrP.getPlace(); ptrP = ptrP.next; if (DrawCircle == true) { if (tracingPlace) Trace (" DRAWING PLACE\n" + " id = " + tempObj.id + ": " + " x = " + String.valueOf(tempObj.x) + "; " + " y = " + String.valueOf(tempObj.y) + "; \n" + " radius = " + String.valueOf(Place.radius), 150); drawPlace(g, tempObj); } } // end while (ptrP != null) } // Trace("\n ARCS, TRANSITIONS & PLACES (TOKENS) PAINTED", 100); } //end of paint /********************************/ //This method adds a token for the given place void addToken (Place aPlace) { aPlace.token = true; PutDot = true; repaint(); replayVector.addElement("O"); //WeiDong replayVector.addElement(aPlace); if(child != null) { child.repaint(); child.replayVector.addElement("O"); //WeiDong child.replayVector.addElement(aPlace); } if (!subWindows.isEmpty()) { for (Enumeration e = subWindows.elements(); e.hasMoreElements();) { ExtendedGraphCanvas eg = (ExtendedGraphCanvas)e.nextElement(); eg.PutDot = true; eg.repaint(); eg.replayVector.addElement("O"); //WeiDong eg.replayVector.addElement(aPlace); } } } // end of addToken /*******************************************/ //code taken from the original mouseUp method //add a token for the use by IDL public void addToken () { start.token = true; PutDot = true; repaint(); if(child != null) child.repaint(); if (!subWindows.isEmpty()) { for (Enumeration e = subWindows.elements(); e.hasMoreElements();) { ExtendedGraphCanvas eg = (ExtendedGraphCanvas)e.nextElement(); eg.PutDot = true; eg.repaint(); } } } // end of addToken /********************************/ //This method delete a token for the given place /********************************************/ //code taken from the original mouseUp method // this method adds transition and arcs between two places // before calling this method, check that start != end public void addTransition (Place start, Place end) { Transition newTransition; // O---------------O if (tracing) { Trace ("\n U2, " + start.id + " O------------------O " + end.id + "\n" + String.valueOf(start.x) + ", " + String.valueOf(start.y) + " " + String.valueOf(end.x) + ", " + String.valueOf(end.y) + "\n" + " " + String.valueOf((int)((start.x + end.x)/2)) + ", " + String.valueOf((int)((start.y + end.y)/2)), 2500); } //create a new transition in the middle between start and end newTransition = new Transition((int)((start.x + end.x)/2), (int)((start.y + end.y)/2)); if (tracing) { Trace(" 3 NEW TRANSITION:\n" + start.id + " O--------------------O " + end.id + "\n" + " | " + newTransition.id + ": " + "x = " + String.valueOf(newTransition.x) + ", y = " + String.valueOf(newTransition.y), 150); } transitionList.insertTranAtFront(newTransition); replayVector.addElement("T"); replayVector.addElement(newTransition); if (child != null) { child.transitionList.insertTranAtFront(newTransition); child.replayVector.addElement("T"); child.replayVector.addElement(newTransition); } if (!subWindows.isEmpty()) { for (Enumeration e = subWindows.elements(); e.hasMoreElements();) { ExtendedGraphCanvas eg = (ExtendedGraphCanvas)e.nextElement(); eg.transitionList.insertTranAtFront(newTransition); eg.replayVector.addElement("T"); eg.replayVector.addElement(newTransition); } } if (tracing) Trace("\n U4, tranList added", 100); start.outgoingTransition.insertTranAtFront(newTransition); // if (tracing) // Trace("4 "+ start.id + ".outgoingTransition added", 150); newTransition.inputPlace.insertAtFront(start); // if (tracing) // Trace (" 5 "+ newTransition.id + ".inputPlace added", 150); // Trace("\n\n Arc.cardinality = " + // ng.valueOf(Arc.cardinality), 100); Arc arc = new Arc(start, newTransition, Arc.place2Transition); // if (tracing) // Trace (" 6 New Arc: O----------| \n" + "place.id = " // + arc.place.id + "; transition.id = " // + arc.transition.id, 100); arcList.insertArcAtFront(arc); replayVector.addElement("A"); replayVector.addElement(arc); if (child != null) { child.arcList.insertArcAtFront(arc); child.replayVector.addElement("A"); child.replayVector.addElement(arc); } // if (tracing) // Trace(" 7 arcList added", 100); if (!subWindows.isEmpty()) { for (Enumeration e = subWindows.elements(); e.hasMoreElements();) { ExtendedGraphCanvas eg = (ExtendedGraphCanvas)e.nextElement(); eg.arcList.insertArcAtFront(arc); eg.replayVector.addElement("A"); eg.replayVector.addElement(arc); eg.repaint(); } } //end of subWindows newTransition.outputPlace.insertAtFront(end); if (tracing) Trace("\n U8, "+ newTransition.id + ".outputPlace added", 300); end.incomingTransition.insertTranAtFront(newTransition); // if (tracing) // Trace("9 "+ end.id + ".incomingTransition added", 300); arc = new Arc(end, newTransition, Arc.transition2Place); // if (tracing) // Trace("10 New Arc: |------------O \n" + "place.id = " // + arc.place.id + "; transition.id = " // + arc.transition.id, 300); arcList.insertArcAtFront(arc); replayVector.addElement("A"); replayVector.addElement(arc); if (child != null) { child.arcList.insertArcAtFront(arc); child.replayVector.addElement("A"); child.replayVector.addElement(arc); } // if (tracing) // Trace("11 \n arcList added\n" + "arrowHead.x = " // + String.valueOf(arc.arrowHead.x) + ", arrowHead.y = " // + String.valueOf(arc.arrowHead.y), 100); repaint(); if (child != null) child.repaint(); if (!subWindows.isEmpty()) { for (Enumeration e = subWindows.elements(); e.hasMoreElements(); ) { ExtendedGraphCanvas eg = (ExtendedGraphCanvas)e.nextElement(); eg.arcList.insertArcAtFront(arc); eg.replayVector.addElement("A"); eg.replayVector.addElement(arc); eg.repaint(); } } //end subWindows } //end addTransition to two places /*********************************************/ //code taken from the original mouseUp method //draw an arc between a place and a transition; //the third variable determines the direction of the arc public void drawArc(Place start, Transition aTransition, int direction) { if(direction == Arc.place2Transition) { newEdgeFromPlace = false; if (tracing) Trace("\n U20, "+ start.id + " O------------| " + endTransition.id, 150); start.outgoingTransition.insertTranAtFront(endTransition); endTransition.inputPlace.insertAtFront(start); Arc arc = new Arc(start, endTransition, Arc.place2Transition); arcList.insertArcAtFront(arc); replayVector.addElement("A"); replayVector.addElement(arc); repaint(); if (child != null) { child.arcList.insertArcAtFront(arc); child.replayVector.addElement("A"); child.replayVector.addElement(arc); child.repaint(); } if (!subWindows.isEmpty()) { for (Enumeration e = subWindows.elements(); e.hasMoreElements();) { ExtendedGraphCanvas eg = (ExtendedGraphCanvas)e.nextElement(); eg.newEdgeFromPlace = false; eg.arcList.insertArcAtFront(arc); eg.replayVector.addElement("A"); eg.replayVector.addElement(arc); eg.repaint(); } } } else { //direction == Arc.transition2Place if (tracing) Trace("\n U14, "+ startTransition.id + " |-----O " + end.id, 150); newEdgeFromTransition = false; // Create an edge from "startTransition" to "end" startTransition.outputPlace.insertAtFront(end); // if (tracing) // Trace("15 "+ startTransition.id + ".outputPlace added", 150); end.incomingTransition.insertTranAtFront(startTransition); // if (tracing) // Trace("16 "+ endTransition.id + ".incomingTran added", 150); Arc arc = new Arc(end, startTransition, Arc.transition2Place); // if (tracing) // Trace("16 new arc with;\n" + "place.id = " + arc.place.id // + "; transition.id = " + arc.transition.id, 150); arcList.insertArcAtFront(arc); replayVector.addElement("A"); replayVector.addElement(arc); if (child != null) { child.arcList.insertArcAtFront(arc); child.replayVector.addElement("A"); child.replayVector.addElement(arc); } // if (tracing) // Trace("17 arcList added", 150); repaint(); if (child != null) child.repaint(); if (!subWindows.isEmpty()) { for (Enumeration e = subWindows.elements(); e.hasMoreElements();) { ExtendedGraphCanvas eg = (ExtendedGraphCanvas)e.nextElement(); eg.newEdgeFromTransition = true; eg.arcList.insertArcAtFront(arc); eg.replayVector.addElement("A"); eg.replayVector.addElement(arc); eg.repaint(); } } //end subWindows } } //end drawArc /*******************************************/ //code taken from the original mouseUp method //fire transition from the current transition public void transitionFiring (Transition endTransition, boolean fireCondition, Point aPoint) { Vector v1 = new Vector(); newEdgeFromTransition = false; Element ptrP1 = endTransition.inputPlace.root; Place startPlace = (Place)ptrP1.getPlace(); // if (tracing) // Trace(" 22 startPlace.id = " + startPlace.id, 150); Element ptrP2 = endTransition.outputPlace.root; Place endPlace = (Place)ptrP2.getPlace(); int trans_flag = 0; // if (tracing) // Trace("23 endPlace.id = " + endPlace.id, 150); // fire transition process while (fireCondition && (startPlace != null)) { if (tracing) Trace("\n U24, ANIMATE: " + startPlace.id + " O-------->|------->O " + endPlace.id, 150); lock(); // not do anything startPlace.token = false; // animating the movement of token if (trans_flag == 0) { Arc arc = arcList.givenPlaceAndTransition(startPlace, endTransition); if (tracing) Trace("\n U25, "+ arc.place.id + " O--------| " + arc.transition.id, 700); FireTransition temp = new FireTransition(this, endTransition.x, endTransition.y, startPlace.x, startPlace.y, arc); v1.addElement(temp); if (tracing) Trace("\n U26, FireTransition done", 500); temp.setArtist(this, 0); if (child != null && !Replay) { FireTransition ctemp = new FireTransition(child, endTransition.x, endTransition.y, startPlace.x, startPlace.y, arc); v1.addElement(ctemp); ctemp.setArtist(child,0); ctemp.artist(child, 0); // } if (!subWindows.isEmpty() && !Replay) { for (Enumeration e = subWindows.elements(); e.hasMoreElements();) { ExtendedGraphCanvas eg = (ExtendedGraphCanvas)e.nextElement(); FireTransition tempSub = new FireTransition(eg, endTransition.x, endTransition.y, startPlace.x, startPlace.y, arc); v1.addElement(tempSub); tempSub.setArtist(eg,0); } } //end subWindows if (tracing) Trace("\n U27, artist done", 500); } ptrP1 = ptrP1.getNext(); if (ptrP1 != null) startPlace = (Place)ptrP1.getPlace(); else startPlace = null; } //end of while loop for(int iTmp = 0; iTmp < v1.size(); iTmp ++) { ((Thread)v1.elementAt(iTmp)).start(); } for(int iTmp = 0; iTmp < v1.size(); iTmp ++) { try { ((Thread)v1.elementAt(iTmp)).join(); } catch( InterruptedException e) {}; } v1.removeAllElements(); repaint(); while (fireCondition && (endPlace != null)) { lock(); // not do anything Arc arc1 = arcList.givenPlaceAndTransition(endPlace,endTransition); FireTransition temp1 = new FireTransition(this, endPlace.x, endPlace.y, endTransition.x, endTransition.y, arc1); v1.addElement(temp1); temp1.setArtist(this,0); if (child != null && !Replay) { FireTransition ctemp1 = new FireTransition(child, endPlace.x, endPlace.y, endTransition.x, endTransition.y, arc1); v1.addElement(ctemp1); ctemp1.setArtist(child,0); } if (!subWindows.isEmpty() && !Replay) { for (Enumeration e = subWindows.elements(); e.hasMoreElements();) { ExtendedGraphCanvas eg = (ExtendedGraphCanvas)e.nextElement(); FireTransition tempSub1 = new FireTransition(eg, endPlace.x, endPlace.y, endTransition.x, endTransition.y, arc1); v1.addElement(tempSub1); tempSub1.setArtist(eg,0); } } //end subWindows /////// endPlace.token = true; PutDot = true; /* temp1.g.fillOval(endPLace.x - (Place.radius)/10, endPlace.y-(Place.radius)/10, Place.radius/5, Place.radius/5); temp1.g.setColor(Color.white); temp1.g.drawOval(endPlace.x - (Place.radius)/10, endPlace.y - (Place.radius)/10, Place.radius/5, Place.radius/5); */ repaint(); if (child != null && !Replay) child.repaint(); if (!subWindows.isEmpty() && !Replay) { for (Enumeration e = subWindows.elements(); e.hasMoreElements();) { ExtendedGraphCanvas eg = (ExtendedGraphCanvas)e.nextElement(); Transition endTransitionSub = eg.transitionList.returnTransitionForXY (aPoint.x, aPoint.y); Element ptrSub = endTransitionSub.outputPlace.root; Place endPlaceSub = (Place)ptrSub.getPlace(); endPlaceSub.token = true; PutDot = true; eg.repaint(); } } ptrP2 = ptrP2.getNext(); if (ptrP2 != null) endPlace = (Place) ptrP2.getPlace(); else endPlace = null; } //end of while loop for(int iTmp = 0; iTmp < v1.size(); iTmp ++) { ((Thread)v1.elementAt(iTmp)).start(); } for(int iTmp = 0; iTmp < v1.size(); iTmp ++) { try { ((Thread)v1.elementAt(iTmp)).join(); } catch( InterruptedException e) {}; } v1.removeAllElements(); repaint(); trans_flag = 1; unlock(); if (trans_flag == 0) Trace("\n ILLEGAL FIRING", 700); } //end transitionFiring /*******************************************/ //code taken from the original mouseUp method //Add a transition between a place and a point public void addTransition (Place start, Point aPoint) { Transition newTransition; newEdgeFromPlace = false; newTransition = new Transition(aPoint.x, aPoint.y); // if (tracing) // Trace("29 NEW |: " + newTransition.id, 100); transitionList.insertTranAtFront(newTransition); if (child != null) child.transitionList.insertTranAtFront(newTransition); if (tracing) Trace("\n U30, transitionList added", 100); if (!subWindows.isEmpty()) { for (Enumeration e = subWindows.elements(); e.hasMoreElements();) { ExtendedGraphCanvas eg = (ExtendedGraphCanvas)e.nextElement(); eg.transitionList.insertTranAtFront(newTransition); } } start.outgoingTransition.insertTranAtFront(newTransition); if (tracing) Trace("\n U31, "+ start.id + ".outgoingTransition added", 300); newTransition.inputPlace.insertAtFront(start); // if (tracing) // { // Trace("32 "+ newTransition.id + ".inputPlace added", 300); // Trace("\n 33 Arc.cardinality = " + // String.valueOf(Arc.cardinality), 100); // } Arc arc = new Arc(start, newTransition, Arc.place2Transition); // if (tracing) // Trace("34 New Arc:\n" + "place.id = " + arc.place.id // + "; transition.id = " + arc.transition.id, 300); arcList.insertArcAtFront(arc); replayVector.addElement("A"); replayVector.addElement(arc); replayVector.addElement("T"); //WeiDong replayVector.addElement(newTransition); if (child != null) { child.arcList.insertArcAtFront(arc); child.replayVector.addElement("A"); child.replayVector.addElement(arc); child.replayVector.addElement("T"); //WeiDong child.replayVector.addElement(newTransition); } // if (tracing) // Trace("35 arcList added", 100); if (!subWindows.isEmpty()) { for (Enumeration e = subWindows.elements(); e.hasMoreElements();) { ExtendedGraphCanvas eg = (ExtendedGraphCanvas)e.nextElement(); eg.arcList.insertArcAtFront(arc); eg.replayVector.addElement("A"); eg.replayVector.addElement(arc); eg.replayVector.addElement("T"); //WeiDong eg.replayVector.addElement(newTransition); eg.repaint(); } } //end subWindows repaint(); if (child != null) child.repaint(); } //end addTransiton to a transition and a place /*********************************************/ //code taken from the original mouseUp method //add a place at the given point from the transition public void addPlace (Transition startTransition, Point aPoint) { newEdgeFromTransition = false; if (placeList.withinDistanceFromPlace(aPoint.x, aPoint.y, Place.neighborDistance) == false) { if (tracing) Trace("\n U37, ADD NEW PLACE\n", 100); DrawCircle = true; // if (tracing) // Trace("\n 38 Place.cardinality = " + // String.valueOf(Place.cardinality), 100); end = new Place(aPoint.x, aPoint.y, false); placeList.insertAtFront(end); replayVector.addElement("P"); replayVector.addElement(end); //////////// if (child != null) { child.placeList.insertAtFront(end); child.replayVector.addElement("P"); child.replayVector.addElement(end); } if (tracing) Trace("\n U39, ADD NEW PLACE --- DONE", 100); startTransition.outputPlace.insertAtFront(end); // if (tracing) // Trace("40 "+ startTransition.id + ".outputPlace added", 300); end.incomingTransition.insertTranAtFront(startTransition); // if (tracing) // Trace("41 "+ end.id + ".incomingTransition added", 300); Arc arc = new Arc(end, startTransition, Arc.transition2Place); // if (tracing) // Trace("42 New Arc:\n" + "place.id = " + arc.place.id // + "; transition.id = " + arc.transition.id, 200); arcList.insertArcAtFront(arc); replayVector.addElement("A"); replayVector.addElement(arc); if (child != null) { child.arcList.insertArcAtFront(arc); child.replayVector.addElement("A"); child.replayVector.addElement(arc); } // if (tracing) // Trace("43 arcList added: " + "arrowHead.x = " // + String.valueOf(arc.arrowHead.x) // + ", arrowHead.y = " // + String.valueOf(arc.arrowHead.y), 300); repaint(); if (child != null) child.repaint(); if (!subWindows.isEmpty()) { for (Enumeration e = subWindows.elements(); e.hasMoreElements();) { ExtendedGraphCanvas eg = (ExtendedGraphCanvas)e.nextElement(); eg.DrawCircle = true; eg.placeList.insertAtFront(end); eg.replayVector.addElement("P"); eg.replayVector.addElement(end); eg.arcList.insertArcAtFront(arc); eg.replayVector.addElement("A"); eg.replayVector.addElement(arc); eg.repaint(); } } //end subWindows newEdge = false; newEdgeFromPlace = false; newEdgeFromTransition = false; } // else if } //end addPlace /*******************************************/ //code taken from the original mouseUp method //set the global variable start which is a Place public void setStartPlace(int x, int y) { start = (Place)placeList.checkIfInCircle(x, y, Place.radius); } /*******************************************/ public void setEndPlace(int x, int y) { end = (Place)placeList.checkIfInCircle(x, y, Place.radius); if (end != null) { /* end is a place; start is either a place or a transition O--O / / | */ if (newEdgeFromPlace) { newEdgeFromPlace = false; if (start != end) { //o----------------o addTransition(start, end); } else { //start == end if (tracing) Trace("\n U12, ADD TOKEN", 150); addToken(start); if (tracing) Trace("\n U13, ALLOW A LOOP LATER", 150); } // end else } // end if (newEdgeFromPlace) else { // if (newEdgeFromTransition) |-------O drawArc(end, startTransition, Arc.transition2Place); } //end else } // end if (end != null) else { /* if (end == null) --- i.e., current mouse position is not on a place either in the vicinity of a transition, or nowhere O---| 1. newEdgeFromPlace \ \ 2. nowhere: allow for creation of a new transition | 3. mouse down and mouse up: firing transition */ if (tracing) Trace("\n U18, NEW EDGE FROM PLACE, OR ANIMATE", 150); setEndTransition (x, y); } // else // if (end != null) - current mouse position is // not on a place }//end setEndPlace /*****************************************/ //code taken from the original mouseUp method public void setEndTransition(int x, int y) { Point releasePoint = new Point (x, y); endTransition = transitionList.returnTransitionForXY(x, y); // if (tracing) // Trace("19 END TRANSITION COMPUTED", 100); if (endTransition != null) { // case 1 & 3 - a transition already exists if (newEdgeFromPlace) { // case 1 O----| drawArc(start, endTransition, Arc.place2Transition); } else { // if (!newEdgeFromPlace) --- case 3 boolean fireCondition = checkFireCondition(endTransition); if (tracing && fireCondition==true ) Trace("\n U21, ANIMATE TRANSITION " + endTransition.id, 150); //fire transition transitionFiring(endTransition,fireCondition, releasePoint); replayVector.addElement("F"); //WeiDong replayVector.addElement(releasePoint); if (child!=null) { child.replayVector.addElement("F"); //WeiDong child.replayVector.addElement(releasePoint); } if (!subWindows.isEmpty()) { for (Enumeration e = subWindows.elements(); e.hasMoreElements();) { ExtendedGraphCanvas eg = (ExtendedGraphCanvas)e.nextElement(); eg.replayVector.addElement("F"); //WeiDong eg.replayVector.addElement(releasePoint); } } //end subWindows } // end else } // end if (endTransition != null) else { // if (endTransition == null) - case 2 if (newEdgeFromPlace) { /* case 2 O \ \ */ if (tracing) { Trace("\n U28, "+ start.id + " O------------- (" + String.valueOf(x) + ", " + String.valueOf(y) + ")", 300); // Trace("\n Transition.cardinality = " + // String.valueOf(Transition.cardinality), 100); } addTransition(start, releasePoint); } else { /* if (!newEdgeFromPlace) - a new edge ending nowhere starting from a transition */ if (tracing) Trace("\n U36, |-------------o\n", 200); addPlace(startTransition, releasePoint); } // end else } // end else // if (endTransition == null) - case 2 } //end setEndTransition /********************************************/ //code taken from the original mouseUp method public void setStartTransition (int x, int y) { startTransition = transitionList.returnTransitionForXY(x, y); if (tracing) Trace("\n D12, TRAN COMPUTED", 100); //take appropriate actions depending on whether startTransition exists or not if (startTransition != null) { if (tracing) Trace("\n D13, " + startTransition.id + " |---->O, OR ANIMATE", 100); newEdge = true; newEdgeFromTransition = true; } // end of if else { //startTransition == NULL // drawing place if (placeList.withinDistanceFromPlace(x, y, Place.neighborDistance) == false) { if (tracing) Trace("\n D14, ADD NEW PLACE.", 100); DrawCircle = true; // if (tracing) // Trace("\n Place.cardinality = " // + String.valueOf(Place.cardinality), 100); Place PLACE = new Place(x, y, false); placeList.insertAtFront(PLACE); replayVector.addElement("P"); replayVector.addElement(PLACE); if (child != null) { child.placeList.insertAtFront(PLACE); child.replayVector.addElement("P"); child.replayVector.addElement(PLACE); child.repaint(); if (tracing) Trace("\n D15, Child window adding place.", 100); } placeList.print(); repaint(); if (!subWindows.isEmpty()) { for (Enumeration e = subWindows.elements(); e.hasMoreElements();) { ExtendedGraphCanvas eg = (ExtendedGraphCanvas)e.nextElement(); eg.DrawCircle = true; eg.placeList.insertAtFront(PLACE); eg.replayVector.addElement("P"); eg.replayVector.addElement(PLACE); eg.repaint(); if (tracing) Trace("\n D17, Main window adding place.", 100); } } if (tracing) Trace("\n D18, ADD NEW PLACE --- DONE", 100); newEdge = false; newEdgeFromPlace = false; newEdgeFromTransition = false; } // end of else if else Trace("\n D19, EXCEPTION", 1000); } // end of else --- (startTransition == null) } //end setStartTransition } //end of class GraphCanvas