OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #library("Total"); | 5 #library("Total"); |
6 #import("dart:html"); | 6 #import("dart:html"); |
7 #import("TotalLib.dart"); | 7 #import("TotalLib.dart"); |
8 | 8 |
9 class Total { | 9 class Total { |
10 static final int DEFAULT_VISIBLE_COLUMNS = 10; | 10 static final int DEFAULT_VISIBLE_COLUMNS = 10; |
11 static final int DEFAULT_VISIBLE_ROWS = 25; | 11 static final int DEFAULT_VISIBLE_ROWS = 25; |
12 | 12 |
13 Spreadsheet _spreadsheet; | 13 Spreadsheet _spreadsheet; |
14 SpreadsheetPresenter _presenter; | 14 SpreadsheetPresenter _presenter; |
15 | 15 |
16 Total() { | 16 Total() { |
17 Element recalcButton = document.query("#recalcButton"); | 17 Element recalcButton = document.query("#recalcButton"); |
18 recalcButton.innerHTML = "Recalculate"; | 18 recalcButton.innerHTML = "Recalculate"; |
19 recalcButton.on.click.add((Event e) { | 19 recalcButton.on.click.add((Event e) { |
20 _presenter.recalculateAll(); | 20 _presenter.recalculateAll(); |
21 }); | 21 }); |
22 } | 22 } |
23 | 23 |
24 void run() { | 24 void run() { |
25 _spreadsheet = new Spreadsheet(); | 25 _spreadsheet = new Spreadsheet(); |
26 Reader reader = new SYLKReader(); | 26 SYLKReader reader = new SYLKReader(); |
27 List<String> data = reader.makeExample("mortgage"); | 27 reader.request("mortgage", (String data) { |
28 reader.loadSpreadsheet(_spreadsheet, data); | 28 List<String> sylk = data.split('\n'); |
29 _presenter = new SpreadsheetPresenter(_spreadsheet, window, | 29 reader.loadSpreadsheet(_spreadsheet, sylk); |
30 0, 0, DEFAULT_VISIBLE_ROWS, DEFAULT_VISIBLE_COLUMNS); | 30 _presenter = new SpreadsheetPresenter(_spreadsheet, window, |
31 _spreadsheet.setListener(_presenter); | 31 0, 0, DEFAULT_VISIBLE_ROWS, DEFAULT_VISIBLE_COLUMNS); |
32 _presenter.recalculateViewport(); | 32 _spreadsheet.setListener(_presenter); |
| 33 _presenter.recalculateViewport(); |
| 34 }); |
33 } | 35 } |
34 } | 36 } |
35 | 37 |
36 void main() { | 38 void main() { |
37 // Instantiate the app | 39 // Instantiate the app |
38 new Total().run(); | 40 new Total().run(); |
39 | 41 |
40 document.on.keyDown.add((KeyboardEvent event) { | 42 document.on.keyDown.add((KeyboardEvent event) { |
41 // TODO: Browsers need to fix the keyCode/keyIdentifier situation. | 43 // TODO: Browsers need to fix the keyCode/keyIdentifier situation. |
42 if (event.ctrlKey && event.keyCode == 68 /* d */) { | 44 if (event.ctrlKey && event.keyCode == 68 /* d */) { |
43 Element db = document.query('#debugbar'); | 45 Element db = document.query('#debugbar'); |
44 if (db.classes.contains('on')) { | 46 if (db.classes.contains('on')) { |
45 db.classes.remove('on'); | 47 db.classes.remove('on'); |
46 } else { | 48 } else { |
47 db.classes.add('on'); | 49 db.classes.add('on'); |
48 } | 50 } |
49 } | 51 } |
50 }, false); | 52 }, false); |
51 } | 53 } |
OLD | NEW |