Revision: 6083
          http://sourceforge.net/p/jump-pilot/code/6083
Author:   ma15569
Date:     2019-01-13 09:50:18 +0000 (Sun, 13 Jan 2019)
Log Message:
-----------
Added to method to create color schemas of a renge of colors using two ones as 
end members.

Modified Paths:
--------------
    core/trunk/src/com/vividsolutions/jump/util/ColorUtil.java

Modified: core/trunk/src/com/vividsolutions/jump/util/ColorUtil.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/util/ColorUtil.java  2019-01-13 
09:43:32 UTC (rev 6082)
+++ core/trunk/src/com/vividsolutions/jump/util/ColorUtil.java  2019-01-13 
09:50:18 UTC (rev 6083)
@@ -33,10 +33,91 @@
 package com.vividsolutions.jump.util;
 
 import java.awt.Color;
+import java.util.ArrayList;
+import java.util.Random;
 
+import org.openjump.core.rasterimage.styler.ColorUtils;
 
+import com.vividsolutions.jump.workbench.ui.renderer.style.ColorScheme;
+
 public class ColorUtil {
-  public static final Color GOLD = new Color(255, 192, 0, 150);
-  public static final Color PALE_BLUE = new Color(153, 204, 255, 150);
-  public static final Color PALE_RED = new Color(255, 204, 204, 150);  
+    public static final Color GOLD = new Color(255, 192, 0, 150);
+    public static final Color PALE_BLUE = new Color(153, 204, 255, 150);
+    public static final Color PALE_RED = new Color(255, 204, 204, 150);
+
+    //ColorBrewer range color
+    static String[] color2s = { "#08306b", "#00441b", "#7f2704", "#3f007d",
+            "#67000d", "#000000" };
+
+    static String[] color1s = { "#f7fbff", "#f7fcf5", "#fff5eb", "#fcfbfd",
+            "#fff5f0", "#ffffff" };
+
+    /**
+     * Giving an interval, this method creates a random colorschema that fills 
the entire interval,
+     * eg. a feature collection, with a random color set (ColorBrewer).
+     * This method extends color range to more that maximum defined in the 
ColorScheme.txt 
+     * (12 intervals) [Giuseppe Aruta 2019-1-12]
+     * @param intervals
+     * @return com.vividsolutions.jump.workbench.ui.renderer.style.ColorScheme 
class
+     * @throws Exception
+     */
+    public static ColorScheme createRandomColorSchema(int intervals)
+            throws Exception {
+
+        final ColorUtils colorUtils = new ColorUtils();
+        final ArrayList<Color> arrayColor = new ArrayList<Color>();
+        final Color startColor = Color.decode(color1s[new Random()
+                .nextInt(color1s.length)]);
+        arrayColor.add(startColor);
+        final Color endColor = Color.decode(color2s[new Random()
+                .nextInt(color2s.length)]);
+        for (int c = 1; c < intervals; c++) {
+
+            final double cellRelDistance = (double) c / (double) (intervals);
+
+            final Color color = colorUtils.interpolateColor(startColor,
+                    endColor, cellRelDistance);
+            arrayColor.add(color);
+        }
+        arrayColor.add(endColor);
+
+        final ColorScheme colorScheme = new ColorScheme("test", arrayColor);
+        return colorScheme;
+    }
+
+    /**
+     * Giving an interval, and two colors, this method creates a random 
colorschema that fills 
+     * the entire interval, eg. a feature collection, with a set of color 
between the 
+     * two ones 
+     * This method extends color range to more that maximum defined in the 
ColorScheme.txt 
+     * (12 intervals) [Giuseppe Aruta 2019-1-12]
+     * @param int intervals
+     * @param Color startColor
+     * @param Color endColor
+     * @return com.vividsolutions.jump.workbench.ui.renderer.style.ColorScheme 
class
+     * @throws Exception
+     */
+
+    public static ColorScheme createColorSchema(int intervals,
+            Color startColor, Color endColor) throws Exception {
+
+        final ColorUtils colorUtils = new ColorUtils();
+        final ArrayList<Color> arrayColor = new ArrayList<Color>();
+
+        arrayColor.add(startColor);
+
+        for (int c = 1; c < intervals; c++) {
+
+            final double cellRelDistance = (double) c / (double) (intervals);
+
+            final Color color = colorUtils.interpolateColor(startColor,
+                    endColor, cellRelDistance);
+            arrayColor.add(color);
+        }
+        arrayColor.add(endColor);
+
+        final ColorScheme colorScheme = new ColorScheme("test", arrayColor);
+        return colorScheme;
+    }
+
 }



_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to