// 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: SelectionSingle.java // Classes: SelectionSingle // Original Author: Jason Robbins // $Id: SelectionSingle.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.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); } /** 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); } /* public void dragHandle(int mx, int my, int h) { _content.dragHandle(mx, my, 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 */