private void completeNickname(KeyEvent e) {
        e.consume();

        String text = getText();
        if ( text.trim().isEmpty() )
            return;

        AbstractTab activeTab = InputHandler.getActiveTab();
        if (activeTab instanceof ChannelTab == false)
            return;

        ChannelTab tab = (ChannelTab) activeTab;
        
        int position = getCaret().getDot();

        int nickStartPos = text.substring(0, position).lastIndexOf(" ");
        if (nickStartPos == -1)
            nickStartPos = 0;
        else
            nickStartPos++;

        int nickEndPos = text.indexOf(" ", position);
        if (nickEndPos == -1)
            nickEndPos = text.length();

        if (nickEndPos < text.length() && text.charAt(nickEndPos) == ':')
            nickEndPos--;

        String partialNick = text.substring(nickStartPos, nickEndPos);
        String completeNickname;
        if ( tab.contains(partialNick) )
            completeNickname = tab.getNickAfter(partialNick);
        else
            completeNickname = tab.getCompleteNickname(partialNick);

        text = text.substring(0, nickStartPos) + completeNickname + text.substring(nickEndPos);
        setText(text);
    }