001: package org.acm.seguin.completer.popup;
002:
003: import org.acm.seguin.completer.Config;
004: import org.acm.seguin.ide.jedit.Navigator.NavigatorLogger;
005: import org.acm.seguin.completer.Completer;
006: import org.acm.seguin.completer.info.*;
007: import javax.swing.ImageIcon;
008: import java.lang.reflect.*;
009:
010: //import anthelper.utils.ReflectUtils;
011:
012: /**
013: * Description of the Class
014: *
015: * @author btateyama@yahoo.com
016: * @created December 11, 2002
017: */
018: public abstract class PopupItem implements Comparable {
019: static final NavigatorLogger logger = Completer
020: .getLogger(PopupItem.class);
021: // text to view in popup
022: String _strData = null;
023: String _strLeftText = "void";
024: String _strFormattedString = null;
025:
026: // text to insert
027: String _strBeforeCaret = null;
028: String _strAfterCaret = null;
029: // underlying data source
030: Object _objDataSource = null;
031: // formatting info
032: boolean _bUnderline = false;
033: boolean _bBold = false;
034: boolean _bLeftHighLight = true;
035: ImageIcon _icon = null;
036: int _iIconWidth = 0;
037:
038: protected PopupItem() {
039: }
040:
041: void initFormatForMods(int argMods) {
042: // perhaps add more here for bg color, etc.
043: _bUnderline = Modifier.isStatic(argMods);
044: }
045:
046: /**
047: * Gets the beforeCaretString attribute of the PopupItem object
048: *
049: * @return The beforeCaretString value
050: */
051: public String getBeforeCaretString() {
052: return _strBeforeCaret;
053: }
054:
055: /**
056: * Gets the afterCaretString attribute of the PopupItem object
057: *
058: * @return The afterCaretString value
059: */
060: public String getAfterCaretString() {
061: return _strAfterCaret == null ? "" : _strAfterCaret;
062: }
063:
064: /**
065: * Gets the icon attribute of the PopupItem object
066: *
067: * @return The icon value
068: */
069: public ImageIcon getIcon() {
070: return _icon;
071: }
072:
073: /**
074: * Gets the returnType attribute of the PopupItem object
075: *
076: * @return The returnType value
077: */
078: public String getLeftText() {
079: return _strLeftText;
080: }
081:
082: /**
083: * Gets the dataSource attribute of the PopupItem object
084: *
085: * @return The dataSource value
086: */
087: public Object getDataSource() {
088: return _objDataSource;
089: }
090:
091: /**
092: * Description of the Method
093: *
094: * @return Description of the Return Value1
095: */
096: public String toString() {
097: return _strData;
098: }
099:
100: /**
101: * Description of the Method
102: *
103: * @param argPadLen Description of the Parameter
104: * @return Description of the Return Value
105: */
106: public String toString(int argPadLen) {
107:
108: synchronized (this ) {
109:
110: if (_strFormattedString == null) {
111: StringBuffer sb = new StringBuffer();
112: if (getLeftText().length() != 0) {
113: // 1st pad to len
114: String strLeft = getLeftText();
115: for (int i = 0, l = argPadLen - strLeft.length(); i < l; i++) {
116: sb.append(" ");
117: }
118: sb.append(strLeft);
119: }
120: sb.append(_strData);
121: _strFormattedString = sb.toString();
122: }
123: }
124: return _strFormattedString;
125: }
126:
127: /**
128: * Description of the Method
129: *
130: * @return Description of the Return Value
131: */
132: public boolean underLine() {
133: return _bUnderline;
134: }
135:
136: public boolean leftHighlight() {
137: return _bLeftHighLight;
138: }
139:
140: /**
141: * Gets the iconWidth attribute of the PopupItem object
142: *
143: * @return The iconWidth value
144: */
145: public int getIconWidth() {
146: return _iIconWidth;
147: }
148:
149: /**
150: * Description of the Method
151: *
152: * @param obj Description of the Parameter
153: * @return Description of the Return Value
154: */
155: public int compareTo(Object obj) {
156: return (obj instanceof PopupItem ? toString().compareTo(
157: obj.toString()) : -1);
158: }
159:
160: /**
161: * Description of the Method
162: *
163: * @param obj Description of the Parameter
164: * @return Description of the Return Value
165: */
166: public boolean equals(Object obj) {
167: boolean bEq = obj == this ;
168: if (!bEq && obj != null) {
169: PopupItem pi = (PopupItem) obj;
170: bEq = (pi.toString().equals(toString())
171: && pi.getBeforeCaretString().equals(
172: getBeforeCaretString())
173: && pi.getAfterCaretString().equals(
174: getAfterCaretString()) && pi
175: .getDataSource().equals(getDataSource()));
176: }
177: return bEq;
178: }
179:
180: static String getParamsDesc(String[] argParamTypes) {
181: StringBuffer sb = new StringBuffer("(");
182: for (int i = 0, l = argParamTypes.length; i < l; i++) {
183: sb.append(getPlainName(argParamTypes[i]));
184: if (i + 1 < l)
185: sb.append(",");
186: }
187: sb.append(")");
188: return sb.toString();
189: }
190:
191: static String decodeTypeArray(char argChar) {
192: String str = null;
193: switch (argChar) {
194: case 'B':
195: str = "byte";
196: break;
197: case 'C':
198: str = "char";
199: break;
200: case 'D':
201: str = "double";
202: break;
203: case 'F':
204: str = "float";
205: break;
206: case 'I':
207: str = "int";
208: break;
209: case 'J':
210: str = "long";
211: break;
212: case 'S':
213: str = "short";
214: break;
215: case 'Z':
216: str = "boolean";
217: break;
218: // ?? V void
219: }
220: return str;
221: }
222:
223: static String getPlainName(String argType) {
224: StringBuffer sb = new StringBuffer();
225: //logger.msg("type", argType);
226: if (argType.startsWith("[")) {
227: //logger.msg("in stuff");
228: // it's an array of some kind and some dimension
229: StringBuffer sbDim = new StringBuffer();
230: for (int i = 0, l = argType.length(); i < l
231: && argType.charAt(i) == '['; i++) {
232: sbDim.append("[]");
233: }
234:
235: // we have accounted for dimension, now decode type
236: int iL = argType.indexOf("[L");
237: if (iL != -1) {
238: // we have a class of somekind
239: String strFullName = argType.substring(iL + 2, argType
240: .indexOf(";"));
241: sb.append(getPlainName(strFullName));
242: } else {
243: // we have a native type array (see Class.getName())
244: String strNativeType = decodeTypeArray(argType
245: .charAt(sbDim.length() / 2));
246: if (strNativeType != null) {
247: sb.append(strNativeType);
248: }
249: }
250: sb.append(sbDim.toString());
251: } else {
252: sb.append(getPlainName(argType));
253: }
254: return sb.toString();
255: }
256:
257: public static String getPlainName2(String argName) {
258: String strPlainName = argName.substring(argName
259: .lastIndexOf(".") + 1);
260: //@REVIEW
261: // We make a special case for the static field class.
262: // It appears as class$<className with $ instead of .>
263: // Ex: class$anthelper$ui$ConfigDialog
264: if (strPlainName.startsWith("class$")) {
265: strPlainName = "class";
266: }
267: strPlainName = strPlainName.replace('$', '.');
268: return strPlainName;
269: }
270:
271: }
|