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
14 * @author Toni Kalajainen
\r
16 package org.simantics.utils.ui.color;
\r
18 import org.eclipse.jface.viewers.DialogCellEditor;
\r
19 import org.eclipse.jface.window.Window;
\r
20 import org.eclipse.swt.graphics.Color;
\r
21 import org.eclipse.swt.widgets.Composite;
\r
22 import org.eclipse.swt.widgets.Control;
\r
24 public class ColorGradientCellEditor extends DialogCellEditor {
\r
26 public ColorGradientCellEditor(Composite parent) {
\r
31 * The composite showing the gradient
\r
33 private ColorGradientCanvas canvas;
\r
36 * Method declared on DialogCellEditor.
\r
38 protected Control createContents(Composite cell) {
\r
39 Color bg = cell.getBackground();
\r
40 canvas = new ColorGradientCanvas(cell, getStyle());
\r
41 canvas.setBackground(bg);
\r
46 * Method declared on DialogCellEditor.
\r
48 protected Object openDialogBox(Control cellEditorWindow) {
\r
49 ColorGradient value = (ColorGradient)getValue();
\r
50 ColorGradientDialog dialog = new ColorGradientDialog(cellEditorWindow.getShell(), value);
\r
51 if (dialog.open() == Window.OK)
\r
52 return dialog.getGradient();
\r
57 * Method declared on DialogCellEditor.
\r
59 protected void updateContents(Object value) {
\r
60 ColorGradient cg = (ColorGradient) value;
\r
61 canvas.setGradient(cg);
\r