better save error dialogs

This commit is contained in:
Denis Molony 2021-05-21 13:34:33 +10:00
parent af706e03c7
commit d3f21e0d49
4 changed files with 28 additions and 8 deletions

View File

@ -17,8 +17,7 @@ public class SectorListConverter
sectors = new ArrayList<> ();
sectorText = text;
String[] blocks = text.split (";");
for (String s : blocks)
for (String s : text.split (";"))
{
int pos = s.indexOf ('-');
if (pos > 0)

View File

@ -2,6 +2,7 @@ package com.bytezone.diskbrowser.gui;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
@ -52,10 +53,17 @@ public abstract class AbstractSaveAction extends DefaultAction
JOptionPane.showMessageDialog (null,
String.format ("File %s saved", file.getName ()));
}
catch (FileAlreadyExistsException e)
{
JOptionPane.showMessageDialog (null,
"File " + file.getName () + " already exists", "Failed",
JOptionPane.ERROR_MESSAGE);
}
catch (IOException e)
{
e.printStackTrace ();
JOptionPane.showMessageDialog (null, "File failed to save");
JOptionPane.showMessageDialog (null, "File failed to save - " + e.getMessage (),
"Failed", JOptionPane.ERROR_MESSAGE);
}
}
}

View File

@ -2,9 +2,13 @@ package com.bytezone.diskbrowser.gui;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.List;
import javax.swing.JOptionPane;
import com.bytezone.diskbrowser.disk.Disk;
import com.bytezone.diskbrowser.disk.DiskAddress;
// -----------------------------------------------------------------------------------//
class SaveSectorsAction extends AbstractSaveAction implements SectorSelectionListener
// -----------------------------------------------------------------------------------//
@ -30,8 +34,14 @@ class SaveSectorsAction extends AbstractSaveAction implements SectorSelectionLis
return;
}
setSelectedFile (new File ("savedSectors.bin"));
saveBuffer (event.getFormattedDisk ().getDisk ().readBlocks (event.getSectors ()));
// block 0 will not read when it is the only DiskAddress in the list
List<DiskAddress> blocks = event.getSectors ();
Disk disk = event.getFormattedDisk ().getDisk ();
byte[] buffer =
blocks.size () == 1 ? disk.readBlock (blocks.get (0)) : disk.readBlocks (blocks);
setSelectedFile (new File ("SavedSectors.bin"));
saveBuffer (buffer);
}
// ---------------------------------------------------------------------------------//

View File

@ -12,7 +12,7 @@ class SectorSelectedEvent extends EventObject
// -----------------------------------------------------------------------------------//
{
private final List<DiskAddress> sectors;
private final FormattedDisk owner;
private final FormattedDisk owner; // for dual-format disks
boolean redo;
// ---------------------------------------------------------------------------------//
@ -20,6 +20,7 @@ class SectorSelectedEvent extends EventObject
// ---------------------------------------------------------------------------------//
{
super (source);
this.sectors = sectors;
// always store the parent if this disk is part of a dual-dos disk
this.owner = owner.getParent () == null ? owner : owner.getParent ();
@ -44,8 +45,10 @@ class SectorSelectedEvent extends EventObject
// ---------------------------------------------------------------------------------//
{
StringBuilder text = new StringBuilder ();
SectorListConverter slc = new SectorListConverter (sectors);
text.append (slc.sectorText);
SectorListConverter sectorListConverter = new SectorListConverter (sectors);
text.append (sectorListConverter.sectorText);
return text.toString ();
}