Added a formatted checkbox to the save dialog

This commit is contained in:
Denis Molony 2022-07-31 07:13:59 +10:00
parent 37c489f252
commit 898587b23b
7 changed files with 41 additions and 40 deletions

View File

@ -88,7 +88,7 @@ public class CPMDisk extends AbstractFormattedDisk
if (b1 > 31 && b1 != EMPTY_BYTE_VALUE) if (b1 > 31 && b1 != EMPTY_BYTE_VALUE)
break; break;
if (b2 < 32 || (b2 > 126 && b2 != EMPTY_BYTE_VALUE)) if (b2 <= 32 || (b2 > 126 && b2 != EMPTY_BYTE_VALUE))
break; break;
for (int i = 0; i < buffer.length; i += 32) for (int i = 0; i < buffer.length; i += 32)
@ -99,7 +99,7 @@ public class CPMDisk extends AbstractFormattedDisk
if (b1 == EMPTY_BYTE_VALUE) // deleted file?? if (b1 == EMPTY_BYTE_VALUE) // deleted file??
continue; continue;
if (b2 < 32 || (b2 > 126 && b2 != EMPTY_BYTE_VALUE)) if (b2 <= 32 || (b2 > 126 && b2 != EMPTY_BYTE_VALUE))
break; break;
DirectoryEntry entry = new DirectoryEntry (this, buffer, i); DirectoryEntry entry = new DirectoryEntry (this, buffer, i);
@ -188,9 +188,8 @@ public class CPMDisk extends AbstractFormattedDisk
public AppleFileSource getCatalog () public AppleFileSource getCatalog ()
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
String line = String line = "---- --------- --- - - -- -- -- -- ----------------------------"
"---- --------- --- - - -- -- -- -- ----------------------------" + "-------------------\n";
+ "-------------------\n";
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();
text.append (String.format ("File : %s%n%n", getDisplayPath ())); text.append (String.format ("File : %s%n%n", getDisplayPath ()));
text.append ("User Name Typ R S Ex S2 S1 RC Blocks\n"); text.append ("User Name Typ R S Ex S2 S1 RC Blocks\n");

View File

@ -139,9 +139,8 @@ class DirectoryEntry implements AppleFileSource
char ro = readOnly ? '*' : ' '; char ro = readOnly ? '*' : ' ';
char sf = systemFile ? '*' : ' '; char sf = systemFile ? '*' : ' ';
String text = String text = String.format ("%3d %-8s %-3s %s %s %02X %02X %02X %02X %s",
String.format ("%3d %-8s %-3s %s %s %02X %02X %02X %02X %s", userNumber, name, type, ro, sf, extent, s2, s1, recordsUsed, bytes);
userNumber, name, type, ro, sf, extent, s2, s1, recordsUsed, bytes);
for (DirectoryEntry entry : entries) for (DirectoryEntry entry : entries)
text = text + "\n" + entry.line (); text = text + "\n" + entry.line ();
@ -218,14 +217,13 @@ class DirectoryEntry implements AppleFileSource
else if ("DVR".equals (type)) else if ("DVR".equals (type))
appleFile = new DefaultAppleFile (name, exactBuffer, "DVR File"); appleFile = new DefaultAppleFile (name, exactBuffer, "DVR File");
else if ("ASM".equals (type) || "DOC".equals (type) || "COB".equals (type) else if ("ASM".equals (type) || "DOC".equals (type) || "COB".equals (type)
|| "HLP".equals (type) || "TXT".equals (type) || "LET".equals (type) || "HLP".equals (type) || "TXT".equals (type) || "LET".equals (type) || "ALX".equals (type)
|| "ALX".equals (type) || "SRC".equals (type) || "H".equals (type) || "SRC".equals (type) || "H".equals (type) || exactBuffer[len - 1] == 0x1A)
|| exactBuffer[len - 1] == 0x1A)
appleFile = new CPMTextFile (name, exactBuffer); appleFile = new CPMTextFile (name, exactBuffer);
else if ("BAS".equals (type)) else if ("BAS".equals (type))
appleFile = new CPMBasicFile (name, exactBuffer); appleFile = new CPMBasicFile (name, exactBuffer);
else else
appleFile = new DefaultAppleFile (name, exactBuffer, "CPM File : " + type); appleFile = new DefaultAppleFile (name, exactBuffer, "CPM File : " + name + "." + type);
return appleFile; return appleFile;
} }

