📄 petri.java
字号:
case CLICK_START_NEW_ARC: /* tell network to mark a place/trans at the location of the mouse click as place for the upcoming arc */ if ( network . selectNewArcPlace (evt . x, evt . y)) { help . setHelp (help . SELECT_TRANSITION); clickState = CLICK_TRANS_END_NEW_ARC; } else { if ( network . selectNewArcTransition (evt . x, evt . y)) { help . setHelp (help . SELECT_PLACE); clickState = CLICK_PLACE_END_NEW_ARC; } else { help . setHelp (help . NO_OBJECT_HERE); break; } } repaint (); return true; case CLICK_TRANS_END_NEW_ARC: /* tell network to mark a trans at the location of the mouse click as end for the upcoming arc */ if (! network . selectNewArcTransition (evt . x, evt . y)) { help . setHelp (help . NO_TRANSITION); break; } help . setHelp (help . EMPTY); /* add the arc */ network.addArc(); break; case CLICK_PLACE_END_NEW_ARC: /* tell network to mark a place at the location of the mouse click as end for the upcoming arc */ if (! network . selectNewArcPlace (evt . x, evt . y)) { help . setHelp (help . NO_PLACE); break; } help . setHelp (help . EMPTY); /* add the arc */ network.addArc(); break; case CLICK_START_REMOVE_ARC: /* tell network to mark a place/trans at the location of the mouse click as place for the upcoming arc */ if ( network . selectNewArcPlace (evt . x, evt . y)) { help . setHelp (help . SELECT_TRANSITION); clickState = CLICK_TRANS_END_REMOVE_ARC; } else { if ( network . selectNewArcTransition (evt . x, evt . y)) { help . setHelp (help . SELECT_PLACE); clickState = CLICK_PLACE_END_REMOVE_ARC; } else { help . setHelp (help . NO_OBJECT_HERE); break; } } repaint (); return true; case CLICK_TRANS_END_REMOVE_ARC: /* tell network to mark a trans at the location of the mouse click as end for the upcoming arc */ if (! network . selectNewArcTransition (evt . x, evt . y)) { help . setHelp (help . NO_TRANSITION); break; } help . setHelp (help . EMPTY); /* remove the arc */ network.removeArc(); break; case CLICK_PLACE_END_REMOVE_ARC: /* tell network to mark a place at the location of the mouse click as end for the upcoming arc */ if (! network . selectNewArcPlace (evt . x, evt . y)) { help . setHelp (help . NO_PLACE); break; } help . setHelp (help . EMPTY); /* remove the arc */ network.removeArc(); break; case CLICK_RUN_SIMULATION: /* invoke runSimulation method on network until it returns false */ switch (network . runSimulation ()) { case PetriNet.STATUS_NO_ACTIVABLE_TRANSITION: help . setHelp (help . NO_ACTIVABLE_TRANSITION); break; case PetriNet.STATUS_NORMAL: default: repaint (); return true; } break; case CLICK_ADD_TOKEN: /* tell network to add a token to the place at the location of the mouse click */ if (! network . addTokenToPlaceAt (evt . x, evt . y)) { help . setHelp (help . NO_PLACE); break; } help . setHelp (help . EMPTY); break; case CLICK_REMOVE_TOKEN: /* tell network to remove a token from the place at the location of the mouse click */ if (! network . removeTokenFromPlaceAt (evt . x, evt . y)) { help . setHelp (help . NO_PLACE_OR_NO_TOKEN); break; } help . setHelp (help . EMPTY); break; case CLICK_NORMAL: default: /* see if there is a state to drag */ dragging = network . selectDrag (evt . x, evt . y); break; } clickState = CLICK_NORMAL; break; case Event . MOUSE_UP: /* if we are dragging something - stop it */ if (dragging) { network . deselectDrag (evt . x, evt . y); dragging = false; } break; case Event . MOUSE_DRAG: /* if we are dragging something - keep dragging */ if (dragging) network . drag (evt . x, evt . y); break; /* handle action events (button presses) */ case Event . ACTION_EVENT: /* only respond to button presses */ if (evt . target instanceof Button) { /* find out the name of the button pressed */ String label = ((Button)(evt . target)) . getLabel (); /* pressing a button destroys previous click state */ clickState = CLICK_NORMAL; if (label . equals ("Quit")) { /* popup quit confirmation dialog */ quitDialog . show (); } else if (label . equals ("About")) { /* popup about window and play a sound */ aboutBox . show(); play (getCodeBase (), "welcome.au"); } else if (label . equals ("New")) { clearAll = true; /* create new network instance - the old one will get garbage collected */ network = new PetriNet (); /* link dialogs with the new network */ fileInput . setPetriNet (network, help); help . setHelp (help . INITIAL); } else if (label . equals ("Load")) { /* 'load' does implicit 'new' */ clearAll = true; /* create new network instance - the old one will get garbage collected */ network = new PetriNet (); /* link dialogs with the new network */ fileInput . setPetriNet (network, help); help . setHelp (help . INITIAL); /* tell file dialog to perform load and pop it up */ fileInput . setMode (FileInput . LOAD); fileInput . show(); } else if (label . equals ("Save")) { /* tell file dialog to perform save and pop it up */ fileInput . setMode (FileInput . SAVE); fileInput . show(); } else if (label . equals ("Run")) { /* tell network to start simulation */ switch (network . startSimulation ()) { case PetriNet . STATUS_NORMAL: help . setHelp (help . RUN_INSTRUCTIONS); clickState = CLICK_RUN_SIMULATION; break; default: break; } } else if (label . equals ("Stop")) { /* tell network to stop simulation */ network . stopSimulation (); help . setHelp (help . EMPTY); clickState = CLICK_NORMAL; } /* for the following buttons just set the appropriate click state and hint line text. all the work will be done after the mouse is clicked */ else if (label . equals ("Add Place")) { clickState = CLICK_PLACE_ADD; help . setHelp (help . SELECT_LOCATION); } else if (label . equals ("Del Place")) { clickState = CLICK_PLACE_REMOVE; help . setHelp (help . SELECT_PLACE); } else if (label . equals ("Add Transition")) { clickState = CLICK_TRANSITION_ADD; help . setHelp (help . SELECT_LOCATION); } else if (label . equals ("Del Transition")) { clickState = CLICK_TRANSITION_REMOVE; help . setHelp (help . SELECT_TRANSITION); } else if (label . equals ("Add Arc")) { clickState = CLICK_START_NEW_ARC; help . setHelp (help . SELECT_OBJECT); } else if (label . equals ("Del Arc")) { clickState = CLICK_START_REMOVE_ARC; help . setHelp (help . SELECT_OBJECT); } else if (label . equals ("Add Token")) { clickState = CLICK_ADD_TOKEN; help . setHelp (help . SELECT_PLACE); } else if (label . equals ("Del Token")) { clickState = CLICK_REMOVE_TOKEN; help . setHelp (help . SELECT_PLACE); } } break; /* for all other events run the default Applet class handler */ default: return super . handleEvent (evt); } /* force applet repaint as something could have changed */ repaint (); /* return true - means we have handled the event and there is no no need to pass it along to other components */ return true; } /* end handleEvent */} /* end Petri */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -