1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
\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.charts.ui;
\r
14 import java.awt.Color;
\r
15 import java.util.Map;
\r
17 import org.eclipse.jface.resource.ImageDescriptor;
\r
18 import org.simantics.browsing.ui.model.images.ImageRule;
\r
19 import org.simantics.charts.ontology.ChartResource;
\r
20 import org.simantics.databoard.Bindings;
\r
21 import org.simantics.db.ReadGraph;
\r
22 import org.simantics.db.Resource;
\r
23 import org.simantics.db.exception.DatabaseException;
\r
24 import org.simantics.diagram.stubs.G2DResource;
\r
25 import org.simantics.trend.impl.JarisPaints;
\r
26 import org.simantics.utils.datastructures.ArrayMap;
\r
28 public enum ChartItemImageRule implements ImageRule {
\r
31 public static ChartItemImageRule get() { return INSTANCE; }
\r
33 public static final String COLUMN_KEY = "single";
\r
34 public static final String[] COLUMN_KEYS = { COLUMN_KEY };
\r
36 ChartItemIcon chartIcons = new ChartItemIcon();
\r
39 public boolean isCompatible(Class<?> contentType) {
\r
40 return contentType.equals(Resource.class);
\r
44 public Map<String, ImageDescriptor> getImage(ReadGraph graph, Object content) throws DatabaseException {
\r
45 Resource item = (Resource) content;
\r
46 ChartResource CHART = ChartResource.getInstance(graph);
\r
47 G2DResource G2D = G2DResource.getInstance(graph);
\r
50 float[] customColor = graph.getPossibleRelatedValue(item, G2D.HasColor, Bindings.FLOAT_ARRAY);
\r
51 if (customColor != null && customColor.length >= 3)
\r
52 color = new Color(customColor[0], customColor[1], customColor[2]);
\r
53 if (color == null) {
\r
54 Integer index = graph.getPossibleRelatedValue(item, CHART.Chart_Item_Index);
\r
55 if ( index == null ) index = 1;
\r
56 color = JarisPaints.getColor( index );
\r
59 Resource rend = graph.getPossibleObject(item, CHART.Chart_Item_Renderer);
\r
60 boolean binary = CHART.Renderer_Binary.equals(rend);
\r
62 ImageDescriptor icon = chartIcons.createIcon(!binary, color, false);
\r
64 return ArrayMap.make(COLUMN_KEYS, new ImageDescriptor[] { icon });
\r