comparison org.eclipse.draw2d/src/org/eclipse/draw2d/FreeformViewport.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children
comparison
equal deleted inserted replaced
11:43904fec5dca 12:bc29606a740c
1 /*******************************************************************************
2 * Copyright (c) 2000, 2005 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 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module org.eclipse.draw2d.FreeformViewport;
14
15 import java.lang.all;
16
17 import org.eclipse.draw2d.geometry.Dimension;
18 import org.eclipse.draw2d.geometry.Rectangle;
19 import org.eclipse.draw2d.Viewport;
20 import org.eclipse.draw2d.ViewportLayout;
21 import org.eclipse.draw2d.IFigure;
22 import org.eclipse.draw2d.FreeformFigure;
23
24 /**
25 * A viewport for {@link org.eclipse.draw2d.FreeformFigure FreeformFigures}.
26 * FreeformFigures can only reside in this type of viewport.
27 */
28 public class FreeformViewport
29 : Viewport
30 {
31
32 class FreeformViewportLayout
33 : ViewportLayout
34 {
35 protected Dimension calculatePreferredSize(IFigure parent, int wHint, int hHint) {
36 getContents().validate();
37 wHint = Math.max(0, wHint);
38 hHint = Math.max(0, hHint);
39 return (cast(FreeformFigure)getContents())
40 .getFreeformExtent()
41 .getExpanded(getInsets())
42 .union_(0, 0)
43 .union_(wHint - 1, hHint - 1)
44 .getSize();
45 }
46
47 protected bool isSensitiveHorizontally(IFigure parent) {
48 return true;
49 }
50
51 protected bool isSensitiveVertically(IFigure parent) {
52 return true;
53 }
54
55
56 public void layout(IFigure figure) {
57 //Do nothing, contents updates itself.
58 }
59 }
60
61 /**
62 * Constructs a new FreeformViewport. This viewport must use graphics translation to
63 * scroll the FreeformFigures inside of it.
64 */
65 public this() {
66 super(true); //Must use graphics translate to scroll freeforms.
67 setLayoutManager(new FreeformViewportLayout());
68 }
69
70 /**
71 * Readjusts the scrollbars. In doing so, it gets the freeform extent of the contents and
72 * unions this rectangle with this viewport's client area, then sets the contents freeform
73 * bounds to be this unioned rectangle. Then proceeds to set the scrollbar values based
74 * on this new information.
75 * @see Viewport#readjustScrollBars()
76 */
77 protected void readjustScrollBars() {
78 if (getContents() is null)
79 return;
80 if (!( null !is cast(FreeformFigure)getContents() ))
81 return;
82 FreeformFigure ff = cast(FreeformFigure)getContents();
83 Rectangle clientArea = getClientArea();
84 Rectangle bounds = ff.getFreeformExtent().getCopy();
85 bounds.union_(0, 0, clientArea.width, clientArea.height);
86 ff.setFreeformBounds(bounds);
87
88 getVerticalRangeModel().setAll(bounds.y, clientArea.height, bounds.bottom());
89 getHorizontalRangeModel().setAll(bounds.x, clientArea.width, bounds.right());
90 }
91
92 /**
93 * Returns <code>true</code>.
94 * @see Figure#useLocalCoordinates()
95 */
96 protected bool useLocalCoordinates() {
97 return true;
98 }
99
100 }