Example usage for javax.swing.text AbstractDocument remove

List of usage examples for javax.swing.text AbstractDocument remove

Introduction

In this page you can find the example usage for javax.swing.text AbstractDocument remove.

Prototype

public void remove(int offs, int len) throws BadLocationException 

Source Link

Document

Removes some content from the document.

Usage

From source file:nl.xs4all.home.freekdb.b52reader.gui.MainGuiTest.java

private void testFilter(FilterTestType testType)
        throws BadLocationException, InterruptedException, ReflectiveOperationException {
    MainGui mainGui = new MainGui(mockManyBrowsersPanel);
    mainGui.setMainCallbacks(mockMainCallbacks);

    Mockito.when(mockConfiguration.useSpanTable()).thenReturn(testType == CHANGE_TEXT);

    mainGui.initializeBackgroundBrowsersPanel(mockFrame, mockConfiguration);
    mainGui.initializeGui(TestUtilities.getSixTestArticles());

    waitForGuiTasks();/*from   w  w w  .  ja  v  a2  s.  c  o  m*/

    JTable table = (JTable) findComponent(mockContentPane, JTable.class);
    assertNotNull(table);

    assertEquals(mockConfiguration.useSpanTable() ? 12 : 6, table.getRowCount());

    JTextField filterTextField = (JTextField) findComponent(mockContentPane, JTextField.class);
    assertNotNull(filterTextField);
    AbstractDocument document = (AbstractDocument) filterTextField.getDocument();

    document.insertString(0, "title:title1", null);

    assertEquals(mockConfiguration.useSpanTable() ? 2 : 1, table.getRowCount());

    if (testType == REMOVE_TEXT) {
        document.remove(0, document.getLength());
    } else if (testType == CHANGE_TEXT) {
        document.replace(6, 6, "title2", null);

        // Since change is implemented as remove and insert, the fireChangedUpdate method is called with reflection.
        AbstractDocument.DefaultDocumentEvent mockEvent = Mockito
                .mock(AbstractDocument.DefaultDocumentEvent.class);
        Method method = AbstractDocument.class.getDeclaredMethod("fireChangedUpdate", DocumentEvent.class);
        method.setAccessible(true);
        method.invoke(document, mockEvent);
    } else if (testType == NO_MATCHES) {
        document.insertString(document.getLength(), "-some-nonsense", null);
    }

    checkArticlesInGui(testType, mainGui, table.getRowCount());
}