IndexTranslator.java 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package ui.view;
  2. import interfaces.IGraphedElement;
  3. import ui.controller.SingletonControl;
  4. import ui.model.Model;
  5. public class IndexTranslator {
  6. public static int STANDARD_GRAPH_ACCURACY = 100;
  7. /**
  8. * Determines the index of the internal value array
  9. * of an element that should be used, since elements only save 100 values,
  10. * but iterations and local period can be anything between 1 and 100000.
  11. *
  12. * @param m the corresponding model.
  13. * @param e the element for which the calculation should be made.
  14. * @param timeStep the iteration for which the calculation should be made.
  15. * @return
  16. */
  17. public static int getEffectiveIndex(Model m, IGraphedElement e, int timeStep){
  18. if(e.isStretching())return timeStep*100/(m==null?STANDARD_GRAPH_ACCURACY:m.getIterations());
  19. else return timeStep%e.getLocalPeriod()*100/e.getLocalPeriod();
  20. }
  21. /**
  22. * Same as getEffectiveIndex(Model, IGraphedElement, int),
  23. * but using the Model obtained from the singleton controller
  24. * to determine the total number of iterations(for "use global").
  25. */
  26. public static int getEffectiveIndex(IGraphedElement e, int timeStep){
  27. return getEffectiveIndex(SingletonControl.getInstance().getControl()==null ? null : SingletonControl.getInstance().getControl().getModel(),e,timeStep);
  28. }
  29. /**
  30. * Same as getEffectiveIndex(Model, IGraphedElement),
  31. * but the current iteration is also obtained from the standard model.
  32. */
  33. public static int getEffectiveIndex(IGraphedElement e){
  34. return getEffectiveIndex(e,SingletonControl.getInstance().getControl().getModel().getCurIteration());
  35. }
  36. }