List of usage examples for java.awt Graphics2D drawString
public abstract void drawString(AttributedCharacterIterator iterator, float x, float y);
From source file:net.sourceforge.processdash.ui.web.reports.RadarPlot.java
/** * Draws the label for one radar axis./*from w w w . j a va2 s. c om*/ * * @param g2 The graphics device. * @param chartArea The area for the radar chart. * @param data The data for the plot. * @param axis The axis (zero-based index). * @param startAngle The starting angle. */ protected void drawLabel(Graphics2D g2, Rectangle2D chartArea, String label, int axis, double labelX, double labelY) { // handle label drawing... FontRenderContext frc = g2.getFontRenderContext(); Rectangle2D labelBounds = this.axisLabelFont.getStringBounds(label, frc); LineMetrics lm = this.axisLabelFont.getLineMetrics(label, frc); double ascent = lm.getAscent(); if (labelX == chartArea.getCenterX()) labelX -= labelBounds.getWidth() / 2; else if (labelX < chartArea.getCenterX()) labelX -= labelBounds.getWidth(); if (labelY > chartArea.getCenterY()) labelY += ascent; g2.setPaint(this.axisLabelPaint); g2.setFont(this.axisLabelFont); g2.drawString(label, (float) labelX, (float) labelY); }
From source file:com.qumasoft.guitools.compare.ContentRow.java
@Override public void paint(Graphics g) { if ((getRowType() == ROWTYPE_REPLACE) && rowHadAnnotations) { Graphics2D g2 = (Graphics2D) g; String s = getText();/*from w ww . j a v a 2 s .c o m*/ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (s.length() > 0) { int index = 0; AttributedString attributedString = new AttributedString(s, getFont().getAttributes()); try { for (byte rType : fileACharacterTypeArray) { switch (rType) { case ContentRow.ROWTYPE_DELETE: attributedString.addAttribute(TextAttribute.STRIKETHROUGH, null, index, index + 1); break; case ContentRow.ROWTYPE_REPLACE: attributedString.addAttribute(TextAttribute.BACKGROUND, ColorManager.getReplaceCompareHiliteBackgroundColor(), index, index + 1); break; default: break; } index++; } g2.drawString(attributedString.getIterator(), 0, getFont().getSize()); } catch (java.lang.IllegalArgumentException e) { LOGGER.log(Level.WARNING, "bad replace indexes. begin index: [" + index + "] end index: [" + index + "]. String length: [" + s.length() + "]"); } } else { super.paint(g); } } else { super.paint(g); } }
From source file:LineStyles.java
/** This method draws the example figure */ public void paint(Graphics g1) { Graphics2D g = (Graphics2D) g1; // Use anti-aliasing to avoid "jaggies" in the lines g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Define the shape to draw GeneralPath shape = new GeneralPath(); shape.moveTo(xpoints[0], ypoints[0]); // start at point 0 shape.lineTo(xpoints[1], ypoints[1]); // draw a line to point 1 shape.lineTo(xpoints[2], ypoints[2]); // and then on to point 2 // Move the origin to the right and down, creating a margin g.translate(20, 40);//from w w w . j a v a2s . co m // Now loop, drawing our shape with the three different line styles for (int i = 0; i < linestyles.length; i++) { g.setColor(Color.gray); // Draw a gray line g.setStroke(linestyles[i]); // Select the line style to use g.draw(shape); // Draw the shape g.setColor(Color.black); // Now use black g.setStroke(thindashed); // And the thin dashed line g.draw(shape); // And draw the shape again. // Highlight the location of the vertexes of the shape // This accentuates the cap and join styles we're demonstrating for (int j = 0; j < xpoints.length; j++) g.fillRect(xpoints[j] - 2, ypoints[j] - 2, 5, 5); g.drawString(capNames[i], 5, 105); // Label the cap style g.drawString(joinNames[i], 5, 120); // Label the join style g.translate(150, 0); // Move over to the right before looping again } }
From source file:pt.lsts.neptus.plugins.sunfish.awareness.SituationAwareness.java
public void paintLabels(Graphics2D g, StateRenderer2D renderer) { g.setFont(new Font("Arial", Font.PLAIN, 11)); for (AssetTrack track : assets.values()) { AssetPosition p = track.getLatest(newestTimestampSelection); if (p == null || hiddenPosTypes.contains(p.getType())) continue; if (p.getTimestamp() < oldestTimestampSelection || p.getTimestamp() > newestTimestampSelection) continue; Point2D pt = renderer.getScreenPosition(p.getLoc()); g.setColor(track.getColor());// ww w . j av a 2s .co m g.setColor(Color.black); String name = p.getAssetName();//assetProperties.containsKey(p.getAssetName()) ? assetProperties.get(p.getAssetName()).friendly : p.getAssetName(); g.drawString( name + " (" + DateTimeUtil.milliSecondsToFormatedString( System.currentTimeMillis() - p.getTimestamp()) + ")", (int) (pt.getX() + 13), (int) (pt.getY() + 5)); } }
From source file:org.csml.tommo.sugar.modules.QualityHeatMapsPerTileAndBase.java
void drawRowHeader(Graphics2D g2, final ResultsTableModel model, int imgSize, int width, int xOffset) { for (int r = 0; r < model.getRowCount(); r++) { int bp = model.getBasePosition(r); if (model.getCycleID(r) == 0) { String s = String.valueOf(bp); int stringHeight = g2.getFont().getSize(); //g2.getFontMetrics().getHeight(); int stringWidth = g2.getFontMetrics().stringWidth(s); g2.drawString(s, 1 + width + (xOffset - 1 - stringWidth) / 2, imgSize * (r + 1) - (imgSize - stringHeight) / 2); }//from ww w . j ava 2 s. c o m } }
From source file:org.geomajas.plugin.rasterizing.layer.RasterDirectLayer.java
protected void addLoadError(Graphics2D graphics, ImageException imageResult, MapViewport viewport) { Bbox imageBounds = imageResult.getRasterImage().getBounds(); ReferencedEnvelope viewBounds = viewport.getBounds(); double rasterScale = viewport.getScreenArea().getWidth() / viewport.getBounds().getWidth(); double width = imageBounds.getWidth(); double height = imageBounds.getHeight(); // subtract screen position of lower-left corner double x = imageBounds.getX() - rasterScale * viewBounds.getMinX(); // shift y to lower left corner, flip y to user space and subtract // screen position of lower-left // corner/*from w ww.ja v a 2s . co m*/ double y = -imageBounds.getY() - imageBounds.getHeight() - rasterScale * viewBounds.getMinY(); if (log.isDebugEnabled()) { log.debug("adding image, width=" + width + ",height=" + height + ",x=" + x + ",y=" + y); } // opacity log.debug("before drawImage"); graphics.drawString(getNlsString("loaderror.line1"), (int) x, (int) y); }
From source file:org.kalypso.ogc.gml.map.MapPanel.java
/** * If a message is present, paint it and return true *//*w w w . j a v a2s .com*/ private void paintStatus(final Graphics2D g) { if (m_status.isOK()) return; final String message = m_status.getMessage(); final int stringWidth = g.getFontMetrics().stringWidth(message); final int width = getWidth(); final int height = getHeight(); g.setColor(m_backgroundColor); g.fillRect(0, 0, width, height); g.setColor(Color.black); g.drawString(message, (width - stringWidth) / 2, height / 2); }
From source file:org.tros.logo.swing.LogoPanel.java
@Override public void drawString(final String message) { Drawable command = new Drawable() { @Override/*from w ww .j a va 2 s . c o m*/ public void draw(Graphics2D g2, TurtleState turtleState) { if (!turtleState.penup) { AffineTransform saveXform = g2.getTransform(); //double offsetAngle = (Math.PI / 2.0); double offsetAngle = 0; g2.setTransform(AffineTransform.getRotateInstance(turtleState.angle + offsetAngle, turtleState.penX, turtleState.penY)); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); g2.drawString(message, (int) turtleState.penX, (int) turtleState.penY); g2.setTransform(saveXform); } } @Override public void addListener(DrawListener listener) { } @Override public void removeListener(DrawListener listener) { } @Override public Drawable cloneDrawable() { return this; } }; submitCommand(command); }
From source file:costumetrade.common.verify.ImageVerification.java
public Pair<String, BufferedImage> create() { int x = 0, fontHeight = 0, codeY = 0; int red = 0, green = 0, blue = 0; x = width / (codeCount + 2);//? fontHeight = height - 2;// codeY = height - 4;/*w w w . ja v a 2 s .co m*/ // ?buffer BufferedImage buffImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = buffImg.createGraphics(); // ? g.setColor(Color.WHITE); g.fillRect(0, 0, width, height); // g.setFont(new Font("Arial", Font.PLAIN, fontHeight)); for (int i = 0; i < lineCount; i++) { int xs = RandomUtils.nextInt(0, width); int ys = RandomUtils.nextInt(0, height); int xe = xs + RandomUtils.nextInt(0, width / 8); int ye = ys + RandomUtils.nextInt(0, height / 8); red = RandomUtils.nextInt(0, 255); green = RandomUtils.nextInt(0, 255); blue = RandomUtils.nextInt(0, 255); g.setColor(new Color(red, green, blue)); g.drawLine(xs, ys, xe, ye); } // randomCode??? StringBuilder randomCode = new StringBuilder(); // ?codeCount?? for (int i = 0; i < codeCount; i++) { String strRand = String.valueOf(codeSequence[RandomUtils.nextInt(0, codeSequence.length)]); // ???? red = RandomUtils.nextInt(0, 255); green = RandomUtils.nextInt(0, 255); blue = RandomUtils.nextInt(0, 255); g.setColor(new Color(red, green, blue)); g.drawString(strRand, (i + 1) * x, codeY); // ?? randomCode.append(strRand); } // ????Session return new Pair<String, BufferedImage>(randomCode.toString(), buffImg); }
From source file:org.jcurl.core.swing.WCComponent.java
private BufferedImage renderPng(final String watermark) { final BufferedImage img = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); final Graphics2D g2 = (Graphics2D) img.getGraphics(); {//from w w w .j ava 2 s .c o m final Map<Key, Object> hints = new HashMap<Key, Object>(); hints.put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); hints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); hints.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); hints.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); hints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); hints.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.addRenderingHints(hints); } final Font f0 = g2.getFont(); paint(g2); g2.setTransform(new AffineTransform()); if (watermark != null) { if (log.isDebugEnabled()) log.debug(f0); g2.setFont(f0); g2.setColor(new Color(0, 0, 0, 128)); g2.drawString(watermark, 10, 20); } g2.dispose(); return img; }