public void printLineNumbers(Graphics g, int start, int count, int width) {
    Object map = Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints"); //$NON-NLS-1$
    if (map != null) {
      ((Graphics2D) g).addRenderingHints((Map<?, ?>) map);
    }

    final int insetY = metrics.getLeading() + metrics.getAscent();
    final int gh = metrics.getHeight();
    Dimension size = new Dimension(width, count * gh);
    int lineNum = start;
    final int end = size.height;

    // we don't want to waste the users ink, most IDE's do not print the background
    g.setColor(bgColor);
    g.fillRect(0, 0, size.width, size.height);
    g.setColor(fgColor);

    g.setFont(new Font("Monospace", Font.PLAIN, 12)); //$NON-NLS-1$

    for (int y = insetY; lineNum < lines && y <= end; lineNum++, y += gh) {
      String str = Integer.toString(lineNum);
      int strw = (int) g.getFontMetrics().getStringBounds(str, g).getWidth();
      g.drawString(str, size.width - strw - 3, y);
    }
  }