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