Revision: 6209 http://sourceforge.net/p/jump-pilot/code/6209 Author: michaudm Date: 2019-12-30 15:22:01 +0000 (Mon, 30 Dec 2019) Log Message: ----------- Fix bug #488 : color ramp inverted
Modified Paths: -------------- core/trunk/src/org/openjump/core/rasterimage/styler/ui/GradientCanvas.java core/trunk/src/org/openjump/core/rasterimage/styler/ui/GradientLabelLegendComponent.java Modified: core/trunk/src/org/openjump/core/rasterimage/styler/ui/GradientCanvas.java =================================================================== --- core/trunk/src/org/openjump/core/rasterimage/styler/ui/GradientCanvas.java 2019-12-30 11:41:16 UTC (rev 6208) +++ core/trunk/src/org/openjump/core/rasterimage/styler/ui/GradientCanvas.java 2019-12-30 15:22:01 UTC (rev 6209) @@ -33,17 +33,42 @@ this.width = width; this.height = height; this.type = type; - + this.orientation = GradientOrientation.DIRECT; super.setSize(new Dimension(width, height)); } + + /** + * Construct a JComponent whose background is stretched between colorStart and + * colorEnd. + * + * @param colorMapEntries map values to colors + * @param width Width of the stretched effect. + * @param height Height of the stretched effect. + * @param type Gradient direction. HORIZONTAL colorStart is on left and colorEnd is on right, VERTICAL + * colorStart is at top and colorEnd is bottom. + * @param orientation Gradient orientation. DIRECT is oriented from top to bottom + * or from left to right, INVERSE is the opposite. + */ + public GradientCanvas(ColorMapEntry[] colorMapEntries, int width, int height, + GradientType type, GradientOrientation orientation) { + + this.colorMapEntries = colorMapEntries; + this.width = width; + this.height = height; + this.type = type; + this.orientation = orientation; + super.setSize(new Dimension(width, height)); + + } /* * Stretched for vertical effect from top to bottom and for horizontal effect from left to right. */ @Override - public void paint(Graphics g){ - + public void paint(Graphics g){ + + Graphics2D g2d = (Graphics2D) g; LinearGradientPaint paint = null; float[] fractions = new float[colorMapEntries.length]; Color[] colors = new Color[colorMapEntries.length]; @@ -52,13 +77,22 @@ fractions[c] = (float) (colorMapEntries[c].getUpperValue()/ colorMapEntries[colorMapEntries.length-1].getUpperValue()); } - if(type == GradientType.HORIZONTAL){ - paint = new LinearGradientPaint(0, 0, width, height, fractions, colors); - } else if (type == GradientType.VERTICAL){ - paint = new LinearGradientPaint((width / 2), 0, (width/2), height, fractions, colors); + if(type == GradientType.HORIZONTAL) { + if (orientation == GradientOrientation.DIRECT) { + paint = new LinearGradientPaint(0, 0, width, height, fractions, colors); + } + else if (orientation == GradientOrientation.INVERSE) { + paint = new LinearGradientPaint(width, height, 0, 0, fractions, colors); + } + } else if (type == GradientType.VERTICAL) { + if (orientation == GradientOrientation.DIRECT) { + paint = new LinearGradientPaint((width / 2), 0, (width / 2), height, fractions, colors); + } + if (orientation == GradientOrientation.INVERSE) { + paint = new LinearGradientPaint((width / 2), height, (width / 2), 0, fractions, colors); + } } - - Graphics2D g2d = (Graphics2D) g; + Paint oldPaint = g2d.getPaint(); g2d.setPaint(paint); g2d.fillRect(0, 0, (int)width, (int) height); @@ -82,7 +116,10 @@ private final float width; private final float height; - public enum GradientType {HORIZONTAL, VERTICAL}; + public enum GradientType {HORIZONTAL, VERTICAL} private final GradientType type; + public enum GradientOrientation {DIRECT, INVERSE} + private final GradientOrientation orientation; + } \ No newline at end of file Modified: core/trunk/src/org/openjump/core/rasterimage/styler/ui/GradientLabelLegendComponent.java =================================================================== --- core/trunk/src/org/openjump/core/rasterimage/styler/ui/GradientLabelLegendComponent.java 2019-12-30 11:41:16 UTC (rev 6208) +++ core/trunk/src/org/openjump/core/rasterimage/styler/ui/GradientLabelLegendComponent.java 2019-12-30 15:22:01 UTC (rev 6209) @@ -1,10 +1,6 @@ package org.openjump.core.rasterimage.styler.ui; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; +import java.awt.*; import java.util.Map; import java.util.TreeMap; @@ -177,8 +173,15 @@ add(jLabel_NoDataValue, gridBagConstraints); // Set gradient color panel - final GUIUtils updatePanel = new GUIUtils(); - updatePanel.setGradientPanel(jPanel_Gradient, paletteColorMapEntry); + //final GUIUtils updatePanel = new GUIUtils(); + //updatePanel.setGradientPanel(jPanel_Gradient, paletteColorMapEntry); + GradientCanvas gradientCanvas = new GradientCanvas( + paletteColorMapEntry, 40, 100, + GradientCanvas.GradientType.VERTICAL, + GradientCanvas.GradientOrientation.INVERSE + ); + jPanel_Gradient.setLayout(new BorderLayout()); + jPanel_Gradient.add(gradientCanvas, BorderLayout.CENTER); setPreferredSize(new Dimension(200, 250)); } _______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel