Example #1
0
 @Override
 public Dimension getMinimumSize(int cols) {
   Font f = xtext.getFont();
   FontMetrics fm = xtext.getFontMetrics(f);
   return new Dimension(
       fm.charWidth('0') * cols + 10, fm.getMaxDescent() + fm.getMaxAscent() + PADDING);
 }
Example #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);
    }
  }
Example #3
0
 /**
  * Converts a line index to a y co-ordinate.
  *
  * @param line The line
  */
 public int lineToY(int line) {
   FontMetrics fm = painter.getFontMetrics();
   return (line - firstLine) * fm.getHeight() - (fm.getLeading() + fm.getMaxDescent());
 }
Example #4
0
  private boolean recalcPositions(Graphics g) {
    Font f = g.getFont();
    if (f != oldFont || !(StringUtil.stringsEqual(oldText, text))) {
      FontMetrics fm = g.getFontMetrics(f);
      sw = MesquiteInteger.maximum(fm.stringWidth("888"), fm.stringWidth(tf.getText()));
      sh = fm.getMaxAscent() + fm.getMaxDescent();
    }
    oldText = text;
    oldFont = f;
    if (oldTextBoxWidth < sw + MesquiteModule.textEdgeCompensationWidth - 1
        || oldTextBoxHeight < sh + MesquiteModule.textEdgeCompensationHeight - 1) {
      textBoxWidth = sw + MesquiteModule.textEdgeCompensationWidth; // 34
      textBoxHeight = sh + MesquiteModule.textEdgeCompensationHeight; // 18
      oldTextBoxWidth = textBoxWidth;
      oldTextBoxHeight = textBoxHeight;
      if (horizontal) {
        if (stacked) {
          totalWidth = textBoxWidth + EnterButton.MIN_DIMENSION + 2;
          totalHeight = textBoxHeight + 20;
          setSize(totalWidth, totalHeight);
          tf.setSize(textBoxWidth, textBoxHeight);
          tf.setLocation(0, 0);
          decrementButton.setLocation(2, textBoxHeight + 4);
          incrementButton.setLocation(totalWidth - 20, textBoxHeight + 4);
        } else {
          totalWidth = textBoxWidth + 36 + EnterButton.MIN_DIMENSION + 2;
          totalHeight = textBoxHeight + 4;
          setSize(totalWidth, totalHeight);
          tf.setSize(textBoxWidth, textBoxHeight);
          decrementButton.setLocation(0, 2);
          tf.setLocation(
              decrementButton.getBounds().x + decrementButton.getBounds().width + 1,
              0); // 1 added to x
          incrementButton.setLocation(
              tf.getBounds().x + tf.getBounds().width + EnterButton.MIN_DIMENSION + 2,
              2); // 1 added to x
        }
        enterButton.setLocation(tf.getBounds().x + tf.getBounds().width + 1, 2);
      } else {
        if (stacked) {
          totalWidth = textBoxWidth + EnterButton.MIN_DIMENSION + 2;
          totalHeight = textBoxHeight + 20;
          setSize(totalWidth, totalHeight);
          tf.setSize(textBoxWidth, textBoxHeight);
          tf.setLocation(0, 0);
          decrementButton.setLocation(2, textBoxHeight + 4);
          incrementButton.setLocation(totalWidth - 22, textBoxHeight + 4);
          enterButton.setLocation(tf.getBounds().x + tf.getBounds().width + 1, 2);
        } else {
          totalWidth = textBoxWidth; // should be 0
          totalHeight = textBoxHeight + 36 + EnterButton.MIN_DIMENSION + 2;

          setSize(totalWidth, totalHeight);
          tf.setSize(textBoxWidth, textBoxHeight);
          incrementButton.setLocation(1, 2);
          tf.setLocation(0, incrementButton.getBounds().height + 3);
          decrementButton.setLocation(
              1, tf.getBounds().y + tf.getBounds().height + EnterButton.MIN_DIMENSION + 2);
          enterButton.setLocation(1, tf.getBounds().y + tf.getBounds().height + 1);
        }
      }
      incrementButton.repaint();
      decrementButton.repaint();
      enterButton.repaint();
      repaint();
      getParent().repaint();
      return true;
    }
    if (checkBackground()) {
      repaint();
      return true;
    }
    /*	if (!getBackground().equals(getParent().getBackground())) {
    	bg =getParent().getBackground();
    	setBackground(bg);
    	//setBackground(Color.green);
    	tf.setBackground(bg);
    	decrementButton.setBackground(bg);
    	incrementButton.setBackground(bg);
    	enterButton.setBackground(bg);
    	repaint();
    	return true;
    }*/
    return false;
  }