/** Erases the guide and the feedback shown by the container of the elements. */ protected void eraseSourceFeedback() { if (guideline.getParent() != null) { guideline.getParent().remove(guideline); } if (_container != null) { _container.eraseSourceFeedback(getSourceRequest()); } ChangeBoundsRequest request = new ChangeBoundsRequest(RequestConstants.REQ_MOVE); request.setEditParts(Collections.emptyList()); request.setSizeDelta(new Dimension(0, 0)); request.setMoveDelta(new Point(0, 0)); for (IGraphicalEditPart part : _movingShapes) { part.eraseSourceFeedback(request); } ChangeBoundsRequest spRequest = new ChangeBoundsRequest(RequestConstants.REQ_RESIZE); spRequest.setEditParts(Collections.emptyList()); spRequest.setSizeDelta(new Dimension(0, 0)); spRequest.setMoveDelta(new Point(0, 0)); for (IGraphicalEditPart sp : _subProcesses) { sp.eraseSourceFeedback(spRequest); } }
// We override reveal to show the Handles of the selected EditPart when // scrolling public void reveal(EditPart part) { // In some case, the editor control is not created, but get the sync selection event. // Fix this problem temporary. if (getFigureCanvas() == null || getFigureCanvas().isDisposed()) { return; } Viewport port = getFigureCanvas().getViewport(); IFigure target = ((GraphicalEditPart) part).getFigure(); Rectangle exposeRegion = target.getBounds().getCopy(); // Get the primary editpolicy EditPolicy policy = part.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); // If the policy let us access the handles, proceed, otherwise // default to original behaviour if (!(policy instanceof ISelectionHandlesEditPolicy)) { super.reveal(part); return; } // First translate exposeRegion to the root level target = target.getParent(); while (target != null && target != port) { target.translateToParent(exposeRegion); target = target.getParent(); } // Merge selection handles if any to the exposeRegion List handles = ((ISelectionHandlesEditPolicy) policy).getHandles(); for (Iterator iter = handles.iterator(); iter.hasNext(); ) { AbstractHandle handle = (AbstractHandle) iter.next(); Locator locator = handle.getLocator(); locator.relocate(handle); exposeRegion.union(handle.getBounds().getCopy()); } exposeRegion.getExpanded(5, 5); Dimension viewportSize = port.getClientArea().getSize(); Point topLeft = exposeRegion.getTopLeft(); Point bottomRight = exposeRegion.getBottomRight().translate(viewportSize.getNegated()); Point finalLocation = new Point(); if (viewportSize.width < exposeRegion.width) finalLocation.x = Math.min(bottomRight.x, Math.max(topLeft.x, port.getViewLocation().x)); else finalLocation.x = Math.min(topLeft.x, Math.max(bottomRight.x, port.getViewLocation().x)); if (viewportSize.height < exposeRegion.height) finalLocation.y = Math.min(bottomRight.y, Math.max(topLeft.y, port.getViewLocation().y)); else finalLocation.y = Math.min(topLeft.y, Math.max(bottomRight.y, port.getViewLocation().y)); getFigureCanvas().scrollSmoothTo(finalLocation.x, finalLocation.y); }
private double getFitXZoomLevel(int which) { IFigure fig = getScalableFigure(); Dimension available = getViewport().getClientArea().getSize(); Dimension desired; if (fig instanceof FreeformFigure) { desired = ((FreeformFigure) fig).getFreeformExtent().getCopy().union(0, 0).getSize(); } else { desired = fig.getPreferredSize().getCopy(); } desired.width -= fig.getInsets().getWidth(); desired.height -= fig.getInsets().getHeight(); while (fig != getViewport()) { available.width -= fig.getInsets().getWidth(); available.height -= fig.getInsets().getHeight(); fig = fig.getParent(); } double scaleX = Math.min(available.width * zoom / desired.width, getMaxZoom()); double scaleY = Math.min(available.height * zoom / desired.height, getMaxZoom()); if (which == 0) { return scaleX; } if (which == 1) { return scaleY; } return Math.min(scaleX, scaleY); }
public void figureMoved(IFigure figure) { Rectangle bounds = figure.getBounds(); if (relativeToParent) { bounds = Rectangle.SINGLETON.setBounds(bounds); // copy Rectangle parentBounds = figure.getParent().getBounds(); bounds.translate(-parentBounds.x, -parentBounds.y); } Point loc = element.getLocation(); if (loc == null || loc.x != bounds.x || loc.y != bounds.y) { Point newLocation = new Point(bounds.x, bounds.y); if (element instanceof FormElementGroup) { FormElementGroupPropertySource formElementGroupPropertySource = new FormElementGroupPropertySource((FormElementGroup) element, form); formElementGroupPropertySource.setLocation(newLocation); } else { element.setLocation(newLocation); } } Dimension dim = element.getSize(); if (dim == null || dim.width != bounds.width || dim.height != bounds.height) { Dimension newSize = new Dimension(bounds.width, bounds.height); if (element instanceof FormElementGroup) { FormElementGroupPropertySource formElementGroupPropertySource = new FormElementGroupPropertySource((FormElementGroup) element, null); formElementGroupPropertySource.setSize(newSize); } else { element.setSize(newSize); } } }
private Viewport getViewPort() { Viewport result = null; IFigure parent = label.getParent(); while (parent != null && !(parent instanceof Viewport)) { parent = parent.getParent(); } if (parent != null) { result = (Viewport) parent; } return result; }
private void addLabelForFigure(IFigure figure, GraphLabel label) { IFigure parent = figure.getParent(); if (parent instanceof ZestRootLayer) { ((ZestRootLayer) parent).addDecoration(figure, label); } else { if (parent.getChildren().contains(label)) { parent.remove(label); } int index = parent.getChildren().indexOf(figure); parent.add(label, index + 1); } }
/** Shows a nice guideline to show the move */ protected void showSourceFeedback() { if (_container == null) { return; } if (guideline.getParent() == null) { addFeedback(guideline); } Rectangle bounds = Rectangle.SINGLETON.getCopy(); bounds.y = getCurrentPositionZoomed(); Rectangle containerBounds = _container.getFigure().getBounds().getCopy(); _container.getFigure().translateToAbsolute(containerBounds); ((DiagramEditPart) getCurrentViewer().getContents()) .getFigure() .translateToRelative(containerBounds); bounds.x = containerBounds.x; bounds.height = 1; bounds.width = containerBounds.width; ZoomManager zoomManager = ((DiagramRootEditPart) getCurrentViewer().getRootEditPart()).getZoomManager(); bounds.performScale(zoomManager.getZoom()); guideline.setBounds(bounds); guideline.setVisible(getState() == STATE_DRAG_IN_PROGRESS); ChangeBoundsRequest request = new ChangeBoundsRequest(RequestConstants.REQ_MOVE); request.setMoveDelta(((ChangeBoundsRequest) getSourceRequest()).getMoveDelta()); request.setSizeDelta(new Dimension(0, 0)); request.setEditParts(_movingShapes); for (IGraphicalEditPart part : _movingShapes) { part.showSourceFeedback(request); } ChangeBoundsRequest spRequest = new ChangeBoundsRequest(RequestConstants.REQ_RESIZE); Point moveDelta = ((ChangeBoundsRequest) getSourceRequest()).getMoveDelta().getCopy(); Dimension spSizeDelta = new Dimension(moveDelta.x, moveDelta.y); spRequest.setSizeDelta(spSizeDelta); spRequest.setMoveDelta(new Point(0, 0)); spRequest.setEditParts(_subProcesses); for (IGraphicalEditPart sp : _subProcesses) { sp.showSourceFeedback(spRequest); } ((DiagramEditPart) getCurrentViewer().getContents()).getRoot().refresh(); }
/* * public void addChild() { * List<EditPart> listchildren = this.getChildren(); * if(!listchildren.isEmpty()) { * int size = listchildren.size(); * EditPart childEditPart = listchildren.get(0); * this.addChild(childEditPart, size); * listchildren = this.getChildren(); * size = listchildren.size(); * System.out.printf("Size of ListChildren %d\n", size); * * } * } */ @Override protected boolean removeFixedChild(EditPart childEditPart) { if (childEditPart instanceof MessageNameEditPart) { if (childEditPart instanceof MessageNameEditPart) { IFigure childFigureBefore = ((GraphicalEditPart) childEditPart).getFigure(); getPrimaryShape().remove(((MessageNameEditPart) childEditPart).getFigure()); IFigure childFigure = ((GraphicalEditPart) childEditPart).getFigure(); if (childFigure.getParent() == null) { childFigure.setParent(this.getPrimaryShape()); } if (childFigure.getBounds() == new Rectangle(0, 0, 0, 0)) { // System.out.println("The bound have changed!!!! "); childFigure.setBounds(childFigureBefore.getBounds()); } } return true; } if (childEditPart instanceof AppliedStereotypeMessageEditPart) { return true; } return false; }
@Override public Image stereotypeIconToDisplay() { // retrieve the first stereotype in the list of displayed stereotype // String firstStereotypeName = tokenizer.nextToken(); EList<Stereotype> stereotype_list = getUMLElement().getAppliedStereotypes(); if (stereotype_list.size() != 0) { Stereotype stereotype = stereotype_list.get(0); if (stereotype.getName().equals("DataFlowPort") || stereotype.getName().equals("ServicePort")) { Image icon = Activator.getIconElement(getUMLElement(), stereotype, false); IFigure portView = getHostFigure(); IFigure parentView = portView.getParent().getParent(); Rectangle parentBounds = parentView.getBounds(); Rectangle portBounds = portView.getBounds(); if (portBounds.x() <= parentBounds.x()) { // left return icon; } else if (portBounds.x() >= (parentBounds.right() - portBounds.width())) { // right return new Image(icon.getDevice(), RotationHelper.rotateImage(icon, 180)); } else if (portBounds.y() <= parentBounds.y()) { // top return new Image(icon.getDevice(), RotationHelper.rotateImage(icon, 90)); } else if (portBounds.y() >= parentBounds.bottom() - portBounds.height()) { // bottom return new Image(icon.getDevice(), RotationHelper.rotateImage(icon, -90)); } else { return null; } } return Activator.getIconElement(getUMLElement(), stereotype, false); } return null; }
private void removeBranchView() { IFigure figure = branch.getFigure(); if (figure.getParent() != null) { figure.getParent().remove(figure); } }