📄 savesessionaction.java
字号:
package abchr.gui;
import abchr.crypto.BlowfishCipher;
import abchr.crypto.Util;
import guiutils.SimpleFileChooser;
import guiutils.SimpleFileFilter;
import jlfgr.GraphicsRepository;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.*;
import java.util.Random;
class SaveSessionAction extends AbstractAction {
public static boolean USE_ENCRYPTION=false;
public static final byte[] MAGIC=new byte[]{65,66,67,72,82,48,53,49};
private static final Random rand=new Random();
private static final SimpleFileFilter FILE_FILTER=new SimpleFileFilter(".abc","Session files (*.abc)");
private ProjectFrame frame;
public SaveSessionAction(ProjectFrame frame) {
super("Save ABC/HR Session...",GraphicsRepository.getToolbarIcon("general/Save16.gif"));
this.putValue(Action.SHORT_DESCRIPTION,"Save Session...");
this.frame=frame;
}
public void actionPerformed(ActionEvent e) {
File f=SimpleFileChooser.saveFile(frame,FILE_FILTER);
if(f==null){return;}
try {
ByteArrayOutputStream byteArrayOut=new ByteArrayOutputStream();
byteArrayOut.write(MAGIC);
ObjectOutputStream stream=new ObjectOutputStream(byteArrayOut);
stream.writeObject(frame.getProject());
stream.flush();
byte[] buffer=byteArrayOut.toByteArray();
stream.close();
DataOutputStream out=new DataOutputStream(new BufferedOutputStream(new FileOutputStream(f)));
out.write(MAGIC);
if(USE_ENCRYPTION) {
byte[] key=new byte[16];
rand.nextBytes(key);
BlowfishCipher cipher=new BlowfishCipher(Util.bytesToInts(key));
buffer=cipher.encrypt(buffer);
out.write(key);
out.writeInt(buffer.length);
}
out.write(buffer);
out.flush();
out.close();
} catch(IOException e1) {
e1.printStackTrace();
JOptionPane.showMessageDialog(frame,"Could not save file.","Error",JOptionPane.ERROR_MESSAGE);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -