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;
}
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;
}
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();
}
});
}
Aggregations