]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.ui/src/org/simantics/ui/colors/RGBAdapter.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.ui / src / org / simantics / ui / colors / RGBAdapter.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.ui.colors;
13
14 import org.eclipse.swt.graphics.RGB;
15 import org.simantics.databoard.Bindings;
16 import org.simantics.databoard.binding.Binding;
17 import org.simantics.db.AsyncReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.common.adaption.ResourceAdapter;
20 import org.simantics.db.procedure.AsyncProcedure;
21
22 public class RGBAdapter implements ResourceAdapter<RGB> {
23
24     public static class RGBDouble {
25         public double red;
26         public double green;
27         public double blue;
28     }
29
30     public static final Binding BINDING = Bindings.getBindingUnchecked(RGBDouble.class);
31
32     @Override
33     public void adapt(AsyncReadGraph g, Resource source, Resource r, final AsyncProcedure<RGB> procedure) {
34         g.forValue(r, BINDING, new AsyncProcedure<RGBDouble>() {
35             @Override
36             public void execute(AsyncReadGraph graph, RGBDouble result) {
37                 procedure.execute(graph, 
38                         new RGB(
39                                 (int)(result.red*255.0),
40                                 (int)(result.green*255.0),
41                                 (int)(result.blue*255.0)
42                         )
43                 );
44             }
45
46             @Override
47             public void exception(AsyncReadGraph graph, Throwable throwable) {
48                 procedure.exception(graph, throwable);
49             }
50         });
51     }
52
53 }