View File

@ -15,27 +15,21 @@ import com.bytezone.diskbrowser.utilities.DefaultAction;
public abstract class AbstractSaveAction extends DefaultAction public abstract class AbstractSaveAction extends DefaultAction
// -----------------------------------------------------------------------------------// // -----------------------------------------------------------------------------------//
{ {
private JFileChooser fileChooser; protected JFileChooser fileChooser = new JFileChooser ();
private String dialogTitle;
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
public AbstractSaveAction (String menuText, String tip, String dialogTitle) public AbstractSaveAction (String menuText, String tip, String dialogTitle)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
super (menuText, tip); super (menuText, tip);
this.dialogTitle = dialogTitle;
fileChooser.setDialogTitle (dialogTitle);
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
void setSelectedFile (File file) void setSelectedFile (File file)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
if (fileChooser == null)
{
fileChooser = new JFileChooser ();
fileChooser.setDialogTitle (dialogTitle);
}
fileChooser.setSelectedFile (file); fileChooser.setSelectedFile (file);
} }
@ -43,26 +37,22 @@ public abstract class AbstractSaveAction extends DefaultAction
void saveBuffer (byte[] buffer) void saveBuffer (byte[] buffer)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
if (fileChooser.showSaveDialog (null) != JFileChooser.APPROVE_OPTION)
return;
File file = fileChooser.getSelectedFile (); File file = fileChooser.getSelectedFile ();
try try
{ {
Files.write (file.toPath (), buffer, StandardOpenOption.CREATE_NEW); Files.write (file.toPath (), buffer, StandardOpenOption.CREATE_NEW);
JOptionPane.showMessageDialog (null, JOptionPane.showMessageDialog (null, String.format ("File %s saved", file.getName ()));
String.format ("File %s saved", file.getName ()));
} }
catch (FileAlreadyExistsException e) catch (FileAlreadyExistsException e)
{ {
JOptionPane.showMessageDialog (null, "File " + file.getName () + " already exists", JOptionPane.showMessageDialog (null, "File " + file.getName () + " already exists", "Failed",
"Failed", JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
} }
catch (IOException e) catch (IOException e)
{ {
e.printStackTrace (); e.printStackTrace ();
JOptionPane.showMessageDialog (null, "File failed to save - " + e.getMessage (), JOptionPane.showMessageDialog (null, "File failed to save - " + e.getMessage (), "Failed",
"Failed", JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
} }
} }
} }

View File

@ -3,6 +3,7 @@ package com.bytezone.diskbrowser.gui;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.io.File; import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import com.bytezone.diskbrowser.disk.AppleDisk; import com.bytezone.diskbrowser.disk.AppleDisk;
@ -40,7 +41,9 @@ class SaveDiskAction extends AbstractSaveAction implements DiskSelectionListener
String suffix = blocks <= 560 ? ".dsk" : ".hdv"; String suffix = blocks <= 560 ? ".dsk" : ".hdv";
setSelectedFile (new File (formattedDisk.getName () + suffix)); setSelectedFile (new File (formattedDisk.getName () + suffix));
saveBuffer (appleDisk.getBuffer ());
if (fileChooser.showSaveDialog (null) == JFileChooser.APPROVE_OPTION)
saveBuffer (appleDisk.getBuffer ());
} }
else else
System.out.println ("Not an AppleDisk"); // impossible System.out.println ("Not an AppleDisk"); // impossible

View File

