Java Code Examples for org.eclipse.draw2d.geometry.Rectangle#width()

The following examples show how to use org.eclipse.draw2d.geometry.Rectangle#width() . 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: OverviewEventLayer.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Rectangle getConstraint(IFigure figure) {
	final TimeBaseConverter timeConverter = RootFigure.getTimeViewDetails(figure);

	final EventFigure eventFigure = (EventFigure) super.getConstraint(figure);
	final ITimed event = eventFigure.getEvent();

	final Timing screenCoordinates = timeConverter.toOverviewScreenCoordinates(event.getTiming());
	final Rectangle overviewEventArea = new PrecisionRectangle(screenCoordinates.left(),
			OverviewFigure.VERTICAL_INDENT + ((fEventHeight + OverviewFigure.Y_PADDING) * RootFigure.getLaneIndex(eventFigure)),
			screenCoordinates.getDuration(), fEventHeight);

	if (overviewEventArea.width() < MINIMUM_WIDTH)
		overviewEventArea.setWidth(MINIMUM_WIDTH);

	return overviewEventArea;
}
 
Example 2
Source File: LaneFigure.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void layout(IFigure parent) {
	final TimeBaseConverter timeViewDetails = RootFigure.getRootFigure(parent).getTimeViewDetails();

	for (final Object figure : getChildren()) {
		final ITimelineEvent event = (ITimelineEvent) getConstraint((IFigure) figure);

		final Timing screenCoordinates = timeViewDetails.toDetailCoordinates(event.getTiming());
		final Rectangle screenBounds = new PrecisionRectangle(screenCoordinates.getTimestamp(), getBounds().y(), screenCoordinates.getDuration(),
				getBounds().height());

		if (screenBounds.width() == 0)
			screenBounds.setWidth(1);

		((IFigure) figure).setBounds(screenBounds);
	}
}
 
Example 3
Source File: OverviewSelectionLayer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Object getConstraint(IFigure figure) {
	final TimeBaseConverter timeConverter = RootFigure.getTimeViewDetails(figure);

	final Timing coordinates = timeConverter.toOverviewScreenCoordinates(timeConverter.getVisibleEventArea());
	final Rectangle bounds = new PrecisionRectangle(coordinates.left(), 0, coordinates.getDuration(), getBounds().height());
	if (bounds.width() < MINIMUM_WIDTH)
		bounds.setWidth(MINIMUM_WIDTH);

	return bounds;
}
 
Example 4
Source File: AdjustIdentityAnchorCommand.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
private PrecisionPoint computeNewAnchor(PrecisionPoint currentAnchorPoint, EditPart editPart) {

		double scale = getScale(editPart);
		IFigure figure = ((IGraphicalEditPart) editPart).getFigure();
		Rectangle bounds = figure.getBounds();
		if (figure instanceof HandleBounds) {
			bounds = ((HandleBounds) figure).getHandleBounds();
		}

		Point currentRelativePoint = getAnchorRelativePoint(currentAnchorPoint, bounds);

		if (futureSize != null && delta != null) {
			// In case of border node, the real location is computed earlier
			// (according to BorderItemLocator). The corresponding futureSize
			// and delta are used instead of the request data.
			return new PrecisionPoint(((double) (currentRelativePoint.x - delta.x)) / futureSize.width,
					((double) (currentRelativePoint.y - delta.y)) / futureSize.height);
		} else {

			double logicalWidthDelta = request.getSizeDelta().width / scale;
			double logicalHeightDelta = request.getSizeDelta().height / scale;

			int direction = request.getResizeDirection();

			double newRelativeX = computeNewXRelativeLocation(direction, currentRelativePoint, logicalWidthDelta);
			double newRelativeY = computeNewYRelativeLocation(direction, currentRelativePoint, logicalHeightDelta);

			return new PrecisionPoint(newRelativeX / (bounds.width() + logicalWidthDelta),
					newRelativeY / (bounds.height() + logicalHeightDelta));
		}
	}
 
Example 5
Source File: AdjustIdentityAnchorCommand.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
protected Point getAnchorRelativePoint(PrecisionPoint currentAnchorPoint, Rectangle bounds) {
	return new PrecisionPoint(bounds.width() * currentAnchorPoint.preciseX(),
			bounds.height() * currentAnchorPoint.preciseY());
}
 
Example 6
Source File: ExtractSubdiagramRefactoring.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a new {@link Diagram} and copies child elements
 */
protected Diagram createSubdiagram() {
	View contextView = getContextObject();
	State contextElement = (State) contextView.getElement();
	Diagram subdiagram = ViewService.createDiagram(contextElement, StatechartDiagramEditor.ID, preferencesHint);
	View figureCompartment = ViewUtil.getChildBySemanticHint(contextView, SemanticHints.STATE_FIGURE_COMPARTMENT);
	getResource().getContents().add(subdiagram);

	boolean isHorizontal = isHorizontal(figureCompartment);
	int offset = 0;
	int subregions = figureCompartment.getChildren().size();
	while (figureCompartment.getChildren().size() > 0) {
		Node child = (Node) figureCompartment.getChildren().get(0);
		if (subregions > 1) {
			Rectangle actualBounds = getActualBounds(child);
			if (actualBounds != Rectangle.SINGLETON) {
				Bounds modelBounds = (Bounds) child.getLayoutConstraint();
				modelBounds.setWidth(actualBounds.width());
				modelBounds.setHeight(actualBounds.height());
				if (isHorizontal) {
					modelBounds.setX(offset);
					offset += actualBounds.width();
				} else {
					modelBounds.setY(offset);
					offset += actualBounds.height();
				}
			}
		}
		subdiagram.insertChild(child);
	}

	@SuppressWarnings("unchecked")
	List<Edge> edges = figureCompartment.getDiagram().getEdges();
	List<Edge> moveEdges = edges.stream().filter(
			(edge) -> edge.getSource().getDiagram() == subdiagram && edge.getTarget().getDiagram() == subdiagram)
			.collect(Collectors.toList());
	for (Edge edge2 : moveEdges) {
		subdiagram.insertEdge(edge2);
	}
	return subdiagram;	
}