javax.swing.text.DocumentFilter源码实例Demo

类javax.swing.text.DocumentFilter源码实例Demo

下面列出了javax.swing.text.DocumentFilter 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ghidra   文件: HexIntegerFormatter.java
HexAllowedPositiveValueIntgerDocumentFilterWrapper(Format format,
		DocumentFilter wrappedFilter) {
	super(format, wrappedFilter);

	hexCharacterSet.add('a');
	hexCharacterSet.add('A');
	hexCharacterSet.add('b');
	hexCharacterSet.add('B');
	hexCharacterSet.add('c');
	hexCharacterSet.add('C');
	hexCharacterSet.add('d');
	hexCharacterSet.add('D');
	hexCharacterSet.add('e');
	hexCharacterSet.add('E');
	hexCharacterSet.add('f');
	hexCharacterSet.add('F');
}
 
源代码2 项目: netbeans   文件: BaseDocument.java
/** Inserts string into document */
    public @Override void insertString(int offset, String text, AttributeSet attrs)
    throws BadLocationException {
//        if (LOG_EDT.isLoggable(Level.FINE)) { // Only permit operations in EDT
//            // Disabled due to failing OpenEditorEnablesEditMenuFactoryTest
//            if (!SwingUtilities.isEventDispatchThread()) {
//                throw new IllegalStateException("BaseDocument.insertString not in EDT: offset=" + // NOI18N
//                        offset + ", text=" + org.netbeans.lib.editor.util.CharSequenceUtilities.debugText(text)); // NOI18N
//            }
//        }
        
        // Always acquire atomic lock (it simplifies processing and improves readability)
        atomicLockImpl();
        try {
            checkModifiable(offset);
            DocumentFilter filter = getDocumentFilter();
            if (filter != null) {
                filter.insertString(getFilterBypass(), offset, text, attrs);
            } else {
                handleInsertString(offset, text, attrs);
            }
        } finally {
            atomicUnlockImpl(true);
        }
    }
 
源代码3 项目: netbeans   文件: BaseDocument.java
/** Removes portion of a document */
    public @Override void remove(int offset, int length) throws BadLocationException {
//        if (LOG_EDT.isLoggable(Level.FINE)) { // Only permit operations in EDT
//            if (!SwingUtilities.isEventDispatchThread()) {
//                throw new IllegalStateException("BaseDocument.insertString not in EDT: offset=" + // NOI18N
//                        offset + ", len=" + length); // NOI18N
//            }
//        }

        // Always acquire atomic lock (it simplifies processing and improves readability)
        atomicLockImpl();
        try {
            checkModifiable(offset);
            DocumentFilter filter = getDocumentFilter();
            if (filter != null) {
                filter.remove(getFilterBypass(), offset, length);
            } else {
                handleRemove(offset, length);
            }
        } finally {
            atomicUnlockImpl(true);
        }
    }
 
源代码4 项目: netbeans   文件: BaseDocument.java
public void replace(int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
    // Always acquire atomic lock (it simplifies processing and improves readability)
    atomicLockImpl();
    try {
        checkModifiable(offset);
        DocumentFilter filter = getDocumentFilter();
        if (filter != null) {
            filter.replace(getFilterBypass(), offset, length, text, attrs);
        } else {
            handleRemove(offset, length);
            handleInsertString(offset, text, attrs);
        }
    } finally {
        atomicUnlockImpl(true);
    }
}
 
源代码5 项目: java-swing-tips   文件: MainPanel.java
@Override public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
  Document doc = fb.getDocument();
  Element root = doc.getDefaultRootElement();
  int count = root.getElementCount();
  int index = root.getElementIndex(offset);
  Element cur = root.getElement(index);
  int promptPosition = cur.getStartOffset() + PROMPT.length();
  if (index == count - 1 && offset - promptPosition >= 0) {
    String str = text;
    if (LB.equals(str)) {
      String line = doc.getText(promptPosition, offset - promptPosition);
      // String[] args = line.split("\\s");
      String[] args = Stream.of(line.split(","))
        .map(String::trim)
        .filter(s -> !s.isEmpty())
        .toArray(String[]::new);
      String cmd = args[0];
      if (cmd.isEmpty()) {
        str = String.format("%n%s", PROMPT);
      } else {
        str = String.format("%n%s: command not found%n%s", cmd, PROMPT);
      }
    }
    fb.replace(offset, length, str, attrs);
  }
}
 
源代码6 项目: groovy   文件: ConsoleTextEditor.java
public void enableHighLighter(Class clazz) {
    DefaultStyledDocument doc = (DefaultStyledDocument) textEditor.getDocument();

    try {
        DocumentFilter documentFilter = (DocumentFilter) clazz.getConstructor(doc.getClass()).newInstance(doc);
        doc.setDocumentFilter(documentFilter);

        disableMatchingHighlighter();
        if (documentFilter instanceof SmartDocumentFilter) {
            final SmartDocumentFilter smartDocumentFilter = (SmartDocumentFilter) documentFilter;
            enableMatchingHighlighter(smartDocumentFilter);
        }
    } catch (ReflectiveOperationException e) {
        e.printStackTrace();
    }
}
 
