comparison dwtx/draw2d/AbstractLayout.d @ 98:95307ad235d9

Added Draw2d code, still work in progress
author Frank Benoit <benoit@tionex.de>
date Sun, 03 Aug 2008 00:52:14 +0200
parents
children
comparison
equal deleted inserted replaced
96:b492ba44e44d 98:95307ad235d9
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 dwtx.draw2d.AbstractLayout;
14
15 import dwt.dwthelper.utils;
16
17 import dwtx.draw2d.geometry.Dimension;
18 import dwtx.draw2d.IFigure;
19 import dwtx.draw2d.LayoutManager;
20
21 /**
22 * Provides generic support for LayoutManagers.
23 */
24 public abstract class AbstractLayout
25 : LayoutManager
26 {
27
28 /**
29 * The cached preferred size.
30 */
31 protected Dimension preferredSize;
32
33 /**
34 * Whether or not this layout pays attention to visiblity of figures when
35 * calculating its bounds. By default, false.
36 */
37 protected bool isObservingVisibility_ = false;
38
39 /**
40 * This method is now {@link #calculatePreferredSize(IFigure, int, int)}.
41 * @param container the figure
42 */
43 protected final void calculatePreferredSize(IFigure container) { }
44
45 /**
46 * Calculates the preferred size of the given figure, using width and height hints.
47 * @param container The figure
48 * @param wHint The width hint
49 * @param hHint The height hint
50 * @return The preferred size
51 */
52 protected abstract Dimension calculatePreferredSize(IFigure container,
53 int wHint, int hHint);
54
55 /**
56 * Returns the preferred size of the figure's border.
57 * @param container The figure that the border is on
58 * @return The border's preferred size
59 */
60 protected Dimension getBorderPreferredSize(IFigure container) {
61 if (container.getBorder() is null)
62 return new Dimension();
63 return container.getBorder().getPreferredSize(container);
64 }
65
66 /**
67 * Returns the constraint for the given figure.
68 * @param child The figure
69 * @return The constraint
70 */
71 public Object getConstraint(IFigure child) {
72 return null;
73 }
74
75 /**
76 * This method is now {@link #getMinimumSize(IFigure, int, int)}.
77 * @param container the figure
78 */
79 public final void getMinimumSize(IFigure container) { }
80
81 /**
82 * @see dwtx.draw2d.LayoutManager#getMinimumSize(IFigure, int, int)
83 */
84 public Dimension getMinimumSize(IFigure container, int wHint, int hHint) {
85 return getPreferredSize(container, wHint, hHint);
86 }
87
88 /**
89 * Returns the preferred size of the given figure, using width and height hints. If the
90 * preferred size is cached, that size is returned. Otherwise, {@link
91 * #calculatePreferredSize(IFigure, int, int)} is called.
92 * @param container The figure
93 * @param wHint The width hint
94 * @param hHint The height hint
95 * @return The preferred size
96 */
97 public Dimension getPreferredSize(IFigure container, int wHint, int hHint) {
98 if (preferredSize is null)
99 preferredSize = calculatePreferredSize(container, wHint, hHint);
100 return preferredSize;
101 }
102
103 /**
104 * This method is now {@link #getPreferredSize(IFigure, int, int)}.
105 * @param container the figure
106 */
107 public final void getPreferredSize(IFigure container) { }
108
109
110 /**
111 * @see dwtx.draw2d.LayoutManager#invalidate()
112 */
113 public void invalidate() {
114 preferredSize = null;
115 }
116
117 /**
118 * Removes any cached information about the given figure.
119 * @param child the child that is invalidated
120 */
121 protected void invalidate(IFigure child) {
122 invalidate();
123 }
124
125 /**
126 * Returns whether or not this layout pays attention to visiblity when calculating its
127 * bounds.
128 * @return true if invisible figures should not contribute to this layout's bounds.
129 */
130 public bool isObservingVisibility() {
131 return isObservingVisibility_;
132 }
133
134 /**
135 * Removes the given figure from this LayoutManager's list of figures.
136 * @param child The figure to remove
137 */
138 public void remove(IFigure child) {
139 invalidate();
140 }
141
142 /**
143 * Sets the constraint for the given figure.
144 * @param child the child
145 * @param constraint the child's new constraint
146 */
147 public void setConstraint(IFigure child, Object constraint) {
148 invalidate(child);
149 }
150
151 /**
152 * Sets isObservingVisibility to the given value.
153 * @param newValue <code>true</code> if visibility should be observed
154 */
155 public void setObserveVisibility(bool newValue) {
156 if (isObservingVisibility_ is newValue)
157 return;
158 isObservingVisibility_ = newValue;
159 }
160
161 }