diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/SimulationLayout.java b/AlgebraicDataflowArchitectureModel/src/application/editor/SimulationLayout.java index 4534ab4..99bbdff 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/SimulationLayout.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/SimulationLayout.java @@ -15,7 +15,9 @@ import java.util.Set; public class SimulationLayout { + // Hold the division level for each resource HashMap divisionLevelMap = new HashMap<>(); + // Hold the scaling factor for each resource HashMap resourceScaleMap = new HashMap<>(); int maxDivisionLevel = 1; public final double BASE_WIDTH = 400; @@ -24,9 +26,11 @@ SystemState systemState; public SimulationLayout(SystemState systemState){ this.systemState = systemState; + // Calculate the division level for each resource for (Resource res:systemState.getRootResources()) { setDivisionLevel(divisionLevelMap, res.getResourceIdentifier(), 1); } + // Calculate the scaling factor for each resource for (ResourceIdentifier res:divisionLevelMap.keySet()) { double scale = (double) maxDivisionLevel / divisionLevelMap.get(res); resourceScaleMap.put(res, scale); @@ -63,6 +67,16 @@ } } } + /** + * + * Draw an object corresponding to the target resource on the mxGraph. + * @param graph The mxGraph for drawing. + * @param parent The parent object of the target resource. + * @param resourceIdentifier The ID of the target resource. + * @param index The index. + * @param length The number of sibling resources of the target resource. + * @return The drawing object of the target resource. + */ private Object setLayout(mxGraph graph,Object parent, ResourceIdentifier resourceIdentifier,double index, double length){ double width, height, x, y; @@ -73,6 +87,7 @@ height = width/2; x = parentWidth * (index - 1)/length + (parentWidth/length)*(1-MARGIN_SCALE)/2; + // Process to avoid hiding the parent's resource name if ((int)length == 1) { y = 20; height -=20;