Project

General

Profile

Download (2.76 KB) Statistics
| Branch: | Tag: | Revision:
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2010 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

    
12
package org.eclipse.gef.internal.ui.palette.editparts;
13

    
14
import org.eclipse.swt.graphics.Color;
15

    
16
import org.eclipse.draw2d.Border;
17
import org.eclipse.draw2d.ButtonModel;
18
import org.eclipse.draw2d.ChangeEvent;
19
import org.eclipse.draw2d.ChangeListener;
20
import org.eclipse.draw2d.FigureUtilities;
21
import org.eclipse.draw2d.Graphics;
22
import org.eclipse.draw2d.ImageFigure;
23
import org.eclipse.draw2d.Label;
24
import org.eclipse.draw2d.MarginBorder;
25
import org.eclipse.draw2d.Toggle;
26

    
27
import org.eclipse.gef.internal.InternalImages;
28
import org.eclipse.gef.internal.ui.palette.PaletteColorUtil;
29
import org.eclipse.gef.ui.palette.PaletteMessages;
30

    
31
/**
32
 * This is the figure for the pinned and unpinned toggle.
33
 * 
34
 * @author crevells
35
 * @since 3.4
36
 */
37
public class PinFigure extends Toggle {
38

    
39
	private static final Color PIN_HOTSPOT_COLOR = FigureUtilities.mixColors(
40
			PaletteColorUtil.WIDGET_LIST_BACKGROUND,
41
			PaletteColorUtil.WIDGET_NORMAL_SHADOW, 0.60);
42

    
43
	private static final Border TOOLTIP_BORDER = new MarginBorder(0, 2, 1, 0);
44

    
45
	public PinFigure() {
46
		super(new ImageFigure(InternalImages.get(InternalImages.IMG_UNPINNED)));
47
		setRolloverEnabled(true);
48
		setRequestFocusEnabled(false);
49
		Label tooltip = new Label(PaletteMessages.TOOLTIP_PIN_FIGURE);
50
		tooltip.setBorder(TOOLTIP_BORDER);
51
		setToolTip(tooltip);
52
		setOpaque(false);
53

    
54
		addChangeListener(new ChangeListener() {
55

    
56
			public void handleStateChanged(ChangeEvent e) {
57
				if (e.getPropertyName().equals(ButtonModel.SELECTED_PROPERTY)) {
58
					if (isSelected()) {
59
						((ImageFigure) (getChildren().get(0)))
60
								.setImage(InternalImages
61
										.get(InternalImages.IMG_PINNED));
62
						((Label) getToolTip())
63
								.setText(PaletteMessages.TOOLTIP_UNPIN_FIGURE);
64
					} else {
65
						((ImageFigure) (getChildren().get(0)))
66
								.setImage(InternalImages
67
										.get(InternalImages.IMG_UNPINNED));
68
						((Label) getToolTip())
69
								.setText(PaletteMessages.TOOLTIP_PIN_FIGURE);
70
					}
71
				}
72
			}
73
		});
74
	}
75

    
76
	protected void paintFigure(Graphics graphics) {
77
		super.paintFigure(graphics);
78

    
79
		ButtonModel model = getModel();
80
		if (isRolloverEnabled() && model.isMouseOver()) {
81
			graphics.setBackgroundColor(PIN_HOTSPOT_COLOR);
82
			graphics.fillRoundRectangle(getClientArea().getCopy().shrink(1, 1),
83
					3, 3);
84
		}
85
	}
86
}
(13-13/22)