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

📄 bsmapwinmanager.java

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

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

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

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.buddyfinder.core.*;
import edu.ou.kmi.buddyspace.plugins.maps.xml.*;
import edu.ou.kmi.buddyspace.plugins.maps.core.*;
import edu.ou.kmi.buddyspace.plugins.maps.editor.*;
import edu.ou.kmi.buddyspace.plugins.maps.pubsub.*;

/**
 * <code>BSMapWinManager</code> manages map windows.
 * It relies on <code>BSMapBean</code> and forwards events to particular
 * map windows.
 *
 * @author  Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
 * BuddyFinder additions by Chris Denham
 */
public class BSMapWinManager extends WinManager
                             implements BSMapListener, BSBuddyFinderListener {

    protected BSMapBean mapBean = null;
    protected BSBuddyFinderBean buddyFinderBean = null;
    protected BSPresenceBean presenceBean = null;
    protected BSRosterBean rosterBean = null;

    public BSMainFrame mainFrame;
    protected String mapPath;
    protected Image mapImage = null;

    // wheter the support for .plan (BSPlansPlugin) is present
    public boolean supportPlans = false;

    /** Constructor */
    public BSMapWinManager(BSMainFrame mainFrame, JTabbedPane tabbedPane,
                           String mapPath) {

        super(tabbedPane);
        this.mainFrame = mainFrame;
        this.mapPath = mapPath;
        mapImage = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/map.gif"));
    }

    /** Sets the buddyfinder bean */
    public void setBuddyFinderBean(BSBuddyFinderBean buddyFinderBean)
    {
        if (this.buddyFinderBean != null)
            this.buddyFinderBean.removeBuddyFinderListener(this);
        this.buddyFinderBean = buddyFinderBean;
        if (buddyFinderBean != null)
            buddyFinderBean.addBuddyFinderListener(this);
    }

    /** Sets map bean */
    public void setMapBean(BSMapBean mapBean) {
        if (this.mapBean != null)
            this.mapBean.removeMapListener(this);
        this.mapBean = mapBean;
        if (mapBean != null)
            mapBean.addMapListener(this);
    }

    /** Sets presence bean */
    public void setPresenceBean(BSPresenceBean presenceBean) {
        this.presenceBean = presenceBean;
    }

    /** Sets roster bean */
    public void setRosterBean(BSRosterBean rosterBean) {
        this.rosterBean = rosterBean;
    }

    /** Sets wether support for plans is present */
    public void setSupportPlans(boolean present) {
        supportPlans = present;
    }

    /** Returns main roster elements */
    public Enumeration getRoster() {
        if (rosterBean != null)
            return rosterBean.entries();
        else {
            return new Vector().elements();
        }
    }


    /** Opens given map */
    public boolean openMap(JID jid) {
        if (jid == null) return false;
        String mapName = jid.getResource();
        String originID = ((jid.getUsername()!=null)? (jid.getUsername() + "@") : "")
                         + jid.getServer();
        return openMap(mapName, originID);
    }


    /** Opens given map */
    public boolean openMap(String mapName, String originID) {
        if (mapName == null || "".equals(mapName) || "".equals(originID)) {
            JOptionPane.showMessageDialog(mainFrame,
                                  "Invalid map identification.",
                                  "Error",
                                  JOptionPane.ERROR_MESSAGE);
            return false;
        }
        mapBean.loadMap(mapName, originID);
        return true;
    }


    /** Selects window with given map */
    public void selectMap(String completeMapID) {
        if (completeMapID == null) return;

        DockableWindow win = (DockableWindow) getWindow(completeMapID);
        if (win == null) return;

        selectWindow(win);
    }

    /** Called when a buddyfinder result is received. */
    public void buddyFinderResultReceived(Collection users, String requestID)
    {
        DockableWindow win = getWindow(requestID);
        if (win instanceof BSMapWindow) ((BSMapWindow)win).buddyFinderResponse(users);
    }

    /** Called when map received. Opens a new window for it. */
    public void mapReceived(MapTag map, String originID) {
        if (map == null || originID == null) return;

        String mapID = map.getID();
        //String completeMapID = new String(originID + "/" + mapID);
        String windowTitle = BSMapPubsubCore.getFriendlyOrigin(originID);
        windowTitle += "/" + mapID.substring(0, mapID.length()-4);
        boolean dock = mainFrame.isDockingWindows();
        BSMapWindow win = new BSMapWindow(mainFrame, this, windowTitle, mapImage,
                                map, mapID, originID, mapPath, rosterBean, dock);
        win.setPresenceBean(presenceBean);
        addWindow(win, dock);
        showWindow(win, true, true);
        selectWindow(win);

        win.repaint();
    }

    /** Starts editting of given map.
     *  Closes normal map window and opens editting one.
     */
    public void edit(DockableWindow win) {
        if (win == null || (win instanceof BSMapEditWindow)) return;

        String mapID = ((BSMapWindow)win).getMapID();
        String originID = ((BSMapWindow)win).getOriginID();
        String completeMapID = new String(originID + "/" + mapID);
        boolean dock = win.isDocked();
        MapTag map = mapBean.getMap(originID, mapID);

        closeWindow(win);
        BSMapEditWindow newWin = new BSMapEditWindow(mainFrame, this, completeMapID, mapImage,
                                map, mapID, originID, mapPath, rosterBean, dock);
        newWin.setPresenceBean(presenceBean);
        addWindow(newWin, dock);
        showWindow(newWin, true, true);
        selectWindow(newWin);

        newWin.repaint();
    }

    /** Sends the map to the JID */
    public void sendMap(String mapID, String originID, JID jid, String subject, String body) {
        if (mapBean != null) {
            if (!mapBean.sendMap(mapID, originID, jid, subject, body))
                JOptionPane.showMessageDialog(mainFrame,
                                              "Error occured while sending map",
                                              "Error",
                                              JOptionPane.ERROR_MESSAGE);
        }
        else
            JOptionPane.showMessageDialog(mainFrame,
                          "Cannot send map - no connected",
                          "Error",
                          JOptionPane.ERROR_MESSAGE);

    }

    /** Saves the map into file with given filename */
    public void saveMap(String mapID, String originID,
                        String newMapID, String newOriginID) {

        if (mapBean != null) {
            if (!mapBean.saveMap(mapID, originID, newMapID, newOriginID))
                JOptionPane.showMessageDialog(mainFrame,
                                              "Error occured while saving map",
                                              "Error",
                                              JOptionPane.ERROR_MESSAGE);
        }
        else
            JOptionPane.showMessageDialog(mainFrame,
                          "Cannot save map",
                          "Error",
                          JOptionPane.ERROR_MESSAGE);

        String completeMapID = new String(originID + "/" + mapID);
        DockableWindow win = (DockableWindow) openWindows.get(completeMapID);
        if (win != null) {
            openWindows.remove(completeMapID);
            completeMapID = new String(newOriginID + "/" + newMapID);
            openWindows.put(completeMapID, win);
        }
    }

    /** Returns if connected */
    public boolean isConnected() {
        if (mainFrame != null)
            return mainFrame.isConnected();
        else return false;
    }

    /** Opens chat with the JID */
    public void openChat(JID jid) {
        if (mainFrame != null) {
            mainFrame.openChatWindow(jid, true, true);
        }
    }

    /** Sends message to JID */
    public void sendMessage(JID jid) {
        if (mainFrame != null) {
            mainFrame.composeMessage(jid);
        }
    }

    /** Sends file to the jid */
    public void sendFile(JID jid) {
        if (mainFrame != null) {
            mainFrame.sendFile(jid);
        }
    }

    /** Sends subscription request to the jid */
    public void sendSubscriptionRequest(JID jid) {
        if (mainFrame != null) {
            mainFrame.sendSubscriptionRequest(jid);
        }
    }

    /** Sends request for .plan of given jid */
    public void getPlan(JID jid) {
        if (mainFrame != null)
            mainFrame.performAction(jid, "http://jabber.open.ac.uk/tags/plan#get");
    }

    /** Returns the <code>MapTag</code> obtained from <code>MapBean</code> */
    public MapTag getMap(String originID, String mapID) {
        if (mapBean == null) return null;
        return mapBean.getMap(originID, mapID);
    }

    /** Copies all necessary files for given map into specified dir. */
    public boolean copyFilesForMap(MapTag map, String sourceOriginID,
                                               String destOriginID) {
        if (mapBean == null) return false;
        return mapBean.copyFilesForMap(map, sourceOriginID, destOriginID);
    }

    public boolean addBookmark(String originID, String mapID) {
        if (mainFrame == null || originID == null || mapID == null) return false;
        JID jid = JID.fromString(originID + "/" + mapID);
        if (jid == null) return false;
        /*return mainFrame.addBookmark(jid, "http://jabber.open.ac.uk/tags/map",
                                     "Map " + jid.getResource() + " from " +
                                     (new JID(jid.getUsername(), jid.getServer(), null)).toString());*/
        return mainFrame.addBookmark(jid, "http://jabber.open.ac.uk/tags/map",
                                     "Map " + mapID.substring(0,mapID.length()-4) + " from " +
                                     BSMapPubsubCore.getFriendlyOrigin(originID));
    }


    /** Opens windows specified in vector. */
    public void openTheWindows(Vector openWindows, boolean connected) {
        if (openWindows == null) return;
        if (connected) return;

        Enumeration owEnum = openWindows.elements();
        while (owEnum.hasMoreElements()) {
            BSOpenWindows.BSOpenWindow ow = (BSOpenWindows.BSOpenWindow) owEnum.nextElement();
            if ("http://jabber.open.ac.uk/tags/map".equals(ow.namespace) && ow.jid != null) {
                BSOpenWindows.adjustWindowToScreen(ow);
                openMap(ow.jid);
                String mapName = ow.jid.getResource();
                String originID = ((ow.jid.getUsername()!=null)? (ow.jid.getUsername() + "@") : "")
                                 + ow.jid.getServer();
                DockableWindow win = (DockableWindow) getWindow(originID + "/" + mapName);
                if (win != null) {
                    win.setFrameSize(ow.width, ow.height);
                    win.setFrameLocation(ow.x, ow.y);
                    setWindowDocked(win, ow.docked);
                }
            } //if
        } //while
    }


    /** Add its open windows into the vector (for opening when starting next time). */
    public void addOpenWindows(Vector openWindows, boolean connected) {
        if (openWindows == null) return;
        if (connected) return;

        Enumeration owEnum = this.openWindows.elements();
        while (owEnum.hasMoreElements()) {
            BSMapWindow win = (BSMapWindow) owEnum.nextElement();
            JID jid = JID.fromString(win.getOriginID() + "/" + win.getMapID());
            if (jid != null) {
                BSOpenWindows.BSOpenWindow ow = new BSOpenWindows.BSOpenWindow(jid,
                                        "http://jabber.open.ac.uk/tags/map",
                                        win.getFrameX(), win.getFrameY(),
                                        win.getFrameWidth(), win.getFrameHeight(),
                                        win.isDocked());
                openWindows.add(ow);
            }
        } //while
    }

}

⌨️ 快捷键说明

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