1 19 package org.apache.excalibur.instrument.client; 20 21 import java.awt.event.ActionEvent ; 22 23 import javax.swing.AbstractAction ; 24 import javax.swing.Action ; 25 import javax.swing.ImageIcon ; 26 import javax.swing.JMenuItem ; 27 28 31 class InstrumentNodeData 32 extends NodeData 33 { 34 35 private static final ImageIcon m_iconInstrumentCtrConf; 36 37 38 private static final ImageIcon m_iconInstrumentCtrReg; 39 40 42 private static final ImageIcon m_iconInstrumentCtrRegConf; 43 44 46 private static final ImageIcon m_iconInstrumentCtrOld; 47 48 49 private static final ImageIcon m_iconInstrumentValConf; 50 51 52 private static final ImageIcon m_iconInstrumentValReg; 53 54 56 private static final ImageIcon m_iconInstrumentValRegConf; 57 58 60 private static final ImageIcon m_iconInstrumentValOld; 61 62 private InstrumentData m_data; 63 private InstrumentManagerConnection m_connection; 64 65 private boolean m_configured; 66 private boolean m_registered; 67 private int m_type; 68 69 72 static 73 { 74 ClassLoader cl = InstrumentManagerTreeCellRenderer.class.getClassLoader(); 76 m_iconInstrumentCtrConf = 77 new ImageIcon ( cl.getResource( MEDIA_PATH + "instrument_ctr_conf.gif") ); 78 m_iconInstrumentCtrReg = 79 new ImageIcon ( cl.getResource( MEDIA_PATH + "instrument_ctr_reg.gif") ); 80 m_iconInstrumentCtrRegConf = 81 new ImageIcon ( cl.getResource( MEDIA_PATH + "instrument_ctr_reg_conf.gif") ); 82 m_iconInstrumentCtrOld = 83 new ImageIcon ( cl.getResource( MEDIA_PATH + "instrument_ctr_old.gif") ); 84 85 m_iconInstrumentValConf = 86 new ImageIcon ( cl.getResource( MEDIA_PATH + "instrument_val_conf.gif") ); 87 m_iconInstrumentValReg = 88 new ImageIcon ( cl.getResource( MEDIA_PATH + "instrument_val_reg.gif") ); 89 m_iconInstrumentValRegConf = 90 new ImageIcon ( cl.getResource( MEDIA_PATH + "instrument_val_reg_conf.gif") ); 91 m_iconInstrumentValOld = 92 new ImageIcon ( cl.getResource( MEDIA_PATH + "instrument_val_old.gif") ); 93 } 94 95 98 InstrumentNodeData( InstrumentData data, 99 InstrumentManagerConnection connection ) 100 { 101 m_data = data; 102 m_connection = connection; 103 104 update(); 105 } 106 107 108 111 116 ImageIcon getIcon() 117 { 118 ImageIcon icon; 119 switch ( getType() ) 120 { 121 case InstrumentData.INSTRUMENT_TYPE_COUNTER: 122 if ( isConfigured() && isRegistered() ) 123 { 124 icon = m_iconInstrumentCtrRegConf; 125 } 126 else if ( isConfigured() ) 127 { 128 icon = m_iconInstrumentCtrConf; 129 } 130 else if ( isRegistered() ) 131 { 132 icon = m_iconInstrumentCtrReg; 133 } 134 else 135 { 136 icon = m_iconInstrumentCtrOld; 137 } 138 break; 139 140 case InstrumentData.INSTRUMENT_TYPE_VALUE: 141 if ( isConfigured() && isRegistered() ) 142 { 143 icon = m_iconInstrumentValRegConf; 144 } 145 else if ( isConfigured() ) 146 { 147 icon = m_iconInstrumentValConf; 148 } 149 else if ( isRegistered() ) 150 { 151 icon = m_iconInstrumentValReg; 152 } 153 else 154 { 155 icon = m_iconInstrumentValOld; 156 } 157 break; 158 159 default: 160 throw new IllegalStateException ( "Encountered an unknown instrument type: " + 161 getType() ); 162 } 163 164 return icon; 165 } 166 167 172 String getToolTipText() 173 { 174 String text; 175 switch ( getType() ) 176 { 177 case InstrumentData.INSTRUMENT_TYPE_COUNTER: 178 if ( isConfigured() && isRegistered() ) 179 { 180 text = "Registered and Configured Counter Instrument"; 181 } 182 else if ( isConfigured() ) 183 { 184 text = "Configured but unregistered Counter Instrument"; 185 } 186 else if ( isRegistered() ) 187 { 188 text = "Registered Counter Instrument"; 189 } 190 else 191 { 192 text = "Old Counter Instrument loaded from state file"; 193 } 194 break; 195 196 case InstrumentData.INSTRUMENT_TYPE_VALUE: 197 if ( isConfigured() && isRegistered() ) 198 { 199 text = "Registered and Configured Value Instrument"; 200 } 201 else if ( isConfigured() ) 202 { 203 text = "Configured but unregistered Value Instrument"; 204 } 205 else if ( isRegistered() ) 206 { 207 text = "Registered Value Instrument"; 208 } 209 else 210 { 211 text = "Old Value Instrument loaded from state file"; 212 } 213 break; 214 215 default: 216 throw new IllegalStateException ( "Encountered an unknown instrument type: " + 217 getType() ); 218 } 219 220 return text; 221 } 222 223 229 public JMenuItem [] getCommonMenuItems() 230 { 231 JMenuItem [] menuItems = new JMenuItem [1]; 232 233 Action createSampleAction = new AbstractAction ( "Create Sample..." ) 234 { 235 public void actionPerformed( ActionEvent event ) 236 { 237 InstrumentData data = InstrumentNodeData.this.getData(); 239 m_connection.showCreateSampleDialog( data ); 240 } 241 }; 242 JMenuItem createSampleItem = new JMenuItem ( createSampleAction ); 243 createSampleItem.setMnemonic( 'C' ); 244 menuItems[0] = createSampleItem; 245 246 return menuItems; 247 } 248 249 252 InstrumentData getData() 253 { 254 return m_data; 255 } 256 257 boolean isConfigured() 258 { 259 return m_configured; 260 } 261 262 boolean isRegistered() 263 { 264 return m_registered; 265 } 266 267 int getType() 268 { 269 return m_type; 270 } 271 272 boolean update() 273 { 274 boolean changed = false; 275 changed |= update( m_data.getName(), m_data.getDescription(), m_data.getStateVersion() ); 276 277 boolean newConfigured = m_data.isConfigured(); 278 if ( newConfigured != m_configured ) 279 { 280 changed = true; 281 m_configured = newConfigured; 282 } 283 284 boolean newRegistered = m_data.isRegistered(); 285 if ( newRegistered != m_registered ) 286 { 287 changed = true; 288 m_registered = newRegistered; 289 } 290 291 int newType = m_data.getType(); 292 if ( newType != m_type ) 293 { 294 changed = true; 295 m_type = newType; 296 } 297 298 return changed; 299 } 300 } 301 | Popular Tags |