源代码7 项目: opensim-gui   文件: JConsole.java
@Override
public void insertString(DocumentFilter.FilterBypass fb, int offset, String string, AttributeSet attr)
        throws BadLocationException {
    if (useFilters) {
        // determine if we can insert
        if (console.getSelectionStart() >= console.editStart) {
            // can insert
            fb.insertString(offset, string, attr);
        } else {
            // insert at the end of the document
            fb.insertString(console.getText().length(), string, attr);
            // move cursor to the end
            console.getCaret().setDot(console.getText().length());
            // console.setSelectionEnd(console.getText().length());
            // console.setSelectionStart(console.getText().length());
        }
    } else {
        fb.insertString(offset, string, attr);
    }
}
 
源代码8 项目: opensim-gui   文件: JConsole.java
@Override
public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs)
        throws BadLocationException {
    if (useFilters) {
        // determine if we can replace
        if (console.getSelectionStart() >= console.editStart) {
            // can replace
            fb.replace(offset, length, text, attrs);
        } else {
            // insert at end
            fb.insertString(console.getText().length(), text, attrs);
            // move cursor to the end
            console.getCaret().setDot(console.getText().length());
            // console.setSelectionEnd(console.getText().length());
            // console.setSelectionStart(console.getText().length());
        }
    } else {
        fb.replace(offset, length, text, attrs);
    }
}
 
源代码9 项目: Explvs-AIO   文件: DoubleDocumentFilter.java
@Override
public void replace(DocumentFilter.FilterBypass fb,
                    int offset,
                    int length,
                    String text,
                    AttributeSet attrs) throws BadLocationException {

    Matcher matcher = DOUBLE_REGEX.matcher(text);

    if (!matcher.matches()) {
        return;
    }

    super.replace(fb, offset, length, text, attrs);
}
 
源代码10 项目: Explvs-AIO   文件: IntegerDocumentFilter.java
@Override
public void replace(DocumentFilter.FilterBypass fb,
                    int offset,
                    int length,
                    String text,
                    AttributeSet attrs) throws BadLocationException {

    Matcher matcher = NUMBER_REGEX.matcher(text);

    if (!matcher.matches()) {
        return;
    }

    super.replace(fb, offset, length, text, attrs);
}
 
源代码11 项目: Explvs-AIO   文件: DoubleDocumentFilter.java
@Override
public void replace(DocumentFilter.FilterBypass fb,
                    int offset,
                    int length,
                    String text,
                    AttributeSet attrs) throws BadLocationException {

    Matcher matcher = DOUBLE_REGEX.matcher(text);

    if (!matcher.matches()) {
        return;
    }

    super.replace(fb, offset, length, text, attrs);
}
 
源代码12 项目: Explvs-AIO   文件: IntegerDocumentFilter.java
@Override
public void replace(DocumentFilter.FilterBypass fb,
                    int offset,
                    int length,
                    String text,
                    AttributeSet attrs) throws BadLocationException {

    Matcher matcher = NUMBER_REGEX.matcher(text);

    if (!matcher.matches()) {
        return;
    }

    super.replace(fb, offset, length, text, attrs);
}
 
源代码13 项目: netbeans   文件: SimpleTestStepLocation.java
@Override
public void replace(DocumentFilter.FilterBypass bypass,
                    int offset,
                    int length,
                    String text,
                    AttributeSet attrs) throws BadLocationException {
    if (!programmaticChange && srcGroupNameDisplayed) {
        removeSrcGroupName(bypass);
    }
    super.replace(bypass, offset, length, text, attrs);
}
 
源代码14 项目: netbeans   文件: SimpleTestStepLocation.java
@Override
public void insertString(
                    DocumentFilter.FilterBypass bypass,
                    int offset,
                    String string,
                    AttributeSet attr) throws BadLocationException {
    if (!programmaticChange && srcGroupNameDisplayed) {
        removeSrcGroupName(bypass);
    }
    super.insertString(bypass, offset, string, attr);
}
 
源代码15 项目: netbeans   文件: SimpleTestStepLocation.java
@Override
public void remove(DocumentFilter.FilterBypass bypass,
                   int offset,
                   int length) throws BadLocationException {
    if (!programmaticChange && srcGroupNameDisplayed) {
        removeSrcGroupName(bypass);
    }
    super.remove(bypass, offset, length);
}
 
源代码16 项目: netbeans   文件: SimpleTestStepLocation.java
private void removeSrcGroupName(DocumentFilter.FilterBypass bypass)
                                        throws BadLocationException {
    bypass.remove(classNameLength,
                  tfClassToTest.getText().length() - classNameLength);
    srcGroupNameDisplayed = false;
    setNavigationFilterEnabled(false);
}
 
