changeset 165:61807fc09405

Bug 3191: Enable to change font size of Reference Tree by config Reviewed-by: yasuenag GitHub: https://github.com/HeapStats/heapstats/pull/37
author KUBOTA Yuji <kubota.yuji@lab.ntt.co.jp>
date Fri, 07 Oct 2016 22:13:17 +0900
parents 20ded99138ad
children cf00c05c2431
files ChangeLog analyzer/fx/heapstats.properties analyzer/fx/src/main/java/jp/co/ntt/oss/heapstats/plugin/builtin/snapshot/tabs/RefTreeController.java analyzer/fx/src/main/java/jp/co/ntt/oss/heapstats/plugin/builtin/snapshot/tabs/ReferenceCell.java analyzer/fx/src/main/java/jp/co/ntt/oss/heapstats/plugin/builtin/snapshot/tabs/ReferenceGraph.java analyzer/fx/src/main/java/jp/co/ntt/oss/heapstats/utils/HeapStatsUtils.java
diffstat 6 files changed, 59 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Oct 06 19:00:44 2016 +0900
+++ b/ChangeLog	Fri Oct 07 22:13:17 2016 +0900
@@ -1,3 +1,7 @@
+2016-10-07  KUBOTA Yuji <kubota.yuji@lab.ntt.co.jp>
+
+	* Bug 3191: Enable to change font size of Reference Tree by config
+
 2016-10-06  Yasumasa Suenaga <yasuenag@gmail.com>
 
 	* Bug 2999: HeapStats agent should notify when ring buffer is overwritten
--- a/analyzer/fx/heapstats.properties	Thu Oct 06 19:00:44 2016 +0900
+++ b/analyzer/fx/heapstats.properties	Fri Oct 07 22:13:17 2016 +0900
@@ -11,4 +11,5 @@
 heaporder_bottom_young=true
 language=en
 datetime_format=yyyy/MM/dd HH:mm:ss
