X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2Fnodes%2FDynamicVisualisationContributionsNode.java;h=b3149324eb42fb342262a88f1831d194c0c5cdb6;hb=607611b465ee7737db9489d21d261ff793692b89;hp=53d7862c854115115cb77d2e89f3da8f5a911010;hpb=dab24824da1b284b8a4734a069cfba72fb1f05de;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DynamicVisualisationContributionsNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DynamicVisualisationContributionsNode.java index 53d7862c..b3149324 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DynamicVisualisationContributionsNode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DynamicVisualisationContributionsNode.java @@ -5,7 +5,6 @@ import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.geom.AffineTransform; -import java.awt.geom.Ellipse2D; import java.awt.geom.Rectangle2D; import java.util.List; import java.util.Map; @@ -119,25 +118,33 @@ public class DynamicVisualisationContributionsNode extends G2DNode { Font rulerFont = new Font("Tahoma", Font.PLAIN, DPIUtil.upscale(9)); g2d.setFont(rulerFont); - g2d.setColor(Color.BLACK); - - String str = Double.toString(max); - g2d.drawString(str, (int)(colorBarBoxLeft + colorBarBoxWidth - 30), (int)(colorBarBoxTop + colorBarBoxHeight)); - - str = Double.toString(min); - g2d.drawString(str, (int)colorBarBoxLeft + 1, (int)(colorBarBoxTop + colorBarBoxHeight)); + double interval = (max - min) / intensities.size(); - for (RGBIntensity intensity : intensities) { + for (int j = 0; j < intensities.size(); j++) { + + RGBIntensity intensity = intensities.get(j); g2d.setColor(new Color((float)intensity.getRed(), (float)intensity.getGreen(), (float)intensity.getBlue(), 1f)); Rectangle2D colorVertical = new Rectangle2D.Double(colorVerticalLeft, colorVerticalTop, colorVerticalWidth, colorVerticalHeigth); g2d.fill(colorVertical); + + double value = min + j * interval; + String str = Double.toString(value); + if (str.length() > 4) { + str = str.substring(0, 3); + } + g2d.setColor(Color.BLACK); + g2d.drawString(str, (float)(colorVerticalLeft - 8), (float)(colorBarBoxTop + colorBarBoxHeight)); colorVerticalLeft = colorVerticalLeft + colorVerticalWidth; } g2d.setColor(Color.BLACK); + + String str = Double.toString(max); + g2d.drawString(str, (float)(colorVerticalLeft - 8), (float)(colorBarBoxTop + colorBarBoxHeight)); + str = object.getKey() + " - " + label + " [" + unit + "]"; - g2d.drawString(str, (int)colorBarBoxLeft + 5, (int)colorBarBoxTop + 10); + g2d.drawString(str, (float)colorBarBoxLeft + 5, (float)colorBarBoxTop + 10); } } } @@ -209,60 +216,69 @@ public class DynamicVisualisationContributionsNode extends G2DNode { int i = 0; - for (Entry object : dynamicSizingContributions.entrySet()) { - DynamicSizeContribution cc = object.getValue(); - - double min = cc.getDefaultMin(); - double max = cc.getDefaultMax(); - String unit = cc.getUnit(); - String label = cc.getLabel(); - - DynamicSizeMap map = cc.getDefaultSizeMap(); - - List sizes = map.getSizes(); - - double sizeBarBoxTop = (sizeBarBoxTopInitial + (colorBarBoxHeight * i)); - i++; -// double backgroundBoxPaddingRight = 20; -// double backgroundBoxHeight = 50; -// double backgroundBoxWidth = 300; -// double backgroundBoxRight = bounds.getMaxX() - backgroundBoxPaddingRight; -// double backgroundBoxLeft = backgroundBoxRight - backgroundBoxWidth; -// double backgroundBoxTop = bounds.getMaxY();// + (initialPosition + (position * i)); - g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f)); - g2d.setColor(new Color(0.9f, 0.9f, 0.9f, 0.95f)); - - Rectangle2D vertical = new Rectangle2D.Double(sizeBarBoxLeft, sizeBarBoxTop, colorBarBoxWidth, colorBarBoxHeight); - g2d.fill(vertical); - - double sizeVerticalLeft = sizeBarBoxLeft + 5; - double sizeVerticalTop = sizeBarBoxTop + 15; - double sizeVerticalHeigth = colorBarBoxHeight - 30; - - double sizeVerticalWidth = (sizeBarBoxWidth - 10) / sizes.size(); - - Font rulerFont = new Font("Tahoma", Font.PLAIN, DPIUtil.upscale(9)); - g2d.setFont(rulerFont); - g2d.setColor(Color.BLACK); - - String str = Double.toString(max); - g2d.drawString(str, (int)(sizeBarBoxLeft + sizeBarBoxWidth - 30), (int)(sizeBarBoxTop + sizeBarBoxHeight)); - - str = Double.toString(min); - g2d.drawString(str, (int)sizeBarBoxLeft + 1, (int)(sizeBarBoxTop + sizeBarBoxHeight)); - - - g2d.setColor(new Color((float)0, (float)0, (float)0.8, 0.8f)); - for (Double size: sizes) { + if (dynamicSizingContributions != null) { + for (Entry object : dynamicSizingContributions.entrySet()) { + DynamicSizeContribution cc = object.getValue(); + + if (!cc.isUsed()) + continue; + + double min = cc.getDefaultMin(); + double max = cc.getDefaultMax(); + String unit = cc.getUnit(); + String label = cc.getLabel(); + + DynamicSizeMap map = cc.getDefaultSizeMap(); + + List sizes = map.getSizes(); + + double sizeBarBoxTop = (sizeBarBoxTopInitial + (colorBarBoxHeight * i)); + i++; + + g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f)); + g2d.setColor(new Color(0.9f, 0.9f, 0.9f, 0.95f)); + + Rectangle2D vertical = new Rectangle2D.Double(sizeBarBoxLeft, sizeBarBoxTop, colorBarBoxWidth, colorBarBoxHeight); + g2d.fill(vertical); + + double sizeVerticalLeft = sizeBarBoxLeft + 5; + double sizeVerticalTop = sizeBarBoxTop + 15; + double sizeVerticalHeigth = colorBarBoxHeight - 30; + + double sizeVerticalWidth = (sizeBarBoxWidth - 10) / sizes.size(); - Ellipse2D ellipse = new Ellipse2D.Double(sizeVerticalLeft + sizeVerticalWidth / 2, (sizeVerticalTop), size * sizeVerticalHeigth, size * sizeVerticalHeigth); - g2d.fill(ellipse); + Font rulerFont = new Font("Tahoma", Font.PLAIN, DPIUtil.upscale(9)); + g2d.setFont(rulerFont); + + double interval = (max - min) / sizes.size(); - sizeVerticalLeft = sizeVerticalLeft + sizeVerticalWidth; + for (int j = 0; j < sizes.size(); j++) { + + Double size = sizes.get(j); + + g2d.setColor(new Color((float)0, (float)0, (float)0.8, 0.8f)); + double sizedWidth = (size / 5) * sizeVerticalHeigth; + Rectangle2D rect = new Rectangle2D.Double(sizeVerticalLeft, (sizeVerticalTop), sizedWidth, sizeVerticalHeigth); + g2d.fill(rect); + + double value = min + j * interval; + String str = Double.toString(value); + if (str.length() > 4) { + str = str.substring(0, 3); + } + g2d.setColor(Color.BLACK); + g2d.drawString(str, (float)(sizeVerticalLeft - 8), (float)(sizeBarBoxTop + sizeBarBoxHeight)); + + sizeVerticalLeft = sizeVerticalLeft + sizeVerticalWidth; + } + g2d.setColor(Color.BLACK); + + String str = Double.toString(max); + g2d.drawString(str, (int)(sizeBarBoxLeft + sizeBarBoxWidth - 30), (int)(sizeBarBoxTop + sizeBarBoxHeight)); + + str = object.getKey() + " - " + label + " [" + unit + "]"; + g2d.drawString(str, (int)sizeBarBoxLeft + 5, (int)sizeBarBoxTop + 10); } - g2d.setColor(Color.BLACK); - str = object.getKey() + " - " + label + " [" + unit + "]"; - g2d.drawString(str, (int)sizeBarBoxLeft + 5, (int)sizeBarBoxTop + 10); } }