Search in sources :

Example 26 with ControlAdapter

use of org.eclipse.swt.events.ControlAdapter in project eclipse.platform.text by eclipse.

the class FindReplaceDialog method createContents.

@Override
protected Control createContents(Composite parent) {
    Composite panel = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    layout.makeColumnsEqualWidth = true;
    panel.setLayout(layout);
    setGridData(panel, SWT.FILL, true, SWT.FILL, true);
    ScrolledComposite scrolled = new ScrolledComposite(panel, SWT.V_SCROLL);
    setGridData(scrolled, SWT.FILL, true, SWT.FILL, true);
    Composite mainArea = new Composite(scrolled, SWT.NONE);
    setGridData(mainArea, SWT.FILL, true, SWT.FILL, true);
    mainArea.setLayout(new GridLayout(1, true));
    Composite inputPanel = createInputPanel(mainArea);
    setGridData(inputPanel, SWT.FILL, true, SWT.TOP, false);
    Composite configPanel = createConfigPanel(mainArea);
    setGridData(configPanel, SWT.FILL, true, SWT.TOP, true);
    scrolled.setContent(mainArea);
    scrolled.setExpandHorizontal(true);
    scrolled.setExpandVertical(true);
    scrolled.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            scrolled.setMinHeight(mainArea.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
        }
    });
    Composite buttonPanelB = createButtonSection(panel);
    setGridData(buttonPanelB, SWT.RIGHT, true, SWT.BOTTOM, false);
    Composite statusBar = createStatusAndCloseButton(panel);
    setGridData(statusBar, SWT.FILL, true, SWT.BOTTOM, false);
    panel.addTraverseListener(new TraverseListener() {

        @Override
        public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_RETURN) {
                if (!Util.isMac()) {
                    Control controlWithFocus = getShell().getDisplay().getFocusControl();
                    if (controlWithFocus != null && (controlWithFocus.getStyle() & SWT.PUSH) == SWT.PUSH)
                        return;
                }
                Event event = new Event();
                event.type = SWT.Selection;
                event.stateMask = e.stateMask;
                fFindNextButton.notifyListeners(SWT.Selection, event);
                e.doit = false;
            } else if (e.detail == SWT.TRAVERSE_MNEMONIC) {
                Character mnemonic = Character.valueOf(Character.toLowerCase(e.character));
                if (fMnemonicButtonMap.containsKey(mnemonic)) {
                    Button button = fMnemonicButtonMap.get(mnemonic);
                    if ((fFindField.isFocusControl() || fReplaceField.isFocusControl() || (button.getStyle() & SWT.PUSH) != 0) && button.isEnabled()) {
                        Event event = new Event();
                        event.type = SWT.Selection;
                        event.stateMask = e.stateMask;
                        if ((button.getStyle() & SWT.RADIO) != 0) {
                            Composite buttonParent = button.getParent();
                            if (buttonParent != null) {
                                Control[] children = buttonParent.getChildren();
                                for (int i = 0; i < children.length; i++) ((Button) children[i]).setSelection(false);
                            }
                            button.setSelection(true);
                        } else {
                            button.setSelection(!button.getSelection());
                        }
                        button.notifyListeners(SWT.Selection, event);
                        e.detail = SWT.TRAVERSE_NONE;
                        e.doit = true;
                    }
                }
            }
        }
    });
    updateButtonState();
    applyDialogFont(panel);
    return panel;
}
Also used : TraverseEvent(org.eclipse.swt.events.TraverseEvent) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) TraverseListener(org.eclipse.swt.events.TraverseListener) Point(org.eclipse.swt.graphics.Point) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) TraverseEvent(org.eclipse.swt.events.TraverseEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 27 with ControlAdapter

use of org.eclipse.swt.events.ControlAdapter in project yamcs-studio by yamcs.

the class ContentProposalPopup method createDialogArea.

/*
     * Creates the content area for the proposal popup. This creates a table and places it inside the composite. The
     * table will contain a list of all the proposals.
     *
     * @param parent The parent composite to contain the dialog area; must not be <code>null</code>.
     */
@Override
protected final Control createDialogArea(final Composite parent) {
    Composite wrapper = (Composite) super.createDialogArea(parent);
    wrapper.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    wrapper.setLayout(new GridLayout());
    // Use virtual where appropriate (see flag definition).
    if (USE_VIRTUAL) {
        proposalTable = new Table(wrapper, SWT.H_SCROLL | SWT.V_SCROLL | SWT.VIRTUAL | SWT.NO_FOCUS);
        Listener listener = new Listener() {

            @Override
            public void handleEvent(Event event) {
                handleSetData(event);
            }
        };
        proposalTable.addListener(SWT.SetData, listener);
        proposalTable.addListener(SWTPaintItem, new Listener() {

            @Override
            public void handleEvent(Event event) {
                TableItem item = (TableItem) event.item;
                int index = proposalTable.indexOf(item);
                if (textLayouts != null && index < textLayouts.length && textLayouts[index] != null) {
                    textLayouts[index].handlePaintItemEvent(event, 20, 2);
                }
                Proposal p = (Proposal) item.getData();
                Image image = getImage(p, index == proposalTable.getSelectionIndex());
                if (image != null)
                    event.gc.drawImage(image, event.x, event.y + 2);
            }
        });
        proposalTable.addListener(SWTMeasureItem, new Listener() {

            @Override
            public void handleEvent(Event event) {
                TableItem item = (TableItem) event.item;
                int index = proposalTable.indexOf(item);
                if (textLayouts != null && index < textLayouts.length && textLayouts[index] != null) {
                    textLayouts[index].handleMeasureItemEvent(event);
                }
            }
        });
    } else {
        proposalTable = new Table(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.NO_FOCUS);
    }
    footer = new Text(wrapper, SWT.READ_ONLY | SWT.WRAP | SWT.NO_FOCUS);
    GridData textGridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
    textGridData.heightHint = FOOTER_MINIMUM_HEIGHT;
    textGridData.widthHint = 100;
    footer.setLayoutData(textGridData);
    // set the proposals to force population of the table.
    setProposals(proposalList);
    proposalTable.setHeaderVisible(false);
    proposalTable.addListener(SWT.KeyDown, new Listener() {

        @Override
        public void handleEvent(Event e) {
            getTargetControlListener().handleEvent(e);
        }
    });
    proposalTable.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // popup. Otherwise close the popup.
            if (e.item == null) {
                if (infoPopup != null)
                    infoPopup.close();
            } else {
                Proposal proposal = (Proposal) e.item.getData();
                if (proposal != null) {
                    showProposalDescription();
                    adapter.proposalSelected(proposal);
                } else {
                    if (infoPopup != null)
                        infoPopup.close();
                    proposalTable.deselectAll();
                }
            }
        }

        // Default selection was made. Accept the current proposal.
        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            Proposal proposal = (Proposal) e.item.getData();
            if (proposal != null) {
                acceptCurrentProposal(true);
            } else {
                proposalTable.deselectAll();
            }
        }
    });
    // Added to solve a item resize bug on windows:
    new TableColumn(proposalTable, SWT.NONE | SWT.NO_FOCUS);
    proposalTable.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent event) {
            if (proposalTable.getColumnCount() > 0) {
                if (proposalTable.getClientArea().width > maxItemWidth) {
                    proposalTable.getColumn(0).setWidth(proposalTable.getClientArea().width);
                } else {
                    proposalTable.getColumn(0).setWidth(maxItemWidth);
                }
            }
        }
    });
    return proposalTable;
}
Also used : Table(org.eclipse.swt.widgets.Table) DisposeListener(org.eclipse.swt.events.DisposeListener) Listener(org.eclipse.swt.widgets.Listener) SelectionListener(org.eclipse.swt.events.SelectionListener) Composite(org.eclipse.swt.widgets.Composite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) TableItem(org.eclipse.swt.widgets.TableItem) Text(org.eclipse.swt.widgets.Text) Image(org.eclipse.swt.graphics.Image) TableColumn(org.eclipse.swt.widgets.TableColumn) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ControlEvent(org.eclipse.swt.events.ControlEvent) Proposal(org.csstudio.autocomplete.proposals.Proposal) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 28 with ControlAdapter

