use of org.eclipse.swt.events.MouseEvent in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method getRulerMouseListener.
/**
* Creates and returns the listener on this editor's vertical ruler.
*
* @return the mouse listener
*/
protected final MouseListener getRulerMouseListener() {
if (fMouseListener == null) {
fMouseListener = new MouseListener() {
private boolean fDoubleClicked = false;
private final int fDoubleClickTime = getSite().getShell().getDisplay().getDoubleClickTime();
private long fMouseUpDelta = 0;
private void triggerAction(String actionID, MouseEvent e) {
IAction action = getAction(actionID);
if (action != null) {
if (action instanceof IUpdate)
((IUpdate) action).update();
if (action.isEnabled()) {
Event event = new Event();
event.type = fDoubleClicked ? SWT.MouseDoubleClick : SWT.MouseUp;
event.display = e.display;
event.widget = e.widget;
event.time = e.time;
event.data = e.data;
event.x = e.x;
event.y = e.y;
event.button = e.button;
event.stateMask = e.stateMask;
event.count = e.count;
action.runWithEvent(event);
}
}
}
@Override
public void mouseUp(final MouseEvent e) {
setFocus();
final int delay = fMouseUpDelta == 0 ? 0 : fDoubleClickTime - (int) (System.currentTimeMillis() - fMouseUpDelta);
if (1 != e.button)
return;
Runnable runnable = new Runnable() {
@Override
public void run() {
if (!fDoubleClicked)
triggerAction(ITextEditorActionConstants.RULER_CLICK, e);
}
};
if (delay <= 0)
runnable.run();
else
e.widget.getDisplay().timerExec(delay, runnable);
}
@Override
public void mouseDoubleClick(MouseEvent e) {
if (1 == e.button) {
fDoubleClicked = true;
triggerAction(ITextEditorActionConstants.RULER_DOUBLE_CLICK, e);
}
}
@Override
public void mouseDown(MouseEvent e) {
fMouseUpDelta = System.currentTimeMillis();
fDoubleClicked = false;
if (fRulerContextMenu != null && !fRulerContextMenu.isDisposed()) {
Display display = fRulerContextMenu.getDisplay();
Point location = display.getCursorLocation();
fRulerContextMenu.setLocation(location.x, location.y);
}
}
};
}
return fMouseListener;
}
use of org.eclipse.swt.events.MouseEvent in project eclipse.platform.text by eclipse.
the class VerticalRuler method createControl.
@Override
public Control createControl(Composite parent, ITextViewer textViewer) {
fTextViewer = textViewer;
fCanvas = new Canvas(parent, SWT.NO_BACKGROUND);
fCanvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent event) {
if (fTextViewer != null)
doubleBufferPaint(event.gc);
}
});
fCanvas.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
handleDispose();
fTextViewer = null;
}
});
fCanvas.addMouseListener(new MouseListener() {
@Override
public void mouseUp(MouseEvent event) {
}
@Override
public void mouseDown(MouseEvent event) {
fLastMouseButtonActivityLine = toDocumentLineNumber(event.y);
}
@Override
public void mouseDoubleClick(MouseEvent event) {
fLastMouseButtonActivityLine = toDocumentLineNumber(event.y);
}
});
if (fTextViewer != null) {
fTextViewer.addViewportListener(fInternalListener);
fTextViewer.addTextListener(fInternalListener);
}
return fCanvas;
}
use of org.eclipse.swt.events.MouseEvent 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.MouseEvent 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.MouseEvent in project eclipse.platform.text by eclipse.
the class AnnotationBarHoverManager method computeInformation.
@Override
protected void computeInformation() {
fAllowMouseExit = false;
MouseEvent event = getHoverEvent();
if ((event.stateMask & SWT.BUTTON_MASK) != 0) {
setInformation(null, null);
return;
}
IAnnotationHover hover = getHover(event);
if (hover == null) {
setInformation(null, null);
return;
}
int line = getHoverLine(event);
if (hover instanceof IAnnotationHoverExtension) {
IAnnotationHoverExtension extension = (IAnnotationHoverExtension) hover;
ILineRange range = extension.getHoverLineRange(fSourceViewer, line);
setCustomInformationControlCreator(extension.getHoverControlCreator());
range = adaptLineRange(range, line);
if (range != null)
setInformation(extension.getHoverInfo(fSourceViewer, range, computeNumberOfVisibleLines()), computeArea(range));
else
setInformation(null, null);
} else {
setCustomInformationControlCreator(null);
setInformation(hover.getHoverInfo(fSourceViewer, line), computeArea(line));
}
}
Aggregations