List of usage examples for java.awt RenderingHints VALUE_INTERPOLATION_BICUBIC
Object VALUE_INTERPOLATION_BICUBIC
To view the source code for java.awt RenderingHints VALUE_INTERPOLATION_BICUBIC.
Click Source Link
From source file:edu.kit.dama.ui.components.TextImage.java
/** * Get the bytes of the final image.//w w w. j a va 2 s . c o m * * @return The byte array containing the bytes of the resulting image. * * @throws IOException if creating the image fails. */ public byte[] getBytes() throws IOException { Image transparentImage = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource( new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB).getSource(), new RGBImageFilter() { @Override public final int filterRGB(int x, int y, int rgb) { return (rgb << 8) & 0xFF000000; } })); //create the actual image and overlay it by the transparent background BufferedImage outputImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = outputImage.createGraphics(); g2d.drawImage(transparentImage, 0, 0, null); //draw the remaining stuff g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2d.setColor(color); g2d.fillRoundRect(0, 0, size, size, 20, 20); g2d.setColor(new Color(Math.round((float) color.getRed() * .9f), Math.round((float) color.getGreen() * .9f), Math.round((float) color.getBlue() * .9f))); g2d.drawRoundRect(0, 0, size - 1, size - 1, 20, 20); Font font = new Font("Dialog", Font.BOLD, size - 4); g2d.setFont(font); g2d.setColor(Color.WHITE); String s = text.toUpperCase().substring(0, 1); FontMetrics fm = g2d.getFontMetrics(); float x = ((float) size - (float) fm.stringWidth(s)) / 2f; float y = ((float) fm.getAscent() + (float) ((float) size - ((float) fm.getAscent() + (float) fm.getDescent())) / 2f) - 1f; g2d.drawString(s, x, y); ByteArrayOutputStream bout = new ByteArrayOutputStream(); ImageIO.write(outputImage, "png", bout); g2d.dispose(); return bout.toByteArray(); }
From source file:com.frostwire.gui.library.LibraryCoverArt.java
private void setPrivateImage(Image image) { coverArtImage = image;//from www. j a v a 2 s . c om if (coverArtImage == null) { coverArtImage = defaultCoverArt; } Graphics2D g2 = background.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.setBackground(new Color(255, 255, 255, 0)); g2.clearRect(0, 0, getWidth(), getHeight()); g2.drawImage(coverArtImage, 0, 0, getWidth(), getHeight(), null); g2.dispose(); repaint(); getToolkit().sync(); }
From source file:net.sf.firemox.clickable.target.card.VirtualCard.java
@SuppressWarnings("null") @Override// www . ja v a 2s .c o m public void paintComponent(Graphics g) { final Graphics2D g2D = (Graphics2D) g; // Renderer g2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); // Optimization card painting final MZone container = card.getContainer(); final boolean shortPaint = container == null || !container.isMustBePainted(card); // tap/reverse operation : PI/2, PI, -PI/2 rotation if (!shortPaint) { if (container.isMustBePaintedReversed(card)) { if (card.tapped) { g2D.translate(rotateTransformY, CardFactory.cardWidth + rotateTransformX); g2D.rotate(angle - Math.PI / 2); } else { g2D.translate(CardFactory.cardWidth + rotateTransformX, CardFactory.cardHeight + rotateTransformY); g2D.rotate(Math.PI - angle); } } else { if (card.tapped) { g2D.translate(CardFactory.cardHeight + rotateTransformY, rotateTransformX); g2D.rotate(Math.PI / 2 + angle); } else { g2D.translate(rotateTransformX, rotateTransformY); g2D.rotate(angle); } } } if (container != null) { if (container.isVisibleForOpponent() && !card.isVisibleForOpponent() && card.isVisibleForYou()) { /* * This card is visible for you but not for opponent in despite of the * fact the container is public. */ g2D.drawImage(card.scaledImage(), null, null); g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); g2D.drawImage(DatabaseFactory.scaledBackImage, null, null); } else if (!card.isVisibleForYou()) { g2D.drawImage(DatabaseFactory.scaledBackImage, null, null); } else { g2D.drawImage(card.scaledImage(), null, null); } } if (shortPaint) return; /* * The card picture is displayed as a rounded rectangle with 0,90,180 or * 270 */ if (card.isHighLighted && (card.isVisibleForYou() || StackManager.idHandedPlayer == 0)) { // Draw the rounded colored rectangle g2D.setColor(card.highLightColor); g2D.draw3DRect(0, 0, CardFactory.cardWidth - 2, CardFactory.cardHeight - 2, false); } // Draw the eventual progress bar card.database.updatePaintNotification(card, g); // Cursor for our pretty pictures int px = 3; int py = 3; int maxX = CardFactory.cardWidth - 2; // for in-play, visible cards if (card.isVisibleForYou() || (container != null && container.isVisibleForYou())) { // draw registers above the card's picture if (refreshToolTipFilter().powerANDtoughness) { // power / toughness final String powerANDtoughness = String.valueOf(card.getValue(IdTokens.POWER)) + "/" + card.getValue(IdTokens.TOUGHNESS); g2D.setFont(g2D.getFont().deriveFont(Font.BOLD, 13)); final Rectangle2D stringDim = g2D.getFontMetrics().getStringBounds(powerANDtoughness, g2D); g2D.setColor(CardFactory.powerToughnessColor); g2D.drawString(powerANDtoughness, (int) (CardFactory.cardWidth - stringDim.getWidth() - 3), CardFactory.cardHeight - 5); g2D.setColor(Color.BLUE); g2D.drawString(powerANDtoughness, (int) (CardFactory.cardWidth - stringDim.getWidth() - 3), CardFactory.cardHeight - 6); } /* * START drawing additional pictures */ // draw state pictures for (StatePicture statePicture : CardFactory.statePictures) { if (px + 13 > maxX) { px = 3; py += 13; } if (statePicture.paint(card, g2D, px, py)) { px += 13; } } // draw properties if (card.cachedProperties != null) { for (Integer property : card.cachedProperties) { if (Configuration.getBoolean("card.property.picture", true) && CardFactory.propertyPictures.get(property) != null) { // There is an associated picture to this property if (px + 13 > maxX) { px = 3; py += 13; } g2D.drawImage(CardFactory.propertyPictures.get(property), px, py, 12, 12, null); px += 13; } } } } // draw attached objects int startX = 3; int startY = CardFactory.cardHeight - 18; if (card.registerModifiers != null) { for (int i = card.registerModifiers.length; i-- > 0;) { if (card.registerModifiers[i] != null) { startX = card.registerModifiers[i].paintObject(g, startX, startY); } } } if (card.propertyModifier != null) { startX = card.propertyModifier.paintObject(g, startX, startY); } if (card.idCardModifier != null) { card.idCardModifier.paintObject(g, startX, startY); /* * END drawing additional pictures */ } // Draw the target Id if helper said it final String id = TargetHelper.getInstance().getMyId(card); if (id != null) { if (px + 13 > maxX) { px = 3; py += 13; } if (id == TargetHelper.STR_CONTEXT1) { // TODO I am in the context 1, draw a picture g2D.setColor(Color.BLUE); g2D.setFont(g2D.getFont().deriveFont(Font.BOLD, 60 / id.length())); g2D.drawString(id, 5, CardFactory.cardHeight - 15); } else if (id == TargetHelper.STR_CONTEXT2) { // TODO I am in the context 2, draw a picture g2D.setColor(Color.BLUE); g2D.setFont(g2D.getFont().deriveFont(Font.BOLD, 60 / id.length())); g2D.drawString(id, 5, CardFactory.cardHeight - 15); } else if (id != TargetHelper.STR_SOURCE) { // } else if (id == TargetHelper.STR_SOURCE) { // TODO I am the source, draw a picture // } else { // I am a target g2D.drawImage(TargetHelper.getInstance().getTargetPictureSml(), px, py, null); py += 12; } } g2D.dispose(); }
From source file:com.sdk.connector.chart.CoherenceDomainRenderer.java
public CoherenceDomainRenderer(final String title, JPanel panel, String side) { sdf = Protocol.getInstance().getTimestampFormat(); serieFFT.setKey(side + " FFT Based"); serieLomb.setKey(side + " Lomb Based"); serieMemse.setKey(side + " AR Based"); dataset.addSeries(serieFFT);/*w w w .j ava 2 s.co m*/ dataset.addSeries(serieLomb); dataset.addSeries(serieMemse); chart = ChartFactory.createTimeSeriesChart(title, java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("coherence.xlabel"), java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("coherence.ylabel"), dataset, true, true, false); chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); chart.getRenderingHints().put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); chart.getRenderingHints().put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); chart.getRenderingHints().put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); chart.getRenderingHints().put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); chart.getRenderingHints().put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); chart.getRenderingHints().put(RenderingHints.KEY_TEXT_LCD_CONTRAST, 100); //chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.GREEN)); // chart.setBackgroundPaint(new Color(220,255,220,0)); //chart.setBackgroundImage(new javax.swing.ImageIcon(getClass().getResource("/com/sdk/connector/resources/background.png")).getImage()); chart.addSubtitle(rangeAnnotation); plot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, true); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator( StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, sdf, new DecimalFormat("0.00"))); renderer.setSeriesOutlinePaint(0, Color.BLACK); if (side.startsWith( java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("side.left"))) { renderer.setSeriesPaint(0, Color.BLUE); leftSide = true; } else { renderer.setSeriesPaint(0, Color.RED); leftSide = false; } renderer.setSeriesShape(0, new Ellipse2D.Double(-1.0, -1.0, 3.0, 3.0)); DateTickUnit dtUnit = new DateTickUnit(DateTickUnitType.MINUTE, 1, tickSDF); final DateAxis domainAxis = (DateAxis) plot.getDomainAxis(); domainAxis.setTickUnit(dtUnit); // ValueAxis axis = plot.getDomainAxis(); // axis = plot.getRangeAxis(); // ((NumberAxis) axis).setTickUnit(new NumberTickUnit(100)); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.BLACK); plot.setRangeGridlinePaint(Color.BLACK); plot.getRenderer().setSeriesStroke(0, new BasicStroke(1.0f)); // plot.getRenderer().setSeriesStroke(1, new BasicStroke(1.0f)); plot.setForegroundAlpha(0.5f); plot.setNoDataMessage( java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("message.wait")); plot.setRangePannable(true); plot.setDomainPannable(true); Color color1 = new Color(0, 0, 0, 24); Color color2 = new Color(255, 255, 255, 24); GradientPaint gp = new GradientPaint(0, 0, color1, 0, 0, color2); plot.setBackgroundPaint(gp); chartPanel = new ChartPanel(chart); panel.setLayout(new GridLayout(0, 1)); panel.add(chartPanel); panel.repaint(); panel.revalidate(); }
From source file:de.bamamoto.mactools.png2icns.Scaler.java
public static BufferedImage resize(BufferedImage source, int width, int height) { double xScale = ((double) width) / (double) source.getWidth(); double yScale = ((double) height) / (double) source.getHeight(); BufferedImage result = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration()/*from w w w . j a v a 2 s . co m*/ .createCompatibleImage(width, height, source.getColorModel().getTransparency()); Graphics2D newImage = null; try { newImage = result.createGraphics(); newImage.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); newImage.drawRenderedImage(source, AffineTransform.getScaleInstance(xScale, yScale)); } finally { if (newImage != null) { newImage.dispose(); } } return result; }
From source file:com.hmsinc.epicenter.spatial.render.SpatialScanRenderer.java
/** * @param context//w w w. j av a2 s.c om * @return */ private BufferedImage renderImage(final MapContext context, int width, int height) { logger.trace("Image width: {} height: {}", width, height); final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); final Graphics2D graphics2D = (Graphics2D) image.getGraphics(); final GTRenderer renderer = new StreamingRenderer(); final RenderingHints h = new RenderingHints(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); h.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); h.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); h.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); h.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); renderer.setJava2DHints(h); renderer.setContext(context); renderer.paint(graphics2D, new Rectangle(width, height), context.getAreaOfInterest()); return image; }
From source file:com.sdk.connector.chart.TimeDomainRenderer.java
public TimeDomainRenderer(final String title, JPanel panel, String side, String type) { sdf = protocol.getTimestampFormat(); this.side = side + type; this.type = type; serie.setKey(side);//from ww w. ja va 2s.c o m dataset.addSeries(serie); String legendX = ""; if (type.startsWith(java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("RR"))) { legendX = java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle") .getString("timeRR.ylabel"); } else { legendX = java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle") .getString("timeBC.ylabel"); } chart = ChartFactory.createTimeSeriesChart(title, java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("time.xlabel"), legendX, dataset, true, true, false); chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); chart.getRenderingHints().put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); chart.getRenderingHints().put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); chart.getRenderingHints().put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); chart.getRenderingHints().put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); chart.getRenderingHints().put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); chart.getRenderingHints().put(RenderingHints.KEY_TEXT_LCD_CONTRAST, 100); //chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.GREEN)); // chart.setBackgroundPaint(new Color(220,255,220,0)); //chart.setBackgroundImage(new javax.swing.ImageIcon(getClass().getResource("/com/sdk/connector/resources/background.png")).getImage()); chart.addSubtitle(rangeAnnotation); plot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, true); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator( StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, sdf, new DecimalFormat("0.00"))); renderer.setSeriesOutlinePaint(0, Color.BLACK); if (side.startsWith( java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("side.left"))) { renderer.setSeriesPaint(0, Color.BLUE); } else { renderer.setSeriesPaint(0, Color.RED); } renderer.setSeriesShape(0, new Ellipse2D.Double(-1.0, -1.0, 3.0, 3.0)); if (type.startsWith(java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("BC"))) { renderer.setSeriesShape(0, new Rectangle2D.Double(-1.0, -1.0, 3.0, 3.0)); } DateTickUnit dtUnit = new DateTickUnit(DateTickUnitType.MINUTE, 1, tickSDF); final DateAxis domainAxis = (DateAxis) plot.getDomainAxis(); domainAxis.setTickUnit(dtUnit); // ValueAxis axis = plot.getDomainAxis(); // axis = plot.getRangeAxis(); // ((NumberAxis) axis).setTickUnit(new NumberTickUnit(100)); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.BLACK); plot.setRangeGridlinePaint(Color.BLACK); plot.getRenderer().setSeriesStroke(0, new BasicStroke(1.0f)); // plot.getRenderer().setSeriesStroke(1, new BasicStroke(1.0f)); plot.setForegroundAlpha(0.5f); plot.setNoDataMessage( java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("CALIBRATING...")); plot.setRangePannable(true); plot.setDomainPannable(true); Color color1 = new Color(0, 0, 0, 24); Color color2 = new Color(255, 255, 255, 24); GradientPaint gp = new GradientPaint(0, 0, color1, 0, 0, color2); plot.setBackgroundPaint(gp); chartPanel = new ChartPanel(chart); chartPanel.addChartMouseListener(this); panel.setLayout(new GridLayout(0, 1)); panel.add(chartPanel); panel.repaint(); panel.revalidate(); }
From source file:com.sun.socialsite.util.ImageUtil.java
public static BufferedImage getScaledImage(BufferedImage origImage, Integer desiredWidth, Integer desiredHeight) throws IOException { if (origImage == null) { return null; }/* w ww.j av a 2 s .co m*/ if (desiredWidth == null) { desiredWidth = origImage.getWidth(); } if (desiredHeight == null) { desiredHeight = origImage.getHeight(); } int origWidth = origImage.getWidth(); int origHeight = origImage.getHeight(); double ratio = Math.min((((double) desiredWidth) / origWidth), (((double) desiredHeight) / origHeight)); int extraWidth = desiredWidth - ((int) (origWidth * ratio)); int extraHeight = desiredHeight - ((int) (origHeight * ratio)); int tmpWidth = (desiredWidth - extraWidth); int tmpHeight = (desiredHeight - extraHeight); BufferedImage tmpImage = getScaledInstance(origImage, tmpWidth, tmpHeight, RenderingHints.VALUE_INTERPOLATION_BICUBIC, true); log.debug(String.format("tmpImage[width=%d height=%d", tmpImage.getWidth(), tmpImage.getHeight())); if ((tmpImage.getWidth() == desiredWidth) && (tmpImage.getHeight() == desiredHeight)) { return tmpImage; } else { BufferedImage scaledImage = new BufferedImage(desiredWidth, desiredHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = scaledImage.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); // We recalculate these in case scaling didn't quite hit its targets extraWidth = desiredWidth - tmpImage.getWidth(); extraHeight = desiredHeight - tmpImage.getHeight(); int dx1 = extraWidth / 2; int dy1 = extraHeight / 2; int dx2 = desiredWidth - dx1; int dy2 = desiredWidth - dy1; // transparent background g2d.setColor(new Color(0, 0, 0, 0)); g2d.fillRect(0, 0, desiredWidth, desiredHeight); g2d.drawImage(tmpImage, dx1, dy1, dx2, dy2, null); return scaledImage; } }
From source file:com.sdk.connector.chart.FrequencyDomainRenderer.java
/** * Creates a new demo application.//from w w w.jav a 2 s. c om * * @param title the frame title. */ public FrequencyDomainRenderer(String title, JPanel panel, String side, String type) { this.side = side; this.type = type; serie.setKey(side); dataset.addSeries(serie); JFreeChart chart = ChartFactory.createXYAreaChart(title, java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("frequency.xlabel"), java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("frequency.ylabel2"), dataset, PlotOrientation.VERTICAL, true, true, false); // TextTitle t1 = new TextTitle( "Espectro de Frequncia Estimado (PSD)", new Font("SansSerif", Font.BOLD, 14) ); // //TextTitle t2 = new TextTitle( "valores atualizados a cada potncia de 2", new Font("SansSerif", Font.PLAIN, 11) ); // chart.addSubtitle(t1); chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); chart.getRenderingHints().put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); chart.getRenderingHints().put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); chart.getRenderingHints().put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); chart.getRenderingHints().put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); chart.getRenderingHints().put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); chart.getRenderingHints().put(RenderingHints.KEY_TEXT_LCD_CONTRAST, 100); //chart.addSubtitle(t2); plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.BLUE); plot.setRangeGridlinePaint(Color.CYAN); plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f)); plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f)); //plot.setRangePannable(true); plot.setForegroundAlpha(0.65f); //XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer = plot.getRenderer(); renderer.setSeriesOutlinePaint(0, Color.BLACK); if (side.startsWith( java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("side.left"))) { renderer.setSeriesPaint(0, Color.BLUE); } else { renderer.setSeriesPaint(0, Color.RED); } // renderer.setSeriesLinesVisible(0, true); // renderer.setSeriesShapesVisible(0, false); // renderer.setSeriesLinesVisible(1, true); // renderer.setSeriesShapesVisible(1, false); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.BLACK); plot.setRangeGridlinePaint(Color.BLACK); plot.setForegroundAlpha(0.5f); Color color1 = new Color(0, 0, 0, 24); Color color2 = new Color(255, 255, 255, 24); GradientPaint gp = new GradientPaint(0, 0, color1, 0, 0, color2); plot.setBackgroundPaint(gp); final ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setTickMarkPaint(Color.black); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); NumberAxis numDomainAxis = (NumberAxis) plot.getDomainAxis(); numDomainAxis.setAutoRangeIncludesZero(true); // // final NumberAxis rangeAxis = new LogarithmicAxis("Log(y)"); // // plot.setRangeAxis(rangeAxis); final ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setTickMarkPaint(Color.black); numRangeAxis = (NumberAxis) plot.getRangeAxis(); numRangeAxis.setAutoRangeIncludesZero(true); vlfTarget.setLabel("VLF"); vlfTarget.setLabelFont(new Font("SansSerif", Font.ITALIC, 9)); vlfTarget.setLabelAnchor(RectangleAnchor.CENTER); vlfTarget.setLabelTextAnchor(TextAnchor.CENTER); vlfTarget.setPaint(new Color(0, 100, 255, 128)); // plot.addRangeMarker(target, Layer.BACKGROUND); plot.addDomainMarker(vlfTarget, Layer.BACKGROUND); lfTarget.setLabel("LF"); lfTarget.setLabelFont(new Font("SansSerif", Font.ITALIC, 9)); lfTarget.setLabelAnchor(RectangleAnchor.CENTER); lfTarget.setLabelTextAnchor(TextAnchor.CENTER); lfTarget.setPaint(new Color(255, 255, 0, 128)); // plot.addRangeMarker(target, Layer.BACKGROUND); plot.addDomainMarker(lfTarget, Layer.BACKGROUND); hfTarget.setLabel("HF"); hfTarget.setLabelFont(new Font("SansSerif", Font.ITALIC, 9)); hfTarget.setLabelAnchor(RectangleAnchor.CENTER); hfTarget.setLabelTextAnchor(TextAnchor.CENTER); hfTarget.setPaint(new Color(255, 0, 255, 128)); // plot.addRangeMarker(target, Layer.BACKGROUND); plot.addDomainMarker(hfTarget, Layer.BACKGROUND); plot.setNoDataMessage( java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("message.wait")); chartPanel = new ChartPanel(chart); panel.setLayout(new GridLayout(0, 1)); panel.add(chartPanel); panel.repaint(); panel.revalidate(); }
From source file:com.piketec.jenkins.plugins.tpt.publisher.PieChart.java
/** * Render the pie chart with the given height * //w w w . j a va 2 s. c o m * @param height * The height of the resulting image * @return The pie chart rendered as an image */ public BufferedImage render(int height) { BufferedImage image = new BufferedImage(totalWidth, totalHeight, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.scale(zoom, zoom); // fill background to white g2.setColor(Color.WHITE); g2.fill(new Rectangle(totalWidth, totalHeight)); // prepare render hints g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2.setStroke(new BasicStroke(4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); // draw shadow image g2.drawImage(pieShadow.getImage(), 0, 0, pieShadow.getImageObserver()); double start = 0; List<Arc2D> pies = new ArrayList<>(); // pie segmente erzeugen und fuellen if (total == 0) { g2.setColor(BRIGHT_GRAY); g2.fillOval(centerX - radius, centerY - radius, 2 * radius, 2 * radius); g2.setColor(Color.WHITE); g2.drawOval(centerX - radius, centerY - radius, 2 * radius, 2 * radius); } else { for (Segment s : segments) { double portionDegrees = s.getPortion() / total; Arc2D pie = paintPieSegment(g2, start, portionDegrees, s.getColor()); if (withSubSegments) { double smallRadius = radius * s.getSubSegmentRatio(); paintPieSegment(g2, start, portionDegrees, smallRadius, s.getColor().darker()); } start += portionDegrees; // portion degree jetzt noch als String (z.B. "17.3%" oder "20%" zusammenbauen) String p = String.format(Locale.ENGLISH, "%.1f", Math.rint(portionDegrees * 1000) / 10.0); p = removeSuffix(p, ".0"); // evtl. ".0" bei z.B. "25.0" abschneiden (-> "25") s.setPercent(p + "%"); pies.add(pie); } // weissen Rahmen um die pie segmente zeichen g2.setColor(Color.WHITE); for (Arc2D pie : pies) { g2.draw(pie); } } // Legende zeichnen renderLegend(g2); // "xx%" Label direkt auf die pie segmente zeichen g2.setColor(Color.WHITE); float fontSize = 32f; g2.setFont(NORMALFONT.deriveFont(fontSize).deriveFont(Font.BOLD)); start = 0; for (Segment s : segments) { if (s.getPortion() < 1E-6) { continue; // ignore segments with portions that are extremely small } double portionDegrees = s.getPortion() / total; double angle = start + portionDegrees / 2; // genau in der Mitte des Segments double xOffsetForCenteredTxt = 8 * s.getPercent().length(); // assume roughly 8px per char int x = (int) (centerX + 0.6 * radius * Math.sin(2 * Math.PI * angle) - xOffsetForCenteredTxt); int y = (int) (centerY - 0.6 * radius * Math.cos(2 * Math.PI * angle) + fontSize / 2); g2.drawString(s.getPercent(), x, y); start += portionDegrees; } return image; }