KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > ajde > ui > swing > BrowserViewTreeListener


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.ajde.ui.swing;
27
28 import java.util.*;
29 import java.awt.Component JavaDoc;
30 import java.awt.Color JavaDoc;
31 import java.awt.Font JavaDoc;
32 import java.awt.font.*;
33 import java.awt.event.*;
34 import javax.swing.*;
35 import javax.swing.tree.*;
36 import javax.swing.event.*;
37 import org.aspectj.ajde.Ajde;
38 import org.aspectj.asm.*;
39 import org.aspectj.asm.associations.*;
40 import org.aspectj.asm.views.*;
41 import org.aspectj.ajde.ui.*;
42
43 /**
44  * @author Mik Kersten
45  */

46 class BrowserViewTreeListener implements TreeSelectionListener, MouseListener {
47     private StructureTree tree = null;
48
49     public BrowserViewTreeListener(StructureTree tree) {
50         this.tree = tree;
51     }
52
53     public void valueChanged(TreeSelectionEvent e) { }
54
55     public void mouseEntered(MouseEvent e) { }
56
57     public void mouseExited(MouseEvent e) { }
58
59     public void mousePressed(MouseEvent e) { }
60
61     public void mouseReleased(MouseEvent e) { }
62
63     public void mouseClicked(MouseEvent e) {
64         singleClickNavigation(e);
65         //doubleClickNavigation(e);
66
maybeShowPopup(e);
67     }
68
69     public void singleClickNavigation(MouseEvent e) {
70         SwingTreeViewNode treeNode = (SwingTreeViewNode)tree.getLastSelectedPathComponent();
71         if (treeNode != null && !e.isControlDown() && !e.isShiftDown() && e.getModifiers() != 4) {
72             StructureNode currNode = (StructureNode)treeNode.getUserObject();
73             if (currNode instanceof ProgramElementNode && !e.isControlDown()
74                 && !e.isShiftDown() && e.getModifiers() != 4) {
75                 //AjdeUIManager.getDefault().getViewManager().showNodeInMasterView((ProgramElementNode)currNode);
76
//if (AjdeUIManager.getDefault().getViewManager().isSplitViewMode()) {
77
// AjdeUIManager.getDefault().getViewManager().showNodeInSlaveView((ProgramElementNode)currNode);
78
//}
79
} else if (currNode instanceof LinkNode) {
80                 //if (!AjdeUIManager.getDefault().getViewManager().isSplitViewMode()) {
81
// AjdeUIManager.getDefault().getViewManager().showNodeInMasterView((LinkNode)currNode);
82
//} else {
83
// AjdeUIManager.getDefault().getViewManager().showNodeInSlaveView(((LinkNode)currNode).getProgramElementNode());
84
//}
85
}
86         }
87     }
88
89         public void doubleClickNavigation(MouseEvent e) {
90             int clickCount = e.getClickCount();
91             SwingTreeViewNode treeNode = (SwingTreeViewNode)tree.getLastSelectedPathComponent();
92             if (treeNode != null) {
93                 StructureNode currNode = (StructureNode)treeNode.getUserObject();
94                 if (currNode instanceof ProgramElementNode && !e.isControlDown() && !e.isShiftDown()
95                     && e.getModifiers() != 4) {
96                     //AjdeUIManager.getDefault().getViewManager().showNodeInMasterView(((LinkNode)currNode).getProgramElementNode());
97
//AjdeUIManager.getDefault().getViewManager().showNodeInSlaveView(((LinkNode)currNode).getProgramElementNode());
98
} else if (currNode instanceof LinkNode) {
99                     if (clickCount == 1) {
100                         //AjdeUIManager.getDefault().getViewManager().showLink((LinkNode)currNode);
101
} else if (clickCount == 2) {
102                         //navigationAction((ProgramElementNode)((LinkNode)currNode).getProgramElementNode(), true, true);
103
}
104                 }
105             }
106         }
107
108     /**
109      * @todo this should probably use <CODE>e.isPopupTrigger()</CODE> but that
110      * doesn't work for some reason, so we just check if the right mouse button
111      * has been clicked.
112      */

113     private void maybeShowPopup(MouseEvent e) {
114         if (e.getModifiers() == e.BUTTON3_MASK && tree.getSelectionCount() > 0) {
115             TreePath[] selectionPaths = tree.getSelectionPaths();
116             final List signatures = new ArrayList();
117             for (int i = 0; i < selectionPaths.length; i++) {
118                 StructureNode currNode = (StructureNode)((SwingTreeViewNode)selectionPaths[i].getLastPathComponent()).getUserObject();
119                 if (currNode instanceof LinkNode || currNode instanceof ProgramElementNode) {
120                     signatures.add(currNode);
121                 }
122             }
123
124             JPopupMenu popup = new JPopupMenu();
125             JMenuItem showSourcesItem = new JMenuItem("Display sources", AjdeUIManager.getDefault().getIconRegistry().getStructureSwingIcon(ProgramElementNode.Kind.CODE));
126             showSourcesItem.setFont(new java.awt.Font JavaDoc("Dialog", 0, 11));
127             showSourcesItem.addActionListener(new AbstractAction() {
128                 public void actionPerformed(ActionEvent e) {
129                     //AjdeUIManager.getDefault().getViewManager().showSourcesNodes(signatures);
130
}
131             });
132             popup.add(showSourcesItem);
133
134             popup.addSeparator();
135             JMenuItem generatePCD = new JMenuItem("Pointcut Wizard (alpha)...", AjdeUIManager.getDefault().getIconRegistry().getStructureSwingIcon(ProgramElementNode.Kind.POINTCUT));
136             generatePCD.setFont(new java.awt.Font JavaDoc("Dialog", 0, 11));
137             generatePCD.addActionListener(new AbstractAction() {
138                 public void actionPerformed(ActionEvent e) {
139                     AjdeUIManager.getDefault().getViewManager().extractAndInsertSignatures(signatures, true);
140                 }
141             });
142             popup.add(generatePCD);
143
144             popup.show(e.getComponent(), e.getX(), e.getY());
145         }
146     }
147 }
Popular Tags