2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia. All rights
7 * ================================================================================
8 * Modifications Copyright (c) 2019 Samsung
9 * ================================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 * ============LICENSE_END============================================
22 * Modifications copyright (c) 2019 AT&T.
23 * ===================================================================
27 package org.onap.clamp.clds.util.drawing;
29 import java.awt.Color;
31 import java.awt.FontMetrics;
32 import java.awt.Graphics2D;
33 import java.awt.Point;
34 import java.awt.Rectangle;
36 public class AwtUtils {
37 private static final int ARROW_W = 4;
38 private static final int ARROW_H = 2;
39 private static final int FONT_SIZE = 12;
40 private static final int FONT_STYLE = Font.PLAIN;
41 private static final String FONT_FACE = "SansSerif";
42 private static final Color TRANSPARENT = new Color(0.0f, 0.0f, 0.0f, 0.0f);
47 static void rectWithText(Graphics2D g2d, String text, Point point, int width, int height) {
48 Rectangle rect = new Rectangle(point.x, point.y, width, height);
50 Color oldColor = g2d.getColor();
51 g2d.setColor(TRANSPARENT);
53 g2d.setColor(oldColor);
54 addText(g2d, text, point.x + width / 2, point.y + height / 2);
57 static void drawArrow(Graphics2D g2d, Point from, Point to, int lineThickness) {
58 int x2 = to.x - lineThickness;
59 g2d.drawLine(from.x, from.y, x2 - lineThickness, to.y);
60 g2d.drawPolygon(new int[]{x2 - ARROW_W, x2 - ARROW_W, x2}, new int[]{to.y - ARROW_H, to.y + ARROW_H, to.y}, 3);
61 g2d.fillPolygon(new int[]{x2 - ARROW_W, x2 - ARROW_W, x2}, new int[]{to.y - ARROW_H, to.y + ARROW_H, to.y}, 3);
64 private static void addText(Graphics2D g2d, String text, int abs, int ord) {
65 Font font = new Font(FONT_FACE, FONT_STYLE, FONT_SIZE);
68 FontMetrics fm1 = g2d.getFontMetrics();
69 int w1 = fm1.stringWidth(text);
70 int x1 = abs - (w1 / 2);
73 g2d.setColor(Color.BLACK);
74 g2d.drawString(text, x1, ord);