From 92147b03acca41f5704c3c96cd449cf57881d054 Mon Sep 17 00:00:00 2001 From: Rob Greene Date: Tue, 8 Mar 2022 21:44:15 -0600 Subject: [PATCH] Adding ability to view shape table files. --- lib/ac-api/build.gradle | 1 + .../storage/filters/ShapeTableFileFilter.java | 42 ++++++++++++++++++ .../applecommander/ui/UiBundle.properties | 2 + .../applecommander/ui/images/shape_table.gif | Bin 0 -> 364 bytes .../ui/swt/FileViewerWindow.java | 37 ++++++++++++--- .../ui/swt/filteradapter/FilterAdapter.java | 18 +++++++- .../ShapeTableFilterAdapter.java | 18 ++++++++ .../ui/swt/util/ImageManager.java | 3 +- 8 files changed, 113 insertions(+), 8 deletions(-) create mode 100644 lib/ac-api/src/main/java/com/webcodepro/applecommander/storage/filters/ShapeTableFileFilter.java create mode 100644 lib/ac-api/src/main/resources/com/webcodepro/applecommander/ui/images/shape_table.gif create mode 100644 lib/ac-swt-common/src/main/java/com/webcodepro/applecommander/ui/swt/filteradapter/ShapeTableFilterAdapter.java diff --git a/lib/ac-api/build.gradle b/lib/ac-api/build.gradle index e822055..a2e5c4d 100644 --- a/lib/ac-api/build.gradle +++ b/lib/ac-api/build.gradle @@ -17,6 +17,7 @@ repositories { dependencies { implementation "net.sf.applecommander:ShrinkItArchive:$shkVersion" implementation "net.sf.applecommander:acdasm:$acdasmVersion" + implementation "net.sf.applecommander:bastools-api:$btVersion" implementation "org.apache.commons:commons-csv:$commonsCsvVersion" implementation "com.google.code.gson:gson:$gsonVersion" diff --git a/lib/ac-api/src/main/java/com/webcodepro/applecommander/storage/filters/ShapeTableFileFilter.java b/lib/ac-api/src/main/java/com/webcodepro/applecommander/storage/filters/ShapeTableFileFilter.java new file mode 100644 index 0000000..a53af77 --- /dev/null +++ b/lib/ac-api/src/main/java/com/webcodepro/applecommander/storage/filters/ShapeTableFileFilter.java @@ -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; + } +} diff --git a/lib/ac-api/src/main/resources/com/webcodepro/applecommander/ui/UiBundle.properties b/lib/ac-api/src/main/resources/com/webcodepro/applecommander/ui/UiBundle.properties index 621aa1c..3b6156f 100644 --- a/lib/ac-api/src/main/resources/com/webcodepro/applecommander/ui/UiBundle.properties +++ b/lib/ac-api/src/main/resources/com/webcodepro/applecommander/ui/UiBundle.properties @@ -353,6 +353,8 @@ FileViewerWindow.CopyTooltip=Copies selection to the clipboard (CTRL+C) FileViewerWindow.PrintTooltip=Print contents... (CTRL+P) FileViewerWindow.DisassemblyButton=Disassembly FileViewerWindow.DisassemblyTooltip=Displays file disassembled +FileViewerWindow.ShapeTableButton=Shape Table +FileViewerWindow.ShapeTableTooltip=Display as shape table # DiskWindow diff --git a/lib/ac-api/src/main/resources/com/webcodepro/applecommander/ui/images/shape_table.gif b/lib/ac-api/src/main/resources/com/webcodepro/applecommander/ui/images/shape_table.gif new file mode 100644 index 0000000000000000000000000000000000000000..b6efdd3d8672a42eb3983a3d0d55658cf5cf6238 GIT binary patch literal 364 zcmZ?wbhEHb6krfwxXQrr>Fe)bzyJRH_2=G;A5Y%=eEaFwo#)^0zx?s=)sI&ne*XCN z_u0FjAHM$9^vIsE=FqBxH``{c{`%wh_n*Ii|M`3F{LvXRCeEJK|L^bnWeeNyUf;EN ze%Jgty<1n+ZCKv8dP(cwFXxYMEj+Th_~6F!z3VD>uBra}`TW+2%3CKX@0zam=lSA! zm14^prIs~GEp3uo*Cqe^Zu86%;s5{tGY}0Ff3h$#Fc>oEfOLTT#K6{hU`Bz5j#U2& zrHqqjECQ!L5l~sd#T0S*Wsw!H^P~+aMuoL@OD`Q)6>(MSYqPnKwKQV&Lk@-v2RQ*= zE-ig67Zo0!y3QU0R~c5;#=42DBCfKWv-lbXX34tBaW7unxLD3rf`z57fp@ips}#qU jB3`~NQm)eMd-v^SmUb0mJ9_Mxn5*dNGiODe9T}_v5ICWT literal 0 HcmV?d00001 diff --git a/lib/ac-swt-common/src/main/java/com/webcodepro/applecommander/ui/swt/FileViewerWindow.java b/lib/ac-swt-common/src/main/java/com/webcodepro/applecommander/ui/swt/FileViewerWindow.java index 6923866..a797a3c 100644 --- a/lib/ac-swt-common/src/main/java/com/webcodepro/applecommander/ui/swt/FileViewerWindow.java +++ b/lib/ac-swt-common/src/main/java/com/webcodepro/applecommander/ui/swt/FileViewerWindow.java @@ -51,10 +51,11 @@ import com.webcodepro.applecommander.storage.filters.AssemblySourceFileFilter; import com.webcodepro.applecommander.storage.filters.BusinessBASICFileFilter; import com.webcodepro.applecommander.storage.filters.DisassemblyFileFilter; 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.PascalTextFileFilter; +import com.webcodepro.applecommander.storage.filters.ShapeTableFileFilter; 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.swt.filteradapter.ApplesoftFilterAdapter; 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.HexFilterAdapter; 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.util.ImageManager; import com.webcodepro.applecommander.ui.swt.util.SwtUtil; @@ -93,9 +95,11 @@ public class FileViewerWindow { private ToolBar toolBar; private ToolItem nativeToolItem; private ToolItem hexDumpToolItem; - private Optional disassemblyToolItem = Optional.empty(); // May or may not be setup private ToolItem rawDumpToolItem; private ToolItem copyToolItem; + // May or may not be setup + private Optional disassemblyToolItem = Optional.empty(); + private Optional shapeTableToolItem = Optional.empty(); private Font courier; private Color black; @@ -108,6 +112,7 @@ public class FileViewerWindow { private FilterAdapter hexFilterAdapter; private FilterAdapter rawDumpFilterAdapter; private FilterAdapter disassemblyFilterAdapter; + private FilterAdapter shapeTableFilterAdapter; /** * Construct the file viewer window. @@ -232,6 +237,11 @@ public class FileViewerWindow { textBundle.get("FileViewerWindow.DisassemblyTooltip"), 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. if (fileEntry != null && fileEntry.needsAddress() && !(nativeFilter instanceof DisassemblyFileFilter)) { disassemblyToolItem = Optional.of(createDisassemblyToolItem()); + shapeTableToolItem = Optional.of(createShapeTableToolItem()); } new ToolItem(toolBar, SWT.SEPARATOR); copyToolItem = createCopyToolItem(); @@ -318,6 +329,18 @@ public class FileViewerWindow { 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). */ @@ -377,15 +400,15 @@ public class FileViewerWindow { switch (event.keyCode) { case SWT.F2: // the "native" file format (image, text, etc) getNativeFilterAdapter().display(); - setFilterToolItemSelection(true, false, false, false); + setFilterToolItemSelection(true, false, false, false, false); break; case SWT.F3: // Hex format getHexFilterAdapter().display(); - setFilterToolItemSelection(false, true, false, false); + setFilterToolItemSelection(false, true, false, false, false); break; case SWT.F4: // "Raw" hex format getRawDumpFilterAdapter().display(); - setFilterToolItemSelection(false, false, true, false); + setFilterToolItemSelection(false, false, true, false, false); break; } } @@ -421,11 +444,13 @@ public class FileViewerWindow { public Color getBlueColor() { 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); hexDumpToolItem.setSelection(hexSelected); rawDumpToolItem.setSelection(dumpSelected); disassemblyToolItem.ifPresent(toolItem -> toolItem.setSelection(disassemblySelected)); + shapeTableToolItem.ifPresent(toolItem -> toolItem.setSelection(shapeTableSelected)); } protected ContentTypeAdapter getContentTypeAdapter() { return contentTypeAdapter; diff --git a/lib/ac-swt-common/src/main/java/com/webcodepro/applecommander/ui/swt/filteradapter/FilterAdapter.java b/lib/ac-swt-common/src/main/java/com/webcodepro/applecommander/ui/swt/filteradapter/FilterAdapter.java index a39b98f..c4a7630 100644 --- a/lib/ac-swt-common/src/main/java/com/webcodepro/applecommander/ui/swt/filteradapter/FilterAdapter.java +++ b/lib/ac-swt-common/src/main/java/com/webcodepro/applecommander/ui/swt/filteradapter/FilterAdapter.java @@ -51,6 +51,7 @@ public abstract class FilterAdapter { private boolean hexSelected = false; private boolean dumpSelected = false; private boolean disassemblySelected = false; + private boolean shapeTableSelected = false; public FilterAdapter(FileViewerWindow window, String text, String toolTipText, Image image) { @@ -78,7 +79,8 @@ public abstract class FilterAdapter { public void widgetSelected(SelectionEvent e) { display(); getWindow().setFilterToolItemSelection( - isNativeSelected(), isHexSelected(), isDumpSelected(), isDisassemblySelected()); + isNativeSelected(), isHexSelected(), isDumpSelected(), isDisassemblySelected(), + isShapeTableSelected()); } }); } @@ -132,25 +134,36 @@ public abstract class FilterAdapter { hexSelected = false; dumpSelected = true; disassemblySelected = false; + shapeTableSelected = false; } public void setHexSelected() { nativeSelected = false; hexSelected = true; dumpSelected = false; disassemblySelected = false; + shapeTableSelected = false; } public void setDisassemblySelected() { nativeSelected = false; hexSelected = false; dumpSelected = false; disassemblySelected = true; + shapeTableSelected = false; } public void setNativeSelected() { nativeSelected = true; hexSelected = false; dumpSelected = false; disassemblySelected = false; + shapeTableSelected = false; } + public void setShapeTableSelected() { + nativeSelected = false; + hexSelected = false; + dumpSelected = false; + disassemblySelected = false; + shapeTableSelected = true; + } protected boolean isDumpSelected() { return dumpSelected; } @@ -163,6 +176,9 @@ public abstract class FilterAdapter { protected boolean isNativeSelected() { return nativeSelected; } + protected boolean isShapeTableSelected() { + return shapeTableSelected; + } protected FileViewerWindow getWindow() { return window; } diff --git a/lib/ac-swt-common/src/main/java/com/webcodepro/applecommander/ui/swt/filteradapter/ShapeTableFilterAdapter.java b/lib/ac-swt-common/src/main/java/com/webcodepro/applecommander/ui/swt/filteradapter/ShapeTableFilterAdapter.java new file mode 100644 index 0000000..ab4edf9 --- /dev/null +++ b/lib/ac-swt-common/src/main/java/com/webcodepro/applecommander/ui/swt/filteradapter/ShapeTableFilterAdapter.java @@ -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(); + } +} diff --git a/lib/ac-swt-common/src/main/java/com/webcodepro/applecommander/ui/swt/util/ImageManager.java b/lib/ac-swt-common/src/main/java/com/webcodepro/applecommander/ui/swt/util/ImageManager.java index 477b819..293414b 100644 --- a/lib/ac-swt-common/src/main/java/com/webcodepro/applecommander/ui/swt/util/ImageManager.java +++ b/lib/ac-swt-common/src/main/java/com/webcodepro/applecommander/ui/swt/util/ImageManager.java @@ -67,6 +67,7 @@ public class ImageManager { 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_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_APPLECOMMANDER = "AppleCommanderLogo.jpg"; //$NON-NLS-1$ @@ -91,7 +92,7 @@ public class ImageManager { ICON_VIEW_AS_SPREADSHEET, ICON_VIEW_AS_TEXTFILE, ICON_VIEW_AS_WORDPROCESSOR, ICON_VIEW_AS_BASIC_PROGRAM, ICON_COPY, ICON_COMPARE_DISKS, - ICON_CHANGE_IMAGE_ORDER, + ICON_CHANGE_IMAGE_ORDER, ICON_SHAPE_TABLE, // Logos: LOGO_EXPORT_WIZARD, LOGO_APPLECOMMANDER, LOGO_DISK_IMAGE_WIZARD, LOGO_IMPORT_WIZARD,