Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 63f0f8d7b0a437e3896826f2fcc1b24de67340c3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*******************************************************************************
 * Copyright (c) 2000, 2012 IBM Corporation and others.
 * Copyright (C) 2009, Tor Arne Vestbø <torarnv@gmail.com>
 * Copyright (C) 2010, Mathias Kinzler <mathias.kinzler@sap.com>
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *******************************************************************************/
package org.eclipse.egit.ui.internal.decorators;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.DecorationContext;
import org.eclipse.jface.viewers.IDecoration;
import org.eclipse.jface.viewers.IDecorationContext;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;

/**
 * IDecoration which stores the applied decoration elements and provides methods
 * for getting them.
 */
public class DecorationResult implements IDecoration {

	private List<String> prefixes = new ArrayList<>();

	private List<String> suffixes = new ArrayList<>();

	private ImageDescriptor overlay = null;

	private Color backgroundColor = null;

	private Font font = null;

	private Color foregroundColor = null;

	/**
	 * Adds an icon overlay to the decoration
	 * <p>
	 * Copies the behavior of <code>DecorationBuilder</code> of only allowing
	 * the overlay to be set once.
	 */
	@Override
	public void addOverlay(ImageDescriptor overlayImage) {
		if (overlay == null)
			overlay = overlayImage;
	}

	@Override
	public void addOverlay(ImageDescriptor overlayImage, int quadrant) {
		addOverlay(overlayImage);
	}

	@Override
	public void addPrefix(String prefix) {
		prefixes.add(prefix);
	}

	@Override
	public void addSuffix(String suffix) {
		suffixes.add(suffix);
	}

	@Override
	public IDecorationContext getDecorationContext() {
		return new DecorationContext();
	}

	@Override
	public void setBackgroundColor(Color color) {
		backgroundColor = color;
	}

	@Override
	public void setForegroundColor(Color color) {
		foregroundColor = color;
	}

	@Override
	public void setFont(Font font) {
		this.font = font;
	}

	/**
	 * @return the overlay image which was set
	 */
	public ImageDescriptor getOverlay() {
		return overlay;
	}

	/**
	 * @return background color
	 */
	public Color getBackgroundColor() {
		return backgroundColor;
	}

	/**
	 * @return foreground color
	 */
	public Color getForegroundColor() {
		return foregroundColor;
	}

	/**
	 * @return font
	 */
	public Font getFont() {
		return font;
	}

	/**
	 * @return text decoration prefix
	 */
	public String getPrefix() {
		StringBuilder sb = new StringBuilder();
		for (Iterator<String> iter = prefixes.iterator(); iter.hasNext();) {
			sb.append(iter.next());
		}
		return sb.toString();
	}

	/**
	 * @return text decoration suffix
	 */
	public String getSuffix() {
		StringBuilder sb = new StringBuilder();
		for (Iterator<String> iter = suffixes.iterator(); iter.hasNext();) {
			sb.append(iter.next());
		}
		return sb.toString();
	}

}

Back to the top