Package java.awt.font

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


     * 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

            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

        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

        } 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

    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

    /*
    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

              current_interval_pos - cpt * (pixels_per_interval / 10),
              dimension.height - axis_margin_bottom - 1);

      final String current_time_str = formatTime(current_time_to_display);
      final String current_date_str = formatDate(current_time_to_display);
      final TextLayout current_layout = new TextLayout(current_time_str, backing_g.getFont(), backing_g.getFontRenderContext());
      final TextLayout current_layout_date = new TextLayout(current_date_str, backing_g.getFont(), backing_g.getFontRenderContext());
      final Rectangle2D current_bounds = current_layout.getBounds();
      final Rectangle2D current_bounds_date = current_layout_date.getBounds();
      backing_g.setColor(Color.YELLOW.darker());
      backing_g.drawString(current_time_str,
          current_interval_pos - (int) (current_bounds.getWidth() / 2),
          dimension.height - axis_margin_bottom + (int) current_bounds.getHeight() + 2 * std_separator);
      backing_g.setColor(Color.YELLOW.darker().darker());
      backing_g.drawString(current_date_str,
          current_interval_pos - (int) (current_bounds_date.getWidth() / 2),
          3 + ((int) current_bounds.getHeight()) + dimension.height - axis_margin_bottom + (int) current_bounds.getHeight() + 2 * std_separator);
      if (current_interval_pos - current_bounds.getWidth() / 2 < axis_margin_left)
        stop = true;
      current_interval_pos -= pixels_per_interval;
      current_time_to_display -= _getDelayPerInterval();
    }
    backing_g.setClip(null);

    vinterval_pos = dimension.height - axis_margin_bottom - pixels_per_vinterval;
    int value = value_per_vinterval;
    while (vinterval_pos > axis_margin_top) {
      backing_g.setColor(Color.YELLOW.darker());
      backing_g.drawLine(axis_margin_left - std_separator, vinterval_pos,
          dimension.width - axis_margin_right, vinterval_pos);
      final String value_str;
      if (value >= 1000000) value_str = "" + value / 1000000 + "M";
      else if (value >= 1000) value_str = "" + value / 1000 + "k";
      else value_str = "" + value;
      final TextLayout current_layout = new TextLayout(value_str, backing_g.getFont(), backing_g.getFontRenderContext());
      final Rectangle2D current_bounds = current_layout.getBounds();
      backing_g.setColor(Color.YELLOW.darker());
      backing_g.drawString(value_str,
          axis_margin_left - (int) current_bounds.getWidth() - 2 * std_separator,
          vinterval_pos + (int) (current_bounds.getHeight() / 2));
      vinterval_pos -= pixels_per_vinterval;
View Full Code Here

            descText);
        attributedDescription.addAttribute(TextAttribute.FONT, font);
        LineBreakMeasurer lineBreakMeasurer = new LineBreakMeasurer(
            attributedDescription.getIterator(), frc);
        while (true) {
          TextLayout tl = lineBreakMeasurer.nextLayout(descTextWidth);
          if (tl == null)
            break;
          descriptionTextHeight += fontHeight;
        }
        // add an empty line after the paragraph
        descriptionTextHeight += fontHeight;
      }
      // remove the empty line after the last paragraph
      descriptionTextHeight -= fontHeight;

      if (tooltipInfo.getMainImage() != null) {
        height += Math.max(descriptionTextHeight, new JLabel(
            new ImageIcon(tooltipInfo.getMainImage()))
            .getPreferredSize().height);
      } else {
        height += descriptionTextHeight;
      }

      if ((tooltipInfo.getFooterImage() != null)
          || (tooltipInfo.getFooterSections().size() > 0)) {
        height += gap;
        // The footer separator
        height += new JSeparator(JSeparator.HORIZONTAL)
            .getPreferredSize().height;

        height += gap;

        int footerTextHeight = 0;
        int availableWidth = descTextWidth;
        if (tooltipInfo.getFooterImage() != null) {
          availableWidth -= tooltipInfo.getFooterImage().getWidth(
              null);
        }
        if (tooltipInfo.getMainImage() != null) {
          availableWidth += tooltipInfo.getMainImage().getWidth(null);
        }
        for (String footerText : tooltipInfo.getFooterSections()) {
          AttributedString attributedDescription = new AttributedString(
              footerText);
          attributedDescription
              .addAttribute(TextAttribute.FONT, font);
          LineBreakMeasurer lineBreakMeasurer = new LineBreakMeasurer(
              attributedDescription.getIterator(), frc);
          while (true) {
            TextLayout tl = lineBreakMeasurer
                .nextLayout(availableWidth);
            if (tl == null)
              break;
            footerTextHeight += fontHeight;
          }
View Full Code Here

        attributedDescription.addAttribute(TextAttribute.FONT, font);
        LineBreakMeasurer lineBreakMeasurer = new LineBreakMeasurer(
            attributedDescription.getIterator(), frc);
        int currOffset = 0;
        while (true) {
          TextLayout tl = lineBreakMeasurer
              .nextLayout(descLabelWidth);
          if (tl == null)
            break;
          int charCount = tl.getCharacterCount();
          String line = descText.substring(currOffset, currOffset
              + charCount);

          JLabel descLabel = new JLabel(line);
          descriptionLabels.add(descLabel);
          richTooltipPanel.add(descLabel);
          descLabel.setBounds(x, y,
              descLabel.getPreferredSize().width, fontHeight);
          y += descLabel.getHeight();

          currOffset += charCount;
        }
        // add an empty line after the paragraph
        y += titleLabel.getHeight();
      }
      // remove the empty line after the last paragraph
      y -= titleLabel.getHeight();

      if (mainImageLabel != null) {
        y = Math.max(y, mainImageLabel.getY()
            + mainImageLabel.getHeight());
      }

      if ((tooltipInfo.getFooterImage() != null)
          || (tooltipInfo.getFooterSections().size() > 0)) {
        y += gap;
        // The footer separator
        footerSeparator = new JSeparator(JSeparator.HORIZONTAL);
        richTooltipPanel.add(footerSeparator);
        footerSeparator.setBounds(ins.left, y, parent.getWidth()
            - ins.left - ins.right, footerSeparator
            .getPreferredSize().height);

        y += footerSeparator.getHeight() + gap;

        // The footer image
        x = ins.left;
        if (tooltipInfo.getFooterImage() != null) {
          footerImageLabel = new JLabel(new ImageIcon(tooltipInfo
              .getFooterImage()));
          richTooltipPanel.add(footerImageLabel);
          footerImageLabel.setBounds(x, y, footerImageLabel
              .getPreferredSize().width, footerImageLabel
              .getPreferredSize().height);
          x += footerImageLabel.getWidth() + 2 * gap;
        }

        // The footer text
        int footerLabelWidth = parent.getWidth() - x - ins.right;
        for (String footerText : tooltipInfo.getFooterSections()) {
          AttributedString attributedDescription = new AttributedString(
              footerText);
          attributedDescription
              .addAttribute(TextAttribute.FONT, font);
          LineBreakMeasurer lineBreakMeasurer = new LineBreakMeasurer(
              attributedDescription.getIterator(), frc);
          int currOffset = 0;
          while (true) {
            TextLayout tl = lineBreakMeasurer
                .nextLayout(footerLabelWidth);
            if (tl == null)
              break;
            int charCount = tl.getCharacterCount();
            String line = footerText.substring(currOffset,
                currOffset + charCount);

            JLabel footerLabel = new JLabel(line);
            footerLabels.add(footerLabel);
View Full Code Here

TOP

Related Classes of java.awt.font.TextLayout

Copyright © 2018 www.massapicom. 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.