List of usage examples for java.awt Color getRGB
public int getRGB()
From source file:edu.umn.cs.spatialHadoop.operations.Plot.java
public static <S extends Shape> void plotMapReduce(Path inFile, Path outFile, Shape shape, int width, int height, Color color, boolean showBorders, boolean showBlockCount, boolean showRecordCount, boolean background) throws IOException { JobConf job = new JobConf(Plot.class); job.setJobName("Plot"); job.setMapperClass(PlotMap.class); ClusterStatus clusterStatus = new JobClient(job).getClusterStatus(); job.setNumMapTasks(clusterStatus.getMaxMapTasks() * 5); job.setReducerClass(PlotReduce.class); job.setNumReduceTasks(Math.max(1, clusterStatus.getMaxReduceTasks())); job.setMapOutputKeyClass(Rectangle.class); SpatialSite.setShapeClass(job, shape.getClass()); job.setMapOutputValueClass(shape.getClass()); FileSystem inFs = inFile.getFileSystem(job); Rectangle fileMbr = FileMBR.fileMBRMapReduce(inFs, inFile, shape, false); FileStatus inFileStatus = inFs.getFileStatus(inFile); CellInfo[] cellInfos;//w w w . j av a 2s .c om GlobalIndex<Partition> gindex = SpatialSite.getGlobalIndex(inFs, inFile); if (gindex == null) { // A heap file. The map function should partition the file GridInfo gridInfo = new GridInfo(fileMbr.x1, fileMbr.y1, fileMbr.x2, fileMbr.y2); gridInfo.calculateCellDimensions(inFileStatus.getLen(), inFileStatus.getBlockSize()); cellInfos = gridInfo.getAllCells(); // Doesn't make sense to show any partition information in a heap file showBorders = showBlockCount = showRecordCount = false; } else { cellInfos = SpatialSite.cellsOf(inFs, inFile); } // Set cell information in the job configuration to be used by the mapper SpatialSite.setCells(job, cellInfos); // Adjust width and height to maintain aspect ratio if ((fileMbr.x2 - fileMbr.x1) / (fileMbr.y2 - fileMbr.y1) > (double) width / height) { // Fix width and change height height = (int) ((fileMbr.y2 - fileMbr.y1) * width / (fileMbr.x2 - fileMbr.x1)); } else { width = (int) ((fileMbr.x2 - fileMbr.x1) * height / (fileMbr.y2 - fileMbr.y1)); } LOG.info("Creating an image of size " + width + "x" + height); ImageOutputFormat.setFileMBR(job, fileMbr); ImageOutputFormat.setImageWidth(job, width); ImageOutputFormat.setImageHeight(job, height); job.setBoolean(ShowBorders, showBorders); job.setBoolean(ShowBlockCount, showBlockCount); job.setBoolean(ShowRecordCount, showRecordCount); job.setInt(StrokeColor, color.getRGB()); // Set input and output job.setInputFormat(ShapeInputFormat.class); ShapeInputFormat.addInputPath(job, inFile); // Set output committer which will stitch images together after all reducers // finish job.setOutputCommitter(PlotOutputCommitter.class); job.setOutputFormat(ImageOutputFormat.class); TextOutputFormat.setOutputPath(job, outFile); if (background) { JobClient jc = new JobClient(job); lastSubmittedJob = jc.submitJob(job); } else { lastSubmittedJob = JobClient.runJob(job); } }
From source file:com.jcraft.weirdx.XPixmap.java
Graphics getGraphics(GC gc, int mask) { Graphics graphics = imgg;/*w w w .jav a 2 s . co m*/ if (gc == currentGC && gc.time == gctime && (mask & ~gmask) == 0) { return graphics; } gctime = gc.time; currentGC = gc; gmask = mask; if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { java.awt.Rectangle rec = (Rectangle) (gc.clip_mask.getMask()); if (rec == null) { return graphics; } graphics.setClip(rec.x, rec.y, rec.width, rec.height); } if ((mask & GC.GCFunction) != 0) { Color color = getColormap().getColor(gc.fgPixel); if (gc.function == GC.GXxor) { gmask &= ~GC.GCFunction; graphics.setXORMode(new Color((color.getRGB() ^ graphics.getColor().getRGB()) & 0xffffff)); } else if (gc.function == GC.GXinvert) { //System.out.println("Pimxpa: GXinvert"); } else { graphics.setColor(color); } } if ((mask & GC.GCFont) != 0) { XFont font = gc.font; graphics.setFont(font.getFont()); } if ((mask & GC.GCLineWidth) != 0 || (mask & GC.GCLineStyle) != 0 || (mask & GC.GCCapStyle) != 0 || (mask & GC.GCJoinStyle) != 0) { } return graphics; }
From source file:it.eng.spagobi.kpi.utils.BasicTemplateBuilder.java
private SourceBean setLineAttributes(KpiLine line, SourceBean semaphor, SourceBean textCodeName, SourceBean textValue, SourceBean textWeight, SourceBean image1, int level, SourceBean separatorline, SourceBean threshCode, SourceBean threshValue, SourceBean extraimageToAdd) { logger.debug("IN"); KpiValue kpiValue = line.getValue(); ThresholdValue t = null;/*from w w w. ja va 2 s .c o m*/ Color colorSemaphor = null; if (kpiValue != null && kpiValue.getValue() != null) { t = kpiValue.getThresholdOfValue(); if (t != null) { colorSemaphor = t.getColor(); } } Integer xValue = xStarter + (xIncrease * Integer.valueOf(level)); Integer yValue = actualHeight; try { //set Semaphor semaphor.setAttribute("reportElement.x", xValue.toString()); semaphor.setAttribute("reportElement.y", new Integer(yValue.intValue() + 2).toString()); if (colorSemaphor != null) { String color = Integer.toHexString(colorSemaphor.getRGB()); color = "#" + color.substring(2); semaphor.setAttribute("reportElement.forecolor", "#000000"); semaphor.setAttribute("reportElement.backcolor", color); } else { semaphor.setAttribute("reportElement.forecolor", "#FFFFFF"); semaphor.setAttribute("reportElement.backcolor", "#FFFFFF"); } xValue = xValue + semaphorWidth + separatorWidth; // set text 1: Model CODE - Model NAME textCodeName.setAttribute("reportElement.x", (xValue)); textCodeName.setAttribute("reportElement.y", yValue.toString()); SourceBean textValue1 = (SourceBean) textCodeName.getAttribute("text"); textValue1.setCharacters(line.getModelInstanceCode() + "-" + line.getModelNodeName()); xValue = xValue + textWidth + separatorWidth; //Set Value, weight and threshold code and value if (kpiValue != null) { String value1 = kpiValue.getValue() != null ? kpiValue.getValue() : ""; //set text2 textValue.setAttribute("reportElement.y", yValue.toString()); SourceBean textValue2 = (SourceBean) textValue.getAttribute("text"); textValue2.setCharacters(value1); String weight = (kpiValue.getWeight() != null) ? kpiValue.getWeight().toString() : ""; //set text2 xValue = xValue + numbersWidth + separatorWidth; textWeight.setAttribute("reportElement.y", new Integer(yValue.intValue() + 2).toString()); SourceBean textValue3 = (SourceBean) textWeight.getAttribute("text"); textValue3.setCharacters(weight); if (t != null) { try { Threshold tr = DAOFactory.getThresholdDAO().loadThresholdById(t.getThresholdId()); if (!thresholdsList.contains(tr)) { thresholdsList.add(tr); } } catch (EMFUserError e) { logger.error("error in loading the Threshold by Id", e); e.printStackTrace(); } String code = t.getThresholdCode() != null ? t.getThresholdCode() : ""; String codeTh = "Code: " + code; if (codeTh.length() > 20) codeTh = codeTh.substring(0, 19); threshCode.setAttribute("reportElement.y", new Integer(yValue.intValue() - 2).toString()); SourceBean threshCode2 = (SourceBean) threshCode.getAttribute("text"); threshCode2.setCharacters(codeTh); String labelTh = t.getLabel() != null ? t.getLabel() : ""; String min = t.getMinValue() != null ? t.getMinValue().toString() : null; String max = t.getMaxValue() != null ? t.getMaxValue().toString() : null; String valueTh = "Value: "; if (t.getThresholdType().equalsIgnoreCase("RANGE")) { if (min != null && max != null) { valueTh = valueTh + min + "-" + max + " " + labelTh; } else if (min != null && max == null) { valueTh = valueTh + "> " + min + " " + labelTh; } else if (min == null && max != null) { valueTh = valueTh + "< " + max + " " + labelTh; } } else if (t.getThresholdType().equalsIgnoreCase("MINIMUM")) { valueTh = valueTh + "< " + min + " " + labelTh; } else if (t.getThresholdType().equalsIgnoreCase("MAXIMUM")) { valueTh = valueTh + "> " + max + " " + labelTh; } if (valueTh.length() > 25) valueTh = valueTh.substring(0, 24); threshValue.setAttribute("reportElement.y", new Integer(yValue.intValue() + 7).toString()); SourceBean threshValue2 = (SourceBean) threshValue.getAttribute("text"); threshValue2.setCharacters(valueTh); } } //Sets the bullet chart and or the threshold image if (options.getDisplay_bullet_chart() && options.getDisplay_threshold_image()) { //both threshold image and bullet chart have to be seen if (kpiValue != null && kpiValue.getValue() != null && kpiValue.getThresholdValues() != null && !kpiValue.getThresholdValues().isEmpty()) { List thresholdValues = kpiValue.getThresholdValues(); // String chartType = value.getChartType(); String chartType = "BulletGraph"; Double val = new Double(kpiValue.getValue()); Double target = kpiValue.getTarget(); ChartImpl sbi = ChartImpl.createChart(chartType); sbi.setValueDataSet(val); if (target != null) { sbi.setTarget(target); } sbi.setShowAxis(options.getShow_axis()); sbi.setThresholdValues(thresholdValues); JFreeChart chart = sbi.createChart(); ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); String requestIdentity = null; UUIDGenerator uuidGen = UUIDGenerator.getInstance(); UUID uuid = uuidGen.generateTimeBasedUUID(); requestIdentity = uuid.toString(); requestIdentity = requestIdentity.replaceAll("-", ""); String path_param = requestIdentity; String dir = System.getProperty("java.io.tmpdir"); String path = dir + "/" + requestIdentity + ".png"; java.io.File file1 = new java.io.File(path); logger.debug("Where is the image: " + path); try { ChartUtilities.saveChartAsPNG(file1, chart, 89, 11, info); } catch (IOException e) { e.printStackTrace(); logger.error("Error in saving chart", e); } String urlPng = GeneralUtilities.getSpagoBiHost() + GeneralUtilities.getSpagoBiContext() + GeneralUtilities.getSpagoAdapterHttpUrl() + "?ACTION_NAME=GET_PNG2&NEW_SESSION=TRUE&path=" + path_param + "&LIGHT_NAVIGATOR_DISABLED=TRUE"; urlPng = "new java.net.URL(\"" + urlPng + "\")"; logger.debug("Image url: " + urlPng); image1.setAttribute("reportElement.y", yValue.toString()); image1.setAttribute("reportElement.x", new Integer(310).toString()); image1.setAttribute("reportElement.width", 90); SourceBean imageValue = (SourceBean) image1.getAttribute("imageExpression"); imageValue.setCharacters(urlPng); } ThresholdValue tOfVal = line.getThresholdOfValue(); if (tOfVal != null && tOfVal.getPosition() != null && tOfVal.getThresholdCode() != null) { String fileName = "position_" + tOfVal.getPosition().intValue(); String dirName = tOfVal.getThresholdCode(); String urlPng = GeneralUtilities.getSpagoBiHost() + GeneralUtilities.getSpagoBiContext() + GeneralUtilities.getSpagoAdapterHttpUrl() + "?ACTION_NAME=GET_THR_IMAGE&NEW_SESSION=TRUE&fileName=" + fileName + "&dirName=" + dirName + "&LIGHT_NAVIGATOR_DISABLED=TRUE"; urlPng = "new java.net.URL(\"" + urlPng + "\")"; logger.debug("url: " + urlPng); extraimageToAdd = new SourceBean(image); extraimageToAdd.setAttribute("reportElement.y", yValue.toString()); extraimageToAdd.setAttribute("reportElement.width", 35); extraimageToAdd.setAttribute("reportElement.x", new Integer(408).toString()); SourceBean imageValue = (SourceBean) extraimageToAdd.getAttribute("imageExpression"); imageValue.setCharacters(urlPng); } } else if (options.getDisplay_bullet_chart() && !options.getDisplay_threshold_image()) { //only bullet chart has to be seen if (kpiValue != null && kpiValue.getValue() != null && kpiValue.getThresholdValues() != null && !kpiValue.getThresholdValues().isEmpty()) { List thresholdValues = kpiValue.getThresholdValues(); // String chartType = value.getChartType(); String chartType = "BulletGraph"; Double val = new Double(kpiValue.getValue()); Double target = kpiValue.getTarget(); ChartImpl sbi = ChartImpl.createChart(chartType); sbi.setValueDataSet(val); if (target != null) { sbi.setTarget(target); } sbi.setShowAxis(options.getShow_axis()); sbi.setThresholdValues(thresholdValues); JFreeChart chart = sbi.createChart(); ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); String requestIdentity = null; UUIDGenerator uuidGen = UUIDGenerator.getInstance(); UUID uuid = uuidGen.generateTimeBasedUUID(); requestIdentity = uuid.toString(); requestIdentity = requestIdentity.replaceAll("-", ""); String path_param = requestIdentity; String dir = System.getProperty("java.io.tmpdir"); String path = dir + "/" + requestIdentity + ".png"; java.io.File file1 = new java.io.File(path); logger.debug("Where is the image: " + path); try { ChartUtilities.saveChartAsPNG(file1, chart, 130, 11, info); } catch (IOException e) { e.printStackTrace(); logger.error("Error in saving chart", e); } String urlPng = GeneralUtilities.getSpagoBiHost() + GeneralUtilities.getSpagoBiContext() + GeneralUtilities.getSpagoAdapterHttpUrl() + "?ACTION_NAME=GET_PNG2&NEW_SESSION=TRUE&path=" + path_param + "&LIGHT_NAVIGATOR_DISABLED=TRUE"; urlPng = "new java.net.URL(\"" + urlPng + "\")"; logger.debug("Image url: " + urlPng); image1.setAttribute("reportElement.y", yValue.toString()); SourceBean imageValue = (SourceBean) image1.getAttribute("imageExpression"); imageValue.setCharacters(urlPng); } } else if (!options.getDisplay_bullet_chart() && options.getDisplay_threshold_image()) { //only threshold image has to be seen ThresholdValue tOfVal = line.getThresholdOfValue(); if (tOfVal != null && tOfVal.getPosition() != null && tOfVal.getThresholdCode() != null) { String fileName = "position_" + tOfVal.getPosition().intValue(); String dirName = tOfVal.getThresholdCode(); String urlPng = GeneralUtilities.getSpagoBiHost() + GeneralUtilities.getSpagoBiContext() + GeneralUtilities.getSpagoAdapterHttpUrl() + "?ACTION_NAME=GET_THR_IMAGE&NEW_SESSION=TRUE&fileName=" + fileName + "&dirName=" + dirName + "&LIGHT_NAVIGATOR_DISABLED=TRUE"; urlPng = "new java.net.URL(\"" + urlPng + "\")"; logger.debug("url: " + urlPng); image1.setAttribute("reportElement.y", yValue.toString()); SourceBean imageValue = (SourceBean) image1.getAttribute("imageExpression"); imageValue.setCharacters(urlPng); } } separatorline.setAttribute("reportElement.y", new Integer(yValue.intValue() + 16).toString()); } catch (SourceBeanException e) { logger.error("error in drawing the line", e); e.printStackTrace(); } logger.debug("OUT"); return extraimageToAdd; }
From source file:com.hygenics.imaging.ImageCleanup.java
/** * Private method that performs the sharpen */// w w w . j a v a 2s. c om public byte[] sharpen(byte[] ibytes, int weight, String format) { /* * Kernel is |-1|-1|-1| |-1|weight|-1||-1|-1|-1| */ try { InputStream is = new ByteArrayInputStream(ibytes); BufferedImage proxyimage = ImageIO.read(is); // a secondary image for storing new outcomes BufferedImage image2 = new BufferedImage(proxyimage.getWidth(), proxyimage.getHeight(), BufferedImage.TYPE_BYTE_GRAY); // image width and height int width = proxyimage.getWidth(); int height = proxyimage.getHeight(); int r = 0; int g = 0; int b = 0; Color c = null; for (int x = 1; x < width - 1; x++) { for (int y = 1; y < height - 1; y++) { // sharpen the image using the kernel (center is c5) Color c00 = new Color(proxyimage.getRGB(x - 1, y - 1)); Color c01 = new Color(proxyimage.getRGB(x - 1, y)); Color c02 = new Color(proxyimage.getRGB(x - 1, y + 1)); Color c10 = new Color(proxyimage.getRGB(x, y - 1)); Color c11 = new Color(proxyimage.getRGB(x, y)); Color c12 = new Color(proxyimage.getRGB(x, y + 1)); Color c20 = new Color(proxyimage.getRGB(x + 1, y - 1)); Color c21 = new Color(proxyimage.getRGB(x + 1, y)); Color c22 = new Color(proxyimage.getRGB(x + 1, y + 1)); // apply the kernel for r r = -c00.getRed() - c01.getRed() - c02.getRed() - c10.getRed() + (weight * c11.getRed()) - c12.getRed() - c20.getRed() - c21.getRed() - c22.getRed(); // apply the kernel for g g = c00.getGreen() - c01.getGreen() - c02.getGreen() - c10.getGreen() + (weight * c11.getGreen()) - c12.getGreen() - c20.getGreen() - c21.getGreen() - c22.getGreen(); // apply the transformation for b b = c00.getBlue() - c01.getBlue() - c02.getBlue() - c10.getBlue() + (weight * c11.getBlue()) - c12.getBlue() - c20.getBlue() - c21.getBlue() - c22.getBlue(); // set the new rgb values r = Math.min(255, Math.max(0, r)); g = Math.min(255, Math.max(0, g)); b = Math.min(255, Math.max(0, b)); c = new Color(r, g, b); // set the new mask colors in the new image image2.setRGB(x, y, c.getRGB()); } } // add the new values back to the original image Color cmask = null; Color corig = null; for (int x = 1; x < width - 1; x++) { for (int y = 1; y < height - 1; y++) { // get the 2 colors cmask = new Color(image2.getRGB(x, y)); corig = new Color(proxyimage.getRGB(x, y)); // add the new values r = cmask.getRed() + corig.getRed(); g = cmask.getGreen() + corig.getGreen(); b = cmask.getBlue() + corig.getBlue(); // set the new rgb values r = Math.min(255, Math.max(0, r)); g = Math.min(255, Math.max(0, g)); b = Math.min(255, Math.max(0, b)); proxyimage.setRGB(x, y, new Color(r, g, b).getRGB()); } } try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { ImageIO.write(proxyimage, format, baos); ibytes = baos.toByteArray(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return ibytes; }
From source file:org.opencms.loader.CmsImageScaler.java
/** * Returns a scaled version of the given image byte content according this image scalers parameters.<p> * //from w w w .java2 s .com * @param content the image byte content to scale * @param rootPath the root path of the image file in the VFS * * @return a scaled version of the given image byte content according to the provided scaler parameters */ public byte[] scaleImage(byte[] content, String rootPath) { byte[] result = content; // flag for processed image boolean imageProcessed = false; // initialize image crop area initCropArea(); RenderSettings renderSettings; if ((m_renderMode == 0) && (m_quality == 0)) { // use default render mode and quality renderSettings = new RenderSettings(Simapi.RENDER_QUALITY); } else { // use special render mode and/or quality renderSettings = new RenderSettings(m_renderMode); if (m_quality != 0) { renderSettings.setCompressionQuality(m_quality / 100f); } } // set max blur size renderSettings.setMaximumBlurSize(m_maxBlurSize); // new create the scaler Simapi scaler = new Simapi(renderSettings); // calculate a valid image type supported by the imaging library (e.g. "JPEG", "GIF") String imageType = Simapi.getImageType(rootPath); if (imageType == null) { // no type given, maybe the name got mixed up String mimeType = OpenCms.getResourceManager().getMimeType(rootPath, null, null); // check if this is another known MIME type, if so DONT use it (images should not be named *.pdf) if (mimeType == null) { // no MIME type found, use JPEG format to write images to the cache imageType = Simapi.TYPE_JPEG; } } if (imageType == null) { // unknown type, unable to scale the image if (LOG.isDebugEnabled()) { LOG.debug( Messages.get().getBundle().key(Messages.ERR_UNABLE_TO_SCALE_IMAGE_2, rootPath, toString())); } return result; } try { BufferedImage image = Simapi.read(content); if (isCropping()) { // check if the crop width / height are not larger then the source image if ((m_cropHeight > image.getHeight()) || (m_cropWidth > image.getWidth())) { // crop height / width is outside of image - return image unchanged return result; } } Color color = getColor(); if (!m_filters.isEmpty()) { Iterator<String> i = m_filters.iterator(); while (i.hasNext()) { String filter = i.next(); if (FILTER_GRAYSCALE.equals(filter)) { // add a gray scale filter GrayscaleFilter grayscaleFilter = new GrayscaleFilter(); renderSettings.addImageFilter(grayscaleFilter); } else if (FILTER_SHADOW.equals(filter)) { // add a drop shadow filter ShadowFilter shadowFilter = new ShadowFilter(); shadowFilter.setXOffset(5); shadowFilter.setYOffset(5); shadowFilter.setOpacity(192); shadowFilter.setBackgroundColor(color.getRGB()); color = Simapi.COLOR_TRANSPARENT; renderSettings.setTransparentReplaceColor(Simapi.COLOR_TRANSPARENT); renderSettings.addImageFilter(shadowFilter); } } } if (isCropping()) { // image crop operation image = scaler.cropToSize(image, m_cropX, m_cropY, m_cropWidth, m_cropHeight, getWidth(), getHeight(), color); imageProcessed = true; } else { // only rescale the image, if the width and hight are different to the target size int imageWidth = image.getWidth(); int imageHeight = image.getHeight(); // image rescale operation switch (getType()) { // select the "right" method of scaling according to the "t" parameter case 1: // thumbnail generation mode (like 0 but no image enlargement) image = scaler.resize(image, getWidth(), getHeight(), color, getPosition(), false); imageProcessed = true; break; case 2: // scale to exact target size, crop what does not fit if (((imageWidth != getWidth()) || (imageHeight != getHeight()))) { image = scaler.resize(image, getWidth(), getHeight(), getPosition()); imageProcessed = true; } break; case 3: // scale and keep image proportions, target size variable if (((imageWidth != getWidth()) || (imageHeight != getHeight()))) { image = scaler.resize(image, getWidth(), getHeight(), true); imageProcessed = true; } break; case 4: // don't keep image proportions, use exact target size if (((imageWidth != getWidth()) || (imageHeight != getHeight()))) { image = scaler.resize(image, getWidth(), getHeight(), false); imageProcessed = true; } break; case 5: // scale and keep image proportions, target size variable, include maxWidth / maxHeight option // image proportions have already been calculated so should not be a problem, use // 'false' to make sure image size exactly matches height and width attributes of generated tag if (((imageWidth != getWidth()) || (imageHeight != getHeight()))) { image = scaler.resize(image, getWidth(), getHeight(), false); imageProcessed = true; } break; default: // scale to exact target size with background padding image = scaler.resize(image, getWidth(), getHeight(), color, getPosition(), true); imageProcessed = true; } } if (!m_filters.isEmpty()) { Rectangle targetSize = scaler.applyFilterDimensions(getWidth(), getHeight()); image = scaler.resize(image, (int) targetSize.getWidth(), (int) targetSize.getHeight(), Simapi.COLOR_TRANSPARENT, Simapi.POS_CENTER); image = scaler.applyFilters(image); imageProcessed = true; } // get the byte result for the scaled image if some changes have been made. // otherwiese use the original image if (imageProcessed) { result = scaler.getBytes(image, imageType); } } catch (Exception e) { if (LOG.isDebugEnabled()) { LOG.debug( Messages.get().getBundle().key(Messages.ERR_UNABLE_TO_SCALE_IMAGE_2, rootPath, toString()), e); } } return result; }
From source file:net.sf.jasperreports.engine.export.HtmlExporter.java
protected boolean matchesBackcolor(Color backcolor) { if (backcolorStack.isEmpty()) { return false; }/*from ww w. j a va 2 s.co m*/ Color currentBackcolor = backcolorStack.getFirst(); return currentBackcolor != null && backcolor.getRGB() == currentBackcolor.getRGB(); }
From source file:es.sm2.openppm.front.servlets.ProjectControlServlet.java
/** * Chart kpis//from w w w . ja v a 2 s. c om * * @param req * @param resp * @throws IOException */ private void kpiChartJX(HttpServletRequest req, HttpServletResponse resp) throws IOException { int idProject = ParamUtil.getInteger(req, "id"); PrintWriter out = resp.getWriter(); try { Date minDate = null; Date maxDate = null; SimpleDateFormat date = new SimpleDateFormat("MM/dd/yyyy"); SimpleDateFormat tempDate = new SimpleDateFormat("MM/dd/yyyy"); Random random = new Random(); Float r = null; Float g = null; Float b = null; String[] defaultColors = new String[] { "#4bb2c5", "#c5b47f", "#EAA228", "#579575", "#839557", "#958c12", "#953579", "#4b5de4", "#d8b83f", "#ff5800", "#0085cc" }; Boolean insufficientDates = true; HistorickpiLogic historickpiLogic = new HistorickpiLogic(); ProjectLogic projectLogic = new ProjectLogic(getSettings(req), getResourceBundle(req)); JSONArray kpisValuesJSON = new JSONArray(); JSONArray kpisNamesJSON = new JSONArray(); JSONArray kpisColorsJSON = new JSONArray(); JSONObject updateJSON = new JSONObject(); List<String> joins = new ArrayList<String>(); joins.add(Projectkpi.METRICKPI); Project project = projectLogic.findById(idProject); ProjectKpiLogic projectKpiLogic = new ProjectKpiLogic(); List<Projectkpi> projectKpis = projectKpiLogic.findByRelation(Projectkpi.PROJECT, project, joins); //colors for (String defaultColor : defaultColors) { kpisColorsJSON.add(defaultColor); } int varianceColors = projectKpis.size() > defaultColors.length ? projectKpis.size() - defaultColors.length : 0; for (int i = 0; i < varianceColors; i++) { random.setSeed(new Date().getTime()); r = random.nextFloat(); g = random.nextFloat(); b = random.nextFloat(); Color randomColor = new Color(r, g, b); String rgb = Integer.toHexString(randomColor.getRGB()); rgb = rgb.substring(2, rgb.length()); rgb = StringPool.POUND.concat(rgb); kpisColorsJSON.add(rgb); } List<String> joinsHistoricKpi = new ArrayList<String>(); joinsHistoricKpi.add(Historickpi.EMPLOYEE); joinsHistoricKpi.add(Historickpi.EMPLOYEE + "." + Employee.CONTACT); for (Projectkpi kpi : projectKpis) { JSONArray kpiJSON = new JSONArray(); List<Historickpi> historic = historickpiLogic.findByRelation(Historickpi.PROJECTKPI, new Projectkpi(kpi.getIdProjectKpi()), Historickpi.ACTUALDATE, Constants.ASCENDENT, joinsHistoricKpi); if (!historic.isEmpty()) { String tempDateStr = tempDate.format(historic.get(0).getActualDate()); for (Historickpi hKpi : historic) { JSONArray hKpiJSON = new JSONArray(); hKpiJSON.add(date.format(hKpi.getActualDate())); hKpiJSON.add(hKpi.getValueKpi() == null ? 0 : hKpi.getValueKpi()); if (!tempDateStr.equals(date.format(hKpi.getActualDate()))) { insufficientDates = false; } kpiJSON.add(hKpiJSON); } } kpisValuesJSON.add(kpiJSON); if (kpi.getMetrickpi() != null) { kpisNamesJSON.add(kpi.getMetrickpi().getName()); } else { kpisNamesJSON.add(kpi.getSpecificKpi()); } /* min and max dates*/ if (!insufficientDates) { Date tempMinDate = historic.get(0).getActualDate(); Date tempMaxDate = historic.get(historic.size() - 1).getActualDate(); if (minDate == null && maxDate == null) { minDate = tempMinDate; maxDate = tempMaxDate; } else { if (tempMinDate.compareTo(minDate) < 0) { minDate = tempMinDate; } if (tempMaxDate.compareTo(maxDate) > 0) { maxDate = tempMaxDate; } } } } ChartJQPLOT chart = new ChartJQPLOT(minDate, maxDate); updateJSON.put("tickInterval", chart.getTickInterval()); updateJSON.put("minDate", chart.addDate(minDate, -1)); updateJSON.put("maxDate", chart.addDate(maxDate, 1)); updateJSON.put("kpisColors", kpisColorsJSON); updateJSON.put("kpisNames", kpisNamesJSON); updateJSON.put("kpisValues", kpisValuesJSON); updateJSON.put("insufficientDates", insufficientDates); out.print(updateJSON); } catch (Exception e) { ExceptionUtil.evalueExceptionJX(out, req, getResourceBundle(req), LOGGER, e); } finally { out.close(); } }
From source file:au.org.emii.portal.composer.MapComposer.java
MapLayer mapSpeciesWMSByFilter(String label, String filter, int subType, Query query, boolean grid, int size, float opacity, int colour) { String uri;/*from w w w .j a v a 2s . c o m*/ int r = (colour >> 16) & 0x000000ff; int g = (colour >> 8) & 0x000000ff; int b = (colour) & 0x000000ff; int sz = size; int uncertaintyCheck = 0; float op = opacity; if (activeLayerMapProperties != null) { r = (Integer) activeLayerMapProperties.get(StringConstants.RED); b = (Integer) activeLayerMapProperties.get(StringConstants.BLUE); g = (Integer) activeLayerMapProperties.get(StringConstants.GREEN); sz = (Integer) activeLayerMapProperties.get(StringConstants.SIZE); op = (Float) activeLayerMapProperties.get(StringConstants.OPACITY); uncertaintyCheck = (Integer) activeLayerMapProperties.get(StringConstants.UNCERTAINTY); } if (subType == LayerUtilitiesImpl.SCATTERPLOT) { //set defaults for scatterplot r = 0; g = 0; b = 255; op = 1; sz = 4; } Color c = new Color(r, g, b); String hexColour = Integer.toHexString(c.getRGB() & 0x00ffffff); String envString = ""; //TODO make the default map type configurable envString = "color:" + hexColour + ";colormode:osgrid"; // if (grid) { // colour mode is in 'filter' but need to move it to envString // envString += "colormode:grid"; // } else { // envString = "color:" + hexColour; // } envString += ";name:circle;size:" + sz + ";opacity:1"; if (uncertaintyCheck > 0) { envString += ";uncertainty:1"; } uri = query.getUrl(); uri += "service=WMS&version=1.1.0&request=GetMap&styles=&format=image/png"; uri += "&layers=ALA:occurrences"; uri += "&transparent=true"; uri += (query.getQc() == null ? "" : query.getQc()); uri += "&CACHE=" + useSpeciesWMSCache; uri += "&CQL_FILTER="; LOGGER.debug("Mapping: " + label + " with " + uri + filter); try { if (safeToPerformMapAction()) { if (getMapLayer(label) == null) { MapLayer ml = addWMSLayer(label, label, uri + filter, op, null, null, subType, "", envString, query); if (ml != null) { ml.setDynamicStyle(true); ml.setEnvParams(envString); ml.setGeometryType(LayerUtilitiesImpl.POINT); ml.setBlueVal(b); ml.setGreenVal(g); ml.setRedVal(r); ml.setSizeVal(sz); ml.setOpacity(op); ml.setClustered(false); ml.setSpeciesQuery(query); updateLayerControls(); //create highlight layer MapLayer mlHighlight = (MapLayer) ml.clone(); mlHighlight.setName(ml.getName() + "_highlight"); ml.addChild(mlHighlight); return ml; } else { // fail //hide error, might be clustering zoom in LOGGER.debug("adding WMS layer failed "); } } else { //need to cleanup any additional scripts outstanding openLayersJavascript.useAdditionalScript(); // fail LOGGER.debug("refusing to add a new layer with URI " + uri + " because it already exists in the menu"); } } } catch (Exception ex) { LOGGER.error("error mapSpeciesByNameRank:", ex); } return null; }
From source file:au.org.emii.portal.composer.MapComposer.java
public void applyChange(MapLayer selectedLayer) { if (selectedLayer != null) { /*/*from w ww. ja v a2s . c o m*/ * different path for each type layer 1. symbol 2. classification * legend 3. prediction legend 4. other (wms) */ if (selectedLayer.isDynamicStyle()) { Color c = new Color(selectedLayer.getRedVal(), selectedLayer.getGreenVal(), selectedLayer.getBlueVal()); String hexColour = Integer.toHexString(c.getRGB() & 0x00ffffff); String rgbColour = "rgb(" + selectedLayer.getRedVal() + "," + selectedLayer.getGreenVal() + "," + selectedLayer.getBlueVal() + ")"; selectedLayer.setEnvColour(rgbColour); if (selectedLayer.getType() == LayerUtilitiesImpl.GEOJSON) { openLayersJavascript.redrawFeatures(selectedLayer); } else if (selectedLayer.getType() == LayerUtilitiesImpl.WKT) { openLayersJavascript.redrawWKTFeatures(selectedLayer); } else { String envString = "color:" + hexColour; LegendObject lo = selectedLayer.getLegendObject(); if (lo != null && lo.getColourMode() != null) { envString += ";colormode:" + lo.getColourMode(); } else { envString += ";colormode:" + selectedLayer.getColourMode(); } if (selectedLayer.getOsGridResolution() != null) { envString += ";gridres:" + selectedLayer.getOsGridResolution(); if (selectedLayer.isDisplayGridReferences()) { envString += ";gridlabels:on"; } } envString += ";name:circle"; envString += ";size:" + selectedLayer.getSizeVal(); //Opacity now handled only by openlayers if ((selectedLayer.getHighlight() == null || selectedLayer.getHighlight().length() == 0 || !StringConstants.GRID.equals(selectedLayer.getColourMode())) && selectedLayer.getSizeUncertain()) { envString += ";uncertainty:1"; } selectedLayer.setEnvParams(envString + ";opacity:1"); if (selectedLayer.hasChildren()) { MapLayer highlightLayer = selectedLayer.getChild(0); if (highlightLayer.getName().equals(selectedLayer.getName() + "_highlight")) { //apply sel to envString String highlightEnv = "color:000000;size:" + selectedLayer.getSizeVal() + ";opacity:0"; highlightLayer.setOpacity(1); if (selectedLayer.getHighlight() != null && selectedLayer.getHighlight().length() > 0 && !StringConstants.GRID.equals(selectedLayer.getColourMode())) { if (selectedLayer.getSpeciesQuery() instanceof UserDataQuery) { try { highlightLayer.setEnvParams(highlightEnv + ";sel:" + selectedLayer.getHighlight().replace(";", "%3B")); } catch (Exception e) { LOGGER.error("error encoding highlight to UTF-8: " + selectedLayer.getHighlight(), e); } } else { highlightLayer.setEnvParams(highlightEnv + ";sel:" + selectedLayer.getHighlight().replace(";", "%3B")); } highlightLayer.setHighlightState("show"); } else { highlightLayer.setHighlightState("hide"); highlightLayer.setEnvParams(highlightEnv); } } } if (selectedLayer.isDisplayed()) { reloadMapLayerNowAndIndexes(selectedLayer); } } } else if (selectedLayer.getSelectedStyle() != null) { /* * 1. classification legend has uri with ".zul" content 2. * prediction legend works here * */ LOGGER.debug("******** is this ever reached? **********"); selectedLayer.setOpacity(selectedLayer.getOpacity()); String legendUri = selectedLayer.getSelectedStyle().getLegendUri(); if (legendUri.contains(".zul")) { //bbox is null, not required for redraw addImageLayer(selectedLayer.getId(), selectedLayer.getName(), selectedLayer.getUri(), selectedLayer.getOpacity(), null, LayerUtilitiesImpl.ALOC); } else { //redraw if (selectedLayer.isDisplayed()) { reloadMapLayerNowAndIndexes(selectedLayer); } } } else { //redraw wms layer if opacity changed if (selectedLayer.isDisplayed()) { reloadMapLayerNowAndIndexes(selectedLayer); } } } }
From source file:tufts.vue.LWComponent.java
public static String ColorToString(final Color c) { // if null, or no hue and no alpha, return null //if (c == null || ((c.getRGB() & 0xFFFFFF) == 0 && c.getAlpha() == 255)) if (c == null) return null; if (c.getAlpha() == 255) // opaque: only bother to save hue info return String.format("#%06X", c.getRGB() & 0xFFFFFF); else// www . j av a 2s . c o m return String.format("#%08X", c.getRGB()); }