Add info in the SVG
[clamp.git] / src / main / java / org / onap / clamp / clds / util / drawing / Painter.java
index e41ca8f..ff7d2c2 100755 (executable)
@@ -17,6 +17,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * ============LICENSE_END============================================
+ * Modifications copyright (c) 2019 AT&T
  * ===================================================================
  *
  */
@@ -27,65 +28,78 @@ import java.awt.BasicStroke;
 import java.awt.Color;
 import java.awt.Point;
 import java.awt.RenderingHints;
-import java.util.List;
+import java.util.Set;
 import org.apache.batik.svggen.SVGGraphics2D;
+import org.onap.clamp.policy.microservice.MicroServicePolicy;
+import org.onap.clamp.policy.operational.OperationalPolicy;
 
 public class Painter {
     private final int canvasSize;
     private final SVGGraphics2D g2d;
     private final DocumentBuilder documentBuilder;
 
-    private static final int DEFALUT_CANVAS_SIZE = 900;
+    private static final int DEFAULT_CANVAS_SIZE = 900;
     private static final int SLIM_LINE = 2;
     private static final int THICK_LINE = 4;
     private static final double RECT_RATIO = 3.0 / 2.0;
     private static final int CIRCLE_RADIUS = 17;
-
+    private static final int MINIMUM_BASE_LENGTH = 120;
+
+    /**
+     * Constructor to create instance of Painter.
+     *
+     * @param svgGraphics2D   svg graphics
+     * @param documentBuilder document builder
+     */
     public Painter(SVGGraphics2D svgGraphics2D, DocumentBuilder documentBuilder) {
         this.g2d = svgGraphics2D;
         this.documentBuilder = documentBuilder;
-        this.canvasSize = DEFALUT_CANVAS_SIZE;
+        this.canvasSize = DEFAULT_CANVAS_SIZE;
     }
 
-    DocumentBuilder doPaint(String collector, List<String> microServices, String policy) {
+    DocumentBuilder doPaint(String collector, Set<MicroServicePolicy> microServices, Set<OperationalPolicy> policies) {
         int numOfRectangles = 2 + microServices.size();
         int numOfArrows = numOfRectangles + 1;
         int baseLength = (canvasSize - 2 * CIRCLE_RADIUS) / (numOfArrows + numOfRectangles);
+        if (baseLength < MINIMUM_BASE_LENGTH) {
+            baseLength = MINIMUM_BASE_LENGTH;
+        }
         int rectHeight = (int) (baseLength / RECT_RATIO);
 
         adjustGraphics2DProperties();
 
-        Point origin = new Point(0, rectHeight / 2);
+        Point origin = new Point(1, rectHeight / 2);
         ImageBuilder ib = new ImageBuilder(g2d, documentBuilder, origin, baseLength, rectHeight);
 
-        doTheActualDrawing(collector, microServices, policy, ib);
+        doTheActualDrawing(collector, microServices, policies, ib);
 
         return ib.getDocumentBuilder();
     }
 
-    private void doTheActualDrawing(String collector, List<String> microServices, String policy, ImageBuilder ib) {
-        ib.circle("start-circle", SLIM_LINE)
-            .arrow()
-            .rectangle(collector, RectTypes.COLECTOR, collector);
+    private void doTheActualDrawing(String collector, Set<MicroServicePolicy> microServices,
+                                    Set<OperationalPolicy> policies,
+                                    ImageBuilder ib) {
+        ib.circle("start-circle", SLIM_LINE).arrow().rectangle(collector, RectTypes.COLECTOR, collector, null, null);
 
-        for(String ms : microServices) {
-            ib.arrow().rectangle(ms, RectTypes.MICROSERVICE, ms);
+        for (MicroServicePolicy ms : microServices) {
+            ib.arrow().rectangle(ms.getName(),
+                    RectTypes.MICROSERVICE, ms.getPolicyModel().getPolicyAcronym(),
+                    ms.getLoopElementModel() != null ? ms.getLoopElementModel().getName() : null,
+                    ms.getLoopElementModel() != null ? ms.getLoopElementModel().getName() : null);
         }
-
-        ib.arrow()
-            .rectangle(policy, RectTypes.POLICY, policy)
-            .arrow()
-            .circle("stop-circle", THICK_LINE);
+        for (OperationalPolicy policy : policies) {
+            ib.arrow().rectangle(policy.getName(), RectTypes.POLICY, policy.getPolicyModel().getPolicyAcronym(),
+                    policy.getLoopElementModel() != null ? policy.getLoopElementModel().getName() : null,
+                    policy.getLoopElementModel() != null ? policy.getLoopElementModel().getName() : null);
+        }
+        ib.arrow().circle("stop-circle", THICK_LINE);
     }
 
     private void adjustGraphics2DProperties() {
-        g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
-            RenderingHints.VALUE_FRACTIONALMETRICS_ON);
-        g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
-            RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
+        g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
+        g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
         g2d.setStroke(new BasicStroke(SLIM_LINE));
         g2d.setPaint(Color.BLACK);
     }
 
-
 }