diff --git a/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java b/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java index e3fdbe6..2651c23 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java +++ b/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java @@ -16,8 +16,8 @@ import com.mxgraph.util.mxEventSource.mxIEventListener; import com.mxgraph.view.mxGraph; -import application.editor.DataFlowCellEditor; import application.editor.Editor; +import application.editor.stages.DataFlowCellEditor; import application.views.NavigationWindow; public class ApplicationWindow extends JFrame { @@ -26,15 +26,16 @@ private Editor editor; private mxGraph graph; + private mxGraphComponent graphComponent; + private ApplicationMenuBar menuBar; private NavigationWindow navigationWindow; - private mxGraphComponent graphComponent; public ApplicationWindow() { setTitle(title); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - graph = new mxGraph() { + this.graph = new mxGraph() { public boolean isPort(Object cell) { mxGeometry geo = getCellGeometry(cell); @@ -46,13 +47,10 @@ } }; - editor = new Editor(graph); + this.graphComponent = new mxGraphComponent(graph); - graphComponent = new mxGraphComponent(graph) { - protected mxICellEditor createCellEditor() { - return new DataFlowCellEditor(this, editor); - } - }; + this.editor = new Editor(graphComponent); + graph.getModel().addListener(mxEvent.CHANGE, new mxIEventListener() { public void invoke(Object sender, mxEventObject evt) { List terminals = new ArrayList<>(); diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/DataFlowCellEditor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/DataFlowCellEditor.java deleted file mode 100644 index 25fbd20..0000000 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/DataFlowCellEditor.java +++ /dev/null @@ -1,248 +0,0 @@ -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 DataFlowCellEditor 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 DataFlowCellEditor(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 index 82450a8..c255db9 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java @@ -19,6 +19,8 @@ import com.mxgraph.model.mxCell; import com.mxgraph.model.mxGraphModel; import com.mxgraph.model.mxIGraphModel; +import com.mxgraph.swing.mxGraphComponent; +import com.mxgraph.swing.view.mxICellEditor; import com.mxgraph.util.mxConstants; import com.mxgraph.view.mxCellState; import com.mxgraph.util.mxRectangle; @@ -28,6 +30,7 @@ import algorithms.DataTransferModelAnalyzer; import algorithms.Validation; import application.editor.stages.ControlFlowDelegationStage; +import application.editor.stages.DataFlowCellEditor; import application.editor.stages.DataFlowModelingStage; import application.editor.stages.PushPullSelectionStage; import application.layouts.*; @@ -67,6 +70,7 @@ public class Editor { public DataTransferModel model = null; public mxGraph graph = null; + private mxGraphComponent graphComponent = null; protected Stage curStage = null; protected List stageQueue = null; @@ -80,16 +84,22 @@ public static PushPullSelectionStage STAGE_PUSH_PULL_SELECTION = null; public static ControlFlowDelegationStage STAGE_CONTROL_FLOW_DELEGATION = null; - public Editor(mxGraph graph) { - this.graph = graph; - stageQueue = new ArrayList<>(); + public Editor(mxGraphComponent graphComponent) { + this.graphComponent = graphComponent; + this.graph = graphComponent.getGraph(); + STAGE_DATA_FLOW_MODELING = new DataFlowModelingStage(graph); STAGE_PUSH_PULL_SELECTION = new PushPullSelectionStage(graph); STAGE_CONTROL_FLOW_DELEGATION = new ControlFlowDelegationStage(graph); + + graphComponent.setCellEditor(STAGE_DATA_FLOW_MODELING.createCellEditor(graphComponent)); + + stageQueue = new ArrayList<>(); stageQueue.add(STAGE_DATA_FLOW_MODELING); stageQueue.add(STAGE_PUSH_PULL_SELECTION); stageQueue.add(STAGE_CONTROL_FLOW_DELEGATION); curStage = STAGE_DATA_FLOW_MODELING; + stageChangeListeners = new ArrayList<>(); } @@ -97,6 +107,10 @@ return graph; } + public mxGraphComponent getGraphComponent() { + return this.graphComponent; + } + public DataTransferModel getModel() { model = curStage.getModel(); return model; @@ -119,6 +133,7 @@ public boolean changeStage(Stage nextStage) { if (!nextStage.canChangeFrom(curStage)) return false; nextStage.init(curStage); + graphComponent.setCellEditor(nextStage.createCellEditor(graphComponent)); curStage = nextStage; return true; } @@ -450,15 +465,6 @@ notifyStageChangeListeners(); } - public void setChannelCode(DataTransferChannelGenerator ch, String code) { - // Force to change to the data-flow modeling stage. - boolean stageChanged = changeStage(STAGE_DATA_FLOW_MODELING); - if (!stageChanged) return; - notifyStageChangeListeners(); - - ((DataFlowModelingStage) curStage).setChannelCode(ch, code); - } - public static class SrcDstAttribute extends EdgeAttribute { private Object src; private Object dst; diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java index 46e3b6b..642c492 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java @@ -1,5 +1,7 @@ package application.editor; +import com.mxgraph.swing.mxGraphComponent; +import com.mxgraph.swing.view.mxICellEditor; import com.mxgraph.view.mxGraph; import models.dataFlowModel.DataTransferModel; @@ -18,4 +20,5 @@ abstract public boolean canChangeFrom(Stage prevStage); abstract public void init(Stage prevStage); + abstract public mxICellEditor createCellEditor(mxGraphComponent graphComponent); } diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java index d4c0538..4ded42d 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java @@ -1,29 +1,165 @@ package application.editor.stages; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.util.HashMap; +import java.util.Map; + +import com.mxgraph.model.mxCell; +import com.mxgraph.model.mxGeometry; +import com.mxgraph.model.mxGraphModel; +import com.mxgraph.swing.mxGraphComponent; +import com.mxgraph.swing.mxGraphComponent.mxGraphControl; +import com.mxgraph.swing.view.mxICellEditor; +import com.mxgraph.util.mxConstants; +import com.mxgraph.util.mxPoint; import com.mxgraph.view.mxGraph; +import application.editor.Editor; import application.editor.Stage; +import application.editor.Editor.SrcDstAttribute; +import application.editor.FlowCellEditor; +import models.Edge; +import models.Node; +import models.controlFlowModel.CallEdge; +import models.controlFlowModel.ControlFlowGraph; +import models.controlFlowModel.ObjectNode; +import models.controlFlowModel.StatefulObjectNode; +import models.dataConstraintModel.ChannelGenerator; +import models.dataConstraintModel.IdentifierTemplate; import models.dataFlowModel.DataFlowGraph; +import models.dataFlowModel.DataTransferChannelGenerator; +import models.dataFlowModel.DataTransferModel; +import models.dataFlowModel.ResourceNode; public class ControlFlowDelegationStage extends Stage { - private DataFlowGraph dataFlowGraph; + public final int PORT_DIAMETER = 8; + public final int PORT_RADIUS = PORT_DIAMETER / 2; + private ControlFlowGraph controlFlowGraph = null; + + /**-------------------------------------------------------------------------------- + * [ *constructor ] + /*-------------------------------------------------------------------------------- + * + * @param graph + */ public ControlFlowDelegationStage(mxGraph graph) { super(graph); } + /**-------------------------------------------------------------------------------- + * [ *public ] + /**-------------------------------------------------------------------------------- + * + * @return + */ @Override public boolean canChangeFrom(Stage prevStage) { if (prevStage instanceof PushPullSelectionStage) return true; return false; } + /**-------------------------------------------------------------------------------- + * + */ @Override public void init(Stage prevStage) { if (prevStage instanceof PushPullSelectionStage) { model = ((PushPullSelectionStage) prevStage).getModel(); - dataFlowGraph = ((PushPullSelectionStage) prevStage).getDataFlowGraph(); + + DataFlowGraph dataFlowGraph = ((PushPullSelectionStage) prevStage).getDataFlowGraph(); + controlFlowGraph = new ControlFlowGraph(dataFlowGraph); + +// graph = constructGraph(graph, model); + // First, a mouse-event is "Showing delegatable Objects". + // curMouseAdapter = new SelectingACallEdgeAction(); + + // removeExistingDelegationMouseListener(graphComponent.getGraphControl(), curMouseAdapter); + // graphComponent.getGraphControl().addMouseListener(curMouseAdapter); } } + + /**-------------------------------------------------------------------------------- + * + */ + @Override + public FlowCellEditor createCellEditor(mxGraphComponent graphComponent) { + return new ControlFlowDelegationCellEditor(this, graphComponent); + } + /**-------------------------------------------------------------------------------- + /* [ *private ] + /**-------------------------------------------------------------------------------- + * remove an existing mouse event handler which is used in Control-Flow-Delegation Stage. + * @param graphControl + * @param mouseHandler + */ + private void removeExistingDelegationMouseListener(mxGraphControl graphControl, MouseAdapter mouseHandler) { + if(graphControl.getMouseListeners().length <= 0) return; + + for(MouseListener listener : graphControl.getMouseListeners()) { + if(listener.getClass().equals(mouseHandler.getClass())) + graphControl.removeMouseListener(listener); + } + } + + /**-------------------------------------------------------------------------------- + * Construct a mxGraph from DataFlowModel + * @param model + * @param dataFlowGraph + * @return constructed mxGraph + */ + public mxGraph constructGraph(mxGraph graph, DataTransferModel model) { + return graph; + } + + /**-------------------------------------------------------------------------------- + * [ *handler ] + /**-------------------------------------------------------------------------------- + * 委譲する基点となる呼び出し辺(データフロー)の選択 + */ + public class SelectingACallEdgeAction extends MouseAdapter { + private StatefulObjectNode statefulObjNode = null; + private mxGraphComponent graphComponent = null; + + /**-------------------------------------------------------------------------------- + * [ *constructor ] + /**-------------------------------------------------------------------------------- + * + */ + public SelectingACallEdgeAction(mxGraphComponent graphComponent) { + this.graphComponent = graphComponent; + } + + /**-------------------------------------------------------------------------------- + * + /**-------------------------------------------------------------------------------- + * + */ + @Override + public void mouseClicked(MouseEvent e) { + mxCell cell = graphComponent.getCellAt(e.getX(), e.getY()) instanceof mxCell + ? (mxCell) graphComponent.getCellAt(e.getX(), e.getY()) + : null; + if(cell == null) return; + + String resourceName = graph.getModel().getValue(cell) instanceof String + ? graph.getModel().getValue(cell).toString() + : null; + if(resourceName == null) return; + + IdentifierTemplate identifireTemplate = model.getIdentifierTemplate(resourceName); + if(identifireTemplate == null) return; + + ResourceNode resNode = controlFlowGraph.getDataFlowGraph().getResouceNode(identifireTemplate); + + // + // statefulObjNode = controlFlowGraph. + + System.out.println("show: " + identifireTemplate.getResourceName()); + } + } + } diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowCellEditor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowCellEditor.java new file mode 100644 index 0000000..0dfe0b4 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowCellEditor.java @@ -0,0 +1,246 @@ +package application.editor.stages; + +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 application.editor.Editor; +import application.editor.FlowCellEditor; +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 DataFlowCellEditor extends FlowCellEditor { + 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; + + public DataFlowCellEditor(DataFlowModelingStage stage, mxGraphComponent graphComponent) { + super(stage, graphComponent); + } + + @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)) { + DataTransferChannelGenerator ch = (DataTransferChannelGenerator) stage.getModel().getChannelGenerator((String) ((mxCell) cell).getValue()); + if (ch == null) { + ch = (DataTransferChannelGenerator) stage.getModel().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, stage.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) { + ((DataFlowModelingStage)stage).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/stages/DataFlowModelingStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java index d1d92e9..b63196a 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java @@ -2,17 +2,21 @@ import java.util.HashMap; import java.util.Map; +import java.util.concurrent.Flow; import com.mxgraph.model.mxCell; import com.mxgraph.model.mxGeometry; import com.mxgraph.model.mxGraphModel; +import com.mxgraph.swing.mxGraphComponent; +import com.mxgraph.swing.view.mxICellEditor; import com.mxgraph.util.mxPoint; import com.mxgraph.view.mxGraph; import algorithms.Validation; -import application.editor.Stage; -import application.editor.Editor; import application.editor.Editor.SrcDstAttribute; +import application.editor.FlowCellEditor; +import application.editor.Editor; +import application.editor.Stage; import models.dataConstraintModel.ChannelGenerator; import models.dataConstraintModel.ChannelMember; import models.dataConstraintModel.IdentifierTemplate; @@ -50,6 +54,11 @@ public void init(Stage prevStage) { } + @Override + public FlowCellEditor createCellEditor(mxGraphComponent graphComponent) { + return new DataFlowCellEditor(this, graphComponent); + } + public void clear() { model = null; ((mxGraphModel) graph.getModel()).clear(); @@ -106,6 +115,7 @@ 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); @@ -126,15 +136,15 @@ 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"); + graph.insertEdge(parent, null, new SrcDstAttribute(srcRes, channelGen), resources.get(srcRes), channelsIn.get(channelGen), "movable=false;strokeColor=#FF0000"); } // output edge for (IdentifierTemplate dstRes: channelGen.getOutputIdentifierTemplates()) { - graph.insertEdge(parent, null, new SrcDstAttribute(channelGen, dstRes), channelsOut.get(channelGen), resources.get(dstRes), "movable=false"); + graph.insertEdge(parent, null, new SrcDstAttribute(channelGen, dstRes), channelsOut.get(channelGen), resources.get(dstRes), "movable=false;strokeColor=#FF0000"); } // reference edges for (IdentifierTemplate refRes: channelGen.getReferenceIdentifierTemplates()) { - graph.insertEdge(parent, null, null, resources.get(refRes), channelsIn.get(channelGen), "dashed=true;movable=false"); + graph.insertEdge(parent, null, null, resources.get(refRes), channelsIn.get(channelGen), "dashed=true;movable=false;strokeColor=#FF0000"); } } @@ -146,7 +156,7 @@ 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"); + graph.insertEdge(parent, null, null, port_out, resources.get(outRes), "movable=false;strokeColor=#FF0000"); } } } diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java index 3030100..ca248e2 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java @@ -1,11 +1,15 @@ package application.editor.stages; import com.mxgraph.model.mxCell; +import com.mxgraph.swing.mxGraphComponent; +import com.mxgraph.swing.view.mxICellEditor; import com.mxgraph.view.mxGraph; import algorithms.DataTransferModelAnalyzer; +import application.editor.Editor; import application.editor.Stage; import application.editor.Editor.SrcDstAttribute; +import application.editor.FlowCellEditor; import models.Edge; import models.dataFlowModel.DataFlowEdge; import models.dataFlowModel.DataFlowGraph; @@ -37,6 +41,11 @@ dataFlowGraph = analyzeDataTransferModel(graph, model); } } + + @Override + public FlowCellEditor createCellEditor(mxGraphComponent graphComponent) { + return new PushPullSelectionCellEditor(this, graphComponent); + } public DataFlowGraph getDataFlowGraph() { return dataFlowGraph; diff --git a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowDelegator.java b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowDelegator.java index c0dc8fb..b958591 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowDelegator.java +++ b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowDelegator.java @@ -1,12 +1,19 @@ package models.controlFlowModel; +import java.util.ArrayList; + +import models.Node; +import models.dataFlowModel.PushPullAttribute; +import models.dataFlowModel.PushPullValue; + + /**-------------------------------------------------------------------------------- - * + * it has Delegation of Control-Flow algorithm. */ public class ControlFlowDelegator { /**-------------------------------------------------------------------------------- - * + * [ *public ] /**-------------------------------------------------------------------------------- * * Todo: @@ -14,7 +21,26 @@ * 2. mxGraphを再構築? * 3. mxGraphModelから委譲可能なmxCellのリストと */ - public void changeGraph() { + public void changeControlFlowGraph() { } + + /**-------------------------------------------------------------------------------- + * + *@param callEdge + */ + public ArrayList searchDelegatableNodes(final CallEdge callEdge){ + ArrayList nodes = new ArrayList<>(); + + Node parentNode = callEdge.getSource(); + if(parentNode == null) return null; + + PushPullAttribute pushPullAttribute = (PushPullAttribute)callEdge.getAttribute(); + if( pushPullAttribute == null) return null; + if( !(pushPullAttribute instanceof PushPullAttribute) ) return null; + + // switch objects by transfer type + + return null; + } } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowGraph.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowGraph.java index 5df4229..861a51c 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowGraph.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowGraph.java @@ -37,4 +37,9 @@ } addEdge(new DataFlowEdge(srcNode, dstNode, dfChannelGen)); } + + public ResourceNode getResouceNode(IdentifierTemplate identifierTemplate) { + if(nodeMap.get(identifierTemplate) == null) throw new NullPointerException(identifierTemplate.getResourceName() + "was not found."); + return nodeMap.get(identifierTemplate); + } } diff --git a/AlgebraicDataflowArchitectureModel/src/tests/controlFlowModel/ControlFlowDelegatorTest.java b/AlgebraicDataflowArchitectureModel/src/tests/controlFlowModel/ControlFlowDelegatorTest.java deleted file mode 100644 index c29e7fe..0000000 --- a/AlgebraicDataflowArchitectureModel/src/tests/controlFlowModel/ControlFlowDelegatorTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package tests.controlFlowModel; - -import org.junit.Test; - -import models.dataConstraintModel.IdentifierTemplate; -import models.dataFlowModel.DataTransferModel; - -import static org.junit.Assert.*; - - -/**-------------------------------------------------------------------------------- - * - */ -public class ControlFlowDelegatorTest { - @Test - public void test() { - // Construct a data-flow architecture model. - DataTransferModel model = new DataTransferModel(); - IdentifierTemplate customer_off = new IdentifierTemplate("customers.{x1}.off", 1); // an identifier template to specify a customer's office resource - IdentifierTemplate company_add = new IdentifierTemplate("companies.{x2}.add", 1); // an identifier template to specify a companie's address resource - IdentifierTemplate customer_add = new IdentifierTemplate("customers.{x1}.add", 1); // an identifier template to specify a customer's address resource - - - - } -}