Examples of TextLayout


Examples of java.awt.font.TextLayout

       
        if (xmin <= 0 && xmax > 0) {
    xmin = Math.abs(xmin);
    xmax = Math.abs(xmax);
   
    TextLayout layout = new TextLayout(c.getYAxisUnit(), c.getFont(),
               c.getFontRenderContext());
       
    // yaxis label width
    int maxlmargin = computeYAxisLabelWidth() + marginOffset; // + yaxis title width
       
    // unit width
    maxlmargin = Math.max(maxlmargin, (int) layout.getBounds().getWidth() + marginOffset);
       
       
    int margin = (int)(maxlmargin - (xmin / (xmin + xmax)) * (c.getBounds().getWidth() - c.getRightMargin()));
       
    margin += 5; // just for good looking
View Full Code Here

Examples of java.awt.font.TextLayout

  }
    }
   
    /** Computes the right margin. */
    public int computeRightMargin() {
  TextLayout layout = new TextLayout(c.getXAxisUnit(), c.getFont(),
              c.getFontRenderContext());
  return Math.max((int)(layout.getBounds().getWidth() + (double)c.ARROWLENGTH / 3) , c.ARROWLENGTH);
    }
View Full Code Here

Examples of java.awt.font.TextLayout

  return Math.max((int)(layout.getBounds().getWidth() + (double)c.ARROWLENGTH / 3) , c.ARROWLENGTH);
    }
   
    /** Computes the top margin. */
    public int computeTopMargin() {
  TextLayout layout = new TextLayout(c.getYAxisUnit(), c.getFont(),
             c.getFontRenderContext());
  return Math.max((int)(layout.getBounds().getHeight() + (double)c.ARROWLENGTH / 3 + layout.getDescent()), c.ARROWLENGTH);
    }
View Full Code Here

Examples of java.awt.font.TextLayout

 
        if (ymin <= 0 && ymax > 0) {
    ymin = Math.abs(ymin);
    ymax = Math.abs(ymax);
   
    TextLayout layout = new TextLayout(c.getXAxisUnit(), c.getFont(),
                c.getFontRenderContext());
       
    // xaxis label height
    int maxbmargin = computeXAxisLabelHeight() + marginOffset; // + xaxis title height
       
    // unit height
    maxbmargin = Math.max(maxbmargin, (int) layout.getBounds().getHeight() + marginOffset);
       
       
    int margin = (int)(maxbmargin - (ymin / (ymin + ymax)) * (c.getBounds().getHeight() - c.getTopMargin()));
       
    margin += 10; // just for good looking
View Full Code Here

Examples of java.awt.font.TextLayout

     * the possible scaling.
     * @param g the <CODE>Graphics2D</CODE> object to paint in
     */
    public void paintDefault(Graphics2D g) {
        g.setColor(Color.black);
        TextLayout layout = new TextLayout(getText(), getFont(),
                                           new FontRenderContext(null, true, false));
       
        layout.draw(g, 0f, (float)getPreferredSize().getHeight() - layout.getDescent());
    }
View Full Code Here

Examples of java.awt.font.TextLayout

            3);
    }
       
        // draw X-Axis label right below the Arrow ?!
        g.setColor(Color.black);
        TextLayout layoutX = new TextLayout(getXAxisUnit(), getFont(),
                                           new FontRenderContext(null, true, false));
    layoutX.draw(g, (float)x.getX2() + (float)ARROWLENGTH / 3(float)x.getY2() + (float)layoutX.getBounds().getHeight() + 5);
       
        // draw Y-Axis Arrow
    if(shouldDrawArrows) {
      g.drawLine((int)y.getX1(), (int)y.getY1(), (int)y.getX1(), (int)y.getY1() - ARROWLENGTH);
      g.fillPolygon(new int[] {(int)(y.getX1() - 3),
            (int)(y.getX1() + 3),
            (int)(y.getX1())},
            new int[] {(int)(y.getY1() - ARROWLENGTH / 3.0),
            (int)(y.getY1() - ARROWLENGTH / 3.0),
            (int)y.getY1() - ARROWLENGTH},
            3);
    }

        // draw Y-Axis label right below the Arrow ?!
        g.setColor(Color.black);
        TextLayout layoutY = new TextLayout(getYAxisUnit(), getFont(),
                                           new FontRenderContext(null, true, false));
        layoutY.draw(g, (float)y.getX1()-6-(float)layoutY.getBounds().getWidth(),
                        (float)y.getY1() - layoutX.getDescent() - 3);
       
        if(getSecondYAxis() != null) {
            Line2D y2 = c.getSecondYAxisLine2D();
            g.draw(y2);
View Full Code Here

Examples of java.awt.font.TextLayout

        if(text.length() == 0)
            return 0;
        Graphics2D g2 = (Graphics2D) g;
        FontRenderContext frc = g2.getFontRenderContext();
        Font font = g.getFont();
        TextLayout layout = new TextLayout(text, font, frc);
        Rectangle2D bounds = layout.getBounds();
        return (int) bounds.getWidth() + 1;
    }
View Full Code Here

Examples of java.awt.font.TextLayout

        } else {
          g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));
        }
        g2D.setStroke(new BasicStroke(3 / planScale));
        FontRenderContext fontRenderContext = g2D.getFontRenderContext();
        TextLayout textLayout = new TextLayout(lengthText, font, fontRenderContext);
        g2D.draw(textLayout.getOutline(new AffineTransform()));
        g2D.setComposite(oldComposite);
        g2D.setPaint(foregroundColor);
      }
      // Draw dimension length in middle
      g2D.setFont(font);
View Full Code Here

Examples of java.awt.font.TextLayout

    public static BufferedImage createImageFromText(String text, Font font) {
        //You may want to change these setting, or make them parameters
        boolean isAntiAliased = true;
        boolean usesFractionalMetrics = false;
        FontRenderContext frc = new FontRenderContext(null, isAntiAliased, usesFractionalMetrics);
        TextLayout layout = new TextLayout(text, font, frc);
        Rectangle2D bounds = layout.getBounds();
        int w = (int) Math.ceil(bounds.getWidth());
        int h = (int) Math.ceil(bounds.getHeight()) + 2;
        BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); //for example;
        Graphics2D g = image.createGraphics();
        g.setColor(Color.WHITE);
View Full Code Here

Examples of java.awt.font.TextLayout

    /*
    final String left_values_str = "" + (int) (value_per_vinterval *
        (1 + (dimension.height - axis_margin_top - axis_margin_bottom) / pixels_per_vinterval));
*/
    final String left_values_str = "1000M";
    final TextLayout layout = new TextLayout(left_values_str, backing_g.getFont(), backing_g.getFontRenderContext());
    final Rectangle2D bounds = layout.getBounds();
    axis_margin_left = (int) bounds.getWidth() + 5 + 10;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.