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

105 lines
3.4 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;
import javax.swing.tree.DefaultMutableTreeNode;
import com.bytezone.diskbrowser.applefile.AbstractFile;
import com.bytezone.diskbrowser.disk.DefaultAppleFileSource;
import com.bytezone.diskbrowser.disk.FormattedDisk;
2020-02-09 13:02:48 +00:00
// -----------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
class PropertyManager extends AbstractFile
2020-02-09 13:02:48 +00:00
// -----------------------------------------------------------------------------------//
2015-06-01 09:35:51 +00:00
{
2020-02-02 10:17:49 +00:00
List<Statistic> list = new ArrayList<> ();
2016-03-23 23:37:59 +00:00
Header header;
2015-06-01 09:35:51 +00:00
2020-02-09 13:02:48 +00:00
// ---------------------------------------------------------------------------------//
PropertyManager (String name, byte[] buffer, Header header)
// ---------------------------------------------------------------------------------//
2016-03-23 23:37:59 +00:00
{
super (name, buffer);
this.header = header;
2015-06-01 09:35:51 +00:00
2016-03-23 23:37:59 +00:00
for (int propertyNo = 1; propertyNo <= 31; propertyNo++)
{
Statistic statistic = new Statistic (propertyNo);
list.add (statistic);
}
}
2015-06-01 09:35:51 +00:00
2020-02-09 13:02:48 +00:00
// ---------------------------------------------------------------------------------//
2016-03-23 23:37:59 +00:00
public void addNodes (DefaultMutableTreeNode node, FormattedDisk disk)
2020-02-09 13:02:48 +00:00
// ---------------------------------------------------------------------------------//
2016-03-23 23:37:59 +00:00
{
node.setAllowsChildren (true);
2015-06-01 09:35:51 +00:00
2016-03-23 23:37:59 +00:00
for (Statistic stat : list)
if (stat.list.size () > 0)
{
2019-04-22 04:35:50 +00:00
String title = "Property " + header.getPropertyName (stat.id).trim ();
2016-03-23 23:37:59 +00:00
DefaultMutableTreeNode child = new DefaultMutableTreeNode (
new DefaultAppleFileSource (title, stat.getText (), disk));
node.add (child);
child.setAllowsChildren (false);
}
}
2015-06-01 09:35:51 +00:00
2020-02-09 13:02:48 +00:00
// ---------------------------------------------------------------------------------//
2016-03-23 23:37:59 +00:00
@Override
public String getText ()
2020-02-09 13:02:48 +00:00
// ---------------------------------------------------------------------------------//
2016-03-23 23:37:59 +00:00
{
StringBuilder text = new StringBuilder ("Property Type Frequency\n");
text.append ("-------- ----- ---------\n");
2015-06-01 09:35:51 +00:00
2016-03-23 23:37:59 +00:00
for (Statistic stat : list)
text.append (String.format ("%s%n", stat));
if (text.length () > 0)
text.deleteCharAt (text.length () - 1);
return text.toString ();
}
2015-06-01 09:35:51 +00:00
2020-02-09 13:02:48 +00:00
// ---------------------------------------------------------------------------------//
2016-03-23 23:37:59 +00:00
private class Statistic
2020-02-09 13:02:48 +00:00
// ---------------------------------------------------------------------------------//
2016-03-23 23:37:59 +00:00
{
int id;
2020-02-02 10:17:49 +00:00
List<ZObject> list = new ArrayList<> ();
2015-06-01 09:35:51 +00:00
2016-03-23 23:37:59 +00:00
public Statistic (int id)
{
this.id = id;
for (ZObject o : header.objectManager)
{
ZObject.Property p = o.getProperty (id);
if (p != null)
list.add (o);
}
}
2015-06-01 09:35:51 +00:00
2016-03-23 23:37:59 +00:00
String getText ()
{
2019-04-22 04:35:50 +00:00
StringBuilder text = new StringBuilder (String
.format ("Objects with property %d %s set:%n%n", id, header.propertyNames[id]));
2016-03-23 23:37:59 +00:00
for (ZObject o : list)
{
ZObject.Property p = o.getProperty (id);
2019-04-22 04:35:50 +00:00
text.append (String.format ("%02X %-29s%s%n", o.getId (), o.getName (),
p.toString ().substring (11)));
2016-03-23 23:37:59 +00:00
}
if (text.length () > 0)
text.deleteCharAt (text.length () - 1);
return text.toString ();
}
2015-06-01 09:35:51 +00:00
2016-03-23 23:37:59 +00:00
@Override
public String toString ()
{
2019-04-22 04:35:50 +00:00
return String.format (" %2d %-6s %3d", id, header.getPropertyName (id),
2019-04-19 21:15:12 +00:00
list.size ());
2016-03-23 23:37:59 +00:00
}
}
2015-06-01 09:35:51 +00:00
}