use of org.eclipse.swt.events.ControlAdapter in project yamcs-studio by yamcs.

the class DisplayEditpart method activate.

@Override
public void activate() {
    super.activate();
    initProperties();
    if (getExecutionMode() == ExecutionMode.RUN_MODE && getWidgetModel().getDisplayScaleData().isAutoScaleWidgets()) {
        originSize = new org.eclipse.swt.graphics.Point(getWidgetModel().getWidth(), getWidgetModel().getHeight());
        oldSize = originSize;
        scaleListener = new ControlAdapter() {

            @Override
            public void controlResized(ControlEvent e) {
                if (getViewer() == null || getViewer().getControl().isDisposed())
                    return;
                org.eclipse.swt.graphics.Point size = getViewer().getControl().getSize();
                if (size.equals(oldSize))
                    return;
                double widthRatio = size.x / (double) originSize.x;
                double heightRatio = size.y / (double) originSize.y;
                oldSize = size;
                getWidgetModel().scale(widthRatio, heightRatio);
            // oldSize = size;
            }
        };
        UIBundlingThread.getInstance().addRunnable(new Runnable() {

            @Override
            public void run() {
                scaleListener.controlResized(null);
            }
        });
        getViewer().getControl().addControlListener(scaleListener);
    }
    if (getExecutionMode() == ExecutionMode.RUN_MODE && getWidgetModel().isAutoZoomToFitAll()) {
        originSize = new org.eclipse.swt.graphics.Point(getWidgetModel().getWidth(), getWidgetModel().getHeight());
        oldSize = originSize;
        zoomListener = new ControlAdapter() {

            @Override
            public void controlResized(ControlEvent e) {
                if (!isActive() || getViewer() == null || getViewer().getControl().isDisposed())
                    return;
                org.eclipse.swt.graphics.Point size = ((Canvas) getViewer().getControl()).getSize();
                if (size.equals(oldSize))
                    return;
                if (size.x * size.y > 0) {
                    DisplayModel displayModel = (DisplayModel) getModel();
                    getZoomManager().getScalableFigure().setPreferredSize(displayModel.getSize());
                    getZoomManager().setZoomAsText(Draw2dSingletonUtil.ZoomManager_FIT_ALL);
                }
                oldSize = size;
            }
        };
        UIBundlingThread.getInstance().addRunnable(new Runnable() {

            @Override
            public void run() {
                zoomListener.controlResized(null);
            }
        });
        getViewer().getControl().addControlListener(zoomListener);
    }
    UIBundlingThread.getInstance().addRunnable(new Runnable() {

        @Override
        public void run() {
            if (getViewer() != null && getViewer().getControl() != null && !getViewer().getControl().isDisposed())
                getViewer().getControl().forceFocus();
        }
    });
}
Also used : ControlAdapter(org.eclipse.swt.events.ControlAdapter) DisplayModel(org.csstudio.opibuilder.model.DisplayModel) Point(org.eclipse.draw2d.geometry.Point) ControlEvent(org.eclipse.swt.events.ControlEvent)

Aggregations

ControlAdapter (org.eclipse.swt.events.ControlAdapter)28 ControlEvent (org.eclipse.swt.events.ControlEvent)28 Composite (org.eclipse.swt.widgets.Composite)16 SelectionEvent (org.eclipse.swt.events.SelectionEvent)12 GridLayout (org.eclipse.swt.layout.GridLayout)11 Point (org.eclipse.swt.graphics.Point)9 GridData (org.eclipse.swt.layout.GridData)9 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)8 Rectangle (org.eclipse.swt.graphics.Rectangle)7 TableColumn (org.eclipse.swt.widgets.TableColumn)7 ModifyEvent (org.eclipse.swt.events.ModifyEvent)6 Button (org.eclipse.swt.widgets.Button)6 ModifyListener (org.eclipse.swt.events.ModifyListener)5 FillLayout (org.eclipse.swt.layout.FillLayout)5 Label (org.eclipse.swt.widgets.Label)5 Table (org.eclipse.swt.widgets.Table)5 SashForm (org.eclipse.swt.custom.SashForm)4 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)4 Event (org.eclipse.swt.widgets.Event)4 Listener (org.eclipse.swt.widgets.Listener)4