Search in sources :

Example 1 with NativeTextFigure

use of org.csstudio.opibuilder.widgets.figures.NativeTextFigure in project yamcs-studio by yamcs.

the class NativeTextEditpart method doCreateFigure.

@Override
protected IFigure doCreateFigure() {
    initFields();
    int style = SWT.NONE;
    NativeTextModel model = getWidgetModel();
    if (model.isShowNativeBorder())
        style |= SWT.BORDER;
    if (model.isMultilineInput()) {
        style |= SWT.MULTI;
        if (model.isShowHScroll())
            style |= SWT.H_SCROLL;
        if (model.isShowVScroll())
            style |= SWT.V_SCROLL;
        if (model.isWrapWords())
            style |= SWT.WRAP;
    } else {
        style |= SWT.SINGLE;
        if (model.isPasswordInput())
            style |= SWT.PASSWORD;
    }
    if (model.isReadOnly())
        style |= SWT.READ_ONLY;
    switch(model.getHorizontalAlignment()) {
        case CENTER:
            style |= SWT.CENTER;
            break;
        case LEFT:
            style |= SWT.LEFT;
            break;
        case RIGHT:
            style |= SWT.RIGHT;
        default:
            break;
    }
    final NativeTextFigure figure = new NativeTextFigure(this, style);
    text = figure.getSWTWidget();
    if (!model.isReadOnly()) {
        if (model.isMultilineInput()) {
            text.addKeyListener(new KeyAdapter() {

                @Override
                public void keyPressed(KeyEvent keyEvent) {
                    if (keyEvent.character == '\r') {
                        // Return key
                        if (text != null && !text.isDisposed() && (text.getStyle() & SWT.MULTI) != 0) {
                            if ((keyEvent.stateMask & SWT.CTRL) != 0) {
                                outputText(text.getText());
                                keyEvent.doit = false;
                                text.getShell().setFocus();
                            }
                        }
                    }
                }
            });
        } else {
            text.addListener(SWT.DefaultSelection, new Listener() {

                @Override
                public void handleEvent(Event e) {
                    outputText(text.getText());
                    switch(getWidgetModel().getFocusTraverse()) {
                        case LOSE:
                            text.getShell().setFocus();
                            break;
                        case NEXT:
                            SingleSourceHelper.swtControlTraverse(text, SWT.TRAVERSE_TAB_PREVIOUS);
                            break;
                        case PREVIOUS:
                            SingleSourceHelper.swtControlTraverse(text, SWT.TRAVERSE_TAB_NEXT);
                            break;
                        case KEEP:
                        default:
                            break;
                    }
                }
            });
        }
        // Recover text if editing aborted.
        text.addKeyListener(new KeyAdapter() {

            @Override
            public void keyPressed(KeyEvent keyEvent) {
                if (keyEvent.character == SWT.ESC) {
                    text.setText(getWidgetModel().getText());
                }
            }
        });
        text.addFocusListener(new FocusAdapter() {

            @Override
            public void focusLost(FocusEvent e) {
                if (getPV() != null)
                    text.setText(getWidgetModel().getText());
                else if (figure.isEnabled())
                    outputText(text.getText());
            }
        });
    }
    getPVWidgetEditpartDelegate().setUpdateSuppressTime(-1);
    updatePropSheet();
    return figure;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) FocusAdapter(org.eclipse.swt.events.FocusAdapter) PropertyChangeListener(java.beans.PropertyChangeListener) Listener(org.eclipse.swt.widgets.Listener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) NativeTextModel(org.csstudio.opibuilder.widgets.model.NativeTextModel) FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) KeyEvent(org.eclipse.swt.events.KeyEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) NativeTextFigure(org.csstudio.opibuilder.widgets.figures.NativeTextFigure) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 2 with NativeTextFigure

use of org.csstudio.opibuilder.widgets.figures.NativeTextFigure in project yamcs-studio by yamcs.

the class NativeTextEditpartDelegate method doCreateFigure.

@Override
public IFigure doCreateFigure() {
    int style = SWT.NONE;
    if (model.isShowNativeBorder())
        style |= SWT.BORDER;
    if (model.isMultilineInput()) {
        style |= SWT.MULTI;
        if (model.isShowHScroll())
            style |= SWT.H_SCROLL;
        if (model.isShowVScroll())
            style |= SWT.V_SCROLL;
        if (model.isWrapWords())
            style |= SWT.WRAP;
    } else {
        style |= SWT.SINGLE;
        if (model.isPasswordInput())
            style |= SWT.PASSWORD;
    }
    if (model.isReadOnly())
        style |= SWT.READ_ONLY;
    switch(model.getHorizontalAlignment()) {
        case CENTER:
            style |= SWT.CENTER;
            break;
        case LEFT:
            style |= SWT.LEFT;
            break;
        case RIGHT:
            style |= SWT.RIGHT;
        default:
            break;
    }
    final NativeTextFigure figure = new NativeTextFigure(editpart, style);
    text = figure.getSWTWidget();
    if (!model.isReadOnly()) {
        if (model.isMultilineInput()) {
            text.addKeyListener(new KeyAdapter() {

                @Override
                public void keyPressed(KeyEvent keyEvent) {
                    if (keyEvent.character == '\r') {
                        // Return key
                        if (text != null && !text.isDisposed() && (text.getStyle() & SWT.MULTI) != 0) {
                            if ((keyEvent.stateMask & SWT.CTRL) != 0) {
                                outputText(text.getText());
                                keyEvent.doit = false;
                                text.getShell().setFocus();
                            }
                        }
                    }
                }
            });
        } else {
            text.addListener(SWT.DefaultSelection, new Listener() {

                @Override
                public void handleEvent(Event e) {
                    outputText(text.getText());
                    switch(model.getFocusTraverse()) {
                        case LOSE:
                            text.getShell().setFocus();
                            break;
                        case NEXT:
                            SingleSourceHelper.swtControlTraverse(text, SWT.TRAVERSE_TAB_PREVIOUS);
                            break;
                        case PREVIOUS:
                            SingleSourceHelper.swtControlTraverse(text, SWT.TRAVERSE_TAB_NEXT);
                            break;
                        case KEEP:
                        default:
                            break;
                    }
                }
            });
            text.addTraverseListener(e -> {
                // if key code is not tab, ignore
                if (e.character != '\t' || skipTraverse)
                    return;
                e.doit = false;
                skipTraverse = true;
                if (e.stateMask == 0) {
                    SingleSourceHelper.swtControlTraverse(text, SWT.TRAVERSE_TAB_PREVIOUS);
                } else {
                    SingleSourceHelper.swtControlTraverse(text, SWT.TRAVERSE_TAB_NEXT);
                }
                skipTraverse = false;
            });
        }
        // Recover text if editing aborted.
        text.addKeyListener(new KeyAdapter() {

            @Override
            public void keyPressed(KeyEvent keyEvent) {
                if (keyEvent.character == SWT.ESC) {
                    text.setText(model.getText());
                }
            }
        });
        text.addFocusListener(new FocusAdapter() {

            @Override
            public void focusLost(FocusEvent e) {
                if (editpart.getPV() != null)
                    text.setText(model.getText());
                else if (figure.isEnabled())
                    outputText(text.getText());
            }
        });
    }
    return figure;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) FocusAdapter(org.eclipse.swt.events.FocusAdapter) PropertyChangeListener(java.beans.PropertyChangeListener) Listener(org.eclipse.swt.widgets.Listener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) KeyEvent(org.eclipse.swt.events.KeyEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) NativeTextFigure(org.csstudio.opibuilder.widgets.figures.NativeTextFigure) FocusEvent(org.eclipse.swt.events.FocusEvent)

Aggregations

PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 NativeTextFigure (org.csstudio.opibuilder.widgets.figures.NativeTextFigure)2 FocusAdapter (org.eclipse.swt.events.FocusAdapter)2 FocusEvent (org.eclipse.swt.events.FocusEvent)2 KeyAdapter (org.eclipse.swt.events.KeyAdapter)2 KeyEvent (org.eclipse.swt.events.KeyEvent)2 Event (org.eclipse.swt.widgets.Event)2 Listener (org.eclipse.swt.widgets.Listener)2 NativeTextModel (org.csstudio.opibuilder.widgets.model.NativeTextModel)1