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