Esempio n. 1
0
 void setPosition(int newX, int newY) {
   Insets insets = eNode.getContext().getInsets();
   FontMetrics metrics = getFontMetrics(getFont());
   int stringWidth = metrics.stringWidth(getText());
   int stringHeight = metrics.getHeight();
   setBounds(
       newX + insets.left + eNode.getWidth() + SEPARATION,
       newY + insets.top + eNode.getInsets().top,
       metrics.stringWidth(getText()),
       metrics.getHeight());
 }
Esempio n. 2
0
  /**
   * This is called to paint within the EditCanvas
   *
   * @param g Graphics
   * @param c DisplayCanvas to paint on.
   */
  public void paint(Graphics g, DisplayCanvas c) {
    Rectangle nb = transformOutput(c, getBounds());
    if (!getActive()) {
      Rectangle r = getBounds();
      g.setColor(Color.lightGray);
      g.fillRect(r.x, r.y, r.width, r.height);
    }

    draw((Graphics2D) g, nb.x, nb.y, nb.width, nb.height);

    if ((c instanceof StationModelCanvas) && ((StationModelCanvas) c).getShowParams()) {
      int xoff = 0;
      FontMetrics fm = g.getFontMetrics();
      g.setColor(Color.black);
      for (int i = 0; i < paramIds.length; i++) {
        String s = paramIds[i];
        if (i > 0) {
          s = ", " + s;
        }
        g.drawString(s, nb.x + xoff, nb.y + nb.height + fm.getMaxDescent() + fm.getMaxAscent() + 4);
        xoff += fm.stringWidth(s);
      }
    }
    if ((c instanceof StationModelCanvas) && ((StationModelCanvas) c).shouldShowAlignmentPoints()) {
      paintRectPoint(g, c);
    }
  }
Esempio n. 3
0
  public void paint(Graphics g) {
    m_fm = g.getFontMetrics();

    g.setColor(getBackground());
    g.fillRect(0, 0, getWidth(), getHeight());
    getBorder().paintBorder(this, g, 0, 0, getWidth(), getHeight());

    g.setColor(getForeground());
    g.setFont(getFont());
    m_insets = getInsets();
    int x = m_insets.left;
    int y = m_insets.top + m_fm.getAscent();

    StringTokenizer st = new StringTokenizer(getText(), "\t");
    while (st.hasMoreTokens()) {
      String sNext = st.nextToken();
      g.drawString(sNext, x, y);
      x += m_fm.stringWidth(sNext);

      if (!st.hasMoreTokens()) break;
      int index = 0;
      while (x >= getTab(index)) index++;
      x = getTab(index);
    }
  }
Esempio n. 4
0
 void setPosition(int newX, int newY) {
   Insets insets = getContext().getInsets();
   insets = getContext().getInsets();
   FontMetrics metrics = getFontMetrics(getFont());
   int stringWidth = metrics.stringWidth(getText());
   int stringHeight = metrics.getHeight();
   setBounds(
       newX + insets.left,
       newY + insets.top,
       stringWidth + getInsets().left + getInsets().right,
       stringHeight + insets.top + insets.bottom + VERTICAL_PAD);
   if (rightLabel != null) rightLabel.setPosition(newX, newY);
 }
 private Dimension calcTypeListPreferredSize(final List<ModuleBuilder> allModuleTypes) {
   int width = 0;
   int height = 0;
   final FontMetrics fontMetrics = myTypesList.getFontMetrics(myTypesList.getFont());
   final int fontHeight = fontMetrics.getMaxAscent() + fontMetrics.getMaxDescent();
   for (final ModuleBuilder type : allModuleTypes) {
     final Icon icon = type.getBigIcon();
     final int iconHeight = icon != null ? icon.getIconHeight() : 0;
     final int iconWidth = icon != null ? icon.getIconWidth() : 0;
     height += Math.max(iconHeight, fontHeight) + 6;
     width = Math.max(width, iconWidth + fontMetrics.stringWidth(type.getPresentableName()) + 10);
   }
   return new Dimension(width, height);
 }
Esempio n. 6
0
  /**
   * Draw the line numbers
   *
   * @param g
   */
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    ((Graphics2D) g)
        .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    //	Determine the width of the space available to draw the line number

    FontMetrics fontMetrics = component.getFontMetrics(component.getFont());
    Insets insets = getInsets();
    int availableWidth = getSize().width - insets.left - insets.right;

    //  Determine the rows to draw within the clipped bounds.

    Rectangle clip = g.getClipBounds();
    int rowStartOffset = component.viewToModel(new Point(0, clip.y));
    int endOffset = component.viewToModel(new Point(0, clip.y + clip.height));

    while (rowStartOffset <= endOffset) {
      try {
        if (isCurrentLine(rowStartOffset)) g.setColor(getCurrentLineForeground());
        else g.setColor(getForeground());

        //  Get the line number as a string and then determine the
        //  "X" and "Y" offsets for drawing the string.

        String lineNumber = getTextLineNumber(rowStartOffset);
        int stringWidth = fontMetrics.stringWidth(lineNumber);
        int x = getOffsetX(availableWidth, stringWidth) + insets.left;
        int y = getOffsetY(rowStartOffset, fontMetrics);
        g.drawString(lineNumber, x, y);

        //  Move to the next row

        rowStartOffset = Utilities.getRowEnd(component, rowStartOffset) + 1;
      } catch (Exception e) {
        break;
      }
    }
  }
Esempio n. 7
0
 private int getTextWidth(String text) {
   return fmRef.stringWidth(text);
 }