Project

General

Profile

Download (2.79 KB) Statistics
| Branch: | Tag: | Revision:
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.draw2d;
12

    
13
import org.eclipse.draw2d.geometry.Dimension;
14
import org.eclipse.draw2d.geometry.Rectangle;
15

    
16
/**
17
 * A viewport for {@link org.eclipse.draw2d.FreeformFigure FreeformFigures}.
18
 * FreeformFigures can only reside in this type of viewport.
19
 */
20
public class FreeformViewport extends Viewport {
21

    
22
	class FreeformViewportLayout extends ViewportLayout {
23
		protected Dimension calculatePreferredSize(IFigure parent, int wHint,
24
				int hHint) {
25
			getContents().validate();
26
			wHint = Math.max(0, wHint);
27
			hHint = Math.max(0, hHint);
28
			return ((FreeformFigure) getContents()).getFreeformExtent()
29
					.getExpanded(getInsets()).union(0, 0)
30
					.union(wHint - 1, hHint - 1).getSize();
31
		}
32

    
33
		protected boolean isSensitiveHorizontally(IFigure parent) {
34
			return true;
35
		}
36

    
37
		protected boolean isSensitiveVertically(IFigure parent) {
38
			return true;
39
		}
40

    
41
		public void layout(IFigure figure) {
42
			// Do nothing, contents updates itself.
43
		}
44
	}
45

    
46
	/**
47
	 * Constructs a new FreeformViewport. This viewport must use graphics
48
	 * translation to scroll the FreeformFigures inside of it.
49
	 */
50
	public FreeformViewport() {
51
		super(true); // Must use graphics translate to scroll freeforms.
52
		setLayoutManager(new FreeformViewportLayout());
53
	}
54

    
55
	/**
56
	 * Readjusts the scrollbars. In doing so, it gets the freeform extent of the
57
	 * contents and unions this rectangle with this viewport's client area, then
58
	 * sets the contents freeform bounds to be this unioned rectangle. Then
59
	 * proceeds to set the scrollbar values based on this new information.
60
	 * 
61
	 * @see Viewport#readjustScrollBars()
62
	 */
63
	protected void readjustScrollBars() {
64
		if (getContents() == null)
65
			return;
66
		if (!(getContents() instanceof FreeformFigure))
67
			return;
68
		FreeformFigure ff = (FreeformFigure) getContents();
69
		Rectangle clientArea = getClientArea();
70
		Rectangle bounds = ff.getFreeformExtent().getCopy();
71
		bounds.union(0, 0, clientArea.width, clientArea.height);
72
		ff.setFreeformBounds(bounds);
73

    
74
		getVerticalRangeModel().setAll(bounds.y, clientArea.height,
75
				bounds.bottom());
76
		getHorizontalRangeModel().setAll(bounds.x, clientArea.width,
77
				bounds.right());
78
	}
79

    
80
	/**
81
	 * Returns <code>true</code>.
82
	 * 
83
	 * @see Figure#useLocalCoordinates()
84
	 */
85
	protected boolean useLocalCoordinates() {
86
		return true;
87
	}
88

    
89
}
(76-76/171)