Adding ability to view shape table files.

This commit is contained in:
Rob Greene 2022-03-08 21:44:15 -06:00
parent 13be406278
commit 92147b03ac
8 changed files with 113 additions and 8 deletions

View File

@ -17,6 +17,7 @@ repositories {
dependencies { dependencies {
implementation "net.sf.applecommander:ShrinkItArchive:$shkVersion" implementation "net.sf.applecommander:ShrinkItArchive:$shkVersion"
implementation "net.sf.applecommander:acdasm:$acdasmVersion" implementation "net.sf.applecommander:acdasm:$acdasmVersion"
implementation "net.sf.applecommander:bastools-api:$btVersion"
implementation "org.apache.commons:commons-csv:$commonsCsvVersion" implementation "org.apache.commons:commons-csv:$commonsCsvVersion"
implementation "com.google.code.gson:gson:$gsonVersion" implementation "com.google.code.gson:gson:$gsonVersion"

View File

@ -0,0 +1,42 @@
package com.webcodepro.applecommander.storage.filters;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import com.webcodepro.applecommander.storage.FileEntry;
import com.webcodepro.applecommander.storage.FileFilter;
import io.github.applecommander.bastools.api.shapes.ShapeExporter;
import io.github.applecommander.bastools.api.shapes.ShapeTable;
public class ShapeTableFileFilter implements FileFilter {
@Override
public byte[] filter(FileEntry fileEntry) {
try {
ShapeTable shapeTable = ShapeTable.read(fileEntry.getFileData());
ShapeExporter exporter = ShapeExporter.image()
.border(true)
.maxWidth(512)
.png()
.skipEmptyShapes(false)
.build();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
exporter.export(shapeTable, outputStream);
return outputStream.toByteArray();
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
@Override
public String getSuggestedFileName(FileEntry fileEntry) {
String fileName = fileEntry.getFilename().trim();
if (!fileName.toLowerCase().endsWith(".png")) {
fileName += ".png";
}
return fileName;
}
}

View File

@ -353,6 +353,8 @@ FileViewerWindow.CopyTooltip=Copies selection to the clipboard (CTRL+C)
FileViewerWindow.PrintTooltip=Print contents... (CTRL+P) FileViewerWindow.PrintTooltip=Print contents... (CTRL+P)
FileViewerWindow.DisassemblyButton=Disassembly FileViewerWindow.DisassemblyButton=Disassembly
FileViewerWindow.DisassemblyTooltip=Displays file disassembled FileViewerWindow.DisassemblyTooltip=Displays file disassembled
FileViewerWindow.ShapeTableButton=Shape Table
FileViewerWindow.ShapeTableTooltip=Display as shape table
# DiskWindow # DiskWindow

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 B

View File

@ -51,10 +51,11 @@ import com.webcodepro.applecommander.storage.filters.AssemblySourceFileFilter;
import com.webcodepro.applecommander.storage.filters.BusinessBASICFileFilter; import com.webcodepro.applecommander.storage.filters.BusinessBASICFileFilter;
import com.webcodepro.applecommander.storage.filters.DisassemblyFileFilter; import com.webcodepro.applecommander.storage.filters.DisassemblyFileFilter;
import com.webcodepro.applecommander.storage.filters.GraphicsFileFilter; import com.webcodepro.applecommander.storage.filters.GraphicsFileFilter;
import com.webcodepro.applecommander.storage.filters.GutenbergFileFilter;
import com.webcodepro.applecommander.storage.filters.IntegerBasicFileFilter; import com.webcodepro.applecommander.storage.filters.IntegerBasicFileFilter;
import com.webcodepro.applecommander.storage.filters.PascalTextFileFilter; import com.webcodepro.applecommander.storage.filters.PascalTextFileFilter;
import com.webcodepro.applecommander.storage.filters.ShapeTableFileFilter;
import com.webcodepro.applecommander.storage.filters.TextFileFilter; import com.webcodepro.applecommander.storage.filters.TextFileFilter;
import com.webcodepro.applecommander.storage.filters.GutenbergFileFilter;
import com.webcodepro.applecommander.ui.UiBundle; import com.webcodepro.applecommander.ui.UiBundle;
import com.webcodepro.applecommander.ui.swt.filteradapter.ApplesoftFilterAdapter; import com.webcodepro.applecommander.ui.swt.filteradapter.ApplesoftFilterAdapter;
import com.webcodepro.applecommander.ui.swt.filteradapter.BusinessBASICFilterAdapter; import com.webcodepro.applecommander.ui.swt.filteradapter.BusinessBASICFilterAdapter;
@ -63,6 +64,7 @@ import com.webcodepro.applecommander.ui.swt.filteradapter.FilterAdapter;
import com.webcodepro.applecommander.ui.swt.filteradapter.GraphicsFilterAdapter; import com.webcodepro.applecommander.ui.swt.filteradapter.GraphicsFilterAdapter;
import com.webcodepro.applecommander.ui.swt.filteradapter.HexFilterAdapter; import com.webcodepro.applecommander.ui.swt.filteradapter.HexFilterAdapter;
import com.webcodepro.applecommander.ui.swt.filteradapter.RawDumpFilterAdapter; import com.webcodepro.applecommander.ui.swt.filteradapter.RawDumpFilterAdapter;
import com.webcodepro.applecommander.ui.swt.filteradapter.ShapeTableFilterAdapter;
import com.webcodepro.applecommander.ui.swt.filteradapter.TextFilterAdapter; import com.webcodepro.applecommander.ui.swt.filteradapter.TextFilterAdapter;
import com.webcodepro.applecommander.ui.swt.util.ImageManager; import com.webcodepro.applecommander.ui.swt.util.ImageManager;
import com.webcodepro.applecommander.ui.swt.util.SwtUtil; import com.webcodepro.applecommander.ui.swt.util.SwtUtil;
@ -93,9 +95,11 @@ public class FileViewerWindow {
private ToolBar toolBar; private ToolBar toolBar;
private ToolItem nativeToolItem; private ToolItem nativeToolItem;
private ToolItem hexDumpToolItem; private ToolItem hexDumpToolItem;
private Optional<ToolItem> disassemblyToolItem = Optional.empty(); // May or may not be setup
private ToolItem rawDumpToolItem; private ToolItem rawDumpToolItem;
private ToolItem copyToolItem; private ToolItem copyToolItem;
// May or may not be setup
private Optional<ToolItem> disassemblyToolItem = Optional.empty();
private Optional<ToolItem> shapeTableToolItem = Optional.empty();
private Font courier; private Font courier;
private Color black; private Color black;
@ -108,6 +112,7 @@ public class FileViewerWindow {
private FilterAdapter hexFilterAdapter; private FilterAdapter hexFilterAdapter;
private FilterAdapter rawDumpFilterAdapter; private FilterAdapter rawDumpFilterAdapter;
private FilterAdapter disassemblyFilterAdapter; private FilterAdapter disassemblyFilterAdapter;
private FilterAdapter shapeTableFilterAdapter;
/** /**
* Construct the file viewer window. * Construct the file viewer window.
@ -232,6 +237,11 @@ public class FileViewerWindow {
textBundle.get("FileViewerWindow.DisassemblyTooltip"), textBundle.get("FileViewerWindow.DisassemblyTooltip"),
imageManager.get(ImageManager.ICON_COMPILE_FILE) imageManager.get(ImageManager.ICON_COMPILE_FILE)
)); ));
nativeFilterAdapterMap.put(ShapeTableFileFilter.class,
new ShapeTableFilterAdapter(this, textBundle.get("FileViewerWindow.ShapeTableButton"),
textBundle.get("FileViewerWindow.ShapeTableTooltip"),
imageManager.get(ImageManager.ICON_SHAPE_TABLE)
));
} }
/** /**
@ -274,6 +284,7 @@ public class FileViewerWindow {
// Add the disassembly button only if it's not the default and if this filetype has a start address. // Add the disassembly button only if it's not the default and if this filetype has a start address.
if (fileEntry != null && fileEntry.needsAddress() && !(nativeFilter instanceof DisassemblyFileFilter)) { if (fileEntry != null && fileEntry.needsAddress() && !(nativeFilter instanceof DisassemblyFileFilter)) {
disassemblyToolItem = Optional.of(createDisassemblyToolItem()); disassemblyToolItem = Optional.of(createDisassemblyToolItem());
shapeTableToolItem = Optional.of(createShapeTableToolItem());
} }
new ToolItem(toolBar, SWT.SEPARATOR); new ToolItem(toolBar, SWT.SEPARATOR);
copyToolItem = createCopyToolItem(); copyToolItem = createCopyToolItem();
@ -318,6 +329,18 @@ public class FileViewerWindow {
return toolItem; return toolItem;
} }
/**
* Create the shape table tool item (button).
*/
protected ToolItem createShapeTableToolItem() {
shapeTableFilterAdapter = new ShapeTableFilterAdapter(this, textBundle.get("FileViewerWindow.ShapeTableButton"),
textBundle.get("FileViewerWindow.ShapeTableTooltip"),
imageManager.get(ImageManager.ICON_SHAPE_TABLE));
shapeTableFilterAdapter.setShapeTableSelected();
ToolItem toolItem = shapeTableFilterAdapter.create(toolBar);
return toolItem;
}
/** /**
* Create the copy tool item (button). * Create the copy tool item (button).
*/ */
@ -377,15 +400,15 @@ public class FileViewerWindow {
switch (event.keyCode) { switch (event.keyCode) {
case SWT.F2: // the "native" file format (image, text, etc) case SWT.F2: // the "native" file format (image, text, etc)
getNativeFilterAdapter().display(); getNativeFilterAdapter().display();
setFilterToolItemSelection(true, false, false, false); setFilterToolItemSelection(true, false, false, false, false);
break; break;
case SWT.F3: // Hex format case SWT.F3: // Hex format
getHexFilterAdapter().display(); getHexFilterAdapter().display();
setFilterToolItemSelection(false, true, false, false); setFilterToolItemSelection(false, true, false, false, false);
break; break;
case SWT.F4: // "Raw" hex format case SWT.F4: // "Raw" hex format
getRawDumpFilterAdapter().display(); getRawDumpFilterAdapter().display();
setFilterToolItemSelection(false, false, true, false); setFilterToolItemSelection(false, false, true, false, false);
break; break;
} }
} }
@ -421,11 +444,13 @@ public class FileViewerWindow {
public Color getBlueColor() { public Color getBlueColor() {
return blue; return blue;
} }
public void setFilterToolItemSelection(boolean nativeSelected, boolean hexSelected, boolean dumpSelected, boolean disassemblySelected) { public void setFilterToolItemSelection(boolean nativeSelected, boolean hexSelected, boolean dumpSelected,
boolean disassemblySelected, boolean shapeTableSelected) {
if (nativeToolItem != null) nativeToolItem.setSelection(nativeSelected); if (nativeToolItem != null) nativeToolItem.setSelection(nativeSelected);
hexDumpToolItem.setSelection(hexSelected); hexDumpToolItem.setSelection(hexSelected);
rawDumpToolItem.setSelection(dumpSelected); rawDumpToolItem.setSelection(dumpSelected);
disassemblyToolItem.ifPresent(toolItem -> toolItem.setSelection(disassemblySelected)); disassemblyToolItem.ifPresent(toolItem -> toolItem.setSelection(disassemblySelected));
shapeTableToolItem.ifPresent(toolItem -> toolItem.setSelection(shapeTableSelected));
} }
protected ContentTypeAdapter getContentTypeAdapter() { protected ContentTypeAdapter getContentTypeAdapter() {
return contentTypeAdapter; return contentTypeAdapter;

View File

@ -51,6 +51,7 @@ public abstract class FilterAdapter {
private boolean hexSelected = false; private boolean hexSelected = false;
private boolean dumpSelected = false; private boolean dumpSelected = false;
private boolean disassemblySelected = false; private boolean disassemblySelected = false;
private boolean shapeTableSelected = false;
public FilterAdapter(FileViewerWindow window, String text, String toolTipText, public FilterAdapter(FileViewerWindow window, String text, String toolTipText,
Image image) { Image image) {
@ -78,7 +79,8 @@ public abstract class FilterAdapter {
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
display(); display();
getWindow().setFilterToolItemSelection( getWindow().setFilterToolItemSelection(
isNativeSelected(), isHexSelected(), isDumpSelected(), isDisassemblySelected()); isNativeSelected(), isHexSelected(), isDumpSelected(), isDisassemblySelected(),
isShapeTableSelected());
} }
}); });
} }
@ -132,25 +134,36 @@ public abstract class FilterAdapter {
hexSelected = false; hexSelected = false;
dumpSelected = true; dumpSelected = true;
disassemblySelected = false; disassemblySelected = false;
shapeTableSelected = false;
} }
public void setHexSelected() { public void setHexSelected() {
nativeSelected = false; nativeSelected = false;
hexSelected = true; hexSelected = true;
dumpSelected = false; dumpSelected = false;
disassemblySelected = false; disassemblySelected = false;
shapeTableSelected = false;
} }
public void setDisassemblySelected() { public void setDisassemblySelected() {
nativeSelected = false; nativeSelected = false;
hexSelected = false; hexSelected = false;
dumpSelected = false; dumpSelected = false;
disassemblySelected = true; disassemblySelected = true;
shapeTableSelected = false;
} }
public void setNativeSelected() { public void setNativeSelected() {
nativeSelected = true; nativeSelected = true;
hexSelected = false; hexSelected = false;
dumpSelected = false; dumpSelected = false;
disassemblySelected = false; disassemblySelected = false;
shapeTableSelected = false;
} }
public void setShapeTableSelected() {
nativeSelected = false;
hexSelected = false;
dumpSelected = false;
disassemblySelected = false;
shapeTableSelected = true;
}
protected boolean isDumpSelected() { protected boolean isDumpSelected() {
return dumpSelected; return dumpSelected;
} }
@ -163,6 +176,9 @@ public abstract class FilterAdapter {
protected boolean isNativeSelected() { protected boolean isNativeSelected() {
return nativeSelected; return nativeSelected;
} }
protected boolean isShapeTableSelected() {
return shapeTableSelected;
}
protected FileViewerWindow getWindow() { protected FileViewerWindow getWindow() {
return window; return window;
} }

View File

@ -0,0 +1,18 @@
package com.webcodepro.applecommander.ui.swt.filteradapter;
import org.eclipse.swt.graphics.Image;
import com.webcodepro.applecommander.storage.FileFilter;
import com.webcodepro.applecommander.storage.filters.ShapeTableFileFilter;
import com.webcodepro.applecommander.ui.swt.FileViewerWindow;
public class ShapeTableFilterAdapter extends GraphicsFilterAdapter {
public ShapeTableFilterAdapter(FileViewerWindow window, String text, String toolTipText, Image image) {
super(window, text, toolTipText, image);
}
@Override
protected FileFilter getFileFilter() {
return new ShapeTableFileFilter();
}
}

View File

@ -67,6 +67,7 @@ public class ImageManager {
public static final String ICON_COPY = "copy.gif"; //$NON-NLS-1$ public static final String ICON_COPY = "copy.gif"; //$NON-NLS-1$
public static final String ICON_COMPARE_DISKS = "comparedisks.gif"; //$NON-NLS-1$ public static final String ICON_COMPARE_DISKS = "comparedisks.gif"; //$NON-NLS-1$
public static final String ICON_CHANGE_IMAGE_ORDER = "changeorder.gif"; //$NON-NLS-1$ public static final String ICON_CHANGE_IMAGE_ORDER = "changeorder.gif"; //$NON-NLS-1$
public static final String ICON_SHAPE_TABLE = "shape_table.gif";
public static final String LOGO_EXPORT_WIZARD = "ExportWizardLogo.jpg"; //$NON-NLS-1$ public static final String LOGO_EXPORT_WIZARD = "ExportWizardLogo.jpg"; //$NON-NLS-1$
public static final String LOGO_APPLECOMMANDER = "AppleCommanderLogo.jpg"; //$NON-NLS-1$ public static final String LOGO_APPLECOMMANDER = "AppleCommanderLogo.jpg"; //$NON-NLS-1$
@ -91,7 +92,7 @@ public class ImageManager {
ICON_VIEW_AS_SPREADSHEET, ICON_VIEW_AS_TEXTFILE, ICON_VIEW_AS_SPREADSHEET, ICON_VIEW_AS_TEXTFILE,
ICON_VIEW_AS_WORDPROCESSOR, ICON_VIEW_AS_BASIC_PROGRAM, ICON_VIEW_AS_WORDPROCESSOR, ICON_VIEW_AS_BASIC_PROGRAM,
ICON_COPY, ICON_COMPARE_DISKS, ICON_COPY, ICON_COMPARE_DISKS,
ICON_CHANGE_IMAGE_ORDER, ICON_CHANGE_IMAGE_ORDER, ICON_SHAPE_TABLE,
// Logos: // Logos:
LOGO_EXPORT_WIZARD, LOGO_APPLECOMMANDER, LOGO_EXPORT_WIZARD, LOGO_APPLECOMMANDER,
LOGO_DISK_IMAGE_WIZARD, LOGO_IMPORT_WIZARD, LOGO_DISK_IMAGE_WIZARD, LOGO_IMPORT_WIZARD,