Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 219393 | Differences between
and this patch

Collapse All | Expand All

(-)ui/org/eclipse/jdt/ui/tests/core/ColoredStringsTest.java (-798 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.ui.tests.core;
12
13
import junit.framework.Test;
14
import junit.framework.TestCase;
15
import junit.framework.TestSuite;
16
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.custom.StyleRange;
19
import org.eclipse.swt.graphics.TextStyle;
20
21
import org.eclipse.jdt.internal.ui.viewsupport.ColoredString;
22
import org.eclipse.jdt.internal.ui.viewsupport.ColoredString.Style;
23
24
public class ColoredStringsTest extends TestCase {
25
	
26
	public static class TestStyle extends Style {
27
		
28
		public final int borderStyle;
29
30
		public TestStyle(int borderStyle) {
31
			this.borderStyle= borderStyle;
32
		}
33
		
34
		public void applyStyles(TextStyle textStyle) {
35
			textStyle.borderStyle= borderStyle;
36
		}
37
	}
38
	
39
	public static final TestStyle STYLE1= new TestStyle(SWT.BORDER_DOT);
40
	public static final TestStyle STYLE2= new TestStyle(SWT.BORDER_DASH);
41
	
42
	
43
	public static Test allTests() {
44
		return new TestSuite(ColoredStringsTest.class);
45
	}
46
47
	public static Test suite() {
48
		return allTests();
49
	}
50
	
51
	public void testEmpty() {
52
		ColoredString coloredString= new ColoredString();
53
		
54
		String str= "";
55
		
56
		assertEquals(str.length(), coloredString.length());
57
		assertEquals(str, coloredString.getString());
58
		assertEquals(coloredString.getStyleRanges().length, 0);
59
	}
60
	
61
	public void testAppendString1() {
62
		ColoredString coloredString= new ColoredString();
63
		
64
		String str= "Hello";
65
		
66
		coloredString.append(str, STYLE1);
67
		
68
		assertEquals(str.length(), coloredString.length());
69
		assertEquals(str, coloredString.getString());
70
		StyleRange[] styleRanges= coloredString.getStyleRanges();
71
		assertEquals(1, styleRanges.length);
72
		
73
		assertEquals(styleRanges[0], STYLE1, 0, str.length());
74
	}
75
	
76
	public void testAppendString2() {
77
		ColoredString coloredString= new ColoredString();
78
		
79
		String str1= "Hello";
80
		String str2= "You";
81
		coloredString.append(str1);
82
		coloredString.append(str2, STYLE1);
83
		
84
		String res= str1 + str2;
85
		
86
		assertEquals(res.length(), coloredString.length());
87
		assertEquals(res, coloredString.getString());
88
		StyleRange[] styleRanges= coloredString.getStyleRanges();
89
		assertEquals(1, styleRanges.length);
90
		assertEquals(styleRanges[0], STYLE1, str1.length(), str2.length());
91
	}
92
	
93
	public void testAppendString3() {
94
		ColoredString coloredString= new ColoredString();
95
		
96
		String str1= "Hello";
97
		String str2= "You";
98
		coloredString.append(str1, STYLE1);
99
		coloredString.append(str2);
100
		
101
		String res= str1 + str2;
102
		
103
		assertEquals(res.length(), coloredString.length());
104
		assertEquals(res, coloredString.getString());
105
		StyleRange[] styleRanges= coloredString.getStyleRanges();
106
		assertEquals(1, styleRanges.length);
107
		assertEquals(styleRanges[0], STYLE1, 0, str1.length());
108
	}
109
	
110
	public void testAppendString4() {
111
		ColoredString coloredString= new ColoredString();
112
		
113
		String str1= "Hello";
114
		String str2= "You";
115
		coloredString.append(str1);
116
		coloredString.append(str2, STYLE1);
117
		coloredString.append(str2, STYLE1);
118
		
119
		String res= str1 + str2 + str2;
120
		
121
		assertEquals(res.length(), coloredString.length());
122
		assertEquals(res, coloredString.getString());
123
		StyleRange[] styleRanges= coloredString.getStyleRanges();
124
		assertEquals(1, styleRanges.length);
125
		assertEquals(styleRanges[0], STYLE1, str1.length(), str2.length() * 2);
126
	}
127
	
128
	public void testAppendString5() {
129
		ColoredString coloredString= new ColoredString();
130
		
131
		String str1= "Hello";
132
		String str2= "You";
133
		String str3= "Me";
134
		coloredString.append(str1);
135
		coloredString.append(str2, STYLE1);
136
		coloredString.append(str3, STYLE2);
137
		
138
		String res= str1 + str2 + str3;
139
		
140
		assertEquals(res.length(), coloredString.length());
141
		assertEquals(res, coloredString.getString());
142
		StyleRange[] styleRanges= coloredString.getStyleRanges();
143
		assertEquals(2, styleRanges.length);
144
		assertEquals(styleRanges[0], STYLE1, str1.length(), str2.length());
145
		assertEquals(styleRanges[1], STYLE2, str1.length() + str2.length(), str3.length());
146
	}
147
	
148
	public void testAppendString6() {
149
		ColoredString coloredString= new ColoredString();
150
		
151
		String str1= "Hello";
152
		String str2= "You";
153
		String str3= "Me";
154
		coloredString.append(str1, STYLE1);
155
		coloredString.append(str2);
156
		coloredString.append(str3, STYLE2);
157
		
158
		String res= str1 + str2 + str3;
159
		
160
		assertEquals(res.length(), coloredString.length());
161
		assertEquals(res, coloredString.getString());
162
		StyleRange[] styleRanges= coloredString.getStyleRanges();
163
		assertEquals(2, styleRanges.length);
164
		assertEquals(styleRanges[0], STYLE1, 0, str1.length());
165
		assertEquals(styleRanges[1], STYLE2, str1.length() + str2.length(), str3.length());
166
	}
167
	
168
	public void testAppendString7() {
169
		ColoredString coloredString= new ColoredString();
170
		
171
		String str1= "Hello";
172
		String str2= "";
173
		String str3= "Me";
174
		coloredString.append(str1, STYLE1);
175
		coloredString.append(str2, STYLE2);
176
		coloredString.append(str3, STYLE1);
177
		
178
		String res= str1 + str2 + str3;
179
		
180
		assertEquals(res.length(), coloredString.length());
181
		assertEquals(res, coloredString.getString());
182
		StyleRange[] styleRanges= coloredString.getStyleRanges();
183
		assertEquals(1, styleRanges.length);
184
		assertEquals(styleRanges[0], STYLE1, 0, res.length());
185
	}
186
	
187
	public void testAppendChar1() {
188
		ColoredString coloredString= new ColoredString();
189
		
190
		coloredString.append('H', STYLE1);
191
		coloredString.append('2', STYLE2);
192
		coloredString.append('O', STYLE1);
193
		
194
		String res= "H2O";
195
		
196
		assertEquals(res.length(), coloredString.length());
197
		assertEquals(res, coloredString.getString());
198
		StyleRange[] styleRanges= coloredString.getStyleRanges();
199
		assertEquals(3, styleRanges.length);
200
		assertEquals(styleRanges[0], STYLE1, 0, 1);
201
		assertEquals(styleRanges[1], STYLE2, 1, 1);
202
		assertEquals(styleRanges[2], STYLE1, 2, 1);
203
	}
204
	
205
	public void testAppendChar2() {
206
		ColoredString coloredString= new ColoredString();
207
		
208
		coloredString.append('H', STYLE1);
209
		coloredString.append('2');
210
		coloredString.append('O', STYLE2);
211
		
212
		String res= "H2O";
213
		
214
		assertEquals(res.length(), coloredString.length());
215
		assertEquals(res, coloredString.getString());
216
		StyleRange[] styleRanges= coloredString.getStyleRanges();
217
		assertEquals(2, styleRanges.length);
218
		assertEquals(styleRanges[0], STYLE1, 0, 1);
219
		assertEquals(styleRanges[1], STYLE2, 2, 1);
220
	}
221
	
222
	public void testAppendColoredString1() {
223
		ColoredString other= new ColoredString();
224
		
225
		String str2= "You";
226
		String str3= "Me";
227
		other.append(str2, STYLE1);
228
		other.append(str3, STYLE2);
229
		
230
		String str1= "We";
231
		
232
		ColoredString coloredString= new ColoredString(str1);
233
		coloredString.append(other);
234
		
235
		String res= str1 + str2 + str3;
236
		
237
		assertEquals(res.length(), coloredString.length());
238
		assertEquals(res, coloredString.getString());
239
		StyleRange[] styleRanges= coloredString.getStyleRanges();
240
		assertEquals(2, styleRanges.length);
241
		assertEquals(styleRanges[0], STYLE1, str1.length(), str2.length());
242
		assertEquals(styleRanges[1], STYLE2, str1.length() + str2.length(), str3.length());
243
	}
244
	
245
	public void testAppendColoredString2() {
246
		ColoredString other= new ColoredString();
247
		
248
		String str2= "You";
249
		String str3= "Me";
250
		other.append(str2, STYLE1);
251
		other.append(str3, STYLE2);
252
		
253
		String str1= "We";
254
		
255
		ColoredString coloredString= new ColoredString(str1, STYLE1);
256
		coloredString.append(other);
257
		
258
		String res= str1 + str2 + str3;
259
		
260
		assertEquals(res.length(), coloredString.length());
261
		assertEquals(res, coloredString.getString());
262
		StyleRange[] styleRanges= coloredString.getStyleRanges();
263
		assertEquals(2, styleRanges.length);
264
		assertEquals(styleRanges[0], STYLE1, 0, str1.length() + str2.length());
265
		assertEquals(styleRanges[1], STYLE2, str1.length() + str2.length(), str3.length());
266
	}
267
	
268
	public void testAppendColoredString3() {
269
		
270
		ColoredString other= new ColoredString();
271
		
272
		String str2= "You";
273
		String str3= "Me";
274
		other.append(str2);
275
		other.append(str3, STYLE2);
276
		
277
		String str1= "We";
278
		
279
		ColoredString coloredString= new ColoredString(str1, STYLE1);
280
		coloredString.append(other);
281
		
282
		String res= str1 + str2 + str3;
283
		
284
		assertEquals(res.length(), coloredString.length());
285
		assertEquals(res, coloredString.getString());
286
		StyleRange[] styleRanges= coloredString.getStyleRanges();
287
		assertEquals(2, styleRanges.length);
288
		assertEquals(styleRanges[0], STYLE1, 0, str1.length());
289
		assertEquals(styleRanges[1], STYLE2, str1.length() + str2.length(), str3.length());
290
	}
291
	
292
	public void testAppendColoredString4() {
293
		
294
		ColoredString other= new ColoredString();
295
		
296
		String str2= "You";
297
		String str3= "Me";
298
		other.append(str2, STYLE2);
299
		other.append(str3);
300
		
301
		String str1= "We";
302
		
303
		ColoredString coloredString= new ColoredString(str1, STYLE1);
304
		coloredString.append(other);
305
		
306
		String res= str1 + str2 + str3;
307
		
308
		assertEquals(res.length(), coloredString.length());
309
		assertEquals(res, coloredString.getString());
310
		StyleRange[] styleRanges= coloredString.getStyleRanges();
311
		assertEquals(2, styleRanges.length);
312
		assertEquals(styleRanges[0], STYLE1, 0, str1.length());
313
		assertEquals(styleRanges[1], STYLE2, str1.length(), str2.length());
314
	}
315
	
316
	public void testAppendColoredString5() {
317
		ColoredString other= new ColoredString();
318
		
319
		String str2= "You";
320
		String str3= "Me";
321
		other.append(str2);
322
		other.append(str3, STYLE1);
323
		
324
		String str1= "We";
325
		
326
		ColoredString coloredString= new ColoredString(str1);
327
		coloredString.append(other);
328
		
329
		String res= str1 + str2 + str3;
330
		
331
		assertEquals(res.length(), coloredString.length());
332
		assertEquals(res, coloredString.getString());
333
		StyleRange[] styleRanges= coloredString.getStyleRanges();
334
		assertEquals(1, styleRanges.length);
335
		assertEquals(styleRanges[0], STYLE1, str1.length() +  str2.length(), str3.length());
336
	}
337
	
338
	public void testSetStyle1() {
339
		String str1= "One";
340
		String str2= "Two";
341
		String str3= "Three";
342
		
343
		String res= str1 + str2 + str3;
344
		
345
		ColoredString coloredString= new ColoredString();
346
		coloredString.append(res);
347
		
348
		coloredString.setStyle(0, str1.length(), STYLE1);
349
		
350
		assertEquals(res.length(), coloredString.length());
351
		assertEquals(res, coloredString.getString());
352
		StyleRange[] styleRanges= coloredString.getStyleRanges();
353
		assertEquals(1, styleRanges.length);
354
		assertEquals(styleRanges[0], STYLE1, 0, str1.length());
355
	}
356
	
357
	public void testSetStyle2() {
358
		
359
		String str1= "One";
360
		String str2= "Two";
361
		String str3= "Three";
362
		
363
		String res= str1 + str2 + str3;
364
		
365
		ColoredString coloredString= new ColoredString();
366
		coloredString.append(res);
367
		
368
		coloredString.setStyle(str1.length(), str2.length(), STYLE1);
369
		
370
		assertEquals(res.length(), coloredString.length());
371
		assertEquals(res, coloredString.getString());
372
		StyleRange[] styleRanges= coloredString.getStyleRanges();
373
		assertEquals(1, styleRanges.length);
374
		assertEquals(styleRanges[0], STYLE1, str1.length(), str2.length());
375
	}
376
	
377
	public void testSetStyle3() {
378
		
379
		String str1= "One";
380
		String str2= "Two";
381
		String str3= "Three";
382
		
383
		String res= str1 + str2 + str3;
384
		
385
		ColoredString coloredString= new ColoredString();
386
		coloredString.append(res);
387
		
388
		coloredString.setStyle(str1.length(), res.length() - str1.length(), STYLE1);
389
		
390
		assertEquals(res.length(), coloredString.length());
391
		assertEquals(res, coloredString.getString());
392
		StyleRange[] styleRanges= coloredString.getStyleRanges();
393
		assertEquals(1, styleRanges.length);
394
		assertEquals(styleRanges[0], STYLE1, str1.length(), res.length() - str1.length());
395
	}
396
	
397
	public void testSetStyle4() {
398
		
399
		String str1= "One";
400
		String str2= "Two";
401
		String str3= "Three";
402
		
403
		String res= str1 + str2 + str3;
404
		
405
		ColoredString coloredString= new ColoredString();
406
		coloredString.append(res);
407
		
408
		coloredString.setStyle(0, res.length(), STYLE1);
409
		
410
		assertEquals(res.length(), coloredString.length());
411
		assertEquals(res, coloredString.getString());
412
		StyleRange[] styleRanges= coloredString.getStyleRanges();
413
		assertEquals(1, styleRanges.length);
414
		assertEquals(styleRanges[0], STYLE1, 0, res.length());
415
	}
416
	
417
	public void testSetStyle5() {
418
		
419
		String str1= "One";
420
		String str2= "Two";
421
		String str3= "Three";
422
		
423
		String res= str1 + str2 + str3;
424
		
425
		ColoredString coloredString= new ColoredString();
426
		coloredString.append(res);
427
		
428
		coloredString.setStyle(0, res.length(), null);
429
		
430
		assertEquals(res.length(), coloredString.length());
431
		assertEquals(res, coloredString.getString());
432
		StyleRange[] styleRanges= coloredString.getStyleRanges();
433
		assertEquals(0, styleRanges.length);
434
	}
435
	
436
	public void testSetStyle6() {
437
		
438
		String str1= "One";
439
		String str2= "Two";
440
		
441
		String res= str1 + str2;
442
		
443
		ColoredString coloredString= new ColoredString(str1, STYLE1);
444
		coloredString.append(str2);
445
		
446
		coloredString.setStyle(str1.length(), str2.length(), STYLE2);
447
		
448
		assertEquals(res.length(), coloredString.length());
449
		assertEquals(res, coloredString.getString());
450
		StyleRange[] styleRanges= coloredString.getStyleRanges();
451
		assertEquals(2, styleRanges.length);
452
		assertEquals(styleRanges[0], STYLE1, 0, str1.length());
453
		assertEquals(styleRanges[1], STYLE2, str1.length(), str2.length());
454
	}
455
	
456
	public void testSetStyle7() {
457
		
458
		String str1= "One";
459
		String str2= "Two";
460
		
461
		String res= str1 + str2;
462
		
463
		ColoredString coloredString= new ColoredString(str1);
464
		coloredString.append(str2, STYLE1);
465
		
466
		coloredString.setStyle(0, str1.length(), STYLE2);
467
		
468
		assertEquals(res.length(), coloredString.length());
469
		assertEquals(res, coloredString.getString());
470
		StyleRange[] styleRanges= coloredString.getStyleRanges();
471
		assertEquals(2, styleRanges.length);
472
		assertEquals(styleRanges[0], STYLE2, 0, str1.length());
473
		assertEquals(styleRanges[1], STYLE1, str1.length(), str2.length());
474
	}
475
	
476
	public void testSetStyle8() {
477
		
478
		String str1= "One";
479
		String str2= "Two";
480
		
481
		String res= str1 + str2;
482
		
483
		ColoredString coloredString= new ColoredString();
484
		coloredString.append(str1, STYLE1);
485
		coloredString.append(str2, STYLE2);
486
		
487
		coloredString.setStyle(0, str1.length(), STYLE2);
488
		
489
		assertEquals(res.length(), coloredString.length());
490
		assertEquals(res, coloredString.getString());
491
		StyleRange[] styleRanges= coloredString.getStyleRanges();
492
		assertEquals(1, styleRanges.length);
493
		assertEquals(styleRanges[0], STYLE2, 0, res.length());
494
	}
495
	
496
	public void testSetStyle9() {
497
		
498
		String str1= "One";
499
		String str2= "Two";
500
		
501
		String res= str1 + str2;
502
		
503
		ColoredString coloredString= new ColoredString();
504
		coloredString.append(str1, STYLE1);
505
		coloredString.append(str2, STYLE2);
506
		
507
		coloredString.setStyle(0, res.length(), null);
508
		
509
		assertEquals(res.length(), coloredString.length());
510
		assertEquals(res, coloredString.getString());
511
		StyleRange[] styleRanges= coloredString.getStyleRanges();
512
		assertEquals(0, styleRanges.length);
513
	}
514
	
515
	public void testSetStyle10() {
516
		
517
		String str1= "One";
518
		String str2= "Two";
519
		
520
		String res= str1 + str2;
521
		
522
		ColoredString coloredString= new ColoredString();
523
		coloredString.append(str1, STYLE1);
524
		coloredString.append(str2, STYLE2);
525
		
526
		coloredString.setStyle(1, res.length() - 2, null);
527
		
528
		assertEquals(res.length(), coloredString.length());
529
		assertEquals(res, coloredString.getString());
530
		StyleRange[] styleRanges= coloredString.getStyleRanges();
531
		assertEquals(2, styleRanges.length);
532
		
533
		assertEquals(styleRanges[0], STYLE1, 0, 1);
534
		assertEquals(styleRanges[1], STYLE2, res.length() - 1, 1);
535
	}
536
	
537
	public void testSetStyle11() {
538
		
539
		String str1= "One";
540
		String str2= "Two";
541
		
542
		String res= str1 + str2;
543
		
544
		ColoredString coloredString= new ColoredString();
545
		coloredString.append(str1, STYLE1);
546
		coloredString.append(str2, STYLE2);
547
		
548
		coloredString.setStyle(1, res.length() - 1, STYLE1);
549
		
550
		assertEquals(res.length(), coloredString.length());
551
		assertEquals(res, coloredString.getString());
552
		StyleRange[] styleRanges= coloredString.getStyleRanges();
553
		assertEquals(1, styleRanges.length);
554
		
555
		assertEquals(styleRanges[0], STYLE1, 0, res.length());
556
	}
557
	
558
	public void testSetStyle12() {
559
		
560
		String str1= "One";
561
		String str2= "Two";
562
		
563
		String res= str1 + str2;
564
		
565
		ColoredString coloredString= new ColoredString();
566
		coloredString.append(str1, STYLE1);
567
		coloredString.append(str2, STYLE2);
568
		
569
		coloredString.setStyle(0, res.length() - 1, STYLE2);
570
		
571
		assertEquals(res.length(), coloredString.length());
572
		assertEquals(res, coloredString.getString());
573
		StyleRange[] styleRanges= coloredString.getStyleRanges();
574
		assertEquals(1, styleRanges.length);
575
		
576
		assertEquals(styleRanges[0], STYLE2, 0, res.length());
577
	}
578
	
579
	public void testSetStyle13() {
580
		
581
		String str1= "One";
582
		String str2= "Two";
583
		
584
		String res= str1 + str2;
585
		
586
		ColoredString coloredString= new ColoredString();
587
		coloredString.append(str1, STYLE1);
588
		coloredString.append(str2, STYLE2);
589
		
590
		coloredString.setStyle(1, res.length() - 2, STYLE1);
591
		
592
		assertEquals(res.length(), coloredString.length());
593
		assertEquals(res, coloredString.getString());
594
		StyleRange[] styleRanges= coloredString.getStyleRanges();
595
		assertEquals(2, styleRanges.length);
596
		
597
		assertEquals(styleRanges[0], STYLE1, 0, res.length() - 1);
598
		assertEquals(styleRanges[1], STYLE2, res.length() - 1, 1);
599
	}
600
	
601
	public void testSetStyle14() {
602
		
603
		String str1= "One";
604
		String str2= "Two";
605
		
606
		String res= str1 + str2;
607
		
608
		ColoredString coloredString= new ColoredString();
609
		coloredString.append(str1, STYLE1);
610
		coloredString.append(str2, STYLE2);
611
		
612
		coloredString.setStyle(1, res.length() - 2, STYLE2);
613
		
614
		assertEquals(res.length(), coloredString.length());
615
		assertEquals(res, coloredString.getString());
616
		StyleRange[] styleRanges= coloredString.getStyleRanges();
617
		assertEquals(2, styleRanges.length);
618
		
619
		assertEquals(styleRanges[0], STYLE1, 0, 1);
620
		assertEquals(styleRanges[1], STYLE2, 1, res.length() - 1);
621
	}
622
	
623
	public void testSetStyle15() {
624
		
625
		String str1= "One";
626
		String str2= "Two";
627
		
628
		String res= str1 + str2;
629
		
630
		ColoredString coloredString= new ColoredString();
631
		coloredString.append(str1, null);
632
		coloredString.append(str2, STYLE2);
633
		
634
		coloredString.setStyle(0, 1, STYLE1);
635
		
636
		assertEquals(res.length(), coloredString.length());
637
		assertEquals(res, coloredString.getString());
638
		StyleRange[] styleRanges= coloredString.getStyleRanges();
639
		assertEquals(2, styleRanges.length);
640
		
641
		assertEquals(styleRanges[0], STYLE1, 0, 1);
642
		assertEquals(styleRanges[1], STYLE2, str1.length(), str2.length());
643
	}
644
	
645
	public void testSetStyle16() {
646
				
647
		String res= "H2O";
648
		
649
		ColoredString coloredString= new ColoredString();
650
		coloredString.append('H', null);
651
		coloredString.append('2', STYLE1);
652
		coloredString.append('O', STYLE2);
653
		
654
		coloredString.setStyle(0, res.length(), STYLE1);
655
		
656
		assertEquals(res.length(), coloredString.length());
657
		assertEquals(res, coloredString.getString());
658
		StyleRange[] styleRanges= coloredString.getStyleRanges();
659
		assertEquals(1, styleRanges.length);
660
		
661
		assertEquals(styleRanges[0], STYLE1, 0, res.length());
662
	}
663
	
664
	public void testSetStyle17() {
665
		
666
		String res= "H2O";
667
		
668
		ColoredString coloredString= new ColoredString();
669
		coloredString.append('H', null);
670
		coloredString.append('2', STYLE1);
671
		coloredString.append('O', STYLE2);
672
		
673
		coloredString.setStyle(0, res.length(), null);
674
		
675
		assertEquals(res.length(), coloredString.length());
676
		assertEquals(res, coloredString.getString());
677
		StyleRange[] styleRanges= coloredString.getStyleRanges();
678
		assertEquals(0, styleRanges.length);
679
	}
680
	
681
	public void testSetStyle18() {
682
		String res= "H2OH2O";
683
		
684
		ColoredString coloredString= new ColoredString();
685
		coloredString.append('H', null);
686
		coloredString.append('2', STYLE1);
687
		coloredString.append('O', STYLE2);
688
		coloredString.append('H', null);
689
		coloredString.append('2', STYLE2);
690
		coloredString.append('O', STYLE1);
691
		
692
		coloredString.setStyle(1, res.length() - 2, STYLE1);
693
		
694
		assertEquals(res.length(), coloredString.length());
695
		assertEquals(res, coloredString.getString());
696
		StyleRange[] styleRanges= coloredString.getStyleRanges();
697
		assertEquals(1, styleRanges.length);
698
		
699
		assertEquals(styleRanges[0], STYLE1, 1, res.length() - 1);
700
	}
701
	
702
	public void testSetStyle19() {
703
		String res= "O2O2O2O2O2O2";
704
		
705
		ColoredString coloredString= new ColoredString();
706
		coloredString.append("O2", null);
707
		coloredString.append("O2", STYLE1);
708
		coloredString.append("O2", STYLE2);
709
		coloredString.append("O2", STYLE1);
710
		coloredString.append("O2", STYLE2);
711
		coloredString.append("O2", null);
712
		
713
		coloredString.setStyle(1, res.length() - 2, STYLE1);
714
		
715
		assertEquals(res.length(), coloredString.length());
716
		assertEquals(res, coloredString.getString());
717
		StyleRange[] styleRanges= coloredString.getStyleRanges();
718
		assertEquals(1, styleRanges.length);
719
		
720
		assertEquals(styleRanges[0], STYLE1, 1, res.length() - 2);
721
	}
722
	
723
	public void testSetStyle20() {
724
		String res= "O2O2O2O2O2O2";
725
		
726
		ColoredString coloredString= new ColoredString();
727
		coloredString.append("O2", null);
728
		coloredString.append("O2", STYLE1);
729
		coloredString.append("O2", STYLE2);
730
		coloredString.append("O2", STYLE1);
731
		coloredString.append("O2", STYLE2);
732
		coloredString.append("O2", null);
733
		
734
		coloredString.setStyle(3, 6, null);
735
		
736
		assertEquals(res.length(), coloredString.length());
737
		assertEquals(res, coloredString.getString());
738
		StyleRange[] styleRanges= coloredString.getStyleRanges();
739
		assertEquals(2, styleRanges.length);
740
		
741
		assertEquals(styleRanges[0], STYLE1, 2, 1);
742
		assertEquals(styleRanges[1], STYLE2, 9, 1);
743
	}
744
	
745
	public void testSetStyle21() {
746
		String res= "O2O2O2O2O2O2";
747
		
748
		ColoredString coloredString= new ColoredString();
749
		coloredString.append("O2", null);
750
		coloredString.append("O2", STYLE1);
751
		coloredString.append("O2", STYLE2);
752
		coloredString.append("O2", STYLE1);
753
		coloredString.append("O2", STYLE2);
754
		coloredString.append("O2", null);
755
		
756
		coloredString.setStyle(3, 6, STYLE1);
757
		coloredString.setStyle(3, 6, null);
758
		
759
		assertEquals(res.length(), coloredString.length());
760
		assertEquals(res, coloredString.getString());
761
		StyleRange[] styleRanges= coloredString.getStyleRanges();
762
		assertEquals(2, styleRanges.length);
763
		
764
		assertEquals(styleRanges[0], STYLE1, 2, 1);
765
		assertEquals(styleRanges[1], STYLE2, 9, 1);
766
	}
767
	
768
	public void testCombination1() {
769
		String str1= "One";
770
		String str2= "Two";
771
		
772
		String res= str1 + str2 + str1;
773
		
774
		ColoredString coloredString= new ColoredString();
775
		coloredString.append(str1, null);
776
		coloredString.append(str2, STYLE2);
777
		
778
		coloredString.setStyle(str1.length(), str2.length(), STYLE1);
779
		
780
		coloredString.append(str1, STYLE1);
781
		
782
		assertEquals(res.length(), coloredString.length());
783
		assertEquals(res, coloredString.getString());
784
		StyleRange[] styleRanges= coloredString.getStyleRanges();
785
		assertEquals(1, styleRanges.length);
786
		
787
		assertEquals(styleRanges[0], STYLE1, str1.length(), str2.length() + str1.length());
788
	}
789
	
790
	
791
	private void assertEquals(StyleRange range, TestStyle style, int offset, int length) {
792
		assertEquals(offset, range.start);
793
		assertEquals(length, range.length);
794
		assertEquals(style.borderStyle, range.borderStyle);
795
	}
796
	
797
	
798
}
(-)ui/org/eclipse/jdt/ui/tests/core/StyledStringTest.java (+798 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.ui.tests.core;
12
13
import junit.framework.Test;
14
import junit.framework.TestCase;
15
import junit.framework.TestSuite;
16
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.custom.StyleRange;
19
import org.eclipse.swt.graphics.TextStyle;
20
21
import org.eclipse.jface.viewers.StyledString;
22
import org.eclipse.jface.viewers.StyledString.Style;
23
24
public class StyledStringTest extends TestCase {
25
	
26
	public static class TestStyle extends Style {
27
		
28
		public final int borderStyle;
29
30
		public TestStyle(int borderStyle) {
31
			this.borderStyle= borderStyle;
32
		}
33
		
34
		public void applyStyles(TextStyle textStyle) {
35
			textStyle.borderStyle= borderStyle;
36
		}
37
	}
38
	
39
	public static final TestStyle STYLE1= new TestStyle(SWT.BORDER_DOT);
40
	public static final TestStyle STYLE2= new TestStyle(SWT.BORDER_DASH);
41
	
42
	
43
	public static Test allTests() {
44
		return new TestSuite(StyledStringTest.class);
45
	}
46
47
	public static Test suite() {
48
		return allTests();
49
	}
50
	
51
	public void testEmpty() {
52
		StyledString StyledString= new StyledString();
53
		
54
		String str= "";
55
		
56
		assertEquals(str.length(), StyledString.length());
57
		assertEquals(str, StyledString.getString());
58
		assertEquals(StyledString.getStyleRanges().length, 0);
59
	}
60
	
61
	public void testAppendString1() {
62
		StyledString StyledString= new StyledString();
63
		
64
		String str= "Hello";
65
		
66
		StyledString.append(str, STYLE1);
67
		
68
		assertEquals(str.length(), StyledString.length());
69
		assertEquals(str, StyledString.getString());
70
		StyleRange[] styleRanges= StyledString.getStyleRanges();
71
		assertEquals(1, styleRanges.length);
72
		
73
		assertEquals(styleRanges[0], STYLE1, 0, str.length());
74
	}
75
	
76
	public void testAppendString2() {
77
		StyledString StyledString= new StyledString();
78
		
79
		String str1= "Hello";
80
		String str2= "You";
81
		StyledString.append(str1);
82
		StyledString.append(str2, STYLE1);
83
		
84
		String res= str1 + str2;
85
		
86
		assertEquals(res.length(), StyledString.length());
87
		assertEquals(res, StyledString.getString());
88
		StyleRange[] styleRanges= StyledString.getStyleRanges();
89
		assertEquals(1, styleRanges.length);
90
		assertEquals(styleRanges[0], STYLE1, str1.length(), str2.length());
91
	}
92
	
93
	public void testAppendString3() {
94
		StyledString StyledString= new StyledString();
95
		
96
		String str1= "Hello";
97
		String str2= "You";
98
		StyledString.append(str1, STYLE1);
99
		StyledString.append(str2);
100
		
101
		String res= str1 + str2;
102
		
103
		assertEquals(res.length(), StyledString.length());
104
		assertEquals(res, StyledString.getString());
105
		StyleRange[] styleRanges= StyledString.getStyleRanges();
106
		assertEquals(1, styleRanges.length);
107
		assertEquals(styleRanges[0], STYLE1, 0, str1.length());
108
	}
109
	
110
	public void testAppendString4() {
111
		StyledString StyledString= new StyledString();
112
		
113
		String str1= "Hello";
114
		String str2= "You";
115
		StyledString.append(str1);
116
		StyledString.append(str2, STYLE1);
117
		StyledString.append(str2, STYLE1);
118
		
119
		String res= str1 + str2 + str2;
120
		
121
		assertEquals(res.length(), StyledString.length());
122
		assertEquals(res, StyledString.getString());
123
		StyleRange[] styleRanges= StyledString.getStyleRanges();
124
		assertEquals(1, styleRanges.length);
125
		assertEquals(styleRanges[0], STYLE1, str1.length(), str2.length() * 2);
126
	}
127
	
128
	public void testAppendString5() {
129
		StyledString StyledString= new StyledString();
130
		
131
		String str1= "Hello";
132
		String str2= "You";
133
		String str3= "Me";
134
		StyledString.append(str1);
135
		StyledString.append(str2, STYLE1);
136
		StyledString.append(str3, STYLE2);
137
		
138
		String res= str1 + str2 + str3;
139
		
140
		assertEquals(res.length(), StyledString.length());
141
		assertEquals(res, StyledString.getString());
142
		StyleRange[] styleRanges= StyledString.getStyleRanges();
143
		assertEquals(2, styleRanges.length);
144
		assertEquals(styleRanges[0], STYLE1, str1.length(), str2.length());
145
		assertEquals(styleRanges[1], STYLE2, str1.length() + str2.length(), str3.length());
146
	}
147
	
148
	public void testAppendString6() {
149
		StyledString StyledString= new StyledString();
150
		
151
		String str1= "Hello";
152
		String str2= "You";
153
		String str3= "Me";
154
		StyledString.append(str1, STYLE1);
155
		StyledString.append(str2);
156
		StyledString.append(str3, STYLE2);
157
		
158
		String res= str1 + str2 + str3;
159
		
160
		assertEquals(res.length(), StyledString.length());
161
		assertEquals(res, StyledString.getString());
162
		StyleRange[] styleRanges= StyledString.getStyleRanges();
163
		assertEquals(2, styleRanges.length);
164
		assertEquals(styleRanges[0], STYLE1, 0, str1.length());
165
		assertEquals(styleRanges[1], STYLE2, str1.length() + str2.length(), str3.length());
166
	}
167
	
168
	public void testAppendString7() {
169
		StyledString StyledString= new StyledString();
170
		
171
		String str1= "Hello";
172
		String str2= "";
173
		String str3= "Me";
174
		StyledString.append(str1, STYLE1);
175
		StyledString.append(str2, STYLE2);
176
		StyledString.append(str3, STYLE1);
177
		
178
		String res= str1 + str2 + str3;
179
		
180
		assertEquals(res.length(), StyledString.length());
181
		assertEquals(res, StyledString.getString());
182
		StyleRange[] styleRanges= StyledString.getStyleRanges();
183
		assertEquals(1, styleRanges.length);
184
		assertEquals(styleRanges[0], STYLE1, 0, res.length());
185
	}
186
	
187
	public void testAppendChar1() {
188
		StyledString StyledString= new StyledString();
189
		
190
		StyledString.append('H', STYLE1);
191
		StyledString.append('2', STYLE2);
192
		StyledString.append('O', STYLE1);
193
		
194
		String res= "H2O";
195
		
196
		assertEquals(res.length(), StyledString.length());
197
		assertEquals(res, StyledString.getString());
198
		StyleRange[] styleRanges= StyledString.getStyleRanges();
199
		assertEquals(3, styleRanges.length);
200
		assertEquals(styleRanges[0], STYLE1, 0, 1);
201
		assertEquals(styleRanges[1], STYLE2, 1, 1);
202
		assertEquals(styleRanges[2], STYLE1, 2, 1);
203
	}
204
	
205
	public void testAppendChar2() {
206
		StyledString StyledString= new StyledString();
207
		
208
		StyledString.append('H', STYLE1);
209
		StyledString.append('2');
210
		StyledString.append('O', STYLE2);
211
		
212
		String res= "H2O";
213
		
214
		assertEquals(res.length(), StyledString.length());
215
		assertEquals(res, StyledString.getString());
216
		StyleRange[] styleRanges= StyledString.getStyleRanges();
217
		assertEquals(2, styleRanges.length);
218
		assertEquals(styleRanges[0], STYLE1, 0, 1);
219
		assertEquals(styleRanges[1], STYLE2, 2, 1);
220
	}
221
	
222
	public void testAppendStyledString1() {
223
		StyledString other= new StyledString();
224
		
225
		String str2= "You";
226
		String str3= "Me";
227
		other.append(str2, STYLE1);
228
		other.append(str3, STYLE2);
229
		
230
		String str1= "We";
231
		
232
		StyledString StyledString= new StyledString(str1);
233
		StyledString.append(other);
234
		
235
		String res= str1 + str2 + str3;
236
		
237
		assertEquals(res.length(), StyledString.length());
238
		assertEquals(res, StyledString.getString());
239
		StyleRange[] styleRanges= StyledString.getStyleRanges();
240
		assertEquals(2, styleRanges.length);
241
		assertEquals(styleRanges[0], STYLE1, str1.length(), str2.length());
242
		assertEquals(styleRanges[1], STYLE2, str1.length() + str2.length(), str3.length());
243
	}
244
	
245
	public void testAppendStyledString2() {
246
		StyledString other= new StyledString();
247
		
248
		String str2= "You";
249
		String str3= "Me";
250
		other.append(str2, STYLE1);
251
		other.append(str3, STYLE2);
252
		
253
		String str1= "We";
254
		
255
		StyledString StyledString= new StyledString(str1, STYLE1);
256
		StyledString.append(other);
257
		
258
		String res= str1 + str2 + str3;
259
		
260
		assertEquals(res.length(), StyledString.length());
261
		assertEquals(res, StyledString.getString());
262
		StyleRange[] styleRanges= StyledString.getStyleRanges();
263
		assertEquals(2, styleRanges.length);
264
		assertEquals(styleRanges[0], STYLE1, 0, str1.length() + str2.length());
265
		assertEquals(styleRanges[1], STYLE2, str1.length() + str2.length(), str3.length());
266
	}
267
	
268
	public void testAppendStyledString3() {
269
		
270
		StyledString other= new StyledString();
271
		
272
		String str2= "You";
273
		String str3= "Me";
274
		other.append(str2);
275
		other.append(str3, STYLE2);
276
		
277
		String str1= "We";
278
		
279
		StyledString StyledString= new StyledString(str1, STYLE1);
280
		StyledString.append(other);
281
		
282
		String res= str1 + str2 + str3;
283
		
284
		assertEquals(res.length(), StyledString.length());
285
		assertEquals(res, StyledString.getString());
286
		StyleRange[] styleRanges= StyledString.getStyleRanges();
287
		assertEquals(2, styleRanges.length);
288
		assertEquals(styleRanges[0], STYLE1, 0, str1.length());
289
		assertEquals(styleRanges[1], STYLE2, str1.length() + str2.length(), str3.length());
290
	}
291
	
292
	public void testAppendStyledString4() {
293
		
294
		StyledString other= new StyledString();
295
		
296
		String str2= "You";
297
		String str3= "Me";
298
		other.append(str2, STYLE2);
299
		other.append(str3);
300
		
301
		String str1= "We";
302
		
303
		StyledString StyledString= new StyledString(str1, STYLE1);
304
		StyledString.append(other);
305
		
306
		String res= str1 + str2 + str3;
307
		
308
		assertEquals(res.length(), StyledString.length());
309
		assertEquals(res, StyledString.getString());
310
		StyleRange[] styleRanges= StyledString.getStyleRanges();
311
		assertEquals(2, styleRanges.length);
312
		assertEquals(styleRanges[0], STYLE1, 0, str1.length());
313
		assertEquals(styleRanges[1], STYLE2, str1.length(), str2.length());
314
	}
315
	
316
	public void testAppendStyledString5() {
317
		StyledString other= new StyledString();
318
		
319
		String str2= "You";
320
		String str3= "Me";
321
		other.append(str2);
322
		other.append(str3, STYLE1);
323
		
324
		String str1= "We";
325
		
326
		StyledString StyledString= new StyledString(str1);
327
		StyledString.append(other);
328
		
329
		String res= str1 + str2 + str3;
330
		
331
		assertEquals(res.length(), StyledString.length());
332
		assertEquals(res, StyledString.getString());
333
		StyleRange[] styleRanges= StyledString.getStyleRanges();
334
		assertEquals(1, styleRanges.length);
335
		assertEquals(styleRanges[0], STYLE1, str1.length() +  str2.length(), str3.length());
336
	}
337
	
338
	public void testSetStyle1() {
339
		String str1= "One";
340
		String str2= "Two";
341
		String str3= "Three";
342
		
343
		String res= str1 + str2 + str3;
344
		
345
		StyledString StyledString= new StyledString();
346
		StyledString.append(res);
347
		
348
		StyledString.setStyle(0, str1.length(), STYLE1);
349
		
350
		assertEquals(res.length(), StyledString.length());
351
		assertEquals(res, StyledString.getString());
352
		StyleRange[] styleRanges= StyledString.getStyleRanges();
353
		assertEquals(1, styleRanges.length);
354
		assertEquals(styleRanges[0], STYLE1, 0, str1.length());
355
	}
356
	
357
	public void testSetStyle2() {
358
		
359
		String str1= "One";
360
		String str2= "Two";
361
		String str3= "Three";
362
		
363
		String res= str1 + str2 + str3;
364
		
365
		StyledString StyledString= new StyledString();
366
		StyledString.append(res);
367
		
368
		StyledString.setStyle(str1.length(), str2.length(), STYLE1);
369
		
370
		assertEquals(res.length(), StyledString.length());
371
		assertEquals(res, StyledString.getString());
372
		StyleRange[] styleRanges= StyledString.getStyleRanges();
373
		assertEquals(1, styleRanges.length);
374
		assertEquals(styleRanges[0], STYLE1, str1.length(), str2.length());
375
	}
376
	
377
	public void testSetStyle3() {
378
		
379
		String str1= "One";
380
		String str2= "Two";
381
		String str3= "Three";
382
		
383
		String res= str1 + str2 + str3;
384
		
385
		StyledString StyledString= new StyledString();
386
		StyledString.append(res);
387
		
388
		StyledString.setStyle(str1.length(), res.length() - str1.length(), STYLE1);
389
		
390
		assertEquals(res.length(), StyledString.length());
391
		assertEquals(res, StyledString.getString());
392
		StyleRange[] styleRanges= StyledString.getStyleRanges();
393
		assertEquals(1, styleRanges.length);
394
		assertEquals(styleRanges[0], STYLE1, str1.length(), res.length() - str1.length());
395
	}
396
	
397
	public void testSetStyle4() {
398
		
399
		String str1= "One";
400
		String str2= "Two";
401
		String str3= "Three";
402
		
403
		String res= str1 + str2 + str3;
404
		
405
		StyledString StyledString= new StyledString();
406
		StyledString.append(res);
407
		
408
		StyledString.setStyle(0, res.length(), STYLE1);
409
		
410
		assertEquals(res.length(), StyledString.length());
411
		assertEquals(res, StyledString.getString());
412
		StyleRange[] styleRanges= StyledString.getStyleRanges();
413
		assertEquals(1, styleRanges.length);
414
		assertEquals(styleRanges[0], STYLE1, 0, res.length());
415
	}
416
	
417
	public void testSetStyle5() {
418
		
419
		String str1= "One";
420
		String str2= "Two";
421
		String str3= "Three";
422
		
423
		String res= str1 + str2 + str3;
424
		
425
		StyledString StyledString= new StyledString();
426
		StyledString.append(res);
427
		
428
		StyledString.setStyle(0, res.length(), null);
429
		
430
		assertEquals(res.length(), StyledString.length());
431
		assertEquals(res, StyledString.getString());
432
		StyleRange[] styleRanges= StyledString.getStyleRanges();
433
		assertEquals(0, styleRanges.length);
434
	}
435
	
436
	public void testSetStyle6() {
437
		
438
		String str1= "One";
439
		String str2= "Two";
440
		
441
		String res= str1 + str2;
442
		
443
		StyledString StyledString= new StyledString(str1, STYLE1);
444
		StyledString.append(str2);
445
		
446
		StyledString.setStyle(str1.length(), str2.length(), STYLE2);
447
		
448
		assertEquals(res.length(), StyledString.length());
449
		assertEquals(res, StyledString.getString());
450
		StyleRange[] styleRanges= StyledString.getStyleRanges();
451
		assertEquals(2, styleRanges.length);
452
		assertEquals(styleRanges[0], STYLE1, 0, str1.length());
453
		assertEquals(styleRanges[1], STYLE2, str1.length(), str2.length());
454
	}
455
	
456
	public void testSetStyle7() {
457
		
458
		String str1= "One";
459
		String str2= "Two";
460
		
461
		String res= str1 + str2;
462
		
463
		StyledString StyledString= new StyledString(str1);
464
		StyledString.append(str2, STYLE1);
465
		
466
		StyledString.setStyle(0, str1.length(), STYLE2);
467
		
468
		assertEquals(res.length(), StyledString.length());
469
		assertEquals(res, StyledString.getString());
470
		StyleRange[] styleRanges= StyledString.getStyleRanges();
471
		assertEquals(2, styleRanges.length);
472
		assertEquals(styleRanges[0], STYLE2, 0, str1.length());
473
		assertEquals(styleRanges[1], STYLE1, str1.length(), str2.length());
474
	}
475
	
476
	public void testSetStyle8() {
477
		
478
		String str1= "One";
479
		String str2= "Two";
480
		
481
		String res= str1 + str2;
482
		
483
		StyledString StyledString= new StyledString();
484
		StyledString.append(str1, STYLE1);
485
		StyledString.append(str2, STYLE2);
486
		
487
		StyledString.setStyle(0, str1.length(), STYLE2);
488
		
489
		assertEquals(res.length(), StyledString.length());
490
		assertEquals(res, StyledString.getString());
491
		StyleRange[] styleRanges= StyledString.getStyleRanges();
492
		assertEquals(1, styleRanges.length);
493
		assertEquals(styleRanges[0], STYLE2, 0, res.length());
494
	}
495
	
496
	public void testSetStyle9() {
497
		
498
		String str1= "One";
499
		String str2= "Two";
500
		
501
		String res= str1 + str2;
502
		
503
		StyledString StyledString= new StyledString();
504
		StyledString.append(str1, STYLE1);
505
		StyledString.append(str2, STYLE2);
506
		
507
		StyledString.setStyle(0, res.length(), null);
508
		
509
		assertEquals(res.length(), StyledString.length());
510
		assertEquals(res, StyledString.getString());
511
		StyleRange[] styleRanges= StyledString.getStyleRanges();
512
		assertEquals(0, styleRanges.length);
513
	}
514
	
515
	public void testSetStyle10() {
516
		
517
		String str1= "One";
518
		String str2= "Two";
519
		
520
		String res= str1 + str2;
521
		
522
		StyledString StyledString= new StyledString();
523
		StyledString.append(str1, STYLE1);
524
		StyledString.append(str2, STYLE2);
525
		
526
		StyledString.setStyle(1, res.length() - 2, null);
527
		
528
		assertEquals(res.length(), StyledString.length());
529
		assertEquals(res, StyledString.getString());
530
		StyleRange[] styleRanges= StyledString.getStyleRanges();
531
		assertEquals(2, styleRanges.length);
532
		
533
		assertEquals(styleRanges[0], STYLE1, 0, 1);
534
		assertEquals(styleRanges[1], STYLE2, res.length() - 1, 1);
535
	}
536
	
537
	public void testSetStyle11() {
538
		
539
		String str1= "One";
540
		String str2= "Two";
541
		
542
		String res= str1 + str2;
543
		
544
		StyledString StyledString= new StyledString();
545
		StyledString.append(str1, STYLE1);
546
		StyledString.append(str2, STYLE2);
547
		
548
		StyledString.setStyle(1, res.length() - 1, STYLE1);
549
		
550
		assertEquals(res.length(), StyledString.length());
551
		assertEquals(res, StyledString.getString());
552
		StyleRange[] styleRanges= StyledString.getStyleRanges();
553
		assertEquals(1, styleRanges.length);
554
		
555
		assertEquals(styleRanges[0], STYLE1, 0, res.length());
556
	}
557
	
558
	public void testSetStyle12() {
559
		
560
		String str1= "One";
561
		String str2= "Two";
562
		
563
		String res= str1 + str2;
564
		
565
		StyledString StyledString= new StyledString();
566
		StyledString.append(str1, STYLE1);
567
		StyledString.append(str2, STYLE2);
568
		
569
		StyledString.setStyle(0, res.length() - 1, STYLE2);
570
		
571
		assertEquals(res.length(), StyledString.length());
572
		assertEquals(res, StyledString.getString());
573
		StyleRange[] styleRanges= StyledString.getStyleRanges();
574
		assertEquals(1, styleRanges.length);
575
		
576
		assertEquals(styleRanges[0], STYLE2, 0, res.length());
577
	}
578
	
579
	public void testSetStyle13() {
580
		
581
		String str1= "One";
582
		String str2= "Two";
583
		
584
		String res= str1 + str2;
585
		
586
		StyledString StyledString= new StyledString();
587
		StyledString.append(str1, STYLE1);
588
		StyledString.append(str2, STYLE2);
589
		
590
		StyledString.setStyle(1, res.length() - 2, STYLE1);
591
		
592
		assertEquals(res.length(), StyledString.length());
593
		assertEquals(res, StyledString.getString());
594
		StyleRange[] styleRanges= StyledString.getStyleRanges();
595
		assertEquals(2, styleRanges.length);
596
		
597
		assertEquals(styleRanges[0], STYLE1, 0, res.length() - 1);
598
		assertEquals(styleRanges[1], STYLE2, res.length() - 1, 1);
599
	}
600
	
601
	public void testSetStyle14() {
602
		
603
		String str1= "One";
604
		String str2= "Two";
605
		
606
		String res= str1 + str2;
607
		
608
		StyledString StyledString= new StyledString();
609
		StyledString.append(str1, STYLE1);
610
		StyledString.append(str2, STYLE2);
611
		
612
		StyledString.setStyle(1, res.length() - 2, STYLE2);
613
		
614
		assertEquals(res.length(), StyledString.length());
615
		assertEquals(res, StyledString.getString());
616
		StyleRange[] styleRanges= StyledString.getStyleRanges();
617
		assertEquals(2, styleRanges.length);
618
		
619
		assertEquals(styleRanges[0], STYLE1, 0, 1);
620
		assertEquals(styleRanges[1], STYLE2, 1, res.length() - 1);
621
	}
622
	
623
	public void testSetStyle15() {
624
		
625
		String str1= "One";
626
		String str2= "Two";
627
		
628
		String res= str1 + str2;
629
		
630
		StyledString StyledString= new StyledString();
631
		StyledString.append(str1, null);
632
		StyledString.append(str2, STYLE2);
633
		
634
		StyledString.setStyle(0, 1, STYLE1);
635
		
636
		assertEquals(res.length(), StyledString.length());
637
		assertEquals(res, StyledString.getString());
638
		StyleRange[] styleRanges= StyledString.getStyleRanges();
639
		assertEquals(2, styleRanges.length);
640
		
641
		assertEquals(styleRanges[0], STYLE1, 0, 1);
642
		assertEquals(styleRanges[1], STYLE2, str1.length(), str2.length());
643
	}
644
	
645
	public void testSetStyle16() {
646
				
647
		String res= "H2O";
648
		
649
		StyledString StyledString= new StyledString();
650
		StyledString.append('H', null);
651
		StyledString.append('2', STYLE1);
652
		StyledString.append('O', STYLE2);
653
		
654
		StyledString.setStyle(0, res.length(), STYLE1);
655
		
656
		assertEquals(res.length(), StyledString.length());
657
		assertEquals(res, StyledString.getString());
658
		StyleRange[] styleRanges= StyledString.getStyleRanges();
659
		assertEquals(1, styleRanges.length);
660
		
661
		assertEquals(styleRanges[0], STYLE1, 0, res.length());
662
	}
663
	
664
	public void testSetStyle17() {
665
		
666
		String res= "H2O";
667
		
668
		StyledString StyledString= new StyledString();
669
		StyledString.append('H', null);
670
		StyledString.append('2', STYLE1);
671
		StyledString.append('O', STYLE2);
672
		
673
		StyledString.setStyle(0, res.length(), null);
674
		
675
		assertEquals(res.length(), StyledString.length());
676
		assertEquals(res, StyledString.getString());
677
		StyleRange[] styleRanges= StyledString.getStyleRanges();
678
		assertEquals(0, styleRanges.length);
679
	}
680
	
681
	public void testSetStyle18() {
682
		String res= "H2OH2O";
683
		
684
		StyledString StyledString= new StyledString();
685
		StyledString.append('H', null);
686
		StyledString.append('2', STYLE1);
687
		StyledString.append('O', STYLE2);
688
		StyledString.append('H', null);
689
		StyledString.append('2', STYLE2);
690
		StyledString.append('O', STYLE1);
691
		
692
		StyledString.setStyle(1, res.length() - 2, STYLE1);
693
		
694
		assertEquals(res.length(), StyledString.length());
695
		assertEquals(res, StyledString.getString());
696
		StyleRange[] styleRanges= StyledString.getStyleRanges();
697
		assertEquals(1, styleRanges.length);
698
		
699
		assertEquals(styleRanges[0], STYLE1, 1, res.length() - 1);
700
	}
701
	
702
	public void testSetStyle19() {
703
		String res= "O2O2O2O2O2O2";
704
		
705
		StyledString StyledString= new StyledString();
706
		StyledString.append("O2", null);
707
		StyledString.append("O2", STYLE1);
708
		StyledString.append("O2", STYLE2);
709
		StyledString.append("O2", STYLE1);
710
		StyledString.append("O2", STYLE2);
711
		StyledString.append("O2", null);
712
		
713
		StyledString.setStyle(1, res.length() - 2, STYLE1);
714
		
715
		assertEquals(res.length(), StyledString.length());
716
		assertEquals(res, StyledString.getString());
717
		StyleRange[] styleRanges= StyledString.getStyleRanges();
718
		assertEquals(1, styleRanges.length);
719
		
720
		assertEquals(styleRanges[0], STYLE1, 1, res.length() - 2);
721
	}
722
	
723
	public void testSetStyle20() {
724
		String res= "O2O2O2O2O2O2";
725
		
726
		StyledString StyledString= new StyledString();
727
		StyledString.append("O2", null);
728
		StyledString.append("O2", STYLE1);
729
		StyledString.append("O2", STYLE2);
730
		StyledString.append("O2", STYLE1);
731
		StyledString.append("O2", STYLE2);
732
		StyledString.append("O2", null);
733
		
734
		StyledString.setStyle(3, 6, null);
735
		
736
		assertEquals(res.length(), StyledString.length());
737
		assertEquals(res, StyledString.getString());
738
		StyleRange[] styleRanges= StyledString.getStyleRanges();
739
		assertEquals(2, styleRanges.length);
740
		
741
		assertEquals(styleRanges[0], STYLE1, 2, 1);
742
		assertEquals(styleRanges[1], STYLE2, 9, 1);
743
	}
744
	
745
	public void testSetStyle21() {
746
		String res= "O2O2O2O2O2O2";
747
		
748
		StyledString StyledString= new StyledString();
749
		StyledString.append("O2", null);
750
		StyledString.append("O2", STYLE1);
751
		StyledString.append("O2", STYLE2);
752
		StyledString.append("O2", STYLE1);
753
		StyledString.append("O2", STYLE2);
754
		StyledString.append("O2", null);
755
		
756
		StyledString.setStyle(3, 6, STYLE1);
757
		StyledString.setStyle(3, 6, null);
758
		
759
		assertEquals(res.length(), StyledString.length());
760
		assertEquals(res, StyledString.getString());
761
		StyleRange[] styleRanges= StyledString.getStyleRanges();
762
		assertEquals(2, styleRanges.length);
763
		
764
		assertEquals(styleRanges[0], STYLE1, 2, 1);
765
		assertEquals(styleRanges[1], STYLE2, 9, 1);
766
	}
767
	
768
	public void testCombination1() {
769
		String str1= "One";
770
		String str2= "Two";
771
		
772
		String res= str1 + str2 + str1;
773
		
774
		StyledString StyledString= new StyledString();
775
		StyledString.append(str1, null);
776
		StyledString.append(str2, STYLE2);
777
		
778
		StyledString.setStyle(str1.length(), str2.length(), STYLE1);
779
		
780
		StyledString.append(str1, STYLE1);
781
		
782
		assertEquals(res.length(), StyledString.length());
783
		assertEquals(res, StyledString.getString());
784
		StyleRange[] styleRanges= StyledString.getStyleRanges();
785
		assertEquals(1, styleRanges.length);
786
		
787
		assertEquals(styleRanges[0], STYLE1, str1.length(), str2.length() + str1.length());
788
	}
789
	
790
	
791
	private void assertEquals(StyleRange range, TestStyle style, int offset, int length) {
792
		assertEquals(offset, range.start);
793
		assertEquals(length, range.length);
794
		assertEquals(style.borderStyle, range.borderStyle);
795
	}
796
	
797
	
798
}
(-)src/org/eclipse/jdt/internal/junit/ui/TestSessionLabelProvider.java (-14 / +11 lines)
Lines 19-28 Link Here
19
19
20
import org.eclipse.jface.viewers.LabelProvider;
20
import org.eclipse.jface.viewers.LabelProvider;
21
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
21
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
22
import org.eclipse.jface.viewers.StyledString;
23
import org.eclipse.jface.viewers.DecoratingStyledCellLabelProvider.IStyledLabelProvider;
22
24
23
import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels;
25
import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels;
24
import org.eclipse.jdt.internal.ui.viewsupport.ColoredString;
25
import org.eclipse.jdt.internal.ui.viewsupport.IRichLabelProvider;
26
26
27
import org.eclipse.jdt.junit.model.ITestCaseElement;
27
import org.eclipse.jdt.junit.model.ITestCaseElement;
28
import org.eclipse.jdt.junit.model.ITestElement;
28
import org.eclipse.jdt.junit.model.ITestElement;
Lines 34-40 Link Here
34
import org.eclipse.jdt.internal.junit.model.TestSuiteElement;
34
import org.eclipse.jdt.internal.junit.model.TestSuiteElement;
35
import org.eclipse.jdt.internal.junit.model.TestElement.Status;
35
import org.eclipse.jdt.internal.junit.model.TestElement.Status;
36
36
37
public class TestSessionLabelProvider extends LabelProvider implements IRichLabelProvider {
37
public class TestSessionLabelProvider extends LabelProvider implements IStyledLabelProvider {
38
	
38
	
39
	private final TestRunnerViewPart fTestRunnerPart;
39
	private final TestRunnerViewPart fTestRunnerPart;
40
	private final int fLayoutMode;
40
	private final int fLayoutMode;
Lines 54-68 Link Here
54
		timeFormat.setMinimumIntegerDigits(1);
54
		timeFormat.setMinimumIntegerDigits(1);
55
	}
55
	}
56
	
56
	
57
	/* (non-Javadoc)
57
	public StyledString getStyledText(Object element) {
58
	 * @see org.eclipse.jdt.internal.ui.viewsupport.IRichLabelProvider#getRichTextLabel(java.lang.Object)
59
	 */
60
	public ColoredString getRichTextLabel(Object element) {
61
		String label= getSimpleLabel(element);
58
		String label= getSimpleLabel(element);
62
		if (label == null) {
59
		if (label == null) {
63
			return new ColoredString(element.toString());
60
			return new StyledString(element.toString());
64
		}
61
		}
65
		ColoredString text= new ColoredString(label);
62
		StyledString text= new StyledString(label);
66
		
63
		
67
		ITestElement testElement= (ITestElement) element;
64
		ITestElement testElement= (ITestElement) element;
68
		if (fLayoutMode == TestRunnerViewPart.LAYOUT_HIERARCHICAL) {
65
		if (fLayoutMode == TestRunnerViewPart.LAYOUT_HIERARCHICAL) {
Lines 70-76 Link Here
70
				String testKindDisplayName= fTestRunnerPart.getTestKindDisplayName();
67
				String testKindDisplayName= fTestRunnerPart.getTestKindDisplayName();
71
				if (testKindDisplayName != null) {
68
				if (testKindDisplayName != null) {
72
					String decorated= Messages.format(JUnitMessages.TestSessionLabelProvider_testName_JUnitVersion, new Object[] { label, testKindDisplayName });
69
					String decorated= Messages.format(JUnitMessages.TestSessionLabelProvider_testName_JUnitVersion, new Object[] { label, testKindDisplayName });
73
					text= ColoredJavaElementLabels.decorateColoredString(text, decorated, ColoredJavaElementLabels.QUALIFIER_STYLE);
70
					text= ColoredJavaElementLabels.decorateStyledString(text, decorated, ColoredJavaElementLabels.QUALIFIER_STYLE);
74
				}
71
				}
75
			}
72
			}
76
			
73
			
Lines 78-93 Link Here
78
			if (element instanceof ITestCaseElement) {
75
			if (element instanceof ITestCaseElement) {
79
				String className= ((ITestCaseElement) element).getTestClassName();
76
				String className= ((ITestCaseElement) element).getTestClassName();
80
				String decorated= Messages.format(JUnitMessages.TestSessionLabelProvider_testMethodName_className, new Object[] { label, className });
77
				String decorated= Messages.format(JUnitMessages.TestSessionLabelProvider_testMethodName_className, new Object[] { label, className });
81
				text= ColoredJavaElementLabels.decorateColoredString(text, decorated, ColoredJavaElementLabels.QUALIFIER_STYLE);
78
				text= ColoredJavaElementLabels.decorateStyledString(text, decorated, ColoredJavaElementLabels.QUALIFIER_STYLE);
82
			}
79
			}
83
		}
80
		}
84
		return addElapsedTime(text, testElement.getElapsedTimeInSeconds());
81
		return addElapsedTime(text, testElement.getElapsedTimeInSeconds());
85
	}
