// 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.2 2000/09/19 21:08:33 dougo Exp $ // Modified by : Kedar Patankar package edu.neu.ccs.demeter.tools.apstudio.graphedit; import java.awt.event.MouseEvent; import java.awt.Point; import java.awt.Rectangle; import java.awt.Cursor; import java.util.Vector; 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); } public void setCursorType() { parent.setCursor(new Cursor(Cursor.MOVE_CURSOR)); } public void setMessage(Editor ed){} /** 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 void mouseDown(MouseEvent e) { Selection sel = parent.selection(); if (sel.isEmpty()) { done(); } int x = e.getX(); int y = e.getY(); /* 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); // For attaching edge to other vertex if(currentHandle == -1) { if(sel.size()>1) parent.setMessage("Relocating the objects"); else { DiagramElement de = parent.selectionsingle(); if (de instanceof Perspective) parent.setMessage("Relocating the class"); else parent.setMessage("Stretching the edge"); } } else parent.setMessage("Moving the selected object"); lastX = x; lastY = y; } /** 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; } */ /** On mouse up the modification interaction is done. */ public void mouseUp(MouseEvent e) { int x = e.getX(); int y = e.getY(); int changeX = Math.abs(lastX - x); int changeY = Math.abs(lastY - y); if(changeX < 3 && changeY < 3) { done(); return; } Selection sel = parent.selection(); if(currentHandle!=-1) { x=(x<15 ?15:x); y=(y<15 ?15:y); sel.startTrans(); sel.dragHandle(x, y, anchor.x, anchor.y, currentHandle); } else { Rectangle rr=sel.getBoundingBox(); x = (rr.x-(lastX-x) < 15 ? 15 - rr.x + lastX: x); y = (rr.y-(lastY-y) < 15 ? 15 - rr.y + lastY: y); sel.startTrans(); sel.translate(x - lastX, y - lastY); } sel.endTrans(); parent.gcdNeedsSaving(true); done(); Rectangle r = new Rectangle( Math.min(x, lastX) - 1, Math.min(y, lastY) - 1, Math.max(x, lastX) - Math.min(x, lastX) + 2, Math.max(y, lastY) - Math.min(y, lastY) + 2); parent.damaged(r); switch(sel.size()) // newly added stuff for menu consistency { case 0 : parent.menuFornoSelection(); parent.showDefaultPropertySheet(); break; case 1 : parent.menuForsingleSelection(); Vector selected = parent.selectedDEs(); DiagramElement de = (DiagramElement) selected.firstElement(); if (de instanceof Perspective) parent.showVertexPropertySheet((Perspective)de); else parent.showEdgePropertySheet((ArcPerspective)de); break; default: parent.menuFormultipleSelection(); parent.showDefaultPropertySheet(); break; } } } /* end class ModeModify */