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

📄 albumpanel.java

📁 数码照片管理程序是我们公司在开发过程中的用java编写的模块
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
								try {
									Thread.sleep(300);// 休眠300毫秒

								} catch (InterruptedException e) {
									e.printStackTrace();
								}
							}
						}
					}.start();
				} else {// 选择的为图片

					addPhoto(selectedFile, upLoadPath);// 添加图片

				}
			}
		}
	}

	private void updPhotoButtonActionPerformed(java.awt.event.ActionEvent evt) {
		// TODO add your handling code here:
		Vector<PhotoPreviewButton> selectedPhoto = PhotoPreviewButton
				.getSelectedPhoto();// 获得选中的照片

		if (selectedPhoto.size() != 1) {// 每次只能修改一张照片

			String message = selectedPhoto.isEmpty() ? "请选择要修改的图片!"
					: "每次只能修改一张图片!";// 定义提示信息

			JOptionPane.showMessageDialog(this, message, "友情提示",
					JOptionPane.INFORMATION_MESSAGE);// 弹出提示框

		} else {
			new UpdatePhotoInfoDialog(null, true, selectedPhoto.firstElement())
					.setVisible(true);// 显示修改信息对话框

		}
	}

	private void delPhotoButtonActionPerformed(java.awt.event.ActionEvent evt) {
		// TODO add your handling code here:
		Vector<PhotoPreviewButton> selectedPhoto = PhotoPreviewButton
				.getSelectedPhoto();// 获得被选中的照片

		if (selectedPhoto.isEmpty()) {// 尚未选中任何照片

			JOptionPane.showMessageDialog(this, "请选择要删除的图片!", "友情提示",
					JOptionPane.INFORMATION_MESSAGE);// 弹出提示

		} else {
			int i = JOptionPane.showConfirmDialog(this, "确定要删除这些照片?", "友情提示",
					JOptionPane.YES_NO_OPTION);// 确认删除

			if (i == 0) {// 确定删除

				MPanel panel = (MPanel) photoPanel.getComponent(0);// 获得浏览方式面板

				JPanel photoBox = panel.getPhotoBoxPanel();// 获得图片箱

				for (int j = 0; j < selectedPhoto.size(); j++) {// 遍历被选中的图片

					PhotoPreviewButton button = selectedPhoto.get(j);// 获得被选中的图片按钮

					photoBox.remove(button);// 从图片箱中移除

					dao.deletePhoto(button.getName());// 从数据库中删除

					new File(button.getPath()).delete();// 删除图片文件

				}

				SwingUtilities.updateComponentTreeUI(photoPanel);// 刷新面板

				selectedPhoto.clear();// 清空被选中的照片

			}
		}
	}

	private void findPhotoButtonActionPerformed(java.awt.event.ActionEvent evt) {
		// TODO add your handling code here:
		MTreeNode selectedNode = (MTreeNode) albumTree
				.getLastSelectedPathComponent();// 获得当前选中的节点

		new FindPhotoInfoDialog(null, true, (selectedNode == null ? 0
				: selectedNode.getId())// 传入当前选中节点的主键
		).setVisible(true);
	}

	private void seeModeComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {
		// TODO add your handling code here:
		if (evt.getStateChange() == ItemEvent.SELECTED) {// 由选中新的项目触发

			int selectedIndex = seeModeComboBox.getSelectedIndex();// 获得选中项的索引值

			switch (selectedIndex) {
			case 0:// 缩略图方式

				photoPanel.remove(0);// 移除幻灯片方式面板

				photoPanel.add(new BreviaryPhotoPanel());// 添加缩略图方式面板

				photoPanel.validate();// 刷新面板

				break;
			case 1:// 幻灯片方式

				photoPanel.remove(0);// 移除缩略图方式面板

				LanternSlidePanel panel = new LanternSlidePanel();// 创建幻灯片方式面板

				if (panel.getPhotoBoxPanel().getComponentCount() > 0) {// 如果存在照片

					PhotoPreviewButton lanternSlide = null;// 幻灯片

					if (PhotoPreviewButton.getSelectedPhoto().size() > 0) {// 如果存在被选中的照片

						lanternSlide = PhotoPreviewButton.getSelectedPhoto()
								.lastElement();// 获得最后一次单击的照片

					} else {// 不存在被选中的照片

						lanternSlide = (PhotoPreviewButton) panel
								.getPhotoBoxPanel().getComponent(0);// 获得第一个照片

					}
					panel.getShowPhotoLabel().setIcon(
							new ImageIcon(lanternSlide.getPath()));// 设置幻灯片

				}
				photoPanel.add(panel);// 添加幻灯片方式面板

				photoPanel.validate();// 刷新面板

				break;
			default:// 播放器方式

				MPanel showPanel = (MPanel) photoPanel.getComponent(0);// 获得浏览方式面板

				Component[] photos = showPanel.getPhotoBoxPanel()
						.getComponents();// 获得照片数组

				if (photos.length > 0) {// 如果存在照片

					new PlayDialog(null, true, photos).setVisible(true);// 显示播放器对话框

				}
				seeModeComboBox.removeItemListener(showModeComboBoxIL);// 移除选项事件监听器

				seeModeComboBox.setSelectedItem(primaryItem);// 设置之前的选中项仍被选中

				seeModeComboBox.addItemListener(showModeComboBoxIL);// 添加选项事件监听器

			}
		} else {// 由取消原选中项触发

			primaryItem = evt.getItem();// 获得原选中项

		}
	}

	private void albumTreeTreeExpanded(javax.swing.event.TreeExpansionEvent evt) {
		// TODO add your handling code here:
		TreePath selectedPath = evt.getPath();// 获得选中节点的路径对象

		MTreeNode lastNode = (MTreeNode) selectedPath.getLastPathComponent();// 获得选中节点对象

		if (!lastNode.isLoad()) {// 如果该节点尚未加载

			loadChildNode(lastNode);// 加载该节点

			treeModel.reload(lastNode);// 刷新树模型

		}
	}

	private void albumTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) {
		// TODO add your handling code here:

		if (loadPhotoThread != null && loadPhotoThread.isAlive()) {// 存在加载图片的线程

			synchronized (loadPhotoThread) {// 将其加入到同步块中

				loadPhotoThread.interrupt();// 中断线程

			}
		}
		final MPanel showPanel = (MPanel) photoPanel.getComponent(0);// 获得浏览方式面板

		final MLabel photoLabel = showPanel.getShowPhotoLabel();// 获得幻灯片标签

		if (photoLabel.getIcon() != null) {// 幻灯片方式

			photoLabel.setIcon(null);// 清空幻灯片

		}

		final JPanel photoBoxPanel = showPanel.getPhotoBoxPanel();// 获得图片箱面板

		if (photoBoxPanel.getComponentCount() > 0) {// 如果图片箱不为空

			photoBoxPanel.removeAll();// 清空图片箱

		}

		String selectedPath = getSelectedPath();// 获得选中相册的路径

		if (selectedPath == null) {// 如果路径为空

			showPanel.validate();// 刷新面板

		} else {// 如果路径不为空

			final File[] photos = new File(selectedPath)
					.listFiles(ioFileFilter);// 获得所有照片对象

			if (photos != null && photos.length > 0) {// 如果有照片

				photoBoxPanel.add(new PhotoPreviewButton(photos[0]));// 添加第一个照片到图片箱

				if (photoLabel != null) {// 幻灯片方式

					photoLabel.setIcon(new ImageIcon(photos[0].getPath()));// 为幻灯片设置照片

				}

				showPanel.validate();// 刷新面板

				loadPhotoThread = new Thread() {// 创建一个用来加载照片到图片箱的线程

					@Override
					public void run() {// 重载该方法

						for (int i = 1; i < photos.length; i++) {// 遍历照片数组

							try {
								Thread.sleep(600);// 休眠6秒

							} catch (InterruptedException e) {
								break;
							}
							photoBoxPanel
									.add(new PhotoPreviewButton(photos[i]));// 添加指定照片到图片箱

							showPanel.validate();// 刷新面板

						}
					}
				};
				loadPhotoThread.start();// 开启线程

			} else {// 如果没有照片

				showPanel.validate();// 刷新面板

			}
		}
	}

	private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {
		// TODO add your handling code here:
		Vector<PhotoPreviewButton> photos = PhotoPreviewButton
				.getSelectedPhoto();// 获得选中的照片

		int amount = photos.size();// 获得选中照片数量

		if (amount == 0) {// 尚未选中任何照片

			JOptionPane.showMessageDialog(null, "请先选择要保存的照片!", "友情提示",
					JOptionPane.INFORMATION_MESSAGE);// 弹出提示信息

		} else {// 存在被选中的照片

			JFileChooser pathChooser = new JFileChooser();// 创建文件选择框对象

			pathChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);// 只允许选择文件夹

			int optionSign = pathChooser.showSaveDialog(this);// 弹出对话框并获得操作标记值

			if (optionSign == JFileChooser.APPROVE_OPTION) {// 如果选择了文件夹

				File selectedPath = pathChooser.getSelectedFile();// 获得选择的文件夹对象

				PhotoPreviewButton lastPhoto = photos.lastElement();// 获得最后一个照片对象

				if (lastPhoto == photos.get(0)) {// 和第一个照片重复

					photos.remove(amount - 1);// 移除最后一个照片

				} else {
					if (lastPhoto == photos.get(amount - 2)) {// 和倒数第二个照片重复

						photos.remove(amount - 1);// 移除最后一个照片

					}
				}
				int num = 1;// 照片编号

				for (PhotoPreviewButton photo : photos) {// 遍历照片

					try {
						InputStream inStream = new FileInputStream(photo
								.getPath()); // 创建文件输入流对象

						String name = (num++) + "、" + photo.getText()
								+ photo.getName().substring(23);// 定义照片名称

						OutputStream outStream = new FileOutputStream(
								selectedPath.getPath() + "/" + name);// 创建文件输出流对象

						int readBytes = 0; // 读取字节数

						byte[] buffer = new byte[10240]; // 定义缓存数组

						while ((readBytes = inStream.read(buffer, 0, 10240)) != -1) { // 从输入流读取数据到缓存数组中

							outStream.write(buffer, 0, readBytes); // 输出缓存数组中的数据到输出流

						}
						outStream.close(); // 关闭输出流对象

						inStream.close(); // 关闭输入流对象

					} catch (Exception e1) {
						e1.printStackTrace();
					}
				}
			}
		}
	}

	// Variables declaration - do not modify
	private javax.swing.JButton addAlbumButton;
	private javax.swing.JButton addPhotoButton;
	private javax.swing.JPanel albumPanel;
	private javax.swing.JScrollPane albumScrollPane;
	private static javax.swing.JTree albumTree;
	private javax.swing.JButton cancelSelectedButton;
	private javax.swing.JButton delAlbumButton;
	private javax.swing.JButton delPhotoButton;
	private javax.swing.JButton findPhotoButton;
	private javax.swing.JToolBar.Separator jSeparator1;
	private javax.swing.JToolBar.Separator jSeparator2;
	private static javax.swing.JPanel photoPanel;
	private javax.swing.JButton saveButton;
	private javax.swing.JComboBox seeModeComboBox;
	private javax.swing.JSplitPane splitPane;
	private javax.swing.JToolBar toolBar;
	private javax.swing.JButton updAlbumButton;
	private javax.swing.JButton updPhotoButton;
	// End of variables declaration
}

⌨️ 快捷键说明

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