List of usage examples for java.awt Color decode
public static Color decode(String nm) throws NumberFormatException
From source file:umich.ms.batmass.gui.viewers.map2d.options.Map2DOptions.java
/** * Converts HEX colors stored in an Apache Commons Configuration, e.g.:<br/> * <code>defaultConfig.addProperty("colorPivots", new String[]{"#000000", "#00007F", "#0000FF"});</code> * to {@link java.awt.Color}[].//w w w .ja va 2 s . co m * @param config * @return */ public static Color[] getColorsFromConfig(Configuration config) { String[] colorsArr = config.getStringArray("colorPivots"); Color[] colors = new Color[colorsArr.length]; for (int i = 0; i < colorsArr.length; i++) { colors[i] = Color.decode(colorsArr[i]); } return colors; }
From source file:ancat.visualizers.VertexTransformers.java
/** * Prepares the default colour configuration that is used by the rendering * engine/*ww w. j av a 2s. c o m*/ */ private void colorConfig() { Map<String, String> nodeConfig = _renderConfig.nodeConfiguration(); if (nodeConfig.containsKey("node:default-color")) { try { Color c = Color.decode(nodeConfig.get("node:default-color")); if (c != null) _defaultColor = c; else _defaultColor = Color.darkGray; } catch (NumberFormatException e) { _logger.error("Cannot process color value for node object", e); _defaultColor = Color.darkGray; } } if (nodeConfig.containsKey("node:default-pcolor")) { try { Color c = Color.decode(nodeConfig.get("node:default-pcolor")); if (c != null) _defaultpColor = c; else _defaultpColor = Color.lightGray; } catch (NumberFormatException e) { _logger.error("Cannot process color value for node object", e); _defaultpColor = Color.darkGray; } } }
From source file:net.roboconf.doc.generator.internal.GraphUtils.java
/** * Decodes an hexadecimal color and resolves it as an AWT color. * @param value the value to decode//from ww w . j a va 2s .co m * @param defaultValue the default value to use if value is invalid * @return a color (not null) */ static Color decode(String value, String defaultValue) { Color result; try { result = Color.decode(value); } catch (NumberFormatException e) { Logger logger = Logger.getLogger(GraphUtils.class.getName()); logger.severe("The specified color " + value + " could not be parsed. Back to default value: " + defaultValue); Utils.logException(logger, e); result = Color.decode(defaultValue); } return result; }
From source file:net.sourceforge.processdash.ui.web.reports.PieChart.java
private void configureIndividualColors(PiePlot plot, PieDataset pieData) { int num = 1;/*w ww. j av a2s .c o m*/ for (Object key : pieData.getKeys()) { String colorKey = "c" + num; String color = getParameter(colorKey); if (color != null) plot.setSectionPaint((Comparable) key, Color.decode("#" + color)); num++; } }
From source file:com.chiorichan.util.StringUtil.java
public static Color parseColor(String color) { Pattern c = Pattern.compile("rgb *\\( *([0-9]+), *([0-9]+), *([0-9]+) *\\)"); Matcher m = c.matcher(color); // First try to parse RGB(0,0,0); if (m.matches()) return new Color(Integer.valueOf(m.group(1)), // r Integer.valueOf(m.group(2)), // g Integer.valueOf(m.group(3))); // b try {//from ww w . j a v a2 s . c o m Field field = Class.forName("java.awt.Color").getField(color.trim().toUpperCase()); return (Color) field.get(null); } catch (Exception e) { } try { return Color.decode(color); } catch (Exception e) { } return null; }
From source file:nl.b3p.viewer.stripes.BufferActionBean.java
@DefaultHandler public Resolution image() { final CombineImageSettings cis = new CombineImageSettings(); try {//w ww . j ava 2 s .c o m cis.setBbox(bbox); cis.setWidth(width); cis.setHeight(height); Color c = Color.RED; if (color != null) { c = Color.decode("#" + color); } cis.setDefaultWktGeomColor(c); List<CombineImageWkt> wkts = getFeatures(cis.getBbox()); cis.setWktGeoms(wkts); final BufferedImage bi = ImageTool.drawGeometries(null, cis); if (bi != null) { StreamingResolution res = new StreamingResolution(cis.getMimeType()) { @Override public void stream(HttpServletResponse response) throws Exception { ImageTool.writeImage(bi, cis.getMimeType(), response.getOutputStream()); } }; return res; } else { log.info("No geometries used to draw a buffer"); } } catch (Exception e) { log.error("Error generating buffered image", e); } //if not returned, return a empty image final BufferedImage empty = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE); StreamingResolution res = new StreamingResolution(cis.getMimeType()) { @Override public void stream(HttpServletResponse response) throws Exception { ImageTool.writeImage(empty, cis.getMimeType(), response.getOutputStream()); } }; return res; }
From source file:net.sf.profiler4j.console.ClassListPanel.java
/** * This method initializes classesTable/* w ww.j ava 2 s . c om*/ * * @return javax.swing.JTable */ private JTable getClassesTable() { if (classesTable == null) { classesTable = new JTable(); classesTable.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); classesTable.setFont(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 12)); classesTable.setModel(getClassListTableModel()); classesTable.setRowHeight(20); classesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (classesTable.getSelectedRowCount() > 0) { addAsRuleButton.setEnabled(true); } else { addAsRuleButton.setEnabled(false); } } }); TableColumn c = classesTable.getColumnModel().getColumn(0); c.setMinWidth(50); c.setMaxWidth(50); c = classesTable.getColumnModel().getColumn(1); c.setMinWidth(300); c.setCellRenderer(new DefaultTableCellRenderer() { Font f1 = new Font("Tahoma", java.awt.Font.PLAIN, 12); Font f2 = new Font("Tahoma", java.awt.Font.BOLD, 12); @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (isSelected) { setFont(f2); } else { setFont(f1); } if (classListTableModel.getRow(row).info.isInstrumented()) { if (isSelected) { setForeground(Color.YELLOW); setBackground(Color.BLUE); } else { setBackground(Color.decode("#bbffbb")); setForeground(Color.BLACK); } } else { if (isSelected) { setForeground(Color.WHITE); setBackground(Color.BLUE); } else { setBackground(Color.WHITE); setForeground(Color.BLACK); } } setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 4)); return this; } }); } return classesTable; }
From source file:de.iteratec.iteraplan.presentation.dialog.GraphicalReporting.Line.JFreeChartSvgRenderer.java
byte[] renderJFreeChart(JFreeChart chart, float width, float height, boolean naked, Date fromDate, Date toDate) throws IOException { String svgNamespaceUri = SVGDOMImplementation.SVG_NAMESPACE_URI; Document doc = SVGDOMImplementation.getDOMImplementation().createDocument(svgNamespaceUri, "svg", null); String generatedText = "Generated " + DateUtils.formatAsStringToLong(new Date(), UserContext.getCurrentLocale()) + " by " + MessageAccess.getStringOrNull("global.applicationname", UserContext.getCurrentLocale()) + " " + properties.getBuildId();//from www.ja v a 2 s . com String drawingInfo = MessageAccess.getStringOrNull("graphicalExport.timeline.drawInfo", UserContext.getCurrentLocale()) + ": " + DateUtils.formatAsString(fromDate, UserContext.getCurrentLocale()) + " -> " + DateUtils.formatAsString(toDate, UserContext.getCurrentLocale()); SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(doc); ctx.setComment(generatedText); SVGGraphics2D svgGraphics = new SVGGraphics2D(ctx, false); if (!naked) { //Render the chart to the SVG graphics object chart.draw(svgGraphics, new Rectangle(20, 20, Math.round(width - MARGIN), Math.round(height - MARGIN))); //Add logo and generated text int widthIntForLogo = Math.round(width + 40 - MARGIN); int heightIntForLogo = Math.round(height - MARGIN + 20); int xLogoUpperRightCorner[] = { widthIntForLogo - 40, widthIntForLogo, widthIntForLogo, widthIntForLogo - 8, widthIntForLogo - 8, widthIntForLogo - 40 }; int yLogoUpperRightCorner[] = { MARGIN_TOP, MARGIN_TOP, MARGIN_TOP + 40, MARGIN_TOP + 40, MARGIN_TOP + 8, MARGIN_TOP + 8 }; GeneralPath logoUpperRightCorner = new GeneralPath(); logoUpperRightCorner.moveTo(xLogoUpperRightCorner[0], yLogoUpperRightCorner[0]); for (int i = 1; i < xLogoUpperRightCorner.length; i++) { logoUpperRightCorner.lineTo(xLogoUpperRightCorner[i], yLogoUpperRightCorner[i]); } logoUpperRightCorner.closePath(); svgGraphics.setColor(Color.decode(COLOR_LOGO)); svgGraphics.fill(logoUpperRightCorner); svgGraphics.draw(logoUpperRightCorner); int xLogoLowerLeftCorner[] = { MARGIN_LEFT, MARGIN_LEFT + 8, MARGIN_LEFT + 8, MARGIN_LEFT + 40, MARGIN_LEFT + 40, MARGIN_LEFT }; int yLogoLowerLeftCorner[] = { heightIntForLogo, heightIntForLogo, heightIntForLogo + 32, heightIntForLogo + 32, heightIntForLogo + 40, heightIntForLogo + 40 }; GeneralPath logoLowerLeftCorner = new GeneralPath(); logoLowerLeftCorner.moveTo(xLogoLowerLeftCorner[0], yLogoLowerLeftCorner[0]); for (int i = 1; i < xLogoLowerLeftCorner.length; i++) { logoLowerLeftCorner.lineTo(xLogoLowerLeftCorner[i], yLogoLowerLeftCorner[i]); } logoLowerLeftCorner.closePath(); svgGraphics.setColor(Color.BLACK); svgGraphics.fill(logoLowerLeftCorner); svgGraphics.draw(logoLowerLeftCorner); Font f = new Font(null, Font.ITALIC, 12); svgGraphics.setFont(f); FontMetrics fontMetrics = svgGraphics.getFontMetrics(f); int charsWidthInfo = fontMetrics.stringWidth(drawingInfo); svgGraphics.drawString(drawingInfo, width - MARGIN - charsWidthInfo, height - MARGIN + MARGIN_DOWN_GENERATED_TEXT); int charsWidth = fontMetrics.stringWidth(generatedText); svgGraphics.drawString(generatedText, width - MARGIN - charsWidth, height - MARGIN + MARGIN_DOWN_GENERATED_TEXT + 20); } else { chart.draw(svgGraphics, new Rectangle(20, 20, Math.round(JFreeChartLineGraphicCreator.DEFAULT_HEIGHT - NAKED_MARGIN), Math.round(JFreeChartLineGraphicCreator.DEFAULT_HEIGHT - NAKED_MARGIN))); } svgGraphics.setSVGCanvasSize(new Dimension((int) width, (int) height)); //Convert the SVGGraphics2D object to SVG XML ByteArrayOutputStream baos = new ByteArrayOutputStream(); Writer out = new OutputStreamWriter(baos, "UTF-8"); svgGraphics.stream(out, true); byte[] originalSvgXml = baos.toByteArray(); // return originalSvgXml; return addAdditionalAttributes(originalSvgXml); }
From source file:org.kalypsodeegree_impl.graphics.sld.Stroke_Impl.java
/** * extracts the color of the stroke if it is simple (nor Expression) to avoid new calculation for each call of * getStroke(Feature feature)/*from ww w .j a v a2 s . c om*/ */ private void extractSimpleColor() throws FilterEvaluationException { final CssParameter cssParam = getParameter(CSS_STROKE); if (cssParam != null) { final Object[] o = cssParam.getValue().getComponents(); for (final Object element : o) { if (element instanceof Expression) { color = null; break; } try { color = Color.decode(((String) element).trim()); } catch (final NumberFormatException e) { throw new FilterEvaluationException("Given value ('" + element + "') for CSS-Parameter 'stroke' " + "does not denote a valid color!"); } } } }
From source file:com.openkm.extension.servlet.StampServlet.java
@Override public void Stamp(int id, int type, String path) throws OKMException { log.debug("Stamp({}, {})", new Object[] { (Object) id, (Object) type }); updateSessionManager();//w w w .j av a 2 s .co m File tmp = null; File tmpPdf = null; File tmpStampPdf = null; try { Document doc = OKMDocument.getInstance().getProperties(null, path); tmp = File.createTempFile("okm", ".tmp"); tmpPdf = File.createTempFile("okm", ".pdf"); tmpStampPdf = File.createTempFile("okm", ".pdf"); FileOutputStream fos = null; // Copying from repository to temporal file if (doc.getMimeType().equals("application/pdf")) { fos = new FileOutputStream(tmpPdf); } else { fos = new FileOutputStream(tmp); } InputStream is = OKMDocument.getInstance().getContent(null, path, false); IOUtils.copy(is, fos); fos.flush(); fos.close(); is.close(); // Convert from temporal file to temporal PDF (if needed) if (!doc.getMimeType().equals("application/pdf")) { DocConverter converter = DocConverter.getInstance(); if (doc.getMimeType().startsWith("image/")) { converter.img2pdf(tmp, doc.getMimeType(), tmpPdf); } else { converter.doc2pdf(tmp, doc.getMimeType(), tmpPdf); } } // Stamping pdf file is = new FileInputStream(tmpPdf); fos = new FileOutputStream(tmpStampPdf); switch (type) { case GWTStamp.STAMP_TEXT: StampText st = StampTextDAO.findByPk(id); PDFUtils.stampText(is, st.getText(), st.getLayer(), st.getOpacity(), st.getSize(), Color.decode(st.getColor()), st.getRotation(), st.getAlign(), st.getExprX(), st.getExprY(), fos); break; case GWTStamp.STAMP_IMAGE: StampImage si = StampImageDAO.findByPk(id); byte[] image = SecureStore.b64Decode(si.getImageContent()); PDFUtils.stampImage(is, image, si.getLayer(), si.getOpacity(), si.getExprX(), si.getExprY(), fos); break; } fos.close(); is.close(); is = new FileInputStream(tmpStampPdf); // Upload document to repository if original is PDF we increment version otherwise create new file if (!doc.getMimeType().equals("application/pdf")) { Document newDoc = new Document(); String parentFld = JCRUtils.getParent(path); String docName = JCRUtils.getName(path); int idx = docName.lastIndexOf('.'); if (idx > 0) { docName = docName.substring(0, idx); } newDoc.setPath(parentFld + "/" + docName + ".pdf"); OKMDocument.getInstance().create(null, newDoc, is); } else { OKMDocument.getInstance().checkout(null, path); OKMDocument.getInstance().setContent(null, path, is); OKMDocument.getInstance().checkin(null, path, "Stamped"); } is.close(); } catch (DatabaseException e) { log.error(e.getMessage(), e); throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMStampService, ErrorCode.CAUSE_Database), e.getMessage()); } catch (RepositoryException e) { log.error(e.getMessage(), e); throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMStampService, ErrorCode.CAUSE_Repository), e.getMessage()); } catch (PathNotFoundException e) { log.error(e.getMessage(), e); throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMStampService, ErrorCode.CAUSE_PathNotFound), e.getMessage()); } catch (IOException e) { log.error(e.getMessage(), e); throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMStampService, ErrorCode.CAUSE_IO), e.getMessage()); } catch (NumberFormatException e) { log.error(e.getMessage(), e); throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMStampService, ErrorCode.CAUSE_NumberFormat), e.getMessage()); } catch (DocumentException e) { log.error(e.getMessage(), e); throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMStampService, ErrorCode.CAUSE_Document), e.getMessage()); } catch (EvalError e) { log.error(e.getMessage(), e); throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMStampService, ErrorCode.CAUSE_Eval), e.getMessage()); } catch (UnsupportedMimeTypeException e) { log.error(e.getMessage(), e); throw new OKMException( ErrorCode.get(ErrorCode.ORIGIN_OKMStampService, ErrorCode.CAUSE_UnsupportedMimeType), e.getMessage()); } catch (FileSizeExceededException e) { log.error(e.getMessage(), e); throw new OKMException( ErrorCode.get(ErrorCode.ORIGIN_OKMStampService, ErrorCode.CAUSE_FileSizeExceeded), e.getMessage()); } catch (UserQuotaExceededException e) { log.error(e.getMessage(), e); throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMStampService, ErrorCode.CAUSE_QuotaExceed), e.getMessage()); } catch (VirusDetectedException e) { log.error(e.getMessage(), e); throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMStampService, ErrorCode.CAUSE_Virus), e.getMessage()); } catch (ItemExistsException e) { log.error(e.getMessage(), e); throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMStampService, ErrorCode.CAUSE_ItemExists), e.getMessage()); } catch (AccessDeniedException e) { log.error(e.getMessage(), e); throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMStampService, ErrorCode.CAUSE_AccessDenied), e.getMessage()); } catch (LockException e) { log.error(e.getMessage(), e); throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMStampService, ErrorCode.CAUSE_Lock), e.getMessage()); } catch (VersionException e) { log.error(e.getMessage(), e); throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMStampService, ErrorCode.CAUSE_Version), e.getMessage()); } catch (ConversionException e) { log.error(e.getMessage(), e); throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMStampService, ErrorCode.CAUSE_Conversion), e.getMessage()); } catch (ExtensionException e) { log.error(e.getMessage(), e); throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMStampService, ErrorCode.CAUSE_Extension), e.getMessage()); } finally { // Cleaning temp files tmp.delete(); tmpPdf.delete(); tmpStampPdf.delete(); } }