82
	}
86
	
83
	
87
	private ColoredString addElapsedTime(ColoredString coloredString, double time) {
84
	private StyledString addElapsedTime(StyledString StyledString, double time) {
88
		String string= coloredString.getString();
85
		String string= StyledString.getString();
89
		String decorated= addElapsedTime(string, time);
86
		String decorated= addElapsedTime(string, time);
90
		return ColoredJavaElementLabels.decorateColoredString(coloredString, decorated, ColoredJavaElementLabels.COUNTER_STYLE);
87
		return ColoredJavaElementLabels.decorateStyledString(StyledString, decorated, ColoredJavaElementLabels.COUNTER_STYLE);
91
	}
88
	}
92
89
93
	private String addElapsedTime(String string, double time) {
90
	private String addElapsedTime(String string, double time) {
(-)ui/org/eclipse/jdt/internal/ui/browsing/PackagesViewLabelProvider.java (-6 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 18-23 Link Here
18
import org.eclipse.swt.graphics.Image;
18
import org.eclipse.swt.graphics.Image;
19
19
20
import org.eclipse.jface.resource.ImageDescriptor;
20
import org.eclipse.jface.resource.ImageDescriptor;
21
import org.eclipse.jface.viewers.StyledString;
21
22
22
import org.eclipse.jdt.core.IPackageFragment;
23
import org.eclipse.jdt.core.IPackageFragment;
23
import org.eclipse.jdt.core.JavaModelException;
24
import org.eclipse.jdt.core.JavaModelException;
Lines 27-33 Link Here
27
import org.eclipse.jdt.internal.ui.JavaPlugin;
28
import org.eclipse.jdt.internal.ui.JavaPlugin;
28
import org.eclipse.jdt.internal.ui.JavaPluginImages;
29
import org.eclipse.jdt.internal.ui.JavaPluginImages;
29
import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
30
import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
30
import org.eclipse.jdt.internal.ui.viewsupport.ColoredString;
31
import org.eclipse.jdt.internal.ui.viewsupport.ImageDescriptorRegistry;
31
import org.eclipse.jdt.internal.ui.viewsupport.ImageDescriptorRegistry;
32
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
32
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
33
import org.eclipse.jdt.internal.ui.viewsupport.TreeHierarchyLayoutProblemsDecorator;
33
import org.eclipse.jdt.internal.ui.viewsupport.TreeHierarchyLayoutProblemsDecorator;
Lines 119-131 Link Here
119
	/* (non-Javadoc)
119
	/* (non-Javadoc)
120
	 * @see org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider#getRichTextLabel(java.lang.Object)
120
	 * @see org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider#getRichTextLabel(java.lang.Object)
121
	 */
121
	 */
122
	public ColoredString getRichTextLabel(Object element) {
122
	public StyledString getStyledText(Object element) {
123
		if (element instanceof IPackageFragment || element instanceof LogicalPackage)
123
		if (element instanceof IPackageFragment || element instanceof LogicalPackage)
124
			return new ColoredString(getText(element));
124
			return new StyledString(getText(element));
125
		return super.getRichTextLabel(element);
125
		return super.getStyledText(element);
126
	}
126
	}
127
	
127
	
128
129
	private String getText(IPackageFragment fragment) {
128
	private String getText(IPackageFragment fragment) {
130
		if (isFlatView())
129
		if (isFlatView())
131
			return getFlatText(fragment);
130
			return getFlatText(fragment);
(-)ui/org/eclipse/jdt/internal/ui/browsing/JavaBrowsingPart.java (-2 / +1 lines)
Lines 124-130 Link Here
124
import org.eclipse.jdt.internal.ui.search.SearchUtil;
124
import org.eclipse.jdt.internal.ui.search.SearchUtil;
125
import org.eclipse.jdt.internal.ui.util.JavaUIHelp;
125
import org.eclipse.jdt.internal.ui.util.JavaUIHelp;
126
import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
126
import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
127
import org.eclipse.jdt.internal.ui.viewsupport.ColoringLabelProvider;
128
import org.eclipse.jdt.internal.ui.viewsupport.DecoratingJavaLabelProvider;
127
import org.eclipse.jdt.internal.ui.viewsupport.DecoratingJavaLabelProvider;
129
import org.eclipse.jdt.internal.ui.viewsupport.IViewPartInputProvider;
128
import org.eclipse.jdt.internal.ui.viewsupport.IViewPartInputProvider;
130
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
129
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
Lines 329-335 Link Here
329
		initDragAndDrop();
328
		initDragAndDrop();
330
329
331
		fLabelProvider= createLabelProvider();
330
		fLabelProvider= createLabelProvider();
332
		fViewer.setLabelProvider(new ColoringLabelProvider(createDecoratingLabelProvider(fLabelProvider)));
331
		fViewer.setLabelProvider(createDecoratingLabelProvider(fLabelProvider));
333
332
334
		fViewer.setComparator(createJavaElementComparator());
333
		fViewer.setComparator(createJavaElementComparator());
335
		fViewer.setUseHashlookup(true);
334
		fViewer.setUseHashlookup(true);
(-)ui/org/eclipse/jdt/internal/ui/javaeditor/JavaOutlinePage.java (-2 / +1 lines)
Lines 123-129 Link Here
123
import org.eclipse.jdt.internal.ui.dnd.JdtViewerDropSupport;
123
import org.eclipse.jdt.internal.ui.dnd.JdtViewerDropSupport;
124
import org.eclipse.jdt.internal.ui.preferences.MembersOrderPreferenceCache;
124
import org.eclipse.jdt.internal.ui.preferences.MembersOrderPreferenceCache;
125
import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
125
import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
126
import org.eclipse.jdt.internal.ui.viewsupport.ColoringLabelProvider;
127
import org.eclipse.jdt.internal.ui.viewsupport.DecoratingJavaLabelProvider;
126
import org.eclipse.jdt.internal.ui.viewsupport.DecoratingJavaLabelProvider;
128
import org.eclipse.jdt.internal.ui.viewsupport.SourcePositionComparator;
127
import org.eclipse.jdt.internal.ui.viewsupport.SourcePositionComparator;
129
import org.eclipse.jdt.internal.ui.viewsupport.StatusBarUpdater;
128
import org.eclipse.jdt.internal.ui.viewsupport.StatusBarUpdater;
Lines 1037-1043 Link Here
1037
		fOutlineViewer= new JavaOutlineViewer(tree);
1036
		fOutlineViewer= new JavaOutlineViewer(tree);
1038
		initDragAndDrop();
1037
		initDragAndDrop();
1039
		fOutlineViewer.setContentProvider(new ChildrenProvider());
1038
		fOutlineViewer.setContentProvider(new ChildrenProvider());
1040
		fOutlineViewer.setLabelProvider(new ColoringLabelProvider(new DecoratingJavaLabelProvider(lprovider)));
1039
		fOutlineViewer.setLabelProvider(new DecoratingJavaLabelProvider(lprovider));
1041
1040
1042
		Object[] listeners= fSelectionChangedListeners.getListeners();
1041
		Object[] listeners= fSelectionChangedListeners.getListeners();
1043
		for (int i= 0; i < listeners.length; i++) {
1042
		for (int i= 0; i < listeners.length; i++) {
(-)ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditorBreadcrumb.java (-19 / +1 lines)
Lines 30-40 Link Here
30
import org.eclipse.jface.viewers.ILabelProviderListener;
30
import org.eclipse.jface.viewers.ILabelProviderListener;
31
import org.eclipse.jface.viewers.ISelectionChangedListener;
31
import org.eclipse.jface.viewers.ISelectionChangedListener;
32
import org.eclipse.jface.viewers.ITreeContentProvider;
32
import org.eclipse.jface.viewers.ITreeContentProvider;
33
import org.eclipse.jface.viewers.IViewerLabelProvider;
34
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
33
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
35
import org.eclipse.jface.viewers.SelectionChangedEvent;
34
import org.eclipse.jface.viewers.SelectionChangedEvent;
36
import org.eclipse.jface.viewers.Viewer;
35
import org.eclipse.jface.viewers.Viewer;
37
import org.eclipse.jface.viewers.ViewerLabel;
38
36
39
import org.eclipse.ui.IEditorPart;
37
import org.eclipse.ui.IEditorPart;
40
import org.eclipse.ui.IEditorSite;
38
import org.eclipse.ui.IEditorSite;
Lines 64-72 Link Here
64
import org.eclipse.jdt.internal.ui.javaeditor.breadcrumb.BreadcrumbViewer;
62
import org.eclipse.jdt.internal.ui.javaeditor.breadcrumb.BreadcrumbViewer;
65
import org.eclipse.jdt.internal.ui.javaeditor.breadcrumb.EditorBreadcrumb;
63
import org.eclipse.jdt.internal.ui.javaeditor.breadcrumb.EditorBreadcrumb;
66
import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
64
import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
67
import org.eclipse.jdt.internal.ui.viewsupport.ColoredString;
68
import org.eclipse.jdt.internal.ui.viewsupport.DecoratingJavaLabelProvider;
65
import org.eclipse.jdt.internal.ui.viewsupport.DecoratingJavaLabelProvider;
69
import org.eclipse.jdt.internal.ui.viewsupport.IRichLabelProvider;
70
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
66
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
71
import org.eclipse.jdt.internal.ui.viewsupport.ResourceToItemsMapper;
67
import org.eclipse.jdt.internal.ui.viewsupport.ResourceToItemsMapper;
72
68
Lines 164-170 Link Here
164
		}
160
		}
165
	}
161
	}
166
162
167
	private static final class JavaBreadcrumbLabelProvider implements ILabelProvider, IRichLabelProvider, IViewerLabelProvider {
163
	private static final class JavaBreadcrumbLabelProvider implements ILabelProvider {
168
164
169
		private final DecoratingJavaLabelProvider fParent;
165
		private final DecoratingJavaLabelProvider fParent;
170
166
Lines 215-234 Link Here
215
			fParent.removeListener(listener);
211
			fParent.removeListener(listener);
216
		}
212
		}
217
213
218
		/*
219
		 * @see org.eclipse.jdt.internal.ui.viewsupport.IRichLabelProvider#getRichTextLabel(java.lang.Object)
220
		 */
221
		public ColoredString getRichTextLabel(Object object) {
222
			return fParent.getRichTextLabel(object);
223
		}
224
225
		/*
226
		 * @see org.eclipse.jface.viewers.IViewerLabelProvider#updateLabel(org.eclipse.jface.viewers.ViewerLabel, java.lang.Object)
227
		 */
228
		public void updateLabel(ViewerLabel label, Object element) {
229
			fParent.updateLabel(label, element);
230
		}
231
232
		private void internalDispose() {
214
		private void internalDispose() {
233
			fParent.dispose();
215
			fParent.dispose();
234
		}
216
		}
(-)ui/org/eclipse/jdt/internal/ui/search/SearchLabelProvider.java (-4 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 26-31 Link Here
26
import org.eclipse.jface.viewers.ILabelProvider;
26
import org.eclipse.jface.viewers.ILabelProvider;
27
import org.eclipse.jface.viewers.ILabelProviderListener;
27
import org.eclipse.jface.viewers.ILabelProviderListener;
28
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
28
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
29
import org.eclipse.jface.viewers.StyledString;
29
30
30
import org.eclipse.ui.preferences.ScopedPreferenceStore;
31
import org.eclipse.ui.preferences.ScopedPreferenceStore;
31
32
Lines 44-50 Link Here
44
import org.eclipse.jdt.internal.ui.JavaPlugin;
45
import org.eclipse.jdt.internal.ui.JavaPlugin;
45
import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
46
import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
46
import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels;
47
import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels;
47
import org.eclipse.jdt.internal.ui.viewsupport.ColoredString;
48
48
49
public abstract class SearchLabelProvider extends AppearanceAwareLabelProvider {
49
public abstract class SearchLabelProvider extends AppearanceAwareLabelProvider {
50
	
50
	
Lines 122-132 Link Here
122
		return res;
122
		return res;
123
	}
123
	}
124
		
124
		
125
	protected final ColoredString getColoredLabelWithCounts(Object element, ColoredString coloredName) {
125
	protected final StyledString getColoredLabelWithCounts(Object element, StyledString coloredName) {
126
		String name= coloredName.getString();
126
		String name= coloredName.getString();
127
		String decorated= getLabelWithCounts(element, name);
127
		String decorated= getLabelWithCounts(element, name);
128
		if (decorated.length() > name.length()) {
128
		if (decorated.length() > name.length()) {
129
			ColoredJavaElementLabels.decorateColoredString(coloredName, decorated, ColoredJavaElementLabels.COUNTER_STYLE);
129
			ColoredJavaElementLabels.decorateStyledString(coloredName, decorated, ColoredJavaElementLabels.COUNTER_STYLE);
130
		}
130
		}
131
		return coloredName;
131
		return coloredName;
132
	}
132
	}
(-)ui/org/eclipse/jdt/internal/ui/search/OccurrencesSearchLabelProvider.java (-14 / +15 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 13-18 Link Here
13
13
14
import org.eclipse.swt.graphics.Image;
14
import org.eclipse.swt.graphics.Image;
15
15
16
import org.eclipse.jface.viewers.StyledString;
17
import org.eclipse.jface.viewers.DecoratingStyledCellLabelProvider.IStyledLabelProvider;
18
import org.eclipse.jface.viewers.StyledString.Style;
19
16
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
20
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
17
import org.eclipse.search.ui.text.Match;
21
import org.eclipse.search.ui.text.Match;
18
22
Lines 20-30 Link Here
20
24
21
import org.eclipse.jdt.internal.ui.JavaPluginImages;
25
import org.eclipse.jdt.internal.ui.JavaPluginImages;
22
import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels;
26
import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels;
23
import org.eclipse.jdt.internal.ui.viewsupport.ColoredString;
24
import org.eclipse.jdt.internal.ui.viewsupport.IRichLabelProvider;
25
import org.eclipse.jdt.internal.ui.viewsupport.ColoredString.Style;
26
27
27
class OccurrencesSearchLabelProvider extends TextSearchLabelProvider implements IRichLabelProvider {
28
class OccurrencesSearchLabelProvider extends TextSearchLabelProvider implements IStyledLabelProvider {
28
	
29
	
29
	public OccurrencesSearchLabelProvider(AbstractTextSearchViewPage page) {
30
	public OccurrencesSearchLabelProvider(AbstractTextSearchViewPage page) {
30
		super(page);
31
		super(page);
Lines 37-49 Link Here
37
		return getLabelWithCounts(element, internalGetText(element)); 
38
		return getLabelWithCounts(element, internalGetText(element)); 
38
	}
39
	}
39
	
40
	
40
	/* (non-Javadoc)
41
	 * @see org.eclipse.jdt.internal.ui.viewsupport.IRichLabelProvider#getRichTextLabel(java.lang.Object)
42
	 */
43
	public ColoredString getRichTextLabel(Object element) {
44
		return getColoredLabelWithCounts(element, internalGetRichText(element)); 
45
	}
46
47
	private String getLineNumberLabel(JavaElementLine element) {
41
	private String getLineNumberLabel(JavaElementLine element) {
48
		return Messages.format(SearchMessages.OccurrencesSearchLabelProvider_line_number, new Integer(element.getLine()));
42
		return Messages.format(SearchMessages.OccurrencesSearchLabelProvider_line_number, new Integer(element.getLine()));
49
	}
43
	}
Lines 53-66 Link Here
53
		return getLineNumberLabel(jel) + jel.getLineContents();
47
		return getLineNumberLabel(jel) + jel.getLineContents();
54
	}
48
	}
55
	
49
	
56
	private ColoredString internalGetRichText(Object element) {
50
	private StyledString internalGetRichText(Object element) {
57
		JavaElementLine jel= (JavaElementLine) element;
51
		JavaElementLine jel= (JavaElementLine) element;
58
52
59
		String lineNumberString= getLineNumberLabel(jel);
53
		String lineNumberString= getLineNumberLabel(jel);
60
54
61
		Style highlightStyle= ColoredJavaElementLabels.HIGHLIGHT_STYLE;
55
		Style highlightStyle= ColoredJavaElementLabels.HIGHLIGHT_STYLE;
62
		
56
		
63
		ColoredString res= new ColoredString();
57
		StyledString res= new StyledString();
64
		res.append(lineNumberString, ColoredJavaElementLabels.QUALIFIER_STYLE);
58
		res.append(lineNumberString, ColoredJavaElementLabels.QUALIFIER_STYLE);
65
		res.append(jel.getLineContents());
59
		res.append(jel.getLineContents());
66
		Match[] matches= getPage().getInput().getMatches(jel);
60
		Match[] matches= getPage().getInput().getMatches(jel);
Lines 95-98 Link Here
95
		}
89
		}
96
		return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_SEARCH_OCCURRENCE);
90
		return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_SEARCH_OCCURRENCE);
97
	}
91
	}
92
93
	/* (non-Javadoc)
94
	 * @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider#getStyledText(java.lang.Object)
95
	 */
96
	public StyledString getStyledText(Object element) {
97
		return getColoredLabelWithCounts(element, internalGetRichText(element));			
98
	}
98
}
99
}
(-)ui/org/eclipse/jdt/internal/ui/search/PostfixLabelProvider.java (-7 / +7 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 13-18 Link Here
13
import org.eclipse.swt.graphics.Image;
13
import org.eclipse.swt.graphics.Image;
14
14
15
import org.eclipse.jface.viewers.ITreeContentProvider;
15
import org.eclipse.jface.viewers.ITreeContentProvider;
16
import org.eclipse.jface.viewers.StyledString;
16
17
17
import org.eclipse.jdt.core.IClassFile;
18
import org.eclipse.jdt.core.IClassFile;
18
import org.eclipse.jdt.core.ICompilationUnit;
19
import org.eclipse.jdt.core.ICompilationUnit;
Lines 22-28 Link Here
22
import org.eclipse.jdt.ui.JavaElementLabels;
23
import org.eclipse.jdt.ui.JavaElementLabels;
23
24
24
import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels;
25
import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels;
25
import org.eclipse.jdt.internal.ui.viewsupport.ColoredString;
26
26
27
public class PostfixLabelProvider extends SearchLabelProvider {
27
public class PostfixLabelProvider extends SearchLabelProvider {
28
	private ITreeContentProvider fContentProvider;
28
	private ITreeContentProvider fContentProvider;
Lines 88-99 Link Here
88
	}
88
	}
89
	
89
	
90
	/* (non-Javadoc)
90
	/* (non-Javadoc)
91
	 * @see org.eclipse.jdt.internal.ui.viewsupport.IRichLabelProvider#getRichTextLabel(java.lang.Object)
91
	 * @see org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider#getStyledText(java.lang.Object)
92
	 */
92
	 */
93
	public ColoredString getRichTextLabel(Object element) {
93
	public StyledString getStyledText(Object element) {
94
		ColoredString coloredString= getColoredLabelWithCounts(element, super.getRichTextLabel(element));
94
		StyledString StyledString= getColoredLabelWithCounts(element, super.getStyledText(element));
95
		coloredString.append(getQualification(element), ColoredJavaElementLabels.QUALIFIER_STYLE);
95
		StyledString.append(getQualification(element), ColoredJavaElementLabels.QUALIFIER_STYLE);
96
		return coloredString;
96
		return StyledString;
97
	}
97
	}
98
98
99
}
99
}
(-)ui/org/eclipse/jdt/internal/ui/search/JavaSearchResultPage.java (-3 / +2 lines)
Lines 82-88 Link Here
82
import org.eclipse.jdt.internal.ui.dnd.ResourceTransferDragAdapter;
82
import org.eclipse.jdt.internal.ui.dnd.ResourceTransferDragAdapter;
83
import org.eclipse.jdt.internal.ui.packageview.SelectionTransferDragAdapter;
83
import org.eclipse.jdt.internal.ui.packageview.SelectionTransferDragAdapter;
84
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
84
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
85
import org.eclipse.jdt.internal.ui.viewsupport.ColoringLabelProvider;
86
import org.eclipse.jdt.internal.ui.viewsupport.DecoratingJavaLabelProvider;
85
import org.eclipse.jdt.internal.ui.viewsupport.DecoratingJavaLabelProvider;
87
import org.eclipse.jdt.internal.ui.viewsupport.ProblemTableViewer;
86
import org.eclipse.jdt.internal.ui.viewsupport.ProblemTableViewer;
88
import org.eclipse.jdt.internal.ui.viewsupport.ProblemTreeViewer;
87
import org.eclipse.jdt.internal.ui.viewsupport.ProblemTreeViewer;
Lines 306-312 Link Here
306
	protected void configureTableViewer(TableViewer viewer) {
305
	protected void configureTableViewer(TableViewer viewer) {
307
		viewer.setUseHashlookup(true);
306
		viewer.setUseHashlookup(true);
308
		fSortingLabelProvider= new SortingLabelProvider(this);
307
		fSortingLabelProvider= new SortingLabelProvider(this);
309
		viewer.setLabelProvider(new ColoringLabelProvider(new DecoratingJavaLabelProvider(fSortingLabelProvider, false)));
308
		viewer.setLabelProvider(new DecoratingJavaLabelProvider(fSortingLabelProvider, false));
310
		fContentProvider=new JavaSearchTableContentProvider(this);
309
		fContentProvider=new JavaSearchTableContentProvider(this);
311
		viewer.setContentProvider(fContentProvider);
310
		viewer.setContentProvider(fContentProvider);
312
		viewer.setComparator(new DecoratorIgnoringViewerSorter(fSortingLabelProvider));
311
		viewer.setComparator(new DecoratorIgnoringViewerSorter(fSortingLabelProvider));
Lines 318-324 Link Here
318
		PostfixLabelProvider postfixLabelProvider= new PostfixLabelProvider(this);
317
		PostfixLabelProvider postfixLabelProvider= new PostfixLabelProvider(this);
319
		viewer.setUseHashlookup(true);
318
		viewer.setUseHashlookup(true);
320
		viewer.setComparator(new DecoratorIgnoringViewerSorter(postfixLabelProvider));
319
		viewer.setComparator(new DecoratorIgnoringViewerSorter(postfixLabelProvider));
321
		viewer.setLabelProvider(new ColoringLabelProvider(new DecoratingJavaLabelProvider(postfixLabelProvider, false)));
320
		viewer.setLabelProvider(new DecoratingJavaLabelProvider(postfixLabelProvider, false));
322
		fContentProvider= new LevelTreeContentProvider(this, fCurrentGrouping);
321
		fContentProvider= new LevelTreeContentProvider(this, fCurrentGrouping);
323
		viewer.setContentProvider(fContentProvider);
322
		viewer.setContentProvider(fContentProvider);
324
		addDragAdapters(viewer);
323
		addDragAdapters(viewer);
(-)ui/org/eclipse/jdt/internal/ui/search/SortingLabelProvider.java (-7 / +8 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 14-26 Link Here
14
14
15
import org.eclipse.swt.graphics.Image;
15
import org.eclipse.swt.graphics.Image;
16
16
17
import org.eclipse.jface.viewers.StyledString;
18
17
import org.eclipse.jdt.core.IImportDeclaration;
19
import org.eclipse.jdt.core.IImportDeclaration;
18
import org.eclipse.jdt.core.IJavaElement;
20
import org.eclipse.jdt.core.IJavaElement;
19
21
20
import org.eclipse.jdt.ui.JavaElementLabels;
22
import org.eclipse.jdt.ui.JavaElementLabels;
21
23
22
import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels;
24
import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels;
23
import org.eclipse.jdt.internal.ui.viewsupport.ColoredString;
24
25
25
public class SortingLabelProvider extends SearchLabelProvider {
26
public class SortingLabelProvider extends SearchLabelProvider {
26
	
27
	
Lines 64-84 Link Here
64
	}
65
	}
65
	
66
	
66
	/* (non-Javadoc)
67
	/* (non-Javadoc)
67
	 * @see org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider#getRichTextLabel(java.lang.Object)
68
	 * @see org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider#getStyledText(java.lang.Object)
68
	 */
69
	 */
69
	public ColoredString getRichTextLabel(Object element) {
70
	public StyledString getStyledText(Object element) {
70
		if (element instanceof IImportDeclaration)
71
		if (element instanceof IImportDeclaration)
71
			element= ((IImportDeclaration)element).getParent().getParent();
72
			element= ((IImportDeclaration)element).getParent().getParent();
72
		
73
		
73
		ColoredString text= super.getRichTextLabel(element);
74
		StyledString text= super.getStyledText(element);
74
		if (text.length() > 0) {
75
		if (text.length() > 0) {
75
			ColoredString countLabel= getColoredLabelWithCounts(element, text);
76
			StyledString countLabel= getColoredLabelWithCounts(element, text);
76
			if (fCurrentOrder == SHOW_ELEMENT_CONTAINER) {
77
			if (fCurrentOrder == SHOW_ELEMENT_CONTAINER) {
77
				countLabel.append(getPostQualification(element), ColoredJavaElementLabels.QUALIFIER_STYLE);
78
				countLabel.append(getPostQualification(element), ColoredJavaElementLabels.QUALIFIER_STYLE);
78
			}
79
			}
79
			return countLabel;
80
			return countLabel;
80
		}
81
		}
81
		return new ColoredString(getParticipantText(element));	
82
		return new StyledString(getParticipantText(element));	
82
	}
83
	}
83
84
84
	private String getPostQualification(Object element) {
85
	private String getPostQualification(Object element) {
(-)ui/org/eclipse/jdt/internal/ui/search/TextSearchLabelProvider.java (-4 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 11-23 Link Here
11
package org.eclipse.jdt.internal.ui.search;
11
package org.eclipse.jdt.internal.ui.search;
12
12
13
import org.eclipse.jface.viewers.LabelProvider;
13
import org.eclipse.jface.viewers.LabelProvider;
14
import org.eclipse.jface.viewers.StyledString;
14
15
15
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
16
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
16
17
17
import org.eclipse.jdt.internal.corext.util.Messages;
18
import org.eclipse.jdt.internal.corext.util.Messages;
18
19
19
import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels;
20
import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels;
20
import org.eclipse.jdt.internal.ui.viewsupport.ColoredString;
21
21
22
public abstract class TextSearchLabelProvider extends LabelProvider {
22
public abstract class TextSearchLabelProvider extends LabelProvider {
23
23
Lines 31-41 Link Here
31
		return fPage;
31
		return fPage;
32
	}
32
	}
33
			
33
			
34
	protected final ColoredString getColoredLabelWithCounts(Object element, ColoredString coloredName) {
34
	protected final StyledString getColoredLabelWithCounts(Object element, StyledString coloredName) {
35
		String name= coloredName.getString();
35
		String name= coloredName.getString();
36
		String decorated= getLabelWithCounts(element, name);
36
		String decorated= getLabelWithCounts(element, name);
37
		if (decorated.length() > name.length()) {
37
		if (decorated.length() > name.length()) {
38
			ColoredJavaElementLabels.decorateColoredString(coloredName, decorated, ColoredJavaElementLabels.COUNTER_STYLE);
38
			ColoredJavaElementLabels.decorateStyledString(coloredName, decorated, ColoredJavaElementLabels.COUNTER_STYLE);
39
		}
39
		}
40
		return coloredName;
40
		return coloredName;
41
	}
41
	}
(-)ui/org/eclipse/jdt/internal/ui/packageview/PackageExplorerLabelProvider.java (-6 / +6 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 22-27 Link Here
22
import org.eclipse.swt.graphics.Image;
22
import org.eclipse.swt.graphics.Image;
23
23
24
import org.eclipse.jface.resource.ImageDescriptor;
24
import org.eclipse.jface.resource.ImageDescriptor;
25
import org.eclipse.jface.viewers.StyledString;
25
26
26
import org.eclipse.ui.IWorkingSet;
27
import org.eclipse.ui.IWorkingSet;
27
28
Lines 30-36 Link Here
30
import org.eclipse.jdt.ui.JavaElementLabels;
31
import org.eclipse.jdt.ui.JavaElementLabels;
31
32
32
import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
33
import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
33
import org.eclipse.jdt.internal.ui.viewsupport.ColoredString;
34
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
34
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
35
35
36
/**
36
/**
Lines 60-73 Link Here
60
	}
60
	}
61
	
61
	
62
	/* (non-Javadoc)
62
	/* (non-Javadoc)
63
	 * @see org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider#getRichTextLabel(java.lang.Object)
63
	 * @see org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider#getStyledText(java.lang.Object)
64
	 */
64
	 */
65
	public ColoredString getRichTextLabel(Object element) {
65
	public StyledString getStyledText(Object element) {
66
		String text= getSpecificText(element);
66
		String text= getSpecificText(element);
67
		if (text != null) {
67
		if (text != null) {
68
			return new ColoredString(decorateText(text, element));
68
			return new StyledString(decorateText(text, element));
69
		}
69
		}
70
		return super.getRichTextLabel(element);
70
		return super.getStyledText(element);
71
	}
71
	}
72
	
72
	
73
	private String getSpecificText(Object element) {
73
	private String getSpecificText(Object element) {
(-)ui/org/eclipse/jdt/internal/ui/packageview/PackageExplorerPart.java (-2 / +1 lines)
Lines 137-143 Link Here
137
import org.eclipse.jdt.internal.ui.preferences.MembersOrderPreferenceCache;
137
import org.eclipse.jdt.internal.ui.preferences.MembersOrderPreferenceCache;
138
import org.eclipse.jdt.internal.ui.util.JavaUIHelp;
138
import org.eclipse.jdt.internal.ui.util.JavaUIHelp;
139
import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
139
import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
140
import org.eclipse.jdt.internal.ui.viewsupport.ColoringLabelProvider;
141
import org.eclipse.jdt.internal.ui.viewsupport.DecoratingJavaLabelProvider;
140
import org.eclipse.jdt.internal.ui.viewsupport.DecoratingJavaLabelProvider;
142
import org.eclipse.jdt.internal.ui.viewsupport.FilterUpdater;
141
import org.eclipse.jdt.internal.ui.viewsupport.FilterUpdater;
143
import org.eclipse.jdt.internal.ui.viewsupport.IViewPartInputProvider;
142
import org.eclipse.jdt.internal.ui.viewsupport.IViewPartInputProvider;
Lines 662-668 Link Here
662
		fLabelProvider= createLabelProvider();
661
		fLabelProvider= createLabelProvider();
663
		fLabelProvider.setIsFlatLayout(fIsCurrentLayoutFlat);
662
		fLabelProvider.setIsFlatLayout(fIsCurrentLayoutFlat);
664
		fDecoratingLabelProvider= new DecoratingJavaLabelProvider(fLabelProvider, false, fIsCurrentLayoutFlat);
663
		fDecoratingLabelProvider= new DecoratingJavaLabelProvider(fLabelProvider, false, fIsCurrentLayoutFlat);
665
		fViewer.setLabelProvider(new ColoringLabelProvider(fDecoratingLabelProvider));
664
		fViewer.setLabelProvider(fDecoratingLabelProvider);
666
		// problem decoration provided by PackageLabelProvider
665
		// problem decoration provided by PackageLabelProvider
667
	}
666
	}
668
	
667
	
(-)ui/org/eclipse/jdt/internal/ui/viewsupport/OwnerDrawSupport.java (-160 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.viewsupport;
12
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.custom.StyleRange;
15
import org.eclipse.swt.graphics.Color;
16
import org.eclipse.swt.graphics.Font;
17
import org.eclipse.swt.graphics.GC;
18
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.swt.graphics.Rectangle;
20
import org.eclipse.swt.graphics.TextLayout;
21
import org.eclipse.swt.widgets.Control;
22
import org.eclipse.swt.widgets.Display;
23
import org.eclipse.swt.widgets.Event;
24
import org.eclipse.swt.widgets.Item;
25
import org.eclipse.swt.widgets.Listener;
26
import org.eclipse.swt.widgets.TableItem;
27
import org.eclipse.swt.widgets.TreeItem;
28
29
import org.eclipse.jface.window.Window;
30
31
/**
32
 * Adding owner draw support to a control
33
 */
34
public abstract class OwnerDrawSupport implements Listener {
35
	
36
	private TextLayout fTextLayout;
37
	private final Control fControl;
38
	
39
	public OwnerDrawSupport(Control control) {
40
		fControl= control;
41
		fTextLayout= new TextLayout(control.getDisplay());
42
		fTextLayout.setOrientation(Window.getDefaultOrientation());
43
		
44
		control.addListener(SWT.PaintItem, this);
45
		control.addListener(SWT.EraseItem, this);
46
		control.addListener(SWT.Dispose, this);
47
	}
48
	
49
	/**
50
	 * Return the colored label for the given item.
51
	 * @param item the item to return the colored label for
52
	 * @return the colored string
53
	 */
54
	public abstract ColoredString getColoredLabel(Item item);
55
	
56
	/**
57
	 * Return the color for the given style
58
	 * @param colorName the name of the color
59
	 * @param display the current display
60
	 * @return the color
61
	 */
62
	public abstract Color getColor(String colorName, Display display);
63
	
64
	/* (non-Javadoc)
65
	 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
66
	 */
67
	public void handleEvent(Event event) {
68
		if (event.type == SWT.PaintItem) {
69
			performPaint(event);
70
		} else if (event.type == SWT.EraseItem) {
71
			performErase(event);
72
		} else if (event.type == SWT.Dispose) {
73
			dispose();
74
		}
75
	}
76
	
77
	private void performErase(Event event) {
78
		event.detail &= ~SWT.FOREGROUND;
79
	}
80
			
81
	private void performPaint(Event event) {
82
		Item item= (Item) event.item;
83
		GC gc= event.gc;
84
85
		ColoredString coloredLabel= getColoredLabel(item);
86
		boolean isSelected= (event.detail & SWT.SELECTED) != 0;
87
		if (item instanceof TreeItem) {
88
			TreeItem treeItem= (TreeItem) item;
89
			Image image = treeItem.getImage(event.index);
90
			if (image != null) {
91
				processImage(image, gc, treeItem.getImageBounds(event.index));
92
			}
93
			Rectangle textBounds= treeItem.getTextBounds(event.index);
94
			Font font= treeItem.getFont(event.index);
95
			processColoredLabel(coloredLabel, gc, textBounds, isSelected, font);
96
			
97
			Rectangle bounds= treeItem.getBounds();
98
			if ((event.detail & SWT.FOCUSED) != 0) {
99
				gc.drawFocus(bounds.x, bounds.y, bounds.width, bounds.height);
100
			}
101
		} else if (item instanceof TableItem) {
102
			TableItem tableItem= (TableItem) item;		
103
			Image image = tableItem.getImage(event.index);
104
			if (image != null) {
105
				processImage(image, gc, tableItem.getImageBounds(event.index));
106
			}
107
			Rectangle textBounds= tableItem.getTextBounds(event.index);
108
			Font font= tableItem.getFont(event.index);
109
			processColoredLabel(coloredLabel, gc, textBounds, isSelected, font);
110
			
111
			Rectangle bounds= tableItem.getBounds();
112
			if ((event.detail & SWT.FOCUSED) != 0) {
113
				gc.drawFocus(bounds.x, bounds.y, bounds.width, bounds.height);
114
			}
115
		}
116
	}
117
	
118
	private void processImage(Image image, GC gc, Rectangle imageBounds) {
119
		Rectangle bounds= image.getBounds();
120
		int x= imageBounds.x + Math.max(0, (imageBounds.width - bounds.width) / 2);
121
		int y= imageBounds.y + Math.max(0, (imageBounds.height - bounds.height) / 2);
122
		gc.drawImage(image, x, y);
123
	}
124
	
125
	private void processColoredLabel(ColoredString richLabel, GC gc, Rectangle textBounds, boolean isSelected, Font font) {
126
		String text= richLabel.getString();
127
		fTextLayout.setText(text);
128
		fTextLayout.setFont(font);
129
		
130
		// apply the styled ranges only when element is not selected
131
		StyleRange[] styleRanges= richLabel.getStyleRanges();
132
		for (int i= 0; i < styleRanges.length; i++) {
133
			StyleRange styleRange= styleRanges[i];
134
			if (isSelected) {
135
				styleRange.foreground= null;
136
				styleRange.background= null;
137
			}
138
			fTextLayout.setStyle(styleRange, styleRange.start, styleRange.start + styleRange.length - 1);
139
		}
140
		
141
		Rectangle bounds= fTextLayout.getBounds();
142
		int x= textBounds.x;
143
		int y = textBounds.y + Math.max(0, (textBounds.height - bounds.height) / 2);
144
		
145
		fTextLayout.draw(gc, x, y);
146
		fTextLayout.setText(""); // clear all ranges //$NON-NLS-1$
147
	}
148
	
149
	public void dispose() {
150
		if (fTextLayout != null) {
151
			fTextLayout.dispose();
152
			fTextLayout= null;
153
		}
154
		if (!fControl.isDisposed()) {
155
			fControl.removeListener(SWT.PaintItem, this);
156
			fControl.removeListener(SWT.EraseItem, this);
157
			fControl.removeListener(SWT.Dispose, this);
158
		}
159
	}
160
}
(-)ui/org/eclipse/jdt/internal/ui/viewsupport/JavaUILabelProvider.java (-6 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 26-35 Link Here
26
import org.eclipse.jface.viewers.ILabelProvider;
26
import org.eclipse.jface.viewers.ILabelProvider;
27
import org.eclipse.jface.viewers.ILabelProviderListener;
27
import org.eclipse.jface.viewers.ILabelProviderListener;
28
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
28
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
29
import org.eclipse.jface.viewers.StyledString;
30
import org.eclipse.jface.viewers.DecoratingStyledCellLabelProvider.IStyledLabelProvider;
29
31
30
import org.eclipse.jdt.ui.JavaElementLabels;
32
import org.eclipse.jdt.ui.JavaElementLabels;
31
33
32
public class JavaUILabelProvider implements ILabelProvider, IColorProvider, IRichLabelProvider {
34
public class JavaUILabelProvider implements ILabelProvider, IColorProvider, IStyledLabelProvider {
33
	
35
	
34
	protected ListenerList fListeners = new ListenerList();
36
	protected ListenerList fListeners = new ListenerList();
35
	
37
	
Lines 171-184 Link Here
171
		return decorateText(result, element);
173
		return decorateText(result, element);
172
	}
174
	}
173
	
175
	
174
	public ColoredString getRichTextLabel(Object element) {
176
	public StyledString getStyledText(Object element) {
175
		ColoredString string= ColoredJavaElementLabels.getTextLabel(element, evaluateTextFlags(element) | ColoredJavaElementLabels.COLORIZE);
177
		StyledString string= ColoredJavaElementLabels.getTextLabel(element, evaluateTextFlags(element) | ColoredJavaElementLabels.COLORIZE);
176
		if (string.length() == 0 && (element instanceof IStorage)) {
178
		if (string.length() == 0 && (element instanceof IStorage)) {
177
			string= new ColoredString(fStorageLabelProvider.getText(element));
179
			string= new StyledString(fStorageLabelProvider.getText(element));
178
		}
180
		}
179
		String decorated= decorateText(string.getString(), element);
181
		String decorated= decorateText(string.getString(), element);
180
		if (decorated != null) {
182
		if (decorated != null) {
181
			return ColoredJavaElementLabels.decorateColoredString(string, decorated, ColoredJavaElementLabels.DECORATIONS_STYLE);
183
			return ColoredJavaElementLabels.decorateStyledString(string, decorated, ColoredJavaElementLabels.DECORATIONS_STYLE);
182
		}
184
		}
183
		return string;
185
		return string;
184
	}
186
	}
Lines 279-282 Link Here
279
        }
281
        }
280
    }
282
    }
281
283
284
282
}
285
}
(-)ui/org/eclipse/jdt/internal/ui/viewsupport/IRichLabelProvider.java (-19 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.viewsupport;
12
13
import org.eclipse.jface.viewers.ILabelProvider;
14
15
public interface IRichLabelProvider extends ILabelProvider {
16
	
17
	ColoredString getRichTextLabel(Object object);
18
19
}
(-)ui/org/eclipse/jdt/internal/ui/viewsupport/DecoratingJavaLabelProvider.java (-35 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-20 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.viewsupport;
11
package org.eclipse.jdt.internal.ui.viewsupport;
12
12
13
import org.eclipse.jface.viewers.DecoratingLabelProvider;
14
import org.eclipse.jface.viewers.DecorationContext;
13
import org.eclipse.jface.viewers.DecorationContext;
15
import org.eclipse.jface.viewers.ILabelDecorator;
16
import org.eclipse.jface.viewers.ILabelProvider;
17
import org.eclipse.jface.viewers.LabelDecorator;
18
14
19
import org.eclipse.ui.PlatformUI;
15
import org.eclipse.ui.PlatformUI;
20
16
Lines 22-28 Link Here
22
18
23
import org.eclipse.jdt.internal.ui.packageview.HierarchicalDecorationContext;
19
import org.eclipse.jdt.internal.ui.packageview.HierarchicalDecorationContext;
24
20
25
public class DecoratingJavaLabelProvider extends DecoratingLabelProvider implements IRichLabelProvider {
21
public class DecoratingJavaLabelProvider extends ColoringLabelProvider {
26
	
22
	
27
	/**
23
	/**
28
	 * Decorating label provider for Java. Combines a JavaUILabelProvider
24
	 * Decorating label provider for Java. Combines a JavaUILabelProvider
Lines 54-60 Link Here
54
	 * @param flatPackageMode configure flat package mode
50
	 * @param flatPackageMode configure flat package mode
55
	 */
51
	 */
56
	public DecoratingJavaLabelProvider(JavaUILabelProvider labelProvider, boolean errorTick, boolean flatPackageMode) {
52
	public DecoratingJavaLabelProvider(JavaUILabelProvider labelProvider, boolean errorTick, boolean flatPackageMode) {
57
		super(labelProvider, PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator());
53
		super(labelProvider, PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator(), DecorationContext.DEFAULT_CONTEXT);
58
		if (errorTick) {
54
		if (errorTick) {
59
			labelProvider.addLabelDecorator(new ProblemsLabelDecorator(null));
55
			labelProvider.addLabelDecorator(new ProblemsLabelDecorator(null));
60
		}
56
		}
Lines 73-104 Link Here
73
		}
69
		}
74
	}
70
	}
75
71
76
	/* (non-Javadoc)
77
	 * @see org.eclipse.jdt.internal.ui.viewsupport.IRichLabelProvider#getRichTextLabel(Object)
78
	 */
79
	public ColoredString getRichTextLabel(Object element) {
80
		ILabelProvider labelProvider= getLabelProvider();
81
		if (labelProvider instanceof IRichLabelProvider) {
82
			// get a rich label from the label decorator
83
			IRichLabelProvider richLabelProvider= (IRichLabelProvider) labelProvider;
84
			ColoredString richLabel= richLabelProvider.getRichTextLabel(element);
85
			if (richLabel != null) {
86
				String decorated= null;
87
				ILabelDecorator labelDecorator= getLabelDecorator();
88
				if (labelDecorator != null) {
89
					if (labelDecorator instanceof LabelDecorator) {
90
						decorated= ((LabelDecorator) labelDecorator).decorateText(richLabel.getString(), element, getDecorationContext());
91
					} else {
92
						decorated= labelDecorator.decorateText(richLabel.getString(), element);
93
					}
94
				}
95
				if (decorated != null) {
96
					return ColoredJavaElementLabels.decorateColoredString(richLabel, decorated, ColoredJavaElementLabels.DECORATIONS_STYLE);
97
				}
98
				return richLabel;
99
			}
100
		}
101
		return null;
102
	}
103
104
}
72
}
(-)ui/org/eclipse/jdt/internal/ui/viewsupport/ColoredViewersManager.java (-11 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 16-22 Link Here
16
16
17
import org.eclipse.swt.widgets.Display;
17
import org.eclipse.swt.widgets.Display;
18
18
19
import org.eclipse.jface.resource.ColorRegistry;
19
import org.eclipse.jface.preference.JFacePreferences;
20
import org.eclipse.jface.resource.JFaceResources;
20
import org.eclipse.jface.resource.JFaceResources;
21
import org.eclipse.jface.util.IPropertyChangeListener;
21
import org.eclipse.jface.util.IPropertyChangeListener;
22
import org.eclipse.jface.util.PropertyChangeEvent;
22
import org.eclipse.jface.util.PropertyChangeEvent;
Lines 31-39 Link Here
31
	 */
31
	 */
32
	public static final String PREF_COLORED_LABELS= "colored_labels_in_views"; //$NON-NLS-1$
32
	public static final String PREF_COLORED_LABELS= "colored_labels_in_views"; //$NON-NLS-1$
33
	
33
	
34
	public static final String QUALIFIER_COLOR_NAME= "org.eclipse.jdt.ui.ColoredLabels.qualifier"; //$NON-NLS-1$
34
	public static final String QUALIFIER_COLOR_NAME= JFacePreferences.QUALIFIER_COLOR;
35
	public static final String DECORATIONS_COLOR_NAME= "org.eclipse.jdt.ui.ColoredLabels.decorations"; //$NON-NLS-1$
35
	public static final String DECORATIONS_COLOR_NAME= JFacePreferences.DECORATIONS_COLOR;
36
	public static final String COUNTER_COLOR_NAME= "org.eclipse.jdt.ui.ColoredLabels.counter"; //$NON-NLS-1$
36
	public static final String COUNTER_COLOR_NAME= JFacePreferences.COUNTER_COLOR;
37
	
37
	public static final String INHERITED_COLOR_NAME= "org.eclipse.jdt.ui.ColoredLabels.inherited"; //$NON-NLS-1$
38
	public static final String INHERITED_COLOR_NAME= "org.eclipse.jdt.ui.ColoredLabels.inherited"; //$NON-NLS-1$
38
	
39
	
39
	public static final String HIGHLIGHT_BG_COLOR_NAME= "org.eclipse.jdt.ui.ColoredLabels.match_highlight"; //$NON-NLS-1$
40
	public static final String HIGHLIGHT_BG_COLOR_NAME= "org.eclipse.jdt.ui.ColoredLabels.match_highlight"; //$NON-NLS-1$
Lines 42-53 Link Here
42
	private static ColoredViewersManager fgInstance= new ColoredViewersManager();
43
	private static ColoredViewersManager fgInstance= new ColoredViewersManager();
43
	
44
	
44
	private Set fManagedLabelProviders;
45
	private Set fManagedLabelProviders;
45
	
46
		
46
	private ColorRegistry fColorRegisty;
47
	
48
	public ColoredViewersManager() {
47
	public ColoredViewersManager() {
49
		fManagedLabelProviders= new HashSet();
48
		fManagedLabelProviders= new HashSet();
50
		fColorRegisty= JFaceResources.getColorRegistry();
51
	}
49
	}
52
	
50
	
53
	public void installColoredLabels(ColoringLabelProvider labelProvider) {
51
	public void installColoredLabels(ColoringLabelProvider labelProvider) {
Lines 57-63 Link Here
57
		if (fManagedLabelProviders.isEmpty()) {
55
		if (fManagedLabelProviders.isEmpty()) {
58
			// first lp installed
56
			// first lp installed
59
			PreferenceConstants.getPreferenceStore().addPropertyChangeListener(this);
57
			PreferenceConstants.getPreferenceStore().addPropertyChangeListener(this);
60
			fColorRegisty.addListener(this);
58
			JFaceResources.getColorRegistry().addListener(this);
61
		}
59
		}
62
		fManagedLabelProviders.add(labelProvider);
60
		fManagedLabelProviders.add(labelProvider);
63
	}
61
	}
Lines 68-74 Link Here
68
		
66
		
69
		if (fManagedLabelProviders.isEmpty()) {
67
		if (fManagedLabelProviders.isEmpty()) {
70
			PreferenceConstants.getPreferenceStore().removePropertyChangeListener(this);
68
			PreferenceConstants.getPreferenceStore().removePropertyChangeListener(this);
71
			fColorRegisty.removeListener(this);
69
			JFaceResources.getColorRegistry().removeListener(this);
72
			// last viewer uninstalled
70
			// last viewer uninstalled
73
		}
71
		}
74
	}
72
	}
(-)ui/org/eclipse/jdt/internal/ui/viewsupport/ColoredJavaElementLabels.java (-75 / +51 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 15-24 Link Here
15
import org.eclipse.core.resources.IProject;
15
import org.eclipse.core.resources.IProject;
16
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.resources.IResource;
17
17
18
import org.eclipse.swt.graphics.TextStyle;
18
import org.eclipse.jface.viewers.StyledString;
19
19
import org.eclipse.jface.viewers.StyledString.Style;
20
import org.eclipse.jface.resource.ColorRegistry;
21
import org.eclipse.jface.resource.JFaceResources;
22
20
23
import org.eclipse.ui.model.IWorkbenchAdapter;
21
import org.eclipse.ui.model.IWorkbenchAdapter;
24
22
Lines 54-90 Link Here
54
import org.eclipse.jdt.internal.ui.JavaPlugin;
52
import org.eclipse.jdt.internal.ui.JavaPlugin;
55
import org.eclipse.jdt.internal.ui.JavaUIMessages;
53
import org.eclipse.jdt.internal.ui.JavaUIMessages;
56
import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer;
54
import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer;
57
import org.eclipse.jdt.internal.ui.viewsupport.ColoredString.Style;
58
55
59
public class ColoredJavaElementLabels {
56
public class ColoredJavaElementLabels {
60
	
61
	public static class DefaultStyle extends Style {
62
		private final String fForegroundColorName;
63
		private final String fBackgroundColorName;
64
65
		public DefaultStyle(String foregroundColorName, String backgroundColorName) {
66
			fForegroundColorName= foregroundColorName;	
67
			fBackgroundColorName= backgroundColorName;
68
		}
69
		
70
		public void applyStyles(TextStyle textStyle) {
71
			ColorRegistry colorRegistry= JFaceResources.getColorRegistry();
72
			if (fForegroundColorName != null) {
73
				textStyle.foreground= colorRegistry.get(fForegroundColorName);
74
			}
75
			if (fBackgroundColorName != null) {
76
				textStyle.background= colorRegistry.get(fBackgroundColorName);
77
			}
78
		}
79
	}
80
81
57
82
	public static final Style QUALIFIER_STYLE= new DefaultStyle(ColoredViewersManager.QUALIFIER_COLOR_NAME, null); 
58
	public static final Style QUALIFIER_STYLE= StyledString.QUALIFIER_STYLE; 
83
	public static final Style COUNTER_STYLE= new DefaultStyle(ColoredViewersManager.COUNTER_COLOR_NAME, null); 
59
	public static final Style COUNTER_STYLE= StyledString.COUNTER_STYLE; 
84
	public static final Style DECORATIONS_STYLE= new DefaultStyle(ColoredViewersManager.DECORATIONS_COLOR_NAME, null); 
60
	public static final Style DECORATIONS_STYLE= StyledString.DECORATIONS_STYLE; 
85
	
61
	
86
	public static final Style HIGHLIGHT_STYLE= new DefaultStyle(null, ColoredViewersManager.HIGHLIGHT_BG_COLOR_NAME);
62
	public static final Style HIGHLIGHT_STYLE= StyledString.createColorRegistryStyle(null, ColoredViewersManager.HIGHLIGHT_BG_COLOR_NAME);
87
	public static final Style HIGHLIGHT_WRITE_STYLE= new DefaultStyle(null, ColoredViewersManager.HIGHLIGHT_WRITE_BG_COLOR_NAME);
63
	public static final Style HIGHLIGHT_WRITE_STYLE= StyledString.createColorRegistryStyle(null, ColoredViewersManager.HIGHLIGHT_WRITE_BG_COLOR_NAME);
88
	
64
	
89
	private static final Style APPENDED_TYPE_STYLE= DECORATIONS_STYLE; 
65
	private static final Style APPENDED_TYPE_STYLE= DECORATIONS_STYLE; 
90
	
66
	
Lines 104-119 Link Here
104
	 * @param flags The rendering flags
80
	 * @param flags The rendering flags
105
	 * @return Returns the label or the empty string if the object type is not supported.
81
	 * @return Returns the label or the empty string if the object type is not supported.
106
	 */
82
	 */
107
	public static ColoredString getTextLabel(Object obj, long flags) {
83
	public static StyledString getTextLabel(Object obj, long flags) {
108
		if (obj instanceof IJavaElement) {
84
		if (obj instanceof IJavaElement) {
109
			return getElementLabel((IJavaElement) obj, flags);
85
			return getElementLabel((IJavaElement) obj, flags);
110
		} else if (obj instanceof IResource) {
86
		} else if (obj instanceof IResource) {
111
			return new ColoredString(((IResource) obj).getName());
87
			return new StyledString(((IResource) obj).getName());
112
		} else if (obj instanceof ClassPathContainer) {
88
		} else if (obj instanceof ClassPathContainer) {
113
			ClassPathContainer container= (ClassPathContainer) obj;
89
			ClassPathContainer container= (ClassPathContainer) obj;
114
			return getContainerEntryLabel(container.getClasspathEntry().getPath(), container.getJavaProject());
90
			return getContainerEntryLabel(container.getClasspathEntry().getPath(), container.getJavaProject());
115
		}
91
		}
116
		return new ColoredString(JavaElementLabels.getTextLabel(obj, flags));
92
		return new StyledString(JavaElementLabels.getTextLabel(obj, flags));
117
	}
93
	}
118
				
94
				
119
	/**
95
	/**
Lines 122-129 Link Here
122
	 * @param flags The rendering flags.
98
	 * @param flags The rendering flags.
123
	 * @return the label of the Java element
99
	 * @return the label of the Java element
124
	 */
100
	 */
125
	public static ColoredString getElementLabel(IJavaElement element, long flags) {
101
	public static StyledString getElementLabel(IJavaElement element, long flags) {
126
		ColoredString result= new ColoredString();
102
		StyledString result= new StyledString();
127
		getElementLabel(element, flags, result);
103
		getElementLabel(element, flags, result);
128
		return result;
104
		return result;
129
	}
105
	}
Lines 134-140 Link Here
134
	 * @param flags The rendering flags.
110
	 * @param flags The rendering flags.
135
	 * @param result The buffer to append the resulting label to.
111
	 * @param result The buffer to append the resulting label to.
136
	 */
112
	 */
137
	public static void getElementLabel(IJavaElement element, long flags, ColoredString result) {
113
	public static void getElementLabel(IJavaElement element, long flags, StyledString result) {
138
		int type= element.getElementType();
114
		int type= element.getElementType();
139
		IPackageFragmentRoot root= null;
115
		IPackageFragmentRoot root= null;
140
		
116
		
Lines 199-210 Link Here
199
	}
175
	}
200
176
201
	/**
177
	/**
202
	 * Appends the label for a method to a {@link ColoredString}. Considers the M_* flags.
178
	 * Appends the label for a method to a {@link StyledString}. Considers the M_* flags.
203
	 * 	@param method The element to render.
179
	 * 	@param method The element to render.
204
	 * @param flags The rendering flags. Flags with names starting with 'M_' are considered.
180
	 * @param flags The rendering flags. Flags with names starting with 'M_' are considered.
205
	 * @param result The buffer to append the resulting label to.
181
	 * @param result The buffer to append the resulting label to.
206
	 */		
182
	 */		
207
	public static void getMethodLabel(IMethod method, long flags, ColoredString result) {
183
	public static void getMethodLabel(IMethod method, long flags, StyledString result) {
208
		try {
184
		try {
209
			BindingKey resolvedKey= getFlag(flags, JavaElementLabels.USE_RESOLVED) && method.isResolved() ? new BindingKey(method.getKey()) : null;
185
			BindingKey resolvedKey= getFlag(flags, JavaElementLabels.USE_RESOLVED) && method.isResolved() ? new BindingKey(method.getKey()) : null;
210
			String resolvedSig= (resolvedKey != null) ? resolvedKey.toSignature() : null;
186
			String resolvedSig= (resolvedKey != null) ? resolvedKey.toSignature() : null;
Lines 392-402 Link Here
392
		}
368
		}
393
	}
369
	}
394
370
395
	private static void getCategoryLabel(IMember member, long flags, ColoredString result) throws JavaModelException {
371
	private static void getCategoryLabel(IMember member, long flags, StyledString result) throws JavaModelException {
396
		String[] categories= member.getCategories();
372
		String[] categories= member.getCategories();
397
		if (categories.length > 0) {
373
		if (categories.length > 0) {
398
			int offset= result.length();
374
			int offset= result.length();
399
			ColoredString categoriesBuf= new ColoredString();
375
			StyledString categoriesBuf= new StyledString();
400
			for (int i= 0; i < categories.length; i++) {
376
			for (int i= 0; i < categories.length; i++) {
401
				if (i > 0)
377
				if (i > 0)
402
					categoriesBuf.append(JavaUIMessages.JavaElementLabels_category_separator_string);
378
					categoriesBuf.append(JavaUIMessages.JavaElementLabels_category_separator_string);
Lines 416-422 Link Here
416
	 * @param flags flags with render options
392
	 * @param flags flags with render options
417
	 * @param result the resulting string buffer
393
	 * @param result the resulting string buffer
418
	 */
394
	 */
419
	private static void getTypeParametersLabel(ITypeParameter[] typeParameters, long flags, ColoredString result) {
395
	private static void getTypeParametersLabel(ITypeParameter[] typeParameters, long flags, StyledString result) {
420
		if (typeParameters.length > 0) {
396
		if (typeParameters.length > 0) {
421
			result.append('<');
397
			result.append('<');
422
			for (int i = 0; i < typeParameters.length; i++) {
398
			for (int i = 0; i < typeParameters.length; i++) {
Lines 430-441 Link Here
430
	}
406
	}
431
	
407
	
432
	/**
408
	/**
433
	 * Appends the label for a field to a {@link ColoredString}. Considers the F_* flags.
409
	 * Appends the label for a field to a {@link StyledString}. Considers the F_* flags.
434
	 * 	@param field The element to render.
410
	 * 	@param field The element to render.
435
	 * @param flags The rendering flags. Flags with names starting with 'F_' are considered.
411
	 * @param flags The rendering flags. Flags with names starting with 'F_' are considered.
436
	 * @param result The buffer to append the resulting label to.
412
	 * @param result The buffer to append the resulting label to.
437
	 */	
413
	 */	
438
	public static void getFieldLabel(IField field, long flags, ColoredString result) {
414
	public static void getFieldLabel(IField field, long flags, StyledString result) {
439
		try {
415
		try {
440
			
416
			
441
			if (getFlag(flags, JavaElementLabels.F_PRE_TYPE_SIGNATURE) && field.exists() && !Flags.isEnum(field.getFlags())) {
417
			if (getFlag(flags, JavaElementLabels.F_PRE_TYPE_SIGNATURE) && field.exists() && !Flags.isEnum(field.getFlags())) {
Lines 487-498 Link Here
487
	}
463
	}
488
	
464
	
489
	/**
465
	/**
490
	 * Appends the label for a local variable to a {@link ColoredString}.
466
	 * Appends the label for a local variable to a {@link StyledString}.
491
	 * 	@param localVariable The element to render.
467
	 * 	@param localVariable The element to render.
492
	 * @param flags The rendering flags. Flags with names starting with 'F_' are considered.
468
	 * @param flags The rendering flags. Flags with names starting with 'F_' are considered.
493
	 * @param result The buffer to append the resulting label to.
469
	 * @param result The buffer to append the resulting label to.
494
	 */	
470
	 */	
495
	public static void getLocalVariableLabel(ILocalVariable localVariable, long flags, ColoredString result) {
471
	public static void getLocalVariableLabel(ILocalVariable localVariable, long flags, StyledString result) {
496
		if (getFlag(flags, JavaElementLabels.F_PRE_TYPE_SIGNATURE)) {
472
		if (getFlag(flags, JavaElementLabels.F_PRE_TYPE_SIGNATURE)) {
497
			getTypeSignatureLabel(localVariable.getTypeSignature(), flags, result);
473
			getTypeSignatureLabel(localVariable.getTypeSignature(), flags, result);
498
			result.append(' ');
474
			result.append(' ');
Lines 522-533 Link Here
522
	}
498
	}
523
	
499
	
524
	/**
500
	/**
525
	 * Appends the label for a initializer to a {@link ColoredString}. Considers the I_* flags.
501
	 * Appends the label for a initializer to a {@link StyledString}. Considers the I_* flags.
526
	 * 	@param initializer The element to render.
502
	 * 	@param initializer The element to render.
527
	 * @param flags The rendering flags. Flags with names starting with 'I_' are considered.
503
	 * @param flags The rendering flags. Flags with names starting with 'I_' are considered.
528
	 * @param result The buffer to append the resulting label to.
504
	 * @param result The buffer to append the resulting label to.
529
	 */	
505
	 */	
530
	public static void getInitializerLabel(IInitializer initializer, long flags, ColoredString result) {
506
	public static void getInitializerLabel(IInitializer initializer, long flags, StyledString result) {
531
		// qualification
507
		// qualification
532
		if (getFlag(flags, JavaElementLabels.I_FULLY_QUALIFIED)) {
508
		if (getFlag(flags, JavaElementLabels.I_FULLY_QUALIFIED)) {
533
			getTypeLabel(initializer.getDeclaringType(), JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS), result);
509
			getTypeLabel(initializer.getDeclaringType(), JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS), result);
Lines 546-552 Link Here
546
		}
522
		}
547
	}
523
	}
548
	
524
	
549
	private static void getTypeSignatureLabel(String typeSig, long flags, ColoredString result) {
525
	private static void getTypeSignatureLabel(String typeSig, long flags, StyledString result) {
550
		int sigKind= Signature.getTypeSignatureKind(typeSig);
526
		int sigKind= Signature.getTypeSignatureKind(typeSig);
551
		switch (sigKind) {
527
		switch (sigKind) {
552
			case Signature.BASE_TYPE_SIGNATURE:
528
			case Signature.BASE_TYPE_SIGNATURE:
Lines 590-596 Link Here
590
		}
566
		}
591
	}
567
	}
592
	
568
	
593
	private static void getTypeArgumentSignaturesLabel(String[] typeArgsSig, long flags, ColoredString result) {
569
	private static void getTypeArgumentSignaturesLabel(String[] typeArgsSig, long flags, StyledString result) {
594
		if (typeArgsSig.length > 0) {
570
		if (typeArgsSig.length > 0) {
595
			result.append('<');
571
			result.append('<');
596
			for (int i = 0; i < typeArgsSig.length; i++) {
572
			for (int i = 0; i < typeArgsSig.length; i++) {
Lines 609-615 Link Here
609
	 * @param flags flags with render options
585
	 * @param flags flags with render options
610
	 * @param result the resulting string buffer
586
	 * @param result the resulting string buffer
611
	 */
587
	 */
612
	private static void getTypeParameterSignaturesLabel(String[] typeParamSigs, long flags, ColoredString result) {
588
	private static void getTypeParameterSignaturesLabel(String[] typeParamSigs, long flags, StyledString result) {
613
		if (typeParamSigs.length > 0) {
589
		if (typeParamSigs.length > 0) {
614
			result.append('<');
590
			result.append('<');
615
			for (int i = 0; i < typeParamSigs.length; i++) {
591
			for (int i = 0; i < typeParamSigs.length; i++) {
Lines 624-635 Link Here
624
	
600
	
625
601
626
	/**
602
	/**
627
	 * Appends the label for a type to a {@link ColoredString}. Considers the T_* flags.
603
	 * Appends the label for a type to a {@link StyledString}. Considers the T_* flags.
628
	 * 	@param type The element to render.
604
	 * 	@param type The element to render.
629
	 * @param flags The rendering flags. Flags with names starting with 'T_' are considered.
605
	 * @param flags The rendering flags. Flags with names starting with 'T_' are considered.
630
	 * @param result The buffer to append the resulting label to.
606
	 * @param result The buffer to append the resulting label to.
631
	 */		
607
	 */		
632
	public static void getTypeLabel(IType type, long flags, ColoredString result) {
608
	public static void getTypeLabel(IType type, long flags, StyledString result) {
633
		
609
		
634
		if (getFlag(flags, JavaElementLabels.T_FULLY_QUALIFIED)) {
610
		if (getFlag(flags, JavaElementLabels.T_FULLY_QUALIFIED)) {
635
			IPackageFragment pack= type.getPackageFragment();
611
			IPackageFragment pack= type.getPackageFragment();
Lines 722-733 Link Here
722
	}
698
	}
723
699
724
	/**
700
	/**
725
	 * Appends the label for a import container, import or package declaration to a {@link ColoredString}. Considers the D_* flags.
701
	 * Appends the label for a import container, import or package declaration to a {@link StyledString}. Considers the D_* flags.
726
	 * 	@param declaration The element to render.
702
	 * 	@param declaration The element to render.
727
	 * @param flags The rendering flags. Flags with names starting with 'D_' are considered.
703
	 * @param flags The rendering flags. Flags with names starting with 'D_' are considered.
728
	 * @param result The buffer to append the resulting label to.
704
	 * @param result The buffer to append the resulting label to.
729
	 */	
705
	 */	
730
	public static void getDeclarationLabel(IJavaElement declaration, long flags, ColoredString result) {
706
	public static void getDeclarationLabel(IJavaElement declaration, long flags, StyledString result) {
731
		if (getFlag(flags, JavaElementLabels.D_QUALIFIED)) {
707
		if (getFlag(flags, JavaElementLabels.D_QUALIFIED)) {
732
			IJavaElement openable= (IJavaElement) declaration.getOpenable();
708
			IJavaElement openable= (IJavaElement) declaration.getOpenable();
733
			if (openable != null) {
709
			if (openable != null) {
Lines 755-766 Link Here
755
	}	
731
	}	
756
	
732
	
757
	/**
733
	/**
758
	 * Appends the label for a class file to a {@link ColoredString}. Considers the CF_* flags.
734
	 * Appends the label for a class file to a {@link StyledString}. Considers the CF_* flags.
759
	 * 	@param classFile The element to render.
735
	 * 	@param classFile The element to render.
760
	 * @param flags The rendering flags. Flags with names starting with 'CF_' are considered.
736
	 * @param flags The rendering flags. Flags with names starting with 'CF_' are considered.
761
	 * @param result The buffer to append the resulting label to.
737
	 * @param result The buffer to append the resulting label to.
762
	 */	
738
	 */	
763
	public static void getClassFileLabel(IClassFile classFile, long flags, ColoredString result) {
739
	public static void getClassFileLabel(IClassFile classFile, long flags, StyledString result) {
764
		if (getFlag(flags, JavaElementLabels.CF_QUALIFIED)) {
740
		if (getFlag(flags, JavaElementLabels.CF_QUALIFIED)) {
765
			IPackageFragment pack= (IPackageFragment) classFile.getParent();
741
			IPackageFragment pack= (IPackageFragment) classFile.getParent();
766
			if (!pack.isDefaultPackage()) {
742
			if (!pack.isDefaultPackage()) {
Lines 781-792 Link Here
781
	}
757
	}
782
758
783
	/**
759
	/**
784
	 * Appends the label for a compilation unit to a {@link ColoredString}. Considers the CU_* flags.
760
	 * Appends the label for a compilation unit to a {@link StyledString}. Considers the CU_* flags.
785
	 * 	@param cu The element to render.
761
	 * 	@param cu The element to render.
786
	 * @param flags The rendering flags. Flags with names starting with 'CU_' are considered.
762
	 * @param flags The rendering flags. Flags with names starting with 'CU_' are considered.
787
	 * @param result The buffer to append the resulting label to.
763
	 * @param result The buffer to append the resulting label to.
788
	 */
764
	 */
789
	public static void getCompilationUnitLabel(ICompilationUnit cu, long flags, ColoredString result) {
765
	public static void getCompilationUnitLabel(ICompilationUnit cu, long flags, StyledString result) {
790
		if (getFlag(flags, JavaElementLabels.CU_QUALIFIED)) {
766
		if (getFlag(flags, JavaElementLabels.CU_QUALIFIED)) {
791
			IPackageFragment pack= (IPackageFragment) cu.getParent();
767
			IPackageFragment pack= (IPackageFragment) cu.getParent();
792
			if (!pack.isDefaultPackage()) {
768
			if (!pack.isDefaultPackage()) {
Lines 807-818 Link Here
807
	}
783
	}
808
784
809
	/**
785
	/**
810
	 * Appends the label for a package fragment to a {@link ColoredString}. Considers the P_* flags.
786
	 * Appends the label for a package fragment to a {@link StyledString}. Considers the P_* flags.
811
	 * 	@param pack The element to render.
787
	 * 	@param pack The element to render.
812
	 * @param flags The rendering flags. Flags with names starting with P_' are considered.
788
	 * @param flags The rendering flags. Flags with names starting with P_' are considered.
813
	 * @param result The buffer to append the resulting label to.
789
	 * @param result The buffer to append the resulting label to.
814
	 */	
790
	 */	
815
	public static void getPackageFragmentLabel(IPackageFragment pack, long flags, ColoredString result) {
791
	public static void getPackageFragmentLabel(IPackageFragment pack, long flags, StyledString result) {
816
		if (getFlag(flags, JavaElementLabels.P_QUALIFIED)) {
792
		if (getFlag(flags, JavaElementLabels.P_QUALIFIED)) {
817
			getPackageFragmentRootLabel((IPackageFragmentRoot) pack.getParent(), JavaElementLabels.ROOT_QUALIFIED, result);
793
			getPackageFragmentRootLabel((IPackageFragmentRoot) pack.getParent(), JavaElementLabels.ROOT_QUALIFIED, result);
818
			result.append('/');
794
			result.append('/');
Lines 837-855 Link Here
837
	}
813
	}
838
814
839
	/**
815
	/**
840
	 * Appends the label for a package fragment root to a {@link ColoredString}. Considers the ROOT_* flags.
816
	 * Appends the label for a package fragment root to a {@link StyledString}. Considers the ROOT_* flags.
841
	 * 	@param root The element to render.
817
	 * 	@param root The element to render.
842
	 * @param flags The rendering flags. Flags with names starting with ROOT_' are considered.
818
	 * @param flags The rendering flags. Flags with names starting with ROOT_' are considered.
843
	 * @param result The buffer to append the resulting label to.
819
	 * @param result The buffer to append the resulting label to.
844
	 */	
820
	 */	
845
	public static void getPackageFragmentRootLabel(IPackageFragmentRoot root, long flags, ColoredString result) {
821
	public static void getPackageFragmentRootLabel(IPackageFragmentRoot root, long flags, StyledString result) {
846
		if (root.isArchive())
822
		if (root.isArchive())
847
			getArchiveLabel(root, flags, result);
823
			getArchiveLabel(root, flags, result);
848
		else
824
		else
849
			getFolderLabel(root, flags, result);
825
			getFolderLabel(root, flags, result);
850
	}
826
	}
851
	
827
	
852
	private static void getArchiveLabel(IPackageFragmentRoot root, long flags, ColoredString result) {
828
	private static void getArchiveLabel(IPackageFragmentRoot root, long flags, StyledString result) {
853
		// Handle variables different	
829
		// Handle variables different	
854
		if (getFlag(flags, JavaElementLabels.ROOT_VARIABLE) && getVariableLabel(root, flags, result))
830
		if (getFlag(flags, JavaElementLabels.ROOT_VARIABLE) && getVariableLabel(root, flags, result))
855
			return;
831
			return;
Lines 860-866 Link Here
860
			getInternalArchiveLabel(root, flags, result);
836
			getInternalArchiveLabel(root, flags, result);
861
	}
837
	}
862
	
838
	
863
	private static boolean getVariableLabel(IPackageFragmentRoot root, long flags, ColoredString result) {
839
	private static boolean getVariableLabel(IPackageFragmentRoot root, long flags, StyledString result) {
864
		try {
840
		try {
865
			IClasspathEntry rawEntry= root.getRawClasspathEntry();
841
			IClasspathEntry rawEntry= root.getRawClasspathEntry();
866
			if (rawEntry != null && rawEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
842
			if (rawEntry != null && rawEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
Lines 898-904 Link Here
898
		return false;
874
		return false;
899
	}
875
	}
900
876
901
	private static void getExternalArchiveLabel(IPackageFragmentRoot root, long flags, ColoredString result) {
877
	private static void getExternalArchiveLabel(IPackageFragmentRoot root, long flags, StyledString result) {
902
		IPath path= root.getPath();
878
		IPath path= root.getPath();
903
		if (getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED)) {
879
		if (getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED)) {
904
			int segements= path.segmentCount();
880
			int segements= path.segmentCount();
Lines 920-926 Link Here
920
		}
896
		}
921
	}
897
	}
922
898
923
	private static void getInternalArchiveLabel(IPackageFragmentRoot root, long flags, ColoredString result) {
899
	private static void getInternalArchiveLabel(IPackageFragmentRoot root, long flags, StyledString result) {
924
		IResource resource= root.getResource();
900
		IResource resource= root.getResource();
925
		boolean rootQualified= getFlag(flags, JavaElementLabels.ROOT_QUALIFIED);
901
		boolean rootQualified= getFlag(flags, JavaElementLabels.ROOT_QUALIFIED);
926
		boolean referencedQualified= getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED) && isReferenced(root);
902
		boolean referencedQualified= getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED) && isReferenced(root);
Lines 944-950 Link Here
944
		}
920
		}
945
	}
921
	}
946
922
947
	private static void getFolderLabel(IPackageFragmentRoot root, long flags, ColoredString result) {
923
	private static void getFolderLabel(IPackageFragmentRoot root, long flags, StyledString result) {
948
		IResource resource= root.getResource();
924
		IResource resource= root.getResource();
949
		boolean rootQualified= getFlag(flags, JavaElementLabels.ROOT_QUALIFIED);
925
		boolean rootQualified= getFlag(flags, JavaElementLabels.ROOT_QUALIFIED);
950
		boolean referencedQualified= getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED) && isReferenced(root);
926
		boolean referencedQualified= getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED) && isReferenced(root);
Lines 1000-1006 Link Here
1000
	 * @param project The project the container is resolved in.
976
	 * @param project The project the container is resolved in.
1001
	 * @return Returns the label of the classpath container
977
	 * @return Returns the label of the classpath container
1002
	 */
978
	 */
1003
	public static ColoredString getContainerEntryLabel(IPath containerPath, IJavaProject project) {
979
	public static StyledString getContainerEntryLabel(IPath containerPath, IJavaProject project) {
1004
		try {
980
		try {
1005
			IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, project);
981
			IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, project);
1006
			String description= null;
982
			String description= null;
Lines 1014-1020 Link Here
1014
				}
990
				}
1015
			}
991
			}
1016
			if (description != null) {
992
			if (description != null) {
1017
				ColoredString str= new ColoredString(description);
993
				StyledString str= new StyledString(description);
1018
				if (containerPath.segmentCount() > 0 && JavaRuntime.JRE_CONTAINER.equals(containerPath.segment(0))) {
994
				if (containerPath.segmentCount() > 0 && JavaRuntime.JRE_CONTAINER.equals(containerPath.segment(0))) {
1019
					int index= description.indexOf('[');
995
					int index= description.indexOf('[');
1020
					if (index != -1) {
996
					if (index != -1) {
Lines 1026-1042 Link Here
1026
		} catch (JavaModelException e) {
1002
		} catch (JavaModelException e) {
1027
			// ignore
1003
			// ignore
1028
		}
1004
		}
1029
		return new ColoredString(containerPath.toString());
1005
		return new StyledString(containerPath.toString());
1030
	}
1006
	}
1031
1007
1032
	public static ColoredString decorateColoredString(ColoredString string, String decorated, Style color) {
1008
	public static StyledString decorateStyledString(StyledString string, String decorated, Style color) {
1033
		String label= string.getString();
1009
		String label= string.getString();
1034
		int originalStart= decorated.indexOf(label);
1010
		int originalStart= decorated.indexOf(label);
1035
		if (originalStart == -1) {
1011
		if (originalStart == -1) {
1036
			return new ColoredString(decorated); // the decorator did something wild
1012
			return new StyledString(decorated); // the decorator did something wild
1037
		}
1013
		}
1038
		if (originalStart > 0) {
1014
		if (originalStart > 0) {
1039
			ColoredString newString= new ColoredString(decorated.substring(0, originalStart), color);
1015
			StyledString newString= new StyledString(decorated.substring(0, originalStart), color);
1040
			newString.append(string);
1016
			newString.append(string);
1041
			string= newString;
1017
			string= newString;
1042
		}
1018
		}
(-)ui/org/eclipse/jdt/internal/ui/viewsupport/ColoringLabelProvider.java (-72 / +13 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-53 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.viewsupport;
11
package org.eclipse.jdt.internal.ui.viewsupport;
12
12
13
import org.eclipse.swt.custom.StyleRange;
14
import org.eclipse.swt.graphics.Color;
15
import org.eclipse.swt.graphics.Font;
16
import org.eclipse.swt.graphics.Image;
17
18
import org.eclipse.jface.viewers.ColumnViewer;
13
import org.eclipse.jface.viewers.ColumnViewer;
19
import org.eclipse.jface.viewers.IColorProvider;
14
import org.eclipse.jface.viewers.DecoratingStyledCellLabelProvider;
20
import org.eclipse.jface.viewers.IFontProvider;
15
import org.eclipse.jface.viewers.IDecorationContext;
16
import org.eclipse.jface.viewers.ILabelDecorator;
21
import org.eclipse.jface.viewers.ILabelProvider;
17
import org.eclipse.jface.viewers.ILabelProvider;
22
import org.eclipse.jface.viewers.ILabelProviderListener;
23
import org.eclipse.jface.viewers.SimpleStyledCellLabelProvider;
24
import org.eclipse.jface.viewers.ViewerColumn;
18
import org.eclipse.jface.viewers.ViewerColumn;
25
19
26
public class ColoringLabelProvider extends SimpleStyledCellLabelProvider implements ILabelProvider {
20
public class ColoringLabelProvider extends DecoratingStyledCellLabelProvider implements ILabelProvider {
27
	
28
	private ILabelProvider fLabelProvider;
29
	
21
	
30
	public ColoringLabelProvider(ILabelProvider labelProvider) {
22
	public ColoringLabelProvider(IStyledLabelProvider labelProvider) {
31
		fLabelProvider= labelProvider;
23
		super(labelProvider);
32
	}
24
	}
33
	
25
	
26
	public ColoringLabelProvider(IStyledLabelProvider labelProvider, ILabelDecorator decorator, IDecorationContext decorationContext) {
27
		super(labelProvider, decorator, decorationContext);
28
	}
29
34
	public void initialize(ColumnViewer viewer, ViewerColumn column) {
30
	public void initialize(ColumnViewer viewer, ViewerColumn column) {
35
		ColoredViewersManager.install(this);
31
		ColoredViewersManager.install(this);
36
		setOwnerDrawEnabled(ColoredViewersManager.showColoredLabels());
32
		setOwnerDrawEnabled(ColoredViewersManager.showColoredLabels());
37
		
33
		
38
		super.initialize(viewer, column);
34
		super.initialize(viewer, column);
39
	}
35
	}
40
	
36
		
41
	public void addListener(ILabelProviderListener listener) {
42
		super.addListener(listener);
43
		fLabelProvider.addListener(listener);
44
	}
45
	
46
	public void removeListener(ILabelProviderListener listener) {
47
		super.removeListener(listener);
48
		fLabelProvider.removeListener(listener);
49
	}
50
	
51
	public void dispose() {
37
	public void dispose() {
52
		super.dispose();
38
		super.dispose();
53
		ColoredViewersManager.uninstall(this);
39
		ColoredViewersManager.uninstall(this);
Lines 68-120 Link Here
68
		}
54
		}
69
	}
55
	}
70
	
56
	
71
	protected LabelPresentationInfo getLabelPresentationInfo(Object element) {
72
		Image image= fLabelProvider.getImage(element);
73
		Font defaultFont= null;
74
		
75
		if (fLabelProvider instanceof IFontProvider) {
76
			IFontProvider fontProvider= (IFontProvider) fLabelProvider;
77
			defaultFont= fontProvider.getFont(element);
78
		}
79
		Color foreground= null;
80
		Color background= null;
81
		if (fLabelProvider instanceof IColorProvider) {
82
			IColorProvider colorProvider= (IColorProvider) fLabelProvider;
83
			foreground= colorProvider.getForeground(element);
84
			background= colorProvider.getBackground(element);
85
		}
86
		String text;
87
		StyleRange[] ranges;
88
		ColoredString label= getRichTextLabel(element);
89
		if (label != null) {
90
			text= label.getString();
91
			ranges= label.getStyleRanges();
92
		} else {
93
			text= fLabelProvider.getText(element);
94
			ranges= new StyleRange[0];
95
		}
96
		return new LabelPresentationInfo(text, ranges, image, defaultFont, foreground, background);
97
	}
98
	
99
	
100
	private ColoredString getRichTextLabel(Object element) {
101
		if (fLabelProvider instanceof IRichLabelProvider) {
102
			// get a rich label 
103
			IRichLabelProvider richLabelProvider= (IRichLabelProvider) fLabelProvider;
104
			ColoredString richLabel= richLabelProvider.getRichTextLabel(element);
105
			if (richLabel != null) {
106
				return richLabel;
107
			}
108
		}
109
		return null;
110
	}
111
112
	public Image getImage(Object element) {
113
		return fLabelProvider.getImage(element);
114
	}
115
116
	public String getText(Object element) {
57
	public String getText(Object element) {
117
		return fLabelProvider.getText(element);
58
		return getStyledText(element).getString();
118
	}
59
	}
119
60
120
}
61
}
(-)ui/org/eclipse/jdt/internal/ui/viewsupport/ColoredString.java (-369 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.viewsupport;
12
13
import java.util.ArrayList;
14
import java.util.List;
15
16
import org.eclipse.swt.custom.StyleRange;
17
import org.eclipse.swt.graphics.TextStyle;
18
19
/**
20
 * Represents a string with styled ranges. All ranges mark substrings of the string and do not overlap.
21
 * Styles are represented by {@link Style}.
22
 * 
23
 * The styled string can be modified:
24
 * <ul>
25
 * <li>new strings with styles can be appended</li>
26
 * <li>styles can by applied to to the existing string</li>
27
 * </ul>
28
 * 
29
 * <p>
30
 * This class may be instantiated; it is not intended to be subclassed.
31
 * </p>
32
 *  
33
 */
34
public class ColoredString {
35
	
36
	/**
37
	 * Represents a style that can be associated to one ore more ranges in the {@link ColoredString}
38
	 *  
39
	 */
40
	public static abstract class Style {
41
		
42
		/**
43
		 * Applies the styles represented by this object to the given textStyle.
44
		 * 
45
		 * @param textStyle the {@link TextStyle} to modify
46
		 */
47
		public abstract void applyStyles(TextStyle textStyle);
48
	}
49
	
50
	private static final StyleRange[] EMPTY= new StyleRange[0];
51
	
52
	private StringBuffer fBuffer;
53
	private StyleRunList fStyleRuns;
54
	
55
	/**
56
	 * Creates an empty {@link ColoredString}.
57
	 */
58
	public ColoredString() {
59
		fBuffer= new StringBuffer();
60
		fStyleRuns= null;
61
	}
62
	
63
	/**
64
	 * Creates an {@link ColoredString} initialized with a string without a style associated.
65
	 * 
66
	 * @param string the string 
67
	 */
68
	public ColoredString(String string) {
69
		this(string, null);
70
	}
71
	
72
	/**
73
	 * Creates an {@link ColoredString} initialized with a string and a style.  
74
	 * 
75
	 * @param string the string 
76
	 * @param style the style of the text or <code>null</code> to not associated a style.
77
	 */
78
	public ColoredString(String string, Style style) {
79
		this();
80
		append(string, style);
81
	}
82
	
83
	/**
84
	 * Returns the string of this {@link ColoredString}.
85
	 * 
86
	 * @return the current string of this {@link ColoredString}.
87
	 */
88
	public String getString() {
89
		return fBuffer.toString();
90
	}
91
	
92
	/**
93
	 * Returns the length of the string of this {@link ColoredString}.
94
	 * 
95
	 * @return the length of the current string
96
	 */
97
	public int length() {
98
		return fBuffer.length();
99
	}
100
	
101
	/**
102
	 * Appends a string to the {@link ColoredString}. The appended string will have no style associated.
103
	 * 
104
	 * @param string the string to append.
105
	 * @return returns a reference to this object.
106
	 */
107
	public ColoredString append(String string) {
108
		return append(string, null);
109
	}
110
	
111
	/**
112
	 * Appends a character to the {@link ColoredString}. The appended character will have no style associated.
113
	 * 
114
	 * @param ch the character to append.
115
	 * @return returns a reference to this object.
116
	 */
117
	public ColoredString append(char ch) {
118
		return append(String.valueOf(ch), null);
119
	}
120
	
121
	/**
122
	 * Appends a string with styles to the {@link ColoredString}.
123
	 * 
124
	 * @param string the string to append.
125
	 * @return returns a reference to this object.
126
	 */
127
	public ColoredString append(ColoredString string) {
128
		if (string.length() == 0) {
129
			return this;
130
		}
131
		
132
		int offset= fBuffer.length();
133
		fBuffer.append(string.getString());
134
		
135
		List otherRuns= string.fStyleRuns;
136
		if (otherRuns != null && !otherRuns.isEmpty()) {
137
			for (int i= 0; i < otherRuns.size(); i++) {
138
				StyleRun curr= (StyleRun) otherRuns.get(i);
139
				if (i == 0 && curr.offset != 0) {
140
					appendStyleRun(null, offset); // appended string will start with the default color
141
				}
142
				appendStyleRun(curr.style, offset + curr.offset);
143
			}
144
		} else {
145
			appendStyleRun(null, offset); // appended string will start with the default color
146
		}
147
		return this;
148
	}
149
	
150
	/**
151
	 * Appends a character with a style to the {@link ColoredString}. The appended character will
152
	 * have the given style associated.
153
	 * 
154
	 * @param ch the character to append.
155
	 * @param style the style to of the character to append or <code>null</code> if no style should be
156
	 * associated to the string.
157
	 * @return returns a reference to this object.
158
	 */
159
	public ColoredString append(char ch, Style style) {
160
		return append(String.valueOf(ch), style);
161
	}
162
	
163
	/**
164
	 * Appends a string with a style to the {@link ColoredString}. The appended string will
165
	 * have the given style associated.
166
	 * 
167
	 * @param string the string to append.
168
	 * @param style the style to of the string to append or <code>null</code> if no style should be
169
	 * associated to the string.
170
	 * @return returns a reference to this object.
171
	 */
172
	public ColoredString append(String string, Style style) {
173
		if (string.length() == 0)
174
			return this;
175
		
176
		int offset= fBuffer.length(); // the length before appending
177
		fBuffer.append(string);
178
		appendStyleRun(style, offset);
179
		return this;
180
	}
181
	
182
	/**
183
	 * Sets a style to the given source range. The range must be subrange of actual string of this {@link ColoredString}.
184
	 * Styles previously set for that range will be overwritten.
185
	 * 
186
	 * @param offset the start offset of the range
187
	 * @param length the length of the range
188
	 * @param style the style to set
189
	 * 
190
	 * @throws StringIndexOutOfBoundsException if <code>start</code> is
191
     *             less than zero, or if offset plus length is greater than the length of this object.
192
	 */
193
	public void setStyle(int offset, int length, Style style) {
194
		if (offset < 0 || offset + length > fBuffer.length()) {
195
			throw new StringIndexOutOfBoundsException("Invalid offset (" + offset + ") or length (" + length + ")");   //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
196
		}
197
		if (length == 0) {
198
			return;
199
		}
200
		if (!hasRuns() || getLastRun().offset <= offset) {
201
			appendStyleRun(style, offset);
202
			if (offset + length != fBuffer.length()) {
203
				appendStyleRun(null, offset + length);
204
			}
205
			return;
206
		}
207
		
208
		int endRun= findRun(offset + length);
209
		if (endRun >= 0) {
210
			// run with the same end index, nothing to change
211
		} else {
212
			endRun= -(endRun + 1);
213
			if (offset + length < fBuffer.length()) {
214
				Style prevStyle= endRun > 0 ? fStyleRuns.getRun(endRun - 1).style : null;
215
				fStyleRuns.add(endRun, new StyleRun(offset + length, prevStyle));
216
			}
217
		}
218
		
219
		int startRun= findRun(offset);
220
		if (startRun >= 0) {
221
			// run with the same start index
222
			StyleRun styleRun= fStyleRuns.getRun(startRun);
223
			styleRun.style= style;
224
		} else {
225
			startRun= -(startRun + 1);
226
			
227
			Style prevStyle= startRun > 0 ? fStyleRuns.getRun(startRun - 1).style : null;
228
			if (isDifferentStyle(prevStyle, style) || (startRun == 0 && style != null)) {
229
				fStyleRuns.add(startRun, new StyleRun(offset, style));
230
				endRun++; // endrun is moved one back
231
			} else {
232
				startRun--; // we use the previous
233
			}
234
		}
235
		if (startRun + 1 < endRun) {
236
			fStyleRuns.removeRange(startRun + 1, endRun);
237
		}
238
	}
239
	
240
	/**
241
	 * Returns {@link StyleRange} for all applied styles to this string
242
	 * 
243
	 * @return an array of all {@link StyleRange} applied to this string.
244
	 */
245
	public StyleRange[] getStyleRanges() {
246
		if (hasRuns()) {
247
			ArrayList res= new ArrayList();
248
			
249
			List styleRuns= getStyleRuns();
250
			int offset= 0;
251
			Style style= null;
252
			for (int i= 0; i < styleRuns.size(); i++) {
253
				StyleRun curr= (StyleRun) styleRuns.get(i);
254
				if (isDifferentStyle(curr.style, style)) {
255
					if (curr.offset > offset && style != null) {
256
						res.add(createStyleRange(offset, curr.offset, style));
257
					}
258
					offset= curr.offset;
259
					style= curr.style;
260
				}
261
			}
262
			if (fBuffer.length() > offset && style != null) {
263
				res.add(createStyleRange(offset, fBuffer.length(), style));
264
			}
265
			return (StyleRange[]) res.toArray(new StyleRange[res.size()]);
266
		}
267
		return EMPTY;
268
	}
269
	
270
	private int findRun(int offset) {
271
		// method assumes that fStyleRuns is not null
272
		int low= 0;
273
		int high= fStyleRuns.size() - 1;
274
		while (low <= high) {
275
		    int mid = (low + high) / 2;
276
		    StyleRun styleRun= fStyleRuns.getRun(mid);
277
		    if (styleRun.offset < offset) {
278
		    	low = mid + 1;
279
		    } else if (styleRun.offset > offset) {
280
		    	high = mid - 1;
281
		    } else {
282
		    	return mid; // key found
283
		    }
284
		}
285
		return -(low + 1);  // key not found.
286
	}
287
	
288
	private StyleRange createStyleRange(int start, int end, Style style) {
289
		StyleRange styleRange= new StyleRange();
290
		styleRange.start= start;
291
		styleRange.length= end - start;
292
		style.applyStyles(styleRange);
293
		return styleRange;
294
	}
295
	
296
	
297
	/* (non-Javadoc)
298
	 * @see java.lang.Object#toString()
299
	 */
300
	public String toString() {
301
		return fBuffer.toString();
302
	}
303
	
304
	private boolean hasRuns() {
305
		return fStyleRuns != null && !fStyleRuns.isEmpty();
306
	}
307
		
308
	private void appendStyleRun(Style style, int offset) {
309
		StyleRun lastRun= getLastRun();
310
		if (lastRun != null && lastRun.offset == offset) {
311
			lastRun.style= style;
312
			return;
313
		}
314
		
315
		if (lastRun == null && style != null || lastRun != null && isDifferentStyle(style, lastRun.style)) {
316
			getStyleRuns().add(new StyleRun(offset, style));
317
		}
318
	}
319
	
320
	private boolean isDifferentStyle(Style style1, Style style2) {
321
		if (style1 == null) {
322
			return style2 != null;
323
		}
324
		return !style1.equals(style2);
325
	}
326
	
327
	private StyleRun getLastRun() {
328
		if (fStyleRuns == null || fStyleRuns.isEmpty()) {
329
			return null;
330
		}
331
		return fStyleRuns.getRun(fStyleRuns.size() - 1);
332
	}
333
	
334
	private List getStyleRuns() {
335
		if (fStyleRuns == null)
336
			fStyleRuns= new StyleRunList();
337
		return fStyleRuns;
338
	}
339
	
340
	private static class StyleRun {
341
		public int offset;
342
		public Style style;
343
		
344
		public StyleRun(int offset, Style style) {
345
			this.offset= offset;
346
			this.style= style;
347
		}
348
		
349
		public String toString() {
350
			return "Offset " + offset + ", style: " + style.toString();  //$NON-NLS-1$//$NON-NLS-2$
351
		}
352
	}
353
	
354
	private static class StyleRunList extends ArrayList {
355
		private static final long serialVersionUID= 123L;
356
357
		public StyleRunList() {
358
			super(3);
359
		}
360
361
		public StyleRun getRun(int index) {
362
			return (StyleRun) get(index);
363
		}
364
				
365
		public void removeRange(int fromIndex, int toIndex) {
366
			super.removeRange(fromIndex, toIndex);
367
		}	
368
	}
369
}
(-)ui/org/eclipse/jdt/internal/ui/typehierarchy/MethodsLabelProvider.java (-6 / +8 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 16-21 Link Here
16
import org.eclipse.jface.util.IPropertyChangeListener;
16
import org.eclipse.jface.util.IPropertyChangeListener;
17
import org.eclipse.jface.util.PropertyChangeEvent;
17
import org.eclipse.jface.util.PropertyChangeEvent;
18
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
18
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
19
import org.eclipse.jface.viewers.StyledString;
19
20
20
import org.eclipse.jdt.core.IJavaElement;
21
import org.eclipse.jdt.core.IJavaElement;
21
import org.eclipse.jdt.core.IMember;
22
import org.eclipse.jdt.core.IMember;
Lines 29-35 Link Here
29
import org.eclipse.jdt.ui.JavaElementLabels;
30
import org.eclipse.jdt.ui.JavaElementLabels;
30
31
31
import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
32
import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
32
import org.eclipse.jdt.internal.ui.viewsupport.ColoredString;
33
import org.eclipse.jdt.internal.ui.viewsupport.ColoredViewersManager;
33
import org.eclipse.jdt.internal.ui.viewsupport.ColoredViewersManager;
34
34
35
/**
35
/**
Lines 102-114 Link Here
102
	}
102
	}
103
	
103
	
104
	/* (non-Javadoc)
104
	/* (non-Javadoc)
105
	 * @see org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider#getRichTextLabel(java.lang.Object)
105
	 * @see org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider#getStyledText(java.lang.Object)
106
	 */
106
	 */
107
	public ColoredString getRichTextLabel(Object element) {
107
	public StyledString getStyledText(Object element) {
108
		ColoredString text= super.getRichTextLabel(element);
108
		StyledString text= super.getStyledText(element);
109
		String qualifier= getQualifier(element);
109
		String qualifier= getQualifier(element);
110
		if (qualifier != null) {
110
		if (qualifier != null) {
111
			return new ColoredString(qualifier).append(text);
111
			StyledString StyledString= new StyledString(qualifier);
112
			StyledString.append(text);
113
			return StyledString;
112
		}
114
		}
113
		return text;
115
		return text;
114
		
116
		
(-)ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyViewer.java (-2 / +1 lines)
Lines 36-42 Link Here
36
36
37
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
37
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
38
import org.eclipse.jdt.internal.ui.util.JavaUIHelp;
38
import org.eclipse.jdt.internal.ui.util.JavaUIHelp;
39
import org.eclipse.jdt.internal.ui.viewsupport.ColoringLabelProvider;
40
import org.eclipse.jdt.internal.ui.viewsupport.DecoratingJavaLabelProvider;
39
import org.eclipse.jdt.internal.ui.viewsupport.DecoratingJavaLabelProvider;
41
import org.eclipse.jdt.internal.ui.viewsupport.ProblemTreeViewer;
40
import org.eclipse.jdt.internal.ui.viewsupport.ProblemTreeViewer;
42
 
41
 
Lines 50-56 Link Here
50
49
51
		fLabelProvider= new HierarchyLabelProvider(lifeCycle);
50
		fLabelProvider= new HierarchyLabelProvider(lifeCycle);
52
	
51
	
53
		setLabelProvider(new ColoringLabelProvider(new DecoratingJavaLabelProvider(fLabelProvider, true)));
52
		setLabelProvider(new DecoratingJavaLabelProvider(fLabelProvider, true));
54
		setUseHashlookup(true);
53
		setUseHashlookup(true);
55
			
54
			
56
		setContentProvider(contentProvider);
55
		setContentProvider(contentProvider);
(-)ui/org/eclipse/jdt/internal/ui/typehierarchy/MethodsViewer.java (-2 / +1 lines)
Lines 47-53 Link Here
47
import org.eclipse.jdt.internal.ui.filters.SyntheticMembersFilter;
47
import org.eclipse.jdt.internal.ui.filters.SyntheticMembersFilter;
48
import org.eclipse.jdt.internal.ui.util.JavaUIHelp;
48
import org.eclipse.jdt.internal.ui.util.JavaUIHelp;
49
import org.eclipse.jdt.internal.ui.util.SelectionUtil;
49
import org.eclipse.jdt.internal.ui.util.SelectionUtil;
50
import org.eclipse.jdt.internal.ui.viewsupport.ColoringLabelProvider;
51
import org.eclipse.jdt.internal.ui.viewsupport.DecoratingJavaLabelProvider;
50
import org.eclipse.jdt.internal.ui.viewsupport.DecoratingJavaLabelProvider;
52
import org.eclipse.jdt.internal.ui.viewsupport.ProblemTableViewer;
51
import org.eclipse.jdt.internal.ui.viewsupport.ProblemTableViewer;
53
52
Lines 77-83 Link Here
77
		
76
		
78
		fLabelProvider= new MethodsLabelProvider(lifeCycle, this);
77
		fLabelProvider= new MethodsLabelProvider(lifeCycle, this);
79
	
78
	
80
		setLabelProvider(new ColoringLabelProvider(new DecoratingJavaLabelProvider(fLabelProvider, true)));
79
		setLabelProvider(new DecoratingJavaLabelProvider(fLabelProvider, true));
81
		setContentProvider(new MethodsContentProvider(lifeCycle));
80
		setContentProvider(new MethodsContentProvider(lifeCycle));
82
		
81
		
83
		HierarchyViewerSorter sorter= new HierarchyViewerSorter(lifeCycle);
82
		HierarchyViewerSorter sorter= new HierarchyViewerSorter(lifeCycle);
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyLabelProvider.java (-7 / +7 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 16-21 Link Here
16
import org.eclipse.swt.graphics.Image;
16
import org.eclipse.swt.graphics.Image;
17
17
18
import org.eclipse.jface.viewers.ILabelDecorator;
18
import org.eclipse.jface.viewers.ILabelDecorator;
19
import org.eclipse.jface.viewers.StyledString;
19
20
20
import org.eclipse.ui.model.IWorkbenchAdapter;
21
import org.eclipse.ui.model.IWorkbenchAdapter;
21
22
Lines 26-32 Link Here
26
27
27
import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
28
import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
28
import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels;
29
import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels;
29
import org.eclipse.jdt.internal.ui.viewsupport.ColoredString;
30
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
30
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
31
31
32
class CallHierarchyLabelProvider extends AppearanceAwareLabelProvider {
32
class CallHierarchyLabelProvider extends AppearanceAwareLabelProvider {
Lines 70-85 Link Here
70
    }
70
    }
71
    
71
    
72
    /* (non-Javadoc)
72
    /* (non-Javadoc)
73
     * @see org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider#getRichTextLabel(java.lang.Object)
73
     * @see org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider#getStyledText(java.lang.Object)
74
     */
74
     */
75
    public ColoredString getRichTextLabel(Object element) {
75
    public StyledString getStyledText(Object element) {
76
        if (element instanceof MethodWrapper && ((MethodWrapper) element).getMember() != null) {
76
        if (element instanceof MethodWrapper && ((MethodWrapper) element).getMember() != null) {
77
        	MethodWrapper wrapper= (MethodWrapper) element;
77
        	MethodWrapper wrapper= (MethodWrapper) element;
78
        	String decorated= getElementLabel(wrapper);
78
        	String decorated= getElementLabel(wrapper);
79
        	ColoredString text= super.getRichTextLabel(wrapper.getMember());
79
        	StyledString text= super.getStyledText(wrapper.getMember());
80
        	return ColoredJavaElementLabels.decorateColoredString(text, decorated, ColoredJavaElementLabels.COUNTER_STYLE);
80
        	return ColoredJavaElementLabels.decorateStyledString(text, decorated, ColoredJavaElementLabels.COUNTER_STYLE);
81
        }
81
        }
82
        return new ColoredString(getSpecialLabel(element));
82
        return new StyledString(getSpecialLabel(element));
83
    }
83
    }
84
    
84
    
85
    private String getSpecialLabel(Object element) {
85
    private String getSpecialLabel(Object element) {
(-)ui/org/eclipse/jdt/internal/ui/dialogs/FilteredTypesSelectionDialog.java (-59 / +17 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 32-46 Link Here
32
32
33
import org.eclipse.swt.events.DisposeEvent;
33
import org.eclipse.swt.events.DisposeEvent;
34
import org.eclipse.swt.events.DisposeListener;
34
import org.eclipse.swt.events.DisposeListener;
35
import org.eclipse.swt.graphics.Color;
36
import org.eclipse.swt.graphics.Image;
35
import org.eclipse.swt.graphics.Image;
37
import org.eclipse.swt.layout.GridData;
36
import org.eclipse.swt.layout.GridData;
38
import org.eclipse.swt.widgets.Composite;
37
import org.eclipse.swt.widgets.Composite;
39
import org.eclipse.swt.widgets.Control;
38
import org.eclipse.swt.widgets.Control;
40
import org.eclipse.swt.widgets.Display;
41
import org.eclipse.swt.widgets.Item;
42
import org.eclipse.swt.widgets.Shell;
39
import org.eclipse.swt.widgets.Shell;
43
import org.eclipse.swt.widgets.Table;
44
import org.eclipse.swt.widgets.Text;
40
import org.eclipse.swt.widgets.Text;
45
41
46
import org.eclipse.jface.action.Action;
42
import org.eclipse.jface.action.Action;
Lines 60-65 Link Here
60
import org.eclipse.jface.viewers.ISelection;
56
import org.eclipse.jface.viewers.ISelection;
61
import org.eclipse.jface.viewers.LabelProvider;
57
import org.eclipse.jface.viewers.LabelProvider;
62
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
58
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
59
import org.eclipse.jface.viewers.StyledString;
60
import org.eclipse.jface.viewers.DecoratingStyledCellLabelProvider.IStyledLabelProvider;
63
61
64
import org.eclipse.jface.text.ITextSelection;
62
import org.eclipse.jface.text.ITextSelection;
65
63
Lines 114-123 Link Here
114
import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory;
112
import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory;
115
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
113
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
116
import org.eclipse.jdt.internal.ui.util.TypeNameMatchLabelProvider;
114
import org.eclipse.jdt.internal.ui.util.TypeNameMatchLabelProvider;
117
import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels;
118
import org.eclipse.jdt.internal.ui.viewsupport.ColoredString;
119
import org.eclipse.jdt.internal.ui.viewsupport.ColoredViewersManager;
120
import org.eclipse.jdt.internal.ui.viewsupport.OwnerDrawSupport;
121
import org.eclipse.jdt.internal.ui.workingsets.WorkingSetFilterActionGroup;
115
import org.eclipse.jdt.internal.ui.workingsets.WorkingSetFilterActionGroup;
122
116
123
/**
117
/**
Lines 529-583 Link Here
529
		super.configureShell(shell);
523
		super.configureShell(shell);
530
		PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, IJavaHelpContextIds.TYPE_SELECTION_DIALOG2);
524
		PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, IJavaHelpContextIds.TYPE_SELECTION_DIALOG2);
531
	}
525
	}
532
	
533
	protected Control createContents(Composite parent) {
534
		Control contents= super.createContents(parent);
535
		if (ColoredViewersManager.showColoredLabels()) {
536
			if (contents instanceof Composite) {
537
				Table listControl= findTableControl((Composite) contents);
538
				if (listControl != null) {
539
					installOwnerDraw(listControl);
540
				}
541
			}
542
		}
543
		return contents;
544
	}
545
	
546
	private void installOwnerDraw(Table tableControl) {
547
		new OwnerDrawSupport(tableControl) { // installs the owner draw listeners
548
			public ColoredString getColoredLabel(Item item) {
549
				String text= item.getText();
550
				ColoredString str= new ColoredString(text);
551
				int index= text.indexOf('-');
552
				if (index != -1) {
553
					str.setStyle(index, str.length() - index, ColoredJavaElementLabels.QUALIFIER_STYLE);
554
				}
555
				return str;
556
			}
557
558
			public Color getColor(String foregroundColorName, Display display) {
559
				return PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry().get(foregroundColorName);
560
			}
561
		};
562
	}
563
564
	private Table findTableControl(Composite composite) {
565
		Control[] children= composite.getChildren();
566
		for (int i= 0; i < children.length; i++) {
567
			Control curr= children[i];
568
			if (curr instanceof Table) {
569
				return (Table) curr;
570
			} else if (curr instanceof Composite) {
571
				Table res= findTableControl((Composite) curr);
572
				if (res != null) {
573
					return res;
574
				}
575
			}
576
		}
577
		return null;
578
	}
579
	
580
	
581
526
582
	/*
527
	/*
583
	 * (non-Javadoc)
528
	 * (non-Javadoc)
Lines 796-802 Link Here
796
	/**
741
	/**
797
	 * A <code>LabelProvider</code> for (the table of) types.
742
	 * A <code>LabelProvider</code> for (the table of) types.
798
	 */
743
	 */
799
	private class TypeItemLabelProvider extends LabelProvider implements ILabelDecorator {
744
	private class TypeItemLabelProvider extends LabelProvider implements ILabelDecorator, IStyledLabelProvider {
800
745
801
		private boolean fContainerInfo;
746
		private boolean fContainerInfo;
802
		private LocalResourceManager fImageManager;
747
		private LocalResourceManager fImageManager;
Lines 884-889 Link Here
884
			return fTypeInfoUtil.getQualifiedText((TypeNameMatch) element);
829
			return fTypeInfoUtil.getQualifiedText((TypeNameMatch) element);
885
		}
830
		}
886
831
832
		/* (non-Javadoc)
833
		 * @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider#getStyledText(java.lang.Object)
834
		 */
835
		public StyledString getStyledText(Object element) {
836
			String text= getText(element);
837
			StyledString string= new StyledString(text);			
838
			int index= text.indexOf(JavaElementLabels.CONCAT_STRING);
839
			if (index != -1) {
840
				string.setStyle(index, text.length() - index, StyledString.QUALIFIER_STYLE);
841
			}
842
			return string;
843
		}
844
887
	}
845
	}
888
846
889
	/**
847
	/**
(-)ui/org/eclipse/jdt/internal/ui/workingsets/JavaWorkingSetPage.java (-3 / +2 lines)
Lines 43-49 Link Here
43
import org.eclipse.jdt.internal.ui.actions.SelectionConverter;
43
import org.eclipse.jdt.internal.ui.actions.SelectionConverter;
44
import org.eclipse.jdt.internal.ui.filters.EmptyInnerPackageFilter;
44
import org.eclipse.jdt.internal.ui.filters.EmptyInnerPackageFilter;
45
import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
45
import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
46
import org.eclipse.jdt.internal.ui.viewsupport.ColoringLabelProvider;
47
import org.eclipse.jdt.internal.ui.viewsupport.DecoratingJavaLabelProvider;
46
import org.eclipse.jdt.internal.ui.viewsupport.DecoratingJavaLabelProvider;
48
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
47
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
49
48
Lines 103-109 Link Here
103
				AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS | JavaElementImageProvider.SMALL_ICONS
102
				AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS | JavaElementImageProvider.SMALL_ICONS
104
			);
103
			);
105
		
104
		
106
		tree.setLabelProvider(new ColoringLabelProvider(new DecoratingJavaLabelProvider(javaElementLabelProvider)));
105
		tree.setLabelProvider(new DecoratingJavaLabelProvider(javaElementLabelProvider));
107
		tree.setComparator(new JavaElementComparator());
106
		tree.setComparator(new JavaElementComparator());
108
		tree.addFilter(new EmptyInnerPackageFilter());
107
		tree.addFilter(new EmptyInnerPackageFilter());
109
		
108
		
Lines 137-143 Link Here
137
				AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS | JavaElementImageProvider.SMALL_ICONS
136
				AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS | JavaElementImageProvider.SMALL_ICONS
138
			);
137
			);
139
			
138
			
140
		table.setLabelProvider(new ColoringLabelProvider(new DecoratingJavaLabelProvider(javaElementLabelProvider)));
139
		table.setLabelProvider(new DecoratingJavaLabelProvider(javaElementLabelProvider));
141
		table.setComparator(new JavaElementComparator());
140
		table.setComparator(new JavaElementComparator());
142
	}
141
	}
143
	
142
	
(-)ui refactoring/org/eclipse/jdt/internal/ui/refactoring/nls/search/NLSSearchResultLabelProvider2.java (-17 / +16 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 15-20 Link Here
15
15
16
import org.eclipse.swt.graphics.Image;
16
import org.eclipse.swt.graphics.Image;
17
17
18
import org.eclipse.jface.viewers.StyledString;
19
import org.eclipse.jface.viewers.DecoratingStyledCellLabelProvider.IStyledLabelProvider;
20
18
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
21
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
19
22
20
import org.eclipse.jdt.ui.JavaElementLabels;
23
import org.eclipse.jdt.ui.JavaElementLabels;
Lines 22-32 Link Here
22
import org.eclipse.jdt.internal.ui.search.TextSearchLabelProvider;
25
import org.eclipse.jdt.internal.ui.search.TextSearchLabelProvider;
23
import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
26
import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
24
import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels;
27
import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels;
25
import org.eclipse.jdt.internal.ui.viewsupport.ColoredString;
26
import org.eclipse.jdt.internal.ui.viewsupport.IRichLabelProvider;
27
28
28
29
29
class NLSSearchResultLabelProvider2 extends TextSearchLabelProvider implements IRichLabelProvider {
30
class NLSSearchResultLabelProvider2 extends TextSearchLabelProvider implements IStyledLabelProvider {
30
	
31
	
31
	private AppearanceAwareLabelProvider fLabelProvider;
32
	private AppearanceAwareLabelProvider fLabelProvider;
32
	
33
	
Lines 35-57 Link Here
35
		fLabelProvider= new AppearanceAwareLabelProvider(JavaElementLabels.ALL_POST_QUALIFIED, 0);
36
		fLabelProvider= new AppearanceAwareLabelProvider(JavaElementLabels.ALL_POST_QUALIFIED, 0);
36
	}
37
	}
37
	
38
	
39
	public StyledString getStyledText(Object element) {
40
		return getColoredLabelWithCounts(element, internalGetText(element));
41
	}
42
	
43
	
38
	/* (non-Javadoc)
44
	/* (non-Javadoc)
39
	 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
45
	 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
40
	 */
46
	 */
41
	public String getText(Object element) {
47
	public String getText(Object element) {
42
		return getLabelWithCounts(element, internalGetText(element).toString()); 
48
		return getLabelWithCounts(element, internalGetText(element).toString()); 
43
	}
49
	}
44
	
50
		
45
	/* (non-Javadoc)
51
	private StyledString internalGetText(Object element) {
46
	 * @see org.eclipse.jdt.internal.ui.viewsupport.IRichLabelProvider#getRichTextLabel(java.lang.Object)
47
	 */
48
	public ColoredString getRichTextLabel(Object element) {
49
		return getColoredLabelWithCounts(element, internalGetText(element)); 
50
	}
51
	
52
	private ColoredString internalGetText(Object element) {
53
		String description;
52
		String description;
54
		ColoredString elementLabel;
53
		StyledString elementLabel;
55
		
54
		
56
		if (element instanceof FileEntry) {
55
		if (element instanceof FileEntry) {
57
			FileEntry fileEntry= (FileEntry) element;
56
			FileEntry fileEntry= (FileEntry) element;
Lines 65-76 Link Here
65
			description= NLSSearchMessages.NLSSearchResultLabelProvider2_undefinedKeys;
64
			description= NLSSearchMessages.NLSSearchResultLabelProvider2_undefinedKeys;
66
			elementLabel= ColoredJavaElementLabels.getTextLabel(element, JavaElementLabels.ALL_POST_QUALIFIED | ColoredJavaElementLabels.COLORIZE);
65
			elementLabel= ColoredJavaElementLabels.getTextLabel(element, JavaElementLabels.ALL_POST_QUALIFIED | ColoredJavaElementLabels.COLORIZE);
67
		}
66
		}
68
		return new ColoredString(description).append(' ').append(elementLabel);
67
		return new StyledString(description).append(' ').append(elementLabel);
69
	}
68
	}
70
	
69
	
71
	private ColoredString getPropertiesName(IFile propertiesFile) {
70
	private StyledString getPropertiesName(IFile propertiesFile) {
72
		String path= propertiesFile.getFullPath().removeLastSegments(1).makeRelative().toString();
71
		String path= propertiesFile.getFullPath().removeLastSegments(1).makeRelative().toString();
73
		return new ColoredString(propertiesFile.getName()).append(" - " + path, ColoredJavaElementLabels.QUALIFIER_STYLE); //$NON-NLS-1$
72
		return new StyledString(propertiesFile.getName()).append(" - " + path, ColoredJavaElementLabels.QUALIFIER_STYLE); //$NON-NLS-1$
74
	}
73
	}
75
	
74
	
76
	/*
75
	/*
(-)plugin.xml (-3 / +3 lines)
Lines 980-986 Link Here
980
            label="%coloredLabels.qualifier.label"
980
            label="%coloredLabels.qualifier.label"
981
            categoryId="org.eclipse.jdt.ui.presentation"
981
            categoryId="org.eclipse.jdt.ui.presentation"
982
            value="COLOR_DARK_GRAY"
982
            value="COLOR_DARK_GRAY"
983
            id="org.eclipse.jdt.ui.ColoredLabels.qualifier">
983
            id="QUALIFIER_COLOR">
984
         <description>
984
         <description>
985
            %coloredLabels.qualifier.description
985
            %coloredLabels.qualifier.description
986
         </description>
986
         </description>
Lines 989-995 Link Here
989
            label="%coloredLabels.decorations.label"
989
            label="%coloredLabels.decorations.label"
990
            categoryId="org.eclipse.jdt.ui.presentation"
990
            categoryId="org.eclipse.jdt.ui.presentation"
991
            value="149,125,71"
991
            value="149,125,71"
992
            id="org.eclipse.jdt.ui.ColoredLabels.decorations">
992
            id="DECORATIONS_COLOR">
993
         <description>
993
         <description>
994
            %coloredLabels.decorations.description
994
            %coloredLabels.decorations.description
995
         </description>
995
         </description>
Lines 998-1004 Link Here
998
            label="%coloredLabels.counter.label"
998
            label="%coloredLabels.counter.label"
999
            categoryId="org.eclipse.jdt.ui.presentation"
999
            categoryId="org.eclipse.jdt.ui.presentation"
1000
            value="0,127,174"
1000
            value="0,127,174"
1001
            id="org.eclipse.jdt.ui.ColoredLabels.counter">
1001
            id="COUNTER_COLOR">
1002
         <description>
1002
         <description>
1003
            %coloredLabels.counter.description
1003
            %coloredLabels.counter.description
1004
         </description>
1004
         </description>
(-)ui/org/eclipse/jdt/internal/ui/javaeditor/breadcrumb/BreadcrumbItemDropDown.java (-2 / +1 lines)
Lines 49-55 Link Here
49
import org.eclipse.jdt.internal.ui.JavaPluginImages;
49
import org.eclipse.jdt.internal.ui.JavaPluginImages;
50
import org.eclipse.jdt.internal.ui.javaeditor.breadcrumb.FilteredTable.Direction;
50
import org.eclipse.jdt.internal.ui.javaeditor.breadcrumb.FilteredTable.Direction;
51
import org.eclipse.jdt.internal.ui.javaeditor.breadcrumb.FilteredTable.INavigateListener;
51
import org.eclipse.jdt.internal.ui.javaeditor.breadcrumb.FilteredTable.INavigateListener;
52
import org.eclipse.jdt.internal.ui.viewsupport.ColoringLabelProvider;
53
52
54
53
55
/**
54
/**
Lines 234-240 Link Here
234
				return false;
233
				return false;
235
			}
234
			}
236
		});
235
		});
237
		viewer.setLabelProvider(new ColoringLabelProvider(fLabelProvider));
236
		viewer.setLabelProvider(fLabelProvider);
238
		viewer.setComparator(new JavaElementComparator());
237
		viewer.setComparator(new JavaElementComparator());
239
		viewer.setInput(fParent.getInput());
238
		viewer.setInput(fParent.getInput());
240
239

Return to bug 219393