use of org.eclipse.draw2d.Viewport in project tdi-studio-se by Talend.
the class ZoneContentLayout method layout.
@Override
public void layout(IFigure parent) {
Rectangle vBounds = null;
if (parent.getParent() instanceof Viewport) {
vBounds = ((Viewport) parent.getParent()).getBounds();
}
int wHint = -1;
int hHint = -1;
if (isHorizontal()) {
hHint = parent.getClientArea(Rectangle.SINGLETON).height;
} else {
wHint = parent.getClientArea(Rectangle.SINGLETON).width;
}
List children = parent.getChildren();
int numChildren = children.size();
Rectangle clientArea = transposer.t(parent.getClientArea());
int x = clientArea.x;
int y = clientArea.y;
int availableHeight = clientArea.height;
Dimension[] prefSizes = new Dimension[numChildren];
Dimension[] minSizes = new Dimension[numChildren];
IFigure child;
int totalHeight = 0;
int totalMinHeight = 0;
int prefMinSumHeight = 0;
int connSize = 0;
// boolean isLookupConnMax = true;
for (int i = 0; i < numChildren; i++) {
child = (IFigure) children.get(i);
prefSizes[i] = transposer.t(getChildPreferredSize(child, wHint, hHint));
minSizes[i] = transposer.t(getChildMinimumSize(child, wHint, hHint));
totalHeight += prefSizes[i].height;
totalMinHeight += minSizes[i].height;
if (child instanceof AbstractTableContainer) {
connSize = getLookupConnectionSize((AbstractTableContainer) child);
}
}
totalHeight += (numChildren - 1) * spacing;
totalMinHeight += (numChildren - 1) * spacing;
prefMinSumHeight = totalHeight - totalMinHeight;
int defaultSize = DEFAULT_OFFSET;
for (int i = 0; i < numChildren; i++) {
int amntShrinkCurrentHeight = 0;
int prefHeight = prefSizes[i].height;
int minHeight = minSizes[i].height;
int prefWidth = prefSizes[i].width;
int minWidth = minSizes[i].width;
child = (IFigure) children.get(i);
Rectangle newBounds = new Rectangle(x, y, prefWidth, prefHeight);
if (connSize > 0) {
newBounds = new Rectangle(x + (connSize - 1) * defaultSize, y, prefWidth, prefHeight);
}
Border border = parent.getBorder();
Insets insets = border.getInsets(child);
if (vBounds != null) {
newBounds.width = vBounds.width - insets.left - insets.right;
if (connSize > 0) {
newBounds.width = newBounds.width - (connSize - 1) * defaultSize;
}
}
newBounds.height -= amntShrinkCurrentHeight;
child.setBounds(transposer.t(newBounds));
prefMinSumHeight -= (prefHeight - minHeight);
y += newBounds.height + spacing;
}
}
use of org.eclipse.draw2d.Viewport in project tdi-studio-se by Talend.
the class MapperScalableRootEditPart method createFigure.
/*
* (non-Javadoc)
*
* @see org.eclipse.gef.editparts.ScalableRootEditPart#createFigure()
*/
@Override
protected IFigure createFigure() {
Viewport figure = (Viewport) super.createFigure();
figure.setContentsTracksWidth(true);
return figure;
}
use of org.eclipse.draw2d.Viewport in project dbeaver by serge-rider.
the class ERDOutlinePage method createControl.
/* (non-Javadoc)
* @see org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createControl(Composite parent) {
// create canvas and lws
overview = new Canvas(parent, SWT.NONE);
LightweightSystem lws = new LightweightSystem(overview);
// create thumbnail
thumbnail = new ScrollableThumbnail((Viewport) rootEditPart.getFigure());
thumbnail.setBorder(new MarginBorder(3));
thumbnail.setSource(rootEditPart.getLayer(LayerConstants.PRINTABLE_LAYERS));
lws.setContents(thumbnail);
}
use of org.eclipse.draw2d.Viewport in project xtext-eclipse by eclipse.
the class RailroadView method reveal.
public void reveal(IFigure figure) {
Viewport viewport = canvas.getViewport();
Rectangle viewportBounds = viewport.getBounds().getCopy();
viewportBounds.translate(viewport.getViewLocation());
Rectangle figureBounds = figure.getBounds().getCopy();
figure.translateToAbsolute(figureBounds);
figureBounds.translate(viewport.getViewLocation());
if (!viewportBounds.contains(figureBounds)) {
int newX = viewportBounds.x;
int newY = viewportBounds.y;
if (viewportBounds.x > figureBounds.x) {
newX = figureBounds.x;
} else if (viewportBounds.x + viewportBounds.getRight().x < figureBounds.getRight().x) {
newX = figureBounds.getRight().x - viewportBounds.width;
}
if (viewportBounds.y > figureBounds.y) {
newY = figureBounds.y;
} else if (viewportBounds.getBottom().y < figureBounds.getBottom().y) {
newY = figureBounds.getBottom().y - viewportBounds.height;
}
canvas.scrollSmoothTo(newX, newY);
}
}
use of org.eclipse.draw2d.Viewport in project archi by archimatetool.
the class ExtendedViewportAutoexposeHelper method step.
@Override
public boolean step(Point where) {
Viewport port = findViewport(owner);
Rectangle rect = Rectangle.SINGLETON;
port.getClientArea(rect);
port.translateToParent(rect);
port.translateToAbsolute(rect);
if (!(continueIfOutside || 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