From: jsimomaa Date: Fri, 27 Jul 2018 06:51:11 +0000 (+0300) Subject: Add max digits for ruler node for subclasses to override X-Git-Tag: v1.43.0~136^2~434 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=436ecca6458503a993a92af8aa456b6b0f266418;p=simantics%2Fplatform.git Add max digits for ruler node for subclasses to override gitlab #59 Change-Id: I7063af75d8ae1190271386a8441b90ccec7342af --- diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/RulerNode.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/RulerNode.java index 27c1c1fd2..7e962976e 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/RulerNode.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/RulerNode.java @@ -111,7 +111,7 @@ public class RulerNode extends G2DNode { if(x > 20) { double val = (x-offsetX)/scaleX / getTransform().getScaleX(); double modifiedValue = modifyHorizontalValue(val); - String str = formatValue(modifiedValue); + String str = formatValue(modifiedValue, getMaxDigits()); FontMetrics fm = g.getFontMetrics(); Rectangle2D r = fm.getStringBounds(str, g); if((x-r.getWidth()/2) > previousText) { @@ -144,7 +144,7 @@ public class RulerNode extends G2DNode { if(y > 20) { double val = (y-offsetY)/scaleY / getTransform().getScaleY(); double modifiedValue = modifyVerticalValue(val); - String str = formatValue(modifiedValue); + String str = formatValue(modifiedValue, getMaxDigits()); FontMetrics fm = g.getFontMetrics(); Rectangle2D r = fm.getStringBounds(str, g); if(y-1+r.getHeight()/2 > previousText) { @@ -202,11 +202,15 @@ public class RulerNode extends G2DNode { private static final transient String[] SI_UNIT_LARGE_PREFIXES = { "k", "M", "G", "T", "P", "E", "Z", "Y" }; + + protected int getMaxDigits() { + return MAX_DIGITS; + } - public static String formatValue(double value) { + public static String formatValue(double value, int maxDigits) { int magnitude = (int) Math.round(Math.log10(value)); //System.out.println("magnitude: " + magnitude + ", " + value); - int allowedDecimals = MAX_DIGITS; + int allowedDecimals = maxDigits; allowedDecimals -= Math.abs(magnitude); if (allowedDecimals < 0) allowedDecimals = 0;