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

📄 gvapplication.java

📁 无线传感器网络节点Sun SPOT管理工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     */    public void addToView(GridView view) {        view.add(this,0);        validate();   //This is what made the tComponentHolder finally be fully visible.        setInitialPositionInView(view);        setLabelTextAndResize();        repaint();    }        /*     * Currently. migration  set to work between SunSPOTs only.     *     */    public void dropIntoView(GridView gv){         if(! Application.ALLOW_APP_MIGRATION ) {                    super.dropIntoView(gv);            getHostUIObject(gv).resetGVApplicationPositions();            return;        }        SquawkHost currHost = getHostUIObject(gv).getSquawkHost();        if(! (currHost instanceof SunSPOT)) {            super.dropIntoView(gv);            return;        }        SunSPOT currSPOT = (SunSPOT) currHost;        SunSPOT newSPOT = currSPOT;        GVSunSPOT newGVSPOT = null;        /* Look for acceptable migration target */        for(Component c : gv.getComponents()){            if(c instanceof GVSunSPOT){                if(c.getBounds().intersects(getBounds())){                    /* Found a possible host */                    newSPOT =  ((GVSunSPOT)c).getSpot();                    newGVSPOT = (GVSunSPOT) c;                }            }        }        if(newSPOT != currSPOT) {            getApplication().setState(Application.AppState.MIGRATING);            gv.add(this,0);          //  paintImmediately(0, 0 ,getWidth(),getHeight());            /* NOTE: The order is critical: must start listener before sending, otherwise sender sends packets "into the void" so to speak. */            newSPOT.sendSPOTMessage("RECEIVE_APP", getApplication().getIsolateID(), currSPOT.getAddress());            currSPOT.sendSPOTMessage("MIGRATE_APP", getApplication().getIsolateID(), newSPOT.getAddress());            super.dropIntoView(gv);            getHostUIObject(gv).resetGVApplicationPositions();            //A slow move towards the new host in anticipation of arrival there. Note the app is not yet assigned to the new host, that happems            //when the new hoist reports APP_ARRIVED.            animateTo(newGVSPOT,  newGVSPOT.getWidth(), (newGVSPOT.getHeight() - getHeight())/2, 6.0, 0.05, 0.0, 0.0);        } else {            super.dropIntoView(gv);        }    }        public void delete(){        GridView gv = getView();        super.delete();        if(gv != null){            GVSquawkHost sh = getHostUIObject(gv);            if( sh != null) sh.resetGVApplicationPositions();        }    }        public String getAppName(){        if (getVirtualObject() == null) return LocaleUtil.getString("No app");        return ((Application)getVirtualObject()).getClassName();    }        public Application getApplication(){        return (Application) getVirtualObject();    }        public PrintStream displayOutputGetStream(int port) {           GVComponentHolder tch = new GVComponentHolder();        SPOTTextWindow frm = new SPOTTextWindow(){            PrintStream ps;            public PrintStream makePrintStream(){                ps = super.makePrintStream();                return ps;            }            public void dispose() {                super.dispose();                ps.close();             }        };        String hostName = getHostUIObject(getView()).getSquawkHost().getName();        frm.setTitle("Sytem.out from " + getAppName() + " on " + hostName);        tch.add(frm);        tch.setLocation(getLocation().x + getBasicWidth() , getLocation().y );        addLoosePiece(tch);        tch.addToView(getView());        frm.setDefaultCloseOperation(SPOTTextWindow.DISPOSE_ON_CLOSE);        try {            frm.setSelected(true);        } catch (PropertyVetoException ex) {            ex.printStackTrace();        }         PrintStream out = frm.makePrintStream();        return out;    }        public PrintStream displayOutputExternalGetStream(int port){        String hostName = getHostUIObject(getView()).getSquawkHost().getName();        final SPOTTextExternalWindow frame = new SPOTTextExternalWindow();        frame.setTitle("Sytem.out from " + getAppName() + " on " + hostName);        PrintStream out = frame.makePrintStream();        javax.swing.SwingUtilities.invokeLater(new Runnable() {            public void run() {                frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);                //Display the window.                frame.pack();                frame.setVisible(true);             }        });        return out;    }        public void startRemotePrinting(){        GVRemotePrintWindow w = new GVRemotePrintWindow();          Vector[] reply = ((SunSPOT)getApplication().getHost()).sendSPOTMessage("START_REMOTE_PRINT_APP", getApplication().getIsolateID());        String answer = (String) reply[0].elementAt(1);        int portNum = Integer.decode(answer); //Automatic unboxing.          w.open(this, getApplication().getIsolateID(), getApplication().getClassName(), portNum, (SunSPOT) getApplication().getHost());    };        /*     * This returns the GVSquawkHost with which this *should* be associated (as a "loosePiece").     *      */    public GVSquawkHost getHostUIObject(GridView gv){        if(getVirtualObject() == null) return null;        if(! (getVirtualObject() instanceof Application)) return null;        Application app = getApplication();        if(app.getHost() == null) return null;        for(IUIObject uio : app.getHost().getUIObjectsCopy()) {            if(uio instanceof GVSquawkHost){                GVSquawkHost t = (GVSquawkHost) uio;                if(t.getView() == gv){                    return t;                }            }        }        return null;    }        public Vector<JMenuItem> getMenuItems() {        if (getApplication() == null) return new Vector<JMenuItem>();        Vector<JMenuItem> menuItems = new Vector<JMenuItem>();        menuItems.addAll(menuHelper(getApplication().getApplicationMethods()));                return menuItems;    }        public JPopupMenu getPopupMenu(){        JPopupMenu menu = new JPopupMenu();        Vector<JMenuItem> v = getMenuItems();        for(JMenuItem item : v){            menu.add(item);        }        return menu;    }        public void mouseButton3Pressed(MouseEvent e){        JPopupMenu m = getPopupMenu();        m.show(e.getComponent(), e.getX(), e.getY());    }        public void setInitialPositionInView(GridView gv) {        //get iterator to find the UI object associated with this app.         GVSquawkHost gvsh = getHostUIObject(gv);        if(! gvsh.getLoosePieces().contains(this)){             //Not yet associated with the host             setLocation(gvsh.getX(), gvsh.getY() + gvsh.getHeight()/2 - getHeight()/2);             gvsh.addLoosePiece(this);             gvsh.resetGVApplicationPositions();        }      }        public void noteState(Object obj){        super.noteState(obj);        if(obj == getApplication()){            setLabelTextAndResize();            GridView gv = getView();            GVSquawkHost properParent = getHostUIObject(gv);            if(properParent == null) return;            if(properParent != getLooseParent()){                if(getLooseParent() != null){                    getLooseParent().removeLoosePiece(this);                }                properParent.addLoosePiece(this);                properParent.resetGVApplicationPositions();            }        }         repaint();    }        public String toString(){        return getClass().getSimpleName() + " (" + getApplication() + ")";    }}

⌨️ 快捷键说明

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