Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: samples/total/client/Cell.dart

Issue 10635015: Delete proxy and total samples, which have bit-rotted. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « samples/total/client/CSVReader.dart ('k') | samples/total/client/CellContents.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 /**
6 * A Cell holds all the information for a single spreadsheet cell location.
7 *
8 * A cell has contents and style, and tracks cells that depend on this cell (dep endents).
9 */
10 class Cell {
11 CellContent _content;
12 Set<CellLocation> _dependents;
13 bool _isStyleDirty;
14 Style _style;
15
16 CellContent get content() => _content;
17
18 /**
19 * Return the Set of (row, col) references to the cells that depend on this ce ll directly.
20 *
21 * 'null' indicates the empty set.
22 */
23 Set<CellLocation> get dependents() => _dependents;
24
25 Style get style() => _style;
26
27 Cell() {
28 _style = new Style();
29 }
30
31 Cell.content(CellContent this._content) {
32 // Default style
33 _style = new Style();
34 }
35
36 Cell.contentAndStyle(CellContent this._content, Style this._style) {
37 if (_style == null) {
38 throw new RuntimeException("style == null");
39 }
40 }
41
42 Cell.style(Style this._style) {
43 if (_style == null) {
44 throw new RuntimeException("style == null");
45 }
46 _isStyleDirty = true;
47 // Leave content null
48 }
49
50 bool operator==(Cell o) {
51 if (o is !Cell) {
52 return false;
53 }
54 Cell other = o;
55 return _content == other._content && _style == other._style;
56 }
57
58 /**
59 * Add a single dependent.
60 */
61 void addDependent(CellLocation location) {
62 if (_dependents == null) {
63 _dependents = new Set<CellLocation>();
64 }
65 _dependents.add(location);
66 }
67
68 /**
69 * Add a set of dependents (cells that rely on this cell for values).
70 */
71 void addDependents(Set<CellLocation> locations) {
72 if (locations == null || locations.isEmpty()) {
73 return;
74 }
75 if (_dependents == null) {
76 _dependents = new Set<CellLocation>();
77 }
78 _dependents.addAll(locations);
79 }
80
81 /**
82 * Return true if the cell's value should be refreshed on every spreadsheet re calculation.
83 */
84 bool alwaysRecalculate() => _content == null ? false : _content.alwaysRecalcul ate();
85
86 /**
87 * Clear the set of dependents.
88 */
89 void clearDependents() {
90 _dependents = null;
91 }
92
93 /**
94 * Clear the dirty style flag.
95 *
96 * Call this when you have used the style information to update the display an d will not need
97 * to update it again until the style for the cell changes.
98 */
99 void clearStyleDirty() {
100 _isStyleDirty = false;
101 }
102
103 // Return the content as a string
104 String getContentString() => _content == null ? "" : _content.getContent();
105
106 /**
107 * Return the datatype of this cell, one of [Value.TYPE_BOOLEAN], [Value.TYPE_ DOUBLE],
108 * [Value.TYPE_DATE_TIME], [Value.TYPE_DOUBLE], [Value.TYPE_STRING], or [Value .TYPE_TIME],
109 * or [Value.TYPE_UNKNOWN] if unknown.
110 */
111 int getDatatype() => _content == null ? Value.TYPE_UNKNOWN : _content.getDatat ype();
112
113 /**
114 * Return a displayable version of the datatype associated with this cell.
115 */
116 String getDatatypeAsString() => Value.getDatatypeAsString(getDatatype());
117
118 /**
119 * Return the Set of (row, col) references to the cells on which this cell dep ends directly.
120 *
121 * 'null' indicates the empty set.
122 */
123 Set<CellLocation> getDependencies() => _content == null ? null : _content.getD ependencies();
124
125 double getDoubleValue() => getValue().asDouble(null);
126
127 // Return the cell contents in 'RC' form, suitable for pasting into another ce ll.
128 String getPasteContent() => _content == null ? "" : _content.getPasteContent() ;
129
130 String getStringValue() => getValue().asString(null);
131
132 /**
133 * Return a displayable HTML version of the Style associated with this cell.
134 */
135 String getStyleAsHtml() => _style.toHtml();
136
137 /**
138 * Return what the user typed to produce the cell.
139 */
140 String getUserContent() => _content == null ? "" : _content.getContent();
141
142 /**
143 * Return the computed value of this cell, or throw a ValueException if there is
144 * no way to compute a value.
145 */
146 Value getValue() {
147 if (_content == null) {
148 throw new ValueException();
149 }
150 CellContent cc = _content;
151 return cc.getValue();
152 }
153
154 /**
155 * Invalidate this cell's reference to a range of cells that will be removed.
156 *
157 * See [CellContents].
158 *
159 * Return the old content if the content has changed; otherwise null.
160 */
161 CellContent invalidateReferences(CellLocation thisLocation, CellRange range, R owCol shiftOffset) {
162 if (_content == null) {
163 return null;
164 }
165
166 CellContent originalContent = _content;
167 CellContent newContent = _content.invalidateReferences(thisLocation, range, shiftOffset);
168 if (newContent != null) {
169 _content = newContent;
170 return originalContent;
171 }
172
173 return null;
174 }
175
176 /**
177 * Return true if this cell requires recomputation.
178 */
179 bool isDirty() => _isStyleDirty || (_content == null ? false : _content.isDirt y());
180
181 /**
182 * A cell with [:null:] content is considered empty for the purposes of the "C OUNTA" function.
183 */
184 bool isEmpty() => _content == null;
185
186 /**
187 * Return true if this cell contains a formula.
188 */
189 bool isFormula() => _content == null ? false : _content.isFormula();
190
191 /**
192 * Return true if this cell contains a numeric value.
193 */
194 bool isNumeric() => _content == null ? false : _content.isNumeric();
195
196 /**
197 * Return true if this cell contains a String value.
198 */
199 bool isString() => _content == null ? false : _content.isString();
200
201 /**
202 * Return true if the Style associated with this cell is the default style.
203 */
204 bool isStyleDefault() => _style.isDefault();
205
206 /**
207 * Update formula dependencies for an insertion.
208 *
209 * See [CellContents].
210 *
211 * Return the old content if the content has changed; otherwise null.
212 */
213 CellContent modifyDependenciesForShift(CellRange range, RowCol offset) {
214 if (_content == null) {
215 return null;
216 }
217
218 CellContent originalContent = _content;
219 CellContent newContent = _content.modifyDependenciesForShift(range, offset);
220 if (newContent != null) {
221 _content = newContent;
222 return originalContent;
223 }
224
225 return null;
226 }
227
228 /**
229 * Remove a single dependent.
230 */
231 void removeDependent(CellLocation location) {
232 if (_dependents == null) {
233 return;
234 }
235 _dependents.remove(location);
236 if (_dependents.isEmpty()) {
237 _dependents = null;
238 }
239 }
240
241 /**
242 * Set the content associated with this cell.
243 *
244 * Returns the former content associated with the cell.
245 */
246 CellContent setContent(CellContent newContent) {
247 CellContent originalContent = _content;
248 _content = newContent;
249 return originalContent;
250 }
251
252 /**
253 * Mark this cell as dirty for the purposes of spreadsheet recalculation.
254 *
255 * For cells that don't perform computation, this has no effect.
256 */
257 void setContentDirty() {
258 if (_content != null) {
259 _content.setDirty();
260 }
261 }
262
263 /**
264 * Set the style associated with this cell.
265 *
266 * Returns the former style associated with the cell.
267 */
268 Style setStyle(Style newStyle) {
269 Style originalStyle = _style;
270 if (newStyle == null) {
271 _style = new Style();
272 } else {
273 _style = newStyle;
274 }
275 _isStyleDirty = true;
276 return originalStyle;
277 }
278
279 /**
280 * Return a formatted HTML version of the content of this cell.
281 */
282 String toHtml() => _content == null ? "" : _content.toHtml(_style);
283 }
OLDNEW
« no previous file with comments | « samples/total/client/CSVReader.dart ('k') | samples/total/client/CellContents.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698