123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544 |
- /**
- * Copyright (c) 2006-2015, JGraph Ltd
- * Copyright (c) 2006-2015, Gaudenz Alder
- */
- /**
- * Class: mxEdgeHandler
- *
- * Graph event handler that reconnects edges and modifies control points and
- * the edge label location. Uses <mxTerminalMarker> for finding and
- * highlighting new source and target vertices. This handler is automatically
- * created in <mxGraph.createHandler> for each selected edge.
- *
- * To enable adding/removing control points, the following code can be used:
- *
- * (code)
- * mxEdgeHandler.prototype.addEnabled = true;
- * mxEdgeHandler.prototype.removeEnabled = true;
- * (end)
- *
- * Note: This experimental feature is not recommended for production use.
- *
- * Constructor: mxEdgeHandler
- *
- * Constructs an edge handler for the specified <mxCellState>.
- *
- * Parameters:
- *
- * state - <mxCellState> of the cell to be handled.
- */
- function mxEdgeHandler(state)
- {
- if (state != null && state.shape != null)
- {
- this.state = state;
- this.init();
-
- // Handles escape keystrokes
- this.escapeHandler = mxUtils.bind(this, function(sender, evt)
- {
- var dirty = this.index != null;
- this.reset();
-
- if (dirty)
- {
- this.graph.cellRenderer.redraw(this.state, false, state.view.isRendering());
- }
- });
-
- this.state.view.graph.addListener(mxEvent.ESCAPE, this.escapeHandler);
- }
- };
- /**
- * Variable: graph
- *
- * Reference to the enclosing <mxGraph>.
- */
- mxEdgeHandler.prototype.graph = null;
- /**
- * Variable: state
- *
- * Reference to the <mxCellState> being modified.
- */
- mxEdgeHandler.prototype.state = null;
- /**
- * Variable: marker
- *
- * Holds the <mxTerminalMarker> which is used for highlighting terminals.
- */
- mxEdgeHandler.prototype.marker = null;
- /**
- * Variable: constraintHandler
- *
- * Holds the <mxConstraintHandler> used for drawing and highlighting
- * constraints.
- */
- mxEdgeHandler.prototype.constraintHandler = null;
- /**
- * Variable: error
- *
- * Holds the current validation error while a connection is being changed.
- */
- mxEdgeHandler.prototype.error = null;
- /**
- * Variable: shape
- *
- * Holds the <mxShape> that represents the preview edge.
- */
- mxEdgeHandler.prototype.shape = null;
- /**
- * Variable: bends
- *
- * Holds the <mxShapes> that represent the points.
- */
- mxEdgeHandler.prototype.bends = null;
- /**
- * Variable: labelShape
- *
- * Holds the <mxShape> that represents the label position.
- */
- mxEdgeHandler.prototype.labelShape = null;
- /**
- * Variable: cloneEnabled
- *
- * Specifies if cloning by control-drag is enabled. Default is true.
- */
- mxEdgeHandler.prototype.cloneEnabled = true;
- /**
- * Variable: addEnabled
- *
- * Specifies if adding bends by shift-click is enabled. Default is false.
- * Note: This experimental feature is not recommended for production use.
- */
- mxEdgeHandler.prototype.addEnabled = false;
- /**
- * Variable: removeEnabled
- *
- * Specifies if removing bends by shift-click is enabled. Default is false.
- * Note: This experimental feature is not recommended for production use.
- */
- mxEdgeHandler.prototype.removeEnabled = false;
- /**
- * Variable: dblClickRemoveEnabled
- *
- * Specifies if removing bends by double click is enabled. Default is false.
- */
- mxEdgeHandler.prototype.dblClickRemoveEnabled = false;
- /**
- * Variable: mergeRemoveEnabled
- *
- * Specifies if removing bends by dropping them on other bends is enabled.
- * Default is false.
- */
- mxEdgeHandler.prototype.mergeRemoveEnabled = false;
- /**
- * Variable: straightRemoveEnabled
- *
- * Specifies if removing bends by creating straight segments should be enabled.
- * If enabled, this can be overridden by holding down the alt key while moving.
- * Default is false.
- */
- mxEdgeHandler.prototype.straightRemoveEnabled = false;
- /**
- * Variable: virtualBendsEnabled
- *
- * Specifies if virtual bends should be added in the center of each
- * segments. These bends can then be used to add new waypoints.
- * Default is false.
- */
- mxEdgeHandler.prototype.virtualBendsEnabled = false;
- /**
- * Variable: virtualBendOpacity
- *
- * Opacity to be used for virtual bends (see <virtualBendsEnabled>).
- * Default is 20.
- */
- mxEdgeHandler.prototype.virtualBendOpacity = 20;
- /**
- * Variable: parentHighlightEnabled
- *
- * Specifies if the parent should be highlighted if a child cell is selected.
- * Default is false.
- */
- mxEdgeHandler.prototype.parentHighlightEnabled = false;
- /**
- * Variable: preferHtml
- *
- * Specifies if bends should be added to the graph container. This is updated
- * in <init> based on whether the edge or one of its terminals has an HTML
- * label in the container.
- */
- mxEdgeHandler.prototype.preferHtml = false;
- /**
- * Variable: allowHandleBoundsCheck
- *
- * Specifies if the bounds of handles should be used for hit-detection in IE
- * Default is true.
- */
- mxEdgeHandler.prototype.allowHandleBoundsCheck = true;
- /**
- * Variable: snapToTerminals
- *
- * Specifies if waypoints should snap to the routing centers of terminals.
- * Default is false.
- */
- mxEdgeHandler.prototype.snapToTerminals = false;
- /**
- * Variable: handleImage
- *
- * Optional <mxImage> to be used as handles. Default is null.
- */
- mxEdgeHandler.prototype.handleImage = null;
- /**
- * Variable: tolerance
- *
- * Optional tolerance for hit-detection in <getHandleForEvent>. Default is 0.
- */
- mxEdgeHandler.prototype.tolerance = 0;
- /**
- * Variable: outlineConnect
- *
- * Specifies if connections to the outline of a highlighted target should be
- * enabled. This will allow to place the connection point along the outline of
- * the highlighted target. Default is false.
- */
- mxEdgeHandler.prototype.outlineConnect = false;
- /**
- * Variable: manageLabelHandle
- *
- * Specifies if the label handle should be moved if it intersects with another
- * handle. Uses <checkLabelHandle> for checking and moving. Default is false.
- */
- mxEdgeHandler.prototype.manageLabelHandle = false;
- /**
- * Function: init
- *
- * Initializes the shapes required for this edge handler.
- */
- mxEdgeHandler.prototype.init = function()
- {
- this.graph = this.state.view.graph;
- this.marker = this.createMarker();
- this.constraintHandler = new mxConstraintHandler(this.graph);
-
- // Clones the original points from the cell
- // and makes sure at least one point exists
- this.points = [];
-
- // Uses the absolute points of the state
- // for the initial configuration and preview
- this.abspoints = this.getSelectionPoints(this.state);
- this.shape = this.createSelectionShape(this.abspoints);
- this.shape.dialect = (this.graph.dialect != mxConstants.DIALECT_SVG) ?
- mxConstants.DIALECT_MIXEDHTML : mxConstants.DIALECT_SVG;
- this.shape.init(this.graph.getView().getOverlayPane());
- this.shape.pointerEvents = false;
- this.shape.setCursor(mxConstants.CURSOR_MOVABLE_EDGE);
- mxEvent.redirectMouseEvents(this.shape.node, this.graph, this.state);
- // Updates preferHtml
- this.preferHtml = this.state.text != null &&
- this.state.text.node.parentNode == this.graph.container;
-
- if (!this.preferHtml)
- {
- // Checks source terminal
- var sourceState = this.state.getVisibleTerminalState(true);
-
- if (sourceState != null)
- {
- this.preferHtml = sourceState.text != null &&
- sourceState.text.node.parentNode == this.graph.container;
- }
-
- if (!this.preferHtml)
- {
- // Checks target terminal
- var targetState = this.state.getVisibleTerminalState(false);
-
- if (targetState != null)
- {
- this.preferHtml = targetState.text != null &&
- targetState.text.node.parentNode == this.graph.container;
- }
- }
- }
- // Creates bends for the non-routed absolute points
- // or bends that don't correspond to points
- if (this.graph.getSelectionCount() < mxGraphHandler.prototype.maxCells ||
- mxGraphHandler.prototype.maxCells <= 0)
- {
- this.bends = this.createBends();
- if (this.isVirtualBendsEnabled())
- {
- this.virtualBends = this.createVirtualBends();
- }
- }
- // Adds a rectangular handle for the label position
- this.label = new mxPoint(this.state.absoluteOffset.x, this.state.absoluteOffset.y);
- this.labelShape = this.createLabelHandleShape();
- this.initBend(this.labelShape);
- this.labelShape.setCursor(mxConstants.CURSOR_LABEL_HANDLE);
-
- this.customHandles = this.createCustomHandles();
-
- this.updateParentHighlight();
- this.redraw();
- };
- /**
- * Function: isParentHighlightVisible
- *
- * Returns true if the parent highlight should be visible. This implementation
- * always returns true.
- */
- mxEdgeHandler.prototype.isParentHighlightVisible = mxVertexHandler.prototype.isParentHighlightVisible;
- /**
- * Function: updateParentHighlight
- *
- * Updates the highlight of the parent if <parentHighlightEnabled> is true.
- */
- mxEdgeHandler.prototype.updateParentHighlight = mxVertexHandler.prototype.updateParentHighlight;
- /**
- * Function: createCustomHandles
- *
- * Returns an array of custom handles. This implementation returns null.
- */
- mxEdgeHandler.prototype.createCustomHandles = function()
- {
- return null;
- };
- /**
- * Function: isVirtualBendsEnabled
- *
- * Returns true if virtual bends should be added. This returns true if
- * <virtualBendsEnabled> is true and the current style allows and
- * renders custom waypoints.
- */
- mxEdgeHandler.prototype.isVirtualBendsEnabled = function(evt)
- {
- return this.virtualBendsEnabled && (this.state.style[mxConstants.STYLE_EDGE] == null ||
- this.state.style[mxConstants.STYLE_EDGE] == mxConstants.NONE ||
- this.state.style[mxConstants.STYLE_NOEDGESTYLE] == 1) &&
- mxUtils.getValue(this.state.style, mxConstants.STYLE_SHAPE, null) != 'arrow';
- };
- /**
- * Function: isCellEnabled
- *
- * Returns true if the given cell allows new connections to be created. This implementation
- * always returns true.
- */
- mxEdgeHandler.prototype.isCellEnabled = function(cell)
- {
- return true;
- };
- /**
- * Function: isAddPointEvent
- *
- * Returns true if the given event is a trigger to add a new point. This
- * implementation returns true if shift is pressed.
- */
- mxEdgeHandler.prototype.isAddPointEvent = function(evt)
- {
- return mxEvent.isShiftDown(evt);
- };
- /**
- * Function: isRemovePointEvent
- *
- * Returns true if the given event is a trigger to remove a point. This
- * implementation returns true if shift is pressed.
- */
- mxEdgeHandler.prototype.isRemovePointEvent = function(evt)
- {
- return mxEvent.isShiftDown(evt);
- };
- /**
- * Function: getSelectionPoints
- *
- * Returns the list of points that defines the selection stroke.
- */
- mxEdgeHandler.prototype.getSelectionPoints = function(state)
- {
- return state.absolutePoints;
- };
- /**
- * Function: createParentHighlightShape
- *
- * Creates the shape used to draw the selection border.
- */
- mxEdgeHandler.prototype.createParentHighlightShape = function(bounds)
- {
- var shape = new mxRectangleShape(mxRectangle.fromRectangle(bounds),
- null, this.getSelectionColor());
- shape.strokewidth = this.getSelectionStrokeWidth();
- shape.isDashed = this.isSelectionDashed();
-
- return shape;
- };
- /**
- * Function: createSelectionShape
- *
- * Creates the shape used to draw the selection border.
- */
- mxEdgeHandler.prototype.createSelectionShape = function(points)
- {
- var shape = new this.state.shape.constructor();
- shape.outline = true;
- shape.apply(this.state);
-
- shape.isDashed = this.isSelectionDashed();
- shape.stroke = this.getSelectionColor();
- shape.isShadow = false;
-
- return shape;
- };
- /**
- * Function: getSelectionColor
- *
- * Returns <mxConstants.EDGE_SELECTION_COLOR>.
- */
- mxEdgeHandler.prototype.getSelectionColor = function()
- {
- return mxConstants.EDGE_SELECTION_COLOR;
- };
- /**
- * Function: getSelectionStrokeWidth
- *
- * Returns <mxConstants.EDGE_SELECTION_STROKEWIDTH>.
- */
- mxEdgeHandler.prototype.getSelectionStrokeWidth = function()
- {
- return mxConstants.EDGE_SELECTION_STROKEWIDTH;
- };
- /**
- * Function: isSelectionDashed
- *
- * Returns <mxConstants.EDGE_SELECTION_DASHED>.
- */
- mxEdgeHandler.prototype.isSelectionDashed = function()
- {
- return mxConstants.EDGE_SELECTION_DASHED;
- };
- /**
- * Function: isConnectableCell
- *
- * Returns true if the given cell is connectable. This is a hook to
- * disable floating connections. This implementation returns true.
- */
- mxEdgeHandler.prototype.isConnectableCell = function(cell)
- {
- return true;
- };
- /**
- * Function: getCellAt
- *
- * Creates and returns the <mxCellMarker> used in <marker>.
- */
- mxEdgeHandler.prototype.getCellAt = function(x, y)
- {
- return (!this.outlineConnect) ? this.graph.getCellAt(x, y) : null;
- };
- /**
- * Function: createMarker
- *
- * Creates and returns the <mxCellMarker> used in <marker>.
- */
- mxEdgeHandler.prototype.createMarker = function()
- {
- var marker = new mxCellMarker(this.graph);
- var self = this; // closure
- // Only returns edges if they are connectable and never returns
- // the edge that is currently being modified
- marker.getCell = function(me)
- {
- var cell = mxCellMarker.prototype.getCell.apply(this, arguments);
- // Checks for cell at preview point (with grid)
- if ((cell == self.state.cell || cell == null) && self.currentPoint != null)
- {
- cell = self.graph.getCellAt(self.currentPoint.x, self.currentPoint.y);
- }
-
- // Uses connectable parent vertex if one exists
- if (cell != null && !this.graph.isCellConnectable(cell))
- {
- var parent = this.graph.getModel().getParent(cell);
-
- if (this.graph.getModel().isVertex(parent) && this.graph.isCellConnectable(parent))
- {
- cell = parent;
- }
- }
-
- var model = self.graph.getModel();
-
- if ((this.graph.isSwimlane(cell) && self.currentPoint != null &&
- this.graph.hitsSwimlaneContent(cell, self.currentPoint.x, self.currentPoint.y)) ||
- (!self.isConnectableCell(cell)) || (cell == self.state.cell ||
- (cell != null && !self.graph.connectableEdges && model.isEdge(cell))) ||
- model.isAncestor(self.state.cell, cell))
- {
- cell = null;
- }
-
- if (!this.graph.isCellConnectable(cell))
- {
- cell = null;
- }
-
- return cell;
- };
- // Sets the highlight color according to validateConnection
- marker.isValidState = function(state)
- {
- var model = self.graph.getModel();
- var other = self.graph.view.getTerminalPort(state,
- self.graph.view.getState(model.getTerminal(self.state.cell,
- !self.isSource)), !self.isSource);
- var otherCell = (other != null) ? other.cell : null;
- var source = (self.isSource) ? state.cell : otherCell;
- var target = (self.isSource) ? otherCell : state.cell;
-
- // Updates the error message of the handler
- self.error = self.validateConnection(source, target);
- return self.error == null;
- };
-
- return marker;
- };
- /**
- * Function: validateConnection
- *
- * Returns the error message or an empty string if the connection for the
- * given source, target pair is not valid. Otherwise it returns null. This
- * implementation uses <mxGraph.getEdgeValidationError>.
- *
- * Parameters:
- *
- * source - <mxCell> that represents the source terminal.
- * target - <mxCell> that represents the target terminal.
- */
- mxEdgeHandler.prototype.validateConnection = function(source, target)
- {
- return this.graph.getEdgeValidationError(this.state.cell, source, target);
- };
- /**
- * Function: createBends
- *
- * Creates and returns the bends used for modifying the edge. This is
- * typically an array of <mxRectangleShapes>.
- */
- mxEdgeHandler.prototype.createBends = function()
- {
- var cell = this.state.cell;
- var bends = [];
- for (var i = 0; i < this.abspoints.length; i++)
- {
- if (this.isHandleVisible(i))
- {
- var source = i == 0;
- var target = i == this.abspoints.length - 1;
- var terminal = source || target;
- if (terminal || this.graph.isCellBendable(cell))
- {
- (mxUtils.bind(this, function(index)
- {
- var bend = this.createHandleShape(index);
- this.initBend(bend, mxUtils.bind(this, mxUtils.bind(this, function()
- {
- if (this.dblClickRemoveEnabled)
- {
- this.removePoint(this.state, index);
- }
- })));
-
- if (this.isHandleEnabled(i))
- {
- bend.setCursor((terminal) ? mxConstants.CURSOR_TERMINAL_HANDLE : mxConstants.CURSOR_BEND_HANDLE);
- }
-
- bends.push(bend);
-
- if (!terminal)
- {
- this.points.push(new mxPoint(0,0));
- bend.node.style.visibility = 'hidden';
- }
- }))(i);
- }
- }
- }
- return bends;
- };
- /**
- * Function: createVirtualBends
- *
- * Creates and returns the bends used for modifying the edge. This is
- * typically an array of <mxRectangleShapes>.
- */
- mxEdgeHandler.prototype.createVirtualBends = function()
- {
- var cell = this.state.cell;
- var last = this.abspoints[0];
- var bends = [];
- if (this.graph.isCellBendable(cell))
- {
- for (var i = 1; i < this.abspoints.length; i++)
- {
- (mxUtils.bind(this, function(bend)
- {
- this.initBend(bend);
- bend.setCursor(mxConstants.CURSOR_VIRTUAL_BEND_HANDLE);
- bends.push(bend);
- }))(this.createHandleShape());
- }
- }
- return bends;
- };
- /**
- * Function: isHandleEnabled
- *
- * Creates the shape used to display the given bend.
- */
- mxEdgeHandler.prototype.isHandleEnabled = function(index)
- {
- return true;
- };
- /**
- * Function: isHandleVisible
- *
- * Returns true if the handle at the given index is visible.
- */
- mxEdgeHandler.prototype.isHandleVisible = function(index)
- {
- var source = this.state.getVisibleTerminalState(true);
- var target = this.state.getVisibleTerminalState(false);
- var geo = this.graph.getCellGeometry(this.state.cell);
- var edgeStyle = (geo != null) ? this.graph.view.getEdgeStyle(this.state, geo.points, source, target) : null;
- return edgeStyle != mxEdgeStyle.EntityRelation || index == 0 || index == this.abspoints.length - 1;
- };
- /**
- * Function: createHandleShape
- *
- * Creates the shape used to display the given bend. Note that the index may be
- * null for special cases, such as when called from
- * <mxElbowEdgeHandler.createVirtualBend>. Only images and rectangles should be
- * returned if support for HTML labels with not foreign objects is required.
- * Index if null for virtual handles.
- */
- mxEdgeHandler.prototype.createHandleShape = function(index)
- {
- if (this.handleImage != null)
- {
- var shape = new mxImageShape(new mxRectangle(0, 0, this.handleImage.width, this.handleImage.height), this.handleImage.src);
-
- // Allows HTML rendering of the images
- shape.preserveImageAspect = false;
- return shape;
- }
- else
- {
- var s = mxConstants.HANDLE_SIZE;
-
- if (this.preferHtml)
- {
- s -= 1;
- }
-
- return new mxRectangleShape(new mxRectangle(0, 0, s, s), mxConstants.HANDLE_FILLCOLOR, mxConstants.HANDLE_STROKECOLOR);
- }
- };
- /**
- * Function: createLabelHandleShape
- *
- * Creates the shape used to display the the label handle.
- */
- mxEdgeHandler.prototype.createLabelHandleShape = function()
- {
- if (this.labelHandleImage != null)
- {
- var shape = new mxImageShape(new mxRectangle(0, 0, this.labelHandleImage.width, this.labelHandleImage.height), this.labelHandleImage.src);
-
- // Allows HTML rendering of the images
- shape.preserveImageAspect = false;
- return shape;
- }
- else
- {
- var s = mxConstants.LABEL_HANDLE_SIZE;
- return new mxRectangleShape(new mxRectangle(0, 0, s, s), mxConstants.LABEL_HANDLE_FILLCOLOR, mxConstants.HANDLE_STROKECOLOR);
- }
- };
- /**
- * Function: initBend
- *
- * Helper method to initialize the given bend.
- *
- * Parameters:
- *
- * bend - <mxShape> that represents the bend to be initialized.
- */
- mxEdgeHandler.prototype.initBend = function(bend, dblClick)
- {
- if (this.preferHtml)
- {
- bend.dialect = mxConstants.DIALECT_STRICTHTML;
- bend.init(this.graph.container);
- }
- else
- {
- bend.dialect = (this.graph.dialect != mxConstants.DIALECT_SVG) ?
- mxConstants.DIALECT_MIXEDHTML : mxConstants.DIALECT_SVG;
- bend.init(this.graph.getView().getOverlayPane());
- }
- mxEvent.redirectMouseEvents(bend.node, this.graph, this.state,
- null, null, null, dblClick);
-
- // Fixes lost event tracking for images in quirks / IE8 standards
- if (mxClient.IS_QUIRKS || document.documentMode == 8)
- {
- mxEvent.addListener(bend.node, 'dragstart', function(evt)
- {
- mxEvent.consume(evt);
-
- return false;
- });
- }
-
- if (mxClient.IS_TOUCH)
- {
- bend.node.setAttribute('pointer-events', 'none');
- }
- };
- /**
- * Function: getHandleForEvent
- *
- * Returns the index of the handle for the given event.
- */
- mxEdgeHandler.prototype.getHandleForEvent = function(me)
- {
- var result = null;
-
- if (this.state != null)
- {
- // Connection highlight may consume events before they reach sizer handle
- var tol = (!mxEvent.isMouseEvent(me.getEvent())) ? this.tolerance : 1;
- var hit = (this.allowHandleBoundsCheck && (mxClient.IS_IE || tol > 0)) ?
- new mxRectangle(me.getGraphX() - tol, me.getGraphY() - tol, 2 * tol, 2 * tol) : null;
- var minDistSq = null;
-
- function checkShape(shape)
- {
- if (shape != null && shape.node != null && shape.node.style.display != 'none' &&
- shape.node.style.visibility != 'hidden' &&
- (me.isSource(shape) || (hit != null && mxUtils.intersects(shape.bounds, hit))))
- {
- var dx = me.getGraphX() - shape.bounds.getCenterX();
- var dy = me.getGraphY() - shape.bounds.getCenterY();
- var tmp = dx * dx + dy * dy;
-
- if (minDistSq == null || tmp <= minDistSq)
- {
- minDistSq = tmp;
-
- return true;
- }
- }
-
- return false;
- }
-
- if (this.customHandles != null && this.isCustomHandleEvent(me))
- {
- // Inverse loop order to match display order
- for (var i = this.customHandles.length - 1; i >= 0; i--)
- {
- if (checkShape(this.customHandles[i].shape))
- {
- // LATER: Return reference to active shape
- return mxEvent.CUSTOM_HANDLE - i;
- }
- }
- }
-
- if (me.isSource(this.state.text) || checkShape(this.labelShape))
- {
- result = mxEvent.LABEL_HANDLE;
- }
-
- if (this.bends != null)
- {
- for (var i = 0; i < this.bends.length; i++)
- {
- if (checkShape(this.bends[i]))
- {
- result = i;
- }
- }
- }
-
- if (this.virtualBends != null && this.isAddVirtualBendEvent(me))
- {
- for (var i = 0; i < this.virtualBends.length; i++)
- {
- if (checkShape(this.virtualBends[i]))
- {
- result = mxEvent.VIRTUAL_HANDLE - i;
- }
- }
- }
- }
- return result;
- };
- /**
- * Function: isAddVirtualBendEvent
- *
- * Returns true if the given event allows virtual bends to be added. This
- * implementation returns true.
- */
- mxEdgeHandler.prototype.isAddVirtualBendEvent = function(me)
- {
- return true;
- };
- /**
- * Function: isCustomHandleEvent
- *
- * Returns true if the given event allows custom handles to be changed. This
- * implementation returns true.
- */
- mxEdgeHandler.prototype.isCustomHandleEvent = function(me)
- {
- return true;
- };
- /**
- * Function: mouseDown
- *
- * Handles the event by checking if a special element of the handler
- * was clicked, in which case the index parameter is non-null. The
- * indices may be one of <LABEL_HANDLE> or the number of the respective
- * control point. The source and target points are used for reconnecting
- * the edge.
- */
- mxEdgeHandler.prototype.mouseDown = function(sender, me)
- {
- var handle = this.getHandleForEvent(me);
-
- if (this.bends != null && this.bends[handle] != null)
- {
- var b = this.bends[handle].bounds;
- this.snapPoint = new mxPoint(b.getCenterX(), b.getCenterY());
- }
-
- if (this.addEnabled && handle == null && this.isAddPointEvent(me.getEvent()))
- {
- this.addPoint(this.state, me.getEvent());
- me.consume();
- }
- else if (handle != null && !me.isConsumed() && this.graph.isEnabled())
- {
- if (this.removeEnabled && this.isRemovePointEvent(me.getEvent()))
- {
- this.removePoint(this.state, handle);
- }
- else if (handle != mxEvent.LABEL_HANDLE || this.graph.isLabelMovable(me.getCell()))
- {
- if (handle <= mxEvent.VIRTUAL_HANDLE)
- {
- mxUtils.setOpacity(this.virtualBends[mxEvent.VIRTUAL_HANDLE - handle].node, 100);
- }
-
- this.start(me.getX(), me.getY(), handle);
- }
-
- me.consume();
- }
- };
- /**
- * Function: start
- *
- * Starts the handling of the mouse gesture.
- */
- mxEdgeHandler.prototype.start = function(x, y, index)
- {
- this.startX = x;
- this.startY = y;
- this.isSource = (this.bends == null) ? false : index == 0;
- this.isTarget = (this.bends == null) ? false : index == this.bends.length - 1;
- this.isLabel = index == mxEvent.LABEL_HANDLE;
- if (this.isSource || this.isTarget)
- {
- var cell = this.state.cell;
- var terminal = this.graph.model.getTerminal(cell, this.isSource);
- if ((terminal == null && this.graph.isTerminalPointMovable(cell, this.isSource)) ||
- (terminal != null && this.graph.isCellDisconnectable(cell, terminal, this.isSource)))
- {
- this.index = index;
- }
- }
- else
- {
- this.index = index;
- }
-
- // Hides other custom handles
- if (this.index <= mxEvent.CUSTOM_HANDLE && this.index > mxEvent.VIRTUAL_HANDLE)
- {
- if (this.customHandles != null)
- {
- for (var i = 0; i < this.customHandles.length; i++)
- {
- if (i != mxEvent.CUSTOM_HANDLE - this.index)
- {
- this.customHandles[i].setVisible(false);
- }
- }
- }
- }
- };
- /**
- * Function: clonePreviewState
- *
- * Returns a clone of the current preview state for the given point and terminal.
- */
- mxEdgeHandler.prototype.clonePreviewState = function(point, terminal)
- {
- return this.state.clone();
- };
- /**
- * Function: getSnapToTerminalTolerance
- *
- * Returns the tolerance for the guides. Default value is
- * gridSize * scale / 2.
- */
- mxEdgeHandler.prototype.getSnapToTerminalTolerance = function()
- {
- return this.graph.gridSize * this.graph.view.scale / 2;
- };
- /**
- * Function: updateHint
- *
- * Hook for subclassers do show details while the handler is active.
- */
- mxEdgeHandler.prototype.updateHint = function(me, point) { };
- /**
- * Function: removeHint
- *
- * Hooks for subclassers to hide details when the handler gets inactive.
- */
- mxEdgeHandler.prototype.removeHint = function() { };
- /**
- * Function: roundLength
- *
- * Hook for rounding the unscaled width or height. This uses Math.round.
- */
- mxEdgeHandler.prototype.roundLength = function(length)
- {
- return Math.round(length);
- };
- /**
- * Function: isSnapToTerminalsEvent
- *
- * Returns true if <snapToTerminals> is true and if alt is not pressed.
- */
- mxEdgeHandler.prototype.isSnapToTerminalsEvent = function(me)
- {
- return this.snapToTerminals && !mxEvent.isAltDown(me.getEvent());
- };
- /**
- * Function: getPointForEvent
- *
- * Returns the point for the given event.
- */
- mxEdgeHandler.prototype.getPointForEvent = function(me)
- {
- var view = this.graph.getView();
- var scale = view.scale;
- var point = new mxPoint(this.roundLength(me.getGraphX() / scale) * scale,
- this.roundLength(me.getGraphY() / scale) * scale);
-
- var tt = this.getSnapToTerminalTolerance();
- var overrideX = false;
- var overrideY = false;
-
- if (tt > 0 && this.isSnapToTerminalsEvent(me))
- {
- function snapToPoint(pt)
- {
- if (pt != null)
- {
- var x = pt.x;
- if (Math.abs(point.x - x) < tt)
- {
- point.x = x;
- overrideX = true;
- }
-
- var y = pt.y;
- if (Math.abs(point.y - y) < tt)
- {
- point.y = y;
- overrideY = true;
- }
- }
- }
-
- // Temporary function
- function snapToTerminal(terminal)
- {
- if (terminal != null)
- {
- snapToPoint.call(this, new mxPoint(view.getRoutingCenterX(terminal),
- view.getRoutingCenterY(terminal)));
- }
- };
- snapToTerminal.call(this, this.state.getVisibleTerminalState(true));
- snapToTerminal.call(this, this.state.getVisibleTerminalState(false));
- if (this.state.absolutePoints != null)
- {
- for (var i = 0; i < this.state.absolutePoints.length; i++)
- {
- snapToPoint.call(this, this.state.absolutePoints[i]);
- }
- }
- }
- if (this.graph.isGridEnabledEvent(me.getEvent()))
- {
- var tr = view.translate;
-
- if (!overrideX)
- {
- point.x = (this.graph.snap(point.x / scale - tr.x) + tr.x) * scale;
- }
-
- if (!overrideY)
- {
- point.y = (this.graph.snap(point.y / scale - tr.y) + tr.y) * scale;
- }
- }
-
- return point;
- };
- /**
- * Function: getPreviewTerminalState
- *
- * Updates the given preview state taking into account the state of the constraint handler.
- */
- mxEdgeHandler.prototype.getPreviewTerminalState = function(me)
- {
- this.constraintHandler.update(me, this.isSource, true, me.isSource(this.marker.highlight.shape) ? null : this.currentPoint);
-
- if (this.constraintHandler.currentFocus != null && this.constraintHandler.currentConstraint != null)
- {
- // Handles special case where grid is large and connection point is at actual point in which
- // case the outline is not followed as long as we're < gridSize / 2 away from that point
- if (this.marker.highlight != null && this.marker.highlight.state != null &&
- this.marker.highlight.state.cell == this.constraintHandler.currentFocus.cell)
- {
- // Direct repaint needed if cell already highlighted
- if (this.marker.highlight.shape.stroke != 'transparent')
- {
- this.marker.highlight.shape.stroke = 'transparent';
- this.marker.highlight.repaint();
- }
- }
- else
- {
- this.marker.markCell(this.constraintHandler.currentFocus.cell, 'transparent');
- }
-
- var model = this.graph.getModel();
- var other = this.graph.view.getTerminalPort(this.state,
- this.graph.view.getState(model.getTerminal(this.state.cell,
- !this.isSource)), !this.isSource);
- var otherCell = (other != null) ? other.cell : null;
- var source = (this.isSource) ? this.constraintHandler.currentFocus.cell : otherCell;
- var target = (this.isSource) ? otherCell : this.constraintHandler.currentFocus.cell;
-
- // Updates the error message of the handler
- this.error = this.validateConnection(source, target);
- var result = null;
-
- if (this.error == null)
- {
- result = this.constraintHandler.currentFocus;
- }
-
- if (this.error != null || (result != null &&
- !this.isCellEnabled(result.cell)))
- {
- this.constraintHandler.reset();
- }
-
- return result;
- }
- else if (!this.graph.isIgnoreTerminalEvent(me.getEvent()))
- {
- this.marker.process(me);
- var state = this.marker.getValidState();
-
- if (state != null && !this.isCellEnabled(state.cell))
- {
- this.constraintHandler.reset();
- this.marker.reset();
- }
-
- return this.marker.getValidState();
- }
- else
- {
- this.marker.reset();
-
- return null;
- }
- };
- /**
- * Function: getPreviewPoints
- *
- * Updates the given preview state taking into account the state of the constraint handler.
- *
- * Parameters:
- *
- * pt - <mxPoint> that contains the current pointer position.
- * me - Optional <mxMouseEvent> that contains the current event.
- */
- mxEdgeHandler.prototype.getPreviewPoints = function(pt, me)
- {
- var geometry = this.graph.getCellGeometry(this.state.cell);
- var points = (geometry.points != null) ? geometry.points.slice() : null;
- var point = new mxPoint(pt.x, pt.y);
- var result = null;
-
- if (!this.isSource && !this.isTarget)
- {
- this.convertPoint(point, false);
-
- if (points == null)
- {
- points = [point];
- }
- else
- {
- // Adds point from virtual bend
- if (this.index <= mxEvent.VIRTUAL_HANDLE)
- {
- points.splice(mxEvent.VIRTUAL_HANDLE - this.index, 0, point);
- }
- // Removes point if dragged on terminal point
- if (!this.isSource && !this.isTarget)
- {
- for (var i = 0; i < this.bends.length; i++)
- {
- if (i != this.index)
- {
- var bend = this.bends[i];
-
- if (bend != null && mxUtils.contains(bend.bounds, pt.x, pt.y))
- {
- if (this.index <= mxEvent.VIRTUAL_HANDLE)
- {
- points.splice(mxEvent.VIRTUAL_HANDLE - this.index, 1);
- }
- else
- {
- points.splice(this.index - 1, 1);
- }
-
- result = points;
- }
- }
- }
-
- // Removes point if user tries to straighten a segment
- if (result == null && this.straightRemoveEnabled && (me == null || !mxEvent.isAltDown(me.getEvent())))
- {
- var tol = this.graph.tolerance * this.graph.tolerance;
- var abs = this.state.absolutePoints.slice();
- abs[this.index] = pt;
-
- // Handes special case where removing waypoint affects tolerance (flickering)
- var src = this.state.getVisibleTerminalState(true);
-
- if (src != null)
- {
- var c = this.graph.getConnectionConstraint(this.state, src, true);
-
- // Checks if point is not fixed
- if (c == null || this.graph.getConnectionPoint(src, c) == null)
- {
- abs[0] = new mxPoint(src.view.getRoutingCenterX(src), src.view.getRoutingCenterY(src));
- }
- }
-
- var trg = this.state.getVisibleTerminalState(false);
-
- if (trg != null)
- {
- var c = this.graph.getConnectionConstraint(this.state, trg, false);
-
- // Checks if point is not fixed
- if (c == null || this.graph.getConnectionPoint(trg, c) == null)
- {
- abs[abs.length - 1] = new mxPoint(trg.view.getRoutingCenterX(trg), trg.view.getRoutingCenterY(trg));
- }
- }
- function checkRemove(idx, tmp)
- {
- if (idx > 0 && idx < abs.length - 1 &&
- mxUtils.ptSegDistSq(abs[idx - 1].x, abs[idx - 1].y,
- abs[idx + 1].x, abs[idx + 1].y, tmp.x, tmp.y) < tol)
- {
- points.splice(idx - 1, 1);
- result = points;
- }
- };
-
- // LATER: Check if other points can be removed if a segment is made straight
- checkRemove(this.index, pt);
- }
- }
-
- // Updates existing point
- if (result == null && this.index > mxEvent.VIRTUAL_HANDLE)
- {
- points[this.index - 1] = point;
- }
- }
- }
- else if (this.graph.resetEdgesOnConnect)
- {
- points = null;
- }
-
- return (result != null) ? result : points;
- };
- /**
- * Function: isOutlineConnectEvent
- *
- * Returns true if <outlineConnect> is true and the source of the event is the outline shape
- * or shift is pressed.
- */
- mxEdgeHandler.prototype.isOutlineConnectEvent = function(me)
- {
- var offset = mxUtils.getOffset(this.graph.container);
- var evt = me.getEvent();
-
- var clientX = mxEvent.getClientX(evt);
- var clientY = mxEvent.getClientY(evt);
-
- var doc = document.documentElement;
- var left = (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0);
- var top = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
-
- var gridX = this.currentPoint.x - this.graph.container.scrollLeft + offset.x - left;
- var gridY = this.currentPoint.y - this.graph.container.scrollTop + offset.y - top;
- return this.outlineConnect && !mxEvent.isShiftDown(me.getEvent()) &&
- (me.isSource(this.marker.highlight.shape) ||
- (mxEvent.isAltDown(me.getEvent()) && me.getState() != null) ||
- this.marker.highlight.isHighlightAt(clientX, clientY) ||
- ((gridX != clientX || gridY != clientY) && me.getState() == null &&
- this.marker.highlight.isHighlightAt(gridX, gridY)));
- };
- /**
- * Function: updatePreviewState
- *
- * Updates the given preview state taking into account the state of the constraint handler.
- */
- mxEdgeHandler.prototype.updatePreviewState = function(edge, point, terminalState, me, outline)
- {
- // Computes the points for the edge style and terminals
- var sourceState = (this.isSource) ? terminalState : this.state.getVisibleTerminalState(true);
- var targetState = (this.isTarget) ? terminalState : this.state.getVisibleTerminalState(false);
-
- var sourceConstraint = this.graph.getConnectionConstraint(edge, sourceState, true);
- var targetConstraint = this.graph.getConnectionConstraint(edge, targetState, false);
- var constraint = this.constraintHandler.currentConstraint;
- if (constraint == null && outline)
- {
- if (terminalState != null)
- {
- // Handles special case where mouse is on outline away from actual end point
- // in which case the grid is ignored and mouse point is used instead
- if (me.isSource(this.marker.highlight.shape))
- {
- point = new mxPoint(me.getGraphX(), me.getGraphY());
- }
-
- constraint = this.graph.getOutlineConstraint(point, terminalState, me);
- this.constraintHandler.setFocus(me, terminalState, this.isSource);
- this.constraintHandler.currentConstraint = constraint;
- this.constraintHandler.currentPoint = point;
- }
- else
- {
- constraint = new mxConnectionConstraint();
- }
- }
-
- if (this.outlineConnect && this.marker.highlight != null && this.marker.highlight.shape != null)
- {
- var s = this.graph.view.scale;
-
- if (this.constraintHandler.currentConstraint != null &&
- this.constraintHandler.currentFocus != null)
- {
- this.marker.highlight.shape.stroke = (outline) ? mxConstants.OUTLINE_HIGHLIGHT_COLOR : 'transparent';
- this.marker.highlight.shape.strokewidth = mxConstants.OUTLINE_HIGHLIGHT_STROKEWIDTH / s / s;
- this.marker.highlight.repaint();
- }
- else if (this.marker.hasValidState())
- {
- this.marker.highlight.shape.stroke = (this.graph.isCellConnectable(me.getCell()) &&
- this.marker.getValidState() != me.getState()) ?
- 'transparent' : mxConstants.DEFAULT_VALID_COLOR;
- this.marker.highlight.shape.strokewidth = mxConstants.HIGHLIGHT_STROKEWIDTH / s / s;
- this.marker.highlight.repaint();
- }
- }
-
- if (this.isSource)
- {
- sourceConstraint = constraint;
- }
- else if (this.isTarget)
- {
- targetConstraint = constraint;
- }
-
- if (this.isSource || this.isTarget)
- {
- if (constraint != null && constraint.point != null)
- {
- edge.style[(this.isSource) ? mxConstants.STYLE_EXIT_X : mxConstants.STYLE_ENTRY_X] = constraint.point.x;
- edge.style[(this.isSource) ? mxConstants.STYLE_EXIT_Y : mxConstants.STYLE_ENTRY_Y] = constraint.point.y;
- }
- else
- {
- delete edge.style[(this.isSource) ? mxConstants.STYLE_EXIT_X : mxConstants.STYLE_ENTRY_X];
- delete edge.style[(this.isSource) ? mxConstants.STYLE_EXIT_Y : mxConstants.STYLE_ENTRY_Y];
- }
- }
-
- edge.setVisibleTerminalState(sourceState, true);
- edge.setVisibleTerminalState(targetState, false);
-
- if (!this.isSource || sourceState != null)
- {
- edge.view.updateFixedTerminalPoint(edge, sourceState, true, sourceConstraint);
- }
-
- if (!this.isTarget || targetState != null)
- {
- edge.view.updateFixedTerminalPoint(edge, targetState, false, targetConstraint);
- }
-
- if ((this.isSource || this.isTarget) && terminalState == null)
- {
- edge.setAbsoluteTerminalPoint(point, this.isSource);
- if (this.marker.getMarkedState() == null)
- {
- this.error = (this.graph.allowDanglingEdges) ? null : '';
- }
- }
-
- edge.view.updatePoints(edge, this.points, sourceState, targetState);
- edge.view.updateFloatingTerminalPoints(edge, sourceState, targetState);
- };
- /**
- * Function: mouseMove
- *
- * Handles the event by updating the preview.
- */
- mxEdgeHandler.prototype.mouseMove = function(sender, me)
- {
- if (this.index != null && this.marker != null)
- {
- this.currentPoint = this.getPointForEvent(me);
- this.error = null;
-
- // Uses the current point from the constraint handler if available
- if (!this.graph.isIgnoreTerminalEvent(me.getEvent()) && mxEvent.isShiftDown(me.getEvent()) && this.snapPoint != null)
- {
- if (Math.abs(this.snapPoint.x - this.currentPoint.x) < Math.abs(this.snapPoint.y - this.currentPoint.y))
- {
- this.currentPoint.x = this.snapPoint.x;
- }
- else
- {
- this.currentPoint.y = this.snapPoint.y;
- }
- }
-
- if (this.index <= mxEvent.CUSTOM_HANDLE && this.index > mxEvent.VIRTUAL_HANDLE)
- {
- if (this.customHandles != null)
- {
- this.customHandles[mxEvent.CUSTOM_HANDLE - this.index].processEvent(me);
- this.customHandles[mxEvent.CUSTOM_HANDLE - this.index].positionChanged();
-
- if (this.shape != null && this.shape.node != null)
- {
- this.shape.node.style.display = 'none';
- }
- }
- }
- else if (this.isLabel)
- {
- this.label.x = this.currentPoint.x;
- this.label.y = this.currentPoint.y;
- }
- else
- {
- this.points = this.getPreviewPoints(this.currentPoint, me);
- var terminalState = (this.isSource || this.isTarget) ? this.getPreviewTerminalState(me) : null;
-
- if (this.constraintHandler.currentConstraint != null &&
- this.constraintHandler.currentFocus != null &&
- this.constraintHandler.currentPoint != null)
- {
- this.currentPoint = this.constraintHandler.currentPoint.clone();
- }
- else if (this.outlineConnect)
- {
- // Need to check outline before cloning terminal state
- var outline = (this.isSource || this.isTarget) ? this.isOutlineConnectEvent(me) : false
-
- if (outline)
- {
- terminalState = this.marker.highlight.state;
- }
- else if (terminalState != null && terminalState != me.getState() &&
- this.graph.isCellConnectable(me.getCell()) &&
- this.marker.highlight.shape != null)
- {
- this.marker.highlight.shape.stroke = 'transparent';
- this.marker.highlight.repaint();
- terminalState = null;
- }
- }
-
- if (terminalState != null && !this.isCellEnabled(terminalState.cell))
- {
- terminalState = null;
- this.marker.reset();
- }
-
- var clone = this.clonePreviewState(this.currentPoint, (terminalState != null) ? terminalState.cell : null);
- this.updatePreviewState(clone, this.currentPoint, terminalState, me, outline);
- // Sets the color of the preview to valid or invalid, updates the
- // points of the preview and redraws
- var color = (this.error == null) ? this.marker.validColor : this.marker.invalidColor;
- this.setPreviewColor(color);
- this.abspoints = clone.absolutePoints;
- this.active = true;
- this.updateHint(me, this.currentPoint);
- }
- // This should go before calling isOutlineConnectEvent above. As a workaround
- // we add an offset of gridSize to the hint to avoid problem with hit detection
- // in highlight.isHighlightAt (which uses comonentFromPoint)
- this.drawPreview();
- mxEvent.consume(me.getEvent());
- me.consume();
- }
- // Workaround for disabling the connect highlight when over handle
- else if (mxClient.IS_IE && this.getHandleForEvent(me) != null)
- {
- me.consume(false);
- }
- };
- /**
- * Function: mouseUp
- *
- * Handles the event to applying the previewed changes on the edge by
- * using <moveLabel>, <connect> or <changePoints>.
- */
- mxEdgeHandler.prototype.mouseUp = function(sender, me)
- {
- // Workaround for wrong event source in Webkit
- if (this.index != null && this.marker != null)
- {
- if (this.shape != null && this.shape.node != null)
- {
- this.shape.node.style.display = '';
- }
-
- var edge = this.state.cell;
- var index = this.index;
- this.index = null;
- // Ignores event if mouse has not been moved
- if (me.getX() != this.startX || me.getY() != this.startY)
- {
- var clone = !this.graph.isIgnoreTerminalEvent(me.getEvent()) && this.graph.isCloneEvent(me.getEvent()) &&
- this.cloneEnabled && this.graph.isCellsCloneable();
-
- // Displays the reason for not carriying out the change
- // if there is an error message with non-zero length
- if (this.error != null)
- {
- if (this.error.length > 0)
- {
- this.graph.validationAlert(this.error);
- }
- }
- else if (index <= mxEvent.CUSTOM_HANDLE && index > mxEvent.VIRTUAL_HANDLE)
- {
- if (this.customHandles != null)
- {
- var model = this.graph.getModel();
-
- model.beginUpdate();
- try
- {
- this.customHandles[mxEvent.CUSTOM_HANDLE - index].execute(me);
-
- if (this.shape != null && this.shape.node != null)
- {
- this.shape.apply(this.state);
- this.shape.redraw();
- }
- }
- finally
- {
- model.endUpdate();
- }
- }
- }
- else if (this.isLabel)
- {
- this.moveLabel(this.state, this.label.x, this.label.y);
- }
- else if (this.isSource || this.isTarget)
- {
- var terminal = null;
-
- if (this.constraintHandler.currentConstraint != null &&
- this.constraintHandler.currentFocus != null)
- {
- terminal = this.constraintHandler.currentFocus.cell;
- }
-
- if (terminal == null && this.marker.hasValidState() && this.marker.highlight != null &&
- this.marker.highlight.shape != null &&
- this.marker.highlight.shape.stroke != 'transparent' &&
- this.marker.highlight.shape.stroke != 'white')
- {
- terminal = this.marker.validState.cell;
- }
-
- if (terminal != null)
- {
- var model = this.graph.getModel();
- var parent = model.getParent(edge);
-
- model.beginUpdate();
- try
- {
- // Clones and adds the cell
- if (clone)
- {
- var geo = model.getGeometry(edge);
- var clone = this.graph.cloneCell(edge);
- model.add(parent, clone, model.getChildCount(parent));
-
- if (geo != null)
- {
- geo = geo.clone();
- model.setGeometry(clone, geo);
- }
-
- var other = model.getTerminal(edge, !this.isSource);
- this.graph.connectCell(clone, other, !this.isSource);
-
- edge = clone;
- }
-
- edge = this.connect(edge, terminal, this.isSource, clone, me);
- }
- finally
- {
- model.endUpdate();
- }
- }
- else if (this.graph.isAllowDanglingEdges())
- {
- var pt = this.abspoints[(this.isSource) ? 0 : this.abspoints.length - 1];
- pt.x = this.roundLength(pt.x / this.graph.view.scale - this.graph.view.translate.x);
- pt.y = this.roundLength(pt.y / this.graph.view.scale - this.graph.view.translate.y);
- var pstate = this.graph.getView().getState(
- this.graph.getModel().getParent(edge));
-
- if (pstate != null)
- {
- pt.x -= pstate.origin.x;
- pt.y -= pstate.origin.y;
- }
-
- pt.x -= this.graph.panDx / this.graph.view.scale;
- pt.y -= this.graph.panDy / this.graph.view.scale;
-
- // Destroys and recreates this handler
- edge = this.changeTerminalPoint(edge, pt, this.isSource, clone);
- }
- }
- else if (this.active)
- {
- edge = this.changePoints(edge, this.points, clone);
- }
- else
- {
- this.graph.getView().invalidate(this.state.cell);
- this.graph.getView().validate(this.state.cell);
- }
- }
- else if (this.graph.isToggleEvent(me.getEvent()))
- {
- this.graph.selectCellForEvent(this.state.cell, me.getEvent());
- }
- // Resets the preview color the state of the handler if this
- // handler has not been recreated
- if (this.marker != null)
- {
- this.reset();
- // Updates the selection if the edge has been cloned
- if (edge != this.state.cell)
- {
- this.graph.setSelectionCell(edge);
- }
- }
- me.consume();
- }
- };
- /**
- * Function: reset
- *
- * Resets the state of this handler.
- */
- mxEdgeHandler.prototype.reset = function()
- {
- if (this.active)
- {
- this.refresh();
- }
-
- this.error = null;
- this.index = null;
- this.label = null;
- this.points = null;
- this.snapPoint = null;
- this.isLabel = false;
- this.isSource = false;
- this.isTarget = false;
- this.active = false;
-
- if (this.livePreview && this.sizers != null)
- {
- for (var i = 0; i < this.sizers.length; i++)
- {
- if (this.sizers[i] != null)
- {
- this.sizers[i].node.style.display = '';
- }
- }
- }
- if (this.marker != null)
- {
- this.marker.reset();
- }
-
- if (this.constraintHandler != null)
- {
- this.constraintHandler.reset();
- }
-
- if (this.customHandles != null)
- {
- for (var i = 0; i < this.customHandles.length; i++)
- {
- this.customHandles[i].reset();
- }
- }
- this.setPreviewColor(mxConstants.EDGE_SELECTION_COLOR);
- this.removeHint();
- this.redraw();
- };
- /**
- * Function: setPreviewColor
- *
- * Sets the color of the preview to the given value.
- */
- mxEdgeHandler.prototype.setPreviewColor = function(color)
- {
- if (this.shape != null)
- {
- this.shape.stroke = color;
- }
- };
- /**
- * Function: convertPoint
- *
- * Converts the given point in-place from screen to unscaled, untranslated
- * graph coordinates and applies the grid. Returns the given, modified
- * point instance.
- *
- * Parameters:
- *
- * point - <mxPoint> to be converted.
- * gridEnabled - Boolean that specifies if the grid should be applied.
- */
- mxEdgeHandler.prototype.convertPoint = function(point, gridEnabled)
- {
- var scale = this.graph.getView().getScale();
- var tr = this.graph.getView().getTranslate();
-
- if (gridEnabled)
- {
- point.x = this.graph.snap(point.x);
- point.y = this.graph.snap(point.y);
- }
-
- point.x = Math.round(point.x / scale - tr.x);
- point.y = Math.round(point.y / scale - tr.y);
- var pstate = this.graph.getView().getState(
- this.graph.getModel().getParent(this.state.cell));
- if (pstate != null)
- {
- point.x -= pstate.origin.x;
- point.y -= pstate.origin.y;
- }
- return point;
- };
- /**
- * Function: moveLabel
- *
- * Changes the coordinates for the label of the given edge.
- *
- * Parameters:
- *
- * edge - <mxCell> that represents the edge.
- * x - Integer that specifies the x-coordinate of the new location.
- * y - Integer that specifies the y-coordinate of the new location.
- */
- mxEdgeHandler.prototype.moveLabel = function(edgeState, x, y)
- {
- var model = this.graph.getModel();
- var geometry = model.getGeometry(edgeState.cell);
-
- if (geometry != null)
- {
- var scale = this.graph.getView().scale;
- geometry = geometry.clone();
-
- if (geometry.relative)
- {
- // Resets the relative location stored inside the geometry
- var pt = this.graph.getView().getRelativePoint(edgeState, x, y);
- geometry.x = Math.round(pt.x * 10000) / 10000;
- geometry.y = Math.round(pt.y);
-
- // Resets the offset inside the geometry to find the offset
- // from the resulting point
- geometry.offset = new mxPoint(0, 0);
- var pt = this.graph.view.getPoint(edgeState, geometry);
- geometry.offset = new mxPoint(Math.round((x - pt.x) / scale), Math.round((y - pt.y) / scale));
- }
- else
- {
- var points = edgeState.absolutePoints;
- var p0 = points[0];
- var pe = points[points.length - 1];
-
- if (p0 != null && pe != null)
- {
- var cx = p0.x + (pe.x - p0.x) / 2;
- var cy = p0.y + (pe.y - p0.y) / 2;
-
- geometry.offset = new mxPoint(Math.round((x - cx) / scale), Math.round((y - cy) / scale));
- geometry.x = 0;
- geometry.y = 0;
- }
- }
- model.setGeometry(edgeState.cell, geometry);
- }
- };
- /**
- * Function: connect
- *
- * Changes the terminal or terminal point of the given edge in the graph
- * model.
- *
- * Parameters:
- *
- * edge - <mxCell> that represents the edge to be reconnected.
- * terminal - <mxCell> that represents the new terminal.
- * isSource - Boolean indicating if the new terminal is the source or
- * target terminal.
- * isClone - Boolean indicating if the new connection should be a clone of
- * the old edge.
- * me - <mxMouseEvent> that contains the mouse up event.
- */
- mxEdgeHandler.prototype.connect = function(edge, terminal, isSource, isClone, me)
- {
- var model = this.graph.getModel();
- var parent = model.getParent(edge);
-
- model.beginUpdate();
- try
- {
- var constraint = this.constraintHandler.currentConstraint;
-
- if (constraint == null)
- {
- constraint = new mxConnectionConstraint();
- }
- this.graph.connectCell(edge, terminal, isSource, constraint);
- }
- finally
- {
- model.endUpdate();
- }
-
- return edge;
- };
- /**
- * Function: changeTerminalPoint
- *
- * Changes the terminal point of the given edge.
- */
- mxEdgeHandler.prototype.changeTerminalPoint = function(edge, point, isSource, clone)
- {
- var model = this.graph.getModel();
- model.beginUpdate();
- try
- {
- if (clone)
- {
- var parent = model.getParent(edge);
- var terminal = model.getTerminal(edge, !isSource);
- edge = this.graph.cloneCell(edge);
- model.add(parent, edge, model.getChildCount(parent));
- model.setTerminal(edge, terminal, !isSource);
- }
- var geo = model.getGeometry(edge);
-
- if (geo != null)
- {
- geo = geo.clone();
- geo.setTerminalPoint(point, isSource);
- model.setGeometry(edge, geo);
- this.graph.connectCell(edge, null, isSource, new mxConnectionConstraint());
- }
- }
- finally
- {
- model.endUpdate();
- }
-
- return edge;
- };
- /**
- * Function: changePoints
- *
- * Changes the control points of the given edge in the graph model.
- */
- mxEdgeHandler.prototype.changePoints = function(edge, points, clone)
- {
- var model = this.graph.getModel();
- model.beginUpdate();
- try
- {
- if (clone)
- {
- var parent = model.getParent(edge);
- var source = model.getTerminal(edge, true);
- var target = model.getTerminal(edge, false);
- edge = this.graph.cloneCell(edge);
- model.add(parent, edge, model.getChildCount(parent));
- model.setTerminal(edge, source, true);
- model.setTerminal(edge, target, false);
- }
-
- var geo = model.getGeometry(edge);
-
- if (geo != null)
- {
- geo = geo.clone();
- geo.points = points;
-
- model.setGeometry(edge, geo);
- }
- }
- finally
- {
- model.endUpdate();
- }
-
- return edge;
- };
- /**
- * Function: addPoint
- *
- * Adds a control point for the given state and event.
- */
- mxEdgeHandler.prototype.addPoint = function(state, evt)
- {
- var pt = mxUtils.convertPoint(this.graph.container, mxEvent.getClientX(evt),
- mxEvent.getClientY(evt));
- var gridEnabled = this.graph.isGridEnabledEvent(evt);
- this.convertPoint(pt, gridEnabled);
- this.addPointAt(state, pt.x, pt.y);
- mxEvent.consume(evt);
- };
- /**
- * Function: addPointAt
- *
- * Adds a control point at the given point.
- */
- mxEdgeHandler.prototype.addPointAt = function(state, x, y)
- {
- var geo = this.graph.getCellGeometry(state.cell);
- var pt = new mxPoint(x, y);
-
- if (geo != null)
- {
- geo = geo.clone();
- var t = this.graph.view.translate;
- var s = this.graph.view.scale;
- var offset = new mxPoint(t.x * s, t.y * s);
-
- var parent = this.graph.model.getParent(this.state.cell);
-
- if (this.graph.model.isVertex(parent))
- {
- var pState = this.graph.view.getState(parent);
- offset = new mxPoint(pState.x, pState.y);
- }
-
- var index = mxUtils.findNearestSegment(state, pt.x * s + offset.x, pt.y * s + offset.y);
- if (geo.points == null)
- {
- geo.points = [pt];
- }
- else
- {
- geo.points.splice(index, 0, pt);
- }
-
- this.graph.getModel().setGeometry(state.cell, geo);
- this.refresh();
- this.redraw();
- }
- };
- /**
- * Function: removePoint
- *
- * Removes the control point at the given index from the given state.
- */
- mxEdgeHandler.prototype.removePoint = function(state, index)
- {
- if (index > 0 && index < this.abspoints.length - 1)
- {
- var geo = this.graph.getCellGeometry(this.state.cell);
-
- if (geo != null && geo.points != null)
- {
- geo = geo.clone();
- geo.points.splice(index - 1, 1);
- this.graph.getModel().setGeometry(state.cell, geo);
- this.refresh();
- this.redraw();
- }
- }
- };
- /**
- * Function: getHandleFillColor
- *
- * Returns the fillcolor for the handle at the given index.
- */
- mxEdgeHandler.prototype.getHandleFillColor = function(index)
- {
- var isSource = index == 0;
- var cell = this.state.cell;
- var terminal = this.graph.getModel().getTerminal(cell, isSource);
- var color = mxConstants.HANDLE_FILLCOLOR;
-
- if ((terminal != null && !this.graph.isCellDisconnectable(cell, terminal, isSource)) ||
- (terminal == null && !this.graph.isTerminalPointMovable(cell, isSource)))
- {
- color = mxConstants.LOCKED_HANDLE_FILLCOLOR;
- }
- else if (terminal != null && this.graph.isCellDisconnectable(cell, terminal, isSource))
- {
- color = mxConstants.CONNECT_HANDLE_FILLCOLOR;
- }
-
- return color;
- };
- /**
- * Function: redraw
- *
- * Redraws the preview, and the bends- and label control points.
- */
- mxEdgeHandler.prototype.redraw = function(ignoreHandles)
- {
- if (this.state != null)
- {
- this.abspoints = this.state.absolutePoints.slice();
- var g = this.graph.getModel().getGeometry(this.state.cell);
-
- if (g != null)
- {
- var pts = g.points;
-
- if (this.bends != null && this.bends.length > 0)
- {
- if (pts != null)
- {
- if (this.points == null)
- {
- this.points = [];
- }
-
- for (var i = 1; i < this.bends.length - 1; i++)
- {
- if (this.bends[i] != null && this.abspoints[i] != null)
- {
- this.points[i - 1] = pts[i - 1];
- }
- }
- }
- }
- }
-
- this.drawPreview();
-
- if (!ignoreHandles)
- {
- this.redrawHandles();
- }
- }
- };
- /**
- * Function: redrawHandles
- *
- * Redraws the handles.
- */
- mxEdgeHandler.prototype.redrawHandles = function()
- {
- var cell = this.state.cell;
- // Updates the handle for the label position
- var b = this.labelShape.bounds;
- this.label = new mxPoint(this.state.absoluteOffset.x, this.state.absoluteOffset.y);
- this.labelShape.bounds = new mxRectangle(Math.round(this.label.x - b.width / 2),
- Math.round(this.label.y - b.height / 2), b.width, b.height);
- // Shows or hides the label handle depending on the label
- var lab = this.graph.getLabel(cell);
- this.labelShape.visible = (lab != null && lab.length > 0 && this.graph.isLabelMovable(cell));
-
- if (this.bends != null && this.bends.length > 0)
- {
- var n = this.abspoints.length - 1;
-
- var p0 = this.abspoints[0];
- var x0 = p0.x;
- var y0 = p0.y;
-
- b = this.bends[0].bounds;
- this.bends[0].bounds = new mxRectangle(Math.floor(x0 - b.width / 2),
- Math.floor(y0 - b.height / 2), b.width, b.height);
- this.bends[0].fill = this.getHandleFillColor(0);
- this.bends[0].redraw();
-
- if (this.manageLabelHandle)
- {
- this.checkLabelHandle(this.bends[0].bounds);
- }
-
- var pe = this.abspoints[n];
- var xn = pe.x;
- var yn = pe.y;
-
- var bn = this.bends.length - 1;
- b = this.bends[bn].bounds;
- this.bends[bn].bounds = new mxRectangle(Math.floor(xn - b.width / 2),
- Math.floor(yn - b.height / 2), b.width, b.height);
- this.bends[bn].fill = this.getHandleFillColor(bn);
- this.bends[bn].redraw();
-
- if (this.manageLabelHandle)
- {
- this.checkLabelHandle(this.bends[bn].bounds);
- }
-
- this.redrawInnerBends(p0, pe);
- }
- if (this.abspoints != null && this.virtualBends != null && this.virtualBends.length > 0)
- {
- var last = this.abspoints[0];
-
- for (var i = 0; i < this.virtualBends.length; i++)
- {
- if (this.virtualBends[i] != null && this.abspoints[i + 1] != null)
- {
- var pt = this.abspoints[i + 1];
- var b = this.virtualBends[i];
- var x = last.x + (pt.x - last.x) / 2;
- var y = last.y + (pt.y - last.y) / 2;
- b.bounds = new mxRectangle(Math.floor(x - b.bounds.width / 2),
- Math.floor(y - b.bounds.height / 2), b.bounds.width, b.bounds.height);
- b.redraw();
- mxUtils.setOpacity(b.node, this.virtualBendOpacity);
- last = pt;
-
- if (this.manageLabelHandle)
- {
- this.checkLabelHandle(b.bounds);
- }
- }
- }
- }
-
- if (this.labelShape != null)
- {
- this.labelShape.redraw();
- }
-
- if (this.customHandles != null)
- {
- for (var i = 0; i < this.customHandles.length; i++)
- {
- var temp = this.customHandles[i].shape.node.style.display;
- this.customHandles[i].redraw();
- this.customHandles[i].shape.node.style.display = temp;
- // Hides custom handles during text editing
- this.customHandles[i].shape.node.style.visibility =
- (this.isCustomHandleVisible(this.customHandles[i])) ?
- '' : 'hidden';
- }
- }
- };
- /**
- * Function: isCustomHandleVisible
- *
- * Returns true if the given custom handle is visible.
- */
- mxEdgeHandler.prototype.isCustomHandleVisible = function(handle)
- {
- return !this.graph.isEditing() && this.state.view.graph.getSelectionCount() == 1;
- };
- /**
- * Function: hideHandles
- *
- * Shortcut to <hideSizers>.
- */
- mxEdgeHandler.prototype.setHandlesVisible = function(visible)
- {
- if (this.bends != null)
- {
- for (var i = 0; i < this.bends.length; i++)
- {
- this.bends[i].node.style.display = (visible) ? '' : 'none';
- }
- }
-
- if (this.virtualBends != null)
- {
- for (var i = 0; i < this.virtualBends.length; i++)
- {
- this.virtualBends[i].node.style.display = (visible) ? '' : 'none';
- }
- }
- if (this.labelShape != null)
- {
- this.labelShape.node.style.display = (visible) ? '' : 'none';
- }
-
- if (this.customHandles != null)
- {
- for (var i = 0; i < this.customHandles.length; i++)
- {
- this.customHandles[i].setVisible(visible);
- }
- }
- };
- /**
- * Function: redrawInnerBends
- *
- * Updates and redraws the inner bends.
- *
- * Parameters:
- *
- * p0 - <mxPoint> that represents the location of the first point.
- * pe - <mxPoint> that represents the location of the last point.
- */
- mxEdgeHandler.prototype.redrawInnerBends = function(p0, pe)
- {
- for (var i = 1; i < this.bends.length - 1; i++)
- {
- if (this.bends[i] != null)
- {
- if (this.abspoints[i] != null)
- {
- var x = this.abspoints[i].x;
- var y = this.abspoints[i].y;
-
- var b = this.bends[i].bounds;
- this.bends[i].node.style.visibility = 'visible';
- this.bends[i].bounds = new mxRectangle(Math.round(x - b.width / 2),
- Math.round(y - b.height / 2), b.width, b.height);
-
- if (this.manageLabelHandle)
- {
- this.checkLabelHandle(this.bends[i].bounds);
- }
- else if (this.handleImage == null && this.labelShape.visible && mxUtils.intersects(this.bends[i].bounds, this.labelShape.bounds))
- {
- w = mxConstants.HANDLE_SIZE + 3;
- h = mxConstants.HANDLE_SIZE + 3;
- this.bends[i].bounds = new mxRectangle(Math.round(x - w / 2), Math.round(y - h / 2), w, h);
- }
-
- this.bends[i].redraw();
- }
- else
- {
- this.bends[i].destroy();
- this.bends[i] = null;
- }
- }
- }
- };
- /**
- * Function: checkLabelHandle
- *
- * Checks if the label handle intersects the given bounds and moves it if it
- * intersects.
- */
- mxEdgeHandler.prototype.checkLabelHandle = function(b)
- {
- if (this.labelShape != null)
- {
- var b2 = this.labelShape.bounds;
-
- if (mxUtils.intersects(b, b2))
- {
- if (b.getCenterY() < b2.getCenterY())
- {
- b2.y = b.y + b.height;
- }
- else
- {
- b2.y = b.y - b2.height;
- }
- }
- }
- };
- /**
- * Function: drawPreview
- *
- * Redraws the preview.
- */
- mxEdgeHandler.prototype.drawPreview = function()
- {
- try
- {
- if (this.isLabel)
- {
- var b = this.labelShape.bounds;
- var bounds = new mxRectangle(Math.round(this.label.x - b.width / 2),
- Math.round(this.label.y - b.height / 2), b.width, b.height);
-
- if (!this.labelShape.bounds.equals(bounds))
- {
- this.labelShape.bounds = bounds;
- this.labelShape.redraw();
- }
- }
-
- if (this.shape != null && !mxUtils.equalPoints(this.shape.points, this.abspoints))
- {
- this.shape.apply(this.state);
- this.shape.points = this.abspoints.slice();
- this.shape.scale = this.state.view.scale;
- this.shape.isDashed = this.isSelectionDashed();
- this.shape.stroke = this.getSelectionColor();
- this.shape.strokewidth = this.getSelectionStrokeWidth() / this.shape.scale / this.shape.scale;
- this.shape.isShadow = false;
- this.shape.redraw();
- }
-
- this.updateParentHighlight();
- }
- catch (e)
- {
- // ignore
- }
- };
- /**
- * Function: refresh
- *
- * Refreshes the bends of this handler.
- */
- mxEdgeHandler.prototype.refresh = function()
- {
- if (this.state != null)
- {
- this.abspoints = this.getSelectionPoints(this.state);
- this.points = [];
-
- if (this.bends != null)
- {
- this.destroyBends(this.bends);
- this.bends = this.createBends();
- }
-
- if (this.virtualBends != null)
- {
- this.destroyBends(this.virtualBends);
- this.virtualBends = this.createVirtualBends();
- }
-
- if (this.customHandles != null)
- {
- this.destroyBends(this.customHandles);
- this.customHandles = this.createCustomHandles();
- }
-
- // Puts label node on top of bends
- if (this.labelShape != null && this.labelShape.node != null && this.labelShape.node.parentNode != null)
- {
- this.labelShape.node.parentNode.appendChild(this.labelShape.node);
- }
- }
- };
- /**
- * Function: isDestroyed
- *
- * Returns true if <destroy> was called.
- */
- mxEdgeHandler.prototype.isDestroyed = function()
- {
- return this.shape == null;
- };
- /**
- * Function: destroyBends
- *
- * Destroys all elements in <bends>.
- */
- mxEdgeHandler.prototype.destroyBends = function(bends)
- {
- if (bends != null)
- {
- for (var i = 0; i < bends.length; i++)
- {
- if (bends[i] != null)
- {
- bends[i].destroy();
- }
- }
- }
- };
- /**
- * Function: destroy
- *
- * Destroys the handler and all its resources and DOM nodes. This does
- * normally not need to be called as handlers are destroyed automatically
- * when the corresponding cell is deselected.
- */
- mxEdgeHandler.prototype.destroy = function()
- {
- if (this.escapeHandler != null)
- {
- this.state.view.graph.removeListener(this.escapeHandler);
- this.escapeHandler = null;
- }
-
- if (this.marker != null)
- {
- this.marker.destroy();
- this.marker = null;
- }
-
- if (this.shape != null)
- {
- this.shape.destroy();
- this.shape = null;
- }
-
- if (this.parentHighlight != null)
- {
- var parent = this.graph.model.getParent(this.state.cell);
- var pstate = this.graph.view.getState(parent);
- if (pstate != null && pstate.parentHighlight == this.parentHighlight)
- {
- pstate.parentHighlight = null;
- }
-
- this.parentHighlight.destroy();
- this.parentHighlight = null;
- }
-
- if (this.labelShape != null)
- {
- this.labelShape.destroy();
- this.labelShape = null;
- }
- if (this.constraintHandler != null)
- {
- this.constraintHandler.destroy();
- this.constraintHandler = null;
- }
-
- this.destroyBends(this.virtualBends);
- this.virtualBends = null;
-
- this.destroyBends(this.customHandles);
- this.customHandles = null;
- this.destroyBends(this.bends);
- this.bends = null;
-
- this.removeHint();
- };
|