Search in sources :

Example 1 with CaretListener

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

the class Test_org_eclipse_swt_custom_StyledText method test_addCaretListener_CaretListenerCalled.

@Test
public void test_addCaretListener_CaretListenerCalled() {
    listenerCalled = false;
    CaretListener listener = event -> listenerCalled = true;
    text.setText("Line1");
    text.addCaretListener(listener);
    text.setCaretOffset(1);
    assertTrue("Listener not called", listenerCalled);
}
Also used : Printer(org.eclipse.swt.printing.Printer) RTFTransfer(org.eclipse.swt.dnd.RTFTransfer) StyledTextContent(org.eclipse.swt.custom.StyledTextContent) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) StyledText(org.eclipse.swt.custom.StyledText) Rectangle(org.eclipse.swt.graphics.Rectangle) HashMap(java.util.HashMap) MovementEvent(org.eclipse.swt.custom.MovementEvent) TextChangeListener(org.eclipse.swt.custom.TextChangeListener) Point(org.eclipse.swt.graphics.Point) Clipboard(org.eclipse.swt.dnd.Clipboard) Event(org.eclipse.swt.widgets.Event) LineBackgroundListener(org.eclipse.swt.custom.LineBackgroundListener) VerifyListener(org.eclipse.swt.events.VerifyListener) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) Map(java.util.Map) TextTransfer(org.eclipse.swt.dnd.TextTransfer) After(org.junit.After) RGB(org.eclipse.swt.graphics.RGB) Assert.fail(org.junit.Assert.fail) BidiSegmentListener(org.eclipse.swt.custom.BidiSegmentListener) Font(org.eclipse.swt.graphics.Font) LineStyleListener(org.eclipse.swt.custom.LineStyleListener) ExtendedModifyListener(org.eclipse.swt.custom.ExtendedModifyListener) Before(org.junit.Before) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Assert.assertNotNull(org.junit.Assert.assertNotNull) MovementListener(org.eclipse.swt.custom.MovementListener) Assert.assertTrue(org.junit.Assert.assertTrue) StyleRange(org.eclipse.swt.custom.StyleRange) Caret(org.eclipse.swt.widgets.Caret) Test(org.junit.Test) GlyphMetrics(org.eclipse.swt.graphics.GlyphMetrics) Display(org.eclipse.swt.widgets.Display) CaretListener(org.eclipse.swt.custom.CaretListener) Transfer(org.eclipse.swt.dnd.Transfer) Assert.assertNull(org.junit.Assert.assertNull) Color(org.eclipse.swt.graphics.Color) BidiUtil(org.eclipse.swt.internal.BidiUtil) Assert.assertFalse(org.junit.Assert.assertFalse) ModifyListener(org.eclipse.swt.events.ModifyListener) SWT(org.eclipse.swt.SWT) ST(org.eclipse.swt.custom.ST) FontData(org.eclipse.swt.graphics.FontData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Assert.assertEquals(org.junit.Assert.assertEquals) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) CaretListener(org.eclipse.swt.custom.CaretListener) Test(org.junit.Test)

Example 2 with CaretListener

use of org.eclipse.swt.custom.CaretListener in project otertool by wuntee.

the class CTabItemWithHexViewer method addListeners.

