use of org.eclipse.draw2d.Viewport in project whole by wholeplatform.
the class WholeViewportAutoexposeHelper 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 (!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);
RangeModel hm = port.getHorizontalRangeModel();
RangeModel vm = port.getVerticalRangeModel();
final Point loc = port.getViewLocation();
if ((region & PositionConstants.SOUTH) != 0)
loc.y = Math.min(loc.y + scrollOffset, vm.getMaximum() - vm.getExtent());
else if ((region & PositionConstants.NORTH) != 0)
loc.y = Math.max(loc.y - scrollOffset, 0);
if ((region & PositionConstants.EAST) != 0)
loc.x = Math.min(loc.x + scrollOffset, hm.getMaximum() - hm.getExtent());
else if ((region & PositionConstants.WEST) != 0)
loc.x = Math.max(loc.x - scrollOffset, 0);
if (loc.x != hm.getValue() || loc.y != vm.getValue())
Display.getCurrent().asyncExec(new Runnable() {
public void run() {
exposeLocation(loc);
}
});
return true;
}
use of org.eclipse.draw2d.Viewport in project webtools.sourceediting by eclipse.
the class CategoryEditPart method createFigure.
protected IFigure createFigure() {
outerPane = new Figure();
outerPane.setBorder(new RoundedLineBorder(1, 6));
createHeadingFigure();
int minHeight = SWT.DEFAULT;
switch(getType()) {
case CategoryAdapter.DIRECTIVES:
{
minHeight = 80;
break;
}
case CategoryAdapter.ATTRIBUTES:
case CategoryAdapter.GROUPS:
{
minHeight = 100;
break;
}
}
final int theMinHeight = minHeight;
ToolbarLayout outerLayout = new ToolbarLayout(false) {
protected Dimension calculatePreferredSize(IFigure parent, int width, int height) {
Dimension d = super.calculatePreferredSize(parent, width, height);
d.union(new Dimension(250, theMinHeight));
return d;
}
};
outerLayout.setStretchMinorAxis(true);
outerPane.setLayoutManager(outerLayout);
RectangleFigure line = new RectangleFigure() {
public Dimension getPreferredSize(int wHint, int hHint) {
Dimension d = super.getPreferredSize(wHint, hHint);
d.width += 20;
d.height = 1;
return d;
}
};
ToolbarLayout lineLayout = new ToolbarLayout(false);
lineLayout.setVertical(true);
lineLayout.setStretchMinorAxis(true);
line.setLayoutManager(lineLayout);
outerPane.add(line);
scrollpane = new ScrollPane();
// ScrollPane.ALWAYS);
scrollpane.setVerticalScrollBarVisibility(ScrollPane.AUTOMATIC);
outerPane.add(scrollpane);
Figure pane = new Figure();
pane.setBorder(new MarginBorder(5, 8, 5, 8));
ContainerLayout layout = new ContainerLayout();
layout.setHorizontal(false);
layout.setSpacing(0);
pane.setLayoutManager(layout);
Viewport viewport = new Viewport();
viewport.setContentsTracksHeight(true);
ViewportLayout viewportLayout = new ViewportLayout() {
protected Dimension calculatePreferredSize(IFigure parent, int width, int height) {
Dimension d = super.calculatePreferredSize(parent, width, height);
if (theMinHeight > 0)
d.height = Math.min(d.height, theMinHeight);
else {
double factor = getZoomManager().getZoom();
// adjust for other categories and spaces
int scaledHeight = (int) Math.round((getViewer().getControl().getBounds().height - minimumHeight) / factor);
d.height = Math.max(250, scaledHeight);
}
d.width = Math.min(d.width, 300);
return d;
}
};
viewport.setLayoutManager(viewportLayout);
scrollpane.setViewport(viewport);
scrollpane.setContents(pane);
return outerPane;
}
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 yamcs-studio by yamcs.
the class OverviewOutlinePage method createControl.
@Override
public void createControl(Composite parent) {
overview = new Canvas(parent, SWT.NONE);
var lws = new LightweightSystem(overview);
thumbnail = new ScrollableThumbnail((Viewport) rootEP.getFigure());
thumbnail.setBorder(new MarginBorder(3));
thumbnail.setSource(rootEP.getLayer(LayerConstants.PRINTABLE_LAYERS));
lws.setContents(thumbnail);
disposeListener = e -> {
if (thumbnail != null) {
thumbnail.deactivate();
thumbnail = null;
}
};
rootEP.getViewer().getControl().addDisposeListener(disposeListener);
}
use of org.eclipse.draw2d.Viewport in project yamcs-studio by yamcs.
the class AbstractSWTWidgetFigure method relocateWidget.
/**
* relocate the widget so it follows the figure position.
*/
protected void relocateWidget() {
if (wrapComposite != null && getParent().getParent() instanceof Viewport) {
var viewPortArea = getParent().getParent().getClientArea();
var clientArea = getClientArea();
getParent().translateToAbsolute(viewPortArea);
translateToAbsolute(clientArea);
isIntersectViewPort = viewPortArea.intersects(clientArea);
// isIntersectViewPort = getParent().getParent().getClientArea()
// .intersects(getClientArea());
}
GUIRefreshThread.getInstance(runmode).addIgnorableTask(new WidgetIgnorableUITask(this, () -> {
if (!getSWTWidget().isDisposed() && getParent() != null) {
doRelocateWidget();
}
}, composite.getDisplay()));
}
Aggregations