]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DynamicVisualisationContributionsNode.java
Add support for gradients in dynamic visualisations
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / nodes / DynamicVisualisationContributionsNode.java
index b3149324eb42fb342262a88f1831d194c0c5cdb6..d8d2e1d194a97d9f45c9bdeb8a2e85394392cf2b 100644 (file)
@@ -125,9 +125,41 @@ public class DynamicVisualisationContributionsNode extends G2DNode {
                     
                     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);
+                    if (colorBarsOptions.isUseGradients()) {
+                        
+                        RGBIntensity upperLimitIntensity;
+                        if (j + 1 != intensities.size())
+                            upperLimitIntensity = intensities.get(j + 1);
+                        else
+                            upperLimitIntensity = intensity;
+                        
+                        double minRed = intensity.getRed();
+                        double minGreen = intensity.getGreen();
+                        double minBlue = intensity.getBlue();
+                        
+                        double maxRed = upperLimitIntensity.getRed();
+                        double maxGreen = upperLimitIntensity.getGreen();
+                        double maxBlue = upperLimitIntensity.getBlue();
+                        
+                        double redDelta = (maxRed - minRed) / colorVerticalWidth;
+                        double greenDelta = (maxGreen - minGreen) / colorVerticalWidth;
+                        double blueDelta = (maxBlue - minBlue) / colorVerticalWidth;
+                        
+                        for (int k = 0; k < colorVerticalWidth; k++) {
+                            
+                            
+                            g2d.setColor(new Color((float)(minRed + (k * redDelta)), (float)(minGreen + (k * greenDelta)), (float)(minBlue + (k * blueDelta)), 1f));
+                            Rectangle2D colorVertical = new Rectangle2D.Double(colorVerticalLeft + k, colorVerticalTop, 1, colorVerticalHeigth);
+                            g2d.fill(colorVertical);
+                        }
+                        
+                    } else {
+                        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);