1 package com.explosion.expfmodules.texteditor;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.awt.Color;
23 import java.util.Hashtable;
24 import java.util.Properties;
25 import java.util.Vector;
26 import java.util.prefs.Preferences;
27
28 import javax.swing.JPanel;
29
30 import com.explosion.expf.Application;
31 import com.explosion.expf.ExpActionListener;
32 import com.explosion.expf.ExpConstants;
33 import com.explosion.expf.ExpModuleManager;
34 import com.explosion.expf.preferences.SystemPreferences;
35 import com.explosion.utilities.preferences.Preference;
36
37 /***
38 * Author: Stephen Cowx
39 * Date: Dec 9, 2002
40 * Time: 11:48:47 PM
41 */
42
43 public class TextEditorModuleManager implements ExpModuleManager
44 {
45 private Vector preferences = new Vector();
46 private Hashtable preferenceHash = new Hashtable();
47 private static TextEditorModuleManager instance = null;
48 private ExpActionListener globalActionListener = null;
49
50 public TextEditorModuleManager()
51 {
52 instance = this;
53 }
54
55 public void initialiseGui() throws Exception
56 {
57
58 Application.addToGlobalCookie(ExpConstants.MENU_NEW,1);
59 Application.addToGlobalCookie(ExpConstants.MENU_OPEN,1);
60
61 globalActionListener = new TextEditorListener();
62 }
63
64 public String getVersion()
65 {
66 return "1.0";
67 }
68
69 public String getName()
70 {
71 return "Text Editor";
72 }
73
74 public String getDescription()
75 {
76 return "A basic text editor.";
77 }
78
79 public void initialiseCore(Properties properties)
80 {
81 try
82 {
83 Preferences prefs = Preferences.userRoot().node(getPreferenceRoot());
84
85 Preference defaultExtension = new Preference(TextEditorConstants.DEFAULTEXTENSION, Preference.PROPERTY_TYPE_TEXT, ".txt", prefs);
86 defaultExtension.setLongName("Default extension");
87 defaultExtension.setDescription("This is the default extension which is given to new text files.");
88 preferences.addElement(defaultExtension);
89 preferenceHash.put(TextEditorConstants.DEFAULTEXTENSION, defaultExtension);
90
91 Preference undoListSize = new Preference(TextEditorConstants.UNDOLIST_SIZE, Preference.PROPERTY_TYPE_INT, new Integer(-1), prefs);
92 undoListSize.setLongName("Max undo list size");
93 undoListSize.setDescription("The maximum size (in number of operations) of the undo list. The value -1 indicates that there is no maximum size.");
94 preferences.addElement(undoListSize);
95 preferenceHash.put(TextEditorConstants.UNDOLIST_SIZE,undoListSize);
96
97 Preference wordWrap = new Preference(TextEditorConstants.WORDWRAP, Preference.PROPERTY_TYPE_BOOLEAN, new Boolean(true), prefs);
98 wordWrap.setLongName("Word wrap");
99 wordWrap.setDescription("Determines whether text is wrapped in the editor window or not.");
100 preferences.addElement(wordWrap);
101 preferenceHash.put(TextEditorConstants.WORDWRAP, wordWrap);
102
103 Preference font = new Preference(TextEditorConstants.FONT, Preference.PROPERTY_TYPE_FONT, SystemPreferences.getPreference(ExpConstants.BASE_FONT), prefs);
104 font.setLongName("Text font");
105 font.setDescription("This is the text font which gets used by this editor.");
106 preferences.addElement(font);
107 preferenceHash.put(TextEditorConstants.FONT, font);
108
109 Preference foregroundColor = new Preference(TextEditorConstants.COLORS_FOREGROUND, Preference.PROPERTY_TYPE_COLOR, Color.black, prefs);
110 foregroundColor.setLongName("Foreground colour");
111 foregroundColor.setDescription("This is the colour of the foreground text in the editor.");
112 preferences.addElement(foregroundColor);
113 preferenceHash.put(TextEditorConstants.COLORS_FOREGROUND, foregroundColor);
114
115 Preference backgroundColor = new Preference(TextEditorConstants.COLORS_BACKGROUND, Preference.PROPERTY_TYPE_COLOR, Color.white, prefs);
116 backgroundColor.setLongName("Background colour");
117 backgroundColor.setDescription("This is the colour of the background in the editor.");
118 preferences.addElement(backgroundColor);
119 preferenceHash.put(TextEditorConstants.COLORS_BACKGROUND, backgroundColor);
120
121 Preference caretColor = new Preference(TextEditorConstants.CARET_COLOR, Preference.PROPERTY_TYPE_COLOR, Color.gray, prefs);
122 caretColor.setLongName("Caret colour");
123 caretColor.setDescription("This is the colour of the caret (cursor).");
124 preferences.addElement(caretColor);
125 preferenceHash.put(TextEditorConstants.CARET_COLOR, caretColor);
126
127 Preference selectedForegroundColor = new Preference(TextEditorConstants.COLOR_SELECTEDFORGROUND, Preference.PROPERTY_TYPE_COLOR, Color.white, prefs);
128 selectedForegroundColor.setLongName("Selected foreground colour");
129 selectedForegroundColor.setDescription("This is the colour of the foreground text in the editor when that text has been highlighted.");
130 preferences.addElement(selectedForegroundColor);
131 preferenceHash.put(TextEditorConstants.COLOR_SELECTEDFORGROUND, selectedForegroundColor);
132
133 Preference selectedBackgroundColor = new Preference(TextEditorConstants.COLOR_SELECTEDBACKGROUND, Preference.PROPERTY_TYPE_COLOR, Color.gray, prefs);
134 selectedBackgroundColor.setLongName("Selected background colour");
135 selectedBackgroundColor.setDescription("This is the colour of the backround in the editor when it is behind text has been highlighted.");
136 preferences.addElement(selectedBackgroundColor);
137 preferenceHash.put(TextEditorConstants.COLOR_SELECTEDBACKGROUND, selectedBackgroundColor);
138
139 }
140 catch (Exception e)
141 {
142 com.explosion.utilities.exception.ExceptionManagerFactory.getExceptionManager().manageException(e, "Exception caught while initialising the Text Editor module.");
143 }
144 }
145
146 public Vector getPreferences()
147 {
148 return preferences;
149 }
150
151 public ExpActionListener getGlobalListener()
152 {
153 return globalActionListener;
154 }
155
156
157 public Preference getPreference(String preferenceName)
158 {
159 return (Preference) preferenceHash.get(preferenceName);
160 }
161
162 public JPanel getPreferencesEditor()
163 {
164 return null;
165 }
166
167 public static TextEditorModuleManager instance()
168 {
169 return instance;
170 }
171
172 public String getPreferenceRoot()
173 {
174 return (String) SystemPreferences.getPreference(ExpConstants.EXPF_APP_PREFIX).getValue()+"/txt";
175 }
176
177 }