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
.ide
;
18 import com
.intellij
.openapi
.application
.ApplicationAdapter
;
19 import com
.intellij
.openapi
.application
.impl
.ApplicationImpl
;
20 import com
.intellij
.openapi
.components
.ApplicationComponent
;
21 import com
.intellij
.openapi
.wm
.IdeFrame
;
22 import com
.intellij
.util
.Alarm
;
23 import com
.intellij
.util
.containers
.ContainerUtil
;
24 import org
.jetbrains
.annotations
.NonNls
;
25 import org
.jetbrains
.annotations
.NotNull
;
27 import java
.util
.concurrent
.CopyOnWriteArrayList
;
29 public class FrameStateManagerImpl
extends FrameStateManager
implements ApplicationComponent
{
31 private final CopyOnWriteArrayList
<FrameStateListener
> myListeners
= ContainerUtil
.createEmptyCOWList();
33 private boolean myShouldSynchronize
;
34 private final Alarm mySyncAlarm
;
36 public FrameStateManagerImpl(final ApplicationImpl app
) {
38 myShouldSynchronize
= false;
39 mySyncAlarm
= new Alarm();
41 app
.addApplicationListener(new ApplicationAdapter() {
43 public void applicationActivated(IdeFrame ideFrame
) {
44 mySyncAlarm
.cancelAllRequests();
45 if (myShouldSynchronize
) {
46 myShouldSynchronize
= false;
47 fireActivationEvent();
52 public void applicationDeactivated(IdeFrame ideFrame
) {
53 mySyncAlarm
.cancelAllRequests();
54 mySyncAlarm
.addRequest(new Runnable() {
56 if (!app
.isActive()) {
57 myShouldSynchronize
= true;
58 fireDeactivationEvent();
69 public String
getComponentName() {
70 return "FrameStateManager";
73 public void initComponent() {
76 public void disposeComponent() {
79 private void fireDeactivationEvent() {
80 for (FrameStateListener listener
: myListeners
) {
81 listener
.onFrameDeactivated();
85 private void fireActivationEvent() {
86 for (FrameStateListener listener
: myListeners
) {
87 listener
.onFrameActivated();
91 public synchronized void addListener(FrameStateListener listener
) {
92 myListeners
.add(listener
);
95 public synchronized void removeListener(FrameStateListener listener
) {
96 myListeners
.remove(listener
);