List of usage examples for java.awt Graphics2D drawString
public abstract void drawString(AttributedCharacterIterator iterator, float x, float y);
From source file:org.prom5.analysis.performance.sequence.Pattern.java
/** * Draws the pattern in the pattern diagram * @param lifeLines HashMap/* ww w. j ava 2 s . c om*/ * @param startY int * @param g Graphics2D */ public void drawPattern(HashMap lifeLines, int startY, Graphics2D g) { g.setColor(Color.BLACK); g.drawString("Pattern " + patternNumber + ":", 10, startY + 5); g.setColor(color); //draw data-element blocks for (int i = 0; i < sortedDataEltBlocks.size(); i++) { DataElementBlock block = (DataElementBlock) sortedDataEltBlocks.get(i); try { block.drawBlock(((LifeLine) lifeLines.get(block.getDataElement())).getMiddle() - 10, color, g); } catch (NullPointerException ex) { } } //draw arrows ListIterator arrows = arrowList.listIterator(); while (arrows.hasNext()) { Arrow arrow = (Arrow) arrows.next(); arrow.drawArrow(lifeLines, color, g); } }
From source file:Main.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); g2d.setColor(Color.RED);/* w w w . jav a 2 s . co m*/ g2d.drawLine(getWidth() / 2, 0, getWidth() / 2, getHeight()); g2d.drawLine(0, getHeight() / 2, getWidth(), getHeight() / 2); Font font = new Font("Arial", Font.BOLD, 48); g2d.setFont(font); FontMetrics fm = g2d.getFontMetrics(); int x = ((getWidth() - fm.stringWidth(text)) / 2); int y = ((getHeight() - fm.getHeight()) / 2) + fm.getAscent(); g2d.setColor(Color.BLACK); g2d.drawString(text, x, y); g2d.dispose(); }
From source file:TextBouncer.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; setAntialiasing(g2);/*from www . j a v a 2s . c o m*/ setTransform(g2); setPaint(g2); // Draw the string. g2.setFont(getFont()); g2.drawString(mString, mX, mY + mHeight); drawAxes(g2); }
From source file:IteratorUnderStrike.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; String s = "\"www.java2s.com\" is great."; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Font plainFont = new Font("Times New Roman", Font.PLAIN, 24); AttributedString as = new AttributedString(s); as.addAttribute(TextAttribute.FONT, plainFont); as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, 1, 15); as.addAttribute(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON, 18, 25); g2.drawString(as.getIterator(), 24, 70); }
From source file:TexturedText.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Font font = new Font("Times New Roman", Font.PLAIN, 72); g2.setFont(font);/*www . j a va 2 s. c om*/ String s = "Java Source and Support"; Dimension d = getSize(); float x = 20, y = 100; BufferedImage bi = getTextureImage(); Rectangle r = new Rectangle(0, 0, bi.getWidth(), bi.getHeight()); TexturePaint tp = new TexturePaint(bi, r); g2.setPaint(tp); g2.drawString(s, x, y); }
From source file:edu.umn.cs.spatialHadoop.nasa.MultiHDFPlot.java
/** * Draws a scale used with the heat map/*from w w w .jav a 2s . c o m*/ * @param output * @param valueRange * @param width * @param height * @throws IOException */ private static void drawVerticalScale(Path output, double min, double max, int width, int height, OperationsParams params) throws IOException { BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); g.setBackground(Color.BLACK); g.clearRect(0, 0, width, height); // fix this part to work according to color1, color2 and gradient type HDFPlot.HDFRasterizer gradient = new HDFPlot.HDFRasterizer(); gradient.configure(params); HDFRasterLayer gradientLayer = (HDFRasterLayer) gradient.createCanvas(0, 0, new Rectangle()); for (int y = 0; y < height; y++) { Color color = gradientLayer.calculateColor(height - y, 0, height); g.setColor(color); g.drawRect(width * 3 / 4, y, width / 4, 1); } int fontSize = 24; g.setFont(new Font("Arial", Font.BOLD, fontSize)); double step = (max - min) * fontSize * 5 / height; step = (int) (Math.pow(10.0, Math.round(Math.log10(step)))); double min_value = Math.floor(min / step) * step; double max_value = Math.floor(max / step) * step; g.setColor(Color.WHITE); for (double value = min_value; value <= max_value; value += step) { double y = ((value - min) + (max - value) * (height - fontSize)) / (max - min); g.drawString(String.valueOf((int) value), 5, (int) y); } g.dispose(); FileSystem fs = output.getFileSystem(new Configuration()); FSDataOutputStream outStream = fs.create(output, true); ImageIO.write(image, "png", outStream); outStream.close(); }
From source file:edu.umn.cs.spatialHadoop.nasa.MultiHDFPlot.java
/** * Draws a scale used with the heat map/*from w ww . ja v a 2s . c o m*/ * @param output * @param valueRange * @param width * @param height * @throws IOException */ private static void drawHorizontalScale(Path output, double min, double max, int width, int height, OperationsParams params) throws IOException { BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); g.setBackground(Color.BLACK); g.clearRect(0, 0, width, height); int fontSize = 24; // fix this part to work according to color1, color2 and gradient type HDFPlot.HDFRasterizer gradient = new HDFPlot.HDFRasterizer(); gradient.configure(params); HDFRasterLayer gradientLayer = (HDFRasterLayer) gradient.createCanvas(0, 0, new Rectangle()); for (int x = 0; x < width; x++) { Color color = gradientLayer.calculateColor(x, 0, width); g.setColor(color); g.drawRect(x, height - (fontSize - 5), 1, fontSize - 5); } g.setFont(new Font("Arial", Font.BOLD, fontSize)); double step = (max - min) * fontSize * 5 / width; step = (int) (Math.pow(10.0, Math.round(Math.log10(step)))); double min_value = Math.floor(min / step) * step; double max_value = Math.floor(max / step) * step; g.setColor(Color.WHITE); for (double value = min_value; value <= max_value; value += step) { double x = ((value - min) * (width - fontSize) + (max - value)) / (max - min); g.drawString(String.valueOf((int) value), (int) x, fontSize); } g.dispose(); FileSystem fs = output.getFileSystem(new Configuration()); FSDataOutputStream outStream = fs.create(output, true); ImageIO.write(image, "png", outStream); outStream.close(); }
From source file:org.uva.itast.blended.omr.pages.PageImage.java
/** * Mark the results in a thumbnail of the page intended for reporting *///from w w w .j a v a2 s . c o m public void labelPageAsProcessed() { BufferedImage imagen = getReportingImage(); Graphics2D g = imagen.createGraphics(); g.setColor(Color.RED); g.drawString("Page Processed at:" + new Date() + " W:" + imagen.getWidth() + " H:" + imagen.getHeight(), 10, 10); }
From source file:MainClass.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Font serifFont = new Font("Serif", Font.PLAIN, 32); AttributedString as = new AttributedString("www.java2s.com"); as.addAttribute(TextAttribute.FONT, serifFont); Image image = createImage();//from w w w. j a v a2 s . c o m ImageGraphicAttribute imageAttribute = new ImageGraphicAttribute(image, GraphicAttribute.TOP_ALIGNMENT); as.addAttribute(TextAttribute.CHAR_REPLACEMENT, imageAttribute, 5, 6); g2.drawString(as.getIterator(), 20, 120); }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2D = (Graphics2D) g; Point2D.Float p1 = new Point2D.Float(150.f, 75.f); Point2D.Float p2 = new Point2D.Float(250.f, 75.f); float width = 300; float height = 50; GradientPaint g1 = new GradientPaint(p1, Color.WHITE, p2, Color.DARK_GRAY); Rectangle2D.Float rect1 = new Rectangle2D.Float(p1.x - 100, p1.y - 25, width, height); g2D.setPaint(g1);/*from w ww .j av a2s.c om*/ g2D.fill(rect1); g2D.setPaint(Color.BLACK); g2D.draw(rect1); g2D.draw(new Line2D.Float(p1, p2)); g2D.drawString("Cyclic Gradient Paint", p1.x - 100, p1.y - 50); g2D.drawString("p1", p1.x - 20, p1.y); g2D.drawString("p2", p2.x + 10, p2.y); p1.setLocation(150, 200); p2.setLocation(250, 200); GradientPaint g2 = new GradientPaint(p1, Color.WHITE, p2, Color.DARK_GRAY, false); rect1.setRect(p1.x - 100, p1.y - 25, width, height); g2D.setPaint(g2); g2D.fill(rect1); g2D.setPaint(Color.BLACK); g2D.draw(rect1); g2D.draw(new Line2D.Float(p1, p2)); g2D.drawString("Acyclic Gradient Paint", p1.x - 100, p1.y - 50); g2D.drawString("p1", p1.x - 20, p1.y); g2D.drawString("p2", p2.x + 10, p2.y); }