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

📄 gvobject.java

📁 无线传感器网络节点Sun SPOT管理工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            }            getView().remove(this);        }    }        /**     * Hook called after object creation.     * This gives the object a chance to present any dialog windows     * necessary for it's creation.     * @return false if none or cancelld.     */    public boolean createDialog() {        return false;    }        /**     * Enforce proper world ordering for adding.     */    public Component add(Component c) {                Component[] comps = getComponents();                int cLayer;        int indexForAdding = -1;                /*         * Check for a desired layerInWorld.         */        if(c instanceof GVObject) {            cLayer = ((GVObject)c).getLayerInView();        } else {            cLayer = 0;        }                /*         * Sweep through components to find an appropriate place.         */        for(int i = 0; i < comps.length; i++) {            int compLayer;                        if( comps[i] instanceof GVObject ) {                compLayer = ((GVObject)comps[i]).getLayerInView();            } else {                compLayer = 0;            }                        if( cLayer <= compLayer ) {                indexForAdding = i;                break;            }        }                add(c, indexForAdding);        return c;    }        public GVObject[] getGridObjects() {        Component[] compA = getComponents();        GVObject[] woA = new GVObject[compA.length ];                for (int i = 0; i < compA.length; i++)            woA[i] = (GVObject)compA[i];        return woA;    }        /*     *                   Metohds for loosePiece - looseParrent hierarchy.     *     */        public GVObject getLooseParent() {        return looseParent;    }        public void setLooseParent(GVObject looseParent) {        this.looseParent = looseParent;    }        public void addLoosePiece(GVObject c) {        InvisoObjectHolder holder = getHolder();        if( loosePieces.contains(c) ) {            return;        }        if(c.getLooseParent() != null){            c.getLooseParent().removeLoosePiece(c);            c.setLooseParent(this);        }        loosePieces.add(c);        c.setLooseParent(this);        if( holder != null && holder.isDragging() ) {            holder.add(c);        }    }        public void removeLoosePiece(Component c) {        InvisoObjectHolder holder = getHolder();        if( !loosePieces.contains(c) ) {            return;        }        loosePieces.remove(c);        if (c instanceof GVObject)            ((GVObject) c).setLooseParent((GVObject) c);        if( holder != null && holder.isDragging() ) {            holder.remove(c);        }    }    public Vector<GVObject> getLoosePieces() {        return (Vector<GVObject>) loosePieces.clone();    }        public void clearLoosePieces() {        for (Iterator i = loosePieces.iterator(); i.hasNext(); ) {            Component c = (Component)i.next();            removeLoosePiece(c);        }    }        public Vector<GVObject> getAllLoosePieces() {        Vector<GVObject> v = getLoosePieces();        /*         * Scan through the list of loose pieces, and         * recursively construct a vector using getAllLoosePieces().         */        Vector<GVObject> newV = new Vector<GVObject>();        for(GVObject c : v){            newV.add(c);            if (c instanceof GVTangibleObject) {                newV.addAll(((GVTangibleObject) c).getAllLoosePieces());            }        }        return newV;    }        public InvisoObjectHolder getHolder(){        if (getRoot()  instanceof InvisoObjectHolder)            return (InvisoObjectHolder) getRoot();        else            return null;    }        /*     *     *              Animation functions.     *     */    public synchronized Animator getCurrentAnimator() {        return currentAnimator;    }        public void setCurrentAnimator(Animator animator) {        this.currentAnimator = animator;    }        public void setPositionAndMoveLoosePieces(int x, int y) {        Point translateBy = new Point(x - getLocationInView().x, y - getLocationInView().y);        setLocationInView(x,y);                Vector<GVObject> v = getLoosePieces();                for(GVObject g : v) {            Point p = g.getLocationInView();            p.translate(translateBy.x, translateBy.y);            if (g instanceof GVTangibleObject)                ((GVTangibleObject) g).setPositionAndMoveLoosePieces(p.x, p.y);        }    }        public synchronized void thenAnimateTo(GVObject goalObject, final int xF, final int yF, final double dur, final double dt, final double slowIn, final double slowOut) {        Animator newA = new Animator(this, goalObject, xF, yF, dur, dt, slowIn, slowOut);        if(currentAnimator == null) {            currentAnimator = newA;            newA.start();        } else {            currentAnimator.addAnimator(newA);        }    }        /*     *               Painting     *     */    public void paintComponent(Graphics g) {        Graphics2D g2 = (Graphics2D)g;        if(isShadowed()) paintComponentWithShadow(g2); else paintComponentNoShadow(g2);    }        /*     * This is the call to override in normal usage to create an apprpriate appearance for     * any subclasses.     */    public void paintComponentNoShadow(Graphics2D g2){        super.paintComponent(g2);        g2.setColor(Color.blue);        g2.fillOval(0, 0, getBasicWidth(), getBasicHeight());    }        public void paintComponentWithShadow(Graphics2D g2){        g2.translate(shadowOffsetX, shadowOffsetY);        paintShadow(g2);        g2.translate(-shadowOffsetX, -shadowOffsetY);        paintComponentNoShadow(g2);    }        /*     * Override this call if you render your shape in a special way so the     * shadow will be correct.  This method will be sufficient for any simple     * rectangular bounded full width and height shape.     */    public void paintShadow(Graphics2D g2) {        Composite c = g2.getComposite();        if (c instanceof AlphaComposite) {            AlphaComposite ca = (AlphaComposite)c;            AlphaComposite a = AlphaComposite.getInstance(ca.getRule(), 0.2f);            g2.setComposite(a);            g2.setColor(Color.black);            g2.fillOval(0,0, getBasicWidth(), getBasicHeight());            g2.setComposite(ca);        }    }        /*     *     *             Other UI aspects.     *     */    public Dimension getPreferredSize() {        return new Dimension(100, 100);    }        public String toString(){        String s = getClass().getSimpleName() + getX() + ", " + getY() + " " +                LocaleUtil.getString("size") + "=" + getWidth() + "X" + getHeight() + ": ";        Component[] comps = getComponents();        for (int i = 0; i < comps.length; i++) {            s = s + ", " + comps[i].toString();        }        return s;    }        public boolean isSelected() {        return selected;    }    public void select() {        selected = true;    }        public void deselect() {        selected = false;        if(getHolder() != null && getHolder() instanceof ShadowingHolder )  return;    }        public boolean isShadowed() {        //Note getLooseParent() == this if this is not a loosePiece of something else.        return getLooseParent().isSelected();    }            public void tellUser(String msg){        JOptionPane.showMessageDialog(this, msg, "", JOptionPane.WARNING_MESSAGE);    }}

⌨️ 快捷键说明

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