List of usage examples for java.awt RenderingHints VALUE_ANTIALIAS_ON
Object VALUE_ANTIALIAS_ON
To view the source code for java.awt RenderingHints VALUE_ANTIALIAS_ON.
Click Source Link
From source file:com.igormaznitsa.jhexed.renders.svg.SVGImage.java
private static void processAntialias(final boolean flag, final Graphics2D g) { if (flag) {// w ww . j av a 2 s . c o m g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); } else { g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED); } }
From source file:uk.ac.babraham.BamQC.Graphs.ScatterGraph.java
@Override protected void paintComponent(Graphics g) { g.setColor(Color.WHITE);/*w w w . j a va2s . com*/ g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(Color.BLACK); if (g instanceof Graphics2D) { ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } double yStart, xStart; if (minY % yInterval == 0) { yStart = minY; } else { yStart = yInterval * (((int) minY / yInterval) + 1); } if (minX % xInterval == 0) { xStart = minX; } else { xStart = xInterval * (((int) minX / xInterval) + 1); } int xOffset = 0; // Draw the yLabel on the left of the yAxis int yLabelRightShift = 12; if (yLabel == null || yLabel.isEmpty()) { yLabelRightShift = 0; } else { if (g instanceof Graphics2D) { Graphics2D g2 = (Graphics2D) g; AffineTransform orig = g2.getTransform(); g2.rotate(-Math.PI / 2); g2.setColor(Color.BLACK); g2.drawString(yLabel, -getY(-yInterval) / 2 - (g.getFontMetrics().stringWidth(yLabel) / 2), yLabelRightShift); g2.setTransform(orig); } } // Draw the y axis labels int lastYLabelEnd = Integer.MAX_VALUE; for (double i = yStart; i <= maxY; i += yInterval) { String label = "" + i; label = label.replaceAll(".0$", ""); // Don't leave trailing .0s where we don't need them. // Calculate the new xOffset depending on the widest ylabel. int width = g.getFontMetrics().stringWidth(label); if (width > xOffset) { xOffset = width; } // place the y axis labels so that they don't overlap when the plot is resized. int baseNumberHeight = g.getFontMetrics().getHeight(); int baseNumberPosition = getY(i) + (baseNumberHeight / 2); if (baseNumberPosition + baseNumberHeight < lastYLabelEnd) { // Draw the y axis labels g.drawString(label, yLabelRightShift + 6, baseNumberPosition); lastYLabelEnd = baseNumberPosition + 2; } } // Give the x axis a bit of breathing space xOffset = xOffset + yLabelRightShift + 8; // Now draw horizontal lines across from the y axis g.setColor(new Color(180, 180, 180)); for (double i = yStart; i <= maxY; i += yInterval) { g.drawLine(xOffset, getY(i), getWidth() - 10, getY(i)); } g.setColor(Color.BLACK); // Draw the graph title int titleWidth = g.getFontMetrics().stringWidth(graphTitle); g.drawString(graphTitle, (xOffset + ((getWidth() - (xOffset + 10)) / 2)) - (titleWidth / 2), 30); // Draw the xLabel under the xAxis g.drawString(xLabel, (getWidth() / 2) - (g.getFontMetrics().stringWidth(xLabel) / 2), getHeight() - 5); // Now draw the data points double baseWidth = (getWidth() - (xOffset + 10)) / (maxX - minX); // System.out.println("Base Width is "+baseWidth); // Let's find the longest label, and then work out how often we can draw labels int lastXLabelEnd = 0; // Draw the x axis labels for (double i = xStart; i <= maxX; i += xInterval) { g.setColor(Color.BLACK); String baseNumber = "" + i; baseNumber = baseNumber.replaceAll(".0$", ""); // Don't leave trailing .0s where we don't need them. // Calculate the new xOffset depending on the widest ylabel. int baseNumberWidth = g.getFontMetrics().stringWidth(baseNumber); int baseNumberPosition = (int) (xOffset + (baseWidth * i) - (baseNumberWidth / 2)); if (baseNumberPosition > lastXLabelEnd) { g.drawString(baseNumber, baseNumberPosition, getHeight() - 25); lastXLabelEnd = baseNumberPosition + baseNumberWidth + 5; } // Now draw vertical lines across from the y axis g.setColor(new Color(180, 180, 180)); g.drawLine((int) (xOffset + (baseWidth * i)), getHeight() - 40, (int) (xOffset + (baseWidth * i)), 40); g.setColor(Color.BLACK); } // Now draw the axes g.drawLine(xOffset, getHeight() - 40, getWidth() - 10, getHeight() - 40); g.drawLine(xOffset, getHeight() - 40, xOffset, 40); // Initialise the arrays containing the tooltips rectangles = new ArrayList<Rectangle>(); tips = new ArrayList<String>(); g.setColor(Color.BLUE); // Draw the data points double ovalSize = 5; // We distinguish two inputs since the x label does not start from 0. // used for computing the actual line points as if they were starting from 0. double[] inputVar = new double[data.length]; double[] responseVar = new double[data.length]; for (int d = 0; d < data.length; d++) { double x = getX(xCategories[d], xOffset) - ovalSize / 2; double y = getY(data[d]) - ovalSize / 2; g.fillOval((int) x, (int) y, (int) (ovalSize), (int) (ovalSize)); g.drawString(toolTipLabels[d], (int) x + 2, (int) y + 16); inputVar[d] = Double.valueOf(xCategories[d]); responseVar[d] = data[d]; // Tool tips Rectangle r = new Rectangle((int) x, (int) y, (int) (ovalSize), (int) (ovalSize)); rectangles.add(r); tips.add(toolTipLabels[d]); } g.setColor(Color.BLACK); // Draw the intercept // WARNING: Is drawing a least squares regression line asserting that "the distribution follows a power law" correct? // This is our case if we plot log-log.. // It seems not in this paper (Appendix A) http://arxiv.org/pdf/0706.1062v2.pdf if (data.length > 1) { LinearRegression linReg = new LinearRegression(inputVar, responseVar); double intercept = linReg.intercept(); double slope = linReg.slope(); double rSquare = linReg.R2(); // Let's now calculate the two points (x1, y1) and (xn, yn) // (x1, y1). We need to skip the areas where x1<minY and y1>maxY double x1 = minX; double y1 = slope * minX + intercept; if (y1 < minY) { x1 = (minY - intercept) / slope; y1 = minY; } else if (y1 > maxY) { x1 = (maxY - intercept) / slope; y1 = maxY; } // (xn, yn). maxX which essentially is inputVar[inputVar.length-1] double xn = maxX; double yn = slope * maxX + intercept; if (g instanceof Graphics2D) { ((Graphics2D) g).setStroke(new BasicStroke(1.5f)); } g.setColor(Color.RED); g.drawLine(getX(x1, xOffset), getY(y1), getX(xn, xOffset), getY(yn)); g.setColor(Color.BLACK); if (g instanceof Graphics2D) { ((Graphics2D) g).setStroke(new BasicStroke(1)); } // Draw the legend for the intercept String legendString = "y = " + Precision.round(slope, 3) + "x"; if (intercept < 0) legendString += " - " + Precision.round(-intercept, 3); else legendString += " + " + Precision.round(intercept, 3); int width = g.getFontMetrics().stringWidth(legendString); // First draw a box to put the legend in g.setColor(Color.WHITE); g.fillRect(xOffset + 10, 45, width + 8, 35); g.setColor(Color.LIGHT_GRAY); g.drawRect(xOffset + 10, 45, width + 8, 35); // Now draw the legend label g.setColor(Color.RED); g.drawString(legendString, xOffset + 13, 60); g.drawString("R^2 = " + Precision.round(rSquare, 3), xOffset + 13, 76); g.setColor(Color.BLACK); } }
From source file:com.ctsim.simemua_instructor.ACarControlPanelFrame.java
private void initGraphics() { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); try {/*ww w .j a v a 2 s. c om*/ x = (int) viewPanel.getMousePosition().getX(); y = (int) viewPanel.getMousePosition().getY(); } catch (Exception ex) { x = 0; y = 0; } g2.drawImage(aCarControlPanelImg, null, this); //drawDevices(); drawSwitchRotary(); g2.drawString("(" + x + ", " + y + ")", 10, 10); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java
protected void paintComponent(Graphics g) { // prepare graphic object Graphics2D g2d = (Graphics2D) g.create(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // set clipping area if (is_printing) { g2d.translate(-draw_area.x, -draw_area.y); g2d.setClip(draw_area);//ww w. j a v a 2 s .com } //paint canvas background if (!is_printing) { g2d.setColor(getBackground()); g2d.fillRect(0, 0, getWidth(), getHeight()); } // paint white background on drawing area g2d.setColor(Color.white); g2d.fillRect(draw_area.x, draw_area.y, draw_area.width, draw_area.height); if (!is_printing) { g2d.setColor(Color.black); g2d.draw(draw_area); } // paint paintChart(g2d); paintAnnotations(g2d); // dispose graphic object g2d.dispose(); if (!is_printing) { if (first_time) { if (first_time_init_pos) placeStructures(true); else theDocument.fireDocumentInit(); first_time = false; } else revalidate(); } }
From source file:org.kalypso.contribs.eclipse.jobs.BufferPaintJob.java
/** * Configures the graphics-context before actual painting is started (i.e. {@link IPaintable#paint(Graphics2D, IProgressMonitor)} is called).<br> * Default behaviour is to set activate anti-aliasing (normal and text).<br> * Overwrite to change./*from www.j a v a2 s.com*/ */ private void configureGraphics(final Graphics2D gr) { gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); gr.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); }
From source file:domainhealth.frontend.graphics.JFreeChartGraphImpl.java
/** * Gets handle on the 2D graphics image object for the graph ready to * change (eg. add text to).//w w w . ja v a 2 s .c om * * @param graphImage The current graph image * @return The 2D object handle */ private Graphics2D get2DGraphics(BufferedImage graphImage) { Graphics2D graphics2D = (Graphics2D) graphImage.getGraphics(); graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics2D.setColor(Color.BLACK); return graphics2D; }
From source file:org.colombbus.tangara.CommandSelection.java
/** * Initializes the icons//from w w w . j a v a 2 s .com * */ private void initializeIcons() { BufferedImage imageSelected = new BufferedImage(iconSize, iconSize, BufferedImage.TYPE_INT_RGB); Graphics2D g = (Graphics2D) imageSelected.getGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(selectedBackgroundColor); g.fillRect(0, 0, iconSize, iconSize); g.setColor(Color.green); g.fillOval(0, 0, iconSize - 1, iconSize - 1); iconSelected = new ImageIcon(imageSelected); BufferedImage imageNotSelected = new BufferedImage(iconSize, iconSize, BufferedImage.TYPE_INT_RGB); g = (Graphics2D) imageNotSelected.getGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(Color.white); g.fillRect(0, 0, iconSize, iconSize); g.setColor(Color.lightGray); g.fillOval(0, 0, iconSize - 1, iconSize - 1); iconNotSelected = new ImageIcon(imageNotSelected); }
From source file:figs.treeVisualization.gui.TimeAxisTree2DPanel.java
/** * Paint this Component using the Tree2DPainter with TimeBars * * @param g the graphics device/*ww w .ja v a 2 s. co m*/ */ @Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g.create(); /** * Enable antialiased graphics. */ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); Dimension currentSize = this.getSize(); /** * Check to see if this component has changed size or if this * is our first time drawing. */ if (this.fDimension == null || !this.fDimension.equals(currentSize) || this.fTreeArea == null || this.fLeftTreeArea == null || this.fEstMaxDateWidth == null) { this.fDimension = currentSize; this.fTreeArea = new Rectangle2D.Double(0, 0, currentSize.getWidth(), currentSize.getHeight()); /** Adjust the width ratio using the maximum date width. */ this.refreshLeafNodes(); this.estimateMaximumDateWidth(g2); if ((this.fEstMaxDateWidth * 2) > (this.fTreeArea.getWidth() * this.fTreeWidthRatio) - this.fTreeArea.getWidth()) { this.fTreeWidthRatio = (this.fTreeArea.getWidth() - (this.fEstMaxDateWidth * 2)) / this.fTreeArea.getWidth(); } /** Make left tree area for tree. */ this.fLeftTreeArea = new Rectangle2D.Double(0, 0, this.fTreeArea.getWidth() * this.fTreeWidthRatio, this.fTreeArea.getHeight()); /** Now, clear the right tree area so that it will be recalculated. */ this.fRightTreeArea = null; } /** Paint the tree. */ this.fTreePainter.drawTree(g2, this.fLeftTreeArea); /** * Check to see if we have calculated the date data. * The order of this is very important. We need to have * called the painter before we can get the coordinates. */ if (this.fLeafNodes.isEmpty() || this.fLeafDates.isEmpty()) /** Just calculate the Leaf data. */ this.refreshLeafNodes(); /** * Draw the date axis and lines to the leaf nodes. */ if (fTopLeafDate != null || fBottomLeafDate != null) { if (this.fRightTreeArea == null) { calculateDateMargins(); this.fRightTreeArea = new Rectangle2D.Double(this.fTreeArea.getWidth() * this.fTreeWidthRatio, this.fTopLeafPt.getY(), this.fTreeArea.getWidth(), this.fBottomLeafPt.getY()); } double cursor = this.fRightTreeArea.getX() + ((this.fRightTreeArea.getWidth() - this.fRightTreeArea.getX()) / 2); drawDateAxis(g2, cursor, this.fRightTreeArea); drawDatesToLeafs(g2, cursor, this.fRightTreeArea); } else { // g2."No TIME INFORMATION AVAILABLE // g2.drawString("NO TIME INFORMATION AVAILABLE", x, y); System.out.println("TimeBarPanel: No time information available!"); } if (this.fMousePressed && this.fMouseSelectionRect != null) { /** Color of line varies depending on image colors. */ g2.setXORMode(Color.white); g2.drawRect(this.fMouseSelectionRect.x, this.fMouseSelectionRect.y, this.fMouseSelectionRect.width - 1, this.fMouseSelectionRect.height - 1); } }
From source file:TextBouncer.java
protected void setAntialiasing(Graphics2D g2) { if (mAntialiasing == false) return;//from ww w . j a va 2 s. co m g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); }
From source file:org.tros.logo.swing.LogoPanel.java
@Override public void forward(final double distance) { Drawable command = new Drawable() { @Override/* w w w . j av a 2 s . co m*/ public void draw(Graphics2D g2, TurtleState turtleState) { double newx = turtleState.penX + (distance * Math.cos(turtleState.angle)); double newy = turtleState.penY + (distance * Math.sin(turtleState.angle)); if (!turtleState.penup) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.draw(new Line2D.Double(turtleState.penX, turtleState.penY, newx, newy)); } turtleState.penX = newx; turtleState.penY = newy; } @Override public void addListener(DrawListener listener) { } @Override public void removeListener(DrawListener listener) { } @Override public Drawable cloneDrawable() { return this; } }; submitCommand(command); }