X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.utils.ui%2Fsrc%2Forg%2Fsimantics%2Futils%2Fui%2Fcolor%2FColorGradientCellEditor.java;fp=bundles%2Forg.simantics.utils.ui%2Fsrc%2Forg%2Fsimantics%2Futils%2Fui%2Fcolor%2FColorGradientCellEditor.java;h=08ff08cfd4643d68f8a16a43d7b0013e2a37932e;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/color/ColorGradientCellEditor.java b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/color/ColorGradientCellEditor.java new file mode 100644 index 000000000..08ff08cfd --- /dev/null +++ b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/color/ColorGradientCellEditor.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * 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: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +/* + * + * @author Toni Kalajainen + */ +package org.simantics.utils.ui.color; + +import org.eclipse.jface.viewers.DialogCellEditor; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +public class ColorGradientCellEditor extends DialogCellEditor { + + public ColorGradientCellEditor(Composite parent) { + super(parent); + } + + /** + * The composite showing the gradient + */ + private ColorGradientCanvas canvas; + + /* (non-Javadoc) + * Method declared on DialogCellEditor. + */ + protected Control createContents(Composite cell) { + Color bg = cell.getBackground(); + canvas = new ColorGradientCanvas(cell, getStyle()); + canvas.setBackground(bg); + return canvas; + } + + /* (non-Javadoc) + * Method declared on DialogCellEditor. + */ + protected Object openDialogBox(Control cellEditorWindow) { + ColorGradient value = (ColorGradient)getValue(); + ColorGradientDialog dialog = new ColorGradientDialog(cellEditorWindow.getShell(), value); + if (dialog.open() == Window.OK) + return dialog.getGradient(); + return value; + } + + /* (non-Javadoc) + * Method declared on DialogCellEditor. + */ + protected void updateContents(Object value) { + ColorGradient cg = (ColorGradient) value; + canvas.setGradient(cg); + } + + +}