mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-06-05 14:30:10 +00:00
better save error dialogs
This commit is contained in:
parent
af706e03c7
commit
d3f21e0d49
|
@ -17,8 +17,7 @@ public class SectorListConverter
|
||||||
sectors = new ArrayList<> ();
|
sectors = new ArrayList<> ();
|
||||||
sectorText = text;
|
sectorText = text;
|
||||||
|
|
||||||
String[] blocks = text.split (";");
|
for (String s : text.split (";"))
|
||||||
for (String s : blocks)
|
|
||||||
{
|
{
|
||||||
int pos = s.indexOf ('-');
|
int pos = s.indexOf ('-');
|
||||||
if (pos > 0)
|
if (pos > 0)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.bytezone.diskbrowser.gui;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.FileAlreadyExistsException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
|
@ -52,10 +53,17 @@ public abstract class AbstractSaveAction extends DefaultAction
|
||||||
JOptionPane.showMessageDialog (null,
|
JOptionPane.showMessageDialog (null,
|
||||||
String.format ("File %s saved", file.getName ()));
|
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)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace ();
|
e.printStackTrace ();
|
||||||
JOptionPane.showMessageDialog (null, "File failed to save");
|
JOptionPane.showMessageDialog (null, "File failed to save - " + e.getMessage (),
|
||||||
|
"Failed", JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,13 @@ package com.bytezone.diskbrowser.gui;
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
|
import com.bytezone.diskbrowser.disk.Disk;
|
||||||
|
import com.bytezone.diskbrowser.disk.DiskAddress;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
class SaveSectorsAction extends AbstractSaveAction implements SectorSelectionListener
|
class SaveSectorsAction extends AbstractSaveAction implements SectorSelectionListener
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
|
@ -30,8 +34,14 @@ class SaveSectorsAction extends AbstractSaveAction implements SectorSelectionLis
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setSelectedFile (new File ("savedSectors.bin"));
|
// block 0 will not read when it is the only DiskAddress in the list
|
||||||
saveBuffer (event.getFormattedDisk ().getDisk ().readBlocks (event.getSectors ()));
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
|
|
|
@ -12,7 +12,7 @@ class SectorSelectedEvent extends EventObject
|
||||||
// -----------------------------------------------------------------------------------//
|
// -----------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
private final List<DiskAddress> sectors;
|
private final List<DiskAddress> sectors;
|
||||||
private final FormattedDisk owner;
|
private final FormattedDisk owner; // for dual-format disks
|
||||||
boolean redo;
|
boolean redo;
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
|
@ -20,6 +20,7 @@ class SectorSelectedEvent extends EventObject
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
super (source);
|
super (source);
|
||||||
|
|
||||||
this.sectors = sectors;
|
this.sectors = sectors;
|
||||||
// always store the parent if this disk is part of a dual-dos disk
|
// always store the parent if this disk is part of a dual-dos disk
|
||||||
this.owner = owner.getParent () == null ? owner : owner.getParent ();
|
this.owner = owner.getParent () == null ? owner : owner.getParent ();
|
||||||
|
@ -44,8 +45,10 @@ class SectorSelectedEvent extends EventObject
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
StringBuilder text = new StringBuilder ();
|
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 ();
|
return text.toString ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user