List of usage examples for java.awt Color decode
public static Color decode(String nm) throws NumberFormatException
From source file:au.org.ala.biocache.web.WMSController.java
/** * * @return//from w w w . j ava2s. co m * @throws Exception */ private ImgObj wmsCached(WMSTile wco, SpatialSearchRequestParams requestParams, WmsEnv vars, PointType pointType, double[] pbbox, double[] bbox, double[] mbbox, int width, int height, double width_mult, double height_mult, int pointWidth, String[] originalFqs, Set<Integer> hq, String[] boundingBoxFqs, boolean outlinePoints, String outlineColour, HttpServletResponse response, boolean is4326, double[] tilebbox) throws Exception { ImgObj imgObj = null; //grid setup int divs = 16; //number of x & y divisions in the WIDTH/HEIGHT int[][] gridCounts = new int[divs][divs]; int xstep = 256 / divs; int ystep = 256 / divs; double grid_width_mult = (width / (pbbox[2] - pbbox[0])) / (width / divs); double grid_height_mult = (height / (pbbox[1] - pbbox[3])) / (height / divs); int x, y; //if not transparent and zero size, render dots if (vars.alpha > 0 && vars.size > 0) { List<float[]> points = wco.getPoints(); List<int[]> counts = wco.getCounts(); List<Integer> pColour = wco.getColours(); if (pColour.size() == 1 && vars.colourMode.equals("-1")) { pColour.set(0, vars.colour | (vars.alpha << 24)); } //initialise the image object imgObj = ImgObj.create(width, height); for (int j = 0; j < points.size(); j++) { if (hq != null && hq.contains(j)) { //dont render these points continue; } float[] ps = points.get(j); if (ps == null || ps.length == 0) { continue; } //for 4326 double top = tilebbox[3]; double bottom = tilebbox[1]; double left = tilebbox[0]; double right = tilebbox[2]; if (vars.colourMode.equals("grid")) { //render grids int[] count = counts.get(j); //populate grid for (int i = 0; i < ps.length; i += 2) { float lng = ps[i]; float lat = ps[i + 1]; if (lng >= bbox[0] && lng <= bbox[2] && lat >= bbox[1] && lat <= bbox[3]) { if (is4326) { x = convertLngToPixel4326(lng, left, right, width); y = convertLatToPixel4326(lat, top, bottom, height); } else { x = (int) ((convertLngToPixel(lng) - pbbox[0]) * grid_width_mult); y = (int) ((convertLatToPixel(lat) - pbbox[3]) * grid_height_mult); } if (x >= 0 && x < divs && y >= 0 && y < divs) { gridCounts[x][y] += count[i / 2]; } } } } else { //render points Paint currentFill = new Color(pColour.get(j), true); imgObj.g.setPaint(currentFill); Color oColour = Color.decode(outlineColour); for (int i = 0; i < ps.length; i += 2) { float lng = ps[i]; float lat = ps[i + 1]; if (lng >= bbox[0] && lng <= bbox[2] && lat >= bbox[1] && lat <= bbox[3]) { if (is4326) { x = convertLngToPixel4326(lng, left, right, width); y = convertLatToPixel4326(lat, top, bottom, height); } else { x = (int) ((convertLngToPixel(lng) - pbbox[0]) * width_mult); y = (int) ((convertLatToPixel(lat) - pbbox[3]) * height_mult); } imgObj.g.fillOval(x - vars.size, y - vars.size, pointWidth, pointWidth); if (outlinePoints) { imgObj.g.setPaint(oColour); imgObj.g.drawOval(x - vars.size, y - vars.size, pointWidth, pointWidth); imgObj.g.setPaint(currentFill); } } } } } } //no points if (imgObj == null) { if (vars.highlight == null) { displayBlankImage(response); return null; } } else if (vars.colourMode.equals("grid")) { //draw grid for (x = 0; x < divs; x++) { for (y = 0; y < divs; y++) { int v = gridCounts[x][y]; if (v > 0) { if (v > 500) { v = 500; } int colour = (((500 - v) / 2) << 8) | (vars.alpha << 24) | 0x00FF0000; imgObj.g.setColor(new Color(colour)); imgObj.g.fillRect(x * xstep, y * ystep, xstep, ystep); } } } } else { drawUncertaintyCircles(requestParams, vars, height, width, pbbox, mbbox, width_mult, height_mult, imgObj.g, originalFqs, boundingBoxFqs, is4326, tilebbox); } //highlight if (vars.highlight != null) { imgObj = drawHighlight(requestParams, vars, pointType, width, height, pbbox, width_mult, height_mult, imgObj, originalFqs, boundingBoxFqs, is4326, tilebbox); } return imgObj; }
From source file:org.kalypsodeegree_impl.graphics.sld.SLDFactory.java
private static SortedMap<Double, ColorMapEntry> createColorMap(final Element colorMapElement) { final SortedMap<Double, ColorMapEntry> colorMap = new TreeMap<>(); if (colorMapElement == null) return null; final NodeList entryNodes = colorMapElement.getChildNodes(); for (int i = 0; i < entryNodes.getLength(); i++) { final Node entryNode = entryNodes.item(i); final String nodeName = entryNode.getNodeName(); final String namespaceUri = entryNode.getNamespaceURI(); if (entryNode instanceof Element && NS.SLD.equals(namespaceUri) && "ColorMapEntry".equals(nodeName)) //$NON-NLS-1$ {/*from ww w .j av a2 s . co m*/ final Element entryElement = (Element) entryNode; final String colorAttribute = entryElement.getAttribute("color"); //$NON-NLS-1$ final String opacityAttribite = entryElement.getAttribute("opacity"); //$NON-NLS-1$ final String quantityAttribute = entryElement.getAttribute("quantity"); //$NON-NLS-1$ final String labelAttribute = entryElement.getAttribute("label"); //$NON-NLS-1$ final Color color = Color.decode(colorAttribute); final Double opacity = NumberUtils.toDouble(opacityAttribite, 1.0); final Double quantity = NumberUtils.toDouble(quantityAttribute, Double.NaN); final String label = StringUtils.trimToEmpty(labelAttribute); if (Double.isNaN(quantity)) System.err.println( String.format("SLD-Parser: skipping quantity '%s', not a number.", quantityAttribute)); else { final ColorMapEntry colorMapEntryObject = new ColorMapEntry_Impl(color, opacity, quantity, label); colorMap.put(quantity, colorMapEntryObject); } } } return colorMap; }
From source file:au.org.ala.biocache.web.WMSController.java
private void renderPoints(WmsEnv vars, double[] pbbox, double width_mult, double height_mult, int pointWidth, boolean outlinePoints, String outlineColour, List<Integer> pColour, ImgObj imgObj, int j, List<OccurrencePoint> ps, boolean is4326, double[] tilebbox, int height, int width) { int x;//from ww w .j a v a 2 s . c o m int y; Paint currentFill = new Color(pColour.get(j), true); imgObj.g.setPaint(currentFill); Color oColour = Color.decode(outlineColour); //for 4326 double top = tilebbox[3]; double bottom = tilebbox[1]; double left = tilebbox[0]; double right = tilebbox[2]; for (int i = 0; i < ps.size(); i++) { OccurrencePoint pt = ps.get(i); float lng = pt.getCoordinates().get(0).floatValue(); float lat = pt.getCoordinates().get(1).floatValue(); if (is4326) { x = convertLngToPixel4326(lng, left, right, width); y = convertLatToPixel4326(lat, top, bottom, height); } else { x = (int) ((convertLngToPixel(lng) - pbbox[0]) * width_mult); y = (int) ((convertLatToPixel(lat) - pbbox[3]) * height_mult); } //System.out.println("Drawing an oval....."); imgObj.g.fillOval(x - vars.size, y - vars.size, pointWidth, pointWidth); if (outlinePoints) { imgObj.g.setPaint(oColour); imgObj.g.drawOval(x - vars.size, y - vars.size, pointWidth, pointWidth); imgObj.g.setPaint(currentFill); } } }