📄 memebertree.java
字号:
/*
Copyright (c) 2008, Intel Corporation.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/import java.awt.LayoutManager;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import java.util.Hashtable;import java.util.Vector;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.tree.DefaultMutableTreeNode;import javax.swing.tree.TreePath;import com.intel.mobile.base.InstanceObject;import com.intel.mobile.base.IntelMobileException;import com.intel.mobile.battery.BatteryClass;import com.intel.mobile.battery.BatteryCollection;import com.intel.mobile.battery.BatteryInstance;import com.intel.mobile.context.BandwidthInstance;import com.intel.mobile.context.ConnectivityInstance;import com.intel.mobile.context.ContextClass;import com.intel.mobile.context.PowerInstance;import com.intel.mobile.network.LinkProtocolClass;import com.intel.mobile.network.LinkProtocolCollection;import com.intel.mobile.network.LinkProtocolInstance;import com.intel.mobile.network.NetworkAdapterClass;import com.intel.mobile.network.NetworkAdapterCollection;import com.intel.mobile.network.NetworkAdapterInstance;import com.intel.mobile.network.Protocol802_11Class;import com.intel.mobile.network.Protocol802_11Instance;import com.intel.mobile.network.Protocol802_3Class;import com.intel.mobile.network.Protocol802_3Instance;import com.intel.mobile.network.RadioAdapterClass;import com.intel.mobile.network.RadioAdapterInstance;import com.intel.mobile.network.WiredAdapterClass;import com.intel.mobile.network.WiredAdapterInstance;import com.intel.mobile.processor.ProcessorClass;import com.intel.mobile.processor.ProcessorCollection;import com.intel.mobile.processor.ProcessorInstance;import com.intel.mobile.storage.*;import com.intel.mobile.display.*;import com.intel.mobile.context.*;import com.intel.mobile.network.*;import com.intel.mobile.base.*;import com.intel.mobile.battery.*;/* * Created on 2004-6-10 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments *//** * @ * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */public class MemeberTree extends JPanel { private javax.swing.JTree jTree = null; private javax.swing.JTree tmpTree=null; private DefaultMutableTreeNode chosenNode = null; private static DefaultMutableTreeNode root = new DefaultMutableTreeNode("Providers"); private static Hashtable deviceSet = new Hashtable(); private static Hashtable devicekeySet = new Hashtable(); private static BatteryClass myBatteryClass; private static PhysicalDiskClass myPhysicalDiskClass; private static LogicalDiskClass myLogicalDiskClass; private static MemoryClass myMemoryClass; private static DisplayAdapterClass myDisplayAdapterClass; private static NetworkAdapterClass myNetworkAdapterClass; private static WiredAdapterClass myWiredAdapterClass; private static RadioAdapterClass myRadioAdapterClass; private static ProcessorClass myProcessorClass; private static LinkProtocolClass myLinkProtocolClass; private static Protocol802_3Class myProtocol802_3Class; private static ProtocolBluetoothPanClass myProtocolBluetoothPanClass; private static Protocol802_11Class myProtocol802_11Class; private static ProtocolWwanClass myProtocolWwanClass; private static ContextClass myContextClass; private Vector vectPropertyWindows=new Vector(); static { deviceSet.clear(); devicekeySet.clear(); } private javax.swing.JMenuBar jJMenuBar1 = null; private javax.swing.JMenu jMenu = null;// private javax.swing.JMenu jMenu1 = null;// private javax.swing.JMenu jMenu2 = null; private javax.swing.JMenu jMenu3 = null; private javax.swing.JPopupMenu jPopupMenu = null; private javax.swing.JMenuItem jMenuItem = null; private javax.swing.JScrollPane jScrollPane = null; /** * @param arg0 * @param arg1 */ public MemeberTree(LayoutManager arg0, boolean arg1) throws IntelMobileException { super(arg0, arg1); initialize(); } /** * @param arg0 */ public MemeberTree(LayoutManager arg0) throws IntelMobileException { super(arg0); initialize(); } /** * @param arg0 */ public MemeberTree(boolean arg0) throws IntelMobileException { super(arg0); initialize(); } /** * */ public MemeberTree() throws IntelMobileException { super(); initialize(); } /** * This method initializes this * * @return void */ private void initialize() throws IntelMobileException { //this.setSize(300,300); this.setLayout(new java.awt.BorderLayout()); this.add(getJJMenuBar1(), java.awt.BorderLayout.NORTH); this.add(getJPopupMenu(), java.awt.BorderLayout.WEST); this.add(getJScrollPane(), java.awt.BorderLayout.CENTER); //this.setSize(556, 414); } private javax.swing.JScrollPane getJScrollPane() throws IntelMobileException { if(jScrollPane == null){ jScrollPane = new javax.swing.JScrollPane(); jScrollPane.setAutoscrolls(true); //jScrollPane.setViewportView(getJTree()); jScrollPane.getViewport().add(getJTree()); } return jScrollPane; } public void refreshTree() throws IntelMobileException { try { Vector nodes = new Vector(); nodes.addElement(createBranch(new DefaultMutableTreeNode("Processors"))); nodes.addElement(createBranch(new DefaultMutableTreeNode("Batteries"))); nodes.addElement(createBranch(new DefaultMutableTreeNode("PhysicalDisks"))); nodes.addElement(createBranch(new DefaultMutableTreeNode("LogicalDisks"))); nodes.addElement(createBranch(new DefaultMutableTreeNode("Memories"))); nodes.addElement(createBranch(new DefaultMutableTreeNode("Bluetooths"))); nodes.addElement(createBranch(new DefaultMutableTreeNode("DisplayAdapters"))); nodes.addElement(createBranch(new DefaultMutableTreeNode("Network Adapters"))); nodes.addElement(createBranch(new DefaultMutableTreeNode("Link Protocols"))); nodes.addElement(createBranch(new DefaultMutableTreeNode("Contexts"))); root.removeAllChildren(); for(int i =0; i< nodes.size(); i++) { if(((DefaultMutableTreeNode)nodes.get(i)).getChildCount()!=0) { root.add((DefaultMutableTreeNode)nodes.get(i)); } } tmpTree = new javax.swing.JTree(root); jTree.setModel(tmpTree.getModel()); jTree.repaint(); } catch(Exception e) { } } /** * This method initializes jTree * * @return javax.swing.JTree */ private javax.swing.JTree getJTree() throws IntelMobileException { if(jTree == null) { //root = new DefaultMutableTreeNode("MyDeviceProvider"); /*DefaultMutableTreeNode processorNode = createBranch(new DefaultMutableTreeNode("Processor")); DefaultMutableTreeNode batteryNode = createBranch(new DefaultMutableTreeNode("Battery")); DefaultMutableTreeNode networkadapterNode = createBranch(new DefaultMutableTreeNode("Network Adapter")); DefaultMutableTreeNode protocolNode = createBranch(new DefaultMutableTreeNode("Protocol")); DefaultMutableTreeNode capabilityNode = createBranch(new DefaultMutableTreeNode("Capability"));*/ Vector nodes = new Vector(); nodes.addElement(createBranch(new DefaultMutableTreeNode("Processors"))); nodes.addElement(createBranch(new DefaultMutableTreeNode("Batteries"))); nodes.addElement(createBranch(new DefaultMutableTreeNode("PhysicalDisks"))); nodes.addElement(createBranch(new DefaultMutableTreeNode("LogicalDisks"))); nodes.addElement(createBranch(new DefaultMutableTreeNode("Memories"))); nodes.addElement(createBranch(new DefaultMutableTreeNode("Bluetooths"))); nodes.addElement(createBranch(new DefaultMutableTreeNode("DisplayAdapters"))); nodes.addElement(createBranch(new DefaultMutableTreeNode("Network Adapters"))); nodes.addElement(createBranch(new DefaultMutableTreeNode("Link Protocols"))); nodes.addElement(createBranch(new DefaultMutableTreeNode("Contexts"))); for(int i =0; i< nodes.size(); i++) { if(((DefaultMutableTreeNode)nodes.get(i)).getChildCount()!=0) { root.add((DefaultMutableTreeNode)nodes.get(i)); } } jTree = new javax.swing.JTree(root); //jTree.setPreferredSize(new java.awt.Dimension(500,360)); jTree.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent e) { if(e.getButton() == MouseEvent.BUTTON3) { TreePath tp = jTree.getPathForLocation(e.getX(),e.getY()); if (tp!= null) { jTree.setSelectionPath(tp); DefaultMutableTreeNode chosen = (DefaultMutableTreeNode)jTree.getLastSelectedPathComponent(); if (chosen.getChildCount() == 0) { getJMenuItem().setVisible(true); getJPopupMenu().show(e.getComponent(),e.getX(),e.getY()); chosenNode = chosen; } } } else if(e.getClickCount() ==2) { TreePath tp = jTree.getPathForLocation(e.getX(),e.getY()); if (tp!= null) { jTree.setSelectionPath(tp); DefaultMutableTreeNode chosen = (DefaultMutableTreeNode)jTree.getLastSelectedPathComponent(); if (chosen.getChildCount() == 0) { try { openPropertyFrame(chosen); } catch (IntelMobileException ex) { ex.printStackTrace(); } } } } } }); } return jTree; } /** * This method initializes jJMenuBar1 * * @return javax.swing.JMenuBar */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -