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

📄 gvapplication.java

📁 无线传感器网络节点Sun SPOT管理工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * 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 com.sun.spot.spotworld.common.LocaleUtil; import com.sun.spot.spotworld.gui.IUIApplication;import com.sun.spot.spotworld.gui.IUIObject;import com.sun.spot.spotworld.gui.SPOTTextExternalWindow;import com.sun.spot.spotworld.gui.SPOTTextWindow;import com.sun.spot.spotworld.participants.Application;import com.sun.spot.spotworld.participants.SquawkHost;import com.sun.spot.spotworld.participants.SunSPOT;import com.sun.spot.spotworld.virtualobjects.IVirtualObject;import java.awt.AlphaComposite;import java.awt.Color;import java.awt.Component;import java.awt.Composite;import java.awt.Graphics2D;import java.awt.Polygon;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import java.beans.PropertyVetoException;import java.io.PrintStream;import java.util.Vector;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JMenuItem;import javax.swing.JPopupMenu;/** * represents the running applications on a GridView depictiono fo a SPOT. * @author randy */public class GVApplication extends GVVirtualEntity implements ActionListener, IUIApplication {          static int bezelInset = 3; // Bezel width    static int textInsetX = 4; //Space around text    static int textInsetY = 6;        static Color[] deadColors = {        new Color(0.2f, 0.2f, 0.2f),        new Color(0.3f, 0.3f, 0.3f),        new Color(0.4f, 0.4f, 0.4f),        new Color(0.5f, 0.5f, 0.5f),        new Color(0.6f, 0.6f, 0.6f)    };        static Color[] liveColors = {        new Color(0.35f, 0.45f, 0.4f),        new Color(0.35f, 0.55f, 0.5f),        new Color(0.35f, 0.65f, 0.6f),        new Color(0.35f, 0.75f, 0.7f),        new Color(0.35f, 0.85f, 0.8f)    };        static Color[] pausedColors = {        new Color(0.4f, 0.4f, 0.35f),        new Color(0.5f, 0.5f, 0.35f),        new Color(0.6f, 0.6f, 0.35f),        new Color(0.7f, 0.7f, 0.35f),        new Color(0.8f, 0.8f, 0.35f)    };        static Color[] unbornColors = {        new Color(0.5f, 0.5f, 0.5f),        new Color(0.6f, 0.6f, 0.6f),        new Color(0.7f, 0.7f, 0.7f),        new Color(0.8f, 0.8f, 0.8f),        new Color(0.9f, 0.9f, 0.9f)    };        JLabel label;        public void init(){        super.init();        label = new JLabel();        setLabelTextAndResize();        add(label);    }        public void setLabelTextAndResize(){        label.setText(getAppName());        int lblW = (int) label.getUI().getPreferredSize(label).getWidth();        int lblH = (int) label.getUI().getPreferredSize(label).getHeight();        int width = 2*bezelInset + 2*textInsetX + lblW;        width = Math.max(100, width);        int height = 2*bezelInset + 2*textInsetY + lblH;        setSize(width, height);        label.setBounds((getBasicWidth() - lblW) / 2, (getBasicHeight() - lblH) / 2, lblW, lblH);    }            public void paintComponentNoShadow(Graphics2D g2){        Color[] colors = liveColors;        Application.AppState state = getApplication().getState();        if(state == Application.AppState.NEW)           colors = unbornColors;        if(state == Application.AppState.RUNNING)       colors = liveColors;        if(state == Application.AppState.EXITED)        colors = deadColors;        if(state == Application.AppState.PAUSED)        colors = pausedColors;        if(state == Application.AppState.MIGRATING)     colors = unbornColors;        Composite c = g2.getComposite();        if(state == Application.AppState.MIGRATING) {            if (c instanceof AlphaComposite) {                AlphaComposite ca = (AlphaComposite)c;                AlphaComposite a = AlphaComposite.getInstance(ca.getRule(), 0.6f);                g2.setComposite(a);            }        }        int[] xs = new int[4];        int[] ys = new int[4];                int w = getBasicWidth();        int h = getBasicHeight();                //Top facet        g2.setColor(colors[4]);        xs[0] = 0;               ys[0] = 0;        xs[1] = w;               ys[1] = 0;        xs[2] = w - bezelInset;  ys[2] = bezelInset;        xs[3] = bezelInset;      ys[3] = bezelInset;        g2.fill(new Polygon(xs, ys, 4));                //Right facet        g2.setColor(colors[1]);        xs[0] = w;               ys[0] = 0;        xs[1] = w;               ys[1] = h;        xs[2] = w - bezelInset;  ys[2] = h - bezelInset;        xs[3] = w - bezelInset;  ys[3] = bezelInset;        g2.fill(new Polygon(xs, ys, 4));                //Bottom facet        g2.setColor(colors[0]);        xs[0] = 0;               ys[0] = h;        xs[1] = w;               ys[1] = h;        xs[2] = w - bezelInset;  ys[2] = h - bezelInset;        xs[3] = bezelInset;      ys[3] = h - bezelInset;        g2.fill(new Polygon(xs, ys, 4));                //Left facet        g2.setColor(colors[3]);        xs[0] = 0;               ys[0] = 0;        xs[1] = 0;               ys[1] = h;        xs[2] = bezelInset;      ys[2] = h - bezelInset;        xs[3] = bezelInset;      ys[3] = bezelInset;        g2.fill(new Polygon(xs, ys, 4));                //Middle        g2.setColor(colors[2]);        g2.fillRect(bezelInset, bezelInset, w - 2*bezelInset, h - 2*bezelInset);                //restore composite        g2.setComposite(c);    }        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.fillRect(0,0, getBasicWidth(), getBasicHeight());            g2.setComposite(ca);        }    }        /**     * Hook called to add this to a view.     * See the super inmplementation.     * TO DO This is not synchronized as is the super method.     * That method uses a private variable viewLock for the synch.     *     * @param view the world the view is being added to

⌨️ 快捷键说明

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