KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > mdrxml > looks > NodeLook


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is Forte for Java, Community Edition. The Initial
16  * Developer of the Original Software is Sun Microsystems, Inc. Portions
17  * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.mdrxml.looks;
21
22 import java.lang.ref.WeakReference JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.awt.datatransfer.Transferable JavaDoc;
25 import org.openide.actions.PropertiesAction;
26 import org.openide.nodes.*;
27 import org.openide.util.NbBundle;
28 import org.openide.util.actions.SystemAction;
29 import org.netbeans.api.looks.*;
30 import org.netbeans.spi.looks.*;
31 import org.netbeans.modules.mdrxml.looks.actions.DeleteAction;
32 import org.netbeans.modules.mdrxml.looks.actions.GenerateTextAction;
33 /**
34  *
35  * @author Tomas Zezula
36  */

37 public class NodeLook extends DefaultLook {
38     
39     private static class NameProperty extends PropertySupport.ReadWrite {
40         
41         private WeakReference JavaDoc ref;
42         
43         public NameProperty(Look.NodeSubstitute substitute) {
44             super(NbBundle.getMessage(NodeLook.class,"TXT_Name"),String JavaDoc.class,NbBundle.getMessage(NodeLook.class,"TXT_Name"),NbBundle.getMessage(NodeLook.class,"TIP_Name"));
45             this.ref = new WeakReference JavaDoc (substitute);
46         }
47         
48         public Object JavaDoc getValue() {
49         Look.NodeSubstitute val = (Look.NodeSubstitute) this.ref.get ();
50             if (val != null && (val.getRepresentedObject() instanceof xmlmodel.Node)) {
51                 return ((xmlmodel.Node)val.getRepresentedObject()).getName();
52             }
53             else {
54                 return null;
55             }
56         }
57         
58         public void setValue(Object JavaDoc value) {
59         Look.NodeSubstitute val = (Look.NodeSubstitute) this.ref.get ();
60             if (value instanceof String JavaDoc && val != null && val.getRepresentedObject() instanceof xmlmodel.Node) {
61                 ((xmlmodel.Node)val.getRepresentedObject()).setName((String JavaDoc)value);
62                 val.fireNameChange(null,(String JavaDoc)value);
63                 val.fireDisplayNameChange(null,(String JavaDoc)value);
64             }
65         }
66         
67     }
68     
69     /** Creates a new instance of NodeLook */
70     public NodeLook(String JavaDoc name) {
71         super(name);
72     }
73     
74     public String JavaDoc getName(Look.NodeSubstitute substitute) {
75         try {
76             xmlmodel.Node en = (xmlmodel.Node) substitute.getRepresentedObject();
77             return en.getName();
78         }catch (javax.jmi.reflect.InvalidObjectException ioe) {
79             return new String JavaDoc ();
80         }
81     }
82     
83     public String JavaDoc getDisplayName(Look.NodeSubstitute substitute) {
84         return this.getName(substitute);
85     }
86     
87     public Node.PropertySet[] getPropertySets(Look.NodeSubstitute substitute) {
88         Sheet.Set set = new Sheet.Set();
89         String JavaDoc name = NbBundle.getMessage(NodeLook.class,"TXT_Properties");
90         set.setName(name);
91         set.setDisplayName(name);
92         set.put(new NameProperty(substitute));
93         return new Node.PropertySet[] {set};
94     }
95     
96     public javax.swing.Action JavaDoc[] getActions(Look.NodeSubstitute substitute) {
97         return new javax.swing.Action JavaDoc[] {
98             SystemAction.get(DeleteAction.class),
99             SystemAction.get(PropertiesAction.class),
100             SystemAction.get(GenerateTextAction.class)
101         };
102     }
103     
104     public boolean canCopy (Look.NodeSubstitute substitute) {
105       return true;
106     }
107     
108     public Transferable JavaDoc drag (Look.NodeSubstitute substitute) throws IOException JavaDoc {
109         return this.clipboardCopy (substitute);
110     }
111     
112 }
113
Popular Tags