X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fclamp%2Fclds%2Futil%2Fdrawing%2FPainter.java;h=ff7d2c21575e575a577cf11dca962ec2efb6f881;hb=a573c0f2b362536783709770a88120b242c204fc;hp=e41ca8fb3248fde3216852c400c26ef7603f6504;hpb=43f0b01f68e145b74993e31adf7ef41379c72be1;p=clamp.git diff --git a/src/main/java/org/onap/clamp/clds/util/drawing/Painter.java b/src/main/java/org/onap/clamp/clds/util/drawing/Painter.java index e41ca8fb..ff7d2c21 100755 --- a/src/main/java/org/onap/clamp/clds/util/drawing/Painter.java +++ b/src/main/java/org/onap/clamp/clds/util/drawing/Painter.java @@ -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 microServices, String policy) { + DocumentBuilder doPaint(String collector, Set microServices, Set 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 microServices, String policy, ImageBuilder ib) { - ib.circle("start-circle", SLIM_LINE) - .arrow() - .rectangle(collector, RectTypes.COLECTOR, collector); + private void doTheActualDrawing(String collector, Set microServices, + Set 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); } - }