comparison org.eclipse.draw2d/src/org/eclipse/draw2d/text/FlowContainerLayout.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 dbfb303e8fb0
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.text.FlowContainerLayout;
14
15 import java.lang.all;
16
17 import org.eclipse.draw2d.Figure;
18 import org.eclipse.draw2d.text.FlowFigureLayout;
19 import org.eclipse.draw2d.text.FlowBox;
20 import org.eclipse.draw2d.text.LineBox;
21 import org.eclipse.draw2d.text.FlowContext;
22 import org.eclipse.draw2d.text.FlowFigure;
23
24 /**
25 * A layout for FlowFigures with children.
26 *
27 * <P>WARNING: This class is not intended to be subclassed by clients.
28 * @author hudsonr
29 * @since 2.1
30 */
31 public abstract class FlowContainerLayout
32 : FlowFigureLayout
33 , FlowContext
34 {
35
36 /**
37 * the current line
38 */
39 LineBox currentLine;
40
41 /**
42 * @see org.eclipse.draw2d.text.FlowFigureLayout#FlowFigureLayout(FlowFigure)
43 */
44 protected this(FlowFigure flowFigure) {
45 super(flowFigure);
46 }
47
48 /**
49 * Adds the given box the current line and clears the context's state.
50 * @see org.eclipse.draw2d.text.FlowContext#addToCurrentLine(FlowBox)
51 */
52 public void addToCurrentLine(FlowBox child) {
53 getCurrentLine().add(child);
54 setContinueOnSameLine(false);
55 }
56
57 /**
58 * Flush anything pending and free all temporary data used during layout.
59 */
60 protected void cleanup() {
61 currentLine = null;
62 }
63
64 /**
65 * Used by getCurrentLine().
66 */
67 protected abstract void createNewLine();
68
69 /**
70 * Called after {@link #layoutChildren()} when all children have been laid out. This
71 * method exists to flush the last line.
72 */
73 protected abstract void flush();
74
75 /**
76 * FlowBoxes shouldn't be added directly to the current line. Use
77 * {@link #addToCurrentLine(FlowBox)} for that.
78 * @see org.eclipse.draw2d.text.FlowContext#getCurrentLine()
79 */
80 LineBox getCurrentLine() {
81 if (currentLine is null)
82 createNewLine();
83 return currentLine;
84 }
85
86 /**
87 * @see FlowContext#getRemainingLineWidth()
88 */
89 public int getRemainingLineWidth() {
90 return getCurrentLine().getAvailableWidth();
91 }
92
93 /**
94 * @see FlowContext#isCurrentLineOccupied()
95 */
96 public bool isCurrentLineOccupied() {
97 return currentLine !is null && currentLine.isOccupied();
98 }
99
100 /**
101 * @see FlowFigureLayout#layout()
102 */
103 protected void layout() {
104 preLayout();
105 layoutChildren();
106 flush();
107 cleanup();
108 }
109
110 /**
111 * Layout all children.
112 */
113 protected void layoutChildren() {
114 List children = getFlowFigure().getChildren();
115 for (int i = 0; i < children.size(); i++) {
116 Figure f = cast(Figure)children.get(i);
117 if (forceChildInvalidation(f))
118 f.invalidate();
119 f.validate();
120 }
121 }
122
123 bool forceChildInvalidation(Figure f) {
124 return true;
125 }
126
127 /**
128 * Called before layoutChildren() to setup any necessary state.
129 */
130 protected abstract void preLayout();
131
132 }