001: package tide.editor.linemessages;
002:
003: import java.awt.Color;
004: import snow.utils.storage.*;
005: import java.util.*;
006: import javax.swing.AbstractAction;
007:
008: /** A general message associated with a source line.
009: * ( Compiler errors and warnings are of subtype CompilationMessage )
010: */
011: public abstract class LineMessage implements Comparable<LineMessage> // compares {1: line numbers}
012: {
013: public boolean isSelectedInTable = false;
014:
015: @edu.umd.cs.findbugs.annotations.NonNull
016: final protected String javaName;
017: final protected String sourceJavaName;
018: protected int line;
019: protected long created;
020:
021: public LineMessage(String javaName, int line, long created) {
022: this .javaName = javaName;
023: this .line = line;
024: this .created = created;
025: int pos = javaName.indexOf('$');
026: if (pos > 0) {
027: sourceJavaName = javaName.substring(0, pos);
028: } else {
029: sourceJavaName = javaName;
030: }
031: }
032:
033: public void removeFromModel() {
034: LineMessagesManager.getInstance().remove(this );
035: }
036:
037: /** Inner classes names contains "$" signs, as in Test$1.
038: * use getSourceJavaName to retrieve Test.
039: */
040: public final String getClassJavaName() {
041: return javaName;
042: }
043:
044: /** These doesn't contain any "$". Use getClassJavaName() !
045: * use this when you want to know in which source the message is.
046: */
047: public final String getSourceJavaName() {
048: return sourceJavaName;
049: }
050:
051: public final int getLine() {
052: return line;
053: }
054:
055: /** Used during editor line inserts, very practical !!
056: */
057: public final void shiftLine(int inc) {
058: line += inc;
059: }
060:
061: public int getColumn() {
062: return -1;
063: }
064:
065: public String toStringHTML() {
066: return null;
067: }
068:
069: public Color getColor() {
070: return Color.red;
071: }
072:
073: /** @return null => point
074: */
075: public String getLetter() {
076: return null;
077: }
078:
079: public int getShiftX() {
080: return 1;
081: }
082:
083: public String getMessage() {
084: return null;
085: }
086:
087: public int getPriority() {
088: return 1;
089: }
090:
091: public String getSourceLineForTableColumn() {
092: StringBuilder sb = new StringBuilder();
093: sb.append(getClassJavaName());
094: //not necessary : if(getLine()>-1) sb.append(":"+getLine());
095: return sb.toString();
096: }
097:
098: /** Used when one clicks on the line in the messages table.
099: */
100: public String getMessageForOutputPanel() {
101: StringBuilder sb = new StringBuilder();
102: sb.append(getSourceJavaName()); // class not recognized when $ signs present
103: sb.append(".java:" + getLine() + ":"); // tricky
104: if (getColumn() > 0) {
105: sb.append("" + getColumn() + ":");
106: }
107: sb.append(getMessage());
108: return sb.toString();
109: }
110:
111: public String getCategory() {
112: return "";
113: }
114:
115: /** If not overridden, returns the getMessage().
116: * Please override here to provide single line messages.
117: */
118: public String getMessageForTableColumn() {
119: return getMessage();
120: }
121:
122: public abstract String getMessageOriginator();
123:
124: public List<AbstractAction> lookForAvailableActions() {
125: return null;
126: }
127:
128: // persistence
129: //
130:
131: public abstract StorageVector getStorageRepresentation();
132:
133: public int compareTo(LineMessage lm) {
134: if (getLine() < lm.getLine())
135: return -1;
136: if (getLine() > lm.getLine())
137: return 1;
138: return 0;
139: }
140: }
|