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:org.tsho.dmc2.core.chart.CowebRenderer.java
private void animateCowebPlot(Graphics2D g2, Rectangle2D dataArea) { Graphics2D g2bisec = (Graphics2D) g2.create(); g2bisec.setColor(Color.blue); Stroke stroke = new BasicStroke(3f); Stroke origStroke = g2.getStroke(); Color color = Color.BLACK; g2blink = (Graphics2D) g2.create(); g2blink.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); g2blink.setXORMode(color);//from w ww . j a v a2 s. c o m g2blink.setStroke(stroke); if (plot.isAlpha()) { g2bisec.setComposite(AlphaComposite.SrcOver); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, plot.getForegroundAlpha())); } /* transients */ stepper.setInitialValue(initialValue); stepper.initialize(); state = STATE_TRANSIENTS; for (int index = 0; index < transients; index++) { stepper.step(); if (stopped) { state = STATE_STOPPED; return; } } state = STATE_RUNNING; Range xDataRange = plot.getDataRange(domainAxis); int transX, transY, transX1, transY1; transX = (int) this.domainAxis.valueToJava2D(xDataRange.getLowerBound(), dataArea, RectangleEdge.BOTTOM); transY = (int) this.rangeAxis.valueToJava2D(xDataRange.getLowerBound(), dataArea, RectangleEdge.LEFT); transX1 = (int) this.domainAxis.valueToJava2D(xDataRange.getUpperBound(), dataArea, RectangleEdge.BOTTOM); transY1 = (int) this.rangeAxis.valueToJava2D(xDataRange.getUpperBound(), dataArea, RectangleEdge.LEFT); g2bisec.drawLine(transX, transY, transX1, transY1); //renderer.reset(); recurseCoweb(g2, dataArea); }
From source file:RadialGradientApp.java
@Override protected void paintComponent(Graphics g) { setFont(getFont().deriveFont(70.f).deriveFont(Font.BOLD)); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Retains the previous state Paint oldPaint = g2.getPaint(); // Fills the circle with solid blue color g2.setColor(new Color(0x0153CC)); g2.fillOval(0, 0, getWidth() - 1, getHeight() - 1); // Adds shadows at the top Paint p;/*from w w w. j a v a 2 s .c om*/ p = new GradientPaint(0, 0, new Color(0.0f, 0.0f, 0.0f, 0.4f), 0, getHeight(), new Color(0.0f, 0.0f, 0.0f, 0.0f)); g2.setPaint(p); g2.fillOval(0, 0, getWidth() - 1, getHeight() - 1); // Adds highlights at the bottom p = new GradientPaint(0, 0, new Color(1.0f, 1.0f, 1.0f, 0.0f), 0, getHeight(), new Color(1.0f, 1.0f, 1.0f, 0.4f)); g2.setPaint(p); g2.fillOval(0, 0, getWidth() - 1, getHeight() - 1); // Creates dark edges for 3D effect p = new RadialGradientPaint(new Point2D.Double(getWidth() / 2.0, getHeight() / 2.0), getWidth() / 2.0f, new float[] { 0.0f, 1.0f }, new Color[] { new Color(6, 76, 160, 127), new Color(0.0f, 0.0f, 0.0f, 0.8f) }); g2.setPaint(p); g2.fillOval(0, 0, getWidth() - 1, getHeight() - 1); // Adds oval inner highlight at the bottom p = new RadialGradientPaint(new Point2D.Double(getWidth() / 2.0, getHeight() * 1.5), getWidth() / 2.3f, new Point2D.Double(getWidth() / 2.0, getHeight() * 1.75 + 6), new float[] { 0.0f, 0.8f }, new Color[] { new Color(64, 142, 203, 255), new Color(64, 142, 203, 0) }, RadialGradientPaint.CycleMethod.NO_CYCLE, RadialGradientPaint.ColorSpaceType.SRGB, AffineTransform.getScaleInstance(1.0, 0.5)); g2.setPaint(p); g2.fillOval(0, 0, getWidth() - 1, getHeight() - 1); // Adds oval specular highlight at the top left p = new RadialGradientPaint(new Point2D.Double(getWidth() / 2.0, getHeight() / 2.0), getWidth() / 1.4f, new Point2D.Double(45.0, 25.0), new float[] { 0.0f, 0.5f }, new Color[] { new Color(1.0f, 1.0f, 1.0f, 0.4f), new Color(1.0f, 1.0f, 1.0f, 0.0f) }, RadialGradientPaint.CycleMethod.NO_CYCLE); g2.setPaint(p); g2.fillOval(0, 0, getWidth() - 1, getHeight() - 1); // Restores the previous state g2.setPaint(oldPaint); // Draws the logo // FontRenderContext context = g2.getFontRenderContext(); // TextLayout layout = new TextLayout("R", getFont(), context); // Rectangle2D bounds = layout.getBounds(); // // float x = (getWidth() - (float) bounds.getWidth()) / 2.0f; // float y = (getHeight() + (float) bounds.getHeight()) / 2.0f; // // g2.setColor(Color.WHITE); // layout.draw(g2, x, y); // // Area shadow = new Area(layout.getOutline(null)); // shadow.subtract(new Area(layout.getOutline(AffineTransform.getTranslateInstance(1.0, 1.0)))); // g2.setColor(Color.BLACK); // g2.translate(x, y); // g2.fill(shadow); // g2.translate(-x, -y); }
From source file:org.apache.pdfbox.pdmodel.font.PDSimpleFont.java
/** * {@inheritDoc}//from w w w . j a v a 2 s . c om */ public void drawString(String string, int[] codePoints, Graphics g, float fontSize, AffineTransform at, float x, float y) throws IOException { Font awtFont = getawtFont(); FontRenderContext frc = new FontRenderContext(new AffineTransform(), true, true); GlyphVector glyphs = null; boolean useCodepoints = codePoints != null && isType0Font(); PDFont descendantFont = useCodepoints ? ((PDType0Font) this).getDescendantFont() : null; // symbolic fonts may trigger the same fontmanager.so/dll error as described below if (useCodepoints && !descendantFont.getFontDescriptor().isSymbolic()) { PDCIDFontType2Font cid2Font = null; if (descendantFont instanceof PDCIDFontType2Font) { cid2Font = (PDCIDFontType2Font) descendantFont; } if ((cid2Font != null && cid2Font.hasCIDToGIDMap()) || isFontSubstituted) { // we still have to use the string if a CIDToGIDMap is used glyphs = awtFont.createGlyphVector(frc, string); } else { glyphs = awtFont.createGlyphVector(frc, codePoints); } } else { // mdavis - fix fontmanager.so/dll on sun.font.FileFont.getGlyphImage // for font with bad cmaps? // Type1 fonts are not affected as they don't have cmaps if (!isType1Font() && awtFont.canDisplayUpTo(string) != -1) { LOG.warn("Changing font on <" + string + "> from <" + awtFont.getName() + "> to the default font"); awtFont = Font.decode(null).deriveFont(1f); } glyphs = awtFont.createGlyphVector(frc, string); } Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); writeFont(g2d, at, x, y, glyphs); }
From source file:ClipImage.java
public Graphics2D createDemoGraphics2D(Graphics g) { Graphics2D g2 = null;// w w w .j av a 2 s . c om if (offImg == null || offImg.getWidth() != w || offImg.getHeight() != h) { offImg = (BufferedImage) createImage(w, h); newBufferedImage = true; } if (offImg != null) { g2 = offImg.createGraphics(); g2.setBackground(getBackground()); } // .. set attributes .. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); // .. clear canvas .. g2.clearRect(0, 0, w, h); return g2; }
From source file:org.locationtech.udig.style.advanced.points.PointStyleManager.java
private TableViewer createStylesTableViewer(Composite parent) { final StyleFilter filter = new StyleFilter(); final Text searchText = new Text(parent, SWT.BORDER | SWT.SEARCH); searchText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); searchText.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent ke) { filter.setSearchText(searchText.getText()); stylesViewer.refresh();/* w w w. j ava2s . c o m*/ } }); stylesViewer = new TableViewer(parent, SWT.SINGLE | SWT.BORDER); Table table = stylesViewer.getTable(); GridData tableGD = new GridData(SWT.FILL, SWT.FILL, true, true); tableGD.heightHint = 200; table.setLayoutData(tableGD); stylesViewer.addFilter(filter); stylesViewer.setContentProvider(new IStructuredContentProvider() { public Object[] getElements(Object inputElement) { if (inputElement instanceof List<?>) { List<?> styles = (List<?>) inputElement; StyleWrapper[] array = (StyleWrapper[]) styles.toArray(new StyleWrapper[styles.size()]); return array; } return null; } public void dispose() { } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } }); stylesViewer.setLabelProvider(new LabelProvider() { public Image getImage(Object element) { if (element instanceof StyleWrapper) { StyleWrapper styleWrapper = (StyleWrapper) element; List<FeatureTypeStyleWrapper> featureTypeStyles = styleWrapper .getFeatureTypeStylesWrapperList(); int iconSize = 48; BufferedImage image = new BufferedImage(iconSize, iconSize, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = image.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); for (FeatureTypeStyleWrapper featureTypeStyle : featureTypeStyles) { List<RuleWrapper> rulesWrapperList = featureTypeStyle.getRulesWrapperList(); BufferedImage tmpImage = WrapperUtilities.pointRulesWrapperToImage(rulesWrapperList, iconSize, iconSize); g2d.drawImage(tmpImage, 0, 0, null); } g2d.dispose(); Image convertToSWTImage = AWTSWTImageUtils.convertToSWTImage(image); return convertToSWTImage; } return null; } public String getText(Object element) { if (element instanceof StyleWrapper) { StyleWrapper styleWrapper = (StyleWrapper) element; String styleName = styleWrapper.getName(); if (styleName == null || styleName.length() == 0) { styleName = Utilities.DEFAULT_STYLENAME; styleName = WrapperUtilities.checkSameNameStyle(getStyles(), styleName); styleWrapper.setName(styleName); } return styleName; } return ""; //$NON-NLS-1$ } }); stylesViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { ISelection selection = event.getSelection(); if (!(selection instanceof IStructuredSelection)) { return; } IStructuredSelection sel = (IStructuredSelection) selection; if (sel.isEmpty()) { return; } Object selectedItem = sel.getFirstElement(); if (selectedItem == null) { // unselected, show empty panel return; } if (selectedItem instanceof StyleWrapper) { currentSelectedStyleWrapper = (StyleWrapper) selectedItem; } } }); return stylesViewer; }
From source file:doge.photo.DogePhotoManipulator.java
private void setGraphicsHints(Graphics2D graphics) { graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP); }
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 www. j a v a 2s.c om*/ 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.epiq.bitshark.ui.FrequencyDomainMouseMarker.java
/** * Draws the marker// w ww .j a va 2 s . c o m * @param g2 * @param rect */ public void draw(Graphics2D g2, Rectangle2D rect) { g2.setColor(outlineColor); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.fillOval((int) Math.round(rect.getX()), (int) Math.round(rect.getY()), (int) Math.round(rect.getWidth()), (int) Math.round(rect.getHeight())); }
From source file:no.met.jtimeseries.chart.XYWindArrowRenderer.java
private void drawCircle(Graphics2D g) { g.setStroke(new BasicStroke(1)); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.drawOval(-arrowHeight / 2, -arrowHeight / 2, arrowHeight, arrowHeight); }
From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java
private void drawTitle(Graphics2D g2) { final Object oldValueAntiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING); final Color oldColor = g2.getColor(); final Font oldFont = g2.getFont(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); final Font titleFont = oldFont.deriveFont(oldFont.getStyle() | Font.BOLD, (float) oldFont.getSize() * 1.5f); final int margin = 5; final FontMetrics titleFontMetrics = g2.getFontMetrics(titleFont); final FontMetrics oldFontMetrics = g2.getFontMetrics(oldFont); final java.text.NumberFormat numberFormat = java.text.NumberFormat.getInstance(); numberFormat.setMaximumFractionDigits(2); numberFormat.setMinimumFractionDigits(2); final double totalInvestValue = this.investmentFlowChartJDialog.getTotalInvestValue(); final double totalROIValue = this.investmentFlowChartJDialog.getTotalROIValue(); final DecimalPlace decimalPlace = JStock.instance().getJStockOptions().getDecimalPlace(); final String invest = org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace, totalInvestValue);// w ww .j a v a 2s. c o m final String roi = org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace, totalROIValue); final double gain = totalROIValue - totalInvestValue; final double percentage = totalInvestValue > 0.0 ? gain / totalInvestValue * 100.0 : 0.0; final String gain_str = org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace, gain); final String percentage_str = numberFormat.format(percentage); final String SELECTED = this.investmentFlowChartJDialog.getCurrentSelectedString(); final String INVEST = GUIBundle.getString("InvestmentFlowLayerUI_Invest"); final String RETURN = GUIBundle.getString("InvestmentFlowLayerUI_Return"); final String GAIN = (SELECTED.length() > 0 ? SELECTED + " " : "") + GUIBundle.getString("InvestmentFlowLayerUI_Gain"); final String LOSS = (SELECTED.length() > 0 ? SELECTED + " " : "") + GUIBundle.getString("InvestmentFlowLayerUI_Loss"); final int string_width = oldFontMetrics.stringWidth(INVEST + ": ") + titleFontMetrics.stringWidth(invest + " ") + oldFontMetrics.stringWidth(RETURN + ": ") + titleFontMetrics.stringWidth(roi + " ") + oldFontMetrics.stringWidth((gain >= 0 ? GAIN : LOSS) + ": ") + titleFontMetrics.stringWidth(gain_str + " (" + percentage_str + "%)"); int x = (int) (this.investmentFlowChartJDialog.getChartPanel().getWidth() - string_width) >> 1; final int y = margin + titleFontMetrics.getAscent(); g2.setFont(oldFont); g2.drawString(INVEST + ": ", x, y); x += oldFontMetrics.stringWidth(INVEST + ": "); g2.setFont(titleFont); g2.drawString(invest + " ", x, y); x += titleFontMetrics.stringWidth(invest + " "); g2.setFont(oldFont); g2.drawString(RETURN + ": ", x, y); x += oldFontMetrics.stringWidth(RETURN + ": "); g2.setFont(titleFont); g2.drawString(roi + " ", x, y); x += titleFontMetrics.stringWidth(roi + " "); g2.setFont(oldFont); if (gain >= 0) { if (gain > 0) { if (org.yccheok.jstock.engine.Utils.isFallBelowAndRiseAboveColorReverse()) { g2.setColor(JStock.instance().getJStockOptions().getLowerNumericalValueForegroundColor()); } else { g2.setColor(JStock.instance().getJStockOptions().getHigherNumericalValueForegroundColor()); } } g2.drawString(GAIN + ": ", x, y); x += oldFontMetrics.stringWidth(GAIN + ": "); } else { if (org.yccheok.jstock.engine.Utils.isFallBelowAndRiseAboveColorReverse()) { g2.setColor(JStock.instance().getJStockOptions().getHigherNumericalValueForegroundColor()); } else { g2.setColor(JStock.instance().getJStockOptions().getLowerNumericalValueForegroundColor()); } g2.drawString(LOSS + ": ", x, y); x += oldFontMetrics.stringWidth(LOSS + ": "); } g2.setFont(titleFont); g2.drawString(gain_str + " (" + percentage_str + "%)", x, y); g2.setColor(oldColor); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldValueAntiAlias); g2.setFont(oldFont); }