/********************************************************************** Tool: Augmented Petrinet for distributed behavioral requirements modelling and simulation Authors: Sangeet Gupta Minqi Li Padma Ravindranathan DanDan Wang. Naveen K Yeddula Last modified on: 9/25/97. ************************************************************************/ // Here this file imports the Abstract Windowing Toolkit from the java library import java.awt.*; import java.applet.*; import java.lang.String; public class petrinet1 extends java.applet.Applet { /* applet's dimensions */ final static int DIMENSION = 750; /* height of the button control area */ final static int CONTROL_HEIGHT = 500; Frame frame; Frame frame2; // Frame frame3; GraphCanvas graphcanvas = new GraphCanvas(this); GraphCanvas graphcanvas2 = new GraphCanvas(this); // GraphCanvas graphcanvas3 = new GraphCanvas(this); // Options options = new Options(this); Documentation documentation = new Documentation(); Documentation documentation2 = new Documentation(); // Documentation documentation3 = new Documentation(); public void init() { petrinet1 g = new petrinet1(); Frame frame = new MenuFrame("Petrinet"); Frame frame2 = new MenuFrame("Second window"); // Frame frame3 = new MenuFrame("Third window"); setLayout(new BorderLayout(2, 2)); frame.add("South", documentation); frame.add("Center", graphcanvas); frame.setBackground(Color.pink); frame.resize(DIMENSION,CONTROL_HEIGHT); frame.show(); frame2.setBackground(Color.white); frame2.add("South", documentation2); frame2.add("Center",graphcanvas2); frame2.resize(300,300); frame2.show(); // frame3.setBackground(Color.white); // frame3.add("South",documentation3); // frame3.add("Center",graphcanvas3); // frame3.resize(300,300); // frame3.show(); } public Insets insets() { // return new Insets(10, 10, 10, 10); return new Insets(1, 1, 1, 1); } public void lock() { graphcanvas.lock(); //options.lock(); } public void unlock() { graphcanvas.unlock(); //options.unlock(); } } // end petrinet1 class MenuFrame extends Frame { // set of options at the top of the screen // from Quan's NFR-Assistant private Menu file_menu, place_menu, transition_menu, token_menu, condition_menu, simulate_menu, edit_menu, help_menu; private MenuBar menu_bar; private Display pad; private Panel main_panel; private GridBagLayout gridbag = new GridBagLayout(); petrinet1 parent; boolean Locked=false; MenuFrame(String title) { super(title); file_menu = new Menu("File"); file_menu.add (new MenuItem("Clear")); file_menu.add (new MenuItem("Load")); file_menu.add (new MenuItem("Save")); file_menu.add (new MenuItem("Print")); file_menu.add (new MenuItem("Quit")); place_menu = new Menu("Place"); place_menu.add (new MenuItem("Add place")); place_menu.add (new MenuItem("Delete place")); transition_menu = new Menu("Transition"); transition_menu.add (new MenuItem("Add transition")); transition_menu.add (new MenuItem("Delete transition")); transition_menu.add (new MenuItem("Fire transition")); token_menu = new Menu("Token"); token_menu.add (new MenuItem("Add token")); token_menu.add (new MenuItem("Delete token")); condition_menu = new Menu("Condition"); condition_menu.add (new MenuItem("Add Condition")); condition_menu.add (new MenuItem("Delete Condition")); simulate_menu = new Menu("Simulate"); simulate_menu.add (new MenuItem("Arrival interval")); simulate_menu.add (new MenuItem("Firing delay")); simulate_menu.add (new MenuItem("Weight")); edit_menu = new Menu("Edit"); edit_menu.add (new MenuItem("Drag")); edit_menu.add (new MenuItem("Move")); edit_menu.add (new MenuItem("Scale")); edit_menu.add (new MenuItem("Font")); edit_menu.add (new MenuItem("Add Link")); edit_menu.add (new MenuItem("Delete Link")); help_menu = new Menu("Help"); help_menu.add (new MenuItem("Glossary")); help_menu.add (new MenuItem("Tutorial")); help_menu.add (new MenuItem("About")); menu_bar = new MenuBar(); menu_bar.add (file_menu); menu_bar.add (place_menu); menu_bar.add (transition_menu); menu_bar.add (token_menu); menu_bar.add (condition_menu); menu_bar.add (simulate_menu); menu_bar.add (edit_menu); menu_bar.add (help_menu); this.setMenuBar (menu_bar); } // end of Display frame constructor FileDialog openFile = new FileDialog(this,"Open Your Petrinet File",FileDialog.LOAD); FileDialog saveFile = new FileDialog(this,"Save Your Petrinet File As",FileDialog.SAVE); public boolean handleEvent(Event event){ if (event.target instanceof MenuItem){ if("New".equals(event.arg)){ return true;} else if("Load".equals(event.arg)){ openFile.show(); return true;} else if("Save".equals(event.arg)){ saveFile.show(); return true;} else if("Black".equals(event.arg)){ return true;} else if("Blue".equals(event.arg)){ return true;} else if("Red".equals(event.arg)){ return true;} else if("White".equals(event.arg)){ return true;} else if("Black Background".equals(event.arg)){ return true;} else if("Blue Background".equals(event.arg)){ return true;} else if("Red Background".equals(event.arg)){ return true;} else if("White Background".equals(event.arg)){ return true;} else if("Exit".equals(event.arg)){ System.exit(0); return true;} }//end if return false; } class Documentation extends Panel { // Documentation on top of the screen DocOptions docopt = new DocOptions(this); DocText doctext = new DocText(); Documentation() { setLayout(new BorderLayout(1, 1)); add("West", docopt); add("Center", doctext); } } class DocOptions extends Panel { Choice doc = new Choice(); Documentation parent; DocOptions(Documentation myparent) { // setLayout(new GridLayout(2, 1, 5, 0)); setLayout(new GridLayout(0, 2)); parent = myparent; Label l = new Label ("Instruction:", Label . LEFT); //Label l = new Label ("Instruction:", Label . CENTER); l . setForeground (Color . red); l . setFont (new Font ("Helvetica", Font . BOLD, 10)); add (l); doc.addItem("Add Place"); doc.addItem("Del Place"); doc.addItem("Add Transition"); doc.addItem("Del Transition"); doc.addItem("Add Token"); doc.addItem("Fire Transition"); doc.addItem("Clear"); doc.addItem("run algorithm"); doc.addItem("step through"); doc.addItem("example"); doc.addItem("exit"); doc.addItem("all items"); add(doc); } public boolean action(Event evt, Object arg) { if (evt.target instanceof Choice) { String str=new String(doc.getSelectedItem()); parent.doctext.showline(str); } return true; } } class DocText extends TextArea { final String addPlace = new String("Add Place:\n"+ "Draw a place by clicking the mouse.\n\n"); final String delPlace = new String("Delete Place:\n"+ "To delete a place press and click on the place.\n"); final String addTransition = new String("Add Transition:\n"+ "To add a transition click mouse on a place,"+ "and drag it to another place.\n\n"); final String delTransition = new String("Delete Transition:\n"+ "To remove a transition, change its weight to 0.\n\n"); final String fireTransition=new String("Fire Transition:\n"+ "Currently, you can click on the destination place to fire the in-coming" +"transition(s).\n\n"); final String addToken = new String("Add Token\n"+ "To add a token keep the mouse moving on the place\n"+ "with out clicking it on the place, press button\n"); final String startNode = new String("Start Node:\n"+ "The startNode is blue, other places are grey."+ "The first place you draw on the screen will be the startNode.\n"+ "To select another startNode press , click on the startNode, "+ "and drag the mouse to another place.\n"+ "To delete the startNode, first select another startNode, and then"+ "remove the place the usual way.\n"); final String clrReset = new String(" BUTTON: "+ "This Button has to remove the current petrinet from the screen\n"+ "but its current functionality is only removing lines\n"+ "and transitions from the screen\n"); final String runalg = new String(" BUTTON: "+ "Run the algorithm on the graph, there will be a time\n" + "delay of +/- 1 second between steps.\n"+ "To run the algorithm slower, use .\n"); final String step = new String(" BUTTON: " + "An opportunity to step through the algorithm.\n"); final String example = new String(" BUTTON: "+ "Displays a graph on the screen for you.\n"+ "If wanted, the graph can be edited before you "+ " or through the animation of the algorithm.\n"); final String exitbutton = new String(" BUTTON: " + "Only works if applet is run with appletviewer.\n"); final String toclose = new String("ERROR: "+ "This position is too close to another place/transition.\n"); final String done = new String("Algorithm has finished, " + "follow orange transitions from startNode to any place "+ "to get\nthe shortest path to " + "the place. The length of the path is written in the place.\n" + "press to reset the graph, and unlock the screen."); final String some = new String("Algorithm has finished, " + "follow orange transitions from startNode to any place "+ "to get\nthe shortest path to " + "the place. The length of the path is written in the place.\n" + "There are no paths from the startNode to any gray place.\n" + "press to reset the graph, and unlock the screen."); final String none = new String("Algorithm has finished, " + "there are no places reachable from the start place.\n"+ "press to reset the graph, and unlock the screen."); final String maxplaces = new String("ERROR: "+ "Maximum number of places reached!\n\n"); final String info = new String("You can scroll through the documentation or get documentation\n"+ "on a specific "+ "item by selecting the item on the left.\nSelecting "+ "brings you back "+ " to the scrolling text.\n\n"); final String locked = new String("ERROR: "+ "Keyboard/mouse locked for this action.\n"+ "Either press or .\n"); final String doc = info; final String docAll = info + addPlace + delPlace + addToken + startNode + addTransition + fireTransition + delTransition + clrReset + runalg + step + example + exitbutton; DocText() { //super(5, 2); //super(3, 2); super(2, 2); setText(doc); } public void showline(String str) { if (str.equals("Add Place")) setText(addPlace); else if (str.equals("Del Place")) setText(delPlace); else if (str.equals("Add Transition")) setText(addTransition); else if (str.equals("Del Transition")) setText(delTransition); else if (str.equals("Add Token")) setText(addToken); else if (str.equals("Fire Transition")) setText(fireTransition); else if (str.equals("Start Node")) setText(startNode); else if (str.equals("Clear")) setText(clrReset); else if (str.equals("run algorith")) setText(runalg); else if (str.equals("step throug")) setText(step); else if (str.equals("exampl")) setText(example); else if (str.equals("exit")) setText(exitbutton); else if (str.equals("all items")) setText(docAll); else if (str.equals("toclose")) setText(toclose); else if (str.equals("done")) setText(done); else if (str.equals("locked")) setText(locked); else if (str.equals("maxplaces")) setText(maxplaces); else if (str.equals("none")) setText(none); else if (str.equals("some")) setText(some); else setText(str); } } class fireTransition { double slope; int endX, endY, startX, startY; //a, b, c, d; double distance, dx, dy; double l=20; int step; Canvas canvas; Graphics g; Arc arc; //GraphCanvas graphCanvas = new GraphCanvas(); boolean painting=false; fireTransition(Canvas canvas, int endX, int endY, int startX, int startY, Arc arc) { this.canvas = canvas; this.endX = endX; this.endY = endY; this.startX = startX; this.startY = startY; this.g = canvas.getGraphics(); this.arc = arc; slope = Math.atan((double)(endY - startY)/(endX - startX)); step=1; distance=Math.sqrt((endY - startY) * (endY - startY) + (endX - startX) * (endX - startX)); this.l = this.distance/10; //calculate the sign of dx and dy if (startX < endX && startY > endY) slope = slope + 3.14159; else if (startX < endX && startY < endY) slope = slope - 3.14159; dx = -l * Math.cos(slope); dy = -l * Math.sin(slope); }//end constructor. //paintings: //public void artist(Canvas canvas)//, int a, int b, int c, int d) public void artist(GraphCanvas canvas)//, int a, int b, int c, int d) { int xp, yp; //store the previous position int xc, yc; //store the center token position xc = startX + step/21 * (int)dx - Place.radius/10; yc = startY + step/21 * (int)dy - Place.radius/10; {// draw the first token: g.setColor(Color.red); g.fillOval(xc, yc, Place.radius/5, Place.radius/5); g.setColor(Color.white); g.drawOval(xc, yc, Place.radius/5, Place.radius/5); xp = startX; yp = startY; canvas.repaint(); try { Thread.sleep(1); } //try { Thread.sleep(40); } //try { Thread.sleep(100); } catch (InterruptedException e) {} step++; } Color bg = canvas.getBackground(); // draw the following circle and hide the previous circle while (step/21 * l < distance) //while (step*lO, OR ANIMATE", 1000);} newEdge = true; newEdgeFromTransition = true; //thisPoint = new Point(x, y); //transition temp = tranList.returnTransitionForXY(x, y); //start = new Place(temp.middle.x, temp.middle.y, false ); //Place.counter--; //Place.cardinality--; //startout = new Point (x,y); } // if (startTransition != null) else // if (startTransition == null) { //if (Place.placeList.withinDistanceFromPlace(x, y, if (placeList.withinDistanceFromPlace(x, y, Place.neighborDistance) == false) { if (tracing) { Trace("ADD NEW PLACE\n", 1000); } DrawCircle = true; if (tracing) {Trace("\n Place.cardinality = " + String.valueOf(Place.cardinality), 1000); } Place PLACE = new Place(x, y, false); placeList.insertAtFront( PLACE ); //Place.placeList.insertAtFront( PLACE ); placeList.print(); //Place.placeList.print(); repaint(); if (tracing) {Trace("\nADD NEW PLACE --- DONE", 1000);} //AddPlace(x, y); newEdge = false; newEdgeFromPlace = false; newEdgeFromTransition = false; } // else if else {Trace("EXCEPTION", 1000);} } // end else --- (startTransition == null) } // else // (!evt.shiftDown() && // !evt.shiftDown() && // (enclosingPlace == null)) } // else // (!evt.controlDown() && !evt.shiftDown()) } // else (!(evt.controlDown()) ) return true; } //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; } //For every mouse drag event this method is accesed public boolean mouseDrag(Event evt, int x, int y) { if (newEdge) { if (tracing) { Trace("mouseDrag", 1000); } thisPoint = new Point(x, y); if (tracing) { Trace("\n " + "thisPoint.x = " + String.valueOf(x) + ", " + "thisPoint.y = " + String.valueOf(y), 500); } sessionStart = true; repaint(); if (tracing) { Trace("\n\nDRAGGING DONE", 500); } } return true; } //For every mouse up event this method is accesed public boolean mouseUp(Event evt, int x, int y) { if (tracing) { Trace("mouseUp", 1000); } Transition newTransition; if (newEdge) { newEdge = false; //end = Place.placeList.checkIfInCircle(x, y, Place.radius); 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 { if (tracing) {Trace (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); } newTransition = new Transition( (int)( (start.x + end.x)/2 ), (int)( (start.y + end.y)/2 ) ); if (tracing) { Trace("NEW TRANSITION:\n" + start.id + " O--------------------O " + end.id + "\n " + " | " + newTransition.id + ": " + "x = " + String.valueOf(newTransition.x) + ", y = " + String.valueOf(newTransition.y), 1500); } transitionList.insertTranAtFront(newTransition); if (tracing) { Trace("tranList added", 1000); } start.outgoingTransition.insertTranAtFront(newTransition); if (tracing) { Trace(start.id + ".outgoingTransition added", 1500); } newTransition.inputPlace.insertAtFront(start); if (tracing) {Trace (newTransition.id + ".inputPlace added", 1500); Trace("\n\n Arc.cardinality = " + String.valueOf(Arc.cardinality), 1000);} Arc arc = new Arc(start, newTransition, Arc.place2Transition); if (tracing) { Trace ("New Arc: O----------| \n" + "place.id = " + arc.place.id + "; transition.id = " + arc.transition.id, 1000);} arcList.insertArcAtFront(arc); if (tracing) {Trace("arcList added", 1000);} //newTransition.oneIncomingArc = arc; newTransition.outputPlace.insertAtFront(end); if (tracing) {Trace(newTransition.id + ".outputPlace added", 3000);} end.incomingTransition.insertTranAtFront(newTransition); if (tracing) {Trace(end.id + ".incomingTransition added", 3000);} arc = new Arc(end, newTransition, Arc.transition2Place); if (tracing) {Trace("New Arc: |------------O \n" + "place.id = " + arc.place.id + "; transition.id = " + arc.transition.id, 3000);} arcList.insertArcAtFront(arc); if (tracing) {Trace("\n arcList added\n" + "arrowHead.x = " + String.valueOf(arc.arrowHead.x) + ", arrowHead.y = " + String.valueOf(arc.arrowHead.y), 1000);} //newTransition.oneOutgoingArc = arc; repaint(); } else // start == end { if (tracing) {Trace("ADD TOKEN", 1500);} start.token = true; PutDot = true; repaint(); if (tracing) {Trace("ALLOW A LOOP LATER", 1500);} // Create a transition, tr; // Create an edge from "start" to tr; // Create an edge from tr to "end" //transitionUpdate (start, end, 50, x, y); //repaint(); } // end else } // end if (newEdgeFromPlace) else // if (newEdgeFromTransition) |-------O { if (tracing) {Trace(startTransition.id + " |-----O " + end.id, 1500);} newEdgeFromTransition = false; // Create an edge from "startTransition" to "end" startTransition.outputPlace.insertAtFront(end); if (tracing) {Trace(startTransition.id + ".outputPlace added", 1500);} end.incomingTransition.insertTranAtFront(startTransition); if (tracing) {Trace(endTransition.id + ".incomingTran added", 1500);} Arc arc = new Arc(end, startTransition, Arc.transition2Place); if (tracing) {Trace("new arc with;\n" + "place.id = " + arc.place.id + "; transition.id = " + arc.transition.id, 1500);} arcList.insertArcAtFront(arc); if (tracing) {Trace("arcList added", 1500);} repaint(); } //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("NEW EDGE FROM PLACE, OR ANIMATE", 1500);} endTransition = transitionList.returnTransitionForXY(x, y); if (tracing) {Trace("END TRANSITION COMPUTED", 1000);} if (endTransition != null) // case 1 & 3 - a transition already exists { if (newEdgeFromPlace) // case 1 O----| { newEdgeFromPlace = false; if (tracing) {Trace(start.id + " O------------| " + endTransition.id, 1500);} start.outgoingTransition.insertTranAtFront(endTransition); endTransition.inputPlace.insertAtFront(start); Arc arc = new Arc(start, endTransition, Arc.place2Transition); arcList.insertArcAtFront(arc); repaint(); } else // if (!newEdgeFromPlace) --- case 3 { if (tracing) {Trace("ANIMATE TRANSITION " + endTransition.id, 1500);} newEdgeFromTransition = false; Element ptrP1 = endTransition.inputPlace.root; Place startPlace = (Place)ptrP1.getPlace(); if (tracing) {Trace("startPlace.id = " + startPlace.id, 1500);} Element ptrP2 = endTransition.outputPlace.root; Place endPlace = (Place)ptrP2.getPlace(); if (tracing) {Trace("endPlace.id = " + endPlace.id, 1500);} if ((startPlace != null) && (endPlace != null)) { if (tracing) {Trace("ANIMATE: " + startPlace.id + " O-------->|------->O " + endPlace.id, 1500);} lock(); //Place.placeList.DeleteToken(startPlace.x, //placeList.DeleteToken(startPlace.x, //startPlace.y, Place.radius); startPlace.token = false; // animating the movement of token // fireTransition temp = new fireTransition(this, // endPlace.x, endPlace.y, // startPlace.x, startPlace.y); // temp.artist(this); Arc arc = arcList.givenPlaceAndTransition(startPlace, endTransition); if (tracing) {Trace(arc.place.id + " O--------| " + arc.transition.id, 7000);} fireTransition temp = new fireTransition(this, endTransition.x, endTransition.y, startPlace.x, startPlace.y, arc); if (tracing) {Trace("fireTransition done", 5000);} temp.artist(this); if (tracing) {Trace("artist done", 5000);} arc = arcList.givenPlaceAndTransition(endPlace, endTransition); temp = new fireTransition(this, endPlace.x, endPlace.y, endTransition.x, endTransition.y, arc); temp.artist(this); // end of animation endPlace.token=true; PutDot=true; repaint(); unlock(); } // end if (weight[i][endPlace.place_id]>0) else {Trace("ILLEGAL FIRING", 7000);} } // end else } // end if (endTransition != null) else // if (endTransition == null) - case 2 { if (newEdgeFromPlace) // case 2 O // \ // \ { if (tracing) {Trace(start.id + " O------------- (" + String.valueOf(x) + ", " + String.valueOf(y) + ")", 3000); Trace("\n Transition.cardinality = " + String.valueOf(Transition.cardinality), 1000); } newEdgeFromPlace = false; newTransition = new Transition(x, y); if (tracing) {Trace("NEW |: " + newTransition.id, 1000);} transitionList.insertTranAtFront(newTransition); if (tracing) {Trace("transitionList added", 1000);} start.outgoingTransition.insertTranAtFront(newTransition); if (tracing) {Trace(start.id + ".outgoingTransition added", 3000);} newTransition.inputPlace.insertAtFront(start); if (tracing) {Trace(newTransition.id + ".inputPlace added", 3000); Trace("\n Arc.cardinality = " + String.valueOf(Arc.cardinality), 1000);} Arc arc = new Arc(start, newTransition, Arc.place2Transition); if (tracing) {Trace("New Arc:\n" + "place.id = " + arc.place.id + "; transition.id = " + arc.transition.id, 3000);} arcList.insertArcAtFront(arc); if (tracing) {Trace("arcList added", 1000);} //newTransition.oneIncomingArc = arc; } else // if (!newEdgeFromPlace) - a new edge ending nowhere // starting from a transition { if (tracing) {Trace("|--------------\n", 2000);} newEdgeFromTransition = false; if (placeList.withinDistanceFromPlace(x, y, Place.neighborDistance) == false) { if (tracing) {Trace("ADD NEW PLACE\n", 1000);} DrawCircle = true; if (tracing) {Trace("\n Place.cardinality = " + String.valueOf(Place.cardinality), 1000);} end = new Place(x, y, false); placeList.insertAtFront( end ); //Place.placeList.insertAtFront( end ); //placeList.print(); //Place.placeList.print(); if (tracing) {Trace("\nADD NEW PLACE --- DONE", 1000);} //AddPlace(x, y); startTransition.outputPlace.insertAtFront(end); if (tracing) {Trace(startTransition.id + ".outputPlace added", 3000);} end.incomingTransition.insertTranAtFront(startTransition); if (tracing) {Trace(end.id +".incomingTransition added", 3000);} Arc arc = new Arc(end, startTransition, Arc.transition2Place); if (tracing) {Trace("New Arc:\n" + "place.id = " + arc.place.id + "; transition.id = " + arc.transition.id, 2000);} arcList.insertArcAtFront(arc); if (tracing) {Trace("arcList added: " + "arrowHead.x = " + String.valueOf(arc.arrowHead.x) + ", arrowHead.y = " + String.valueOf(arc.arrowHead.y), 3000);} repaint(); newEdge = false; newEdgeFromPlace = false; newEdgeFromTransition = false; } // else if } // end else } // end else // if (endTransition == null) - case 2 } // else // if (end != null) - current mouse position is not on a place } // if (newEdge) else // if (newEdge) { if (tracing) {Trace("\n\n\n ALL ELSE", 100);} } // end else //repaint(); return true; } // method for deleting a place void DeleteCircle(Place tempPlace) { //Place.placeList.delete(tempPlace); placeList.delete(tempPlace); Place.cardinality--; DrawCircle = true; //Place.placeList.print(); placeList.print(); repaint(); System.out.println(" I deleted what you wanted"); } // 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; } public void drawPlace(Graphics g, Place place) { g.setColor(new Color(150,150,250)); g.fillOval(place.x - (Place.radius)/2, place.y- (Place.radius)/2, Place.radius, Place.radius); if (tracingPlace) { Trace("\n WRITING PLACE ID", 1000);} //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.pink); g.setFont(new Font("Helvetica", Font.BOLD, 10)); g.drawString(place.id, place.x - 19, place.y - 19); if (tracingPlace) { Trace("**** DRAWING TOKEN *****", 1500);} // 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); } // end if (tempObj.token == true) } // end if (PutDot == true) } /* 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("drawTransition:" + " id = " + transition.id, 1000);} Arc incomingArc = (Arc)arcList.oneIncomingArc(transition); Arc outgoingArc = (Arc)arcList.oneOutgoingArc(transition); if (incomingArc != null) { if (tracingTransition) { Trace("\n incomingArc.place = " + incomingArc.place.id, 1000); } // 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 // (incomingArc != null) { if (tracingTransition) { Trace("\n outgoingArc.place = " + outgoingArc.place.id, 3000);} // 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)(arrowHead.x + 6*dirx); //y3= (int)(arrowHead.y + 6*diry); 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", 1000);} 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, arrowHead.x + dx, arrowHead.y - dy); g.drawString(transition.id, transition.x + dx, transition.y - dy); } else if ((startPt.x>=endPt.x) && (startPt.yendPt.y)) { g.drawString(transition.id, transition.x + dx, transition.y + fmetrics.getHeight() ); //g.drawString(transition.id, arrowHead.x + dx, //arrowHead.y + fmetrics.getHeight() ); } g.setColor(Color.black); if (tracingTransition) { Trace("\n\n transition id written", 1000);} } public void drawArc(Graphics g, Arc arc) { // draw an arc int x1, x2, x3, y1, y2, y3; Point startPt; Point endPt; if (tracingArc) { Trace("drawArc:\n" + arc.place.id + " O----------| " + arc.transition.id, 2000);} if (arc.direction == Arc.place2Transition) { if (tracingArc) { Trace("from place 2 trans", 1000);} startPt = new Point(arc.place.x, arc.place.y); endPt = new Point(arc.transition.x, arc.transition.y); } else // (arc.direction == Arc.transition2Place) { if (tracingArc) { Trace("from trans 2 place", 1000);} startPt = new Point(arc.transition.x, arc.transition.y); endPt = new Point(arc.place.x, arc.place.y); } if (tracingArc) { Trace("startPt & endPt computed", 1000);} g.setColor(new Color(100,100,250)); 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 +")", 1000);} // calculate arrowHead float dirx = arc.sin_x; float diry = arc.cos_x; if (tracingArc) { Trace("dirx = " + String.valueOf(dirx) + ", diry = " + String.valueOf(diry), 1000);} // x1= (int)(arc.arrowHead.x - 3*dirx + 6*diry); // x2= (int)(arc.arrowHead.x - 3*dirx - 6*diry); // x3= (int)(arc.arrowHead.x + 6*dirx); // // y1= (int)(arc.arrowHead.y - 3*diry - 6*dirx); // y2= (int)(arc.arrowHead.y - 3*diry + 6*dirx); // y3= (int)(arc.arrowHead.y + 6*diry); // // int transitionHead_x[] = { x1, x2, x3 ,x1}; // int transitionHead_y[] = { y1, y2, y3, y1 }; // 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}; // 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.setColor(Color.black); g.fillPolygon(transitionHead_x, transitionHead_y, 4); if (tracingArc) { Trace("Arc arrow head drawn", 1000);} // g.fillPolygon(transitionHead_x_End, transitionHead_y_End, 4); // // // write weight of transition at an appropriate position // 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() ); // } // g.setColor(Color.black); } ////draws the nodes in the tranList //public void drawTransitionNode (Graphics g, Point currentStart, Point currentEnd) { // g.setColor(new Color(100,100,250)); // g.drawLine (currentStart.x, currentStart.y, currentEnd.x, currentEnd.y); //} /*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); paint(offScreenGraphics); g.drawImage(offScreenImage, 0, 0, null); } /*this method paints the information on to the applet */ public void paint(Graphics g) { if (sessionStart) { if (tracing) {Trace("\n **** PAINT ****", 1000);} if (newEdge) { if (tracing) {Trace("\n ** PAINT: DRAGGING LINE **\n" + "start = " + start.id, 500);} g.setColor(Color.blue); //g.drawLine(start.x, start.y, thisPoint.x, thisPoint.y); g.drawLine(lastPoint.x, lastPoint.y, thisPoint.x, thisPoint.y); if (tracing) {Trace(" DRAGGING DONE", 1500); } } if (tracingArc) {Trace("\n **** start DRAWING ARCS ****", 1000);} Element ptrArc = arcList.root; while ( ptrArc != null) { if (tracingArc) {Trace("\n\n\nAN ARC EXISTS", 1000);} Arc tempObj; tempObj = (Arc)ptrArc.getArc(); ptrArc = ptrArc.next; drawArc(g, tempObj); } if (tracingTransition) {Trace("**** start DRAWING TRANSITIONS****", 1000);} //Element ptr = Transition.transitionList.root; Element ptr = transitionList.root; while ( ptr != null) { if (tracingTransition) { Trace("\n\nA TRANSITION EXISTS ", 1000);} 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); // } } if (tracingPlace) {Trace("\n\n start DRAWING PLACE ****", 1000);} //Element ptrP = Place.placeList.root; Element ptrP = placeList.root; while (ptrP != null) { if (tracingPlace) { Trace("\n\n\n A PLACE EXISTS", 1000);} 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), 1500);} drawPlace(g, tempObj); } } // end while (ptrP != null) //if (tracing) {Trace("\n ARCS, TRANSITIONS & PLACES (TOKENS) PAINTED", 1500);} {Trace("\n ARCS, TRANSITIONS & PLACES (TOKENS) PAINTED", 100);} } //end if (sessionStart) } //end paint } //end class