2026
2066
drawingSurface().updatePreferredSize();
2029
public TabContent duplicateTab(FeatureOption option, boolean isYes) {
2030
NetWriter tapnWriter = new TimedArcPetriNetNetworkWriter(
2034
network().constants()
2037
option = isNetChanged(option, isYes) ? option : FeatureOption.TIME;
2040
ByteArrayOutputStream outputStream = tapnWriter.savePNML();
2041
String composedName = getTabTitle();
2042
composedName = composedName.replace(".tapn", "");
2046
composedName += isYes ? "-timed" : "-untimed";
2049
composedName += isYes ? "-game" : "-noGame";
2053
if (isNetChanged(option, isYes)) {
2054
return createNewTabFromInputStream(new ByteArrayInputStream(outputStream.toByteArray()), composedName, option, isYes);
2056
return createNewTabFromInputStream(new ByteArrayInputStream(outputStream.toByteArray()), composedName);
2058
} catch (Exception e1) {
2059
e1.printStackTrace();
2060
System.console().printf(e1.getMessage());
2065
private boolean isNetChanged(FeatureOption option, boolean isYes) {
2068
return lens.isTimed() != isYes;
2070
return lens.isGame() != isYes;
2069
public TabContent duplicateTab(TAPNLens overwriteLens, String appendName) {
2070
NetWriter tapnWriter = new TimedArcPetriNetNetworkWriter(
2074
network().constants(),
2079
ByteArrayOutputStream outputStream = tapnWriter.savePNML();
2080
String composedName = getTabTitle();
2081
composedName = composedName.replace(".tapn", "");
2082
composedName += appendName;
2083
return createNewTabFromInputStream(new ByteArrayInputStream(outputStream.toByteArray()), composedName);
2084
} catch (Exception e1) {
2085
Logger.log("Could not load model");
2086
e1.printStackTrace();
2076
2091
class CanvasPlaceDrawController extends AbstractDrawingSurfaceManager {
2669
public List<GuiAction> getAvailableDrawActions(){
2671
return new ArrayList<>(Arrays.asList(selectAction, timedPlaceAction,transAction, timedArcAction, transportArcAction, inhibarcAction, tokenAction, deleteTokenAction));
2673
return new ArrayList<>(Arrays.asList(selectAction, timedPlaceAction,transAction, timedArcAction, inhibarcAction, tokenAction, deleteTokenAction));
2677
public List<GuiAction> getAvailableSimActions(){
2679
return new ArrayList<>(Arrays.asList(timeAction, delayFireAction));
2681
delayFireAction.setName("Fire");
2682
delayFireAction.setTooltip("Fire Selected Transition");
2683
return new ArrayList<>(Arrays.asList(delayFireAction));
2687
private final GuiAction selectAction = new GuiAction("Select", "Select components (S)", "S", true) {
2688
public void actionPerformed(ActionEvent e) {
2689
setMode(Pipe.ElementType.SELECT);
2692
private final GuiAction annotationAction = new GuiAction("Annotation", "Add an annotation (N)", "N", true) {
2693
public void actionPerformed(ActionEvent e) {
2694
setMode(Pipe.ElementType.ANNOTATION);
2697
private final GuiAction inhibarcAction = new GuiAction("Inhibitor arc", "Add an inhibitor arc (I)", "I", true) {
2698
public void actionPerformed(ActionEvent e) {
2699
setMode(Pipe.ElementType.TAPNINHIBITOR_ARC);
2702
private final GuiAction transAction = new GuiAction("Transition", "Add a transition (T)", "T", true) {
2703
public void actionPerformed(ActionEvent e) {
2704
setMode(Pipe.ElementType.TAPNTRANS);
2707
private final GuiAction tokenAction = new GuiAction("Add token", "Add a token (+)", "typed +", true) {
2708
public void actionPerformed(ActionEvent e) {
2709
setMode(Pipe.ElementType.ADDTOKEN);
2713
private final GuiAction deleteTokenAction = new GuiAction("Delete token", "Delete a token (-)", "typed -", true) {
2714
public void actionPerformed(ActionEvent e) {
2715
setMode(Pipe.ElementType.DELTOKEN);
2718
private final GuiAction timedPlaceAction = new GuiAction("Place", "Add a place (P)", "P", true) {
2719
public void actionPerformed(ActionEvent e) {
2720
setMode(Pipe.ElementType.TAPNPLACE);
2724
private final GuiAction timedArcAction = new GuiAction("Arc", "Add an arc (A)", "A", true) {
2725
public void actionPerformed(ActionEvent e) {
2726
setMode(Pipe.ElementType.TAPNARC);
2729
private final GuiAction transportArcAction = new GuiAction("Transport arc", "Add a transport arc (R)", "R", true) {
2730
public void actionPerformed(ActionEvent e) {
2731
setMode(Pipe.ElementType.TRANSPORTARC);
2734
private final GuiAction timeAction = new GuiAction("Delay one time unit", "Let time pass one time unit", "W") {
2735
public void actionPerformed(ActionEvent e) {
2739
private final GuiAction delayFireAction = new GuiAction("Delay and fire", "Delay and fire selected transition", "F") {
2740
public void actionPerformed(ActionEvent e) {
2745
public void updateMode() {
2746
// deselect other actions
2747
selectAction.setSelected(CreateGui.guiMode == Pipe.ElementType.SELECT);
2748
transAction.setSelected(editorMode == Pipe.ElementType.TAPNTRANS);
2749
timedPlaceAction.setSelected(editorMode == Pipe.ElementType.TAPNPLACE);
2750
timedArcAction.setSelected(editorMode == Pipe.ElementType.TAPNARC);
2751
transportArcAction.setSelected(editorMode == Pipe.ElementType.TRANSPORTARC);
2752
inhibarcAction.setSelected(editorMode == Pipe.ElementType.TAPNINHIBITOR_ARC);
2753
tokenAction.setSelected(editorMode == Pipe.ElementType.ADDTOKEN);
2754
deleteTokenAction.setSelected(editorMode == Pipe.ElementType.DELTOKEN);
2755
annotationAction.setSelected(editorMode == Pipe.ElementType.ANNOTATION);
2758
public void updateEnabledActions(GuiFrame.GUIMode mode){
2761
selectAction.setEnabled(true);
2762
transAction.setEnabled(true);
2763
timedPlaceAction.setEnabled(true);
2764
timedArcAction.setEnabled(true);
2765
transportArcAction.setEnabled(true);
2766
inhibarcAction.setEnabled(true);
2767
tokenAction.setEnabled(true);
2768
deleteTokenAction.setEnabled(true);
2769
annotationAction.setEnabled(true);
2770
delayFireAction.setEnabled(false);
2771
timeAction.setEnabled(false);
2774
selectAction.setEnabled(false);
2775
transAction.setEnabled(false);
2776
timedPlaceAction.setEnabled(false);
2777
timedArcAction.setEnabled(false);
2778
transportArcAction.setEnabled(false);
2779
inhibarcAction.setEnabled(false);
2780
tokenAction.setEnabled(false);
2781
deleteTokenAction.setEnabled(false);
2782
annotationAction.setEnabled(false);
2783
delayFireAction.setEnabled(false);
2784
timeAction.setEnabled(false);
2786
selectAction.setEnabled(false);
2787
transAction.setEnabled(false);
2788
timedPlaceAction.setEnabled(false);
2789
timedArcAction.setEnabled(false);
2790
transportArcAction.setEnabled(false);
2791
inhibarcAction.setEnabled(false);
2792
tokenAction.setEnabled(false);
2793
deleteTokenAction.setEnabled(false);
2794
annotationAction.setEnabled(false);
2795
delayFireAction.setEnabled(true);
2797
timeAction.setEnabled(true);
2803
public static final String textforDrawing = "Drawing Mode: Click on a button to start adding components to the Editor";
2804
public static final String textforPlace = "Place Mode: Right click on a place to see menu options ";
2805
public static final String textforTAPNPlace = "Place Mode: Right click on a place to see menu options ";
2806
public static final String textforTrans = "Transition Mode: Right click on a transition to see menu options [Mouse wheel -> rotate]";
2807
public static final String textforTimedTrans = "Timed Transition Mode: Right click on a transition to see menu options [Mouse wheel -> rotate]";
2808
public static final String textforAddtoken = "Add Token Mode: Click on a place to add a token";
2809
public static final String textforDeltoken = "Delete Token Mode: Click on a place to delete a token ";
2810
public static final String textforAnimation = "Simulation Mode: Red transitions are enabled, click a transition to fire it";
2811
public static final String textforArc = "Arc Mode: Right click on an arc to see menu options ";
2812
public static final String textforTransportArc = "Transport Arc Mode: Right click on an arc to see menu options ";
2813
public static final String textforInhibArc = "Inhibitor Mode: Right click on an arc to see menu options ";
2814
public static final String textforMove = "Select Mode: Click/drag to select objects; drag to move them";
2815
public static final String textforAnnotation = "Annotation Mode: Right click on an annotation to see menu options; double click to edit";
2816
public static final String textforDrag = "Drag Mode";
2818
public void changeStatusbarText(Pipe.ElementType type) {
2821
app.ifPresent(o13 -> o13.setStatusBarText(textforPlace));
2825
app.ifPresent(o12 -> o12.setStatusBarText(textforTAPNPlace));
2830
app.ifPresent(o11 -> o11.setStatusBarText(textforTrans));
2834
app.ifPresent(o10 -> o10.setStatusBarText(textforTimedTrans));
2839
app.ifPresent(o9 -> o9.setStatusBarText(textforArc));
2843
app.ifPresent(o8 -> o8.setStatusBarText(textforTransportArc));
2846
case TAPNINHIBITOR_ARC:
2848
app.ifPresent(o7 -> o7.setStatusBarText(textforInhibArc));
2852
app.ifPresent(o6 -> o6.setStatusBarText(textforAddtoken));
2856
app.ifPresent(o5 -> o5.setStatusBarText(textforDeltoken));
2860
app.ifPresent(o4 -> o4.setStatusBarText(textforMove));
2864
app.ifPresent(o3 -> o3.setStatusBarText(textforDrawing));
2868
app.ifPresent(o2 -> o2.setStatusBarText(textforAnnotation));
2872
app.ifPresent(o1 -> o1.setStatusBarText(textforDrag));
2876
app.ifPresent(o->o.setStatusBarText("To-do (textfor" + type));