Java Code Examples for org.eclipse.draw2d.geometry.Rectangle#getCopy()
The following examples show how to use
org.eclipse.draw2d.geometry.Rectangle#getCopy() .
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: LaneFigure.java From nebula with Eclipse Public License 2.0 | 6 votes |
/** * This is a copy of the parent method. Only change is that we call getContraintAsRectangle() instead of directly accessing the constraints member. */ @Override protected Dimension calculatePreferredSize(IFigure f, int wHint, int hHint) { final Rectangle rect = new Rectangle(); final ListIterator children = f.getChildren().listIterator(); while (children.hasNext()) { final IFigure child = (IFigure) children.next(); Rectangle r = getConstraintAsRectangle(child); if (r == null) continue; if ((r.width == -1) || (r.height == -1)) { final Dimension preferredSize = child.getPreferredSize(r.width, r.height); r = r.getCopy(); if (r.width == -1) r.width = preferredSize.width; if (r.height == -1) r.height = preferredSize.height; } rect.union(r); } final Dimension d = rect.getSize(); final Insets insets = f.getInsets(); return new Dimension(d.width + insets.getWidth(), d.height + insets.getHeight()).union(getBorderPreferredSize(f)); }
Example 2
Source File: BarResizeEditPolicy.java From statecharts with Eclipse Public License 1.0 | 6 votes |
@Override protected ResizeTracker getResizeTracker(int direction) { return new ResizeTracker((GraphicalEditPart) getHost(), direction) { @Override protected void enforceConstraintsForResize(ChangeBoundsRequest request) { Rectangle locationAndSize = getOriginalBounds(); final Rectangle origRequestedBounds = request.getTransformedRectangle(locationAndSize); final Rectangle modified = origRequestedBounds.getCopy(); checkAndPrepareConstraint(request, modified); Dimension newDelta = new Dimension(modified.width - locationAndSize.width, modified.height - locationAndSize.height); request.setSizeDelta(newDelta); final Point moveDelta = request.getMoveDelta(); request.setMoveDelta(new Point(moveDelta.x - origRequestedBounds.x + modified.x, moveDelta.y - origRequestedBounds.y + modified.y)); } }; }
Example 3
Source File: GroupStatesIntoCompositeRefactoring.java From statecharts with Eclipse Public License 1.0 | 6 votes |
/** * Iterates through all {@link StateEditPart}s of the current selection and * computes layout constraints for the composite node. * * @param compositeStateNode * node of the composite state */ protected void setCompositeStateLayoutConstraint(Node compositeStateNode) { Rectangle newbounds = null; for (GraphicalEditPart editPart : getContextObjects()) { Rectangle childBounds = editPart.getFigure().getBounds(); if (newbounds == null) newbounds = childBounds.getCopy(); newbounds.union(childBounds); } newbounds.expand(new Insets(PADDING, PADDING, PADDING, PADDING)); Bounds bounds = NotationFactory.eINSTANCE.createBounds(); bounds.setX(newbounds.x); bounds.setY(newbounds.y); bounds.setWidth(newbounds.width); bounds.setHeight(newbounds.height); compositeStateNode.setLayoutConstraint(bounds); }
Example 4
Source File: MasterPageLayout.java From birt with Eclipse Public License 1.0 | 6 votes |
private Rectangle convertRectangle( Rectangle bounds, Rectangle clientArea ) { Rectangle b = bounds.getCopy( ); b.width = clientArea.width; if ( b.x == 0 ) { b.x = clientArea.getTopLeft( ).x; b.y = clientArea.getTopLeft( ).y; } else { b.x = clientArea.getBottomLeft( ).x; b.y = clientArea.getBottomLeft( ).y - ( ( b.height < 0 ) ? MasterPageLayout.MINIMUM_HEIGHT : b.height ); } return b; }
Example 5
Source File: DropShadowRectangle.java From ermasterr with Apache License 2.0 | 5 votes |
private Rectangle shrink(final Rectangle bounds, final Insets insets) { final Rectangle shrinked = bounds.getCopy(); shrinked.x += insets.left; shrinked.y += insets.top; shrinked.width -= insets.getWidth(); shrinked.height -= insets.getHeight(); return shrinked; }
Example 6
Source File: PrintERDiagramOperation.java From ermasterr with Apache License 2.0 | 5 votes |
private Rectangle shrink(final Rectangle bounds, final Insets insets) { final Rectangle shrinked = bounds.getCopy(); shrinked.x += insets.left; shrinked.y += insets.top; shrinked.width -= insets.getWidth(); shrinked.height -= insets.getHeight(); return shrinked; }
Example 7
Source File: EnlargeContainerEditPolicy.java From statecharts with Eclipse Public License 1.0 | 5 votes |
@SuppressWarnings({ "unchecked" }) private PrecisionRectangle calculateFeedbackBounds(ChangeBoundsRequest request, Rectangle feedbackBounds, IFigure containerFigure) { PrecisionRectangle result = new PrecisionRectangle(feedbackBounds.getCopy()); List<IGraphicalEditPart> editParts = request.getEditParts(); for (IGraphicalEditPart editPart : editParts) { PrecisionRectangle transformedRect = new PrecisionRectangle(editPart.getFigure().getBounds().getCopy()); editPart.getFigure().translateToAbsolute(transformedRect); result.union((Rectangle) transformedRect); } PrecisionDimension preferredSize = new PrecisionDimension(containerFigure.getPreferredSize().getCopy()); containerFigure.translateToAbsolute(preferredSize); if (result.preciseWidth() < preferredSize.preciseWidth() + SPACEING) { result.setPreciseWidth(preferredSize.preciseWidth() + SPACEING); } if (result.preciseHeight() < preferredSize.preciseHeight() + SPACEING) { result.setPreciseHeight(preferredSize.preciseHeight() + SPACEING); } if (result.x < feedbackBounds.x) { result.x = feedbackBounds.x; } if (result.y < feedbackBounds.y) { result.y = feedbackBounds.y; } return result; }
Example 8
Source File: ControlEditPart.java From statecharts with Eclipse Public License 1.0 | 5 votes |
@Override public void setBounds(Rectangle rect) { super.setBounds(rect); rect = rect.getCopy(); translateToAbsolute(rect); control.setBounds(rect.x, rect.y, rect.width, rect.height); super.setBounds(rect); }
Example 9
Source File: DropShadowRectangle.java From erflute with Apache License 2.0 | 5 votes |
private Rectangle shrink(Rectangle bounds, Insets insets) { final Rectangle shrinked = bounds.getCopy(); shrinked.x += insets.left; shrinked.y += insets.top; shrinked.width -= insets.getWidth(); shrinked.height -= insets.getHeight(); return shrinked; }
Example 10
Source File: PrintERDiagramOperation.java From erflute with Apache License 2.0 | 5 votes |
private Rectangle shrink(Rectangle bounds, Insets insets) { final Rectangle shrinked = bounds.getCopy(); shrinked.x += insets.left; shrinked.y += insets.top; shrinked.width -= insets.getWidth(); shrinked.height -= insets.getHeight(); return shrinked; }
Example 11
Source File: DropShadowRectangle.java From ermaster-b with Apache License 2.0 | 5 votes |
private Rectangle shrink(Rectangle bounds, Insets insets) { Rectangle shrinked = bounds.getCopy(); shrinked.x += insets.left; shrinked.y += insets.top; shrinked.width -= insets.getWidth(); shrinked.height -= insets.getHeight(); return shrinked; }
Example 12
Source File: PrintERDiagramOperation.java From ermaster-b with Apache License 2.0 | 5 votes |
private Rectangle shrink(Rectangle bounds, Insets insets) { Rectangle shrinked = bounds.getCopy(); shrinked.x += insets.left; shrinked.y += insets.top; shrinked.width -= insets.getWidth(); shrinked.height -= insets.getHeight(); return shrinked; }
Example 13
Source File: GaugeFigure.java From nebula with Eclipse Public License 2.0 | 4 votes |
public void layout(IFigure container) { Rectangle area = container.getClientArea(); area.width = Math.min(area.width, area.height); area.height = area.width; area.shrink(BORDER_WIDTH, BORDER_WIDTH); Point center = area.getCenter(); if(scale != null) { scale.setBounds(area); } if(ramp != null && ramp.isVisible()) { Rectangle rampBounds = area.getCopy(); ramp.setBounds(rampBounds.shrink(area.width/4, area.height/4)); } if(valueLabel != null) { Dimension labelSize = valueLabel.getPreferredSize(); valueLabel.setBounds(new Rectangle(area.x + area.width/2 - labelSize.width/2, (int)(area.y + area.height * 6.3f/8 - labelSize.height/2), labelSize.width, labelSize.height)); } if(title != null) { Dimension titleSize = titleLabel.getPreferredSize(); titleLabel.setBounds(new Rectangle(area.x + area.width/2 - titleSize.width/2, (int)(area.y + area.height * 7.1f/8 - titleSize.height/2), titleSize.width, titleSize.height)); } if(unit != null) { Dimension unitSize = unitLabel.getPreferredSize(); unitLabel.setBounds(new Rectangle(area.x + area.width/2 - unitSize.width/2, (int)(area.y + area.height * 5.5f/8 - unitSize.height/2), unitSize.width, unitSize.height)); } if(needle != null && scale != null) { needlePoints.setPoint ( new Point(center.x, center.y - NeedleCenter.DIAMETER/2 + 3), 0); scale.getScaleTickMarks(); needlePoints.setPoint( new Point(center.x + area.width/2 - RoundScaleTickMarks.MAJOR_TICK_LENGTH - GAP_BTW_NEEDLE_SCALE, center.y), 1); needlePoints.setPoint( new Point(center.x, center.y + NeedleCenter.DIAMETER/2 - 3), 2); double valuePosition = 360 - scale.getValuePosition(getCoercedValue(), false); if(maximum > minimum){ if(value > maximum) valuePosition += 10; else if(value < minimum) valuePosition -=10; }else{ if(value > minimum) valuePosition -= 10; else if(value < maximum) valuePosition +=10; } needlePoints.setPoint( PointsUtil.rotate(needlePoints.getPoint(0), valuePosition, center), 0); needlePoints.setPoint( PointsUtil.rotate(needlePoints.getPoint(1), valuePosition, center), 1); needlePoints.setPoint( PointsUtil.rotate(needlePoints.getPoint(2), valuePosition, center),2); needle.setPoints(needlePoints); } if(needleCenter != null){ needleCenter.setBounds(new Rectangle(center.x - NeedleCenter.DIAMETER/2, center.y - NeedleCenter.DIAMETER/2, NeedleCenter.DIAMETER, NeedleCenter.DIAMETER)); } }
Example 14
Source File: KnobFigure.java From nebula with Eclipse Public License 2.0 | 4 votes |
public void layout(IFigure container) { Rectangle area = container.getClientArea(); area.width = Math.min(area.width, area.height); area.height = area.width; area.shrink(BORDER_WIDTH, BORDER_WIDTH); Point center = area.getCenter(); Rectangle bulbBounds = null; if(scale != null) { scale.setBounds(area); bulbBounds = area.getCopy(); bulbBounds.shrink(area.width/2 - scale.getInnerRadius() + GAP_BTW_BULB_SCALE, area.height/2 - scale.getInnerRadius() + GAP_BTW_BULB_SCALE); } if(scale != null && ramp != null && ramp.isVisible()) { Rectangle rampBounds = area.getCopy(); ramp.setBounds(rampBounds.shrink(area.width/2 - scale.getInnerRadius() - ramp.getRampWidth()+2, area.height/2 - scale.getInnerRadius() - ramp.getRampWidth()+2)); } if(valueLabel != null && valueLabel.isVisible()) { Dimension labelSize = valueLabel.getPreferredSize(); valueLabel.setBounds(new Rectangle(bulbBounds.x + bulbBounds.width/2 - labelSize.width/2, bulbBounds.y + bulbBounds.height * 3/4 - labelSize.height/2, labelSize.width, labelSize.height)); } if(bulb != null && scale != null && bulb.isVisible()) { bulb.setBounds(bulbBounds); } if(scale != null && thumb != null && thumb.isVisible()){ Point thumbCenter = new Point(bulbBounds.x + bulbBounds.width*7.0/8.0, bulbBounds.y + bulbBounds.height/2); double valuePosition = 360 - scale.getValuePosition(getCoercedValue(), false); thumbCenter = PointsUtil.rotate(thumbCenter, valuePosition, center); int thumbDiameter = bulbBounds.width/6; thumb.setBounds(new Rectangle(thumbCenter.x - thumbDiameter/2, thumbCenter.y - thumbDiameter/2, thumbDiameter, thumbDiameter)); } }
Example 15
Source File: TreeLayout.java From statecharts with Eclipse Public License 1.0 | 4 votes |
private void layoutTree(TreeNode treeNode, int start, double share) { final Rectangle constraint = (Rectangle) getConstraint(treeNode.figure); if (constraint != null) { Rectangle bounds = constraint.getCopy(); if (bounds.width <= 0 || bounds.height <= 0) { final Dimension preferredSize = treeNode.figure .getPreferredSize(bounds.width, bounds.height); if (bounds.width <= 0) { bounds.width = preferredSize.width; } if (bounds.height <= 0) { bounds.height = preferredSize.height; } } // Calculation for tree level distance assumes that all figures have // the same width and/or height; final int rankPos = isTopLeftAlignment ? treeNode.level : maxTreeLevel - treeNode.level; // final int levelPos = (rankPos * (bounds.width + rankSpacing)) // + (rankSpacing / 2); final int levelPos = getlevelPos(rankPos) + (rankSpacing / 2) ; final int cellPos = (int) (start + treeNode.weight * share / 2); bounds.x = isVertical ? cellPos - (bounds.width / 2) : levelPos; bounds.y = isVertical ? levelPos : cellPos - (bounds.height / 2); for (final TreeNode childNode : treeNode.children) { layoutTree(childNode, start, share); start += share * childNode.weight; } // System.out.println("******************************************"); // //System.out.println("Parent Size: " + // treeNode.parent.figure.getSize()); // System.out.println("Figure " + treeNode.figure + " Tree Level: " // + treeNode.level + " Weight: " + treeNode.weight); // System.out.println(" X: " + bounds.x + " Y: " + bounds.y // + " Width : " + bounds.width + " Height: " + bounds.height); // System.out.println("******************************************"); bounds = bounds.getTranslated(parentOffset); treeNode.figure.setBounds(bounds); treeNode.setLayouted(true); } }
Example 16
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; }