package ui.view; import interfaces.LocalMode; 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, LocalMode e, int timeStep){ if(e.isUsingLocalPeriod())return timeStep%e.getLocalPeriod()*100/e.getLocalPeriod(); else return timeStep*100/(m==null?STANDARD_GRAPH_ACCURACY:m.getIterations()); } /** * 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(LocalMode 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(LocalMode e){ return getEffectiveIndex(e,SingletonControl.getInstance().getControl().getModel().getCurIteration()); } }