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