Package java.awt

Examples of java.awt.FontMetrics


         * @param g
         *            Graphics where the graphical node is to be painted.
         */
        private void paintMe(Graphics g) {
            g.setFont(g.getFont().deriveFont(11f).deriveFont(Font.BOLD));
            FontMetrics fontMetrics = g.getFontMetrics(g.getFont());

            int type = this.node.getType();
            Color color = NORMAL_COLOR;
            switch (type) {
            case PertChartAbstraction.Type.NORMAL: {
                color = NORMAL_COLOR;
                break;
            }
            case PertChartAbstraction.Type.SUPER: {
                color = SUPER_COLOR;
                break;
            }
            case PertChartAbstraction.Type.MILESTONE: {
                color = MILESTONE_COLOR;
                break;
            }
            }
            g.setColor(this.backgroundColor);

            g.fillRoundRect(x, y, NODE_WIDTH, NODE_HEIGHT, 16, 16);
            g.setColor(color);
            g.drawRoundRect(x, y, NODE_WIDTH, NODE_HEIGHT, 16, 16);
            g.drawRoundRect(x + 1, y + 1, NODE_WIDTH - 2, NODE_HEIGHT - 2, 14,
                    14);

            g.drawLine(x, y + yName + fontMetrics.getHeight() + Y_OFFSET, x
                    + NODE_WIDTH, y + yName + fontMetrics.getHeight()
                    + Y_OFFSET);

            g.setColor(Color.BLACK);
            String name = node.getName();
            int nameWidth = fontMetrics.stringWidth(name);

            g.drawString(getTruncatedString(name, NODE_WIDTH - xName,
                    fontMetrics), x + xName, y + yName
                    + fontMetrics.getHeight());

            g.setFont(g.getFont().deriveFont(Font.PLAIN));
            fontMetrics = g.getFontMetrics(g.getFont());

            g.setColor(Color.BLACK);
            g.drawString(ourLanguage.getText("start")
                    + ": "
                    + node.getStartDate().toString(), x + xName, (int) (y
                    + yName + 2.3 * fontMetrics.getHeight()));
            g.drawString(ourLanguage.getText("end")
                    + ": "
                    + node.getEndDate().toString(), x + xName,
                    (int) (y + yName + 3.3 * fontMetrics.getHeight()));

            if (node.getDuration() != null)
                g.drawString(ourLanguage.getText("duration")
                        + ": "
                        + node.getDuration().getLength(), x + xName, (int) (y
                        + yName + 4.3 * fontMetrics.getHeight()));

        }
