From fa0672769044030b255152472f10537862fde9f8 Mon Sep 17 00:00:00 2001 From: lducerf Date: Wed, 6 Mar 2019 17:49:40 +0100 Subject: [PATCH 01/14] Added .gif for the icons --- src/resources/pneditor/macroFastPlay.gif | Bin 0 -> 887 bytes src/resources/pneditor/macroPlay.gif | Bin 0 -> 857 bytes src/resources/pneditor/macroRecord.gif | Bin 0 -> 870 bytes src/resources/pneditor/macroStop.gif | Bin 0 -> 866 bytes 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/resources/pneditor/macroFastPlay.gif create mode 100644 src/resources/pneditor/macroPlay.gif create mode 100644 src/resources/pneditor/macroRecord.gif create mode 100644 src/resources/pneditor/macroStop.gif diff --git a/src/resources/pneditor/macroFastPlay.gif b/src/resources/pneditor/macroFastPlay.gif new file mode 100644 index 0000000000000000000000000000000000000000..8d7522d0f522200e05bfcb64748a5b5f274bc86e GIT binary patch literal 887 zcmZ?wbhEHb6krfw_|5({T} zzkmPv^XKp1zyJUL2kRImMnhnjgn$mnAE3Ozz!Ag1$RXpgVZi}*4q>g3ih_sCth{1o zIX@g8Ft#xW@Lkama6Hs0&CV8aVB%s&1}3E@8_ooWqdoeOX)&1r4o%b5(z#R)EJ*R` bW0k3C@f2)e>@<+ITCzf9u}?E2BZD;n?rJ-l literal 0 HcmV?d00001 diff --git a/src/resources/pneditor/macroPlay.gif b/src/resources/pneditor/macroPlay.gif new file mode 100644 index 0000000000000000000000000000000000000000..5a5e42cc160779807fd093e7fc27edaa4b63ad67 GIT binary patch literal 857 zcmZ?wbhEHb6krfw_|5=+n1WIQ%3IKaRmtQAsG zu+X`MSCOegLLteun^RY)WJRI!;Z8~Jx<4-hl{|Z74dYaPZcuies_z(NlerO=$rpSVpDcb>(P`6 Date: Wed, 6 Mar 2019 18:24:49 +0100 Subject: [PATCH 02/14] Added basic functions for replaying Undo/redo doesn't work (for now) Fast replaying works, classic play freeze the app --- src/org/pneditor/editor/MacroManager.java | 159 ++++++++++++++++++ src/org/pneditor/editor/Root.java | 25 ++- src/org/pneditor/editor/UndoManager.java | 3 + .../editor/actions/FastPlayMacroAction.java | 50 ++++++ .../editor/actions/PlayMacroAction.java | 51 ++++++ .../editor/actions/RecordMacroAction.java | 68 ++++++++ 6 files changed, 354 insertions(+), 2 deletions(-) create mode 100644 src/org/pneditor/editor/MacroManager.java create mode 100644 src/org/pneditor/editor/actions/FastPlayMacroAction.java create mode 100644 src/org/pneditor/editor/actions/PlayMacroAction.java create mode 100644 src/org/pneditor/editor/actions/RecordMacroAction.java diff --git a/src/org/pneditor/editor/MacroManager.java b/src/org/pneditor/editor/MacroManager.java new file mode 100644 index 0000000..968638e --- /dev/null +++ b/src/org/pneditor/editor/MacroManager.java @@ -0,0 +1,159 @@ +/* + * Copyright (C) 2008-2010 Martin Riesz + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.pneditor.editor; + +import java.util.ArrayList; +import java.util.List; +import javax.swing.AbstractAction; +import org.pneditor.editor.actions.RecordMacroAction; +import org.pneditor.editor.actions.PlayMacroAction; +import org.pneditor.editor.actions.FastPlayMacroAction; +import org.pneditor.util.Command; +import org.pneditor.editor.UndoManager; +import java.util.concurrent.TimeUnit; + +/** + * MacroManager manages macro, and rely on UndoManager + * + * @author Martin Riesz + */ +public class MacroManager { + + + //the list of commands, once recording is done + private List recordedCommands = new ArrayList(); + // list of commands being recorded + private List buffer = new ArrayList(); + /* + * The separation of the two list allows for the saved macro to be played during + * recording, so the new one can be composed of the old one + */ + + private int currentCommandIndex = -1; + private Root root; + private RecordMacroAction recordMacroAction; + private PlayMacroAction playMacroAction; + private FastPlayMacroAction fastPlayMacroAction; + private boolean recording; + private boolean playing; + + /** + * Constructs a new MacroManager + * + * @param root Root object + * @param undoAction action for undo button + * @param redoAction action for redo button + */ + public MacroManager(Root root, RecordMacroAction recordMacroAction, PlayMacroAction playMacroAction, FastPlayMacroAction fastPlayMacroAction) { + this.root = root; + this.recordMacroAction = recordMacroAction; + this.playMacroAction = playMacroAction; + this.fastPlayMacroAction = fastPlayMacroAction; + this.recording = false; + this.playing = false; + } + + public void recordCommand(Command command) { + /* + List nonRedoedCommands = new ArrayList(buffer.subList(currentCommandIndex + 1, buffer.size())); + buffer.removeAll(nonRedoedCommands); + */ + //Do we want macro to be sensitive to undo/redo during recording ? + buffer.add(command); + currentCommandIndex = buffer.size() - 1; + //command.execute(); + //refresh(); + //root.setModified(true); + } + + public void beginRecording() { + this.recording = true; + eraseBuffer(); + refresh(); + } + + public void endRecording() { + this.recording = false; + copyBufferToRecordedCommands(); + refresh(); + } + + + + public void playMacro(boolean fast) { + for (Command command : recordedCommands) { + command.execute(); + refresh(); + if (!fast) { + try { + TimeUnit.MILLISECONDS.sleep(500); + } + catch (InterruptedException e) {} + } + } + + } + + /** + * Erases all commands from the buffer. + */ + public void eraseBuffer() { + buffer = new ArrayList(); + } + + public void copyBufferToRecordedCommands() { + recordedCommands = new ArrayList(buffer); + } + + public int getRecordedCommandsNumber() { + return recordedCommands.size(); + } + + public boolean getRecording() { + return recording; + } + + public boolean getPlaying() { + return playing; + } + + public void setPlaying(boolean set) { + playing = set; + } + + public void setRecording(boolean set) { + recording = set; + } + + private void refresh() { + root.refreshAll(); + /* + if (isUndoable()) { + + undoAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Undo: " + executedCommands.get(currentCommandIndex).toString()); + } else { + undoAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Undo"); + } + if (isRedoable()) { + redoAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Redo: " + executedCommands.get(currentCommandIndex + 1).toString()); + } else { + redoAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Redo"); + } + */ + } + +} diff --git a/src/org/pneditor/editor/Root.java b/src/org/pneditor/editor/Root.java index 7fbdd07..28cb4cb 100644 --- a/src/org/pneditor/editor/Root.java +++ b/src/org/pneditor/editor/Root.java @@ -119,6 +119,16 @@ public UndoManager getUndoManager() { return undoManager; } + // Macro manager - per tab + protected RecordMacroAction recordMacro = new RecordMacroAction(this); + protected PlayMacroAction playMacro = new PlayMacroAction(this); + protected FastPlayMacroAction fastPlayMacro = new FastPlayMacroAction(this); + private MacroManager macroManager = new MacroManager(this, recordMacro, playMacro,fastPlayMacro); + + public MacroManager getMacroManager() { + return macroManager; + } + // Current directory - per application private File currentDirectory; @@ -335,7 +345,9 @@ private void enableOnlyPossibleActions() { boolean roleSelected = !roleEditor.getSelectedElements().isEmpty(); boolean isParent = !document.petriNet.isCurrentSubnetRoot(); boolean isPtoT = false; - + boolean macroCurrentlyPlaying = false; + boolean macroExists = (getMacroManager().getRecordedCommandsNumber()!=0 ); + if (isArc) { Arc test; test = (Arc) clickedElement; @@ -362,6 +374,10 @@ private void enableOnlyPossibleActions() { undo.setEnabled(getUndoManager().isUndoable()); redo.setEnabled(getUndoManager().isRedoable()); setPlaceStatic.setEnabled(isPlaceNode); + + recordMacro.setEnabled(!macroCurrentlyPlaying); + playMacro.setEnabled(macroExists&(!macroCurrentlyPlaying)); + fastPlayMacro.setEnabled(macroExists&(!macroCurrentlyPlaying)); } @Override @@ -521,7 +537,12 @@ private void setupMainFrame() { toolBar.addSeparator(); toolBar.add(addSelectedTransitionsToSelectedRoles); toolBar.add(removeSelectedTransitionsFromSelectedRoles); - + toolBar.addSeparator(); + + toolBar.add(recordMacro); + toolBar.add(playMacro); + toolBar.add(fastPlayMacro); + JMenuBar menuBar = new JMenuBar(); mainFrame.setJMenuBar(menuBar); diff --git a/src/org/pneditor/editor/UndoManager.java b/src/org/pneditor/editor/UndoManager.java index 118d6cf..0d1ce06 100644 --- a/src/org/pneditor/editor/UndoManager.java +++ b/src/org/pneditor/editor/UndoManager.java @@ -60,6 +60,9 @@ public void executeCommand(Command command) { executedCommands.add(command); currentCommandIndex = executedCommands.size() - 1; command.execute(); + if (root.getMacroManager().getRecording()) { + root.getMacroManager().recordCommand(command); + } refresh(); root.setModified(true); } diff --git a/src/org/pneditor/editor/actions/FastPlayMacroAction.java b/src/org/pneditor/editor/actions/FastPlayMacroAction.java new file mode 100644 index 0000000..54b6353 --- /dev/null +++ b/src/org/pneditor/editor/actions/FastPlayMacroAction.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2008-2010 Martin Riesz + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.pneditor.editor.actions; + +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import java.util.HashSet; +import java.util.Set; +import javax.swing.AbstractAction; +import javax.swing.KeyStroke; +import org.pneditor.editor.Root; +//import org.pneditor.editor.commands.DeleteElementsCommand; +import org.pneditor.petrinet.Element; +import org.pneditor.util.GraphicsTools; + +/** + * + * @author Martin Riesz + */ +public class FastPlayMacroAction extends AbstractAction { + + private Root root; + + public FastPlayMacroAction(Root root) { + this.root = root; + String name = "Play macro"; + putValue(NAME, name); + putValue(SMALL_ICON, GraphicsTools.getIcon("pneditor/macroFastPlay.gif")); + putValue(SHORT_DESCRIPTION, name); + setEnabled(false); + } + + public void actionPerformed(ActionEvent e) { + root.getMacroManager().playMacro(true); + } +} diff --git a/src/org/pneditor/editor/actions/PlayMacroAction.java b/src/org/pneditor/editor/actions/PlayMacroAction.java new file mode 100644 index 0000000..c01b2fc --- /dev/null +++ b/src/org/pneditor/editor/actions/PlayMacroAction.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2008-2010 Martin Riesz + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.pneditor.editor.actions; + +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import java.util.HashSet; +import java.util.Set; +import javax.swing.AbstractAction; +import javax.swing.KeyStroke; +import org.pneditor.editor.Root; +//import org.pneditor.editor.commands.DeleteElementsCommand; +import org.pneditor.petrinet.Element; +import org.pneditor.util.GraphicsTools; + +/** + * + * @author Martin Riesz + */ +public class PlayMacroAction extends AbstractAction { + + private Root root; + + public PlayMacroAction(Root root) { + this.root = root; + String name = "Play macro"; + putValue(NAME, name); + putValue(SMALL_ICON, GraphicsTools.getIcon("pneditor/macroPlay.gif")); + putValue(SHORT_DESCRIPTION, name); + setEnabled(false); + } + + public void actionPerformed(ActionEvent e) { + root.getMacroManager().playMacro(false); + + } +} diff --git a/src/org/pneditor/editor/actions/RecordMacroAction.java b/src/org/pneditor/editor/actions/RecordMacroAction.java new file mode 100644 index 0000000..50eab14 --- /dev/null +++ b/src/org/pneditor/editor/actions/RecordMacroAction.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2008-2010 Martin Riesz + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.pneditor.editor.actions; + +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import java.util.HashSet; +import java.util.Set; +import javax.swing.AbstractAction; +import javax.swing.KeyStroke; +import org.pneditor.editor.Root; +//import org.pneditor.editor.commands.DeleteElementsCommand; +import org.pneditor.petrinet.Element; +import org.pneditor.util.GraphicsTools; + +/** + * + * @author Martin Riesz + */ +public class RecordMacroAction extends AbstractAction { + + private Root root; + + public RecordMacroAction(Root root) { + this.root = root; + String name = "Record macro"; + putValue(NAME, name); + putValue(SMALL_ICON, GraphicsTools.getIcon("pneditor/macroRecord.gif")); + putValue(SHORT_DESCRIPTION, name); + setEnabled(true); + } + + public void actionPerformed(ActionEvent e) { + if(!root.getMacroManager().getPlaying()) { + if(root.getMacroManager().getRecording()) { //currently recording + root.getMacroManager().endRecording(); + putValue(SMALL_ICON, GraphicsTools.getIcon("pneditor/macroRecord.gif")); + String name = "Record macro"; + putValue(NAME, name); + putValue(SHORT_DESCRIPTION, name); + + }else { //currently not recording + root.getMacroManager().beginRecording(); + putValue(SMALL_ICON, GraphicsTools.getIcon("pneditor/macroStop.gif")); + String name = "Stop macro recording"; + putValue(NAME, name); + putValue(SHORT_DESCRIPTION, name); + + } + + } + + } +} From 25eba3abe4380fa1a1aaf9721e1b5e431a972be9 Mon Sep 17 00:00:00 2001 From: lducerf Date: Thu, 7 Mar 2019 15:05:56 +0100 Subject: [PATCH 03/14] Modified the MacroManager so that it only registers meaningful commands : - AddTokenCommand - FireTransitionCommand - RemoveTokenCommand All the others commands would have a very limited interest in being macro'ed, and can already be duplicated with others means, such as copy/paste. It also make the "undo" function more manageable, as it will be restricted to token operations. It also filters out some not really redoable actions, like setting a place static --- src/org/pneditor/editor/MacroManager.java | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/org/pneditor/editor/MacroManager.java b/src/org/pneditor/editor/MacroManager.java index 968638e..beeb264 100644 --- a/src/org/pneditor/editor/MacroManager.java +++ b/src/org/pneditor/editor/MacroManager.java @@ -25,6 +25,11 @@ import org.pneditor.util.Command; import org.pneditor.editor.UndoManager; import java.util.concurrent.TimeUnit; +import org.pneditor.editor.commands.AddTokenCommand; +import org.pneditor.editor.commands.FireTransitionCommand; +import org.pneditor.editor.commands.RemoveTokenCommand; + + /** * MacroManager manages macro, and rely on UndoManager @@ -73,13 +78,27 @@ public void recordCommand(Command command) { buffer.removeAll(nonRedoedCommands); */ //Do we want macro to be sensitive to undo/redo during recording ? - buffer.add(command); - currentCommandIndex = buffer.size() - 1; + if(recordableCommand(command) ) { + buffer.add(command); + currentCommandIndex = buffer.size() - 1; + } //command.execute(); //refresh(); //root.setModified(true); } + public boolean recordableCommand(Command command) { + if(command instanceof AddTokenCommand) { + return true; + }else if (command instanceof FireTransitionCommand) { + return true; + }else if (command instanceof RemoveTokenCommand) { + return true; + } else { + return false; + } + } + public void beginRecording() { this.recording = true; eraseBuffer(); From 9fd3d76a29849275d02787bdd5db60e8a4685f2a Mon Sep 17 00:00:00 2001 From: lducerf Date: Fri, 8 Mar 2019 16:57:13 +0100 Subject: [PATCH 04/14] command for execution of recorded macro in the works --- src/org/pneditor/editor/Root.java | 7 ++- .../editor/actions/RecordMacroAction.java | 2 +- .../editor/commands/FastPlayMacroCommand.java | 58 +++++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 src/org/pneditor/editor/commands/FastPlayMacroCommand.java diff --git a/src/org/pneditor/editor/Root.java b/src/org/pneditor/editor/Root.java index 28cb4cb..0868d91 100644 --- a/src/org/pneditor/editor/Root.java +++ b/src/org/pneditor/editor/Root.java @@ -327,6 +327,9 @@ public void repaintCanvas() { } private void enableOnlyPossibleActions() { + + + boolean isDeletable = clickedElement != null && !(clickedElement instanceof ReferencePlace) || !selection.isEmpty() @@ -347,13 +350,15 @@ private void enableOnlyPossibleActions() { boolean isPtoT = false; boolean macroCurrentlyPlaying = false; boolean macroExists = (getMacroManager().getRecordedCommandsNumber()!=0 ); + boolean notRecording = (!getMacroManager().getRecording()); + if (isArc) { Arc test; test = (Arc) clickedElement; isPtoT = test.isPlaceToTransition(); } - + // && notRecording ? cutAction.setEnabled(isCutable); copyAction.setEnabled(isCopyable); pasteAction.setEnabled(isPastable); diff --git a/src/org/pneditor/editor/actions/RecordMacroAction.java b/src/org/pneditor/editor/actions/RecordMacroAction.java index 50eab14..2ee9e9a 100644 --- a/src/org/pneditor/editor/actions/RecordMacroAction.java +++ b/src/org/pneditor/editor/actions/RecordMacroAction.java @@ -37,7 +37,7 @@ public class RecordMacroAction extends AbstractAction { public RecordMacroAction(Root root) { this.root = root; - String name = "Record macro"; + String name = "Record macro of token operations"; putValue(NAME, name); putValue(SMALL_ICON, GraphicsTools.getIcon("pneditor/macroRecord.gif")); putValue(SHORT_DESCRIPTION, name); diff --git a/src/org/pneditor/editor/commands/FastPlayMacroCommand.java b/src/org/pneditor/editor/commands/FastPlayMacroCommand.java new file mode 100644 index 0000000..9cb6fb6 --- /dev/null +++ b/src/org/pneditor/editor/commands/FastPlayMacroCommand.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2008-2010 Martin Riesz + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.pneditor.editor.commands; + +import org.pneditor.petrinet.Marking; +import org.pneditor.petrinet.Transition; +import org.pneditor.util.Command; + +/** + * + * @author Martin Riesz + */ +public class FastPlayMacroCommand implements Command { + + private Transition transition; + private Marking marking; + + public FastPlayMacroCommand(Transition transition, Marking marking) { + this.transition = transition; + this.marking = marking; + } + + public void execute() { + if (marking.isEnabled(transition)) { + marking.fire(transition); + } + } + + public void undo() { + if (marking.canBeUnfired(transition)) { + marking.undoFire(transition); + } + } + + public void redo() { + execute(); + } + + @Override + public String toString() { + return "Fire transition"; + } + +} From 09293c1a6128248603037129ddfec3cb5ef119cb Mon Sep 17 00:00:00 2001 From: lducerf Date: Fri, 8 Mar 2019 16:59:12 +0100 Subject: [PATCH 05/14] .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d6648aa..6df6619 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ nbproject/private/ out/ .idea/workspace.xml .idea/tasks.xml +/bin/ From 0b40ceee2c1a41c4b908e9f4e774298a5db628b2 Mon Sep 17 00:00:00 2001 From: lducerf Date: Sun, 10 Mar 2019 18:17:03 +0100 Subject: [PATCH 06/14] Macros can now be undone and redone "undo" undo a complete macro execution and "redo" also redo the whole macro --- src/org/pneditor/editor/MacroManager.java | 85 +++++++++++++++++++ .../editor/actions/FastPlayMacroAction.java | 4 +- .../editor/commands/FastPlayMacroCommand.java | 23 ++--- 3 files changed, 95 insertions(+), 17 deletions(-) diff --git a/src/org/pneditor/editor/MacroManager.java b/src/org/pneditor/editor/MacroManager.java index beeb264..9a9c2e1 100644 --- a/src/org/pneditor/editor/MacroManager.java +++ b/src/org/pneditor/editor/MacroManager.java @@ -87,6 +87,27 @@ public void recordCommand(Command command) { //root.setModified(true); } + + /* + public boolean macroAvailable() { + boolean available = true; + for (Command command : recordedCommands) { + if(command instanceof AddTokenCommand) { + if (command.) { + + } + }else if (command instanceof FireTransitionCommand) { + return true; + }else if (command instanceof RemoveTokenCommand) { + return true; + } else { + return false; + } + } + return available; + } + */ + public boolean recordableCommand(Command command) { if(command instanceof AddTokenCommand) { return true; @@ -111,7 +132,71 @@ public void endRecording() { refresh(); } + /** + * Performs the undo action. + */ + /* + public void undoCommand() { + if (isUndoable()) { + Command command = executedCommands.get(currentCommandIndex); + command.undo(); + currentCommandIndex--; + refresh(); + } + root.setModified(true); + } + */ + + + public void undoMacro() { + System.out.println(recordedCommands.size()); + for (int i = recordedCommands.size() - 1 ; i >= 0 ; i --) { + Command command = recordedCommands.get(i); + System.out.println(command); + command.undo(); + refresh(); + } + } + + + /** + * Performs the redo action. + */ + /* + public void redoNextCommand() { + if (isRedoable()) { + Command command = executedCommands.get(currentCommandIndex + 1); + command.redo(); + currentCommandIndex++; + refresh(); + } + root.setModified(true); + } + */ + + /** + * Determines if undo is possible. + * + * @return true if undo action is possible otherwise false + */ + /* + public boolean isUndoable() { + return currentCommandIndex != -1; + } + */ + + /** + * Determines if redo is possible. + * + * @return true if redo action is possible otherwise false + */ + /* + public boolean isRedoable() { + return currentCommandIndex < executedCommands.size() - 1; + } + */ + public void playMacro(boolean fast) { for (Command command : recordedCommands) { diff --git a/src/org/pneditor/editor/actions/FastPlayMacroAction.java b/src/org/pneditor/editor/actions/FastPlayMacroAction.java index 54b6353..12107c8 100644 --- a/src/org/pneditor/editor/actions/FastPlayMacroAction.java +++ b/src/org/pneditor/editor/actions/FastPlayMacroAction.java @@ -23,7 +23,7 @@ import javax.swing.AbstractAction; import javax.swing.KeyStroke; import org.pneditor.editor.Root; -//import org.pneditor.editor.commands.DeleteElementsCommand; +import org.pneditor.editor.commands.FastPlayMacroCommand; import org.pneditor.petrinet.Element; import org.pneditor.util.GraphicsTools; @@ -45,6 +45,6 @@ public FastPlayMacroAction(Root root) { } public void actionPerformed(ActionEvent e) { - root.getMacroManager().playMacro(true); + root.getUndoManager().executeCommand(new FastPlayMacroCommand(root.getMacroManager())); } } diff --git a/src/org/pneditor/editor/commands/FastPlayMacroCommand.java b/src/org/pneditor/editor/commands/FastPlayMacroCommand.java index 9cb6fb6..51ffae4 100644 --- a/src/org/pneditor/editor/commands/FastPlayMacroCommand.java +++ b/src/org/pneditor/editor/commands/FastPlayMacroCommand.java @@ -16,9 +16,8 @@ */ package org.pneditor.editor.commands; -import org.pneditor.petrinet.Marking; -import org.pneditor.petrinet.Transition; import org.pneditor.util.Command; +import org.pneditor.editor.MacroManager; /** * @@ -26,24 +25,18 @@ */ public class FastPlayMacroCommand implements Command { - private Transition transition; - private Marking marking; - - public FastPlayMacroCommand(Transition transition, Marking marking) { - this.transition = transition; - this.marking = marking; + private MacroManager macroManager; + + public FastPlayMacroCommand(MacroManager macroManager) { + this.macroManager = macroManager; } public void execute() { - if (marking.isEnabled(transition)) { - marking.fire(transition); - } + macroManager.playMacro(true); } public void undo() { - if (marking.canBeUnfired(transition)) { - marking.undoFire(transition); - } + macroManager.undoMacro(); } public void redo() { @@ -52,7 +45,7 @@ public void redo() { @Override public String toString() { - return "Fire transition"; + return "Play Macro"; } } From ca61f04e589d80f3b9a44ee4546abb92781b669d Mon Sep 17 00:00:00 2001 From: lducerf Date: Sun, 10 Mar 2019 21:45:27 +0100 Subject: [PATCH 07/14] New interface RecordableCommand.java. It extends the Command interface and add a method getRecordedElement so that the MacroManager have access to more info about recorded commands. playMacro Action/Command have been deleted and FastPlayMacro Action/Command have been renamed into playMacro The interface now display a "?" in the PlayMacroAction icon when an element used in the recorded macro is missing --- src/org/pneditor/editor/MacroManager.java | 162 ++++-------------- src/org/pneditor/editor/Root.java | 10 +- .../editor/actions/FastPlayMacroAction.java | 50 ------ .../editor/actions/PlayMacroAction.java | 5 +- .../editor/actions/RecordMacroAction.java | 2 +- .../editor/commands/AddTokenCommand.java | 9 +- .../commands/FireTransitionCommand.java | 11 +- ...acroCommand.java => PlayMacroCommand.java} | 6 +- .../editor/commands/RemoveTokenCommand.java | 9 +- src/org/pneditor/util/RecordableCommand.java | 28 +++ ...croFastPlay.gif => macroPlayUncertain.gif} | Bin 887 -> 878 bytes 11 files changed, 95 insertions(+), 197 deletions(-) delete mode 100644 src/org/pneditor/editor/actions/FastPlayMacroAction.java rename src/org/pneditor/editor/commands/{FastPlayMacroCommand.java => PlayMacroCommand.java} (89%) create mode 100644 src/org/pneditor/util/RecordableCommand.java rename src/resources/pneditor/{macroFastPlay.gif => macroPlayUncertain.gif} (72%) diff --git a/src/org/pneditor/editor/MacroManager.java b/src/org/pneditor/editor/MacroManager.java index 9a9c2e1..9fef406 100644 --- a/src/org/pneditor/editor/MacroManager.java +++ b/src/org/pneditor/editor/MacroManager.java @@ -18,17 +18,13 @@ import java.util.ArrayList; import java.util.List; -import javax.swing.AbstractAction; import org.pneditor.editor.actions.RecordMacroAction; import org.pneditor.editor.actions.PlayMacroAction; -import org.pneditor.editor.actions.FastPlayMacroAction; import org.pneditor.util.Command; -import org.pneditor.editor.UndoManager; -import java.util.concurrent.TimeUnit; -import org.pneditor.editor.commands.AddTokenCommand; -import org.pneditor.editor.commands.FireTransitionCommand; -import org.pneditor.editor.commands.RemoveTokenCommand; +import org.pneditor.util.GraphicsTools; +import javax.swing.AbstractAction; +import org.pneditor.util.RecordableCommand; /** @@ -40,19 +36,17 @@ public class MacroManager { //the list of commands, once recording is done - private List recordedCommands = new ArrayList(); + private List recordedCommands = new ArrayList(); // list of commands being recorded - private List buffer = new ArrayList(); + private List buffer = new ArrayList(); /* * The separation of the two list allows for the saved macro to be played during * recording, so the new one can be composed of the old one */ - private int currentCommandIndex = -1; private Root root; - private RecordMacroAction recordMacroAction; + private RecordMacroAction recordMacroAction; // useful only to modify them form here private PlayMacroAction playMacroAction; - private FastPlayMacroAction fastPlayMacroAction; private boolean recording; private boolean playing; @@ -63,11 +57,10 @@ public class MacroManager { * @param undoAction action for undo button * @param redoAction action for redo button */ - public MacroManager(Root root, RecordMacroAction recordMacroAction, PlayMacroAction playMacroAction, FastPlayMacroAction fastPlayMacroAction) { + public MacroManager(Root root, RecordMacroAction recordMacroAction, PlayMacroAction playMacroAction) { this.root = root; this.recordMacroAction = recordMacroAction; this.playMacroAction = playMacroAction; - this.fastPlayMacroAction = fastPlayMacroAction; this.recording = false; this.playing = false; } @@ -78,46 +71,19 @@ public void recordCommand(Command command) { buffer.removeAll(nonRedoedCommands); */ //Do we want macro to be sensitive to undo/redo during recording ? - if(recordableCommand(command) ) { - buffer.add(command); - currentCommandIndex = buffer.size() - 1; + // Currently they are not + if(isRecordableCommand(command) ) { + buffer.add((RecordableCommand) command); + //currentCommandIndex = buffer.size() - 1; } //command.execute(); //refresh(); //root.setModified(true); } + - - /* - public boolean macroAvailable() { - boolean available = true; - for (Command command : recordedCommands) { - if(command instanceof AddTokenCommand) { - if (command.) { - - } - }else if (command instanceof FireTransitionCommand) { - return true; - }else if (command instanceof RemoveTokenCommand) { - return true; - } else { - return false; - } - } - return available; - } - */ - - public boolean recordableCommand(Command command) { - if(command instanceof AddTokenCommand) { - return true; - }else if (command instanceof FireTransitionCommand) { - return true; - }else if (command instanceof RemoveTokenCommand) { - return true; - } else { - return false; - } + public boolean isRecordableCommand(Command command) { + return (command instanceof RecordableCommand); } public void beginRecording() { @@ -132,22 +98,17 @@ public void endRecording() { refresh(); } - /** - * Performs the undo action. - */ - /* - public void undoCommand() { - if (isUndoable()) { - Command command = executedCommands.get(currentCommandIndex); - command.undo(); - currentCommandIndex--; - refresh(); - } - root.setModified(true); + public boolean macroUnaffected() { + boolean unaffected = true; + for (RecordableCommand command : recordedCommands) { + if(! root.getDocument().petriNet.getCurrentSubnet().getElements().contains(command.getRecordedElement())) { + unaffected = false; + break; + } + } + return unaffected; } - */ - public void undoMacro() { System.out.println(recordedCommands.size()); for (int i = recordedCommands.size() - 1 ; i >= 0 ; i --) { @@ -158,56 +119,12 @@ public void undoMacro() { } } - - - /** - * Performs the redo action. - */ - /* - public void redoNextCommand() { - if (isRedoable()) { - Command command = executedCommands.get(currentCommandIndex + 1); - command.redo(); - currentCommandIndex++; - refresh(); - } - root.setModified(true); - } - */ - - /** - * Determines if undo is possible. - * - * @return true if undo action is possible otherwise false - */ - /* - public boolean isUndoable() { - return currentCommandIndex != -1; - } - */ - - /** - * Determines if redo is possible. - * - * @return true if redo action is possible otherwise false - */ - /* - public boolean isRedoable() { - return currentCommandIndex < executedCommands.size() - 1; - } - */ - public void playMacro(boolean fast) { + public void playMacro() { for (Command command : recordedCommands) { command.execute(); refresh(); - if (!fast) { - try { - TimeUnit.MILLISECONDS.sleep(500); - } - catch (InterruptedException e) {} - } } } @@ -216,11 +133,11 @@ public void playMacro(boolean fast) { * Erases all commands from the buffer. */ public void eraseBuffer() { - buffer = new ArrayList(); + buffer = new ArrayList(); } public void copyBufferToRecordedCommands() { - recordedCommands = new ArrayList(buffer); + recordedCommands = new ArrayList(buffer); } public int getRecordedCommandsNumber() { @@ -234,30 +151,17 @@ public boolean getRecording() { public boolean getPlaying() { return playing; } - - public void setPlaying(boolean set) { - playing = set; - } - - public void setRecording(boolean set) { - recording = set; - } - + private void refresh() { root.refreshAll(); - /* - if (isUndoable()) { - - undoAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Undo: " + executedCommands.get(currentCommandIndex).toString()); - } else { - undoAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Undo"); - } - if (isRedoable()) { - redoAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Redo: " + executedCommands.get(currentCommandIndex + 1).toString()); + } + + public void refreshPlayIcon() { + if (macroUnaffected()) { + playMacroAction.putValue(AbstractAction.SMALL_ICON, GraphicsTools.getIcon("pneditor/macroPlay.gif")); } else { - redoAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Redo"); + playMacroAction.putValue(AbstractAction.SMALL_ICON, GraphicsTools.getIcon("pneditor/macroPlayUncertain.gif")); } - */ } } diff --git a/src/org/pneditor/editor/Root.java b/src/org/pneditor/editor/Root.java index 0868d91..14995a5 100644 --- a/src/org/pneditor/editor/Root.java +++ b/src/org/pneditor/editor/Root.java @@ -122,8 +122,7 @@ public UndoManager getUndoManager() { // Macro manager - per tab protected RecordMacroAction recordMacro = new RecordMacroAction(this); protected PlayMacroAction playMacro = new PlayMacroAction(this); - protected FastPlayMacroAction fastPlayMacro = new FastPlayMacroAction(this); - private MacroManager macroManager = new MacroManager(this, recordMacro, playMacro,fastPlayMacro); + private MacroManager macroManager = new MacroManager(this, recordMacro,playMacro); public MacroManager getMacroManager() { return macroManager; @@ -320,6 +319,7 @@ public void refreshAll() { canvas.repaint(); enableOnlyPossibleActions(); getRoleEditor().refreshSelected(); + getMacroManager().refreshPlayIcon(); } public void repaintCanvas() { @@ -350,7 +350,8 @@ private void enableOnlyPossibleActions() { boolean isPtoT = false; boolean macroCurrentlyPlaying = false; boolean macroExists = (getMacroManager().getRecordedCommandsNumber()!=0 ); - boolean notRecording = (!getMacroManager().getRecording()); + //boolean notRecording = (!getMacroManager().getRecording()); + boolean macroComplete = getMacroManager().macroUnaffected(); if (isArc) { @@ -381,8 +382,8 @@ private void enableOnlyPossibleActions() { setPlaceStatic.setEnabled(isPlaceNode); recordMacro.setEnabled(!macroCurrentlyPlaying); + //playMacro.setEnabled(macroComplete); playMacro.setEnabled(macroExists&(!macroCurrentlyPlaying)); - fastPlayMacro.setEnabled(macroExists&(!macroCurrentlyPlaying)); } @Override @@ -546,7 +547,6 @@ private void setupMainFrame() { toolBar.add(recordMacro); toolBar.add(playMacro); - toolBar.add(fastPlayMacro); JMenuBar menuBar = new JMenuBar(); mainFrame.setJMenuBar(menuBar); diff --git a/src/org/pneditor/editor/actions/FastPlayMacroAction.java b/src/org/pneditor/editor/actions/FastPlayMacroAction.java deleted file mode 100644 index 12107c8..0000000 --- a/src/org/pneditor/editor/actions/FastPlayMacroAction.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2008-2010 Martin Riesz - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.pneditor.editor.actions; - -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.util.HashSet; -import java.util.Set; -import javax.swing.AbstractAction; -import javax.swing.KeyStroke; -import org.pneditor.editor.Root; -import org.pneditor.editor.commands.FastPlayMacroCommand; -import org.pneditor.petrinet.Element; -import org.pneditor.util.GraphicsTools; - -/** - * - * @author Martin Riesz - */ -public class FastPlayMacroAction extends AbstractAction { - - private Root root; - - public FastPlayMacroAction(Root root) { - this.root = root; - String name = "Play macro"; - putValue(NAME, name); - putValue(SMALL_ICON, GraphicsTools.getIcon("pneditor/macroFastPlay.gif")); - putValue(SHORT_DESCRIPTION, name); - setEnabled(false); - } - - public void actionPerformed(ActionEvent e) { - root.getUndoManager().executeCommand(new FastPlayMacroCommand(root.getMacroManager())); - } -} diff --git a/src/org/pneditor/editor/actions/PlayMacroAction.java b/src/org/pneditor/editor/actions/PlayMacroAction.java index c01b2fc..1ba92a8 100644 --- a/src/org/pneditor/editor/actions/PlayMacroAction.java +++ b/src/org/pneditor/editor/actions/PlayMacroAction.java @@ -23,7 +23,7 @@ import javax.swing.AbstractAction; import javax.swing.KeyStroke; import org.pneditor.editor.Root; -//import org.pneditor.editor.commands.DeleteElementsCommand; +import org.pneditor.editor.commands.PlayMacroCommand; import org.pneditor.petrinet.Element; import org.pneditor.util.GraphicsTools; @@ -45,7 +45,6 @@ public PlayMacroAction(Root root) { } public void actionPerformed(ActionEvent e) { - root.getMacroManager().playMacro(false); - + root.getUndoManager().executeCommand(new PlayMacroCommand(root.getMacroManager())); } } diff --git a/src/org/pneditor/editor/actions/RecordMacroAction.java b/src/org/pneditor/editor/actions/RecordMacroAction.java index 2ee9e9a..86079c2 100644 --- a/src/org/pneditor/editor/actions/RecordMacroAction.java +++ b/src/org/pneditor/editor/actions/RecordMacroAction.java @@ -49,7 +49,7 @@ public void actionPerformed(ActionEvent e) { if(root.getMacroManager().getRecording()) { //currently recording root.getMacroManager().endRecording(); putValue(SMALL_ICON, GraphicsTools.getIcon("pneditor/macroRecord.gif")); - String name = "Record macro"; + String name = "Record macro of the 'Edit tokens / Fire transitions' tool"; putValue(NAME, name); putValue(SHORT_DESCRIPTION, name); diff --git a/src/org/pneditor/editor/commands/AddTokenCommand.java b/src/org/pneditor/editor/commands/AddTokenCommand.java index 9b725c9..5c6403d 100644 --- a/src/org/pneditor/editor/commands/AddTokenCommand.java +++ b/src/org/pneditor/editor/commands/AddTokenCommand.java @@ -16,15 +16,16 @@ */ package org.pneditor.editor.commands; +import org.pneditor.petrinet.Element; import org.pneditor.petrinet.Marking; import org.pneditor.petrinet.PlaceNode; -import org.pneditor.util.Command; +import org.pneditor.util.RecordableCommand; /** * * @author Martin Riesz */ -public class AddTokenCommand implements Command { +public class AddTokenCommand implements RecordableCommand { private PlaceNode placeNode; private Marking marking; @@ -51,4 +52,8 @@ public String toString() { return "Add token"; } + public Element getRecordedElement() { + return placeNode; + } + } diff --git a/src/org/pneditor/editor/commands/FireTransitionCommand.java b/src/org/pneditor/editor/commands/FireTransitionCommand.java index 0375173..4d61cdd 100644 --- a/src/org/pneditor/editor/commands/FireTransitionCommand.java +++ b/src/org/pneditor/editor/commands/FireTransitionCommand.java @@ -16,15 +16,17 @@ */ package org.pneditor.editor.commands; +import org.pneditor.petrinet.Element; import org.pneditor.petrinet.Marking; import org.pneditor.petrinet.Transition; -import org.pneditor.util.Command; +import org.pneditor.util.RecordableCommand; + /** * * @author Martin Riesz */ -public class FireTransitionCommand implements Command { +public class FireTransitionCommand implements RecordableCommand { private Transition transition; private Marking marking; @@ -50,9 +52,14 @@ public void redo() { execute(); } + public Element getRecordedElement() { + return transition; + } + @Override public String toString() { return "Fire transition"; } + } diff --git a/src/org/pneditor/editor/commands/FastPlayMacroCommand.java b/src/org/pneditor/editor/commands/PlayMacroCommand.java similarity index 89% rename from src/org/pneditor/editor/commands/FastPlayMacroCommand.java rename to src/org/pneditor/editor/commands/PlayMacroCommand.java index 51ffae4..1f58b88 100644 --- a/src/org/pneditor/editor/commands/FastPlayMacroCommand.java +++ b/src/org/pneditor/editor/commands/PlayMacroCommand.java @@ -23,16 +23,16 @@ * * @author Martin Riesz */ -public class FastPlayMacroCommand implements Command { +public class PlayMacroCommand implements Command { private MacroManager macroManager; - public FastPlayMacroCommand(MacroManager macroManager) { + public PlayMacroCommand(MacroManager macroManager) { this.macroManager = macroManager; } public void execute() { - macroManager.playMacro(true); + macroManager.playMacro(); } public void undo() { diff --git a/src/org/pneditor/editor/commands/RemoveTokenCommand.java b/src/org/pneditor/editor/commands/RemoveTokenCommand.java index d72933a..2785543 100644 --- a/src/org/pneditor/editor/commands/RemoveTokenCommand.java +++ b/src/org/pneditor/editor/commands/RemoveTokenCommand.java @@ -16,15 +16,16 @@ */ package org.pneditor.editor.commands; +import org.pneditor.petrinet.Element; import org.pneditor.petrinet.Marking; import org.pneditor.petrinet.PlaceNode; -import org.pneditor.util.Command; +import org.pneditor.util.RecordableCommand; /** * * @author Martin Riesz */ -public class RemoveTokenCommand implements Command { +public class RemoveTokenCommand implements RecordableCommand { private PlaceNode placeNode; private Marking marking; @@ -53,4 +54,8 @@ public String toString() { return "Remove token"; } + public Element getRecordedElement() { + return placeNode; + } + } diff --git a/src/org/pneditor/util/RecordableCommand.java b/src/org/pneditor/util/RecordableCommand.java new file mode 100644 index 0000000..697a4ff --- /dev/null +++ b/src/org/pneditor/util/RecordableCommand.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2008-2010 Martin Riesz + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.pneditor.util; + +import org.pneditor.petrinet.Element; +/** + * + * @author Martin Riesz + */ +public interface RecordableCommand extends Command{ + + public Element getRecordedElement(); + +} diff --git a/src/resources/pneditor/macroFastPlay.gif b/src/resources/pneditor/macroPlayUncertain.gif similarity index 72% rename from src/resources/pneditor/macroFastPlay.gif rename to src/resources/pneditor/macroPlayUncertain.gif index 8d7522d0f522200e05bfcb64748a5b5f274bc86e..7949ffe46c820e045cb0f790d48ea5d7c9788e8e 100644 GIT binary patch literal 878 zcmZ?wbhEHb6krfw_|5(^b From 0b1326d6d3988bfcb11d2280ec6b15d3882e3ad7 Mon Sep 17 00:00:00 2001 From: lducerf Date: Sun, 10 Mar 2019 22:03:56 +0100 Subject: [PATCH 08/14] added comments --- src/org/pneditor/editor/MacroManager.java | 57 +++++++++++++++++------ src/org/pneditor/editor/Root.java | 11 ++--- 2 files changed, 45 insertions(+), 23 deletions(-) diff --git a/src/org/pneditor/editor/MacroManager.java b/src/org/pneditor/editor/MacroManager.java index 9fef406..1681aa0 100644 --- a/src/org/pneditor/editor/MacroManager.java +++ b/src/org/pneditor/editor/MacroManager.java @@ -30,7 +30,7 @@ /** * MacroManager manages macro, and rely on UndoManager * - * @author Martin Riesz + * @author Ladislas Ducerf */ public class MacroManager { @@ -45,7 +45,6 @@ public class MacroManager { */ private Root root; - private RecordMacroAction recordMacroAction; // useful only to modify them form here private PlayMacroAction playMacroAction; private boolean recording; private boolean playing; @@ -54,50 +53,64 @@ public class MacroManager { * Constructs a new MacroManager * * @param root Root object - * @param undoAction action for undo button - * @param redoAction action for redo button + * @param playMacroAction action for play macro button */ - public MacroManager(Root root, RecordMacroAction recordMacroAction, PlayMacroAction playMacroAction) { + public MacroManager(Root root, PlayMacroAction playMacroAction) { this.root = root; - this.recordMacroAction = recordMacroAction; this.playMacroAction = playMacroAction; this.recording = false; this.playing = false; } + /** + * Records a command in the buffer if it implements the RecordableCommand + * interface + * + * @param command the command to be recorded + */ public void recordCommand(Command command) { - /* - List nonRedoedCommands = new ArrayList(buffer.subList(currentCommandIndex + 1, buffer.size())); - buffer.removeAll(nonRedoedCommands); - */ //Do we want macro to be sensitive to undo/redo during recording ? // Currently they are not if(isRecordableCommand(command) ) { buffer.add((RecordableCommand) command); //currentCommandIndex = buffer.size() - 1; } - //command.execute(); - //refresh(); - //root.setModified(true); } - + /** + * Returns true if a commands implements the RecordableCommand interface + * + * @param command the command to be tested + * @return + */ public boolean isRecordableCommand(Command command) { return (command instanceof RecordableCommand); } + /** + * Puts the macroManager in recording mode and prepares everything + */ public void beginRecording() { this.recording = true; eraseBuffer(); refresh(); } + /** + * Puts the macroManager out of recording mode and saves the buffer + */ public void endRecording() { this.recording = false; copyBufferToRecordedCommands(); refresh(); } + + /** + * Identifies if all elements of the macro (places/nodes) are still existing + * + * @return false if at least one element is missing, true otherwise + */ public boolean macroUnaffected() { boolean unaffected = true; for (RecordableCommand command : recordedCommands) { @@ -109,6 +122,9 @@ public boolean macroUnaffected() { return unaffected; } + /** + * Undo a played macro. Called by the undo method of the PlayMacro command + */ public void undoMacro() { System.out.println(recordedCommands.size()); for (int i = recordedCommands.size() - 1 ; i >= 0 ; i --) { @@ -120,7 +136,9 @@ public void undoMacro() { } - + /** + * Execute a macro. Called by the execute method of the PlayMacro command + */ public void playMacro() { for (Command command : recordedCommands) { command.execute(); @@ -136,14 +154,23 @@ public void eraseBuffer() { buffer = new ArrayList(); } + /** + * Copy the buffer to the recorded commands + */ public void copyBufferToRecordedCommands() { recordedCommands = new ArrayList(buffer); } + /** + * Return the number of commands saved + * + * @return the size of recordedCommands + */ public int getRecordedCommandsNumber() { return recordedCommands.size(); } + public boolean getRecording() { return recording; } diff --git a/src/org/pneditor/editor/Root.java b/src/org/pneditor/editor/Root.java index 14995a5..449fb39 100644 --- a/src/org/pneditor/editor/Root.java +++ b/src/org/pneditor/editor/Root.java @@ -122,7 +122,7 @@ public UndoManager getUndoManager() { // Macro manager - per tab protected RecordMacroAction recordMacro = new RecordMacroAction(this); protected PlayMacroAction playMacro = new PlayMacroAction(this); - private MacroManager macroManager = new MacroManager(this, recordMacro,playMacro); + private MacroManager macroManager = new MacroManager(this, playMacro); public MacroManager getMacroManager() { return macroManager; @@ -348,10 +348,8 @@ private void enableOnlyPossibleActions() { boolean roleSelected = !roleEditor.getSelectedElements().isEmpty(); boolean isParent = !document.petriNet.isCurrentSubnetRoot(); boolean isPtoT = false; - boolean macroCurrentlyPlaying = false; + boolean macroCurrentlyRecording = getMacroManager().getRecording(); boolean macroExists = (getMacroManager().getRecordedCommandsNumber()!=0 ); - //boolean notRecording = (!getMacroManager().getRecording()); - boolean macroComplete = getMacroManager().macroUnaffected(); if (isArc) { @@ -359,7 +357,6 @@ private void enableOnlyPossibleActions() { test = (Arc) clickedElement; isPtoT = test.isPlaceToTransition(); } - // && notRecording ? cutAction.setEnabled(isCutable); copyAction.setEnabled(isCopyable); pasteAction.setEnabled(isPastable); @@ -381,9 +378,7 @@ private void enableOnlyPossibleActions() { redo.setEnabled(getUndoManager().isRedoable()); setPlaceStatic.setEnabled(isPlaceNode); - recordMacro.setEnabled(!macroCurrentlyPlaying); - //playMacro.setEnabled(macroComplete); - playMacro.setEnabled(macroExists&(!macroCurrentlyPlaying)); + playMacro.setEnabled(macroExists&(!macroCurrentlyRecording)); } @Override From fd58a1c71a8c98a6c428832069738f5241cea7e9 Mon Sep 17 00:00:00 2001 From: lducerf Date: Sun, 10 Mar 2019 22:12:19 +0100 Subject: [PATCH 09/14] Modified author for the created files --- src/org/pneditor/editor/MacroManager.java | 2 +- src/org/pneditor/editor/commands/PlayMacroCommand.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/org/pneditor/editor/MacroManager.java b/src/org/pneditor/editor/MacroManager.java index 1681aa0..f23f88b 100644 --- a/src/org/pneditor/editor/MacroManager.java +++ b/src/org/pneditor/editor/MacroManager.java @@ -28,7 +28,7 @@ /** - * MacroManager manages macro, and rely on UndoManager + * MacroManager manages macro recording and playing * * @author Ladislas Ducerf */ diff --git a/src/org/pneditor/editor/commands/PlayMacroCommand.java b/src/org/pneditor/editor/commands/PlayMacroCommand.java index 1f58b88..00f8d95 100644 --- a/src/org/pneditor/editor/commands/PlayMacroCommand.java +++ b/src/org/pneditor/editor/commands/PlayMacroCommand.java @@ -21,7 +21,7 @@ /** * - * @author Martin Riesz + * @author Ladislas Ducerf */ public class PlayMacroCommand implements Command { From 538303f71084b0cd6ea2ad350136180e565556fe Mon Sep 17 00:00:00 2001 From: lducerf Date: Sun, 10 Mar 2019 23:15:50 +0100 Subject: [PATCH 10/14] more correct authors --- src/org/pneditor/editor/actions/PlayMacroAction.java | 2 +- src/org/pneditor/editor/actions/RecordMacroAction.java | 2 +- src/org/pneditor/util/RecordableCommand.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/org/pneditor/editor/actions/PlayMacroAction.java b/src/org/pneditor/editor/actions/PlayMacroAction.java index 1ba92a8..d8ce22b 100644 --- a/src/org/pneditor/editor/actions/PlayMacroAction.java +++ b/src/org/pneditor/editor/actions/PlayMacroAction.java @@ -29,7 +29,7 @@ /** * - * @author Martin Riesz + * @author Ladislas Ducerf */ public class PlayMacroAction extends AbstractAction { diff --git a/src/org/pneditor/editor/actions/RecordMacroAction.java b/src/org/pneditor/editor/actions/RecordMacroAction.java index 86079c2..0a6ee33 100644 --- a/src/org/pneditor/editor/actions/RecordMacroAction.java +++ b/src/org/pneditor/editor/actions/RecordMacroAction.java @@ -29,7 +29,7 @@ /** * - * @author Martin Riesz + * @author Ladislas Ducerf */ public class RecordMacroAction extends AbstractAction { diff --git a/src/org/pneditor/util/RecordableCommand.java b/src/org/pneditor/util/RecordableCommand.java index 697a4ff..001b7c4 100644 --- a/src/org/pneditor/util/RecordableCommand.java +++ b/src/org/pneditor/util/RecordableCommand.java @@ -19,7 +19,7 @@ import org.pneditor.petrinet.Element; /** * - * @author Martin Riesz + * @author Ladislas Ducerf */ public interface RecordableCommand extends Command{ From ded8aee7508772017470bfcbe5fd11f67e7b6d20 Mon Sep 17 00:00:00 2001 From: lducerf Date: Mon, 11 Mar 2019 09:54:32 +0100 Subject: [PATCH 11/14] a bit of cleanup --- src/org/pneditor/editor/MacroManager.java | 5 ---- .../editor/actions/RecordMacroAction.java | 30 ++++++++----------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/src/org/pneditor/editor/MacroManager.java b/src/org/pneditor/editor/MacroManager.java index f23f88b..a8be2e4 100644 --- a/src/org/pneditor/editor/MacroManager.java +++ b/src/org/pneditor/editor/MacroManager.java @@ -47,7 +47,6 @@ public class MacroManager { private Root root; private PlayMacroAction playMacroAction; private boolean recording; - private boolean playing; /** * Constructs a new MacroManager @@ -59,7 +58,6 @@ public MacroManager(Root root, PlayMacroAction playMacroAction) { this.root = root; this.playMacroAction = playMacroAction; this.recording = false; - this.playing = false; } /** @@ -175,9 +173,6 @@ public boolean getRecording() { return recording; } - public boolean getPlaying() { - return playing; - } private void refresh() { root.refreshAll(); diff --git a/src/org/pneditor/editor/actions/RecordMacroAction.java b/src/org/pneditor/editor/actions/RecordMacroAction.java index 0a6ee33..aa6e0d0 100644 --- a/src/org/pneditor/editor/actions/RecordMacroAction.java +++ b/src/org/pneditor/editor/actions/RecordMacroAction.java @@ -45,24 +45,20 @@ public RecordMacroAction(Root root) { } public void actionPerformed(ActionEvent e) { - if(!root.getMacroManager().getPlaying()) { - if(root.getMacroManager().getRecording()) { //currently recording - root.getMacroManager().endRecording(); - putValue(SMALL_ICON, GraphicsTools.getIcon("pneditor/macroRecord.gif")); - String name = "Record macro of the 'Edit tokens / Fire transitions' tool"; - putValue(NAME, name); - putValue(SHORT_DESCRIPTION, name); + if(root.getMacroManager().getRecording()) { //currently recording + root.getMacroManager().endRecording(); + putValue(SMALL_ICON, GraphicsTools.getIcon("pneditor/macroRecord.gif")); + String name = "Record macro of the 'Edit tokens / Fire transitions' tool"; + putValue(NAME, name); + putValue(SHORT_DESCRIPTION, name); - }else { //currently not recording - root.getMacroManager().beginRecording(); - putValue(SMALL_ICON, GraphicsTools.getIcon("pneditor/macroStop.gif")); - String name = "Stop macro recording"; - putValue(NAME, name); - putValue(SHORT_DESCRIPTION, name); - - } - - } + }else { //currently not recording + root.getMacroManager().beginRecording(); + putValue(SMALL_ICON, GraphicsTools.getIcon("pneditor/macroStop.gif")); + String name = "Stop macro recording"; + putValue(NAME, name); + putValue(SHORT_DESCRIPTION, name); + } } } From d8a460779561389765e04b3421c66f1caef83bf9 Mon Sep 17 00:00:00 2001 From: lducerf Date: Tue, 12 Mar 2019 21:42:16 +0100 Subject: [PATCH 12/14] remove System.out.println --- src/org/pneditor/editor/MacroManager.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/org/pneditor/editor/MacroManager.java b/src/org/pneditor/editor/MacroManager.java index a8be2e4..0691922 100644 --- a/src/org/pneditor/editor/MacroManager.java +++ b/src/org/pneditor/editor/MacroManager.java @@ -124,10 +124,8 @@ public boolean macroUnaffected() { * Undo a played macro. Called by the undo method of the PlayMacro command */ public void undoMacro() { - System.out.println(recordedCommands.size()); for (int i = recordedCommands.size() - 1 ; i >= 0 ; i --) { Command command = recordedCommands.get(i); - System.out.println(command); command.undo(); refresh(); } From f086f797ea3906b7443ef34faa51ef812c0e23ea Mon Sep 17 00:00:00 2001 From: lducerf Date: Wed, 13 Mar 2019 09:07:19 +0100 Subject: [PATCH 13/14] branch cleanup --- src/org/pneditor/editor/MacroManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/org/pneditor/editor/MacroManager.java b/src/org/pneditor/editor/MacroManager.java index 0691922..82e21d8 100644 --- a/src/org/pneditor/editor/MacroManager.java +++ b/src/org/pneditor/editor/MacroManager.java @@ -44,6 +44,7 @@ public class MacroManager { * recording, so the new one can be composed of the old one */ + private Root root; private PlayMacroAction playMacroAction; private boolean recording; From dec9315dd86138b744b47b4e3853190bdb33b52b Mon Sep 17 00:00:00 2001 From: lducerf Date: Wed, 13 Mar 2019 09:09:30 +0100 Subject: [PATCH 14/14] updated README.md --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 95d6ad8..d0bffdf 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,16 @@ PNEditor (Petri Net editor) ======== +Status of the different branches : + +- Invariant : adds a token limit on places +- MacroRecorder : abandonned branche (a version of macro that had modifications from invariant) +- MacroRecorderClean : adds a macro manager +- MacroLimit : integrates the token limit and the macro manager +- macroAndTokenLimit : integrates the token limit, the macro manager and the fire N modification +from https://github.com/e17goudi/pneditor. due to some modifications on the marking class there, +this version compile but has some bugs (try to find them !) + + You can download PNEditor from [www.pneditor.org](http://www.pneditor.org/)