diff --git a/AlgebraicDataflowArchitectureModel/models/Algo.model b/AlgebraicDataflowArchitectureModel/models/Algo.model new file mode 100644 index 0000000..6228431 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/models/Algo.model @@ -0,0 +1,12 @@ +channel turnA{ + ref handsB(b:List, drawA(target:Int, guess:Int, b, d)) + ref deck(d:List, drawA(target, guess, b, d)) + out handsA(a:List, drawA(target, guess, b, d)) == if(eq(get(b, target), guess), cons(tuple(fst(head(d)), false), a), cons(tuple(fst(head(d)), true), a)) + out handsB(a:List, drawA(target, guess, b, d)) == if(eq(get(b, target), guess), set(a, target, tuple(fst(get(a, target)), true)), a) + out deck(t:List, drawA(target, guess, b, d)) == tail(d) +} +channel turnAA{ + ref handsB(b:List, selectA(target:Int, guess:Int, attacker:Int, b)) + out handsA(a:List, selectA(target, guess, attacker, b)) == if(eq(get(b, target), guess), a, set(a, attacker, tuple(fst(get(a, attacker)), true))) + out handsB(a:List, selectA(target, guess, attacker, b)) == if(eq(get(b, target), guess), set(a, target, tuple(fst(get(a, target)), true)), a) +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/models/Bug.model b/AlgebraicDataflowArchitectureModel/models/Bug.model new file mode 100644 index 0000000..f31727b --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/models/Bug.model @@ -0,0 +1,7 @@ +channel CIO{ + out aUa(a, input(x:Int)) == x +} +channel C1{ + in aUa(a, update(x)) == x + out aUb(b, update(x)) == x + 3 +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/models/Hello.model b/AlgebraicDataflowArchitectureModel/models/Hello.model new file mode 100644 index 0000000..46bb932 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/models/Hello.model @@ -0,0 +1,3 @@ +channel cio { + out r1(x1:Int,set(x2)) == x2 +} diff --git a/AlgebraicDataflowArchitectureModel/models/Hello2.model b/AlgebraicDataflowArchitectureModel/models/Hello2.model new file mode 100644 index 0000000..4815cf6 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/models/Hello2.model @@ -0,0 +1,3 @@ +channel cio { + out r1(x1:Int,set(x2:Int)) == x2:Int +} diff --git a/AlgebraicDataflowArchitectureModel/models/HelloWorld.model b/AlgebraicDataflowArchitectureModel/models/HelloWorld.model new file mode 100644 index 0000000..44aa310 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/models/HelloWorld.model @@ -0,0 +1,7 @@ +channel cio { + out r1(x1:Int,set(x2:Int)) == x2:Int +} +channel c2 { + in r1(x1:Int,update(x2:Int)) == x2:Int + out r2(y1:Int,update(x2:Int)) == (x2:Int+1) +} diff --git a/AlgebraicDataflowArchitectureModel/models/StockManagement2.model b/AlgebraicDataflowArchitectureModel/models/StockManagement2.model new file mode 100644 index 0000000..6ee866a --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/models/StockManagement2.model @@ -0,0 +1,13 @@ +init { + stock := nil + shortage := nil +} + +channel CIO_enter { + out deriver(s:Tuple, arrive(item:Str, num:Int)) == tuple(item, num, num) +} + +channel C3 { + in deriver(dr, update3(dr2)) == dr2 + out shipping(sp:Tuple, update3(dr2)) == tuple(fst(dr2), fst(snd(dr2))) +} diff --git a/AlgebraicDataflowArchitectureModel/models/Test.model b/AlgebraicDataflowArchitectureModel/models/Test.model new file mode 100644 index 0000000..a8a1348 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/models/Test.model @@ -0,0 +1,9 @@ +channel CIO { + out a(x:Int, set(n:Int)) == n +} + +channel C1 { + in a(x, update(y)) == y + out b(z, update(y)) == y + 1 + out c(v, update(y)) == v + y +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/src/Main.java b/AlgebraicDataflowArchitectureModel/src/Main.java index 119bdd3..54fdaf8 100644 --- a/AlgebraicDataflowArchitectureModel/src/Main.java +++ b/AlgebraicDataflowArchitectureModel/src/Main.java @@ -1,11 +1,11 @@ -import graphicalrefactor.views.GraphicalRefactor; +import application.ApplicationWindow; public class Main { public static void main(String[] args) { - GraphicalRefactor frame = new GraphicalRefactor(); + ApplicationWindow frame = new ApplicationWindow(); frame.setVisible(true); } diff --git a/AlgebraicDataflowArchitectureModel/src/application/ApplicationMenuBar.java b/AlgebraicDataflowArchitectureModel/src/application/ApplicationMenuBar.java new file mode 100644 index 0000000..38e2370 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/ApplicationMenuBar.java @@ -0,0 +1,94 @@ +package application; + +import javax.swing.JMenu; +import javax.swing.JMenuBar; + +import application.actions.CircleLayoutAction; +import application.actions.DAGLayoutAction; +import application.actions.DeleteAction; +import application.actions.ExitAction; +import application.actions.JavaPrototypeGenerateAction; +import application.actions.JerseyPrototypeGenerateAction; +import application.actions.NewChannelAction; +import application.actions.NewFormulaChannelAction; +import application.actions.NewIOChannelAction; +import application.actions.NewModelAction; +import application.actions.NewResourceAction; +import application.actions.OpenAction; +import application.actions.SaveAction; +import application.actions.SaveAsAction; +import application.actions.TreeLayoutAction; +import application.actions.ZoomInAction; +import application.actions.ZoomOutAction; +import application.editor.Editor; + +public class ApplicationMenuBar extends JMenuBar { + private static final long serialVersionUID = 4811536194182272888L; + + private ApplicationWindow applicationWindow = null; + + private NewResourceAction newResourceAction = null; + private NewChannelAction newChannelAction = null; + private NewIOChannelAction newIOChannelAction = null; + private NewFormulaChannelAction newFormulaChannelAction = null; + private DeleteAction deleteAction = null; + private JavaPrototypeGenerateAction javaPrototypeGenerateAction = null; + private JerseyPrototypeGenerateAction jerseyPrototypeGenerateAction = null; + private DAGLayoutAction dagLayoutAction = null; + private TreeLayoutAction treeLayoutAction = null; + private CircleLayoutAction circleLayoutAction = null; + + public ApplicationMenuBar(ApplicationWindow applicationWindow) { + this.applicationWindow = applicationWindow; + JMenu newMenu = new JMenu("New"); + + newMenu.add(new NewModelAction(applicationWindow)); + + newMenu.add(newResourceAction = new NewResourceAction(applicationWindow.getEditor())); + newMenu.add(newChannelAction = new NewChannelAction(applicationWindow.getEditor())); + newMenu.add(newIOChannelAction = new NewIOChannelAction(applicationWindow.getEditor())); + newMenu.add(newFormulaChannelAction = new NewFormulaChannelAction(applicationWindow.getEditor())); + + JMenu menu = null; + menu = add(new JMenu("File")); + menu.add(newMenu); + menu.add(new OpenAction(applicationWindow)); + menu.addSeparator(); + menu.add(new SaveAction(applicationWindow)); + menu.add(new SaveAsAction(applicationWindow)); + menu.addSeparator(); + menu.add(new ExitAction()); + + menu = add(new JMenu("Edit")); + menu.add(deleteAction = new DeleteAction(applicationWindow.getEditor())); + + + menu = add(new JMenu("Layout")); + menu.add(dagLayoutAction = new DAGLayoutAction(applicationWindow.getEditor())); + menu.add(treeLayoutAction = new TreeLayoutAction(applicationWindow.getEditor())); + menu.add(circleLayoutAction = new CircleLayoutAction(applicationWindow.getEditor())); + + menu = add(new JMenu("View")); + menu.add(new ZoomInAction(applicationWindow.getGraphComponent())); + menu.add(new ZoomOutAction(applicationWindow.getGraphComponent())); + + menu = add(new JMenu("Generate")); + menu.add(javaPrototypeGenerateAction = new JavaPrototypeGenerateAction(applicationWindow.getEditor())); + menu.add(jerseyPrototypeGenerateAction = new JerseyPrototypeGenerateAction(applicationWindow.getEditor())); + } + + public Editor getEditor() { + return applicationWindow.getEditor(); + } + + public void setEditor(Editor editor) { + newResourceAction.setEditor(editor); + newChannelAction.setEditor(editor); + newIOChannelAction.setEditor(editor); + deleteAction.setEditor(editor); + javaPrototypeGenerateAction.setEditor(editor); + jerseyPrototypeGenerateAction.setEditor(editor); + treeLayoutAction.setEditor(editor); + circleLayoutAction.setEditor(editor); + } +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java b/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java new file mode 100644 index 0000000..63324d0 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java @@ -0,0 +1,97 @@ +package application; + +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JFrame; + +import com.mxgraph.model.mxCell; +import com.mxgraph.model.mxGeometry; +import com.mxgraph.model.mxGraphModel; +import com.mxgraph.swing.mxGraphComponent; +import com.mxgraph.swing.handler.mxRubberband; +import com.mxgraph.swing.view.mxICellEditor; +import com.mxgraph.util.mxEvent; +import com.mxgraph.util.mxEventObject; +import com.mxgraph.util.mxEventSource.mxIEventListener; +import com.mxgraph.view.mxGraph; + +import application.editor.Editor; +import application.editor.DataTransferModelingCellEditor; + +public class ApplicationWindow extends JFrame { + private static final long serialVersionUID = -8690140317781055614L; + public static final String title = "Visual Modeling Tool"; + + private Editor editor = null; + private mxGraph graph = null; + private mxGraphComponent graphComponent = null; + + private ApplicationMenuBar menuBar = null; + + public ApplicationWindow() { + setTitle(title); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + this.graph = new mxGraph() { + public boolean isPort(Object cell) { + mxGeometry geo = getCellGeometry(cell); + + return (geo != null) ? geo.isRelative() : false; + } + + public boolean isCellFoldable(Object cell, boolean collapse) { + return false; + } + }; + + this.graphComponent = new mxGraphComponent(graph); + + this.editor = new Editor(graphComponent); + + graph.getModel().addListener(mxEvent.CHANGE, new mxIEventListener() { + public void invoke(Object sender, mxEventObject evt) { + List terminals = new ArrayList<>(); + mxCell cell = null; + for (Object change: ((List) evt.getProperties().get("changes"))) { + if (change instanceof mxGraphModel.mxTerminalChange) { + mxGraphModel.mxTerminalChange terminalChange = (mxGraphModel.mxTerminalChange) change; + cell = (mxCell) terminalChange.getCell(); + mxCell terminal = (mxCell) terminalChange.getTerminal(); + terminals.add(terminal); + } + } + if (terminals.size() == 2) { + if (!editor.connectEdge(cell, terminals.get(0), terminals.get(1))) { + graph.removeCells(new mxCell[] {cell}); + } + } + } + }); + getContentPane().add(graphComponent); + new mxRubberband(graphComponent); + graph.setAllowDanglingEdges(false); + graph.setCellsDisconnectable(true); + + menuBar = new ApplicationMenuBar(this); + setJMenuBar(menuBar); + setSize(870, 640); + } + + public mxGraph getGraph() { + return graph; + } + + public mxGraphComponent getGraphComponent() { + return graphComponent; + } + + public Editor getEditor() { + return editor; + } + + public void setEditor(Editor editor) { + this.editor = editor; + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/AbstractEditorAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/AbstractEditorAction.java new file mode 100644 index 0000000..8b09b17 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/AbstractEditorAction.java @@ -0,0 +1,23 @@ +package application.actions; + +import javax.swing.AbstractAction; +import javax.swing.Icon; + +import com.mxgraph.view.mxGraph; + +import application.editor.Editor; + +public abstract class AbstractEditorAction extends AbstractAction { + + protected Editor editor; + + public AbstractEditorAction(String name, Editor editor) { + super(name); + this.editor = editor; + } + + public void setEditor(Editor editor) { + this.editor = editor; + } + +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/AbstractSystemAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/AbstractSystemAction.java new file mode 100644 index 0000000..f734ae0 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/AbstractSystemAction.java @@ -0,0 +1,23 @@ +package application.actions; + +import java.awt.event.ActionEvent; + +import javax.swing.AbstractAction; + +import application.ApplicationWindow; +import application.editor.Editor; + +public abstract class AbstractSystemAction extends AbstractAction { + + protected ApplicationWindow frame; + + public AbstractSystemAction(String name, ApplicationWindow frame) { + super(name); + this.frame = frame; + } + + public void setFrame(ApplicationWindow frame) { + this.frame = frame; + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/AbstractViewerAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/AbstractViewerAction.java new file mode 100644 index 0000000..422c537 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/AbstractViewerAction.java @@ -0,0 +1,17 @@ +package application.actions; + +import java.awt.event.ActionEvent; + +import javax.swing.AbstractAction; + +import com.mxgraph.swing.mxGraphComponent; + +public abstract class AbstractViewerAction extends AbstractAction { + + protected mxGraphComponent graphComponent = null; + + public AbstractViewerAction(String name, mxGraphComponent graphComponent) { + super(name); + this.graphComponent = graphComponent; + } +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/CircleLayoutAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/CircleLayoutAction.java new file mode 100644 index 0000000..ba643bc --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/CircleLayoutAction.java @@ -0,0 +1,18 @@ +package application.actions; + +import java.awt.event.ActionEvent; + +import application.editor.Editor; + +public class CircleLayoutAction extends AbstractEditorAction { + + public CircleLayoutAction(Editor editor) { + super("Circle Layout", editor); + } + + @Override + public void actionPerformed(ActionEvent e) { + editor.setCircleLayout(); + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/DAGLayoutAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/DAGLayoutAction.java new file mode 100644 index 0000000..8dcc54f --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/DAGLayoutAction.java @@ -0,0 +1,18 @@ +package application.actions; + +import java.awt.event.ActionEvent; + +import application.editor.Editor; + +public class DAGLayoutAction extends AbstractEditorAction { + + public DAGLayoutAction(Editor editor) { + super("DAG Layout", editor); + } + + @Override + public void actionPerformed(ActionEvent e) { + editor.setDAGLayout(); + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/DeleteAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/DeleteAction.java new file mode 100644 index 0000000..23225f1 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/DeleteAction.java @@ -0,0 +1,23 @@ +package application.actions; + +import java.awt.event.ActionEvent; + +import application.editor.Editor; + +public class DeleteAction extends AbstractEditorAction { + + /** + * + */ + private static final long serialVersionUID = -4410145389391154784L; + + public DeleteAction(Editor editor) { + super("Delete", editor); + } + + @Override + public void actionPerformed(ActionEvent e) { + editor.delete(); + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/ExitAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/ExitAction.java new file mode 100644 index 0000000..4069533 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/ExitAction.java @@ -0,0 +1,22 @@ +package application.actions; + +import java.awt.event.ActionEvent; + +import javax.swing.AbstractAction; + +public class ExitAction extends AbstractAction { + /** + * + */ + private static final long serialVersionUID = -8733766417378036850L; + + public ExitAction() { + super("Exit"); + } + + @Override + public void actionPerformed(ActionEvent e) { + System.exit(0); + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/JavaPrototypeGenerateAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/JavaPrototypeGenerateAction.java new file mode 100644 index 0000000..28070d2 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/JavaPrototypeGenerateAction.java @@ -0,0 +1,89 @@ +package application.actions; + +import java.awt.event.ActionEvent; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +import javax.swing.JFileChooser; + +import algorithms.*; +import application.editor.Editor; +import code.ast.*; +import generators.DataTransferMethodAnalyzer; +import generators.JavaCodeGenerator; +import generators.JavaMethodBodyGenerator; +import models.dataConstraintModel.IdentifierTemplate; +import models.dataFlowModel.DataTransferModel; +import models.dataFlowModel.ModelExtension; +import models.dataFlowModel.DataFlowGraph; + +public class JavaPrototypeGenerateAction extends AbstractEditorAction { + /** + * + */ + private static final long serialVersionUID = -3694103632055735068L; + + private String lastDir = null; + + public JavaPrototypeGenerateAction(Editor editor) { + super("Generate Plain Java Prototype", editor); + } + + @Override + public void actionPerformed(ActionEvent e) { + DataFlowGraph graph = editor.getDataFlowGraph(); + if (graph != null) { + DataTransferModel model = editor.getModel(); + ModelExtension.extendModel(model); + TypeInference.infer(model); + DataTransferMethodAnalyzer.decideToStoreResourceStates(graph); + String fileName = editor.getCurFileName(); + if (fileName == null) fileName = "Main"; + String mainTypeName = fileName.split("\\.")[0]; + boolean exist = false; + for (IdentifierTemplate id: model.getIdentifierTemplates()) { + String resourceName = id.getResourceName().substring(0, 1).toUpperCase() + id.getResourceName().substring(1); + if (mainTypeName.equals(resourceName)) { + exist = true; + } + } + if (!exist) { + JavaCodeGenerator.setMainTypeName(mainTypeName); // use model's file name as the main type's name. + } else { + JavaCodeGenerator.resetMainTypeName(); // use the default main type's name. + } + editor.setCodes(JavaMethodBodyGenerator.doGenerate(graph, model, JavaCodeGenerator.doGenerate(graph, model))); + ModelExtension.recoverModel(model); + for (CompilationUnit file : editor.getCodes()) { + System.out.println(file); + } + + String wd = (lastDir != null) ? lastDir : System.getProperty("user.dir"); + JFileChooser fc = new JFileChooser(wd); + fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); + int rc = fc.showSaveDialog(null); + if (rc == JFileChooser.APPROVE_OPTION) { + lastDir = fc.getSelectedFile().getPath(); + for (CompilationUnit cu : editor.getCodes()) { + save(fc.getSelectedFile(), cu); + } + } + } + } + + private void save(File dir, CompilationUnit cu) { + File javaFile = new File(dir.getPath(), cu.getFileName()); + try { + BufferedWriter writer = new BufferedWriter(new FileWriter(javaFile)); + writer.write(cu.toString()); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/JerseyPrototypeGenerateAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/JerseyPrototypeGenerateAction.java new file mode 100644 index 0000000..b74075c --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/JerseyPrototypeGenerateAction.java @@ -0,0 +1,90 @@ +package application.actions; + +import java.awt.event.ActionEvent; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +import javax.swing.JFileChooser; + +import algorithms.*; +import application.editor.Editor; +import code.ast.*; +import generators.DataTransferMethodAnalyzer; +import generators.JerseyCodeGenerator; +import generators.JerseyMethodBodyGenerator; +import models.algebra.Type; +import models.dataConstraintModel.IdentifierTemplate; +import models.dataFlowModel.DataTransferModel; +import models.dataFlowModel.ModelExtension; +import models.dataFlowModel.DataFlowGraph; + +public class JerseyPrototypeGenerateAction extends AbstractEditorAction { + /** + * + */ + private static final long serialVersionUID = 1117065654665887436L; + + private String lastDir = null; + + public JerseyPrototypeGenerateAction(Editor editor) { + super("Generate JAX-RS Prototype", editor); + } + + @Override + public void actionPerformed(ActionEvent e) { + DataFlowGraph graph = editor.getDataFlowGraph(); + if (graph != null) { + DataTransferModel model = editor.getModel(); + ModelExtension.extendModel(model); + TypeInference.infer(model); + DataTransferMethodAnalyzer.decideToStoreResourceStates(graph); + String fileName = editor.getCurFileName(); + if (fileName == null) fileName = "Main"; + String mainTypeName = fileName.split("\\.")[0]; + boolean exist = false; + for (IdentifierTemplate id: model.getIdentifierTemplates()) { + String resourceName = id.getResourceName().substring(0, 1).toUpperCase() + id.getResourceName().substring(1); + if (mainTypeName.equals(resourceName)) { + exist = true; + } + } + if (!exist) { + JerseyCodeGenerator.setMainTypeName(mainTypeName); // use model's file name as the main type's name. + } else { + JerseyCodeGenerator.resetMainTypeName(); // use the default main type's name. + } + editor.setCodes(JerseyMethodBodyGenerator.doGenerate(graph, model, JerseyCodeGenerator.doGenerate(graph, model))); + ModelExtension.recoverModel(model); + for (CompilationUnit file : editor.getCodes()) { + System.out.println(file); + } + + String wd = (lastDir != null) ? lastDir : System.getProperty("user.dir"); + JFileChooser fc = new JFileChooser(wd); + fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); + int rc = fc.showSaveDialog(null); + if (rc == JFileChooser.APPROVE_OPTION) { + lastDir = fc.getSelectedFile().getPath(); + for (CompilationUnit cu : editor.getCodes()) { + save(fc.getSelectedFile(), cu); + } + } + } + } + + private void save(File dir, CompilationUnit cu) { + File javaFile = new File(dir.getPath(), cu.getFileName()); + try { + BufferedWriter writer = new BufferedWriter(new FileWriter(javaFile)); + writer.write(cu.toString()); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/NewChannelAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/NewChannelAction.java new file mode 100644 index 0000000..e8148f5 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/NewChannelAction.java @@ -0,0 +1,28 @@ +package application.actions; + +import java.awt.event.ActionEvent; + +import javax.swing.JOptionPane; + +import application.editor.Editor; +import models.dataFlowModel.DataTransferChannelGenerator; + +public class NewChannelAction extends AbstractEditorAction { + + /** + * + */ + private static final long serialVersionUID = 5979007029473101802L; + + public NewChannelAction(Editor editor) { + super("Channel...", editor); + } + + @Override + public void actionPerformed(ActionEvent e) { + String channelName = JOptionPane.showInputDialog("Channel Name:"); + if (channelName == null) return; + editor.addChannelGenerator(new DataTransferChannelGenerator(channelName)); + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/NewFormulaChannelAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/NewFormulaChannelAction.java new file mode 100644 index 0000000..4eb4afe --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/NewFormulaChannelAction.java @@ -0,0 +1,62 @@ +package application.actions; + +import java.awt.BorderLayout; +import java.awt.Container; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; + +import application.ApplicationWindow; +import application.editor.Editor; +import models.visualModel.FormulaChannelGenerator; + +public class NewFormulaChannelAction extends AbstractEditorAction implements ActionListener { + + /** + * + */ + private static final long serialVersionUID = 5345875219049178252L; + + public NewFormulaChannelAction(Editor editor) { + super("FormulaChannel...", editor); + } + + @Override + public void actionPerformed(ActionEvent e) { + JPanel panel = new JPanel(); + GridLayout layout = new GridLayout(2,2); + panel.setLayout(layout); + layout.setVgap(5); + layout.setHgap(20); + panel.add(new JLabel("Channel Name:")); + JTextField channelText = new JTextField(); + panel.add(channelText); + panel.add(new JLabel("Symbol:")); + JTextField symbolText = new JTextField(); + panel.add(symbolText); + + int r = JOptionPane.showConfirmDialog( + null, // �I�[�i�[�E�B���h�E + panel, // ���b�Z�[�W + "New Formula Channel", // �E�B���h�E�^�C�g�� + JOptionPane.OK_CANCEL_OPTION, // �I�v�V�����i�{�^���̎�ށj + JOptionPane.QUESTION_MESSAGE); // ���b�Z�[�W�^�C�v�i�A�C�R���̎�ށj + + String channelName = channelText.getText(); + String symbol = symbolText.getText(); + if(r == JOptionPane.OK_OPTION) { + editor.addFormulaChannelGenerator(new FormulaChannelGenerator(channelName, editor.getModel().getSymbol(symbol))); + } + } +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/NewIOChannelAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/NewIOChannelAction.java new file mode 100644 index 0000000..8d819d8 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/NewIOChannelAction.java @@ -0,0 +1,28 @@ +package application.actions; + +import java.awt.event.ActionEvent; + +import javax.swing.JOptionPane; + +import application.editor.Editor; +import models.dataFlowModel.DataTransferChannelGenerator; + +public class NewIOChannelAction extends AbstractEditorAction { + + /** + * + */ + private static final long serialVersionUID = -1657072017390171313L; + + public NewIOChannelAction(Editor editor) { + super("I/O Channel", editor); + } + + @Override + public void actionPerformed(ActionEvent e) { + String channelName = JOptionPane.showInputDialog("I/O Channel Name:"); + if (channelName == null) return; + editor.addIOChannelGenerator(new DataTransferChannelGenerator(channelName)); + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/NewModelAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/NewModelAction.java new file mode 100644 index 0000000..517f525 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/NewModelAction.java @@ -0,0 +1,24 @@ +package application.actions; + +import java.awt.event.ActionEvent; + +import application.ApplicationWindow; +import application.editor.Editor; + +public class NewModelAction extends AbstractSystemAction { + /** + * + */ + private static final long serialVersionUID = 8484493203589724589L; + + public NewModelAction(ApplicationWindow frame) { + super("Model", frame); + } + + @Override + public void actionPerformed(ActionEvent e) { + frame.getEditor().clear(); + frame.setTitle(frame.title); + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/NewResourceAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/NewResourceAction.java new file mode 100644 index 0000000..5c230f7 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/NewResourceAction.java @@ -0,0 +1,28 @@ +package application.actions; + +import java.awt.event.ActionEvent; + +import javax.swing.JOptionPane; + +import application.editor.Editor; +import models.dataConstraintModel.IdentifierTemplate; + +public class NewResourceAction extends AbstractEditorAction { + + /** + * + */ + private static final long serialVersionUID = -4439207504700741286L; + + public NewResourceAction(Editor editor) { + super("Resource...", editor); + } + + @Override + public void actionPerformed(ActionEvent e) { + String resName = JOptionPane.showInputDialog("Resourece Name:"); + if (resName == null) return; + editor.addIdentifierTemplate(new IdentifierTemplate(resName, 0)); + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/OpenAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/OpenAction.java new file mode 100644 index 0000000..d01c518 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/OpenAction.java @@ -0,0 +1,62 @@ +package application.actions; + +import java.awt.event.ActionEvent; +import java.io.File; + +import javax.swing.JFileChooser; +import javax.swing.filechooser.FileFilter; +import javax.swing.filechooser.FileNameExtensionFilter; + +import application.ApplicationWindow; +import application.editor.Editor; + +public class OpenAction extends AbstractSystemAction { + /** + * + */ + private static final long serialVersionUID = -8290761032629599683L; + + private String lastDir = null; + + public OpenAction(ApplicationWindow 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"); + + JFileChooser fc = new JFileChooser(wd); + + FileFilter model = new FileNameExtensionFilter("model","model"); + FileFilter dtram = new FileNameExtensionFilter("dtram", "dtram"); + + // Adds file filter for supported file format + FileFilter defaultFilter = new FileFilter() { + + public boolean accept(File file) { + String lcase = file.getName().toLowerCase(); + return lcase.endsWith(".model"); + } + + @Override + public String getDescription() { + return null; + } + }; + + fc.addChoosableFileFilter(defaultFilter); + fc.addChoosableFileFilter(model); + fc.addChoosableFileFilter(dtram); + int rc = fc.showDialog(null, "Open Model File"); + 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/application/actions/SaveAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/SaveAction.java new file mode 100644 index 0000000..0b41331 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/SaveAction.java @@ -0,0 +1,26 @@ +package application.actions; + +import java.awt.event.ActionEvent; + +import application.ApplicationWindow; +import application.editor.Editor; + +public class SaveAction extends AbstractSystemAction { + /** + * + */ + private static final long serialVersionUID = 5660460585305281982L; + + public SaveAction(ApplicationWindow frame) { + super("Save", frame); + } + + @Override + public void actionPerformed(ActionEvent e) { + Editor editor = frame.getEditor(); + if (editor != null && editor.getCurFileName() != null) { + editor.save(); + } + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/SaveAsAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/SaveAsAction.java new file mode 100644 index 0000000..1a38b08 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/SaveAsAction.java @@ -0,0 +1,79 @@ +package application.actions; + +import java.awt.event.ActionEvent; +import java.io.File; + +import javax.swing.AbstractAction; +import javax.swing.JFileChooser; +import javax.swing.filechooser.FileFilter; +import javax.swing.filechooser.FileNameExtensionFilter; + +import application.ApplicationWindow; +import application.editor.Editor; + +public class SaveAsAction extends AbstractSystemAction { + /** + * + */ + private static final long serialVersionUID = -2599502783032684084L; + + private String lastDir = null; + + public SaveAsAction(ApplicationWindow frame) { + super("Save As...", frame); + } + + @Override + public void actionPerformed(ActionEvent e) { + Editor editor = frame.getEditor(); + if (editor != null) { + String wd = (lastDir != null) ? lastDir : System.getProperty("user.dir"); + + JFileChooser fc = new JFileChooser(wd); + FileFilter model = new FileNameExtensionFilter("model","model"); + FileFilter dtram = new FileNameExtensionFilter("dtram", "dtram"); + + // Adds file filter for supported file format + FileFilter defaultFilter = new FileFilter() { + public boolean accept(File file) { + String lcase = file.getName().toLowerCase(); + return lcase.endsWith(".model"); + } + + @Override + public String getDescription() { + return null; + } + }; + + fc.addChoosableFileFilter(defaultFilter); + fc.addChoosableFileFilter(model); + fc.addChoosableFileFilter(dtram); + int rc = fc.showDialog(null, "Save Model File"); + + // choose a file extension from a dialog. + if (rc == JFileChooser.APPROVE_OPTION) { + + // if extension filter is filled, then attaching extension by choosing filter. + // but if it's not filled, then using default extension name. + String extension = ""; + if(fc.getFileFilter() instanceof FileNameExtensionFilter) { + FileNameExtensionFilter selectedFilter = (FileNameExtensionFilter)fc.getFileFilter(); + extension = "." + selectedFilter.getExtensions()[0].toString(); + } + + lastDir = fc.getSelectedFile().getParent(); + + String fileName = fc.getSelectedFile().getAbsolutePath() + extension; + + // checking file duplicates + if(! (fc.getSelectedFile().exists())) editor.setCurFilePath(fileName); + + // overwriting file + editor.save(); + frame.setTitle(ApplicationWindow.title + " - " + fc.getSelectedFile().getAbsolutePath()); + } + } + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/TreeLayoutAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/TreeLayoutAction.java new file mode 100644 index 0000000..c2324c8 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/TreeLayoutAction.java @@ -0,0 +1,18 @@ +package application.actions; + +import java.awt.event.ActionEvent; + +import application.editor.Editor; + +public class TreeLayoutAction extends AbstractEditorAction { + + public TreeLayoutAction(Editor editor) { + super("Tree Layout", editor); + } + + @Override + public void actionPerformed(ActionEvent e) { + editor.setTreeLayout(); + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/ZoomInAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/ZoomInAction.java new file mode 100644 index 0000000..d3b2c85 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/ZoomInAction.java @@ -0,0 +1,28 @@ +package application.actions; + +import java.awt.event.ActionEvent; + +import javax.swing.AbstractAction; +import javax.swing.JOptionPane; + +import com.mxgraph.swing.mxGraphComponent; +import com.mxgraph.util.mxResources; + +import application.editor.Editor; + +public class ZoomInAction extends AbstractViewerAction { + /** + * + */ + private static final long serialVersionUID = 6758532166946195926L; + + public ZoomInAction(mxGraphComponent graphComponent) { + super("Zoom In", graphComponent); + } + + @Override + public void actionPerformed(ActionEvent e) { + graphComponent.zoomIn(); + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/ZoomOutAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/ZoomOutAction.java new file mode 100644 index 0000000..032e8b2 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/ZoomOutAction.java @@ -0,0 +1,26 @@ +package application.actions; + +import java.awt.event.ActionEvent; + +import javax.swing.AbstractAction; + +import com.mxgraph.swing.mxGraphComponent; + +import application.editor.Editor; + +public class ZoomOutAction extends AbstractViewerAction { + /** + * + */ + private static final long serialVersionUID = 8657530769383486605L; + + public ZoomOutAction(mxGraphComponent graphComponent) { + super("Zoom Out", graphComponent); + } + + @Override + public void actionPerformed(ActionEvent e) { + graphComponent.zoomOut(); + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/DataTransferModelingCellEditor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/DataTransferModelingCellEditor.java new file mode 100644 index 0000000..d89a024 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/DataTransferModelingCellEditor.java @@ -0,0 +1,248 @@ +package application.editor; + +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Rectangle; +import java.util.EventObject; +import java.util.List; + +import javax.swing.BorderFactory; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextArea; +import javax.swing.JTextField; + +import com.mxgraph.model.mxCell; +import com.mxgraph.model.mxIGraphModel; +import com.mxgraph.swing.mxGraphComponent; +import com.mxgraph.swing.view.mxICellEditor; +import com.mxgraph.util.mxConstants; +import com.mxgraph.util.mxUtils; +import com.mxgraph.view.mxCellState; + +import models.algebra.Expression; +import models.dataFlowModel.DataTransferModel; +import models.dataFlowModel.DataTransferChannelGenerator; +import models.dataFlowModel.PushPullAttribute; +import models.dataFlowModel.PushPullValue; +import models.visualModel.FormulaChannelGenerator; +import parser.Parser; +import parser.Parser.TokenStream; +import parser.exceptions.ExpectedRightBracket; + +public class DataTransferModelingCellEditor implements mxICellEditor { + public int DEFAULT_MIN_WIDTH = 70; + public int DEFAULT_MIN_HEIGHT = 30; + public double DEFAULT_MINIMUM_EDITOR_SCALE = 1; + + protected double minimumEditorScale = DEFAULT_MINIMUM_EDITOR_SCALE; + protected int minimumWidth = DEFAULT_MIN_WIDTH; + protected int minimumHeight = DEFAULT_MIN_HEIGHT; + + private Object editingCell; + private EventObject trigger; + private JComboBox comboBox; + private mxGraphComponent graphComponent; + private Editor editor; + + public DataTransferModelingCellEditor(mxGraphComponent graphComponent, Editor editor) { + this.graphComponent = graphComponent; + this.editor = editor; + } + + @Override + public Object getEditingCell() { + return editingCell; + } + + @Override + public void startEditing(Object cell, EventObject evt) { + if (editingCell != null) { + stopEditing(true); + } + + if (!graphComponent.getGraph().getModel().isEdge(cell)) { + DataTransferModel model = editor.getModel(); + DataTransferChannelGenerator ch = (DataTransferChannelGenerator) model.getChannelGenerator((String) ((mxCell) cell).getValue()); + if (ch == null) { + ch = (DataTransferChannelGenerator) model.getIOChannelGenerator((String) ((mxCell) cell).getValue()); + if(ch == null) { + //resource + return; + } + } + + if(ch instanceof FormulaChannelGenerator) { + + JPanel panel = new JPanel(); + JLabel label1 = new JLabel("Formula: "); + JLabel label2 = new JLabel("Source: "); + GridBagLayout layout = new GridBagLayout(); + panel.setLayout(layout); + GridBagConstraints gbc = new GridBagConstraints(); + + gbc.gridx = 0; + gbc.gridy = 0; + layout.setConstraints(label1, gbc); + panel.add(label1); + + gbc.gridx = 1; + gbc.gridy = 0; + JTextField formulaText = new JTextField(((FormulaChannelGenerator) ch).getFormula(),15); + layout.setConstraints(formulaText, gbc); + panel.add(formulaText); + + gbc.gridx = 0; + gbc.gridy = 1; + layout.setConstraints(label2, gbc); + panel.add(label2); + + gbc.gridx = 1; + gbc.gridy = 1; + JTextArea textArea = new JTextArea(ch.getSourceText(),7,15); + textArea.setEditable(false); + layout.setConstraints(textArea, gbc); + panel.add(textArea); + + int r = JOptionPane.showConfirmDialog( + null, // owner window + panel, // message + "Edit Formula Channel", // window's title + JOptionPane.OK_CANCEL_OPTION, // option (button types) + JOptionPane.QUESTION_MESSAGE); // message type (icon types) + if(r == JOptionPane.OK_OPTION) { + TokenStream stream = new Parser.TokenStream(); + Parser parser = new Parser(stream); + + String formula = formulaText.getText(); + stream.addLine(formula.split(Parser.EQUALS)[1]); + + try { + Expression exp = parser.parseTerm(stream, editor.getModel()); + ((FormulaChannelGenerator) ch).setFormula(formula); + ((FormulaChannelGenerator) ch).setFormulaTerm(exp); + } catch (ExpectedRightBracket e) { + e.printStackTrace(); + } + } + }else { + JPanel panel = new JPanel(); + JTextArea textArea = new JTextArea(ch.getSourceText(), 10, 20); + panel.add(textArea); + // JEditorPane panel = new JEditorPane("text/plain", ch.toString()); + // panel.setEditable(true); + int ret = JOptionPane.showConfirmDialog(null, panel, "Channel Code", JOptionPane.OK_CANCEL_OPTION); + if (ret == JOptionPane.OK_OPTION) { + editor.setChannelCode(ch, textArea.getText()); + } + } + return; + } + + mxCellState state = graphComponent.getGraph().getView().getState(cell); + if (state != null && state.getLabel() != null && !state.getLabel().equals("")) { + editingCell = cell; + trigger = evt; + + double scale = Math.max(minimumEditorScale, graphComponent.getGraph().getView().getScale()); + Object value = graphComponent.getGraph().getModel().getValue(cell); + if (value != null && value instanceof PushPullAttribute) { + PushPullAttribute attr = (PushPullAttribute) value; + comboBox = new JComboBox<>(attr.getOptionStrings()); + comboBox.setBorder(BorderFactory.createEmptyBorder()); + comboBox.setOpaque(false); + comboBox.setBounds(getEditorBounds(state, scale)); + comboBox.setVisible(true); + graphComponent.getGraphControl().add(comboBox, 0); + comboBox.updateUI(); + } + } + } + + @Override + public void stopEditing(boolean cancel) { + if (editingCell != null) { + comboBox.transferFocusUpCycle(); + Object cell = editingCell; + editingCell = null; + if (!cancel) { + EventObject trig = trigger; + trigger = null; + Object value = graphComponent.getGraph().getModel().getValue(cell); + if (value != null && value instanceof PushPullAttribute) { + PushPullAttribute attr = (PushPullAttribute) value; + List options = attr.getOptions(); + PushPullValue selected = null; + for (PushPullValue option: options) { + if (option.toString().equals(getCurrentValue())) { + selected = option; + break; + } + } + if (selected != null) { + options.remove(selected); + options.add(0, selected); + } + graphComponent.labelChanged(cell, attr, trig); + } + } else { + mxCellState state = graphComponent.getGraph().getView().getState(cell); + graphComponent.redraw(state); + } + + if (comboBox.getParent() != null) { + comboBox.setVisible(false); + comboBox.getParent().remove(comboBox); + } + + graphComponent.requestFocusInWindow(); + } + } + + public String getCurrentValue() { + return (String) comboBox.getSelectedItem(); + } + + /** + * Returns the bounds to be used for the editor. + */ + public Rectangle getEditorBounds(mxCellState state, double scale) { + mxIGraphModel model = state.getView().getGraph().getModel(); + Rectangle bounds = null; + + bounds = state.getLabelBounds().getRectangle(); + bounds.height += 10; + + // Applies the horizontal and vertical label positions + if (model.isVertex(state.getCell())) { + String horizontal = mxUtils.getString(state.getStyle(), mxConstants.STYLE_LABEL_POSITION, mxConstants.ALIGN_CENTER); + + if (horizontal.equals(mxConstants.ALIGN_LEFT)) { + bounds.x -= state.getWidth(); + } else if (horizontal.equals(mxConstants.ALIGN_RIGHT)) { + bounds.x += state.getWidth(); + } + + String vertical = mxUtils.getString(state.getStyle(), + mxConstants.STYLE_VERTICAL_LABEL_POSITION, + mxConstants.ALIGN_MIDDLE); + + if (vertical.equals(mxConstants.ALIGN_TOP)) { + bounds.y -= state.getHeight(); + } else if (vertical.equals(mxConstants.ALIGN_BOTTOM)) { + bounds.y += state.getHeight(); + } + } + + bounds.setSize( + (int) Math.max(bounds.getWidth(), + Math.round(minimumWidth * scale)), + (int) Math.max(bounds.getHeight(), + Math.round(minimumHeight * scale))); + + return bounds; + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java new file mode 100644 index 0000000..e7c0fa2 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java @@ -0,0 +1,671 @@ +package application.editor; + +import java.io.BufferedReader; +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.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import com.mxgraph.layout.mxCircleLayout; +import com.mxgraph.layout.mxCompactTreeLayout; +import com.mxgraph.model.mxCell; +import com.mxgraph.model.mxGeometry; +import com.mxgraph.model.mxGraphModel; +import com.mxgraph.model.mxIGraphModel; +import com.mxgraph.swing.mxGraphComponent; +import com.mxgraph.util.mxConstants; +import com.mxgraph.util.mxPoint; +import com.mxgraph.view.mxCellState; +import com.mxgraph.util.mxRectangle; +import com.mxgraph.view.mxGraph; +import com.mxgraph.view.mxGraphView; + +import algorithms.DataTransferModelAnalyzer; +import algorithms.Validation; +import application.layouts.*; +import code.ast.CompilationUnit; +import models.Edge; +import models.EdgeAttribute; +import models.Node; +import models.dataConstraintModel.ChannelGenerator; +import models.dataConstraintModel.ChannelMember; +import models.dataConstraintModel.IdentifierTemplate; +import models.dataFlowModel.DataTransferModel; +import models.dataFlowModel.DataTransferChannelGenerator; +import models.dataFlowModel.PushPullAttribute; +import models.dataFlowModel.DataFlowEdge; +import models.dataFlowModel.DataFlowGraph; +import models.dataFlowModel.ResourceNode; +import models.visualModel.FormulaChannelGenerator; +import parser.Parser; +import parser.Parser.TokenStream; +import parser.exceptions.ExpectedAssignment; +import parser.exceptions.ExpectedChannel; +import parser.exceptions.ExpectedChannelName; +import parser.exceptions.ExpectedEquals; +import parser.exceptions.ExpectedFormulaChannel; +import parser.exceptions.ExpectedGeometry; +import parser.exceptions.ExpectedInOrOutOrRefKeyword; +import parser.exceptions.ExpectedIoChannel; +import parser.exceptions.ExpectedLeftCurlyBracket; +import parser.exceptions.ExpectedModel; +import parser.exceptions.ExpectedNode; +import parser.exceptions.ExpectedRHSExpression; +import parser.exceptions.ExpectedResource; +import parser.exceptions.ExpectedRightBracket; +import parser.exceptions.ExpectedStateTransition; +import parser.exceptions.WrongLHSExpression; +import parser.exceptions.WrongRHSExpression; +import parser.ParserDTRAM; + +public class Editor { + final int PORT_DIAMETER = 8; + final int PORT_RADIUS = PORT_DIAMETER / 2; + + protected DataTransferModel model = null; + protected mxGraph graph = null; + private mxGraphComponent graphComponent = null; + + protected DataFlowGraph dataFlowGraph = null; + + protected String curFileName = null; + protected String curFilePath = null; + protected ArrayList codes = null; + + public Editor(mxGraphComponent graphComponent) { + this.graphComponent = graphComponent; + this.graph = graphComponent.getGraph(); + + graphComponent.setCellEditor(new DataTransferModelingCellEditor(graphComponent, this)); + } + + public mxGraph getGraph() { + return graph; + } + + public mxGraphComponent getGraphComponent() { + return this.graphComponent; + } + + public DataTransferModel getModel() { + if (model == null) { + model = new DataTransferModel(); + } + return model; + } + + public DataFlowGraph getDataFlowGraph() { + if (dataFlowGraph == null) { + analyzeDataTransferModel(getModel()); + } + return dataFlowGraph; + } + + public DataFlowGraph analyzeDataTransferModel(DataTransferModel model) { + DataFlowGraph flowGraph = DataTransferModelAnalyzer.createDataFlowGraphWithStateStoringAttribute(model); + dataFlowGraph = DataTransferModelAnalyzer.annotateWithSelectableDataTransferAttiribute(flowGraph); + updateEdgeAttiributes(dataFlowGraph); + return dataFlowGraph; + } + + public void resetDataFlowGraph() { + dataFlowGraph = null; + } + + public void setDataFlowGraph(DataFlowGraph dataFlowGraph) { + this.dataFlowGraph = dataFlowGraph; + } + + public ArrayList getCodes() { + return codes; + } + + public void setCodes(ArrayList codes) { + this.codes = codes; + } + + public String getCurFileName() { + return curFileName; + } + + public String getCurFilePath() { + return curFilePath; + } + + public void setCurFilePath(String curFilePath) { + this.curFilePath = curFilePath; + this.curFileName = new File(curFilePath).getName(); + } + + public void clear() { + model = null; + ((mxGraphModel) graph.getModel()).clear(); + dataFlowGraph = null; + curFilePath = null; + curFileName = null; + codes = null; + } + + /** + * Open a given file, parse the file, construct a DataFlowModel and a mxGraph + * @param file given file + * @return a constructed DataFlowModel + */ + public DataTransferModel open(File file) { + try { + + String extension =""; + if(file != null && file.exists()) { + // get a file's name + String name = file.getName(); + + // get a file's extension + extension = name.substring(name.lastIndexOf(".")); + } + if(extension.contains(".model")) { + openModel(file); + } else { + ParserDTRAM parserDTRAM = new ParserDTRAM(new BufferedReader(new FileReader(file))); + try { + model = parserDTRAM.doParseModel(); + graph = constructGraph(model); + parserDTRAM.doParseGeometry(graph); + curFilePath = file.getAbsolutePath(); + curFileName = file.getName(); + if (!Validation.checkUpdateConflict(model)) return null; + analyzeDataTransferModel(model); + return model; + } catch (ExpectedChannel | ExpectedChannelName | ExpectedLeftCurlyBracket | ExpectedInOrOutOrRefKeyword + | ExpectedStateTransition | ExpectedEquals | ExpectedRHSExpression | WrongLHSExpression + | WrongRHSExpression | ExpectedRightBracket | ExpectedAssignment | ExpectedModel | ExpectedGeometry | ExpectedNode | ExpectedResource | ExpectedFormulaChannel | ExpectedIoChannel e) { + e.printStackTrace(); + } + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + return null; + } + + public DataTransferModel openModel(File file) { + try { + + Parser parser = new Parser(new BufferedReader(new FileReader(file))); + + try { + model = parser.doParse(); + curFilePath = file.getAbsolutePath(); + curFileName = file.getName(); + if (!Validation.checkUpdateConflict(model)) return null; + graph = constructGraph(model); + analyzeDataTransferModel(model); + return model; + } catch (ExpectedChannel | ExpectedChannelName | ExpectedLeftCurlyBracket | ExpectedInOrOutOrRefKeyword + | ExpectedStateTransition | ExpectedEquals | ExpectedRHSExpression | WrongLHSExpression + | WrongRHSExpression | ExpectedRightBracket | ExpectedAssignment e) { + e.printStackTrace(); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + return null; + } + + /**-------------------------------------------------------------------------------- + * save + /**-------------------------------------------------------------------------------- + * + */ + public void save() { + if (curFilePath != null) { + try { + File file = new File(curFilePath); + String extension = ""; + if(file != null && file.exists()) { + // get a file's name + String name = file.getName(); + + // get a file's extension + extension = name.substring(name.lastIndexOf(".")); + } + if(extension.contains(".model")) { + saveModel(file); + } else { + FileWriter filewriter = new FileWriter(file); + filewriter.write(toOutputString()); + filewriter.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + public void saveModel(File file) { + if (curFilePath != null) { + try { + FileWriter filewriter = new FileWriter(file); + filewriter.write(model.getSourceText()); + filewriter.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + /**-------------------------------------------------------------------------------- + * get writing texts "dtram" file information is written. + * + * @return formatted "dtram" info texts. + */ + protected String toOutputString() { + String fileString = ""; + + fileString += "model {\n"; + fileString += this.model.getSourceText(); + fileString += "}\n"; + + fileString += "geometry {\n"; + + Object root = graph.getDefaultParent(); + for (int i = 0; i < graph.getModel().getChildCount(root); i++) { + Object cell = graph.getModel().getChildAt(root, i); + if (graph.getModel().isVertex(cell)) { + mxGraphView view = graph.getView(); + mxCellState state = view.getState(cell); + int x = (int) state.getX(); + int y = (int) state.getY(); + int w = (int) state.getWidth(); + int h = (int) state.getHeight(); + + for(ChannelGenerator ch: model.getChannelGenerators()) { + if(ch instanceof FormulaChannelGenerator && state.getLabel().equals(ch.getChannelName())) { + fileString += "\tnode fc " + state.getLabel() + ":" + x + "," + y + "," + w + "," + h+"\n"; + } else if(ch instanceof ChannelGenerator && state.getLabel().equals(ch.getChannelName())) { + fileString +="\tnode c " + state.getLabel() + ":" + x + "," + y + "," + w + "," + h+"\n"; + } + } + + for (IdentifierTemplate res: model.getIdentifierTemplates()){ + if(res instanceof IdentifierTemplate && state.getLabel().equals(res.getResourceName())) + fileString += "\tnode r " + state.getLabel() + ":" + x + "," + y + "," + w + "," + h + "\n"; + } + + for (ChannelGenerator ioC: model.getIOChannelGenerators()) { + if(ioC instanceof ChannelGenerator && state.getLabel().equals(ioC.getChannelName())) { + fileString += "\tnode ioc " + state.getLabel() + ":" + x + "," + y + "," + w + "," + h + "\n"; + } + } + } + } + fileString += "}\n"; + + return fileString; + } + + /** + * Construct a mxGraph from DataFlowModel and DataFlowModel + * @param model + * @param dataFlowGraph + * @return constructed mxGraph + */ + public mxGraph constructGraph(DataTransferModel model) { + ((mxGraphModel) graph.getModel()).clear(); + Object parent = graph.getDefaultParent(); + graph.getModel().beginUpdate(); + try { + mxGeometry geo1 = new mxGeometry(0, 0.5, PORT_DIAMETER, PORT_DIAMETER); + geo1.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS)); + geo1.setRelative(true); + + mxGeometry geo2 = new mxGeometry(1.0, 0.5, PORT_DIAMETER, PORT_DIAMETER); + geo2.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS)); + geo2.setRelative(true); + + Map channelsIn = new HashMap<>(); + Map channelsOut = new HashMap<>(); + Map resources = new HashMap<>(); + + // create channel vertices + for (ChannelGenerator c: model.getChannelGenerators()) { + DataTransferChannelGenerator channelGen = (DataTransferChannelGenerator) c; + if (channelsIn.get(channelGen) == null || channelsOut.get(channelGen) == null) { + Object channel = graph.insertVertex(parent, null, channelGen.getChannelName(), 150, 20, 30, 30); // insert a channel as a vertex + mxCell port_in = new mxCell(null, geo1, "shape=ellipse;perimter=ellipsePerimeter"); + port_in.setVertex(true); + graph.addCell(port_in, channel); // insert the input port of a channel + mxCell port_out = new mxCell(null, geo2, "shape=ellipse;perimter=ellipsePerimeter"); + port_out.setVertex(true); + graph.addCell(port_out, channel); // insert the output port of a channel + channelsIn.put(channelGen, port_in); + channelsOut.put(channelGen, port_out); + } + } + + // create resource vertices + for (IdentifierTemplate res: model.getIdentifierTemplates()) { + Object resource = graph.insertVertex(parent, null, + res.getResourceName(), 20, 20, 80, 30, + "shape=ellipse;perimeter=ellipsePerimeter"); // insert a resource as a vertex + resources.put(res, resource); + } + + // add input, output and reference edges + for (ChannelGenerator ch: model.getChannelGenerators()) { + DataTransferChannelGenerator channelGen = (DataTransferChannelGenerator) ch; + // input edge + for (IdentifierTemplate srcRes: channelGen.getInputIdentifierTemplates()) { + graph.insertEdge(parent, null, new SrcDstAttribute(srcRes, channelGen), resources.get(srcRes), channelsIn.get(channelGen), "movable=false"); + } + // output edge + for (IdentifierTemplate dstRes: channelGen.getOutputIdentifierTemplates()) { + graph.insertEdge(parent, null, new SrcDstAttribute(channelGen, dstRes), channelsOut.get(channelGen), resources.get(dstRes), "movable=false"); + } + // reference edges + for (IdentifierTemplate refRes: channelGen.getReferenceIdentifierTemplates()) { + graph.insertEdge(parent, null, null, resources.get(refRes), channelsIn.get(channelGen), "dashed=true;movable=false"); + } + } + + for (ChannelGenerator ioChannelGen: model.getIOChannelGenerators()) { + if (channelsOut.get(ioChannelGen) == null) { + Object channel = graph.insertVertex(parent, null, ioChannelGen.getChannelName(), 150, 20, 30, 30); // insert an I/O channel as a vertex + mxCell port_out = new mxCell(null, geo2, "shape=ellipse;perimter=ellipsePerimeter"); + port_out.setVertex(true); + graph.addCell(port_out, channel); // insert the output port of a channel + channelsOut.put((DataTransferChannelGenerator) ioChannelGen, port_out); + for (IdentifierTemplate outRes: ((DataTransferChannelGenerator) ioChannelGen).getOutputIdentifierTemplates()) { + graph.insertEdge(parent, null, null, port_out, resources.get(outRes), "movable=false"); + } + } + } + } finally { + graph.getModel().endUpdate(); + } + setTreeLayout(); + + return graph; + } + + public void setDAGLayout() { + Object parent = graph.getDefaultParent(); + graph.getModel().beginUpdate(); + try { + DAGLayout ctl = new DAGLayout(graph); + ctl.execute(parent); + } finally { + graph.getModel().endUpdate(); + } + } + + public void updateEdgeAttiributes(DataFlowGraph dataFlowGraph) { + Object parent = graph.getDefaultParent(); + graph.getModel().beginUpdate(); + try { + // add input, output and reference edges + for (Edge e : dataFlowGraph.getEdges()) { + if (e instanceof DataFlowEdge) { + DataFlowEdge dataFlow = (DataFlowEdge) e; + DataTransferChannelGenerator channelGen = dataFlow.getChannelGenerator(); + ResourceNode srcRes = (ResourceNode) dataFlow.getSource(); + // input edge + for (Object edge: graph.getChildEdges(parent)) { + mxCell edgeCell = (mxCell) edge; + if (edgeCell.getValue() instanceof SrcDstAttribute) { + SrcDstAttribute edgeAttr = (SrcDstAttribute) edgeCell.getValue(); + if (edgeAttr.getSrouce() == srcRes.getIdentifierTemplate() && edgeAttr.getDestination() == channelGen) { + edgeCell.setValue(dataFlow.getAttribute()); + break; + } + } + } + } + } + } finally { + graph.getModel().endUpdate(); + } + graph.refresh(); + } + + public void setTreeLayout() { + Object parent = graph.getDefaultParent(); + graph.getModel().beginUpdate(); + try { + mxCompactTreeLayout ctl = new mxCompactTreeLayout(graph); + ctl.setLevelDistance(100); + // ctl.setHorizontal(false); + ctl.setEdgeRouting(false); + ctl.execute(parent); + } finally { + graph.getModel().endUpdate(); + } + } + + public void setCircleLayout() { + Object parent = graph.getDefaultParent(); + graph.getModel().beginUpdate(); + try { + mxCircleLayout ctl = new mxCircleLayout(graph); + ctl.execute(parent); + } finally { + graph.getModel().endUpdate(); + } + } + + public void addIdentifierTemplate(IdentifierTemplate res) { + getModel().addIdentifierTemplate(res); + resetDataFlowGraph(); + graph.getModel().beginUpdate(); + Object parent = graph.getDefaultParent(); + try { + graph.insertVertex(parent, null, res.getResourceName(), 20, 20, 80, 30, + "shape=ellipse;perimeter=ellipsePerimeter"); // insert a resource as a vertex + } finally { + graph.getModel().endUpdate(); + } + } + + public void addChannelGenerator(DataTransferChannelGenerator channelGen) { + getModel().addChannelGenerator(channelGen); + resetDataFlowGraph(); + graph.getModel().beginUpdate(); + Object parent = graph.getDefaultParent(); + try { + mxGeometry geo1 = new mxGeometry(0, 0.5, PORT_DIAMETER, PORT_DIAMETER); + geo1.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS)); + geo1.setRelative(true); + + mxGeometry geo2 = new mxGeometry(1.0, 0.5, PORT_DIAMETER, PORT_DIAMETER); + geo2.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS)); + geo2.setRelative(true); + + Object channel = graph.insertVertex(parent, null, channelGen.getChannelName(), 150, 20, 30, 30); // insert a channel as a vertex + mxCell port_in = new mxCell(null, geo1, "shape=ellipse;perimter=ellipsePerimeter"); + port_in.setVertex(true); + graph.addCell(port_in, channel); // insert the input port of a channel + mxCell port_out = new mxCell(null, geo2, "shape=ellipse;perimter=ellipsePerimeter"); + port_out.setVertex(true); + graph.addCell(port_out, channel); // insert the output port of a channel + } finally { + graph.getModel().endUpdate(); + } + } + + public void addIOChannelGenerator(DataTransferChannelGenerator ioChannelGen) { + getModel().addIOChannelGenerator(ioChannelGen); + resetDataFlowGraph(); + graph.getModel().beginUpdate(); + Object parent = graph.getDefaultParent(); + try { + mxGeometry geo2 = new mxGeometry(1.0, 0.5, PORT_DIAMETER, PORT_DIAMETER); + geo2.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS)); + geo2.setRelative(true); + + Object channel = graph.insertVertex(parent, null, ioChannelGen.getChannelName(), 150, 20, 30, 30); // insert an I/O channel as a vertex + mxCell port_out = new mxCell(null, geo2, "shape=ellipse;perimter=ellipsePerimeter"); + port_out.setVertex(true); + graph.addCell(port_out, channel); // insert the output port of a channel + } finally { + graph.getModel().endUpdate(); + } + } + + public void addFormulaChannelGenerator(FormulaChannelGenerator formulaChannelGen) { + getModel().addChannelGenerator(formulaChannelGen); + resetDataFlowGraph(); + graph.getModel().beginUpdate(); + Object parent = graph.getDefaultParent(); + try { + mxGeometry geo1 = new mxGeometry(0, 0.5, PORT_DIAMETER, PORT_DIAMETER); + geo1.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS)); + geo1.setRelative(true); + + mxGeometry geo2 = new mxGeometry(1.0, 0.5, PORT_DIAMETER, PORT_DIAMETER); + geo2.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS)); + geo2.setRelative(true); + + Object channel = graph.insertVertex(parent, null, formulaChannelGen.getChannelName(), 150, 20, 30, 30); // insert a channel as a vertex + mxCell port_in = new mxCell(null, geo1, "shape=ellipse;perimter=ellipsePerimeter"); + port_in.setVertex(true); + graph.addCell(port_in, channel); // insert the input port of a channel + mxCell port_out = new mxCell(null, geo2, "shape=ellipse;perimter=ellipsePerimeter"); + port_out.setVertex(true); + graph.addCell(port_out, channel); // insert the output port of a channel + } finally { + graph.getModel().endUpdate(); + } + } + + public boolean connectEdge(mxCell edge, mxCell src, mxCell dst) { + DataTransferModel model = getModel(); + ChannelGenerator srcCh = model.getChannelGenerator((String) src.getValue()); + if (srcCh == null) { + srcCh = model.getIOChannelGenerator((String) src.getValue()); + if (srcCh == null) { + IdentifierTemplate srcRes = model.getIdentifierTemplate((String) src.getValue()); + ChannelGenerator dstCh = model.getChannelGenerator((String) dst.getValue()); + if (srcRes == null || dstCh == null) return false; + // resource to channel edge + ChannelMember srcCm = new ChannelMember(srcRes); + ((DataTransferChannelGenerator ) dstCh).addChannelMemberAsInput(srcCm); + edge.setValue(new SrcDstAttribute(srcRes, dstCh)); + resetDataFlowGraph(); + return true; + } + } + IdentifierTemplate dstRes = model.getIdentifierTemplate((String) dst.getValue()); + if (dstRes == null) return false; + // channel to resource edge + ChannelMember dstCm = new ChannelMember(dstRes); + ((DataTransferChannelGenerator) srcCh).addChannelMemberAsOutput(dstCm); + edge.setValue(new SrcDstAttribute(srcCh, dstRes)); + resetDataFlowGraph(); + return true; + } + + public void delete() { + for (Object obj: graph.getSelectionCells()) { + mxCell cell = (mxCell) obj; + if (cell.isEdge()) { + String srcName = (String) cell.getSource().getValue(); + String dstName = (String) cell.getTarget().getValue(); + if (model.getIdentifierTemplate(srcName) != null) { + // resource to channel edge + ChannelGenerator ch = model.getChannelGenerator(dstName); + ch.removeChannelMember(model.getIdentifierTemplate(srcName)); + } else if (model.getIdentifierTemplate(dstName) != null) { + // channel to resource edge + ChannelGenerator ch = model.getChannelGenerator(srcName); + if (ch == null) { + ch = model.getIOChannelGenerator(srcName); + } + ch.removeChannelMember(model.getIdentifierTemplate(dstName)); + } + } else if (cell.isVertex()) { + String name = (String) cell.getValue(); + if (model.getChannelGenerator(name) != null) { + model.removeChannelGenerator(name); + } else if (model.getIOChannelGenerator(name) != null) { + model.removeIOChannelGenerator(name); + } else if (model.getIdentifierTemplate(name) != null) { + model.removeIdentifierTemplate(name); + } + } + } + graph.removeCells(graph.getSelectionCells()); + resetDataFlowGraph(); + } + + public void setChannelCode(DataTransferChannelGenerator ch, String code) { + ch.setSourceText(code); + TokenStream stream = new Parser.TokenStream(); + Parser parser = new Parser(stream); + + for (String line: code.split("\n")) { + stream.addLine(line); + } + try { + DataTransferChannelGenerator ch2 = parser.parseChannel(getModel()); + for (ChannelMember chm2: ch2.getInputChannelMembers()) { + for (ChannelMember chm: ch.getInputChannelMembers()) { + if (chm2.getIdentifierTemplate() == chm.getIdentifierTemplate()) { + chm.setStateTransition(chm2.getStateTransition()); + break; + } + } + } + for (ChannelMember chm2: ch2.getOutputChannelMembers()) { + for (ChannelMember chm: ch.getOutputChannelMembers()) { + if (chm2.getIdentifierTemplate() == chm.getIdentifierTemplate()) { + chm.setStateTransition(chm2.getStateTransition()); + break; + } + } + } + for (ChannelMember chm2: ch2.getReferenceChannelMembers()) { + for (ChannelMember chm: ch.getReferenceChannelMembers()) { + if (chm2.getIdentifierTemplate() == chm.getIdentifierTemplate()) { + chm.setStateTransition(chm2.getStateTransition()); + break; + } + } + } + resetDataFlowGraph(); + } catch (ExpectedRightBracket | ExpectedChannel | ExpectedChannelName | ExpectedLeftCurlyBracket + | ExpectedInOrOutOrRefKeyword | ExpectedStateTransition | ExpectedEquals | ExpectedRHSExpression + | WrongLHSExpression | WrongRHSExpression | ExpectedAssignment e) { + e.printStackTrace(); + } + } + + private class SrcDstAttribute extends EdgeAttribute { + private Object src; + private Object dst; + + public SrcDstAttribute(Object src, Object dst) { + this.src = src; + this.dst = dst; + } + + public Object getSrouce() { + return src; + } + + public Object getDestination() { + return dst; + } + + public String toString() { + return ""; + } + } +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/layouts/DAGLayout.java b/AlgebraicDataflowArchitectureModel/src/application/layouts/DAGLayout.java new file mode 100644 index 0000000..d493d10 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/layouts/DAGLayout.java @@ -0,0 +1,143 @@ +package application.layouts; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import com.mxgraph.layout.mxGraphLayout; +import com.mxgraph.model.mxCell; +import com.mxgraph.model.mxGeometry; +import com.mxgraph.model.mxIGraphModel; +import com.mxgraph.view.mxCellState; +import com.mxgraph.view.mxGraph; +import com.mxgraph.view.mxGraphView; + +public class DAGLayout extends mxGraphLayout { + + public DAGLayout(mxGraph graph) { + super(graph); + } + + public void execute(Object parent) { + mxIGraphModel model = graph.getModel(); + + model.beginUpdate(); + try { + List> map = new ArrayList>(); + List moved = new ArrayList<>(); + + for (int i = 0; i < model.getChildCount(parent); i++) { + + mxCell cell = (mxCell) model.getChildAt(parent, i); + + if (model.isVertex(cell)) { + mxGraphView view = graph.getView(); + mxCellState state = view.getState(cell); + + if (!"ellipse".equals(state.getStyle().get("shape")) && (cell.getEdgeCount() == 1) && !"true".equals(state.getStyle().get("dashed"))) { + List newline = new ArrayList(); + map.add(newline); + lines(map, cell); + } + } + } + + sort(map, 0, false); + + // layout + int count; + int skip = 0; + mxGraphView view = graph.getView(); + for (int i = 0; i < map.size(); i++) { + count = 0; + for (int j = 0; j < map.get(i).size(); j++) { + mxGeometry geom = (mxGeometry) map.get(i).get(j).getGeometry().clone(); + mxCellState state = view.getState(map.get(i).get(j)); + if (checkmoved(moved, map.get(i).get(j))) { + if ("ellipse".equals(state.getStyle().get("shape"))){ + geom.setX(50 + j*200); + } else { + geom.setX(100 + j*200); + } + geom.setY(100 + (i-skip)*100); + model.setGeometry(map.get(i).get(j), geom); + moved.add(map.get(i).get(j).getId()); + } else if (geom.getX() < 100 + j*150) { + if ("ellipse".equals(state.getStyle().get("shape"))){ + geom.setX(50 + j*200); + } else { + geom.setX(100 + j*200); + } + geom.setY(100 + (i-skip)*100); + model.setGeometry(map.get(i).get(j), geom); + } else { + count++; + } + } + if (count >= map.get(i).size())skip++; + } + + } finally { + model.endUpdate(); + } + } + + + public void lines(List> mapping, mxCell next) { + mapping.get(mapping.size()-1).add(next); + int tagcount = 0; + mxCell edge; + mxGraphView view = graph.getView(); + for (int i = 0; i < next.getEdgeCount(); i++) { + edge = (mxCell) next.getEdgeAt(i); + mxCellState state = view.getState(edge); + if (next != (mxCell) edge.getTarget() && ((mxCell) edge.getTarget() != null) && !"true".equals(state.getStyle().get("dashed"))) { + tagcount++; + if (tagcount > 1) { + List newline = new ArrayList(mapping.get(mapping.size()-1)); + while (newline.get(newline.size()-1).getId() != next.getId()) { + newline.remove(newline.size()-1); + } + mapping.add(newline); + lines(mapping, (mxCell) edge.getTarget()); + + } else { + lines(mapping, (mxCell) edge.getTarget()); + } + } + } + } + + public boolean checkmoved(List list, mxCell cell) { + for (int i = 0; i < list.size(); i++) { + if (list.get(i).equals(cell.getId()))return false; + } + return true; + } + + public void sort(List> map, int n, boolean check) { + int msize = -1; + int mnum = -1; + if (check) { + for (int i = n; i < map.size(); i++) { + if (map.get(i).size() > msize && (map.get(n-1).get(0).getId().equals(map.get(i).get(0).getId()))) { + mnum = i; + } + } + } else { + for (int i = n; i < map.size(); i++) { + if (map.get(i).size() > msize) { + mnum = i; + } + } + } + if (mnum >= 0) { + Collections.swap(map, n, mnum); + sort(map, n+1, true); + } else if(n < map.size()) { + sort(map, n+1, false); + } + } + + +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/src/code/ast/MethodDeclaration.java b/AlgebraicDataflowArchitectureModel/src/code/ast/MethodDeclaration.java index fc4e104..fad7629 100644 --- a/AlgebraicDataflowArchitectureModel/src/code/ast/MethodDeclaration.java +++ b/AlgebraicDataflowArchitectureModel/src/code/ast/MethodDeclaration.java @@ -21,7 +21,7 @@ this(methodName, false); } - public MethodDeclaration(String methodName,Type returnType) { + public MethodDeclaration(String methodName, Type returnType) { this(methodName, false); this.returnType = returnType; } diff --git a/AlgebraicDataflowArchitectureModel/src/code/ast/TypeDeclaration.java b/AlgebraicDataflowArchitectureModel/src/code/ast/TypeDeclaration.java index 1dc5cf3..0406d59 100644 --- a/AlgebraicDataflowArchitectureModel/src/code/ast/TypeDeclaration.java +++ b/AlgebraicDataflowArchitectureModel/src/code/ast/TypeDeclaration.java @@ -34,6 +34,10 @@ methods.add(method); } + public void removeMethod(MethodDeclaration method) { + methods.remove(method); + } + public List getFields() { return fields; } @@ -41,6 +45,12 @@ public List getMethods() { return methods; } + + public MethodDeclaration createConstructor() { + MethodDeclaration constructor = new MethodDeclaration(typeName, true); + addMethod(constructor); + return constructor; + } @Override public Annotation getAnnotation(String name) { diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/AbstractEditorAction.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/AbstractEditorAction.java deleted file mode 100644 index c473f18..0000000 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/AbstractEditorAction.java +++ /dev/null @@ -1,23 +0,0 @@ -package graphicalrefactor.actions; - -import javax.swing.AbstractAction; -import javax.swing.Icon; - -import com.mxgraph.view.mxGraph; - -import graphicalrefactor.editor.Editor; - -public abstract class AbstractEditorAction extends AbstractAction { - - protected Editor editor; - - public AbstractEditorAction(String name, Editor editor) { - super(name); - this.editor = editor; - } - - public void setEditor(Editor editor) { - this.editor = editor; - } - -} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/AbstractSystemAction.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/AbstractSystemAction.java deleted file mode 100644 index e3f827d..0000000 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/AbstractSystemAction.java +++ /dev/null @@ -1,23 +0,0 @@ -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 deleted file mode 100644 index 13c4a07..0000000 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/AbstractViewerAction.java +++ /dev/null @@ -1,17 +0,0 @@ -package graphicalrefactor.actions; - -import java.awt.event.ActionEvent; - -import javax.swing.AbstractAction; - -import com.mxgraph.swing.mxGraphComponent; - -public abstract class AbstractViewerAction extends AbstractAction { - - protected mxGraphComponent graphComponent = null; - - public AbstractViewerAction(String name, mxGraphComponent graphComponent) { - super(name); - this.graphComponent = graphComponent; - } -} diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/CircleLayoutAction.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/CircleLayoutAction.java deleted file mode 100644 index 07f3b7b..0000000 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/CircleLayoutAction.java +++ /dev/null @@ -1,18 +0,0 @@ -package graphicalrefactor.actions; - -import java.awt.event.ActionEvent; - -import graphicalrefactor.editor.Editor; - -public class CircleLayoutAction extends AbstractEditorAction { - - public CircleLayoutAction(Editor editor) { - super("Circle Layout", editor); - } - - @Override - public void actionPerformed(ActionEvent e) { - editor.setCircleLayout(); - } - -} diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/DAGLayoutAction.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/DAGLayoutAction.java deleted file mode 100644 index db8bb5d..0000000 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/DAGLayoutAction.java +++ /dev/null @@ -1,17 +0,0 @@ -package graphicalrefactor.actions; - -import java.awt.event.ActionEvent; -import graphicalrefactor.editor.Editor; - -public class DAGLayoutAction extends AbstractEditorAction { - - public DAGLayoutAction(Editor editor) { - super("DAG Layout", editor); - } - - @Override - public void actionPerformed(ActionEvent e) { - editor.setDAGLayout(); - } - -} diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/DeleteAction.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/DeleteAction.java deleted file mode 100644 index 1ac8a47..0000000 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/DeleteAction.java +++ /dev/null @@ -1,23 +0,0 @@ -package graphicalrefactor.actions; - -import java.awt.event.ActionEvent; - -import graphicalrefactor.editor.Editor; - -public class DeleteAction extends AbstractEditorAction { - - /** - * - */ - private static final long serialVersionUID = -4410145389391154784L; - - public DeleteAction(Editor editor) { - super("Delete", editor); - } - - @Override - public void actionPerformed(ActionEvent e) { - editor.delete(); - } - -} diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/ExitAction.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/ExitAction.java deleted file mode 100644 index c18a6c5..0000000 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/ExitAction.java +++ /dev/null @@ -1,22 +0,0 @@ -package graphicalrefactor.actions; - -import java.awt.event.ActionEvent; - -import javax.swing.AbstractAction; - -public class ExitAction extends AbstractAction { - /** - * - */ - private static final long serialVersionUID = -8733766417378036850L; - - public ExitAction() { - super("Exit"); - } - - @Override - public void actionPerformed(ActionEvent e) { - System.exit(0); - } - -} diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/JavaPrototypeGenerateAction.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/JavaPrototypeGenerateAction.java deleted file mode 100644 index 60ca2f1..0000000 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/JavaPrototypeGenerateAction.java +++ /dev/null @@ -1,89 +0,0 @@ -package graphicalrefactor.actions; - -import java.awt.event.ActionEvent; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; - -import javax.swing.JFileChooser; - -import algorithms.*; -import code.ast.*; -import generators.DataTransferMethodAnalyzer; -import generators.JavaCodeGenerator; -import generators.JavaMethodBodyGenerator; -import graphicalrefactor.editor.Editor; -import models.dataConstraintModel.IdentifierTemplate; -import models.dataFlowModel.DataTransferModel; -import models.dataFlowModel.ModelExtension; -import models.dataFlowModel.DataFlowGraph; - -public class JavaPrototypeGenerateAction extends AbstractEditorAction { - /** - * - */ - private static final long serialVersionUID = -3694103632055735068L; - - private String lastDir = null; - - public JavaPrototypeGenerateAction(Editor editor) { - super("Generate Plain Java Prototype", editor); - } - - @Override - public void actionPerformed(ActionEvent e) { - DataFlowGraph graph = editor.getDataFlowGraph(); - if (graph != null) { - DataTransferModel model = editor.getModel(); - ModelExtension.extendModel(model); - TypeInference.infer(model); - DataTransferMethodAnalyzer.decideToStoreResourceStates(graph); - String fileName = editor.getCurFileName(); - if (fileName == null) fileName = "Main"; - String mainTypeName = fileName.split("\\.")[0]; - boolean exist = false; - for (IdentifierTemplate id: model.getIdentifierTemplates()) { - String resourceName = id.getResourceName().substring(0, 1).toUpperCase() + id.getResourceName().substring(1); - if (mainTypeName.equals(resourceName)) { - exist = true; - } - } - if (!exist) { - JavaCodeGenerator.setMainTypeName(mainTypeName); // use model's file name as the main type's name. - } else { - JavaCodeGenerator.resetMainTypeName(); // use the default main type's name. - } - editor.setCodes(JavaMethodBodyGenerator.doGenerate(graph, model, JavaCodeGenerator.doGenerate(graph, model))); - ModelExtension.recoverModel(model); - for (CompilationUnit file : editor.getCodes()) { - System.out.println(file); - } - - String wd = (lastDir != null) ? lastDir : System.getProperty("user.dir"); - JFileChooser fc = new JFileChooser(wd); - fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); - int rc = fc.showSaveDialog(null); - if (rc == JFileChooser.APPROVE_OPTION) { - lastDir = fc.getSelectedFile().getPath(); - for (CompilationUnit cu : editor.getCodes()) { - save(fc.getSelectedFile(), cu); - } - } - } - } - - private void save(File dir, CompilationUnit cu) { - File javaFile = new File(dir.getPath(), cu.getFileName()); - try { - BufferedWriter writer = new BufferedWriter(new FileWriter(javaFile)); - writer.write(cu.toString()); - writer.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - -} diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/JerseyPrototypeGenerateAction.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/JerseyPrototypeGenerateAction.java deleted file mode 100644 index 083c690..0000000 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/JerseyPrototypeGenerateAction.java +++ /dev/null @@ -1,90 +0,0 @@ -package graphicalrefactor.actions; - -import java.awt.event.ActionEvent; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; - -import javax.swing.JFileChooser; - -import algorithms.*; -import code.ast.*; -import generators.DataTransferMethodAnalyzer; -import generators.JerseyCodeGenerator; -import generators.JerseyMethodBodyGenerator; -import graphicalrefactor.editor.Editor; -import models.algebra.Type; -import models.dataConstraintModel.IdentifierTemplate; -import models.dataFlowModel.DataTransferModel; -import models.dataFlowModel.ModelExtension; -import models.dataFlowModel.DataFlowGraph; - -public class JerseyPrototypeGenerateAction extends AbstractEditorAction { - /** - * - */ - private static final long serialVersionUID = 1117065654665887436L; - - private String lastDir = null; - - public JerseyPrototypeGenerateAction(Editor editor) { - super("Generate JAX-RS Prototype", editor); - } - - @Override - public void actionPerformed(ActionEvent e) { - DataFlowGraph graph = editor.getDataFlowGraph(); - if (graph != null) { - DataTransferModel model = editor.getModel(); - ModelExtension.extendModel(model); - TypeInference.infer(model); - DataTransferMethodAnalyzer.decideToStoreResourceStates(graph); - String fileName = editor.getCurFileName(); - if (fileName == null) fileName = "Main"; - String mainTypeName = fileName.split("\\.")[0]; - boolean exist = false; - for (IdentifierTemplate id: model.getIdentifierTemplates()) { - String resourceName = id.getResourceName().substring(0, 1).toUpperCase() + id.getResourceName().substring(1); - if (mainTypeName.equals(resourceName)) { - exist = true; - } - } - if (!exist) { - JerseyCodeGenerator.setMainTypeName(mainTypeName); // use model's file name as the main type's name. - } else { - JerseyCodeGenerator.resetMainTypeName(); // use the default main type's name. - } - editor.setCodes(JerseyMethodBodyGenerator.doGenerate(graph, model, JerseyCodeGenerator.doGenerate(graph, model))); - ModelExtension.recoverModel(model); - for (CompilationUnit file : editor.getCodes()) { - System.out.println(file); - } - - String wd = (lastDir != null) ? lastDir : System.getProperty("user.dir"); - JFileChooser fc = new JFileChooser(wd); - fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); - int rc = fc.showSaveDialog(null); - if (rc == JFileChooser.APPROVE_OPTION) { - lastDir = fc.getSelectedFile().getPath(); - for (CompilationUnit cu : editor.getCodes()) { - save(fc.getSelectedFile(), cu); - } - } - } - } - - private void save(File dir, CompilationUnit cu) { - File javaFile = new File(dir.getPath(), cu.getFileName()); - try { - BufferedWriter writer = new BufferedWriter(new FileWriter(javaFile)); - writer.write(cu.toString()); - writer.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - -} diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewChannelAction.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewChannelAction.java deleted file mode 100644 index 9328f5f..0000000 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewChannelAction.java +++ /dev/null @@ -1,28 +0,0 @@ -package graphicalrefactor.actions; - -import java.awt.event.ActionEvent; - -import javax.swing.JOptionPane; - -import graphicalrefactor.editor.Editor; -import models.dataFlowModel.DataTransferChannelGenerator; - -public class NewChannelAction extends AbstractEditorAction { - - /** - * - */ - private static final long serialVersionUID = 5979007029473101802L; - - public NewChannelAction(Editor editor) { - super("Channel...", editor); - } - - @Override - public void actionPerformed(ActionEvent e) { - String channelName = JOptionPane.showInputDialog("Channel Name:"); - if (channelName == null) return; - editor.addChannelGenerator(new DataTransferChannelGenerator(channelName)); - } - -} diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewFormulaChannelAction.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewFormulaChannelAction.java deleted file mode 100644 index 7fb9299..0000000 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewFormulaChannelAction.java +++ /dev/null @@ -1,62 +0,0 @@ -package graphicalrefactor.actions; - -import java.awt.BorderLayout; -import java.awt.Container; -import java.awt.FlowLayout; -import java.awt.Frame; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JTextField; - -import graphicalrefactor.editor.Editor; -import graphicalrefactor.views.GraphicalRefactor; -import models.visualModel.FormulaChannelGenerator; - -public class NewFormulaChannelAction extends AbstractEditorAction implements ActionListener { - - /** - * - */ - private static final long serialVersionUID = 5345875219049178252L; - - public NewFormulaChannelAction(Editor editor) { - super("FormulaChannel...", editor); - } - - @Override - public void actionPerformed(ActionEvent e) { - JPanel panel = new JPanel(); - GridLayout layout = new GridLayout(2,2); - panel.setLayout(layout); - layout.setVgap(5); - layout.setHgap(20); - panel.add(new JLabel("Channel Name:")); - JTextField channelText = new JTextField(); - panel.add(channelText); - panel.add(new JLabel("Symbol:")); - JTextField symbolText = new JTextField(); - panel.add(symbolText); - - int r = JOptionPane.showConfirmDialog( - null, // �I�[�i�[�E�B���h�E - panel, // ���b�Z�[�W - "New Formula Channel", // �E�B���h�E�^�C�g�� - JOptionPane.OK_CANCEL_OPTION, // �I�v�V�����i�{�^���̎�ށj - JOptionPane.QUESTION_MESSAGE); // ���b�Z�[�W�^�C�v�i�A�C�R���̎�ށj - - String channelName = channelText.getText(); - String symbol = symbolText.getText(); - if(r == JOptionPane.OK_OPTION) { - editor.addFormulaChannelGenerator(new FormulaChannelGenerator(channelName, editor.getModel().getSymbol(symbol))); - } - } -} diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewIOChannelAction.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewIOChannelAction.java deleted file mode 100644 index 6b3bf66..0000000 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewIOChannelAction.java +++ /dev/null @@ -1,29 +0,0 @@ -package graphicalrefactor.actions; - -import java.awt.event.ActionEvent; - -import javax.swing.JOptionPane; - - -import graphicalrefactor.editor.Editor; -import models.dataFlowModel.DataTransferChannelGenerator; - -public class NewIOChannelAction extends AbstractEditorAction { - - /** - * - */ - private static final long serialVersionUID = -1657072017390171313L; - - public NewIOChannelAction(Editor editor) { - super("I/O Channel", editor); - } - - @Override - public void actionPerformed(ActionEvent e) { - String channelName = JOptionPane.showInputDialog("I/O Channel Name:"); - if (channelName == null) return; - editor.addIOChannelGenerator(new DataTransferChannelGenerator(channelName)); - } - -} diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewModelAction.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewModelAction.java deleted file mode 100644 index c79d868..0000000 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewModelAction.java +++ /dev/null @@ -1,24 +0,0 @@ -package graphicalrefactor.actions; - -import java.awt.event.ActionEvent; - -import graphicalrefactor.editor.Editor; -import graphicalrefactor.views.GraphicalRefactor; - -public class NewModelAction extends AbstractSystemAction { - /** - * - */ - private static final long serialVersionUID = 8484493203589724589L; - - public NewModelAction(GraphicalRefactor frame) { - super("Model", frame); - } - - @Override - public void actionPerformed(ActionEvent e) { - frame.getEditor().clear(); - frame.setTitle(frame.title); - } - -} diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewResourceAction.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewResourceAction.java deleted file mode 100644 index 600daf7..0000000 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewResourceAction.java +++ /dev/null @@ -1,28 +0,0 @@ -package graphicalrefactor.actions; - -import java.awt.event.ActionEvent; - -import javax.swing.JOptionPane; - -import graphicalrefactor.editor.Editor; -import models.dataConstraintModel.IdentifierTemplate; - -public class NewResourceAction extends AbstractEditorAction { - - /** - * - */ - private static final long serialVersionUID = -4439207504700741286L; - - public NewResourceAction(Editor editor) { - super("Resource...", editor); - } - - @Override - public void actionPerformed(ActionEvent e) { - String resName = JOptionPane.showInputDialog("Resourece Name:"); - if (resName == null) return; - editor.addIdentifierTemplate(new IdentifierTemplate(resName, 0)); - } - -} diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/OpenAction.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/OpenAction.java deleted file mode 100644 index 2fcfe73..0000000 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/OpenAction.java +++ /dev/null @@ -1,62 +0,0 @@ -package graphicalrefactor.actions; - -import java.awt.event.ActionEvent; -import java.io.File; - -import javax.swing.JFileChooser; -import javax.swing.filechooser.FileFilter; -import javax.swing.filechooser.FileNameExtensionFilter; - -import graphicalrefactor.editor.Editor; -import graphicalrefactor.views.GraphicalRefactor; - -public class OpenAction extends AbstractSystemAction { - /** - * - */ - private static final long serialVersionUID = -8290761032629599683L; - - private String lastDir = null; - - 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"); - - JFileChooser fc = new JFileChooser(wd); - - FileFilter model = new FileNameExtensionFilter("model","model"); - FileFilter dtram = new FileNameExtensionFilter("dtram", "dtram"); - - // Adds file filter for supported file format - FileFilter defaultFilter = new FileFilter() { - - public boolean accept(File file) { - String lcase = file.getName().toLowerCase(); - return lcase.endsWith(".model"); - } - - @Override - public String getDescription() { - return null; - } - }; - - fc.addChoosableFileFilter(defaultFilter); - fc.addChoosableFileFilter(model); - fc.addChoosableFileFilter(dtram); - int rc = fc.showDialog(null, "Open Model File"); - 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 deleted file mode 100644 index 62f0609..0000000 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/SaveAction.java +++ /dev/null @@ -1,26 +0,0 @@ -package graphicalrefactor.actions; - -import java.awt.event.ActionEvent; - -import graphicalrefactor.editor.Editor; -import graphicalrefactor.views.GraphicalRefactor; - -public class SaveAction extends AbstractSystemAction { - /** - * - */ - private static final long serialVersionUID = 5660460585305281982L; - - public SaveAction(GraphicalRefactor frame) { - super("Save", frame); - } - - @Override - public void actionPerformed(ActionEvent e) { - Editor editor = frame.getEditor(); - if (editor != null && editor.getCurFileName() != null) { - editor.save(); - } - } - -} diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/SaveAsAction.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/SaveAsAction.java deleted file mode 100644 index d8ce78e..0000000 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/SaveAsAction.java +++ /dev/null @@ -1,79 +0,0 @@ -package graphicalrefactor.actions; - -import java.awt.event.ActionEvent; -import java.io.File; - -import javax.swing.AbstractAction; -import javax.swing.JFileChooser; -import javax.swing.filechooser.FileFilter; -import javax.swing.filechooser.FileNameExtensionFilter; - -import graphicalrefactor.editor.Editor; -import graphicalrefactor.views.GraphicalRefactor; - -public class SaveAsAction extends AbstractSystemAction { - /** - * - */ - private static final long serialVersionUID = -2599502783032684084L; - - private String lastDir = null; - - public SaveAsAction(GraphicalRefactor frame) { - super("Save As...", frame); - } - - @Override - public void actionPerformed(ActionEvent e) { - Editor editor = frame.getEditor(); - if (editor != null) { - String wd = (lastDir != null) ? lastDir : System.getProperty("user.dir"); - - JFileChooser fc = new JFileChooser(wd); - FileFilter model = new FileNameExtensionFilter("model","model"); - FileFilter dtram = new FileNameExtensionFilter("dtram", "dtram"); - - // Adds file filter for supported file format - FileFilter defaultFilter = new FileFilter() { - public boolean accept(File file) { - String lcase = file.getName().toLowerCase(); - return lcase.endsWith(".model"); - } - - @Override - public String getDescription() { - return null; - } - }; - - fc.addChoosableFileFilter(defaultFilter); - fc.addChoosableFileFilter(model); - fc.addChoosableFileFilter(dtram); - int rc = fc.showDialog(null, "Save Model File"); - - // choose a file extension from a dialog. - if (rc == JFileChooser.APPROVE_OPTION) { - - // if extension filter is filled, then attaching extension by choosing filter. - // but if it's not filled, then using default extension name. - String extension = ""; - if(fc.getFileFilter() instanceof FileNameExtensionFilter) { - FileNameExtensionFilter selectedFilter = (FileNameExtensionFilter)fc.getFileFilter(); - extension = "." + selectedFilter.getExtensions()[0].toString(); - } - - lastDir = fc.getSelectedFile().getParent(); - - String fileName = fc.getSelectedFile().getAbsolutePath() + extension; - - // checking file duplicates - if(! (fc.getSelectedFile().exists())) editor.setCurFilePath(fileName); - - // overwriting file - editor.save(); - frame.setTitle(GraphicalRefactor.title + " - " + fc.getSelectedFile().getAbsolutePath()); - } - } - } - -} diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/TreeLayoutAction.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/TreeLayoutAction.java deleted file mode 100644 index 1ce409f..0000000 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/TreeLayoutAction.java +++ /dev/null @@ -1,18 +0,0 @@ -package graphicalrefactor.actions; - -import java.awt.event.ActionEvent; - -import graphicalrefactor.editor.Editor; - -public class TreeLayoutAction extends AbstractEditorAction { - - public TreeLayoutAction(Editor editor) { - super("Tree Layout", editor); - } - - @Override - public void actionPerformed(ActionEvent e) { - editor.setTreeLayout(); - } - -} diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/ZoomInAction.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/ZoomInAction.java deleted file mode 100644 index e2d1549..0000000 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/ZoomInAction.java +++ /dev/null @@ -1,28 +0,0 @@ -package graphicalrefactor.actions; - -import java.awt.event.ActionEvent; - -import javax.swing.AbstractAction; -import javax.swing.JOptionPane; - -import com.mxgraph.swing.mxGraphComponent; -import com.mxgraph.util.mxResources; - -import graphicalrefactor.editor.Editor; - -public class ZoomInAction extends AbstractViewerAction { - /** - * - */ - private static final long serialVersionUID = 6758532166946195926L; - - public ZoomInAction(mxGraphComponent graphComponent) { - super("Zoom In", graphComponent); - } - - @Override - public void actionPerformed(ActionEvent e) { - graphComponent.zoomIn(); - } - -} diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/ZoomOutAction.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/ZoomOutAction.java deleted file mode 100644 index 7518f38..0000000 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/ZoomOutAction.java +++ /dev/null @@ -1,26 +0,0 @@ -package graphicalrefactor.actions; - -import java.awt.event.ActionEvent; - -import javax.swing.AbstractAction; - -import com.mxgraph.swing.mxGraphComponent; - -import graphicalrefactor.editor.Editor; - -public class ZoomOutAction extends AbstractViewerAction { - /** - * - */ - private static final long serialVersionUID = 8657530769383486605L; - - public ZoomOutAction(mxGraphComponent graphComponent) { - super("Zoom Out", graphComponent); - } - - @Override - public void actionPerformed(ActionEvent e) { - graphComponent.zoomOut(); - } - -} diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/editor/Editor.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/editor/Editor.java deleted file mode 100644 index bc27ce5..0000000 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/editor/Editor.java +++ /dev/null @@ -1,667 +0,0 @@ -package graphicalrefactor.editor; - -import java.io.BufferedReader; -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.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import com.mxgraph.layout.mxCircleLayout; -import com.mxgraph.layout.mxCompactTreeLayout; -import com.mxgraph.model.mxCell; -import com.mxgraph.model.mxGeometry; -import com.mxgraph.model.mxGraphModel; -import com.mxgraph.model.mxIGraphModel; -import com.mxgraph.util.mxConstants; -import com.mxgraph.util.mxPoint; -import com.mxgraph.view.mxCellState; -import com.mxgraph.util.mxRectangle; -import com.mxgraph.view.mxGraph; -import com.mxgraph.view.mxGraphView; - -import algorithms.DataTransferModelAnalyzer; -import algorithms.Validation; -import code.ast.CompilationUnit; -import graphicalrefactor.layouts.*; -import models.Edge; -import models.EdgeAttribute; -import models.Node; -import models.dataConstraintModel.ChannelGenerator; -import models.dataConstraintModel.ChannelMember; -import models.dataConstraintModel.IdentifierTemplate; -import models.dataFlowModel.DataTransferModel; -import models.dataFlowModel.DataTransferChannelGenerator; -import models.dataFlowModel.PushPullAttribute; -import models.dataFlowModel.DataFlowEdge; -import models.dataFlowModel.DataFlowGraph; -import models.dataFlowModel.ResourceNode; -import models.visualModel.FormulaChannelGenerator; -import parser.Parser; -import parser.Parser.TokenStream; -import parser.exceptions.ExpectedAssignment; -import parser.exceptions.ExpectedChannel; -import parser.exceptions.ExpectedChannelName; -import parser.exceptions.ExpectedEquals; -import parser.exceptions.ExpectedFormulaChannel; -import parser.exceptions.ExpectedGeometry; -import parser.exceptions.ExpectedInOrOutOrRefKeyword; -import parser.exceptions.ExpectedIoChannel; -import parser.exceptions.ExpectedLeftCurlyBracket; -import parser.exceptions.ExpectedModel; -import parser.exceptions.ExpectedNode; -import parser.exceptions.ExpectedRHSExpression; -import parser.exceptions.ExpectedResource; -import parser.exceptions.ExpectedRightBracket; -import parser.exceptions.ExpectedStateTransition; -import parser.exceptions.WrongLHSExpression; -import parser.exceptions.WrongRHSExpression; -import parser.ParserDTRAM; - -public class Editor { - final int PORT_DIAMETER = 8; - final int PORT_RADIUS = PORT_DIAMETER / 2; - - protected String curFileName = null; - protected String curFilePath = null; - protected ArrayList codes = null; - - protected DataTransferModel model = null; - protected mxGraph graph = null; - - protected DataFlowGraph dataFlowGraph = null; - - - public Editor(mxGraph graph) { - this.graph = graph; - } - - public mxGraph getGraph() { - return graph; - } - - public void setGraph(mxGraph graph) { - this.graph = graph; - } - - public DataTransferModel getModel() { - if (model == null) { - model = new DataTransferModel(); - } - return model; - } - - public DataFlowGraph getDataFlowGraph() { - if (dataFlowGraph == null) { - analyzeDataTransferModel(getModel()); - } - return dataFlowGraph; - } - - public DataFlowGraph analyzeDataTransferModel(DataTransferModel model) { - DataFlowGraph flowGraph = DataTransferModelAnalyzer.createDataFlowGraphWithStateStoringAttribute(model); - dataFlowGraph = DataTransferModelAnalyzer.annotateWithSelectableDataTransferAttiribute(flowGraph); - updateEdgeAttiributes(dataFlowGraph); - return dataFlowGraph; - } - - public void resetDataFlowGraph() { - dataFlowGraph = null; - } - - public void setDataFlowGraph(DataFlowGraph dataFlowGraph) { - this.dataFlowGraph = dataFlowGraph; - } - - public ArrayList getCodes() { - return codes; - } - - public void setCodes(ArrayList codes) { - this.codes = codes; - } - - public String getCurFileName() { - return curFileName; - } - - public String getCurFilePath() { - return curFilePath; - } - - public void setCurFilePath(String curFilePath) { - this.curFilePath = curFilePath; - this.curFileName = new File(curFilePath).getName(); - } - - public void clear() { - model = null; - ((mxGraphModel) graph.getModel()).clear(); - dataFlowGraph = null; - curFilePath = null; - curFileName = null; - codes = null; - } - - /** - * Open a given file, parse the file, construct a DataFlowModel and a mxGraph - * @param file given file - * @return a constructed DataFlowModel - */ - public DataTransferModel open(File file) { - try { - - String extension =""; - if(file != null && file.exists()) { - // get a file's name - String name = file.getName(); - - // get a file's extension - extension = name.substring(name.lastIndexOf(".")); - } - if(extension.contains(".model")) { - openModel(file); - } else { - ParserDTRAM parserDTRAM = new ParserDTRAM(new BufferedReader(new FileReader(file))); - try { - model = parserDTRAM.doParseModel(); - graph = constructGraph(model); - parserDTRAM.doParseGeometry(graph); - curFilePath = file.getAbsolutePath(); - curFileName = file.getName(); - if (!Validation.checkUpdateConflict(model)) return null; - analyzeDataTransferModel(model); - return model; - } catch (ExpectedChannel | ExpectedChannelName | ExpectedLeftCurlyBracket | ExpectedInOrOutOrRefKeyword - | ExpectedStateTransition | ExpectedEquals | ExpectedRHSExpression | WrongLHSExpression - | WrongRHSExpression | ExpectedRightBracket | ExpectedAssignment | ExpectedModel | ExpectedGeometry | ExpectedNode | ExpectedResource | ExpectedFormulaChannel | ExpectedIoChannel e) { - e.printStackTrace(); - } - } - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - - return null; - } - - public DataTransferModel openModel(File file) { - try { - - Parser parser = new Parser(new BufferedReader(new FileReader(file))); - - try { - model = parser.doParse(); - curFilePath = file.getAbsolutePath(); - curFileName = file.getName(); - if (!Validation.checkUpdateConflict(model)) return null; - graph = constructGraph(model); - analyzeDataTransferModel(model); - return model; - } catch (ExpectedChannel | ExpectedChannelName | ExpectedLeftCurlyBracket | ExpectedInOrOutOrRefKeyword - | ExpectedStateTransition | ExpectedEquals | ExpectedRHSExpression | WrongLHSExpression - | WrongRHSExpression | ExpectedRightBracket | ExpectedAssignment e) { - e.printStackTrace(); - } - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - return null; - } - - /**-------------------------------------------------------------------------------- - * save - /**-------------------------------------------------------------------------------- - * - */ - public void save() { - if (curFilePath != null) { - try { - File file = new File(curFilePath); - String extension = ""; - if(file != null && file.exists()) { - // get a file's name - String name = file.getName(); - - // get a file's extension - extension = name.substring(name.lastIndexOf(".")); - } - if(extension.contains(".model")) { - saveModel(file); - } else { - FileWriter filewriter = new FileWriter(file); - filewriter.write(toOutputString()); - filewriter.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - public void saveModel(File file) { - if (curFilePath != null) { - try { - FileWriter filewriter = new FileWriter(file); - filewriter.write(model.getSourceText()); - filewriter.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - /**-------------------------------------------------------------------------------- - * get writing texts "dtram" file information is written. - * - * @return formatted "dtram" info texts. - */ - protected String toOutputString() { - String fileString = ""; - - fileString += "model {\n"; - fileString += this.model.getSourceText(); - fileString += "}\n"; - - fileString += "geometry {\n"; - - Object root = graph.getDefaultParent(); - for (int i = 0; i < graph.getModel().getChildCount(root); i++) { - Object cell = graph.getModel().getChildAt(root, i); - if (graph.getModel().isVertex(cell)) { - mxGraphView view = graph.getView(); - mxCellState state = view.getState(cell); - int x = (int) state.getX(); - int y = (int) state.getY(); - int w = (int) state.getWidth(); - int h = (int) state.getHeight(); - - for(ChannelGenerator ch: model.getChannelGenerators()) { - if(ch instanceof FormulaChannelGenerator && state.getLabel().equals(ch.getChannelName())) { - fileString += "\tnode fc " + state.getLabel() + ":" + x + "," + y + "," + w + "," + h+"\n"; - } else if(ch instanceof ChannelGenerator && state.getLabel().equals(ch.getChannelName())) { - fileString +="\tnode c " + state.getLabel() + ":" + x + "," + y + "," + w + "," + h+"\n"; - } - } - - for (IdentifierTemplate res: model.getIdentifierTemplates()){ - if(res instanceof IdentifierTemplate && state.getLabel().equals(res.getResourceName())) - fileString += "\tnode r " + state.getLabel() + ":" + x + "," + y + "," + w + "," + h + "\n"; - } - - for (ChannelGenerator ioC: model.getIOChannelGenerators()) { - if(ioC instanceof ChannelGenerator && state.getLabel().equals(ioC.getChannelName())) { - fileString += "\tnode ioc " + state.getLabel() + ":" + x + "," + y + "," + w + "," + h + "\n"; - } - } - } - } - fileString += "}\n"; - - return fileString; - } - - /** - * Construct a mxGraph from DataFlowModel and DataFlowModel - * @param model - * @param dataFlowGraph - * @return constructed mxGraph - */ - public mxGraph constructGraph(DataTransferModel model) { - ((mxGraphModel) graph.getModel()).clear(); - Object parent = graph.getDefaultParent(); - graph.getModel().beginUpdate(); - try { - mxGeometry geo1 = new mxGeometry(0, 0.5, PORT_DIAMETER, PORT_DIAMETER); - geo1.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS)); - geo1.setRelative(true); - - mxGeometry geo2 = new mxGeometry(1.0, 0.5, PORT_DIAMETER, PORT_DIAMETER); - geo2.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS)); - geo2.setRelative(true); - - Map channelsIn = new HashMap<>(); - Map channelsOut = new HashMap<>(); - Map resources = new HashMap<>(); - - // create channel vertices - for (ChannelGenerator c: model.getChannelGenerators()) { - DataTransferChannelGenerator channelGen = (DataTransferChannelGenerator) c; - if (channelsIn.get(channelGen) == null || channelsOut.get(channelGen) == null) { - Object channel = graph.insertVertex(parent, null, channelGen.getChannelName(), 150, 20, 30, 30); // insert a channel as a vertex - mxCell port_in = new mxCell(null, geo1, "shape=ellipse;perimter=ellipsePerimeter"); - port_in.setVertex(true); - graph.addCell(port_in, channel); // insert the input port of a channel - mxCell port_out = new mxCell(null, geo2, "shape=ellipse;perimter=ellipsePerimeter"); - port_out.setVertex(true); - graph.addCell(port_out, channel); // insert the output port of a channel - channelsIn.put(channelGen, port_in); - channelsOut.put(channelGen, port_out); - } - } - - // create resource vertices - for (IdentifierTemplate res: model.getIdentifierTemplates()) { - Object resource = graph.insertVertex(parent, null, - res.getResourceName(), 20, 20, 80, 30, - "shape=ellipse;perimeter=ellipsePerimeter"); // insert a resource as a vertex - resources.put(res, resource); - } - - // add input, output and reference edges - for (ChannelGenerator ch: model.getChannelGenerators()) { - DataTransferChannelGenerator channelGen = (DataTransferChannelGenerator) ch; - // input edge - for (IdentifierTemplate srcRes: channelGen.getInputIdentifierTemplates()) { - graph.insertEdge(parent, null, new SrcDstAttribute(srcRes, channelGen), resources.get(srcRes), channelsIn.get(channelGen), "movable=false"); - } - // output edge - for (IdentifierTemplate dstRes: channelGen.getOutputIdentifierTemplates()) { - graph.insertEdge(parent, null, new SrcDstAttribute(channelGen, dstRes), channelsOut.get(channelGen), resources.get(dstRes), "movable=false"); - } - // reference edges - for (IdentifierTemplate refRes: channelGen.getReferenceIdentifierTemplates()) { - graph.insertEdge(parent, null, null, resources.get(refRes), channelsIn.get(channelGen), "dashed=true;movable=false"); - } - } - - for (ChannelGenerator ioChannelGen: model.getIOChannelGenerators()) { - if (channelsOut.get(ioChannelGen) == null) { - Object channel = graph.insertVertex(parent, null, ioChannelGen.getChannelName(), 150, 20, 30, 30); // insert an I/O channel as a vertex - mxCell port_out = new mxCell(null, geo2, "shape=ellipse;perimter=ellipsePerimeter"); - port_out.setVertex(true); - graph.addCell(port_out, channel); // insert the output port of a channel - channelsOut.put((DataTransferChannelGenerator) ioChannelGen, port_out); - for (IdentifierTemplate outRes: ((DataTransferChannelGenerator) ioChannelGen).getOutputIdentifierTemplates()) { - graph.insertEdge(parent, null, null, port_out, resources.get(outRes), "movable=false"); - } - } - } - } finally { - graph.getModel().endUpdate(); - } - setTreeLayout(); - - return graph; - } - - public void setDAGLayout() { - Object parent = graph.getDefaultParent(); - graph.getModel().beginUpdate(); - try { - DAGLayout ctl = new DAGLayout(graph); - ctl.execute(parent); - } finally { - graph.getModel().endUpdate(); - } - } - - public void updateEdgeAttiributes(DataFlowGraph dataFlowGraph) { - Object parent = graph.getDefaultParent(); - graph.getModel().beginUpdate(); - try { - // add input, output and reference edges - for (Edge e : dataFlowGraph.getEdges()) { - if (e instanceof DataFlowEdge) { - DataFlowEdge dataFlow = (DataFlowEdge) e; - DataTransferChannelGenerator channelGen = dataFlow.getChannelGenerator(); - ResourceNode srcRes = (ResourceNode) dataFlow.getSource(); - // input edge - for (Object edge: graph.getChildEdges(parent)) { - mxCell edgeCell = (mxCell) edge; - if (edgeCell.getValue() instanceof SrcDstAttribute) { - SrcDstAttribute edgeAttr = (SrcDstAttribute) edgeCell.getValue(); - if (edgeAttr.getSrouce() == srcRes.getIdentifierTemplate() && edgeAttr.getDestination() == channelGen) { - edgeCell.setValue(dataFlow.getAttribute()); - break; - } - } - } - } - } - } finally { - graph.getModel().endUpdate(); - } - graph.refresh(); - } - - public void setTreeLayout() { - Object parent = graph.getDefaultParent(); - graph.getModel().beginUpdate(); - try { - mxCompactTreeLayout ctl = new mxCompactTreeLayout(graph); - ctl.setLevelDistance(100); - // ctl.setHorizontal(false); - ctl.setEdgeRouting(false); - ctl.execute(parent); - } finally { - graph.getModel().endUpdate(); - } - } - - public void setCircleLayout() { - Object parent = graph.getDefaultParent(); - graph.getModel().beginUpdate(); - try { - mxCircleLayout ctl = new mxCircleLayout(graph); - ctl.execute(parent); - } finally { - graph.getModel().endUpdate(); - } - } - - public void addIdentifierTemplate(IdentifierTemplate res) { - getModel().addIdentifierTemplate(res); - resetDataFlowGraph(); - graph.getModel().beginUpdate(); - Object parent = graph.getDefaultParent(); - try { - graph.insertVertex(parent, null, res.getResourceName(), 20, 20, 80, 30, - "shape=ellipse;perimeter=ellipsePerimeter"); // insert a resource as a vertex - } finally { - graph.getModel().endUpdate(); - } - } - - public void addChannelGenerator(DataTransferChannelGenerator channelGen) { - getModel().addChannelGenerator(channelGen); - resetDataFlowGraph(); - graph.getModel().beginUpdate(); - Object parent = graph.getDefaultParent(); - try { - mxGeometry geo1 = new mxGeometry(0, 0.5, PORT_DIAMETER, PORT_DIAMETER); - geo1.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS)); - geo1.setRelative(true); - - mxGeometry geo2 = new mxGeometry(1.0, 0.5, PORT_DIAMETER, PORT_DIAMETER); - geo2.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS)); - geo2.setRelative(true); - - Object channel = graph.insertVertex(parent, null, channelGen.getChannelName(), 150, 20, 30, 30); // insert a channel as a vertex - mxCell port_in = new mxCell(null, geo1, "shape=ellipse;perimter=ellipsePerimeter"); - port_in.setVertex(true); - graph.addCell(port_in, channel); // insert the input port of a channel - mxCell port_out = new mxCell(null, geo2, "shape=ellipse;perimter=ellipsePerimeter"); - port_out.setVertex(true); - graph.addCell(port_out, channel); // insert the output port of a channel - } finally { - graph.getModel().endUpdate(); - } - } - - public void addIOChannelGenerator(DataTransferChannelGenerator ioChannelGen) { - getModel().addIOChannelGenerator(ioChannelGen); - resetDataFlowGraph(); - graph.getModel().beginUpdate(); - Object parent = graph.getDefaultParent(); - try { - mxGeometry geo2 = new mxGeometry(1.0, 0.5, PORT_DIAMETER, PORT_DIAMETER); - geo2.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS)); - geo2.setRelative(true); - - Object channel = graph.insertVertex(parent, null, ioChannelGen.getChannelName(), 150, 20, 30, 30); // insert an I/O channel as a vertex - mxCell port_out = new mxCell(null, geo2, "shape=ellipse;perimter=ellipsePerimeter"); - port_out.setVertex(true); - graph.addCell(port_out, channel); // insert the output port of a channel - } finally { - graph.getModel().endUpdate(); - } - } - - public void addFormulaChannelGenerator(FormulaChannelGenerator formulaChannelGen) { - getModel().addChannelGenerator(formulaChannelGen); - resetDataFlowGraph(); - graph.getModel().beginUpdate(); - Object parent = graph.getDefaultParent(); - try { - mxGeometry geo1 = new mxGeometry(0, 0.5, PORT_DIAMETER, PORT_DIAMETER); - geo1.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS)); - geo1.setRelative(true); - - mxGeometry geo2 = new mxGeometry(1.0, 0.5, PORT_DIAMETER, PORT_DIAMETER); - geo2.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS)); - geo2.setRelative(true); - - Object channel = graph.insertVertex(parent, null, formulaChannelGen.getChannelName(), 150, 20, 30, 30); // insert a channel as a vertex - mxCell port_in = new mxCell(null, geo1, "shape=ellipse;perimter=ellipsePerimeter"); - port_in.setVertex(true); - graph.addCell(port_in, channel); // insert the input port of a channel - mxCell port_out = new mxCell(null, geo2, "shape=ellipse;perimter=ellipsePerimeter"); - port_out.setVertex(true); - graph.addCell(port_out, channel); // insert the output port of a channel - } finally { - graph.getModel().endUpdate(); - } - } - - public boolean connectEdge(mxCell edge, mxCell src, mxCell dst) { - DataTransferModel model = getModel(); - ChannelGenerator srcCh = model.getChannelGenerator((String) src.getValue()); - if (srcCh == null) { - srcCh = model.getIOChannelGenerator((String) src.getValue()); - if (srcCh == null) { - IdentifierTemplate srcRes = model.getIdentifierTemplate((String) src.getValue()); - ChannelGenerator dstCh = model.getChannelGenerator((String) dst.getValue()); - if (srcRes == null || dstCh == null) return false; - // resource to channel edge - ChannelMember srcCm = new ChannelMember(srcRes); - ((DataTransferChannelGenerator ) dstCh).addChannelMemberAsInput(srcCm); - edge.setValue(new SrcDstAttribute(srcRes, dstCh)); - resetDataFlowGraph(); - return true; - } - } - IdentifierTemplate dstRes = model.getIdentifierTemplate((String) dst.getValue()); - if (dstRes == null) return false; - // channel to resource edge - ChannelMember dstCm = new ChannelMember(dstRes); - ((DataTransferChannelGenerator) srcCh).addChannelMemberAsOutput(dstCm); - edge.setValue(new SrcDstAttribute(srcCh, dstRes)); - resetDataFlowGraph(); - return true; - } - - public void delete() { - for (Object obj: graph.getSelectionCells()) { - mxCell cell = (mxCell) obj; - if (cell.isEdge()) { - String srcName = (String) cell.getSource().getValue(); - String dstName = (String) cell.getTarget().getValue(); - if (model.getIdentifierTemplate(srcName) != null) { - // resource to channel edge - ChannelGenerator ch = model.getChannelGenerator(dstName); - ch.removeChannelMember(model.getIdentifierTemplate(srcName)); - } else if (model.getIdentifierTemplate(dstName) != null) { - // channel to resource edge - ChannelGenerator ch = model.getChannelGenerator(srcName); - if (ch == null) { - ch = model.getIOChannelGenerator(srcName); - } - ch.removeChannelMember(model.getIdentifierTemplate(dstName)); - } - } else if (cell.isVertex()) { - String name = (String) cell.getValue(); - if (model.getChannelGenerator(name) != null) { - model.removeChannelGenerator(name); - } else if (model.getIOChannelGenerator(name) != null) { - model.removeIOChannelGenerator(name); - } else if (model.getIdentifierTemplate(name) != null) { - model.removeIdentifierTemplate(name); - } - } - } - graph.removeCells(graph.getSelectionCells()); - resetDataFlowGraph(); - } - - public void setChannelCode(DataTransferChannelGenerator ch, String code) { - ch.setSourceText(code); - TokenStream stream = new Parser.TokenStream(); - Parser parser = new Parser(stream); - - for (String line: code.split("\n")) { - stream.addLine(line); - } - try { - DataTransferChannelGenerator ch2 = parser.parseChannel(getModel()); - for (ChannelMember chm2: ch2.getInputChannelMembers()) { - for (ChannelMember chm: ch.getInputChannelMembers()) { - if (chm2.getIdentifierTemplate() == chm.getIdentifierTemplate()) { - chm.setStateTransition(chm2.getStateTransition()); - break; - } - } - } - for (ChannelMember chm2: ch2.getOutputChannelMembers()) { - for (ChannelMember chm: ch.getOutputChannelMembers()) { - if (chm2.getIdentifierTemplate() == chm.getIdentifierTemplate()) { - chm.setStateTransition(chm2.getStateTransition()); - break; - } - } - } - for (ChannelMember chm2: ch2.getReferenceChannelMembers()) { - for (ChannelMember chm: ch.getReferenceChannelMembers()) { - if (chm2.getIdentifierTemplate() == chm.getIdentifierTemplate()) { - chm.setStateTransition(chm2.getStateTransition()); - break; - } - } - } - resetDataFlowGraph(); - } catch (ExpectedRightBracket | ExpectedChannel | ExpectedChannelName | ExpectedLeftCurlyBracket - | ExpectedInOrOutOrRefKeyword | ExpectedStateTransition | ExpectedEquals | ExpectedRHSExpression - | WrongLHSExpression | WrongRHSExpression | ExpectedAssignment e) { - e.printStackTrace(); - } - } - - private class SrcDstAttribute extends EdgeAttribute { - private Object src; - private Object dst; - - public SrcDstAttribute(Object src, Object dst) { - this.src = src; - this.dst = dst; - } - - public Object getSrouce() { - return src; - } - - public Object getDestination() { - return dst; - } - - public String toString() { - return ""; - } - } -} diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/layouts/DAGLayout.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/layouts/DAGLayout.java deleted file mode 100644 index 2665efe..0000000 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/layouts/DAGLayout.java +++ /dev/null @@ -1,150 +0,0 @@ -package graphicalrefactor.layouts; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import com.mxgraph.layout.mxGraphLayout; -import com.mxgraph.model.mxCell; -import com.mxgraph.model.mxGeometry; -import com.mxgraph.model.mxICell; -import com.mxgraph.model.mxIGraphModel; -import com.mxgraph.util.mxRectangle; -import com.mxgraph.view.mxCellState; -import com.mxgraph.view.mxGraph; -import com.mxgraph.view.mxGraphView; - -import models.dataConstraintModel.ChannelGenerator; -import models.dataConstraintModel.IdentifierTemplate; - -public class DAGLayout extends mxGraphLayout { - - public DAGLayout(mxGraph arg0) { - super(arg0); - } - - public void execute(Object parent) { - mxIGraphModel model = graph.getModel(); - - model.beginUpdate(); - try { - List> map = new ArrayList>(); - List moved = new ArrayList<>(); - - for (int i = 0; i < model.getChildCount(parent); i++) { - - mxCell cell = (mxCell) model.getChildAt(parent, i); - - if (model.isVertex(cell)) { - mxGraphView view = graph.getView(); - mxCellState state = view.getState(cell); - - if (!"ellipse".equals(state.getStyle().get("shape")) && (cell.getEdgeCount() == 1) && !"true".equals(state.getStyle().get("dashed"))) { - List newline = new ArrayList(); - map.add(newline); - lines(map, cell); - } - } - } - - // ���בւ� - sort(map, 0, false); - - // layout - int count; - int skip = 0; - mxGraphView view = graph.getView(); - for (int i = 0; i < map.size(); i++) { - count = 0; - for (int j = 0; j < map.get(i).size(); j++) { - mxGeometry geom = (mxGeometry) map.get(i).get(j).getGeometry().clone(); - mxCellState state = view.getState(map.get(i).get(j)); - if (checkmoved(moved, map.get(i).get(j))) { - if ("ellipse".equals(state.getStyle().get("shape"))){ - geom.setX(50 + j*200); - } else { - geom.setX(100 + j*200); - } - geom.setY(100 + (i-skip)*100); - model.setGeometry(map.get(i).get(j), geom); - moved.add(map.get(i).get(j).getId()); - } else if (geom.getX() < 100 + j*150) { - if ("ellipse".equals(state.getStyle().get("shape"))){ - geom.setX(50 + j*200); - } else { - geom.setX(100 + j*200); - } - geom.setY(100 + (i-skip)*100); - model.setGeometry(map.get(i).get(j), geom); - } else { - count++; - } - } - if (count >= map.get(i).size())skip++; - } - - } finally { - model.endUpdate(); - } - } - - - public void lines(List> mapping, mxCell next) { - mapping.get(mapping.size()-1).add(next); - int tagcount = 0; - mxCell edge; - mxGraphView view = graph.getView(); - for (int i = 0; i < next.getEdgeCount(); i++) { - edge = (mxCell) next.getEdgeAt(i); - mxCellState state = view.getState(edge); - if (next != (mxCell) edge.getTarget() && ((mxCell) edge.getTarget() != null) && !"true".equals(state.getStyle().get("dashed"))) { - tagcount++; - if (tagcount > 1) { - List newline = new ArrayList(mapping.get(mapping.size()-1)); - while (newline.get(newline.size()-1).getId() != next.getId()) { - newline.remove(newline.size()-1); - } - mapping.add(newline); - lines(mapping, (mxCell) edge.getTarget()); - - } else { - lines(mapping, (mxCell) edge.getTarget()); - } - } - } - } - - public boolean checkmoved(List list, mxCell cell) { - for (int i = 0; i < list.size(); i++) { - if (list.get(i).equals(cell.getId()))return false; - } - return true; - } - - public void sort(List> map, int n, boolean check) { - int msize = -1; - int mnum = -1; - if (check) { - for (int i = n; i < map.size(); i++) { - if (map.get(i).size() > msize && (map.get(n-1).get(0).getId().equals(map.get(i).get(0).getId()))) { - mnum = i; - } - } - } else { - for (int i = n; i < map.size(); i++) { - if (map.get(i).size() > msize) { - mnum = i; - } - } - } - if (mnum >= 0) { - Collections.swap(map, n, mnum); - sort(map, n+1, true); - } else if(n < map.size()) { - sort(map, n+1, false); - } - } - - -} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/views/GraphicalRefactor.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/views/GraphicalRefactor.java deleted file mode 100644 index ab035a5..0000000 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/views/GraphicalRefactor.java +++ /dev/null @@ -1,98 +0,0 @@ -package graphicalrefactor.views; - -import java.util.ArrayList; -import java.util.List; - -import javax.swing.JFrame; - -import com.mxgraph.model.mxCell; -import com.mxgraph.model.mxGeometry; -import com.mxgraph.model.mxGraphModel; -import com.mxgraph.swing.mxGraphComponent; -import com.mxgraph.swing.handler.mxRubberband; -import com.mxgraph.swing.view.mxICellEditor; -import com.mxgraph.util.mxEvent; -import com.mxgraph.util.mxEventObject; -import com.mxgraph.util.mxEventSource.mxIEventListener; -import com.mxgraph.view.mxGraph; - -import graphicalrefactor.editor.Editor; - -public class GraphicalRefactor extends JFrame { - private static final long serialVersionUID = -8690140317781055614L; - public static final String title = "Visual Modeling Tool"; - - private Editor editor; - private mxGraph graph; - private GraphicalRefactorMenuBar menuBar; - private mxGraphComponent graphComponent; - - public GraphicalRefactor() { - setTitle(title); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - graph = new mxGraph() { - public boolean isPort(Object cell) { - mxGeometry geo = getCellGeometry(cell); - - return (geo != null) ? geo.isRelative() : false; - } - - public boolean isCellFoldable(Object cell, boolean collapse) { - return false; - } - }; - - editor = new Editor(graph); - - graphComponent = new mxGraphComponent(graph) { - protected mxICellEditor createCellEditor() { - return new GraphicalRefactorCellEditor(this, editor); - } - }; - graph.getModel().addListener(mxEvent.CHANGE, new mxIEventListener() { - public void invoke(Object sender, mxEventObject evt) { - List terminals = new ArrayList<>(); - mxCell cell = null; - for (Object change: ((List) evt.getProperties().get("changes"))) { - if (change instanceof mxGraphModel.mxTerminalChange) { - mxGraphModel.mxTerminalChange terminalChange = (mxGraphModel.mxTerminalChange) change; - cell = (mxCell) terminalChange.getCell(); - mxCell terminal = (mxCell) terminalChange.getTerminal(); - terminals.add(terminal); - } - } - if (terminals.size() == 2) { - if (!editor.connectEdge(cell, terminals.get(0), terminals.get(1))) { - graph.removeCells(new mxCell[] {cell}); - } - } - } - }); - getContentPane().add(graphComponent); - new mxRubberband(graphComponent); - graph.setAllowDanglingEdges(false); - graph.setCellsDisconnectable(true); - - menuBar = new GraphicalRefactorMenuBar(this); - setJMenuBar(menuBar); - setSize(870, 640); - } - - public mxGraph getGraph() { - return graph; - } - - public mxGraphComponent getGraphComponent() { - return graphComponent; - } - - public Editor getEditor() { - return editor; - } - - public void setEditor(Editor editor) { - this.editor = editor; - } - -} diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/views/GraphicalRefactorCellEditor.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/views/GraphicalRefactorCellEditor.java deleted file mode 100644 index 606c7e4..0000000 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/views/GraphicalRefactorCellEditor.java +++ /dev/null @@ -1,249 +0,0 @@ -package graphicalrefactor.views; - -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Rectangle; -import java.util.EventObject; -import java.util.List; - -import javax.swing.BorderFactory; -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JTextArea; -import javax.swing.JTextField; - -import com.mxgraph.model.mxCell; -import com.mxgraph.model.mxIGraphModel; -import com.mxgraph.swing.mxGraphComponent; -import com.mxgraph.swing.view.mxICellEditor; -import com.mxgraph.util.mxConstants; -import com.mxgraph.util.mxUtils; -import com.mxgraph.view.mxCellState; - -import graphicalrefactor.editor.Editor; -import models.algebra.Expression; -import models.dataFlowModel.DataTransferModel; -import models.dataFlowModel.DataTransferChannelGenerator; -import models.dataFlowModel.PushPullAttribute; -import models.dataFlowModel.PushPullValue; -import models.visualModel.FormulaChannelGenerator; -import parser.Parser; -import parser.Parser.TokenStream; -import parser.exceptions.ExpectedRightBracket; - -public class GraphicalRefactorCellEditor implements mxICellEditor { - public int DEFAULT_MIN_WIDTH = 70; - public int DEFAULT_MIN_HEIGHT = 30; - public double DEFAULT_MINIMUM_EDITOR_SCALE = 1; - - protected double minimumEditorScale = DEFAULT_MINIMUM_EDITOR_SCALE; - protected int minimumWidth = DEFAULT_MIN_WIDTH; - protected int minimumHeight = DEFAULT_MIN_HEIGHT; - - private Object editingCell; - private EventObject trigger; - private JComboBox comboBox; - private mxGraphComponent graphComponent; - private Editor editor; - - public GraphicalRefactorCellEditor(mxGraphComponent graphComponent, Editor editor) { - this.graphComponent = graphComponent; - this.editor = editor; - } - - @Override - public Object getEditingCell() { - return editingCell; - } - - @Override - public void startEditing(Object cell, EventObject evt) { - if (editingCell != null) { - stopEditing(true); - } - - if (!graphComponent.getGraph().getModel().isEdge(cell)) { - DataTransferModel model = editor.getModel(); - DataTransferChannelGenerator ch = (DataTransferChannelGenerator) model.getChannelGenerator((String) ((mxCell) cell).getValue()); - if (ch == null) { - ch = (DataTransferChannelGenerator) model.getIOChannelGenerator((String) ((mxCell) cell).getValue()); - if(ch == null) { - //resource - return; - } - } - - if(ch instanceof FormulaChannelGenerator) { - - JPanel panel = new JPanel(); - JLabel label1 = new JLabel("Formula: "); - JLabel label2 = new JLabel("Source: "); - GridBagLayout layout = new GridBagLayout(); - panel.setLayout(layout); - GridBagConstraints gbc = new GridBagConstraints(); - - gbc.gridx = 0; - gbc.gridy = 0; - layout.setConstraints(label1, gbc); - panel.add(label1); - - gbc.gridx = 1; - gbc.gridy = 0; - JTextField formulaText = new JTextField(((FormulaChannelGenerator) ch).getFormula(),15); - layout.setConstraints(formulaText, gbc); - panel.add(formulaText); - - gbc.gridx = 0; - gbc.gridy = 1; - layout.setConstraints(label2, gbc); - panel.add(label2); - - gbc.gridx = 1; - gbc.gridy = 1; - JTextArea textArea = new JTextArea(ch.getSourceText(),7,15); - textArea.setEditable(false); - layout.setConstraints(textArea, gbc); - panel.add(textArea); - - int r = JOptionPane.showConfirmDialog( - null, // owner window - panel, // message - "Edit Formula Channel", // window's title - JOptionPane.OK_CANCEL_OPTION, // option (button types) - JOptionPane.QUESTION_MESSAGE); // message type (icon types) - if(r == JOptionPane.OK_OPTION) { - TokenStream stream = new Parser.TokenStream(); - Parser parser = new Parser(stream); - - String formula = formulaText.getText(); - stream.addLine(formula.split(Parser.EQUALS)[1]); - - try { - Expression exp = parser.parseTerm(stream, editor.getModel()); - ((FormulaChannelGenerator) ch).setFormula(formula); - ((FormulaChannelGenerator) ch).setFormulaTerm(exp); - } catch (ExpectedRightBracket e) { - e.printStackTrace(); - } - } - }else { - JPanel panel = new JPanel(); - JTextArea textArea = new JTextArea(ch.getSourceText(), 10, 20); - panel.add(textArea); - // JEditorPane panel = new JEditorPane("text/plain", ch.toString()); - // panel.setEditable(true); - int ret = JOptionPane.showConfirmDialog(null, panel, "Channel Code", JOptionPane.OK_CANCEL_OPTION); - if (ret == JOptionPane.OK_OPTION) { - editor.setChannelCode(ch, textArea.getText()); - } - } - return; - } - - mxCellState state = graphComponent.getGraph().getView().getState(cell); - if (state != null && state.getLabel() != null && !state.getLabel().equals("")) { - editingCell = cell; - trigger = evt; - - double scale = Math.max(minimumEditorScale, graphComponent.getGraph().getView().getScale()); - Object value = graphComponent.getGraph().getModel().getValue(cell); - if (value != null && value instanceof PushPullAttribute) { - PushPullAttribute attr = (PushPullAttribute) value; - comboBox = new JComboBox<>(attr.getOptionStrings()); - comboBox.setBorder(BorderFactory.createEmptyBorder()); - comboBox.setOpaque(false); - comboBox.setBounds(getEditorBounds(state, scale)); - comboBox.setVisible(true); - graphComponent.getGraphControl().add(comboBox, 0); - comboBox.updateUI(); - } - } - } - - @Override - public void stopEditing(boolean cancel) { - if (editingCell != null) { - comboBox.transferFocusUpCycle(); - Object cell = editingCell; - editingCell = null; - if (!cancel) { - EventObject trig = trigger; - trigger = null; - Object value = graphComponent.getGraph().getModel().getValue(cell); - if (value != null && value instanceof PushPullAttribute) { - PushPullAttribute attr = (PushPullAttribute) value; - List options = attr.getOptions(); - PushPullValue selected = null; - for (PushPullValue option: options) { - if (option.toString().equals(getCurrentValue())) { - selected = option; - break; - } - } - if (selected != null) { - options.remove(selected); - options.add(0, selected); - } - graphComponent.labelChanged(cell, attr, trig); - } - } else { - mxCellState state = graphComponent.getGraph().getView().getState(cell); - graphComponent.redraw(state); - } - - if (comboBox.getParent() != null) { - comboBox.setVisible(false); - comboBox.getParent().remove(comboBox); - } - - graphComponent.requestFocusInWindow(); - } - } - - public String getCurrentValue() { - return (String) comboBox.getSelectedItem(); - } - - /** - * Returns the bounds to be used for the editor. - */ - public Rectangle getEditorBounds(mxCellState state, double scale) { - mxIGraphModel model = state.getView().getGraph().getModel(); - Rectangle bounds = null; - - bounds = state.getLabelBounds().getRectangle(); - bounds.height += 10; - - // Applies the horizontal and vertical label positions - if (model.isVertex(state.getCell())) { - String horizontal = mxUtils.getString(state.getStyle(), mxConstants.STYLE_LABEL_POSITION, mxConstants.ALIGN_CENTER); - - if (horizontal.equals(mxConstants.ALIGN_LEFT)) { - bounds.x -= state.getWidth(); - } else if (horizontal.equals(mxConstants.ALIGN_RIGHT)) { - bounds.x += state.getWidth(); - } - - String vertical = mxUtils.getString(state.getStyle(), - mxConstants.STYLE_VERTICAL_LABEL_POSITION, - mxConstants.ALIGN_MIDDLE); - - if (vertical.equals(mxConstants.ALIGN_TOP)) { - bounds.y -= state.getHeight(); - } else if (vertical.equals(mxConstants.ALIGN_BOTTOM)) { - bounds.y += state.getHeight(); - } - } - - bounds.setSize( - (int) Math.max(bounds.getWidth(), - Math.round(minimumWidth * scale)), - (int) Math.max(bounds.getHeight(), - Math.round(minimumHeight * scale))); - - return bounds; - } - -} diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/views/GraphicalRefactorMenuBar.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/views/GraphicalRefactorMenuBar.java deleted file mode 100644 index 7c0d477..0000000 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/views/GraphicalRefactorMenuBar.java +++ /dev/null @@ -1,93 +0,0 @@ -package graphicalrefactor.views; - -import javax.swing.JMenu; -import javax.swing.JMenuBar; - -import graphicalrefactor.actions.CircleLayoutAction; -import graphicalrefactor.actions.DAGLayoutAction; -import graphicalrefactor.actions.DeleteAction; -import graphicalrefactor.actions.ExitAction; -import graphicalrefactor.actions.JavaPrototypeGenerateAction; -import graphicalrefactor.actions.JerseyPrototypeGenerateAction; -import graphicalrefactor.actions.NewChannelAction; -import graphicalrefactor.actions.NewFormulaChannelAction; -import graphicalrefactor.actions.NewIOChannelAction; -import graphicalrefactor.actions.NewModelAction; -import graphicalrefactor.actions.NewResourceAction; -import graphicalrefactor.actions.OpenAction; -import graphicalrefactor.actions.SaveAction; -import graphicalrefactor.actions.SaveAsAction; -import graphicalrefactor.actions.TreeLayoutAction; -import graphicalrefactor.actions.ZoomInAction; -import graphicalrefactor.actions.ZoomOutAction; -import graphicalrefactor.editor.Editor; - -public class GraphicalRefactorMenuBar extends JMenuBar { - private static final long serialVersionUID = 4811536194182272888L; - - private GraphicalRefactor graphicalModelRefactor = null; - private NewResourceAction newResourceAction = null; - private NewChannelAction newChannelAction = null; - private NewIOChannelAction newIOChannelAction = null; - private NewFormulaChannelAction newFormulaChannelAction = null; - private DeleteAction deleteAction = null; - private JavaPrototypeGenerateAction javaPrototypeGenerateAction = null; - private JerseyPrototypeGenerateAction jerseyPrototypeGenerateAction = null; - private DAGLayoutAction dagLayoutAction = null; - private TreeLayoutAction treeLayoutAction = null; - private CircleLayoutAction circleLayoutAction = null; - - public GraphicalRefactorMenuBar(GraphicalRefactor graphicalModelRefactor) { - this.graphicalModelRefactor = graphicalModelRefactor; - JMenu newMenu = new JMenu("New"); - - newMenu.add(new NewModelAction(graphicalModelRefactor)); - - newMenu.add(newResourceAction = new NewResourceAction(graphicalModelRefactor.getEditor())); - newMenu.add(newChannelAction = new NewChannelAction(graphicalModelRefactor.getEditor())); - newMenu.add(newIOChannelAction = new NewIOChannelAction(graphicalModelRefactor.getEditor())); - newMenu.add(newFormulaChannelAction = new NewFormulaChannelAction(graphicalModelRefactor.getEditor())); - - JMenu menu = null; - menu = add(new JMenu("File")); - menu.add(newMenu); - menu.add(new OpenAction(graphicalModelRefactor)); - menu.addSeparator(); - menu.add(new SaveAction(graphicalModelRefactor)); - menu.add(new SaveAsAction(graphicalModelRefactor)); - menu.addSeparator(); - menu.add(new ExitAction()); - - menu = add(new JMenu("Edit")); - menu.add(deleteAction = new DeleteAction(graphicalModelRefactor.getEditor())); - - - menu = add(new JMenu("Layout")); - menu.add(dagLayoutAction = new DAGLayoutAction(graphicalModelRefactor.getEditor())); - menu.add(treeLayoutAction = new TreeLayoutAction(graphicalModelRefactor.getEditor())); - menu.add(circleLayoutAction = new CircleLayoutAction(graphicalModelRefactor.getEditor())); - - menu = add(new JMenu("View")); - menu.add(new ZoomInAction(graphicalModelRefactor.getGraphComponent())); - menu.add(new ZoomOutAction(graphicalModelRefactor.getGraphComponent())); - - menu = add(new JMenu("Generate")); - menu.add(javaPrototypeGenerateAction = new JavaPrototypeGenerateAction(graphicalModelRefactor.getEditor())); - menu.add(jerseyPrototypeGenerateAction = new JerseyPrototypeGenerateAction(graphicalModelRefactor.getEditor())); - } - - public Editor getEditor() { - return graphicalModelRefactor.getEditor(); - } - - public void setEditor(Editor editor) { - newResourceAction.setEditor(editor); - newChannelAction.setEditor(editor); - newIOChannelAction.setEditor(editor); - deleteAction.setEditor(editor); - javaPrototypeGenerateAction.setEditor(editor); - jerseyPrototypeGenerateAction.setEditor(editor); - treeLayoutAction.setEditor(editor); - circleLayoutAction.setEditor(editor); - } -} diff --git a/AlgebraicDataflowArchitectureModel/src/models/DirectedGraph.java b/AlgebraicDataflowArchitectureModel/src/models/DirectedGraph.java index 3b9d1d3..42b7208 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/DirectedGraph.java +++ b/AlgebraicDataflowArchitectureModel/src/models/DirectedGraph.java @@ -64,4 +64,8 @@ edge.getSource().removeOutEdge(edge); edge.getDestination().removeInEdge(edge); } + + protected void simpleAddEdge(Edge edge) { + edges.add(edge); + } }