Search in sources :

Example 11 with TextChangedEvent

use of org.eclipse.swt.custom.TextChangedEvent in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_custom_TextChangeListener method test_textChangedLorg_eclipse_swt_custom_TextChangedEvent.

@Test
public void test_textChangedLorg_eclipse_swt_custom_TextChangedEvent() {
    StyledTextContent content = styledText.getContent();
    TextChangeListener listener = new TextChangeListener() {

        @Override
        public void textChanged(TextChangedEvent event) {
            switch(verify) {
                case 1:
                    {
                        assertTrue(":1:", styledText.getText().equals("\ntesting"));
                        break;
                    }
                case 2:
                    {
                        assertTrue(":2:", styledText.getText().equals("a"));
                        break;
                    }
                case 3:
                    {
                        assertTrue(":3:", styledText.getText().equals("\n\n"));
                        break;
                    }
                case 4:
                    {
                        assertTrue(":4:", false);
                        break;
                    }
                case 5:
                    {
                        assertTrue(":5:", styledText.getText().equals("\rLine 1\r\nLine 2"));
                        break;
                    }
                case 6:
                    {
                        assertTrue(":6:", styledText.getText().equals("This\nis a test\nline 3"));
                        break;
                    }
                case 7:
                    {
                        assertTrue(":7:", styledText.getText().equals("This\n\r"));
                        break;
                    }
                case 8:
                    {
                        assertTrue(":8:", styledText.getText().equals("\nL1\r\nL2"));
                        break;
                    }
                case 9:
                    {
                        assertTrue(":9:", styledText.getText().equals("L1test"));
                        break;
                    }
                case 10:
                    {
                        assertTrue(":10:", false);
                        break;
                    }
                case 11:
                    {
                        assertTrue(":11:", false);
                        break;
                    }
                case 12:
                    {
                        assertTrue(":12:", styledText.getText().equals("L1\r\n"));
                        break;
                    }
                case 13:
                    {
                        assertTrue(":13:", styledText.getText().equals("L1\r\n"));
                        break;
                    }
                case 14:
                    {
                        assertTrue(":14:", false);
                        break;
                    }
                case 15:
                    {
                        assertTrue(":15:", styledText.getText().equals("L1test\n\n"));
                        break;
                    }
                case 16:
                    {
                        assertTrue(":16:", false);
                        break;
                    }
                case 17:
                    {
                        assertTrue(":17:", false);
                        break;
                    }
                case 18:
                    {
                        assertTrue(":18:", styledText.getText().equals("L1\r\ntest\r\n"));
                        break;
                    }
                case 19:
                    {
                        assertTrue(":19:", styledText.getText().equals("L1test\r\r\r\n"));
                        break;
                    }
                case 20:
                    {
                        assertTrue(":20:", false);
                        break;
                    }
            }
        }

        @Override
        public void textChanging(TextChangingEvent event) {
        }

        @Override
        public void textSet(TextChangedEvent event) {
        }
    };
    content.addTextChangeListener(listener);
    boolean exceptionHandled = false;
    verify = 0;
    styledText.setText("testing");
    verify = 1;
    styledText.replaceTextRange(0, 0, "\n");
    verify = 0;
    styledText.setText("\n\n");
    verify = 2;
    styledText.replaceTextRange(0, 2, "a");
    verify = 0;
    styledText.setText("a");
    verify = 3;
    styledText.replaceTextRange(0, 1, "\n\n");
    verify = 0;
    styledText.setText("L1\r\nL2\r\nL3\r\nL4\r\n");
    verify = 4;
    try {
        styledText.replaceTextRange(3, 1, "test\n");
    } catch (IllegalArgumentException ex) {
        exceptionHandled = true;
    }
    assertTrue(":4: exception not thrown", exceptionHandled);
    exceptionHandled = false;
    verify = 0;
    styledText.setText("Line 1\r\nLine 2");
    verify = 5;
    styledText.replaceTextRange(0, 0, "\r");
    verify = 0;
    styledText.setText("This\nis a test\nline 3\nline 4");
    verify = 6;
    styledText.replaceTextRange(21, 7, "");
    verify = 0;
    styledText.setText("This\nis a test\r");
    verify = 7;
    styledText.replaceTextRange(5, 9, "");
    verify = 0;
    styledText.setText("\nL1\r\nL2\r\n");
    verify = 8;
    styledText.replaceTextRange(7, 2, "");
    verify = 0;
    styledText.setText("L1\r\n");
    verify = 9;
    styledText.replaceTextRange(2, 2, "test");
    verify = 0;
    styledText.setText("L1\r\n");
    verify = 10;
    try {
        styledText.replaceTextRange(3, 1, "");
    } catch (IllegalArgumentException ex) {
        exceptionHandled = true;
    }
    assertTrue(":10: exception not thrown", exceptionHandled);
    exceptionHandled = false;
    verify = 0;
    styledText.setText("L1\r\nL2\r\nL3\r\nL4\r\n");
    verify = 11;
    try {
        styledText.replaceTextRange(1, 2, "");
    } catch (IllegalArgumentException ex) {
        exceptionHandled = true;
    }
    assertTrue(":11: exception not thrown", exceptionHandled);
    exceptionHandled = false;
    verify = 0;
    styledText.setText("L1\r");
    verify = 12;
    styledText.replaceTextRange(3, 0, "\n");
    verify = 0;
    styledText.setText("L1\n");
    verify = 13;
    styledText.replaceTextRange(2, 0, "\r");
    verify = 0;
    styledText.setText("L1\r\n");
    verify = 14;
    try {
        styledText.replaceTextRange(3, 0, "test");
    } catch (IllegalArgumentException ex) {
        exceptionHandled = true;
    }
    assertTrue(":14: exception not thrown", exceptionHandled);
    exceptionHandled = false;
    verify = 0;
    styledText.setText("L1\r\n");
    verify = 15;
    styledText.replaceTextRange(2, 2, "test\n\n");
    verify = 0;
    styledText.setText("L1\r\n");
    verify = 16;
    try {
        styledText.replaceTextRange(3, 1, "test\r\n");
    } catch (IllegalArgumentException ex) {
        exceptionHandled = true;
    }
    assertTrue(":16: exception not thrown", exceptionHandled);
    exceptionHandled = false;
    verify = 0;
    styledText.setText("L1\r\nL2\r\nL3\r\nL4\r\n");
    verify = 17;
    try {
        styledText.replaceTextRange(1, 2, "test\n\n");
    } catch (IllegalArgumentException ex) {
        exceptionHandled = true;
    }
    assertTrue(":17: exception not thrown", exceptionHandled);
    exceptionHandled = false;
    verify = 0;
    styledText.setText("L1\r");
    verify = 18;
    styledText.replaceTextRange(3, 0, "\ntest\r\n");
    verify = 0;
    styledText.setText("L1\n");
    verify = 19;
    styledText.replaceTextRange(2, 0, "test\r\r\r");
    verify = 0;
    styledText.setText("L1\r\nL2\r\nL3\r\nL4\r\n");
    verify = 20;
    try {
        styledText.replaceTextRange(3, 1, "test\n");
    } catch (IllegalArgumentException ex) {
        exceptionHandled = true;
    }
    assertTrue(":20: exception not thrown", exceptionHandled);
    exceptionHandled = false;
    content.removeTextChangeListener(listener);
}
Also used : StyledTextContent(org.eclipse.swt.custom.StyledTextContent) TextChangingEvent(org.eclipse.swt.custom.TextChangingEvent) TextChangeListener(org.eclipse.swt.custom.TextChangeListener) TextChangedEvent(org.eclipse.swt.custom.TextChangedEvent) Test(org.junit.Test)

