001: // Copyright (c) 2000, 2005 BlueJ Group, Deakin University
002: //
003: // This software is made available under the terms of the "MIT License"
004: // A copy of this license is included with this source distribution
005: // in "license.txt" and is also available at:
006: // http://www.opensource.org/licenses/mit-license.html
007: // Any queries should be directed to Michael Kolling mik@bluej.org
008:
009: package bluej.editor.moe;
010:
011: import bluej.Config;
012: import bluej.editor.Editor;
013: import bluej.editor.EditorWatcher;
014:
015: import java.util.Properties;
016: import java.util.ArrayList;
017: import java.util.List;
018: import java.util.Iterator;
019:
020: import java.awt.*; // Object input, ouput streams
021:
022: /**
023: ** @author Michael Kolling
024: **
025: **/
026:
027: public final class MoeEditorManager extends bluej.editor.EditorManager {
028: // public static variables
029:
030: protected static MoeEditorManager editorManager; // the manager object itself
031:
032: // private variables
033:
034: private Properties resources;
035: private List editors; // open editors
036: private Finder finder; // the finder object
037:
038: // user preferences
039:
040: private boolean showLineNum;
041: private boolean showToolBar;
042:
043: // =========================== PUBLIC METHODS ===========================
044:
045: public MoeEditorManager() {
046: editors = new ArrayList(4);
047: finder = new Finder();
048:
049: showToolBar = true;
050: showLineNum = false;
051:
052: resources = Config.moeUserProps;
053:
054: editorManager = this ; // make this object publicly available
055: }
056:
057: // ------------------------------------------------------------------------
058: /**
059: ** Open an editor to display a class. The filename may be "null"
060: ** to open an empty editor (e.g. for displaying a view). The editor
061: ** is initially hidden. A call to "Editor::show" is needed to make
062: ** is visible after opening it.
063: **
064: ** @param filename name of the source file to open (may be null)
065: ** @param windowTitle title of window (usually class name)
066: ** @param watcher an object interested in editing events
067: ** @param compiled true, if the class has been compiled
068: ** @param breakpoints list of Integers: line numbers where bpts are
069: ** @return the new editor, or null if there was a problem
070: **/
071:
072: public Editor openClass(String filename, String docFilename,
073: String windowTitle, EditorWatcher watcher,
074: boolean compiled, Rectangle bounds) {
075: return openEditor(filename, docFilename, true, windowTitle,
076: watcher, compiled, bounds);
077: }
078:
079: // ------------------------------------------------------------------------
080: /**
081: ** Open an editor to display a text document. The difference to
082: ** "openClass" is that code specific functions (such as compile,
083: ** debug, view) are disabled in the editor. The filename may be
084: ** "null" to open an empty editor. The editor is initially hidden.
085: ** A call to "Editor::show" is needed to make is visible after
086: ** opening it.
087: **
088: ** @param filename name of the source file to open (may be null)
089: ** @param windowTitle title of window (usually class name)
090: ** @returns the new editor, or null if there was a problem
091: **/
092:
093: public Editor openText(String filename, String windowTitle,
094: Rectangle bounds) // inherited from EditorManager
095: {
096: return openEditor(filename, null, false, windowTitle, null,
097: false, bounds);
098: }
099:
100: public void refreshAll() {
101: Iterator e = editors.iterator();
102:
103: while (e.hasNext()) {
104: Editor ed = (Editor) e.next();
105:
106: if (ed.isShowing())
107: ed.refresh();
108: }
109: }
110:
111: // ------------------------------------------------------------------------
112: /**
113: * Sound a beep if the "beep with warning" option is true
114: */
115: public void beep() {
116: if (true) // if beepWarning option is on...
117: Toolkit.getDefaultToolkit().beep();
118: }
119:
120: // ------------------------------------------------------------------------
121: /**
122: * Discard the given editor and leave it to be collected by the garbage
123: * collector.
124: */
125: public void discardEditor(Editor ed) {
126: ed.close();
127: editors.remove(ed);
128: }
129:
130: // ========================== PACKAGE METHODS ===========================
131:
132: // ------------------------------------------------------------------------
133: /**
134: ** Return the shared finder object
135: **/
136:
137: Finder getFinder() {
138: return finder;
139: }
140:
141: // ------------------------------------------------------------------------
142:
143: // ========================== PRIVATE METHODS ===========================
144:
145: // ------------------------------------------------------------------------
146: /**
147: ** Open an editor to display a class. The filename may be "null"
148: ** to open an empty editor (e.g. for displaying a view). The editor
149: ** is initially hidden. A call to "Editor::show" is needed to make
150: ** is visible after opening it.
151: **
152: ** @param filename name of the source file to open (may be null)
153: ** @param docFilename name of the documentation based on filename
154: ** @param windowTitle title of window (usually class name)
155: ** @param watcher an object interested in editing events
156: ** @param compiled true, if the class has been compiled
157: ** @param bounds bounds for the editor window
158: ** @returns the new editor, or null if there was a problem
159: **/
160:
161: private Editor openEditor(String filename, String docFilename,
162: boolean isCode, String windowTitle, EditorWatcher watcher,
163: boolean compiled, Rectangle bounds) {
164: MoeEditor editor;
165:
166: editor = new MoeEditor(windowTitle, isCode, watcher,
167: showToolBar, showLineNum, resources);
168: editors.add(editor);
169: if (watcher != null && filename == null) // editor for class interface
170: return editor;
171: if (editor.showFile(filename, compiled, docFilename, bounds))
172: return editor;
173: else {
174: editor.doClose(); // editor will remove itself
175: return null;
176: }
177: }
178:
179: } // end class MoeEditorManager
|