// File: SelectionSingle.java // Classes: SelectionSingle // Original Author: Jason Robbins // $Id: SelectionSingle.java,v 1.1.1.1 1997/02/27 20:52:48 chandra Exp $ package uci.graphedit; import java.awt.Event; import java.awt.Graphics; import java.awt.Point; /** Shared implementations of methods for all kinds of Selections that * just select one thing. * This is an abstract class, subclasses define the look and behavior * of actual selections. * @see SelectionMultiple * @see SelectionHandle * @see SelectionBox */ public abstract class SelectionSingle extends Selection { /** _content refers to the DiagramElement that is selected */ protected DiagramElement _content; /** Construct a new selection object that refers to the given * DiagramElement */ public SelectionSingle(DiagramElement de) { if (null == de) throw new java.lang.NullPointerException(); _content = de; } /** Reply true iff this selection contains the given DiagramElement */ public boolean contains(DiagramElement de) { return de == _content; } /** Reply the DiagramElement that was selected */ public DiagramElement content() { return _content; } /** Tell the content to start a transaction that causes damage */ public void startTrans() { content().startTrans(); } /** Tell the content to end a transaction that causes damage */ public void endTrans() { content().endTrans(); } /** This type of selection always refers to 1 selected DiagramElement */ public int size() { return 1; } /** Draw the handles or selection box or whatever is appropriate */ public void draw(Graphics g) { // needs-more-work: should manage Handle objects here _content.drawSelected(g); } /** Reply one of the graphical attributes of the selected DiagramElement */ public Object getGraphicAttribute(String k) { return _content.getGraphicAttribute(k); } /** Set one of the graphical attributes of the selected DiagramElement */ public void setGraphicAttribute(String k, Object v) { _content.setGraphicAttribute(k, v); } /** reply the position of the selected DiagramElement */ public Point position() { return _content.position(); } /** This selection object needs to be redrawn, register its damaged * area within the given Editor */ public void damagedIn(Document ed) { _content.damagedIn(ed); } /** reply true if the given point is inside this selection */ boolean inside(int x, int y) { return _content.inside(x, y); } /** Tell the selected DiagramElement to move to front or back, etc. */ public void reorder(int function, Layer view) { view.reorder(_content, function); } /** Do nothing because alignment only makes sense for multiple * selections */ public void align(int direction) { /* do nothing */ } /** When the selection is told to move, move the selected * DiagramElement */ void translate(int dx,int dy) { _content.translate(dx, dy); } /** Reply an integer handle number for the handle under the given * mouse point. Normally called from ModeModify. * @see ModeModify * needs-more-work: should take on more of this responsibility */ public int pickHandle(int x, int y) { return _content.pickHandle(x, y); } /** Drag a handle on the selected object. Normally called from ModeModify. * @see ModeModify */ public void dragHandle(int mx, int my, int an_x,int an_y, int h) { _content.dragHandle(mx, my, an_x, an_y, h); } /** If the selection is being deleted, the selected object is * deleted also. This is different from just deselecting the * selected DiagramElement, to do that use one of the deselect * operations in Editor * @see Editor#deselectItem */ public void removeFrom(Document ed) { _content.removeFrom(ed); } /** If the selection is being disposed, the selected object is * disposed also. This is different from just deselecting the * selected DiagramElement, to do that use one of the deselect * operations in Editor * @see Editor#deselectItem */ public void dispose(Document ed) { _content.dispose(ed); } /** Pass any events along to the selected DiagramElement. * Subclasses of SelectionSingle may reimplement this to add * functionality. */ public boolean keyDown(Event e,int key) { return _content.keyDown(e, key); } public boolean mouseMove(Event e,int x,int y) { return _content.mouseMove(e, x, y); } public boolean mouseDrag(Event e,int x,int y) { return _content.mouseDrag(e, x, y); } public boolean mouseDown(Event e,int x,int y) { return _content.mouseDown(e, x, y); } public boolean mouseUp(Event e,int x,int y) { return _content.mouseUp(e, x, y); } } /* end class SelectionSingle */