package org.mwc.cmap.core.preferences;

import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.jface.preference.*;
import org.eclipse.ui.*;
import org.mwc.cmap.core.CorePlugin;

import MWC.GUI.Properties.UnitsPropertyEditor;

/**
 * This class represents a preference page that is contributed to the
 * Preferences dialog. By subclassing <samp>FieldEditorPreferencePage</samp>,
 * we can use the field support built into JFace that allows us to create a page
 * that is small and knows how to save, restore and apply itself.
 * <p>
 * This page is used to modify preferences only. They are stored in the
 * preference store that belongs to the main plug-in class. That way,
 * preferences can be accessed directly via the preference store.
 */

public class CMAPPrefsPage extends FieldEditorPreferencePage implements
		IWorkbenchPreferencePage
{

	public CMAPPrefsPage()
	{
		super(GRID);
		setPreferenceStore(CorePlugin.getDefault().getPreferenceStore());
		setDescription("Settings applicable to MWC's Core Maritime Analysis Platform");
	}

	/** the tags and labels to use in the range units editor
	 * 
	 */
	private static String[][] _distanceUnitTags;

	/**
	 * Creates the field editors. Field editors are abstractions of the common GUI
	 * blocks needed to manipulate various types of preferences. Each field editor
	 * knows how to save and restore itself.
	 */
	public void createFieldEditors()
	{
		// initialise the units tags, if we have to
		if (_distanceUnitTags == null)
		{
			// get the unit types
			UnitsPropertyEditor units = new UnitsPropertyEditor();
			String[] tags = units.getTags();

			_distanceUnitTags = new String[tags.length][2];
			for (int i = 0; i < tags.length; i++)
			{
				_distanceUnitTags[i][0] = tags[i];
				_distanceUnitTags[i][1] = tags[i];
			}
		}

		addField(new RadioGroupFieldEditor(PreferenceConstants.RNG_UNITS,
				"Default &range units:", 1, _distanceUnitTags, getFieldEditorParent()));
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
	 */
	public void init(IWorkbench workbench)
	{
	}

	/**
	 * Constant definitions for plug-in preferences
	 */
	public static class PreferenceConstants
	{
		public static final String RNG_UNITS = MWC.GUI.Properties.UnitsPropertyEditor.UNITS_PROPERTY;
	}

	public static class CMAPPreferenceInitializer extends
			AbstractPreferenceInitializer
	{

		/*
		 * (non-Javadoc)
		 * 
		 * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
		 */
		public void initializeDefaultPreferences()
		{
			IPreferenceStore store = CorePlugin.getDefault().getPreferenceStore();
		}

	}

}
@@ -210,16 +210,71 @@
 lugin;%0A%0A
+import Debrief.Tools.Tote.Calculations.relBearingCalc;%0A
 import M
@@ -1243,16 +1243,146 @@
 nitTags;
+%0A%09%0A%09/** the tags and labels to use in the relative bearing format selector%0A%09 * %0A%09 */%0A%09private static String%5B%5D%5B%5D _relBearingTags;%0A%09
 %0A%0A%09/**%0A%09
@@ -2018,119 +2018,639 @@
 %0A%0A%09%09
-addField(new RadioGroupFieldEditor(PreferenceConstants.RNG_UNITS,%0A%09%09%09%09%22Default &range units:%22, 1, _distanceUnit
+// initialise the units tags, if we have to%0A%09%09if (_relBearingTags == null)%0A%09%09%7B%0A%09%09%09_relBearingTags = new String%5B2%5D%5B2%5D;%0A%09%09%09_relBearingTags%5B0%5D%5B0%5D = %22UK format (R180..G180)%22;%0A%09%09%09_relBearingTags%5B0%5D%5B1%5D = relBearingCalc.UK_REL_BEARING_FORMAT;%0A%09%09%09_relBearingTags%5B1%5D%5B0%5D = %22US format (0..360)%22;%0A%09%09%09_relBearingTags%5B1%5D%5B1%5D = relBearingCalc.US_REL_BEARING_FORMAT;%0A%09%09%7D%0A%0A%09%09addField(new RadioGroupFieldEditor(PreferenceConstants.RNG_UNITS,%0A%09%09%09%09%22Default &range units:%22, 1, _distanceUnitTags, getFieldEditorParent()));%0A%09%09%0A%09%09%0A%09%09addField(new RadioGroupFieldEditor(PreferenceConstants.REL_BEARING_FORMAT,%0A%09%09%09%09%22Relative &bearingf format:%22, 1, _relBearing
 Tags
@@ -3040,16 +3040,101 @@
 OPERTY;%0A
+%09%09public static final String REL_BEARING_FORMAT = relBearingCalc.REL_BEARING_FORMAT;%0A
 %09%7D%0A%0A%09pub
@@ -3488,16 +3488,115 @@
 tore();%0A
+%09%09%09store.setDefault(PreferenceConstants.REL_BEARING_FORMAT, relBearingCalc.UK_REL_BEARING_FORMAT);%0A
 %09%09%7D%0A%0A%09%7D%0A

Add support for rel-bearing-format