List of usage examples for java.awt Graphics2D setPaint
public abstract void setPaint(Paint paint);
From source file:au.org.ala.biocache.web.MapController.java
@Deprecated @RequestMapping(value = "/occurrences/wms", method = RequestMethod.GET) public void pointsWmsImage(SpatialSearchRequestParams requestParams, @RequestParam(value = "colourby", required = false, defaultValue = "0") Integer colourby, @RequestParam(value = "width", required = false, defaultValue = "256") Integer widthObj, @RequestParam(value = "height", required = false, defaultValue = "256") Integer heightObj, @RequestParam(value = "zoom", required = false, defaultValue = "0") Integer zoomLevel, @RequestParam(value = "symsize", required = false, defaultValue = "4") Integer symsize, @RequestParam(value = "symbol", required = false, defaultValue = "circle") String symbol, @RequestParam(value = "bbox", required = false, defaultValue = "110,-45,157,-9") String bboxString, @RequestParam(value = "type", required = false, defaultValue = "normal") String type, @RequestParam(value = "outline", required = true, defaultValue = "false") boolean outlinePoints, @RequestParam(value = "outlineColour", required = true, defaultValue = "0x000000") String outlineColour, HttpServletResponse response) throws Exception { // size of the circles int size = symsize.intValue(); int width = widthObj.intValue(); int height = heightObj.intValue(); requestParams.setStart(0);/* w ww . ja v a 2 s . c o m*/ requestParams.setPageSize(Integer.MAX_VALUE); String query = requestParams.getQ(); String[] filterQuery = requestParams.getFq(); if (StringUtils.isBlank(query) && StringUtils.isBlank(requestParams.getFormattedQuery())) { displayBlankImage(width, height, false, response); return; } // let's force it to PNG's for now response.setContentType("image/png"); // Convert array to list so we append more values onto it ArrayList<String> fqList = null; if (filterQuery != null) { fqList = new ArrayList<String>(Arrays.asList(filterQuery)); } else { fqList = new ArrayList<String>(); } // the bounding box double[] bbox = new double[4]; int i; i = 0; for (String s : bboxString.split(",")) { try { bbox[i] = Double.parseDouble(s); i++; } catch (Exception e) { logger.error(e.getMessage(), e); } } double pixelWidth = (bbox[2] - bbox[0]) / width; double pixelHeight = (bbox[3] - bbox[1]) / height; bbox[0] += pixelWidth / 2; bbox[2] -= pixelWidth / 2; bbox[1] += pixelHeight / 2; bbox[3] -= pixelHeight / 2; //offset for points bounding box by size double xoffset = (bbox[2] - bbox[0]) / (double) width * (size * 2); double yoffset = (bbox[3] - bbox[1]) / (double) height * (size * 2); //adjust offset for pixel height/width xoffset += pixelWidth; yoffset += pixelHeight; double[] bbox2 = new double[4]; bbox2[0] = convertMetersToLng(bbox[0] - xoffset); bbox2[1] = convertMetersToLat(bbox[1] - yoffset); bbox2[2] = convertMetersToLng(bbox[2] + xoffset); bbox2[3] = convertMetersToLat(bbox[3] + yoffset); bbox[0] = convertMetersToLng(bbox[0]); bbox[1] = convertMetersToLat(bbox[1]); bbox[2] = convertMetersToLng(bbox[2]); bbox[3] = convertMetersToLat(bbox[3]); double[] pbbox = new double[4]; //pixel bounding box pbbox[0] = convertLngToPixel(bbox[0]); pbbox[1] = convertLatToPixel(bbox[1]); pbbox[2] = convertLngToPixel(bbox[2]); pbbox[3] = convertLatToPixel(bbox[3]); String bboxString2 = bbox2[0] + "," + bbox2[1] + "," + bbox2[2] + "," + bbox2[3]; bboxToQuery(bboxString2, fqList); PointType pointType = getPointTypeForZoomLevel(zoomLevel); String[] newFilterQuery = (String[]) fqList.toArray(new String[fqList.size()]); // convert back to array requestParams.setFq(newFilterQuery); List<OccurrencePoint> points = searchDAO.getFacetPoints(requestParams, pointType); logger.debug("Points search for " + pointType.getLabel() + " - found: " + points.size()); if (points.size() == 0) { displayBlankImage(width, height, false, response); return; } BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = (Graphics2D) img.getGraphics(); g.setColor(Color.RED); int x, y; int pointWidth = size * 2; double width_mult = (width / (pbbox[2] - pbbox[0])); double height_mult = (height / (pbbox[1] - pbbox[3])); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Color oColour = Color.decode(outlineColour); for (i = 0; i < points.size(); i++) { OccurrencePoint pt = points.get(i); float lng = pt.getCoordinates().get(0).floatValue(); float lat = pt.getCoordinates().get(1).floatValue(); x = (int) ((convertLngToPixel(lng) - pbbox[0]) * width_mult); y = (int) ((convertLatToPixel(lat) - pbbox[3]) * height_mult); if (colourby != null) { int colour = 0xFF000000 | colourby.intValue(); Color c = new Color(colour); g.setPaint(c); } else { g.setPaint(Color.blue); } // g.fillOval(x - (size / 2), y - (size / 2), pointWidth, pointWidth); Shape shp = getShape(symbol, x - (size / 2), y - (size / 2), pointWidth, pointWidth); g.draw(shp); g.fill(shp); if (outlinePoints) { g.setPaint(oColour); g.drawOval(x - (size / 2), y - (size / 2), pointWidth, pointWidth); } } g.dispose(); try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ImageIO.write(img, "png", outputStream); ServletOutputStream outStream = response.getOutputStream(); outStream.write(outputStream.toByteArray()); outStream.flush(); outStream.close(); } catch (Exception e) { logger.error("Unable to write image", e); } }
From source file:com.openbravo.pos.util.ThumbNailBuilder.java
public Image getThumbNailText(Image img, String text) { /*//from www .j av a2s . co m * Create an image containing a thumbnail of the product image, * or default image. * * Then apply the text of the product name. Use text wrapping. * * If the product name is too big for the label, ensure that * the first part is displayed. */ img = getThumbNail(img); BufferedImage imgtext = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = imgtext.createGraphics(); // The text // <p style="width: 100px"> DOES NOT WORK PROPERLY. // use width= instead. String html = "<html><p style=\"text-align:center\" width=\"" + imgtext.getWidth() + "\">" + StringEscapeUtils.escapeHtml(text) + "</p>"; JLabel label = new JLabel(html); label.setOpaque(false); //label.setText("<html><center>Line1<br>Line2"); label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); label.setVerticalAlignment(javax.swing.SwingConstants.TOP); Dimension d = label.getPreferredSize(); label.setBounds(0, 0, imgtext.getWidth(), d.height); // The background Color c1 = new Color(0xff, 0xff, 0xff, 0x40); Color c2 = new Color(0xff, 0xff, 0xff, 0xd0); // Point2D center = new Point2D.Float(imgtext.getWidth() / 2, label.getHeight()); // float radius = imgtext.getWidth() / 3; // float[] dist = {0.1f, 1.0f}; // Color[] colors = {c2, c1}; // Paint gpaint = new RadialGradientPaint(center, radius, dist, colors); Paint gpaint = new GradientPaint(new Point(0, 0), c1, new Point(label.getWidth() / 2, 0), c2, true); g2d.drawImage(img, 0, 0, null); int ypos = imgtext.getHeight() - label.getHeight(); int ypos_min = -4; // todo: configurable if (ypos < ypos_min) ypos = ypos_min; // Clamp label g2d.translate(0, ypos); g2d.setPaint(gpaint); g2d.fillRect(0, 0, imgtext.getWidth(), label.getHeight()); label.paint(g2d); g2d.dispose(); return imgtext; }
From source file:org.mwc.cmap.grideditor.chart.RendererWithDynamicFeedback.java
/** * @see drawSecondaryPass// ww w. j av a 2 s . com */ private void drawFeedBackNode(final Graphics2D g2, final XYPlot plot, final XYDataset dataset, final int pass, // final int series, final int item, final ValueAxis domainAxis, final Rectangle2D dataArea, final ValueAxis rangeAxis, // final CrosshairState crosshairState, final EntityCollection entities) { // get the data point... final double x1 = myFeedBackValue != null ? myFeedBackValue.x : dataset.getXValue(series, item); final double y1 = myFeedBackValue != null ? myFeedBackValue.y : dataset.getYValue(series, item); if (Double.isNaN(y1) || Double.isNaN(x1)) { return; } final PlotOrientation orientation = plot.getOrientation(); final RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); final RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); final double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); final double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); if (getItemShapeVisible(series, item)) { Shape shape = getItemShape(series, item); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1); } if (shape.intersects(dataArea)) { g2.setPaint(getFeedbackNodePaint()); g2.fill(shape); } } double xx = transX1; double yy = transY1; if (orientation == PlotOrientation.HORIZONTAL) { xx = transY1; yy = transX1; } drawFeedbackItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0)); }
From source file:KIDLYRenderer.java
/** * Draws an item label. This method is overridden so that the bar can be * used to calculate the label anchor point. * * @param g2 the graphics device./*from ww w. j a va 2 s .c om*/ * @param data the dataset. * @param row the row. * @param column the column. * @param plot the plot. * @param generator the label generator. * @param bar the bar. * @param negative a flag indicating a negative value. */ protected void drawItemLabel(Graphics2D g2, CategoryDataset data, int row, int column, CategoryPlot plot, CategoryItemLabelGenerator generator, Rectangle2D bar, boolean negative) { String label = generator.generateLabel(data, row, column); if (label == null) { return; // nothing to do } Font labelFont = getItemLabelFont(row, column); g2.setFont(labelFont); Paint paint = getItemLabelPaint(row, column); g2.setPaint(paint); // find out where to place the label... ItemLabelPosition position = null; if (!negative) { position = getPositiveItemLabelPosition(row, column); } else { position = getNegativeItemLabelPosition(row, column); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, plot.getOrientation()); if (isInternalAnchor(position.getItemLabelAnchor())) { Shape bounds = TextUtilities.calculateRotatedStringBounds(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); if (bounds != null) { if (!bar.contains(bounds.getBounds2D())) { if (!negative) { position = getPositiveItemLabelPositionFallback(); } else { position = getNegativeItemLabelPositionFallback(); } if (position != null) { anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, plot.getOrientation()); } } } } if (position != null) { TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }
From source file:com.rapidminer.gui.viewer.metadata.AttributeStatisticsPanel.java
@Override public void paintComponent(final Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int x = 0;// ww w.j av a 2 s. c o m int y = 0; int width = (int) getSize().getWidth(); int height = (int) getSize().getHeight(); // draw background depending special roles and hovering if (getModel() != null && getModel().isSpecialAtt()) { if (Attributes.LABEL_NAME.equals(getModel().getSpecialAttName())) { // label special attributes have a distinct color g2.setPaint( new GradientPaint(x, y, getColorForSpecialAttribute(Attributes.LABEL_NAME, true, hovered), x, height, getColorForSpecialAttribute(Attributes.LABEL_NAME, false, hovered))); } else if (Attributes.WEIGHT_NAME.equals(getModel().getSpecialAttName())) { // weight special attributes have another distinct color g2.setPaint( new GradientPaint(x, y, getColorForSpecialAttribute(Attributes.WEIGHT_NAME, true, hovered), x, height, getColorForSpecialAttribute(Attributes.WEIGHT_NAME, false, hovered))); } else if (Attributes.PREDICTION_NAME.equals(getModel().getSpecialAttName())) { // prediction special attributes have another distinct color g2.setPaint(new GradientPaint(x, y, getColorForSpecialAttribute(Attributes.PREDICTION_NAME, true, hovered), x, height, getColorForSpecialAttribute(Attributes.PREDICTION_NAME, false, hovered))); } else if (getModel().getSpecialAttName().startsWith(Attributes.CONFIDENCE_NAME + "_")) { // confidence special attributes have another distinct color g2.setPaint(new GradientPaint(x, y, getColorForSpecialAttribute(Attributes.CONFIDENCE_NAME, true, hovered), x, height, getColorForSpecialAttribute(Attributes.CONFIDENCE_NAME, false, hovered))); } else if (Attributes.ID_NAME.equals(getModel().getSpecialAttName())) { // id special attributes have another distinct color g2.setPaint(new GradientPaint(x, y, getColorForSpecialAttribute(Attributes.ID_NAME, true, hovered), x, height, getColorForSpecialAttribute(Attributes.ID_NAME, false, hovered))); } else { // other special attributes have another color g2.setPaint( new GradientPaint(x, y, getColorForSpecialAttribute(GENERIC_SPECIAL_NAME, true, hovered), x, height, getColorForSpecialAttribute(GENERIC_SPECIAL_NAME, false, hovered))); } } else { // regular attributes g2.setPaint( new GradientPaint(x, y, getColorForSpecialAttribute(Attributes.ATTRIBUTE_NAME, true, hovered), x, height, getColorForSpecialAttribute(Attributes.ATTRIBUTE_NAME, false, hovered))); } g2.fillRoundRect(x, y, width, height, CORNER_ARC_WIDTH, CORNER_ARC_WIDTH); // draw border g2.setPaint(new GradientPaint(x, y, COLOR_BORDER_GRADIENT_FIRST, x, height, COLOR_BORDER_GRADIENT_SECOND)); if (hovered) { g2.setStroke(new BasicStroke(1.0f)); } else { g2.setStroke(new BasicStroke(0.5f)); } g2.drawRoundRect(x, y, width - 1, height - 1, CORNER_ARC_WIDTH, CORNER_ARC_WIDTH); // let Swing draw its components super.paintComponent(g2); }
From source file:org.fhcrc.cpl.viewer.quant.gui.QuantitationVisualizer.java
/** * Save chart to an image file, with or without the sidebar information and/or theoretical peaks * @param chartPanel/* w w w .j av a2 s . c om*/ * @param outFile * @param sidebarWidth * @param charge * @param lightMz * @param heavyMz * @param ratio * @throws IOException */ public void saveChartToImageFile(PanelWithChart chartPanel, File outFile, int sidebarWidth, int charge, float lightMz, float heavyMz, float ratio, boolean writeChartInfo, int width, int height, boolean overrideSize) throws IOException { BufferedImage spectrumImage = null; if (overrideSize) spectrumImage = chartPanel.createImage(width, height); else spectrumImage = chartPanel.createImage(); BufferedImage imageToWrite = spectrumImage; if (writeChartInfo) { int fullImageWidth = spectrumImage.getWidth() + sidebarWidth; imageToWrite = new BufferedImage(fullImageWidth, spectrumImage.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics2D g = imageToWrite.createGraphics(); g.drawImage(spectrumImage, sidebarWidth, 0, null); //write in sidebar int lineHeight = 20; int lineNum = 1; int indent = 5; if (writeChartInfo) { g.setPaint(Color.WHITE); // g.drawString(peptide, indent, lineNum++ * lineHeight); // g.drawString("Charge=" + charge, indent, lineNum++ * lineHeight); // g.drawString("Light mass=" + lightMass, indent, lineNum++ * lineHeight); // g.drawString("Light m/z=" + lightMz, indent, lineNum++ * lineHeight); // g.drawString("Heavy m/z=" + heavyMz, indent, lineNum++ * lineHeight); // g.drawString("Light int=" + lightIntensity, indent, lineNum++ * lineHeight); // g.drawString("Heavy int=" + heavyIntensity, indent, lineNum++ * lineHeight); g.drawString("Ratio=" + ratio, indent, lineNum++ * lineHeight); // g.drawString("MinscanLt=" + lightMinQuantScan, indent, lineNum++ * lineHeight); // g.drawString("MaxscanLt=" + lightMaxQuantScan, indent, lineNum++ * lineHeight); // g.drawString("MinScanHv=" + heavyMinQuantScan, indent, lineNum++ * lineHeight); // g.drawString("MaxScanHv=" + heavyMaxQuantScan, indent, lineNum++ * lineHeight); // g.drawString("ID scan=" + idScan, indent, lineNum++ * lineHeight); // g.drawString("IDscan level=" + idScanLevel, indent, lineNum++ * lineHeight); //theoretical peaks in bottom left int theoreticalPeaksHeight = (int) (sidebarWidth * 2.0 / 3.0); int theoreticalPeaksTop = spectrumImage.getHeight() - theoreticalPeaksHeight - 10; g.drawString("Ideal Peaks", indent, theoreticalPeaksTop - 20); //combined theoretical peak distribution chart PanelWithPeakChart theoreticalPeakChart = buildTheoreticalPeakChart(lightMz, heavyMz, charge, ratio, sidebarWidth, (int) (sidebarWidth * 2.0 / 3.0)); g.drawImage(theoreticalPeakChart.createImage(sidebarWidth, (int) (sidebarWidth * 2.0 / 3.0)), 0, theoreticalPeaksTop, null); } g.dispose(); } ImageIO.write(imageToWrite, "png", outFile); }
From source file:org.pentaho.platform.uifoundation.chart.BubbleRenderer.java
/** * Draws the visual representation of a single data item. * //from w w w. ja v a 2 s . com * @param g2 * the graphics device. * @param state * the renderer state. * @param dataArea * the area within which the data is being drawn. * @param info * collects information about the drawing. * @param plot * the plot (can be used to obtain standard color information etc). * @param domainAxis * the domain (horizontal) axis. * @param rangeAxis * the range (vertical) axis. * @param dataset * the dataset (an {@link XYZDataset} is expected). * @param series * the series index (zero-based). * @param item * the item index (zero-based). * @param crosshairState * crosshair information for the plot (<code>null</code> permitted). * @param pass * the pass index. */ @Override public void drawItem(final Graphics2D g2, final XYItemRendererState state, final Rectangle2D dataArea, final PlotRenderingInfo info, final XYPlot plot, final ValueAxis domainAxis, final ValueAxis rangeAxis, final XYDataset dataset, final int series, final int item, final CrosshairState crosshairState, final int pass) { PlotOrientation orientation = plot.getOrientation(); // get the data point... double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double z = Double.NaN; if (dataset instanceof XYZDataset) { XYZDataset xyzData = (XYZDataset) dataset; z = xyzData.getZValue(series, item); } if (!Double.isNaN(z)) { RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation); double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation); double circleSize; circleSize = maxSize * (z / maxZ); circleSize = Math.abs(circleSize); Ellipse2D circle = null; if (orientation == PlotOrientation.VERTICAL) { circle = new Ellipse2D.Double(transX - circleSize / 2.0, transY - circleSize / 2.0, circleSize, circleSize); } else if (orientation == PlotOrientation.HORIZONTAL) { circle = new Ellipse2D.Double(transY - circleSize / 2.0, transX - circleSize / 2.0, circleSize, circleSize); } g2.setPaint(getItemPaint(series, item)); g2.fill(circle); g2.setStroke(getItemOutlineStroke(series, item)); g2.setPaint(getItemOutlinePaint(series, item)); g2.draw(circle); if (isItemLabelVisible(series, item)) { if (orientation == PlotOrientation.VERTICAL) { drawItemLabel(g2, orientation, dataset, series, item, transX, transY, false); } else if (orientation == PlotOrientation.HORIZONTAL) { drawItemLabel(g2, orientation, dataset, series, item, transY, transX, false); } } // setup for collecting optional entity info... EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } // add an entity for the item... if (entities != null) { String tip = null; XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) { tip = generator.generateToolTip(dataset, series, item); } String url = null; if (getURLGenerator() != null) { url = getURLGenerator().generateURL(dataset, series, item); } XYItemEntity entity = new XYItemEntity(circle, dataset, series, item, tip, url); entities.add(entity); } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation); } }
From source file:org.earthtime.UPb_Redux.dateInterpretation.WeightedMeanGraphPanel.java
private void drawAxesAndTicks(Graphics2D g2d, double rangeX, double rangeY) { // oct 2014 new tic logic // reset the clip bounds to paint axis and numbers g2d.setClip(0, 0, getWidth(), getHeight()); g2d.setFont(new Font("Monospaced", Font.BOLD, 14)); g2d.setPaint(Color.BLACK); g2d.setStroke(new BasicStroke(2.0f)); // determine the axis ticks BigDecimal[] tics = TicGeneratorForAxes.generateTics(getMinY_Display(), getMaxY_Display(), 12); // trap for bad plot if (tics.length <= 1) { tics = new BigDecimal[0]; }/*from ww w. j a v a2 s.c o m*/ double minXDisplay = 0.0; int yAxisTicWidth = 8; int yTicLabelFrequency = 2; int labeledTicCountYAxis = 0; g2d.setPaint(Color.black); for (int i = 0; i < tics.length; i++) { double y = tics[i].doubleValue(); if ((y > getMinY_Display()) // dont print across mappedX axis && (y < getMaxY_Display())) // dont print across top border { try { Shape ticMark = new Line2D.Double( // mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth), mapY(y, getMaxY_Display(), rangeY, graphHeight), mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) + 7, mapY(y, getMaxY_Display(), rangeY, graphHeight)); g2d.draw(ticMark); String intString = "00000" + tics[i].toPlainString().replace(".", ""); int lastPlace = Integer.parseInt(intString.substring(intString.length() - 4)); if (lastPlace % yTicLabelFrequency == 0) { if (labeledTicCountYAxis % yTicLabelFrequency == 0) { TextLayout mLayout = // new TextLayout(tics[i].toPlainString(), g2d.getFont(), g2d.getFontRenderContext()); Rectangle2D bounds = mLayout.getBounds(); //if (isyAxisHorizontalTicLabels()) { // g2d.drawString(tics[i].toPlainString(),// // (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f, // (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + 30f); // } else { float yLabelCenterOffset = (float) mLayout.getBounds().getWidth() / 2f; g2d.rotate(-Math.PI / 2.0, (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f, (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + yLabelCenterOffset); g2d.drawString(tics[i].toPlainString(), (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f, (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + yLabelCenterOffset); g2d.rotate(Math.PI / 2.0, (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f, (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + yLabelCenterOffset); } labeledTicCountYAxis++; } else { if (labeledTicCountYAxis > 0) { labeledTicCountYAxis++; } } } catch (Exception e) { } } } //// // reset the clip bounds to paint axis and numbers //// g2d.setClip(0, 0, getWidth(), getHeight()); //// //// g2d.setFont(new Font("Monospaced", Font.BOLD, 14)); //// g2d.setPaint(Color.BLACK); //// g2d.setStroke(new BasicStroke(2.0f)); //// //// // determine the axis ticks //// double minYtick = Math.ceil(getMinY_Display() * 100) / 100; //// double maxYtick = Math.floor(getMaxY_Display() * 100) / 100; //// //// int count = 0; //// double deltay = Math.rint((maxYtick - minYtick) * 10 + 0.5); //// double stepYtick = deltay / 100; //// //// for (double y = minYtick; y //// < maxYtick; y //// += stepYtick) { //// Line2D line = new Line2D.Double( //// mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth), //// mapY(y, getMaxY_Display(), rangeY, graphHeight), //// mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) + 7, //// mapY(y, getMaxY_Display(), rangeY, graphHeight)); //// g2d.draw(line); //// //// if ((count % 2) == 1) { //// NumberFormat yFormat = null; //// String temp = null; //// //// yFormat //// = new DecimalFormat("0.00"); //// temp //// = yFormat.format(y); //// //// g2d.setPaint(Color.black); //// g2d.rotate( //// -Math.PI / 2.0, //// (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f, //// (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + 30f); //// g2d.drawString( //// temp, //// (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f, //// (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + 30f); //// g2d.rotate( //// Math.PI / 2.0, //// (float) mapX(getMinX_Display(), getMinX_Display(), rangeX, graphWidth) - 4f, //// (float) mapY(y, getMaxY_Display(), rangeY, graphHeight) + 30f); //// //// } //// //// count++; //// //// } // draw and label axes g2d.setFont(new Font("Monospaced", Font.BOLD, 20)); g2d.drawRect(getLeftMargin(), getTopMargin(), getGraphWidth() - 1, getGraphHeight() - 1); }
From source file:org.openfaces.component.chart.impl.renderers.LineFillRenderer.java
private void configureGradientAreaFill(Graphics2D g2, CategoryPlot plot, Paint itemPaint, PlotRenderingInfo info, GradientLineAreaFill gradientLineAreaFill) { double plotWidth = info.getPlotArea().getWidth(); double plotHeight = info.getPlotArea().getHeight(); Double mainColorTransparency = gradientLineAreaFill.getMaxValueTransparency(); Double bgColorTransparency = gradientLineAreaFill.getMinValueTransparency(); if (itemPaint instanceof Color) { Color itemColor = (Color) itemPaint; int red = itemColor.getRed(); int green = itemColor.getGreen(); int blue = itemColor.getBlue(); int mainColorAlpha = (mainColorTransparency >= 0.0 && mainColorTransparency <= 1.0) ? Math.round(255 * mainColorTransparency.floatValue()) : 150;/*from www .j av a2 s. c o m*/ int bgColorAlpha = (bgColorTransparency >= 0.0 && bgColorTransparency <= 1.0) ? Math.round(255 * bgColorTransparency.floatValue()) : 128; Color mainColor = new Color(red, green, blue, mainColorAlpha); Paint bgColor = getBackgroundPaint(); if (bgColor == null) { bgColor = plot.getBackgroundPaint(); } Color secondaryColor = getSecondaryColor(bgColorAlpha, bgColor); Paint areaPaint = getAreaFillPaint(plot, plotWidth, plotHeight, mainColor, secondaryColor); g2.setPaint(areaPaint); } else { g2.setPaint(itemPaint); } }
From source file:org.pentaho.plugin.jfreereport.reportcharts.BubbleRenderer.java
/** * Draws the visual representation of a single data item. * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area within which the data is being drawn. * @param info collects information about the drawing. * @param plot the plot (can be used to obtain standard color information etc). * @param domainAxis the domain (horizontal) axis. * @param rangeAxis the range (vertical) axis. * @param dataset the dataset (an {@link XYZDataset} is expected). * @param series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState crosshair information for the plot (<code>null</code> permitted). * @param pass the pass index. *///ww w . j a v a 2 s .c o m public void drawItem(final Graphics2D g2, final XYItemRendererState state, final Rectangle2D dataArea, final PlotRenderingInfo info, final XYPlot plot, final ValueAxis domainAxis, final ValueAxis rangeAxis, final XYDataset dataset, final int series, final int item, final CrosshairState crosshairState, final int pass) { final PlotOrientation orientation = plot.getOrientation(); // get the data point... final double x = dataset.getXValue(series, item); final double y = dataset.getYValue(series, item); double z = Double.NaN; if (dataset instanceof XYZDataset) { final XYZDataset xyzData = (XYZDataset) dataset; z = xyzData.getZValue(series, item); } if (!Double.isNaN(z)) { final RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); final RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); final double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation); final double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation); double circleSize; circleSize = maxSize * (z / maxZ); circleSize = Math.abs(circleSize); Ellipse2D circle = null; if (orientation == PlotOrientation.VERTICAL) { circle = new Ellipse2D.Double(transX - circleSize / 2.0, transY - circleSize / 2.0, circleSize, circleSize); } else if (orientation == PlotOrientation.HORIZONTAL) { circle = new Ellipse2D.Double(transY - circleSize / 2.0, transX - circleSize / 2.0, circleSize, circleSize); } g2.setPaint(getItemPaint(series, item)); g2.fill(circle); g2.setStroke(getItemOutlineStroke(series, item)); g2.setPaint(getItemOutlinePaint(series, item)); g2.draw(circle); if (isItemLabelVisible(series, item)) { if (orientation == PlotOrientation.VERTICAL) { drawItemLabel(g2, orientation, dataset, series, item, transX, transY, false); } else if (orientation == PlotOrientation.HORIZONTAL) { drawItemLabel(g2, orientation, dataset, series, item, transY, transX, false); } } // setup for collecting optional entity info... EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } // add an entity for the item... if (entities != null) { String tip = null; final XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) { tip = generator.generateToolTip(dataset, series, item); } String url = null; if (getURLGenerator() != null) { url = getURLGenerator().generateURL(dataset, series, item); } final XYItemEntity entity = new XYItemEntity(circle, dataset, series, item, tip, url); entities.add(entity); } final int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); final int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation); } }