package interactors; import java.util.Vector; import java.awt.Rectangle; import java.awt.event.*; class Interactor { public static final int START = 0; public static final int RUNNING = 1; public static final int STOP = 2; // the state the interactor is current in int currentState; // the start event for the interactor int startEvent; // the stop event for the interactor int stopEvent; // the set of objects on which this interactor operates Vector registeredObjs = new Vector(); // the object on which this interactor currently operates Rectangle selectedObj = null; // If the user does not provide a start event, then the user is // responsible for changing the current state to STOP when the // interactor should cease operating public Interactor(int start) { startEvent = start; stopEvent = -1; } public Interactor(int start, int stop) { startEvent = start; stopEvent = stop; } public int getStartEvent() { return startEvent; } public int getStopEvent() { return stopEvent; } public int getState() { return currentState; } public void setState(int newState) { currentState = newState; } // add an object to the list of objects on which the interactor operates public void add(Rectangle obj) { registeredObjs.add(obj); } // remove an object from the list of objects on which the interactor // operators public void remove(Rectangle obj) { registeredObjs.remove(obj); } // determines if the interactor operates on any object that contains // the location of this mouse event public Rectangle findObject(MouseEvent e) { for (Rectangle r : registeredObjs) { if (r.contains(e.getPoint())) { selectedObj = r; return r; } } return null; } // these methods should be overridden by subclassing interactors. // the subclassing interactors should use these methods to compute // the information required for the startAction, runningAction, and // stopAction methods public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} public void mouseClicked(MouseEvent e) {} public void mouseMoved(MouseEvent e) {} public void mouseDragged(MouseEvent e) {} }