mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-12-21 19:29:20 +00:00
Added a formatted checkbox to the save dialog
This commit is contained in:
parent
37c489f252
commit
898587b23b
@ -88,7 +88,7 @@ public class CPMDisk extends AbstractFormattedDisk
|
||||
if (b1 > 31 && b1 != EMPTY_BYTE_VALUE)
|
||||
break;
|
||||
|
||||
if (b2 < 32 || (b2 > 126 && b2 != EMPTY_BYTE_VALUE))
|
||||
if (b2 <= 32 || (b2 > 126 && b2 != EMPTY_BYTE_VALUE))
|
||||
break;
|
||||
|
||||
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??
|
||||
continue;
|
||||
|
||||
if (b2 < 32 || (b2 > 126 && b2 != EMPTY_BYTE_VALUE))
|
||||
if (b2 <= 32 || (b2 > 126 && b2 != EMPTY_BYTE_VALUE))
|
||||
break;
|
||||
|
||||
DirectoryEntry entry = new DirectoryEntry (this, buffer, i);
|
||||
@ -188,9 +188,8 @@ public class CPMDisk extends AbstractFormattedDisk
|
||||
public AppleFileSource getCatalog ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
String line =
|
||||
"---- --------- --- - - -- -- -- -- ----------------------------"
|
||||
+ "-------------------\n";
|
||||
String line = "---- --------- --- - - -- -- -- -- ----------------------------"
|
||||
+ "-------------------\n";
|
||||
StringBuilder text = new StringBuilder ();
|
||||
text.append (String.format ("File : %s%n%n", getDisplayPath ()));
|
||||
text.append ("User Name Typ R S Ex S2 S1 RC Blocks\n");
|
||||
|
@ -139,9 +139,8 @@ class DirectoryEntry implements AppleFileSource
|
||||
char ro = readOnly ? '*' : ' ';
|
||||
char sf = systemFile ? '*' : ' ';
|
||||
|
||||
String text =
|
||||
String.format ("%3d %-8s %-3s %s %s %02X %02X %02X %02X %s",
|
||||
userNumber, name, type, ro, sf, extent, s2, s1, recordsUsed, bytes);
|
||||
String text = String.format ("%3d %-8s %-3s %s %s %02X %02X %02X %02X %s",
|
||||
userNumber, name, type, ro, sf, extent, s2, s1, recordsUsed, bytes);
|
||||
for (DirectoryEntry entry : entries)
|
||||
text = text + "\n" + entry.line ();
|
||||
|
||||
@ -218,14 +217,13 @@ class DirectoryEntry implements AppleFileSource
|
||||
else if ("DVR".equals (type))
|
||||
appleFile = new DefaultAppleFile (name, exactBuffer, "DVR File");
|
||||
else if ("ASM".equals (type) || "DOC".equals (type) || "COB".equals (type)
|
||||
|| "HLP".equals (type) || "TXT".equals (type) || "LET".equals (type)
|
||||
|| "ALX".equals (type) || "SRC".equals (type) || "H".equals (type)
|
||||
|| exactBuffer[len - 1] == 0x1A)
|
||||
|| "HLP".equals (type) || "TXT".equals (type) || "LET".equals (type) || "ALX".equals (type)
|
||||
|| "SRC".equals (type) || "H".equals (type) || exactBuffer[len - 1] == 0x1A)
|
||||
appleFile = new CPMTextFile (name, exactBuffer);
|
||||
else if ("BAS".equals (type))
|
||||
appleFile = new CPMBasicFile (name, exactBuffer);
|
||||
else
|
||||
appleFile = new DefaultAppleFile (name, exactBuffer, "CPM File : " + type);
|
||||
appleFile = new DefaultAppleFile (name, exactBuffer, "CPM File : " + name + "." + type);
|
||||
|
||||
return appleFile;
|
||||
}
|
||||
|
@ -15,27 +15,21 @@ import com.bytezone.diskbrowser.utilities.DefaultAction;
|
||||
public abstract class AbstractSaveAction extends DefaultAction
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
private JFileChooser fileChooser;
|
||||
private String dialogTitle;
|
||||
protected JFileChooser fileChooser = new JFileChooser ();
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public AbstractSaveAction (String menuText, String tip, String dialogTitle)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super (menuText, tip);
|
||||
this.dialogTitle = dialogTitle;
|
||||
|
||||
fileChooser.setDialogTitle (dialogTitle);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
void setSelectedFile (File file)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (fileChooser == null)
|
||||
{
|
||||
fileChooser = new JFileChooser ();
|
||||
fileChooser.setDialogTitle (dialogTitle);
|
||||
}
|
||||
|
||||
fileChooser.setSelectedFile (file);
|
||||
}
|
||||
|
||||
@ -43,26 +37,22 @@ public abstract class AbstractSaveAction extends DefaultAction
|
||||
void saveBuffer (byte[] buffer)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
if (fileChooser.showSaveDialog (null) != JFileChooser.APPROVE_OPTION)
|
||||
return;
|
||||
|
||||
File file = fileChooser.getSelectedFile ();
|
||||
try
|
||||
{
|
||||
Files.write (file.toPath (), buffer, StandardOpenOption.CREATE_NEW);
|
||||
JOptionPane.showMessageDialog (null,
|
||||
String.format ("File %s saved", file.getName ()));
|
||||
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);
|
||||
JOptionPane.showMessageDialog (null, "File " + file.getName () + " already exists", "Failed",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace ();
|
||||
JOptionPane.showMessageDialog (null, "File failed to save - " + e.getMessage (),
|
||||
"Failed", JOptionPane.ERROR_MESSAGE);
|
||||
JOptionPane.showMessageDialog (null, "File failed to save - " + e.getMessage (), "Failed",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.bytezone.diskbrowser.gui;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.io.File;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import com.bytezone.diskbrowser.disk.AppleDisk;
|
||||
@ -40,7 +41,9 @@ class SaveDiskAction extends AbstractSaveAction implements DiskSelectionListener
|
||||
String suffix = blocks <= 560 ? ".dsk" : ".hdv";
|
||||
|
||||
setSelectedFile (new File (formattedDisk.getName () + suffix));
|
||||
saveBuffer (appleDisk.getBuffer ());
|
||||
|
||||
if (fileChooser.showSaveDialog (null) == JFileChooser.APPROVE_OPTION)
|
||||
saveBuffer (appleDisk.getBuffer ());
|
||||
}
|
||||
else
|
||||
System.out.println ("Not an AppleDisk"); // impossible
|
||||
|
@ -3,6 +3,8 @@ package com.bytezone.diskbrowser.gui;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.io.File;
|
||||
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import com.bytezone.diskbrowser.applefile.AppleFileSource;
|
||||
@ -12,12 +14,15 @@ class SaveFileAction extends AbstractSaveAction implements FileSelectionListener
|
||||
//-----------------------------------------------------------------------------------//
|
||||
{
|
||||
AppleFileSource appleFileSource;
|
||||
private JCheckBox formatted = new JCheckBox ("Formatted");
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
SaveFileAction ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super ("Save file...", "Save currently selected file", "Save File");
|
||||
|
||||
fileChooser.setAccessory (formatted);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@ -31,8 +36,13 @@ class SaveFileAction extends AbstractSaveAction implements FileSelectionListener
|
||||
return;
|
||||
}
|
||||
|
||||
setSelectedFile (new File (appleFileSource.getUniqueName () + ".bin"));
|
||||
saveBuffer (appleFileSource.getDataSource ().getBuffer ());
|
||||
if (fileChooser.showSaveDialog (null) != JFileChooser.APPROVE_OPTION)
|
||||
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;
|
||||
setEnabled (
|
||||
event.appleFileSource != null && event.appleFileSource.getDataSource () != null
|
||||
&& event.appleFileSource.getDataSource ().getBuffer () != null);
|
||||
setSelectedFile (new File (appleFileSource.getUniqueName () + ".bin"));
|
||||
|
||||
setEnabled (appleFileSource != null && appleFileSource.getDataSource () != null
|
||||
&& appleFileSource.getDataSource ().getBuffer () != null);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.awt.event.ActionEvent;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
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);
|
||||
|
||||
setSelectedFile (new File ("SavedSectors.bin"));
|
||||
saveBuffer (buffer);
|
||||
|
||||
if (fileChooser.showSaveDialog (null) == JFileChooser.APPROVE_OPTION)
|
||||
saveBuffer (buffer);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.bytezone.diskbrowser.pascal;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.text.DateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.FormatStyle;
|
||||
@ -30,7 +29,6 @@ public class PascalDisk extends AbstractFormattedDisk
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
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 VolumeEntry volumeEntry;
|
||||
private final PascalCatalogSector diskCatalogSector;
|
||||
@ -235,7 +233,6 @@ public class PascalDisk extends AbstractFormattedDisk
|
||||
}
|
||||
|
||||
int lastByte = Utility.getShort (buffer, ptr + 22);
|
||||
// GregorianCalendar date = Utility.getPascalDate (buffer, 24);
|
||||
LocalDate localDate = Utility.getPascalLocalDate (buffer, 24);
|
||||
String dateString = localDate == null ? ""
|
||||
: localDate.format (DateTimeFormatter.ofLocalizedDate (FormatStyle.SHORT));
|
||||
|
Loading…
Reference in New Issue
Block a user