List of usage examples for java.awt.font GlyphVector getPixelBounds
public Rectangle getPixelBounds(FontRenderContext renderFRC, float x, float y)
From source file:net.sf.mzmine.modules.visualization.metamsecorrelate.visual.pseudospectra.PseudoSpectraRenderer.java
@Override protected void drawItemLabel(Graphics2D g2, XYDataset dataset, int series, int item, XYPlot plot, XYItemLabelGenerator generator, Rectangle2D bar, boolean negative) { //super.drawItemLabel(g2, dataset, series, item, plot, generator, bar, negative); if (generator != null) { String label = generator.generateLabel(dataset, series, item); if (label != null) { Font labelFont = getItemLabelFont(series, item); Paint paint = getItemLabelPaint(series, item); g2.setFont(labelFont);//from w w w. ja v a2 s . c o m g2.setPaint(paint); // get the label position.. ItemLabelPosition position; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, plot.getOrientation()); // split by \n String symbol = "\n"; String[] splitted = label.split(symbol); if (splitted.length > 1) { FontRenderContext frc = g2.getFontRenderContext(); GlyphVector gv = g2.getFont().createGlyphVector(frc, "Fg,"); int height = 4 + (int) gv.getPixelBounds(null, 0, 0).getHeight(); // draw more than one row for (int i = 0; i < splitted.length; i++) { int offset = -height * (splitted.length - i - 1); TextUtilities.drawRotatedString(splitted[i], g2, (float) anchorPoint.getX(), (float) anchorPoint.getY() + offset, position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } } else { // one row TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } } } }
From source file:org.goko.viewer.jogl.service.JoglSceneManager.java
private void drawOverlay() { this.frame += 1; overlay.beginRendering();//from w w w . ja v a2 s. c om Graphics2D g2d = overlay.createGraphics(); try { if (getActiveCamera() != null) { FontRenderContext frc = g2d.getFontRenderContext(); String cameraString = getActiveCamera().getLabel(); GlyphVector gv = getOverlayFont().createGlyphVector(frc, cameraString); Rectangle bounds = gv.getPixelBounds(frc, 0, 0); int x = 5; int y = 5 + bounds.height; g2d.setFont(getOverlayFont()); Color overlayColor = new Color(0.8f, 0.8f, 0.8f); Color transparentColor = new Color(0, 0, 0, 0); g2d.setBackground(transparentColor); g2d.setColor(overlayColor); g2d.clearRect(0, 0, getWidth(), height); if (isEnabled()) { g2d.drawString(cameraString, x, y); } else { g2d.drawString("Disabled", x, y); } if (System.currentTimeMillis() - lastFrameReset >= 500) { this.lastFrameReset = System.currentTimeMillis(); this.fps = this.frame; this.frame = 0; } g2d.setColor(new Color(0.55f, 0.45f, 0.28f)); g2d.drawString(String.valueOf(this.fps * 2) + "fps", x, y + bounds.height + 4); drawOverlayData(g2d); overlay.markDirty(0, 0, getWidth(), height); overlay.drawAll(); } } catch (GkException e) { LOG.error(e); } g2d.dispose(); overlay.endRendering(); }
From source file:org.goko.viewer.jogl.service.JoglViewerServiceImpl.java
/** (inheritDoc) * @see org.goko.viewer.jogl.service.JoglSceneManager#drawOverlayData(java.awt.Graphics2D) *//*from www . ja v a2 s .co m*/ @Override protected void drawOverlayData(Graphics2D g2d) throws GkException { if (getCanvas().isKeyboardJogEnabled()) { // Draw a big red warning saying jog is enabled FontRenderContext frc = g2d.getFontRenderContext(); String warn = "Keyboard jog enabled"; GlyphVector gv = jogWarnFont.createGlyphVector(frc, warn); Rectangle bounds = gv.getPixelBounds(frc, 0, 0); int x = (getWidth() - bounds.width) / 2; int y = 5 + bounds.height; Rectangle2D bg = new Rectangle2D.Double(x - 5, 2, bounds.width + 15, bounds.height + 10); g2d.setFont(jogWarnFont); g2d.setColor(Color.RED);//new Color(0.9f,0,0,0.5f)); g2d.fill(bg); g2d.setColor(Color.WHITE); g2d.drawString(warn, x, y); } }