@Override
    public void draw(Graphics g) {
        if (!isVisible)
            return;

        super.draw(g);
        g.setColor(Color.WHITE);
        g.setFont(font);

        // show text until position
        int textX = x;
        int textY;
        for (int i = currentPage * MAX_CHARS_PER_PAGE; i <= position; i++) {
            char c = text[i];
            if (getCharPositionInLine(i) == 0)
                textX = x;
            else
                textX += g.getFontMetrics().charWidth(c);
            textY = y + LINE_SPACE * getLinePositionInPage(i);
            g.drawString(String.valueOf(c), textX, textY);
        }

        // show cursor
        if (cursor != null && isEndOfPage(position) && !isLastPage(currentPage) && !isDrawingMessage) {
            int cursorX = innerX + innerWidth - cursor.getWidth(null) - 3;
            int cursorY = innerY + innerHeight - cursor.getHeight(null);
            g.drawImage(cursor, cursorX, cursorY, null);
        }
    }