001: /*
002: This program is free software; you can redistribute it and/or
003: modify it under the terms of the GNU General Public License
004: as published by the Free Software Foundation; either version 2
005: of the License, or any later version.
006: This program is distributed in the hope that it will be useful,
007: but WITHOUT ANY WARRANTY; without even the implied warranty of
008: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
009: GNU General Public License for more detaProjectTreeSelectionListenerils.
010: You should have received a copy of the GNU General Public License
011: along with this program; if not, write to the Free Software
012: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
013: */
014: package org.acm.seguin.ide.jedit;
015:
016: import javax.swing.JScrollPane;
017: import javax.swing.tree.*;
018:
019: import net.sourceforge.jrefactory.ast.*;
020:
021: // JRefactory imports
022: import org.gjt.sp.jedit.Buffer;
023: import org.gjt.sp.jedit.EBComponent;
024: import org.gjt.sp.jedit.EBMessage;
025: import org.gjt.sp.jedit.View;
026: import org.gjt.sp.jedit.buffer.BufferChangeListener;
027: import org.gjt.sp.jedit.jEdit;
028: import org.gjt.sp.jedit.msg.*;
029: import org.gjt.sp.util.Log;
030:
031: /**
032: * Main GUI for JRefactory
033: *
034: * @author <a href="mailto:JRefactoryPlugin@ladyshot.demon.co.uk">Mike Atkinson</a>
035: * @since 0.0.1
036: * @created 23 July 2003
037: * @version $Id: Navigator.java,v 1.5 2003/12/02 23:39:37 mikeatkinson Exp $
038: */
039: public final class Navigator extends JScrollPane implements
040: BufferChangeListener, EBComponent {
041: private View view;
042: private org.acm.seguin.ide.common.Navigator navigator;
043:
044: /**
045: * Constructor for the Navigator object
046: *
047: * @param aView Description of Parameter
048: * @since v 1.0
049: */
050: public Navigator(View aView) {
051: this .view = aView;
052: navigator = new org.acm.seguin.ide.common.Navigator(view);
053: navigator.viewCreated(view);
054: Buffer[] buffers = jEdit.getBuffers();
055: for (int i = 0; i < buffers.length; i++) {
056: navigator.addBuffer(buffers[i]);
057: }
058: JavaStylePlugin.addNavigator(this );
059: //add(new JScrollPane(navigator), BorderLayout.CENTER);
060: setViewportView(navigator);
061: Buffer buffer = aView.getBuffer();
062: addBufferChangeListener(buffer, this );
063: }
064:
065: /**
066: * Description of the Method
067: *
068: * @param msg Description of the Parameter
069: * @since v 1.0
070: */
071: public void handleMessage(EBMessage msg) {
072: System.out.println("Navigator: handleMessage(" + msg + ")");
073: try {
074: if (msg instanceof ViewUpdate) {
075: ViewUpdate update = (ViewUpdate) msg;
076: System.out.println("Navigator.handleMessage(" + update
077: + ")");
078: if (update.getWhat() == ViewUpdate.CREATED) {
079: navigator.viewCreated(update.getView());
080: } else if (update.getWhat() == ViewUpdate.CLOSED) {
081: navigator.viewClosed(update.getView());
082: }
083: } else if (msg instanceof BufferUpdate) {
084: BufferUpdate update = (BufferUpdate) msg;
085: System.out.println("Navigator.handleMessage(" + update
086: + ")");
087: String name = update.getBuffer().getName()
088: .toLowerCase();
089: if (name.endsWith(".java")) {
090: Buffer buffer = update.getBuffer();
091: if (update.getWhat() == BufferUpdate.CREATED) {
092: Log.log(Log.MESSAGE, this , "created buffer "
093: + name);
094: navigator.addBuffer(buffer);
095: addBufferChangeListener(buffer, this );
096: } else if (update.getWhat() == BufferUpdate.SAVED) {
097: Log.log(Log.MESSAGE, this , "saving buffer "
098: + name);
099: navigator.addBuffer(buffer);
100: addBufferChangeListener(buffer, this );
101: } else if (update.getWhat() == BufferUpdate.CLOSED) {
102: Log.log(Log.MESSAGE, this , "removing buffer "
103: + name);
104: navigator.removeBuffer(buffer);
105: buffer.removeBufferChangeListener(this );
106: } else if (update.getWhat() == BufferUpdate.LOADED) {
107: Log.log(Log.MESSAGE, this , "loaded buffer "
108: + name);
109: navigator.addBuffer(buffer);
110: addBufferChangeListener(buffer, this );
111: } else if (update.getWhat() == BufferUpdate.DIRTY_CHANGED) {
112: Log.log(Log.MESSAGE, this ,
113: "dirty changed buffer " + name);
114: navigator.addBuffer(buffer);
115: addBufferChangeListener(buffer, this );
116: }
117: }
118: //} else if (msg instanceof EditPaneUpdate) {
119: //EditPaneUpdate epu = (EditPaneUpdate)msg;
120: //View view = epu.getEditPane().getView();
121: //Navigation nav = (Navigation)(viewToNavigation.get(view));
122: //if (nav != null) {
123: /*
124: if (epu.getWhat() == EditPaneUpdate.BUFFER_CHANGED &&
125: Config.FLUSH_CACHE_ON_BUFFER_CHANGE.getAsBoolean()){
126: //logger.msg("****buffer.changed", epu.toString());
127: flushCacheForBuffer(view);
128: }
129: */
130: //}
131: } else if (msg instanceof PropertiesChanged) {
132: navigator.reconfigure();
133: /*
134: } else if (msg instanceof ContextUpdateMessage) {
135: if (ClassPathSrcMgr.isAntHelperSrc()){
136: ClassPathSrcMgr.getInstance().reload();
137: }
138: */
139: }
140: } catch (Exception e) {
141: e.printStackTrace();
142: }
143: }
144:
145: private void addBufferChangeListener(Buffer buffer, Navigator nav) {
146: BufferChangeListener[] listeners = buffer
147: .getBufferChangeListeners();
148: for (int i = 0; i < listeners.length; i++) {
149: if (listeners[i] == nav) {
150: return;
151: }
152: }
153: buffer.addBufferChangeListener(nav);
154: }
155:
156: /**
157: * Description of the Method
158: *
159: * @param buffer Description of Parameter
160: * @param startLine Description of Parameter
161: * @param offset Description of Parameter
162: * @param numLines Description of Parameter
163: * @param length Description of Parameter
164: * @since v 1.0
165: */
166: public void preContentInserted(Buffer buffer, int startLine,
167: int offset, int numLines, int length) {
168: }
169:
170: /**
171: * Description of the Method
172: *
173: * @param buffer Description of Parameter
174: * @param startLine Description of Parameter
175: * @param offset Description of Parameter
176: * @param numLines Description of Parameter
177: * @param length Description of Parameter
178: * @since v 1.0
179: */
180: public void contentInserted(Buffer buffer, int startLine,
181: int offset, int numLines, int length) {
182: navigator.contentInserted(view, buffer, offset, length);
183: }
184:
185: /**
186: * Description of the Method
187: *
188: * @param buffer Description of Parameter
189: * @param startLine Description of Parameter
190: * @param offset Description of Parameter
191: * @param numLines Description of Parameter
192: * @param length Description of Parameter
193: * @since v 1.0
194: */
195: public void preContentRemoved(Buffer buffer, int startLine,
196: int offset, int numLines, int length) {
197: }
198:
199: /**
200: * Description of the Method
201: *
202: * @param buffer Description of Parameter
203: * @param startLine Description of Parameter
204: * @param offset Description of Parameter
205: * @param numLines Description of Parameter
206: * @param length Description of Parameter
207: * @since v 1.0
208: */
209: public void contentRemoved(Buffer buffer, int startLine,
210: int offset, int numLines, int length) {
211: navigator.contentRemoved(view, buffer, offset, length);
212: }
213:
214: /**
215: * Description of the Method
216: *
217: * @param buffer Description of Parameter
218: * @param startLine Description of Parameter
219: * @param endLine Description of Parameter
220: * @since v 1.0
221: */
222: public void foldLevelChanged(Buffer buffer, int startLine,
223: int endLine) {
224: }
225:
226: /**
227: * Description of the Method
228: *
229: * @param buffer Description of Parameter
230: * @since v 1.0
231: */
232: public void wrapModeChanged(Buffer buffer) {
233: }
234:
235: /**
236: * Description of the Method
237: *
238: * @param buffer Description of Parameter
239: * @since v 1.0
240: */
241: public void foldHandlerChanged(Buffer buffer) {
242: }
243:
244: /**
245: * Description of the Method
246: *
247: * @param buffer Description of Parameter
248: * @since v 1.0
249: */
250: public void transactionComplete(Buffer buffer) {
251: navigator.transactionComplete(view, buffer);
252: }
253:
254: }
|