Skip to main content
summaryrefslogtreecommitdiffstats
blob: d97b2e77cdcf393877baaddb23c1bd2b54a14270 (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
/*******************************************************************************
 * Copyright (c) 2004, 2009 Tasktop Technologies 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:
 *     Tasktop Technologies - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylyn.internal.provisional.commons.ui;

import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.resource.LocalResourceManager;
import org.eclipse.jface.window.ToolTip;
import org.eclipse.mylyn.commons.ui.GradientColors;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;

/**
 * A Custom JFace ToolTip that applies a gradient to the contents
 * 
 * @author Shawn Minto
 * @deprecated use {@link org.eclipse.mylyn.commons.ui.GradientToolTip} instead
 */
@Deprecated
public abstract class GradientToolTip extends ToolTip {

	private GradientColors colors;

	private LocalResourceManager resourceManager;

	public GradientToolTip(Control control, int style, boolean manualActivation) {
		super(control, style, manualActivation);
		initResources(control);
	}

	public GradientToolTip(Control control) {
		super(control);
		initResources(control);
	}

	private void initResources(Control control) {
		resourceManager = new LocalResourceManager(JFaceResources.getResources());
		colors = new GradientColors(control.getDisplay(), resourceManager);
	}

	@Override
	protected final Composite createToolTipContentArea(Event event, final Composite parent) {
		GradientCanvas gradient = new GradientCanvas(parent, SWT.NONE);
		gradient.setSeparatorVisible(false);
		GridLayout headLayout = new GridLayout();
		headLayout.marginHeight = 0;
		headLayout.marginWidth = 0;
		headLayout.horizontalSpacing = 0;
		headLayout.verticalSpacing = 0;
		headLayout.numColumns = 1;
		gradient.setLayout(headLayout);

		gradient.setBackgroundGradient(new Color[] { colors.getGradientBegin(), colors.getGradientEnd() },
				new int[] { 100 }, true);

		createToolTipArea(event, gradient);

		// force a null background so that the gradient shines through
		for (Control c : gradient.getChildren()) {
			setNullBackground(c);
		}

		return gradient;
	}

	private void setNullBackground(final Control outerCircle) {
		outerCircle.setBackground(null);
		if (outerCircle instanceof Composite) {
			((Composite) outerCircle).setBackgroundMode(SWT.INHERIT_FORCE);
			for (Control c : ((Composite) outerCircle).getChildren()) {
				setNullBackground(c);
			}
		}
	}

	protected abstract Composite createToolTipArea(Event event, Composite parent);
}

Back to the top