import java.awt.*; import java.util.*; // class MMover // a holder and maintainer of MMoveable objects // // Author: Alexander Bogomolny, CTK Software, Inc. // URL: http://www.cut-the-knot.com // Date: November 30, 2000 // Copyright: A. Bogomolny // Permission to use and modify the file is therefore granted // as long as this comment remains unchanged. Do this at your // own risk. // class MMover { Vector Moveables = new Vector(); public Vector GetMoveables() { return Moveables; } public void SetMoveables(Vector m) { Moveables = m; } int Selected = -1; public boolean IsSelected(int i) { return i == Selected; } // Draw selected last, // which will place it on top of everything else // boolean PromotedSelected = true; public void SetPromote(boolean set) { PromotedSelected = set; } public MMover() { } public void AddMoveable(MMoveable m) { Moveables.addElement(m); } public void UpdateLocation(int x, int y) { if (Selected == -1) return; MMoveable m = (MMoveable)Moveables.elementAt(Selected); m.UpdateLocation(x, y); } public boolean IsHit(int x, int y) { Selected = -1; int n = Moveables.size(); for (int i = n-1; i >= 0; i--) { MMoveable m = (MMoveable)Moveables.elementAt(i); if (m.Inside(x, y)) { if (PromotedSelected) { Moveables.removeElementAt(i); Moveables.addElement(m); Selected = n-1; } else Selected = i; return true; } } return false; } public boolean Dragging() { return Selected != -1; } public void StopDragging() { Selected = -1; } public void Clear() { Moveables.removeAllElements(); } public void Draw(Graphics g) { int n = Moveables.size(); for (int i = 0; i < n; i++) { MMoveable m = (MMoveable)Moveables.elementAt(i); m.Draw(g); } } public void DrawBackground(Graphics g) { int n = Moveables.size(); for (int i = 0; i < n; i++) ((MMoveable)Moveables.elementAt(i)).DrawBackground(g); } public void DrawFrame(Graphics g) { int n = Moveables.size(); for (int i = 0; i < n; i++) ((MMoveable)Moveables.elementAt(i)).DrawFrame(g); } }