📄 opensessionaction.java
字号:
package abchr.gui;
import abchr.TestProject;
import abchr.ProjectLoader;
import abchr.ParseException;
import abchr.crypto.BlowfishCipher;
import abchr.crypto.Cipher;
import abchr.crypto.Util;
import guiutils.SimpleFileChooser;
import guiutils.SimpleFileFilter;
import guiutils.SwingWorker;
import jlfgr.GraphicsRepository;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.*;
import java.util.Arrays;
class OpenSessionAction extends AbstractAction {
private ProjectFrame frame;
private static final SimpleFileFilter FILE_FILTER=new SimpleFileFilter(".abc","Session files (*.abc)");
private final WaitMessageDialog waitDialog;
public OpenSessionAction(ProjectFrame frame) {
super("Open ABC/HR Session...",GraphicsRepository.getToolbarIcon("general/Open16.gif"));
this.putValue(Action.SHORT_DESCRIPTION,"Open a previously saved session");
this.frame=frame;
waitDialog=new WaitMessageDialog(frame,"Please wait");
waitDialog.setText("Loading samples");
}
public void actionPerformed(ActionEvent e) {
final File f=SimpleFileChooser.openFile(frame,FILE_FILTER);
if(f!=null) {
if(!frame.closeProject()){return;}
final SwingWorker worker=new SwingWorker() {
public Object construct() {
DataInputStream in=null;
ObjectInputStream stream=null;
try {
in=new DataInputStream(new BufferedInputStream(new FileInputStream(f)));
byte[] magic=new byte[8];
in.read(magic);
if(!Arrays.equals(magic,SaveSessionAction.MAGIC)) {
throw new IOException("Wrong file format");
}
in.read(magic);
if(!Arrays.equals(magic,SaveSessionAction.MAGIC)) {
byte[] key=new byte[16];
in.read(key);
int length=in.readInt();
byte[] buffer=new byte[length];
in.read(buffer);
in.close();
Cipher cipher=new BlowfishCipher(Util.bytesToInts(key));
buffer=cipher.decrypt(buffer);
stream=new ObjectInputStream(new ByteArrayInputStream(buffer));
} else {
stream=new ObjectInputStream(in);
}
TestProject project=(TestProject)stream.readObject();
frame.load(project);
} catch(IOException e1) {
return e1;
} catch(ClassNotFoundException e1) {
return e1;
} finally {
if(stream!=null){try{stream.close();}catch(IOException e){}}
if(in!=null){try{in.close();}catch(Exception ex){}}
}
return null;
}
public void finished() {
waitDialog.setVisible(false);
}
};
worker.start();
waitDialog.show();
Exception ex=(Exception)worker.get();
if(ex!=null) {
ex.printStackTrace();
JOptionPane.showMessageDialog(frame,"Could not open file.\n"+ex.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -