// 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: ModeModify.java // Classes: ModeModify // Original Author: ics125b spring 1996 // $Id: ModeModify.java,v 1.1.1.1 1997/02/27 20:52:44 chandra Exp $ package uci.graphedit; import java.awt.Event; import java.awt.Point; import java.awt.Rectangle; /** A Mode to process events from the Editor when the user is * modifying a DiagramElement. Right now users can drag one or more * DiagramElement's around the drawing area, or they can move a handle * on a single DiagramElement. The DiagramElement is responsible for * reacting to the movement of a handle, but so far they all resize * themselves. In the future, some DiagramElement's may have handles * that set properties other than size (e.g., spline curvature). */ public class ModeModify extends Mode { /** The point relative to the original postition of the * DiagramElement where the dragging started. Keeping this point * allows the user to "grip" any part of the DiagramElement, rather * than just dragging its position (or "pin") around. */ Point anchor; /** the mouse location for the most recent drag event */ int lastX, lastY; /** the ID of the handle that the user is dragging */ int currentHandle = -1; /** Construct a new ModeModify with the given parent, and set the * Anchor point to a default location (the anchor's proper position * will be determioned on mouse down). */ ModeModify(Document par) { super(par); anchor = new Point(0,0); } /** When the user drags the mouse two things can happen: (1) if the * user is dragging the body of one or more DiagramElement's then * they are all moved around the drawing area, or (2) if the user * started dragging on a handle of one DiagramElement then the user * can drag the handle around the drawing area and the * DiagramElement reacts to that. */ public boolean mouseDrag(Event e, int x, int y) { /* Selection sel = parent.selection(); sel.startTrans(); // if (currentHandle == -1) sel.translate(x - lastX, y - lastY); // else sel.dragHandle(x, y, anchor.x, anchor.y, currentHandle); sel.translate(x - lastX, y - lastY); sel.endTrans(); lastX = x; lastY = y; parent.isSaved(false); */ return true; } /** When the user presses the mouse button on a DiagramElement, * this Mode starts preparing for future drag events by finding if * a handle was clicked on. This event is passed from ModeSelect. */ public boolean mouseDown(Event e, int x, int y) { Selection sel = parent.selection(); if (sel.isEmpty()) { done(); } /* needs-more-work: anchor point sign convention is backwards */ // anchor.x = sel.position().x - x; // anchor.y = sel.position().y - y; // currentHandle = sel.pickHandle(x, y); lastX = x; lastY = y; return true; } /** On mouse up the modification interaction is done. */ public boolean mouseUp(Event e, int x, int y) { Selection sel = parent.selection(); Rectangle rr=sel.getBoundingBox(); if((x