blob: c609fb490b2a1ef1da18746f155a1ccfd69a3c72 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency
* 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:
* Pierre Allard,
* Regent L'Archeveque - initial API and implementation
*
* SPDX-License-Identifier: EPL-1.0
*
*******************************************************************************/
package org.eclipse.apogy.core.environment.ui.impl;
import javax.vecmath.Color3f;
import javax.vecmath.Point2d;
import javax.vecmath.Point3f;
import org.eclipse.emf.ecore.EDataType;
import org.jfree.data.xy.XYDataItem;
import org.jfree.data.xy.XYSeries;
public class ApogyCoreEnvironmentUIFactoryCustomImpl extends ApogyCoreEnvironmentUIFactoryImpl {
public Point2d createPoint2dFromString(EDataType eDataType, String initialValue) {
String[] values = initialValue.split(",");
double x = Double.parseDouble(values[0]);
double y = Double.parseDouble(values[1]);
return new Point2d(x, y);
}
public String convertPoint2dToString(EDataType eDataType, Object instanceValue) {
Point2d point2d = (Point2d) instanceValue;
return point2d.x + "," + point2d.y;
}
public Color3f createColor3fFromString(EDataType eDataType, String initialValue) {
Color3f color3f = new Color3f();
String[] values = initialValue.split(",");
color3f.x = Float.parseFloat(values[0]);
color3f.y = Float.parseFloat(values[1]);
color3f.z = Float.parseFloat(values[2]);
return color3f;
}
@Override
public String convertColor3fToString(EDataType eDataType, Object instanceValue) {
Color3f color3f = (Color3f) instanceValue;
String string = color3f.x + "," + color3f.y + "," + color3f.z;
return string;
}
@Override
public Point3f createPoint3fFromString(EDataType eDataType, String initialValue) {
Point3f point3f = new Point3f();
String[] values = initialValue.split(",");
point3f.x = Float.parseFloat(values[0]);
point3f.y = Float.parseFloat(values[1]);
point3f.z = Float.parseFloat(values[2]);
return point3f;
}
@Override
public String convertPoint3fToString(EDataType eDataType, Object instanceValue) {
Point3f point3f = (Point3f) instanceValue;
String string = point3f.x + "," + point3f.y + "," + point3f.z;
return string;
}
@Override
public XYSeries createXYSeriesFromString(EDataType eDataType, String initialValue) {
XYSeries xySeries = new XYSeries("Unamed", false, true);
String[] values = initialValue.split(",");
int i = 0;
while (i + 1 < values.length) {
double x = Double.parseDouble(values[i]);
double y = Double.parseDouble(values[i + 1]);
XYDataItem xyDataItem = new XYDataItem(x, y);
xySeries.add(xyDataItem);
i += 2;
}
return xySeries;
}
@Override
public String convertXYSeriesToString(EDataType eDataType, Object instanceValue) {
String string = new String();
XYSeries xySeries = (XYSeries) instanceValue;
for (int i = 0; i < xySeries.getItemCount(); i++) {
XYDataItem xyDataItem = xySeries.getDataItem(i);
string += xyDataItem.getX() + "," + xyDataItem.getY();
if (i + 1 < xySeries.getItemCount())
string += ",";
}
return string;
}
} // ApogyCoreEnvironmentUIFactoryImpl