private void addListeners(final StyledText txt) {
    txt.addMouseWheelListener(new MouseWheelListener() {

        public void mouseScrolled(MouseEvent arg0) {
            binContent.setTopIndex(txt.getTopIndex());
            hexContent.setTopIndex(txt.getTopIndex());
            counter.setTopIndex(txt.getTopIndex());
        }
    });
    txt.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent arg0) {
            binContent.setTopIndex(txt.getTopIndex());
            hexContent.setTopIndex(txt.getTopIndex());
            counter.setTopIndex(txt.getTopIndex());
        }

        public void widgetSelected(SelectionEvent arg0) {
            binContent.setTopIndex(txt.getTopIndex());
            hexContent.setTopIndex(txt.getTopIndex());
            counter.setTopIndex(txt.getTopIndex());
        }
    });
    txt.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent arg0) {
            binContent.setTopIndex(txt.getTopIndex());
            hexContent.setTopIndex(txt.getTopIndex());
            counter.setTopIndex(txt.getTopIndex());
        }
    });
    txt.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent arg0) {
            binContent.setTopIndex(txt.getTopIndex());
            hexContent.setTopIndex(txt.getTopIndex());
            counter.setTopIndex(txt.getTopIndex());
        }
    });
    txt.addCaretListener(new CaretListener() {

        public void caretMoved(CaretEvent arg0) {
            binContent.setTopIndex(txt.getTopIndex());
            hexContent.setTopIndex(txt.getTopIndex());
            counter.setTopIndex(txt.getTopIndex());
        }
    });
    txt.addDragDetectListener(new DragDetectListener() {

        public void dragDetected(DragDetectEvent arg0) {
            binContent.setTopIndex(txt.getTopIndex());
            hexContent.setTopIndex(txt.getTopIndex());
            counter.setTopIndex(txt.getTopIndex());
        }
    });
    ScrollBar vbar = txt.getVerticalBar();
    if (vbar != null) {
        vbar.addListener(SWT.Selection, new Listener() {

            public void handleEvent(Event arg0) {
                binContent.setTopIndex(txt.getTopIndex());
                hexContent.setTopIndex(txt.getTopIndex());
                counter.setTopIndex(txt.getTopIndex());
            }
        });
    }
}
Also used : CaretEvent(org.eclipse.swt.custom.CaretEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) DragDetectListener(org.eclipse.swt.events.DragDetectListener) Listener(org.eclipse.swt.widgets.Listener) MouseWheelListener(org.eclipse.swt.events.MouseWheelListener) CaretListener(org.eclipse.swt.custom.CaretListener) SelectionListener(org.eclipse.swt.events.SelectionListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) MouseWheelListener(org.eclipse.swt.events.MouseWheelListener) DragDetectListener(org.eclipse.swt.events.DragDetectListener) KeyEvent(org.eclipse.swt.events.KeyEvent) CaretListener(org.eclipse.swt.custom.CaretListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DragDetectEvent(org.eclipse.swt.events.DragDetectEvent) DragDetectEvent(org.eclipse.swt.events.DragDetectEvent) Event(org.eclipse.swt.widgets.Event) KeyEvent(org.eclipse.swt.events.KeyEvent) CaretEvent(org.eclipse.swt.custom.CaretEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScrollBar(org.eclipse.swt.widgets.ScrollBar) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 3 with CaretListener

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

the class Test_org_eclipse_swt_custom_StyledText method test_removeCaretListener_CaretListenerNotCalled.

@Test
public void test_removeCaretListener_CaretListenerNotCalled() {
    listenerCalled = false;
    CaretListener listener = event -> listenerCalled = true;
    text.addCaretListener(listener);
    text.removeCaretListener(listener);
    text.setCaretOffset(1);
    assertFalse("Listener not removed", listenerCalled);
}
Also used : Printer(org.eclipse.swt.printing.Printer) RTFTransfer(org.eclipse.swt.dnd.RTFTransfer) StyledTextContent(org.eclipse.swt.custom.StyledTextContent) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) StyledText(org.eclipse.swt.custom.StyledText) Rectangle(org.eclipse.swt.graphics.Rectangle) HashMap(java.util.HashMap) MovementEvent(org.eclipse.swt.custom.MovementEvent) TextChangeListener(org.eclipse.swt.custom.TextChangeListener) Point(org.eclipse.swt.graphics.Point) Clipboard(org.eclipse.swt.dnd.Clipboard) Event(org.eclipse.swt.widgets.Event) LineBackgroundListener(org.eclipse.swt.custom.LineBackgroundListener) VerifyListener(org.eclipse.swt.events.VerifyListener) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) Map(java.util.Map) TextTransfer(org.eclipse.swt.dnd.TextTransfer) After(org.junit.After) RGB(org.eclipse.swt.graphics.RGB) Assert.fail(org.junit.Assert.fail) BidiSegmentListener(org.eclipse.swt.custom.BidiSegmentListener) Font(org.eclipse.swt.graphics.Font) LineStyleListener(org.eclipse.swt.custom.LineStyleListener) ExtendedModifyListener(org.eclipse.swt.custom.ExtendedModifyListener) Before(org.junit.Before) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Assert.assertNotNull(org.junit.Assert.assertNotNull) MovementListener(org.eclipse.swt.custom.MovementListener) Assert.assertTrue(org.junit.Assert.assertTrue) StyleRange(org.eclipse.swt.custom.StyleRange) Caret(org.eclipse.swt.widgets.Caret) Test(org.junit.Test) GlyphMetrics(org.eclipse.swt.graphics.GlyphMetrics) Display(org.eclipse.swt.widgets.Display) CaretListener(org.eclipse.swt.custom.CaretListener) Transfer(org.eclipse.swt.dnd.Transfer) Assert.assertNull(org.junit.Assert.assertNull) Color(org.eclipse.swt.graphics.Color) BidiUtil(org.eclipse.swt.internal.BidiUtil) Assert.assertFalse(org.junit.Assert.assertFalse) ModifyListener(org.eclipse.swt.events.ModifyListener) SWT(org.eclipse.swt.SWT) ST(org.eclipse.swt.custom.ST) FontData(org.eclipse.swt.graphics.FontData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Assert.assertEquals(org.junit.Assert.assertEquals) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) CaretListener(org.eclipse.swt.custom.CaretListener) Test(org.junit.Test)

