Compare commits
	
		
			2 commits
		
	
	
		
			465700e196
			...
			d130907159
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | d130907159 | ||
|   | 6475fa67a0 | 
					 6 changed files with 26 additions and 26 deletions
				
			
		|  | @ -15,8 +15,11 @@ public class BombCell implements Cell { | ||||||
|         throw XLException.ERROR_RECURSIVE; |         throw XLException.ERROR_RECURSIVE; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public String displayValue() { |     public String displayValue(Environment e) { | ||||||
|         throw XLException.ERROR_RECURSIVE; |         throw XLException.ERROR_RECURSIVE; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  |     public String formula() { | ||||||
|  |         throw XLException.ERROR_RECURSIVE; | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -7,5 +7,6 @@ import xl.expr.Environment; | ||||||
|  */ |  */ | ||||||
| public interface Cell { | public interface Cell { | ||||||
|     public double cellValue(Environment e); |     public double cellValue(Environment e); | ||||||
|     public String displayValue(); |     public String displayValue(Environment e); | ||||||
|  |     public String formula(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -15,7 +15,11 @@ public class CommentCell implements Cell { | ||||||
|         return 0; |         return 0; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public String displayValue() { |     public String displayValue(Environment e) { | ||||||
|  |         return "# " + commentText; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public String formula() { | ||||||
|         return commentText; |         return commentText; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -17,10 +17,13 @@ public class ExpressionCell implements Cell { | ||||||
|         return expr.value(env); |         return expr.value(env); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public String displayValue() { |     public String displayValue(Environment e) { | ||||||
|  |         return Double.toString(cellValue(e)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public String formula() { | ||||||
|         return expr.toString(); |         return expr.toString(); | ||||||
|     } |     } | ||||||
|      |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -58,7 +58,7 @@ public class XLModel extends Observable implements Environment { | ||||||
|             status = "Error creating cell"; |             status = "Error creating cell"; | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|          | 
 | ||||||
|         // Tell observers that the model has changed |         // Tell observers that the model has changed | ||||||
|         setChanged(); |         setChanged(); | ||||||
|         notifyObservers(); |         notifyObservers(); | ||||||
|  | @ -99,7 +99,7 @@ public class XLModel extends Observable implements Environment { | ||||||
| 
 | 
 | ||||||
|     public void save(String path) { |     public void save(String path) { | ||||||
|         try (XLPrintStream xlPrintStream = new XLPrintStream(path)) { |         try (XLPrintStream xlPrintStream = new XLPrintStream(path)) { | ||||||
|             xlPrintStream.save(map.entrySet()); |             xlPrintStream.save(this, map.entrySet()); | ||||||
|         } catch (IOException e) { |         } catch (IOException e) { | ||||||
|             status = "Error saving file"; |             status = "Error saving file"; | ||||||
|         } |         } | ||||||
|  | @ -107,25 +107,16 @@ public class XLModel extends Observable implements Environment { | ||||||
| 
 | 
 | ||||||
|     public String getAddressValue(String address) { |     public String getAddressValue(String address) { | ||||||
|         if (map.containsKey(address)) { |         if (map.containsKey(address)) { | ||||||
|             Cell cell = map.get(address); |             return map.get(address).displayValue(this); | ||||||
|             if (cell instanceof CommentCell) { |  | ||||||
|                 return cell.displayValue(); |  | ||||||
|             } |  | ||||||
|             return Double.toString(cell.cellValue(this)); |  | ||||||
|         } |         } | ||||||
|         return ""; |         return ""; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public String getAddressContent(String address) { |     public String getAddressContent(String address) { | ||||||
|         if (map.containsKey(address)) { |         if (map.containsKey(address)) { | ||||||
|             Cell cell = map.get(address); |             return map.get(address).formula(); | ||||||
|             if (cell instanceof CommentCell) { |  | ||||||
|                 return "#" + map.get(address).displayValue(); |  | ||||||
|             } |  | ||||||
|             return map.get(address).displayValue(); |  | ||||||
|         } else { |  | ||||||
|             return ""; |  | ||||||
|         } |         } | ||||||
|  |         return ""; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public boolean containsKey(String address) { |     public boolean containsKey(String address) { | ||||||
|  |  | ||||||
|  | @ -3,6 +3,9 @@ package xl.model; | ||||||
| import java.io.FileNotFoundException; | import java.io.FileNotFoundException; | ||||||
| import java.io.PrintStream; | import java.io.PrintStream; | ||||||
| import java.util.Map.Entry; | import java.util.Map.Entry; | ||||||
|  | 
 | ||||||
|  | import xl.expr.Environment; | ||||||
|  | 
 | ||||||
| import java.util.Set; | import java.util.Set; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  | @ -14,16 +17,11 @@ public class XLPrintStream extends PrintStream { | ||||||
|         super(fileName); |         super(fileName); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public void save(Set<Entry<String, Cell>> set) { |     public void save(Environment e, Set<Entry<String, Cell>> set) { | ||||||
|         for (Entry<String, Cell> entry : set) { |         for (Entry<String, Cell> entry : set) { | ||||||
|             print(entry.getKey()); |             print(entry.getKey()); | ||||||
|             print('='); |             print('='); | ||||||
|             Cell cell = entry.getValue(); |             println(entry.getValue().displayValue(e)); | ||||||
|             if (cell instanceof CommentCell) { |  | ||||||
|                 println("#" + cell.displayValue()); |  | ||||||
|             } else { |  | ||||||
|                 println(cell.displayValue()); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|         flush(); |         flush(); | ||||||
|         close(); |         close(); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue