public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { StringBuilder builder = new StringBuilder(string); for (int i = builder.length() - 1; i >= 0; i--) { int cp = builder.codePointAt(i); if (!Character.isDigit(cp) && cp != '-') { builder.deleteCharAt(i); if (Character.isSupplementaryCodePoint(cp)) { i--; builder.deleteCharAt(i); } } } super.insertString(fb, offset, builder.toString(), attr); }
@Override public void insertString( DocumentFilter.FilterBypass fp, int offset, String string, AttributeSet aset) throws BadLocationException { Document doc = fp.getDocument(); String oldText = doc.getText(0, doc.getLength()); StringBuilder sb = new StringBuilder(oldText); sb.insert(offset, string); int len = string.length(); boolean isValidInteger = true; for (int i = 0; i < len; i++) { if (!Character.isDigit(string.charAt(i))) { isValidInteger = false; break; } } if (isValidInteger && verifyText(sb.toString())) super.insertString(fp, offset, string, aset); else Toolkit.getDefaultToolkit().beep(); }
public void insertString(FilterBypass fb, int offset, String str, AttributeSet a) throws BadLocationException { /* Queue a copy of the event and then modify the textarea */ eventHistory.add(new TextInsertEvent(offset, str)); super.insertString(fb, offset, str, a); }
public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { StringBuilder builder = new StringBuilder(string); // 过滤用户输入的所有字符 filterInt(builder); super.insertString(fb, offset, builder.toString(), attr); }
/** * If the resulting length of the insert will be less than or equal to the allowed length, then * allow it, otherwise ignore it. */ @Override public void insertString( DocumentFilter.FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { int length = fb.getDocument().getLength(); if ((string.length() + length) <= maxLength) { super.insertString(fb, offset, string, attr); } }
/** * insertString * * @param fb * @param offset * @param string * @param attr * @throws BadLocationException */ @Override public void insertString( final FilterBypass fb, final int offset, final String string, final AttributeSet attr) throws BadLocationException { if (offset >= promptPosition) { super.insertString(fb, offset, string, attr); } }
public void insertString(FilterBypass fb, int offs, String str, AttributeSet a) throws BadLocationException { if ("\n".equals(str)) { str = addWhiteSpace(fb.getDocument(), offs); if (fb.getDocument().getText(offs - 2, 1).equals("{")) { str = str + "Meow"; } } super.insertString(fb, offs, str, a); }
public void insertString( DocumentFilter.FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { // This is called by JTextArea.append() (for example). super.insertString(fb, offset, string, attr); // Make sure that the caret is at the end. For extra safety, this should probably be done // with EventQueue.invokeLater() just like as is done in CmdLineWindow.takeChar(). theWindow.theText.setCaretPosition(theWindow.theText.getText().length()); }
@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 Toolkit.getDefaultToolkit().beep(); }
@Override public void replace( DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException { String intToReplacet; if (!Utils.isInteger(text) && !text.equals(".")) { intToReplacet = ""; } else { intToReplacet = text; } super.insertString(fb, offset, intToReplacet, attrs); }
@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 insertString( FilterBypass filterBypass, int offset, String text, AttributeSet attributeSet) throws BadLocationException { text = trimHexadecimal(text); Document document = filterBypass.getDocument(); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(document.getText(0, document.getLength())); stringBuilder.insert(offset, text); if (isValidInput(stringBuilder.toString(), 0)) { super.insertString(filterBypass, offset, text, attributeSet); } else { Toolkit.getDefaultToolkit().beep(); } }
public void insertString(FilterBypass fb, int offs, String str, AttributeSet a) throws BadLocationException { if ("\n".equals(str)) str = addWhiteSpace(fb.getDocument(), offs); super.insertString(fb, offs, str, a); }
@Override public void insertString(FilterBypass fb, int offs, String str, AttributeSet a) throws BadLocationException { if (filter == null) super.insertString(fb, offs, str, a); else filter.insertString(fb, offs, str, a); }