Example 4 with CaretListener

use of org.eclipse.swt.custom.CaretListener in project watchdog by TestRoots.

the class EditorListener method listenToEditorScrolling.

private void listenToEditorScrolling() {
    styledText = (StyledText) editor.getAdapter(Control.class);
    if (styledText == null) {
        return;
    }
    // creates a listener for when the user moves the caret (cursor)
    caretListener = new CaretListener() {

        @Override
        public void caretMoved(CaretEvent event) {
            WatchDogEventType.CARET_MOVED.process(editor);
        // cursor place changed
        }
    };
    styledText.addCaretListener(caretListener);
    // creates a listener for redraws of the view, e.g. when scrolled
    paintListener = new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            WatchDogEventType.PAINT.process(editor);
        }
    };
    styledText.addPaintListener(paintListener);
    focusListener = new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
        }

        @Override
        public void focusGained(FocusEvent e) {
            WatchDogEventType.ACTIVE_FOCUS.process(editor);
        }
    };
    styledText.addFocusListener(focusListener);
}
Also used : CaretEvent(org.eclipse.swt.custom.CaretEvent) CaretListener(org.eclipse.swt.custom.CaretListener) PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Aggregations

CaretListener (org.eclipse.swt.custom.CaretListener)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 SelectionListener (org.eclipse.swt.events.SelectionListener)3 Event (org.eclipse.swt.widgets.Event)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 SWT (org.eclipse.swt.SWT)2 BidiSegmentListener (org.eclipse.swt.custom.BidiSegmentListener)2 CaretEvent (org.eclipse.swt.custom.CaretEvent)2 ExtendedModifyListener (org.eclipse.swt.custom.ExtendedModifyListener)2 LineBackgroundListener (org.eclipse.swt.custom.LineBackgroundListener)2 LineStyleListener (org.eclipse.swt.custom.LineStyleListener)2 MovementEvent (org.eclipse.swt.custom.MovementEvent)2 MovementListener (org.eclipse.swt.custom.MovementListener)2 ST (org.eclipse.swt.custom.ST)2 StyleRange (org.eclipse.swt.custom.StyleRange)2 StyledText (org.eclipse.swt.custom.StyledText)2 StyledTextContent (org.eclipse.swt.custom.StyledTextContent)2 TextChangeListener (org.eclipse.swt.custom.TextChangeListener)2 VerifyKeyListener (org.eclipse.swt.custom.VerifyKeyListener)2