KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * LayoutNode.java
3  *
4  * Created on June 28, 2005, 2:53 PM
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 javax.swing.AbstractAction JavaDoc;
15 import javax.swing.Action JavaDoc;
16 import org.netbeans.modules.piagetproject.layout.LayoutBuilder;
17 import org.openide.util.Utilities;
18 import org.openide.nodes.AbstractNode;
19 import org.openide.nodes.Children;
20
21
22 /**
23  *
24  * @author loicsegapelli
25  */

26 public class LayoutNode extends AbstractNode implements PiagetTreeNode{
27     
28     Info info;
29     private AbstractAction JavaDoc actionInstance;
30     
31     /** Creates a new instance of LayoutNode */
32     public LayoutNode(String JavaDoc filepath, String JavaDoc username, String JavaDoc level) {
33         super(Children.LEAF);
34         info = new Info(filepath, username, level);
35         setShortDescription("window layout");
36         super.setName("layout");
37     }
38     
39     public Action JavaDoc[] getActions(boolean context) {
40         Action JavaDoc[] result = new Action JavaDoc[] {
41             getLayoutAction(),
42                     new DeleteAction((AbstractNode)this, info.path)
43         };
44         return result;
45     }
46     
47     public synchronized AbstractAction JavaDoc getLayoutAction(){
48         if(actionInstance==null) actionInstance = new LayoutAction(info.path);
49         return actionInstance;
50     }
51     
52     public Image JavaDoc getIcon(int type) {
53         return Utilities.loadImage("org/netbeans/modules/piagetproject/resources/layout.png");
54     }
55     
56     public Image JavaDoc getOpenedIcon(int type) {
57         return getIcon(type);
58     }
59     
60     public Action JavaDoc getPreferredAction() {
61         return getLayoutAction();
62     }
63     
64     public Info [] getInfos() {
65         return new Info [] {info};
66     }
67     
68     private class LayoutAction extends AbstractAction JavaDoc {
69         
70         String JavaDoc filepath;
71         
72         public LayoutAction(String JavaDoc filepath){
73             putValue(Action.NAME, "layout");
74             this.filepath = filepath;
75         }
76         
77         public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
78             LayoutBuilder.doLayout(filepath);
79         }
80
81         protected Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
82             throw new CloneNotSupportedException JavaDoc();
83         }
84     }
85 }
86
Popular Tags