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