// 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: ModeCreate.java // Classes: ModeCreate // Original Author: Jason Robbins // $Id: ModeCreate.java,v 1.1.1.1 1997/02/27 20:52:42 chandra Exp $ package uci.graphedit; import java.awt.Graphics; import java.awt.Event; /** Abstract superclass for all Mode's that create new * DiagramElement's. This class factors our shared code that would * otherwise be duplicated in its subclasses. On a mouse down the new * item is created in memory. On mouse drag the new item is resized * via its createDrag() method. On mouse up the new item is officially added * to the document being edited in the parent Editor, the item is * selected, and the Editor is placed in the next Mode (usually * ModeSelect). Subclasses override various of these event handlers to * give specific behaviors, for example, ModeCreateArc handles * dragging differently.
* * Subclasses must implement a createNewItem() method.
* * Maybe I should make newItem a variable of the mode and move it out * of Editor... * * @see ModeCreateArc * @see ModeCreateFigRectangle */ public abstract class ModeCreate extends Mode { /** original mouse down event coordinates */ protected int anchorX, anchorY; /** This holds the DiagramElement to be added to the parent Editor. */ protected DiagramElement newItem; public ModeCreate(Document par) { super(par); } /** On mouse down, make a new DiagramElement in memory. */ public boolean mouseDown(Event e, int x, int y) { anchorX = x; anchorY = y; newItem = createNewItem(e); return true; } /** On mouse drag, resize the new item as the user moves the * mouse. Maybe the DiagramElement createDrag() method should be removed * and I should call dragHandle(). That would elimiate one method * from each oif several classes, but dragging during creation is * not really the same thing as dragging after creation... */ public boolean mouseDrag(Event e, int x, int y) { parent.damaged(newItem); creationDrag(x, y); parent.damaged(newItem); parent.repairDamage(); // should I do this? return true; } /** On mouse up, officially add the new item to the parent Editor * and select it. Then exit this mode. */ public boolean mouseUp(Event e, int x, int y) {return false; } /** Update the new item to reflect the new mouse position. By * default let the new item set its size, subclasses may override. * * @see ModeCreateFigLine#creationDrag */ protected void creationDrag(int x, int y) { ((Fig)newItem).createDrag(anchorX, anchorY, x, y); } /** Draw this mode by drawing the new item. This is the only * feedback that the user will get since the new item is not * officially added to the Editor's document yet. */ public void draw(Graphics g) { if (null != newItem) newItem.draw(g); } /** If the mouse moves without the button down do nothing. */ public boolean mouseMove(Event e, int x, int y) { return true; } /** Construct a new DiagramElement to be added to the * Editor. Typically, subclasses will make a new instance of some Fig * based on the given mouse down event and the state of the parent * Editor (specifically, its default graphical attributes). */ public abstract DiagramElement createNewItem(Event e); } /* end class ModeCreate */