// File: ModeCreateArc.java // Classes: ModeCreateArc // Original Author: ics125b spring 1996 // $Id: ModeCreateConstEdge.java,v 1.1.1.1 1997/02/27 20:52:43 chandra Exp $ package uci.graphedit; import java.awt.Event; /** A Mode to interpret user input while creating an arc. Basically * mouse down starts creating an arc from a source NetPort, mouse * motion draws a rubberband line, mouse up finds the destination port * and finishes creating the arc and makes an ArcPerspective and sends * it to the back of the Layer. */ public class ModeCreateConstEdge extends ModeCreate { private NetNode sourceNode; private Editor _editor; /** Construct a new ModeCreateArc */ public ModeCreateConstEdge(Document par, Editor editor){super(par);_editor=editor;} public void setCursorType(Editor ed) { ed.setCursor(ed.CROSSHAIR_CURSOR); } /** Create the new item that will be drawn. In this case I would * rather create the ArcPerspective when I am done. Here I just * create a rubberband line to show during the interaction. */ public DiagramElement createNewItem(Event e) { return new FigLine(e.x, e.y, 0, 0, Globals.prefs().rubberbandAttrs()); } public boolean mouseDown(Event e,int x, int y) { DiagramElement underMouse = parent.pick(x,y); if (underMouse != null) { if(underMouse instanceof Perspective) { sourceNode=(NetNode)((Perspective)underMouse).owner(); return super.mouseDown(e, x, y); } } done(); return true; } /** On mouse up, find the destination port, ask the NetArc * (SampleArc) to connect the two ports. If that connection is * allowed, then construct a new ArcPerspective and add it to the * Layer and send it to the back. */ public boolean mouseUp(Event e, int x, int y) { newItem.damagedIn(parent); newItem = null; done(); DiagramElement de = parent.pick(x, y); if (de != null) { if (de instanceof Perspective) { NetNode destNode = (NetNode)((Perspective) de).owner(); if (sourceNode!= null && destNode != sourceNode) { if(!(sourceNode instanceof AltClass)) { Class arcClass; NetArc newArc; try { arcClass = Class.forName("uci.graphedit.NetArc"); } catch (java.lang.ClassNotFoundException ignore) { return false; } try { newArc = (NetArc)arcClass.newInstance(); } catch (java.lang.IllegalAccessException ignore) { return false; } catch (java.lang.InstantiationException ignore) { return false; } Action addConstructionEdge = new ActionCreateConstEdge (_editor,newArc,sourceNode,destNode); addConstructionEdge.doIt(); } } } } return true; } } /* end class ModeCreateArc */