001: /*
002: * LocalTag.java
003: *
004: * Copyright (C) 1998-2002 Peter Graves
005: * $Id: LocalTag.java,v 1.3 2003/05/07 01:34:07 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.j;
023:
024: import java.awt.Component;
025: import java.awt.Graphics;
026: import javax.swing.Icon;
027: import javax.swing.ImageIcon;
028: import javax.swing.undo.CompoundEdit;
029:
030: public class LocalTag extends Tag implements Constants {
031: private final Position pos;
032: private final int type;
033: private int flags;
034:
035: protected LocalTag(String name, Line line) {
036: super (name, line.getText());
037: pos = new Position(line, 0);
038: type = TAG_METHOD;
039: }
040:
041: protected LocalTag(String name, Position pos) {
042: super (name, pos.getLine().getText());
043: this .pos = new Position(pos);
044: type = TAG_METHOD;
045: }
046:
047: protected LocalTag(String name, Position pos, int type, int flags) {
048: super (name, pos.getLine().getText());
049: this .pos = new Position(pos);
050: this .type = type;
051: this .flags = flags;
052: }
053:
054: protected LocalTag(String name, Position pos, int type) {
055: super (name, pos.getLine().getText());
056: this .pos = new Position(pos);
057: this .type = type;
058: }
059:
060: public String getMethodName() {
061: return name;
062: }
063:
064: public String getLongName() {
065: return name;
066: }
067:
068: public String getClassName() {
069: return null;
070: }
071:
072: public final Position getPosition() {
073: return pos;
074: }
075:
076: public final Line getLine() {
077: return pos.getLine();
078: }
079:
080: public final int lineNumber() {
081: return pos.lineNumber();
082: }
083:
084: public final int getType() {
085: return type;
086: }
087:
088: public final boolean isPublic() {
089: return (flags & TAG_VISIBILITY_MASK) == TAG_PUBLIC;
090: }
091:
092: public final boolean isProtected() {
093: return (flags & TAG_VISIBILITY_MASK) == TAG_PROTECTED;
094: }
095:
096: public final boolean isPrivate() {
097: return (flags & TAG_VISIBILITY_MASK) == TAG_PRIVATE;
098: }
099:
100: private static ImageIcon interfaceIcon;
101: private static ImageIcon classIcon;
102: private static ImageIcon methodIcon;
103: private static ImageIcon fieldIcon;
104:
105: private static ImageIcon publicIcon;
106: private static ImageIcon protectedIcon;
107: private static ImageIcon privateIcon;
108:
109: public Icon getIcon() {
110: ImageIcon base = null;
111: ImageIcon overlay = null;
112: switch (type) {
113: case TAG_INTERFACE:
114: case TAG_IMPLEMENTS:
115: case TAG_TYPE: // Lisp
116: if (interfaceIcon == null)
117: interfaceIcon = Utilities
118: .getIconFromFile("interface.png");
119: base = interfaceIcon;
120: break;
121: case TAG_CLASS:
122: case TAG_EXTENDS:
123: case TAG_CONDITION: // Lisp
124: case TAG_STRUCT: // Lisp
125: if (classIcon == null)
126: classIcon = Utilities.getIconFromFile("class.png");
127: base = classIcon;
128: break;
129: case TAG_METHOD:
130: case TAG_MACRO: // Lisp
131: case TAG_DEFUN: // Lisp
132: default:
133: if (methodIcon == null)
134: methodIcon = Utilities.getIconFromFile("method.png");
135: base = methodIcon;
136: break;
137: case TAG_FIELD:
138: case TAG_CONSTANT: // Lisp
139: case TAG_PARAMETER: // Lisp
140: case TAG_VAR: // Lisp
141: if (fieldIcon == null)
142: fieldIcon = Utilities.getIconFromFile("field.png");
143: base = fieldIcon;
144: break;
145: }
146: if (isPublic()) {
147: if (publicIcon == null)
148: publicIcon = Utilities.getIconFromFile("public.png");
149: overlay = publicIcon;
150: } else if (isProtected()) {
151: if (protectedIcon == null)
152: protectedIcon = Utilities
153: .getIconFromFile("protected.png");
154: overlay = protectedIcon;
155: } else if (isPrivate()) {
156: if (privateIcon == null)
157: privateIcon = Utilities.getIconFromFile("private.png");
158: overlay = privateIcon;
159: }
160: return new OverlayIcon(base, overlay);
161: }
162:
163: public String toString() {
164: return getMethodName();
165: }
166:
167: public String getSidebarText() {
168: return getMethodName();
169: }
170:
171: public String getToolTipText() {
172: return getLongName();
173: }
174:
175: public void gotoTag(Editor editor) {
176: if (editor.getBuffer().contains(pos.getLine())) {
177: CompoundEdit compoundEdit = editor.beginCompoundEdit();
178: editor.addUndo(SimpleEdit.FOLD);
179: editor.unfoldMethod(pos.getLine());
180: editor.moveDotTo(pos);
181: TagCommands.centerTag(editor);
182: editor.endCompoundEdit(compoundEdit);
183: editor.getBuffer().repaint();
184: editor.updateDisplay();
185: }
186: }
187:
188: private static class OverlayIcon extends ImageIcon {
189: private ImageIcon base;
190: private ImageIcon overlay;
191:
192: private OverlayIcon(ImageIcon base, ImageIcon overlay) {
193: this .base = base;
194: this .overlay = overlay;
195: }
196:
197: public synchronized void paintIcon(Component c, Graphics g,
198: int x, int y) {
199: if (base != null)
200: base.paintIcon(c, g, x, y);
201: if (overlay != null)
202: overlay.paintIcon(c, g, x, y);
203: }
204:
205: public final int getIconWidth() {
206: return base.getIconWidth();
207: }
208:
209: public final int getIconHeight() {
210: return base.getIconHeight();
211: }
212: }
213: }
|