/** * Creates a {@link ColorMapLegendCreator} using the provided elements. * * @return a {@link ColorMapLegendCreator}. */ public ColorMapLegendCreator create() { return new ColorMapLegendCreator(this); }
public synchronized BufferedImage getLegend() { // do we laraedy have a legend if (legend == null) { // init all the values init(); // now build the individuals legends // // header // // XXX no header for the moment // // body // final Queue<BufferedImage> body = createBody(); // // footer // if (bandInformation) { final Queue<BufferedImage> footer = createFooter(); body.addAll(footer); } // now merge them legend = mergeRows(body); } return legend; }
private synchronized BufferedImage createResponse() { if (image == null) { if (cMapLegendCreator != null) // creating a legend image = cMapLegendCreator.getLegend(); else { image = ImageUtils.createImage(width, height, (IndexColorModel) null, transparent); final Graphics2D graphics = ImageUtils.prepareTransparency( transparent, bgColor, image, new HashMap<RenderingHints.Key, Object>()); if (defaultLegend == null) { drawRasterIcon(graphics); } else { graphics.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics.drawImage(defaultLegend, 0, 0, width, height, null); } graphics.dispose(); } } return image; }
@Test public void testRuleTextIntervalOneElements() { StyleBuilder sb = new StyleBuilder(); ColorMap cmap = sb.createColorMap( new String[] {null}, new double[] {10}, new Color[] {Color.RED}, ColorMap.TYPE_INTERVALS); Style style = sb.createStyle(sb.createRasterSymbolizer(cmap, 1)); RasterLayerLegendHelper helper = new RasterLayerLegendHelper(request, style, null); List<ColorMapEntryLegendBuilder> rows = new ArrayList<>(helper.getcMapLegendCreator().getBodyRows()); assertEquals(1, rows.size()); ColorMapEntryLegendBuilder firstRow = rows.get(0); assertEquals("x < 10.0", firstRow.getRuleManager().text); }
cycleBodyRows(graphics); fontAntiAliasing, borderColor)); cycleFooterRows(graphics);
@Test public void testRuleTextRampOneElements() { StyleBuilder sb = new StyleBuilder(); ColorMap cmap = sb.createColorMap( new String[] {null}, new double[] {10}, new Color[] {Color.RED}, ColorMap.TYPE_RAMP); Style style = sb.createStyle(sb.createRasterSymbolizer(cmap, 1)); RasterLayerLegendHelper helper = new RasterLayerLegendHelper(request, style, null); List<ColorMapEntryLegendBuilder> rows = new ArrayList<>(helper.getcMapLegendCreator().getBodyRows()); assertEquals(1, rows.size()); ColorMapEntryLegendBuilder firstRow = rows.get(0); assertEquals("", firstRow.getRuleManager().text); }
@Test public void testRuleTextRampTwoElements() { StyleBuilder sb = new StyleBuilder(); ColorMap cmap = sb.createColorMap( new String[] {null, null}, new double[] {10, 100}, new Color[] {Color.RED, Color.BLUE}, ColorMap.TYPE_RAMP); Style style = sb.createStyle(sb.createRasterSymbolizer(cmap, 1)); RasterLayerLegendHelper helper = new RasterLayerLegendHelper(request, style, null); List<ColorMapEntryLegendBuilder> rows = new ArrayList<>(helper.getcMapLegendCreator().getBodyRows()); assertEquals(2, rows.size()); ColorMapEntryLegendBuilder firstRow = rows.get(0); assertEquals("10.0 >= x", firstRow.getRuleManager().text); ColorMapEntryLegendBuilder lastRow = rows.get(1); assertEquals("100.0 <= x", lastRow.getRuleManager().text); }
@Test public void testRuleTextIntervalsTwoElements() { StyleBuilder sb = new StyleBuilder(); ColorMap cmap = sb.createColorMap( new String[] {null, null}, new double[] {10, 100}, new Color[] {Color.RED, Color.BLUE}, ColorMap.TYPE_INTERVALS); Style style = sb.createStyle(sb.createRasterSymbolizer(cmap, 1)); RasterLayerLegendHelper helper = new RasterLayerLegendHelper(request, style, null); List<ColorMapEntryLegendBuilder> rows = new ArrayList<>(helper.getcMapLegendCreator().getBodyRows()); assertEquals(2, rows.size()); ColorMapEntryLegendBuilder firstRow = rows.get(0); assertEquals("x < 10.0", firstRow.getRuleManager().text); ColorMapEntryLegendBuilder lastRow = rows.get(1); assertEquals("10.0 <= x < 100.0", lastRow.getRuleManager().text); }
@Test public void testInfiniteOnIntervals() { StyleBuilder sb = new StyleBuilder(); ColorMap cmap = sb.createColorMap( new String[] {null, null, null}, new double[] {Double.NEGATIVE_INFINITY, 50, Double.POSITIVE_INFINITY}, new Color[] {Color.RED, Color.WHITE, Color.BLUE}, ColorMap.TYPE_INTERVALS); Style style = sb.createStyle(sb.createRasterSymbolizer(cmap, 1)); RasterLayerLegendHelper helper = new RasterLayerLegendHelper(request, style, null); List<ColorMapEntryLegendBuilder> rows = new ArrayList<>(helper.getcMapLegendCreator().getBodyRows()); assertEquals(2, rows.size()); ColorMapEntryLegendBuilder firstRow = rows.get(0); assertEquals("x < 50.0", firstRow.getRuleManager().text); ColorMapEntryLegendBuilder midRow = rows.get(1); assertEquals("50.0 <= x", midRow.getRuleManager().text); }
@Test public void testRuleTextIntervalsThreeElements() { StyleBuilder sb = new StyleBuilder(); ColorMap cmap = sb.createColorMap( new String[] {null, null, null}, new double[] {10, 50, 100}, new Color[] {Color.RED, Color.WHITE, Color.BLUE}, ColorMap.TYPE_INTERVALS); Style style = sb.createStyle(sb.createRasterSymbolizer(cmap, 1)); RasterLayerLegendHelper helper = new RasterLayerLegendHelper(request, style, null); List<ColorMapEntryLegendBuilder> rows = new ArrayList<>(helper.getcMapLegendCreator().getBodyRows()); assertEquals(3, rows.size()); ColorMapEntryLegendBuilder firstRow = rows.get(0); assertEquals("x < 10.0", firstRow.getRuleManager().text); ColorMapEntryLegendBuilder midRow = rows.get(1); assertEquals("10.0 <= x < 50.0", midRow.getRuleManager().text); ColorMapEntryLegendBuilder lastRow = rows.get(2); assertEquals("50.0 <= x < 100.0", lastRow.getRuleManager().text); }
@Test public void testRuleTextRampThreeElements() { StyleBuilder sb = new StyleBuilder(); ColorMap cmap = sb.createColorMap( new String[] {null, null, null}, new double[] {10, 50, 100}, new Color[] {Color.RED, Color.WHITE, Color.BLUE}, ColorMap.TYPE_RAMP); Style style = sb.createStyle(sb.createRasterSymbolizer(cmap, 1)); RasterLayerLegendHelper helper = new RasterLayerLegendHelper(request, style, null); List<ColorMapEntryLegendBuilder> rows = new ArrayList<>(helper.getcMapLegendCreator().getBodyRows()); assertEquals(3, rows.size()); ColorMapEntryLegendBuilder firstRow = rows.get(0); assertEquals("10.0 >= x", firstRow.getRuleManager().text); ColorMapEntryLegendBuilder midRow = rows.get(1); assertEquals("50.0 = x", midRow.getRuleManager().text); ColorMapEntryLegendBuilder lastRow = rows.get(2); assertEquals("100.0 <= x", lastRow.getRuleManager().text); }
new ArrayList<>(helper.getcMapLegendCreator().getBodyRows()); assertEquals(2, rows.size()); ColorMapEntryLegendBuilder firstRow = rows.get(0); rows = new ArrayList<>(helper.getcMapLegendCreator().getBodyRows()); assertEquals(2, rows.size()); firstRow = rows.get(0); rows = new ArrayList<>(helper.getcMapLegendCreator().getBodyRows()); assertEquals(2, rows.size()); firstRow = rows.get(0);