Merge branch 'interfaces' into htmlGUi
commit 0308d35e7d97007563924332fa4a3e3cd44fba47
2 parents 3782003 + dac98ed
Sakoda2269 authored on 19 Sep
Showing 4 changed files
View
115
AlgebraicDataflowArchitectureModel/src/application/simulator/InputEventCellEditor.java
private Simulator simulator;
private JComboBox<String> pulldownMenu;
private Editor editor;
private boolean bReflectingArchitectureModel = false;
private mxGraph graph;
public InputEventCellEditor(mxGraphComponent graphComponent, Simulator simulator, Editor editor, mxGraph graph) {
public InputEventCellEditor(mxGraphComponent graphComponent, Simulator simulator, Editor editor) {
this.graphComponent = graphComponent;
this.simulator = simulator;
this.editor = editor;
this.graph = graph;
}
 
@Override
public Object getEditingCell() {
Event newEvent = new Event(eventChs.get(eventNum), eventMessage, eventResPath, simulator.getCurState().getResource(resId));
simulator.transition(newEvent);
 
SimulationLayout layout = new SimulationLayout(simulator.getCurState());
layout.constructSimulateGraph(graph, simulator);
 
graphComponent.setCellEditor(new InputEventCellEditor(graphComponent, simulator, this.editor, graph));
// SimulationLayout layout = new SimulationLayout(simulator.getCurState());
// layout.constructSimulateGraph(graph, simulator);
 
graphComponent.setCellEditor(new InputEventCellEditor(graphComponent, simulator, this.editor));
} catch (ParameterizedIdentifierIsFutureWork | ResolvingMultipleDefinitionIsFutureWork
| InvalidMessage | UnificationFailed | ValueUndefined | ExpectedRightBracket | WrongJsonExpression | ExpectedColon e) {
e.printStackTrace();
}
}
}
 
private mxGraph constructNextSimulateGraph(Set<Resource> simulateRes, DataTransferModel model,DataFlowGraph dataFlowGraph, mxGraph nextGraph) {
bReflectingArchitectureModel = true;
((mxGraphModel) nextGraph.getModel()).clear();
Object parent = nextGraph.getDefaultParent();
nextGraph.getModel().beginUpdate();
 
try {
Map<Resource, Object> resources = new HashMap<>();
 
// create resource vertices
for (Resource resNode: simulateRes) {
int w = 400;
int h = 150;
ResourcePath res = resNode.getResourceIdentifier();
Object resource = nextGraph.insertVertex(parent, null,
res.toString(), x, y, w, h,
"shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top;"); // insert a resource as a vertex
resources.put(resNode, resource);
 
createNextChildSimulateResourceVerticies(resource, resNode, resources, w, h);
x+=400;
}
 
} finally {
nextGraph.getModel().endUpdate();
}
 
bReflectingArchitectureModel = false;
return nextGraph;
}
 
private void createNextChildSimulateResourceVerticies(Object resource, Resource resNode, Map<Resource, Object> resources, int w, int h) { //sample
if(resNode.getChildren() != null) {
for (Resource childNode: resNode.getChildren()) {
int i = 1;
ResourcePath childRes = childNode.getResourceIdentifier();
Object childResource = graph.insertVertex(resource, null,
childRes.toString(), x/i, 0, w/(i+1), h/(i+2),
"shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top;"); // insert a resource as a vertex
resources.put(childNode, childResource);
i++;
createNextChildSimulateResourceVerticies(childResource, childNode, resources, w, h);
}
}
if (resNode.getChildren() == null || resNode.getChildren().size() == 0) {
Object state = graph.insertVertex(resource, null,
resNode.getState().getValue().toString(), 0.5, 0.5, 0.25, 0.25, "opacity=0;verticalAlign=down;", true); // insert a state label as a vertex
}
}
// private mxGraph constructNextSimulateGraph(Set<Resource> simulateRes, DataTransferModel model,DataFlowGraph dataFlowGraph, mxGraph nextGraph) {
// bReflectingArchitectureModel = true;
// ((mxGraphModel) nextGraph.getModel()).clear();
// Object parent = nextGraph.getDefaultParent();
// nextGraph.getModel().beginUpdate();
//
// try {
// Map<Resource, Object> resources = new HashMap<>();
//
// // create resource vertices
// for (Resource resNode: simulateRes) {
// int w = 400;
// int h = 150;
// ResourcePath res = resNode.getResourceIdentifier();
// Object resource = nextGraph.insertVertex(parent, null,
// res.toString(), x, y, w, h,
// "shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top;"); // insert a resource as a vertex
// resources.put(resNode, resource);
//
// createNextChildSimulateResourceVerticies(resource, resNode, resources, w, h);
// x+=400;
// }
//
// } finally {
// nextGraph.getModel().endUpdate();
// }
//
// bReflectingArchitectureModel = false;
// return nextGraph;
// }
//
// private void createNextChildSimulateResourceVerticies(Object resource, Resource resNode, Map<Resource, Object> resources, int w, int h) { //sample
//
// if(resNode.getChildren() != null) {
// for (Resource childNode: resNode.getChildren()) {
// int i = 1;
// ResourcePath childRes = childNode.getResourceIdentifier();
// Object childResource = graph.insertVertex(resource, null,
// childRes.toString(), x/i, 0, w/(i+1), h/(i+2),
// "shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top;"); // insert a resource as a vertex
// resources.put(childNode, childResource);
// i++;
// createNextChildSimulateResourceVerticies(childResource, childNode, resources, w, h);
// }
// }
// if (resNode.getChildren() == null || resNode.getChildren().size() == 0) {
// Object state = graph.insertVertex(resource, null,
// resNode.getState().getValue().toString(), 0.5, 0.5, 0.25, 0.25, "opacity=0;verticalAlign=down;", true); // insert a state label as a vertex
// }
// }
 
@Override
public void stopEditing(boolean cancel) {
if (editingCell != null) {
View
124
AlgebraicDataflowArchitectureModel/src/application/simulator/SimulatorWindow.java
import simulator.Event;
import simulator.Resource;
import simulator.ResourceIdentifier;
import simulator.Simulator;
 
public class SimulatorWindow extends JFrame{
import simulator.SystemState;
import simulator.interfaces.INativeReceiver;
 
public class SimulatorWindow extends JFrame implements INativeReceiver {
 
private static final long serialVersionUID = -2425820512017088254L;
public static final String title = "Simulation Tool";
 
TypeInference.infer(model);
simulator = new Simulator(model);
SimulationLayout layout = new SimulationLayout(simulator.getCurState());
layout.constructSimulateGraph(graph, simulator);
graphComponent.setCellEditor(new InputEventCellEditor(graphComponent, simulator, this.editor, graph));
graphComponent.setCellEditor(new InputEventCellEditor(graphComponent, simulator, this.editor));
simulator.addSystemReceiver(this);
menuBar = new SimulatorMenuBar(this);
setJMenuBar(menuBar);
}
 
public mxGraph constructSimulateGraph(Set<Resource> simulateRes, DataTransferModel model, DataFlowGraph dataFlowGraph) {
bReflectingArchitectureModel = true;
((mxGraphModel) graph.getModel()).clear();
Object parent = graph.getDefaultParent();
graph.getModel().beginUpdate();
 
try {
Map<Resource, Object> resources = new HashMap<>();
 
// create resource vertices
for (Resource resNode: simulateRes) {
int w = 80;
int h = 30;
ResourcePath res = resNode.getResourceIdentifier();
Object resource = graph.insertVertex(parent, null,
res.toString(), x, y, w, h,
"shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top;"); // insert a resource as a vertex
resources.put(resNode, resource);
createChildSimulateResourceVerticies(resource, resNode, resources, w, h);
x+=80;
}
 
} finally {
graph.getModel().endUpdate();
}
 
bReflectingArchitectureModel = false;
return graph;
}
public void createChildSimulateResourceVerticies(Object resource, Resource resNode, Map<Resource, Object> resources, int w, int h) { //sample
if(resNode.getChildren() != null) {
for (Resource childNode: resNode.getChildren()) {
ResourcePath childRes = childNode.getResourceIdentifier();
Object childResource = graph.insertVertex(resource, null,
childRes.toString(), 0, 0, w/2, h/2,
"shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top;"); // insert a resource as a vertex
resources.put(childNode, childResource);
createChildSimulateResourceVerticies(childResource, childNode, resources, w, h);
}
}
if (resNode.getChildren() == null || resNode.getChildren().size() == 0) {
Object state = graph.insertVertex(resource, null,
resNode.getState().getValue().toString(), 0.5, 0.5, 0.25, 0.25, "opacity=0;verticalAlign=down;", true); // insert a state label as a vertex
}
}
 
@Override
public void onReceiveFromModel(Event event, SystemState nextSystemState) {
SimulationLayout layout = new SimulationLayout(nextSystemState);
layout.constructSimulateGraph(graph, simulator);
}
 
// public mxGraph constructSimulateGraph(Set<Resource> simulateRes, DataTransferModel model, DataFlowGraph dataFlowGraph) {
// bReflectingArchitectureModel = true;
// ((mxGraphModel) graph.getModel()).clear();
// Object parent = graph.getDefaultParent();
// graph.getModel().beginUpdate();
//
// try {
// Map<Resource, Object> resources = new HashMap<>();
//
// // create resource vertices
// for (Resource resNode: simulateRes) {
// int w = 80;
// int h = 30;
// ResourcePath res = resNode.getResourceIdentifier();
// Object resource = graph.insertVertex(parent, null,
// res.toString(), x, y, w, h,
// "shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top;"); // insert a resource as a vertex
// resources.put(resNode, resource);
// createChildSimulateResourceVerticies(resource, resNode, resources, w, h);
// x+=80;
// }
//
// } finally {
// graph.getModel().endUpdate();
// }
//
// bReflectingArchitectureModel = false;
// return graph;
// }
//
//
// public void createChildSimulateResourceVerticies(Object resource, Resource resNode, Map<Resource, Object> resources, int w, int h) { //sample
//
// if(resNode.getChildren() != null) {
// for (Resource childNode: resNode.getChildren()) {
// ResourcePath childRes = childNode.getResourceIdentifier();
// Object childResource = graph.insertVertex(resource, null,
// childRes.toString(), 0, 0, w/2, h/2,
// "shape=ellipse;perimeter=ellipsePerimeter;verticalAlign=top;"); // insert a resource as a vertex
// resources.put(childNode, childResource);
// createChildSimulateResourceVerticies(childResource, childNode, resources, w, h);
// }
// }
// if (resNode.getChildren() == null || resNode.getChildren().size() == 0) {
// Object state = graph.insertVertex(resource, null,
// resNode.getState().getValue().toString(), 0.5, 0.5, 0.25, 0.25, "opacity=0;verticalAlign=down;", true); // insert a state label as a vertex
// }
// }
public mxGraphComponent getGraphComponent() {
return graphComponent;
}
View
6
AlgebraicDataflowArchitectureModel/src/simulator/ChannelState.java
}
public Object clone() {
ReferenceStructure newReferenceStructure = new ReferenceStructure();
newReferenceStructure.dependingParamAndValues = new HashMap<>(dependingParamAndValues);
if (dependingParamAndValues != null) {
newReferenceStructure.dependingParamAndValues = new HashMap<>(dependingParamAndValues);
}
if (referenceStructure != null) {
newReferenceStructure.referenceStructure = new HashMap<>();
for (Map.Entry<Constant, ReferenceStructure> refEnt: referenceStructure.entrySet()) {
newReferenceStructure.referenceStructure.put(refEnt.getKey(), (ReferenceStructure) refEnt.getValue().clone());
View
AlgebraicDataflowArchitectureModel/src/simulator/Simulator.java