@ -3,6 +3,8 @@ package com.bytezone.diskbrowser.gui;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.io.File; import java.io.File;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import com.bytezone.diskbrowser.applefile.AppleFileSource; import com.bytezone.diskbrowser.applefile.AppleFileSource;
@ -12,12 +14,15 @@ class SaveFileAction extends AbstractSaveAction implements FileSelectionListener
//-----------------------------------------------------------------------------------// //-----------------------------------------------------------------------------------//
{ {
AppleFileSource appleFileSource; AppleFileSource appleFileSource;
private JCheckBox formatted = new JCheckBox ("Formatted");
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
SaveFileAction () SaveFileAction ()
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
super ("Save file...", "Save currently selected file", "Save File"); super ("Save file...", "Save currently selected file", "Save File");
fileChooser.setAccessory (formatted);
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
@ -31,8 +36,13 @@ class SaveFileAction extends AbstractSaveAction implements FileSelectionListener
return; return;
} }
setSelectedFile (new File (appleFileSource.getUniqueName () + ".bin")); if (fileChooser.showSaveDialog (null) != JFileChooser.APPROVE_OPTION)
saveBuffer (appleFileSource.getDataSource ().getBuffer ()); return;
if (formatted.isSelected ())
saveBuffer (appleFileSource.getDataSource ().getText ().getBytes ());
else
saveBuffer (appleFileSource.getDataSource ().getBuffer ());
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
@ -41,8 +51,9 @@ class SaveFileAction extends AbstractSaveAction implements FileSelectionListener
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
this.appleFileSource = event.appleFileSource; this.appleFileSource = event.appleFileSource;
setEnabled ( setSelectedFile (new File (appleFileSource.getUniqueName () + ".bin"));
event.appleFileSource != null && event.appleFileSource.getDataSource () != null
&& event.appleFileSource.getDataSource ().getBuffer () != null); setEnabled (appleFileSource != null && appleFileSource.getDataSource () != null
&& appleFileSource.getDataSource ().getBuffer () != null);
} }
} }

View File

@ -4,6 +4,7 @@ import java.awt.event.ActionEvent;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import com.bytezone.diskbrowser.disk.Disk; import com.bytezone.diskbrowser.disk.Disk;
@ -41,7 +42,9 @@ class SaveSectorsAction extends AbstractSaveAction implements SectorSelectionLis
blocks.size () == 1 ? disk.readBlock (blocks.get (0)) : disk.readBlocks (blocks); blocks.size () == 1 ? disk.readBlock (blocks.get (0)) : disk.readBlocks (blocks);
setSelectedFile (new File ("SavedSectors.bin")); setSelectedFile (new File ("SavedSectors.bin"));
saveBuffer (buffer);
if (fileChooser.showSaveDialog (null) == JFileChooser.APPROVE_OPTION)
saveBuffer (buffer);
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//

View File

@ -1,7 +1,6 @@
package com.bytezone.diskbrowser.pascal; package com.bytezone.diskbrowser.pascal;
import java.awt.Color; import java.awt.Color;
import java.text.DateFormat;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle; import java.time.format.FormatStyle;
@ -30,7 +29,6 @@ public class PascalDisk extends AbstractFormattedDisk
// -----------------------------------------------------------------------------------// // -----------------------------------------------------------------------------------//
{ {
static final int CATALOG_ENTRY_SIZE = 26; static final int CATALOG_ENTRY_SIZE = 26;
private final DateFormat df = DateFormat.getDateInstance (DateFormat.SHORT);
private final DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDate (FormatStyle.SHORT); private final DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDate (FormatStyle.SHORT);
private final VolumeEntry volumeEntry; private final VolumeEntry volumeEntry;
private final PascalCatalogSector diskCatalogSector; private final PascalCatalogSector diskCatalogSector;
@ -235,7 +233,6 @@ public class PascalDisk extends AbstractFormattedDisk
} }
int lastByte = Utility.getShort (buffer, ptr + 22); int lastByte = Utility.getShort (buffer, ptr + 22);
// GregorianCalendar date = Utility.getPascalDate (buffer, 24);
LocalDate localDate = Utility.getPascalLocalDate (buffer, 24); LocalDate localDate = Utility.getPascalLocalDate (buffer, 24);
String dateString = localDate == null ? "" String dateString = localDate == null ? ""
: localDate.format (DateTimeFormatter.ofLocalizedDate (FormatStyle.SHORT)); : localDate.format (DateTimeFormatter.ofLocalizedDate (FormatStyle.SHORT));