KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > search > FindDialogMemory


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 2005 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.search;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import org.netbeans.modules.search.types.FullTextType;
26 import org.openidex.search.SearchHistory;
27 import org.openidex.search.SearchType;
28
29 /**
30  * Registry for everything related to the Find dialog.
31  * It is <em>not</em> designed to be persistent across invocations
32  * of the IDE.
33  *
34  * @author Marian Petras
35  */

36 public final class FindDialogMemory implements PropertyChangeListener JavaDoc {
37
38     /** singleton instance of this class */
39     private static FindDialogMemory singleton;
40     
41     /**
42      * stores information about which search types should be pre-initialized
43      * from their history
44      */

45     private final HashMap JavaDoc searchTypesUsage = new HashMap JavaDoc(4);
46     
47     /**
48      * stores the last used <code>SearchType</code>
49      */

50     private SearchType lastSearchType = null;
51     
52     /** Creates a new instance of FindDialogMemory */
53     private FindDialogMemory() { }
54     
55     
56     /**
57      */

58     public static FindDialogMemory getDefault() {
59         if (singleton == null) {
60             singleton = new FindDialogMemory();
61         }
62         return singleton;
63     }
64     
65     /**
66      */

67     void initialize() {
68         SearchHistory.getDefault().addPropertyChangeListener(this);
69     }
70     
71     /**
72      */

73     void uninitialize() {
74         SearchHistory.getDefault().removePropertyChangeListener(this);
75     }
76     
77     /**
78      * Clears information about used search types.
79      */

80     public void clearSearchTypesUsed() {
81         searchTypesUsage.clear();
82     }
83     
84     /**
85      */

86     public void setSearchTypeUsed(String JavaDoc searchTypeClsName,
87                                          boolean used) {
88         searchTypesUsage.put(searchTypeClsName, Boolean.valueOf(used));
89     }
90     
91     /**
92      */

93     public boolean wasSearchTypeUsed(String JavaDoc searchTypeClsName) {
94         return searchTypesUsage.get(searchTypeClsName) == Boolean.TRUE;
95     }
96     
97     /**
98      */

99     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
100         if (SearchHistory.ADD_TO_HISTORY.equals(evt.getPropertyName())) {
101             searchTypesUsage.put(FullTextType.class.getName(), Boolean.TRUE);
102         }
103     }
104     
105     /**
106      */

107     public void setLastUsedSearchType(SearchType searchType){
108         lastSearchType = searchType;
109     }
110     
111     /**
112      */

113     public SearchType getLastSearchType(){
114         return lastSearchType;
115     }
116
117 }
118
Popular Tags