Java Code Examples for org.eclipse.draw2d.geometry.Rectangle#translate()
The following examples show how to use
org.eclipse.draw2d.geometry.Rectangle#translate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RailroadView.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
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); } }
Example 2
Source File: LinkAnchor.java From olca-app with Mozilla Public License 2.0 | 6 votes |
@Override public Point getLocation(Point reference) { int hTrans = 0; if (!node.isMinimized()) { hTrans = ProcessFigure.MARGIN_WIDTH + 1; if (forInput) { hTrans *= -1; } } Rectangle r = getOwner().getBounds().getCopy(); r.translate(hTrans, 0); getOwner().translateToAbsolute(r); Point location = null; if (forInput) { location = r.getLeft(); } else { location = r.getRight(); } return location; }
Example 3
Source File: FiguresHelper.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
/** * Convenient method to translate bounds to Absolute coordinate * * @param owner * @param b */ public static void translateToAbsolute(final IFigure owner, final Rectangle b) { owner.translateToAbsolute(b); IFigure parentFigure = owner.getParent(); while (parentFigure != null) { if (parentFigure instanceof Viewport) { final Viewport viewport = (Viewport) parentFigure; b.translate( viewport.getHorizontalRangeModel().getValue(), viewport.getVerticalRangeModel().getValue()); parentFigure = parentFigure.getParent(); } else { parentFigure = parentFigure.getParent(); } } }
Example 4
Source File: ReportFlowLayoutEditPolicy.java From birt with Eclipse Public License 1.0 | 6 votes |
/** * Generates a draw2d constraint object derived from the specified child * EditPart using the provided Request. The returned constraint will be * translated to the application's model later using * {@link #translateToModelConstraint(Object)}. * * @param request * the ChangeBoundsRequest * @param child * the child EditPart for which the constraint should be * generated * @return the draw2d constraint */ protected Object getConstraintFor( ChangeBoundsRequest request, GraphicalEditPart child ) { IFigure figure = child.getFigure( ); Rectangle rect = new PrecisionRectangle(figure.getBounds()); figure.translateToAbsolute(rect); rect = request.getTransformedRectangle( rect ); figure.translateToRelative(rect); rect.translate( getLayoutOrigin( ).getNegated( ) ); if (figure instanceof IOutsideBorder) { Border border = ((IOutsideBorder)figure).getOutsideBorder( ); if (border != null) { Insets insets = border.getInsets( figure ); rect.shrink( insets.right, insets.bottom ); } } return getConstraintFor( rect ); }
Example 5
Source File: ListBandHandle.java From birt with Eclipse Public License 1.0 | 6 votes |
public void relocate( IFigure target ) { Rectangle bounds; if ( getReference( ) instanceof ListBandFigure ) { ListBandFigure parent = (ListBandFigure) getReference( ); Figure content = (Figure) parent.getContent( ); bounds = content.getBounds( ).getCopy( ); } else { bounds = getReference( ).getBounds( ).getCopy( ); } getReference( ).translateToAbsolute( bounds ); target.translateToRelative( bounds ); bounds.translate( 1, 1 ); bounds.resize( -1, -1 ); target.setBounds( bounds ); }
Example 6
Source File: PrintERDiagramOperation.java From erflute with Apache License 2.0 | 6 votes |
@Override public Rectangle getPrintRegion() { final ERDiagram diagram = getDiagram(); final PageSettings pageSetting = diagram.getPageSetting(); final org.eclipse.swt.graphics.Rectangle trim = getPrinter().computeTrim(0, 0, 0, 0); final org.eclipse.swt.graphics.Point printerDPI = getPrinter().getDPI(); final Insets notAvailable = new Insets(-trim.y, -trim.x, trim.height + trim.y, trim.width + trim.x); final Insets userPreferred = new Insets((pageSetting.getTopMargin() * printerDPI.x) / 72, (pageSetting.getLeftMargin() * printerDPI.x) / 72, (pageSetting.getBottomMargin() * printerDPI.x) / 72, (pageSetting.getRightMargin() * printerDPI.x) / 72); final Rectangle paperBounds = new Rectangle(getPrinter().getBounds()); final Rectangle printRegion = shrink(paperBounds, notAvailable); printRegion.intersect(shrink(paperBounds, userPreferred)); printRegion.translate(trim.x, trim.y); return printRegion; }
Example 7
Source File: PrintERDiagramOperation.java From ermasterr with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public Rectangle getPrintRegion() { final ERDiagram diagram = getDiagram(); final PageSetting pageSetting = diagram.getPageSetting(); final org.eclipse.swt.graphics.Rectangle trim = getPrinter().computeTrim(0, 0, 0, 0); final org.eclipse.swt.graphics.Point printerDPI = getPrinter().getDPI(); final Insets notAvailable = new Insets(-trim.y, -trim.x, trim.height + trim.y, trim.width + trim.x); final Insets userPreferred = new Insets((pageSetting.getTopMargin() * printerDPI.x) / 72, (pageSetting.getLeftMargin() * printerDPI.x) / 72, (pageSetting.getBottomMargin() * printerDPI.x) / 72, (pageSetting.getRightMargin() * printerDPI.x) / 72); final Rectangle paperBounds = new Rectangle(getPrinter().getBounds()); final Rectangle printRegion = shrink(paperBounds, notAvailable); printRegion.intersect(shrink(paperBounds, userPreferred)); printRegion.translate(trim.x, trim.y); return printRegion; }
Example 8
Source File: CursorLayer.java From nebula with Eclipse Public License 2.0 | 6 votes |
@Override public void layout(IFigure parent) { final TimeBaseConverter timeViewDetails = RootFigure.getTimeViewDetails(parent); for (final Object child : getChildren()) { final ICursor cursor = (ICursor) getConstraint((IFigure) child); final Dimension preferredSize = ((IFigure) child).getPreferredSize(); final Timing screenCoordinates = timeViewDetails.toDetailCoordinates(cursor.getTiming()); final Rectangle screenBounds = new PrecisionRectangle(screenCoordinates.getTimestamp(), 0, preferredSize.width(), getBounds().height()); screenBounds.translate(-preferredSize.width() / 2, 0); ((IFigure) child).setBounds(screenBounds); } }
Example 9
Source File: ProcessPart.java From olca-app with Mozilla Public License 2.0 | 5 votes |
@Override public Command getCommand(Request request) { if (!(request instanceof ChangeBoundsRequest)) return null; ChangeBoundsRequest req = (ChangeBoundsRequest) request; Dimension sizeDelta = req.getSizeDelta(); if (sizeDelta.height != 0 || sizeDelta.width != 0) return null; Command commandChain = null; for (Object o : req.getEditParts()) { if (!(o instanceof ProcessPart)) continue; ProcessPart part = (ProcessPart) o; XYLayoutCommand command = new XYLayoutCommand(); command.setProcessNode(part.getModel()); Rectangle bounds = (part.getModel()).figure.getBounds().getCopy(); part.getModel().figure.translateToAbsolute(bounds); Rectangle moveResize = new Rectangle(req.getMoveDelta(), sizeDelta); bounds.resize(moveResize.getSize()); bounds.translate(moveResize.getLocation()); part.getModel().figure.translateToRelative(bounds); command.setConstraint(bounds); if (commandChain == null) { commandChain = command; } else { commandChain = commandChain.chain(command); } } return commandChain; }
Example 10
Source File: ListBandLayout.java From birt with Eclipse Public License 1.0 | 5 votes |
protected void setBoundsOfChild( IFigure parent, IFigure child, Rectangle bounds ) { parent.getClientArea( Rectangle.SINGLETON ); bounds.translate( Rectangle.SINGLETON.x, Rectangle.SINGLETON.y ); if ( !bounds.equals( child.getBounds( ) ) ) { child.setBounds( bounds ); } }
Example 11
Source File: TableLayout.java From birt with Eclipse Public License 1.0 | 5 votes |
protected void setBoundsOfChild( IFigure parent, IFigure child, Rectangle bounds ) { parent.getClientArea( Rectangle.SINGLETON ); bounds.translate( Rectangle.SINGLETON.x, Rectangle.SINGLETON.y ); // comment out to force invalidation. // if ( !bounds.equals( child.getBounds( ) ) ) { child.setBounds( bounds ); if ( child.getLayoutManager( ) != null ) child.getLayoutManager( ).invalidate( ); child.revalidate( ); } }
Example 12
Source File: AbstractSwitchLaneSelectionEditPolicy.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
/** * @param zoom * */ private void showSelectionForAddBottom(double zoom) { if (!isOnBottom()) { IFigure f = new ImageFigure(Pics.getImage(PicsConstants.arrowDown)); f.setSize(20, 20); sourceFigure = getHostFigure() ; Rectangle bounds = sourceFigure.getBounds().getCopy(); //get the absolute coordinate of bounds sourceFigure.translateToAbsolute(bounds); IFigure parentFigure = sourceFigure.getParent(); while( parentFigure != null ) { if(parentFigure instanceof Viewport) { Viewport viewport = (Viewport)parentFigure; bounds.translate( viewport.getHorizontalRangeModel().getValue(), viewport.getVerticalRangeModel().getValue()); parentFigure = parentFigure.getParent(); } else { parentFigure = parentFigure.getParent(); } } Point location =new Point(bounds.getBottomLeft().x+20,bounds.getBottomLeft().y) ; f.setLocation(location); f.addMouseListener(new MouseListenerForSpan(AbstractSwitchLaneSelectionEditPolicy.ADD_BOTTOM)); getLayer(LayerConstants.HANDLE_LAYER).add(f); figures.add(f); } }
Example 13
Source File: AbstractSwitchLaneSelectionEditPolicy.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
/** * @param zoom * */ private void showSelectionForAddTop(double zoom) { if (!isOnTop()) { IFigure f = new ImageFigure(Pics.getImage(PicsConstants.arrowUp)); f.setParent(getHostFigure()); f.setSize(20, 20); sourceFigure = getHostFigure() ; Rectangle bounds = sourceFigure.getBounds().getCopy(); //get the absolute coordinate of bounds sourceFigure.translateToAbsolute(bounds); IFigure parentFigure = sourceFigure.getParent(); while( parentFigure != null ) { if(parentFigure instanceof Viewport) { Viewport viewport = (Viewport)parentFigure; bounds.translate( viewport.getHorizontalRangeModel().getValue(), viewport.getVerticalRangeModel().getValue()); parentFigure = parentFigure.getParent(); } else { parentFigure = parentFigure.getParent(); } } Point location = new Point(bounds.getTopLeft().x+20,bounds.getTopLeft().y-20) ; f.setLocation(location); f.addMouseListener(new MouseListenerForSpan(AbstractSwitchLaneSelectionEditPolicy.ADD_TOP)); getLayer(LayerConstants.HANDLE_LAYER).add(f); figures.add(f); } }
Example 14
Source File: SwitchPoolSelectionEditPolicy.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
/** * */ private void showSelectionForAddBottom() { if (!isOnBottom()) { IFigure f = new ImageFigure(Pics.getImage(PicsConstants.arrowDown)); f.setSize(20, 20); sourceFigure = getHostFigure() ; Rectangle bounds = sourceFigure.getBounds().getCopy(); //get the absolute coordinate of bounds sourceFigure.translateToAbsolute(bounds); IFigure parentFigure = sourceFigure.getParent(); while( parentFigure != null ) { if(parentFigure instanceof Viewport) { Viewport viewport = (Viewport)parentFigure; bounds.translate( viewport.getHorizontalRangeModel().getValue(), viewport.getVerticalRangeModel().getValue()); parentFigure = parentFigure.getParent(); } else { parentFigure = parentFigure.getParent(); } } f.setLocation(new Point(bounds.getBottomLeft().x,bounds.getBottom().y)); f.addMouseListener(new MouseListenerForSpan(AbstractSwitchLaneSelectionEditPolicy.ADD_BOTTOM)); layer.add(f); figures.add(f); } }
Example 15
Source File: SwitchPoolSelectionEditPolicy.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
/** * */ private void showSelectionForAddTop() { if (!isOnTop()) { IFigure f = new ImageFigure(Pics.getImage(PicsConstants.arrowUp)); f.setParent(getHostFigure()); f.setSize(20, 20); sourceFigure = getHostFigure() ; Rectangle bounds = sourceFigure.getBounds().getCopy(); //get the absolute coordinate of bounds sourceFigure.translateToAbsolute(bounds); IFigure parentFigure = sourceFigure.getParent(); while( parentFigure != null ) { if(parentFigure instanceof Viewport) { Viewport viewport = (Viewport)parentFigure; bounds.translate( viewport.getHorizontalRangeModel().getValue(), viewport.getVerticalRangeModel().getValue()); parentFigure = parentFigure.getParent(); } else { parentFigure = parentFigure.getParent(); } } f.setLocation(new Point(bounds.getTopLeft().x,bounds.getTop().y-20)); f.addMouseListener(new MouseListenerForSpan(AbstractSwitchLaneSelectionEditPolicy.ADD_TOP)); layer.add(f); figures.add(f); } }
Example 16
Source File: CustomPasteCommand.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
/** * Compute the relative location of each copied editparts */ private Rectangle computeRelativeLocation(Point newOrigin,IGraphicalEditPart srcPart, List<IGraphicalEditPart> toCopy) { int relativeToPoolY=0; Rectangle newLoc = new Rectangle(newOrigin, new Dimension()) ; newLoc.setY(newLoc.y()+relativeToPoolY); int minX = Integer.MAX_VALUE ; IGraphicalEditPart mostLeftEditPart = null ; for(IGraphicalEditPart parts : toCopy){ if(!(parts instanceof AbstractConnectionEditPart)){ int x =((Location)((Node)parts.getNotationView()).getLayoutConstraint()).getX() ; if(x < minX){ minX = x ; mostLeftEditPart = parts ; } } } if(mostLeftEditPart.equals(srcPart)){ return newLoc; }else{ int referenceX = minX ; int referenceY =((Location)((Node)mostLeftEditPart.getNotationView()).getLayoutConstraint()).getY() ; int toCopyX = ((Location)((Node)srcPart.getNotationView()).getLayoutConstraint()).getX() ; int toCopyY = ((Location)((Node)srcPart.getNotationView()).getLayoutConstraint()).getY() ; newLoc = newLoc.translate(toCopyX-referenceX, toCopyY-referenceY); newLoc.setY(newLoc.y()+relativeToPoolY); return newLoc; } }
Example 17
Source File: ProcessPart.java From olca-app with Mozilla Public License 2.0 | 5 votes |
private Command getCommand(ProcessPart part, ChangeBoundsRequest request) { IFigure figure = part.getModel().figure; Rectangle bounds = figure.getBounds().getCopy(); figure.translateToAbsolute(bounds); Rectangle moveResize = new Rectangle(request.getMoveDelta(), request.getSizeDelta()); bounds.resize(moveResize.getSize()); bounds.translate(moveResize.getLocation()); figure.translateToRelative(bounds); if (request.getSizeDelta().height != 0 || request.getSizeDelta().width != 0) return XYLayoutCommand.resize(part.getModel(), bounds); if (request.getMoveDelta().x != 0 || request.getMoveDelta().y != 0) return XYLayoutCommand.move(part.getModel(), bounds); return null; }
Example 18
Source File: ProcessLinkAnchor.java From olca-app with Mozilla Public License 2.0 | 5 votes |
@Override public Point getLocation(Point reference) { int horizontalTranslation = 0; Rectangle r = getOwner().getBounds().getCopy(); r.translate(horizontalTranslation, recipient ? -1 : 0); getOwner().translateToAbsolute(r); Point result = null; if (recipient) result = r.getBottom(); else result = r.getTop(); return result; }
Example 19
Source File: FiguresHelper.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
private static Rectangle translate(final IGraphicalEditPart child, final Rectangle newBounds) { final Rectangle childBounds = child.getFigure().getBounds().getCopy(); final Bounds b = (Bounds) ((Node) child.getModel()).getLayoutConstraint(); childBounds.x = b.getX(); childBounds.y = b.getY(); if (childBounds.width <= 0) { childBounds.width = child.getFigure().getPreferredSize().width; } if (childBounds.height <= 0) { childBounds.height = child.getFigure().getPreferredSize().height; } final Rectangle oldBound = newBounds.getCopy(); childBounds.expand(new Insets(15, 15, 15, 15)); if (childBounds.intersects(newBounds)) { final Set<Integer> directionTry = new HashSet<Integer>(); final Set<Integer> allDirection = new HashSet<Integer>(); allDirection.add(PositionConstants.NORTH_WEST); allDirection.add(PositionConstants.NORTH_EAST); allDirection.add(PositionConstants.SOUTH_EAST); allDirection.add(PositionConstants.SOUTH_WEST); while (childBounds.intersects(newBounds)) { if (directionTry.containsAll(allDirection)) { return oldBound; } if (childBounds.x >= newBounds.x && childBounds.y >= newBounds.y) { newBounds.translate(-1, -1); directionTry.add(PositionConstants.NORTH_WEST); } else if (childBounds.x <= newBounds.x && childBounds.y >= newBounds.y) { newBounds.translate(1, -1); directionTry.add(PositionConstants.NORTH_EAST); } else if (childBounds.x <= newBounds.x && childBounds.y <= newBounds.y) { newBounds.translate(1, 1); directionTry.add(PositionConstants.SOUTH_EAST); } else if (childBounds.x >= newBounds.x && childBounds.y <= newBounds.y) { newBounds.translate(-1, 1); directionTry.add(PositionConstants.SOUTH_WEST); } } } return newBounds; }
Example 20
Source File: ReportFlowLayout.java From birt with Eclipse Public License 1.0 | 3 votes |
/** * Sets the given bounds for the child figure input. * * @param parent * the parent figure * @param child * the child figure * @param bounds * the size of the child to be set * @since 2.0 */ protected void setBoundsOfChild( IFigure parent, IFigure child, Rectangle bounds ) { parent.getClientArea( Rectangle.SINGLETON ); bounds.translate( Rectangle.SINGLETON.x, Rectangle.SINGLETON.y ); child.setBounds( bounds ); }