protected void showGradient(Graphics graphics, PrecisionRectangle tempRect, float internalRadius) { Color backgroundColor = getBackgroundColor(); //top gradient Image gradientImage = Drawer.getGradientRectangle( tempRect, backgroundColor.getRGB(), ColorUtils.darker(ColorUtils.darker(ColorUtils.darker( backgroundColor.getRGB()))), internalRadius, 50, SWT.TOP); graphics.drawImage(gradientImage, tempRect.x, tempRect.y); gradientImage.dispose(); //bottom gradient gradientImage = Drawer.getGradientRectangle( tempRect, ColorUtils.darker(ColorUtils.darker(ColorUtils.darker( backgroundColor.getRGB()))), backgroundColor.getRGB(), internalRadius, 50, SWT.BOTTOM); graphics.drawImage(gradientImage, tempRect.x, tempRect.bottom() - gradientImage.getBounds().height); gradientImage.dispose(); }
/** * @param graphics */ private void paingImage(Graphics graphics) { if (image != null){ PrecisionRectangle tempRect = new PrecisionRectangle(getBounds().crop(insets)); float r = getBorder().getActualBorderRadius(tempRect); // must use paths to process not integer values // the difference is visible with zoom graphics.setBackgroundColor(getBackgroundColor()); float borderWidth = Math.min(Math.min(tempRect.height, tempRect.width)/2, getBorder().getBorderWidth()); float internalRadius = Math.max(0, r - borderWidth); tempRect.shrink(borderWidth, borderWidth); Image roundedImage = getBorder().getRoundedImage(new Image(null, image.getImageData().scaledTo(tempRect.width, tempRect.height)), internalRadius); graphics.drawImage(roundedImage, tempRect.x, tempRect.y); roundedImage.dispose(); } }
@Override protected void paintFigure(Graphics graphics) { if (image == null){//draw border to make the component visible if (getBorder().getBorderWidth() <= 1){ getBorder().setBorderWidth(1f); } } super.paintFigure(graphics); if(image != null){ PrecisionRectangle tempRect = new PrecisionRectangle(getBounds().crop(insets)); float r = getBorder().getActualBorderRadius(tempRect); // must use paths to process not integer values // the difference is visible with zoom graphics.setBackgroundColor(getBackgroundColor()); float borderWidth = Math.min(Math.min(tempRect.height, tempRect.width)/2, getBorder().getBorderWidth()); float internalRadius = Math.max(0, r - borderWidth); tempRect.shrink(borderWidth, borderWidth); Image roundedImage = getBorder().getRoundedImage(new Image(null, image.getImageData().scaledTo(tempRect.width, tempRect.height)), internalRadius); graphics.drawImage(roundedImage, tempRect.x, tempRect.y); roundedImage.dispose(); } }
@Override protected void paintTitaniumFigure(Graphics graphics) { if (isON()){ graphics.setForegroundColor(ColorConstants.white); } super.paintTitaniumFigure(graphics); Rectangle rect = getBounds().getCopy(); //rect.shrink((int)getBorder().getBorderWidth(), (int)getBorder().getBorderWidth()); if (isON()){ rect.x = rect.right() - rect.height; } rect.width = rect.height; Image image = Drawer.getGradientRectangle(new PrecisionRectangle(rect.getCopy()), RECT_B_RGB, RECT_T_RGB, rect.height / 2, rect.height, rect.height); graphics.drawImage(image, rect.getLocation()); image.dispose(); }
/** * @see org.eclipse.gef.editpolicies.BendpointEditPolicy#showCreateBendpointFeedback(org.eclipse.gef.requests.BendpointRequest) */ @Override protected void showCreateBendpointFeedback(BendpointRequest request) { IFigure feedback = getDragSourceFeedbackFigure(); Rectangle bounds = new Rectangle(getInitialFeedbackBounds().getCopy()); PrecisionRectangle rect = new PrecisionRectangle(bounds); getHostFigure().translateToAbsolute(rect); Point movePoint = request.getLocation(); movePoint.x = ((GraphicalEditPart) getHost()).getFigure().getBounds().x;//movePoint.x - rect.getSize().width / 2; rect.setLocation(movePoint); feedback.translateToRelative(rect); feedback.setBounds(rect); }
@SuppressWarnings({ "unchecked" }) private Rectangle calculateFeedbackBounds(ChangeBoundsRequest request, Rectangle feedbackBounds, int level, IFigure containerFigure) { Rectangle result = feedbackBounds.getCopy(); List<IGraphicalEditPart> editParts = request.getEditParts(); for (IGraphicalEditPart editPart : editParts) { PrecisionRectangle transformedRect = new PrecisionRectangle(editPart.getFigure().getBounds()); editPart.getFigure().translateToAbsolute(transformedRect); transformedRect.translate(request.getMoveDelta()); transformedRect.resize(request.getSizeDelta()); transformedRect.expand(SPACEING * level, SPACEING * level); result.union(transformedRect); Dimension preferredSize = containerFigure.getPreferredSize().getCopy(); editPart.getFigure().translateToAbsolute(preferredSize); Dimension max = Dimension.max(result.getSize(), preferredSize); result.setSize(max); if (result.x < feedbackBounds.x || result.y < feedbackBounds.y) { return feedbackBounds; } } return result; }
@Override protected void showChangeBoundsFeedback(final ChangeBoundsRequest request) { final IFigure feedback = getDragSourceFeedbackFigure(); final PrecisionRectangle rect = new PrecisionRectangle( getInitialFeedbackBounds().getCopy()); getHostFigure().translateToAbsolute(rect); rect.translate(request.getMoveDelta()); rect.resize(request.getSizeDelta()); // the unchanged value can be set to zero, because // the size will be recalculated later checkAndPrepareConstraint(request, rect); feedback.translateToRelative(rect); feedback.setBounds(rect); }
@Override protected Command getResizeCommand(final ChangeBoundsRequest request) { GraphicalEditPart editPart = (IGraphicalEditPart) getHost(); Rectangle locationAndSize = new PrecisionRectangle(editPart.getFigure() .getBounds()); editPart.getFigure().translateToAbsolute(locationAndSize); final Rectangle origRequestedBounds = request .getTransformedRectangle(locationAndSize); final Rectangle modified = origRequestedBounds.getCopy(); checkAndPrepareConstraint(request, modified); // final Dimension sizeDelta = request.getSizeDelta(); Dimension newDelta = new Dimension(modified.width - locationAndSize.width, modified.height - locationAndSize.height); // ((IGraphicalEditPart) getHost()).getFigure() // .translateToAbsolute(newDelta); request.setSizeDelta(newDelta); final Point moveDelta = request.getMoveDelta(); request.setMoveDelta(new Point(moveDelta.x - origRequestedBounds.x + modified.x, moveDelta.y - origRequestedBounds.y + modified.y)); return super.getResizeCommand(request); }
@Override public void paintFigure(Graphics g) { PrecisionRectangle b = new PrecisionRectangle(getBounds().getCopy()); if (request.getType().equals(REQ_RESIZE)) { super.paintFigure(g); Graphics2D gr = ComponentFigure.getG2D(g); if (gr != null) { gr.fillRect(b.x, b.y, b.width, b.height); AlphaComposite ac = AlphaComposite.getInstance( AlphaComposite.SRC_OVER, 1f); gr.setComposite(ac); gr.fillOval(b.x + (b.width) / 2 - 3, b.y - 3, 7, 7); gr.fillOval(b.x + (b.width) / 2 - 3, b.y + b.height - 4, 7, 7); gr.drawLine(b.x + (b.width) / 2, b.y, b.x + (b.width) / 2, b.y + b.height - 2); } } }
/** * This method can be overridden by clients to customize the snapping behavior. * * @param request * the <code>ChangeBoundsRequest</code> from which the move delta can be extracted and updated * @since 3.4 */ protected void snapPoint(ChangeBoundsRequest request) { Point moveDelta = request.getMoveDelta(); if (editpart != null && getOperationSet().size() > 0) snapToHelper = (SnapToHelper) editpart.getParent().getAdapter(SnapToHelper.class); if (snapToHelper != null && !getCurrentInput().isModKeyDown(MODIFIER_NO_SNAPPING)) { PrecisionRectangle baseRect = sourceRectangle.getPreciseCopy(); PrecisionRectangle jointRect = compoundSrcRect.getPreciseCopy(); baseRect.translate(moveDelta); jointRect.translate(moveDelta); PrecisionPoint preciseDelta = new PrecisionPoint(moveDelta); snapToHelper.snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRect, jointRect }, preciseDelta); request.setMoveDelta(preciseDelta); } }
@Override public void relocate(IFigure target) { IFigure reference = getReferenceFigure(); Rectangle targetBounds = new PrecisionRectangle(getReferenceBox().getResized(-1, -1)); reference.translateToAbsolute(targetBounds); target.translateToRelative(targetBounds); targetBounds.resize(1, 1); Dimension targetSize = target.getPreferredSize(); targetBounds.x += 7; targetBounds.y += (int) (targetBounds.height * relativeY - ((targetSize.height + 1) / 2)); targetBounds.setSize(targetBounds.width - 14, 7); target.setBounds(targetBounds); }
protected void showChangeBoundsFeedback(ChangeBoundsRequest request) { if (getHost().getModel() instanceof IGraphicElement) { // if (getHost() instanceof BandEditPart // && ((BandEditPart) getHost()).getModelNode().getValue() instanceof JRDesignBand) { APropertyNode n = (APropertyNode) getHost().getModel(); int bandHeight = (Integer) n.getPropertyValue(JRDesignElement.PROPERTY_HEIGHT); Integer bWidth = (Integer) n.getPropertyValue(JRDesignElement.PROPERTY_WIDTH); Rectangle oldBounds = new Rectangle(0, 0, bWidth != null ? bWidth : 0, bandHeight); PrecisionRectangle rect2 = new PrecisionRectangle(new Rectangle(0, 0, request.getSizeDelta().width, request.getSizeDelta().height)); getHostFigure().translateToRelative(rect2); oldBounds.resize(rect2.width, rect2.height); setFeedbackText(oldBounds.height + (bWidth != null ? "," + oldBounds.width : "") + " px"); } super.showChangeBoundsFeedback(request); }
/** * This method can be overridden by clients to customize the snapping * behavior. * * @param request * the <code>ChangeBoundsRequest</code> from which the move delta * can be extracted and updated * @since 3.4 */ protected void snapPoint(ChangeBoundsRequest request) { Point moveDelta = request.getMoveDelta(); if (snapToHelper != null && request.isSnapToEnabled()) { PrecisionRectangle baseRect = sourceRectangle.getPreciseCopy(); PrecisionRectangle jointRect = compoundSrcRect.getPreciseCopy(); baseRect.translate(moveDelta); jointRect.translate(moveDelta); PrecisionPoint preciseDelta = new PrecisionPoint(moveDelta); snapToHelper.snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRect, jointRect }, preciseDelta); request.setMoveDelta(preciseDelta); } }
/** * Ensures size constraints (by default minimum and maximum) are respected * by the given request. May be overwritten by clients to enforce additional * constraints. * * @since 3.7 */ protected void enforceConstraintsForSizeOnDropCreate(CreateRequest request) { CreateRequest createRequest = (CreateRequest) getTargetRequest(); if (createRequest.getSize() != null) { // ensure create request respects minimum and maximum size // constraints PrecisionRectangle constraint = new PrecisionRectangle( createRequest.getLocation(), createRequest.getSize()); ((GraphicalEditPart) getTargetEditPart()).getContentPane() .translateToRelative(constraint); constraint.setSize(Dimension.max(constraint.getSize(), getMinimumSizeFor(createRequest))); constraint.setSize(Dimension.min(constraint.getSize(), getMaximumSizeFor(createRequest))); ((GraphicalEditPart) getTargetEditPart()).getContentPane() .translateToAbsolute(constraint); createRequest.setSize(constraint.getSize()); } }
/** * @see ChangeBoundsRequest#getTransformedRectangle(Rectangle) */ public Rectangle getTransformedRectangle(Rectangle rect) { Rectangle result = rect.getCopy(); Rectangle reference = getAlignmentRectangle(); if (result instanceof PrecisionRectangle) { if (reference instanceof PrecisionRectangle) doPrecisionAlignment((PrecisionRectangle) result, (PrecisionRectangle) reference); else doPrecisionAlignment((PrecisionRectangle) result, new PrecisionRectangle(reference)); } else doNormalAlignment(result, reference); return result; }
/** * Relocates the target using the relative offset locations. * * @see org.eclipse.draw2d.Locator#relocate(org.eclipse.draw2d.IFigure) */ public void relocate(IFigure target) { IFigure reference = getReferenceFigure(); // SzI: Rectangle targetBounds = new PrecisionRectangle(getReferenceBox()); // Rectangle targetBounds = new PrecisionRectangle(getReferenceBox() // .getResized(-1, -1)); reference.translateToAbsolute(targetBounds); target.translateToRelative(targetBounds); targetBounds.resize(1, 1); Dimension targetSize = target.getPreferredSize(); targetBounds.x += (int) (targetBounds.width * relativeX - ((targetSize.width + 1) / 2)); targetBounds.y += (int) (targetBounds.height * relativeY - ((targetSize.height + 1) / 2)); targetBounds.setSize(targetSize); target.setBounds(targetBounds); }
public void relocate( IFigure target ) { IFigure reference = getReferenceFigure( ); Rectangle targetBounds = new PrecisionRectangle( getReferenceBox( ).getResized( -1, -1 ) ); reference.translateToAbsolute( targetBounds ); target.translateToRelative( targetBounds ); targetBounds.resize( 1, 1 ); Dimension targetSize = getTargetSize( targetBounds.getSize( ) ); targetBounds.x += (int) ( targetBounds.width * relativeX ) - 1; targetBounds.y += (int) ( targetBounds.height * relativeY ); if (targetBounds.x < 0) { targetBounds.x = 0; } if (targetBounds.y < 0) { targetBounds.y = 0; } targetBounds.setSize( targetSize ); target.setBounds( targetBounds ); }
/** * 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 ); }
public EllipseController ( final SymbolController controller, final org.eclipse.scada.vi.model.Ellipse element, final ResourceManager manager ) { super ( controller, manager ); final PrecisionRectangle rect = new PrecisionRectangle (); if ( element.getSize () != null ) { rect.setPreciseSize ( element.getSize ().getWidth (), element.getSize ().getHeight () ); } this.figure = new Ellipse () { @Override public void addNotify () { super.addNotify (); start (); } @Override public void removeNotify () { stop (); super.removeNotify (); } }; this.figure.setBounds ( rect ); controller.addElement ( element, this ); applyCommon ( element ); }
public RectangleController ( final SymbolController controller, final Rectangle element, final ResourceManager manager ) { super ( controller, manager ); final PrecisionRectangle rect = new PrecisionRectangle (); if ( element.getSize () != null ) { rect.setPreciseSize ( element.getSize ().getWidth (), element.getSize ().getHeight () ); } this.figure = new RectangleFigureExtension ( this ); this.figure.setBounds ( rect ); controller.addElement ( element, this ); applyCommon ( element ); }
public FigureContainerController ( final SymbolController controller, final FigureContainer element, final ResourceManager manager, final BasicViewElementFactory viewElementFactory ) throws Exception { super ( controller, manager ); this.figure = new Figure () { @Override public void addNotify () { super.addNotify (); start (); } @Override public void removeNotify () { stop (); super.removeNotify (); } }; if ( element.getSize () != null ) { final PrecisionRectangle rect = new PrecisionRectangle (); rect.setPreciseSize ( element.getSize ().getWidth (), element.getSize ().getHeight () ); this.figure.setBounds ( rect ); } controller.addElement ( element, this ); this.figure.setLayoutManager ( new StackLayout () ); this.figure.add ( viewElementFactory.create ( controller, element.getContent () ).getFigure () ); applyCommon ( element ); }
/** * Returns the alignment rectangle to which all selected parts should be * aligned. * * @param request * the alignment Request * @return the alignment rectangle */ protected Rectangle calculateAlignmentRectangle(final Request request) { final List editparts = getOperationSet(request); if (editparts == null || editparts.isEmpty()) return null; final GraphicalEditPart part = (GraphicalEditPart) editparts.get(editparts.size() - 1); final Rectangle rect = new PrecisionRectangle(part.getFigure().getBounds()); part.getFigure().translateToAbsolute(rect); return rect; }
/** * Returns the alignment rectangle to which all selected parts should be * aligned. * * @param request * the alignment Request * @return the alignment rectangle */ protected Rectangle calculateAlignmentRectangle(Request request) { List editparts = getOperationSet(request); if (editparts == null || editparts.isEmpty()) return null; GraphicalEditPart part = (GraphicalEditPart) editparts.get(editparts .size() - 1); Rectangle rect = new PrecisionRectangle(part.getFigure().getBounds()); part.getFigure().translateToAbsolute(rect); return rect; }
public GhostImageFigure(IFigure source, int alpha) { this.alpha = alpha; RGB transparency = new RGB(1, 1, 1); Rectangle sourceFigureRelativePrecisionBounds = new PrecisionRectangle( source.getBounds().getCopy()); Image offscreenImage = new Image(Display.getCurrent(), sourceFigureRelativePrecisionBounds.width, sourceFigureRelativePrecisionBounds.height); Color transparentColor = new Color(null, transparency); GC gc = new GC(offscreenImage); SWTGraphics swtGraphics = new SWTGraphics(gc); swtGraphics.setBackgroundColor(transparentColor); swtGraphics.translate(-sourceFigureRelativePrecisionBounds.x, -sourceFigureRelativePrecisionBounds.y); swtGraphics.fillRectangle(sourceFigureRelativePrecisionBounds); source.paint(swtGraphics); ghostImageData = offscreenImage.getImageData(); ghostImageData.transparentPixel = ghostImageData.palette .getPixel(transparency); transparentColor.dispose(); offscreenImage.dispose(); swtGraphics.dispose(); gc.dispose(); }
protected void showGradient(Graphics graphics, PrecisionRectangle tempRect, float internalRadius) { Image gradientImage = Drawer.getGradientRectangle(tempRect, getBackgroundColor().getRGB(), ColorUtils.lighter(ColorUtils.lighter( getBackgroundColor().getRGB())), internalRadius, SWT.TOP,Drawer.MAXIMUM_GRADIENT_HEIGHT,drawLeftSide,drawRightSide); graphics.drawImage(gradientImage, tempRect.x, tempRect.y); gradientImage.dispose(); }
public static Path getTopRoundedRectangle(PrecisionRectangle tempRect, float radius,boolean drawLeftSide,boolean drawRightSide){ if (radius <= 0) return getRoundedRectangle(tempRect, radius,drawLeftSide,drawRightSide); float width = radius * 2; float dy = radius - tempRect.height; float dx = radius - (float) Math.sqrt(radius*radius - dy*dy); float alpha = dy > 0 ? (float)(Math.acos(dy/radius)*180/Math.PI) : 90; Path p = new Path(null); float x = (float) tempRect.preciseX; float y = (float) tempRect.preciseY; float right = (float) tempRect.preciseRight(); float bottom = (float) tempRect.preciseBottom(); if (dy < 0){ p.moveTo(x, y + radius); } else { p.moveTo(x + dx, y - dy); } p.addArc(x, y, width, width, 90 + alpha, -alpha); p.addArc(right-width, y, width, width, 90, -alpha); if (dy < 0){ p.lineTo(right, bottom);//rightBottom p.lineTo(x, bottom);//leftBottom } return p; }
public static Path getBottomRoundedRectangle(PrecisionRectangle tempRect, float radius,boolean drawLeftSide,boolean drawRightSide){ if (radius <= 0) return getRoundedRectangle(tempRect, radius,drawLeftSide,drawRightSide); float width = radius * 2; float dy = radius - tempRect.height; float dx = radius - (float) Math.sqrt(radius*radius - dy*dy); float alpha = dy > 0 ? (float)(Math.acos(dy/radius)*180/Math.PI) : 90; Path p = new Path(null); float x = (float) tempRect.preciseX; float y = (float) tempRect.preciseY; float right = (float) tempRect.preciseRight(); float bottom = (float) tempRect.preciseBottom(); if (dy < 0){ p.moveTo(x, bottom - radius); } else { p.moveTo(x + dx, y); } p.addArc(x, bottom - 2*radius, width, width, 270 - alpha, alpha); p.addArc(right-width, bottom - 2*radius, width, width, 270, alpha); if (dy < 0){ p.lineTo(right, y);//rightTop p.lineTo(x, y);//leftTop } return p; }
@Override protected void paintFigure(Graphics graphics) { super.paintFigure(graphics); Rectangle bounds = getBounds(); graphics.setBackgroundColor(headerColor); float bw = getBorder().getBorderWidth(); if (hasHeader()){ PrecisionRectangle top = new PrecisionRectangle(); top.setX(bounds.x + bw); top.setY(bounds.y + bw); top.setWidth(bounds.width - 2*bw); top.setHeight(getTitleHeight()); //Path topPath = Drawer.getPartlyRoundedRectangle(top, getBorder().getBorderRadius() - bw, true, true, false, false); Path topPath = Drawer.getTopRoundedRectangle(top, getBorder().getActualBorderRadius(getBounds()) - bw); graphics.fillPath(topPath); } if (footerTitle != null || hasFooterView){ PrecisionRectangle bottom = new PrecisionRectangle(); bottom.setX(bounds.x + bw); bottom.setY(bounds.bottom() - bw - getTitleHeight()); bottom.setWidth(bounds.width - 2*bw); bottom.setHeight(getTitleHeight()); //Path bottomPath = Drawer.getPartlyRoundedRectangle(bottom, getBorder().getBorderRadius() - bw, false, false, true, true); Path bottomPath = Drawer.getBottomRoundedRectangle(bottom, getBorder().getActualBorderRadius(getBounds()) - bw); graphics.fillPath(bottomPath); } graphics.restoreState(); this.paintString(graphics, headerTitle, true); this.paintString(graphics, footerTitle, false); }
protected void showChangeBoundsFeedback(ChangeBoundsRequest request) { IFigure feedback = getDragSourceFeedbackFigure(); PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy()); getHostFigure().translateToAbsolute(rect); rect.translate(request.getMoveDelta()); rect.resize(request.getSizeDelta()); feedback.translateToRelative(rect); Rectangle oldConstraint = ((GraphicalEditPart)getHost()).getFigure().getBounds(); feedback.setBounds(new Rectangle(oldConstraint.x, oldConstraint.y, oldConstraint.width, rect.height)); }
@Override public void relocate(IFigure target) { super.relocate(target); if (editPart instanceof IContainerPart) { Rectangle b = target.getBounds(); Dimension d = ((IContainerPart) editPart).getContaierSize(); ZoomManager zm = (ZoomManager) editPart.getViewer().getProperty(ZoomManager.class.toString()); double zoom = zm.getZoom(); b.y = (int) Math.floor(CellMoveHandle.Y_OFFSET * zoom) - CellMoveHandle.Y_OFFSET - 3; b.x = (int) Math.floor(CellMoveHandle.Y_OFFSET * zoom) - CellMoveHandle.Y_OFFSET - 3; b.height = d.height; b.width = d.width; Rectangle copy = new PrecisionRectangle(b.getCopy()); getReference().translateToAbsolute(copy); target.translateToRelative(copy); b.height = CellMoveHandle.Y_OFFSET * 2 + 6 + copy.height; b.width = CellMoveHandle.Y_OFFSET * 2 + 6 + copy.width; target.setBounds(b); } }
@Override public void relocate(IFigure target) { IFigure reference = getReferenceFigure(); Rectangle referenceBox = ((HandleBounds) reference).getHandleBounds(); Rectangle targetBounds = new PrecisionRectangle(referenceBox.getResized(-1, -1)); reference.translateToAbsolute(targetBounds); target.translateToRelative(targetBounds); targetBounds.resize(1, 1); int w = 2; int h = 2; switch (direction & PositionConstants.NORTH_SOUTH) { case PositionConstants.NORTH: w = targetBounds.width; targetBounds.y += (int) (targetBounds.height * relativeY - ((h / 2))) + 1; break; case PositionConstants.SOUTH: w = targetBounds.width; targetBounds.y += (int) (targetBounds.height * relativeY - (h / 2)) - 1; targetBounds.x += -1; break; } switch (direction & PositionConstants.EAST_WEST) { case PositionConstants.WEST: h = targetBounds.height; targetBounds.y += (int) relativeY - 1; targetBounds.x += (int) (targetBounds.width * relativeX - (w / 2)) - 1; break; case PositionConstants.EAST: h = targetBounds.height; targetBounds.y += (int) relativeY - 1; targetBounds.x += (int) (targetBounds.width * relativeX - (w / 2) - 1); break; } targetBounds.setSize(w, h); target.setBounds(targetBounds); }
@Override protected Object getConstraintFor(ChangeBoundsRequest request, GraphicalEditPart child) { // if (child instanceof IContainerPart) { // return ((IContainerPart) child).getConstraintFor(request, child); // } // If we are dragging a band, we need to check the bounds and suggest a // proper // new location accordingly with the max and min band size. IFigure figure = child.getFigure(); Rectangle bounds = figure.getBounds(); if (figure instanceof HandleBounds) { bounds = ((HandleBounds) figure).getHandleBounds(); // if (request.getResizeDirection() == PositionConstants.NORTH // || request.getResizeDirection() == PositionConstants.SOUTH) bounds.width--; // if (request.getResizeDirection() == PositionConstants.EAST // || request.getResizeDirection() == PositionConstants.WEST) bounds.height--; } Rectangle rect = new PrecisionRectangle(bounds); figure.translateToAbsolute(rect); rect = request.getTransformedRectangle(rect); figure.translateToRelative(rect); rect.translate(getLayoutOrigin().getNegated()); if (request.getSizeDelta().width == 0 && request.getSizeDelta().height == 0) { Rectangle cons = getCurrentConstraintFor(child); if (cons != null) // Bug 86473 allows for unintended use of this method rect.setSize(cons.width, cons.height); } else { // resize Dimension minSize = getMinimumSizeFor(child); if (rect.width < minSize.width) { rect.width = minSize.width; } if (rect.height < minSize.height) { rect.height = minSize.height; } } return getConstraintFor(rect); }
/** * Shows or updates feedback for a change bounds request. * * @param request * the request */ protected void showChangeBoundsFeedback(ChangeBoundsRequest request) { IFigure feedback = getDragSourceFeedbackFigure(); PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy()); getHostFigure().translateToAbsolute(rect); rect.translate(request.getMoveDelta()); rect.resize(request.getSizeDelta()); // Calculate changes for the figure... String s = ""; int scaleH = 0; int scaleW = 0; if (getHost() instanceof FigureEditPart && ((FigureEditPart) getHost()).getModelNode().getValue() instanceof JRDesignElement) { JRDesignElement jrElement = (JRDesignElement) ((FigureEditPart) getHost()).getModelNode().getValue(); Rectangle oldBounds = new Rectangle(jrElement.getX(), jrElement.getY(), jrElement.getWidth(), jrElement.getHeight()); PrecisionRectangle rect2 = new PrecisionRectangle(new Rectangle(request.getMoveDelta().x, request.getMoveDelta().y, request.getSizeDelta().width, request.getSizeDelta().height)); getHostFigure().translateToRelative(rect2); oldBounds.translate(rect2.x, rect2.y); oldBounds.resize(rect2.width, rect2.height); s += oldBounds.x + ", " + oldBounds.y + ", " + oldBounds.width + ", " + oldBounds.height; if (oldBounds.width != 0) scaleW = rect.width / oldBounds.width - 1; if (oldBounds.height != 0) scaleH = rect.height / oldBounds.height - 1; } feedback.translateToRelative(rect); ((ElementFeedbackFigure) feedback).setText(s); feedback.setBounds(rect.resize(-scaleW, -scaleH)); }
/** * Print the warning icon when an element is out of bound and set the tooltip text. */ @Override public void paint(Graphics graphics, ComponentFigure fig) { if (fig.getJrElement() instanceof JRDesignElement) { Rectangle r = fig.getBounds(); Graphics2D g = ComponentFigure.getG2D(graphics); if (g != null) { Stroke oldStroke = g.getStroke(); Color oldColor = g.getColor(); g.setColor(JSS_WARNING_BORDER_COLOR); g.setStroke(new BasicStroke(JSS_WARNING_BORDER_SIZE)); PrecisionRectangle tempRect = new PrecisionRectangle(); tempRect.setBounds(fig.getBounds()); if (JSS_WARNING_BORDER_SIZE % 2 == 1) { tempRect.width--; tempRect.height--; } tempRect.width = tempRect.width - (int) Math.ceil(JSS_WARNING_BORDER_SIZE); tempRect.height = tempRect.height - (int) Math.ceil(JSS_WARNING_BORDER_SIZE); tempRect.shrink(JSS_WARNING_BORDER_SIZE, JSS_WARNING_BORDER_SIZE); g.setStroke(new BasicStroke(JSS_WARNING_BORDER_SIZE)); g.drawRect(tempRect.x, tempRect.y, tempRect.width, tempRect.height); RoundedPolygon.paintComplexWarning(r.x + r.width - 5, r.y - 2, 6, 12, JSS_WARNING_BORDER_SIZE, g); fig.setToolTip(new org.eclipse.draw2d.Label(Messages.ErrorDecorator_PositionErrorToolTip, ResourceManager .getPluginImage(JaspersoftStudioPlugin.PLUGIN_ID, "icons/resources/warning2.png"))); //$NON-NLS-2$ g.setStroke(oldStroke); g.setColor(oldColor); } } }
/** * Returns the alignment rectangle to which all selected parts should be aligned. * @param request the alignment Request * @return the alignment rectangle */ protected Rectangle calculateAlignmentRectangle(Request request) { final List<?> editparts = getOperationSet(request); if (editparts == null || editparts.isEmpty()) return null; final GraphicalEditPart part = (GraphicalEditPart) editparts.get(editparts.size() - 1); final Rectangle rect = new PrecisionRectangle(part.getFigure().getBounds()); part.getFigure().translateToAbsolute(rect); return rect; }
@Override protected void showChangeBoundsFeedback(ChangeBoundsRequest request) { IFigure feedback = getDragSourceFeedbackFigure(); PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy()); getHostFigure().translateToAbsolute(rect); rect.translate(request.getMoveDelta()); rect.resize(request.getSizeDelta()); rect.height = 4; rect.x = 0; Point location = request.getLocation(); EditPart ep = getHost().getViewer().findObjectAt(location); if (ep == getHost()) { ep = getHost().getViewer().findObjectAt(location.translate(0, 3)); } if (ep instanceof GraphicalEditPart) { Position position = getPosition((GraphicalEditPart) ep, location); Rectangle bounds = ((GraphicalEditPart)ep).getFigure().getBounds(); switch (position) { case ABOVE: rect.y = bounds.getTop().y; break; case BELOW: rect.y = bounds.getBottom().y; break; } rect.y -= 2; } feedback.translateToRelative(rect); feedback.setBounds(rect); }
/** * Shows or updates feedback for a change bounds request. * * @param request * the request */ protected void showChangeBoundsFeedback(ChangeBoundsRequest request) { IFigure feedback = getDragSourceFeedbackFigure(); PrecisionRectangle rect = new PrecisionRectangle( getInitialFeedbackBounds().getCopy()); getHostFigure().translateToAbsolute(rect); rect.translate(request.getMoveDelta()); rect.resize(request.getSizeDelta()); feedback.translateToRelative(rect); feedback.setBounds(rect); }