📄 tvebasestation.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.treeview;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import java.util.Iterator;import java.util.LinkedHashMap;import java.util.Vector;import javax.swing.JMenuItem;import javax.swing.ImageIcon;import javax.swing.Icon;import com.sun.spot.spotworld.participants.ESpotBasestation;/** * * @author taylorr */public class TVeBasestation extends TVeSPOT { Icon bsFoundIcon = null; Icon bsNotFoundIcon = null; public String getName() { if (getBasestation() != null) return getBasestation().getName(); else return "New Basestation"; } public Icon getIcon() { return icon; } public void init() { super.init(); createIcons(); icon = bsNotFoundIcon; } private void createIcons() { try { // SHOULD THE FOLLOWING BE USED? RELATIVE PATH RATHER THAN ABSOLUTE?// bsFoundIcon = new ImageIcon(getClass().getResource("images/eBasestation-TreeView.gif"), "Basestation is connected");// bsNotFoundIcon = new ImageIcon(getClass().getResource("images/eBasestation-NotFound-TreeView.gif"), "Basestation is not connected"); bsFoundIcon = new ImageIcon(getClass().getResource("/com/sun/spot/spotworld/gridview/images/eBasestation-TreeView.gif"), "Basestation is connected"); bsNotFoundIcon = new ImageIcon(getClass().getResource("/com/sun/spot/spotworld/gridview/images/eBasestation-NotFound-TreeView.gif"), "Basestation is not connected"); } catch (Exception ex) { bsFoundIcon = new ImageIcon(); bsNotFoundIcon = new ImageIcon(); ex.printStackTrace(); } } public ESpotBasestation getBasestation(){ return (ESpotBasestation) getVirtualObject(); } public Vector<JMenuItem> getMenuItems() { if (getBasestation() == null) return new Vector<JMenuItem>(); Vector<JMenuItem> menuItems = new Vector<JMenuItem>(); LinkedHashMap methods = getBasestation().getBasestationMethods(); JMenuItem menuItem = null; for (Iterator it = methods.keySet().iterator(); it.hasNext(); ) { final Method method = (Method) it.next(); menuItem = new JMenuItem((String) methods.get(method)); menuItem.setToolTipText((String) methods.get(method)); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { method.invoke(getSpot(), (Object[]) null); } catch (IllegalArgumentException ex) { ex.printStackTrace(); } catch (InvocationTargetException ex) { ex.printStackTrace(); } catch (IllegalAccessException ex) { ex.printStackTrace(); } } }); menuItems.addElement(menuItem); } return menuItems; } public void noteState(Object obj) { ESpotBasestation bs = getBasestation(); // We expect this call is from our own proxy. if(obj != bs) return; if(bs.isBasestationConnected()) icon = bsFoundIcon; else icon = bsNotFoundIcon; notifyListeners(); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -