📄 filepanel.java
字号:
/* * @(#) FilePanel.java * Copyright 2004 HWStudio. All rights reserved. */package hws.item.smart.panel.function.admin;//导入核心Java类库import java.awt.Insets;import java.awt.Component;import java.awt.FlowLayout;import java.awt.GridBagLayout;import java.awt.GridBagConstraints;import java.util.List;import javax.swing.JTree;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JButton;import javax.swing.JSplitPane;import javax.swing.JScrollPane;import javax.swing.tree.DefaultTreeModel;import javax.swing.tree.DefaultMutableTreeNode;import javax.swing.tree.DefaultTreeCellRenderer;import javax.swing.tree.DefaultTreeSelectionModel;import javax.swing.event.TreeSelectionEvent;import javax.swing.event.TreeSelectionListener;//导入自定义Java类库import hws.item.smart.misc.ImageShop;import hws.item.smart.misc.SBChanger;import hws.item.smart.action.admin.file.StopFileAction;import hws.item.smart.action.admin.file.StartFileAction;import hws.item.smart.action.admin.file.RestartFileAction;import hws.item.smart.utility.chat.UserInfo;import hws.item.smart.utility.admin.XMLAccessor;import hws.item.smart.utility.admin.FileService;import hws.item.smart.utility.share.ShareInfo;import hws.item.smart.utility.share.SharesInfo;//导入第三方Java类库import org.jdom.Element;/** * 获取服务面板 * * @version 0.1 2005-08-25 * @author Hwerz */public class FilePanel extends JPanel { /*------------------------------------------------------------------------* * 属性定义 * *------------------------------------------------------------------------*/ /** * 文件树根节点 */ private static final DefaultMutableTreeNode FILE_ROOT = new DefaultMutableTreeNode("共享文件"); /** * 好友树根节点 */ private static final DefaultMutableTreeNode FRIEND_ROOT = new DefaultMutableTreeNode("共享好友"); /** * 该类自身的一个静态引用 */ private static FilePanel panel; /** * 文件视图 */ private FileViewPanel fileViewPanel; /** * 好友视图 */ private FriendViewPanel friendViewPanel; /*------------------------------------------------------------------------* * 构造函数 * *------------------------------------------------------------------------*/ /** * 构造函数为私有,这样在整个运行过程中该类就只能有一个实例 */ private FilePanel() { super(new GridBagLayout()); //启动文件服务 FileService.getInstance().start(); //工具栏面板 GridBagConstraints constraints = new GridBagConstraints( //gridx, gridy 0, 0, //gridwidth, gridheight 1, 1, //weightx, weighty 1.0, 0.0, //anchor GridBagConstraints.NORTH, //fill GridBagConstraints.HORIZONTAL, //insets new Insets(5, 0, 0, 0), //ipadx, ipady 0, 0); add(new Toolbar(), constraints); //分割条面板 friendViewPanel = new FriendViewPanel(); fileViewPanel = new FileViewPanel(); JSplitPane spliter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, fileViewPanel, friendViewPanel); spliter.setOneTouchExpandable(true); spliter.setDividerLocation(200); constraints.gridy = 1; constraints.weighty = 1.0; constraints.fill = GridBagConstraints.BOTH; constraints.insets = new Insets(5, 5, 5, 5); add(spliter, constraints); } /*------------------------------------------------------------------------* * 公共方法 * *------------------------------------------------------------------------*/ /** * 对该类提供的一个全局访问点,用来实例化该对象 * * @return 该类唯一的一个实例 */ public static FilePanel getInstance() { if (panel == null) { panel = new FilePanel(); } return panel; } /** * 刷新 */ public void refresh() { fileViewPanel.reloadFiles(); } /*------------------------------------------------------------------------* * 私有方法 * *------------------------------------------------------------------------*/ /** * 设置树型组件的附加选项 * * @param tree 待设置的树型组件 */ private void setTree(JTree tree) { DefaultTreeSelectionModel model = new DefaultTreeSelectionModel(); model.setSelectionMode(model.SINGLE_TREE_SELECTION); tree.setSelectionModel(model); tree.setSelectionRow(0); tree.expandRow(0); } /*------------------------------------------------------------------------* * 内部类 * *------------------------------------------------------------------------*/ /** * 工具栏面板 */ class Toolbar extends JPanel { /** * Create a new instance of this class */ public Toolbar() { super(new FlowLayout(FlowLayout.CENTER, 5, 0)); //启动服务 JButton button = new JButton(StartFileAction.getInstance()); button.setIcon(ImageShop.START_IMAGEICON); button.addMouseListener(new SBChanger( StartFileAction.getInstance().getHintInfo(), false)); add(button); //停止服务 button = new JButton(StopFileAction.getInstance()); button.setIcon(ImageShop.STOP_IMAGEICON); button.addMouseListener(new SBChanger( StopFileAction.getInstance().getHintInfo(), false)); add(button); //重启服务 button = new JButton(RestartFileAction.getInstance()); button.setIcon(ImageShop.RESTART_IMAGEICON); button.addMouseListener(new SBChanger( RestartFileAction.getInstance().getHintInfo(), false)); add(button); } } /** * 文件视图 */ class FileViewPanel extends JPanel implements TreeSelectionListener { /** * 文件树的视图 */ private JTree fileTree; /** * 文件树的模型 */ private DefaultTreeModel fileModel; /** * Create a new instance of this class */ public FileViewPanel() { super(new GridBagLayout()); //文件视图标签 GridBagConstraints constraints = new GridBagConstraints( //gridx, gridy 0, 0, //gridwidth, gridheight 1, 1, //weightx, weighty 0.0, 0.0, //anchor GridBagConstraints.NORTHWEST, //fill GridBagConstraints.NONE, //insets new Insets(0, 5, 0, 0), //ipadx, ipady 0, 0); add(new JLabel("文件视图"), constraints); //树型组件 fileModel = new DefaultTreeModel(FILE_ROOT); fileTree = new JTree(fileModel); fileTree.addTreeSelectionListener(this);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -