| /******************************************************************************* |
| * Copyright (c) 2010 Zoltan Ujhelyi and Istvan Rath and Daniel Varro. |
| * 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: |
| * Istvan Rath - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.viatra2.visualisation.common.labelproviders.natives; |
| |
| import org.eclipse.viatra2.core.IModelSpace; |
| import org.eclipse.viatra2.errors.VPMRuntimeException; |
| import org.eclipse.viatra2.natives.NativeFunctionParameter; |
| import org.eclipse.viatra2.natives.VIATRANativeFunction; |
| import org.eclipse.viatra2.visualisation.common.labelproviders.HighlightableSmartLabelProvider; |
| |
| /** |
| * Native function that registers a color to be used for visualization. |
| * @author istvan rath |
| * |
| */ |
| @VIATRANativeFunction(name="viz.getcolor", |
| params = { |
| @NativeFunctionParameter( |
| name = "R", |
| type = { NativeFunctionParameter.ParameterType.INTEGER } |
| ), |
| @NativeFunctionParameter( |
| name = "G", |
| type = { NativeFunctionParameter.ParameterType.INTEGER } |
| ), |
| @NativeFunctionParameter( |
| name = "B", |
| type = { NativeFunctionParameter.ParameterType.INTEGER } |
| ), |
| }, |
| returns = { NativeFunctionParameter.ParameterType.STRING }) |
| public class GetColorFunction extends AbstractVisualisationFunction { |
| |
| |
| public Object run(IModelSpace msp, Object[] params) throws VPMRuntimeException { |
| int r=0,g=0,b=0; |
| int i = 0; |
| for (Object o : params) { |
| try { |
| switch (i%3) { |
| case 0: r=Integer.parseInt(o.toString()); break; |
| case 1: g=Integer.parseInt(o.toString()); break; |
| case 2: b=Integer.parseInt(o.toString()); break; |
| } |
| i++; |
| } catch (NumberFormatException e) { } |
| } |
| return HighlightableSmartLabelProvider.registerColor(r, g, b); |
| } |
| |
| public String getName() { |
| return "viz.getcolor"; |
| } |
| |
| public String getID() { |
| return getName(); |
| } |
| |
| public String getDescription() { |
| return "Registers a color to be used in viz highlighting"; |
| } |
| |
| } |