📄 explorerpanel.java
字号:
cardListPanel.add(cardButtonPanel, BorderLayout.EAST);
final MButton selAllButton = new MButton();
URL selAllUrl = this.getClass().getResource("/img/select_all.png");
selAllButton.setIcon(new ImageIcon(selAllUrl));
URL selAllOverUrl = this.getClass().getResource(
"/img/select_all_over.png");
selAllButton.setRolloverIcon(new ImageIcon(selAllOverUrl));
selAllButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cardListTable.selectAll();// 选中表格中的所有行
}
});
cardButtonPanel.add(selAllButton);
final MButton addToSendListButton = new MButton();
URL addToSendListUrl = this.getClass().getResource(
"/img/add_to_list.png");
addToSendListButton.setIcon(new ImageIcon(addToSendListUrl));
URL addToSendListOverUrl = this.getClass().getResource(
"/img/add_to_list_over.png");
addToSendListButton
.setRolloverIcon(new ImageIcon(addToSendListOverUrl));
addToSendListButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int rowCount = sendListTableModel.getRowCount();// 获得当前收信人列表中的收信人个数
int[] selectedRows = cardListTable.getSelectedRows();// 获得名片列表中的选中行
int index = rowCount + 1;// 初始化收信人列表的序号
for (int selectedRow = 0; selectedRow < selectedRows.length; selectedRow++) {// 遍历选中行
int newNum = (Integer) cardListTable.getValueAt(
selectedRows[selectedRow], 1);// 获得名片编号
boolean had = false;// 默认为未加入收信人列表
for (int row = 0; row < rowCount; row++) {// 遍历收信人列表
int nowNum = (Integer) sendListTableModel.getValueAt(
row, 1);// 获得收信人的编号
if (newNum == nowNum) {// 判断名片编号和收信人编号是否相同
had = true;// 已经加入收信人列表
break;// 跳出循环
}
}
if (!had) {// 未加入收信人列表
Vector rowV = new Vector();// 创建一个代表收信人的向量
rowV.add(index++);// 添加序号
rowV.add(newNum);// 添加编号
rowV.add(cardListTable.getValueAt(
selectedRows[selectedRow], 2));// 添加姓名
sendListTableModel.addRow(rowV);// 加入收信人列表
}
}
cardListTable.clearSelection();// 取消名片列表中的选中行
}
});
cardButtonPanel.add(addToSendListButton);
final MButton addCardButton = new MButton();
URL addCardUrl = this.getClass().getResource("/img/add_info.png");
addCardButton.setIcon(new ImageIcon(addCardUrl));
URL addCardOverUrl = this.getClass().getResource(
"/img/add_info_over.png");
addCardButton.setRolloverIcon(new ImageIcon(addCardOverUrl));
addCardButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (cardTreeRoot.getChildCount() == 0) {// 判断是否存在名片夹
JOptionPane.showMessageDialog(null, "请先建立名片夹!", "友情提示",
JOptionPane.INFORMATION_MESSAGE);// 弹出建立名片夹的提示
} else {
DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) cardTree
.getLastSelectedPathComponent();// 获得当前选中的名片夹
String cardName = treeNode.getUserObject().toString();// 获得名片夹名称
PersonnelDialog personnelDialog = new PersonnelDialog(
"添加名片", cardName, -1);// 创建添加名片的对话框对象
personnelDialog.setVisible(true);// 设置添加名片的对话框为可见
initCardListTable();// 刷新名片列表
}
}
});
cardButtonPanel.add(addCardButton);
final MButton updCardButton = new MButton();
URL updCardUrl = this.getClass().getResource("/img/upd_info.png");
updCardButton.setIcon(new ImageIcon(updCardUrl));
URL updCardOverUrl = this.getClass().getResource(
"/img/upd_info_over.png");
updCardButton.setRolloverIcon(new ImageIcon(updCardOverUrl));
updCardButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int[] selectedRows = cardListTable.getSelectedRows();// 获得名片列表中的选中行
if (selectedRows.length == 1) {// 仅选中了一个名片
int num = (Integer) cardListTable.getValueAt(
selectedRows[0], 1);// 获得选中名片的编号
PersonnelDialog personnelDialog = new PersonnelDialog(
"修改名片", "", num);// 创建修改名片的对话框对象
personnelDialog.setVisible(true);// 设置修改名片的对话框为可见
initCardListTable();
} else {
if (selectedRows.length == 0) {// 未选中要修改的名片
JOptionPane.showMessageDialog(null, "请选择要修改的人员!",
"友情提示", JOptionPane.INFORMATION_MESSAGE);// 弹出提示信息
} else {// 选中了多个名片
JOptionPane.showMessageDialog(null, "一次只能修改一个人员!",
"友情提示", JOptionPane.INFORMATION_MESSAGE);// 弹出提示信息
}
}
}
});
cardButtonPanel.add(updCardButton);
final MButton delCardButton = new MButton();
URL delCardUrl = this.getClass().getResource("/img/del_info.png");
delCardButton.setIcon(new ImageIcon(delCardUrl));
URL delCardOverUrl = this.getClass().getResource(
"/img/del_info_over.png");
delCardButton.setRolloverIcon(new ImageIcon(delCardOverUrl));
delCardButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int[] selectedRows = cardListTable.getSelectedRows();// 获得名片列表中的选中行
if (selectedRows.length == 0) {// 未选中要删除的名片
JOptionPane.showMessageDialog(null, "请选择要删除的人员!", "友情提示",
JOptionPane.INFORMATION_MESSAGE);// 弹出提示信息
} else {
String[] infos = new String[selectedRows.length + 1];// 组织提示信息
infos[0] = "确定要删除以下人员:";// 添加提示信息
for (int i = 0; i < selectedRows.length; i++) {// 遍历选中的名片
infos[i + 1] = " "
+ cardListTable.getValueAt(selectedRows[i], 1)// 获得名片编号
+ " "
+ cardListTable.getValueAt(selectedRows[i], 2);// 获得名片名称
}
int i = JOptionPane.showConfirmDialog(null, infos, "友情提示",
JOptionPane.YES_NO_OPTION);// 弹出提示信息
if (i == 0) {// 确定删除
for (int j = 0; j < selectedRows.length; j++) {// 遍历选中的名片
int num = (Integer) cardListTable.getValueAt(
selectedRows[j], 1);// 获得名片编号
dao.dPersonnelByNum(num);// 从数据库删除
}
initCardListTable();// 刷新名片列表
}
}
}
});
cardButtonPanel.add(delCardButton);
final JSplitPane infoSplitPane = new JSplitPane();
infoSplitPane.setOneTouchExpandable(true);
infoSplitPane.setDividerSize(12);
infoSplitPane.setDividerLocation(244);
tabbedPane.addTab("信息库", null, infoSplitPane, null);
final JPanel infoTreePanel = new JPanel();
infoSplitPane.setLeftComponent(infoTreePanel);
infoTreePanel.setLayout(new BorderLayout());
final JScrollPane infoTreeScrollPane = new JScrollPane();
infoTreePanel.add(infoTreeScrollPane);
infoTreeRoot = new DefaultMutableTreeNode("root");
initTree(infoTreeRoot, "info");
infoTreeModel = new DefaultTreeModel(infoTreeRoot);
infoTree = new JTree(infoTreeModel);
infoTree.setRootVisible(false);
if (infoTreeRoot.getChildCount() > 0)
infoTree.setSelectionRow(0);
infoTree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
initInfoListTable();
}
});
infoTreeScrollPane.setViewportView(infoTree);
final JPanel infoTreeButtonPanel = new JPanel();
final FlowLayout flowLayout = new FlowLayout();
flowLayout.setVgap(0);
flowLayout.setHgap(0);
infoTreeButtonPanel.setLayout(flowLayout);
infoTreePanel.add(infoTreeButtonPanel, BorderLayout.SOUTH);
final MButton addInfoTypeButton = new MButton();
addInfoTypeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = addTreeNode(infoTreeRoot, "信息库");
if (name != null) {
int childCount = infoTreeRoot.getChildCount();
infoTreeModel.insertNodeInto(new DefaultMutableTreeNode(
name), infoTreeRoot, childCount);
infoTreeModel.reload();
infoTree.setSelectionRow(childCount);
dao.iType(name, "info");
}
}
});
URL creInfoTypeUrl = this.getClass().getResource("/img/add_tree.png");
addInfoTypeButton.setIcon(new ImageIcon(creInfoTypeUrl));
URL creInfoTypeOverUrl = this.getClass().getResource(
"/img/add_tree_over.png");
addInfoTypeButton.setRolloverIcon(new ImageIcon(creInfoTypeOverUrl));
infoTreeButtonPanel.add(addInfoTypeButton);
final MButton updInfoTypeButton = new MButton();
updInfoTypeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
TreePath selectionPath = infoTree.getSelectionPath();
if (selectionPath == null) {
JOptionPane.showMessageDialog(null, "请选择要修改的信息库!", "友情提示",
JOptionPane.INFORMATION_MESSAGE);
} else {
DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) selectionPath
.getLastPathComponent();
String nowName = treeNode.getUserObject().toString();
int i = JOptionPane.showConfirmDialog(null, "确定要修改信息库“"
+ nowName + "”的名称?", "友情提示",
JOptionPane.YES_NO_OPTION);
if (i == 0) {
String newName = updateTreeNode(treeNode);
if (newName != null) {
treeNode.setUserObject(newName);
infoTreeModel.reload();
infoTree.setSelectionPath(selectionPath);
dao.uTypeNameByName("info", nowName, newName);
}
}
}
}
});
URL updInfoTypeUrl = this.getClass().getResource("/img/upd_tree.png");
updInfoTypeButton.setIcon(new ImageIcon(updInfoTypeUrl));
URL updInfoTypeOverUrl = this.getClass().getResource(
"/img/upd_tree_over.png");
updInfoTypeButton.setRolloverIcon(new ImageIcon(updInfoTypeOverUrl));
infoTreeButtonPanel.add(updInfoTypeButton);
final MButton delInfoTypeButton = new MButton();
delInfoTypeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) infoTree
.getLastSelectedPathComponent();
if (treeNode == null) {// 未选择要删除的信息库
JOptionPane.showMessageDialog(null, "请选择要删除的信息库!", "友情提示",
JOptionPane.INFORMATION_MESSAGE);
return;
}
String name = treeNode.getUserObject().toString();
int i = JOptionPane.showConfirmDialog(null, "确定要删除信息库“" + name
+ "”?", "友情提示", JOptionPane.YES_NO_OPTION);
if (i != 0)// 用户取消了删除操作
return;
if (dao.sInfoVByTypeName(name).size() > 0) {
String options[] = { "取消", "移入其他信息库", "删除" };
int optionIndex = JOptionPane.showOptionDialog(null,
"请选择对该信息库下信息的处理方式:", "友情提示",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE, null, options,
options[0]);
int typeId = dao.sTypeIdByUsedAndName("info", name);
if (optionIndex == 0)// 用户取消了删除操作
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -