/* (non-Javadoc) * @see org.eclipse.vtp.desktop.editors.core.theme.ElementFrame#getIncursionPoint(int, int) */ public Point getIncursionPoint(int x, int y) { if ((upperLeft == null) || (lowerRight == null)) { return null; } Point p1 = new Point(x, y); Point p2 = new Point(uiElement.getCenterPoint().x, uiElement.getCenterPoint().y); Point ret = getIntersection( p1, p2, new Point(upperLeft.x, upperLeft.y), new Point(lowerRight.x, upperLeft.y)); if (ret == null) { ret = getIntersection( p1, p2, new Point(lowerRight.x, upperLeft.y), new Point(lowerRight.x, lowerRight.y)); } if (ret == null) { ret = getIntersection( p1, p2, new Point(upperLeft.x, upperLeft.y), new Point(upperLeft.x, lowerRight.y)); } if (ret == null) { ret = getIntersection( p1, p2, new Point(upperLeft.x, lowerRight.y), new Point(lowerRight.x, lowerRight.y)); } return ret; }
/* (non-Javadoc) * @see org.eclipse.vtp.desktop.editors.core.theme.ComponentFrame#adjustPosition(int, int) */ public void adjustPosition(int xoffset, int yoffset) { Point newCenter = new Point(uiElement.getCenterPoint().x + xoffset, uiElement.getCenterPoint().y + yoffset); uiElement.setCenterPoint(newCenter); upperLeft.x = upperLeft.x + xoffset; upperLeft.y = upperLeft.y + yoffset; lowerRight.x = lowerRight.x + xoffset; lowerRight.y = lowerRight.y + yoffset; }
/* (non-Javadoc) * @see org.eclipse.vtp.desktop.editors.core.theme.ComponentFrame#initializeGraphics(org.eclipse.swt.graphics.GC, java.util.Map) */ public void initializeGraphics(GC gc, Map<String, Object> resourceMap) { Font originalFont = gc.getFont(); Font nameFont = new Font(gc.getDevice(), "Arial", 10, SWT.NORMAL); gc.setFont(nameFont); Point extent = gc.stringExtent(this.getDesignElement().getName()); if (extent.x > 110) // too long, attempt to wrap text { extent.x = 0; String[] parts = this.getDesignElement().getName().split(" "); Point stringExtent = gc.stringExtent(parts[0]); int ew = 0; ew += stringExtent.x; extent.x = stringExtent.x; for (int i = 1; i < parts.length; i++) { stringExtent = gc.stringExtent(" " + parts[i]); if (ew + stringExtent.x > 110) // wrap it { stringExtent = gc.stringExtent(parts[i]); if (extent.x < ew) extent.x = ew; ew = stringExtent.x; extent.y += 2 + stringExtent.y; } else ew += stringExtent.x; } if (extent.x < ew) extent.x = ew; } int width = (extent.x + 35); int height = (extent.y + 10 + (uiElement.hasConnectors() ? 12 : 0)); Point centerPoint = uiElement.getCenterPoint(); upperLeft = new Point(centerPoint.x - (width / 2), centerPoint.y - (height / 2)); int buffer = width % 2; lowerRight = new Point(upperLeft.x + width + buffer, upperLeft.y + height + buffer); gc.setFont(originalFont); nameFont.dispose(); }
/* (non-Javadoc) * @see org.eclipse.vtp.desktop.editors.core.theme.ElementFrame#alignCenter(int, int) */ public void alignCenter(int orientation, int xy) { int diffX = 0; int diffY = 0; Point center = uiElement.getCenterPoint(); if (orientation == SWT.HORIZONTAL) { diffY = xy - center.y; } else if (orientation == SWT.VERTICAL) { diffX = xy - center.x; } else return; adjustPosition(diffX, diffY); this.fireChange(); }