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.applicationmanager;
043:
044: import java.util.ArrayList;
045: import java.util.List;
046:
047: import org.dom4j.Document;
048: import org.dom4j.Node;
049:
050: import org.netbeans.modules.uml.common.generics.IteratorT;
051: import org.netbeans.modules.uml.core.metamodel.core.foundation.IDependency;
052: import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
053: import org.netbeans.modules.uml.core.metamodel.core.foundation.IPresentationElement;
054: import org.netbeans.modules.uml.core.metamodel.core.foundation.IUsage;
055: import org.netbeans.modules.uml.core.metamodel.diagrams.IDiagram;
056: import org.netbeans.modules.uml.core.metamodel.diagrams.IGraphEventKind;
057: import org.netbeans.modules.uml.core.metamodel.dynamics.IMessage;
058: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IAssociation;
059: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IGeneralization;
060: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IImplementation;
061: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IInterface;
062: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IRealization;
063: import org.netbeans.modules.uml.core.support.umlsupport.ETPoint;
064: import org.netbeans.modules.uml.core.support.umlsupport.IETPoint;
065: import org.netbeans.modules.uml.core.support.umlsupport.IETRect;
066: import org.netbeans.modules.uml.core.support.umlutils.ETArrayList;
067: import org.netbeans.modules.uml.core.support.umlutils.ETList;
068: import org.netbeans.modules.uml.core.support.umlutils.InvalidArguments;
069: import org.netbeans.modules.uml.ui.products.ad.drawengines.INodeDrawEngine;
070: import org.netbeans.modules.uml.ui.products.ad.graphobjects.ETEdge;
071: import org.netbeans.modules.uml.ui.products.ad.viewfactory.IETGraphObjectUI;
072: import org.netbeans.modules.uml.ui.support.viewfactorysupport.ETRectEx;
073: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawEngine;
074: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IETNodeUI;
075: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IEventManager;
076: import org.netbeans.modules.uml.ui.support.viewfactorysupport.TypeConversions;
077: import com.tomsawyer.diagramming.TSResizeControl;
078: import com.tomsawyer.diagramming.command.TSMoveGroupCommand;
079: import com.tomsawyer.editor.ui.TSENodeUI;
080: import com.tomsawyer.editor.TSEGraphManager;
081: import com.tomsawyer.editor.TSENode;
082: import com.tomsawyer.editor.TSEObjectUI;
083: import com.tomsawyer.drawing.geometry.TSConstPoint;
084: import com.tomsawyer.drawing.geometry.TSConstRect;
085: import com.tomsawyer.drawing.geometry.TSRect;
086: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject;
087: import org.netbeans.modules.uml.ui.support.EdgeKindEnum;
088: import org.netbeans.modules.uml.ui.swing.drawingarea.ADGraphWindow;
089: import org.netbeans.modules.uml.ui.swing.drawingarea.IDrawingAreaControl;
090:
091: public class NodePresentation extends ProductGraphPresentation
092: implements INodePresentation, MoveToFlags {
093: private TSENode mNode = null;
094:
095: /**
096: * Creates the class element node.
097: *
098: * @param doc The document owner of the new node
099: * @param parent The parent of the new node
100: */
101: public void establishNodePresence(Document doc, Node parent) {
102: buildNodePresence("UML:NodePresentation", doc, parent);
103: }
104:
105: /**
106: *
107: */
108: public NodePresentation() {
109: super ();
110: }
111:
112: /* (non-Javadoc)
113: * @see org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation#getNodeView()
114: */
115: public TSENodeUI getNodeView() {
116: return this .getUI() instanceof TSENodeUI ? (TSENodeUI) this
117: .getUI() : null;
118: }
119:
120: /* (non-Javadoc)
121: * @see org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation#getTSNode()
122: */
123: public TSENode getTSNode() {
124: //return this.isNode() ? (TSENode)this.getETGraphObject() : null;
125: return mNode;
126: }
127:
128: /* (non-Javadoc)
129: * @see org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation#setTSNode(null)
130: */
131: public void setTSNode(TSENode newVal) {
132: //this.setUI(newVal != null ? (IETGraphObjectUI)newVal.getUI() : null);
133: mNode = newVal;
134: }
135:
136: public IETGraphObjectUI getUI() {
137: TSENode node = getTSNode();
138:
139: IETGraphObjectUI retVal = null;
140:
141: if (node != null) {
142: TSEObjectUI ui = node.getUI();
143: if (ui instanceof IETGraphObjectUI) {
144: retVal = (IETGraphObjectUI) ui;
145: }
146: }
147:
148: return retVal;
149: }
150:
151: /**
152: * Called to notify the node that a link has been added.
153: *
154: * @param edgeToBeDeleted The link about to be deleted
155: * @param isFromNode <code>true</code> if this is the from node.
156: */
157: public void onPreDeleteLink(IEdgePresentation edgeToBeDeleted,
158: boolean isFromNode) {
159: IEventManager manager = getEventManager();
160: if (manager != null) {
161: manager.onPreDeleteLink(edgeToBeDeleted.getETGraphObject(),
162: isFromNode);
163: }
164: }
165:
166: /* (non-Javadoc)
167: * @see org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation#moveTo(long, long, long)
168: */
169: public void moveTo(int x, int y, int flags) {
170: boolean bMoveInX = (flags & MTF_MOVEX) == MTF_MOVEX ? true
171: : false;
172: boolean bMoveInY = (flags & MTF_MOVEY) == MTF_MOVEY ? true
173: : false;
174: boolean deviceCoord = (flags & MTF_DEVICECOORD) == MTF_DEVICECOORD ? true
175: : false;
176: boolean bLogical = (flags & MTF_LOGICALCOORD) == MTF_LOGICALCOORD ? true
177: : false;
178: boolean bInvalidate = (flags & MTF_INVALIDATE) == MTF_INVALIDATE ? true
179: : false;
180: boolean bScrollView = (flags & MTF_SCROLLVIEW) == MTF_SCROLLVIEW ? true
181: : false;
182:
183: TSENode node = getTSNode();
184: IETGraphObjectUI ui = getUI();
185: IDiagram diagram = getDiagram();
186:
187: if ((node != null) && (ui != null)) {
188: if (bInvalidate == true) {
189: invalidate();
190: }
191:
192: IDrawEngine engine = getDrawEngine();
193: engine.onGraphEvent(IGraphEventKind.GEK_PRE_MOVE);
194:
195: // TSConstRect oldBounds = node.getBounds();
196: // TSRect newBounds = new TSRect(oldBounds);
197:
198: // Determine the new location (Bounds).
199: int moveX = x;
200: int moveY = y;
201: if (deviceCoord == true) {
202: IETPoint convertedPoint = diagram.deviceToLogicalPoint(
203: x, y);
204: if (convertedPoint != null) {
205: moveX = convertedPoint.getX();
206: moveY = convertedPoint.getY();
207: }
208: }
209:
210: if (bMoveInX == true) {
211: // newBounds.setLeft(moveX);
212: // newBounds.setWidth(oldBounds.getWidth());
213: node.setCenterX(moveX);
214: }
215:
216: if (bMoveInY == true) {
217: // newBounds.setTop(moveY);
218: // newBounds.setHeight(oldBounds.getHeight());
219: node.setCenterY(moveY);
220: }
221:
222: // Now check if niether bMoveInX and bMoveInY then default to
223: // moving in both the X and the Y direction.
224: if ((bMoveInX == false) && (bMoveInY == false)) {
225: // newBounds.setLeft(moveX);
226: // newBounds.setTop(moveY);
227: // newBounds.setHeight(oldBounds.getHeight());
228: // newBounds.setWidth(oldBounds.getWidth());
229:
230: node.setCenterX(moveX);
231: node.setCenterY(moveY);
232: }
233:
234: // if(bInvalidate == true)
235: // {
236: // invalidate();
237: // }
238:
239: // IDrawEngine engine = getDrawEngine();
240: // engine.onGraphEvent(IGraphEventKind.GEK_PRE_MOVE);
241: //
242: // node.setBounds(newBounds);
243:
244: engine.onGraphEvent(IGraphEventKind.GEK_POST_MOVE);
245:
246: if (bInvalidate == true) {
247: invalidate();
248: IDrawingAreaControl control = ui.getDrawingArea();
249:
250: // Fix J961: When moving a track car on an SQD,
251: // the presenation element must draw immediately.
252: control.getGraphWindow().updateInvalidRegions(true);
253: }
254: }
255:
256: }
257:
258: /**
259: * Moves this node using the TS command
260: *
261: * @param x [in] The new x center
262: * @param x [in] The new y center
263: */
264: public void moveTo(int x, int y) {
265: if (m_Node != null) {
266: TSENode pTSENode = (TSENode) getTSNode();
267:
268: if (pTSENode != null) {
269: TSEGraphManager pTSEGraphManager = (TSEGraphManager) pTSENode
270: .getOwnerGraph().getOwnerGraphManager();
271:
272: if (pTSEGraphManager != null) {
273: List graphs = new ArrayList();
274: List nodeList = new ArrayList();
275:
276: graphs.add(pTSENode.getOwnerGraph());
277: nodeList.add(pTSENode);
278:
279: TSConstPoint oldPoint = pTSENode.getCenter();
280: TSConstPoint newPoint = new TSConstPoint(x, y);
281:
282: TSMoveGroupCommand cmdMove = new TSMoveGroupCommand(
283: graphs, nodeList, new ArrayList(),
284: new ArrayList(), new ArrayList(),
285: new ArrayList(), oldPoint, newPoint);
286:
287: pTSEGraphManager.getGraphWindow().transmit(cmdMove);
288: }
289:
290: }
291: }
292: }
293:
294: /**
295: * Redraw this node.
296: * @see org.netbeans.modules.uml.ui.support.applicationmanager.IProductGraphPresentation#invalidate()
297: */
298: public void invalidate() {
299: IETGraphObject node = getETGraphObject();
300:
301: if (node != null && node.isSelected()) {
302: IETRect bounds = new ETRectEx(node.getBounds());
303: if (node.getETUI() instanceof IETNodeUI) {
304: IETNodeUI nodeUI = (IETNodeUI) node.getETUI();
305: bounds.inflate(nodeUI.getGrappleSize() + 10);
306: }
307:
308: IDrawEngine engine = getDrawEngine();
309: if (engine != null) {
310: engine.invalidateRect(bounds);
311: return;
312: }
313: }
314: super .invalidate();
315: }
316:
317: /**
318: * Returns the bounding rectangle for this node.
319: *
320: * @return The bounding Rectangle
321: * @see org.netbeans.modules.uml.ui.support.applicationmanager.IProductGraphPresentation#getBoundingRect()
322: */
323: public IETRect getBoundingRect() {
324: IETGraphObject node = getETGraphObject();
325: return node != null ? new ETRectEx(node.getBounds()) : null;
326: }
327:
328: /* (non-Javadoc)
329: * @see org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation#resize(long, long, boolean)
330: */
331: public void resize(double cx, double cy, boolean bKeepUpperLeftPoint) {
332: TSENode node = getTSNode();
333: if (node != null) {
334: if (bKeepUpperLeftPoint == false) {
335: node.setWidth(cx);
336: node.setHeight(cy);
337: }
338:
339: else {
340: node.setBounds(node.getLeft(), node.getTop(), node
341: .getLeft()
342: + cx, node.getTop() - cy);
343: }
344:
345: // TS always tells the node it was resized interactively
346: // when we do it programmatically we don't want that
347:
348: if (getDrawEngine() != null) {
349: getDrawEngine().onResized();
350: }
351:
352: // Update the orginal size.
353: node.setOriginalSize(node.getWidth(), node.getHeight());
354: }
355: }
356:
357: /* (non-Javadoc)
358: * @see org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation#sizeToContents()
359: */
360: public void sizeToContents() {
361: IDrawEngine engine = getDrawEngine();
362: if (engine != null)
363: engine.sizeToContents();
364: }
365:
366: /* (non-Javadoc)
367: * @see org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation#getEdges(boolean, boolean)
368: */
369: public ETList<IETGraphObject> getEdges(boolean bIncoming,
370: boolean bOutgoing) {
371: TSENode node = getTSNode();
372: if (node != null && bIncoming && bOutgoing) {
373: ETArrayList<IETGraphObject> edges = new ETArrayList<IETGraphObject>();
374: if (edges != null) {
375: if (bIncoming == true)
376: edges.addAll(node.inEdges());
377: if (bOutgoing == true)
378: edges.addAll(node.outEdges());
379: return edges;
380: }
381: }
382: return null;
383: }
384:
385: /* (non-Javadoc)
386: * @see org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation#getEdgesWithEndPoint(boolean, boolean, org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation)
387: */
388: public ETList<IPresentationElement> getEdgesWithEndPoint(
389: boolean bIncoming, boolean bOutgoing,
390: INodePresentation pEndNodePresentation) {
391: ETList<IETGraphObject> edges = getEdges(bIncoming, bOutgoing);
392: if (edges != null) {
393: try {
394:
395: ETList<IPresentationElement> edgesWithEndPoint = new ETArrayList<IPresentationElement>();
396: IteratorT<ETEdge> iter = new IteratorT<ETEdge>(edges);
397: while (iter.hasNext()) {
398: ETEdge edge = iter.next();
399: IEdgePresentation edgePresentation = (IEdgePresentation) edge
400: .getPresentationElement();
401:
402: if (pEndNodePresentation == null
403: || (edgePresentation != null && (edgePresentation
404: .getEdgeFromPresentationElement() == pEndNodePresentation || edgePresentation
405: .getEdgeToPresentationElement() == pEndNodePresentation))) {
406: edgesWithEndPoint.add(edgePresentation);
407: }
408: }
409: return edgesWithEndPoint;
410: } catch (Exception e) {
411: e.printStackTrace();
412: }
413:
414: }
415: return null;
416: }
417:
418: /* (non-Javadoc)
419: * @see org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation#getEdgesExitingContainer(boolean, boolean)
420: */
421: public ETList<IPresentationElement> getEdgesExitingContainer(
422: boolean bIncoming, boolean bOutgoing) {
423: // TODO Auto-generated method stub
424: return null;
425: }
426:
427: /* (non-Javadoc)
428: * @see org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation#getEdgesByType(int, boolean, boolean)
429: */
430: public ETList<IETGraphObject> getEdgesByType(int nEdgeKind,
431: boolean bIncoming, boolean bOutgoing) {
432: ETList<IETGraphObject> wantedElements = new ETArrayList<IETGraphObject>();
433: ETList<IETGraphObject> edges = getEdges(bIncoming, bOutgoing);
434:
435: if (edges != null) {
436:
437: try {
438: IteratorT<IETGraphObject> iter = new IteratorT<IETGraphObject>(
439: edges);
440:
441: while (iter.hasNext()) {
442: IETGraphObject edge = iter.next();
443: IElement element = TypeConversions.getElement(edge);
444: ;
445:
446: switch (nEdgeKind) {
447: case EdgeKindEnum.EK_ALL:
448: break;
449: case EdgeKindEnum.EK_REALIZATION:
450: if (!(element instanceof IRealization)) {
451: edge = null;
452: }
453: break;
454: case EdgeKindEnum.EK_ASSOCIATION:
455: if (!(element instanceof IAssociation)) {
456: edge = null;
457: }
458: break;
459: case EdgeKindEnum.EK_DEPENDENCY:
460: if (!(element instanceof IDependency)) {
461: edge = null;
462: }
463: break;
464: case EdgeKindEnum.EK_USAGE:
465: if (!(element instanceof IUsage)) {
466: edge = null;
467: }
468: break;
469: case EdgeKindEnum.EK_MESSAGE:
470: if (!(element instanceof IMessage)) {
471: edge = null;
472: }
473: break;
474: case EdgeKindEnum.EK_GENERALIZATION:
475: if (!(element instanceof IGeneralization)) {
476: edge = null;
477: }
478: break;
479: case EdgeKindEnum.EK_IMPLEMENTATION:
480: if (!(element instanceof IImplementation)) {
481: edge = null;
482: }
483: break;
484: case EdgeKindEnum.EK_INTERFACE:
485: if (!(element instanceof IInterface)) {
486: edge = null;
487: }
488: break;
489: case EdgeKindEnum.EK_NESTED_LINK:
490: IDrawEngine drawEngine = TypeConversions
491: .getDrawEngine(edge);
492: if (drawEngine != null) {
493: if (!drawEngine.getDrawEngineID().equals(
494: "NestedLinkDrawEngine")) {
495: edge = null;
496: }
497: } else {
498: edge = null;
499: }
500: break;
501: }
502:
503: if (edge != null) {
504: wantedElements.add(edge);
505: }
506: }
507: } catch (InvalidArguments e) {
508: e.printStackTrace();
509: }
510: }
511:
512: return wantedElements;
513: }
514:
515: /* (non-Javadoc)
516: * @see org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation#getEdgesWithDrawEngine(java.lang.String, boolean, boolean)
517: */
518: public ETList<IPresentationElement> getEdgesWithDrawEngine(
519: String sDrawEngineID, boolean bIncoming, boolean bOutgoing) {
520: // TODO Auto-generated method stub
521: return null;
522: }
523:
524: /* (non-Javadoc)
525: * @see org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation#getLocation()
526: */
527: public IETRect getLocation() {
528: try {
529: return getDrawEngine().getBoundingRect();
530: } catch (Exception e) {
531: return null;
532: }
533: }
534:
535: /* (non-Javadoc)
536: * @see org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation#getHeight()
537: */
538: public long getHeight() {
539: TSENode node = getTSNode();
540: return node != null ? (long) node.getHeight() : 0;
541: }
542:
543: /* (non-Javadoc)
544: * @see org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation#getWidth()
545: */
546: public long getWidth() {
547: TSENode node = getTSNode();
548: return node != null ? (long) node.getWidth() : 0;
549: }
550:
551: /* (non-Javadoc)
552: * @see org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation#getCenter()
553: */
554: public IETPoint getCenter() {
555: TSENode node = getTSNode();
556: return node != null ? new ETPoint(
557: (int) node.getCenter().getX(), (int) node.getCenter()
558: .getY()) : null;
559: }
560:
561: /* (non-Javadoc)
562: * @see org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation#PEsViaBoundingRect(boolean)
563: */
564: public ETList<IPresentationElement> getPEsViaBoundingRect(
565: boolean bTouchingRect) {
566: if (this .getOwnerNode() != null) {
567: if (bTouchingRect)
568: return buildListNodesTouchingBoundingRect();
569: else
570: return buildListNodesFullyContainedInBoundingRect();
571: }
572: return null;
573: }
574:
575: protected ETList<IPresentationElement> buildListNodesFullyContainedInBoundingRect() {
576: return getOwnerNode() != null ? buildListNodesViaRect(
577: getBoundingRect(), false) : null;
578: }
579:
580: protected ETList<IPresentationElement> buildListNodesTouchingBoundingRect() {
581: return getOwnerNode() != null ? buildListNodesViaRect(
582: getBoundingRect(), true) : null;
583: }
584:
585: ETList<IPresentationElement> buildListNodesViaRect(IETRect rect,
586: boolean bTouchingRect) {
587: IDrawingAreaControl control = getDrawingArea();
588: if (control != null) {
589: ETList<IPresentationElement> list = control
590: .getAllNodesViaRect(rect, bTouchingRect);
591:
592: if (list != null) {
593: list.remove(this );
594: }
595:
596: return list;
597: }
598: return null;
599: }
600:
601: /* (non-Javadoc)
602: * @see org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation#PEsViaRect(boolean, org.netbeans.modules.uml.core.support.umlsupport.IETRect)
603: */
604: public ETList<IPresentationElement> getPEsViaRect(
605: boolean bTouchingRect, IETRect pRect) {
606: return buildListNodesViaRect(pRect, bTouchingRect);
607: }
608:
609: protected TSENode getOwnerNode() {
610: return TypeConversions.getOwnerNode(getETGraphObject());
611: }
612:
613: /* (non-Javadoc)
614: * @see org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation#findNearbyElement(boolean, null, java.lang.String)
615: */
616: public IPresentationElement findNearbyElement(
617: boolean bSearchOutsideOfBoundingRect,
618: IElement pElementToFind, String sDrawEngineTypeToFind) {
619: IPresentationElement foundPE = null;
620: if (this .getOwnerNode() != null
621: && getOwnerNode().getBounds() != null) {
622: TSRect qualifierNodeRect = new TSRect(getOwnerNode()
623: .getBounds());
624:
625: TSConstPoint center = qualifierNodeRect.getCenter();
626: qualifierNodeRect.setSize(
627: qualifierNodeRect.getWidth() + 10,
628: qualifierNodeRect.getHeight() + 10);
629: qualifierNodeRect.setCenter(center);
630:
631: ETList<IPresentationElement> otherPEsWithinBoundingRect = getPEsViaBoundingRect(true);
632:
633: int count = 0;
634: if (otherPEsWithinBoundingRect != null) {
635: count = otherPEsWithinBoundingRect.getCount();
636: }
637:
638: for (int index = 0; index < count; index++) {
639: IPresentationElement this PE = otherPEsWithinBoundingRect
640: .item(index);
641: IElement element = TypeConversions.getElement(this PE);
642:
643: if (element != null) {
644: if (pElementToFind.isSame(element)) {
645: if (sDrawEngineTypeToFind != null) {
646: IDrawEngine drawEngine = TypeConversions
647: .getDrawEngine(this PE);
648:
649: if (drawEngine != null) {
650: String sID = drawEngine
651: .getDrawEngineID();
652:
653: if (sID
654: .compareTo(sDrawEngineTypeToFind) != 0)
655: continue;
656: }
657: }
658:
659: foundPE = this PE;
660: }
661: }
662: }
663:
664: if (foundPE == null && bSearchOutsideOfBoundingRect) {
665: IDrawingAreaControl control = getDrawingArea();
666:
667: if (control != null) {
668: ETList<IPresentationElement> elementsOnDiagram = control
669: .getAllItems2(pElementToFind);
670:
671: count = 0;
672:
673: if (elementsOnDiagram != null)
674: count = elementsOnDiagram.getCount();
675:
676: for (int index = 0; index < count; index++) {
677: IPresentationElement this PE = elementsOnDiagram
678: .item(index);
679: IElement element = TypeConversions
680: .getElement(this PE);
681:
682: if (element != null) {
683: if (pElementToFind.isSame(element)) {
684: if (sDrawEngineTypeToFind != null) {
685: IDrawEngine drawEngine = TypeConversions
686: .getDrawEngine(this PE);
687: if (drawEngine != null) {
688: String sID = drawEngine
689: .getDrawEngineID();
690:
691: if (sID
692: .compareTo(sDrawEngineTypeToFind) != 0)
693: continue;
694: }
695: }
696:
697: foundPE = this PE;
698: }
699: }
700: }
701: }
702: }
703: }
704:
705: return foundPE;
706: }
707:
708: /**
709: * Returns the node presentation that is this node presentation's graphical container
710: *
711: * @param pContainer [out,retval] The node presentation that is the graphical container
712: *
713: * @return HRESULT
714: */
715: public INodePresentation getGraphicalContainer() {
716: INodePresentation pContainer = null;
717:
718: IPresentationElement cpThisPE = (IPresentationElement) this ;
719:
720: if (cpThisPE != null) {
721: ETList<IPresentationElement> cpTouchingOrContainedNodePEs = buildListNodesTouchingBoundingRect();
722:
723: if (cpTouchingOrContainedNodePEs != null) {
724: IETRect cpRectThisBounding = getBoundingRect();
725:
726: if (cpRectThisBounding != null) {
727: // Search the list for the "top" container
728: // The list of touching nodes is sorted from bottom to top,
729: // so search the list in reverse order.
730:
731: double fMinContainerArea = 0; // FLT_MAX;
732:
733: IPresentationElement cpContainer = null;
734:
735: int lCnt = cpTouchingOrContainedNodePEs.size();
736:
737: for (int lIndx = (lCnt - 1); lIndx >= 0; lIndx--) {
738: IPresentationElement cpPE = cpTouchingOrContainedNodePEs
739: .get(lIndx);
740:
741: if (cpPE != cpThisPE) {
742: IDrawEngine cpEngine = TypeConversions
743: .getDrawEngine(cpPE);
744:
745: if (cpEngine != null) {
746:
747: boolean bIsContainer = false;
748:
749: bIsContainer = cpEngine
750: .getIsGraphicalContainer();
751:
752: if (bIsContainer) {
753: IETRect cpRectBounding = cpEngine
754: .getLogicalBoundingRect(false);
755:
756: boolean bIsContained = false;
757:
758: bIsContained = cpRectBounding
759: .isContained(cpRectThisBounding);
760:
761: if (bIsContained) {
762: // The true container is the container with the smallest area
763: //Rect rectEngine;
764: //_VH(CRectConversions : : ETRectToRECT(cpRectBounding, rectEngine));
765:
766: IETRect rectEngine = cpRectBounding;
767: //_VH(CRectConversions : : ETRectToRECT(cpRectBounding, rectEngine));
768:
769: double fEngineArea = (double) rectEngine
770: .getWidth()
771: * -rectEngine
772: .getHeight();
773:
774: // ATLASSERT(fEngineArea > 0);
775:
776: if (fEngineArea < fMinContainerArea) {
777: fMinContainerArea = fEngineArea;
778:
779: cpContainer = null;
780: cpContainer = cpPE;
781: }
782: }
783: }
784: }
785: }
786: }
787:
788: if (cpContainer != null) {
789: pContainer = (cpContainer instanceof INodePresentation) ? (INodePresentation) cpContainer
790: : null;
791: }
792: }
793: }
794: }
795:
796: return pContainer;
797: }
798:
799: /* (non-Javadoc)
800: * @see org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation#resizeToContain(org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation)
801: */
802: public void resizeToContain(INodePresentation pContained) {
803: // TODO Auto-generated method stub
804:
805: }
806:
807: /* (non-Javadoc)
808: * @see org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation#getLockEdit()
809: */
810: public boolean getLockEdit() {
811: boolean pVal = false;
812: IDrawEngine engine = this .getDrawEngine();
813: INodeDrawEngine nodeEngine = (engine instanceof INodeDrawEngine) ? (INodeDrawEngine) engine
814: : null;
815:
816: return nodeEngine != null ? nodeEngine.getLockEdit() : false;
817: }
818:
819: /* (non-Javadoc)
820: * @see org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation#lockEdit(boolean)
821: */
822: public void setLockEdit(boolean newVal) {
823: IDrawEngine engine = this .getDrawEngine();
824: INodeDrawEngine nodeEngine = (engine instanceof INodeDrawEngine) ? (INodeDrawEngine) engine
825: : null;
826:
827: if (nodeEngine != null) {
828: nodeEngine.setLockEdit(newVal);
829: }
830: }
831:
832: public ETList<IConnectedNode> getEdgeConnectedNodes() {
833: ETList<IConnectedNode> nodes = new ETArrayList<IConnectedNode>();
834:
835: ETList<IETGraphObject> etGraphObjects = getEdges(true, true);
836:
837: int count = etGraphObjects.getCount();
838:
839: for (int index = 0; index < count; ++index) {
840: IETGraphObject etGraphObject = etGraphObjects.item(index);
841:
842: if (etGraphObject != null) {
843: IEdgePresentation edgePE = TypeConversions
844: .getEdgePresentation(etGraphObject);
845:
846: if (edgePE != null) {
847: INodePresentation nodeAtOtherEndPresentation = edgePE
848: .getOtherEnd(this );
849:
850: if (nodeAtOtherEndPresentation != null) {
851: IConnectedNode connectedNode = new ConnectedNode();
852: connectedNode.setIntermediateEdge(edgePE);
853: connectedNode
854: .setNodeAtOtherEnd(nodeAtOtherEndPresentation);
855: nodes.add(connectedNode);
856: }
857: }
858: }
859: }
860:
861: return nodes;
862: }
863:
864: /* (non-Javadoc)
865: * @see org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation#resizeByHandle(int, int, int, boolean)
866: */
867: public void resizeByHandle(int dx, int dy, int handleLocation,
868: boolean sendGraphEvents) {
869: if (m_Node != null && (dx != 0 || dy != 0)) {
870: IDrawingAreaControl area = getDrawingArea();
871: ADGraphWindow graphWindow = area.getGraphWindow();
872:
873: TSENode tseNode = (TSENode) getTSNode();
874:
875: if (tseNode != null && graphWindow != null) {
876: IDrawEngine engine = null;
877: if (sendGraphEvents)
878: engine = TypeConversions.getDrawEngine(tseNode);
879:
880: if (m_Node != null && graphWindow != null) {
881: // graphWindow.setRedraw(false);
882:
883: TSConstRect rect = tseNode.getBounds();
884:
885: double originalX = 0;
886: double originalY = 0;
887: switch (handleLocation) {/*
888: case TSHandleLocation.TS_TOP_LEFT_HANDLE :
889: originalX = rect.getLeft();
890: originalY = rect.getTop();
891: break;
892:
893: case TSHandleLocation.TS_TOP_CENTER_HANDLE :
894: originalX = rect.getCenter().getX();
895: originalY = rect.getTop();
896: break;
897:
898: case TSHandleLocation.TS_TOP_RIGHT_HANDLE :
899: originalX = rect.getRight();
900: originalY = rect.getTop();
901: break;
902:
903: case TSHandleLocation.TS_MID_LEFT_HANDLE :
904: originalX = rect.getLeft();
905: originalY = rect.getCenter().getY();
906: break;
907:
908: case TSHandleLocation.TS_MID_RIGHT_HANDLE :
909: originalX = rect.getRight();
910: originalY = rect.getCenter().getY();
911: break;
912:
913: case TSHandleLocation.TS_BOTTOM_LEFT_HANDLE :
914: originalX = rect.getLeft();
915: originalY = rect.getBottom();
916: break;
917:
918: case TSHandleLocation.TS_BOTTOM_CENTER_HANDLE :
919: originalX = rect.getCenter().getX();
920: originalY = rect.getBottom();
921: break;
922:
923: case TSHandleLocation.TS_BOTTOM_RIGHT_HANDLE :
924: originalX = rect.getRight();
925: originalY = rect.getBottom();
926: break;
927:
928: */
929: default:
930: break;
931: }
932:
933: TSResizeControl control = new TSResizeControl();
934: control.init(tseNode, handleLocation);
935:
936: if (engine != null)
937: engine
938: .onGraphEvent(IGraphEventKind.GEK_PRE_RESIZE);
939:
940: control.onStart();
941: control.onDragTo(originalX + dx, originalY + dy);
942: control.onDropAt(originalX + dx, originalY + dy);
943:
944: if (engine != null)
945: engine
946: .onGraphEvent(IGraphEventKind.GEK_POST_RESIZE);
947: }
948: }
949: }
950: }
951:
952: }
|