⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 explorerpanel.java

📁 java案例的源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
					if (optionIndex == 1) {// 移入其他信息库
						Vector infoV = dao.sTypeByUsedExcept("info", typeId);
						String[] infos = new String[infoV.size() + 1];
						infos[0] = "请选择";
						for (int j = 0; j < infoV.size(); j++) {
							infos[j + 1] = ((Vector) infoV.get(j)).get(2)
									.toString();
						}
						Object info = "请选择";
						while (info.equals("请选择")) {
							info = JOptionPane.showInputDialog(null,
									"请选择要移入的信息库:", "友情提示",
									JOptionPane.INFORMATION_MESSAGE, null,
									infos, infos[0]);
							if (info == null)// 用户取消了删除操作
								return;
						}
						int newTypeId = dao.sTypeIdByUsedAndName("info", info
								.toString());
						dao.uPersonnelTypeIdByTypeId(typeId, newTypeId);
					}
					if (optionIndex == 2) {// 删除
						dao.dPersonnelByTypeId(typeId);
					}
				}
				DefaultMutableTreeNode selectedNode = treeNode.getNextNode();
				if (selectedNode == null)
					selectedNode = treeNode.getPreviousNode();
				infoTreeModel.removeNodeFromParent(treeNode);
				infoTree.setSelectionRow(selectedNode.getDepth());
				dao.dTypeByName("info", name);
			}
		});
		URL delInfoTypeUrl = this.getClass().getResource("/img/del_tree.png");
		delInfoTypeButton.setIcon(new ImageIcon(delInfoTypeUrl));
		URL delInfoTypeOverUrl = this.getClass().getResource(
				"/img/del_tree_over.png");
		delInfoTypeButton.setRolloverIcon(new ImageIcon(delInfoTypeOverUrl));
		infoTreeButtonPanel.add(delInfoTypeButton);

		final JPanel infoListPanel = new JPanel();
		infoSplitPane.setRightComponent(infoListPanel);
		infoListPanel.setLayout(new BorderLayout());

		final JScrollPane infoListScrollPane = new JScrollPane();
		infoListPanel.add(infoListScrollPane);

		infoListTableColumnV = new Vector<String>();
		infoListTableColumnV.add("序号");
		infoListTableColumnV.add("编号");
		infoListTableColumnV.add("信息内容");

		infoListTableValueV = new Vector<Vector>();

		infoListTableModel = new DefaultTableModel(infoListTableValueV,
				infoListTableColumnV);

		infoListTable = new MTable(infoListTableModel);
		infoListTable.getSelectionModel().setSelectionMode(
				ListSelectionModel.SINGLE_SELECTION);
		initInfoListTable();
		infoListScrollPane.setViewportView(infoListTable);

		final JPanel infoButtonPanel = new JPanel();
		infoButtonPanel.setLayout(new BoxLayout(infoButtonPanel,
				BoxLayout.Y_AXIS));
		infoListPanel.add(infoButtonPanel, BorderLayout.EAST);

		final MButton addToSendInfoButton = new MButton();
		URL addToSendInfoUrl = this.getClass().getResource(
				"/img/add_to_info.png");
		addToSendInfoButton.setIcon(new ImageIcon(addToSendInfoUrl));
		URL addToSendInfoOverUrl = this.getClass().getResource(
				"/img/add_to_info_over.png");
		addToSendInfoButton
				.setRolloverIcon(new ImageIcon(addToSendInfoOverUrl));
		addToSendInfoButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int selectedRow = infoListTable.getSelectedRow();// 获得信息列表的选中行
				if (selectedRow < 0) {// 未选择任何行
					JOptionPane.showMessageDialog(null, "请选择要编辑的信息!", "友情提示",
							JOptionPane.INFORMATION_MESSAGE);// 弹出提示信息
				} else {
					String info = infoListTable.getValueAt(selectedRow, 2)
							.toString();// 获得信息内容
					if (infoTabbedPane.getSelectedIndex() == 0)// 当前被选中的是“短信内容”面板
						infoTextArea.setText(info);// 添加信息到短信内容文本区域
					else
						// 当前被选中的是“E-mail内容”面板
						emailTextArea.setText(info);// 添加信息到E-mail内容文本区域
				}
			}
		});
		infoButtonPanel.add(addToSendInfoButton);

		final MButton addInfoButton = new MButton();
		URL addInfoUrl = this.getClass().getResource("/img/add_info.png");
		addInfoButton.setIcon(new ImageIcon(addInfoUrl));
		URL addInfoOverUrl = this.getClass().getResource(
				"/img/add_info_over.png");
		addInfoButton.setRolloverIcon(new ImageIcon(addInfoOverUrl));
		addInfoButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) infoTree
						.getLastSelectedPathComponent();
				InfoDialog infoDialog = new InfoDialog("添加信息", treeNode
						.getUserObject().toString(), -1, null);
				infoDialog.setVisible(true);
				initInfoListTable();
			}
		});
		infoButtonPanel.add(addInfoButton);

		final MButton updInfoButton = new MButton();
		URL updInfoUrl = this.getClass().getResource("/img/upd_info.png");
		updInfoButton.setIcon(new ImageIcon(updInfoUrl));
		URL updInfoOverUrl = this.getClass().getResource(
				"/img/upd_info_over.png");
		updInfoButton.setRolloverIcon(new ImageIcon(updInfoOverUrl));
		updInfoButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int selectedRow = infoListTable.getSelectedRow();
				if (selectedRow < 0) {
					JOptionPane.showMessageDialog(null, "请选择要修改的信息!", "友情提示",
							JOptionPane.INFORMATION_MESSAGE);
				} else {
					DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) infoTree
							.getLastSelectedPathComponent();
					int num = (Integer) infoListTable
							.getValueAt(selectedRow, 1);
					String content = infoListTable.getValueAt(selectedRow, 2)
							.toString();
					InfoDialog infoDialog = new InfoDialog("修改信息", treeNode
							.getUserObject().toString(), num, content);
					infoDialog.setVisible(true);
					initInfoListTable();
				}
			}
		});
		infoButtonPanel.add(updInfoButton);

		final MButton delInfoButton = new MButton();
		URL delInfoUrl = this.getClass().getResource("/img/del_info.png");
		delInfoButton.setIcon(new ImageIcon(delInfoUrl));
		URL delInfoOverUrl = this.getClass().getResource(
				"/img/del_info_over.png");
		delInfoButton.setRolloverIcon(new ImageIcon(delInfoOverUrl));
		delInfoButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int selectedRow = infoListTable.getSelectedRow();
				if (selectedRow < 0) {
					JOptionPane.showMessageDialog(null, "请选择要删除的信息!", "友情提示",
							JOptionPane.INFORMATION_MESSAGE);
				} else {
					int num = (Integer) infoListTable
							.getValueAt(selectedRow, 1);
					int i = JOptionPane.showConfirmDialog(null, "确定要删除信息" + num
							+ "?", "友情提示", JOptionPane.YES_NO_OPTION);
					if (i == 0) {
						dao.dInfoByNum(num);
						initInfoListTable();
					}
				}
			}
		});
		infoButtonPanel.add(delInfoButton);
		//
	}

	private void initTree(DefaultMutableTreeNode treeRoot, String used) {// 初始化树的方法
		Vector typeV = dao.sTypeByUsed(used);// 查询用于指定树的类型
		for (int i = 0; i < typeV.size(); i++) {// 遍历向量
			Vector type = (Vector) typeV.get(i);// 获得类型向量
			treeRoot.add(new DefaultMutableTreeNode(type.get(2)));// 将类型添加到树中
		}
	}

	private void initCardListTable() {
		cardListTableValueV.removeAllElements();// 清空名片列表
		DefaultMutableTreeNode cardTreeNode = (DefaultMutableTreeNode) cardTree
				.getLastSelectedPathComponent();// 获得名片夹树的选中节点对象
		if (cardTreeNode != null) {// 判断是否存在选中的节点
			String cardName = cardTreeNode.getUserObject().toString();// 获得选中名片夹的名称
			cardListTableValueV.addAll(dao.sPersonnelVByTypeName(cardName));// 检索名片夹包含的名片
		}
		cardListTableModel.setDataVector(cardListTableValueV,
				cardListTableColumnV);// 刷新名片列表表格模型
	}

	private void initInfoListTable() {
		infoListTableValueV.removeAllElements();
		DefaultMutableTreeNode infoTreeNode = (DefaultMutableTreeNode) infoTree
				.getLastSelectedPathComponent();
		if (infoTreeNode != null) {
			String infoName = infoTreeNode.getUserObject().toString();
			infoListTableValueV.addAll(dao.sInfoVByTypeName(infoName));
		}
		infoListTableModel.setDataVector(infoListTableValueV,
				infoListTableColumnV);
	}

	private boolean isHad(DefaultMutableTreeNode treeNode, String newChildName) {// 验证该名称是否已经存在
		boolean had = false;// 默认为不存在
		int childCount = treeNode.getChildCount();// 获得子节点的数量
		for (int i = 0; i < childCount; i++) {// 遍历子节点
			DefaultMutableTreeNode childTreeNode = (DefaultMutableTreeNode) treeNode
					.getChildAt(i);// 获得子节点对象
			if (childTreeNode.getUserObject().toString().equals(newChildName)) {// 判断名称是否相同
				JOptionPane.showMessageDialog(null, "该名称已经存在!", "友情提示",
						JOptionPane.INFORMATION_MESSAGE);// 弹出该名称已经存在的提示
				had = true;// 该名称已经存在
				break;// 跳出循环,停止遍历后面的子节点
			}
		}
		return had;// 返回结果
	}

	private String addTreeNode(DefaultMutableTreeNode treeNode, String typeName) {
		String nodeName = "";// 创建节点名称为空字符串
		while (nodeName.length() == 0) {// 判断节点名称的长度是否为0
			nodeName = JOptionPane.showInputDialog(null, "请输入" + typeName
					+ "名称:", "新建" + typeName, JOptionPane.INFORMATION_MESSAGE);// 弹出输入框令用户输入名称
			if (nodeName == null) {// 判断节点名称是否为空值
				break;// 为空值即用户取消了新建,则跳出循环
			} else {
				nodeName = nodeName.trim();// 去掉首尾空格
				if (nodeName.length() > 0) {// 判断节点名称的长度是否为0
					if (isHad(treeNode, nodeName))// 如果不为0则判断该名称是否已经存在
						nodeName = "";// 如果存在则设置节点名称为空字符串
				}
			}
		}
		return nodeName;// 返回节点名称
	}

	private String updateTreeNode(DefaultMutableTreeNode treeNode) {
		DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) treeNode
				.getParent();// 获得欲修改节点的父节点
		String newNodeName = ""; // 创建节点名称为空字符串
		while (newNodeName.length() == 0) { // 判断节点名称的长度是否为0
			newNodeName = JOptionPane.showInputDialog(null, "请输入新名称:", "修改名称",
					JOptionPane.INFORMATION_MESSAGE);// 接受用户输入名称
			if (newNodeName == null) { // 判断节点名称是否为空值
				break; // 为空值即用户取消了修改,则跳出循环
			} else {
				newNodeName = newNodeName.trim(); // 去掉首尾空格
				if (newNodeName.length() > 0) {// 判断节点名称的长度是否为0
					if (isHad(parentNode, newNodeName))// 如果不为0则判断该名称是否已经存在
						newNodeName = ""; // 如果存在则设置节点名称为空字符串
				}
			}
		}
		return newNodeName; // 返回节点名称
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -