Search in sources :

Example 21 with FocusListener

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

the class StyledTextCellEditor method createTextControl.

protected StyledText createTextControl(Composite parent) {
    TagStyleManager tagStyleManager = xliffEditor.getTagStyleManager();
    IStyle cellStyle = this.hsCellEditor.getCellStyle();
    int styled = HorizontalAlignmentEnum.getSWTStyle(cellStyle);
    styled |= SWT.MULTI | SWT.WRAP;
    viewer = new SegmentViewer(parent, styled, tagStyleManager.getTagStyle());
    // 添加标记样式改变监听
    // addTagStyleChangeListener();
    // 注册标记样式调节器
    net.heartsome.cat.ts.ui.innertag.tagstyle.TagStyleConfigurator.configure(viewer);
    // TagStyleConfigurator.configure(viewer);
    // 将原来直接创建StyledText的方式改为由TextViewer提供
    final StyledText textControl = viewer.getTextWidget();
    initStyle(textControl, cellStyle);
    textControl.addFocusListener(new FocusListener() {

        public void focusLost(FocusEvent e) {
        }

        public void focusGained(FocusEvent e) {
            getActionHandler().updateGlobalActionHandler();
        }
    });
    viewer.getDocument().addDocumentListener(new IDocumentListener() {

        public void documentChanged(DocumentEvent e) {
            // 自动行高
            autoResize();
        }

        public void documentAboutToBeChanged(DocumentEvent event) {
        }
    });
    // 实现编辑模式下添加右键菜单
    // dispose textControl前应去掉右键menu,因为右键menu是和nattable共享的,不能在这儿dispose,说见close()方法
    final Menu menu = (Menu) xliffEditor.getTable().getData(Menu.class.getName());
    textControl.setMenu(menu);
    return textControl;
}
Also used : IStyle(net.sourceforge.nattable.style.IStyle) ISegmentViewer(net.heartsome.cat.ts.ui.innertag.ISegmentViewer) SegmentViewer(net.heartsome.cat.ts.ui.innertag.SegmentViewer) StyledText(org.eclipse.swt.custom.StyledText) IDocumentListener(org.eclipse.jface.text.IDocumentListener) Menu(org.eclipse.swt.widgets.Menu) DocumentEvent(org.eclipse.jface.text.DocumentEvent) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 22 with FocusListener

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

the class CustomMatchConditionDialog method setGray.

/**
	 * 为Text控件增加灰色提醒,获得焦点时自动清除灰色提醒
	 * @param text
	 *            Text控件
	 * @param initTxt
	 *            灰色提醒字符串
	 */
private void setGray(final Text text, final String initTxt) {
    text.setForeground(gray);
    text.setText(initTxt);
    text.addFocusListener(new FocusListener() {

        public void focusLost(FocusEvent arg0) {
            if (text.getText().trim().equals("")) {
                if (!text.getForeground().equals(gray)) {
                    text.setForeground(gray);
                }
                text.setText(initTxt);
            } else {
                if (!text.getForeground().equals(black)) {
                    text.setForeground(black);
                }
            }
        }

        public void focusGained(FocusEvent arg0) {
            if (text.getText().trim().equals(initTxt)) {
                text.setText("");
                text.setForeground(black);
            } else {
                if (!text.getForeground().equals(black)) {
                    text.setForeground(black);
                }
            }
        }
    });
}
Also used : FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 23 with FocusListener

use of org.eclipse.swt.events.FocusListener 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 24 with FocusListener

use of org.eclipse.swt.events.FocusListener in project OpenGrok by OpenGrok.

the class ResultsDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    parent.setLayout(new GridLayout(1, true));
    filter = new Text(parent, SWT.FILL);
    filter.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    TextUtils.setToDefault(filter, FILTER_DEFAULT);
    filter.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            if ("".equals(filter.getText())) {
                TextUtils.setToDefault(filter, FILTER_DEFAULT);
            }
        }

        @Override
        public void focusGained(FocusEvent e) {
            TextUtils.makeEditable(filter);
        }
    });
    filter.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            viewer.refresh();
        }
    });
    return parent;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) KeyAdapter(org.eclipse.swt.events.KeyAdapter) GridData(org.eclipse.swt.layout.GridData) Text(org.eclipse.swt.widgets.Text) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 25 with FocusListener

use of org.eclipse.swt.events.FocusListener in project OpenGrok by OpenGrok.

the class ToolBarControl method createControl.

@Override
protected Control createControl(Composite parent) {
    final Text searchBox = new Text(parent, SWT.FILL | SWT.BORDER);
    TextUtils.setToDefault(searchBox, "{OpenGrok");
    searchBox.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            if (!disableFocusLostEvent) {
                TextUtils.setToDefault(searchBox, "{OpenGrok");
            }
        }

        @Override
        public void focusGained(FocusEvent e) {
            TextUtils.makeEditable(searchBox);
        }
    });
    searchBox.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
                doSearch();
            } else if (e.keyCode == SWT.ARROW_UP) {
                historyIndex++;
                if (historyIndex > history.size()) {
                    historyIndex = history.size();
                }
                if (historyIndex >= 0 && history.size() >= historyIndex) {
                    searchBox.setText(history.get(historyIndex - 1));
                }
            } else if (e.keyCode == SWT.ARROW_DOWN) {
                historyIndex--;
                if (historyIndex < 0) {
                    historyIndex = 0;
                } else if (history.size() > historyIndex) {
                    searchBox.setText(history.get(historyIndex));
                }
            } else if ((e.stateMask & SWT.CTRL) == SWT.CTRL && e.keyCode == 'v') {
                searchBox.setText("");
                searchBox.paste();
                if ((e.stateMask & SWT.SHIFT) == SWT.SHIFT) {
                    doSearch();
                }
            } else if (e.stateMask == SWT.CTRL && e.keyCode == 'c') {
                searchBox.copy();
            }
        }

        private void doSearch() {
            String text = searchBox.getText();
            if (text != null && !"".equals(text)) {
                history.add(0, text);
                historyIndex = 0;
                Rectangle bounds = searchBox.getBounds();
                Point topLeft = new Point(bounds.x, bounds.y + bounds.height);
                topLeft = searchBox.getShell().toDisplay(topLeft);
                final ResultsDialog dialog = new ResultsDialog(Display.getCurrent().getActiveShell(), text, topLeft);
                Query query = new Query(text);
                disableFocusLostEvent = true;
                query.run(dialog);
                disableFocusLostEvent = false;
            }
        }
    });
    return parent;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) Query(org.opensolaris.opengrok.egrok.query.Query) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Aggregations

FocusEvent (org.eclipse.swt.events.FocusEvent)40 FocusListener (org.eclipse.swt.events.FocusListener)40 SelectionEvent (org.eclipse.swt.events.SelectionEvent)14 GridData (org.eclipse.swt.layout.GridData)13 GridLayout (org.eclipse.swt.layout.GridLayout)10 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)9 Text (org.eclipse.swt.widgets.Text)9 ControlEvent (org.eclipse.swt.events.ControlEvent)7 ControlListener (org.eclipse.swt.events.ControlListener)7 SashForm (org.eclipse.swt.custom.SashForm)6 KeyEvent (org.eclipse.swt.events.KeyEvent)6 Composite (org.eclipse.swt.widgets.Composite)6 StyledText (org.eclipse.swt.custom.StyledText)5 DisposeEvent (org.eclipse.swt.events.DisposeEvent)5 DisposeListener (org.eclipse.swt.events.DisposeListener)5 Button (org.eclipse.swt.widgets.Button)5 Label (org.eclipse.swt.widgets.Label)5 Table (org.eclipse.swt.widgets.Table)5 TableViewer (org.eclipse.jface.viewers.TableViewer)4 KeyListener (org.eclipse.swt.events.KeyListener)4