List of usage examples for java.awt Graphics2D drawString
public abstract void drawString(AttributedCharacterIterator iterator, float x, float y);
From source file:DashedRectangleDemo2D.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(Color.gray);/* ww w. j a v a 2 s. c om*/ int x = 5; int y = 7; g2.setStroke(dashed); g2.draw(new RoundRectangle2D.Double(x, y, 200, 200, 10, 10)); g2.drawString("RoundRectangle2D", x, 250); }
From source file:weka.core.ChartUtils.java
/** * Render a combined histogram and box plot chart from summary data * /*from w ww .j ava2s . c o m*/ * @param width the width of the resulting image * @param height the height of the resulting image * @param bins the values for the chart * @param freqs the corresponding frequencies * @param summary the summary stats for the box plot * @param outliers an optional list of outliers for the box plot * @param additionalArgs optional arguments to the renderer (may be null) * @return a buffered image * @throws Exception if a problem occurs */ public static BufferedImage renderCombinedBoxPlotAndHistogramFromSummaryData(int width, int height, List<String> bins, List<Double> freqs, List<Double> summary, List<Double> outliers, List<String> additionalArgs) throws Exception { String plotTitle = "Combined Chart"; String userTitle = getOption(additionalArgs, "-title"); plotTitle = (userTitle != null) ? userTitle : plotTitle; List<String> opts = new ArrayList<String>(); opts.add("-title=histogram"); BufferedImage hist = renderHistogramFromSummaryData(width / 2, height, bins, freqs, opts); opts.clear(); opts.add("-title=box plot"); BufferedImage box = null; try { box = renderBoxPlotFromSummaryData(width / 2, height, summary, outliers, opts); } catch (Exception ex) { // if we can't generate the box plot (i.e. probably because // data is 100% missing) then just return the histogram } if (box == null) { width /= 2; } BufferedImage img = new BufferedImage(width, height + 20, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = img.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP); g2d.setFont(new Font("SansSerif", Font.BOLD, 12)); g2d.setColor(Color.lightGray); g2d.fillRect(0, 0, width, height + 20); g2d.setColor(Color.black); FontMetrics fm = g2d.getFontMetrics(); int fh = fm.getHeight(); int sw = fm.stringWidth(plotTitle); if (box != null) { g2d.drawImage(box, 0, 20, null); g2d.drawImage(hist, width / 2 + 1, 20, null); } else { g2d.drawImage(hist, 0, 20, null); } g2d.drawString(plotTitle, width / 2 - sw / 2, fh + 2); g2d.dispose(); return img; }
From source file:ArcDemo2D.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(Color.gray);// ww w .j a v a 2 s .c o m int x = 5; int y = 7; g2.setStroke(wideStroke); g2.draw(new Arc2D.Double(x, y, 200, 200, 90, 135, Arc2D.OPEN)); g2.drawString("Arc2D", x, 250); }
From source file:Main.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D twoD = (Graphics2D) g; RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); twoD.setRenderingHints(rh);/* ww w . jav a 2 s .c o m*/ twoD.setColor(Color.BLACK); twoD.drawString(raised, 5, 90); }
From source file:domainhealth.frontend.graphics.JFreeChartGraphImpl.java
/** * Check to see if current graph has empty chart lines (ie. no data-series * in any lines), and if so, write the text 'NO DATA' in large letters * across the front of the graph//from w ww. j a v a 2 s. c om * * @param graphImage The current image representation of the generated graph */ @SuppressWarnings("unchecked") private void addNoDataLogoIfEmpty(BufferedImage graphImage) { int maxStatCount = 0; List<XYSeries> seriesList = xySeriesCollection.getSeries(); for (XYSeries series : seriesList) { maxStatCount = Math.max(maxStatCount, series.getItemCount()); } if (maxStatCount <= 0) { Graphics2D graphics2D = get2DGraphics(graphImage); graphics2D.setFont(new Font(GRAPH_TEXT_FONT, Font.PLAIN, 36)); graphics2D.drawString(NO_DATA_TEXT, 200, 210); graphics2D.dispose(); } else if (maxStatCount <= 1) { Graphics2D graphics2D = get2DGraphics(graphImage); graphics2D.setFont(new Font(GRAPH_TEXT_FONT, Font.PLAIN, 22)); graphics2D.drawString(WAITING_FOR_DATA_TEXT_LN1, 152, 205); graphics2D.dispose(); graphics2D = get2DGraphics(graphImage); graphics2D.setFont(new Font(GRAPH_TEXT_FONT, Font.PLAIN, 15)); graphics2D.drawString(WAITING_FOR_DATA_TEXT_LN2, 81, 225); graphics2D.dispose(); } }
From source file:PrintLineByLine.java
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHints(rh);//from w w w. ja v a 2s . c o m g2d.setFont(new Font("Purisa", Font.PLAIN, 13)); g2d.drawString("Line 1", 20, 30); g2d.drawString("Line 2", 20, 60); g2d.drawString("Line 3", 20, 90); g2d.drawString("Line 4", 20, 120); g2d.drawString("Line 5", 20, 150); g2d.drawString("Line 6", 20, 180); }
From source file:FilledRectangleDemo2D.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(Color.gray);//ww w. j av a 2 s.c o m int x = 5; int y = 7; g2.setPaint(Color.red); g2.fill(new Rectangle2D.Double(x, y, 200, 200)); g2.setPaint(Color.black); g2.drawString("Filled Rectangle2D", x, 250); }
From source file:FilledArc.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int x = 5;//from w w w.jav a 2 s.co m int y = 7; // fill Arc2D g2.setPaint(Color.red); g2.fill(new Arc2D.Double(x, y, 200, 200, 90, 135, Arc2D.OPEN)); g2.setPaint(Color.black); g2.drawString("Filled Arc2D", x, 250); }
From source file:FontSizeAnimation.java
public void paint(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; Font font = new Font("Dialog", Font.PLAIN, x); g2d.setFont(font);//from www .j a v a 2 s .co m FontMetrics fm = g2d.getFontMetrics(); String s = "Java"; int w = (int) getSize().getWidth(); int h = (int) getSize().getHeight(); int stringWidth = fm.stringWidth(s); g2d.drawString(s, (w - stringWidth) / 2, h / 2); }
From source file:Text.java
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHints(rh);/*w w w . j a v a 2 s .co m*/ Font font = new Font("New Roma", Font.BOLD, 40); g2d.setFont(font); g2d.drawString("text", 20, 30); }