From f4560ec13084afd3bbcae1962dfba7bc7453b6d6 Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Tue, 15 Mar 2016 07:54:47 +1100 Subject: [PATCH] global format --- .../bytezone/diskbrowser/visicalc/Cell.java | 9 ++++++--- src/com/bytezone/diskbrowser/visicalc/Pi.java | 15 +++++++++++++++ .../bytezone/diskbrowser/visicalc/Sheet.java | 19 ++++++++++++++++--- 3 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 src/com/bytezone/diskbrowser/visicalc/Pi.java diff --git a/src/com/bytezone/diskbrowser/visicalc/Cell.java b/src/com/bytezone/diskbrowser/visicalc/Cell.java index dd0cbc1..0d294ea 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Cell.java +++ b/src/com/bytezone/diskbrowser/visicalc/Cell.java @@ -9,7 +9,7 @@ class Cell implements Comparable, Value final Address address; private final Sheet parent; private CellType type; - private char format = ' '; + private char cellFormat = ' '; private char repeatingChar; private String repeat = ""; @@ -41,7 +41,7 @@ class Cell implements Comparable, Value // /F* - graph (histogram) if (format.startsWith ("/F")) - this.format = format.charAt (2); + this.cellFormat = format.charAt (2); else if (format.startsWith ("/-")) { repeatingChar = format.charAt (2); @@ -118,6 +118,8 @@ class Cell implements Comparable, Value case VALUE: if (hasValue ()) + { + char format = cellFormat != ' ' ? cellFormat : defaultFormat; if (format == 'I') { String integerFormat = String.format ("%%%d.0f", colWidth); @@ -147,13 +149,14 @@ class Cell implements Comparable, Value val = val.substring (val.length () - colWidth); return val; } + } } return getError (); } private String justify (String text, int colWidth) { - if (format == 'R') + if (cellFormat == 'R') { String labelFormat = String.format ("%%%d.%ds", colWidth, colWidth); return (String.format (labelFormat, text)); diff --git a/src/com/bytezone/diskbrowser/visicalc/Pi.java b/src/com/bytezone/diskbrowser/visicalc/Pi.java new file mode 100644 index 0000000..a81bff3 --- /dev/null +++ b/src/com/bytezone/diskbrowser/visicalc/Pi.java @@ -0,0 +1,15 @@ +package com.bytezone.diskbrowser.visicalc; + +class Pi extends Function +{ + Pi (Sheet parent, String text) + { + super (parent, text); + } + + @Override + public double getValue () + { + return 3.14159265; + } +} diff --git a/src/com/bytezone/diskbrowser/visicalc/Sheet.java b/src/com/bytezone/diskbrowser/visicalc/Sheet.java index 20e337c..e1d9a97 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Sheet.java +++ b/src/com/bytezone/diskbrowser/visicalc/Sheet.java @@ -200,6 +200,12 @@ public class Sheet implements Iterable case 'C': columnWidth = Integer.parseInt (line.substring (3)); break; + case 'F': + defaultFormat = line.charAt (3); + break; + default: + System.out.printf ("Unknown global format [%s]%n", line); + break; } break; case 'X': @@ -249,7 +255,7 @@ public class Sheet implements Iterable assert currentCell != null; - if (line.startsWith ("/G")) // global column widths + if (line.startsWith ("/G")) // global column widths { if (line.charAt (2) == 'C' && line.charAt (3) == 'C') { @@ -267,13 +273,20 @@ public class Sheet implements Iterable while (line.startsWith ("/")) { String fmt = line.substring (0, 3); - currentCell.format (fmt); // formatting command + + if (fmt.equals ("/TH") || fmt.equals ("/TV")) // lock titles ?? + { + // ignore + } + else + currentCell.format (fmt); // formatting command + line = line.substring (3); format += fmt; } if (!line.isEmpty ()) - currentCell.setValue (line); // expression + currentCell.setValue (line); // expression if (false) System.out.printf ("[%s][%-3s][%s]%n", currentCell.address, format, line);