2020-01-13 00:05:32 +00:00
|
|
|
package com.bytezone.diskbrowser.gui;
|
|
|
|
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.StandardOpenOption;
|
|
|
|
|
|
|
|
import javax.swing.JFileChooser;
|
|
|
|
import javax.swing.JOptionPane;
|
|
|
|
|
|
|
|
import com.bytezone.common.DefaultAction;
|
|
|
|
|
2020-02-08 22:20:08 +00:00
|
|
|
// -----------------------------------------------------------------------------------//
|
|
|
|
class SaveSectorsAction extends DefaultAction implements SectorSelectionListener
|
|
|
|
// -----------------------------------------------------------------------------------//
|
2020-01-13 00:05:32 +00:00
|
|
|
{
|
|
|
|
SectorSelectedEvent event;
|
|
|
|
|
2020-02-08 22:20:08 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
|
|
|
SaveSectorsAction ()
|
|
|
|
// ---------------------------------------------------------------------------------//
|
2020-01-13 00:05:32 +00:00
|
|
|
{
|
|
|
|
super ("Save sectors...", "Save sectors");
|
|
|
|
this.setEnabled (false);
|
|
|
|
}
|
|
|
|
|
2020-02-08 22:20:08 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2020-01-13 00:05:32 +00:00
|
|
|
@Override
|
|
|
|
public void actionPerformed (ActionEvent evt)
|
2020-02-08 22:20:08 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2020-01-13 00:05:32 +00:00
|
|
|
{
|
|
|
|
if (event == null)
|
|
|
|
{
|
|
|
|
System.out.println ("No sectors");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
byte[] buffer =
|
2020-04-10 23:47:52 +00:00
|
|
|
event.getFormattedDisk ().getDisk ().readBlocks (event.getSectors ());
|
2020-01-13 00:05:32 +00:00
|
|
|
|
|
|
|
JFileChooser fileChooser = new JFileChooser ();
|
|
|
|
fileChooser.setDialogTitle ("Save sectors");
|
|
|
|
fileChooser.setSelectedFile (new File ("saved-" + buffer.length + ".bin"));
|
|
|
|
if (fileChooser.showSaveDialog (null) == JFileChooser.APPROVE_OPTION)
|
|
|
|
{
|
|
|
|
File file = fileChooser.getSelectedFile ();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Files.write (file.toPath (), buffer, StandardOpenOption.CREATE_NEW);
|
|
|
|
JOptionPane.showMessageDialog (null, "File saved");
|
|
|
|
}
|
|
|
|
catch (IOException e)
|
|
|
|
{
|
|
|
|
e.printStackTrace ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-08 22:20:08 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2020-01-13 00:05:32 +00:00
|
|
|
@Override
|
|
|
|
public void sectorSelected (SectorSelectedEvent event)
|
2020-02-08 22:20:08 +00:00
|
|
|
// ---------------------------------------------------------------------------------//
|
2020-01-13 00:05:32 +00:00
|
|
|
{
|
|
|
|
this.event = event;
|
|
|
|
this.setEnabled (true);
|
|
|
|
}
|
|
|
|
}
|