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

📄 gvusbcable.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.gridview;import java.awt.AlphaComposite;import java.awt.BasicStroke;import java.awt.Color;import java.awt.Composite;import java.awt.Graphics2D;import java.awt.geom.CubicCurve2D;/** * Not in use sat this time.  Representas a USB cable coming off a SPOT. * @author randy */public class GVUSBCable extends GVTangibleObject {        private CubicCurve2D.Double shape;        /* These are relative to the location */    private int deviceEndX;    private int hostEndX;    private int ctrlDEX;    private int ctrlHEX;    private int deviceEndY;    private int hostEndY;    private int ctrlDEY;    private int ctrlHEY;        private int   c; //A graphics safety constant buffer around the vertical shape greater than w / 2    private float w; //The width of the shape         public void init(){        super.init();        w = 4;        c = 4;        shape = new CubicCurve2D.Double();        setSize(200,200);        shape.setCurve(0.0, 0.0, 5.0, 25.0, 100.0, 250.0, 200.0, 200.0);        removeMouseListener(this);    }            public void paintComponentNoShadow(Graphics2D g2){        g2.setStroke(new BasicStroke((float)w));        g2.setColor(Color.black);        g2.draw(shape);        g2.setStroke(new BasicStroke(1.0f));        g2.setColor(Color.gray);        g2.draw(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.setStroke(new BasicStroke((float)w));            g2.setColor(Color.black);            g2.draw(shape);            g2.setComposite(ca);        }    }         /*      * This is called by a looseParent object as it drags aroung loosePieces.      * When this object is a loosePiece, this will be called. It is overriden      * in subclasses that need to react in a special way.      *      * In this case, we want the host end to appear to move, while the device end      * stays fixed on the screen.      */    public void followDrag(int dX, int dY){        hostEndX   = hostEndX   - dX;        ctrlHEX    = ctrlHEX    - dX;        hostEndY   = hostEndY   - dY;        ctrlHEY    = ctrlHEY    - dY;        //deviceEndX = deviceEndX - dX;        //ctrlDEX    = ctrlDEX    - dX;        updateSize();        updatePositionFixHostEnd();        updateShape();            }        public void updateSize(){        int xMax = Math.max(Math.max(hostEndX, ctrlHEX), Math.max(deviceEndX, ctrlDEX));        int xMin = Math.min(Math.min(hostEndX, ctrlHEX), Math.min(deviceEndX, ctrlDEX));        int yMax = Math.max(Math.max(hostEndY, ctrlHEY), Math.max(deviceEndY, ctrlDEY));        int yMin = Math.min(Math.min(hostEndY, ctrlHEY), Math.min(deviceEndY, ctrlDEY));        setSize(xMax - xMin + c, yMax - yMin + c    );    }        /*     * This is the most subtle an difficult to understand.     * We have to slide this object so that the Host End stays fixed     * on the screen.     * No sliding may be necessary if the host end is c units from the left.     * This has strong assumptions on the shape, Host End is horizontal, Device vertical     * control points are horizontally and vertailly aligned.     */    public void updatePositionFixHostEnd(){        int deltaX, deltaY;        if(deviceEndX - hostEndX > c){            //Case the host end is at the left edge of our bounding region            // Slide everyone over by that amount.            deltaX = hostEndX;        } else {            // Case the device end is c units in from left edge            deltaX = deviceEndX - c;        }        if(-deviceEndY + hostEndY > c){            deltaY = deviceEndY;            //Case the host end is at the left edge of our bounding region            // Slide everyone over by that amount.        } else {            // Case the device end is c units in from left edge            deltaY = hostEndY - c;        }        hostEndX   = hostEndX   - deltaX;        ctrlHEX    = ctrlHEX    - deltaX;        deviceEndX = deviceEndX - deltaX;        ctrlDEX    = ctrlDEX    - deltaX;        hostEndY   = hostEndY   - deltaY;        ctrlHEY    = ctrlHEY    - deltaY;        deviceEndY = deviceEndY - deltaY;        ctrlDEY    = ctrlDEY    - deltaY;        setLocation(getLocation().x + deltaX, getLocation().y + deltaY);    }        public void updateShape(){        shape.setCurve((float) hostEndX, (float) hostEndY, (float) ctrlHEX, (float) ctrlHEY,                (float) ctrlDEX, (float) ctrlDEY, (float) deviceEndX, (float) deviceEndY);    }        public int getDeviceEndX() {        return deviceEndX;    }        public void setDeviceEndX(int x) {        int dx = x - deviceEndX;        deviceEndX = x;        ctrlDEX = ctrlDEX + dx;        updateSize();        updateShape();    }        public int getHostEndX() {        return hostEndX;    }        public void setHostEndX(int x) {        int dx = x - hostEndX;        hostEndX = x;        ctrlHEX = ctrlHEX + dx;        updateSize();        updateShape();    }        public int getDeviceEndY() {        return deviceEndY;    }        public void setDeviceEndY(int y) {        int dy = y - deviceEndY;        deviceEndY = y;        ctrlDEY = ctrlDEY + dy;        updateSize();        updateShape();    }        public int getHostEndY() {        return hostEndY;    }        public void setHostEndY(int y) {        int dy = y - hostEndY;        hostEndY = y;        ctrlHEY = ctrlHEY + dy;        updateSize();        updateShape();    }        public int getCtrlDEXVect() {        return ctrlDEX - deviceEndX;    }        public void setCtrlDEXVect(int x) {        ctrlDEX = x + deviceEndX;        updateSize();        updateShape();    }        public int getCtrlHEXVect() {        return ctrlHEX - hostEndX;    }        public void setCtrlHEXVect(int x) {        ctrlHEX = x + hostEndX;        updateSize();        updateShape();    }        public int getCtrlDEYVect() {        return ctrlDEY - deviceEndY;    }        public void setCtrlDEYVect(int y) {        ctrlDEY = y + deviceEndY;        updateSize();        updateShape();    }        public int getCtrlHEYVect() {        return ctrlHEY - hostEndY;    }        public void setCtrlHEYVect(int y) {        ctrlHEY = y + hostEndY;        updateSize();        updateShape();    }}

⌨️ 快捷键说明

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