Changeset 601
- Timestamp:
- 01/31/10 14:47:12 (3 years ago)
- Location:
- trunk
- Files:
-
- 2 modified
- 1 copied
-
data/gproperties/styles/user.xml (modified) (1 diff)
-
src/jlatexeditor/gproperties/GPropertiesSyntaxHighlighting.java (copied) (copied from trunk/src/jlatexeditor/syntaxhighlighting/LatexSyntaxHighlighting.java) (8 diffs)
-
src/jlatexeditor/JLatexEditorJFrame.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/data/gproperties/styles/user.xml
r600 r601 19 19 20 20 <element name="number" style="plain"> 21 <foreground><color r="0" g=" 0" b="0"/></foreground>21 <foreground><color r="0" g="128" b="0"/></foreground> 22 22 </element> 23 23 -
trunk/src/jlatexeditor/gproperties/GPropertiesSyntaxHighlighting.java
r535 r601 4 4 */ 5 5 6 package jlatexeditor.syntaxhighlighting; 7 6 package jlatexeditor.gproperties; 7 8 import jlatexeditor.syntaxhighlighting.LatexStyles; 9 import jlatexeditor.syntaxhighlighting.StyleableTerm; 8 10 import jlatexeditor.syntaxhighlighting.states.MathMode; 9 11 import jlatexeditor.syntaxhighlighting.states.RootState; … … 18 20 import java.util.regex.Pattern; 19 21 20 public class LatexSyntaxHighlighting extends SyntaxHighlighting implements SCEDocumentListener{22 public class GPropertiesSyntaxHighlighting extends SyntaxHighlighting implements SCEDocumentListener{ 21 23 private static final Pattern TERM_PATTERN = Pattern.compile("(\\\\?[\\w_\\-\\^]+)"); 22 24 private static final Pattern BAD_TERM_CHARS = Pattern.compile("[\\\\\\d_\\-\\^]"); … … 30 32 private boolean currentlyChanging = false; 31 33 32 private static Aspell aspell; 33 static { 34 try { 35 aspell = Aspell.getInstance(); 36 } catch (IOException e) { 37 e.printStackTrace(); 38 } 39 } 40 41 public LatexSyntaxHighlighting(SCEPane pane){ 34 public GPropertiesSyntaxHighlighting(SCEPane pane){ 42 35 this.pane = pane; 43 36 document = pane.getDocument(); … … 129 122 private void parseRow(int row_nr, int rowsCount, SCEDocumentRow rows[]){ 130 123 boolean ready = false; 131 LatexStyles.CommandStyle lastCommandStyle = null;132 124 133 125 while(!ready && row_nr < rowsCount){ … … 144 136 145 137 // parse the row 138 boolean parsingKey = true; 146 139 SCEDocumentChar chars[] = row.chars; 147 140 for(int char_nr = 0; char_nr < row.length; char_nr++){ … … 151 144 byte[] stateStyles = state.getStyles(); 152 145 153 // search for a backslash '\' 154 if(c == '\\'){ 155 String command = getCommandString(row, char_nr + 1); 156 157 if(command == null){ 158 byte styleText = stateStyles[LatexStyles.TEXT]; 159 // if there is no command -> '\' escapes the next character -> set style text 160 if(char_nr < row.length - 1){ 161 sce_char.style = styleText; 162 chars[char_nr + 1].style = styleText; 163 char_nr += 1; 164 }else{ 165 sce_char.style = stateStyles[LatexStyles.ERROR]; 166 } 167 lastCommandStyle = null; 168 }else{ 169 lastCommandStyle = LatexStyles.getCommandStyle(command); 170 // highlight the command 171 byte commandStyle = stateStyles[lastCommandStyle.commandStyle]; 172 for(int i = 0; i <= command.length(); i++){ 173 chars[char_nr + i].style = commandStyle; 174 } 175 char_nr += command.length(); 176 } 177 178 continue; 179 } 180 181 // search for '$' and "$$" 182 if(c == '$'){ 183 sce_char.style = stateStyles[LatexStyles.MATH]; 184 185 boolean doubleMath = chars[char_nr + 1].character == '$'; 186 if (doubleMath) { 187 char_nr++; 188 chars[char_nr].style = stateStyles[LatexStyles.MATH]; 189 } 190 191 // if active math mode -> close; otherwise open 192 if (state instanceof MathMode) { 193 stateStack.pop(); 194 state = stateStack.peek(); 195 } else { 196 stateStack.push(state = new MathMode(doubleMath)); 197 } 198 199 continue; 200 } 146 // search for '#' (comment) 147 if(c == '#'){ 148 byte commentStyle = stateStyles[LatexStyles.COMMENT]; 149 while(char_nr < row.length) chars[char_nr++].style = commentStyle; 150 continue; 151 } 152 153 if (parsingKey) { 154 // search for a backslash '\' 155 if(c == '='){ 156 sce_char.style = stateStyles[GPropertiesStyles.TEXT]; 157 parsingKey = false; 158 continue; 159 } else { 160 sce_char.style = stateStyles[GPropertiesStyles.KEY]; 161 continue; 162 } 163 } 201 164 202 165 // search for '{' and '}' 203 166 if(c == '{'){ 204 sce_char.style = stateStyles[ LatexStyles.BRACKET];167 sce_char.style = stateStyles[GPropertiesStyles.BRACKET]; 205 168 continue; 206 169 } 207 170 if(c == '}'){ 208 sce_char.style = stateStyles[LatexStyles.BRACKET]; 209 continue; 210 } 211 212 // search for '%' (comment) 213 if(c == '%'){ 214 byte commentStyle = stateStyles[LatexStyles.COMMENT]; 215 while(char_nr < row.length) chars[char_nr++].style = commentStyle; 171 sce_char.style = stateStyles[GPropertiesStyles.BRACKET]; 216 172 continue; 217 173 } … … 219 175 // default style is text or number 220 176 if(c >= '0' && c <= '9'){ 221 sce_char.style = stateStyles[ LatexStyles.NUMBER];177 sce_char.style = stateStyles[GPropertiesStyles.NUMBER]; 222 178 }else{ 223 sce_char.style = stateStyles[LatexStyles.TEXT]; 224 } 225 } 226 227 // extract word from row that shell be checked for misspellings 228 String rowString = document.getRow(row_nr); 229 230 // for each term in this row 231 Matcher matcher = TERM_PATTERN.matcher(rowString); 232 while(matcher.find()) { 233 // check if it's not a tex command and does not contain formula specific characters ("_" and numbers) 234 String termString = matcher.group(1); 235 StyleableTerm term; 236 if (BAD_TERM_CHARS.matcher(termString).find()) { 237 term = new StyleableTerm(termString, chars, matcher.start(1), LatexStyles.U_NORMAL); 238 } else { 239 // spell check 240 try { 241 Aspell.Result aspellResult = aspell.check(termString); 242 term = new StyleableTerm(termString, chars, matcher.start(1), aspellResult.isCorrect() ? LatexStyles.U_NORMAL : LatexStyles.U_MISSPELLED); 243 } catch (IOException e) { 244 term = new StyleableTerm(termString, chars, matcher.start(1), LatexStyles.U_NORMAL); 245 e.printStackTrace(); 246 } 247 } 248 249 term.applyStyleToDoc(); 250 } 179 sce_char.style = stateStyles[GPropertiesStyles.TEXT]; 180 } 181 } 251 182 252 183 // go to the next row … … 264 195 } 265 196 266 /**267 * Returns the command name found at the given position (after '\').268 *269 * @param row the row270 * @param offset the offset271 * @return the command string272 */273 private String getCommandString(SCEDocumentRow row, int offset){274 String command = null;275 276 SCEDocumentChar chars[] = row.chars;277 int end_offset = offset;278 for(; end_offset < row.length; end_offset++){279 char character = chars[end_offset].character;280 281 // only letters are allowed282 if(character >= 'a' && character <= 'z') continue;283 if(character >= 'A' && character <= 'Z') continue;284 285 // we found the end of the command286 break;287 }288 // command consists of at least 1 char289 if (end_offset == offset) end_offset++;290 291 // did we find a command?292 if(offset != end_offset){293 SCEString sceCommand = new SCEString(chars, offset, end_offset - offset);294 command = sceCommand.toString();295 }296 297 return command;298 }299 300 197 // SCEDocumentListener methods 301 198 public void documentChanged(SCEDocument sender, SCEDocumentEvent event){ -
trunk/src/jlatexeditor/JLatexEditorJFrame.java
r600 r601 11 11 import jlatexeditor.errorhighlighting.LatexErrorHighlighting; 12 12 import jlatexeditor.gproperties.GPropertiesStyles; 13 import jlatexeditor.gproperties.GPropertiesSyntaxHighlighting; 13 14 import jlatexeditor.gui.AboutDialog; 14 15 import jlatexeditor.gui.LocalHistory; … … 438 439 439 440 // syntax highlighting 440 // SyntaxHighlighting syntaxHighlighting = new LatexSyntaxHighlighting(scePane);441 //syntaxHighlighting.start();441 GPropertiesSyntaxHighlighting syntaxHighlighting = new GPropertiesSyntaxHighlighting(scePane); 442 syntaxHighlighting.start(); 442 443 443 444 // code completion and quick help
![(please configure the [header_logo] section in trac.ini)](http://jlatexeditor.endrullis.de/chrome/site/logo.png)