2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.openapi
.wm
.impl
;
19 import java
.awt
.event
.ContainerEvent
;
20 import java
.awt
.event
.ContainerListener
;
23 * @author Anton Katilin
24 * @author Vladimir Kondratyev
26 public abstract class HierarchyWatcher
implements ContainerListener
{
27 public final void componentAdded(final ContainerEvent e
){
28 install(e
.getChild());
32 public final void componentRemoved(final ContainerEvent e
){
33 final Component removedChild
=e
.getChild();
34 deinstall(removedChild
);
38 private void install(final Component component
){
39 if(component
instanceof Container
){
40 final Container container
=(Container
)component
;
41 final int componentCount
=container
.getComponentCount();
42 for(int i
=0;i
<componentCount
;i
++){
43 install(container
.getComponent(i
));
45 container
.addContainerListener(this);
49 private void deinstall(final Component component
){
50 if(component
instanceof Container
){
51 final Container container
=(Container
)component
;
52 final int componentCount
=container
.getComponentCount();
53 for(int i
=0;i
<componentCount
;i
++){
54 deinstall(container
.getComponent(i
));
56 container
.removeContainerListener(this);
61 * Override this method to get notifications abot changes in component hierarchy.
62 * <code>HierarchyWatcher</code> invokes this method each time one of the populated container changes.
63 * @param e event which describes the changes.
65 protected abstract void hierarchyChanged(ContainerEvent e
);