List of usage examples for java.awt Color decode
public static Color decode(String nm) throws NumberFormatException
From source file:dpfmanager.conformancechecker.tiff.reporting.PdfReport.java
private PDFParams writeTableHeaders(PDFParams pdfParams, int pos_x, int font_size, PDFont font, List<String> headers, Integer[] margins) throws Exception { pdfParams.checkNewPage();//www .j a v a 2s . com pdfParams = writeRectangle(pdfParams, pos_x, font_size, 490, Color.decode("#333333")); int i = 0; for (String header : headers) { pdfParams = writeText(pdfParams, header, pos_x + margins[i], font, font_size, Color.lightGray); i++; } return pdfParams; }
From source file:com.centurylink.mdw.designer.pages.ExportHelper.java
private Object generateElementHtml(Element element, int depth, Font font) { String tag = element.getName(); Object myself;/*from w w w.j a v a 2 s . c o m*/ Object av; if (element instanceof HTMLDocument.RunElement) { HTMLDocument.RunElement re = (HTMLDocument.RunElement) element; int start = re.getStartOffset(); int end = re.getEndOffset(); try { String content = re.getDocument().getText(start, end - start); HtmlAttr htmlattr = printAttributesHtml(re); av = re.getAttribute(CSS.Attribute.FONT_SIZE); String fontsize = av == null ? null : av.toString(); av = re.getAttribute(CSS.Attribute.FONT_FAMILY); String fontfamily = av == null ? null : av.toString(); av = re.getAttribute(CSS.Attribute.COLOR); String fontcolor = av == null ? null : av.toString(); if (fontcolor != null || fontsize != null || fontfamily != null) { if (fontfamily == null) fontfamily = font.getFamilyname(); if (fontsize != null && fontsize.endsWith("pt")) fontsize = fontsize.substring(0, fontsize.indexOf("pt")); float size = fontsize == null ? font.getSize() : (Float.parseFloat(fontsize) + 8); int style = font.getStyle(); Color color; if (fontcolor != null) { color = Color.decode(fontcolor); } else color = font.getColor(); font = FontFactory.getFont(fontfamily, size, style, color); } else if (htmlattr.bold || htmlattr.italic) { String family = font.getFamilyname(); float size = font.getSize(); Color color = font.getColor(); if (htmlattr.bold && htmlattr.italic) font = FontFactory.getFont(family, size, Font.BOLDITALIC, color); else if (htmlattr.italic) font = FontFactory.getFont(family, size, Font.ITALIC, color); else if (htmlattr.bold) font = FontFactory.getFont(family, size, Font.BOLD); } myself = new Chunk(content, font); } catch (BadLocationException e) { e.printStackTrace(); myself = null; } } else if (element instanceof HTMLDocument.BlockElement) { HTMLDocument.BlockElement be = (HTMLDocument.BlockElement) element; HtmlAttr htmlattr = printAttributesHtml(be); if (htmlattr.bold) { System.out.println("+++BOLD!!!"); } av = be.getAttribute(javax.swing.text.html.HTML.Attribute.ALIGN); String align = av == null ? null : av.toString(); if (htmlattr.bold || htmlattr.italic) { String family = font.getFamilyname(); float size = font.getSize(); Color color = font.getColor(); if (htmlattr.bold && htmlattr.italic) font = FontFactory.getFont(family, size, Font.BOLDITALIC, color); else if (htmlattr.italic) font = FontFactory.getFont(family, size, Font.ITALIC, color); else if (htmlattr.bold) font = FontFactory.getFont(family, size, Font.BOLD, Color.blue); } if (tag.equalsIgnoreCase("html")) { myself = generateElementChildrenHtml(element, depth + 1, font); } else if (tag.equalsIgnoreCase("head")) { myself = null; } else if (tag.equalsIgnoreCase("body")) { myself = generateElementChildrenHtml(element, depth + 1, font); } else if (tag.equalsIgnoreCase("p") || tag.equalsIgnoreCase("p-implied")) { List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); Paragraph paragraph = new Paragraph(); paragraph.setFirstLineIndent(0F); for (Object child : children) { if (child instanceof Chunk) { Chunk chunk = (Chunk) child; /*if (!chunk.getContent().equals("\n"))*/ paragraph.add(chunk); } else paragraph.add(child); } if (align != null) paragraph.setAlignment(align); myself = paragraph; } else if (tag.equalsIgnoreCase("h1") || tag.equalsIgnoreCase("h2") || tag.equalsIgnoreCase("h3")) { List<Object> children = generateElementChildrenHtml(element, depth + 1, subSectionFont); Paragraph title = new Paragraph(); for (Object child : children) { title.add(child); } myself = new TempSectionPdf(title); } else if (tag.equalsIgnoreCase("ul")) { com.lowagie.text.List list = new com.lowagie.text.List(false, false, 20.0f); list.setIndentationLeft(25.0f); List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); for (Object child : children) { list.add(child); } myself = list; } else if (tag.equalsIgnoreCase("ol")) { com.lowagie.text.List list = new com.lowagie.text.List(true, false, 20.0f); list.setIndentationLeft(25.0f); List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); for (Object child : children) { list.add(child); } myself = list; } else if (tag.equalsIgnoreCase("li")) { ListItem li = new ListItem(); li.setSpacingAfter(0.0f); List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); for (Object child : children) { li.add(child); } myself = li; } else if (tag.equalsIgnoreCase("table")) { List<Object> rows = generateElementChildrenHtml(element, depth + 1, normalFont); try { int ncols = 0; for (Object row : rows) { if (row instanceof List<?>) { int n = ((List<?>) row).size(); if (n > ncols) ncols = n; } } Table table = new Table(2); table.setBorderWidth(1); table.setBorderColor(new Color(0, 128, 128)); table.setPadding(1.0f); table.setSpacing(0.5f); Cell c = new Cell("header"); c.setHeader(true); c.setColspan(ncols); table.addCell(c); table.endHeaders(); for (Object row : rows) { if (row instanceof List<?>) { for (Object cell : (List<?>) row) { if (cell instanceof Cell) table.addCell((Cell) cell); } } } myself = table; } catch (BadElementException e) { e.printStackTrace(); myself = null; } } else if (tag.equalsIgnoreCase("tr")) { List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); myself = children; } else if (tag.equalsIgnoreCase("td")) { Cell cell = new Cell(); List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); for (Object child : children) { cell.add(child); } myself = cell; } else if (tag.equalsIgnoreCase("div")) { List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); Paragraph paragraph = new Paragraph(); paragraph.setFirstLineIndent(0F); for (Object child : children) { paragraph.add(child); } if (align != null) paragraph.setAlignment(align); myself = paragraph; } else { System.err.println("Unknown element " + element.getName()); myself = null; } } else { myself = null; // could be BidiElement - not sure what it is } return myself; }
From source file:com.hp.autonomy.frontend.reports.powerpoint.PowerPointServiceImpl.java
/** * Internal implementation to add an image (a world map, though other image data is also fine) to a slide. * Preserves the original image's aspect ratio, leaving blank space below and to the sides of the image. * @param slide the slide to add to./*www. j a v a 2s. c om*/ * @param anchor bounding rectangle to draw onto, in PowerPoint coordinates. * @param picture the picture data. * @param markers an array of markers to draw over the map. * @param polygons * @return the picture shape object added to the slide. */ private static XSLFPictureShape addMap(final XSLFSlide slide, final Rectangle2D.Double anchor, final XSLFPictureData picture, final Marker[] markers, final MapData.Polygon[] polygons) { double tgtW = anchor.getWidth(), tgtH = anchor.getHeight(); final Dimension size = picture.getImageDimension(); final double ratio = size.getWidth() / size.getHeight(); if (ratio > tgtW / tgtH) { // source image is wider than target, clip fixed width variable height tgtH = tgtW / ratio; } else { tgtW = tgtH * ratio; } final XSLFPictureShape canvas = slide.createPicture(picture); // Vertically align top, horizontally-align center final double offsetX = anchor.getMinX() + 0.5 * (anchor.getWidth() - tgtW), offsetY = anchor.getMinY(); canvas.setAnchor(new Rectangle2D.Double(offsetX, offsetY, tgtW, tgtH)); if (polygons != null) { for (MapData.Polygon polygon : polygons) { final Color color = Color.decode(polygon.getColor()); final double[][] shapes = polygon.getPoints(); // The ESRI spec version 1.2.1 from http://www.opengeospatial.org/standards/sfa has section 6.1.11.1, // which defines polygons as follows: /// A Polygon is a planar Surface defined by 1 exterior boundary and 0 or more interior boundaries. // Each interior boundary defines a hole in the Polygon. A Triangle is a polygon with 3 distinct, // non-collinear vertices and no interior boundary. /// The exterior boundary LinearRing defines the top? of the surface which is the side of the surface // from which the exterior boundary appears to traverse the boundary in a counter clockwise direction. // The interior LinearRings will have the opposite orientation, and appear as clockwise // when viewed from the top? // so it's even-odd winding (whereas the Path2D default is non-zero-winding). final Path2D.Double path = new Path2D.Double(Path2D.WIND_EVEN_ODD); for (final double[] points : shapes) { for (int ii = 0; ii < points.length; ii += 2) { final double x1 = offsetX + points[ii] * tgtW; final double y1 = offsetY + points[ii + 1] * tgtH; if (ii == 0) { path.moveTo(x1, y1); } else { path.lineTo(x1, y1); } } path.closePath(); } final XSLFFreeformShape freeform = slide.createFreeform(); freeform.setPath(path); freeform.setStrokeStyle(0.5); // There's a 0.5 alpha transparency on the stroke, and a 0.2 alpha transparency on the polygon fill. freeform.setLineColor(transparentColor(color, 128)); freeform.setFillColor(transparentColor(color, 51)); if (StringUtils.isNotEmpty(polygon.getText())) { final PackageRelationship rel = freeform.getSheet().getPackagePart().addRelationship( slide.getPackagePart().getPartName(), TargetMode.INTERNAL, XSLFRelation.SLIDE.getRelation()); // We create a hyperlink which links back to this slide; so we get hover-over-detail-text on the polygon final CTHyperlink link = ((CTShape) freeform.getXmlObject()).getNvSpPr().getCNvPr() .addNewHlinkClick(); link.setTooltip(polygon.getText()); link.setId(rel.getId()); link.setAction("ppaction://hlinksldjump"); } } } for (Marker marker : markers) { final Color color = Color.decode(marker.getColor()); final double centerX = offsetX + marker.getX() * tgtW; final double centerY = offsetY + marker.getY() * tgtH; if (marker.isCluster()) { final XSLFGroupShape group = slide.createGroup(); double halfMark = 10; double mark = halfMark * 2; double innerHalfMark = 7; double innerMark = innerHalfMark * 2; // align these so the middle is the latlng position final Rectangle2D.Double groupAnchor = new Rectangle2D.Double(centerX - halfMark, centerY - halfMark, mark, mark); group.setAnchor(groupAnchor); group.setInteriorAnchor(groupAnchor); final XSLFAutoShape shape = group.createAutoShape(); shape.setShapeType(ShapeType.ELLIPSE); final boolean fade = marker.isFade(); // There's a 0.3 alpha transparency (255 * 0.3 is 76) when a marker is faded out final int FADE_ALPHA = 76; shape.setFillColor(transparentColor(color, fade ? 47 : 154)); shape.setAnchor(groupAnchor); final XSLFAutoShape inner = group.createAutoShape(); inner.setFillColor(fade ? transparentColor(color, FADE_ALPHA) : color); inner.setLineWidth(0.1); inner.setLineColor(new Color((int) (color.getRed() * 0.9), (int) (color.getGreen() * 0.9), (int) (color.getBlue() * 0.9), fade ? FADE_ALPHA : 255)); inner.setShapeType(ShapeType.ELLIPSE); inner.setHorizontalCentered(true); inner.setWordWrap(false); inner.setVerticalAlignment(VerticalAlignment.MIDDLE); inner.clearText(); final XSLFTextParagraph para = inner.addNewTextParagraph(); para.setTextAlign(TextParagraph.TextAlign.CENTER); final XSLFTextRun text = para.addNewTextRun(); text.setFontSize(6.0); final Color fontColor = Color.decode(StringUtils.defaultString(marker.getFontColor(), "#000000")); text.setFontColor(fade ? transparentColor(fontColor, FADE_ALPHA) : fontColor); text.setText(marker.getText()); inner.setAnchor(new Rectangle2D.Double(centerX - innerHalfMark, centerY - innerHalfMark, innerMark, innerMark)); } else { final XSLFGroupShape group = slide.createGroup(); final XSLFFreeformShape shape = group.createFreeform(); shape.setHorizontalCentered(true); shape.setWordWrap(false); shape.setVerticalAlignment(VerticalAlignment.BOTTOM); shape.setLineWidth(0.5); shape.setLineColor(color.darker()); shape.setFillColor(transparentColor(color, 210)); final double halfMark = 8, mark = halfMark * 2, extension = 0.85, markerHeight = (0.5 + extension) * mark, angle = Math.asin(0.5 / extension) * 180 / Math.PI; // Set group position group.setAnchor( new Rectangle2D.Double(centerX - halfMark, centerY - markerHeight, mark, markerHeight)); group.setInteriorAnchor(new Rectangle2D.Double(0, 0, mark, markerHeight)); // Draw a semicircle and a triangle to represent the marker, pointing at the precise x,y location final Path2D.Double path = new Path2D.Double(); path.moveTo(halfMark, markerHeight); path.append(new Arc2D.Double(0, 0, mark, mark, -angle, 180 + angle + angle, Arc2D.OPEN), true); path.lineTo(halfMark, markerHeight); shape.setPath(path); shape.setAnchor(new Rectangle2D.Double(0, 0, mark, markerHeight)); final XSLFAutoShape disc = group.createAutoShape(); disc.setShapeType(ShapeType.DONUT); final double discRadius = 0.25 * mark; final double discDiameter = 2 * discRadius; disc.setAnchor(new Rectangle2D.Double(halfMark - discRadius, halfMark - discRadius, discDiameter, discDiameter)); disc.setFillColor(Color.WHITE); disc.setLineColor(Color.WHITE); if (StringUtils.isNotEmpty(marker.getText())) { final PackageRelationship rel = shape.getSheet().getPackagePart().addRelationship( slide.getPackagePart().getPartName(), TargetMode.INTERNAL, XSLFRelation.SLIDE.getRelation()); // We create a hyperlink which links back to this slide; so we get hover-over-detail-text on the marker // Annoyingly, you can't put a link on the group, just on the individual shapes. for (XSLFShape clickable : group.getShapes()) { final CTHyperlink link = ((CTShape) clickable.getXmlObject()).getNvSpPr().getCNvPr() .addNewHlinkClick(); link.setTooltip(marker.getText()); link.setId(rel.getId()); link.setAction("ppaction://hlinksldjump"); } } } } return canvas; }
From source file:org.tellervo.desktop.prefs.Prefs.java
/** * Use getPref(PrefKey, ...) instead/*from w w w . j a v a2s .co m*/ * * @param pref * @param deflt * @return */ @Deprecated public Color getColorPref(String pref, Color deflt) { String value = prefs.getProperty(pref); if (value == null) return deflt; try { return Color.decode(value); } catch (NumberFormatException nfe) { log.warn("Invalid color for preference '" + pref + "': " + value); return deflt; } }
From source file:probe.com.view.body.quantdatasetsoverview.diseasegroupsfilters.ComparisonsSelectionOverviewBubbleChart.java
private JFreeChart updateBubbleChartChartWithCustUserData( Set<QuantDiseaseGroupsComparison> selectedComparisonList) { tooltipsProtNumberMap.clear();/* w w w. j a v a2s. c o m*/ DefaultXYZDataset defaultxyzdataset = new DefaultXYZDataset(); int counter = 0; int upper = -1; boolean significantOnly = this.Quant_Central_Manager.isSignificantOnly(); if (userCustomizedComparison.getComparProtsMap().size() > upper) { upper = userCustomizedComparison.getComparProtsMap().size(); } for (QuantDiseaseGroupsComparison qc : selectedComparisonList) { if (significantOnly) { int upperCounter = 0; for (DiseaseGroupsComparisonsProteinLayout qp : qc.getComparProtsMap().values()) { if (qp == null) { continue; } if (qp.getSignificantTrindCategory() == 2) { continue; } upperCounter++; } if (upperCounter > upper) { upper = upperCounter; } } else { if (qc.getComparProtsMap() == null) { System.out.println("null qc " + qc.getComparisonHeader()); } if (qc.getComparProtsMap().size() > upper) { upper = qc.getComparProtsMap().size(); } } } final Map<Integer, Color[]> seriousColorMap = new HashMap<Integer, Color[]>(); Color[] dataColor = new Color[] { Color.WHITE, new Color(0, 153, 0), new Color(0, 229, 132), stableColor, new Color(247, 119, 119), new Color(204, 0, 0), Color.WHITE }; double[] tempWidthValue = new double[8]; double[] yAxisValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 }; double[] xAxisValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 }; double[] widthValueI = new double[] { 0, 0, 0, 0, 0, 0, 0 }; double[][] seriesValuesI = { yAxisValueI, xAxisValueI, widthValueI }; seriousColorMap.put(0, new Color[] { Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE, Color.WHITE }); defaultxyzdataset.addSeries(" ", seriesValuesI); for (String key : userCustomizedComparison.getComparProtsMap().keySet()) { userCustomizedComparison.getComparProtsMap().get(key).updateLabelLayout(); { tempWidthValue[userCustomizedComparison.getComparProtsMap().get(key).getSignificantTrindCategory() + 1] = tempWidthValue[userCustomizedComparison.getComparProtsMap().get(key) .getSignificantTrindCategory() + 1] + 1; } } int length = 0; if (upper < 10) { upper = 10; } double[] tooltipNumbess = new double[tempWidthValue.length]; System.arraycopy(tempWidthValue, 0, tooltipNumbess, 0, tempWidthValue.length); this.tooltipsProtNumberMap.put(userCustomizedComparison.getComparisonHeader(), tooltipNumbess); for (int z = 0; z < tempWidthValue.length; z++) { if (tempWidthValue[z] > 0) { tempWidthValue[z] = scaleValues(tempWidthValue[z], upper, 2.5, 0.05);//Math.max(tempWidthValue[z] * 1.5 / upper, 0.05); length++; } } double[] yAxisValue = new double[length]; double[] xAxisValue = new double[length]; double[] widthValue = new double[length]; Color[] serColorArr = new Color[length]; length = 0; for (int z = 0; z < tempWidthValue.length; z++) { if (tempWidthValue[z] > 0) { xAxisValue[length] = z; yAxisValue[length] = counter + 1; widthValue[length] = tempWidthValue[z]; serColorArr[length] = dataColor[z]; length++; } } if (length == 1 && selectedComparisonList.size() == 1) { widthValue[0] = 1; } seriousColorMap.put(++counter, serColorArr); double[][] seriesValues = { yAxisValue, xAxisValue, widthValue }; defaultxyzdataset.addSeries(userCustomizedComparison.getComparisonHeader(), seriesValues); for (QuantDiseaseGroupsComparison qc : selectedComparisonList) { tempWidthValue = new double[8]; if (qc.getComparProtsMap() == null) { continue; } for (String key : qc.getComparProtsMap().keySet()) { qc.getComparProtsMap().get(key).updateLabelLayout(); if (significantOnly && (qc.getComparProtsMap().get(key).getSignificantTrindCategory() == 2 || qc.getComparProtsMap().get(key).getSignificantTrindCategory() == 5)) { tempWidthValue[3] = 0; tempWidthValue[6] = 0; } else { tempWidthValue[qc.getComparProtsMap().get(key).getSignificantTrindCategory() + 1] = tempWidthValue[qc.getComparProtsMap().get(key).getSignificantTrindCategory() + 1] + 1; } } if (tempWidthValue[3] > 0 && tempWidthValue[6] >= 0) { stableColor = new Color(1, 141, 244); } else { stableColor = Color.decode("#b5babb"); } tempWidthValue[3] = tempWidthValue[3] + tempWidthValue[6]; tempWidthValue[6] = 0; dataColor[3] = stableColor; length = 0; if (upper < 10) { upper = 10; } tooltipNumbess = new double[tempWidthValue.length]; System.arraycopy(tempWidthValue, 0, tooltipNumbess, 0, tempWidthValue.length); this.tooltipsProtNumberMap.put(qc.getComparisonHeader(), tooltipNumbess); for (int x = 0; x < tempWidthValue.length; x++) { if (tempWidthValue[x] > 0) { tempWidthValue[x] = scaleValues(tempWidthValue[x], upper, 2.5, 0.05);//Math.max(tempWidthValue[z] * 1.5 / upper, 0.05); length++; } } yAxisValue = new double[length]; xAxisValue = new double[length]; widthValue = new double[length]; serColorArr = new Color[length]; length = 0; for (int x = 0; x < tempWidthValue.length; x++) { if (tempWidthValue[x] > 0) { xAxisValue[length] = x; yAxisValue[length] = counter + 1; widthValue[length] = tempWidthValue[x]; serColorArr[length] = dataColor[x]; length++; } } if (length == 1 && selectedComparisonList.size() == 1) { widthValue[0] = 1; } seriousColorMap.put(counter + 1, serColorArr); seriesValues = new double[][] { yAxisValue, xAxisValue, widthValue }; defaultxyzdataset.addSeries(qc.getComparisonHeader(), seriesValues); counter++; } double[] yAxisValueII = new double[0]; double[] xAxisValueII = new double[0]; double[] widthValueII = new double[0]; seriousColorMap.put(counter + 1, new Color[] {}); double[][] seriesValuesII = { yAxisValueII, xAxisValueII, widthValueII }; defaultxyzdataset.addSeries(" ", seriesValuesII); final Color[] labelsColor = new Color[] { Color.WHITE, new Color(80, 183, 71), Color.LIGHT_GRAY, new Color(1, 141, 244), Color.LIGHT_GRAY, new Color(204, 0, 0), Color.WHITE }; Font font = new Font("Verdana", Font.BOLD, 13); SymbolAxis yAxis = new SymbolAxis(null, new String[] { " ", "Decreased", " ", "Equal", " ", "Increased", " " }) { int x = 0; @Override public Paint getTickLabelPaint() { if (x >= labelsColor.length) { x = 0; } return labelsColor[x++]; } }; yAxis.setAutoRangeStickyZero(true); yAxis.setFixedAutoRange(8); yAxis.setTickLabelFont(font); yAxis.setGridBandsVisible(false); yAxis.setAxisLinePaint(Color.LIGHT_GRAY); yAxis.setTickMarksVisible(false); yAxis.setUpperBound(6); String[] xAxisLabels = new String[selectedComparisonList.size() + 3]; xAxisLabels[0] = " "; final Color[] diseaseGroupslabelsColor = new Color[selectedComparisonList.size() + 3]; int x = 0; int maxLength = -1; //init labels color String updatedHeader = userCustomizedComparison.getComparisonHeader().split(" / ")[0].split("\n")[0] + " / " + userCustomizedComparison.getComparisonHeader().split(" / ")[1].split("\n")[0] + ""; diseaseGroupslabelsColor[0] = Color.WHITE; diseaseGroupslabelsColor[x + 1] = diseaseColorMap.get("UserData"); xAxisLabels[x + 1] = updatedHeader + " (" + userCustomizedComparison.getDatasetIndexes().length + ") "; if (xAxisLabels[x + 1].length() > maxLength) { maxLength = xAxisLabels[++x].length(); } for (QuantDiseaseGroupsComparison comp : selectedComparisonList) { String header = comp.getComparisonHeader(); updatedHeader = header.split(" / ")[0].split("\n")[0] + " / " + header.split(" / ")[1].split("\n")[0] + ""; xAxisLabels[x + 1] = updatedHeader + " (" + comp.getDatasetIndexes().length + ") "; if (xAxisLabels[x + 1].length() > maxLength) { maxLength = xAxisLabels[x + 1].length(); } diseaseGroupslabelsColor[x + 1] = diseaseColorMap.get(header.split(" / ")[0].split("\n")[1]); x++; } xAxisLabels[x + 1] = " "; SymbolAxis xAxis; final boolean finalNum; finalNum = maxLength > 30 && selectedComparisonList.size() > 4; xAxis = new SymbolAxis(null, xAxisLabels) { int x = 0; @Override public Paint getTickLabelPaint() { if (x >= diseaseGroupslabelsColor.length) { x = 0; } return diseaseGroupslabelsColor[x++]; } private final boolean localfinal = finalNum; @Override protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) { if (localfinal) { setVerticalTickLabels(localfinal); return super.refreshTicksHorizontal(g2, dataArea, edge); } List ticks = new java.util.ArrayList(); Font tickLabelFont = getTickLabelFont(); g2.setFont(tickLabelFont); double size = getTickUnit().getSize(); int count = calculateVisibleTickCount(); double lowestTickValue = calculateLowestVisibleTickValue(); double previousDrawnTickLabelPos = 0.0; double previousDrawnTickLabelLength = 0.0; if (count <= ValueAxis.MAXIMUM_TICK_COUNT) { for (int i = 0; i < count; i++) { double currentTickValue = lowestTickValue + (i * size); double xx = valueToJava2D(currentTickValue, dataArea, edge); String tickLabel; NumberFormat formatter = getNumberFormatOverride(); if (formatter != null) { tickLabel = formatter.format(currentTickValue) + " "; } else { tickLabel = valueToString(currentTickValue) + " "; } // avoid to draw overlapping tick labels Rectangle2D bounds = TextUtilities.getTextBounds(tickLabel, g2, g2.getFontMetrics()); double tickLabelLength = isVerticalTickLabels() ? bounds.getHeight() : bounds.getWidth(); boolean tickLabelsOverlapping = false; if (i > 0) { double avgTickLabelLength = (previousDrawnTickLabelLength + tickLabelLength) / 2.0; if (Math.abs(xx - previousDrawnTickLabelPos) < avgTickLabelLength) { tickLabelsOverlapping = true; } } if (tickLabelsOverlapping) { setVerticalTickLabels(true); } else { // remember these values for next comparison previousDrawnTickLabelPos = xx; previousDrawnTickLabelLength = tickLabelLength; } TextAnchor anchor; TextAnchor rotationAnchor; double angle = 0.0; if (isVerticalTickLabels()) { anchor = TextAnchor.CENTER_RIGHT; rotationAnchor = TextAnchor.CENTER_RIGHT; if (edge == RectangleEdge.TOP) { angle = 76.5; } else { angle = -76.5; } } else { if (edge == RectangleEdge.TOP) { anchor = TextAnchor.BOTTOM_CENTER; rotationAnchor = TextAnchor.BOTTOM_CENTER; } else { anchor = TextAnchor.TOP_CENTER; rotationAnchor = TextAnchor.TOP_CENTER; } } Tick tick = new NumberTick(new Double(currentTickValue), tickLabel, anchor, rotationAnchor, angle); ticks.add(tick); } } return ticks; } }; // } xAxis.setTickLabelFont(font); xAxis.setTickLabelInsets(new RectangleInsets(2, 20, 2, 20)); xAxis.setAutoRangeStickyZero(true); xAxis.setAutoRangeStickyZero(true); xAxis.setTickMarksVisible(false); xAxis.setUpperBound(diseaseGroupslabelsColor.length - 1); xAxis.setGridBandsVisible(false); xAxis.setAxisLinePaint(Color.LIGHT_GRAY); int scale = XYBubbleRenderer.SCALE_ON_RANGE_AXIS; XYItemRenderer xyitemrenderer = new XYBubbleRenderer(scale) { private int counter = 0; private int localSerious = -1; private final Map<Integer, Color[]> localSeriousColorMap = seriousColorMap; @Override public Paint getSeriesPaint(int series) { if (series != localSerious || isNewImge || localSeriousColorMap.get(series).length == counter) { counter = 0; isNewImge = false; } localSerious = series; Color c = localSeriousColorMap.get(series)[counter]; counter++; return c; } }; XYPlot xyplot = new XYPlot(defaultxyzdataset, xAxis, yAxis, xyitemrenderer) { @Override protected void drawRangeGridlines(Graphics2D g2, Rectangle2D area, List ticks) { try { if (!ticks.isEmpty()) { ticks.remove(0); } if (!ticks.isEmpty()) { ticks.remove(ticks.size() - 1); } } catch (Exception e) { } super.drawRangeGridlines(g2, area, ticks); //To change body of generated methods, choose Tools | Templates. } // private final Color[] labelsColor = new Color[]{new Color(0, 153, 0), new Color(0, 229, 132), new Color(1, 141, 244), new Color(255, 51, 51), new Color(204, 0, 0), Color.decode("#b5babb")}; // // private final Font font = new Font("Verdana", Font.PLAIN, 12); // private final String[] labels = new String[]{"Decreased 100%", "Decreased <100% ", "Equal", " Increased <100%", "Increased 100%", "No Quant. Info."}; // // @Override // public LegendItemCollection getLegendItems() { // LegendItemCollection legendItemCollection = new LegendItemCollection(); // for (int i = 0; i < labelsColor.length; i++) { // LegendItem item = new LegendItem(labels[i], labelsColor[i]); // item.setLabelFont(font); // legendItemCollection.add(item); // // } // // return legendItemCollection;//To change body of generated methods, choose Tools | Templates. // } }; JFreeChart generatedChart = new JFreeChart(xyplot) { }; xyplot.setOutlineVisible(false); LegendTitle legend = generatedChart.getLegend(); legend.setVisible(false); xyplot.setBackgroundPaint(Color.WHITE); generatedChart.setBackgroundPaint(Color.WHITE); generatedChart.setPadding(new RectangleInsets(0, 0, 0, 0)); Quant_Central_Manager.setProteinsOverviewBubbleChart(generatedChart); return generatedChart; }
From source file:org.jfree.eastwood.ChartEngine.java
/** * Creates a color from the supplied string, which should be in RRGGBB * format, or RRGGBBAA.// w w w.j av a2 s . c o m * * @param text the text encoding (<code>null</code> not permitted). * * @return A color. */ private static Color parseColor(String text) { if (text == null) { throw new IllegalArgumentException("Null 'text' argument (in parseColor(String))."); } return Color.decode("0x" + text); }
From source file:org.jfree.eastwood.ChartEngine.java
/** * Parses a string containing a comma-separated list of color values (in * the format RRGGBB or RRGGBBAA).//from ww w . jav a2 s . c o m * * @param text the text (<code>null</code> not permitted). * * @return The colors. */ private static Color[] parseColors(String text) { if (text == null) { throw new IllegalArgumentException("Null 'text' argument (in parseColors(String))."); } String[] codes = breakString(text, ','); Color[] result = new Color[codes.length]; for (int i = 0; i < codes.length; i++) { if (codes[i].length() > 0) { String code = breakString(codes[i], '|')[0]; result[i] = Color.decode("0x" + code); } else { result[i] = Color.black; } } return result; }
From source file:PVGraph.java
public static Color getColour(String colourName) { try {// w ww. j a va 2 s .c om return (Color) Class.forName("org.jfree.chart.ChartColor").getField(colourName.toUpperCase()).get(null); } catch (NoSuchFieldException nsfe) { try { return Color.decode(colourName); } catch (NumberFormatException nfe) { System.err.println("Bad colour (should be colour name or hex RGB): " + colourName); } } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:GroupProject.OriginalChartUI.java
/** * The method to draw bar chart//from w w w . j av a 2 s . c om * @param barChartData the data used in the bar chart * @param XTitle the measurement of X axis * @param YTitle the measurement of Y axis */ public void draw3DBarChart(Map<String, Float> barChartData, String XTitle, String YTitle) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); String title = XTitle + " VS " + YTitle; ArrayList<String> keyArrayList = new ArrayList<>(); ArrayList<Float> valueArrayList = new ArrayList<>(); Set set = barChartData.keySet(); int i = 1; for (Map.Entry<String, Float> data : barChartData.entrySet()) { String key = data.getKey(); Float value = data.getValue(); keyArrayList.add(key); valueArrayList.add(value); dataset.setValue(value, "1", key); } JFreeChart chart = ChartFactory.createBarChart3D(title, "", "", dataset, PlotOrientation.VERTICAL, false, false, false); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(new java.awt.Color(255, 255, 255)); plot.setRangeGridlinePaint(Color.GRAY); BarRenderer3D barRender = (BarRenderer3D) plot.getRenderer(); barRender.setSeriesPaint(0, Color.decode("#9DC3E6")); ChartPanel chartPanel = new ChartPanel(chart); chartDisplayPanel.removeAll(); chartDisplayPanel.add(chartPanel, BorderLayout.CENTER); chartDisplayPanel.validate(); }
From source file:com.hp.autonomy.frontend.reports.powerpoint.PowerPointServiceImpl.java
/** * Internal implementation to add a list of documents to a presentation; either as a single slide or a series of slides. * @param imageSource the image source to convert images to data. * @param ppt the presentation to add to. * @param sl the slide to add to (can be null if pagination is enabled). * @param anchor bounding rectangle to draw onto, in PowerPoint coordinates. * @param paginate whether to render results as multiple slides if they don't fit on one slide. * @param data the documents to render./*from w ww. j a v a 2s. c o m*/ * @param results optional string to render into the top-left corner of the available space. * Will appear on each page if pagination is enabled. * @param sortBy optional string to render into the top-right corner of the available space. * Will appear on each page if pagination is enabled. */ private static void addList(final ImageSource imageSource, final XMLSlideShow ppt, XSLFSlide sl, final Rectangle2D.Double anchor, final boolean paginate, final ListData data, final String results, final String sortBy) { final double // How much space to leave at the left and right edge of the slide xMargin = 20, // How much space to leave at the top yMargin = 5, // Size of the icon iconWidth = 20, iconHeight = 24, // Find's thumbnail height is 97px by 55px, hardcoded in the CSS in .document-thumbnail thumbScale = 0.8, thumbW = 97 * thumbScale, thumbH = 55 * thumbScale, // Margin around the thumbnail thumbMargin = 4., // Space between list items listItemMargin = 5.; final Pattern highlightPattern = Pattern .compile("<HavenSearch-QueryText-Placeholder>(.*?)</HavenSearch-QueryText-Placeholder>"); double yCursor = yMargin + anchor.getMinY(), xCursor = xMargin + anchor.getMinX(); int docsOnPage = 0; final Document[] docs = data.getDocs(); for (int docIdx = 0; docIdx < docs.length; ++docIdx) { final Document doc = docs[docIdx]; if (sl == null) { sl = ppt.createSlide(); yCursor = yMargin + anchor.getMinY(); xCursor = xMargin + anchor.getMinX(); docsOnPage = 0; double yStep = 0; if (StringUtils.isNotBlank(results)) { final XSLFTextBox textBox = sl.createTextBox(); textBox.clearText(); final Rectangle2D.Double textBounds = new Rectangle2D.Double(xCursor, yCursor, Math.max(0, anchor.getMaxX() - xCursor - xMargin), 20); textBox.setAnchor(textBounds); addTextRun(textBox.addNewTextParagraph(), results, 12., Color.LIGHT_GRAY); yStep = textBox.getTextHeight(); } if (StringUtils.isNotBlank(sortBy)) { final XSLFTextBox sortByEl = sl.createTextBox(); sortByEl.clearText(); final XSLFTextParagraph sortByText = sortByEl.addNewTextParagraph(); sortByText.setTextAlign(TextParagraph.TextAlign.RIGHT); addTextRun(sortByText, sortBy, 12., Color.LIGHT_GRAY); sortByEl.setAnchor(new Rectangle2D.Double(xCursor, yCursor, Math.max(0, anchor.getMaxX() - xCursor - xMargin), 20)); yStep = Math.max(sortByEl.getTextHeight(), yStep); } if (yStep > 0) { yCursor += listItemMargin + yStep; } } XSLFAutoShape icon = null; if (data.isDrawIcons()) { icon = sl.createAutoShape(); icon.setShapeType(ShapeType.SNIP_1_RECT); icon.setAnchor(new Rectangle2D.Double(xCursor, yCursor + listItemMargin, iconWidth, iconHeight)); icon.setLineColor(Color.decode("#888888")); icon.setLineWidth(2.0); xCursor += iconWidth; } final XSLFTextBox listEl = sl.createTextBox(); listEl.clearText(); listEl.setAnchor(new Rectangle2D.Double(xCursor, yCursor, Math.max(0, anchor.getMaxX() - xCursor - xMargin), Math.max(0, anchor.getMaxY() - yCursor))); final XSLFTextParagraph titlePara = listEl.addNewTextParagraph(); addTextRun(titlePara, doc.getTitle(), data.getTitleFontSize(), Color.BLACK).setBold(true); if (StringUtils.isNotBlank(doc.getDate())) { final XSLFTextParagraph datePara = listEl.addNewTextParagraph(); datePara.setLeftMargin(5.); addTextRun(datePara, doc.getDate(), data.getDateFontSize(), Color.GRAY).setItalic(true); } if (StringUtils.isNotBlank(doc.getRef())) { addTextRun(listEl.addNewTextParagraph(), doc.getRef(), data.getRefFontSize(), Color.GRAY); } final double thumbnailOffset = listEl.getTextHeight(); final XSLFTextParagraph contentPara = listEl.addNewTextParagraph(); Rectangle2D.Double pictureAnchor = null; XSLFPictureData pictureData = null; if (StringUtils.isNotBlank(doc.getThumbnail())) { try { // Picture reuse is automatic pictureData = addPictureData(imageSource, ppt, doc.getThumbnail()); // We reserve space for the picture, but we don't actually add it yet. // The reason is we may have to remove it later if it doesn't fit; but due to a quirk of OpenOffice, // deleting the picture shape removes the pictureData as well; which is a problem since the // pictureData can be shared between multiple pictures. pictureAnchor = new Rectangle2D.Double(xCursor, yCursor + thumbnailOffset + thumbMargin, thumbW, thumbH); // If there is enough horizontal space, put the text summary to the right of the thumbnail image, // otherwise put it under the thumbnail, if (listEl.getAnchor().getWidth() > 2.5 * thumbW) { contentPara.setLeftMargin(thumbW); } else { contentPara.addLineBreak().setFontSize(thumbH); } } catch (RuntimeException e) { // if there's any errors, we'll just ignore the image } } final String rawSummary = doc.getSummary(); if (StringUtils.isNotBlank(rawSummary)) { // HTML treats newlines and multiple whitespace as a single whitespace. final String summary = rawSummary.replaceAll("\\s+", " "); final Matcher matcher = highlightPattern.matcher(summary); int idx = 0; while (matcher.find()) { final int start = matcher.start(); if (idx < start) { addTextRun(contentPara, summary.substring(idx, start), data.getSummaryFontSize(), Color.DARK_GRAY); } addTextRun(contentPara, matcher.group(1), data.getSummaryFontSize(), Color.DARK_GRAY) .setBold(true); idx = matcher.end(); } if (idx < summary.length()) { addTextRun(contentPara, summary.substring(idx), data.getSummaryFontSize(), Color.DARK_GRAY); } } double elHeight = Math.max(listEl.getTextHeight(), iconHeight); if (pictureAnchor != null) { elHeight = Math.max(elHeight, pictureAnchor.getMaxY() - yCursor); } yCursor += elHeight; xCursor = xMargin + anchor.getMinX(); docsOnPage++; if (yCursor > anchor.getMaxY()) { if (docsOnPage > 1) { // If we drew more than one list element on this page; and we exceeded the available space, // delete the last element's shapes and redraw it on the next page. // We don't have to remove the picture since we never added it. sl.removeShape(listEl); if (icon != null) { sl.removeShape(icon); } --docIdx; } else if (pictureAnchor != null) { // We've confirmed we need the picture, add it. sl.createPicture(pictureData).setAnchor(pictureAnchor); } sl = null; if (!paginate) { break; } } else { yCursor += listItemMargin; if (pictureAnchor != null) { // We've confirmed we need the picture, add it. sl.createPicture(pictureData).setAnchor(pictureAnchor); } } } }