package ui.view; import interfaces.IGraphedElement; import ui.controller.SingletonControl; import ui.model.Model; public class IndexTranslator { public static int STANDARD_GRAPH_ACCURACY = 100; /** * Determines the index of the internal value array * of an element that should be used, since elements only save 100 values, * but iterations and local period can be anything between 1 and 100000. * * @param m the corresponding model. * @param e the element for which the calculation should be made. * @param timeStep the iteration for which the calculation should be made. * @return */ public static int getEffectiveIndex(Model m, IGraphedElement e, int timeStep){ if(e.isStretching())return timeStep*100/(m==null?STANDARD_GRAPH_ACCURACY:m.getIterations()); else return timeStep%e.getLocalPeriod()*100/e.getLocalPeriod(); } /** * Same as getEffectiveIndex(Model, IGraphedElement, int), * but using the Model obtained from the singleton controller * to determine the total number of iterations(for "use global"). */ public static int getEffectiveIndex(IGraphedElement e, int timeStep){ return getEffectiveIndex(SingletonControl.getInstance().getControl()==null ? null : SingletonControl.getInstance().getControl().getModel(),e,timeStep); } /** * Same as getEffectiveIndex(Model, IGraphedElement), * but the current iteration is also obtained from the standard model. */ public static int getEffectiveIndex(IGraphedElement e){ return getEffectiveIndex(e,SingletonControl.getInstance().getControl().getModel().getCurIteration()); } }