diff --git a/app/src/main/java/xl/model/BombCell.java b/app/src/main/java/xl/model/BombCell.java index 4f1782d..c8dc2b8 100644 --- a/app/src/main/java/xl/model/BombCell.java +++ b/app/src/main/java/xl/model/BombCell.java @@ -19,4 +19,7 @@ public class BombCell implements Cell { throw XLException.ERROR_RECURSIVE; } + public String formula() { + throw XLException.ERROR_RECURSIVE; + } } diff --git a/app/src/main/java/xl/model/Cell.java b/app/src/main/java/xl/model/Cell.java index a65781e..0971c7f 100644 --- a/app/src/main/java/xl/model/Cell.java +++ b/app/src/main/java/xl/model/Cell.java @@ -8,4 +8,5 @@ import xl.expr.Environment; public interface Cell { public double cellValue(Environment e); public String displayValue(); + public String formula(); } diff --git a/app/src/main/java/xl/model/CommentCell.java b/app/src/main/java/xl/model/CommentCell.java index b9a9550..45a98e7 100644 --- a/app/src/main/java/xl/model/CommentCell.java +++ b/app/src/main/java/xl/model/CommentCell.java @@ -16,6 +16,10 @@ public class CommentCell implements Cell { } public String displayValue() { + return "# " + commentText; + } + + public String formula() { return commentText; } } diff --git a/app/src/main/java/xl/model/ExpressionCell.java b/app/src/main/java/xl/model/ExpressionCell.java index b720159..630dc39 100644 --- a/app/src/main/java/xl/model/ExpressionCell.java +++ b/app/src/main/java/xl/model/ExpressionCell.java @@ -18,9 +18,12 @@ public class ExpressionCell implements Cell { } public String displayValue() { + return Double.toString(cellValue(ENVIRON)); + } + + public String formula() { return expr.toString(); } - } diff --git a/app/src/main/java/xl/model/XLModel.java b/app/src/main/java/xl/model/XLModel.java index 072b43e..62c3483 100644 --- a/app/src/main/java/xl/model/XLModel.java +++ b/app/src/main/java/xl/model/XLModel.java @@ -58,7 +58,7 @@ public class XLModel extends Observable implements Environment { status = "Error creating cell"; return; } - + // Tell observers that the model has changed setChanged(); notifyObservers(); @@ -107,25 +107,16 @@ public class XLModel extends Observable implements Environment { public String getAddressValue(String address) { if (map.containsKey(address)) { - Cell cell = map.get(address); - if (cell instanceof CommentCell) { - return cell.displayValue(); - } - return Double.toString(cell.cellValue(this)); + return map.get(address).displayValue(); } return ""; } public String getAddressContent(String address) { if (map.containsKey(address)) { - Cell cell = map.get(address); - if (cell instanceof CommentCell) { - return "#" + map.get(address).displayValue(); - } - return map.get(address).displayValue(); - } else { - return ""; + return map.get(address).formula(); } + return ""; } public boolean containsKey(String address) {