use of org.eclipse.swt.events.MouseListener 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.MouseListener 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;
}
Aggregations