001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.uml.ui.support.relationshipVerification;
043:
044: import java.util.ArrayList;
045:
046: import org.netbeans.modules.uml.common.generics.ETPairT;
047: import org.netbeans.modules.uml.common.generics.ETTripleT;
048: import org.netbeans.modules.uml.core.eventframework.EventFunctor;
049: import org.netbeans.modules.uml.core.eventframework.EventManager;
050: import org.netbeans.modules.uml.core.eventframework.IEventPayload;
051: import org.netbeans.modules.uml.core.metamodel.diagrams.IDiagram;
052: import org.netbeans.modules.uml.core.support.umlsupport.ETPoint;
053: import org.netbeans.modules.uml.core.support.umlsupport.IETPoint;
054: import org.netbeans.modules.uml.core.support.umlsupport.IResultCell;
055: import org.netbeans.modules.uml.ui.controls.drawingarea.DrawingAreaEventDispatcherImpl;
056: import org.netbeans.modules.uml.ui.controls.drawingarea.IDrawingAreaEventDispatcher;
057: import org.netbeans.modules.uml.ui.support.viewfactorysupport.ETPointEx;
058: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IETNode;
059: import org.netbeans.modules.uml.ui.support.viewfactorysupport.TypeConversions;
060: import org.netbeans.modules.uml.ui.swing.drawingarea.EdgeCreateContext;
061: import org.netbeans.modules.uml.ui.swing.drawingarea.EdgeFinishContext;
062: import org.netbeans.modules.uml.ui.swing.drawingarea.EdgeMouseMoveContext;
063: import org.netbeans.modules.uml.ui.swing.drawingarea.IDrawingAreaAddEdgeEventsSink;
064: import org.netbeans.modules.uml.ui.swing.drawingarea.IEdgeCreateBendContext;
065: import org.netbeans.modules.uml.ui.swing.drawingarea.IEdgeCreateContext;
066: import org.netbeans.modules.uml.ui.swing.drawingarea.IEdgeFinishContext;
067: import org.netbeans.modules.uml.ui.swing.drawingarea.IEdgeMouseMoveContext;
068: import com.tomsawyer.drawing.TSConnector; //import com.tomsawyer.util.TSConstPoint;
069: import com.tomsawyer.drawing.geometry.TSConstPoint;
070:
071: /**
072: * @author KevinM
073: * The AddEdgeEventDispatcher encapsulates the creation and routing of Edge Event contexts,
074: * through drawing area dispatchers exposed interfaces.
075: */
076: public class AddEdgeEventDispatcher implements IAddEdgeEvents {
077:
078: // Data, initialized by the constructor, no need to null them.
079: protected IDrawingAreaEventDispatcher m_dispatcher;
080: protected IDiagram m_parentDiagram;
081: protected String m_viewDesc;
082:
083: /**
084: * Preferred constructor.
085: */
086: public AddEdgeEventDispatcher(
087: IDrawingAreaEventDispatcher dipatcher,
088: IDiagram pParentDiagram, String viewDesc) {
089: super ();
090: setParentDiagram(pParentDiagram);
091: m_viewDesc = viewDesc;
092: m_dispatcher = dipatcher;
093: }
094:
095: public AddEdgeEventDispatcher(
096: IDrawingAreaEventDispatcher dipatcher,
097: IDiagram pParentDiagram) {
098: this (dipatcher, pParentDiagram, null);
099: }
100:
101: /* (non-Javadoc)
102: * @see org.netbeans.modules.uml.ui.support.relationshipVerification.IAddEdgeEvents#getParentDiagram()
103: */
104: public IDiagram getParentDiagram() {
105: return m_parentDiagram;
106: }
107:
108: /* (non-Javadoc)
109: * @see org.netbeans.modules.uml.ui.support.relationshipVerification.IAddEdgeEvents#setParentDiagram(org.netbeans.modules.uml.core.metamodel.diagrams.IDiagram)
110: */
111: public void setParentDiagram(IDiagram pParentDiagram) {
112: m_parentDiagram = pParentDiagram;
113: }
114:
115: /* (non-Javadoc)
116: * @see org.netbeans.modules.uml.ui.support.relationshipVerification.IAddEdgeEvents#getViewDescription()
117: */
118: public String getViewDescription() {
119: return m_viewDesc;
120: }
121:
122: /* (non-Javadoc)
123: * @see org.netbeans.modules.uml.ui.support.relationshipVerification.IAddEdgeEvents#setViewDescription(java.lang.String)
124: */
125: public void setViewDescription(String sViewDescription) {
126: m_viewDesc = sViewDescription;
127: }
128:
129: /* (non-Javadoc)
130: * @see org.netbeans.modules.uml.ui.support.relationshipVerification.IAddEdgeEvents#fireStartingEdgeEvent(org.netbeans.modules.uml.ui.support.viewfactorysupport.IETNode, com.tomsawyer.util.TSConstPoint)
131: */
132: public ETTripleT<TSConnector, Integer, IETPoint> fireStartingEdgeEvent(
133: IETNode pNode, TSConstPoint point) {
134:
135: IETPoint rpoint = null;
136: TSConnector connector = null;
137: Integer canceled = null;
138:
139: if (pNode != null) {
140:
141: TSConstPoint tempPoint = null;
142: if (point != null) {
143: tempPoint = (TSConstPoint) point.clone();
144: }
145:
146: // Create the context, fill it and fire the event
147: IEdgeCreateContext pEdgeCreateContext = new EdgeCreateContext();
148: if (pEdgeCreateContext != null) {
149: pEdgeCreateContext.setNode(pNode);
150: pEdgeCreateContext
151: .setViewDescription(getViewDescription());
152: pEdgeCreateContext
153: .setLogicalPoint(point != null ? new ETPointEx(
154: point) : null);
155:
156: if (getParentDiagram() != null) {
157: pEdgeCreateContext = fireDrawingAreaStartingEdge(
158: pEdgeCreateContext, false);
159:
160: // Now see if any listeners have canceled the event
161: canceled = new Integer(pEdgeCreateContext
162: .getCancel() ? 1 : 0);
163: // Pass back the connector, if it is valid
164: connector = pEdgeCreateContext.getConnector();
165:
166: if (connector != null) {
167: // Get the updated start point
168: rpoint = pEdgeCreateContext.getLogicalPoint();
169: }
170: }
171: }
172: }
173:
174: return new ETTripleT<TSConnector, Integer, IETPoint>(connector,
175: canceled, rpoint);
176: }
177:
178: /* (non-Javadoc)
179: * @see org.netbeans.modules.uml.ui.support.relationshipVerification.IAddEdgeEvents#fireShouldCreateBendEvent(com.tomsawyer.util.TSConstPoint)
180: */
181: public boolean fireShouldCreateBendEvent(TSConstPoint point) {
182: IEdgeCreateBendContext context = new EdgeCreateBendContext();
183: context.setLogicalPoint(point != null ? new ETPointEx(point)
184: : null);
185: context.setViewDescription(getViewDescription());
186: fireShouldCreateBend(context);
187: return context.getCancel() ? false : true;
188: }
189:
190: /* (non-Javadoc)
191: * @see org.netbeans.modules.uml.ui.support.relationshipVerification.IAddEdgeEvents#fireEdgeMouseMoveEvent(org.netbeans.modules.uml.ui.support.viewfactorysupport.IETNode, org.netbeans.modules.uml.ui.support.viewfactorysupport.IETNode, com.tomsawyer.util.TSConstPoint)
192: */
193: public boolean fireEdgeMouseMoveEvent(IETNode pStartNode,
194: IETNode pNodeUnderMouse, TSConstPoint point) {
195: IEdgeMouseMoveContext context = new EdgeMouseMoveContext();
196: context.setLogicalPoint(point != null ? new ETPointEx(point)
197: : null);
198: context.setStartNode(pStartNode);
199: context.setNodeUnderMouse(pNodeUnderMouse);
200: context.setViewDescription(getViewDescription());
201: fireEdgeMouseMove(context);
202: return context.getValid();
203: }
204:
205: /* (non-Javadoc)
206: * @see org.netbeans.modules.uml.ui.support.relationshipVerification.IAddEdgeEvents#fireFinishEdgeEvent(org.netbeans.modules.uml.ui.support.viewfactorysupport.IETNode, org.netbeans.modules.uml.ui.support.viewfactorysupport.IETNode, com.tomsawyer.editor.TSEConnector, com.tomsawyer.util.TSConstPoint)
207: */
208: public ETPairT<TSConnector, Integer> fireFinishEdgeEvent(
209: IETNode pStartNode, IETNode pFinishNode,
210: TSConnector pStartConnector, TSConstPoint point) {
211: if (pStartNode != null && pFinishNode != null) {
212: IEdgeFinishContext pEdgeFinishContext = new EdgeFinishContext();
213: pEdgeFinishContext.setStartNode(pStartNode);
214: pEdgeFinishContext.setFinishNode(pFinishNode);
215: pEdgeFinishContext.setStartConnector(pStartConnector);
216: pEdgeFinishContext
217: .setLogicalPoint(point != null ? new ETPointEx(
218: point) : null);
219: pEdgeFinishContext.setViewDescription(getViewDescription());
220:
221: fireFinishEdge(pEdgeFinishContext);
222:
223: boolean varCanceled = pEdgeFinishContext.getCancel();
224:
225: ETPairT<TSConnector, Integer> retCode = new ETPairT<TSConnector, Integer>(
226: pEdgeFinishContext.getFinishConnector(),
227: new Integer(varCanceled ? 1 : 0));
228: return retCode;
229: }
230: return null;
231: }
232:
233: protected IEdgeCreateContext fireDrawingAreaStartingEdge(
234: IEdgeCreateContext pContext, boolean something) {
235: if (m_dispatcher != null && pContext != null) {
236: m_dispatcher.fireDrawingAreaStartingEdge(
237: getParentDiagram(), pContext, m_dispatcher
238: .createPayload("FireStartingEdge"));
239: }
240: return pContext;
241: }
242:
243: protected void fireShouldCreateBend(IEdgeCreateBendContext pContext) {
244: if (m_dispatcher != null && pContext != null) {
245: m_dispatcher
246: .fireDrawingAreaEdgeShouldCreateBend(
247: getParentDiagram(),
248: pContext,
249: m_dispatcher
250: .createPayload("FireShouldCreateBendEvent"));
251: }
252: }
253:
254: protected void fireEdgeMouseMove(IEdgeMouseMoveContext pContext) {
255: if (m_dispatcher != null && pContext != null) {
256: m_dispatcher.fireDrawingAreaEdgeMouseMove(
257: getParentDiagram(), pContext, m_dispatcher
258: .createPayload("FireEdgeMouseMoveEvent"));
259: }
260: }
261:
262: protected void fireFinishEdge(IEdgeFinishContext pContext) {
263: if (m_dispatcher != null && pContext != null) {
264: m_dispatcher.fireDrawingAreaFinishEdge(getParentDiagram(),
265: pContext, m_dispatcher
266: .createPayload("FireFinishEdgeEvent"));
267: }
268: }
269: }
|