private String fixText (String s, DocumentFilter.FilterBypass  fb) throws BadLocationException
    {
        if (s == null) {
            return null;
        }

        int currentLength = fb.getDocument().getLength();
        int l = fb.getDocument().getLength();
        char prevChar = (l < 1) ? ' ' : fb.getDocument().getText(l-1, 1).charAt(0);

        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < s.length(); ++i)
        {
            boolean doubleSpace = prevChar == ' ' && s.charAt(i) == ' ';
            
            if (!isIllegalFileNameChar (s.charAt (i)) &&
                !doubleSpace &&
                currentLength < 25) //hard coded 25 char max
                sb.append (s.charAt (i));
        }
        return sb.toString();
    }