KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > bluej > editor > moe > MoeEditorManager


1 // Copyright (c) 2000, 2005 BlueJ Group, Deakin University
2
//
3
// This software is made available under the terms of the "MIT License"
4
// A copy of this license is included with this source distribution
5
// in "license.txt" and is also available at:
6
// http://www.opensource.org/licenses/mit-license.html
7
// Any queries should be directed to Michael Kolling mik@bluej.org
8

9 package bluej.editor.moe;
10
11 import bluej.Config;
12 import bluej.editor.Editor;
13 import bluej.editor.EditorWatcher;
14
15 import java.util.Properties JavaDoc;
16 import java.util.ArrayList JavaDoc;
17 import java.util.List JavaDoc;
18 import java.util.Iterator JavaDoc;
19
20 import java.awt.*; // Object input, ouput streams
21

22 /**
23 ** @author Michael Kolling
24 **
25 **/

26
27 public final class MoeEditorManager
28     extends bluej.editor.EditorManager
29 {
30     // public static variables
31

32     protected static MoeEditorManager editorManager; // the manager object itself
33

34     // private variables
35

36     private Properties JavaDoc resources;
37     private List JavaDoc editors; // open editors
38
private Finder finder; // the finder object
39

40     // user preferences
41

42     private boolean showLineNum;
43     private boolean showToolBar;
44
45     // =========================== PUBLIC METHODS ===========================
46

47     public MoeEditorManager()
48     {
49         editors = new ArrayList JavaDoc(4);
50         finder = new Finder();
51                
52         showToolBar = true;
53         showLineNum = false;
54
55         resources = Config.moe_user_props;
56
57         editorManager = this; // make this object publicly available
58
}
59
60
61     // ------------------------------------------------------------------------
62
/**
63     ** Open an editor to display a class. The filename may be "null"
64     ** to open an empty editor (e.g. for displaying a view). The editor
65     ** is initially hidden. A call to "Editor::show" is needed to make
66     ** is visible after opening it.
67     **
68     ** @param filename name of the source file to open (may be null)
69     ** @param windowTitle title of window (usually class name)
70     ** @param watcher an object interested in editing events
71     ** @param compiled true, if the class has been compiled
72     ** @param breakpoints list of Integers: line numbers where bpts are
73     ** @returns the new editor, or null if there was a problem
74     **/

75
76     public Editor openClass(String JavaDoc filename,
77                 String JavaDoc docFilename,
78                             String JavaDoc windowTitle,
79                 EditorWatcher watcher,
80                 boolean compiled,
81                 List JavaDoc breakpoints, // inherited from EditorManager
82
ClassLoader JavaDoc projectClassLoader, Rectangle bounds)
83     {
84         return openEditor (filename, docFilename, true, windowTitle, watcher, compiled,
85                            breakpoints, projectClassLoader, bounds);
86     }
87
88     // ------------------------------------------------------------------------
89
/**
90     ** Open an editor to display a text document. The difference to
91     ** "openClass" is that code specific functions (such as compile,
92     ** debug, view) are disabled in the editor. The filename may be
93     ** "null" to open an empty editor. The editor is initially hidden.
94     ** A call to "Editor::show" is needed to make is visible after
95     ** opening it.
96     **
97     ** @param filename name of the source file to open (may be null)
98     ** @param windowTitle title of window (usually class name)
99     ** @returns the new editor, or null if there was a problem
100     **/

101
102     public Editor openText(String JavaDoc filename, String JavaDoc windowTitle,
103                            Rectangle bounds) // inherited from EditorManager
104
{
105         return openEditor (filename, null, false, windowTitle, null, false, null, null, bounds);
106     }
107
108     public void refreshAll()
109     {
110         Iterator JavaDoc e = editors.iterator();
111
112         while(e.hasNext()) {
113             Editor ed = (Editor)e.next();
114
115             if(ed.isShowing())
116                 ed.refresh();
117        }
118     }
119
120     // ------------------------------------------------------------------------
121
/**
122      * Sound a beep if the "beep with warning" option is true
123      */

124     public void beep()
125     {
126         if(true) // if beepWarning option is on...
127
Toolkit.getDefaultToolkit().beep();
128     }
129
130     // ------------------------------------------------------------------------
131
/**
132      * Discard the given editor and leave it to be collected by the garbage
133      * collector.
134      */

135     public void discardEditor(Editor ed)
136     {
137         ed.close();
138         editors.remove(ed);
139     }
140
141     // ========================== PACKAGE METHODS ===========================
142

143     // ------------------------------------------------------------------------
144
/**
145     ** Return the shared finder object
146     **/

147
148     Finder getFinder()
149     {
150         return finder;
151     }
152
153        // ------------------------------------------------------------------------
154

155     
156     // ========================== PRIVATE METHODS ===========================
157

158     // ------------------------------------------------------------------------
159
/**
160     ** Open an editor to display a class. The filename may be "null"
161     ** to open an empty editor (e.g. for displaying a view). The editor
162     ** is initially hidden. A call to "Editor::show" is needed to make
163     ** is visible after opening it.
164     **
165     ** @param filename name of the source file to open (may be null)
166     ** @param docFilename name of the documentation based on filename
167     ** @param windowTitle title of window (usually class name)
168     ** @param watcher an object interested in editing events
169     ** @param compiled true, if the class has been compiled
170     ** @param breakpoints list of Integers: line numbers where bpts are
171     ** @param bounds bounds for the editor window
172     ** @returns the new editor, or null if there was a problem
173     **/

174
175     private Editor openEditor(String JavaDoc filename, String JavaDoc docFilename,
176                                   boolean isCode, String JavaDoc windowTitle,
177                               EditorWatcher watcher, boolean compiled,
178                               List JavaDoc breakpoints, ClassLoader JavaDoc projectClassLoader, Rectangle bounds)
179     {
180         MoeEditor editor;
181
182         editor = new MoeEditor(windowTitle, isCode, watcher, showToolBar,
183                                showLineNum, resources, projectClassLoader);
184         editors.add(editor);
185         if (watcher!=null && filename==null) // editor for class interface
186
return editor;
187         if (editor.showFile(filename, compiled, docFilename, bounds))
188             return editor;
189         else {
190             editor.doClose(); // editor will remove itself
191
return null;
192         }
193     }
194
195 } // end class MoeEditorManager
196
Popular Tags