1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.utils.ui.color;
\r
14 import org.eclipse.swt.SWT;
\r
15 import org.eclipse.swt.events.PaintEvent;
\r
16 import org.eclipse.swt.events.PaintListener;
\r
17 import org.eclipse.swt.graphics.GC;
\r
18 import org.eclipse.swt.graphics.Image;
\r
19 import org.eclipse.swt.graphics.Rectangle;
\r
20 import org.eclipse.swt.widgets.Canvas;
\r
21 import org.eclipse.swt.widgets.Composite;
\r
22 import org.eclipse.swt.widgets.Display;
\r
26 * Canvas that shows color gradients
\r
28 * @author Marko Luukkainen
\r
31 public class ColorGradientCanvas extends Canvas{
\r
32 ColorGradient gradient;
\r
35 public ColorGradientCanvas(Composite parent, int style) {
\r
36 // FIXME : use xor operation to get SWT.HORIZONTAL and SWT.VERTICAL
\r
37 // out of style when it's passed to parent
\r
38 super(parent,SWT.BORDER);
\r
39 this.style = style & (SWT.VERTICAL | SWT.HORIZONTAL) ;
\r
40 addPaintListener(new PaintListener() {
\r
41 public void paintControl(PaintEvent e) {
\r
43 Rectangle clip = gc.getClipping();
\r
44 if (gradient != null) {
\r
45 Image image = gradient.getGradientImage(clip.width,clip.height,ColorGradientCanvas.this.style);
\r
46 gc.drawImage(image, 0, 0);
\r
49 gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
\r
50 gc.fillRectangle(clip);
\r
56 public void setGradient(ColorGradient gradient) {
\r
57 this.gradient = gradient;
\r