use of org.eclipse.draw2d.Viewport in project yamcs-studio by yamcs.
the class AbstractSWTWidgetFigure method doRelocateWidget.
private void doRelocateWidget() {
boolean sizeWasSet = false;
Rectangle clientArea = getClientArea();
Rectangle rect = clientArea.getCopy();
translateToAbsolute(rect);
// scale the font if necessary
double scale = (double) rect.height / (double) clientArea.height;
if (Math.abs(scale - 1) > 0.05) {
if (Math.abs(scale - lastScale) >= 0.05) {
FontData fontData = getFont().getFontData()[0];
FontData newFontData = new FontData(fontData.getName(), Math.max((int) (fontData.getHeight() * scale), 0), fontData.getStyle());
getSWTWidget().setFont(CustomMediaFactory.getInstance().getFont(newFontData));
lastScale = scale;
}
} else if (getSWTWidget().getFont() != getFont())
getSWTWidget().setFont(getFont());
// }
if (wrapComposite != null && getParent().getParent() instanceof Viewport) {
Rectangle viewPortArea = getParent().getParent().getClientArea();
getParent().translateToAbsolute(viewPortArea);
clientArea = rect;
isIntersectViewPort = viewPortArea.intersects(clientArea);
if (isIntersectViewPort) {
// if the SWT widget is cut by viewPort
if (!viewPortArea.contains(clientArea)) {
Rectangle intersection = viewPortArea.getIntersection(clientArea);
org.eclipse.swt.graphics.Rectangle oldBounds = wrapComposite.getBounds();
if (oldBounds.x != (rect.x + intersection.x - clientArea.x) || oldBounds.y != (rect.y + intersection.y - clientArea.y) || oldBounds.width != intersection.width || oldBounds.height != intersection.height) {
wrapComposite.setBounds(rect.x + intersection.x - clientArea.x, rect.y + intersection.y - clientArea.y, intersection.width, intersection.height);
}
oldBounds = getSWTWidget().getBounds();
if (oldBounds.x != (clientArea.x - intersection.x) || oldBounds.y != (clientArea.y - intersection.y) || oldBounds.width != rect.width || oldBounds.height != rect.height) {
getSWTWidget().setBounds(clientArea.x - intersection.x, clientArea.y - intersection.y, rect.width, rect.height);
}
sizeWasSet = true;
} else {
Point oldLoc = getSWTWidget().getLocation();
if (oldLoc.x != 0 || oldLoc.y != 0)
getSWTWidget().setLocation(0, 0);
}
}
}
if (!sizeWasSet) {
if (wrapComposite != null) {
Rectangle oldBounds = new Rectangle(wrapComposite.getBounds());
if (!oldBounds.equals(rect))
wrapComposite.setBounds(rect.x, rect.y, rect.width, rect.height);
Point oldSize = getSWTWidget().getSize();
if (oldSize.x != rect.width || oldSize.y != rect.height)
getSWTWidget().setSize(rect.width, rect.height);
} else if (!getSWTWidget().getBounds().equals(new org.eclipse.swt.graphics.Rectangle(rect.x, rect.y, rect.width, rect.height)))
getSWTWidget().setBounds(rect.x, rect.y, rect.width, rect.height);
}
}
use of org.eclipse.draw2d.Viewport in project whole by wholeplatform.
the class ViewportTrackingStrategy method calculateTranslateAmount.
@SuppressWarnings("unchecked")
protected Point calculateTranslateAmount() {
translateAmount.setLocation(0, 0);
if (childrenBounds.length == 0)
return translateAmount;
Viewport viewport = getViewport();
LayeredPane layeredPane = (LayeredPane) viewport.getContents();
ScalableFigure scalableLayeredPane = (ScalableFigure) layeredPane.getLayer(LayerConstants.SCALABLE_LAYERS);
Rectangle clientArea = viewport.getClientArea().scale(1 / scalableLayeredPane.getScale());
Rectangle bounds = hostFigure.getBounds();
if (!bounds.intersects(clientArea))
return translateAmount;
if (compositeBounds == null) {
List<IFigure> children = hostFigure.getChildren();
compositeBounds = new Rectangle(children.get(0).getBounds());
compositeBounds.translate(-bounds.x, -bounds.y);
for (int i = 0; i < childrenBounds.length; i++) {
childrenBounds[i].setBounds(children.get(i).getBounds());
childrenBounds[i].translate(-bounds.x, -bounds.y);
compositeBounds.union(childrenBounds[i]);
}
}
Rectangle compositeBounds = Rectangle.SINGLETON.setBounds(this.compositeBounds);
compositeBounds.translate(hostFigure.getBounds().x, hostFigure.getBounds().y);
int minDX = bounds.x - compositeBounds.x;
int minDY = bounds.y - compositeBounds.y;
int maxDX = bounds.right() - compositeBounds.right();
int maxDY = bounds.bottom() - compositeBounds.bottom();
if (clientArea.height < compositeBounds.height && clientArea.width < compositeBounds.width)
return translateAmount;
if (viewportTracking.isHorizontal())
translateAmount.setX(Math.max(minDX, Math.min(maxDX, clientArea.x > compositeBounds.x ? clientArea.x - compositeBounds.x : (compositeBounds.right() > clientArea.right() ? clientArea.right() - compositeBounds.right() : 0))));
if (viewportTracking.isVertical())
translateAmount.setY(Math.max(minDY, Math.min(maxDY, clientArea.y > compositeBounds.y ? clientArea.y - compositeBounds.y : (compositeBounds.bottom() > clientArea.bottom() ? clientArea.bottom() - compositeBounds.bottom() : 0))));
return translateAmount;
}
use of org.eclipse.draw2d.Viewport in project archi by archimatetool.
the class MouseWheelHorizontalScrollHandler method handleMouseWheel.
/**
* Zooms the given viewer.
*
* @see MouseWheelHandler#handleMouseWheel(Event, EditPartViewer)
*/
@Override
public void handleMouseWheel(Event event, EditPartViewer viewer) {
ZoomManager zoomMgr = (ZoomManager) viewer.getProperty(ZoomManager.class.toString());
if (zoomMgr != null) {
Viewport viewport = zoomMgr.getViewport();
if (viewport != null) {
viewport.setViewLocation(viewport.getViewLocation().translate(event.count * DELTA * DIRECTION, 0));
event.doit = false;
}
}
}
use of org.eclipse.draw2d.Viewport in project archi by archimatetool.
the class ScalableRootEditPart method createFigure.
/**
* @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
*/
@Override
protected IFigure createFigure() {
Viewport viewport = createViewport();
innerLayers = new LayeredPane();
createLayers(innerLayers);
viewport.setContents(innerLayers);
return viewport;
}
use of org.eclipse.draw2d.Viewport in project archi by archimatetool.
the class ViewportAutoexposeHelper method step.
/**
* Returns <code>true</code> if the given point is outside the viewport or
* near its edge. Scrolls the viewport by a calculated (time based) amount
* in the current direction.
*
* todo: investigate if we should allow auto expose when the pointer is
* outside the viewport
*
* Phillipus added option to allow auto expose when the pointer is outside!
*
* @see org.eclipse.gef.AutoexposeHelper#step(org.eclipse.draw2d.geometry.Point)
*/
@Override
public boolean step(Point where) {
Viewport port = findViewport(owner);
Rectangle rect = Rectangle.SINGLETON;
port.getClientArea(rect);
port.translateToParent(rect);
port.translateToAbsolute(rect);
if (!(continueOutside || rect.contains(where)) || rect.shrink(threshold).contains(where))
return false;
// set scroll offset (speed factor)
int scrollOffset = 0;
// calculate time based scroll offset
if (lastStepTime == 0)
lastStepTime = System.currentTimeMillis();
long difference = System.currentTimeMillis() - lastStepTime;
if (difference > 0) {
scrollOffset = ((int) difference / 3);
lastStepTime = System.currentTimeMillis();
}
if (scrollOffset == 0)
return true;
rect.shrink(threshold);
int region = rect.getPosition(where);
Point loc = port.getViewLocation();
if ((region & PositionConstants.SOUTH) != 0)
loc.y += scrollOffset;
else if ((region & PositionConstants.NORTH) != 0)
loc.y -= scrollOffset;
if ((region & PositionConstants.EAST) != 0)
loc.x += scrollOffset;
else if ((region & PositionConstants.WEST) != 0)
loc.x -= scrollOffset;
port.setViewLocation(loc);
return true;
}
Aggregations