KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > utilities > Manager


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 2003 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.utilities;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.List JavaDoc;
24 import org.openide.util.actions.SystemAction;
25
26 /**
27  * Control centre - provides access to various parts of the module.
28  * Some of the features are as follows:
29  * <ul>
30  * <li>registry of all open windows and non-modal dialogs
31  * (so that they can be closed when the module is about
32  * to be uninstalled)</li>
33  * <li>registry of actions being activated
34  * (so that more instances of the same modal dialog cannot be opened
35  * - see
36  * <a HREF="http://www.netbeans.org/issues/show_bug.cgi?id=21343">bug
37  * #21343</a>)</li>
38  * </ul>
39  *
40  * @author Marian Petras
41  */

42 public final class Manager {
43     
44     /** list of activated actions */
45     private static List JavaDoc activatedActions = new ArrayList JavaDoc(2);
46     
47     /**
48      * Marks that the specified action is activated and informs whether
49      * the same action is already active or not.
50      *
51      * @param a action to be marked as activated
52      * @return <code>true</code> if the action may be activated
53      * (i.e. was not active at the moment this method was called),
54      * <code>false</code> if it was already active
55      * @see #actionFinished
56      */

57     public static boolean actionActivated(SystemAction a) {
58         synchronized (activatedActions) {
59             if (activatedActions.contains(a)) {
60                 return false;
61             } else {
62                 activatedActions.add(a);
63                 return true;
64             }
65         }
66     }
67     
68     /**
69      * Marks the specified action finished (i.e. not active any more).
70      *
71      * @param a action to be marked as finished
72      * @see #actionActivated
73      */

74     public static void actionFinished(SystemAction a) {
75         synchronized (activatedActions) {
76             activatedActions.remove(a);
77         }
78     }
79     
80     /** Creates a new instance of Manager */
81     private Manager() {
82     }
83     
84 }
85
Popular Tags