debug option

This commit is contained in:
Denis Molony 2016-03-15 09:35:22 +11:00
parent f4560ec130
commit 58d1804a97
6 changed files with 84 additions and 14 deletions

View File

@ -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 (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;

View File

@ -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;
@ -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);

View File

@ -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 ());
}
}

View File

@ -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

View File

@ -128,7 +128,10 @@ class Cell implements Comparable<Cell>, 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<Cell>, Value
return val;
}
}
// else
// return justify ("", colWidth);
}
return getError ();
}

View File

@ -329,7 +329,7 @@ public class Sheet implements Iterable<Cell>
return text.toString ();
}
public String getTextDisplay ()
public String getTextDisplay (boolean debug)
{
StringBuilder text = new StringBuilder ();
String longLine;
@ -363,6 +363,8 @@ public class Sheet implements Iterable<Cell>
else
heading.append (String.format (fmt, underline));
}
if (debug)
text.append (heading);
for (Cell cell : sheet.values ())
@ -371,7 +373,10 @@ public class Sheet implements Iterable<Cell>
{
++lastRow;
lastColumn = 0;
if (debug)
text.append (String.format ("%n%03d:", lastRow + 1));
else
text.append ("\n");
}
while (lastColumn < cell.address.column)