diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/AbstractSystemAction.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/AbstractSystemAction.java new file mode 100644 index 0000000..e3f827d --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/AbstractSystemAction.java @@ -0,0 +1,23 @@ +package graphicalrefactor.actions; + +import java.awt.event.ActionEvent; + +import javax.swing.AbstractAction; + +import graphicalrefactor.editor.Editor; +import graphicalrefactor.views.GraphicalRefactor; + +public abstract class AbstractSystemAction extends AbstractAction { + + protected GraphicalRefactor frame; + + public AbstractSystemAction(String name, GraphicalRefactor frame) { + super(name); + this.frame = frame; + } + + public void setFrame(GraphicalRefactor frame) { + this.frame = frame; + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/AbstractViewerAction.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/AbstractViewerAction.java index 97181bf..13c4a07 100644 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/AbstractViewerAction.java +++ b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/AbstractViewerAction.java @@ -6,7 +6,7 @@ import com.mxgraph.swing.mxGraphComponent; -public class AbstractViewerAction extends AbstractAction { +public abstract class AbstractViewerAction extends AbstractAction { protected mxGraphComponent graphComponent = null; @@ -14,9 +14,4 @@ super(name); this.graphComponent = graphComponent; } - - @Override - public void actionPerformed(ActionEvent e) { - } - } diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/OpenAction.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/OpenAction.java index e018590..dac48f9 100644 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/OpenAction.java +++ b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/OpenAction.java @@ -7,8 +7,9 @@ import javax.swing.filechooser.FileFilter; import graphicalrefactor.editor.Editor; +import graphicalrefactor.views.GraphicalRefactor; -public class OpenAction extends AbstractEditorAction { +public class OpenAction extends AbstractSystemAction { /** * */ @@ -16,12 +17,13 @@ private String lastDir = null; - public OpenAction(Editor editor) { - super("Open...", editor); + public OpenAction(GraphicalRefactor frame) { + super("Open...", frame); } @Override public void actionPerformed(ActionEvent e) { + Editor editor = frame.getEditor(); if (editor != null) { String wd = (lastDir != null) ? lastDir : System.getProperty("user.dir"); @@ -45,6 +47,7 @@ if (rc == JFileChooser.APPROVE_OPTION) { lastDir = fc.getSelectedFile().getParent(); editor.open(fc.getSelectedFile()); + frame.setTitle(frame.title + " - " + fc.getSelectedFile().getAbsolutePath()); } } } diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/SaveAction.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/SaveAction.java index 118f37a..c53eee4 100644 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/SaveAction.java +++ b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/SaveAction.java @@ -2,16 +2,17 @@ import java.awt.event.ActionEvent; -import javax.swing.AbstractAction; +import graphicalrefactor.editor.Editor; +import graphicalrefactor.views.GraphicalRefactor; -public class SaveAction extends AbstractAction { +public class SaveAction extends AbstractSystemAction { /** * */ private static final long serialVersionUID = 5660460585305281982L; - public SaveAction() { - super("Save"); + public SaveAction(GraphicalRefactor frame) { + super("Save", frame); } @Override diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/editor/Editor.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/editor/Editor.java index 4d51c71..8269464 100644 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/editor/Editor.java +++ b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/editor/Editor.java @@ -4,6 +4,8 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -53,6 +55,7 @@ private mxGraph graph = null; private String curFileName = null; + private String curFilePath = null; private DataFlowModel model = null; private ResourceDependencyGraph resourceDependencyGraph = null; private ArrayList codes = null; @@ -96,7 +99,16 @@ public String getCurFileName() { return curFileName; } + + public String getCurFilePath() { + return curFilePath; + } + public void setCurFilePath(String curFilePath) { + this.curFilePath = curFilePath; + this.curFileName = new File(curFilePath).getName(); + } + /** * Open a given file, parse the file, construct a DataFlowModel and a mxGraph * @param file given file @@ -107,6 +119,7 @@ Parser parser = new Parser(new BufferedReader(new FileReader(file))); try { model = parser.doParse(); + curFilePath = file.getAbsolutePath(); curFileName = file.getName(); if (!UpdateConflictCheck.run(model)) return null; ResourceDependencyGraph resourceGraph = NecessityOfStoringResourceStates.doDecide(model); @@ -123,6 +136,19 @@ } return null; } + + public void save() { + if (curFilePath != null) { + try { + File file = new File(curFilePath); + FileWriter filewriter = new FileWriter(file); + filewriter.write(model.toString()); + filewriter.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } /** * Construct a mxGraph from DataFlowModel and DataFlowModel @@ -232,9 +258,6 @@ } } } - - graph.setAllowDanglingEdges(false); - graph.setCellsDisconnectable(false); } finally { graph.getModel().endUpdate(); } diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/views/GraphicalRefactor.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/views/GraphicalRefactor.java index 8c93eba..7d1ce26 100644 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/views/GraphicalRefactor.java +++ b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/views/GraphicalRefactor.java @@ -12,6 +12,7 @@ public class GraphicalRefactor extends JFrame { private static final long serialVersionUID = -8690140317781055614L; + public static final String title = "Graphical Refactor"; private Editor editor; private mxGraph graph; @@ -19,7 +20,7 @@ private mxGraphComponent graphComponent; public GraphicalRefactor() { - setTitle("Graphical Refactor"); + setTitle(title); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); graph = new mxGraph() { @@ -34,6 +35,8 @@ } }; + editor = new Editor(graph); + graphComponent = new mxGraphComponent(graph) { protected mxICellEditor createCellEditor() { return new ComboBoxCellEditor(this); @@ -41,9 +44,9 @@ }; getContentPane().add(graphComponent); new mxRubberband(graphComponent); - - editor = new Editor(graph); - + graph.setAllowDanglingEdges(false); + graph.setCellsDisconnectable(true); + menuBar = new GraphicalRefactorMenuBar(this); setJMenuBar(menuBar); setSize(870, 640); diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/views/GraphicalRefactorMenuBar.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/views/GraphicalRefactorMenuBar.java index 1584119..f2767d0 100644 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/views/GraphicalRefactorMenuBar.java +++ b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/views/GraphicalRefactorMenuBar.java @@ -3,9 +3,6 @@ import javax.swing.JMenu; import javax.swing.JMenuBar; -import com.mxgraph.view.mxGraph; - -import graphicalrefactor.actions.AbstractEditorAction; import graphicalrefactor.actions.CircleLayoutAction; import graphicalrefactor.actions.ExitAction; import graphicalrefactor.actions.OpenAction; @@ -21,7 +18,6 @@ private static final long serialVersionUID = 4811536194182272888L; private GraphicalRefactor graphicalModelRefactor = null; - private OpenAction openAction = null; private JavaPrototypeGenerateAction javaPrototypeGenerateAction = null; private JerseyPrototypeGenerateAction jerseyPrototypeGenerateAction = null; private TreeLayoutAction treeLayoutAction = null; @@ -31,9 +27,9 @@ this.graphicalModelRefactor = graphicalModelRefactor; JMenu menu = null; menu = add(new JMenu("File")); - menu.add(openAction = new OpenAction(graphicalModelRefactor.getEditor())); + menu.add(new OpenAction(graphicalModelRefactor)); menu.addSeparator(); - menu.add(new SaveAction()); + menu.add(new SaveAction(graphicalModelRefactor)); menu.addSeparator(); menu.add(new ExitAction()); @@ -55,8 +51,8 @@ } public void setEditor(Editor editor) { - openAction.setEditor(editor); javaPrototypeGenerateAction.setEditor(editor); + jerseyPrototypeGenerateAction.setEditor(editor); treeLayoutAction.setEditor(editor); circleLayoutAction.setEditor(editor); } diff --git a/AlgebraicDataflowArchitectureModel/src/models/algebra/Variable.java b/AlgebraicDataflowArchitectureModel/src/models/algebra/Variable.java index 99ae839..fa0095b 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/algebra/Variable.java +++ b/AlgebraicDataflowArchitectureModel/src/models/algebra/Variable.java @@ -77,6 +77,11 @@ } public String toString() { + if (type == null) return name; + return name + ":" + type.getTypeName(); + } + + public String toImplementation(String[] sideEffects) { return name; } } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelGenerator.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelGenerator.java index 1f1e01d..ac571de 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelGenerator.java @@ -71,6 +71,15 @@ addSelector(selector); } } + + public void removeChannelMember(IdentifierTemplate id) { + for (ChannelMember cm: channelMembers) { + if (cm.getIdentifierTemplate() == id) { + channelMembers.remove(cm); + break; + } + } + } public Set getIdentifierTemplates() { Set identifierTemplates = new HashSet<>(); diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java index 4643b4c..1679f1a 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java @@ -237,7 +237,7 @@ return identifierTemplates.get(resourceName); } - public void addIdentifierTemplates(IdentifierTemplate identifierTemplate) { + public void addIdentifierTemplate(IdentifierTemplate identifierTemplate) { identifierTemplates.put(identifierTemplate.getResourceName(), identifierTemplate); } @@ -245,6 +245,17 @@ this.identifierTemplates = identifierTemplates; } + public void removeIdentifierTemplate(String resourceName) { + IdentifierTemplate id = identifierTemplates.get(resourceName); + identifierTemplates.remove(resourceName); + for (ChannelGenerator ch: channelGenerators.values()) { + ch.removeChannelMember(id); + } + for (ChannelGenerator ch: ioChannelGenerators.values()) { + ch.removeChannelMember(id); + } + } + public Collection getChannelGenerators() { return channelGenerators.values(); } @@ -269,10 +280,18 @@ } } + public void removeChannelGenerator(String channelName) { + channelGenerators.remove(channelName); + } + public Collection getIOChannelGenerators() { return ioChannelGenerators.values(); } + public ChannelGenerator getIOChannelGenerator(String channelName) { + return ioChannelGenerators.get(channelName); + } + public void setIOChannelGenerators(HashMap ioChannelGenerators) { this.ioChannelGenerators = ioChannelGenerators; for (ChannelGenerator g: ioChannelGenerators.values()) { @@ -289,6 +308,10 @@ } } + public void removeIOChannelGenerator(String ioChannelName) { + ioChannelGenerators.remove(ioChannelName); + } + public void addType(Type type) { types.put(type.getTypeName(), type); } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataflowChannelGenerator.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataflowChannelGenerator.java index b4bdb35..62870b3 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataflowChannelGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataflowChannelGenerator.java @@ -78,6 +78,30 @@ addReferenceChannelMember(groupDependentResource); } + public void removeChannelMember(IdentifierTemplate id) { + for (ChannelMember cm: inputChannelMembers) { + if (cm.getIdentifierTemplate() == id) { + inputChannelMembers.remove(cm); + super.removeChannelMember(id); + return; + } + } + for (ChannelMember cm: outputChannelMembers) { + if (cm.getIdentifierTemplate() == id) { + outputChannelMembers.remove(cm); + super.removeChannelMember(id); + return; + } + } + for (ChannelMember cm: referenceChannelMembers) { + if (cm.getIdentifierTemplate() == id) { + referenceChannelMembers.remove(cm); + super.removeChannelMember(id); + return; + } + } + } + public Set getInputIdentifierTemplates() { Set inputIdentifierTemplates = new HashSet<>(); for (ChannelMember member: inputChannelMembers) { diff --git a/AlgebraicDataflowArchitectureModel/src/parser/Parser.java b/AlgebraicDataflowArchitectureModel/src/parser/Parser.java index c41a255..1e0600d 100644 --- a/AlgebraicDataflowArchitectureModel/src/parser/Parser.java +++ b/AlgebraicDataflowArchitectureModel/src/parser/Parser.java @@ -131,7 +131,7 @@ IdentifierTemplate identifier = model.getIdentifierTemplate(resourceName); if (identifier == null) { identifier = new IdentifierTemplate(resourceName, 0); - model.addIdentifierTemplates(identifier); + model.addIdentifierTemplate(identifier); } if (!stream.hasNext()) throw new ExpectedAssignment(stream.getLine()); @@ -171,7 +171,7 @@ IdentifierTemplate identifier = model.getIdentifierTemplate(resourceName); if (identifier == null) { identifier = new IdentifierTemplate(resourceName, 0); - model.addIdentifierTemplates(identifier); + model.addIdentifierTemplate(identifier); } ChannelMember channelMember = new ChannelMember(identifier); StateTransition stateTransition = new StateTransition();