-#plugins=
\ No newline at end of file
+#plugins=
+reftree_fontsize=11
--- a/analyzer/fx/src/main/java/jp/co/ntt/oss/heapstats/plugin/builtin/snapshot/tabs/RefTreeController.java	Thu Oct 06 19:00:44 2016 +0900
+++ b/analyzer/fx/src/main/java/jp/co/ntt/oss/heapstats/plugin/builtin/snapshot/tabs/RefTreeController.java	Fri Oct 07 22:13:17 2016 +0900
@@ -159,6 +159,7 @@
     @Override
     public void initialize(URL url, ResourceBundle rb) {
         resource = rb;
+        ReferenceCell.initialize();
         currentSnapShotHeader = new SimpleObjectProperty<>();
         currentObjectTag = new SimpleLongProperty();
         currentObjectTag.addListener((v, o, n) -> Optional.ofNullable(n).ifPresent(t -> buildTab()));
--- a/analyzer/fx/src/main/java/jp/co/ntt/oss/heapstats/plugin/builtin/snapshot/tabs/ReferenceCell.java	Thu Oct 06 19:00:44 2016 +0900
+++ b/analyzer/fx/src/main/java/jp/co/ntt/oss/heapstats/plugin/builtin/snapshot/tabs/ReferenceCell.java	Fri Oct 07 22:13:17 2016 +0900
@@ -2,7 +2,7 @@
  * ReferenceCell.java
  * Created on 2012/11/18
  *
- * Copyright (C) 2011-2015 Nippon Telegraph and Telephone Corporation
+ * Copyright (C) 2011-2016 Nippon Telegraph and Telephone Corporation
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -24,7 +24,9 @@
 import java.text.NumberFormat;
 import com.mxgraph.model.mxCell;
 import com.mxgraph.model.mxGeometry;
+import com.mxgraph.util.mxConstants;
 import jp.co.ntt.oss.heapstats.container.snapshot.ObjectData;
+import jp.co.ntt.oss.heapstats.utils.HeapStatsUtils;
 
 /**
  * extends {@link mxCell}<br>
@@ -39,14 +41,23 @@
     private static final long serialVersionUID = -4403355352725440764L;
 
     /**
+     * Defines the font size
+     */
+    private static String FONT_SIZE;
+    /**
+     * Defines the zoom ratio by font size ratio.
+     */
+    private static double ZOOM_RATIO;
+
+    /**
      * Defines the height of the cell.
      */
-    private static final int CELL_HEIGHT = 30;
+    private static int CELL_HEIGHT;
 
     /**
      * Define the width of the character in the cell.
      */
-    private static final int CHAR_WIDTH = 6;
+    private static int CHAR_WIDTH;
 
     /**
      * Information about the objects to display Map.
@@ -76,9 +87,10 @@
             setValue(data.getName());
             setConnectable(false);
             setVertex(true);
+            setStyle("fontSize="+FONT_SIZE);
 
             if (root) {
-                setStyle("shape=ellipse;fillColor=red;fontColor=black");
+                setStyle("shape=ellipse;fillColor=red;fontColor=black;fontSize="+FONT_SIZE);
             }
 
             rootCell = root;
@@ -89,6 +101,17 @@
     }
 
     /**
+     * Initialize to define the size.
+     */
+    public static void initialize() {
+        FONT_SIZE = String.valueOf(HeapStatsUtils.getFontSizeOfRefTree());
+        ZOOM_RATIO = (double) HeapStatsUtils.getFontSizeOfRefTree() / mxConstants.DEFAULT_FONTSIZE;
+        CELL_HEIGHT = (int)(30 * ZOOM_RATIO);
+        CHAR_WIDTH = (int)(7 * ZOOM_RATIO);
+    }
+
+
+    /**
      * Return the tag.
      *
      * @return Return the tag
--- a/analyzer/fx/src/main/java/jp/co/ntt/oss/heapstats/plugin/builtin/snapshot/tabs/ReferenceGraph.java	Thu Oct 06 19:00:44 2016 +0900
+++ b/analyzer/fx/src/main/java/jp/co/ntt/oss/heapstats/plugin/builtin/snapshot/tabs/ReferenceGraph.java	Fri Oct 07 22:13:17 2016 +0900
@@ -2,7 +2,7 @@
  * ReferenceGraph.java
  * Created on 2012/11/18
  *
- * Copyright (C) 2011-2015 Nippon Telegraph and Telephone Corporation
+ * Copyright (C) 2011-2016 Nippon Telegraph and Telephone Corporation
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -27,6 +27,7 @@
 import com.mxgraph.util.mxConstants;
 import com.mxgraph.view.mxGraph;
 import com.mxgraph.view.mxStylesheet;
+import jp.co.ntt.oss.heapstats.utils.HeapStatsUtils;
 
 /**
  * extends {@link mxGraph}<br>
@@ -56,6 +57,7 @@
         edgeStyle.put(mxConstants.STYLE_STROKECOLOR, "#000000");
         edgeStyle.put(mxConstants.STYLE_FONTCOLOR, "#000000");
         edgeStyle.put(mxConstants.STYLE_ALIGN, mxConstants.ALIGN_RIGHT);
+        edgeStyle.put(mxConstants.STYLE_FONTSIZE, HeapStatsUtils.getFontSizeOfRefTree());
 
         mxStylesheet style = new mxStylesheet();
         style.setDefaultEdgeStyle(edgeStyle);
--- a/analyzer/fx/src/main/java/jp/co/ntt/oss/heapstats/utils/HeapStatsUtils.java	Thu Oct 06 19:00:44 2016 +0900
+++ b/analyzer/fx/src/main/java/jp/co/ntt/oss/heapstats/utils/HeapStatsUtils.java	Fri Oct 07 22:13:17 2016 +0900
@@ -177,6 +177,12 @@
         prop.putIfAbsent("datetime_format", "yyyy/MM/dd HH:mm:ss");
         formatter = DateTimeFormatter.ofPattern(prop.getProperty("datetime_format"));
 
+        /* Font size of RefTree */
+        String fontsize = prop.getProperty("reftree_fontsize");
+        if (fontsize == null) {
+            prop.setProperty("reftree_fontsize", "11");
+        }
+
         /* Add shutdown hook for saving current settings. */
         Runnable savePropImpl = () -> {
             try (OutputStream out = Files.newOutputStream(properties, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE)) {
@@ -312,6 +318,22 @@
     }
 
     /**
+     * Get font size of ReferenceTree tab.
+     * @return fontSize
+     */
+    public static int getFontSizeOfRefTree() {
+        return Integer.parseInt(prop.getProperty("reftree_fontsize"));
+    }
+
+    /**
+     * Get font size of ReferenceTree tab.
+     * @param fontSize font size
+     */
+    public static void setFontSizeOfRefTree( int fontSize ) {
+        prop.setProperty("reftree_fontsize", Integer.toString(fontSize));
+    }
+
+    /**
      * Convert stack trace to String.
      *
      * @param e Throwable object to convert.