/*-
 *******************************************************************************
 * Copyright (c) 2011, 2014 Diamond Light Source Ltd.
 * 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:
 *    Matthew Gerring - initial API and implementation and/or initial documentation
 *******************************************************************************/
package org.eclipse.dawnsci.plotting.api.axis;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.dawnsci.plotting.api.IPlottingSystem;

public class AxisUtils {

	public static String getUniqueAxisTitle(String title, IPlottingSystem<?> system) {
		String sugTitle = title;
		int iTitle      = 0;
		while (!isAxisUnique(sugTitle, system)) {
			iTitle++;
			sugTitle = title+iTitle;
		}
		return sugTitle;
	}

	public static boolean isAxisUnique(String title, IPlottingSystem<?> system) {
		final List<IAxis> axes = system.getAxes();
		for (IAxis ia : axes) {
			if (ia.getTitle()!=null && ia.getTitle().equals(title)) {
			    return false;
			}
 		}
		return true;
	}

	/**
	 * 
	 * @return Non-primary axes
	 */
	public static List<IAxis> getUserAxes(IPlottingSystem<?> system) {
		final List<IAxis>  axes = system.getAxes();
		final List<IAxis> avail = new ArrayList<IAxis>(axes.size());
		for (IAxis axis : axes) {
			if (axis.isPrimaryAxis()) continue;
			avail.add(axis);
		}
		return avail;
	}

}

@@ -1587,10 +1587,1086 @@
 il;%0A%09%7D%0A%0A
+%09/**%0A%09 * Find first X axis with given name %0A%09 * @param axisName%0A%09 * @param system%0A%09 * @return axis or null if not found%0A%09 */%0A%09public static IAxis findXAxis(String axisName, IPlottingSystem%3C?%3E system) %7B%0A%09%09return findAxis(false, axisName, system);%0A%09%7D%0A%0A%09/**%0A%09 * Find first Y axis with given name %0A%09 * @param axisName%0A%09 * @param system%0A%09 * @return axis or null if not found%0A%09 */%0A%09public static IAxis findYAxis(String axisName, IPlottingSystem%3C?%3E system) %7B%0A%09%09return findAxis(true, axisName, system);%0A%09%7D%0A%0A%09/**%0A%09 * Find first axis with given name %0A%09 * Note this is better than %7B@link IPlottingSystem#getAxis(String)%7D as that returns the first named%0A%09 * axis which can be an X or Y one%0A%09 * @param isY%0A%09 * @param axisName%0A%09 * @param system%0A%09 * @return%0A%09 */%0A%09public static IAxis findAxis(final boolean isY, final String axisName, final IPlottingSystem%3C?%3E system) %7B%0A%09%09if (axisName == null) %7B%0A%09%09%09return null;%0A%09%09%7D%0A%0A%09%09final List%3CIAxis%3E axes = system.getAxes();%0A%09%09for (IAxis a : axes) %7B%0A%09%09%09if (a.isYAxis() == isY && axisName.equals(a.getTitle())) %7B%0A%09%09%09%09return a;%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09return null;%0A%09%7D%0A
 %7D%0A

Add helper methods to find a named axis