Create SVG in UI
[clamp.git] / src / main / java / org / onap / clamp / clds / util / drawing / AwtUtils.java
index 7a1f122..a4a5a38 100755 (executable)
@@ -40,7 +40,7 @@ public class AwtUtils {
     private static final int FONT_STYLE = Font.PLAIN;
     private static final String FONT_FACE = "SansSerif";
     private static final Color TRANSPARENT = new Color(0.0f, 0.0f, 0.0f, 0.0f);
-    private  static final int TEXT_PADDING = 5;
+    private static final int TEXT_PADDING = 5;
 
     private AwtUtils() {
     }
@@ -58,12 +58,14 @@ public class AwtUtils {
     static void drawArrow(Graphics2D g2d, Point from, Point to, int lineThickness) {
         int x2 = to.x - lineThickness;
         g2d.drawLine(from.x, from.y, x2 - lineThickness, to.y);
-        g2d.drawPolygon(new int[]{x2 - ARROW_W, x2 - ARROW_W, x2}, new int[]{to.y - ARROW_H, to.y + ARROW_H, to.y}, 3);
-        g2d.fillPolygon(new int[]{x2 - ARROW_W, x2 - ARROW_W, x2}, new int[]{to.y - ARROW_H, to.y + ARROW_H, to.y}, 3);
+        g2d.drawPolygon(new int[] { x2 - ARROW_W, x2 - ARROW_W, x2 },
+                new int[] { to.y - ARROW_H, to.y + ARROW_H, to.y }, 3);
+        g2d.fillPolygon(new int[] { x2 - ARROW_W, x2 - ARROW_W, x2 },
+                new int[] { to.y - ARROW_H, to.y + ARROW_H, to.y }, 3);
     }
 
     private static void addText(Graphics2D g2d, String text, Rectangle rect) {
-        int textBoundingBoxLimit = rect.width - 2* TEXT_PADDING;
+        int textBoundingBoxLimit = rect.width - 2 * TEXT_PADDING;
         Font font = new Font(FONT_FACE, FONT_STYLE, FONT_SIZE);
         font = scaleFontToFit(text, textBoundingBoxLimit, g2d, font);
         Font oldFont = g2d.getFont();
@@ -71,21 +73,21 @@ public class AwtUtils {
         g2d.setFont(font);
         g2d.setColor(Color.BLACK);
         FontMetrics fm1 = g2d.getFontMetrics();
-        float x1 = rect.x + (float)(rect.width - fm1.stringWidth(text)) / 2;
-        float y1 = rect.y + (float)(rect.height - fm1.getHeight()) / 2 + fm1.getAscent();
+        float x1 = rect.x + (float) (rect.width - fm1.stringWidth(text)) / 2;
+        float y1 = rect.y + (float) (rect.height - fm1.getHeight()) / 2 + fm1.getAscent();
         g2d.drawString(text, x1, y1);
 
         g2d.setFont(oldFont);
     }
 
-    private static Font scaleFontToFit(String text, int width, Graphics2D g2d, Font pFont) {
-        float fontSize = pFont.getSize();
-        float fWidth = g2d.getFontMetrics(pFont).stringWidth(text);
-        if(fWidth <= width) {
-            return pFont;
+    private static Font scaleFontToFit(String text, int width, Graphics2D g2d, Font font) {
+        float fontSize = font.getSize();
+        float stringWidth = g2d.getFontMetrics(font).stringWidth(text);
+        if (stringWidth <= width) {
+            return font;
         }
-        fontSize = ((float)width / fWidth) * fontSize;
-        return pFont.deriveFont(fontSize);
+        fontSize = (width / stringWidth) * fontSize;
+        return font.deriveFont(fontSize);
     }
 
 }