Example #1
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 #2
0
 private Dimension calcTypeListPreferredSize(final ModuleType[] allModuleTypes) {
   int width = 0;
   int height = 0;
   final FontMetrics fontMetrics = myTypesList.getFontMetrics(myTypesList.getFont());
   final int fontHeight = fontMetrics.getMaxAscent() + fontMetrics.getMaxDescent();
   for (final ModuleType 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.getName()) + 10);
   }
   return new Dimension(width, height);
 }
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());
 }