Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/aspectj/tools/ajde/jbuilder/Listeners.java


1   
2   /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3    *
4    * This file is part of the IDE support for the AspectJ(tm)
5    * programming language; see http://aspectj.org
6    *
7    * The contents of this file are subject to the Mozilla Public License
8    * Version 1.1 (the "License"); you may not use this file except in
9    * compliance with the License. You may obtain a copy of the License at
10   * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
11   *
12   * Software distributed under the License is distributed on an "AS IS" basis,
13   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14   * for the specific language governing rights and limitations under the
15   * License.
16   *
17   * The Original Code is AspectJ.
18   *
19   * The Initial Developer of the Original Code is Xerox Corporation. Portions
20   * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
21   * All Rights Reserved.
22   *
23   * Contributor(s):
24   */
25  
26  package org.aspectj.tools.ajde.jbuilder;
27  
28  import java.awt.event.*;
29  import java.io.IOException;
30  import java.util.*;
31  import javax.swing.*;
32  import com.borland.primetime.ide.*;
33  import com.borland.primetime.node.*;
34  import com.borland.primetime.vfs.Buffer;
35  import com.borland.primetime.vfs.BufferListener;
36  import com.borland.primetime.vfs.BufferUpdater;
37  import com.borland.jbuilder.node.JavaFileNode;
38  import com.borland.primetime.editor.*;
39  import org.aspectj.ajde.*;
40  import org.aspectj.ajde.ui.*;
41  import org.aspectj.ajde.ui.swing.*;
42  import org.aspectj.asm.*;
43  
44  /**
45   * @author Mik Kersten
46   */
47  public class Listeners {
48  
49      private static boolean activated = true;
50    private HashMap fileCursorPositionMap = new HashMap();
51  
52      public static final BuildListener COMPILER_LISTENER = new BuildListener() {
53        public void compileStarted(String buildConfig) { 
54          JBuilderManager.INSTANCE.verifyProjectRuntimeLibrary();
55        } 
56        
57          public void compileFinished(String buildConfig, int buildTime, boolean succeeded, boolean warnings) {
58              JBuilderManager.INSTANCE.updateInlineAnnotations();  
59          }
60          
61          public void compileAborted(String buildConfigFile, String message) { }
62      };
63  
64      public static final BrowserListener IDE_LISTENER = new BrowserListener() {
65  
66          public void browserNodeActivated(Browser browser, Node node) {
67              if (activated && node instanceof JavaFileNode) {
68                Browser.getActiveBrowser().getStructureView().setStructureComponent(
69            AjdeUIManager.getDefault().getFileStructurePanel()
70          );
71              
72              if (JBuilderManager.INSTANCE.getCurrGutter() != null) {
73                  JBuilderManager.INSTANCE.getCurrGutter().addGutterListener(GUTTER_LISTENER);
74                  JBuilderManager.INSTANCE.clearCurrentGutter();
75                  JBuilderManager.INSTANCE.updateInlineAnnotations();
76              }
77              
78  //            JavaFileNode jNode = (JavaFileNode)node;
79  //            try {
80  //          jNode.getBuffer().addBufferListener(new BufferListener() {
81  //             public void bufferChanged(Buffer buffer, BufferUpdater updater) { }
82  //             public void bufferLoaded(Buffer buffer) { }
83  //             public void bufferSaving(Buffer buffer) { }
84  //             public void bufferStateChanged(Buffer buffer, int oldState, int newState) { }
85  //            
86  //          });
87  //        } catch (IOException e) {
88  //        }
89              }
90  
91        try {
92              EditorActions ea = new EditorActions();
93                EditorPane ep =  ea.ACTION_DeleteBeginLine.getFocusedEditor();
94                int caretPosition = ep.getCaretPosition();
95                
96                if (!JBuilderManager.INSTANCE.getNavigationSeekPerformed()) {
97                  Ajde.getDefault().getStructureViewManager().fireNavigationAction(node.getLongDisplayName(), 
98                    ep.getLineNumber(caretPosition));
99              } else {
100               JBuilderManager.INSTANCE.setNavigationSeekPerformed(false);  
101               }
102               AjdeUIManager.getDefault().getFileStructurePanel().highlightActiveNode();
103               
104               ep.setCaretPosition(ep.getLineNumber(caretPosition), ep.getColumnNumber(caretPosition));
105           } catch (Exception e) {
106             // fails silently  
107       }
108         }
109  
110         public void browserProjectActivated(Browser browser, Project project) {
111             //AjdeUIManager.getDefault().getViewManager().updateConfigsList();
112             if (activated) {
113               Ajde.getDefault().getConfigurationManager().setActiveConfigFile(
114                 JBuilderManager.INSTANCE.getProjectProperties().getLastActiveBuildConfigFile());
115                 project.addProjectListener(PROJECT_LISTENER);
116                 JBuilderManager.INSTANCE.updateCompileActions();   
117                 //AjdeUIManager.getDefault().getViewManager().updateView();
118         JBuilderManager.INSTANCE.verifyRuntimeLibraryExists();    
119           }
120         }
121 
122         public void browserProjectClosed(Browser browser, Project project) {
123           JBuilderManager.INSTANCE.getProjectProperties().setLastActiveBuildConfigFile(
124             Ajde.getDefault().getConfigurationManager().getActiveConfigFile());
125             project.removeProjectListener(PROJECT_LISTENER);
126         }
127 
128         public void browserClosing(Browser browser) {
129             if (JBuilderManager.INSTANCE.isEnabled()) {
130                 activated = false;
131                 Install.ajEnableAjdeAction.actionPerformed(Browser.getActiveBrowser());
132             }
133         }
134 
135         public void browserActivated(Browser browser) { }
136 
137         /** Ignored. */
138         public void browserDeactivated(Browser browser) { }
139 
140         /** Ignored. */
141         public void browserClosed(Browser browser) { }
142 
143         /** Ignored. */
144         public void browserNodeClosed(Browser browser, Node node) { }
145 
146         /** Ignored. */
147         public void browserOpened(Browser browser) { }
148 
149         /** Ignored. */
150         public void browserViewerActivated(Browser browser, Node node, NodeViewer viewer) { }
151 
152         /** Ignored. */
153         public void browserViewerDeactivating(Browser browser, Node node, NodeViewer viewer) { }
154     };
155 
156     public static final ProjectListener PROJECT_LISTENER = new ProjectListener() {
157         /**
158          * Ignored.
159          */
160         public void nodeChanged(Project project, Node node) { }
161 
162         /**
163          * Invoked when a node is added to or removed from a parent node in this project.
164          * 
165          * @todo  remove call to getDefaultConfigFile()
166          */
167         public void nodeChildrenChanged(Project project, Node parent) {
168             if (activated) {
169                 //AjdeUIManager.getDefault().getViewManager().updateConfigsList();
170                 Ajde.getDefault().getProjectProperties().getDefaultBuildConfigFile();
171                 JBuilderManager.INSTANCE.updateCompileActions();  
172             }
173         }
174 
175         /**
176          * Ignored.
177          */
178         public void projectPropertyChanged(Project project, String category, String property, String oldValue, String newValue) { }
179     };
180 
181     public static final GutterListener GUTTER_LISTENER = new GutterListener() {
182         public void lineClicked(Gutter source, int line, MouseEvent e, LineMark[] marks) {
183             if (e.isPopupTrigger()) {
184                 JPopupMenu popupMenu = null;
185                 for (int i = 0; i < marks.length; i++) {
186                     if (marks[i] instanceof AjdeGutterMark) {
187                         popupMenu = ((AjdeGutterMark)marks[i]).getPopupMenu();
188                     }
189                 }
190                 if (popupMenu != null) {
191                     popupMenu.show(source, e.getX(), e.getY());
192                 }
193             }
194         }
195 
196         public void linesChanged(Gutter source) { }
197     };
198 }