KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > synchronize > MultiLabelDecorator


1 /*******************************************************************************
2  * Copyright (c) 2006 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.team.internal.ui.synchronize;
12
13 import org.eclipse.jface.viewers.*;
14 import org.eclipse.swt.graphics.*;
15
16 class MultiLabelDecorator extends LabelProvider implements ILabelDecorator, IFontDecorator, IColorDecorator {
17     private ILabelDecorator[] decorators;
18
19     public MultiLabelDecorator(ILabelDecorator[] decorators) {
20         this.decorators = decorators;
21     }
22     
23     /* (non-Javadoc)
24      * @see org.eclipse.jface.viewers.ILabelDecorator#decorateImage(org.eclipse.swt.graphics.Image, java.lang.Object)
25      */

26     public Image decorateImage(Image image, Object JavaDoc element) {
27         for (int i = 0; i < decorators.length; i++) {
28             ILabelDecorator decorator = decorators[i];
29             Image newImage = decorator.decorateImage(image, element);
30             if (newImage != null) {
31                 image = newImage;
32             }
33         }
34         return image;
35     }
36     
37     /* (non-Javadoc)
38      * @see org.eclipse.jface.viewers.ILabelDecorator#decorateText(java.lang.String, java.lang.Object)
39      */

40     public String JavaDoc decorateText(String JavaDoc text, Object JavaDoc element) {
41         for (int i = 0; i < decorators.length; i++) {
42             ILabelDecorator decorator = decorators[i];
43             String JavaDoc newText = decorator.decorateText(text, element);
44             if (newText != null) {
45                 text = newText;
46             }
47         }
48         return text;
49     }
50     
51     /* (non-Javadoc)
52      * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
53      */

54     public void dispose() {
55         for (int i = 0; i < decorators.length; i++) {
56             ILabelDecorator d = decorators[i];
57             d.dispose();
58         }
59     }
60
61     /* (non-Javadoc)
62      * @see org.eclipse.jface.viewers.IFontDecorator#decorateFont(java.lang.Object)
63      */

64     public Font decorateFont(Object JavaDoc element) {
65         for (int i = 0; i < decorators.length; i++) {
66             ILabelDecorator decorator = decorators[i];
67             if(decorator instanceof IFontDecorator) {
68                 return ((IFontDecorator)decorator).decorateFont(element);
69             }
70         }
71         return null;
72     }
73
74     /* (non-Javadoc)
75      * @see org.eclipse.jface.viewers.IColorDecorator#decorateForeground(java.lang.Object)
76      */

77     public Color decorateForeground(Object JavaDoc element) {
78         for (int i = 0; i < decorators.length; i++) {
79             ILabelDecorator decorator = decorators[i];
80             if(decorator instanceof IColorDecorator) {
81                 return ((IColorDecorator)decorator).decorateForeground(element);
82             }
83         }
84         return null;
85     }
86
87     /* (non-Javadoc)
88      * @see org.eclipse.jface.viewers.IColorDecorator#decorateBackground(java.lang.Object)
89      */

90     public Color decorateBackground(Object JavaDoc element) {
91         for (int i = 0; i < decorators.length; i++) {
92             ILabelDecorator decorator = decorators[i];
93             if(decorator instanceof IColorDecorator) {
94                 return ((IColorDecorator)decorator).decorateBackground(element);
95             }
96         }
97         return null;
98     }
99 }
Popular Tags