From bf8cea3faff820ae5a70123af69dd869c769e671 Mon Sep 17 00:00:00 2001 From: Robert Greene Date: Tue, 16 Dec 2003 03:39:12 +0000 Subject: [PATCH] Added print of file listing. --- TODO | 7 +- .../ui/swt/DiskExplorerTab.java | 195 +++++++++++++++++- 2 files changed, 196 insertions(+), 6 deletions(-) diff --git a/TODO b/TODO index 1ddee4b..28594e1 100644 --- a/TODO +++ b/TODO @@ -3,7 +3,8 @@ THINGS TO DO This is the internal list of items that need to be done. --- 1.3.2 --- - +* Print file listing or full disk listing (including subdirectories or multiple + volumes). --- FUTURE 1.3.x --- o Compile of BASIC programs @@ -12,13 +13,13 @@ o Add Apple Pascal writing capability. o Create subdirectories as appropriate (ProDOS). o Need to update preferences with import location, disk creation location. o Enhance the BASIC compiler with a few more commands... -o Print file listing or full disk listing (including subdirectories or multiple - volumes). o Improve file preview for Integer BASIC files. o Improve file preview for AppleWorks Word Processor files (make implementation generic to a Word Processor). o Add formatted assembly FileFilter. Needs to understand multiple assembly programs. Need to recognize various formats - T.*, *.S, etc. (Merlin, Orca, APW, etc). +o SWT image handlers do no appear to work correctly. BMP works - but color seems + off. GIF/PNG/JPEG give errors or a black image. --- FUTURE 1.4.x (or later) --- o Add drag-and-drop capability. diff --git a/src/com/webcodepro/applecommander/ui/swt/DiskExplorerTab.java b/src/com/webcodepro/applecommander/ui/swt/DiskExplorerTab.java index 8da5034..c53fb33 100644 --- a/src/com/webcodepro/applecommander/ui/swt/DiskExplorerTab.java +++ b/src/com/webcodepro/applecommander/ui/swt/DiskExplorerTab.java @@ -60,9 +60,15 @@ import org.eclipse.swt.events.MenuEvent; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.printing.PrintDialog; +import org.eclipse.swt.printing.Printer; +import org.eclipse.swt.printing.PrinterData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.FileDialog; @@ -92,6 +98,7 @@ public class DiskExplorerTab { private static final char CTRL_D = 'D' - '@'; private static final char CTRL_E = 'E' - '@'; private static final char CTRL_I = 'I' - '@'; + private static final char CTRL_P = 'P' - '@'; private static final char CTRL_S = 'S' - '@'; private static final char CTRL_V = 'V' - '@'; @@ -1132,10 +1139,12 @@ public class DiskExplorerTab { printToolItem.setImage(imageManager.get(ImageManager.ICON_PRINT_FILE)); printToolItem.setText("Print"); printToolItem.setToolTipText("Print directory listing..."); - printToolItem.setEnabled(false); + printToolItem.setEnabled(true); printToolItem.addSelectionListener(new SelectionAdapter () { - public void widgetSelected(SelectionEvent e) { - // FIXME + public void widgetSelected(SelectionEvent event) { + if (event.detail != SWT.ARROW) { + print(); + } } }); @@ -1365,6 +1374,9 @@ public class DiskExplorerTab { case CTRL_I: // Import Wizard importFiles(); break; + case CTRL_P: // Print... + print(); + break; case CTRL_S: // Save if (saveToolItem.isEnabled()) { save(); @@ -1406,4 +1418,181 @@ public class DiskExplorerTab { } return fileEntry; } + /** + * Internal class that controls printing of a file listing. + */ + private class Printing implements Runnable { + private Printer printer; + private int y; + private int x; + private Rectangle clientArea; + private GC gc; + private List fileHeaders; + private int[] columnWidths; + private int[] columnPosition; + private Font normalFont; + private Font headerFont; + private String filename; + private int page = 1; + private int dpiY; + private int dpiX; + public Printing(Printer printer) { + this.printer = printer; + } + public void run() { + if (printer.startJob(disks[0].getFilename())) { + clientArea = printer.getClientArea(); + dpiY = printer.getDPI().y; + dpiX = printer.getDPI().x; + // Setup 1" margin: + Rectangle trim = printer.computeTrim(0, 0, 0, 0); + clientArea.x = dpiX + trim.x; + clientArea.y = dpiY + trim.y; + clientArea.width -= (clientArea.x + trim.width); + clientArea.height -= (clientArea.y + trim.height); + // Set default values: + y = clientArea.y; + x = clientArea.x; + gc = new GC(printer); + int fontSize = 12; + if (currentFormat == FormattedDisk.FILE_DISPLAY_NATIVE) { + fontSize = 10; + } else if (currentFormat == FormattedDisk.FILE_DISPLAY_DETAIL) { + fontSize = 8; + } + normalFont = new Font(printer, "", fontSize, SWT.NORMAL); + headerFont = new Font(printer, "", fontSize, SWT.BOLD); + for (int i=0; i= header.getTitle().length()) ? + header.getMaximumWidth() : header.getTitle().length(); + totalWidth+= widths[i]; + } + columnWidths = new int[fileHeaders.size()]; + columnPosition = new int[fileHeaders.size()]; + int position = clientArea.x; + for (int i=0; i (clientArea.y + clientArea.height)) { // filled a page + printFooter(); + printer.endPage(); + y = clientArea.y; + } + } + protected void printHeader() { + Point point = gc.stringExtent(filename); + gc.drawString(filename, + clientArea.x + (clientArea.width - point.x)/2, + y - dpiY + point.y); + } + protected void printFooter() { + String text = "Page " + Integer.toString(page); + Point point = gc.stringExtent(text); + gc.drawString(text, + clientArea.x + (clientArea.width - point.x)/2, + clientArea.y + clientArea.height + dpiY - point.y); + page++; + } + protected void printFiles(DirectoryEntry directory, int level) { + Iterator iterator = directory.getFiles().iterator(); + while (iterator.hasNext()) { + FileEntry fileEntry = (FileEntry) iterator.next(); + if (!fileEntry.isDeleted() || showDeletedFiles) { + List columns = fileEntry.getFileColumnData(currentFormat); + for (int i=0; i