import ij.*; import ij.gui.*; import ij.plugin.frame.*; import java.awt.*; import java.awt.event.*; import java.util.*; import java.lang.reflect.*; /** This class "synchronizes" mouse input in multiple windows. Once several windows are synchronized, mouse events in any one of the synchronized windows are propagated to the others. Note, the notion of synchronization use by the SyncWindows class here (i.e. multiple windows that all get the same mouse input) is somewhat different than the use of the synchronize keyword in the Java language. (In Java, synchronize has to do w/ critical section access by multiple threads.) @author Patrick Kelly */ public class SyncWindows_ extends PlugInFrame implements ActionListener, MouseMotionListener, MouseListener { /** Indecies of synchronized image windows are maintained in this Vector. */ private Vector vwins = null; // Manage mouse information. private int oldX, oldY; private int x=0; private int y=0; /** List of currently displayed windows retrieved from ImageJ window manager. */ private java.awt.List wList; // Buttons for user control. private Button bDone, bSync, bSyncAll, bUnsync, bUnsyncAll; /** Hashtable to map title strings to image window ids. */ private Hashtable htWindows; // Control size of cursor box and clipping region. These could be // changed to tune performance. static final int RSZ = 20; static final int SZ = RSZ/2; static final int SCALE = 3; //-------------------------------------------------- /** Create window sync frame. Frame is shown via call to show() or by invoking run method. */ public SyncWindows_() { super("Synchronize Windows"); buildWindowsHash(); Panel p = controlPanel(); add(p); pack(); setResizable(false); //show(); } // -------------------------------------------------- /** Show the frame, making it accessible to users. */ public void run(String args) { show(); } // -------------------------------------------------- // // MouseMotionListener interface methods. // // -------------------------------------------------- /** Draws the "synchronize" cursor in each of the synchronized windows. */ public void mouseMoved(MouseEvent e) { oldX = x; oldY = y; x = e.getX(); y = e.getY(); Rectangle rect = boundingRect(x,y,oldX,oldY); // Draw new cursor box in each synchronized window. for(int n=0; n 0) vwins = new Vector(); // Add all windows in vector to synchronized window list. for(int n=0; n