use of org.eclipse.swt.events.MouseEvent in project eclipse.platform.text by eclipse.
the class AnnotationRulerColumn method createControl.
@Override
public Control createControl(CompositeRuler parentRuler, Composite parentControl) {
fParentRuler = parentRuler;
fCachedTextViewer = parentRuler.getTextViewer();
fCachedTextWidget = fCachedTextViewer.getTextWidget();
fHitDetectionCursor = parentControl.getDisplay().getSystemCursor(SWT.CURSOR_HAND);
fCanvas = createCanvas(parentControl);
fCanvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent event) {
if (fCachedTextViewer != null)
doubleBufferPaint(event.gc);
}
});
fCanvas.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
handleDispose();
fCachedTextViewer = null;
fCachedTextWidget = null;
}
});
fMouseListener = new MouseListener() {
@Override
public void mouseUp(MouseEvent event) {
int lineNumber;
if (isPropagatingMouseListener()) {
fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y);
lineNumber = fParentRuler.getLineOfLastMouseButtonActivity();
} else
lineNumber = fParentRuler.toDocumentLineNumber(event.y);
if (1 == event.button)
mouseClicked(lineNumber);
}
@Override
public void mouseDown(MouseEvent event) {
int lineNumber;
if (isPropagatingMouseListener()) {
fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y);
lineNumber = fParentRuler.getLineOfLastMouseButtonActivity();
} else
lineNumber = fParentRuler.toDocumentLineNumber(event.y);
if (1 == event.button)
AnnotationRulerColumn.this.mouseDown(lineNumber);
}
@Override
public void mouseDoubleClick(MouseEvent event) {
int lineNumber;
if (isPropagatingMouseListener()) {
fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y);
lineNumber = fParentRuler.getLineOfLastMouseButtonActivity();
} else
lineNumber = fParentRuler.toDocumentLineNumber(event.y);
if (1 == event.button)
mouseDoubleClicked(lineNumber);
}
};
fCanvas.addMouseListener(fMouseListener);
fCanvas.addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e) {
handleMouseMove(e);
}
});
fCanvas.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseScrolled(MouseEvent e) {
handleMouseScrolled(e);
}
});
if (fCachedTextViewer != null) {
VisibleLinesTracker.track(fCachedTextViewer, lineHeightChangeHandler);
fCachedTextViewer.addTextListener(fLineListener);
// on word wrap toggle a "resized" ControlEvent is fired: suggest a redraw of the ruler
fCachedTextWidget.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
if (fCachedTextWidget != null && fCachedTextWidget.getWordWrap()) {
redraw();
}
}
});
}
return fCanvas;
}
use of org.eclipse.swt.events.MouseEvent in project uiautomatorviewer by yangzaiCN.
the class UiAutomatorViewer method createContents.
/**
* Create contents of the application window.
*
* @param parent
*/
@Override
protected Control createContents(Composite parent) {
UiAutomatorModel.createInstance(this);
Composite basePane = new Composite(parent, SWT.NONE);
basePane.setLayout(new GridLayout(2, false));
mScreenshotCanvas = new Canvas(basePane, SWT.NONE);
mScreenshotCanvas.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
UiAutomatorModel.getModel().toggleExploreMode();
}
});
mScreenshotCanvas.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_BLACK));
mScreenshotCanvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3));
mScreenshotCanvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
if (mCachedScaleImage != null) {
// shifting the image here, so that there's a border around screen shot
// this makes highlighting red rectangles on the screen shot edges more visible
e.gc.drawImage(mCachedScaleImage, IMG_BORDER, IMG_BORDER);
Rectangle rect = UiAutomatorModel.getModel().getCurrentDrawingRect();
if (rect != null) {
e.gc.setForeground(e.gc.getDevice().getSystemColor(SWT.COLOR_RED));
if (UiAutomatorModel.getModel().isExploreMode()) {
// when we highlight nodes dynamically on mouse move,
// use dashed borders
e.gc.setLineStyle(SWT.LINE_DASH);
e.gc.setLineWidth(1);
} else {
// when highlighting nodes on tree node selection,
// use solid borders
e.gc.setLineStyle(SWT.LINE_SOLID);
e.gc.setLineWidth(2);
}
e.gc.drawRectangle(IMG_BORDER + getScaledSize(rect.x), IMG_BORDER + getScaledSize(rect.y), getScaledSize(rect.width), getScaledSize(rect.height));
}
}
}
});
mScreenshotCanvas.addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e) {
if (UiAutomatorModel.getModel().isExploreMode()) {
UiAutomatorModel.getModel().updateSelectionForCoordinates(getInverseScaledSize(e.x - IMG_BORDER), getInverseScaledSize(e.y - IMG_BORDER));
}
}
});
mScreenshotCanvas.setBackgroundImage(ImageHelper.loadImageDescriptorFromResource("images/logo.png").createImage());
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
toolBarManager.add(mOpenFilesAction);
toolBarManager.add(mExpandAllAction);
toolBarManager.add(mScreenshotAction);
toolBarManager.createControl(basePane);
mTreeViewer = new TreeViewer(basePane, SWT.BORDER);
Tree tree = mTreeViewer.getTree();
GridData gd_Tree = new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1);
gd_Tree.widthHint = 350;
tree.setLayoutData(gd_Tree);
mTreeViewer.setContentProvider(new BasicTreeNodeContentProvider());
// default LabelProvider uses toString() to generate text to display
mTreeViewer.setLabelProvider(new LabelProvider());
mTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
if (event.getSelection().isEmpty()) {
UiAutomatorModel.getModel().setSelectedNode(null);
} else if (event.getSelection() instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
Object o = selection.toArray()[0];
if (o instanceof BasicTreeNode) {
UiAutomatorModel.getModel().setSelectedNode((BasicTreeNode) o);
}
}
}
});
// move focus so that it's not on tool bar (looks weird)
tree.setFocus();
Group grpNodeDetail = new Group(basePane, SWT.NONE);
grpNodeDetail.setLayout(new FillLayout(SWT.HORIZONTAL));
GridData gd_grpNodeDetail = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_grpNodeDetail.heightHint = FIXED_DETAIL_VIEW_HEIGHT;
gd_grpNodeDetail.minimumHeight = FIXED_DETAIL_VIEW_HEIGHT;
gd_grpNodeDetail.widthHint = FIXED_RHS_WIDTH;
gd_grpNodeDetail.minimumWidth = FIXED_RHS_WIDTH;
grpNodeDetail.setLayoutData(gd_grpNodeDetail);
grpNodeDetail.setText("Node Detail");
Composite tableContainer = new Composite(grpNodeDetail, SWT.NONE);
tableContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
TableColumnLayout columnLayout = new TableColumnLayout();
tableContainer.setLayout(columnLayout);
mTableViewer = new TableViewer(tableContainer, SWT.BORDER | SWT.FULL_SELECTION);
Table table = mTableViewer.getTable();
table.setLinesVisible(true);
// use ArrayContentProvider here, it assumes the input to the TableViewer
// is an array, where each element represents a row in the table
mTableViewer.setContentProvider(new ArrayContentProvider());
TableViewerColumn tableViewerColumnKey = new TableViewerColumn(mTableViewer, SWT.NONE);
TableColumn tblclmnKey = tableViewerColumnKey.getColumn();
tableViewerColumnKey.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof AttributePair) {
// first column, shows the attribute name
return ((AttributePair) element).key;
}
return super.getText(element);
}
});
columnLayout.setColumnData(tblclmnKey, new ColumnWeightData(1, ColumnWeightData.MINIMUM_WIDTH, true));
TableViewerColumn tableViewerColumnValue = new TableViewerColumn(mTableViewer, SWT.NONE);
tableViewerColumnValue.setEditingSupport(new AttributeTableEditingSupport(mTableViewer));
TableColumn tblclmnValue = tableViewerColumnValue.getColumn();
columnLayout.setColumnData(tblclmnValue, new ColumnWeightData(2, ColumnWeightData.MINIMUM_WIDTH, true));
tableViewerColumnValue.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof AttributePair) {
// second column, shows the attribute value
return ((AttributePair) element).value;
}
return super.getText(element);
}
});
return basePane;
}
use of org.eclipse.swt.events.MouseEvent in project linuxtools by eclipse.
the class ChartEditor method createPartControl.
@Override
public void createPartControl(Composite parent) {
final ChartEditorInput input = (ChartEditorInput) getEditorInput();
final HeapChart heapChart = input.getChart();
control = new Chart(parent, SWT.FILL);
heapChart.setChartControl(control);
final Color LIGHTYELLOW = new Color(Display.getDefault(), 255, 255, 225);
final Color WHITE = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
final Color BLACK = Display.getDefault().getSystemColor(SWT.COLOR_BLACK);
final Color RED = Display.getDefault().getSystemColor(SWT.COLOR_RED);
final Color ORANGE = new Color(Display.getDefault(), 255, 165, 0);
final Color GREEN = Display.getDefault().getSystemColor(SWT.COLOR_GREEN);
final Color DARK_BLUE = new Color(Display.getDefault(), 64, 128, 128);
final int TICK_GAP = 40;
control.setBackground(WHITE);
control.setBackgroundInPlotArea(LIGHTYELLOW);
FontData fd = JFaceResources.getDialogFont().getFontData()[0];
fd.setStyle(SWT.BOLD);
Font font = new Font(Display.getDefault(), fd);
fd.setHeight(fd.getHeight() + 2);
Font titleFont = new Font(Display.getDefault(), fd);
ITitle title = control.getTitle();
title.setFont(titleFont);
title.setForeground(BLACK);
title.setText(heapChart.title);
IAxis xAxis = control.getAxisSet().getXAxis(0);
xAxis.getGrid().setStyle(LineStyle.NONE);
xAxis.getTick().setForeground(BLACK);
ITitle xTitle = xAxis.getTitle();
xTitle.setFont(font);
xTitle.setForeground(BLACK);
xTitle.setText(heapChart.xUnits);
IAxis yAxis = control.getAxisSet().getYAxis(0);
yAxis.getGrid().setStyle(LineStyle.SOLID);
yAxis.getTick().setForeground(BLACK);
yAxis.getTick().setTickMarkStepHint(TICK_GAP);
ITitle yTitle = yAxis.getTitle();
yTitle.setFont(font);
yTitle.setText(heapChart.yUnits);
yTitle.setForeground(BLACK);
control.getLegend().setPosition(SWT.BOTTOM);
// data
final ILineSeries lsUseful = (ILineSeries) control.getSeriesSet().createSeries(SeriesType.LINE, // $NON-NLS-1$;
Messages.getString("HeapChart.Useful_Heap"));
lsUseful.setXSeries(heapChart.time);
lsUseful.setYSeries(heapChart.dataUseful);
lsUseful.setSymbolType(PlotSymbolType.DIAMOND);
lsUseful.setSymbolColor(RED);
lsUseful.setLineColor(RED);
final ILineSeries lsExtra = (ILineSeries) control.getSeriesSet().createSeries(SeriesType.LINE, // $NON-NLS-1$;
Messages.getString("HeapChart.Extra_Heap"));
lsExtra.setXSeries(heapChart.time);
lsExtra.setYSeries(heapChart.dataExtra);
lsExtra.setSymbolType(PlotSymbolType.DIAMOND);
lsExtra.setSymbolColor(ORANGE);
lsExtra.setLineColor(ORANGE);
if (heapChart.dataStacks != null) {
final ILineSeries lsStack = (ILineSeries) control.getSeriesSet().createSeries(SeriesType.LINE, // $NON-NLS-1$;
Messages.getString("HeapChart.Stacks"));
lsStack.setXSeries(heapChart.time);
lsStack.setYSeries(heapChart.dataStacks);
lsStack.setSymbolType(PlotSymbolType.DIAMOND);
lsStack.setSymbolColor(DARK_BLUE);
lsStack.setLineColor(DARK_BLUE);
}
final ILineSeries lsTotal = (ILineSeries) control.getSeriesSet().createSeries(SeriesType.LINE, // $NON-NLS-1$;
Messages.getString("HeapChart.Total_Heap"));
lsTotal.setXSeries(heapChart.time);
lsTotal.setYSeries(heapChart.dataTotal);
lsTotal.setSymbolType(PlotSymbolType.DIAMOND);
lsTotal.setSymbolColor(GREEN);
lsTotal.setLineColor(GREEN);
// adjust axes
control.getAxisSet().adjustRange();
IAxisSet axisSet = control.getAxisSet();
Range xRange = axisSet.getXAxis(0).getRange();
Range yRange = axisSet.getYAxis(0).getRange();
double xExtra = 0.05 * (xRange.upper - xRange.lower);
double yExtra = 0.05 * (yRange.upper - yRange.lower);
axisSet.getXAxis(0).setRange(new Range(xRange.lower, xRange.upper + xExtra));
axisSet.getYAxis(0).setRange(new Range(yRange.lower, yRange.upper + yExtra));
// listeners
control.getPlotArea().addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
showView();
TableViewer viewer = input.getView().getTableViewer();
input.getView().setTopControl(viewer.getControl());
Point p = new Point(e.x, e.y);
int closest = 0;
double d1, d2, d3, currMin;
double globalMin = Double.MAX_VALUE;
for (int i = 0; i < heapChart.time.length; i++) {
// get distance from click event to data points for the given index
d1 = distance(lsUseful.getPixelCoordinates(i), p);
d2 = distance(lsExtra.getPixelCoordinates(i), p);
d3 = distance(lsTotal.getPixelCoordinates(i), p);
// find the closest data point to the click event
currMin = Math.min(Math.min(d1, d2), d3);
if (currMin < globalMin) {
closest = i;
globalMin = currMin;
}
}
MassifSnapshot snapshot = (MassifSnapshot) viewer.getElementAt(closest);
viewer.setSelection(new StructuredSelection(snapshot), true);
if (e.count == 2 && snapshot.isDetailed()) {
ChartLocationsDialog dialog = new ChartLocationsDialog(Display.getCurrent().getActiveShell());
dialog.setInput(snapshot);
if (dialog.open() == Window.OK) {
dialog.openEditorForResult();
}
}
}
});
}
use of org.eclipse.swt.events.MouseEvent in project eclipse.platform.swt by eclipse.
the class CurvesTab method createControlPanel.
/**
* Creates the widgets used to control the drawing.
*/
@Override
public void createControlPanel(Composite parent) {
if (cursor == null) {
cursor = parent.getDisplay().getSystemCursor(SWT.CURSOR_HAND);
}
mouseMoveListener = e -> {
if (hovering && mouseDown) {
example.canvas.setCursor(cursor);
} else if (isHovering(e)) {
example.canvas.setCursor(cursor);
hovering = true;
} else {
example.canvas.setCursor(null);
hovering = false;
}
if (quadPtMoved) {
quadDiffX = quadDiffX + e.x - (int) quadXPos - quadHndl.x;
quadDiffY = quadDiffY + e.y - (int) quadYPos - quadHndl.y;
quadHndl.x = e.x - (int) quadXPos;
quadHndl.y = e.y - (int) quadYPos;
} else if (quadEndPtMoved) {
quadEndDiffX = quadEndDiffX + e.x - (int) quadXPos - quadEndHndl.x;
quadEndDiffY = quadEndDiffY + e.y - (int) quadYPos - quadEndHndl.y;
quadEndHndl.x = e.x - (int) quadXPos;
quadEndHndl.y = e.y - (int) quadYPos;
} else if (cubPt1Moved) {
cubDiffX1 = cubDiffX1 + e.x - (int) cubXPos - cubHndl1.x;
cubDiffY1 = cubDiffY1 + e.y - (int) cubYPos - cubHndl1.y;
cubHndl1.x = e.x - (int) cubXPos;
cubHndl1.y = e.y - (int) cubYPos;
} else if (cubPt2Moved) {
cubDiffX2 = cubDiffX2 + e.x - (int) cubXPos - cubHndl2.x;
cubDiffY2 = cubDiffY2 + e.y - (int) cubYPos - cubHndl2.y;
cubHndl2.x = e.x - (int) cubXPos;
cubHndl2.y = e.y - (int) cubYPos;
} else if (cubEndPtMoved) {
cubEndDiffX = cubEndDiffX + e.x - (int) cubXPos - cubEndHndl.x;
cubEndDiffY = cubEndDiffY + e.y - (int) cubYPos - cubEndHndl.y;
cubEndHndl.x = e.x - (int) cubXPos;
cubEndHndl.y = e.y - (int) cubYPos;
}
example.redraw();
};
mouseListener = new MouseListener() {
@Override
public void mouseDoubleClick(MouseEvent e) {
}
/**
* Sent when a mouse button is pressed.
*
* @param e an event containing information about the mouse button press
*/
@Override
public void mouseDown(MouseEvent e) {
Rectangle quad = new Rectangle(quadHndl.x + (int) quadXPos - 1, quadHndl.y + (int) quadYPos - 1, quadHndl.width + 2, quadHndl.height + 2);
Rectangle quadEnd = new Rectangle(quadEndHndl.x + (int) quadXPos - 1, quadEndHndl.y + (int) quadYPos - 1, quadEndHndl.width + 2, quadEndHndl.height + 2);
Rectangle cub1 = new Rectangle(cubHndl1.x + (int) cubXPos - 1, cubHndl1.y + (int) cubYPos - 1, cubHndl1.width + 2, cubHndl1.height + 2);
Rectangle cub2 = new Rectangle(cubHndl2.x + (int) cubXPos - 1, cubHndl2.y + (int) cubYPos - 1, cubHndl2.width + 2, cubHndl2.height + 2);
Rectangle cubEnd = new Rectangle(cubEndHndl.x + (int) cubXPos - 1, cubEndHndl.y + (int) cubYPos - 1, cubEndHndl.width + 2, cubEndHndl.height + 2);
if (quad.contains(e.x, e.y)) {
quadPtMoved = true;
mouseDown = true;
} else if (quadEnd.contains(e.x, e.y)) {
quadEndPtMoved = true;
mouseDown = true;
} else if (cub1.contains(e.x, e.y)) {
cubPt1Moved = true;
mouseDown = true;
} else if (cub2.contains(e.x, e.y)) {
cubPt2Moved = true;
mouseDown = true;
} else if (cubEnd.contains(e.x, e.y)) {
cubEndPtMoved = true;
mouseDown = true;
}
}
/**
* Sent when a mouse button is released.
*
* @param e an event containing information about the mouse button release
*/
@Override
public void mouseUp(MouseEvent e) {
mouseDown = false;
if (isHovering(e)) {
example.canvas.setCursor(cursor);
} else {
example.canvas.setCursor(null);
}
if (quadPtMoved)
quadPtMoved = false;
if (quadEndPtMoved)
quadEndPtMoved = false;
if (cubPt1Moved)
cubPt1Moved = false;
if (cubPt2Moved)
cubPt2Moved = false;
if (cubEndPtMoved)
cubEndPtMoved = false;
example.redraw();
}
};
example.canvas.addMouseMoveListener(mouseMoveListener);
example.canvas.addMouseListener(mouseListener);
}
use of org.eclipse.swt.events.MouseEvent in project eclipse.platform.swt by eclipse.
the class Bug306067_DesktopEffectShellEvent method main.
public static void main(String[] args) {
Device.DEBUG = true;
display = new Display();
shell = new Shell(display);
shell.setLayout(new RowLayout());
// create the drop down shell
dropDownShell = new Shell(shell, SWT.ON_TOP | SWT.DROP_DOWN);
dropDownShell.setLayout(new RowLayout());
dropDownShell.setVisible(false);
dropDownShell.addListener(SWT.Deactivate, event -> {
System.out.println("dropDownShell entering Deactivate event handler and will hide the dropdown shell");
hideDropDown();
});
dropDownShell.addListener(SWT.Close, event -> hideDropDown());
// create the button
button = new Button(shell, SWT.PUSH);
button.setText("Open");
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (!dropDownShell.isVisible()) {
System.out.println("Open button entering widgetSelected event handler and will show the dropdown shell");
showDropDown();
}
}
});
button.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
System.out.println("Open button entering mouseDown event handler");
super.mouseDown(e);
}
@Override
public void mouseUp(MouseEvent e) {
System.out.println("Open button entering mouseUp event handler");
super.mouseUp(e);
}
});
shell.setSize(300, 300);
shell.addDisposeListener(e -> {
if (dropDownShell != null && !dropDownShell.isDisposed()) {
dropDownShell.dispose();
dropDownShell = null;
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
Aggregations