1 package com.explosion.expfmodules.search;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.awt.event.KeyEvent;
23 import java.io.File;
24 import java.util.Hashtable;
25 import java.util.Properties;
26 import java.util.Vector;
27 import java.util.prefs.Preferences;
28
29 import javax.swing.JPanel;
30 import javax.swing.KeyStroke;
31
32 import com.explosion.expf.Application;
33 import com.explosion.expf.ExpActionListener;
34 import com.explosion.expf.ExpConstants;
35 import com.explosion.expf.ExpFrame;
36 import com.explosion.expf.ExpModuleManager;
37 import com.explosion.expf.menusandtools.menu.ExpMenu;
38 import com.explosion.expf.menusandtools.menu.ExpMenuBar;
39 import com.explosion.expf.menusandtools.menu.segmented.ExpMenuSegment;
40 import com.explosion.expf.preferences.SystemPreferences;
41 import com.explosion.utilities.preferences.Preference;
42
43 /***
44 * Author: Stephen Cowx
45 * Date: Dec 9, 2002
46 * Time: 11:48:47 PM
47 */
48
49 public class SearchModuleManager implements ExpModuleManager
50 {
51 private Vector preferences = new Vector();
52 private Hashtable preferenceHash = new Hashtable();
53 private static SearchModuleManager instance = null;
54 private ExpActionListener globalActionListener = null;
55
56 public SearchModuleManager()
57 {
58 instance = this;
59 }
60
61 public void initialiseGui() throws Exception
62 {
63
64 ExpMenuBar menuBar = ((ExpFrame) Application.getApplicationFrame()).getExpMenuBar();
65 ExpMenu menuConnection = menuBar.createExpMenu("Search", 's', SearchConstants.MENU_SEARCH, 1, true);
66
67
68 ExpMenuSegment searchSegment = menuConnection.createNewSegment(ExpMenuSegment.ANY_POSITION);
69
70
71 searchSegment.addElement(menuBar.getMenuHelper().createMenuItem("In files..", 'f', SearchConstants.MENU_SEARCH_IN_FILES,KeyStroke.getKeyStroke(KeyEvent.VK_F, KeyEvent.CTRL_MASK), 1));
72 searchSegment.addElement(menuBar.getMenuHelper().createMenuItem("Replace, in files..", 'f', SearchConstants.MENU_REPLACE_IN_FILES,null, 1));
73 searchSegment.addElement(menuBar.getMenuHelper().createMenuItem("For classes", 'c', SearchConstants.MENU_SEARCH_FOR_CLASSES,null, 1));
74
75
76 Application.addToGlobalCookie(SearchConstants.MENU_SEARCH, 1);
77 Application.addToGlobalCookie(SearchConstants.MENU_SEARCH_IN_FILES, 1);
78 Application.addToGlobalCookie(SearchConstants.MENU_REPLACE_IN_FILES, 1);
79 Application.addToGlobalCookie(SearchConstants.MENU_SEARCH_FOR_CLASSES, 1);
80
81 globalActionListener = new SearchListener();
82
83 }
84
85 public String getVersion()
86 {
87 return "1.0";
88 }
89
90 public String getName()
91 {
92 return "Search";
93 }
94
95 public String getDescription()
96 {
97 return "A set of search utilities";
98 }
99
100 public void initialiseCore(Properties properties)
101 {
102 try
103 {
104 Preferences prefs = Preferences.userRoot().node(getPreferenceRoot());
105
106 Preference lastSearchInFiles = new Preference(SearchConstants.LAST_SEARCH_IN_FILES, Preference.PROPERTY_TYPE_TEXT, "", prefs);
107 lastSearchInFiles.setLongName("Last search");
108 lastSearchInFiles.setDescription("This is the last value that was searched for");
109 preferences.addElement(lastSearchInFiles);
110 preferenceHash.put(SearchConstants.LAST_SEARCH_IN_FILES, lastSearchInFiles);
111
112 Preference lastFilenamePatternSearched = new Preference(SearchConstants.LAST_FILENAMEPATTERN_SEARCHED, Preference.PROPERTY_TYPE_TEXT, "", prefs);
113 lastFilenamePatternSearched.setLongName("Last filename pattern");
114 lastFilenamePatternSearched.setDescription("This is the last filename pattern that was used on a multifile search.");
115 preferences.addElement(lastFilenamePatternSearched);
116 preferenceHash.put(SearchConstants.LAST_FILENAMEPATTERN_SEARCHED, lastFilenamePatternSearched);
117
118 Preference lastReplacePattern = new Preference(SearchConstants.LAST_REPLACE_IN_FILES, Preference.PROPERTY_TYPE_TEXT, "", prefs);
119 lastReplacePattern.setLongName("Last replace string");
120 lastReplacePattern.setDescription("This is the last string that was used as a replace string.");
121 preferences.addElement(lastReplacePattern);
122 preferenceHash.put(SearchConstants.LAST_REPLACE_IN_FILES, lastReplacePattern);
123
124 Preference lastDirSearched = new Preference(SearchConstants.LAST_DIRECTORY_SEARCHED, Preference.PROPERTY_TYPE_DIRECTORY, new File(""), prefs);
125 lastDirSearched.setLongName("Last directory searched");
126 lastDirSearched.setDescription("This is the last directory that was searched");
127 preferences.addElement(lastDirSearched);
128 preferenceHash.put(SearchConstants.LAST_DIRECTORY_SEARCHED, lastDirSearched);
129
130
131 Preference lastClassSearch = new Preference(SearchConstants.LAST_CLASS_SEARCH_IN_FILES, Preference.PROPERTY_TYPE_TEXT, "", prefs);
132 lastClassSearch.setLongName("Last class search");
133 lastClassSearch.setDescription("This is the last class that was searched for");
134 preferences.addElement(lastClassSearch);
135 preferenceHash.put(SearchConstants.LAST_CLASS_SEARCH_IN_FILES, lastClassSearch);
136
137 Preference lastClassDirSearched = new Preference(SearchConstants.LAST_CLASS_DIRECTORY_SEARCHED, Preference.PROPERTY_TYPE_DIRECTORY, new File(""), prefs);
138 lastClassDirSearched.setLongName("Last directory searched for classes");
139 lastClassDirSearched.setDescription("This is the last directory that was searched");
140 preferences.addElement(lastClassDirSearched);
141 preferenceHash.put(SearchConstants.LAST_CLASS_DIRECTORY_SEARCHED, lastClassDirSearched);
142
143 }
144 catch (Exception e)
145 {
146 com.explosion.utilities.exception.ExceptionManagerFactory.getExceptionManager().manageException(e, "Exception caught while initialising Search module.");
147 }
148 }
149
150 public Vector getPreferences()
151 {
152 return null;
153 }
154
155
156 public Preference getPreference(String preferenceName)
157 {
158 return (Preference) preferenceHash.get(preferenceName);
159 }
160
161 public JPanel getPreferencesEditor()
162 {
163 return null;
164 }
165
166 public ExpActionListener getGlobalListener()
167 {
168 return globalActionListener;
169 }
170
171 public static SearchModuleManager instance()
172 {
173 return instance;
174 }
175
176 public String getPreferenceRoot()
177 {
178 return (String) SystemPreferences.getPreference(ExpConstants.EXPF_APP_PREFIX).getValue()+"/search";
179 }
180
181 }