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 java
.util
.Iterator
;
19 import java
.util
.Stack
;
22 * Actually this class represent two stacks.
23 * 1. Stack of <code>id</code>s of active tool windows. This stack is used for reactivation of tool window
24 * after the another tool window was closed. This stack is cleared every time you active the editor.
25 * 2. Permanent stack. It is the same as the first one, but it's not cleared when editor is being
26 * activated. It used to provide id of last active tool window.
28 * @author Vladimir Kondratyev
30 final class ActiveStack
{
32 * Contains <code>id</code>s of tool window that were activated. This stack
33 * is cleared each time when editor is being activated.
35 private final Stack
<String
> myStack
;
37 * This stack is not cleared when editor is being activated. It means its "long"
40 private final Stack
<String
> myPersistentStack
;
43 * Creates enabled window stack.
46 myStack
= new Stack
<String
>();
47 myPersistentStack
= new Stack
<String
>();
51 * Clears stack but doesn't affect long persistence stack.
58 * Return whether the stack of active (not persistent) <code>id</code>s is empty or not.
61 return myStack
.isEmpty();
69 return myStack
.peek();
72 void push(final String id
) {
75 myPersistentStack
.push(id
);
78 int getPersistentSize() {
79 return myPersistentStack
.size();
83 * Peeks element at the persistent stack. <code>0</code> means the top of the stack.
85 String
peekPersistent(final int index
) {
86 return myPersistentStack
.get(myPersistentStack
.size() - index
- 1);
90 * Removes specified <code>ID</code> from stack.
92 * @param id <code>ID</code> to be removed.
93 * @param removePersistentAlso if <code>true</code> then clears last active <code>ID</code>
94 * if it's the last active <code>ID</code>.
96 void remove(final String id
, final boolean removePersistentAlso
) {
97 for (Iterator i
= myStack
.iterator(); i
.hasNext();) {
98 if (id
.equals(i
.next())) {
102 if (removePersistentAlso
) {
103 for (Iterator i
= myPersistentStack
.iterator(); i
.hasNext();) {
104 if (id
.equals(i
.next())) {