diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewChannelAction.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewChannelAction.java index dca44dc..153ebdf 100644 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewChannelAction.java +++ b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewChannelAction.java @@ -25,11 +25,6 @@ @Override public void actionPerformed(ActionEvent e) { - DataFlowModel model = editor.getModel(); - if(model == null) { - model = new DataFlowModel(); - editor.setModel(model); - } String channelName = JOptionPane.showInputDialog("Channel Name:"); if (channelName == null) return; editor.addChannelGenerator(new DataflowChannelGenerator(channelName)); diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewIOChannelAction.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewIOChannelAction.java index e1016d2..06f828d 100644 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewIOChannelAction.java +++ b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewIOChannelAction.java @@ -24,11 +24,6 @@ @Override public void actionPerformed(ActionEvent e) { - DataFlowModel model = editor.getModel(); - if(model == null) { - model = new DataFlowModel(); - editor.setModel(model); - } String channelName = JOptionPane.showInputDialog("I/O Channel Name:"); if (channelName == null) return; editor.addIOChannelGenerator(new DataflowChannelGenerator(channelName)); diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewResourceAction.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewResourceAction.java index ac7622f..cb24554 100644 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewResourceAction.java +++ b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/actions/NewResourceAction.java @@ -24,11 +24,6 @@ @Override public void actionPerformed(ActionEvent e) { - DataFlowModel model = editor.getModel(); - if(model == null) { - model = new DataFlowModel(); - editor.setModel(model); - } String resName = JOptionPane.showInputDialog("Resourece Name:"); if (resName == null) return; editor.addIdentifierTemplate(new IdentifierTemplate(resName, 0)); diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/editor/Editor.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/editor/Editor.java index 1a05174..34d3d66 100644 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/editor/Editor.java +++ b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/editor/Editor.java @@ -44,6 +44,7 @@ import parser.ExpectedRightBracket; import parser.ExpectedStateTransition; import parser.Parser; +import parser.Parser.TokenStream; import parser.WrongLHSExpression; import parser.WrongRHSExpression; @@ -70,16 +71,28 @@ } public DataFlowModel getModel() { + if (model == null) { + model = new DataFlowModel(); + } return model; } - public void setModel(DataFlowModel model) { - this.model = model; + public ResourceDependencyGraph getResourceDependencyGraph() { + if (resourceDependencyGraph == null) { + updateResourceDependencyGraph(getModel()); + } + return resourceDependencyGraph; } - public ResourceDependencyGraph getResourceDependencyGraph() { + public ResourceDependencyGraph updateResourceDependencyGraph(DataFlowModel model) { + ResourceDependencyGraph resourceGraph = NecessityOfStoringResourceStates.doDecide(model); + resourceDependencyGraph = SelectableDataTransfers.init(resourceGraph); return resourceDependencyGraph; } + + public void resetResourceDependencyGraph() { + resourceDependencyGraph = null; + } public void setResourceDependencyGraph(ResourceDependencyGraph resourceDependencyGraph) { this.resourceDependencyGraph = resourceDependencyGraph; @@ -94,6 +107,9 @@ } public String getCurFileName() { + if (curFileName == null) { + curFileName = "notitle"; + } return curFileName; } @@ -109,9 +125,7 @@ model = parser.doParse(); curFileName = file.getName(); if (!UpdateConflictCheck.run(model)) return null; - ResourceDependencyGraph resourceGraph = NecessityOfStoringResourceStates.doDecide(model); - resourceDependencyGraph = SelectableDataTransfers.init(resourceGraph); - graph = constructGraph(model, resourceDependencyGraph); + graph = constructGraph(model, updateResourceDependencyGraph(model)); return model; } catch (ExpectedChannel | ExpectedChannelName | ExpectedLeftCurlyBracket | ExpectedInOrOutOrRefKeyword | ExpectedStateTransition | ExpectedEquals | ExpectedRHSExpression | WrongLHSExpression @@ -260,7 +274,8 @@ } public void addIdentifierTemplate(IdentifierTemplate res) { - model.addIdentifierTemplate(res); + getModel().addIdentifierTemplate(res); + resetResourceDependencyGraph(); graph.getModel().beginUpdate(); Object parent = graph.getDefaultParent(); try { @@ -272,7 +287,8 @@ } public void addChannelGenerator(DataflowChannelGenerator channelGen) { - model.addChannelGenerator(channelGen); + getModel().addChannelGenerator(channelGen); + resetResourceDependencyGraph(); graph.getModel().beginUpdate(); Object parent = graph.getDefaultParent(); try { @@ -297,7 +313,8 @@ } public void addIOChannelGenerator(DataflowChannelGenerator ioChannelGen) { - model.addIOChannelGenerator(ioChannelGen); + getModel().addIOChannelGenerator(ioChannelGen); + resetResourceDependencyGraph(); graph.getModel().beginUpdate(); Object parent = graph.getDefaultParent(); try { @@ -315,6 +332,7 @@ } public boolean connectEdge(mxCell src, mxCell dst) { + DataFlowModel model = getModel(); ChannelGenerator srcCh = model.getChannelGenerator((String) src.getValue()); if (srcCh == null) { srcCh = model.getIOChannelGenerator((String) src.getValue()); @@ -324,6 +342,7 @@ if (srcRes == null || dstCh == null) return false; ChannelMember srcCm = new ChannelMember(srcRes); ((DataflowChannelGenerator ) dstCh).addChannelMemberAsInput(srcCm); + resetResourceDependencyGraph(); return true; } } @@ -331,6 +350,46 @@ if (dstRes == null) return false; ChannelMember dstCm = new ChannelMember(dstRes); ((DataflowChannelGenerator) srcCh).addChannelMemberAsOutput(dstCm); + resetResourceDependencyGraph(); return true; } + + public void setChannelCode(DataflowChannelGenerator ch, String code) { + TokenStream stream = new TokenStream(); + for (String line: code.split("\n")) { + stream.addLine(line); + } + try { + DataflowChannelGenerator ch2 = Parser.parseChannel(stream, 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; + } + } + } + resetResourceDependencyGraph(); + } catch (ExpectedRightBracket | ExpectedChannel | ExpectedChannelName | ExpectedLeftCurlyBracket + | ExpectedInOrOutOrRefKeyword | ExpectedStateTransition | ExpectedEquals | ExpectedRHSExpression + | WrongLHSExpression | WrongRHSExpression | ExpectedAssignment e) { + e.printStackTrace(); + } + } } diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/views/GraphicalRefactorCellEditor.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/views/GraphicalRefactorCellEditor.java index 707c883..07cfc9f 100644 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/views/GraphicalRefactorCellEditor.java +++ b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/views/GraphicalRefactorCellEditor.java @@ -6,7 +6,10 @@ import javax.swing.BorderFactory; import javax.swing.JComboBox; +import javax.swing.JEditorPane; import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextArea; import com.mxgraph.model.mxCell; import com.mxgraph.model.mxIGraphModel; @@ -63,7 +66,15 @@ return; } } - String code = JOptionPane.showInputDialog("Channel Code:"); + JPanel panel = new JPanel(); + JTextArea textArea = new JTextArea(ch.toString(), 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; }