List of usage examples for java.awt Graphics2D setColor
public abstract void setColor(Color c);
From source file:piramide.interaction.reasoner.FuzzyReasonerWizardFacade.java
private BufferedImage createErrorMessagesImage(String text) { final Font font = TextTitle.DEFAULT_FONT; final Font bigBold = new Font(font.getName(), Font.BOLD, 24); final FontRenderContext frc = new FontRenderContext(null, true, false); final TextLayout layout = new TextLayout(text, bigBold, frc); final Rectangle2D bounds = layout.getBounds(); final int w = (int) Math.ceil(bounds.getWidth()); final int h = (int) Math.ceil(bounds.getHeight()); final BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); final Graphics2D g = image.createGraphics(); g.setColor(Color.WHITE); g.fillRect(0, 0, w, h);//from ww w. ja v a2 s .com g.setColor(Color.RED); g.setFont(bigBold); g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF); g.drawString(text, (float) -bounds.getX(), (float) -bounds.getY()); g.dispose(); return image; }
From source file:IconDemoApp.java
public void paintIcon(Component c, Graphics g, int x, int y) { Graphics2D g2d = (Graphics2D) g.create(); g2d.setColor(Color.WHITE); g2d.fillRect(x + 1, y + 1, width - 2, height - 2); g2d.setColor(Color.BLACK);/*w w w . ja v a 2 s. c o m*/ g2d.drawRect(x + 1, y + 1, width - 2, height - 2); g2d.setColor(Color.RED); g2d.setStroke(stroke); g2d.drawLine(x + 10, y + 10, x + width - 10, y + height - 10); g2d.drawLine(x + 10, y + height - 10, x + width - 10, y + 10); g2d.dispose(); }
From source file:Main.java
@Override public void paintComponent(Graphics gr) { Color c = gr.getColor();/*from ww w . j ava 2 s. c o m*/ setForeground(new Color(0, 0, 0, 0)); super.paintComponent(gr); setForeground(c); gr.setColor(c); Graphics2D g = (Graphics2D) gr; g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); double pw = this.getPreferredSize().width; double ph = this.getPreferredSize().height; double w = this.getSize().width; double h = this.getSize().height; g.setColor(this.getForeground()); AffineTransform stretch = AffineTransform.getScaleInstance(w / pw, h / ph); g.setTransform(stretch); g.drawString(getText(), 0, this.getFont().getSize()); }
From source file:main.MapKit.java
private BufferedImage convert(BufferedImage loadImg, Color newColor) { int w = loadImg.getWidth(); int h = loadImg.getHeight(); BufferedImage imgOut = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); BufferedImage imgColor = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g = imgColor.createGraphics(); g.setColor(newColor); g.fillRect(0, 0, w + 1, h + 1);//from ww w . j a va 2 s .com g.dispose(); Graphics2D graphics = imgOut.createGraphics(); graphics.drawImage(loadImg, 0, 0, null); graphics.setComposite(MultiplyComposite.Default); graphics.drawImage(imgColor, 0, 0, null); graphics.dispose(); return imgOut; }
From source file:JavaWorldPrintExample1.java
/** * Method: print//from w w w.ja v a 2 s . c o m * <p> * * This class is responsible for rendering a page using the provided * parameters. The result will be a grid where each cell will be half an * inch by half an inch. * * @param g * a value of type Graphics * @param pageFormat * a value of type PageFormat * @param page * a value of type int * @return a value of type int */ public int print(Graphics g, PageFormat pageFormat, int page) { int i; Graphics2D g2d; Line2D.Double line = new Line2D.Double(); //--- Validate the page number, we only print the first page if (page == 0) { //--- Create a graphic2D object a set the default parameters g2d = (Graphics2D) g; g2d.setColor(Color.black); //--- Translate the origin to be (0,0) g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); //--- Print the vertical lines for (i = 0; i < pageFormat.getWidth(); i += INCH / 2) { line.setLine(i, 0, i, pageFormat.getHeight()); g2d.draw(line); } //--- Print the horizontal lines for (i = 0; i < pageFormat.getHeight(); i += INCH / 2) { line.setLine(0, i, pageFormat.getWidth(), i); g2d.draw(line); } return (PAGE_EXISTS); } else return (NO_SUCH_PAGE); }
From source file:juicebox.track.EigenvectorTrack.java
private void drawRotatedString(Graphics2D g2, String string, float x, float y) { AffineTransform orig = g2.getTransform(); g2.rotate(0);/* ww w .j a v a2 s .c o m*/ g2.setColor(Color.BLUE); g2.translate(x, 0); g2.scale(-1, 1); g2.translate(-x, 0); g2.drawString(string, x, y); g2.setTransform(orig); }
From source file:adams.gui.visualization.stats.paintlet.Exponential.java
/** * The paint routine of the paintlet.// w w w . j a va 2s . c om * * @param g the graphics context to use for painting * @param moment what {@link PaintMoment} is currently being painted */ @Override protected void doPerformPaint(Graphics g, PaintMoment moment) { if ((m_Data != null) && (m_Sorted != null)) { GUIHelper.configureAntiAliasing(g, m_AntiAliasingEnabled); for (int i = 0; i < m_Sorted.length; i++) { Graphics2D g2d = (Graphics2D) g; //If data points are to be filled if (m_Fill) { g2d.setColor(m_FillColor); g2d.setStroke(new BasicStroke(0)); g2d.fillOval(m_AxisBottom.valueToPos(m_Sorted[i]) - m_Size / 2, m_AxisLeft.valueToPos(m_TransformedY[i]) - m_Size / 2, m_Size, m_Size); } //outline of data point g2d.setStroke(new BasicStroke(m_StrokeThickness)); g2d.setColor(m_Color); g2d.drawOval(m_AxisBottom.valueToPos(m_Sorted[i]) - m_Size / 2, m_AxisLeft.valueToPos(m_TransformedY[i]) - m_Size / 2, m_Size, m_Size); } //if drawing regression fit diagonal if (m_RegressionLine) { g.setColor(Color.BLACK); double[] newData = new double[m_Sorted.length]; for (int i = 0; i < m_Sorted.length; i++) { newData[i] = Math.log(m_Sorted[i]); } ExponentialDistributionImpl ex = new ExponentialDistributionImpl(StatUtils.mean(newData)); //draw the expected diagonal line using the exponential distribution for (int i = 0; i < m_Sorted.length - 1; i++) { double prob1; try { prob1 = ex.cumulativeProbability(newData[i]); } catch (MathException e) { prob1 = 0; } double prob2; try { prob2 = ex.cumulativeProbability(newData[i + 1]); } catch (MathException e) { prob2 = 0; } double p1 = -Math.log(1 - prob1); double p2 = -Math.log(1 - prob2); g.drawLine(m_AxisBottom.valueToPos(m_Sorted[i]), m_AxisLeft.valueToPos(p1), m_AxisBottom.valueToPos(m_Sorted[i + 1]), m_AxisLeft.valueToPos(p2)); } } } }
From source file:org.fhcrc.cpl.viewer.quant.gui.LogRatioHistMouseListener.java
/** * Draw the ratio in its box. Separated from drawBoxForRatio so the box can be drawn empty * @param g//from ww w. ja v a2 s . c o m */ protected void drawRatioInBox(Graphics2D g) { drawBoxForRatio(g); g.setFont(new Font("Verdana", Font.PLAIN, 10)); g.setColor(Color.BLACK); g.setPaint(Color.BLACK); g.drawString("Ratio: " + lastMousedRatio, 16, 24); }
From source file:org.n52.oxf.render.sos.ProportionalCircleMapRenderer.java
private Image renderLegend(ObservationSeriesCollection obsValues, String observedProperty) { double lowestValue = (Double) obsValues.getMinimum(0); double highestValue = (Double) obsValues.getMaximum(0); double classDistance = (highestValue - lowestValue) / (NUMBER_OF_CLASSES - 2); int dotSizeDistance = (MAX_DOT_SIZE - MIN_DOT_SIZE) / (NUMBER_OF_CLASSES - 2); BufferedImage image = new BufferedImage(LEGEND_WIDTH, LEGEND_HEIGHT, BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); // draw white background: g.setColor(Color.WHITE); g.fillRect(0, 0, LEGEND_WIDTH, LEGEND_HEIGHT); // draw information: observedProperty = observedProperty.split(":")[observedProperty.split(":").length - 1]; g.setColor(Color.BLACK);/*from w w w . j av a 2s .c om*/ g.drawString("Observed Property: '" + observedProperty + "'", 25, 25); for (int i = 1; i <= NUMBER_OF_CLASSES; i++) { // draw text: int x_stringLocation = 100; int y_location = i * 60; g.setColor(Color.BLACK); DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(Locale.GERMAN); df.applyPattern("#,###,##0.00"); double lowerBorder = lowestValue + classDistance * (i - 1); double upperBorder = lowestValue + classDistance * i; g.drawString(i + ". class: " + df.format(lowerBorder) + " - " + df.format(upperBorder), x_stringLocation, y_location + 10); // draw symbol: int x_symbolLocation = 30; g.setColor(POINT_INNER_COLOR); g.fillOval(x_symbolLocation, y_location, i * dotSizeDistance, i * dotSizeDistance); } return image; }
From source file:net.refractions.udig.catalog.wmsc.server.AbstractTileRange.java
protected BufferedImage createErrorImage() { BufferedImage bf = new BufferedImage(tileset.getWidth(), tileset.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g = bf.createGraphics(); g.setColor(Color.RED); g.drawLine(0, 0, tileset.getWidth(), tileset.getHeight()); g.drawLine(0, tileset.getHeight(), tileset.getWidth(), 0); return bf;/* w w w . j a va2 s. c o m*/ }