1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 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.ui.colors;
\r
14 import org.eclipse.swt.graphics.RGB;
\r
15 import org.simantics.databoard.Bindings;
\r
16 import org.simantics.databoard.binding.Binding;
\r
17 import org.simantics.db.AsyncReadGraph;
\r
18 import org.simantics.db.Resource;
\r
19 import org.simantics.db.common.adaption.ResourceAdapter;
\r
20 import org.simantics.db.procedure.AsyncProcedure;
\r
22 public class RGBAdapter implements ResourceAdapter<RGB> {
\r
24 public static class RGBDouble {
\r
26 public double green;
\r
30 public static final Binding BINDING = Bindings.getBindingUnchecked(RGBDouble.class);
\r
33 public void adapt(AsyncReadGraph g, Resource source, Resource r, final AsyncProcedure<RGB> procedure) {
\r
34 g.forValue(r, BINDING, new AsyncProcedure<RGBDouble>() {
\r
36 public void execute(AsyncReadGraph graph, RGBDouble result) {
\r
37 procedure.execute(graph,
\r
39 (int)(result.red*255.0),
\r
40 (int)(result.green*255.0),
\r
41 (int)(result.blue*255.0)
\r
47 public void exception(AsyncReadGraph graph, Throwable throwable) {
\r
48 procedure.exception(graph, throwable);
\r