KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > ajde > ui > StructureView


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;
27
28 import java.util.*;
29 import org.aspectj.asm.*;
30 import org.aspectj.ajde.ui.internal.*;
31
32 /**
33  * @author Mik Kersten
34  */

35 public abstract class StructureView {
36
37     private StructureViewNode rootNode = null;
38     private StructureViewNode activeNode = null;
39     protected StructureViewProperties viewProperties = null;
40     protected StructureViewRenderer renderer = null;
41     
42     public StructureViewProperties getViewProperties() {
43         return viewProperties;
44     }
45     
46     public StructureViewNode getRootNode() {
47         return rootNode;
48     }
49
50     public void setRootNode(StructureViewNode rootNode) {
51         this.rootNode = rootNode;
52     }
53
54     public void setViewProperties(StructureViewProperties viewProperties) {
55         this.viewProperties = viewProperties;
56     }
57
58     public void setRenderer(StructureViewRenderer renderer) {
59         this.renderer = renderer;
60     }
61
62     protected void notifyViewUpdated() {
63         if (renderer != null) renderer.updateView(this);
64     }
65
66     /**
67      * @return the view node corresponding to the active ProgramElementNode or null
68      */

69     public StructureViewNode getActiveNode() {
70         if (activeNode != null
71             && activeNode.getStructureNode() instanceof ProgramElementNode) {
72             return activeNode;
73         } else {
74             return null;
75         }
76     }
77
78     /**
79      * Searches from the root node of the view down in order to find matches.
80      *
81      * @return the first match
82      */

83     public StructureViewNode findCorrespondingViewNode(ProgramElementNode node) {
84         return findCorrespondingViewNodeHelper(rootNode, node);
85     }
86
87     private StructureViewNode findCorrespondingViewNodeHelper(StructureViewNode node, ProgramElementNode pNode) {
88         
89         if (node != null
90             && node.getStructureNode() != null
91             && node.getStructureNode().equals(pNode)) {
92             return node;
93         }
94         
95         if (node != null && node.getChildren() != null) {
96             for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
97                 StructureViewNode foundNode = findCorrespondingViewNodeHelper((StructureViewNode)it.next(), pNode);
98                 if (foundNode != null) return foundNode;
99             }
100         }
101         
102         return null;
103     }
104
105     public void setActiveNode(StructureViewNode activeNode) {
106         this.activeNode = activeNode;
107         if (renderer != null) renderer.setActiveNode(activeNode);
108     }
109     
110     public void setActiveNode(StructureViewNode activeNode, int sourceLine) {
111         this.activeNode = activeNode;
112         if (renderer != null) renderer.setActiveNode(activeNode, sourceLine);
113     }
114 }
115  
116
Popular Tags