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

📄 bsmapwindow.java

📁 一款即时通讯软件
💻 JAVA
字号:
package edu.ou.kmi.buddyspace.plugins.maps.gui;

/*
 * BSMapWindow.java
 *
 * Project: BuddySpace
 * (C) Copyright Knowledge Media Institute 2002
 *
 *
 * Created on 31 October 2002, 10:15
 */

import java.util.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

import org.jabber.jabberbeans.*;
import org.jabber.jabberbeans.util.*;

import edu.ou.kmi.buddyspace.core.*;
import edu.ou.kmi.buddyspace.gui.*;
import edu.ou.kmi.buddyspace.utils.*;
import edu.ou.kmi.buddyspace.plugins.maps.xml.*;
import edu.ou.kmi.buddyspace.plugins.maps.core.*;
import edu.ou.kmi.buddyspace.plugins.buddyfinder.core.*;

/**
 * <code>BSMapWindow</code> provides map window GUI.
 * It contains <code>BSMapView</code> which is the actual map view and several
 * control components. All communication is done through
 * <code>BSMapWinManager</code>.
 *
 * @author  Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
 * BuddyFinder additions by Chris Denham
 */
public class BSMapWindow extends DockableWindow
                         implements ActionListener {

    private JPanel mainPanel;

    private BSMapView mapView = null;
    //private JPanel mapPanel = null;
    //private JPanel helpPanel = null;
    //private JScrollPane mapScrollPane = null;
    private JPanel buttonPanel = null;

    private JButton closeButton = null;
    private JButton sendButton = null;
    private JButton buddyFinderButton = null;

    private JButton dockButton;
    private JButton bookmarkButton;
    private JButton editButton;
    private JPanel checkBoxesPanel;

    /** Constructor */
    BSMapWindow(Window parent, BSMapWinManager winMan, String title,
                Image icon, MapTag map, String mapID, String originID,
               String mapPath, BSRosterBean rosterBean, boolean docked) {

        super(originID + "/" + mapID, title, icon, docked, winMan);

        mapView = new BSMapView(this, map, mapID, originID, mapPath, rosterBean);

        mainPanel = new JPanel(new BorderLayout());
        mainPanel.add(mapView, BorderLayout.CENTER);

        addButtons();

        if (!docked)
            frame.pack();
    }

    /** Adds buttons */
    protected void addButtons() {
        buttonPanel = new JPanel();

        buddyFinderButton = new JButton();
        buddyFinderButton.setText("BuddyFinder");
        buddyFinderButton.addActionListener(this);
        if (((BSMapWinManager)winMan).mainFrame.pluginBuddyFinder)
        {
            buttonPanel.add(buddyFinderButton);
        }
        sendButton = new JButton();
        sendButton.setText("Send map");
        sendButton.addActionListener(this);
        buttonPanel.add(sendButton);

        closeButton = new JButton();
        closeButton.setText("Close");
        closeButton.addActionListener(this);
        buttonPanel.add(closeButton);

        JPanel checkBoxesPanel = new JPanel();
        Icon icon = new ImageIcon(ClassLoader.getSystemResource(!docked?
                                "images/dock.gif" : "images/float.gif"));
        dockButton = new JButton(icon);
        dockButton.setToolTipText(docked? "Float" : "Dock");
        dockButton.addActionListener(this);
        checkBoxesPanel.add(dockButton);
        if (!OSVersion.isJava1Point4orHigher())
            dockButton.setEnabled(false);
        icon = new ImageIcon(ClassLoader.getSystemResource("images/bookmark.gif"));
        bookmarkButton = new JButton(icon);
        bookmarkButton.setToolTipText("Add bookmark");
        bookmarkButton.addActionListener(this);
        checkBoxesPanel.add(bookmarkButton);
        editButton = new JButton("Edit");
        editButton.addActionListener(this);
        checkBoxesPanel.add(editButton);

        mainPanel.add(checkBoxesPanel, BorderLayout.NORTH);
        mainPanel.add(buttonPanel, BorderLayout.SOUTH);

        setLayout(new BorderLayout());
        add(mainPanel, BorderLayout.CENTER);
    }

    /** Sets presence bean */
    public void setPresenceBean(BSPresenceBean presenceBean) {
        if (mapView != null)
            mapView.setPresenceBean(presenceBean);
    }

    /** Calling this method gets buddyfinder to send a form back to buddyspace.
     * When the form is submitted by the buddyspace user, buddyfinder responds
     * with results that are directed back to the buddyFinderReponse method
     * of this window.
     */
    public void buddyFinderRequest() {
        BSBuddyFinderBean buddyFinderBean = ((BSMapWinManager)winMan).buddyFinderBean;
        if (buddyFinderBean == null) return;
        buddyFinderBean.buddyFinderRequest("buddymapform", getID());
    }

    /**
     * Process the buddyfinder results requested from this window.
     */
    public void buddyFinderResponse(Collection users) {
        // Sets a highlight for all JIDs on the map that are also contained
        // in the 'users' vector.
        if (mapView != null) mapView.setEmphasizedJIDs(users);
        int n = users.size();
        if (n == 0)
        {
            JOptionPane.showMessageDialog(this,
                "Sorry, no records matched the query.",
                "BuddyFinder",
                JOptionPane.INFORMATION_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(this, "" + n +
                " user(s) found and will be highlighted if present on the map",
                "BuddyFinder",
                JOptionPane.INFORMATION_MESSAGE);
        }
    }

    /** Handles actions from GUI controls */
    public void actionPerformed(java.awt.event.ActionEvent evt) {
        if (evt.getSource() == closeButton) {
            winMan.closeWindow(this);
        }
        else if (evt.getSource() == buddyFinderButton) {
            buddyFinderRequest();
        }
        else if (evt.getSource() == sendButton) {
            BSMapSendDialog dlg = new BSMapSendDialog(((BSMapWinManager)winMan).mainFrame, ((BSMapWinManager)winMan).getRoster());
            dlg.setVisible(true);
            if (dlg.jid != null)
                sendMap(dlg.jid, dlg.subject, dlg.body);
        }
        else if (evt.getSource() == dockButton) {
            if (winMan != null) {
                winMan.setWindowDocked(this, !docked);
                Icon icon = new ImageIcon(ClassLoader.getSystemResource(!docked?
                                "images/dock.gif" : "images/float.gif"));
                dockButton.setIcon(icon);
                dockButton.setToolTipText(docked? "Float" : "Dock");
                winMan.selectWindow(this);
            }
        }
        else if (evt.getSource() == editButton) {
            if (winMan != null) {
                ((BSMapWinManager)winMan).edit(this);
            }
        }
        else if (evt.getSource() == bookmarkButton) {
            if (winMan != null) {
                ((BSMapWinManager)winMan).addBookmark(mapView.getOriginID(), mapView.getMapID());
            }
        }
    }

    /** Sends the map to given JID. Calls BSMapWinManager method. */
    public void sendMap(JID jid, String subject, String body) {
        ((BSMapWinManager)winMan).sendMap(mapView.getMapID(), mapView.getOriginID(), jid, subject, body);
    }

    /** Returns if connected. Calls BSMapWinManager method. */
    public boolean isConnected() {
        return ((BSMapWinManager)winMan).isConnected();
    }

    /** Opens chat with given JID. Calls BSMapWinManager method. */
    public void openChat(JID jid) {
        ((BSMapWinManager)winMan).openChat(jid);
    }

    /** Sends message. Calls BSMapWinManager method. */
    public void sendMessage(JID jid) {
        ((BSMapWinManager)winMan).sendMessage(jid);
    }

    /** Sends file to JID. Calls BSMapWinManager method. */
    public void sendFile(JID jid) {
        ((BSMapWinManager)winMan).sendFile(jid);
    }

    /** Sends subscription request to JID. Calls BSMapWinManager method. */
    public void sendSubscriptionRequest(JID jid) {
        ((BSMapWinManager)winMan).sendSubscriptionRequest(jid);
    }

    /** Sends request for .plan of given jid */
    public void getPlan(JID jid) {
        ((BSMapWinManager)winMan).getPlan(jid);
    }

    /** Returns ID of the map */
    public String getMapID() {
        if (mapView == null) return "";
        return mapView.getMapID();
    }

    /** Returns origin ID of the map */
    public String getOriginID() {
        if (mapView == null) return "";
        return mapView.getOriginID();
    }

    /** Returns if the .plan support is present */
    public boolean supportsPlans() {
        return ((BSMapWinManager)winMan).supportPlans;
    }

     public void cancelListening() {
         if (mapView != null)
             mapView.cancelListening();
     }


     public void setDocked(boolean docked, boolean select) {
         super.setDocked(docked, select);
         if (!docked) {
             //setPreferredSize(mapView.getPreferredSize());
             doLayout();
             setPreferredSize(getMinimumSize());
             frame.pack();
         }
     }

}

⌨️ 快捷键说明

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