X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.charts%2Fsrc%2Forg%2Fsimantics%2Fcharts%2Fui%2FChartItemImageRule.java;fp=bundles%2Forg.simantics.charts%2Fsrc%2Forg%2Fsimantics%2Fcharts%2Fui%2FChartItemImageRule.java;h=eb5a8d0703eeafbbe5ba7f5bddb52a6ab879a68f;hp=2b790f5bcaa2449bee4d067bd8aa518b38bb37ae;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.charts/src/org/simantics/charts/ui/ChartItemImageRule.java b/bundles/org.simantics.charts/src/org/simantics/charts/ui/ChartItemImageRule.java index 2b790f5bc..eb5a8d070 100644 --- a/bundles/org.simantics.charts/src/org/simantics/charts/ui/ChartItemImageRule.java +++ b/bundles/org.simantics.charts/src/org/simantics/charts/ui/ChartItemImageRule.java @@ -1,67 +1,67 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 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 - *******************************************************************************/ -package org.simantics.charts.ui; - -import java.awt.Color; -import java.util.Map; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.simantics.browsing.ui.model.images.ImageRule; -import org.simantics.charts.ontology.ChartResource; -import org.simantics.databoard.Bindings; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.diagram.stubs.G2DResource; -import org.simantics.trend.impl.JarisPaints; -import org.simantics.utils.datastructures.ArrayMap; - -public enum ChartItemImageRule implements ImageRule { - - INSTANCE; - public static ChartItemImageRule get() { return INSTANCE; } - - public static final String COLUMN_KEY = "single"; - public static final String[] COLUMN_KEYS = { COLUMN_KEY }; - - ChartItemIcon chartIcons = new ChartItemIcon(); - - @Override - public boolean isCompatible(Class contentType) { - return contentType.equals(Resource.class); - } - - @Override - public Map getImage(ReadGraph graph, Object content) throws DatabaseException { - Resource item = (Resource) content; - ChartResource CHART = ChartResource.getInstance(graph); - G2DResource G2D = G2DResource.getInstance(graph); - - Color color = null; - float[] customColor = graph.getPossibleRelatedValue(item, G2D.HasColor, Bindings.FLOAT_ARRAY); - if (customColor != null && customColor.length >= 3) - color = new Color(customColor[0], customColor[1], customColor[2]); - if (color == null) { - Integer index = graph.getPossibleRelatedValue(item, CHART.Chart_Item_Index); - if ( index == null ) index = 1; - color = JarisPaints.getColor( index ); - } - - Resource rend = graph.getPossibleObject(item, CHART.Chart_Item_Renderer); - boolean binary = CHART.Renderer_Binary.equals(rend); - - ImageDescriptor icon = chartIcons.createIcon(!binary, color, false); - - return ArrayMap.make(COLUMN_KEYS, new ImageDescriptor[] { icon }); - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2011 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 + *******************************************************************************/ +package org.simantics.charts.ui; + +import java.awt.Color; +import java.util.Map; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.simantics.browsing.ui.model.images.ImageRule; +import org.simantics.charts.ontology.ChartResource; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.stubs.G2DResource; +import org.simantics.trend.impl.JarisPaints; +import org.simantics.utils.datastructures.ArrayMap; + +public enum ChartItemImageRule implements ImageRule { + + INSTANCE; + public static ChartItemImageRule get() { return INSTANCE; } + + public static final String COLUMN_KEY = "single"; + public static final String[] COLUMN_KEYS = { COLUMN_KEY }; + + ChartItemIcon chartIcons = new ChartItemIcon(); + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Resource.class); + } + + @Override + public Map getImage(ReadGraph graph, Object content) throws DatabaseException { + Resource item = (Resource) content; + ChartResource CHART = ChartResource.getInstance(graph); + G2DResource G2D = G2DResource.getInstance(graph); + + Color color = null; + float[] customColor = graph.getPossibleRelatedValue(item, G2D.HasColor, Bindings.FLOAT_ARRAY); + if (customColor != null && customColor.length >= 3) + color = new Color(customColor[0], customColor[1], customColor[2]); + if (color == null) { + Integer index = graph.getPossibleRelatedValue(item, CHART.Chart_Item_Index); + if ( index == null ) index = 1; + color = JarisPaints.getColor( index ); + } + + Resource rend = graph.getPossibleObject(item, CHART.Chart_Item_Renderer); + boolean binary = CHART.Renderer_Binary.equals(rend); + + ImageDescriptor icon = chartIcons.createIcon(!binary, color, false); + + return ArrayMap.make(COLUMN_KEYS, new ImageDescriptor[] { icon }); + } + +}