Skip to main content
summaryrefslogtreecommitdiffstats
blob: ed4fdfa709a0281d64b115c9cc3b086b2ae4153b (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
/*******************************************************************************
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylyn.internal.tasks.ui;

import java.lang.reflect.Field;

import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.widgets.Display;

/**
 * @author Mik Kersten
 */
public class TaskListColorsAndFonts {

	public static final String THEME_COLOR_TASKS_INCOMING_BACKGROUND = "org.eclipse.mylyn.tasks.ui.colors.incoming.background";

	public static final String THEME_COLOR_TASK_OVERDUE = "org.eclipse.mylyn.tasks.ui.colors.foreground.overdue";

	public static final String THEME_COLOR_TASK_THISWEEK_SCHEDULED = "org.eclipse.mylyn.tasks.ui.colors.foreground.thisweek.scheduled";

	public static final String THEME_COLOR_COMPLETED = "org.eclipse.mylyn.tasks.ui.colors.foreground.completed";

	public static final String THEME_COLOR_TASK_TODAY_SCHEDULED = "org.eclipse.mylyn.tasks.ui.colors.foreground.today.scheduled";

	public static final String THEME_COLOR_TASK_TODAY_COMPLETED = "org.eclipse.mylyn.tasks.ui.colors.foreground.today.completed";

	public static final String THEME_COLOR_CATEGORY_GRADIENT_START = "org.eclipse.mylyn.tasks.ui.colors.category.gradient.start";

	public static final String THEME_COLOR_CATEGORY_GRADIENT_END = "org.eclipse.mylyn.tasks.ui.colors.category.gradient.end";

	public static final String THEME_COLOR_TASKLIST_CATEGORY = THEME_COLOR_CATEGORY_GRADIENT_END;
	
	public static final Color BACKGROUND_ARCHIVE = new Color(Display.getDefault(), 225, 226, 246);

	public static final Color COLOR_TASK_ACTIVE = new Color(Display.getDefault(), 36, 22, 50);

	public static final Color COLOR_LABEL_CAUTION = new Color(Display.getDefault(), 200, 10, 30);

	public static final Color COLOR_HYPERLINK = new Color(Display.getDefault(), 0, 0, 255);

	public static final Color COLOR_SPELLING_ERROR = new Color(Display.getDefault(), 255, 0, 0);

	public static final Font BOLD = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);

	public static final Font ITALIC = JFaceResources.getFontRegistry().getItalic(JFaceResources.DEFAULT_FONT);

	public static Font STRIKETHROUGH;

	static {
		Font defaultFont = JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT);
		FontData[] defaultData = defaultFont.getFontData();
		if (defaultData != null && defaultData.length == 1) {
			FontData data = new FontData(defaultData[0].getName(), defaultData[0].getHeight(), defaultData[0]
					.getStyle());

			// NOTE: Windows XP only, for: data.data.lfStrikeOut = 1;
			try {
				Field dataField = data.getClass().getDeclaredField("data");
				Object dataObject = dataField.get(data);
				Class<?> clazz = dataObject.getClass().getSuperclass();
				Field strikeOutFiled = clazz.getDeclaredField("lfStrikeOut");
				strikeOutFiled.set(dataObject, (byte) 1);
				STRIKETHROUGH = new Font(Display.getCurrent(), data);
			} catch (Throwable t) {
				// Linux or other platform
				STRIKETHROUGH = defaultFont;
			}
		} else {
			STRIKETHROUGH = defaultFont;
		}
	}

	/**
	 * NOTE: disposal of JFaceResources fonts handled by registry.
	 */
	public static void dispose() {
		if (STRIKETHROUGH != null && !STRIKETHROUGH.isDisposed()) {
			STRIKETHROUGH.dispose();
		}
		BACKGROUND_ARCHIVE.dispose();
		COLOR_LABEL_CAUTION.dispose();
		COLOR_TASK_ACTIVE.dispose();
		COLOR_HYPERLINK.dispose();
		COLOR_SPELLING_ERROR.dispose();
	}

	public static boolean isTaskListTheme(String property) {
		if (property == null) {
			return false;
		} else {
			return property.equals(TaskListColorsAndFonts.THEME_COLOR_TASKLIST_CATEGORY)
					|| property.equals(TaskListColorsAndFonts.THEME_COLOR_TASK_OVERDUE)
					|| property.equals(TaskListColorsAndFonts.THEME_COLOR_TASK_TODAY_COMPLETED)
					|| property.equals(TaskListColorsAndFonts.THEME_COLOR_TASK_TODAY_SCHEDULED)
					|| property.equals(TaskListColorsAndFonts.THEME_COLOR_TASK_TODAY_SCHEDULED)
					|| property.equals(TaskListColorsAndFonts.THEME_COLOR_TASK_THISWEEK_SCHEDULED)
					|| property.equals(TaskListColorsAndFonts.THEME_COLOR_TASKS_INCOMING_BACKGROUND)
					|| property.equals(TaskListColorsAndFonts.THEME_COLOR_CATEGORY_GRADIENT_START)
					|| property.equals(TaskListColorsAndFonts.THEME_COLOR_CATEGORY_GRADIENT_END);
		}
	}

	public static final String TASK_EDITOR_FONT = "org.eclipse.mylyn.tasks.ui.fonts.task.editor.comment";
												   
}

Back to the top