Revision: 6673
http://sourceforge.net/p/jump-pilot/code/6673
Author: michaudm
Date: 2021-03-09 06:51:39 +0000 (Tue, 09 Mar 2021)
Log Message:
-----------
Fix GradientCanvas (synchronize with github repo)
Modified Paths:
--------------
core/trunk/src/org/openjump/core/rasterimage/styler/ui/GradientCanvas.java
Modified:
core/trunk/src/org/openjump/core/rasterimage/styler/ui/GradientCanvas.java
===================================================================
--- core/trunk/src/org/openjump/core/rasterimage/styler/ui/GradientCanvas.java
2021-02-09 07:09:11 UTC (rev 6672)
+++ core/trunk/src/org/openjump/core/rasterimage/styler/ui/GradientCanvas.java
2021-03-09 06:51:39 UTC (rev 6673)
@@ -6,6 +6,9 @@
import java.awt.Graphics2D;
import java.awt.LinearGradientPaint;
import java.awt.Paint;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.TreeMap;
import javax.swing.JComponent;
import org.openjump.core.rasterimage.styler.ColorMapEntry;
@@ -70,13 +73,23 @@
Graphics2D g2d = (Graphics2D) g;
LinearGradientPaint paint = null;
- float[] fractions = new float[colorMapEntries.length];
- Color[] colors = new Color[colorMapEntries.length];
- for(int c=0; c<colors.length; c++) {
- colors[c] = colorMapEntries[c].getColor();
- fractions[c] = (float) (colorMapEntries[c].getUpperValue()/
colorMapEntries[colorMapEntries.length-1].getUpperValue());
+ // put values of the colorMapEntries in a TreeMap to filter possible
duplicates
+ // in fraction values (makes LinearGradientPaint component throws
Exception)
+ Map<Float,Color> map = new TreeMap<>();
+ for (ColorMapEntry colorMapEntry : colorMapEntries) {
+ float fraction = (float) (colorMapEntry.getUpperValue() /
+ colorMapEntries[colorMapEntries.length -
1].getUpperValue());
+ map.put(fraction, colorMapEntry.getColor());
}
-
+ float[] fractions = new float[map.size()];
+ Color[] colors = new Color[map.size()];
+ int index = 0;
+ for (Map.Entry<Float,Color> entry : map.entrySet()) {
+ fractions[index] = entry.getKey();
+ colors[index] = entry.getValue();
+ index++;
+ }
+ System.out.println(Arrays.toString(fractions));
if(type == GradientType.HORIZONTAL) {
if (orientation == GradientOrientation.DIRECT) {
paint = new LinearGradientPaint(0, 0, width, height,
fractions, colors);
@@ -96,8 +109,8 @@
Paint oldPaint = g2d.getPaint();
g2d.setPaint(paint);
g2d.fillRect(0, 0, (int)width, (int) height);
- g2d.setPaint(oldPaint);
-
+ g2d.setPaint(oldPaint);
+
}
public GradientType getType() {
_______________________________________________
Jump-pilot-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel