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

📄 buddylistoptionsmenu.java

📁 网站即时通讯系统
💻 JAVA
字号:
/* Copyright (C) 2003 Adam Olsen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */package com.valhalla.jbother.menus;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.KeyEvent;import java.util.Locale;import java.util.ResourceBundle;import javax.swing.JCheckBoxMenuItem;import javax.swing.JMenu;import javax.swing.JMenuItem;import javax.swing.JOptionPane;import org.jivesoftware.smack.AccountManager;import org.jivesoftware.smack.XMPPException;import com.valhalla.gui.DialogTracker;import com.valhalla.gui.Standard;import com.valhalla.jbother.BuddyList;import com.valhalla.jbother.ChangePasswordDialog;import com.valhalla.jbother.ConsolePanel;import com.valhalla.jbother.JBother;import com.valhalla.jbother.MessageDelegator;import com.valhalla.jbother.PriorityDialog;import com.valhalla.jbother.jabber.BuddyStatus;import com.valhalla.jbother.jabber.ParsedBuddyInfo;import com.valhalla.jbother.preferences.PreferencesDialog;import com.valhalla.pluginmanager.PluginManager;import com.valhalla.settings.Arguments;import com.valhalla.settings.Settings;import com.valhalla.jbother.actions.*;/** * The Options menu for JBother * * @author Adam Olsen * @version 1.0 */class BuddyListOptionsMenu extends JMenu {    private ResourceBundle resources = ResourceBundle.getBundle(            "JBotherBundle", Locale.getDefault());    private JCheckBoxMenuItem offlineBuddies = new JCheckBoxMenuItem(resources            .getString("showOfflineBuddies"));    private JCheckBoxMenuItem unfiledBuddies = new JCheckBoxMenuItem(resources            .getString("showUnfiledBuddies"));    private JCheckBoxMenuItem agentBuddies = new JCheckBoxMenuItem(resources            .getString("showAgentBuddies"));    private JCheckBoxMenuItem agentMessages = new JCheckBoxMenuItem(resources            .getString("receiveAgentMessages"));    private JMenuItem priority = new JMenuItem(resources            .getString("setPriority"));    private JMenuItem prefsItem = new JMenuItem(resources            .getString("preferences"));    private JMenuItem pluginItem = new JMenuItem(resources            .getString("pluginManager"));    private JCheckBoxMenuItem sortItem = new JCheckBoxMenuItem(resources            .getString("sortByStatus"));    private JMenuItem deleteAccount = new JMenuItem(resources            .getString("deleteAccount"));    private JMenu managementMenu = new JMenu(resources            .getString("accountManagement"));    private JMenuItem changePassword = new JMenuItem(resources            .getString("changePassword"));    private JMenuItem consoleItem = new JMenuItem(resources            .getString("xmlConsole"));    /**     * Creates the menu, adds the various items to it     */    public BuddyListOptionsMenu() {        super("Options");        setText(resources.getString("options"));        offlineBuddies.setMnemonic(KeyEvent.VK_H);        unfiledBuddies.setMnemonic(KeyEvent.VK_U);        agentBuddies.setMnemonic(KeyEvent.VK_A);        agentMessages.setMnemonic(KeyEvent.VK_R);        sortItem.setMnemonic(KeyEvent.VK_S);        priority.setMnemonic(KeyEvent.VK_I);        prefsItem.setMnemonic(KeyEvent.VK_P);        pluginItem.setMnemonic(KeyEvent.VK_M);        managementMenu.setMnemonic(KeyEvent.VK_E);        changePassword.setMnemonic(KeyEvent.VK_C);        ShowOfflineAction.addItem( offlineBuddies );        MenuActionListener listener = new MenuActionListener();        prefsItem.addActionListener(listener);        unfiledBuddies.addActionListener(listener);        agentBuddies.addActionListener(listener);        pluginItem.addActionListener(listener);        agentMessages.addActionListener(listener);        priority.addActionListener(listener);        sortItem.addActionListener(listener);        consoleItem.addActionListener(listener);        //get the settings for the "show" states        offlineBuddies.setState(Settings.getInstance().getBoolean(                "showOfflineBuddies"));        unfiledBuddies.setState(Settings.getInstance().getBoolean(                "showUnfiledBuddies"));        agentBuddies.setState(Settings.getInstance().getBoolean(                "showAgentBuddies"));        agentMessages.setState(Settings.getInstance().getBoolean(                "showAgentMessages"));        sortItem.setState(Settings.getInstance().getBoolean("sortByStatus"));        managementMenu.add(changePassword);        managementMenu.add(deleteAccount);        deleteAccount.addActionListener(listener);        changePassword.addActionListener(listener);        add(offlineBuddies);        add(unfiledBuddies);        add(agentBuddies);        add(agentMessages);        add(sortItem);        add(consoleItem);        add(priority);        if (Arguments.getInstance().getProperty("webstart") == null) {            add(pluginItem);        }        add(prefsItem);        add(managementMenu);    }    /**     * @param var     *            true if this is OS X     */    public void setOSX(boolean var) {        if (var) {            remove(prefsItem);        } else {            if (!isMenuComponent(prefsItem))                insert(prefsItem, getItemCount() - 1);        }    }    /**     * Listens for an item to be clicked in the menu     *     * @author Adam Olsen     * @version 1.0     */    class MenuActionListener implements ActionListener {        public void actionPerformed(ActionEvent e) {            if (e.getSource() == unfiledBuddies)                BuddyList.getInstance().getBuddyListTree()                        .setShowUnfiledBuddies(unfiledBuddies.getState());            else if (e.getSource() == agentBuddies)                BuddyList.getInstance().getBuddyListTree().setShowAgentBuddies(                        agentBuddies.getState());            else if (e.getSource() == agentMessages) {                Settings.getInstance().setBoolean("showAgentMessages",                        agentMessages.getState());            } else if (e.getSource() == sortItem)                BuddyList.getInstance().getBuddyListTree().setSortByStatus(                        sortItem.getState());            else if (e.getSource() == prefsItem) {                if (!DialogTracker.containsDialog(PreferencesDialog.class))                    new PreferencesDialog().setVisible(true);            } else if (e.getSource() == priority)                new PriorityDialog().setVisible(true);            else if (e.getSource() == deleteAccount)                deleteAccountHandler();            else if (e.getSource() == changePassword) {                if (!DialogTracker.containsDialog(ChangePasswordDialog.class))                    new ChangePasswordDialog().setVisible(true);            } else if (e.getSource() == pluginItem) {                if (DialogTracker.containsDialog(PluginManager.class))                    return;                PluginManager manager = new PluginManager("www.jbother.org",                        "/plugins/index.rb", JBother.settingsDir);                manager.setVisible(true);            } else if (e.getSource() == consoleItem) {                String from = resources.getString("xmlConsole");;                ParsedBuddyInfo info = new ParsedBuddyInfo(from);                String userId = info.getUserId().toLowerCase();                final BuddyStatus buddyStatus = BuddyList.getInstance()                        .getBuddyStatus(userId);                buddyStatus.setName ( resources.getString ( "xmlConsole"));                if (buddyStatus.getConversation() == null) {                    buddyStatus.setConversation(new ConsolePanel(buddyStatus));                    MessageDelegator.getInstance().showPanel(                            buddyStatus.getConversation());                    MessageDelegator.getInstance().frontFrame(                            buddyStatus.getConversation());                }            }        }    }    /**     * Confirms that the user really wants to delete their account, and does so     * if they do     */    private void deleteAccountHandler() {        if (!BuddyList.getInstance().checkConnection()) {            BuddyList.getInstance().connectionError();            return;        }        int result = JOptionPane.showConfirmDialog(null, resources                .getString("sureDeleteAccount"), resources                .getString("deleteAccount"), JOptionPane.YES_NO_OPTION);        // makes sure one more time :)        if (result == 0) {            result = JOptionPane.showConfirmDialog(null, resources                    .getString("sureDeleteAccountPart2"), resources                    .getString("deleteAccount"), JOptionPane.YES_NO_OPTION);        }        if (result == 0) {            AccountManager manager = BuddyList.getInstance().getConnection()                    .getAccountManager();            // go ahead and delete the account            try {                manager.deleteAccount();            } catch (XMPPException e) {                String errorMessage = "";                errorMessage = resources.getString("xmppError"                        + e.getXMPPError().getCode());                Standard.warningMessage(BuddyList.getInstance(), resources                        .getString("deleteAccount"), errorMessage);                return;            }            // close everything and display a login dialog            BuddyList.getInstance().kill();            Standard.warningMessage(BuddyList.getInstance(), resources                    .getString("deleteAccount"), resources                    .getString("accountDeleted"));        }    }}

⌨️ 快捷键说明

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