KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > piagetproject > treestructure > LevelNode


1 /*
2  * LevelNode.java
3  *
4  * Created on June 25, 2005, 11:33 AM
5  *
6  * To change this template, choose Tools | Options and locate the template under
7  * the Source Creation and Management node. Right-click the template and choose
8  * Open. You can then make changes to the template in the Source Editor.
9  */

10
11 package org.netbeans.modules.piagetproject.treestructure;
12
13 import java.awt.Image JavaDoc;
14 import java.util.ArrayList JavaDoc;
15 import javax.swing.Action JavaDoc;
16 import org.netbeans.modules.piagetproject.PiagetProjectFactory;
17 import org.openide.nodes.AbstractNode;
18 import org.openide.nodes.Children;
19 import org.openide.nodes.Node;
20 import org.openide.util.Utilities;
21
22 /**
23  *
24  * @author loicsegapelli
25  */

26 public class LevelNode extends AbstractNode implements PiagetTreeNode{
27     
28     private int level;
29     
30     /** Creates a new instance of LevelNode */
31     public LevelNode(int level) {
32         super(NodeRetriever.getUsers(level));
33         this.level = level;
34         String JavaDoc myLevel = PiagetProjectFactory.getLevelName(level);
35         this.setName(myLevel);
36         setShortDescription("Level node: "+myLevel);
37     }
38     
39     public Action JavaDoc[] getActions(boolean context) {
40         
41         Action JavaDoc[] result = new Action JavaDoc[] {
42             StatsAction.getInstance()
43         };
44         return result;
45     }
46     
47     public Image JavaDoc getIcon(int type) {
48         switch (level){
49             case 1:
50                 return Utilities.loadImage("org/netbeans/modules/piagetproject/resources/level1.png");
51             case 2:
52                 return Utilities.loadImage("org/netbeans/modules/piagetproject/resources/level2.png");
53             case 3:
54                 return Utilities.loadImage("org/netbeans/modules/piagetproject/resources/level3.png");
55             default:
56                 return Utilities.loadImage("org/netbeans/modules/piagetproject/resources/level1.png");
57         }
58     }
59     
60     public Image JavaDoc getOpenedIcon(int type) {
61         return getIcon(type);
62     }
63     
64
65     /**
66      * a <I>level</I> node will ask all <I>user</I> subnodes to get all their
67      * <I>session</I> subnode infos: the method <CODE>getInfo</CODE> is
68      * propagated
69      * @return an array containing all subnodes infos
70      */

71     public Info [] getInfos() {
72         Children c = this.getChildren();
73         Node n [] = c.getNodes();
74         ArrayList JavaDoc infos = new ArrayList JavaDoc();
75         
76         for(int i=0; i<c.getNodesCount(); i++){
77             Info nodeInfos [] = ((PiagetTreeNode)n[i]).getInfos();
78             for(int j=0; j<nodeInfos.length; j++) infos.add(nodeInfos[j]);
79         }
80         
81         Info [] out = new Info [infos.size()];
82         for(int i=0; i<out.length; i++) out [i] = (Info)infos.get(i);
83         
84         return out;
85     }
86     
87 }
88
89
Popular Tags