use of org.eclipse.swt.events.MouseAdapter in project eclipse.platform.swt by eclipse.
the class Bug514483_getCursorLocation method main.
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setBounds(0, 0, 600, 600);
Label parentShellLabel = new Label(shell, SWT.None);
parentShellLabel.setText("Parent widget.shell.\n" + "INSTRUCTIONS:\n" + "- Parent widget.shell should be maximized.\n" + "- Child widget.shell should be at x400 y400 (in yellow square).\n" + "- Click inside the child widget.shell, observe result coordinates below.\n" + "\n" + "The bug is that x,y is not relative to parent, but relative to child-widget.shell itself (0-200 range).\n" + "Expected coordinates: between ~400 to ~600. (i.e, relative to parent's x,y.)\n" + "Result Coordinates:");
parentShellLabel.setBounds(0, 0, 600, 200);
final Label resultLbl = new Label(shell, SWT.None);
resultLbl.setBounds(0, 180, 600, 100);
resultLbl.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
Label childShellLocation = new Label(shell, SWT.None);
childShellLocation.setText("Child Shell should be here.\nIf it is not, move it here \nmanually");
childShellLocation.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
childShellLocation.setBounds(400, 400, 200, 160);
Shell childShell = new Shell(shell, SWT.ON_TOP);
childShell.setBackground(display.getSystemColor(SWT.COLOR_DARK_YELLOW));
MouseAdapter clickListener = new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
Point loc = display.getCursorLocation();
resultLbl.setText(loc.toString());
if (// give user some slack.
loc.x > 300 && loc.x < 700 && loc.y > 300 && loc.y < 700)
resultLbl.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
else
resultLbl.setBackground(display.getSystemColor(SWT.COLOR_RED));
}
};
childShell.addMouseListener(clickListener);
// display.addFilter(SWT.KeyDown, new Listener() {
// public void handleEvent(Event e) {
// if (e.type == SWT.KeyDown) {
// switch (e.keyCode) {
// case SWT.F1:
// System.out.println("Passed");
// break;
// case SWT.F2:
// System.out.println("Failed");
// break;
// case SWT.F3:
// System.out.println("Skipped");
// break;
// case SWT.F4:
// System.out.println("Exit Test suite");
// break;
// }
// }
// }
// });
shell.open();
childShell.open();
childShell.setBounds(400, 400, 200, 200);
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
use of org.eclipse.swt.events.MouseAdapter in project eclipse.platform.text by eclipse.
the class SearchHistorySelectionDialog method createDialogArea.
/*
* Overrides method from Dialog
*/
@Override
protected Control createDialogArea(Composite container) {
Composite ancestor = (Composite) super.createDialogArea(container);
createMessageArea(ancestor);
Composite parent = new Composite(ancestor, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginHeight = 0;
layout.marginWidth = 0;
parent.setLayout(layout);
parent.setLayoutData(new GridData(GridData.FILL_BOTH));
fViewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
fViewer.setContentProvider(new ArrayContentProvider());
final Table table = fViewer.getTable();
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
okPressed();
}
});
fViewer.setLabelProvider(new SearchesLabelProvider());
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = convertHeightInCharsToPixels(15);
gd.widthHint = convertWidthInCharsToPixels(WIDTH_IN_CHARACTERS);
table.setLayoutData(gd);
fRemoveButton = new Button(parent, SWT.PUSH);
fRemoveButton.setText(SearchMessages.SearchesDialog_remove_label);
fRemoveButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
buttonPressed(REMOVE_ID);
}
});
fRemoveButton.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false));
SWTUtil.setButtonDimensionHint(fRemoveButton);
fViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
validateDialogState();
}
});
fLink = new Link(parent, SWT.NONE);
configureHistoryLink();
fLink.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
HistoryConfigurationDialog dialog = new HistoryConfigurationDialog(getShell(), fInput, fRemovedEntries);
if (dialog.open() == Window.OK) {
fViewer.refresh();
configureHistoryLink();
}
}
});
fLink.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
applyDialogFont(ancestor);
// set input & selections last, so all the widgets are created.
fViewer.setInput(fInput);
fViewer.getTable().setFocus();
return ancestor;
}
use of org.eclipse.swt.events.MouseAdapter in project eclipse.platform.text by eclipse.
the class AbstractInformationControl method addResizeSupportIfNecessary.
private void addResizeSupportIfNecessary(final Composite bars) {
// XXX: workarounds for
// - https://bugs.eclipse.org/bugs/show_bug.cgi?id=219139 : API to add resize grip / grow box in lower right corner of shell
// - https://bugs.eclipse.org/bugs/show_bug.cgi?id=23980 : platform specific shell resize behavior
String platform = SWT.getPlatform();
// $NON-NLS-1$
final boolean isWin = platform.equals("win32");
if (// $NON-NLS-1$
!isWin && !platform.equals("gtk"))
return;
final Canvas resizer = new Canvas(bars, SWT.NONE);
int size = getResizeHandleSize(bars);
GridData data = new GridData(SWT.END, SWT.END, false, true);
data.widthHint = size;
data.heightHint = size;
resizer.setLayoutData(data);
resizer.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
Point s = resizer.getSize();
int x = s.x - 2;
int y = s.y - 2;
int min = Math.min(x, y);
if (isWin) {
// draw dots
e.gc.setBackground(resizer.getDisplay().getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
int end = min - 1;
for (int i = 0; i <= 2; i++) for (int j = 0; j <= 2 - i; j++) e.gc.fillRectangle(end - 4 * i, end - 4 * j, 2, 2);
end--;
e.gc.setBackground(resizer.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
for (int i = 0; i <= 2; i++) for (int j = 0; j <= 2 - i; j++) e.gc.fillRectangle(end - 4 * i, end - 4 * j, 2, 2);
} else {
// draw diagonal lines
e.gc.setForeground(resizer.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
for (int i = 1; i < min; i += 4) {
e.gc.drawLine(i, y, x, i);
}
e.gc.setForeground(resizer.getDisplay().getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
for (int i = 2; i < min; i += 4) {
e.gc.drawLine(i, y, x, i);
}
}
}
});
final boolean isRTL = (resizer.getShell().getStyle() & SWT.RIGHT_TO_LEFT) != 0;
resizer.setCursor(resizer.getDisplay().getSystemCursor(isRTL ? SWT.CURSOR_SIZESW : SWT.CURSOR_SIZESE));
MouseAdapter resizeSupport = new MouseAdapter() {
private MouseMoveListener fResizeListener;
@Override
public void mouseDown(MouseEvent e) {
Rectangle shellBounds = fShell.getBounds();
final int shellX = shellBounds.x;
final int shellY = shellBounds.y;
final int shellWidth = shellBounds.width;
final int shellHeight = shellBounds.height;
Point mouseLoc = resizer.toDisplay(e.x, e.y);
final int mouseX = mouseLoc.x;
final int mouseY = mouseLoc.y;
fResizeListener = new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e2) {
Point mouseLoc2 = resizer.toDisplay(e2.x, e2.y);
int dx = mouseLoc2.x - mouseX;
int dy = mouseLoc2.y - mouseY;
if (isRTL) {
setLocation(new Point(shellX + dx, shellY));
setSize(shellWidth - dx, shellHeight + dy);
} else {
setSize(shellWidth + dx, shellHeight + dy);
}
}
};
resizer.addMouseMoveListener(fResizeListener);
}
@Override
public void mouseUp(MouseEvent e) {
resizer.removeMouseMoveListener(fResizeListener);
fResizeListener = null;
}
};
resizer.addMouseListener(resizeSupport);
}
use of org.eclipse.swt.events.MouseAdapter in project eclipse.platform.text by eclipse.
the class CompletionProposalPopup method createMessageText.
/**
* Creates the caption line under the proposal table.
*
* @since 3.2
*/
private void createMessageText() {
if (fMessageText == null) {
fMessageText = new Label(fProposalShell, SWT.RIGHT);
GridData textData = new GridData(SWT.FILL, SWT.BOTTOM, true, false);
fMessageText.setLayoutData(textData);
// $NON-NLS-1$
fMessageText.setText(fContentAssistant.getStatusMessage() + " ");
if (fMessageTextFont == null) {
Font font = fMessageText.getFont();
Display display = fProposalShell.getDisplay();
FontData[] fontDatas = font.getFontData();
for (FontData fontData : fontDatas) fontData.setHeight(fontData.getHeight() * 9 / 10);
fMessageTextFont = new Font(display, fontDatas);
}
fMessageText.setFont(fMessageTextFont);
fMessageText.setBackground(getBackgroundColor(fProposalShell));
fMessageText.setForeground(getForegroundColor(fProposalShell));
if (fContentAssistant.isRepeatedInvocationMode()) {
fMessageText.setCursor(fProposalShell.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
fMessageText.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
fLastCompletionOffset = fFilterOffset;
fProposalTable.setFocus();
handleRepeatedInvocation();
}
@Override
public void mouseDown(MouseEvent e) {
}
});
}
}
}
use of org.eclipse.swt.events.MouseAdapter in project yamcs-studio by yamcs.
the class CreateAnnotationDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite area = (Composite) super.createDialogArea(parent);
Composite container = new Composite(area, SWT.NONE);
container.setLayoutData(new GridData(GridData.FILL_BOTH));
GridLayout layout = new GridLayout(2, false);
layout.marginHeight = 20;
layout.marginWidth = 20;
layout.verticalSpacing = 2;
container.setLayout(layout);
Label lbl = new Label(container, SWT.NONE);
lbl.setText("Name");
Composite tagAndColorWrapper = new Composite(container, SWT.NONE);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
tagAndColorWrapper.setLayoutData(gd);
GridLayout gl = new GridLayout(2, false);
gl.marginHeight = 0;
gl.marginWidth = 0;
tagAndColorWrapper.setLayout(gl);
tag = new Text(tagAndColorWrapper, SWT.BORDER);
tag.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
tag.setText(tagValue);
// Some ugly tricks to get a border around a label, which should have been a button in the first place
// but at least OSX doesn't support buttons with custom backgrounds. May be getting time to draw GC ourselves..
Composite labelBorder = new Composite(tagAndColorWrapper, SWT.BORDER);
labelBorder.setLayout(new FillLayout());
colorSelector = new Label(labelBorder, SWT.NONE);
colorSelector.setText(" ");
colorSelector.setCursor(handCursor);
colorSelector.setBackground(resourceManager.createColor(colorValue));
colorSelector.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
ColorDialog colorDialog = new ColorDialog(colorSelector.getShell());
colorDialog.setRGB(colorSelector.getBackground().getRGB());
RGB newColor = colorDialog.open();
if (newColor != null)
colorSelector.setBackground(resourceManager.createColor(newColor));
}
});
lbl = new Label(container, SWT.NONE);
lbl.setText("Description");
gd = new GridData();
gd.verticalAlignment = SWT.TOP;
lbl.setLayoutData(gd);
description = new Text(container, SWT.MULTI | SWT.BORDER);
gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = description.getLineHeight() * 3;
description.setLayoutData(gd);
description.setText(descriptionValue);
Composite startLabelWrapper = new Composite(container, SWT.NONE);
gl = new GridLayout(2, false);
gl.marginHeight = 0;
gl.marginWidth = 0;
startLabelWrapper.setLayout(gl);
lbl = new Label(startLabelWrapper, SWT.NONE);
lbl.setText("Start");
startClosed = new Button(startLabelWrapper, SWT.CHECK | SWT.NONE);
startClosed.setSelection(true);
startClosed.addListener(SWT.Selection, e -> {
startDate.setVisible(startClosed.getSelection());
startTime.setVisible(startClosed.getSelection());
validate();
});
Composite startComposite = new Composite(container, SWT.NONE);
RowLayout rl = new RowLayout();
rl.marginLeft = 0;
rl.marginTop = 0;
rl.marginBottom = 0;
rl.center = true;
startComposite.setLayout(rl);
startDate = new DateTime(startComposite, SWT.DATE | SWT.LONG | SWT.DROP_DOWN | SWT.BORDER);
startDate.addListener(SWT.Selection, e -> validate());
startTime = new DateTime(startComposite, SWT.TIME | SWT.LONG | SWT.BORDER);
startTime.addListener(SWT.Selection, e -> validate());
if (startTimeValue != null) {
startDate.setDate(startTimeValue.get(Calendar.YEAR), startTimeValue.get(Calendar.MONTH), startTimeValue.get(Calendar.DAY_OF_MONTH));
startTime.setTime(startTimeValue.get(Calendar.HOUR_OF_DAY), startTimeValue.get(Calendar.MINUTE), startTimeValue.get(Calendar.SECOND));
}
Composite stopLabelWrapper = new Composite(container, SWT.NONE);
gl = new GridLayout(2, false);
gl.marginHeight = 0;
gl.marginWidth = 0;
stopLabelWrapper.setLayout(gl);
lbl = new Label(stopLabelWrapper, SWT.NONE);
lbl.setText("Stop");
stopClosed = new Button(stopLabelWrapper, SWT.CHECK | SWT.NONE);
stopClosed.setSelection(true);
stopClosed.addListener(SWT.Selection, e -> {
stopDate.setVisible(stopClosed.getSelection());
stopTime.setVisible(stopClosed.getSelection());
validate();
});
Composite stopComposite = new Composite(container, SWT.NONE);
rl = new RowLayout();
rl.marginLeft = 0;
rl.marginTop = 0;
rl.marginBottom = 0;
rl.center = true;
rl.fill = true;
stopComposite.setLayout(rl);
stopDate = new DateTime(stopComposite, SWT.DATE | SWT.LONG | SWT.DROP_DOWN | SWT.BORDER);
stopDate.addListener(SWT.Selection, e -> validate());
stopTime = new DateTime(stopComposite, SWT.TIME | SWT.LONG | SWT.BORDER);
stopTime.addListener(SWT.Selection, e -> validate());
if (stopTimeValue != null) {
stopDate.setDate(stopTimeValue.get(Calendar.YEAR), stopTimeValue.get(Calendar.MONTH), stopTimeValue.get(Calendar.DAY_OF_MONTH));
stopTime.setTime(stopTimeValue.get(Calendar.HOUR_OF_DAY), stopTimeValue.get(Calendar.MINUTE), stopTimeValue.get(Calendar.SECOND));
}
return container;
}
Aggregations