KickJava   Java API By Example, From Geeks To Geeks.

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


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
24 /**
25  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
26  */

27 class InstrumentableNodeData
28     extends NodeData
29 {
30     /** An Instrumentable which exists because of configuration. */
31     private static final ImageIcon JavaDoc m_iconInstrumentableConf;
32     
33     /** An Instrumentable which exists because of registration. */
34     private static final ImageIcon JavaDoc m_iconInstrumentableReg;
35     
36     /** An Instrumentable which exists because of registration and
37      * configuration. */

38     private static final ImageIcon JavaDoc m_iconInstrumentableRegConf;
39     
40     /** An Instrumentable which exists because it was loaded from the state
41      * file but is no longer used. */

42     private static final ImageIcon JavaDoc m_iconInstrumentableOld;
43     
44     private InstrumentableData m_data;
45     
46     private boolean m_configured;
47     private boolean m_registered;
48     
49     /*---------------------------------------------------------------
50      * Class Initializer
51      *-------------------------------------------------------------*/

52     static
53     {
54         // Load the images.
55
ClassLoader JavaDoc cl = InstrumentManagerTreeCellRenderer.class.getClassLoader();
56         m_iconInstrumentableConf =
57             new ImageIcon JavaDoc( cl.getResource( MEDIA_PATH + "instrumentable_conf.gif") );
58         m_iconInstrumentableReg =
59             new ImageIcon JavaDoc( cl.getResource( MEDIA_PATH + "instrumentable_reg.gif") );
60         m_iconInstrumentableRegConf =
61             new ImageIcon JavaDoc( cl.getResource( MEDIA_PATH + "instrumentable_reg_conf.gif") );
62         m_iconInstrumentableOld =
63             new ImageIcon JavaDoc( cl.getResource( MEDIA_PATH + "instrumentable_old.gif") );
64     }
65         
66     /*---------------------------------------------------------------
67      * Constructors
68      *-------------------------------------------------------------*/

69     InstrumentableNodeData( InstrumentableData data )
70     {
71         m_data = data;
72         
73         update();
74     }
75     
76     /*---------------------------------------------------------------
77      * NodeData Methods
78      *-------------------------------------------------------------*/

79     /**
80      * Get the icon to display for the node.
81      *
82      * @return the icon to display for the node.
83      */

84     ImageIcon JavaDoc getIcon()
85     {
86         ImageIcon JavaDoc icon;
87         if ( isConfigured() && isRegistered() )
88         {
89             icon = m_iconInstrumentableRegConf;
90         }
91         else if ( isConfigured() )
92         {
93             icon = m_iconInstrumentableConf;
94         }
95         else if ( isRegistered() )
96         {
97             icon = m_iconInstrumentableReg;
98         }
99         else
100         {
101             icon = m_iconInstrumentableOld;
102         }
103         
104         return icon;
105     }
106     
107     /**
108      * Return the text to use for a tool tip on this node.
109      *
110      * @return Tool Tip text. May be null, for no tool tip.
111      */

112     String JavaDoc getToolTipText()
113     {
114         String JavaDoc text;
115         if ( isConfigured() && isRegistered() )
116         {
117             text = "Registered and Configured Instrumentable";
118         }
119         else if ( isConfigured() )
120         {
121             text = "Configured but unregistered Instrumentable";
122         }
123         else if ( isRegistered() )
124         {
125             text = "Registered Instrumentable";
126         }
127         else
128         {
129             text = "Old Instrumentable loaded from state file";
130         }
131         
132         return text;
133     }
134     
135     /*---------------------------------------------------------------
136      * Methods
137      *-------------------------------------------------------------*/

138     InstrumentableData getData()
139     {
140         return m_data;
141     }
142     
143     boolean isConfigured()
144     {
145         return m_configured;
146     }
147     
148     boolean isRegistered()
149     {
150         return m_registered;
151     }
152     
153     /**
154      * Collect latest property values from the server. Each call is remote so this
155      * allows us to use cached values locally to speed things up.
156      */

157     boolean update()
158     {
159         boolean changed = false;
160         changed |= update( m_data.getName(), m_data.getDescription(), m_data.getStateVersion() );
161         
162         boolean newConfigured = m_data.isConfigured();
163         if ( newConfigured != m_configured )
164         {
165             changed = true;
166             m_configured = newConfigured;
167         }
168         
169         boolean newRegistered = m_data.isRegistered();
170         if ( newRegistered != m_registered )
171         {
172             changed = true;
173             m_registered = newRegistered;
174         }
175         
176         return changed;
177     }
178 }
179
Popular Tags