KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > LocalTag


1 /*
2  * LocalTag.java
3  *
4  * Copyright (C) 1998-2002 Peter Graves
5  * $Id: LocalTag.java,v 1.3 2003/05/07 01:34:07 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.j;
23
24 import java.awt.Component JavaDoc;
25 import java.awt.Graphics JavaDoc;
26 import javax.swing.Icon JavaDoc;
27 import javax.swing.ImageIcon JavaDoc;
28 import javax.swing.undo.CompoundEdit JavaDoc;
29
30 public class LocalTag extends Tag implements Constants
31 {
32     private final Position pos;
33     private final int type;
34     private int flags;
35
36     protected LocalTag(String JavaDoc name, Line line)
37     {
38         super(name, line.getText());
39         pos = new Position(line, 0);
40         type = TAG_METHOD;
41     }
42
43     protected LocalTag(String JavaDoc name, Position pos)
44     {
45         super(name, pos.getLine().getText());
46         this.pos = new Position(pos);
47         type = TAG_METHOD;
48     }
49
50     protected LocalTag(String JavaDoc name, Position pos, int type, int flags)
51     {
52         super(name, pos.getLine().getText());
53         this.pos = new Position(pos);
54         this.type = type;
55         this.flags = flags;
56     }
57
58     protected LocalTag(String JavaDoc name, Position pos, int type)
59     {
60         super(name, pos.getLine().getText());
61         this.pos = new Position(pos);
62         this.type = type;
63     }
64
65     public String JavaDoc getMethodName()
66     {
67         return name;
68     }
69
70     public String JavaDoc getLongName()
71     {
72         return name;
73     }
74
75     public String JavaDoc getClassName()
76     {
77         return null;
78     }
79
80     public final Position getPosition()
81     {
82         return pos;
83     }
84
85     public final Line getLine()
86     {
87         return pos.getLine();
88     }
89
90     public final int lineNumber()
91     {
92         return pos.lineNumber();
93     }
94
95     public final int getType()
96     {
97         return type;
98     }
99
100     public final boolean isPublic()
101     {
102         return (flags & TAG_VISIBILITY_MASK) == TAG_PUBLIC;
103     }
104
105     public final boolean isProtected()
106     {
107         return (flags & TAG_VISIBILITY_MASK) == TAG_PROTECTED;
108     }
109
110     public final boolean isPrivate()
111     {
112         return (flags & TAG_VISIBILITY_MASK) == TAG_PRIVATE;
113     }
114
115     private static ImageIcon JavaDoc interfaceIcon;
116     private static ImageIcon JavaDoc classIcon;
117     private static ImageIcon JavaDoc methodIcon;
118     private static ImageIcon JavaDoc fieldIcon;
119
120     private static ImageIcon JavaDoc publicIcon;
121     private static ImageIcon JavaDoc protectedIcon;
122     private static ImageIcon JavaDoc privateIcon;
123
124     public Icon JavaDoc getIcon()
125     {
126         ImageIcon JavaDoc base = null;
127         ImageIcon JavaDoc overlay = null;
128         switch (type) {
129             case TAG_INTERFACE:
130             case TAG_IMPLEMENTS:
131             case TAG_TYPE: // Lisp
132
if (interfaceIcon == null)
133                     interfaceIcon = Utilities.getIconFromFile("interface.png");
134                 base = interfaceIcon;
135                 break;
136             case TAG_CLASS:
137             case TAG_EXTENDS:
138             case TAG_CONDITION: // Lisp
139
case TAG_STRUCT: // Lisp
140
if (classIcon == null)
141                     classIcon = Utilities.getIconFromFile("class.png");
142                 base = classIcon;
143                 break;
144             case TAG_METHOD:
145             case TAG_MACRO: // Lisp
146
case TAG_DEFUN: // Lisp
147
default:
148                 if (methodIcon == null)
149                     methodIcon = Utilities.getIconFromFile("method.png");
150                 base = methodIcon;
151                 break;
152             case TAG_FIELD:
153             case TAG_CONSTANT: // Lisp
154
case TAG_PARAMETER: // Lisp
155
case TAG_VAR: // Lisp
156
if (fieldIcon == null)
157                     fieldIcon = Utilities.getIconFromFile("field.png");
158                 base = fieldIcon;
159                 break;
160         }
161         if (isPublic()) {
162             if (publicIcon == null)
163                 publicIcon = Utilities.getIconFromFile("public.png");
164             overlay = publicIcon;
165         } else if (isProtected()) {
166             if (protectedIcon == null)
167                 protectedIcon = Utilities.getIconFromFile("protected.png");
168             overlay = protectedIcon;
169         } else if (isPrivate()) {
170             if (privateIcon == null)
171                 privateIcon = Utilities.getIconFromFile("private.png");
172             overlay = privateIcon;
173         }
174         return new OverlayIcon(base, overlay);
175     }
176
177     public String JavaDoc toString()
178     {
179         return getMethodName();
180     }
181
182     public String JavaDoc getSidebarText()
183     {
184         return getMethodName();
185     }
186
187     public String JavaDoc getToolTipText()
188     {
189         return getLongName();
190     }
191
192     public void gotoTag(Editor editor)
193     {
194         if (editor.getBuffer().contains(pos.getLine())) {
195             CompoundEdit JavaDoc compoundEdit = editor.beginCompoundEdit();
196             editor.addUndo(SimpleEdit.FOLD);
197             editor.unfoldMethod(pos.getLine());
198             editor.moveDotTo(pos);
199             TagCommands.centerTag(editor);
200             editor.endCompoundEdit(compoundEdit);
201             editor.getBuffer().repaint();
202             editor.updateDisplay();
203         }
204     }
205
206     private static class OverlayIcon extends ImageIcon JavaDoc
207     {
208         private ImageIcon JavaDoc base;
209         private ImageIcon JavaDoc overlay;
210
211         private OverlayIcon(ImageIcon JavaDoc base, ImageIcon JavaDoc overlay)
212         {
213             this.base = base;
214             this.overlay = overlay;
215         }
216
217         public synchronized void paintIcon(Component JavaDoc c, Graphics JavaDoc g, int x, int y)
218         {
219             if (base != null)
220                 base.paintIcon(c, g, x, y);
221             if (overlay != null)
222                 overlay.paintIcon(c, g, x, y);
223         }
224
225         public final int getIconWidth()
226         {
227             return base.getIconWidth();
228         }
229
230         public final int getIconHeight()
231         {
232             return base.getIconHeight();
233         }
234     }
235 }
236
Popular Tags