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

📄 gvjlabelholder.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 com.sun.spot.spotworld.common.LocaleUtil;import java.awt.AlphaComposite;import java.awt.Color;import java.awt.Component;import java.awt.Composite;import java.awt.Dimension;import java.awt.Graphics;import java.awt.Graphics2D;import javax.swing.JLabel;import javax.swing.SwingUtilities;/** * Holds a JLabel in GridView * @author randy */public class GVJLabelHolder extends GVComponentHolder {        public GVJLabelHolder() {    }        public JLabel getJLabel(){        if(getComponents().length < 1) return null;        if(getComponents()[0] instanceof JLabel) {            return (JLabel) getComponents()[0];        } else {            throw new RuntimeException(LocaleUtil.getString("Illegal state: how can you have gotten a non-JLable in here?"));            //return null;        }    }        public void setText(String s){       /* You would think it might be possible to set        * the text in a JLabel, but that doesn't allow the        * JLabel to grow in size.        *        * So just make a whole new JLabel.        */        if(getJLabel() != null){            removeComponent(getJLabel());        }        JLabel newLbl = new JLabel(s);        add(newLbl);        getSnug();        repaint();    }        /*      * Could also have recenterBelow(), etc. but add those methods as needed.     */    public void recenterAbove(final GVObject gvo){        SwingUtilities.invokeLater(new Runnable(){ public void run(){            getSnug();            int pX = gvo.getLocationInView().x;            int pY = gvo.getLocationInView().y;            int x = pX + (gvo.getBasicWidth() - getJLabel().getWidth()) / 2;            int y = pY  - getJLabel().getHeight();             setLocationInView(x,y);            validate();            repaint();        }});    }        /*     * This object typically wraps exactly the singe object it contains.     * This method is called to make that happen.     */    public void getSnug(){        if(getComponents().length == 0) return;        JLabel c = (JLabel) getComponents()[0];        setBounds(getLocation().x,                 getLocation().y,                 (int) c.getUI().getPreferredSize(c).getWidth(),                 (int) c.getUI().getPreferredSize(c).getHeight()                );    }        /*     * This object can have one and only one component.     * Adding a new Component simply replaces the single existing Component.     * It also makes this a listener for the component's events such as resize, etc.     * The component must be a JLabel.     *     */    public Component add(Component c){        if (c instanceof JLabel){            Dimension d = ((JLabel)c).getUI().getPreferredSize((JLabel)c);            c.setSize((int) d.getWidth(), (int) d.getHeight());            return super.add(c);        } else {            throw new RuntimeException(LocaleUtil.getString("Can't add anything but a JLabel to this object."));        }    }      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);             getJLabel().paint(g2);            //g2.drawString(getJLabel().getText(), 0 , 0);              g2.setComposite(ca);        }    }}

⌨️ 快捷键说明

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