List of usage examples for java.awt RenderingHints KEY_ANTIALIASING
Key KEY_ANTIALIASING
To view the source code for java.awt RenderingHints KEY_ANTIALIASING.
Click Source Link
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.PlotInstanceLegendCreator.java
private static Paint createTransparentCheckeredPaint(Color color, int checkerSize) { int s = checkerSize; BufferedImage bufferedImage = new BufferedImage(2 * s, 2 * s, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = bufferedImage.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, // Anti-alias! RenderingHints.VALUE_ANTIALIAS_ON); Color c1 = DataStructureUtils.setColorAlpha(color, (int) (color.getAlpha() * .8)); Color c2 = DataStructureUtils.setColorAlpha(color, (int) (color.getAlpha() * .2)); g2.setStroke(new BasicStroke(0)); g2.setPaint(c2);/*from w w w .j a v a 2 s . c o m*/ g2.setColor(c2); g2.fillRect(0, 0, s, s); g2.fillRect(s, s, s, s); g2.setPaint(c1); g2.setColor(c1); g2.fillRect(0, s, s, s); g2.fillRect(s, 0, s, s); // paint with the texturing brush Rectangle2D rect = new Rectangle2D.Double(0, 0, 2 * s, 2 * s); return new TexturePaint(bufferedImage, rect); }
From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java
private void drawBusyBox(Graphics2D g2, JXLayer<? extends V> layer) { final Font oldFont = g2.getFont(); final Font font = oldFont; final FontMetrics fontMetrics = g2.getFontMetrics(font); // Not sure why. Draw GIF image on JXLayer, will cause endless setDirty // being triggered by system. //final Image image = ((ImageIcon)Icons.BUSY).getImage(); //final int imgWidth = Icons.BUSY.getIconWidth(); //final int imgHeight = Icons.BUSY.getIconHeight(); //final int imgMessageWidthMargin = 5; final int imgWidth = 0; final int imgHeight = 0; final int imgMessageWidthMargin = 0; final String message = MessagesBundle.getString("info_message_retrieving_latest_stock_price"); final int maxWidth = imgWidth + imgMessageWidthMargin + fontMetrics.stringWidth(message); final int maxHeight = Math.max(imgHeight, fontMetrics.getHeight()); final int padding = 5; final int width = maxWidth + (padding << 1); final int height = maxHeight + (padding << 1); final int x = (int) this.drawArea.getX() + (((int) this.drawArea.getWidth() - width) >> 1); final int y = (int) this.drawArea.getY() + (((int) this.drawArea.getHeight() - height) >> 1); final Object oldValueAntiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING); final Composite oldComposite = g2.getComposite(); final Color oldColor = g2.getColor(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(COLOR_BORDER);/* w w w. ja va2 s . c om*/ g2.drawRoundRect(x - 1, y - 1, width + 1, height + 1, 15, 15); g2.setColor(COLOR_BACKGROUND); g2.setComposite(Utils.makeComposite(0.75f)); g2.fillRoundRect(x, y, width, height, 15, 15); g2.setComposite(oldComposite); g2.setColor(oldColor); //g2.drawImage(image, x + padding, y + ((height - imgHeight) >> 1), layer.getView()); g2.setFont(font); g2.setColor(COLOR_BLUE); int yy = y + ((height - fontMetrics.getHeight()) >> 1) + fontMetrics.getAscent(); g2.setFont(font); g2.setColor(COLOR_BLUE); g2.drawString(message, x + padding + imgWidth + imgMessageWidthMargin, yy); g2.setColor(oldColor); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldValueAntiAlias); g2.setFont(oldFont); }
From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java
@Override protected void paintLayer(Graphics2D g2, JXLayer<? extends V> layer) { super.paintLayer(g2, layer); final ChartPanel chartPanel = ((ChartPanel) layer.getView()); final Rectangle2D _plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(); this.drawArea.setRect(_plotArea); if (false == this.investmentFlowChartJDialog.isFinishLookUpPrice()) { this.drawBusyBox(g2, layer); }//w w w . ja va 2 s. c o m if (this.investPoint != null) { final int RADIUS = 8; final Object oldValueAntiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING); final Color oldColor = g2.getColor(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(COLOR_RED); g2.fillOval((int) (this.investPoint.getX() - (RADIUS >> 1) + 0.5), (int) (this.investPoint.getY() - (RADIUS >> 1) + 0.5), RADIUS, RADIUS); g2.setColor(oldColor); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldValueAntiAlias); this.updateInvestInformationBox(g2); } if (this.ROIPoint != null) { final int RADIUS = 8; final Object oldValueAntiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING); final Color oldColor = g2.getColor(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(COLOR_BLUE); g2.fillOval((int) (this.ROIPoint.getX() - (RADIUS >> 1) + 0.5), (int) (this.ROIPoint.getY() - (RADIUS >> 1) + 0.5), RADIUS, RADIUS); g2.setColor(oldColor); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldValueAntiAlias); this.updateROIInformationBox(g2); } this.solveConflict(); if (this.investPoint != null) { this.drawInformationBox(g2, this.investmentFlowChartJDialog.getInvestActivities(this.investPointIndex), investRect, investParams, investValues, GUIBundle.getString("InvestmentFlowLayerUI_Total_Invest"), totalInvestValue, COLOR_RED_BACKGROUND, COLOR_RED_BORDER); } if (this.ROIPoint != null) { this.drawInformationBox(g2, this.investmentFlowChartJDialog.getROIActivities(this.ROIPointIndex), ROIRect, ROIParams, ROIValues, GUIBundle.getString("InvestmentFlowLayerUI_Total_Return"), totalROIValue, COLOR_BLUE_BACKGROUND, COLOR_BLUE_BORDER); } this.drawTitle(g2); }
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;/* w w w .jav 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:savant.view.swing.GraphPane.java
/** * Draw an informational message on top of this GraphPane. * * @param g2 the graphics to be rendered * @param message text of the message to be displayed *//*from w w w.jav a 2s .c om*/ private void drawMessage(Graphics2D g2, String message) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Font font = g2.getFont(); Font subFont = font; int h = getSize().height / 3; int w = getWidth(); if (w > 500) { font = font.deriveFont(Font.PLAIN, 36); subFont = subFont.deriveFont(Font.PLAIN, 18); } else if (w > 150) { font = font.deriveFont(Font.PLAIN, 24); subFont = subFont.deriveFont(Font.PLAIN, 12); } else { font = font.deriveFont(Font.PLAIN, 12); subFont = subFont.deriveFont(Font.PLAIN, 8); } int returnPos = message.indexOf('\n'); g2.setColor(ColourSettings.getColor(ColourKey.GRAPH_PANE_MESSAGE)); if (returnPos > 0) { drawMessageHelper(g2, message.substring(0, returnPos), font, w, h, -(subFont.getSize() / 2)); drawMessageHelper(g2, message.substring(returnPos + 1), subFont, w, h, font.getSize() - (subFont.getSize() / 2)); } else { drawMessageHelper(g2, message, font, w, h, 0); } }
From source file:net.geoprism.dashboard.DashboardMap.java
private BufferedImage getLegendTitleImage(DashboardLayer layer) { FontMetrics fm;// w ww.j a va2s . c o m int textWidth; int textHeight; int textBoxHorizontalPadding = 4; int textBoxVerticalPadding = 4; int borderWidth = 2; int paddedTitleHeight; int paddedTitleWidth; int titleLeftPadding = textBoxHorizontalPadding; BufferedImage newLegendTitleBase; Graphics2D newLegendTitleBaseGraphic = null; try { // Build the Font object Font titleFont = new Font(layer.getName(), Font.BOLD, 14); // Build variables for base legend graphic construction try { newLegendTitleBase = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); newLegendTitleBaseGraphic = newLegendTitleBase.createGraphics(); newLegendTitleBaseGraphic.setFont(titleFont); fm = newLegendTitleBaseGraphic.getFontMetrics(); textHeight = fm.getHeight(); textWidth = fm.stringWidth(layer.getName()); paddedTitleWidth = textWidth + (textBoxHorizontalPadding * 2) + (borderWidth * 2); paddedTitleHeight = textHeight + (textBoxVerticalPadding * 2) + (borderWidth * 2); } finally { // dispose of temporary graphics context if (newLegendTitleBaseGraphic != null) { newLegendTitleBaseGraphic.dispose(); } } titleLeftPadding = ((paddedTitleWidth / 2) - ((textWidth + (textBoxHorizontalPadding * 2) + (borderWidth * 2)) / 2)) + textBoxHorizontalPadding; newLegendTitleBase = new BufferedImage(paddedTitleWidth, paddedTitleHeight, BufferedImage.TYPE_INT_ARGB); newLegendTitleBaseGraphic = newLegendTitleBase.createGraphics(); newLegendTitleBaseGraphic.drawImage(newLegendTitleBase, 0, 0, null); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); newLegendTitleBaseGraphic.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); newLegendTitleBaseGraphic.setFont(titleFont); // draw title text fm = newLegendTitleBaseGraphic.getFontMetrics(); newLegendTitleBaseGraphic.setColor(Color.WHITE); newLegendTitleBaseGraphic.drawString(layer.getName(), titleLeftPadding, fm.getAscent() + textBoxVerticalPadding); newLegendTitleBaseGraphic.drawImage(newLegendTitleBase, 0, 0, null); } finally { if (newLegendTitleBaseGraphic != null) { newLegendTitleBaseGraphic.dispose(); } } return newLegendTitleBase; }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.graphics.internal.LogicalPageDrawable.java
protected boolean drawDrawable(final RenderableReplacedContentBox content, final Graphics2D g2, final DrawableWrapper d) { final double x = StrictGeomUtility.toExternalValue(content.getX()); final double y = StrictGeomUtility.toExternalValue(content.getY()); final double width = StrictGeomUtility.toExternalValue(content.getWidth()); final double height = StrictGeomUtility.toExternalValue(content.getHeight()); if ((width < 0 || height < 0) || (width == 0 && height == 0)) { return false; }/* ww w .j a v a 2s . com*/ final Graphics2D clone = (Graphics2D) g2.create(); final StyleSheet styleSheet = content.getStyleSheet(); final Object attribute = styleSheet.getStyleProperty(ElementStyleKeys.ANTI_ALIASING); if (attribute != null) { if (Boolean.TRUE.equals(attribute)) { clone.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } else if (Boolean.FALSE.equals(attribute)) { clone.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } } if (RenderUtility.isFontSmooth(styleSheet, metaData)) { clone.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } else { clone.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); } if (strictClipping == false) { final double extraPadding; final Object o = styleSheet.getStyleProperty(ElementStyleKeys.STROKE); if (o instanceof BasicStroke) { final BasicStroke stroke = (BasicStroke) o; extraPadding = stroke.getLineWidth() / 2.0; } else { extraPadding = 0.5; } final Rectangle2D.Double clipBounds = new Rectangle2D.Double(x - extraPadding, y - extraPadding, width + 2 * extraPadding, height + 2 * extraPadding); clone.clip(clipBounds); clone.translate(x, y); } else { final Rectangle2D.Double clipBounds = new Rectangle2D.Double(x, y, width + 1, height + 1); clone.clip(clipBounds); clone.translate(x, y); } configureGraphics(styleSheet, clone); configureStroke(styleSheet, clone); final Rectangle2D.Double bounds = new Rectangle2D.Double(0, 0, width, height); d.draw(clone, bounds); clone.dispose(); return true; }
From source file:savant.view.tracks.BAMTrackRenderer.java
@Override public void drawLegend(Graphics2D g2, DrawingMode mode) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int x = 6, y = 17; switch (mode) { case STANDARD: drawStrandLegends(g2, x, y);//from w ww. j av a2 s .c om break; case MISMATCH: case STANDARD_PAIRED: drawStrandLegends(g2, x, y); y += LEGEND_LINE_HEIGHT * 2; drawBaseLegendExtended(g2, x, y, ColourKey.A, ColourKey.C, ColourKey.G, ColourKey.T, ColourKey.SKIPPED); break; case SEQUENCE: drawBaseLegendExtended(g2, x, y, ColourKey.A, ColourKey.C, ColourKey.G, ColourKey.T, ColourKey.SKIPPED); break; case ARC_PAIRED: drawSimpleLegend(g2, 30, 15, ColourKey.CONCORDANT_LENGTH, ColourKey.DISCORDANT_LENGTH, ColourKey.ONE_READ_INVERTED, ColourKey.EVERTED_PAIR, ColourKey.UNMAPPED_MATE); break; case SNP: drawBaseLegendExtended(g2, x, y, ColourKey.A, ColourKey.C, ColourKey.G, ColourKey.T); break; case STRAND_SNP: drawBaseLegendExtended(g2, x, y, ColourKey.A, ColourKey.C, ColourKey.G, ColourKey.T); y += LEGEND_LINE_HEIGHT * 2; drawBaseLegend(g2, x, y, ColourKey.FORWARD_STRAND); x += 90; drawBaseLegend(g2, x, y, ColourKey.REVERSE_STRAND); break; default: break; } }
From source file:tufts.vue.RichTextBox.java
public void paintComponent(Graphics g) { if (TestDebug || DEBUG.TEXT) out("paintComponent @ " + getX() + "," + getY() + " parent=" + getParent()); final MapViewer viewer = (MapViewer) javax.swing.SwingUtilities.getAncestorOfClass(MapViewer.class, this); Graphics2D g2d = (Graphics2D) g; if (viewer != null) { g2d.setRenderingHint(java.awt.RenderingHints.KEY_ANTIALIASING, viewer.AA_ON); g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); }/*ww w . j a v a 2 s . co m*/ // turn on anti-aliasing -- the cursor repaint loop doesn't // set anti-aliasing, so text goes jiggy around cursor/in selection if we don't do this //// g.clipRect(0, 0,getWidth(), getAdjustedHeight()); super.paintComponent(g2d); //super.paintComponent(g); if (true) { // draw a border (we don't want to add one because that changes the preferred size at a bad time) // g.setColor(Color.gray); g.setClip(null); final int xpad = 1; final int ypad = 1; g.drawRect(-xpad, -ypad, (int) ((getWidth()) + xpad * 2 - 1), (int) ((getHeight()) + ypad * 2 - 1)); } }
From source file:com.moviejukebox.plugin.DefaultImagePlugin.java
/** * Draw an overlay on the image, such as a box cover specific for videosource, container, certification if wanted * * @param movie// w w w . j ava2 s . c o m * @param bi * @param offsetY * @param offsetX * @return */ private BufferedImage drawOverlay(Movie movie, BufferedImage bi, int offsetX, int offsetY) { String source; if (overlaySource.equalsIgnoreCase(VIDEOSOURCE)) { source = movie.getVideoSource(); } else if (overlaySource.equalsIgnoreCase(CERTIFICATION)) { source = movie.getCertification(); } else if (overlaySource.equalsIgnoreCase(CONTAINER)) { source = movie.getContainer(); } else { source = DEFAULT; } // Make sure the source is formatted correctly source = source.toLowerCase().trim(); // Check for a blank or an UNKNOWN source and correct it if (StringTools.isNotValidString(source)) { source = DEFAULT; } String overlayFilename = source + "_overlay_" + imageType + ".png"; try { BufferedImage biOverlay = GraphicTools.loadJPEGImage(getResourcesPath() + overlayFilename); BufferedImage returnBI = new BufferedImage(biOverlay.getWidth(), biOverlay.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2BI = returnBI.createGraphics(); g2BI.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2BI.drawImage(bi, offsetX, offsetY, offsetX + bi.getWidth(), offsetY + bi.getHeight(), 0, 0, bi.getWidth(), bi.getHeight(), null); g2BI.drawImage(biOverlay, 0, 0, null); g2BI.dispose(); return returnBI; } catch (FileNotFoundException ex) { LOG.warn(LOG_FAILED_TO_LOAD, overlayFilename); } catch (IOException ex) { LOG.warn("Failed drawing overlay to {}. Please check that {} is in the resources directory.", movie.getBaseName(), overlayFilename); } return bi; }