| /******************************************************************************* |
| * 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.examples.mobile_platform.provider; |
| |
| import java.text.DecimalFormat; |
| |
| import org.eclipse.apogy.examples.mobile_platform.MobilePlatform; |
| import org.eclipse.emf.common.notify.AdapterFactory; |
| |
| public class MobilePlatformCustomItemProvider extends MobilePlatformItemProvider { |
| /** |
| * This is the degree symbol, as expressed in unicode |
| */ |
| public static final String DEGREE_SYM = "\u00b0"; |
| private final DecimalFormat positionFormat = new DecimalFormat("0.000"); |
| private final DecimalFormat linearVelocityFormat = new DecimalFormat("0.000"); |
| private final DecimalFormat angularVelocityFormat = new DecimalFormat("0.000"); |
| |
| public MobilePlatformCustomItemProvider(AdapterFactory adapterFactory) { |
| super(adapterFactory); |
| } |
| |
| @Override |
| public String getText(Object object) { |
| // Get the current mobile platform |
| MobilePlatform mobilePlatform = (MobilePlatform) object; |
| |
| // Get the default label |
| String label = getString("_UI_MobilePlatform_type"); |
| |
| // Adds additional info as part of the text. |
| label += getMobilePlatformSuffixText(mobilePlatform); |
| |
| return label; |
| } |
| |
| /** |
| * Return addition MobilePlatform information as apart of a displayable text. |
| * |
| * @param mobilePlatform The MobilePlatform. |
| * @return The text. |
| */ |
| protected String getMobilePlatformSuffixText(MobilePlatform mobilePlatform) { |
| String text = ""; |
| // If the mobile platform isn't null |
| if (mobilePlatform != null) { |
| // Add on appropriate values |
| text += " (X=" + this.positionFormat.format(mobilePlatform.getPosition().getX()) + ", Y=" |
| + this.positionFormat.format(mobilePlatform.getPosition().getY()) + ", LinVel=" |
| + this.linearVelocityFormat.format(mobilePlatform.getLinearVelocity()) + "(m/s)" + ", AngVel=" |
| + this.angularVelocityFormat.format(Math.toDegrees(mobilePlatform.getAngularVelocity())) + "(" |
| + DEGREE_SYM + "/s))"; |
| } |
| |
| return text; |
| } |
| |
| } |