View Full Code Here


    }
    Image createImage(List myItemsToConsider) {
        BufferedImage tmpImage = new BufferedImage(10, 10,
                BufferedImage.TYPE_INT_RGB);

        FontMetrics fmetric = tmpImage.getGraphics().getFontMetrics(
        myUIConfiguration.getChartMainFont().deriveFont(12f));
        int fourEmWidth = fmetric.stringWidth("mmmm");
       
        int width = 0;
        int height = getTree().getTreeTable().getRowHeight()*3 + HEADER_OFFSET;
        for (Iterator tasks = myItemsToConsider.iterator(); tasks.hasNext();) {
            DefaultMutableTreeNode nextTreeNode = (DefaultMutableTreeNode) tasks
                    .next();

            if (nextTreeNode instanceof BlankLineNode) {
                height += getTree().getTreeTable().getRowHeight();
                continue;
            }

            Task next = (Task) nextTreeNode.getUserObject();
            if ("None".equals(next.toString())) {
                continue;
            }
            if (isVisible(next)) {
                height += getTree().getTreeTable().getRowHeight();
                int nbchar = fmetric.stringWidth(next.getName())+next.getManager().getTaskHierarchy().getDepth(next)*fourEmWidth;
                if (nbchar > width) {
                    width = nbchar;
                }
            }
        }
View Full Code Here

      (offscreenSize.height > 0)) {
     
      int start = map.getIndex(0);
      int end =   map.getIndex(map.getUsedPixels());
      g.setFont(new Font(face, style, size));
      FontMetrics metrics = getFontMetrics(g.getFont());
      int ascent = metrics.getAscent();
     
      // draw backgrounds first...
      int bgColorIndex = headerInfo.getIndex("BGCOLOR");
      if (bgColorIndex > 0) {
        Color back = g.getColor();
View Full Code Here

    /** This method is called when the selection is changed. It causes the component to
     * recalculate it's width, and call repaint.
     */
   private void selectionChanged() {
     maxlength = 1;
     FontMetrics fontMetrics = getFontMetrics(new Font(face, style, size));
     int start = map.getIndex(0);
     int end =   map.getIndex(map.getUsedPixels());
    
     for (int j = start; j < end;j++) {
      int actualGene = j;
       String out = headerSummary.getSummary(headerInfo, actualGene);
       if (out == null) continue;
       int length = fontMetrics.stringWidth(out);
       if (maxlength < length) {
         maxlength = length;
       }
     }
     setPreferredSize(new Dimension(maxlength, map.getUsedPixels()));
View Full Code Here

    final PlanView planView = this.controller.getPlanController().getView();
    if (homePrint != null
        || this.fixedHeaderLabel != null
        || this.fixedFooterLabel != null) {
      if (homePrint != null) {
        FontMetrics fontMetrics = g2D.getFontMetrics(this.headerFooterFont);
        float headerFooterHeight = fontMetrics.getAscent() + fontMetrics.getDescent()
        + HEADER_FOOTER_MARGIN;
       
        // Retrieve variable values
        int pageNumber = page + 1;
        int pageCount = getPageCount();
        String planScale = "?";
        if (homePrint.getPlanScale() != null) {
          planScale = "1/" + Math.round(1 / homePrint.getPlanScale());
        } else {
          if (planView instanceof PlanComponent) {
            planScale = "1/" + Math.round(1 / ((PlanComponent)planView).getPrintPreferredScale(g, pageFormat));
          }       
        }         
        if (page == 0) {
          this.printDate = new Date();
        }
        String homeName = this.home.getName();
        if (homeName == null) {
          homeName = "";
        }
        String homePresentationName = this.controller.getContentManager().getPresentationName(
             homeName, ContentManager.ContentType.SWEET_HOME_3D);
        Object [] variableValues = new Object [] {
            pageNumber, pageCount, planScale, this.printDate, homePresentationName, homeName};
       
        // Create header text
        String headerFormat = homePrint.getHeaderFormat();     
        if (headerFormat != null) {
          header = Variable.getMessageFormat(headerFormat).format(variableValues).trim();
          if (header.length() > 0) {
            xHeader = ((float)pageFormat.getWidth() - fontMetrics.stringWidth(header)) / 2;
            yHeader = imageableY + fontMetrics.getAscent();
            imageableY += headerFooterHeight;
            imageableHeight -= headerFooterHeight;
          } else {
            header = null;
          }
        }
       
        // Create footer text
        String footerFormat = homePrint.getFooterFormat();
        if (footerFormat != null) {
          footer = Variable.getMessageFormat(footerFormat).format(variableValues).trim();
          if (footer.length() > 0) {
            xFooter = ((float)pageFormat.getWidth() - fontMetrics.stringWidth(footer)) / 2;
            yFooter = imageableY + imageableHeight - fontMetrics.getDescent();
            imageableHeight -= headerFooterHeight;
          } else {
            footer = null;
          }
        }
View Full Code Here

            float yName = yRoomCenter + room.getNameYOffset();
            TextStyle nameStyle = room.getNameStyle();
            if (nameStyle == null) {
              nameStyle = this.preferences.getDefaultTextStyle(room.getClass());
            }         
            FontMetrics nameFontMetrics = getFontMetrics(previousFont, nameStyle);
            Rectangle2D nameBounds = nameFontMetrics.getStringBounds(name, g2D);
            // Draw room name
            g2D.setFont(getFont(previousFont, nameStyle));
            g2D.drawString(name, xName - (float)nameBounds.getWidth() / 2, yName);
          }
        }
        if (room.isAreaVisible()) {
          float area = room.getArea();
          if (area > 0.01f) {
            float xArea = xRoomCenter + room.getAreaXOffset();
            float yArea = yRoomCenter + room.getAreaYOffset();
            TextStyle areaStyle = room.getAreaStyle();
            if (areaStyle == null) {
              areaStyle = this.preferences.getDefaultTextStyle(room.getClass());
            }         
            FontMetrics areaFontMetrics = getFontMetrics(previousFont, areaStyle);
            String areaText = this.preferences.getLengthUnit().getAreaFormatWithUnit().format(area);
            Rectangle2D areaTextBounds = areaFontMetrics.getStringBounds(areaText, g2D);
            // Draw room area
            g2D.setFont(getFont(previousFont, areaStyle));
            g2D.drawString(areaText, xArea - (float)areaTextBounds.getWidth() / 2, yArea);
          }
        }
View Full Code Here

            float yName = piece.getY() + piece.getNameYOffset();
            TextStyle nameStyle = piece.getNameStyle();
            if (nameStyle == null) {
              nameStyle = this.preferences.getDefaultTextStyle(piece.getClass());
            }         
            FontMetrics nameFontMetrics = getFontMetrics(previousFont, nameStyle);
            Rectangle2D nameBounds = nameFontMetrics.getStringBounds(name, g2D);
            // Draw piece name
            g2D.setFont(getFont(previousFont, nameStyle));
            g2D.drawString(name, xName - (float)nameBounds.getWidth() / 2, yName);
          }
        }
View Full Code Here

      if (feedback) {
        // Use default for feedback
        lengthStyle = lengthStyle.deriveStyle(getFont().getSize() / getScale());
      }
      Font font = getFont(previousFont, lengthStyle);
      FontMetrics lengthFontMetrics = getFontMetrics(font, lengthStyle);
      Rectangle2D lengthTextBounds = lengthFontMetrics.getStringBounds(lengthText, g2D);
      int fontAscent = lengthFontMetrics.getAscent();
      g2D.translate((dimensionLineLength - (float)lengthTextBounds.getWidth()) / 2,
          dimensionLine.getOffset() <= 0
              ? -lengthFontMetrics.getDescent() - 1
              : fontAscent + 1);
      if (feedback) {
        // Draw text outline with half transparent background color
        g2D.setPaint(backgroundColor);
        if (oldComposite instanceof AlphaComposite) {
View Full Code Here

      if (isPreferredSizeSet()) {
        return super.getPreferredSize();
      } else {
        Insets insets = getInsets();
        Rectangle2D planBounds = getPlanBounds();
        FontMetrics metrics = getFontMetrics(getFont());
        int ruleHeight = metrics.getAscent() + 6;
        if (this.orientation == SwingConstants.HORIZONTAL) {
          return new Dimension(
              Math.round(((float)planBounds.getWidth() + MARGIN * 2)
                         * getScale()) + insets.left + insets.right,
              ruleHeight);
View Full Code Here

      float yMin = (float)planBounds.getMinY() - MARGIN;
      float xMax = convertXPixelToModel(getWidth());
      float yMax = convertYPixelToModel(getHeight());
      boolean leftToRightOriented = getComponentOrientation().isLeftToRight();

      FontMetrics metrics = getFontMetrics(getFont());
      int fontAscent = metrics.getAscent();
      float tickSize = 5 / rulerScale;
      float mainTickSize = (fontAscent + 6) / rulerScale;
      NumberFormat format = NumberFormat.getIntegerInstance();
     
      g2D.setColor(getForeground());
      float lineWidth = 0.5f / rulerScale;
      g2D.setStroke(new BasicStroke(lineWidth));
      if (this.orientation == SwingConstants.HORIZONTAL) {
        // Draw horizontal rule base
        g2D.draw(new Line2D.Float(xMin, yMax - lineWidth, xMax, yMax - lineWidth));
        // Draw small ticks
        for (float x = (int) (xMin / gridSize) * gridSize; x < xMax; x += gridSize) {
          g2D.draw(new Line2D.Float(x, yMax - tickSize, x, yMax));
        }
      } else {
        // Draw vertical rule base
        if (leftToRightOriented) {
          g2D.draw(new Line2D.Float(xMax - lineWidth, yMin, xMax - lineWidth, yMax));
        } else {
          g2D.draw(new Line2D.Float(xMin + lineWidth, yMin, xMin + lineWidth, yMax));
        }
        // Draw small ticks
        for (float y = (int) (yMin / gridSize) * gridSize; y < yMax; y += gridSize) {
          if (leftToRightOriented) {
            g2D.draw(new Line2D.Float(xMax - tickSize, y, xMax, y));
          } else {
            g2D.draw(new Line2D.Float(xMin, y, xMin + tickSize, y));
          }
        }
      }

      if (mainGridSize != gridSize) {
        g2D.setStroke(new BasicStroke(1.5f / rulerScale,
            BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
        AffineTransform previousTransform = g2D.getTransform();
        // Draw big ticks
        if (this.orientation == SwingConstants.HORIZONTAL) {
          for (float x = (int) (xMin / mainGridSize) * mainGridSize; x < xMax; x += mainGridSize) {
            g2D.draw(new Line2D.Float(x, yMax - mainTickSize, x, yMax));
            // Draw unit text
            g2D.translate(x, yMax - mainTickSize);
            g2D.scale(1 / rulerScale, 1 / rulerScale);
            g2D.drawString(getFormattedTickText(format, x), 3, fontAscent - 1);
            g2D.setTransform(previousTransform);
          }
        } else {
          for (float y = (int) (yMin / mainGridSize) * mainGridSize; y < yMax; y += mainGridSize) {
            String yText = getFormattedTickText(format, y);
            if (leftToRightOriented) {
              g2D.draw(new Line2D.Float(xMax - mainTickSize, y, xMax, y));
              // Draw unit text with a vertical orientation
              g2D.translate(xMax - mainTickSize, y);
              g2D.scale(1 / rulerScale, 1 / rulerScale);
              g2D.rotate(-Math.PI / 2);
              g2D.drawString(yText, -metrics.stringWidth(yText) - 3, fontAscent - 1);
            } else {
              g2D.draw(new Line2D.Float(xMin, y, xMin +  mainTickSize, y));
              // Draw unit text with a vertical orientation
              g2D.translate(xMin + mainTickSize, y);
              g2D.scale(1 / rulerScale, 1 / rulerScale);
View Full Code Here

TOP

Related Classes of java.awt.FontMetrics

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.