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

Unified Diff: samples/total/src/SYLKProducer.dart

Issue 8292003: Total now reads mortgage sample from server (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: samples/total/src/SYLKProducer.dart
diff --git a/client/samples/total/src/SYLKReader.dart b/samples/total/src/SYLKProducer.dart
similarity index 59%
copy from client/samples/total/src/SYLKReader.dart
copy to samples/total/src/SYLKProducer.dart
index 2eb4d62630c2420e0a35176c5f81bf6306bbb7d3..13f25fae9767267757bc7ce1558fadbfc3a4ec12 100644
--- a/client/samples/total/src/SYLKReader.dart
+++ b/samples/total/src/SYLKProducer.dart
@@ -2,106 +2,39 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-class SYLKReader extends Reader {
+class SYLKProducer {
+ const SYLKProducer();
+
+ String listSamples() {
+ return '''[
+"empty",
+"mortgage",
+"insertTest",
+"collatz",
+]''';
+ }
+
+ String makeExample(String id) {
- SYLKReader() : super() { }
+ switch (id) {
+ case 'mortgage':
+ return Strings.join(_makeMortgageExample(), '\n');
- void loadSpreadsheet(Spreadsheet spreadsheet, List<String> sylk) {
- int row, col;
- String contents;
- CellLocation lastLocation;
+ case 'insertTest':
+ return Strings.join(_makeInsertTest(), '\n');
- for (int i = 0; i < sylk.length; i++) {
- List<String> parts = StringUtils.split(sylk[i], StringUtils.SEMICOLON);
- String cmd = parts[0];
- switch (cmd) {
- case "ID":
- break;
- case "B":
- for (int j = 1; j < parts.length; j++) {
- String part = parts[j];
- if (part.startsWith("X")) {
- col = Math.parseInt(part.substring(1, part.length));
- spreadsheet.setColumnCount(col);
- } else if (part.startsWith("Y")) {
- row = Math.parseInt(part.substring(1, part.length));
- spreadsheet.setRowCount(row);
- }
- }
- break;
- case "C":
- row = -1;
- col = -1;
- contents = "";
- for (int j = 1; j < parts.length; j++) {
- String part = parts[j];
- if (part.startsWith("Y")) {
- row = Math.parseInt(part.substring(1, part.length));
- } else if (part.startsWith("X")) {
- col = Math.parseInt(part.substring(1, part.length));
- } if (part.startsWith("K")) {
- contents = StringUtils.stripQuotes(part.substring(1, part.length));
- }
- }
- if (row == -1) {
- throw new RuntimeException("No row (Y) specified in ${sylk[i]}");
- }
- if (col == -1) {
- throw new RuntimeException("No col (X) specified in ${sylk[i]}");
- }
- lastLocation = new CellLocation(spreadsheet, new RowCol(row, col));
- spreadsheet.execute(new SetCellContentsCommand(lastLocation, contents));
- break;
- case "F":
- Cell lastCell = lastLocation.getCell();
- if (lastCell == null) {
- break;
- }
- Style style = lastCell.style;
- for (int j = 1; j < parts.length; j++) {
- String part = parts[j];
- if (part.startsWith("P")) {
- int formatIndex = Math.parseInt(part.substring(1, part.length));
- style = style.setNumericFormatByIndex(formatIndex);
- } else if (part.startsWith("S")) {
- switch (part[1]) {
- case "I"[0]:
- style = style.setTextFormatByIndex(Style.ITALIC);
- break;
- case "D"[0]:
- style = style.setTextFormatByIndex(Style.BOLD);
- break;
- }
- } else if (part.startsWith("F")) {
- // F;...;F<format><decimal_places><alignment>
- // Only handle alignment for now
- switch (part[3]) {
- case "L"[0]:
- style = style.setTextAlignment(Style.LEFT);
- break;
- case "C"[0]:
- style = style.setTextAlignment(Style.CENTER);
- break;
- case "R"[0]:
- style = style.setTextAlignment(Style.RIGHT);
- break;
- }
- }
- }
- spreadsheet.setCellStyle(lastLocation.rowCol, style);
- break;
- }
+ case 'collatz':
+ return Strings.join(_makeCollatzTest(), '\n');
+
+ default:
+ return Strings.join(_makeEmpty(), '\n');
}
}
- List<String> makeExample(String id) {
- if (id == "mortgage") {
- return _makeMortgageExample();
- } else if (id == "insertTest") {
- return _makeInsertTest();
- } else if (id == "collatz") {
- return _makeCollatzTest();
- }
+ List<String> _makeEmpty() {
+ List<String> sylk = new List<String>();
+ sylk.add('ID;P');
+ return sylk;
}
List<String> _makeCollatzTest() {

Powered by Google App Engine
This is Rietveld 408576698