private Rectangle getDisplayBounds(final Point location) { Rectangle displayBounds; final Monitor[] allMonitors = _ownerControl.getDisplay().getMonitors(); if (allMonitors.length > 1) { // By default present in the monitor of the control displayBounds = _ownerControl.getMonitor().getBounds(); final Point p = new Point(location.x, location.y); // Search on which monitor the event occurred Rectangle tmp; for (final Monitor element : allMonitors) { tmp = element.getBounds(); if (tmp.contains(p)) { displayBounds = tmp; break; } } } else { displayBounds = _ownerControl.getDisplay().getBounds(); } return displayBounds; }
private Point fixupDisplayBounds(final Point tipSize, final Point location) { final Rectangle displayBounds = getDisplayBounds(location); final Point rightBottomBounds = new Point(tipSize.x + location.x, tipSize.y + location.y); if (!(displayBounds.contains(location) && displayBounds.contains(rightBottomBounds))) { if (rightBottomBounds.x > displayBounds.x + displayBounds.width) { location.x -= rightBottomBounds.x - (displayBounds.x + displayBounds.width); } if (rightBottomBounds.y > displayBounds.y + displayBounds.height) { // ignore when tt is below the bottom, force the user to resize the tt // location.y -= rightBottomBounds.y - (displayBounds.y + displayBounds.height); } if (location.x < displayBounds.x) { location.x = displayBounds.x; } if (location.y < displayBounds.y) { location.y = displayBounds.y; } } return location; }
public void positionWindow(boolean resetToDefault) { String mapWindow; mapShellBounds = mapShell.getBounds(); mapWindow = prefs.get(RadarConsts.PREF_KEY_MAP_WINDOW, ""); if (mapWindow.equals("") || resetToDefault) { Rectangle dispBounds, tableBounds; dispBounds = ((Display.getCurrent()).getPrimaryMonitor()).getClientArea(); tableBounds = display.getShells()[1].getBounds(); mapShellBounds.width = dispBounds.width - tableBounds.width; mapShellBounds.height = dispBounds.height; mapShellBounds.x = dispBounds.x + tableBounds.width; mapShellBounds.y = dispBounds.y; } else { String[] tokens = mapWindow.split(","); mapShellBounds = new Rectangle( new Integer(tokens[0]), // X value new Integer(tokens[1]), // Y value new Integer(tokens[2]), // Width new Integer(tokens[3]) // Height ); } mapShell.setBounds(mapShellBounds); }
protected void drawBottomSpace(GC gc) { Rectangle r = getClientArea(); if (m_Model.getRowCount() > 0) { r.y = m_Model.getFirstRowHeight() + (m_Model.getFixedRowCount() - 1 + m_RowsVisible) * m_Model.getRowHeight() + 1; } gc.setBackground(getBackground()); gc.fillRectangle(r); gc.fillRectangle(getLastColumnRight() + 2, 0, r.width, r.height); if (m_Model.getRowCount() > 0) { if (flatStyleSpecified) // gc.setForeground(this.getBackground()); gc.setForeground(m_Display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); else gc.setForeground(m_Display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW)); // Linke Schattenlinie gc.drawLine(0, 0, 0, r.y - 1); } if (!flatStyleSpecified) gc.setForeground(this.getBackground()); else gc.setForeground(m_Display.getSystemColor(SWT.COLOR_WHITE)); // Untere Abschlusslinie gc.drawLine(0, r.y - 1, getLastColumnRight() + 1, r.y - 1); // Rechte Abschlusslinie gc.drawLine(getLastColumnRight() + 1, 0, getLastColumnRight() + 1, r.y - 1); }
public void addExpressionRow(String expressionName) { RowData rowdata = (RowData) expressionGroup.getLayoutData(); rowdata.height += 120; expressionGroup.setLayoutData(new RowData(rowdata.width, rowdata.height)); Rectangle rect = expressionGroup.getBounds(); rect.height += 120; expressionGroup.setBounds(rect); /*Create a row*/ ExpressionBean expBean = expressions.get(new Integer(expCount - 1)); Label previousLabel = expBean.getLabel(); rect = previousLabel.getBounds(); Label lblNew = new Label(expressionGroup, SWT.NONE); lblNew.setBounds(10, rect.y + 90, 120, 15); lblNew.setText(expressionName); lblNew.setFocus(); Text previousText = expBean.getText(); rect = previousText.getBounds(); Text newText = new Text(expressionGroup, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI); newText.setBounds(135, rect.y + 90, 550, 70); expressions.put(new Integer(expCount), new ExpressionBean(lblNew, newText)); expCount++; expScrolledComposite.setMinSize(expressionGroup.computeSize(SWT.DEFAULT, SWT.DEFAULT)); }
/** * Scrolls the containing editor to the given offset of the contained editor * * @param editor * @param scrollTo text offset in the embedded editor that should be revealed */ public void revealSelection(ContainedEditorManager editor, int scrollTo) { StyledText containedStyledText = (StyledText) editor.getAdapter(StyledText.class); // this progression determines the location of the offset in the coordinate system // of the containing styledText Point containedLoc = containedStyledText.getLocationAtOffset(scrollTo); Point displayLoc = containedStyledText.toDisplay(containedLoc); Point containingLoc = styledText.toControl(displayLoc); // next, we determine if this location is in the visible area. Point containingSize = styledText.getSize(); Rectangle containingBounds = new Rectangle(0, 0, containingSize.x, containingSize.y); if (!containingBounds.contains(containingLoc)) { // pad a little to the left and a little bit down containingLoc.x -= 50; containingLoc.y += 100; // if not, then perform a scroll. styledText.setTopPixel(styledText.getTopPixel() + containingLoc.y - containingSize.y); // do the same for horizontal styledText.setHorizontalPixel(styledText.getHorizontalPixel() + containingLoc.x); } paint(ContainingEditor.EMBEDDED_REPAINT); }
public Rectangle getBounds() { int minx = Integer.MAX_VALUE; int miny = Integer.MAX_VALUE; int maxx = Integer.MIN_VALUE; int maxy = Integer.MIN_VALUE; for (int i = 0; i < pieces.size(); i++) { PipAnimateFramePiece piece = pieces.get(i); double[][] points = piece.getBounds(); for (int j = 0; j < 4; j++) { int px = (int) points[j][0]; int py = (int) points[j][1]; if (px < minx) { minx = px; } if (py < miny) { miny = py; } if (px > maxx) { maxx = px; } if (py > maxy) { maxy = py; } } } Rectangle rect = new Rectangle(minx, miny, maxx - minx, maxy - miny); if (rect.isEmpty()) { rect = new Rectangle(0, 0, 16, 16); } return rect; }
/** * @see ch.post.pf.gui.ocp.wt.ext.dialogs.OcpDialog#showDialogFor(org.eclipse.swt.widgets.Control) */ public int showDialogFor(Control field) { create(); getShell() .addShellListener( new ShellAdapter() { @Override public void shellDeactivated(ShellEvent e) { close(); } }); // make sure that the popup fit into the application window. Rectangle appBounds = getEnvironment().getDisplay().getBounds(); Point absPrefPos = field.toDisplay(field.getSize().x - getShell().getSize().x, field.getSize().y); Rectangle prefBounds = new Rectangle(absPrefPos.x, absPrefPos.y, getShell().getSize().x, getShell().getSize().y); // horizontal correction if (prefBounds.x + prefBounds.width > appBounds.width) { prefBounds.x = appBounds.width - prefBounds.width; } // vertical correciton if (prefBounds.y + prefBounds.height > appBounds.height) { prefBounds.y = appBounds.height - prefBounds.height; } getShell().setLocation(prefBounds.x, prefBounds.y); int ret = this.open(); return ret; }
public void handleEvent(final Event event) { // only go further if the event has a new time stamp if (mayScroll() && acceptEvent(event)) { lastEventTime = event.time; final Rectangle navigationComponentBounds = getNavigationComponent().getBounds(); // convert navigation bounds relative to display final Point navigationPtAtDisplay = getNavigationComponent().toDisplay(0, 0); navigationComponentBounds.x = navigationPtAtDisplay.x; navigationComponentBounds.y = navigationPtAtDisplay.y; if (event.widget instanceof Control) { final Control widget = (Control) event.widget; // convert widget event point relative to display final Point evtPt = widget.toDisplay(event.getBounds().x, event.getBounds().y); // now check if inside navigation if (navigationComponentBounds.contains(evtPt.x, evtPt.y)) { if (event.count > 0) { scrollUp(SCROLLING_STEP); } else { scrollDown(SCROLLING_STEP); } } } } }
LRESULT WM_MOUSEMOVE(int /*long*/ wParam, int /*long*/ lParam) { LRESULT result = super.WM_MOUSEMOVE(wParam, lParam); if (OS.COMCTL32_MAJOR < 6) { int x = OS.GET_X_LPARAM(lParam); int y = OS.GET_Y_LPARAM(lParam); if (OS.GetKeyState(OS.VK_LBUTTON) < 0) { int oldSelection = selection.y; selection.y = layout.getOffset(x, y, null); if (selection.y != oldSelection) { int newSelection = selection.y; if (oldSelection > newSelection) { int temp = oldSelection; oldSelection = newSelection; newSelection = temp; } Rectangle rect = layout.getBounds(oldSelection, newSelection); redraw(rect.x, rect.y, rect.width, rect.height, false); } } else { for (int j = 0; j < offsets.length; j++) { Rectangle[] rects = getRectangles(j); for (int i = 0; i < rects.length; i++) { Rectangle rect = rects[i]; if (rect.contains(x, y)) { setCursor(display.getSystemCursor(SWT.CURSOR_HAND)); return result; } } } setCursor(null); } } return result; }
/** * Draws the current line highlight (over top using theme colors and alpha). If the line highlight * is fully opaque, then this method will not do anything and we'll fall back to using the * mechanism eclipse does in CursorLinePainter with a little modification. */ public void paintControl(PaintEvent e) { // if highlight current line is disabled, don't draw! if (!fEnabled) { return; } // If there's no alpha value for the line highlight, then we need to force the bg color of the // whole line // to the rgb value! RGBa lineHighlight = getCurrentTheme().getLineHighlight(); if (lineHighlight.isFullyOpaque()) { return; } Rectangle rect = new Rectangle(e.x, e.y, e.width, e.height); Rectangle lineRect = getLineRectangle(getCurrentLinePosition()); if (lineRect == null || !lineRect.intersects(rect)) { return; } int previousAlpha = e.gc.getAlpha(); Color previousBG = e.gc.getBackground(); e.gc.setAlpha(lineHighlight.getAlpha()); e.gc.setBackground(getColorManager().getColor(lineHighlight.toRGB())); // Only paint the part of lineRect that is contained in rect! e.gc.fillRectangle(lineRect.intersection(rect)); // BUGFIX: need to set alpha and background color back to what they were before or it breaks // the painting of pair matching! e.gc.setAlpha(previousAlpha); e.gc.setBackground(previousBG); }
private IHyperlink getHyperlink(MouseEvent e) { // bug 257868 support image hyperlinks if (annotations.isEmpty()) { return null; } Point point = new Point(e.x, e.y); for (ImageAnnotation annotation : annotations) { if (annotation.getHyperlnkAnnotation() == null) { continue; } Rectangle region = getRegion(annotation); if (region != null) { if (region.contains(point)) { AnnotationHyperlinkDetector detector = (AnnotationHyperlinkDetector) viewer.getTextWidget().getData(AnnotationHyperlinkDetector.class.getName()); if (detector != null) { IHyperlink hyperlink = detector.createHyperlink( viewer, viewer.getAnnotationModel(), annotation.getHyperlnkAnnotation()); return hyperlink; } } } } return null; }
@Override public void draw(IBNAView view, ICoordinateMapper cm, GL2 gl, Rectangle clip, IResources r) { if (control == null) { control = createControl(view, cm); } // update bounds final Rectangle newBounds = getBounds(control, view, cm); final Rectangle oldBounds = control.getBounds(); if (!oldBounds.equals(newBounds)) { SWTWidgetUtils.async( control, new Runnable() { @Override public void run() { if (oldBounds.width != newBounds.width || oldBounds.height != newBounds.height) { control.setSize(newBounds.width, newBounds.height); if (control instanceof Composite) { ((Composite) control).layout(true, true); control.pack(true); } } control.setLocation(newBounds.x, newBounds.y); } }); } }
/** * Hook to compute the menu location if the focus widget is a tree widget. * * @param tree the tree widget that has the focus * @return a widget relative position of the menu to pop up or <code>null</code> if now position * inside the widget can be computed */ protected Point computeMenuLocation(Tree tree) { TreeItem[] items = tree.getSelection(); Rectangle clientArea = tree.getClientArea(); switch (items.length) { case 0: return null; case 1: Rectangle bounds = items[0].getBounds(); Rectangle intersect = clientArea.intersection(bounds); if (intersect != null && intersect.height == bounds.height) { return new Point( Math.max(0, bounds.x + getAvarageCharWith(tree) * CHAR_INDENT), bounds.y + bounds.height); } else { return null; } default: Rectangle[] rectangles = new Rectangle[items.length]; for (int i = 0; i < rectangles.length; i++) { rectangles[i] = items[i].getBounds(); } Point cursorLocation = tree.getDisplay().getCursorLocation(); Point result = findBestLocation( getIncludedPositions(rectangles, clientArea), tree.toControl(cursorLocation)); if (result != null) result.x = result.x + getAvarageCharWith(tree) * CHAR_INDENT; return result; } }
public void addDescriptionRow(String sectionName) { RowData rowdata = (RowData) descriptionGroup.getLayoutData(); rowdata.height += 60; descriptionGroup.setLayoutData(new RowData(rowdata.width, rowdata.height)); Rectangle rect = descriptionGroup.getBounds(); rect.height += 60; descriptionGroup.setBounds(rect); /*Add the row*/ Text prevText = sections.get(new Integer(secCount - 1)).getEndTokens(); rect = prevText.getBounds(); Text newText_1 = new Text(descriptionGroup, SWT.BORDER); newText_1.setBounds(10, rect.y + 40, 75, 20); newText_1.setFocus(); Label lblNew = new Label(descriptionGroup, SWT.NONE); lblNew.setBounds(120, rect.y + 40, 145, 20); lblNew.setText(sectionName); Text newText_2 = new Text(descriptionGroup, SWT.BORDER); newText_2.setBounds(270, rect.y + 40, 115, 20); Text newText_3 = new Text(descriptionGroup, SWT.BORDER); newText_3.setBounds(420, rect.y + 40, 115, 20); Text newText_4 = new Text(descriptionGroup, SWT.BORDER); newText_4.setBounds(570, rect.y + 40, 115, 20); sections.put( new Integer(secCount), new SectionBean(newText_1, lblNew, newText_2, newText_3, newText_4)); secCount++; descScrolledComposite.setMinSize(descriptionGroup.computeSize(SWT.DEFAULT, SWT.DEFAULT)); }
/** * Handling mouse over event to display hand cursor in case cell contains an URL * * @param e mouse event */ void handleMouseOver(MouseEvent e) { Point pt = new Point(e.x, e.y); ViewerCell cell = getViewer().getCell(pt); boolean cursorSet = false; if (cell != null) { int colIndex = cell.getColumnIndex(); Object element = cell.getElement(); if (getCellControlType(element, colIndex) == CellControlType.URL) { Rectangle cellBounds = cell.getBounds(); Image img = getImage(element, colIndex); if (img != null) { cellBounds.x += img.getBounds().width; } if (cellBounds.contains(pt)) { if (getString(element, colIndex) != null) { this.control.setCursor(CURSOR_HAND); cursorSet = true; } } } } if (!cursorSet) { handleMouseExit(e); } }
private Point computeMenuLocation(Control focus, Menu menu) { Point cursorLocation = focus.getDisplay().getCursorLocation(); Rectangle clientArea = null; Point result = null; if (focus instanceof StyledText) { StyledText styledText = (StyledText) focus; clientArea = styledText.getClientArea(); result = computeMenuLocation(styledText); } else if (focus instanceof Tree) { Tree tree = (Tree) focus; clientArea = tree.getClientArea(); result = computeMenuLocation(tree); } else if (focus instanceof Table) { Table table = (Table) focus; clientArea = table.getClientArea(); result = computeMenuLocation(table); } if (result == null) { result = focus.toControl(cursorLocation); } if (clientArea != null && !clientArea.contains(result)) { result = new Point(clientArea.x + clientArea.width / 2, clientArea.y + clientArea.height / 2); } Rectangle shellArea = focus.getShell().getClientArea(); if (!shellArea.contains(focus.getShell().toControl(focus.toDisplay(result)))) { result = new Point(shellArea.x + shellArea.width / 2, shellArea.y + shellArea.height / 2); } return focus.toDisplay(result); }
protected void mouseMoveSelectMode(MouseEvent e) { switch (dragging) { case DRAG_OBJECT: if (!draggedAway && (Math.abs(e.x - dragPoint.x) >= 5 || Math.abs(e.y - dragPoint.y) >= 5)) { draggedAway = true; startDraggingSelectedObjects(); } if (draggedAway) { dragSelectedObjectsBy(e.x - dragPoint.x, e.y - dragPoint.y); } break; case DRAG_SELECTIONRECTANGLE: if (!draggedAway && (Math.abs(e.x - dragPoint.x) >= 5 || Math.abs(e.y - dragPoint.y) >= 5)) { draggedAway = true; } if (draggedAway) { Rectangle r = new Rectangle(0, 0, 0, 0); r.x = Math.min(dragPoint.x, e.x); r.y = Math.min(dragPoint.y, e.y); r.width = Math.max(dragPoint.x, e.x) - r.x; r.height = Math.max(dragPoint.y, e.y) - r.y; setSelectionRectangle(r); } break; } }
@Override protected void paint(Event event, Object element) { ITerminoOntoAnnotation annotation = (ITerminoOntoAnnotation) element; ITerminoOntoAnnotationType annotationType = annotation.getTerminoOntoAnnotationType(); Image img = null; if (annotationType.getLabel().compareTo(DatabaseAdapter.LABEL_EN_ANNOTATION) == 0) { img = org.dafoe.terminoontologiclevel.ui.Activator.getDefault() .getImageRegistry() .get(org.dafoe.terminoontologiclevel.ui.Activator.US_FLAG_IMG_ID); } else if (annotationType.getLabel().compareTo(DatabaseAdapter.LABEL_SP_ANNOTATION) == 0) { img = org.dafoe.terminoontologiclevel.ui.Activator.getDefault() .getImageRegistry() .get(org.dafoe.terminoontologiclevel.ui.Activator.SP_FLAG_IMG_ID); } if (img != null) { Rectangle bounds = ((TableItem) event.item).getBounds(event.index); Rectangle imgBounds = img.getBounds(); bounds.width /= 2; bounds.width -= imgBounds.width / 2; bounds.height /= 2; bounds.height -= imgBounds.height / 2; int x = bounds.width > 0 ? bounds.x + bounds.width : bounds.x; int y = bounds.height > 0 ? bounds.y + bounds.height : bounds.y; event.gc.drawImage(img, x, y); } }
/** * Sets the clipping to the intersection of the current clip region and the specified rectangle. * * @param x the x-coordinate. * @param y the y-coordinate. * @param width the width. * @param height the height. */ @Override public void clipRect(int x, int y, int width, int height) { org.eclipse.swt.graphics.Rectangle clip = this.gc.getClipping(); org.eclipse.swt.graphics.Rectangle r = new org.eclipse.swt.graphics.Rectangle(x, y, width, height); clip.intersect(r); this.gc.setClipping(clip); }
/* * (non-Javadoc) * * @see org.eclipse.swt.widgets.Control#computeSize(int, int, boolean) */ public Point computeSize(int arg0, int arg1, boolean arg2) { checkWidget(); if (getExpanded()) return super.computeSize(arg0, arg1, arg2); Rectangle trim = strategy.computeTrim(0, 0, 0, 0); trim.width = super.computeSize(arg0, arg1, arg2).x; return new Point(trim.width, Math.max(trim.height, arg1)); }
private synchronized void calcPaddings(int width, int height) { Point canvasSize = getSize(); mPadding.x = (canvasSize.x - width) / 2; mPadding.y = (canvasSize.y - height) / 2; mPadding.width = width; mPadding.height = height; }
private Rectangle getDrawBounds(TableCellSWT cell) { Rectangle bounds = cell.getBounds(); bounds.height -= 12; bounds.y += 6; bounds.x += 4; bounds.width -= 4; return bounds; }
private void setHoverLocation( org.eclipse.swt.widgets.Shell shell, org.eclipse.swt.graphics.Point position) { org.eclipse.swt.graphics.Rectangle displayBounds = shell.getDisplay().getBounds(); org.eclipse.swt.graphics.Rectangle shellBounds = shell.getBounds(); shellBounds.x = Math.max(Math.min(position.x, displayBounds.width - shellBounds.width), 0); shellBounds.y = Math.max(Math.min(position.y + 16, displayBounds.height - shellBounds.height), 0); shell.setBounds(shellBounds); }
private static Rectangle calculateRulerTrim(Canvas canvas) { if ("carbon".equals(SWT.getPlatform())) { // $NON-NLS-1$ Rectangle trim = canvas.computeTrim(0, 0, 0, 0); trim.width = 0 - trim.x * 2; trim.height = 0 - trim.y * 2; return trim; } return new Rectangle(0, 0, 0, 0); }
/** * Scrolls the content so that the given revision is visible. * * @param revision the revision to scroll the client area to. */ private void scrollToRevision(Revision revision) { Rectangle revBounds = revision.getBounds(); Rectangle clientArea = getClientArea(); clientArea.x = getOrigin().x; clientArea.y = getOrigin().y; if (!clientArea.contains(revBounds.x, revBounds.y) && !clientArea.contains(revBounds.x + revBounds.width, revBounds.y + revBounds.height)) { setOrigin(revBounds.x, revBounds.y); } }
private Rectangle computeShellBounds() { Rectangle result = new Rectangle(0, 0, 0, 0); Point preferredSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT); Rectangle displaySize = parent.getDisplay().getBounds(); result.x = (displaySize.width - preferredSize.x) / 2 + displaySize.x; result.y = (displaySize.height - preferredSize.y) / 2 + displaySize.y; result.width = Math.min(preferredSize.x, MAX_WIDTH); result.height = preferredSize.y; return result; }
@Override protected Rectangle getConstrainedShellBounds(Rectangle preferredSize) { decideShellSize(getShell()); Rectangle rect = getShell().getDisplay().getClientArea(); rect.x = rect.width - shellWidth; rect.y = rect.height - shellHeight; rect.width = shellWidth; rect.height = shellHeight; return rect; }
public static int getColumnAtPos(TreeItem item, int x, int y) { int columnCount = item.getParent().getColumnCount(); for (int i = 0; i < columnCount; i++) { Rectangle rect = item.getBounds(i); if (rect.contains(x, y)) { return i; } } return -1; }
private void refreshProposalSize() { if (contentProposalAdapter != null) { Rectangle maxSize = new Rectangle(0, 0, MAX_WIDTH_PROPOSAL_STYLED_TEXT, MAX_HEIGHT_PROPOSAL_STYLED_TEXT); Rectangle boundsStyledText = StyledTextHandler.this.getStyledText().getBounds(); Rectangle intersect = boundsStyledText.intersection(maxSize); Point sizeProposal = new Point(intersect.width, intersect.height); contentProposalAdapter.setPopupSize(sizeProposal); } }