Example 12 with TextChangedEvent

use of org.eclipse.swt.custom.TextChangedEvent in project dbeaver by serge-rider.

the class DisplayedContent method shiftLines.

/**
 * Shifts full lines of text and fills the new empty space with text
 *
 * @param text    to replace new empty lines. Its size determines the number of lines to shift
 * @param forward shifts lines either forward or backward
 */
public void shiftLines(String text, boolean forward) {
    if (text.length() == 0)
        return;
    int linesInText = (text.length() - 1) / numberOfColumns + 1;
    int currentLimit = Math.min(data.length(), linesTimesColumns);
    TextChangingEvent event = new TextChangingEvent(this);
    event.start = forward ? 0 : currentLimit;
    event.newText = text;
    event.replaceCharCount = 0;
    event.newCharCount = text.length();
    event.replaceLineCount = 0;
    event.newLineCount = linesInText;
    for (TextChangeListener myTextListener : textListeners) myTextListener.textChanging(event);
    data.insert(event.start, text);
    TextChangedEvent changedEvent = new TextChangedEvent(this);
    for (TextChangeListener myTextListener : textListeners) myTextListener.textChanged(changedEvent);
    event = new TextChangingEvent(this);
    // event.start = forward ? linesTimesColumns : 0;
    event.start = forward ? linesTimesColumns - 1 : 0;
    event.newText = "";
    event.replaceCharCount = linesInText * numberOfColumns - linesTimesColumns + currentLimit;
    event.newCharCount = 0;
    event.replaceLineCount = linesInText;
    event.newLineCount = 0;
    for (TextChangeListener myTextListener : textListeners) myTextListener.textChanging(event);
    // data.delete(event.start, event.start + event.replaceCharCount);
    if (forward)
        data.delete(linesTimesColumns, linesTimesColumns + event.replaceCharCount);
    else
        data.delete(0, event.replaceCharCount);
    changedEvent = new TextChangedEvent(this);
    for (TextChangeListener myTextListener : textListeners) myTextListener.textChanged(changedEvent);
}
Also used : TextChangingEvent(org.eclipse.swt.custom.TextChangingEvent) TextChangeListener(org.eclipse.swt.custom.TextChangeListener) TextChangedEvent(org.eclipse.swt.custom.TextChangedEvent)

Aggregations

TextChangeListener (org.eclipse.swt.custom.TextChangeListener)12 TextChangedEvent (org.eclipse.swt.custom.TextChangedEvent)12 TextChangingEvent (org.eclipse.swt.custom.TextChangingEvent)8 ExtendedModifyEvent (org.eclipse.swt.custom.ExtendedModifyEvent)3 ExtendedModifyListener (org.eclipse.swt.custom.ExtendedModifyListener)3 StyledTextContent (org.eclipse.swt.custom.StyledTextContent)3 VerifyKeyListener (org.eclipse.swt.custom.VerifyKeyListener)3 ControlEvent (org.eclipse.swt.events.ControlEvent)3 ControlListener (org.eclipse.swt.events.ControlListener)3 FocusEvent (org.eclipse.swt.events.FocusEvent)3 FocusListener (org.eclipse.swt.events.FocusListener)3 KeyEvent (org.eclipse.swt.events.KeyEvent)3 KeyListener (org.eclipse.swt.events.KeyListener)3 ModifyEvent (org.eclipse.swt.events.ModifyEvent)3 ModifyListener (org.eclipse.swt.events.ModifyListener)3 MouseEvent (org.eclipse.swt.events.MouseEvent)3 MouseListener (org.eclipse.swt.events.MouseListener)3 VerifyEvent (org.eclipse.swt.events.VerifyEvent)3 Test (org.junit.Test)3