KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > ui > nodes > categorized > DecoratedDisplayNameFilterNode


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 NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.schema.ui.nodes.categorized;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.text.MessageFormat JavaDoc;
25 import org.openide.nodes.FilterNode;
26 import org.openide.nodes.Node;
27
28 /**
29  *
30  * @author Todd Fast, todd.fast@sun.com
31  */

32 public class DecoratedDisplayNameFilterNode extends FilterNode
33 {
34     /**
35      *
36      *
37      */

38     public DecoratedDisplayNameFilterNode(final Node original,
39         String JavaDoc template, String JavaDoc initialName)
40     {
41         super(original);
42
43         this.template=template;
44
45         // Manage our own display name
46
disableDelegation(
47             FilterNode.DELEGATE_GET_DISPLAY_NAME |
48             FilterNode.DELEGATE_SET_DISPLAY_NAME);
49
50         setDecoratedDisplayName(initialName);
51
52         // Listen to display name changes in the original node, and set
53
// our display name to incorporate the original's name
54
original.addPropertyChangeListener(
55             new PropertyChangeListener JavaDoc()
56             {
57                 public void propertyChange(PropertyChangeEvent JavaDoc event)
58                 {
59                     if (event.getSource()==original &&
60                         event.getPropertyName().equals(
61                             Node.PROP_DISPLAY_NAME))
62                     {
63                         setDecoratedDisplayName((String JavaDoc)event.getNewValue());
64                     }
65                 }
66             });
67     }
68
69
70     /**
71      *
72      *
73      */

74     public String JavaDoc getTemplate()
75     {
76         return template;
77     }
78
79
80     /**
81      *
82      *
83      */

84     public void setTemplate(String JavaDoc value)
85     {
86         template=value;
87         setDecoratedDisplayName(lastName);
88     }
89
90
91     /**
92      *
93      *
94      */

95     public void setDecoratedDisplayName(String JavaDoc name)
96     {
97         setDisplayName(MessageFormat.format(getTemplate(),name));
98         lastName=name;
99     }
100
101
102
103
104     ////////////////////////////////////////////////////////////////////////////
105
// Instance members
106
////////////////////////////////////////////////////////////////////////////
107

108     private String JavaDoc template;
109     private transient String JavaDoc lastName;
110 }
111
Popular Tags