diff --git a/src/com/bytezone/diskbrowser/applefile/VisicalcFile.java b/src/com/bytezone/diskbrowser/applefile/VisicalcFile.java index 03cfcc9..67fd8ae 100644 --- a/src/com/bytezone/diskbrowser/applefile/VisicalcFile.java +++ b/src/com/bytezone/diskbrowser/applefile/VisicalcFile.java @@ -1,10 +1,10 @@ package com.bytezone.diskbrowser.applefile; -import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.visicalc.Sheet; public class VisicalcFile extends AbstractFile { + private static boolean debug; private Sheet sheet; public VisicalcFile (String name, byte[] buffer) @@ -22,17 +22,29 @@ public class VisicalcFile extends AbstractFile text.append ("Visicalc : " + name + "\n"); text.append ("Cells : " + sheet.size () + "\n\n"); - text.append (sheet.getTextDisplay ()); - text.append ("\n\n"); - text.append (sheet.getLines ()); + text.append (sheet.getTextDisplay (debug)); + + if (debug) + { + text.append ("\n\n"); + text.append (sheet.getLines ()); + } return text.toString (); } + public static void setDefaultDebug (boolean value) + { + debug = value; + } + + public void setDebug (boolean value) + { + debug = value; + } + public static boolean isVisicalcFile (byte[] buffer) { - if (false) - System.out.println (HexFormatter.format (buffer)); int firstByte = buffer[0] & 0xFF; if (firstByte != 0xBE && firstByte != 0xAF) return false; diff --git a/src/com/bytezone/diskbrowser/gui/DataPanel.java b/src/com/bytezone/diskbrowser/gui/DataPanel.java index d8b5717..93fe28a 100755 --- a/src/com/bytezone/diskbrowser/gui/DataPanel.java +++ b/src/com/bytezone/diskbrowser/gui/DataPanel.java @@ -13,6 +13,7 @@ import javax.swing.event.ChangeListener; import com.bytezone.common.FontAction.FontChangeEvent; import com.bytezone.common.FontAction.FontChangeListener; import com.bytezone.diskbrowser.applefile.HiResImage; +import com.bytezone.diskbrowser.applefile.VisicalcFile; import com.bytezone.diskbrowser.disk.DiskAddress; import com.bytezone.diskbrowser.disk.SectorList; @@ -75,7 +76,7 @@ class DataPanel extends JTabbedPane imagePane = new JScrollPane (imagePanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); - // imagePane.getVerticalScrollBar ().setUnitIncrement (font.getSize ()); + // imagePane.getVerticalScrollBar ().setUnitIncrement (font.getSize ()); // setTabsFont (font); // this.setMinimumSize (new Dimension (800, 200)); @@ -126,6 +127,7 @@ class DataPanel extends JTabbedPane mh.lineWrapItem.setAction (new LineWrapAction (formattedText)); mh.colourQuirksItem.setAction (new ColourQuirksAction (this)); mh.monochromeItem.setAction (new MonochromeAction (this)); + mh.debuggingItem.setAction (new DebuggingAction (this)); } public void setColourQuirks (boolean value) @@ -148,6 +150,16 @@ class DataPanel extends JTabbedPane } } + public void setDebug (boolean value) + { + if (currentDataSource instanceof VisicalcFile) + { + VisicalcFile visicalcFile = (VisicalcFile) currentDataSource; + visicalcFile.setDebug (value); + setText (formattedText, visicalcFile.getText ()); + } + } + private void setTabsFont (Font font) { formattedText.setFont (font); diff --git a/src/com/bytezone/diskbrowser/gui/DebuggingAction.java b/src/com/bytezone/diskbrowser/gui/DebuggingAction.java new file mode 100644 index 0000000..e1d43f9 --- /dev/null +++ b/src/com/bytezone/diskbrowser/gui/DebuggingAction.java @@ -0,0 +1,29 @@ +package com.bytezone.diskbrowser.gui; + +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.JMenuItem; +import javax.swing.KeyStroke; + +public class DebuggingAction extends AbstractAction +{ + private final DataPanel owner; + + public DebuggingAction (DataPanel owner) + { + super ("Debugging"); + putValue (Action.SHORT_DESCRIPTION, "Show debugging information"); + putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt G")); + putValue (Action.MNEMONIC_KEY, KeyEvent.VK_G); + this.owner = owner; + } + + @Override + public void actionPerformed (ActionEvent e) + { + owner.setDebug (((JMenuItem) e.getSource ()).isSelected ()); + } +} \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/gui/MenuHandler.java b/src/com/bytezone/diskbrowser/gui/MenuHandler.java index 5c86cc3..d179ce8 100755 --- a/src/com/bytezone/diskbrowser/gui/MenuHandler.java +++ b/src/com/bytezone/diskbrowser/gui/MenuHandler.java @@ -13,6 +13,7 @@ import com.bytezone.common.OSXAdapter; import com.bytezone.common.Platform; import com.bytezone.common.QuitAction.QuitListener; import com.bytezone.diskbrowser.applefile.HiResImage; +import com.bytezone.diskbrowser.applefile.VisicalcFile; import com.bytezone.diskbrowser.disk.DataDisk; import com.bytezone.diskbrowser.disk.FormattedDisk; @@ -25,6 +26,7 @@ public class MenuHandler private static final String PREFS_SHOW_FREE_SECTORS = "show free sectors"; private static final String PREFS_COLOUR_QUIRKS = "colour quirks"; private static final String PREFS_MONOCHROME = "monochrome"; + private static final String PREFS_DEBUGGING = "debugging"; FormattedDisk currentDisk; @@ -61,6 +63,7 @@ public class MenuHandler JMenuItem colourQuirksItem = new JCheckBoxMenuItem ("Colour quirks"); JMenuItem monochromeItem = new JCheckBoxMenuItem ("Monochrome"); + JMenuItem debuggingItem = new JCheckBoxMenuItem ("Debugging"); public MenuHandler (Preferences prefs) { @@ -118,6 +121,7 @@ public class MenuHandler formatMenu.add (colourQuirksItem); formatMenu.add (monochromeItem); + formatMenu.add (debuggingItem); helpMenu.add (new JMenuItem (new EnvironmentAction ())); @@ -137,9 +141,6 @@ public class MenuHandler interleaveGroup.add (interleave3Item); dbItem.setEnabled (false); - - HiResImage.setDefaultColourQuirks (colourQuirksItem.isSelected ()); - HiResImage.setDefaultMonochrome (monochromeItem.isSelected ()); } void addHelpMenuAction (Action action, String functionName) @@ -195,6 +196,7 @@ public class MenuHandler prefs.putBoolean (PREFS_SHOW_FREE_SECTORS, showFreeSectorsItem.isSelected ()); prefs.putBoolean (PREFS_COLOUR_QUIRKS, colourQuirksItem.isSelected ()); prefs.putBoolean (PREFS_MONOCHROME, monochromeItem.isSelected ()); + prefs.putBoolean (PREFS_DEBUGGING, debuggingItem.isSelected ()); } @Override @@ -206,6 +208,11 @@ public class MenuHandler showFreeSectorsItem.setSelected (prefs.getBoolean (PREFS_SHOW_FREE_SECTORS, false)); colourQuirksItem.setSelected (prefs.getBoolean (PREFS_COLOUR_QUIRKS, false)); monochromeItem.setSelected (prefs.getBoolean (PREFS_MONOCHROME, false)); + debuggingItem.setSelected (prefs.getBoolean (PREFS_DEBUGGING, false)); + + HiResImage.setDefaultColourQuirks (colourQuirksItem.isSelected ()); + HiResImage.setDefaultMonochrome (monochromeItem.isSelected ()); + VisicalcFile.setDefaultDebug (debuggingItem.isSelected ()); } @Override diff --git a/src/com/bytezone/diskbrowser/visicalc/Cell.java b/src/com/bytezone/diskbrowser/visicalc/Cell.java index 0d294ea..7ad63f4 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Cell.java +++ b/src/com/bytezone/diskbrowser/visicalc/Cell.java @@ -128,7 +128,10 @@ class Cell implements Comparable, Value else if (format == '$') { String currencyFormat = String.format ("%%%d.%ds", colWidth, colWidth); - return String.format (currencyFormat, nf.format (getValue ())); + Double value = getValue (); + if (Double.isNaN (value)) + return justify ("", colWidth); + return String.format (currencyFormat, nf.format (value)); } else if (format == '*') { @@ -150,6 +153,8 @@ class Cell implements Comparable, Value return val; } } + // else + // return justify ("", colWidth); } return getError (); } diff --git a/src/com/bytezone/diskbrowser/visicalc/Sheet.java b/src/com/bytezone/diskbrowser/visicalc/Sheet.java index e1d9a97..0ba71e4 100644 --- a/src/com/bytezone/diskbrowser/visicalc/Sheet.java +++ b/src/com/bytezone/diskbrowser/visicalc/Sheet.java @@ -329,7 +329,7 @@ public class Sheet implements Iterable return text.toString (); } - public String getTextDisplay () + public String getTextDisplay (boolean debug) { StringBuilder text = new StringBuilder (); String longLine; @@ -363,7 +363,9 @@ public class Sheet implements Iterable else heading.append (String.format (fmt, underline)); } - text.append (heading); + + if (debug) + text.append (heading); for (Cell cell : sheet.values ()) { @@ -371,7 +373,10 @@ public class Sheet implements Iterable { ++lastRow; lastColumn = 0; - text.append (String.format ("%n%03d:", lastRow + 1)); + if (debug) + text.append (String.format ("%n%03d:", lastRow + 1)); + else + text.append ("\n"); } while (lastColumn < cell.address.column)