源代码17 项目: netbeans   文件: ClassNameTextField.java
@Override
public void insertString(DocumentFilter.FilterBypass fb,
                         int offset,
                         String string,
                         AttributeSet attr) throws BadLocationException {
    String strToAdd = removeSpaces(string);
    if (strToAdd != null) {
        super.insertString(fb, offset, strToAdd, null);
    }
}
 
源代码18 项目: mts   文件: FloatDocumentFilter.java
@Override
public void insertString(DocumentFilter.FilterBypass fb, int offset, String text, AttributeSet attr) throws BadLocationException {
    String intToInsert;
    if (!Utils.isInteger(text) && !text.equals(".")){
        intToInsert = "";
    }
    else{
        intToInsert = text;
    }
    super.insertString(fb, offset, intToInsert, attr);
}
 
源代码19 项目: mts   文件: FloatDocumentFilter.java
@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);
}
 
源代码20 项目: mts   文件: JPanelNumber.java
public JPanelNumber(PropertiesEnhanced config, String name, DocumentFilter filter){
    super(config, name);
    this.filter = filter;
    this.jTextFieldValue = new JTextField();
    ((AbstractDocument) this.jTextFieldValue.getDocument()).setDocumentFilter(this.filter);        
    this.add(this.jTextFieldValue);
    this.jTextFieldValue.setEditable(true);
    this.jTextFieldValue.setVisible(true);
    this.validate();
}
 
源代码21 项目: java-swing-tips   文件: MainPanel.java
@Override public void insertString(DocumentFilter.FilterBypass fb, int offset, String text, AttributeSet attr) throws BadLocationException {
  fb.insertString(offset, text, attr);
  Element root = fb.getDocument().getDefaultRootElement();
  if (root.getElementCount() > MAX_LINES) {
    fb.remove(0, root.getElement(0).getEndOffset());
  }
}
 
@Override
public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text,
                    AttributeSet attrs) throws BadLocationException {
    if (isNumber(text))
        super.replace(fb, offset, length, text, attrs);
    else {
        java.awt.Toolkit.getDefaultToolkit().beep();
    }
}
 
源代码23 项目: runelite   文件: RuneliteColorPicker.java
/**
 * Gets the whole string from the passed DocumentFilter replace.
 */
static String getReplacedText(DocumentFilter.FilterBypass fb, int offset, int length, String str)
	throws BadLocationException
{
	Document doc = fb.getDocument();
	StringBuilder sb = new StringBuilder(doc.getText(0, doc.getLength()));
	sb.replace(offset, offset + length, str);

	return sb.toString();
}
 
源代码24 项目: java-swing-tips   文件: MainPanel.java
@Override public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
  String str = text;
  if (offset == 0 && Objects.nonNull(text) && !text.isEmpty()) {
    str = text.substring(0, 1).toUpperCase(Locale.ENGLISH) + text.substring(1);
  }
  fb.replace(offset, length, str, attrs);
}
 
源代码25 项目: binnavi   文件: CDecFormatter.java
@Override
public void insertString(final DocumentFilter.FilterBypass fb, final int offset,
    final String string, final AttributeSet attr) throws BadLocationException {
  if (isValid(string, 0)) {
    super.insertString(fb, offset, string, attr);
  }
}
 
源代码26 项目: binnavi   文件: CFilenameFormatter.java
@Override
public void insertString(final DocumentFilter.FilterBypass fb, final int offset,
    final String string, final AttributeSet attr) throws BadLocationException {
  if (isValid(string, 0)) {
    super.insertString(fb, offset, string, attr);
  }
}
 
源代码27 项目: binnavi   文件: CFilenameFormatter.java
@Override
public void replace(final DocumentFilter.FilterBypass fb, final int offset, final int length,
    final String string, final AttributeSet attr) throws BadLocationException {
  if (isValid(string, length)) {
    super.replace(fb, offset, length, string, attr);
  }
}
 
源代码28 项目: binnavi   文件: CHexFormatter.java
@Override
public void insertString(final DocumentFilter.FilterBypass fb, final int offset,
    final String string, final AttributeSet attr) throws BadLocationException {
  if (isValid(string, 0)) {
    super.insertString(fb, offset, string, attr);
  }
}
 
源代码29 项目: binnavi   文件: CHexFormatter.java
@Override
public void replace(final DocumentFilter.FilterBypass fb, final int offset, final int length,
    final String string, final AttributeSet attr) throws BadLocationException {
  if (isValid(string, length)) {
    super.replace(fb, offset, length, string, attr);
  }
}
 
源代码30 项目: java-swing-tips   文件: MainPanel.java
@Override public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
  int len = fb.getDocument().getLength();
  if (len - length + text.length() > MAX) {
    Toolkit.getDefaultToolkit().beep();
    return;
  }
  fb.replace(offset, length, text, attrs);
}
 
如果文章对您有帮助,请点击页面广告。以鼓励作者做出的努力。
 类所在包
 类方法
 同包方法