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
;
18 import org
.jetbrains
.annotations
.NonNls
;
21 import java
.awt
.event
.ComponentAdapter
;
22 import java
.awt
.event
.ComponentEvent
;
23 import java
.beans
.PropertyChangeEvent
;
24 import java
.beans
.PropertyChangeListener
;
27 * @author Anton Katilin
28 * @author Vladimir Kondratyev
30 public abstract class VisibilityWatcher
extends ComponentAdapter
implements PropertyChangeListener
{
31 @NonNls protected static final String ANCESTOR_PROPERTY_NAME
= "ancestor";
33 public final void componentHidden(final ComponentEvent e
){
37 public final void componentShown(final ComponentEvent e
){
41 public final void propertyChange(final PropertyChangeEvent e
){
42 if(ANCESTOR_PROPERTY_NAME
.equals(e
.getPropertyName())){
43 final Component oldAncestor
=(Component
)e
.getOldValue();
44 deinstall(oldAncestor
);
45 final Component newAncestor
=(Component
)e
.getNewValue();
49 throw new IllegalArgumentException("unknown propertyName: "+e
.getPropertyName());
53 public final void install(Component component
){
54 while(component
!=null){
55 component
.removePropertyChangeListener(ANCESTOR_PROPERTY_NAME
,this); // it prevent double registering
56 component
.addPropertyChangeListener(ANCESTOR_PROPERTY_NAME
,this);
58 component
.removeComponentListener(this); // it prevent double registering
59 component
.addComponentListener(this);
60 component
=component
.getParent();
64 public void deinstall(Component component
){
65 while(component
!=null){
66 component
.removePropertyChangeListener(ANCESTOR_PROPERTY_NAME
,this);
67 component
.removeComponentListener(this);
68 component
=component
.getParent();
73 * Invokes every time component changes its visibility. It means one of parent component
74 * change visibility or hierarchy is connected/disconnected to/from peer.
76 public abstract void visibilityChanged();