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

📄 virtualobject.java

📁 无线传感器网络节点Sun SPOT管理工具
💻 JAVA
字号:
/* * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.  *  * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product that is * described in this document. In particular, and without limitation, these intellectual property rights may * include one or more of the U.S. patents listed at http://www.sun.com/patents and one or more additional patents * or pending patent applications in the U.S. and in other countries. *  * U.S. Government Rights - Commercial software. Government users are subject to the Sun Microsystems, Inc. * standard license agreement and applicable provisions of the FAR and its supplements. *  * Use is subject to license terms.  *  * This distribution may include materials developed by third parties. Sun, Sun Microsystems, the Sun logo and * Java are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.  *  * Copyright (c) 2006 Sun Microsystems, Inc. Tous droits r?serv?s. *  * Sun Microsystems, Inc. d?tient les droits de propri?t? intellectuels relatifs ? la technologie incorpor?e dans * le produit qui est d?crit dans ce document. En particulier, et ce sans limitation, ces droits de propri?t? * intellectuelle peuvent inclure un ou plus des brevets am?ricains list?s ? l'adresse http://www.sun.com/patents * et un ou les brevets suppl?mentaires ou les applications de brevet en attente aux Etats - Unis et dans les * autres pays. *  * L'utilisation est soumise aux termes du contrat de licence. *  * Cette distribution peut comprendre des composants d?velopp?s par des tierces parties. * Sun, Sun Microsystems, le logo Sun et Java sont des marques de fabrique ou des marques d?pos?es de Sun * Microsystems, Inc. aux Etats-Unis et dans d'autres pays. */package com.sun.spot.spotworld.virtualobjects;import com.sun.spot.spotworld.common.LocaleUtil;import com.sun.spot.spotworld.gui.IUIObject;import com.sun.spot.spotworld.common.SWCore;import com.sun.spot.spotworld.virtualobjects.IVirtualObject;import java.util.Iterator;import java.util.Vector;import javax.swing.SwingUtilities;/** * This is the root of the Proxy heirarchy - -obejcts that represent SPOTs of various types. * * this is meant to be a building block from which to build other * stuff in SPOTWorld, the hope is that a lot of the accounting * can be done in this class and you subclass it.  * * @author arshan */public abstract class VirtualObject extends SWCore implements IVirtualObject {        Vector<IVirtualObject> vObjects = null;    Vector<IUIObject> uiObjects = null;    private IVirtualObject virtualParent = null;    private boolean selected;        /*     * Devices with an address reply with that. Applications reply with their unique name.     * Other make up womthing appropriate that will not collide.      */    abstract public String getUniqueID();        public void refresh(){}        /*     * Note this method takes care of setting the back pointer, virtualParent     */    public void removeVirtualObject(IVirtualObject obj) {        vObjects.remove(obj);        obj.setVirtualParent(null);        Vector <IUIObject> views;            views = obj.getUIObjectsCopy();            for(IUIObject iui : views){                iui.delete();             }    }        /*     * Note this method takes care of setting the back pointer, virtualParent     */    public void addVirtualObject(IVirtualObject obj) {                if ( vObjects == null ) vObjects = new Vector<IVirtualObject>();                vObjects.add(obj);        obj.setVirtualParent(this);    }        // find an object in the Distributed Hash Table, which does not exist yet.    public IVirtualObject findObject(String addy) {        return null;    }        public void addUIObject(IUIObject uiObj) {        if ( uiObjects == null ) uiObjects = new Vector<IUIObject>();        msg(LocaleUtil.getString("Associating with new uiObj") + ": " + uiObj);        uiObj.noteState(this); //Should this be here? The back pointer from uiObj to this may not be in place yet.        uiObjects.add(uiObj);    }         /** @deprecated     *  Use getVirtualObjectsCopy instead.     */    public Iterator<IVirtualObject> getIterator() {        if (vObjects == null) { return null;}        return  vObjects.iterator();    }        public Vector<IVirtualObject> getVirtualObjectsCopy() {                if (vObjects == null) { return new Vector<IVirtualObject>();}        return (Vector<IVirtualObject>) vObjects.clone();    }        /** @deprecated     *  Use getUIObjectsCopy instead.     */    public Iterator<IUIObject> getUIIterator() {        if (uiObjects == null) { return null;}        return uiObjects.iterator();    }        public Vector<IUIObject> getUIObjectsCopy() {                if (uiObjects == null) { return new Vector<IUIObject>();}        return (Vector<IUIObject>) uiObjects.clone();    }            public void notifyUIObjects(){        final Iterator itr = getUIIterator();        if(itr == null) return;        /* This is typially called from outside the UI Thread, so put it back inside */        SwingUtilities.invokeLater(new Runnable(){            public void run(){                while(itr.hasNext()){                    IUIObject uio = (IUIObject)itr.next();                     uio.noteState(VirtualObject.this);                }            }                    });    }        /* This object is no longer in the world of virtual objects */    public void delete(){        if(isSelected()) deselect();        IVirtualObject p = getVirtualParent();        if(p != null) {            p.removeVirtualObject(this);        }        for(IUIObject iui : getUIObjectsCopy()){            iui.delete();        }    }    public boolean isSelected() {        return selected;    }              public void deselect(){        selected = false;        notifyUIObjects();    }    public void select() {        selected = true;        notifyUIObjects();    }        public IVirtualObject getVirtualParent() {        return virtualParent;    }        /* return the root of the virtualParent-virtualObjects tree */    public IVirtualObject getVirtualRoot(){        if(getVirtualParent() == null) return this;        return getVirtualParent().getVirtualRoot();     }    /*     * This method should not normally be called, (only from within addObject(...) )     */    public void setVirtualParent(IVirtualObject virtualParent) {        this.virtualParent = virtualParent;    }        public Vector<IVirtualObject> getSelectedObjects(){        Vector<IVirtualObject> v = new Vector<IVirtualObject>();        Iterator<IVirtualObject> it = getIterator();        while (it.hasNext()){            IVirtualObject vo = it.next();            if(vo.isSelected()) v.add(vo);        }        return v;    }}

⌨️ 快捷键说明

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