1 21 22 package org.armedbear.j; 23 24 import javax.swing.Icon ; 25 26 public abstract class CompilationErrorBuffer extends Buffer 27 { 28 private CompilationError currentError; 29 30 protected CompilationErrorBuffer() 31 { 32 supportsUndo = false; 33 mode = PlainTextMode.getMode(); 34 formatter = new PlainTextFormatter(this); 35 lineSeparator = System.getProperty("line.separator"); 36 readOnly = true; 37 setTransient(true); 38 setProperty(Property.VERTICAL_RULE, 0); 39 setProperty(Property.SHOW_LINE_NUMBERS, false); 40 setProperty(Property.HIGHLIGHT_MATCHING_BRACKET, false); 41 setProperty(Property.HIGHLIGHT_BRACKETS, false); 42 setInitialized(true); 43 } 44 45 public int load() 46 { 47 if (!isLoaded()) { 48 if (getFirstLine() == null) { 49 try { 50 lockWrite(); 51 } 52 catch (InterruptedException e) { 53 Log.debug(e); 54 return LOAD_FAILED; } 56 try { 57 appendLine(""); 58 renumber(); 59 } 60 finally { 61 unlockWrite(); 62 } 63 } 64 setLoaded(true); 65 } 66 return LOAD_COMPLETED; 67 } 68 69 public CompilationError getCurrentError() 70 { 71 return currentError; 72 } 73 74 public void setCurrentError(CompilationError ce) 75 { 76 currentError = ce; 77 } 78 79 protected CompilationError nextError() 80 { 81 Line line; 82 if (currentError != null) { 83 line = currentError.getErrorLine(); 84 if (line != null) 85 line = line.next(); 86 } else 87 line = getFirstLine(); 88 while (line != null) { 89 CompilationError ce = 90 CompilationError.parseLineAsErrorMessage(line); 91 if (ce != null) { 92 currentError = ce; 93 return ce; 94 } 95 line = line.next(); 96 } 97 return null; 98 } 99 100 protected CompilationError previousError() 101 { 102 Line line; 103 if (currentError != null) { 104 line = currentError.getErrorLine(); 105 if (line != null) 106 line = line.previous(); 107 } else 108 line = getLastLine(); 109 while (line != null) { 110 CompilationError ce = 111 CompilationError.parseLineAsErrorMessage(line); 112 if (ce != null) { 113 currentError = ce; 114 return ce; 115 } 116 line = line.previous(); 117 } 118 return null; 119 } 120 121 public String getMessage() 122 { 123 if (currentError != null) { 124 String message = currentError.getMessage(); 125 if (message != null) 126 return message; 127 Line line = currentError.getErrorLine(); 129 if (line != null && line.next() != null) 130 return line.next().trim(); 131 } 132 return null; 133 } 134 135 public boolean isModified() 136 { 137 return false; 138 } 139 140 public Icon getIcon() 142 { 143 return Utilities.getIconFromFile("jpty.png"); 144 } 145 } 146 | Popular Tags |