1 package com.github.celldynamics.quimp; 2 3 import java.util.List; 4 5 import org.scijava.vecmath.Point2d; 6 import org.slf4j.Logger; 7 import org.slf4j.LoggerFactory; 8 9 /** 10 * Accessor that masks all public methods from object it holds except those manually exposed. 11 * 12 * <p>This class is used for limiting access to public methods of QuimP from external plugins. It 13 * prevents calling those methods in unchecked way. 14 * 15 * <p>Support bi-directional communication. Plugin can call: -# updateView() for updating view (and 16 * recalculating all plugins) -# getSnakeasXX() for current snake (only for previewing purposes). 17 * 18 * @author p.baniukiewicz 19 * 20 */ 21 public class ViewUpdater { 22 23 /** 24 * The Constant LOGGER. 25 */ 26 static final Logger LOGGER = LoggerFactory.getLogger(ViewUpdater.class.getName()); 27 private Object ob; 28 private Snake snake; //!< Hold one snake from main view that can be requested by plugin 29 30 /** 31 * Connect object to accessor. 32 * 33 * @param ob Object 34 */ 35 public ViewUpdater(Object ob) { 36 this.ob = ob; 37 } 38 39 /** 40 * Connect current snake (on current frame) to this object. 41 * 42 * <p>Connected snake can be requested by plugins (always as copy) 43 * 44 * @param snake Snake to be connected. I can be null when user e.g. deleted last object 45 */ 46 protected void connectSnakeObject(final Snake snake) { 47 if (snake != null) { 48 LOGGER.trace("Remembered snake: " + snake.getSnakeID()); 49 } else { 50 LOGGER.trace("Remembered snake: " + "null"); 51 } 52 this.snake = snake; 53 } 54 55 /** 56 * Calls updateView method from object ob. 57 * 58 * <p>Also stores current plugin configuration locally in QuimP. 59 * 60 * @see SnakePluginList 61 */ 62 public void updateView() { 63 if (ob instanceof BOA_) { 64 ((BOA_) ob).recalculatePlugins(); 65 } else { 66 throw new RuntimeException("Class not supported"); 67 } 68 } 69 70 /** 71 * Request copy of connected snake for previewing purposes. 72 * 73 * @return copy of connected snake as list of points or empty list if snake is not connected 74 */ 75 public List<Point2d> getSnakeasPoints() { 76 if (snake != null) { 77 return snake.asList(); 78 } else { 79 return null; 80 } 81 } 82 83 /** 84 * Request copy of connected snake for previewing purposes. 85 * 86 * @return copy of connected snake as Snake 87 */ 88 public Snake getSnakeasSnake() { 89 Snake ret = null; 90 if (snake != null) { 91 ret = new Snake(snake, snake.getSnakeID()); 92 } 93 return ret; 94 } 95 96 }