KickJava   Java API By Example, From Geeks To Geeks.

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


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.awt.*;
29 import java.awt.event.*;
30 import java.io.File JavaDoc;
31
32 import javax.swing.*;
33 import javax.swing.event.*;
34 import java.util.*;
35 import org.aspectj.ajde.*;
36 import org.aspectj.asm.*;
37 import org.aspectj.asm.views.*;
38 import org.aspectj.ajde.ui.*;
39 import javax.swing.border.*;
40
41 /**
42  * Represents the configuration of a structure view of the system, rendered
43  * by the <CODE>StructureTreeManager</CODE>.
44  *
45  * @author Mik Kersten
46  */

47 public class StructureViewPanel extends JPanel implements StructureViewRenderer {
48
49     protected StructureTreeManager treeManager = new StructureTreeManager();
50     protected StructureView currentView = null;
51     private java.util.List JavaDoc structureViews = null;
52
53     protected Border border1;
54     protected Border border2;
55     JScrollPane tree_ScrollPane = new JScrollPane();
56     JPanel structureToolBar_panel = null;
57     BorderLayout borderLayout1 = new BorderLayout();
58
59     public StructureViewPanel(FileStructureView structureView) {
60         currentView = structureView;
61         initView(structureView);
62         structureToolBar_panel = new SimpleStructureViewToolPanel(currentView);
63         init();
64     }
65
66     public StructureViewPanel(java.util.List JavaDoc structureViews) {
67         this.structureViews = structureViews;
68
69         for (Iterator it = structureViews.iterator(); it.hasNext(); ) {
70             initView((StructureView)it.next());
71         }
72         currentView = (StructureView)structureViews.get(0);
73         structureToolBar_panel = new BrowserStructureViewToolPanel(structureViews, currentView, this);
74         init();
75     }
76     
77     private void init() {
78         try {
79             jbInit();
80         } catch (Exception JavaDoc e) {
81             Ajde.getDefault().getErrorHandler().handleError("Could not initialize view panel.", e);
82         }
83         updateView(currentView);
84     }
85
86     public void setCurrentView(StructureView view) {
87         currentView = view;
88         treeManager.updateTree(view);
89     }
90
91     public void updateView(StructureView structureView) {
92         if (structureView == currentView) {
93             treeManager.updateTree(structureView);
94         }
95     }
96
97     private void initView(StructureView view) {
98         view.setRenderer(this);
99     }
100
101     public void setActiveNode(StructureViewNode node) {
102         setActiveNode(node, 0);
103     }
104
105     public void setActiveNode(StructureViewNode node, int lineOffset) {
106         if (node == null) return;
107         if (!(node.getStructureNode() instanceof ProgramElementNode)) return;
108         ProgramElementNode pNode = (ProgramElementNode)node.getStructureNode();
109         treeManager.highlightNode(pNode);
110         if (pNode.getSourceLocation() != null) {
111             Ajde.getDefault().getEditorManager().showSourceLine(
112                 pNode.getSourceLocation().getSourceFilePath(),
113                 pNode.getSourceLocation().getLineNumber() + lineOffset,
114                 true
115             );
116         }
117     }
118
119     public void highlightActiveNode() {
120         if (currentView.getActiveNode() == null) return;
121         StructureNode node = currentView.getActiveNode().getStructureNode();
122         if (node instanceof ProgramElementNode) {
123             treeManager.highlightNode((ProgramElementNode)node);
124         }
125     }
126
127     protected void jbInit() {
128         border1 = BorderFactory.createBevelBorder(BevelBorder.LOWERED,Color.white,Color.white,new Color(156, 156, 158),new Color(109, 109, 110));
129         border2 = BorderFactory.createEmptyBorder(0,1,0,0);
130
131         this.setLayout(borderLayout1);
132         this.add(tree_ScrollPane, BorderLayout.CENTER);
133         this.add(structureToolBar_panel, BorderLayout.NORTH);
134
135         tree_ScrollPane.getViewport().add(treeManager.getStructureTree(), null);
136     }
137 }
Popular Tags