Mercurial > projects > dwt2
comparison org.eclipse.draw2d/src/org/eclipse/draw2d/text/FlowAdapter.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) 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.FlowAdapter; | |
14 | |
15 import java.lang.all; | |
16 | |
17 import org.eclipse.draw2d.IFigure; | |
18 import org.eclipse.draw2d.geometry.Dimension; | |
19 import org.eclipse.draw2d.geometry.Rectangle; | |
20 import org.eclipse.draw2d.text.FlowFigure; | |
21 import org.eclipse.draw2d.text.BidiProcessor; | |
22 import org.eclipse.draw2d.text.FlowFigureLayout; | |
23 import org.eclipse.draw2d.text.FlowContext; | |
24 import org.eclipse.draw2d.text.ContentBox; | |
25 import org.eclipse.draw2d.text.BidiInfo; | |
26 import org.eclipse.draw2d.text.BidiChars; | |
27 | |
28 | |
29 /** | |
30 * Adapts non-flow figures for use within a parent hierarchy requiring flow figures. | |
31 * Normal draw2d figures can be added as children. If a normal LayoutManager is set, the | |
32 * children will be positioned by that layout manager. The size of this figure within | |
33 * the flow will be determined by its preferred size. | |
34 * <p> | |
35 * WARNING: This class is not intended to be subclassed by clients. | |
36 * | |
37 * @author Pratik Shah | |
38 * @since 3.1 | |
39 */ | |
40 public class FlowAdapter | |
41 : FlowFigure | |
42 { | |
43 | |
44 private FlowContext context; | |
45 private FigureBox box; | |
46 | |
47 public this(){ | |
48 box = new FigureBox(); | |
49 } | |
50 /** | |
51 * This FlowFigure contributes an Object Replacement Character. | |
52 * @see FlowFigure#contributeBidi(BidiProcessor) | |
53 */ | |
54 protected void contributeBidi(BidiProcessor proc) { | |
55 box.setBidiLevel(-1); | |
56 // contributes a single object replacement char | |
57 proc.add(this, BidiChars.OBJ); | |
58 } | |
59 | |
60 /** | |
61 * @return <code>null</code> | |
62 * @see org.eclipse.draw2d.text.FlowFigure#createDefaultFlowLayout() | |
63 */ | |
64 protected FlowFigureLayout createDefaultFlowLayout() { | |
65 return null; | |
66 } | |
67 | |
68 /** | |
69 * Sizes the content box to be big enough to display all figures. Wraps to the next line | |
70 * if there is not enough room on the current one. | |
71 * @see org.eclipse.draw2d.Figure#layout() | |
72 */ | |
73 protected void layout() { | |
74 int wHint = context.getRemainingLineWidth(); | |
75 if (wHint is Integer.MAX_VALUE) | |
76 wHint = -1; | |
77 Dimension prefSize = getPreferredSize(wHint, -1); | |
78 if (context.isCurrentLineOccupied() | |
79 && prefSize.width > context.getRemainingLineWidth()) { | |
80 context.endLine(); | |
81 prefSize = getPreferredSize(context.getRemainingLineWidth(), -1); | |
82 } | |
83 box.setSize(prefSize); | |
84 context.addToCurrentLine(box); | |
85 } | |
86 | |
87 /** | |
88 * Updates the bounds of this figure to match that of its content box, and lays out this | |
89 * figure's children. | |
90 * @see FlowFigure#postValidate() | |
91 */ | |
92 public void postValidate() { | |
93 setBounds(new Rectangle(box.getX(), box.getBaseline() - box.ascent, | |
94 box.width, box.ascent)); | |
95 super.layout(); | |
96 for (Iterator itr = getChildren().iterator(); itr.hasNext();) | |
97 (cast(IFigure)itr.next()).validate(); | |
98 } | |
99 | |
100 /** | |
101 * Sets the bidi level of the content box associated with this Figure | |
102 * @see FlowFigure#setBidiInfo(BidiInfo) | |
103 */ | |
104 public void setBidiInfo(BidiInfo info) { | |
105 box.setBidiLevel(info.levelInfo[0]); | |
106 } | |
107 | |
108 /** | |
109 * @see org.eclipse.draw2d.IFigure#setBounds(org.eclipse.draw2d.geometry.Rectangle) | |
110 */ | |
111 public void setBounds(Rectangle rect) { | |
112 int x = bounds.x, | |
113 y = bounds.y; | |
114 | |
115 bool resize = (rect.width !is bounds.width) || (rect.height !is bounds.height), | |
116 translate = (rect.x !is x) || (rect.y !is y); | |
117 | |
118 if ((resize || translate) && isVisible()) | |
119 erase(); | |
120 if (translate) { | |
121 int dx = rect.x - x; | |
122 int dy = rect.y - y; | |
123 primTranslate(dx, dy); | |
124 } | |
125 | |
126 bounds.width = rect.width; | |
127 bounds.height = rect.height; | |
128 | |
129 if (translate || resize) { | |
130 fireFigureMoved(); | |
131 repaint(); | |
132 } | |
133 } | |
134 | |
135 /** | |
136 * @see FlowFigure#setFlowContext(FlowContext) | |
137 */ | |
138 public void setFlowContext(FlowContext flowContext) { | |
139 context = flowContext; | |
140 } | |
141 | |
142 /** | |
143 * Do not validate children. | |
144 * @see org.eclipse.draw2d.IFigure#validate() | |
145 */ | |
146 public void validate() { | |
147 if (isValid()) | |
148 return; | |
149 setValid(true); | |
150 layout(); | |
151 } | |
152 | |
153 private class FigureBox : ContentBox { | |
154 private int ascent; | |
155 public bool containsPoint(int x, int y) { | |
156 return this.outer.containsPoint(x, y); | |
157 } | |
158 public int getAscent() { | |
159 return ascent; | |
160 } | |
161 public int getDescent() { | |
162 return 0; | |
163 } | |
164 public void setSize(Dimension size) { | |
165 ascent = size.height; | |
166 width = size.width; | |
167 } | |
168 } | |
169 | |
170 } |