KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > excalibur > instrument > client > NodeData


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19
20 package org.apache.excalibur.instrument.client;
21
22 import javax.swing.ImageIcon JavaDoc;
23 import javax.swing.JMenuItem JavaDoc;
24 import javax.swing.JPopupMenu JavaDoc;
25
26 /**
27  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
28  */

29 abstract class NodeData
30 {
31     protected static final String JavaDoc MEDIA_PATH = "org/apache/excalibur/instrument/client/media/";
32     protected static final JMenuItem JavaDoc[] EMPTY_MENU_ITEM_ARRAY = new JMenuItem JavaDoc[0];
33     
34     private String JavaDoc m_name;
35     private String JavaDoc m_description;
36     private int m_stateVersion;
37     
38     /*---------------------------------------------------------------
39      * Constructors
40      *-------------------------------------------------------------*/

41     protected NodeData()
42     {
43     }
44     
45     /*---------------------------------------------------------------
46      * Methods
47      *-------------------------------------------------------------*/

48     String JavaDoc getName()
49     {
50         return m_name;
51     }
52     
53     String JavaDoc getDescription()
54     {
55         return m_description;
56     }
57     
58     void setDescription( String JavaDoc description )
59     {
60         m_description = description;
61     }
62     
63     int getStateVersion()
64     {
65         return m_stateVersion;
66     }
67     
68     /**
69      * Get the icon to display for the node.
70      *
71      * @return the icon to display for the node.
72      */

73     abstract ImageIcon JavaDoc getIcon();
74     
75     /**
76      * Return the text to use for a tool tip on this node.
77      *
78      * @return Tool Tip text. May be null, for no tool tip.
79      */

80     abstract String JavaDoc getToolTipText();
81     
82     /**
83      * Return the popup for the node.
84      *
85      * @return The the popup for the node.
86      */

87     public JPopupMenu JavaDoc getPopupMenu()
88     {
89         JPopupMenu JavaDoc popup;
90         JMenuItem JavaDoc[] menuItems = getCommonMenuItems();
91         if ( menuItems.length == 0 )
92         {
93             popup = null;
94         }
95         else
96         {
97             popup = new JPopupMenu JavaDoc( getDescription() );
98             for ( int i = 0; i < menuItems.length; i++ )
99             {
100                 popup.add( menuItems[i] );
101             }
102         }
103         
104         return popup;
105     }
106     
107     /**
108      * Returns an array of any menu items which will be displayed both
109      * in a popup menu and in the menus.
110      *
111      * @return An array of the common menu items.
112      */

113     public JMenuItem JavaDoc[] getCommonMenuItems()
114     {
115         return EMPTY_MENU_ITEM_ARRAY;
116     }
117     
118     /**
119      * Called when the node is selected.
120      */

121     void select()
122     {
123     }
124     
125     
126     boolean update( String JavaDoc name, String JavaDoc description, int stateVersion )
127     {
128         boolean changed = false;
129         
130         changed |= name.equals( m_name );
131         m_name = name;
132         
133         changed |= description.equals( m_description );
134         m_description = description;
135         
136         changed |= stateVersion == m_stateVersion;
137         m_stateVersion = stateVersion;
138         
139         return changed;
140     }
141     
142     public String JavaDoc toString()
143     {
144         return m_description;
145     }
146 }
147
Popular Tags