dmolony-DiskBrowser/src/com/bytezone/diskbrowser/infocom/Abbreviations.java

68 lines
1.9 KiB
Java
Raw Normal View History

2015-06-01 09:35:51 +00:00
package com.bytezone.diskbrowser.infocom;
import java.util.ArrayList;
import java.util.List;
2016-02-05 07:18:23 +00:00
class Abbreviations extends InfocomAbstractFile
2015-06-01 09:35:51 +00:00
{
2016-02-05 07:18:23 +00:00
List<ZString> list;
Header header;
int dataPtr;
int dataSize;
int tablePtr;
int tableSize;
2015-06-01 09:35:51 +00:00
2016-02-05 07:18:23 +00:00
public Abbreviations (Header header)
{
super ("Abbreviations", header.buffer);
this.header = header;
2015-06-01 09:35:51 +00:00
2016-02-05 07:18:23 +00:00
dataPtr = header.getWord (header.abbreviationsTable) * 2;
dataSize = header.abbreviationsTable - dataPtr;
tablePtr = header.abbreviationsTable;
2019-04-22 04:35:50 +00:00
tableSize = header.objectTableOffset - header.abbreviationsTable;
2015-06-01 09:35:51 +00:00
2016-02-05 07:18:23 +00:00
// prepare hex dump
hexBlocks.add (new HexBlock (dataPtr, dataSize, "Abbreviations data:"));
hexBlocks.add (new HexBlock (tablePtr, tableSize, "Abbreviations table:"));
}
2015-06-01 09:35:51 +00:00
2016-02-05 07:18:23 +00:00
private void populate ()
{
2020-02-02 10:17:49 +00:00
list = new ArrayList<> ();
2015-06-01 09:35:51 +00:00
2019-04-22 04:35:50 +00:00
for (int i = header.abbreviationsTable; i < header.objectTableOffset; i += 2)
list.add (new ZString (header, header.getWord (i) * 2));
2016-02-05 07:18:23 +00:00
}
2015-06-01 09:35:51 +00:00
2016-02-05 07:18:23 +00:00
public String getAbbreviation (int abbreviationNumber)
{
if (list == null)
populate ();
2019-04-22 04:35:50 +00:00
2016-02-05 07:18:23 +00:00
return list.get (abbreviationNumber).value;
}
2015-06-01 09:35:51 +00:00
2016-02-05 07:18:23 +00:00
@Override
public String getText ()
{
if (list == null)
populate ();
2015-06-01 09:35:51 +00:00
2016-02-05 07:18:23 +00:00
StringBuilder text = new StringBuilder ();
2015-06-01 09:35:51 +00:00
2016-02-05 07:18:23 +00:00
// text.append (String.format ("Data address....%04X %d%n", dataPtr, dataPtr));
// text.append (String.format ("Data size.......%04X %d%n", dataSize, dataSize));
// text.append (String.format ("Table address...%04X %d%n", tablePtr, tablePtr));
// text.append (String.format ("Table size......%04X %d (%d words)%n%n", tableSize, tableSize,
// (tableSize / 2)));
2015-06-01 09:35:51 +00:00
2016-02-05 07:18:23 +00:00
int count = 0;
for (ZString word : list)
text.append (String.format ("%3d %s%n", count++, word.value));
if (list.size () > 0)
text.deleteCharAt (text.length () - 1);
2015-06-01 09:35:51 +00:00
2016-02-05 07:18:23 +00:00
return text.toString ();
}
2015-06-01 09:35:51 +00:00
}