diff --git a/src/main/java/com/webcodepro/applecommander/storage/DirectoryEntry.java b/src/main/java/com/webcodepro/applecommander/storage/DirectoryEntry.java index 3934e8b..6e4d248 100644 --- a/src/main/java/com/webcodepro/applecommander/storage/DirectoryEntry.java +++ b/src/main/java/com/webcodepro/applecommander/storage/DirectoryEntry.java @@ -28,6 +28,9 @@ import java.util.List; *
* Date Created: Mar 2, 2003
* @author Rob Greene
+ *
+ * Changed at: Dec 1, 2017
+ * @author Lisias Toledo
*/
public interface DirectoryEntry {
/**
@@ -37,17 +40,17 @@ public interface DirectoryEntry {
* return value should always be a list - a directory
* with 0 entries returns an empty list.
*/
- public List
* Date Created: Mar 2, 2003
* @author Rob Greene
+ *
+ * Changed at: Dec 1, 2017
+ * @author Lisias Toledo
*/
public class ProdosDirectoryEntry extends ProdosFileEntry implements DirectoryEntry {
private TextBundle textBundle = StorageBundle.getInstance();
private ProdosSubdirectoryHeader subdirectoryHeader;
-
+
/**
* Constructor for ProdosDirectoryEntry.
*/
- public ProdosDirectoryEntry(ProdosFormatDisk disk, int block, int offset,
+ public ProdosDirectoryEntry(ProdosFormatDisk disk, int block, int offset,
ProdosSubdirectoryHeader subdirectoryHeader) {
super(disk, block, offset);
this.subdirectoryHeader = subdirectoryHeader;
subdirectoryHeader.setProdosDirectoryEntry(this);
}
-
+
/**
* Get the subdirectory header.
*/
@@ -60,8 +64,9 @@ public class ProdosDirectoryEntry extends ProdosFileEntry implements DirectoryEn
* value should be null. If this a directory, the
* return value should always be a list - a directory
* with 0 entries returns an empty list.
+ * @throws DiskException
*/
- public List
* Date created: Oct 3, 2002 11:45:25 PM
* @author Rob Greene
+ *
+ * Changed at: Dec 1, 2017
+ * @author Lisias Toledo
*/
public class ProdosFormatDisk extends FormattedDisk {
private TextBundle textBundle = StorageBundle.getInstance();
@@ -255,9 +262,10 @@ public class ProdosFormatDisk extends FormattedDisk {
/**
* Retrieve a list of files.
+ * @throws DiskException
* @see com.webcodepro.applecommander.storage.FormattedDisk#getFiles()
*/
- public List
* Date created: Nov 17, 2002 9:46:53 PM
* @author Rob Greene
+ *
+ * Changed at: Dec 1, 2017
+ * @author Lisias Toledo
*/
public class DiskExplorerTab {
private static final char CTRL_C = 'C' - '@';
@@ -224,7 +229,11 @@ public class DiskExplorerTab {
* Single-click handler.
*/
public void widgetSelected(SelectionEvent event) {
- changeCurrentFormat(getCurrentFormat()); // minor hack
+ try {
+ changeCurrentFormat(getCurrentFormat()); // minor hack
+ } catch (DiskException e) {
+ // FIXME how to warn the User about this?
+ }
}
/**
* Double-click handler.
@@ -248,8 +257,8 @@ public class DiskExplorerTab {
diskItem.setText(disks[i].getDiskName());
diskItem.setData(disks[i]);
directoryTree.setSelection(new TreeItem[] { diskItem });
-
- if (disks[i].canHaveDirectories()) {
+
+ if (disks[i].canHaveDirectories()) try {
Iterator files = disks[i].getFiles().iterator();
while (files.hasNext()) {
FileEntry entry = (FileEntry) files.next();
@@ -260,15 +269,21 @@ public class DiskExplorerTab {
addDirectoriesToTree(item, (DirectoryEntry)entry);
}
}
- }
+ } catch (DiskException e) {
+ // FIXME how to warn the User about this?
+ }
}
-
+
computeColumnWidths(FormattedDisk.FILE_DISPLAY_STANDARD);
computeColumnWidths(FormattedDisk.FILE_DISPLAY_NATIVE);
computeColumnWidths(FormattedDisk.FILE_DISPLAY_DETAIL);
formatChanged = true;
- fillFileTable(disks[0].getFiles());
+ try {
+ fillFileTable(disks[0].getFiles());
+ } catch (DiskException e) {
+ // FIXME how to warn the User about this?
+ }
directoryTree.setSelection(new TreeItem[] { directoryTree.getItems()[0] });
}
/**
@@ -338,11 +353,15 @@ public class DiskExplorerTab {
item.setImage(imageManager.get(ImageManager.ICON_IMPORT_FILE));
item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
- importFiles();
+ try {
+ importFiles();
+ } catch (DiskException e) {
+ // FIXME how to warn the User about this?
+ }
}
});
item.setEnabled(disks[0].canCreateFile() && disks[0].canWriteFileData());
-
+
return menu;
}
/**
@@ -389,7 +408,11 @@ public class DiskExplorerTab {
item.setImage(imageManager.get(ImageManager.ICON_VIEW_FILE));
item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
- viewFile(null);
+ try {
+ viewFile(null);
+ } catch (DiskException e) {
+ // FIXME how to warn the User about this?
+ }
}
});
@@ -444,7 +467,11 @@ public class DiskExplorerTab {
item.setText(textBundle.get("ViewAsTextMenuItem")); //$NON-NLS-1$
item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
- viewFile(TextFileFilter.class);
+ try {
+ viewFile(TextFileFilter.class);
+ } catch (DiskException e) {
+ // FIXME how to warn the User about this?
+ }
}
});
@@ -452,7 +479,11 @@ public class DiskExplorerTab {
item.setText(textBundle.get("VeiwAsGraphicsMenuItem")); //$NON-NLS-1$
item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
- viewFile(GraphicsFileFilter.class);
+ try {
+ viewFile(GraphicsFileFilter.class);
+ } catch (DiskException e) {
+ // FIXME how to warn the User about this?
+ }
}
});
@@ -879,7 +910,11 @@ public class DiskExplorerTab {
* Double-click handler.
*/
public void widgetDefaultSelected(SelectionEvent event) {
- viewFile(null);
+ try {
+ viewFile(null);
+ } catch (DiskException e) {
+ // FIXME how to warn the User about this?
+ }
}
});
TableColumn column = null;
@@ -1101,12 +1136,13 @@ public class DiskExplorerTab {
}
/**
* Start the import wizard and import the selected files.
+ * @throws DiskException
*/
- protected void importFiles() {
+ protected void importFiles() throws DiskException {
//FIXME: This code has become really ugly!
TreeItem treeItem = directoryTree.getSelection()[0];
DirectoryEntry directory = (DirectoryEntry) treeItem.getData();
- ImportWizard wizard = new ImportWizard(shell,
+ ImportWizard wizard = new ImportWizard(shell,
imageManager, directory.getFormattedDisk());
wizard.open();
if (wizard.isWizardCompleted()) {
@@ -1201,8 +1237,9 @@ public class DiskExplorerTab {
}
/**
* Helper function for building fileTree.
+ * @throws DiskException
*/
- protected void addDirectoriesToTree(TreeItem directoryItem, DirectoryEntry directoryEntry) {
+ protected void addDirectoriesToTree(TreeItem directoryItem, DirectoryEntry directoryEntry) throws DiskException {
Iterator files = directoryEntry.getFiles().iterator();
while (files.hasNext()) {
final FileEntry entry = (FileEntry) files.next();
@@ -1228,8 +1265,12 @@ public class DiskExplorerTab {
standardFormatToolItem.setToolTipText(textBundle.get("StandardViewHoverText")); //$NON-NLS-1$
standardFormatToolItem.setSelection(true);
standardFormatToolItem.addSelectionListener(new SelectionAdapter () {
- public void widgetSelected(SelectionEvent e) {
- changeCurrentFormat(FormattedDisk.FILE_DISPLAY_STANDARD);
+ public void widgetSelected(SelectionEvent event) {
+ try {
+ changeCurrentFormat(FormattedDisk.FILE_DISPLAY_STANDARD);
+ } catch (DiskException e) {
+ // FIXME how to warn the User about this?
+ }
}
});
nativeFormatToolItem = new ToolItem(toolBar, SWT.RADIO);
@@ -1237,8 +1278,12 @@ public class DiskExplorerTab {
nativeFormatToolItem.setText(textBundle.get("NativeViewToolItem")); //$NON-NLS-1$
nativeFormatToolItem.setToolTipText(textBundle.get("NativeViewHoverText")); //$NON-NLS-1$
nativeFormatToolItem.addSelectionListener(new SelectionAdapter () {
- public void widgetSelected(SelectionEvent e) {
- changeCurrentFormat(FormattedDisk.FILE_DISPLAY_NATIVE);
+ public void widgetSelected(SelectionEvent event) {
+ try {
+ changeCurrentFormat(FormattedDisk.FILE_DISPLAY_NATIVE);
+ } catch (DiskException e) {
+ // FIXME how to warn the User about this?
+ }
}
});
detailFormatToolItem = new ToolItem(toolBar, SWT.RADIO);
@@ -1246,13 +1291,17 @@ public class DiskExplorerTab {
detailFormatToolItem.setText(textBundle.get("DetailViewToolItem")); //$NON-NLS-1$
detailFormatToolItem.setToolTipText(textBundle.get("DetailViewHoverText")); //$NON-NLS-1$
detailFormatToolItem.addSelectionListener(new SelectionAdapter () {
- public void widgetSelected(SelectionEvent e) {
- changeCurrentFormat(FormattedDisk.FILE_DISPLAY_DETAIL);
+ public void widgetSelected(SelectionEvent event) {
+ try {
+ changeCurrentFormat(FormattedDisk.FILE_DISPLAY_DETAIL);
+ } catch (DiskException e) {
+ // FIXME how to warn the User about this?
+ }
}
});
-
+
new ToolItem(toolBar, SWT.SEPARATOR);
-
+
showDeletedFilesToolItem = new ToolItem(toolBar, SWT.CHECK);
showDeletedFilesToolItem.setImage(imageManager.get(ImageManager.ICON_SHOW_DELETED_FILES));
showDeletedFilesToolItem.setText(textBundle.get("ShowDeletedFilesToolItem")); //$NON-NLS-1$
@@ -1274,11 +1323,15 @@ public class DiskExplorerTab {
importToolItem.setToolTipText(textBundle.get("ImportWizardHoverText")); //$NON-NLS-1$
importToolItem.setEnabled(disks[0].canCreateFile() && disks[0].canWriteFileData());
importToolItem.addSelectionListener(new SelectionAdapter () {
- public void widgetSelected(SelectionEvent e) {
- importFiles();
+ public void widgetSelected(SelectionEvent event) {
+ try {
+ importFiles();
+ } catch (DiskException e) {
+ // FIXME how to warn the User about this?
+ }
}
});
-
+
exportToolItem = new ToolItem(toolBar, SWT.DROP_DOWN);
exportToolItem.setImage(imageManager.get(ImageManager.ICON_EXPORT_FILE));
exportToolItem.setText(textBundle.get("ExportWizardToolItem")); //$NON-NLS-1$
@@ -1315,9 +1368,11 @@ public class DiskExplorerTab {
viewFileItem.setEnabled(false);
viewFileItem.addSelectionListener(new SelectionAdapter () {
public void widgetSelected(SelectionEvent event) {
- if (event.detail != SWT.ARROW) {
+ if (event.detail != SWT.ARROW) try {
viewFile(null);
- }
+ } catch (DiskException e) {
+ // FIXME how to warn the User about this?
+ }
}
});
printToolItem = new ToolItem(toolBar, SWT.PUSH);
@@ -1402,8 +1457,9 @@ public class DiskExplorerTab {
}
/**
* Change the current format and refresh the display.
+ * @throws DiskException
*/
- protected void changeCurrentFormat(int newFormat) {
+ protected void changeCurrentFormat(int newFormat) throws DiskException {
TreeItem selection = directoryTree.getSelection()[0];
Object data = selection.getData();
DirectoryEntry directory = (DirectoryEntry) data;
@@ -1522,8 +1578,9 @@ public class DiskExplorerTab {
}
/**
* Open up the view file window for the currently selected file.
+ * @throws DiskException
*/
- protected void viewFile(Class fileFilterClass) {
+ protected void viewFile(Class fileFilterClass) throws DiskException {
FileEntry fileEntry = getSelectedFileEntry();
if (fileEntry.isDeleted()) {
SwtUtil.showErrorDialog(shell, textBundle.get("DeleteFileErrorTitle"), //$NON-NLS-1$
@@ -1583,8 +1640,8 @@ public class DiskExplorerTab {
return new Listener() {
public void handleEvent(Event event) {
FileEntry fileEntry = getSelectedFileEntry();
- if (fileEntry != null && event.type == SWT.KeyUp && (event.stateMask & SWT.CTRL) != 0) {
- switch (event.character) {
+ if (fileEntry != null && event.type == SWT.KeyUp && (event.stateMask & SWT.CTRL) != 0)
+ try { switch (event.character) {
case CTRL_C: // Compile Wizard
if (getCompileToolItem().isEnabled()) {
compileFileWizard();
@@ -1601,8 +1658,9 @@ public class DiskExplorerTab {
case CTRL_V: // View file
viewFile(null);
break;
- }
- }
+ } } catch (DiskException e) {
+ // FIXME how to warn the User about this?
+ }
}
};
}
@@ -1624,7 +1682,7 @@ public class DiskExplorerTab {
saveAs();
break;
}
- } else {
+ } else try {
switch (event.character) {
case CTRL_I: // Import Wizard
importFiles();
@@ -1638,10 +1696,12 @@ public class DiskExplorerTab {
}
break;
}
- }
+ } catch (DiskException e) {
+ // FIXME how to warn the User about this?
+ }
} else { // No CTRL key
- if ((event.stateMask & SWT.ALT) != SWT.ALT) { // Ignore ALT key combinations like alt-F4!
- switch (event.keyCode) {
+ if ((event.stateMask & SWT.ALT) != SWT.ALT) // Ignore ALT key combinations like alt-F4!
+ try { switch (event.keyCode) {
case SWT.F2: // Standard file display
changeCurrentFormat(FormattedDisk.FILE_DISPLAY_STANDARD);
break;
@@ -1657,7 +1717,9 @@ public class DiskExplorerTab {
fillFileTable(getCurrentFileList());
break;
}
- }
+ } catch (DiskException e) {
+ // FIXME how to warn the User about this?
+ }
}
}
}
@@ -1728,7 +1790,11 @@ public class DiskExplorerTab {
printFileHeaders();
gc.setFont(normalFont);
println(disk.getDiskName());
- printFiles(disk, 1);
+ try {
+ printFiles(disk, 1);
+ } catch (DiskException e) {
+ // FIXME how to warn the User about this?
+ }
}
if (y != clientArea.y) { // partial page
printFooter();
@@ -1811,7 +1877,7 @@ public class DiskExplorerTab {
clientArea.y + clientArea.height + dpiY - point.y);
page++;
}
- protected void printFiles(DirectoryEntry directory, int level) {
+ protected void printFiles(DirectoryEntry directory, int level) throws DiskException {
Iterator iterator = directory.getFiles().iterator();
while (iterator.hasNext()) {
FileEntry fileEntry = (FileEntry) iterator.next();
+ * Created on Nov 30, 2017.
+ * @author Lisias Toledo
+ */
+public class DiskCorruptException extends DiskException {
+
+ private static final long serialVersionUID = 0xFFFFFFFF80000000L;
+
+ /**
+ * Constructor for DiskFullException.
+ */
+ public DiskCorruptException(String description) {
+ super(description);
+ }
+}
diff --git a/src/main/java/com/webcodepro/applecommander/storage/DiskException.java b/src/main/java/com/webcodepro/applecommander/storage/DiskException.java
new file mode 100644
index 0000000..2114316
--- /dev/null
+++ b/src/main/java/com/webcodepro/applecommander/storage/DiskException.java
@@ -0,0 +1,39 @@
+/*
+ * AppleCommander - An Apple ][ image utility.
+ * Copyright (C) 2002 by Robert Greene
+ * robgreene at users.sourceforge.net
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.webcodepro.applecommander.storage;
+
+/**
+ * A DiskFullException is thrown during a write operation when the file
+ * being written will not fit on the disk.
+ *
+ * Created on Dec 23, 2002.
+ * @author Rob Greene
+ */
+public class DiskException extends Exception {
+
+ private static final long serialVersionUID = 0xFFFFFFFF80000000L;
+
+ /**
+ * Constructor for DiskFullException.
+ */
+ public DiskException(String description) {
+ super(description);
+ }
+}
diff --git a/src/main/java/com/webcodepro/applecommander/storage/DiskFullException.java b/src/main/java/com/webcodepro/applecommander/storage/DiskFullException.java
index 60fa270..de28f56 100644
--- a/src/main/java/com/webcodepro/applecommander/storage/DiskFullException.java
+++ b/src/main/java/com/webcodepro/applecommander/storage/DiskFullException.java
@@ -25,8 +25,11 @@ package com.webcodepro.applecommander.storage;
*
* Created on Dec 23, 2002.
* @author Rob Greene
+ *
+ * Changed at: Dec 1, 2017
+ * @author Lisias Toledo
*/
-public class DiskFullException extends Exception {
+public class DiskFullException extends DiskException {
private static final long serialVersionUID = 0xFFFFFFFF80000000L;
diff --git a/src/main/java/com/webcodepro/applecommander/storage/FormattedDisk.java b/src/main/java/com/webcodepro/applecommander/storage/FormattedDisk.java
index d407638..68160c6 100644
--- a/src/main/java/com/webcodepro/applecommander/storage/FormattedDisk.java
+++ b/src/main/java/com/webcodepro/applecommander/storage/FormattedDisk.java
@@ -268,7 +268,13 @@ public abstract class FormattedDisk extends Disk implements DirectoryEntry {
* Returns a null if specific filename is not located.
*/
public FileEntry getFile(String filename) {
- List files = getFiles();
+ List files;
+ try {
+ files = getFiles();
+ } catch (DiskException e) {
+ // FIXME how to warn the User about this?
+ files = new ArrayList<>();
+ }
return getFile(files, filename.trim());
}
@@ -282,11 +288,13 @@ public abstract class FormattedDisk extends Disk implements DirectoryEntry {
if (files != null) {
for (int i=0; i