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

📄 bsbookmarks.java

📁 一款即时通讯软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            return result && ((namespace == null && bm.namespace == null) ||
                    (namespace != null && namespace.equals(bm.namespace)));
        }
    }
    
    
    public class BSDeleteBookmarkDialog extends JDialog {
        private JOptionPane optionPane;
        
        public BSBookmark bookmark = null;
    
        /** Constructor */
        public BSDeleteBookmarkDialog(Frame _parent, String title, Enumeration bookmarks) {
            super(_parent, title, true);

            final Frame parent = _parent;

            // fills bookmarks hashtable and sorted combo box
            final JComboBox bmComboBox = new JComboBox();
            bmComboBox.setEditable(false);
            final TreeMap bms = new TreeMap();
            while (bookmarks.hasMoreElements()) {
                BSBookmark bm = (BSBookmark) bookmarks.nextElement();
                String namespace = (bm.namespace!=null)? bm.namespace : "";
                String name = (bm.name!=null)? bm.name : "";
                String jid = (bm.jid!=null)? bm.jid.toString() : "";
                String label = name + " - " + namespace + " (" + jid + ")";
                bms.put(label, bm);
            }
            TreeMap tmpMap = (TreeMap) bms.clone();
            while (!tmpMap.isEmpty()) {
                Object o = tmpMap.firstKey();
                bmComboBox.addItem(o);
                tmpMap.remove(o);
            }

            Object[] fields = {"Bookmark: ", bmComboBox};

            final String removeButton = "Delete";
            final String cancelButton = "Cancel";
            Object[] options = {removeButton, cancelButton};

            optionPane = new JOptionPane(fields, 
                                         JOptionPane.PLAIN_MESSAGE,
                                         JOptionPane.OK_CANCEL_OPTION,
                                         null,
                                         options,
                                         options[0]);
            setContentPane(optionPane);
            setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

            pack();
            setLocationRelativeTo(parent);

            // handles actions
            optionPane.addPropertyChangeListener(new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent e) {
                    String prop = e.getPropertyName();

                    if (isVisible() 
                        && (e.getSource() == optionPane)
                        && (prop.equals(JOptionPane.VALUE_PROPERTY) ||
                          prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
                        Object value = optionPane.getValue();

                        if (value == JOptionPane.UNINITIALIZED_VALUE) {
                            // ignore reset
                            return;
                        }

                        // Reset the JOptionPane's value.
                        // If you don't do this, then if the user
                        // presses the same button next time, no
                        // property change event will be fired.
                        optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);

                        if (value.equals(removeButton)) {
                            String bmStr = (String) bmComboBox.getSelectedItem();
                            bookmark = (BSBookmark) ((bmStr != null)? bms.get(bmStr) : null);
                            setVisible(false);
                        }
                        else if (value.equals(cancelButton)) {
                            bookmark = null;
                            setVisible(false);
                        }
                    }
                }
            });
        }
    }
    
    
    public class BSAddBookmarkDialog extends JDialog {
        private JOptionPane optionPane;
        
        public JID jid = null;
        public String namespace = null;
        public String name = null;
    
        /** Constructor */
        public BSAddBookmarkDialog(Frame _parent, String title) {
            super(_parent, title, true);

            final Frame parent = _parent;

            final JTextField jidTextField = new JTextField();
            // probably combo box from namespaces obtained from plugins
            //final JTextField namespaceTextField = new JTextField();
            final JTextField nameTextField = new JTextField();
            
            // fills bookmarks hashtable and sorted combo box
            Vector namespaces = new Vector();
            Vector names = new Vector();
            mainFrame.getSupportedNamespaces(namespaces, names);
            Enumeration nssEnum = namespaces.elements();
            Enumeration nsEnum = names.elements();
            final JComboBox nsComboBox = new JComboBox();
            nsComboBox.setEditable(false);
            final TreeMap nss = new TreeMap();
            while (nsEnum.hasMoreElements()) {
                String ns = (String) nssEnum.nextElement();
                String n = (String) nsEnum.nextElement();
                String label = n /*+ " (" + ns + ")"*/;
                nss.put(label, ns);
            }
            TreeMap tmpMap = (TreeMap) nss.clone();
            while (!tmpMap.isEmpty()) {
                Object o = tmpMap.firstKey();
                nsComboBox.addItem(o);
                tmpMap.remove(o);
            }

            /*Object[] fields = {"Bookmark name", nameTextField,
                               "JID / url / path: ", jidTextField,
                               "Namespace (http, jabber:iq:conference,... or empty)", namespaceTextField};*/
            Object[] fields = {"Bookmark name: ", nameTextField,
                               "JID / url / path: ", jidTextField,
                               "Bookmark type: ", nsComboBox};

            final String okButton = "OK";
            final String cancelButton = "Cancel";
            Object[] options = {okButton, cancelButton};

            optionPane = new JOptionPane(fields, 
                                         JOptionPane.PLAIN_MESSAGE,
                                         JOptionPane.OK_CANCEL_OPTION,
                                         null,
                                         options,
                                         options[0]);
            setContentPane(optionPane);
            setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

            pack();
            setLocationRelativeTo(parent);

            // handles actions
            optionPane.addPropertyChangeListener(new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent e) {
                    String prop = e.getPropertyName();

                    if (isVisible() 
                        && (e.getSource() == optionPane)
                        && (prop.equals(JOptionPane.VALUE_PROPERTY) ||
                          prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
                        Object value = optionPane.getValue();

                        if (value == JOptionPane.UNINITIALIZED_VALUE) {
                            // ignore reset
                            return;
                        }

                        // Reset the JOptionPane's value.
                        // If you don't do this, then if the user
                        // presses the same button next time, no
                        // property change event will be fired.
                        optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);

                        if (value.equals(okButton)) {
                            name = nameTextField.getText();
                            if (name == null || "".equals(name)) {
                                JOptionPane.showMessageDialog(parent, 
                                            "Bookmark name cannot be empty", 
                                            "Error", JOptionPane.ERROR_MESSAGE);
                                return;
                            }
                            //namespace = namespaceTextField.getText();
                            namespace = (String) nss.get(nsComboBox.getSelectedItem());
                            //if ("".equals(namespace)) namespace = null;
                            String jidStr = jidTextField.getText();
                            if (jidStr == null || "".equals(jidStr)) 
                                jid = null;
                            else {
                                jid = JID.fromString(jidStr);
                                if (jid == null) {
                                    JOptionPane.showMessageDialog(parent, "Invalid JID", 
                                                "Error", JOptionPane.ERROR_MESSAGE);
                                    return;
                                }
                            }
                            setVisible(false);
                        }
                        else if (value.equals(cancelButton)) {
                            name = namespace = null;
                            jid = null;
                            setVisible(false);
                        }
                    }
                }
            });
        }
    }
    
}

⌨️ 快捷键说明

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