📄 envpanel.java
字号:
package codeexport.window;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JTextField;
import codeexport.conf.EnvConfigure;
import codeexport.resources.Resources;
import codeexport.util.ActionRunner;
public class EnvPanel extends JPanel implements ActionListener {
private JTextField projectDirTextField = null;
private JTextField saveDirTextField = null;
private JTextField confFileTextField = null;
private JButton projectDirectoryButton = null;
private JButton saveDirectoryButton = null;
private JButton configureFileButton = null;
private JButton timeSaveButton = null;
private JButton runButton = null;
private JButton resetButton = null;
private JFileChooser fileChooser = null;
private EnvConfigure envConf = null;
public EnvPanel(){
envConf = new EnvConfigure();
initComponents();
}
private void initComponents(){
fileChooser = new JFileChooser();
setLayout(new java.awt.GridLayout(4, 1, 2, 2));
add(getProjectDirPanel());
add(getSaveDirectoryPanel());
add(getConfigureFilePanel());
add(getCommandButtonPanel());
}
private JPanel getProjectDirPanel() {
JPanel panel = new JPanel(new BorderLayout());
projectDirTextField = new JTextField();
projectDirTextField.setText("D:\\CodeExport\\source");
panel.add(projectDirTextField, java.awt.BorderLayout.CENTER);
projectDirectoryButton = new JButton(Resources.getString("ProjectDirectory"));
projectDirectoryButton.addActionListener(this);
panel.add(projectDirectoryButton, java.awt.BorderLayout.EAST);
return panel;
}
private JPanel getSaveDirectoryPanel(){
JPanel panel = new JPanel(new BorderLayout());
saveDirTextField = new JTextField();
saveDirTextField.setText("D:\\CodeExport\\dest");
panel.add(saveDirTextField, java.awt.BorderLayout.CENTER);
saveDirectoryButton = new JButton(Resources.getString("SaveDirectory"));
panel.add(saveDirectoryButton, java.awt.BorderLayout.EAST);
saveDirectoryButton.addActionListener(this);
return panel;
}
private JPanel getConfigureFilePanel() {
JPanel panel = new JPanel(new BorderLayout());
confFileTextField = new JTextField();
confFileTextField.setText("D:\\eclipse3.2\\CodeExport\\project.xml");
panel.add(confFileTextField, java.awt.BorderLayout.CENTER);
configureFileButton = new JButton(Resources.getString("ConfigureFile"));
panel.add(configureFileButton, java.awt.BorderLayout.EAST);
configureFileButton.addActionListener(this);
return panel;
}
private JPanel getCommandButtonPanel(){
JPanel panel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0));
timeSaveButton = new JButton(Resources.getString("TimeSave"));
panel.add(timeSaveButton);
timeSaveButton.addActionListener(this);
runButton = new JButton(Resources.getString("run"));
panel.add(runButton);
runButton.addActionListener(this);
resetButton = new JButton(Resources.getString("reset"));
panel.add(resetButton);
resetButton.addActionListener(this);
return panel;
}
/**
* select the project's directory
*
*/
private void selectProjectDirectory(){
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fileChooser.setMultiSelectionEnabled(false);
int approve = fileChooser.showOpenDialog(null);
if(approve == JFileChooser.APPROVE_OPTION){
File file = fileChooser.getSelectedFile();
projectDirTextField.setText(file.getAbsolutePath());
}
}
/**
* select the saved directory
*
*/
private void selectSaveDirectory(){
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fileChooser.setMultiSelectionEnabled(false);
int approve = fileChooser.showOpenDialog(null);
if(approve == JFileChooser.APPROVE_OPTION){
File file = fileChooser.getSelectedFile();
saveDirTextField.setText(file.getAbsolutePath());
}
}
/**
* select the configure file
*
*/
private void selectConfigureFile(){
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setMultiSelectionEnabled(false);
int approve = fileChooser.showOpenDialog(null);
if(approve == JFileChooser.APPROVE_OPTION){
File file = fileChooser.getSelectedFile();
confFileTextField.setText(file.getAbsolutePath());
}
}
private void doTimeSave(){
}
private void doRun(){
File file = new File(projectDirTextField.getText());
envConf.setProjectDir(file);
file = new File(saveDirTextField.getText());
envConf.setSaveDir(file);
file = new File(confFileTextField.getText());
envConf.setConfFile(file);
(new ActionRunner()).doExport(envConf);
}
private void doReset(){
projectDirTextField.setText("");
saveDirTextField.setText("");
confFileTextField.setText("");
}
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if(source == projectDirectoryButton){
selectProjectDirectory();
return;
}
if(source == saveDirectoryButton){
selectSaveDirectory();
return;
}
if(source == configureFileButton){
selectConfigureFile();
return;
}
if(source == timeSaveButton){
doTimeSave();
return;
}
if(source == runButton){
doRun();
return;
}
if(source == resetButton){
doReset();
return;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -