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

📄 accountpanel.java

📁 该系统是一个基于p2p的即时聊天系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                DefaultMutableTreeNode child = new DefaultMutableTreeNode(obj);                accountManagerModel.insertNodeInto(child, ACCOUNT_ROOT, i);            }            accountManagerTree.expandRow(0);        }        /**         * 卸载账号         */        private void unloadAccounts() {            int count = ACCOUNT_ROOT.getChildCount();            for (int i = 0; i < count; i++) {                accountManagerModel.removeNodeFromParent(                    (DefaultMutableTreeNode) ACCOUNT_ROOT.getChildAt(0));            }        }        /**         * 重载账号         */        private void reloadAccounts() {            unloadAccounts();            loadAccounts();        }        /**         * 设置树型组件的附加选项         */        private void setTree() {            DefaultTreeSelectionModel model = new DefaultTreeSelectionModel();            model.setSelectionMode(model.SINGLE_TREE_SELECTION);            accountManagerTree.setSelectionModel(model);            accountManagerTree.setSelectionRow(0);            accountManagerTree.expandRow(0);        }        /**         * 设置树型组件的单元格渲染器         */        private void setTreeCellRenderer() {            final DefaultTreeCellRenderer renderer1 =                (DefaultTreeCellRenderer) accountManagerTree.getCellRenderer();            DefaultTreeCellRenderer renderer2 = new DefaultTreeCellRenderer() {                public Component getTreeCellRendererComponent(JTree tree,                    Object value, boolean selected, boolean expanded,                    boolean leaf, int row, boolean hasFocus) {                    Component c = renderer1.getTreeCellRendererComponent(tree,                        value, selected, expanded, leaf, row, hasFocus);                    JLabel label = (JLabel) c;                    if (value == ACCOUNT_ROOT) {                        label.setIcon(ImageShop.ACCOUNT_ROOT_IMAGEICON);                    } else {                        label.setIcon(ImageShop.ACCOUNT_IMAGEICON);                    }                    return c;                }            };            accountManagerTree.setCellRenderer(renderer2);        }        /**         * 实现TreeSelectionListener接口的方法         *         * @param event TreeSelectionEvent对象         */        public void valueChanged(TreeSelectionEvent event) {            DefaultMutableTreeNode node = (DefaultMutableTreeNode) event                .getPath().getLastPathComponent();            if (node == ACCOUNT_ROOT) {                ActionCenter.getInstance().setActionWhenSelectAccountManager();                accountInfoPanel.setValue(null);            } else {                ActionCenter.getInstance().setActionWhenSelectAccount();                AccountInfo accountInfo = (AccountInfo) node.getUserObject();                accountInfoPanel.setValue(accountInfo);            }            accountInfoPanel.inactivate();        }    }    /**     * 账号信息面板     */    class AccountInfoPanel extends JPanel {        /**         * 个人信息面板         */        private PersonalInfoPanel personalInfoPanel;        /**         * SMTP信息面板         */        private SMTPInfoPanel smtpInfoPanel;        /**         * POP3信息面板         */        private POP3InfoPanel pop3InfoPanel;        /**         * Create a new instance of this class         */        public AccountInfoPanel() {            super(new GridBagLayout());            //个人信息面板            personalInfoPanel = new PersonalInfoPanel();            personalInfoPanel.setBorder(BorderShop.PERSONAL_INFO_BORDER);            GridBagConstraints constraints = new GridBagConstraints(                //gridx, gridy                0, 0,                //gridwidth, gridheight                GridBagConstraints.REMAINDER, 1,                //weightx, weighty                1.0, 0.4,                //anchor                GridBagConstraints.NORTHWEST,                //fill                GridBagConstraints.BOTH,                //insets                new Insets(5, 10, 0, 10),                //ipadx, ipady                0, 0);            add(personalInfoPanel, constraints);            //SMTP信息面板            smtpInfoPanel = new SMTPInfoPanel();            smtpInfoPanel.setBorder(BorderShop.SMTP_INFO_BORDER);            constraints.gridy = 1;            constraints.weighty = 0.3;            add(smtpInfoPanel, constraints);            //POP3信息面板            pop3InfoPanel = new POP3InfoPanel();            pop3InfoPanel.setBorder(BorderShop.POP3_INFO_BORDER);            constraints.gridy = 2;            add(pop3InfoPanel, constraints);        }        /**         * 激活账号信息面板上的所有文本框         */        public void activate() {            personalInfoPanel.activate();            smtpInfoPanel.activate();            pop3InfoPanel.activate();        }        /**         * 禁用账号信息面板上的所有文本框         */        public void inactivate() {            personalInfoPanel.inactivate();            smtpInfoPanel.inactivate();            pop3InfoPanel.inactivate();        }        /**         * 设置显示的账号         *         * @param info 待设置的显示账号         */        public void setValue(AccountInfo info) {            if (info != null) {                PersonalInfo info1 = info.getPersonalInfo();                personalInfoPanel.setName(info1.getName());                personalInfoPanel.setOrganization(info1.getOrganization());                personalInfoPanel.setEmail(info1.getEmail());                personalInfoPanel.setReply(info1.getReply());                SMTPInfo info2 = info.getSMTPInfo();                smtpInfoPanel.setURL(info2.getURL());                smtpInfoPanel.setPort(info2.getPort());                smtpInfoPanel.setUserID(info2.getUserID());                smtpInfoPanel.setPassword(info2.getPassword());                POP3Info info3 = info.getPOP3Info();                pop3InfoPanel.setURL(info3.getURL());                pop3InfoPanel.setPort(info3.getPort());                pop3InfoPanel.setUserID(info3.getUserID());                pop3InfoPanel.setPassword(info3.getPassword());            } else {                personalInfoPanel.setName("");                personalInfoPanel.setOrganization("");                personalInfoPanel.setEmail("");                personalInfoPanel.setReply("");                smtpInfoPanel.setURL("");                smtpInfoPanel.setPort("");                smtpInfoPanel.setUserID("");                smtpInfoPanel.setPassword("");                pop3InfoPanel.setURL("");                pop3InfoPanel.setPort("");                pop3InfoPanel.setUserID("");                pop3InfoPanel.setPassword("");            }        }        /**         * 返回个人信息面板         *         * @return 个人信息面板         */        public PersonalInfoPanel getPersonalInfoPanel() {            return personalInfoPanel;        }        /**         * 返回SMTP信息面板         *         * @return SMTP信息面板         */        public SMTPInfoPanel getSMTPInfoPanel() {            return smtpInfoPanel;        }        /**         * 返回POP3信息面板         *         * @return POP3信息面板         */        public POP3InfoPanel getPOP3InfoPanel() {            return pop3InfoPanel;        }    }    /**     * 个人信息面板     */    class PersonalInfoPanel extends JPanel {        /**         * 姓名文本框         */        private JTextField nameTextField;        /**         * 单位文本框         */        private JTextField orgTextField;        /**         * 电子邮件地址文本框         */        private JTextField emailTextField;        /**         * 回复地址文本框         */        private JTextField replyTextField;        /**         * Create a new instance of this class         */        public PersonalInfoPanel() {            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(5, 10, 0, 0),                //ipadx, ipady                0, 0);            add(new JLabel("姓名:"), constraints);            //姓名文本框            nameTextField = new JTextField();            nameTextField.setEditable(false);            constraints.gridx = 1;            constraints.gridwidth = GridBagConstraints.REMAINDER;            constraints.weightx = 1.0;            constraints.fill = GridBagConstraints.HORIZONTAL;            constraints.insets = new Insets(5, 0, 0, 10);            add(nameTextField, constraints);            //单位标签            constraints.gridx = 0;            constraints.gridy = 1;            constraints.gridwidth = 1;            constraints.weightx = 0.0;            constraints.fill = GridBagConstraints.NONE;            constraints.insets = new Insets(5, 10, 0, 0);            add(new JLabel("单位:"), constraints);            //单位文本框            orgTextField = new JTextField();            orgTextField.setEditable(false);            constraints.gridx = 1;            constraints.gridwidth = GridBagConstraints.REMAINDER;            constraints.weightx = 1.0;            constraints.fill = GridBagConstraints.HORIZONTAL;            constraints.insets = new Insets(5, 0, 0, 10);            add(orgTextField, constraints);            //电子邮件地址标签            constraints.gridx = 0;            constraints.gridy = 2;            constraints.gridwidth = 1;            constraints.weightx = 0.0;            constraints.fill = GridBagConstraints.NONE;            constraints.insets = new Insets(5, 10, 0, 0);            add(new JLabel("电子邮件地址:"), constraints);            //电子邮件地址文本框            emailTextField = new JTextField();            emailTextField.setEditable(false);            constraints.gridx = 1;            constraints.gridwidth = GridBagConstraints.REMAINDER;            constraints.weightx = 1.0;            constraints.fill = GridBagConstraints.HORIZONTAL;            constraints.insets = new Insets(5, 0, 0, 10);            add(emailTextField, constraints);            //回复地址标签            constraints.gridx = 0;            constraints.gridy = 3;            constraints.gridwidth = 1;            constraints.weightx = 0.0;            constraints.weighty = 1.0;            constraints.fill = GridBagConstraints.NONE;            constraints.insets = new Insets(5, 10, 0, 0);            add(new JLabel("回复地址:"), constraints);            //回复地址文本框            replyTextField = new JTextField();            replyTextField.setEditable(false);            constraints.gridx = 1;            constraints.gridwidth = GridBagConstraints.REMAINDER;            constraints.weightx = 1.0;            constraints.fill = GridBagConstraints.HORIZONTAL;            constraints.insets = new Insets(5, 0, 0, 10);            add(replyTextField, constraints);        }        /**         * 激活个人信息面板上的所有文本框         */        public void activate() {            nameTextField.setEditable(true);            orgTextField.setEditable(true);            emailTextField.setEditable(true);            replyTextField.setEditable(true);        }        /**         * 禁用个人信息面板上的所有文本框         */        public void inactivate() {            nameTextField.setEditable(false);            orgTextField.setEditable(false);            emailTextField.setEditable(false);            replyTextField.setEditable(false);        }        /**         * 返回姓名         *         * @return 姓名         */        public String getName() {            return nameTextField.getText().trim();        }        /**         * 设置姓名         *         * @param name 待设置的姓名         */        public void setName(String name) {            nameTextField.setText(name);        }        /**         * 返回单位         *         * @return 单位         */        public String getOrganization() {            return orgTextField.getText().trim();        }        /**         * 设置单位         *         * @param org 待设置的单位         */        public void setOrganization(String org) {            orgTextField.setText(org);        }        /**         * 返回电子邮件地址         *         * @return 电子邮件地址         */        public String getEmail() {            return emailTextField.getText().trim();        }        /**         * 设置电子邮件地址         *         * @param email 待设置的电子邮件地址         */        public void setEmail(String email) {            emailTextField.setText(email);        }        /**         * 返回回复地址         *         * @return 回复地址         */        public String getReply() {            return replyTextField.getText().trim();        }        /**         * 设置回复地址         *         * @param reply 待设置的回复地址         */

⌨️ 快捷键说明

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