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

📄 groupchatbookmarks.java

📁 网站即时通讯系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* 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.groupchat;import java.awt.*;import java.awt.event.*;import java.io.BufferedReader;import java.util.*;import javax.swing.*;import com.valhalla.jbother.jabber.smack.*;import org.jivesoftware.smackx.*;import com.valhalla.gui.*;import com.valhalla.settings.*;import com.valhalla.jbother.BuddyList;import com.valhalla.jbother.JBother;/** * Allows the user to create bookmarks for each of their favorite group chat * rooms * * @author Adam Olsen * @version 1.0 */public class GroupChatBookmarks extends JDialog {    private ResourceBundle resources = ResourceBundle.getBundle(            "JBotherBundle", Locale.getDefault());    private JPanel container = new JPanel();    private JList bookMarkList;    private JPanel rightPanel = new JPanel();    private JPanel leftPanel = new JPanel();    private JPanel buttonPanel = new JPanel();    private JPanel inputPanel = new JPanel();    private JButton saveButton = new JButton(resources.getString("saveButton")),            openButton = new JButton(resources.getString("openButton")),            cancelButton = new JButton(resources.getString("cancelButton"));    private MJTextField roomBox = new MJTextField(15),            serverBox = new MJTextField(20), nickBox = new MJTextField(15);    private JPasswordField passBox = new JPasswordField(15);    private int row = 0;    private GridBagLayout grid = new GridBagLayout();    private GridBagConstraints c = new GridBagConstraints();    private JPopupMenu deleteMenu = new JPopupMenu();    private Vector bookmarks = new Vector();    private JMenuItem deleteItem = new JMenuItem(resources            .getString("deleteButton"));    private JCheckBox auto = new JCheckBox(resources.getString("autoJoinRoom"));    private GroupChatBookmarks thisPointer;    private WaitDialog wait = new WaitDialog(this,null,resources.getString("pleaseWait"));    private Bookmark bookmark;    private PrivateDataManager pDataManager;    /**     * Sets up the visual components of the bookmark dialog     */    public GroupChatBookmarks(Component parent) {        super(BuddyList.getInstance().getContainerFrame(), "Group Chat Bookmarks");        setTitle(resources.getString("groupChatBookmarksDialogTitle"));        container.setLayout(new BoxLayout(container, BoxLayout.X_AXIS));        container.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));        bookMarkList = new JList();        bookMarkList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);        bookMarkList.setCellRenderer(new ListRenderer());        leftPanel.setBackground(Color.WHITE);        leftPanel.setLayout(new GridLayout(0, 1));        setContentPane(container);        deleteMenu.add(deleteItem);        leftPanel.add(new JScrollPane(bookMarkList));        leftPanel.setPreferredSize(new Dimension(120, 200));        inputPanel.setBorder(BorderFactory.createTitledBorder(resources                .getString("groupChatBookmarksDialogTitle")));        rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.Y_AXIS));        inputPanel.setLayout(grid);        c.anchor = GridBagConstraints.WEST;        passBox.setFont(nickBox.getFont());        createInputBox(resources.getString("room") + ":", roomBox);        createInputBox(resources.getString("server") + ":", serverBox);        createInputBox(resources.getString("nickname") + ":", nickBox);        createInputBox(resources.getString("password") + ":", passBox);        c.gridx = 1;        c.gridy++;        grid.setConstraints(auto, c);        inputPanel.add(auto);        container.add(leftPanel);        container.add(Box.createRigidArea(new Dimension(5, 0)));        //this is the space taker        JLabel blankLabel = new JLabel("");        c.weighty = 1;        c.weightx = 1;        c.gridx = 0;        c.gridwidth = 3;        c.gridy++;        grid.setConstraints(blankLabel, c);        inputPanel.add(blankLabel);        buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));        buttonPanel.add(Box.createHorizontalGlue());        buttonPanel.add(saveButton);        buttonPanel.add(openButton);        buttonPanel.add(cancelButton);        rightPanel.add(inputPanel);        rightPanel.add(buttonPanel);        container.add(rightPanel);        setListeners();        setSize(400, 200);        pack();        setLocationRelativeTo(parent);        DialogTracker.addDialog(this, true, true);    }    public static void showDialog(String room, String user, String password) {        int index = room.indexOf("@");        String server = room.substring(index + 1);        room = room.substring(0, index);        index = user.indexOf("@");        String nick = user.substring(0, index);        GroupChatBookmarks gc = new GroupChatBookmarks(null);        gc.load();        gc.roomBox.setText(room);        gc.serverBox.setText(server);        gc.nickBox.setText(nick);        gc.passBox.setText(password);        gc.setVisible(true);    }    public void load()    {         new Thread( new CollectBookmarks(false) ).start();    }    /**     * Adds event listeners to components in the bookmark window     */    private void setListeners() {        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);        cancelButton.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                dispose();            }        });        saveButton.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                saveBookmark();            }        });        openButton.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                openHandler();            }        });        bookMarkList.addMouseListener(new RightClickListener());        deleteItem.addActionListener(new DeleteListener());    }    /**     * Writes a bookmark to the bookmarks file on disk     */    private void saveBookmark() {        if (!checkData())            return;        String defaultString = roomBox.getText();        String result = (String) JOptionPane.showInputDialog(this, resources                .getString("enterBookmarkName"), resources                .getString("saveBookmark"), JOptionPane.QUESTION_MESSAGE, null,                null, defaultString);        if (result == null || result.equals(""))            return;        for( int i = 0; i < bookmarks.size(); i++ )        {            Bookmark.Conference c = (Bookmark.Conference)bookmarks.get(i);            if( c.getName().toLowerCase().equals(result.toLowerCase()))            {                bookmark.removeConference(c);            }        }        bookmark.addConference(result,roomBox.getText() + "@" + serverBox.getText(),            nickBox.getText(), new String(passBox.getPassword()),auto.isSelected());        new Thread(new SaveBookmark()).start();        loadBookmarks();    }    class SaveBookmark implements Runnable    {        public void run()        {            try {                pDataManager.setPrivateData(bookmark);            }            catch( Exception ex ) { com.valhalla.Logger.logException(ex);}        }    }

⌨️ 快捷键说明

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