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

📄 pluginpanel.java

📁 这是无线传感器网络用的操作系统tinyos-1.1.0,未来的世界将是它呵
💻 JAVA
字号:
// $Id: PluginPanel.java,v 1.12.4.3 2003/08/26 09:08:11 cssharp Exp $/*									tab:2 * * * "Copyright (c) 2000 and The Regents of the University  * of California.  All rights reserved. * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose, without fee, and without written * agreement is hereby granted, provided that the above copyright * notice and the following two paragraphs appear in all copies of * this software. *  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, * UPDATES, ENHANCEMENTS, OR MODIFICATIONS." * * Authors:	Nelson Lee * Date:        December 29 2002 * Desc:        Panel that lets the user choose which plugins to register *              and deregister * *//** * @author Nelson Lee */package net.tinyos.sim;import net.tinyos.sim.event.*;import java.util.*;import java.awt.event.*;import javax.swing.*;import java.awt.*;import java.io.*;public class PluginPanel extends JPanel implements SimConst {    private TinyViz tv;  private SimEventBus eventBus;  private PluginReader pluginReader;  private Vector plugins;  private JMenu pluginMenu = new JMenu("Plugins");  private JPanel pluginAreaPanel;  private JTabbedPane pluginTabbedPane;  private JLabel statusLine = new JLabel("Welcome to TinyViz");  private JPanel statusLinePanel = new JPanel();  class pluginInfo {    boolean registered = false;    Plugin plugin;    JCheckBoxMenuItem checkbox;    JPanel panel;    int tabNum;    pluginInfo(Plugin plugin) {      this.plugin = plugin;      this.checkbox = null;      this.panel = null;      this.tabNum = -1;    }    void register() {      if (registered) return;       registered = true;      plugin.register();      plugin.reset();      tv.getEventBus().register(plugin);      /* Send all current option settings to this plugin */      Enumeration e = tv.getOptions();      while (e.hasMoreElements()) {	String option = (String)e.nextElement();	plugin.handleEvent(new net.tinyos.sim.event.OptionSetEvent(option, tv.getOption(option)));      }      if (checkbox != null) checkbox.setSelected(true);      if (tabNum >= 0) {	pluginTabbedPane.setEnabledAt(tabNum, true);	pluginTabbedPane.setSelectedIndex(tabNum);      }    }    void deregister() {      if (!registered) return;      registered = false;      plugin.reset();      tv.getEventBus().deregister(plugin);      plugin.deregister();      if (checkbox != null) checkbox.setSelected(false);      if (tabNum >= 0) {	pluginTabbedPane.setEnabledAt(tabNum, false);	panel.removeAll();      }    }  }  public PluginPanel(TinyViz tv, String plugin_path) {    super();    this.tv = tv;    this.eventBus = tv.getEventBus();    this.plugins = new Vector();    // Plugin area and menu    pluginAreaPanel = new JPanel();    pluginAreaPanel.setLayout(new BorderLayout());    pluginAreaPanel.setPreferredSize(new Dimension(MOTE_PANEL_WIDTH,MOTE_PANEL_HEIGHT));    pluginTabbedPane = new JTabbedPane();    pluginTabbedPane.setTabPlacement(JTabbedPane.TOP);    pluginTabbedPane.setFont(tv.labelFont);    pluginAreaPanel.add(pluginTabbedPane, BorderLayout.CENTER);    pluginReader = new PluginReader(plugin_path);    Plugin[] parr = pluginReader.plugins();    JMenuItem selAll = new JMenuItem("Select all");    selAll.setFont(tv.defaultFont);    selAll.addActionListener(new saListener());    JMenuItem deselAll = new JMenuItem("Deselect all");    deselAll.setFont(tv.defaultFont);    deselAll.addActionListener(new dsaListener());    pluginMenu.add(selAll);    pluginMenu.add(deselAll);    pluginMenu.add(new JSeparator());    for (int i = 0; i < parr.length; i++) {      addPlugin(parr[i]);    }    if (parr.length > 2) {      pluginTabbedPane.setSelectedIndex(0);    } else {      System.err.println("WARNING: Could not find any plugins. Check your plugin path.");    }    tv.getMenuBar().addMenu(pluginMenu);    GridBagLayout gridbag = new GridBagLayout();    GridBagConstraints c = new GridBagConstraints();    setLayout(gridbag);    //setLayout(new BorderLayout());    // Plugin panel    c.anchor = GridBagConstraints.NORTH;    c.gridwidth = GridBagConstraints.REMAINDER;    c.weightx = 1;    c.weighty = 1;    c.fill = GridBagConstraints.BOTH;    gridbag.setConstraints(pluginAreaPanel, c);    // Status    //statusLinePanel.setBackground(Color.white);    statusLinePanel.setLayout(new FlowLayout(FlowLayout.LEFT));    statusLinePanel.setPreferredSize(new Dimension(MOTE_PANEL_WIDTH, 20));    statusLinePanel.add(statusLine);    statusLine.setFont(tv.defaultFont);    statusLine.setForeground(Color.blue);    c.anchor = GridBagConstraints.SOUTHWEST;    c.fill = GridBagConstraints.HORIZONTAL;    gridbag.setConstraints(statusLinePanel, c);    add(pluginAreaPanel);    add(statusLinePanel);    //add(pluginAreaPanel, BorderLayout.CENTER);    //add(statusLinePanel, BorderLayout.SOUTH);  }  public Plugin[] plugins() {    Plugin parr[] = new Plugin[plugins.size()];    synchronized (eventBus) {      int n = 0;      Enumeration e = plugins.elements();      while (e.hasMoreElements()) {	pluginInfo pi = (pluginInfo)e.nextElement();	parr[n++] = pi.plugin;      }      return parr;    }  }  public Plugin getPlugin(String name) {    Enumeration e = plugins.elements();    while (e.hasMoreElements()) {      pluginInfo pi = (pluginInfo)e.nextElement();      if (pi.plugin.getClass().getName().endsWith(name)) {	return pi.plugin;      }    }    return null;  }  public void addPlugin(Plugin plugin) {    pluginInfo pinfo = new pluginInfo(plugin);    // MotePlugin is always enabled    if (plugin instanceof MotePlugin) {      plugins.add(pinfo);      plugin.initialize(tv, null);      pinfo.register();      return;    }    pinfo.tabNum = plugins.size() - 1;    String name = plugin.toString();    pinfo.checkbox = new JCheckBoxMenuItem(name);    pinfo.checkbox.setSelected(false);    cbListener cbl = new cbListener(pinfo);    pinfo.checkbox.addItemListener(cbl);    pinfo.checkbox.setFont(tv.defaultFont);    pluginMenu.add(pinfo.checkbox);    pinfo.panel = new JPanel();    //plugin_panes[n].setMinimumSize(new Dimension(400,300));    //plugin_panes[n].setPreferredSize(new Dimension(400,300));    pinfo.panel.setFont(tv.defaultFont);    pluginTabbedPane.addTab(name, pinfo.panel);    pluginTabbedPane.setEnabledAt(pinfo.tabNum, false);    plugins.addElement(pinfo);    plugin.initialize(tv, pinfo.panel);  }  public void reset() {    Enumeration e = plugins.elements();    while (e.hasMoreElements()) {      pluginInfo pi = (pluginInfo)e.nextElement();      pi.plugin.reset();    }  }  public void refresh() {    repaint();  }  public void paint(Graphics g) {    synchronized (eventBus) {      super.paint(g);    }  }  public void setStatus(String s) {    synchronized (statusLine) {      statusLine.setText(s);    }  }  public void register(Plugin plugin) {    Enumeration e = plugins.elements();    while (e.hasMoreElements()) {      pluginInfo pi = (pluginInfo)e.nextElement();      if (pi.plugin == plugin) pi.register();    }  }  public void deregister(Plugin plugin) {    Enumeration e = plugins.elements();    while (e.hasMoreElements()) {      pluginInfo pi = (pluginInfo)e.nextElement();      if (pi.plugin == plugin) pi.deregister();    }  }  protected class saListener implements ActionListener {    public void actionPerformed(ActionEvent e) {      Enumeration en = plugins.elements();      while (en.hasMoreElements()) {	pluginInfo pi = (pluginInfo)en.nextElement();	if (pi.checkbox != null) {	  if (!pi.checkbox.getState()) pi.checkbox.doClick();	}      }    }  }  protected class dsaListener implements ActionListener {    public void actionPerformed(ActionEvent e) {      Enumeration en = plugins.elements();      while (en.hasMoreElements()) {	pluginInfo pi = (pluginInfo)en.nextElement();	if (pi.checkbox != null) {	  if (pi.checkbox.getState()) pi.checkbox.doClick();	}      }    }  }  protected class cbListener implements ItemListener {    private pluginInfo pinfo;    cbListener(pluginInfo pinfo) {      this.pinfo = pinfo;    }    public void itemStateChanged(ItemEvent e) {      if (e.getStateChange() == ItemEvent.SELECTED) {	tv.setStatus("Registering: "+pinfo.plugin);	pinfo.register();      } else {	tv.setStatus("Deregistering: "+pinfo.plugin);	pinfo.deregister();      }    }  }}

⌨️ 快捷键说明

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