@Override public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException { Document doc = fb.getDocument(); StringBuilder sb = new StringBuilder(); sb.append(doc.getText(0, doc.getLength())); sb.replace(offset, offset + length, text); if (test(sb.toString())) { super.replace(fb, offset, length, text, attrs); } else { // warn the user and don't allow the insert } }
@Override public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs, DocumentFilterChain chain) throws BadLocationException { EditContext ctx = new EditContext(offset, length, text, attrs); if(!enabled) { replace(fb, ctx, chain); return; } if(bloquearEdicao(ctx)) { return; } // Não permite escrever no início ou no final do omissis. ajustaEdicaoForaDoOmissis(ctx); if(podeGerarOmissis(ctx.getOffset(), ctx.getEndOffset(), ctx.getText())) { agendaIdentificacaoAutomatica(); } replace(fb, ctx, chain); }
@Override public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException { int currentLength = fb.getDocument().getLength(); int newTextLength = text == null ? 0 : text.length(); int newLength = currentLength + newTextLength - length; if (newLength <= LIMIT) { super.replace(fb, offset, length, text, attrs); } else { limitReached(); } }
@Override public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { int currentLength = fb.getDocument().getLength(); int newLength = currentLength + string.length(); if (newLength <= LIMIT) { super.insertString(fb, offset, string, attr); } else { limitReached(); } }
@Override public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { String normalized = normalizeWhiteSpaces(string); if (isLengthInLimit(normalized, fb, 0)) { super.insertString(fb, offset, normalized, attr); } else { warnAboutInvalidText(); } }
@Override public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException { String normalized = text == null ? null : normalizeWhiteSpaces(text); //NOI18N if (normalized == null || isLengthInLimit(normalized, fb, length)) { super.replace(fb, offset, length, normalized, attrs); } else { warnAboutInvalidText(); } }
@Override public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { Document doc = fb.getDocument(); StringBuilder sb = new StringBuilder(); sb.append(doc.getText(0, doc.getLength())); sb.insert(offset, string); if (test(sb.toString())) { super.insertString(fb, offset, string, attr); } else { // warn the user and don't allow the insert } }
@Override public void remove(FilterBypass fb, int offset, int length) throws BadLocationException { Document doc = fb.getDocument(); StringBuilder sb = new StringBuilder(); sb.append(doc.getText(0, doc.getLength())); sb.delete(offset, offset + length); if (test(sb.toString())) { super.remove(fb, offset, length); } else { // warn the user and don't allow the insert } }
@Override public void insertString(final FilterBypass filterBypass, final int offset, final String string, final AttributeSet attrs) throws BadLocationException { if (overwriteMode) { int length = getMaxLengthToRemove(filterBypass, offset, string.length()); replaceImpl(filterBypass, offset, length, string, attrs); } else { insertStringImpl(filterBypass, offset, string, attrs); } }
@Override public void replace(final FilterBypass filterBypass, final int offset, final int length, final String text, final AttributeSet attrs) throws BadLocationException { if (overwriteMode) { int strLength = getMaxLengthToRemove(filterBypass, offset, Math.max(length, text != null ? text.length() : 0)); replaceImpl(filterBypass, offset, strLength, text, attrs); } else { replaceImpl(filterBypass, offset, length, text, attrs); } }
void insertStringImpl(final FilterBypass filterBypass, final int offset, final String string, final AttributeSet attrs) throws BadLocationException { if (needEdit(0, offset, 0, string)) { filterBypass.insertString(offset, string, attrs); } }
void removeImpl(final FilterBypass filterBypass, final int offset, final int length) throws BadLocationException { if (needEdit(1, offset, length, null)) { filterBypass.remove(offset, length); } }
void replaceImpl(final FilterBypass filterBypass, final int offset, final int length, final String text, final AttributeSet attrs) throws BadLocationException { if (needEdit(2, offset, length, text)) { filterBypass.replace(offset, length, text, attrs); } }
final int getMaxLengthToRemove(final FilterBypass filterBypass, final int offset, final int length) { return Math.min(length, filterBypass.getDocument().getLength() - offset); }
final void replaceImpl(final FilterBypass filterBypass, final int offset, final int length, final String text, final AttributeSet attrs) throws BadLocationException { if (getAllowsInvalid()) { filterBypass.replace(offset, length, text, attrs); } else if (checkString(offset, text)) { String text1 = addLiteralSympolsToString(offset, text); filterBypass.replace(offset, text1.length(), text1, null); } }
final void insertStringImpl(final FilterBypass filterBypass, final int offset, final String string, final AttributeSet attrs) throws BadLocationException { if (getAllowsInvalid()) { filterBypass.insertString(offset, string, attrs); } }
void removeImpl(final FilterBypass filterBypass, final int offset, final int length) throws BadLocationException { if (getAllowsInvalid()) { filterBypass.remove(offset, length); } else { String text = getSubstring(offset, getMaxLengthToRemove(filterBypass, offset, length)); filterBypass.replace(offset, text.length(), text, null); JFormattedTextField textField = getFormattedTextField(); //perhaps it is temporary solution textField.setCaretPosition(offset); } }
private void highlight(FilterBypass fb) { try { String text; try { text = doc.getText(doc.getStartPosition().getOffset(), doc .getEndPosition().getOffset()); } catch (BadLocationException e) { e.printStackTrace(); return; } lexer.reset(); lexer.setInputStream(new ANTLRInputStream( new StringReader(text))); CommonTokenStream tokens = new CommonTokenStream(lexer); tokens.fill(); doc.setCharacterAttributes(0, text.length(), defaultStyle, true); List<Token> tokenList = tokens.getTokens(); for (int i = 0; i < tokenList.size(); i++) { Token t = tokenList.get(i); int type = t.getType(); if (styles.containsKey(type)) { if (type == IDENTIFIER && i + 1 < tokenList.size()) { if (tokenList.get(i + 1).getType() == OPENP) { type = 999; } } int offs = t.getStartIndex(); int len = t.getStopIndex() - offs + 1; doc.setCharacterAttributes(offs, len, styles.get(type), true); } } } catch (Exception e1) { e1.printStackTrace(); } }
@Override public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException { dirty = true; if (inlineEdit) { text = text.replaceAll("[\\r\\n]", " "); } new DocumentFilterChain(filters).replace(fb, offset, length, text, attrs); edicaoControlada = false; }
public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException { ExtendedHTMLDocumentFilter filter = filters.poll(); if(filter != null) { filter.replace(fb, offset, length, text, attrs, this); } else { // log.info("fb.replace(" + offset + ", " + length + ", \"" + text + "\", " + attrs + ")"); fb.replace(offset, length, text, attrs); } }
@Override public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs, DocumentFilterChain chain) throws BadLocationException { ExtendedHTMLDocument htmlDoc = (ExtendedHTMLDocument) fb.getDocument(); if (HTMLTableDocumentFilter.bloquearEdicaoDeTabela(htmlDoc, offset, length, text)) { return; } chain.replace(fb, offset, length, text, attrs); }
/** * Test of insertString method, of class FixedSizeFilter. */ @Test public void testInsertString() throws Exception { System.out.println("insertString"); FilterBypass fb = null; int offset = 0; String str = ""; AttributeSet attr = null; FixedSizeFilter instance = new FixedSizeFilter(16); //instance.insertString(fb, offset, str, attr); // TODO review the generated test code and remove the default call to fail. // fail("The test case is a prototype."); }