Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 313144
Collapse All | Expand All

(-)src/org/eclipse/draw2d/ViewportAwareConnectionLayerClippingStrategy.java (-22 / +42 lines)
Lines 3-15 Link Here
3
import java.util.Iterator;
3
import java.util.Iterator;
4
import java.util.List;
4
import java.util.List;
5
5
6
import org.eclipse.draw2d.geometry.Insets;
6
import org.eclipse.draw2d.geometry.PointList;
7
import org.eclipse.draw2d.geometry.PointList;
7
import org.eclipse.draw2d.geometry.Rectangle;
8
import org.eclipse.draw2d.geometry.Rectangle;
8
9
9
/**
10
/**
10
 * Clipping strategy for connection layer, which takes into account nested
11
 * Clipping strategy for connection layer, which takes into account nested view
11
 * view ports and truncates those parts of connections which reach outside
12
 * ports and truncates those parts of connections which reach outside and are
12
 * and are thus not visible.
13
 * thus not visible.
13
 * 
14
 * 
14
 * @author Alexander Nyssen
15
 * @author Alexander Nyssen
15
 * @author Philip Ritzkopf
16
 * @author Philip Ritzkopf
Lines 19-24 Link Here
19
public class ViewportAwareConnectionLayerClippingStrategy implements
20
public class ViewportAwareConnectionLayerClippingStrategy implements
20
		IClippingStrategy {
21
		IClippingStrategy {
21
22
23
	private static final Insets PRIVATE_INSETS = new Insets(0, 0, 1, 1);
24
22
	private ConnectionLayer connectionLayer = null;
25
	private ConnectionLayer connectionLayer = null;
23
26
24
	public ViewportAwareConnectionLayerClippingStrategy(
27
	public ViewportAwareConnectionLayerClippingStrategy(
Lines 46-53 Link Here
46
	}
49
	}
47
50
48
	/**
51
	/**
49
	 * Computes clipping rectangle(s) for a given connection. Will consider
52
	 * Computes clipping rectangle(s) for a given connection. Will consider all
50
	 * all enclosing viewports, excluding the root viewport.
53
	 * enclosing viewports, excluding the root viewport.
51
	 */
54
	 */
52
	protected Rectangle[] getEdgeClippingRectangle(Connection connection) {
55
	protected Rectangle[] getEdgeClippingRectangle(Connection connection) {
53
		// start with clipping the connection at its original bounds
56
		// start with clipping the connection at its original bounds
Lines 80-86 Link Here
80
					.getParent()));
83
					.getParent()));
81
		}
84
		}
82
85
83
		// if the nearest common viewport of source and target is not simultaneously
86
		// if the nearest common viewport of source and target is not
87
		// simultaneously
84
		// the nearest enclosing viewport of source and target respectively, the
88
		// the nearest enclosing viewport of source and target respectively, the
85
		// connection has to be further clipped (the connection may even not be
89
		// connection has to be further clipped (the connection may even not be
86
		// visible at all)
90
		// visible at all)
Lines 94-114 Link Here
94
			// itself be nested in other viewports).
98
			// itself be nested in other viewports).
95
			Rectangle sourceClipRect = getAbsoluteBoundsAsCopy(sourceFigure);
99
			Rectangle sourceClipRect = getAbsoluteBoundsAsCopy(sourceFigure);
96
			if (nearestEnclosingSourceViewport != nearestEnclosingCommonViewport) {
100
			if (nearestEnclosingSourceViewport != nearestEnclosingCommonViewport) {
97
				clipAtViewports(sourceClipRect, ViewportUtilities
101
				clipAtViewports(sourceClipRect,
98
						.getViewportsPath(nearestEnclosingSourceViewport,
102
						ViewportUtilities.getViewportsPath(
103
								nearestEnclosingSourceViewport,
99
								nearestEnclosingCommonViewport, false));
104
								nearestEnclosingCommonViewport, false));
100
			}
105
			}
101
			Rectangle targetClipRect = getAbsoluteBoundsAsCopy(targetFigure);
106
			Rectangle targetClipRect = getAbsoluteBoundsAsCopy(targetFigure);
102
			if (nearestEnclosingTargetViewport != nearestEnclosingCommonViewport) {
107
			if (nearestEnclosingTargetViewport != nearestEnclosingCommonViewport) {
103
				clipAtViewports(targetClipRect, ViewportUtilities
108
				clipAtViewports(targetClipRect,
104
						.getViewportsPath(nearestEnclosingTargetViewport,
109
						ViewportUtilities.getViewportsPath(
110
								nearestEnclosingTargetViewport,
105
								nearestEnclosingCommonViewport, false));
111
								nearestEnclosingCommonViewport, false));
106
			}
112
			}
