📄 projectframe.java
字号:
package abchr.gui;
import abchr.TestProject;
import abchr.audio.PlaybackThread;
import abchr.settings.SettingsDialog;
import guiutils.LineLayout;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import jlfgr.GraphicsRepository;
public class ProjectFrame extends JFrame {
private TestProject project=null;
private boolean testActive=false;
private AbchrPanel testPanel=null;
private JMenu fileMenu;
private class NewABXAction extends AbstractAction {
public NewABXAction() {
super("New ABX Test...",GraphicsRepository.getToolbarIcon("general/New16.gif"));
}
public void actionPerformed(ActionEvent e) {
newABXTest();
}
}
private JMenuItem saveSessionItem;
private JMenuItem closeTestItem;
private JPanel startPanel;
public ProjectFrame() {
super("ABC/Hidden Reference for Java");
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
JMenuBar menuBar=new JMenuBar();
fileMenu=new JMenu("File");
JMenuItem mi;
fileMenu.add(new SetupTestAction(this));
fileMenu.add(new NewABXAction());
fileMenu.add(new LoadConfigAction(this));
fileMenu.addSeparator();
fileMenu.add(new OpenSessionAction(this));
saveSessionItem=new JMenuItem(new SaveSessionAction(this));
fileMenu.add(saveSessionItem);
closeTestItem=new JMenuItem("Close Test");
closeTestItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){closeProject();}
});
fileMenu.add(closeTestItem);
fileMenu.addSeparator();
fileMenu.add(new ExitAction(this));
menuBar.add(fileMenu);
JMenu optionsMenu=new JMenu("Options");
JCheckBoxMenuItem fastSwitchingItem=new JCheckBoxMenuItem("Fast Switching",true);
fastSwitchingItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PlaybackThread.getInstance().setFastSwitching(((JCheckBoxMenuItem)e.getSource()).getState());
}
});
optionsMenu.add(fastSwitchingItem);
JCheckBoxMenuItem loopItem=new JCheckBoxMenuItem("Loop",false);
loopItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PlaybackThread.getInstance().setLooping(((JCheckBoxMenuItem)e.getSource()).getState());
}
});
optionsMenu.add(loopItem);
optionsMenu.addSeparator();
JMenuItem settingsItem=new JMenuItem("Settings...");
settingsItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){showSettingsDialog();}
});
optionsMenu.add(settingsItem);
menuBar.add(optionsMenu);
JMenu toolsMenu=new JMenu("Tools");
//toolsMenu.add(new DecryptResultsAction(this));
toolsMenu.add(new DecryptResultsActionNew(this));
menuBar.add(toolsMenu);
JMenu helpMenu=new JMenu("Help");
mi=new JMenuItem("About");
mi.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(ProjectFrame.this,
System.getProperty("abchr-java-versionstring-long")+"\n\n" +
"Java Version by schnofler\n\n" +
"Many ideas and concepts of this program\n" +
"were originally developed by ff123 in his\n" +
"ABC/HR tool for Windows.\n" +
"http://ff123.net/abchr/abchr.html\n\n" +
"This product includes software developed by the\n"+
"JDOM Project (http://www.jdom.org/).\n\n" +
"ABC/HR for Java uses Sean Luke's Java implementation\n" +
"(http://www.cs.umd.edu/users/seanl/gp) of the\n" +
"MersenneTwister algorithm, originally developed by\n" +
"Makoto Matsumoto and Takuji Nishimura\n\n" +
"ABC/HR for Java uses the Looks-L&F\n" +
"by Karsten Lentzsch (http://www.jgoodies.com)",
"About ABC/HR for Java",JOptionPane.INFORMATION_MESSAGE);
}
});
helpMenu.add(mi);
menuBar.add(helpMenu);
this.setJMenuBar(menuBar);
saveSessionItem.setEnabled(false);
closeTestItem.setEnabled(false);
startPanel=new JPanel(new LineLayout(10,10,LineLayout.CENTER,LineLayout.CENTER,true));
startPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
startPanel.add(new JButton(new SetupTestAction(this)));
startPanel.add(new JButton(new NewABXAction()));
startPanel.add(LineLayout.lineBreak());
startPanel.add(new JButton(new LoadConfigAction(this)));
startPanel.add(new JButton(new OpenSessionAction(this)));
this.setContentPane(startPanel);
this.setBounds(100,100,400,150);
this.setVisible(true);
}
private void newABXTest() {
closeProject();
ABXPanel abxPanel=new ABXPanel();
JMenuItem mi=new JMenuItem(new SaveABXLogAction(abxPanel));
fileMenu.add(mi,3);
this.setContentPane(abxPanel);
this.setSize(500,getContentPane().getPreferredSize().height+getInsets().top+getInsets().bottom);
closeTestItem.setEnabled(true);
testActive=true;
this.validate();
System.gc();
}
private SettingsDialog settingsDialog=null;
private void showSettingsDialog() {
if(settingsDialog==null){settingsDialog=new SettingsDialog(this,settingsList);}
settingsDialog.show();
}
public boolean closeProject() {
if(!testActive){return true;}
PlaybackThread.getInstance().stopPlayback();
if(project!=null) {
int option=JOptionPane.showConfirmDialog(this,"Do you want to save your current session first?","Open session",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE);
if(option==JOptionPane.CANCEL_OPTION){return false;}
if(option==JOptionPane.YES_OPTION) {
new SaveSessionAction(this).actionPerformed(new ActionEvent(this,0,""));
}
}
this.project=null;
if(testPanel!=null){testPanel.shutdown();}
testPanel=null;
this.setContentPane(startPanel);
this.setBounds(100,100,400,150);
fileMenu.remove(3);
saveSessionItem.setEnabled(false);
closeTestItem.setEnabled(false);
System.gc();
this.validate();
return true;
}
public void load(TestProject project) {
this.project=project;
saveSessionItem.setEnabled(true);
closeTestItem.setEnabled(true);
JMenuItem mi=new JMenuItem(new SaveResultsAction(project,this));
fileMenu.add(mi,3);
this.setContentPane(testPanel=new AbchrPanel(project));
testActive=true;
this.setSize(790,testPanel.getPreferredSize().height+getInsets().top+getInsets().bottom);
this.validate();
System.gc();
}
public TestProject getProject(){return project;}
private static List settingsList;
static {
BufferedReader reader=null;
try {
String line;
settingsList=new ArrayList(4);
reader=new BufferedReader(new InputStreamReader(ClassLoader.getSystemResourceAsStream("settings.cfg")));
while((line=reader.readLine())!=null) {
settingsList.add(Class.forName(line).newInstance());
}
} catch(FileNotFoundException e) {
e.printStackTrace();
} catch(IOException e) {
e.printStackTrace();
} catch(ClassNotFoundException e) {
e.printStackTrace();
} catch(InstantiationException e) {
e.printStackTrace();
} catch(IllegalAccessException e) {
e.printStackTrace();
} finally {
try{if(reader!=null){reader.close();}}catch(IOException e){}
}
}
public void setProject(TestProject project) {
this.project=project;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -