Mercurial > projects > dwt-addons
comparison dwtx/jface/viewers/TableLayout.d @ 104:04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
These new wrappers now use the tango.util.containers instead of the tango.util.collections.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 07 Aug 2008 15:01:33 +0200 |
parents | b3daa78bc913 |
children |
comparison
equal
deleted
inserted
replaced
103:2d6540440fe6 | 104:04b47443bb01 |
---|---|
15 | 15 |
16 import dwtx.jface.viewers.ColumnLayoutData; | 16 import dwtx.jface.viewers.ColumnLayoutData; |
17 import dwtx.jface.viewers.ColumnPixelData; | 17 import dwtx.jface.viewers.ColumnPixelData; |
18 import dwtx.jface.viewers.ColumnWeightData; | 18 import dwtx.jface.viewers.ColumnWeightData; |
19 | 19 |
20 import tango.util.collection.model.Seq; | |
21 import tango.util.collection.ArraySeq; | |
22 | 20 |
23 import dwt.DWT; | 21 import dwt.DWT; |
24 import dwt.graphics.Point; | 22 import dwt.graphics.Point; |
25 import dwt.widgets.Composite; | 23 import dwt.widgets.Composite; |
26 import dwt.widgets.Item; | 24 import dwt.widgets.Item; |
31 import dwt.widgets.TreeColumn; | 29 import dwt.widgets.TreeColumn; |
32 import dwtx.core.runtime.Assert; | 30 import dwtx.core.runtime.Assert; |
33 import dwtx.jface.layout.TableColumnLayout; | 31 import dwtx.jface.layout.TableColumnLayout; |
34 | 32 |
35 import dwt.dwthelper.utils; | 33 import dwt.dwthelper.utils; |
34 import dwtx.dwtxhelper.Collection; | |
36 | 35 |
37 /** | 36 /** |
38 * A layout for a table. Call <code>addColumnData</code> to add columns. | 37 * A layout for a table. Call <code>addColumnData</code> to add columns. |
39 * The TableLayout {@link ColumnLayoutData} is only valid until the table | 38 * The TableLayout {@link ColumnLayoutData} is only valid until the table |
40 * is resized. To keep the proportions constant when the table is resized | 39 * is resized. To keep the proportions constant when the table is resized |
69 | 68 |
70 /** | 69 /** |
71 * The list of column layout data (element type: | 70 * The list of column layout data (element type: |
72 * <code>ColumnLayoutData</code>). | 71 * <code>ColumnLayoutData</code>). |
73 */ | 72 */ |
74 private Seq!(ColumnLayoutData) columns; | 73 private List columns; |
75 | 74 |
76 /** | 75 /** |
77 * Indicates whether <code>layout</code> has yet to be called. | 76 * Indicates whether <code>layout</code> has yet to be called. |
78 */ | 77 */ |
79 private bool firstTime = true; | 78 private bool firstTime = true; |
80 | 79 |
81 /** | 80 /** |
82 * Creates a new table layout. | 81 * Creates a new table layout. |
83 */ | 82 */ |
84 public this() { | 83 public this() { |
85 columns = new ArraySeq!(ColumnLayoutData); | 84 columns = new ArrayList(); |
86 } | 85 } |
87 | 86 |
88 /** | 87 /** |
89 * Adds a new column of data to this table layout. | 88 * Adds a new column of data to this table layout. |
90 * | 89 * |
91 * @param data | 90 * @param data |
92 * the column layout data | 91 * the column layout data |
93 */ | 92 */ |
94 public void addColumnData(ColumnLayoutData data) { | 93 public void addColumnData(ColumnLayoutData data) { |
95 columns.append(data); | 94 columns.add(data); |
96 } | 95 } |
97 | 96 |
98 /* | 97 /* |
99 * (non-Javadoc) Method declared on Layout. | 98 * (non-Javadoc) Method declared on Layout. |
100 */ | 99 */ |
110 Point result = table.computeSize(wHint, hHint, flush); | 109 Point result = table.computeSize(wHint, hHint, flush); |
111 table.setLayout(this); | 110 table.setLayout(this); |
112 | 111 |
113 int width = 0; | 112 int width = 0; |
114 int size = columns.size(); | 113 int size = columns.size(); |
115 foreach( layoutData; columns ){ | 114 for (int i = 0; i < size; ++i) { |
115 ColumnLayoutData layoutData = cast(ColumnLayoutData) columns.get(i); | |
116 if ( auto col = cast(ColumnPixelData) layoutData ) { | 116 if ( auto col = cast(ColumnPixelData) layoutData ) { |
117 width += col.width; | 117 width += col.width; |
118 if (col.addTrim) { | 118 if (col.addTrim) { |
119 width += COLUMN_TRIM; | 119 width += COLUMN_TRIM; |
120 } | 120 } |
161 int numberOfWeightColumns = 0; | 161 int numberOfWeightColumns = 0; |
162 int totalWeight = 0; | 162 int totalWeight = 0; |
163 | 163 |
164 // First calc space occupied by fixed columns | 164 // First calc space occupied by fixed columns |
165 for (int i = 0; i < size; i++) { | 165 for (int i = 0; i < size; i++) { |
166 ColumnLayoutData col = /+cast(ColumnLayoutData)+/ columns.get(i); | 166 ColumnLayoutData col = cast(ColumnLayoutData) columns.get(i); |
167 if ( auto cpd = cast(ColumnPixelData) col ) { | 167 if ( auto cpd = cast(ColumnPixelData) col ) { |
168 int pixels = cpd.width; | 168 int pixels = cpd.width; |
169 if (cpd.addTrim) { | 169 if (cpd.addTrim) { |
170 pixels += COLUMN_TRIM; | 170 pixels += COLUMN_TRIM; |
171 } | 171 } |
188 if (numberOfWeightColumns > 0) { | 188 if (numberOfWeightColumns > 0) { |
189 // Now distribute the rest to the columns with weight. | 189 // Now distribute the rest to the columns with weight. |
190 int rest = width - fixedWidth; | 190 int rest = width - fixedWidth; |
191 int totalDistributed = 0; | 191 int totalDistributed = 0; |
192 for (int i = 0; i < size; ++i) { | 192 for (int i = 0; i < size; ++i) { |
193 ColumnLayoutData col = /+cast(ColumnLayoutData)+/ columns.get(i); | 193 ColumnLayoutData col = cast(ColumnLayoutData) columns.get(i); |
194 if (auto cw = cast(ColumnWeightData) col ) { | 194 if (auto cw = cast(ColumnWeightData) col ) { |
195 // calculate weight as above | 195 // calculate weight as above |
196 // int weight = firstTime ? cw.weight : | 196 // int weight = firstTime ? cw.weight : |
197 // tableColumns[i].getWidth(); | 197 // tableColumns[i].getWidth(); |
198 int weight = cw.weight; | 198 int weight = cw.weight; |
210 int diff = rest - totalDistributed; | 210 int diff = rest - totalDistributed; |
211 for (int i = 0; diff > 0; ++i) { | 211 for (int i = 0; diff > 0; ++i) { |
212 if (i is size) { | 212 if (i is size) { |
213 i = 0; | 213 i = 0; |
214 } | 214 } |
215 ColumnLayoutData col = /+cast(ColumnLayoutData)+/ columns.get(i); | 215 ColumnLayoutData col = cast(ColumnLayoutData) columns.get(i); |
216 if (cast(ColumnWeightData)col ) { | 216 if (cast(ColumnWeightData)col ) { |
217 ++widths[i]; | 217 ++widths[i]; |
218 --diff; | 218 --diff; |
219 } | 219 } |
220 } | 220 } |