DocumentFilter
DocumentFilter (문서 필터)
Document 안에서 삽입(insert)과 제거(remove) 같은 변경 연산을 거르는(filter) 데 사용되는 추상 클래스입니다.
본문
DocumentFilter를 포함하는 Document가 변경되면(insert 또는 remove를 통해) 적절한 메서드 호출이 DocumentFilter로 전달됩니다. 기본 구현은 변경이 일어나도록 허용합니다.
하위 클래스는 상위 클래스의 메서드를 조건부로 호출하거나 전달된 FilterBypass에 필요한 메서드를 호출해 변경을 거를 수 있습니다. 하위 클래스는 변경을 위해 Document로 다시 콜백해서는 안 되며, 대신 상위 클래스나 FilterBypass를 호출해야 합니다.
기본적으로 AbstractDocument의 insertString, replace, remove 같은 텍스트 관련 변경 메서드는 가능하면 DocumentFilter를 사용하지만, DefaultStyledDocument의 create, insert, removeElement 같은 요소 관련 변경 메서드는 DocumentFilter를 사용하지 않습니다.
중첩 클래스로 DocumentFilter.FilterBypass가 있으며, Document로 다시 호출하지 않고도 변경하는 방법을 제공합니다. Since: 1.4
주요 메서드·상세 (Methods & details)
주요 메서드는 텍스트 변경을 시도하는 insertString(FilterBypass, int, String, AttributeSet)/remove(FilterBypass, int, int)/replace(FilterBypass, int, int, String, AttributeSet)입니다. 하위 클래스는 이 메서드를 오버라이드해 허용 여부를 결정하고, FilterBypass를 통해 실제 변경을 수행합니다.