@@ -104,6 +104,7 @@ public static SyntaxStyle[] getDefaultSyntaxStyles()
104
104
styles [Token .LITERAL2 ] = new SyntaxStyle (new Color (0x650099 ),false ,true );
105
105
styles [Token .LABEL ] = new SyntaxStyle (new Color (0x990033 ),false ,true );
106
106
styles [Token .OPERATOR ] = new SyntaxStyle (Color .black ,false ,true );
107
+ styles [Token .URL ] = new SyntaxStyle (Color .blue ,true ,false );
107
108
styles [Token .INVALID ] = new SyntaxStyle (Color .red ,false ,true );
108
109
109
110
return styles ;
@@ -151,7 +152,7 @@ public static int paintSyntaxLine(Segment line, Token tokens,
151
152
152
153
line .count = length ;
153
154
if (id == Token .COMMENT1 || id == Token .COMMENT2 )
154
- x = drawTabbedCommentsText (line , x , y , gfx , expander );
155
+ x = drawTabbedCommentsText (line , x , y , gfx , expander , styles , styles [ id ] );
155
156
else
156
157
x = Utilities .drawTabbedText (line , x , y , gfx , expander , 0 );
157
158
line .offset += length ;
@@ -174,9 +175,7 @@ public static int paintSyntaxLine(Segment line, Token tokens,
174
175
* the remaining part of the string.
175
176
*/
176
177
public static String [] parseCommentUrls (String line ) {
177
- // Try to find pattern
178
- Pattern schematics = Pattern .compile ("@schematics\\ s+([^\\ s]+)" );
179
- Matcher m = schematics .matcher (line .toString ());
178
+ Matcher m = urlPattern .matcher (line .toString ());
180
179
if (!m .find ())
181
180
return null ;
182
181
@@ -188,12 +187,21 @@ public static String[] parseCommentUrls(String line) {
188
187
return res ;
189
188
}
190
189
190
+ static private Pattern urlPattern = Pattern .compile (
191
+ "((?:https?|ftp)://" + // ( Protocol
192
+ "(?:(?:[\\ w_\\ -]+:)?[\\ w_\\ -]+@)?" + // Username and password
193
+ "(?:[\\ w_\\ -]+\\ .)+[\\ w_\\ -]+" + // Domain name
194
+ "(?::[0-9]{1,5})?" + // Port
195
+ "(?:/[\\ w_\\ -./?%&=+]*)?)" + // Path )
196
+ "(?:\\ s|$)" ); // whitespace or EOL
197
+
191
198
public static Segment stringToSegment (String v ) {
192
199
return new Segment (v .toCharArray (), 0 , v .length ());
193
200
}
194
201
195
202
private static int drawTabbedCommentsText (Segment line , int x , int y ,
196
- Graphics gfx , TabExpander expander ) {
203
+ Graphics gfx , TabExpander expander , SyntaxStyle [] styles ,
204
+ SyntaxStyle commentStyle ) {
197
205
198
206
String parse [] = parseCommentUrls (line .toString ());
199
207
if (parse == null )
@@ -203,14 +211,21 @@ private static int drawTabbedCommentsText(Segment line, int x, int y,
203
211
Segment tag = stringToSegment (parse [1 ]);
204
212
Segment post = stringToSegment (parse [2 ]);
205
213
206
- x = Utilities .drawTabbedText (pre , x , y , gfx , expander , 0 );
214
+ if (pre .length ()>0 )
215
+ x = Utilities .drawTabbedText (pre , x , y , gfx , expander , 0 );
216
+
217
+ Font f = gfx .getFont ();
218
+ styles [Token .URL ].setGraphicsFlags (gfx , f );
207
219
x = Utilities .drawTabbedText (tag , x , y , gfx , expander , 0 );
208
220
209
221
// Draw arrow.
210
222
FontMetrics metrics = gfx .getFontMetrics ();
211
223
int h = metrics .getHeight () - 2 ;
212
224
drawArrow (gfx , x , y - h + metrics .getDescent () - 1 , h , h );
213
- x = Utilities .drawTabbedText (post , x , y , gfx , expander , 0 );
225
+
226
+ commentStyle .setGraphicsFlags (gfx , f );
227
+ if (post .length ()>0 )
228
+ x = Utilities .drawTabbedText (post , x , y , gfx , expander , 0 );
214
229
return x ;
215
230
}
216
231
0 commit comments