107
			PointList absolutePointsAsCopy = getAbsolutePointsAsCopy(connection);
113
			PointList absolutePointsAsCopy = getAbsolutePointsAsCopy(connection);
108
			boolean sourceAnchorVisible = sourceClipRect
114
			boolean sourceAnchorVisible = sourceClipRect.getExpanded(
109
					.contains(absolutePointsAsCopy.getFirstPoint());
115
					PRIVATE_INSETS).contains(
110
			boolean targetAnchorVisible = targetClipRect
116
					absolutePointsAsCopy.getFirstPoint());
111
					.contains(absolutePointsAsCopy.getLastPoint());
117
			boolean targetAnchorVisible = targetClipRect.getExpanded(
118
					PRIVATE_INSETS).contains(
119
					absolutePointsAsCopy.getLastPoint());
112
120
113
			if (!sourceAnchorVisible || !targetAnchorVisible) {
121
			if (!sourceAnchorVisible || !targetAnchorVisible) {
114
				// one (or both) of source or target anchor is invisible
122
				// one (or both) of source or target anchor is invisible
Lines 136-143 Link Here
136
	}
144
	}
137
145
138
	/**
146
	/**
139
	 * Computes clipping rectangle for a given (node) figure. Will consider
147
	 * Computes clipping rectangle for a given (node) figure. Will consider all
140
	 * all enclosing viewports, excluding the root viewport.
148
	 * enclosing viewports, excluding the root viewport.
141
	 */
149
	 */
142
	protected Rectangle getNodeClippingRectangle(IFigure figure) {
150
	protected Rectangle getNodeClippingRectangle(IFigure figure) {
143
		// start with the bounds of the edit part's figure
151
		// start with the bounds of the edit part's figure
Lines 160-167 Link Here
160
			List enclosingViewportsPath) {
168
			List enclosingViewportsPath) {
161
		for (Iterator iterator = enclosingViewportsPath.iterator(); iterator
169
		for (Iterator iterator = enclosingViewportsPath.iterator(); iterator
162
				.hasNext();) {
170
				.hasNext();) {
163
			clipRect.intersect(getAbsoluteViewportClientAreaAsCopy((Viewport) iterator
171
			Viewport viewport = (Viewport) iterator.next();
164
					.next()));
172
			clipRect.intersect(getAbsoluteViewportAreaAsCopy(viewport));
165
		}
173
		}
166
	}
174
	}
167
175
Lines 171-178 Link Here
171
	 * viewport of primary and connection layer.
179
	 * viewport of primary and connection layer.
172
	 */
180
	 */
173
	protected Viewport getRootViewport() {
181
	protected Viewport getRootViewport() {
174
		return ViewportUtilities
182
		return ViewportUtilities.getNearestEnclosingViewport(connectionLayer);
175
				.getNearestEnclosingViewport(connectionLayer);
176
	}
183
	}
177
184
178
	/**
185
	/**
Lines 185-194 Link Here
185
	}
192
	}
186
193
187
	/**
194
	/**
195
	 * Returns the area covered by the viewport in absolute coordinates.
196
	 */
197
	protected Rectangle getAbsoluteViewportAreaAsCopy(Viewport viewport) {
198
		Rectangle absoluteViewportArea = null;
199
		if (viewport.getParent().getBorder() != null
200
				&& viewport.getParent().getBorder().isOpaque()) {
201
			absoluteViewportArea = getAbsoluteViewportClientAreaAsCopy(viewport);
202
		} else {
203
			absoluteViewportArea = getAbsoluteBoundsAsCopy(viewport.getParent());
204
		}
205
		return absoluteViewportArea;
206
	}
207
208
	/**
188
	 * Returns the viewport's client area in absolute coordinates.
209
	 * Returns the viewport's client area in absolute coordinates.
189
	 */
210
	 */
190
	protected Rectangle getAbsoluteViewportClientAreaAsCopy(
211
	protected Rectangle getAbsoluteViewportClientAreaAsCopy(Viewport viewport) {
191
			Viewport viewport) {
192
		Rectangle absoluteClientArea = viewport.getClientArea();
212
		Rectangle absoluteClientArea = viewport.getClientArea();
193
		viewport.translateToParent(absoluteClientArea);
213
		viewport.translateToParent(absoluteClientArea);
194
		viewport.translateToAbsolute(absoluteClientArea);
214
		viewport.translateToAbsolute(absoluteClientArea);

Return to bug 313144