// Copyright (c) 1995, 1996 Regents of the University of California. // All rights reserved. // // This software was developed by the Arcadia project // at the University of California, Irvine. // // Redistribution and use in source and binary forms are permitted // provided that the above copyright notice and this paragraph are // duplicated in all such forms and that any documentation, // advertising materials, and other materials related to such // distribution and use acknowledge that the software was developed // by the University of California, Irvine. The name of the // University may not be used to endorse or promote products derived // from this software without specific prior written permission. // THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR // IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED // WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. // File: Selection.java // Classes: Selection // Original Author: Jason Robbins // $Id: Selection.java,v 1.2 2000/09/19 21:08:34 dougo Exp $ // Modified by : Kedar Patankar package edu.neu.ccs.demeter.tools.apstudio.graphedit; import java.awt.Graphics; import java.awt.Point; import java.awt.Rectangle; import java.awt.Event; import java.util.Hashtable; import java.util.Enumeration; /** This class represents the "selection" object that is used when you * select one or more Figures in the drawing window. Selection's * (should) handle the display of handles or whatever graphics * indicate that something is selected, and they process events to * manipulate the selected DiagramElement. Needs-More-Work: in a * earlier version of this design DiagramElement's did all of that * work themselves which led to much code duplication. Unfortuanately * some of that code is still left over. Specificially, * DiagramElement's still have methods to draw their own handles. * * @see DiagramElement * @see DiagramElement#drawSelected */ public abstract class Selection { /** Construct a new selection. Empty, subclases can override */ public Selection() { } /** Reply true if this selection contains the given DiagramElement */ public abstract boolean contains(DiagramElement de); /** Return the DiagramElement that is contained. This probably * should not be implemented in this abstract class because some * Selection subclasses can select more than one DiagramElement. */ //public abstract DiagramElement content(); /** Reply true if nothing is selected. */ public boolean isEmpty() { return size() == 0; } /** Reply the number of DiagramElement's selected */ public abstract int size(); /** Draw something that indicates a selection to the user */ public abstract void draw(Graphics g); /** Some action is about to change the selected item, mark its * region as damaged .*/ public abstract void startTrans(); /** Some action has just changes the selected item, mark its region * as damaged .*/ public abstract void endTrans(); /** Get and set the graphical attributes of the selected * DiagramElement(s). * * @see DiagramElement#getGraphicAttribute * @see DiagramElement#setGraphicAttribute * @see DiagramElement#setGraphicAttributes */ public abstract Object getGraphicAttribute(String k); public abstract void setGraphicAttribute(String k, Object v); public void setGraphicAttributes(Hashtable newAttrs) { Enumeration cur = newAttrs.keys(); while (cur.hasMoreElements()) { String key = (String) cur.nextElement(); Object val = newAttrs.get(key); setGraphicAttribute(key, val); } } /** Reply the position of the Selection. That is defined to be the * upper left corner of my bounding box. */ public Point position() { Rectangle bbox = getBoundingBox(); return new Point(bbox.x, bbox.y); } /** This Selection needs to be redrawn. */ public void damagedIn(Document ed) { ed.damaged(this); } /** Reply true if the given mouse coordinates are inside or near * enough to this selection that we consider the user to have * clicked on it. */ abstract boolean inside(int x, int y); final boolean inside(Point pnt) { return inside(pnt.x, pnt.y); } /** Find which handle the user clicked on, or return -1 if none. */ public final int pickHandle(Point p) { return pickHandle(p.x, p.y); } public abstract int pickHandle(int x, int y); /** Reorder, align, or translate the selected DiagramElement(s). */ abstract void align(int direction); abstract void translate(int dx,int dy); /** Remove or dispose of the selected DiagramElement(s). */ public abstract void removeFrom(Document ed); public abstract void dispose(Document ed); /** Move one of the handles of a selected DiagramElement. */ public abstract void dragHandle(int mx, int my, int an_x,int an_y, int h); // public abstract void dragHandle(int mx, int my, int h); public abstract Rectangle getBoundingBox(); public boolean keyDown(Event e,int key) { return false; } public boolean mouseMove(Event e,int x,int y) { return false; } public boolean mouseDrag(Event e,int x,int y) { return false; } public boolean mouseDown(Event e,int x,int y) { return false; } public boolean mouseUp(Event e,int x,int y) { return false; } } /* end class Selection */