Search in sources :

Example 21 with TraverseEvent

use of org.eclipse.swt.events.TraverseEvent in project translationstudio8 by heartsome.

the class Grid method initListeners.

/**
     * Initialize all listeners.
     */
private void initListeners() {
    disposeListener = new Listener() {

        public void handleEvent(Event e) {
            onDispose(e);
        }
    };
    addListener(SWT.Dispose, disposeListener);
    addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent e) {
            onPaint(e);
        }
    });
    addListener(SWT.Resize, new Listener() {

        public void handleEvent(Event e) {
            onResize();
        }
    });
    if (getVerticalBar() != null) {
        getVerticalBar().addListener(SWT.Selection, new Listener() {

            public void handleEvent(Event e) {
                onScrollSelection();
            }
        });
    }
    if (getHorizontalBar() != null) {
        getHorizontalBar().addListener(SWT.Selection, new Listener() {

            public void handleEvent(Event e) {
                onScrollSelection();
            }
        });
    }
    addListener(SWT.KeyDown, new Listener() {

        public void handleEvent(Event e) {
            onKeyDown(e);
        }
    });
    addTraverseListener(new TraverseListener() {

        public void keyTraversed(TraverseEvent e) {
            e.doit = true;
        }
    });
    addMouseListener(new MouseListener() {

        public void mouseDoubleClick(MouseEvent e) {
            onMouseDoubleClick(e);
        }

        public void mouseDown(MouseEvent e) {
            onMouseDown(e);
        }

        public void mouseUp(MouseEvent e) {
            onMouseUp(e);
        }
    });
    addMouseMoveListener(new MouseMoveListener() {

        public void mouseMove(MouseEvent e) {
            onMouseMove(e);
        }
    });
    addMouseTrackListener(new MouseTrackListener() {

        public void mouseEnter(MouseEvent e) {
        }

        public void mouseExit(MouseEvent e) {
            onMouseExit(e);
        }

        public void mouseHover(MouseEvent e) {
        }
    });
    addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent e) {
            onFocusIn();
            redraw();
        }

        public void focusLost(FocusEvent e) {
            redraw();
        }
    });
    // Special code to reflect mouse wheel events if using an external
    // scroller
    addListener(SWT.MouseWheel, new Listener() {

        public void handleEvent(Event e) {
            onMouseWheel(e);
        }
    });
}
Also used : MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) TraverseListener(org.eclipse.swt.events.TraverseListener) MouseListener(org.eclipse.swt.events.MouseListener) MouseTrackListener(org.eclipse.swt.events.MouseTrackListener) SelectionListener(org.eclipse.swt.events.SelectionListener) PaintListener(org.eclipse.swt.events.PaintListener) FocusListener(org.eclipse.swt.events.FocusListener) TypedListener(org.eclipse.swt.widgets.TypedListener) Listener(org.eclipse.swt.widgets.Listener) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) TreeListener(org.eclipse.swt.events.TreeListener) PaintEvent(org.eclipse.swt.events.PaintEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) MouseListener(org.eclipse.swt.events.MouseListener) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintListener(org.eclipse.swt.events.PaintListener) TraverseListener(org.eclipse.swt.events.TraverseListener) MouseTrackListener(org.eclipse.swt.events.MouseTrackListener) FocusEvent(org.eclipse.swt.events.FocusEvent) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) AccessibleEvent(org.eclipse.swt.accessibility.AccessibleEvent) Event(org.eclipse.swt.widgets.Event) AccessibleControlEvent(org.eclipse.swt.accessibility.AccessibleControlEvent) TreeEvent(org.eclipse.swt.events.TreeEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 22 with TraverseEvent

use of org.eclipse.swt.events.TraverseEvent in project cubrid-manager by CUBRID.

the class FavoriteQueryNavigatorView method focusCell.

public void focusCell(final TableItem item, final int row, final int col) {
    final StyledText text = new StyledText(tv.getTable(), SWT.SINGLE);
    Listener textListener = new TableItemEditor(text, item, row, col);
    text.addListener(SWT.FocusOut, textListener);
    text.addListener(SWT.Traverse, textListener);
    text.addListener(SWT.FocusIn, textListener);
    text.addTraverseListener(new TraverseListener() {

        public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_TAB_NEXT || e.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
                e.doit = false;
                int newColumn = col == 0 ? 1 : 0;
                focusCell(item, row, newColumn);
            } else if (e.detail == SWT.TRAVERSE_RETURN) {
                e.doit = false;
                addButton.setFocus();
            }
        }
    });
    text.setEditable(true);
    editor.setEditor(text, item, col);
    text.setText(item.getText(col));
    text.selectAll();
    try {
        text.setFocus();
    } catch (Exception e) {
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) TraverseListener(org.eclipse.swt.events.TraverseListener) MenuListener(org.eclipse.swt.events.MenuListener) SelectionListener(org.eclipse.swt.events.SelectionListener) Listener(org.eclipse.swt.widgets.Listener) TraverseEvent(org.eclipse.swt.events.TraverseEvent) TraverseListener(org.eclipse.swt.events.TraverseListener) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException)

Example 23 with TraverseEvent

use of org.eclipse.swt.events.TraverseEvent in project cubrid-manager by CUBRID.

the class ProductInfoDialog method addListeners.

/**
	 * Adds listeners to the given styled text
	 * 
	 * @param styledText the StyledText object
	 */
protected void addListeners(StyledText styledText) {
    styledText.addMouseListener(new MouseAdapter() {

        public void mouseDown(MouseEvent event) {
            if (event.button != 1) {
                return;
            }
            mouseDown = true;
        }

        public void mouseUp(MouseEvent event) {
            mouseDown = false;
            StyledText text = (StyledText) event.widget;
            int offset = text.getCaretOffset();
            if (dragEvent) {
                // don't activate a link during a drag/mouse up operation
                dragEvent = false;
                if (item != null && item.isLinkAt(offset)) {
                    text.setCursor(handCursor);
                }
            } else if (item != null && item.isLinkAt(offset)) {
                text.setCursor(busyCursor);
                String url = item.getLinkAt(offset);
                if (StringUtil.isEmpty(url)) {
                    LOGGER.warn("The url is a null or empty string : {}.", url);
                } else {
                    openLink(url);
                }
                StyleRange selectionRange = getCurrentRange(text);
                if (selectionRange == null) {
                    LOGGER.warn("The selectionRange is a null.");
                } else {
                    text.setSelectionRange(selectionRange.start, selectionRange.length);
                    text.setCursor(null);
                }
            }
        }
    });
    styledText.addMouseMoveListener(new MouseMoveListener() {

        public void mouseMove(MouseEvent event) {
            if (mouseDown) {
                if (!dragEvent) {
                    StyledText text = (StyledText) event.widget;
                    text.setCursor(null);
                }
                dragEvent = true;
                return;
            }
            StyledText text = (StyledText) event.widget;
            int offset = -1;
            try {
                offset = text.getOffsetAtLocation(new Point(event.x, event.y));
            } catch (IllegalArgumentException ex) {
                offset = -1;
            }
            if (offset == -1) {
                text.setCursor(null);
            } else if (item != null && item.isLinkAt(offset)) {
                text.setCursor(handCursor);
            } else {
                text.setCursor(null);
            }
        }
    });
    styledText.addTraverseListener(new TraverseListener() {

        public void keyTraversed(TraverseEvent event) {
            StyledText text = (StyledText) event.widget;
            switch(event.detail) {
                case SWT.TRAVERSE_ESCAPE:
                    event.doit = true;
                    break;
                case SWT.TRAVERSE_TAB_NEXT:
                    // Previously traverse out in the backward direction?
                    Point nextSelection = text.getSelection();
                    int charCount = text.getCharCount();
                    if ((nextSelection.x == charCount) && (nextSelection.y == charCount)) {
                        text.setSelection(0);
                    }
                    StyleRange nextRange = findNextRange(text);
                    if (nextRange == null) {
                        // Next time in start at beginning, also used by
                        // TRAVERSE_TAB_PREVIOUS to indicate we traversed out
                        // in the forward direction
                        text.setSelection(0);
                        event.doit = true;
                    } else {
                        text.setSelectionRange(nextRange.start, nextRange.length);
                        event.doit = true;
                        event.detail = SWT.TRAVERSE_NONE;
                    }
                    break;
                case SWT.TRAVERSE_TAB_PREVIOUS:
                    // Previously traverse out in the forward direction?
                    Point previousSelection = text.getSelection();
                    if ((previousSelection.x == 0) && (previousSelection.y == 0)) {
                        text.setSelection(text.getCharCount());
                    }
                    StyleRange previousRange = findPreviousRange(text);
                    if (previousRange == null) {
                        // Next time in start at the end, also used by
                        // TRAVERSE_TAB_NEXT to indicate we traversed out
                        // in the backward direction
                        text.setSelection(text.getCharCount());
                        event.doit = true;
                    } else {
                        text.setSelectionRange(previousRange.start, previousRange.length);
                        event.doit = true;
                        event.detail = SWT.TRAVERSE_NONE;
                    }
                    break;
                default:
                    break;
            }
        }
    });
    // Listen for Tab and Space to allow keyboard navigation
    styledText.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent event) {
            StyledText text = (StyledText) event.widget;
            if (event.character == ' ' || event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) {
                if (item == null) {
                    LOGGER.warn("AboutItem is a null.");
                    return;
                }
                // Be sure we are in the selection
                int offset = text.getSelection().x + 1;
                if (item.isLinkAt(offset)) {
                    text.setCursor(busyCursor);
                    String url = item.getLinkAt(offset);
                    if (StringUtil.isEmpty(url)) {
                        LOGGER.warn("The url is a null or empty string : {}.", url);
                    } else {
                        openLink(url);
                    }
                    StyleRange selectionRange = getCurrentRange(text);
                    if (selectionRange == null) {
                        LOGGER.warn("The selectionRange is a null.");
                    } else {
                        text.setSelectionRange(selectionRange.start, selectionRange.length);
                        text.setCursor(null);
                    }
                }
            }
        }
    });
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) MouseEvent(org.eclipse.swt.events.MouseEvent) StyledText(org.eclipse.swt.custom.StyledText) TraverseEvent(org.eclipse.swt.events.TraverseEvent) TraverseListener(org.eclipse.swt.events.TraverseListener) StyleRange(org.eclipse.swt.custom.StyleRange) KeyAdapter(org.eclipse.swt.events.KeyAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Point(org.eclipse.swt.graphics.Point)

Example 24 with TraverseEvent

use of org.eclipse.swt.events.TraverseEvent in project cubrid-manager by CUBRID.

the class DataTypeCellEditor method createControl.

protected Control createControl(Composite parent) {
    comboBox = new DataTypeCombo(parent, getStyle());
    comboBox.setFont(parent.getFont());
    populateComboBoxItems();
    //		comboBox.addKeyListener(new KeyAdapter() {
    //			public void keyPressed(KeyEvent event) {
    //				if (event.character == '\r') {
    //					applyEditorValueAndDeactivate();
    //				}
    //				keyReleaseOccured(event);
    //			}
    //
    //			public void keyReleased(KeyEvent event) {
    //			}
    //		});
    comboBox.addModifyListener(getModifyListener());
    comboBox.addSelectionListener(new SelectionAdapter() {

        public void widgetDefaultSelected(SelectionEvent event) {
            applyEditorValueAndDeactivate();
        }

        public void widgetSelected(SelectionEvent event) {
            value = comboBox.getText();
        }
    });
    comboBox.addTraverseListener(new TraverseListener() {

        public void keyTraversed(TraverseEvent event) {
            if (event.detail == SWT.TRAVERSE_ESCAPE || event.detail == SWT.TRAVERSE_RETURN) {
                event.doit = false;
            }
        }
    });
    comboBox.addFocusListener(new FocusAdapter() {

        public void focusLost(FocusEvent event) {
            applyEditorValueAndDeactivate();
            DataTypeCellEditor.this.focusLost();
        }
    });
    return comboBox;
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) TraverseEvent(org.eclipse.swt.events.TraverseEvent) TraverseListener(org.eclipse.swt.events.TraverseListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 25 with TraverseEvent

use of org.eclipse.swt.events.TraverseEvent in project cubrid-manager by CUBRID.

the class BatchRunComposite method focusCell.

public void focusCell(final TableItem item, final int row, final int col) {
    final StyledText text = new StyledText(tv.getTable(), SWT.SINGLE);
    Listener textListener = new TableItemEditor(text, item, row, col);
    text.addListener(SWT.FocusOut, textListener);
    text.addListener(SWT.Traverse, textListener);
    text.addListener(SWT.FocusIn, textListener);
    text.addTraverseListener(new TraverseListener() {

        public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_TAB_NEXT || e.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
                e.doit = false;
                int newColumn = col == 0 ? 1 : 0;
                focusCell(item, row, newColumn);
            } else if (e.detail == SWT.TRAVERSE_RETURN) {
                e.doit = false;
                addButton.setFocus();
            }
        }
    });
    text.setEditable(true);
    editor.setEditor(text, item, col);
    text.setText(item.getText(col));
    text.selectAll();
    try {
        text.setFocus();
    } catch (Exception e) {
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Listener(org.eclipse.swt.widgets.Listener) TraverseListener(org.eclipse.swt.events.TraverseListener) TraverseEvent(org.eclipse.swt.events.TraverseEvent) TraverseListener(org.eclipse.swt.events.TraverseListener)

Aggregations

TraverseEvent (org.eclipse.swt.events.TraverseEvent)26 TraverseListener (org.eclipse.swt.events.TraverseListener)26 FocusAdapter (org.eclipse.swt.events.FocusAdapter)9 FocusEvent (org.eclipse.swt.events.FocusEvent)8 SelectionEvent (org.eclipse.swt.events.SelectionEvent)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)7 Text (org.eclipse.swt.widgets.Text)7 StyledText (org.eclipse.swt.custom.StyledText)6 ModifyEvent (org.eclipse.swt.events.ModifyEvent)6 ModifyListener (org.eclipse.swt.events.ModifyListener)6 MouseEvent (org.eclipse.swt.events.MouseEvent)6 Point (org.eclipse.swt.graphics.Point)6 Button (org.eclipse.swt.widgets.Button)6 KeyEvent (org.eclipse.swt.events.KeyEvent)5 MouseAdapter (org.eclipse.swt.events.MouseAdapter)5 Composite (org.eclipse.swt.widgets.Composite)5 GridData (org.eclipse.swt.layout.GridData)4 Label (org.eclipse.swt.widgets.Label)4 ComboWithEnableFix (edu.cmu.cs.hcii.cogtool.util.ComboWithEnableFix)3 TextWithEnableFix (edu.cmu.cs.hcii.cogtool.util.TextWithEnableFix)3