import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
/**
* The main frame of the application FileCutor
* @author brady
* @version 1.0
*/
public class MainFrame extends JFrame implements ActionListener {
public final static String IDS_APP_TITLE = "FileCutor 1.0";
public final static String IDS_CUT = "切割文件";
public final static String IDS_MERGE = "合并文件";
public final static String IDS_OPEN_FILE = "请选择操作文件";
public final static String IDS_SAVE_PATH = "请选择保存路径";
public final static int ID_CUT_MODE = 1;
public final static int ID_MERGE_MODE = 2;
public final static int ID_MB_UNIT = 0;
public final static int ID_KB_UNIT = 1;
public final static int ID_BYTE_UNIT = 2;
public final static int ID_BUFFER_SIZE = 4096; //4KB
public final static int ID_FILE_CUT = 0x01 << 0;
public final static int ID_FILE_MERGE = 0x01 << 1;
public final static int ID_FILE_ENCRYPT = 0x01 << 2;
private String[] m_aUnit = {"MB","KB","Byte"};
Thread m_thread = null;
JButton m_btnClose = null;
JButton m_btnCutFile = null;
JButton m_btnChooseFile = null;
JButton m_btnChoosePath = null;
JRadioButton m_rdCutFile = null;
JRadioButton m_rdMergeFile = null;
JCheckBox m_cbEncryptFile = null;
JTextArea m_taFileNames = null;
JTextArea m_taSavePath = null;
JTextField m_tfBlockSize = null;
JComboBox m_combUnit = null;
JFileChooser m_fcFile = null;
JProgressBar m_proBar = null;
int m_nWorkMode = ID_CUT_MODE; //1:cut,2:merge
int m_nSizeUnit = ID_MB_UNIT; //0:MB,1:KB,2:Byte
long m_nBlockSize = 0;
boolean m_bEncrypt = false;
boolean m_bIsWorking = false;
String[] m_aFiles = null;
String m_sSavePath = null;
public MainFrame(String title) {
super(title);
m_fcFile = new JFileChooser();
init();
}
public void init() {
Container cp = getContentPane();
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel,BoxLayout.Y_AXIS));
mainPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
JPanel topPanel = createTopPanel();
JPanel filePanel = createFilePanel();
JPanel proBarPanel = createProgressBarPanel();
JPanel btnPanel = createButtonPanel();
topPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
filePanel.setAlignmentX(Component.LEFT_ALIGNMENT);
proBarPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
btnPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
mainPanel.add(topPanel);
mainPanel.add(Box.createRigidArea(new Dimension(0,8)));
mainPanel.add(filePanel);
mainPanel.add(Box.createRigidArea(new Dimension(0,8)));
mainPanel.add(proBarPanel);
mainPanel.add(Box.createRigidArea(new Dimension(0,8)));
mainPanel.add(btnPanel);
mainPanel.add(Box.createRigidArea(new Dimension(0,8)));
cp.add(mainPanel);
pack();
setResizable(false);
centerInScreen();
getRootPane().setDefaultButton(m_btnCutFile);
setVisible(true);
}
public JPanel createTopPanel() {
JPanel panel = new JPanel();
ButtonGroup bg = new ButtonGroup();
m_rdCutFile = new JRadioButton(IDS_CUT,true);
m_rdMergeFile = new JRadioButton(IDS_MERGE,false);
m_rdCutFile.addActionListener(this);
m_rdMergeFile.addActionListener(this);
bg.add(m_rdCutFile);
bg.add(m_rdMergeFile);
panel.setBorder(BorderFactory.createTitledBorder("请选择操作类型"));
panel.setLayout(new BoxLayout(panel,BoxLayout.X_AXIS));
panel.add(Box.createRigidArea(new Dimension(20,0)));
panel.add(m_rdCutFile);
panel.add(m_rdMergeFile);
panel.add(Box.createHorizontalGlue());
return panel;
}
public JPanel createFilePanel() {
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createTitledBorder("请选择操作文件"));
panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
m_btnChooseFile = new JButton("浏览...");
m_btnChooseFile.addActionListener(this);
m_btnChooseFile.setAlignmentY(Component.TOP_ALIGNMENT);
MouseAdapter mouseAdapter = new MouseAdapter() {
//Call this method when mouse is clicked
public void mouseClicked(MouseEvent e) {
String str = m_taFileNames.getText();
if(str == null || str.length() <= 0)
return;
int nCaretPos = m_taFileNames.getCaretPosition();
int beginPos = 0,endPos = 0;
beginPos = str.lastIndexOf('\n', nCaretPos);
beginPos = beginPos != -1 ? beginPos : 0 ;
endPos = str.indexOf('\n', nCaretPos);
endPos = endPos != -1 ? endPos : str.length();
m_taFileNames.select(beginPos,endPos);
}
};
m_taFileNames = new JTextArea(1,28);
m_taFileNames.addMouseListener(mouseAdapter);
JLabel lblFile = new JLabel(" 源文件: ");
lblFile.setAlignmentY(Component.TOP_ALIGNMENT);
JScrollPane sPane = new JScrollPane(m_taFileNames);
sPane.setAlignmentY(Component.TOP_ALIGNMENT);
//top panel
JPanel topPanel = new JPanel();
topPanel.setLayout(new BoxLayout(topPanel,BoxLayout.X_AXIS));
topPanel.add(Box.createRigidArea(new Dimension(20,0)));
topPanel.add(lblFile);
topPanel.add(sPane);
topPanel.add(m_btnChooseFile);
topPanel.add(Box.createHorizontalGlue());
//mid panel
JPanel midPanel = new JPanel();
midPanel.setLayout(new BoxLayout(midPanel,BoxLayout.X_AXIS));
midPanel.add(Box.createRigidArea(new Dimension(20,0)));
JLabel lblSaveTo = new JLabel(" 保存至: ");
lblSaveTo.setAlignmentY(Component.TOP_ALIGNMENT);
m_taSavePath = new JTextArea(1,28);
JScrollPane pathSP = new JScrollPane(m_taSavePath);
pathSP.setAlignmentY(Component.TOP_ALIGNMENT);
m_btnChoosePath = new JButton("浏览...");
m_btnChoosePath.addActionListener(this);
m_btnChoosePath.setAlignmentY(Component.TOP_ALIGNMENT);
midPanel.add(lblSaveTo);
midPanel.add(pathSP);
midPanel.add(m_btnChoosePath);
midPanel.add(Box.createGlue());
//bottom panel
JPanel bottomPanel = new JPanel();
bottomPanel.setLayout(new BoxLayout(bottomPanel,BoxLayout.X_AXIS));
JLabel lblSize = new JLabel(" 块大小: ");
lblSize.setAlignmentY(Component.TOP_ALIGNMENT);
m_tfBlockSize = new JTextField(8);
m_tfBlockSize.setAlignmentY(Component.TOP_ALIGNMENT);
m_combUnit = new JComboBox(m_aUnit);
m_combUnit.setAlignmentY(Component.TOP_ALIGNMENT);
m_combUnit.addActionListener(this);
bottomPanel.add(Box.createRigidArea(new Dimension(20,0)));
bottomPanel.add(lblSize);
bottomPanel.add(m_tfBlockSize);
bottomPanel.add(m_combUnit);
bottomPanel.add(Box.createRigidArea(new Dimension(200,0)));
bottomPanel.add(Box.createHorizontalGlue());
panel.add(topPanel);
panel.add(midPanel);
panel.add(bottomPanel);
panel.add(Box.createVerticalGlue());
return panel;
}
public JPanel createProgressBarPanel() {
JPanel panel = new JPanel();
m_proBar = new JProgressBar(0,100) {
public Dimension getPreferredSize() {
return new Dimension(m_taFileNames.getSize().width + 4, 24);
}
};
m_proBar.setStringPainted(true);
panel.setLayout(new FlowLayout(FlowLayout.LEFT));
panel.add(new JLabel(" 操作进度 "));
panel.add(m_proBar);
return panel;
}
public JPanel createButtonPanel() {
JPanel panel = new JPanel();
m_cbEncryptFile = new JCheckBox("切割时进行加密保护");
m_cbEncryptFile.addActionListener(this);
m_cbEncryptFile.setAlignmentX(Component.LEFT_ALIGNMENT);
m_btnCutFile = new JButton(IDS_CUT);
m_btnCutFile.addActionListener(this);
m_btnClose = new JButton("退出系统");
m_btnClose.addActionListener(this);
panel.setLayout(new BoxLayout(panel,BoxLayout.X_AXIS));
panel.add(m_cbEncryptFile);
panel.add(Box.createHorizontalGlue());
panel.add(m_btnCutFile);
panel.add(m_btnClose);
return panel;
}
public void centerInScreen() {
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension screenDim = tk.getScreenSize();
Dimension dlgDim = getSize();
int x,y;
x = (screenDim.width - dlgDim.width) / 2;
y
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
FileCutor.rar (12个子文件)
FileCutor
.project 385B
bin
MainFrame$2.class 789B
MainFrame$1.class 1KB
Encrypt.class 2KB
MainFrame.class 13KB
CutFile.class 5KB
.settings
org.eclipse.ltk.core.refactoring.prefs 137B
FileCutor.smp 2KB
src
MainFrame.java 14KB
CutFile.java 5KB
Encrypt.java 2KB
.classpath 248B
共 12 条
- 1
资源评论
- zhoujiangzi2012-06-19不错,但是功能上还是有点欠缺 用来查看log文件很好
- wangxinyue_06122013-01-04功能还算不错 自己学到的东西很多吧 但是还需要很多关于java补充的功能
- 漫漫归乡路2012-07-02可以用,正需要,学习了,还可以再改进一下
shingoo
- 粉丝: 0
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功