Java Code Examples for org.eclipse.swt.graphics.Rectangle#contains()
The following examples show how to use
org.eclipse.swt.graphics.Rectangle#contains() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BreadcrumbItemDropDown.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Returns the monitor whose client area contains the given point. If no monitor contains the * point, returns the monitor that is closest to the point. * <p> * Copied from <code>org.eclipse.jface.window.Window.getClosestMonitor(Display, Point)</code> * </p> * * @param display the display showing the monitors * @param point point to find (display coordinates) * @return the monitor closest to the given point */ private static Monitor getClosestMonitor(Display display, Point point) { int closest= Integer.MAX_VALUE; Monitor[] monitors= display.getMonitors(); Monitor result= monitors[0]; for (int i= 0; i < monitors.length; i++) { Monitor current= monitors[i]; Rectangle clientArea= current.getClientArea(); if (clientArea.contains(point)) return current; int distance= Geometry.distanceSquared(Geometry.centerPoint(clientArea), point); if (distance < closest) { closest= distance; result= current; } } return result; }
Example 2
Source File: TmfXYChartViewer.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
private ITmfTimeZoomProvider getTimeZoomProvider() { return (zoomIn, useMousePosition) -> { Chart chart = getSwtChart(); if (chart == null) { return; } Point cursorDisplayLocation = getDisplay().getCursorLocation(); Point cursorControlLocation = getSwtChart().getPlotArea().toControl(cursorDisplayLocation); Point cursorParentLocation = getSwtChart().getPlotArea().getParent().toControl(cursorDisplayLocation); Rectangle controlBounds = getSwtChart().getPlotArea().getBounds(); // check the X axis only if (!controlBounds.contains(cursorParentLocation.x, controlBounds.y)) { return; } if (useMousePosition) { TmfXyUiUtils.zoom(this, chart, zoomIn, cursorControlLocation.x); } else { TmfXyUiUtils.zoom(this, chart, zoomIn); } }; }
Example 3
Source File: SwtUtils.java From xds-ide with Eclipse Public License 1.0 | 6 votes |
public static int getClickedItemColumnIndex(Table table, TableItem item, Point point) { int column = -1; if (item != null) { // Determine which column was selected for (int i = 0, n = table.getColumnCount(); i < n; i++) { Rectangle rect = item.getBounds(i); if (rect.contains(point)) { // This is the selected column column = i; break; } } } return column; }
Example 4
Source File: ColumnThumbAndName.java From BiglyBT with GNU General Public License v2.0 | 6 votes |
@Override public void cellMouseTrigger(TableCellMouseEvent event) { if (event.eventType == TableCellMouseEvent.EVENT_MOUSEMOVE || event.eventType == TableRowMouseEvent.EVENT_MOUSEDOWN) { TableRow row = event.cell.getTableRow(); if (row == null) { return; } Object data = row.getData(TableRowCore.ID_EXPANDOHITAREA); if (data instanceof Rectangle) { Rectangle hitArea = (Rectangle) data; boolean inExpando = hitArea.contains(event.x, event.y); if (event.eventType == TableCellMouseEvent.EVENT_MOUSEMOVE) { ((TableCellCore) event.cell).setCursorID(inExpando ? SWT.CURSOR_HAND : SWT.CURSOR_ARROW); } else if (inExpando) { // mousedown if (row instanceof TableRowCore) { TableRowCore rowCore = (TableRowCore) row; rowCore.setExpanded(!rowCore.isExpanded()); } } } } }
Example 5
Source File: CellEdgeDetectUtil.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
/** * @see CellEdgeDetectUtil#getHorizontalCellEdge(Rectangle, Point, int) */ private static CellEdgeEnum getVerticalCellEdge(Rectangle cellBounds, Point clickPt, int distanceFromEdge) { if (distanceFromEdge < 0) { distanceFromEdge = cellBounds.height / 2; } Rectangle top = new Rectangle(cellBounds.x, cellBounds.y, cellBounds.width, distanceFromEdge); Rectangle bottom = new Rectangle(cellBounds.x, cellBounds.y + cellBounds.height - distanceFromEdge, cellBounds.width, distanceFromEdge); if (top.contains(clickPt)) { return TOP; } else if (bottom.contains(clickPt)) { return BOTTOM; } else { return NONE; } }
Example 6
Source File: AnnotationExpansionControl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public void mouseExit(MouseEvent e) { Item item= (Item) ((Widget) e.getSource()).getData(); if (item != null) item.deselect(); // if the event lies outside the entire popup, dispose org.eclipse.swt.graphics.Region region= fShell.getRegion(); Canvas can= (Canvas) e.getSource(); Point p= can.toDisplay(e.x, e.y); if (region == null) { Rectangle bounds= fShell.getBounds(); // p= fShell.toControl(p); if (!bounds.contains(p)) dispose(); } else { p= fShell.toControl(p); if (!region.contains(p)) dispose(); } }
Example 7
Source File: ComponentFilterTable.java From arx with Apache License 2.0 | 6 votes |
/** * Returns the item at the given location. * * @param x * @param y * @return */ private int getItemRowAt(int x, int y) { Point pt = new Point(x, y); int index = table.getTopIndex(); while (index < table.getItemCount()) { final TableItem item = table.getItem(index); for (int i = 0; i < table.getColumns().length; i++) { final Rectangle rect = item.getBounds(i); if (rect.contains(pt)) { return index; } } index++; } return -1; }
Example 8
Source File: DatePicker.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
private int getDayFromPoint(int x, int y){ int result = -1; for (int i = 1; i <= 31; i++) { Point p = getDayPoint(i); Rectangle r = new Rectangle(p.x, p.y, colSize, rowSize); if (r.contains(x, y)) { result = i; break; } } return result; }
Example 9
Source File: CTree.java From nebula with Eclipse Public License 2.0 | 5 votes |
public void showItem(CTreeItem item) { Rectangle r = item.getBounds(); Rectangle c = getContentArea(); Point scroll = getScrollPosition(); if(r.height > c.height || !c.contains(new Point(r.x, r.y - scroll.y))) { setScrollPosition(new Point(scroll.x, r.y - c.y)); } else if(!c.contains(new Point(r.x, r.y + r.height - 1 - scroll.y))) { setScrollPosition(new Point(scroll.x, r.y - c.y - c.height + r.height)); } // TODO: showItem needs to work horizontally as well (call showColumn) }
Example 10
Source File: CTreeCombo.java From nebula with Eclipse Public License 2.0 | 5 votes |
void popupEvent(Event event) { switch (event.type) { case SWT.Paint: // draw black rectangle around list final Rectangle listRect = tree.getBounds(); final Color black = getDisplay().getSystemColor(SWT.COLOR_BLACK); event.gc.setForeground(black); event.gc.drawRectangle(0, 0, listRect.width + 1, listRect.height + 1); break; case SWT.Close: event.doit = false; dropDown(false); break; case SWT.Deactivate: if (!"carbon".equals(SWT.getPlatform())) { final Point point = arrow.toControl(getDisplay().getCursorLocation()); final Point size = arrow.getSize(); final Rectangle rect = new Rectangle(0, 0, size.x, size.y); if (!rect.contains(point)) { dropDown(false); } } else { dropDown(false); } break; } }
Example 11
Source File: GeoMapViewer.java From nebula with Eclipse Public License 2.0 | 5 votes |
/** * Pans the viewer so the element is revealed * * @param selection * the element to reveal * @param center * whether to center on the element */ public void reveal(Object selection, boolean center) { Point position = getElementPosition(selection, new Point(0, 0), true); Point size = geoMap.getSize(); Rectangle insideMargin = new Rectangle(revealMargin, revealMargin, size.x - revealMargin, size.y - revealMargin); if (position != null && (center || !insideMargin.contains(position))) { Point mapPosition = geoMap.getMapPosition(); geoMap.setCenterPosition(new Point(position.x + mapPosition.x, position.y + mapPosition.y)); } }
Example 12
Source File: SideBarToolTips.java From BiglyBT with GNU General Public License v2.0 | 5 votes |
/** * @return * * @since 3.1.1.1 */ private String getToolTip(Point mousePos_RelativeToItem) { List<MdiEntryVitalityImageSWT> vitalityImages = mdiEntry.getVitalityImages(); for (MdiEntryVitalityImageSWT vitalityImage : vitalityImages) { if (vitalityImage == null) { continue; } String indicatorToolTip = vitalityImage.getToolTip(); if (indicatorToolTip == null || !vitalityImage.isVisible()) { continue; } Rectangle hitArea = vitalityImage.getHitArea(); if (hitArea == null) { continue; } if (hitArea.contains(mousePos_RelativeToItem)) { return indicatorToolTip; } } if (mdiEntry.getViewTitleInfo() != null) { String tt = (String) mdiEntry.getViewTitleInfo().getTitleInfoProperty(ViewTitleInfo.TITLE_INDICATOR_TEXT_TOOLTIP); return tt; } return null; }
Example 13
Source File: BreadcrumbItemDropDown.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * Returns the monitor whose client area contains the given point. If no * monitor contains the point, returns the monitor that is closest to the * point. * <p> * Copied from * <code>org.eclipse.jface.window.Window.getClosestMonitor(Display, Point)</code> * </p> * * @param display * the display showing the monitors * @param point * point to find (display coordinates) * @return the monitor closest to the given point */ private static Monitor getClosestMonitor( Display display, Point point ) { int closest = Integer.MAX_VALUE; Monitor[] monitors = display.getMonitors( ); Monitor result = monitors[0]; for ( int i = 0; i < monitors.length; i++ ) { Monitor current = monitors[i]; Rectangle clientArea = current.getClientArea( ); if ( clientArea.contains( point ) ) return current; int distance = Geometry.distanceSquared( Geometry.centerPoint( clientArea ), point ); if ( distance < closest ) { closest = distance; result = current; } } return result; }
Example 14
Source File: GridCellSpanManager.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
private Rectangle findSpanRectangle(int columnIndex, int rowIndex) { Iterator iter = listOfCellSpanRectangles.iterator(); while (iter.hasNext()) { Rectangle cellSpanRectangle = (Rectangle) iter.next(); if (cellSpanRectangle.contains(columnIndex, rowIndex)) { return cellSpanRectangle; } } return null; }
Example 15
Source File: BooleanCellEditor.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ public boolean handleClick(JaretTable table, IRow row, IColumn column, Rectangle drawingArea, int x, int y) { if (_singleClick) { Rectangle rect = new Rectangle(drawingArea.x + (drawingArea.width - SELECTION_DELTA) / 2, drawingArea.y + (drawingArea.height - SELECTION_DELTA) / 2, SELECTION_DELTA, SELECTION_DELTA); if (rect.contains(x, y)) { toggle(row, column); return true; } } return false; }
Example 16
Source File: AbstractDialog.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Gets the hit column. * * @param item the item * @param p the p * @return the hit column */ public int getHitColumn(TreeItem item, Point p) { for (int i = item.getParent().getColumnCount() - 1; i >= 0; i--) { Rectangle columnBounds = item.getBounds(i); if (columnBounds.contains(p)) return i; } return -1; }
Example 17
Source File: TableCombo.java From tmxeditor8 with GNU General Public License v2.0 | 4 votes |
/** * Handles Popup Events * @param event */ private void popupEvent(Event event) { switch (event.type) { case SWT.Paint: // draw rectangle around table Rectangle tableRect = table.getBounds(); event.gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION)); event.gc.drawRectangle(0, 0, tableRect.width + 1, tableRect.height + 1); break; case SWT.Close: event.doit = false; dropDown(false); break; case SWT.Deactivate: /* * Bug in GTK. When the arrow button is pressed the popup control receives a deactivate event and then the * arrow button receives a selection event. If we hide the popup in the deactivate event, the selection * event will show it again. To prevent the popup from showing again, we will let the selection event of the * arrow button hide the popup. In Windows, hiding the popup during the deactivate causes the deactivate to * be called twice and the selection event to be disappear. */ if (!"carbon".equals(SWT.getPlatform())) { Point point = arrow.toControl(getDisplay().getCursorLocation()); Point size = arrow.getSize(); Rectangle rect = new Rectangle(0, 0, size.x, size.y); if (!rect.contains(point)) dropDown(false); } else { dropDown(false); } break; case SWT.Help: if (isDropped()) { dropDown(false); } Composite comp = TableCombo.this; do { if (comp.getListeners(event.type) != null && comp.getListeners(event.type).length > 0) { comp.notifyListeners(event.type, event); break; } comp = comp.getParent(); } while (null != comp); break; } }
Example 18
Source File: TableCombo.java From nebula with Eclipse Public License 2.0 | 4 votes |
/** * Handles Popup Events * * @param event */ private void popupEvent(final Event event) { switch (event.type) { case SWT.Paint: // draw rectangle around table final Rectangle tableRect = table.getBounds(); event.gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION)); event.gc.drawRectangle(0, 0, tableRect.width + 1, tableRect.height + 1); break; case SWT.Close: event.doit = false; dropDown(false); break; case SWT.Deactivate: /* * Bug in GTK. When the arrow button is pressed the popup control receives a * deactivate event and then the arrow button receives a selection event. If we * hide the popup in the deactivate event, the selection event will show it * again. To prevent the popup from showing again, we will let the selection * event of the arrow button hide the popup. In Windows, hiding the popup during * the deactivate causes the deactivate to be called twice and the selection * event to be disappear. */ if (!"carbon".equals(SWT.getPlatform())) { final Point point = arrow.toControl(getDisplay().getCursorLocation()); final Point size = arrow.getSize(); final Rectangle rect = new Rectangle(0, 0, size.x, size.y); if (!rect.contains(point)) { dropDown(false); } } else { dropDown(false); } break; case SWT.Help: if (isDropped()) { dropDown(false); } Composite comp = TableCombo.this; do { if (comp.getListeners(event.type) != null && comp.getListeners(event.type).length > 0) { comp.notifyListeners(event.type, event); break; } comp = comp.getParent(); } while (null != comp); break; } }
Example 19
Source File: GData1.java From ldparteditor with MIT License | 4 votes |
@Override public void drawGL20_CoplanarityHeatmap(Composite3D c3d) { if (!visible) return; if (matrix != null) { final Rectangle bounds = c3d.getClientArea(); final PerspectiveCalculator PC = c3d.getPerspectiveCalculator(); Vector4f bbmin = new Vector4f(); Vector4f bbmax = new Vector4f(); Vector4f c1 = new Vector4f(boundingBoxMin); Vector4f c2 = new Vector4f(boundingBoxMin); Vector4f c3 = new Vector4f(boundingBoxMin); Vector4f c4 = new Vector4f(boundingBoxMin); Vector4f c5 = new Vector4f(boundingBoxMax); Vector4f c6 = new Vector4f(boundingBoxMax); Vector4f c7 = new Vector4f(boundingBoxMax); Vector4f c8 = new Vector4f(boundingBoxMax); c2.x = boundingBoxMax.x; c3.y = boundingBoxMax.y; c4.z = boundingBoxMax.z; c6.x = boundingBoxMin.x; c7.y = boundingBoxMin.y; c8.z = boundingBoxMin.z; c1.set(PC.getScreenCoordinatesFrom3D(c1.x, c1.y, c1.z)); c2.set(PC.getScreenCoordinatesFrom3D(c2.x, c2.y, c2.z)); c3.set(PC.getScreenCoordinatesFrom3D(c3.x, c3.y, c3.z)); c4.set(PC.getScreenCoordinatesFrom3D(c4.x, c4.y, c4.z)); c5.set(PC.getScreenCoordinatesFrom3D(c5.x, c5.y, c5.z)); c6.set(PC.getScreenCoordinatesFrom3D(c6.x, c6.y, c6.z)); c7.set(PC.getScreenCoordinatesFrom3D(c7.x, c7.y, c7.z)); c8.set(PC.getScreenCoordinatesFrom3D(c8.x, c8.y, c8.z)); bbmin.x = Math.min(c1.x, Math.min(c2.x, Math.min(c3.x, Math.min(c4.x, Math.min(c5.x, Math.min(c6.x, Math.min(c7.x, c8.x))))))); bbmax.x = Math.max(c1.x, Math.max(c2.x, Math.max(c3.x, Math.max(c4.x, Math.max(c5.x, Math.max(c6.x, Math.max(c7.x, c8.x))))))); bbmin.y = Math.min(c1.y, Math.min(c2.y, Math.min(c3.y, Math.min(c4.y, Math.min(c5.y, Math.min(c6.y, Math.min(c7.y, c8.y))))))); bbmax.y = Math.max(c1.y, Math.max(c2.y, Math.max(c3.y, Math.max(c4.y, Math.max(c5.y, Math.max(c6.y, Math.max(c7.y, c8.y))))))); Rectangle boundingBox = new Rectangle((int) bbmin.x, (int) bbmin.y, (int) (bbmax.x - bbmin.x), (int) (bbmax.y - bbmin.y)); boolean tempNegativeDeterminant = GData.globalNegativeDeterminant; GData.globalNegativeDeterminant = GData.globalNegativeDeterminant ^ negativeDeterminant; if (boundingBox.intersects(bounds) || boundingBox.contains(0, 0) || boundingBox.contains(bounds.width, bounds.height) || boundingBox.contains(bounds.width, 0) || boundingBox.contains(0, bounds.height) || bounds.contains(boundingBox.x, boundingBox.y) || bounds.contains(boundingBox.x, boundingBox.y + boundingBox.height) || bounds.contains(boundingBox.x + boundingBox.width, boundingBox.y) || bounds.contains(boundingBox.x + boundingBox.width, boundingBox.y + boundingBox.height)) { GL11.glPushMatrix(); GL11.glMultMatrixf(matrix); if (c3d.isShowingLogo()) { if (filesWithLogo1.contains(shortName)) drawStudLogo1_GL20(); else if (filesWithLogo2.contains(shortName)) drawStudLogo2_GL20(); } GData data2draw = myGData; if (GData.accumClip > 0) { GData.accumClip++; while ((data2draw = data2draw.next) != null && !ViewIdleManager.pause[0].get()) data2draw.drawGL20_CoplanarityHeatmap(c3d); GData.accumClip--; } else { while ((data2draw = data2draw.next) != null && !ViewIdleManager.pause[0].get()) data2draw.drawGL20_CoplanarityHeatmap(c3d); if (GData.accumClip > 0) GData.accumClip = 0; } GL11.glPopMatrix(); } GData.globalNegativeDeterminant = tempNegativeDeterminant; } }
Example 20
Source File: CellRendererBase.java From tmxeditor8 with GNU General Public License v2.0 | 2 votes |
/** * Check whether a position is in the area of the commetn marker. * * @param area drawing area of the cell * @param size size of the marker * @param x x coordinate to check * @param y y coordinate to check * @return true if the position is in the area of the marker */ protected boolean isInCommentMarkerArea(Rectangle area, int size, int x, int y) { Rectangle r = new Rectangle(area.x + area.width - size, area.y, size, size); return r.contains(x, y); }