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

📄 directedgraphplugin.java

📁 传感器网络中的嵌入式操作系统源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        ta.setText("This plugin allows you to define graphs, add edges and remove edges with the two following commands."+                "To display one such graph, select it from the list below.  One can also add " +                "color or labels to the edges or change the directions of the arrows; see DirectedGraphPlugin.java for documentation.");        pluginPanel.add(ta);        JTextArea ta2 = new JTextArea(1, 50);        ta2.setFont(tv.defaultFont);        ta2.setEditable(false);        ta2.setBackground(Color.lightGray);        ta2.setLineWrap(true);        ta2.setText("dbg(DBG_USR1, \"MyGraphName DIRECTED GRAPH: remove edge %d\n\", someNodeID);.");        pluginPanel.add(ta2);        JTextArea ta3 = new JTextArea(1, 50);        ta3.setFont(tv.defaultFont);        ta3.setEditable(false);        ta3.setBackground(Color.lightGray);        ta3.setLineWrap(true);        ta3.setText("dbg(DBG_USR1, \"MyGraphName DIRECTED GRAPH: add edge %d\n\", someNodeID);");        pluginPanel.add(ta3);  */        JPanel parameterPane = new JPanel();        parameterPane.setLayout(new GridLayout(7,2,1,1));        // Create radius constant text field and label        JLabel neighborhoodNameLabel = new JLabel("Graph Name");        neighborhoodNameLabel.setFont(tv.defaultFont);//        cb.addActionListener(new ComboBoxListener());        parameterPane.add(neighborhoodNameLabel);//        parameterPane.add(cb);        parameterPane.add(graphList);        cbSelectedOnly = new JCheckBox("Selected motes only", selectedOnly);        cbSelectedOnly.addItemListener(new DirectedGraphPlugin.cbListener());        cbSelectedOnly.setFont(tv.labelFont);        parameterPane.add(cbSelectedOnly);        JButton help = new JButton ("Instructions");        help.setToolTipText("help");        help.setFont(new Font("Helvetica", Font.PLAIN, 12));        help.setForeground(Color.blue);        help.setActionCommand("help");        help.addActionListener (this);        parameterPane.add(help);        pluginPanel.add(parameterPane);        pluginPanel.revalidate();    }    public void deregister            () {    }    public void draw(Graphics graphics) {        Enumeration enum = neighborhoods.elements();        while (enum.hasMoreElements()) {            Neighborhood neighborhood = (Neighborhood) enum.nextElement();            MoteSimObject mote = state.getMoteSimObject(neighborhood.nodeID);            if (mote == null) continue;            MoteCoordinateAttribute coord = mote.getCoordinate();            if (!selectedOnly ||            state.getSelectedMoteSimObjects().contains(state.getMoteSimObject(neighborhood.nodeID))) {                Enumeration neighbors = neighborhood.neighbors.elements();                while (neighbors.hasMoreElements()) {                    Neighbor neighborID = (Neighbor) neighbors.nextElement();                    MoteSimObject neighbor = state.getMoteSimObject(neighborID.nodeID);                    if( (neighbor == null) || (!isSelected(neighborID.neighborhood)) || (neighborID.timeout >=0 && neighborID.timeout < tv.getTosTime()*1000)) continue;                    MoteCoordinateAttribute neighborCoord = neighbor.getCoordinate();                    graphics.setColor(neighborID.color);                    int x1=(int) cT.simXToGUIX(coord.getX())+neighborID.offset;                    int y1=(int) cT.simYToGUIY(coord.getY())+neighborID.offset;                    int x2=(int) cT.simXToGUIX(neighborCoord.getX())+neighborID.offset;                    int y2=(int) cT.simYToGUIY(neighborCoord.getY())+neighborID.offset;                    Arrow.drawArrow(graphics,x1, y1,x2, y2,neighborID.direction);                    if(neighborID.label!=null){                        int xMidPoint = x1 + (x2-x1)/2;                        int yMidPoint = y1 + (y2-y1)/2;                        graphics.drawString(neighborID.label, xMidPoint, yMidPoint);                    }                }            }        }    }    public void clearAll(String hoodName) {        Enumeration enum = neighborhoods.elements();        while (enum.hasMoreElements()) {            Neighborhood neighborhood = (Neighborhood) enum.nextElement();            Enumeration neighbors = neighborhood.neighbors.elements();            while (neighbors.hasMoreElements()) {                Neighbor neighborID = (Neighbor) neighbors.nextElement();                if(neighborID.neighborhood.equalsIgnoreCase(hoodName)){                    neighborhood.neighbors.remove(neighborID);                }            }        }    }    public boolean isSelected(String graphName){        int selectedGraphs[] = graphList.getSelectedIndices();        for(int i=0; i<selectedGraphs.length;i++){            if(((String)knownHoods.get(selectedGraphs[i])).equalsIgnoreCase(graphName)){                return true;            }        }        return false;    }    public String toString            () {        return "Directed Graph";    }    public class Neighborhood {        public int nodeID;        public Vector neighbors;        Neighborhood(int id) {            nodeID=id;            neighbors=new Vector();        }    }    public class Neighbor {        public int nodeID;        public String neighborhood;        public Color color;        public String label;        public int direction;        public int timeout;        public int offset; //this draws the arrow a little to the side        Neighbor(int id, String hood, Color colour, String Label, int Direction, int Timeout, int Offset) {            nodeID=id;            neighborhood=hood;            color=colour;            label=Label;            direction=Direction;            timeout=Timeout;            offset=Offset;        }        Neighbor(int id, String hood) {            nodeID=id;            neighborhood=hood;        }        public boolean equals(Object obj){            return (nodeID==((Neighbor)obj).nodeID &&                    (neighborhood.equals(((Neighbor)obj).neighborhood)));        }    }   class cbListener implements ItemListener {    public void itemStateChanged(ItemEvent e) {      selectedOnly = (e.getStateChange() == e.SELECTED);    }  }/*  class ComboBoxListener implements ActionListener {    public void actionPerformed(ActionEvent e) {      drawingHood = (String)cb.getSelectedItem();      motePanel.refresh();    }  }                         */    public void actionPerformed (ActionEvent e) {        try {        if(e.getActionCommand() == "help") {            if(helpText!=null){                JDialog dialog = new JDialog();                dialog.getContentPane().add(helpText);                dialog.setSize(600,700);                dialog.setVisible(true);            }        }        } catch(Exception ee) {        }    }}

⌨️ 快捷键说明

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