001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.soa.mapper.basicmapper.canvas.jgo;
021:
022: import java.awt.Point;
023: import java.awt.Rectangle;
024: import java.util.Collection;
025: import java.util.Collections;
026: import java.util.List;
027: import java.util.Vector;
028:
029: import javax.swing.Icon;
030: import com.nwoods.jgo.JGoObject;
031: import org.netbeans.modules.soa.mapper.basicmapper.canvas.jgo.util.AccessibleArea;
032: import org.netbeans.modules.soa.mapper.common.basicmapper.canvas.gtk.ICanvasFieldNode;
033: import org.netbeans.modules.soa.mapper.common.basicmapper.canvas.gtk.ICanvasMethoidNode;
034: import org.netbeans.modules.soa.mapper.common.basicmapper.canvas.gtk.ICanvasView;
035: import org.netbeans.modules.soa.mapper.common.basicmapper.methoid.IMethoidNode;
036: import org.netbeans.modules.soa.mapper.common.gtk.ICanvas;
037: import org.netbeans.modules.soa.mapper.common.gtk.ICanvasAction;
038: import org.netbeans.modules.soa.mapper.common.gtk.ICanvasComponentNode;
039: import org.netbeans.modules.soa.mapper.common.gtk.ICanvasControlNode;
040: import org.netbeans.modules.soa.mapper.common.gtk.ICanvasGroupNode;
041: import org.netbeans.modules.soa.mapper.common.gtk.ICanvasNode;
042: import org.netbeans.modules.soa.mapper.common.gtk.ICanvasNodePopupBox;
043:
044: /**
045: * <p>
046: *
047: * Title: </p> AbstractCanvasMethoidNode<p>
048: *
049: * Description: </p> AbstractCanvasMethoidNode provides the basic implemenation
050: * of a ICanvasMethoidNode providing the basic view of a canvas methoid node.
051: * <p>
052: *
053: * Copyright: Copyright (c) 2002 </p> <p>
054: *
055: * Company: </p>
056: *
057: * @author Un Seng Leong
058: * @created December 4, 2002
059: * @version 1.0
060: */
061: public abstract class AbstractCanvasMethoidNode extends AccessibleArea
062: implements ICanvasMethoidNode {
063:
064: /**
065: * the canvas of this node
066: */
067: private ICanvas mCanvas;
068:
069: /**
070: * the dest nodes storage
071: */
072: private List mDestNodeList;
073:
074: /**
075: * the canvas field node storage
076: */
077: private List mFieldNodeList;
078:
079: /**
080: * the methoid node of this canvas node
081: */
082: protected IMethoidNode mMethoidNode;
083:
084: /**
085: * the group node of this group node
086: */
087: private ICanvasGroupNode mGroup;
088:
089: /**
090: * flag indicates if group node is expanded.
091: */
092: private boolean mIsExpanded;
093:
094: /**
095: * the canvas of this node.
096: */
097: private ICanvasView mMapperCanvas;
098:
099: /**
100: * the name of this node
101: */
102: private String mName;
103:
104: /**
105: * the source node list
106: */
107: private List mSourceNodeList;
108:
109: /**
110: * Creates a new AbstractCanvasMethoidNode object, with specified the
111: * methoid node.
112: *
113: * @param methoidNode the methoid node this canvas node repersents.
114: */
115: public AbstractCanvasMethoidNode(IMethoidNode methoidNode) {
116: super ();
117: mMethoidNode = methoidNode;
118: mFieldNodeList = new Vector();
119: setName(mMethoidNode.getMethoidName());
120: }
121:
122: /**
123: * Return the bounding rectangle of this node.
124: *
125: * @return the bounding rectangle of this node.
126: */
127: public Rectangle getBounding() {
128: return getBoundingRect();
129: }
130:
131: /**
132: * Retrieves the action
133: *
134: * @return always null
135: */
136: public ICanvasAction getAction() {
137: return null;
138: }
139:
140: /**
141: * Return the addable nodes.
142: *
143: * @return always null
144: */
145: public List getAddableNodes() {
146: return null;
147: }
148:
149: /**
150: * Retrieves the aux popup
151: *
152: * @return always null
153: */
154: public ICanvasNodePopupBox getAuxPopup() {
155: return null;
156: }
157:
158: /**
159: * Retrieves the cavnas
160: *
161: * @return The canvas value
162: */
163: public ICanvas getCanvas() {
164: return mMapperCanvas;
165: }
166:
167: /**
168: * Return the compoeent node.
169: *
170: * @return always null
171: */
172: public ICanvasComponentNode getComponentNode() {
173: return null;
174: }
175:
176: /**
177: * Retrieves the container
178: *
179: * @return The container value
180: */
181: public ICanvasGroupNode getContainer() {
182: return mGroup;
183: }
184:
185: /**
186: * Retrieves the control node associated with the canvas node. Return null
187: * is nothing associated.
188: *
189: * @return always null
190: */
191: public ICanvasControlNode getControlNode() {
192: return null;
193: }
194:
195: /**
196: * Retrieves the data object
197: *
198: * @return - underlying data object represented by this node
199: */
200: public Object getDataObject() {
201: return getMethoidNode();
202: }
203:
204: /**
205: * Retrieves a list of nodes that this node is pointing to
206: *
207: * @return The destinationNodes value
208: */
209: public List getDestinationNodes() {
210: return Collections.unmodifiableList(mDestNodeList);
211: }
212:
213: /**
214: * Return a canvas field node that contains the specified connection object,
215: * or null if the field node cannot be found.
216: *
217: * @param pointObj the connection object to be matched.
218: * @return a canvas field node that contains the specified
219: * connection object, or null if the field node cannot be found.
220: */
221: public ICanvasFieldNode getFieldNodeByConnectPointObject(
222: Object pointObj) {
223:
224: synchronized (mFieldNodeList) {
225: int i = mFieldNodeList.size() - 1;
226: Object node = null;
227:
228: for (; i >= 0; i--) {
229: node = mFieldNodeList.get(i);
230:
231: if (node instanceof ICanvasFieldNode
232: && ((ICanvasFieldNode) node)
233: .getConnectPointObject().equals(
234: pointObj)) {
235: return (ICanvasFieldNode) node;
236: }
237: }
238: }
239:
240: return null;
241: }
242:
243: /**
244: * Return a canvas field node that contains the specified point in its
245: * bounding.
246: *
247: * @param point the point to match
248: * @return a canvas field node that contains the specified point in
249: * its bounding.
250: */
251: public ICanvasFieldNode getFieldNodeByPoint(Point point) {
252: synchronized (mFieldNodeList) {
253: int i = mFieldNodeList.size() - 1;
254: Object node = null;
255:
256: for (; i >= 0; i--) {
257: node = mFieldNodeList.get(i);
258:
259: if (node instanceof ICanvasFieldNode
260: && node instanceof JGoObject
261: && ((JGoObject) node).getBoundingRect()
262: .contains(point)) {
263: return (ICanvasFieldNode) node;
264: }
265: }
266: }
267:
268: return null;
269: }
270:
271: /**
272: * Return the methoid node that repersents by this canvas node.
273: *
274: * @return the methoid node that repersents by this canvas node.
275: */
276: public IMethoidNode getMethoidNode() {
277: return mMethoidNode;
278: }
279:
280: /**
281: * Gets the Icon which representing this node
282: *
283: * @return always null
284: */
285: public Icon getIcon() {
286: return null;
287: }
288:
289: /**
290: * Retrun the mapper canvas that displays this node.
291: *
292: * @return the canvas displays this node.
293: */
294: public ICanvasView getMapperCanvas() {
295: return mMapperCanvas;
296: }
297:
298: /**
299: * Retrieves the name of the node
300: *
301: * @return - name
302: */
303: public String getName() {
304: return mName;
305: }
306:
307: /**
308: * Retrieves the location
309: *
310: * @return The nodeLocation value
311: */
312: public Point getNodeLocation() {
313: return this .getLocation();
314: }
315:
316: /**
317: * DOCUMENT ME!
318: *
319: * @return DOCUMENT ME!
320: */
321: public Collection getNodes() {
322: return Collections.unmodifiableCollection(mFieldNodeList);
323: }
324:
325: /**
326: * Retrieves the popup
327: *
328: * @return always null
329: */
330: public ICanvasNodePopupBox getPopup() {
331: return null;
332: }
333:
334: /**
335: * Retrieves a list of nodes that have links connecting TO this node
336: *
337: * @return The sourceNodes value
338: */
339: public List getSourceNodes() {
340: return Collections.unmodifiableList(mSourceNodeList);
341: }
342:
343: /**
344: * Retrieves the underlying ui component
345: *
346: * @return The uIComponent value
347: */
348: public Object getUIComponent() {
349: return this ;
350: }
351:
352: /**
353: * Return true if this node is expended, false otherwise.
354: *
355: * @return true if this node is expended, false otherwise.
356: */
357: public boolean isExpanded() {
358: return mIsExpanded;
359: }
360:
361: /**
362: * Sets the action
363: *
364: * @param action The new action value
365: */
366: public void setAction(ICanvasAction action) {
367: }
368:
369: /**
370: * Set the addable nodes.
371: *
372: * @param nodes the addable node list
373: */
374: public void setAddableNodes(List nodes) {
375: }
376:
377: /**
378: * Sets the aux popup this node is associated with
379: *
380: * @param popup The new auxPopup value
381: */
382: public void setAuxPopup(ICanvasNodePopupBox popup) {
383: }
384:
385: /**
386: * Sets the canvas this node belongs to
387: *
388: * @param canvas The new canvas value
389: */
390: public void setCanvas(ICanvas canvas) {
391: }
392:
393: /**
394: * Sets the component node associated with this canvas node
395: *
396: * @param node The new componentNode value
397: */
398: public void setComponentNode(ICanvasComponentNode node) {
399: }
400:
401: /**
402: * Sets the container this node belongs to
403: *
404: * @param group The new container value
405: */
406: public void setContainer(ICanvasGroupNode group) {
407: mGroup = group;
408: }
409:
410: /**
411: * Sets the control node associated with this canvas node
412: *
413: * @param node The new controlNode value
414: */
415: public void setControlNode(ICanvasControlNode node) {
416: }
417:
418: /**
419: * sets the data object
420: *
421: * @param obj - then object to be represented by this node
422: */
423: public void setDataObject(Object obj) {
424: }
425:
426: /**
427: * Set the group folder object
428: *
429: * @param folder the group folder object
430: */
431: public void setGroupFolder(Object folder) {
432: }
433:
434: /**
435: * Retrun the group folder object
436: *
437: * @return the group folder object
438: */
439: public Object getGroupFolder() {
440: return null;
441: }
442:
443: /**
444: * Sets the icon associated with this node
445: *
446: * @param icon The new icon value
447: */
448: public void setIcon(Icon icon) {
449: }
450:
451: /**
452: * Set the mapper canvas that displays this node.
453: *
454: * @param canvas the canvas displays this node.
455: */
456: public void setMapperCanvas(ICanvasView canvas) {
457: mMapperCanvas = canvas;
458: }
459:
460: /**
461: * Sets the name of the name
462: *
463: * @param name - new name
464: */
465: public void setName(String name) {
466: mName = name;
467: updateLabel(mName);
468: }
469:
470: /**
471: * Sets the location
472: *
473: * @param p - location
474: */
475: public void setNodeLocation(Point p) {
476: this .setLocation(p);
477: }
478:
479: /**
480: * Sets the abstract canvas node popup
481: *
482: * @param popup The new popup value
483: */
484: public void setPopup(ICanvasNodePopupBox popup) {
485: }
486:
487: /**
488: * Adds a new destination node
489: *
490: * @param node The feature to be added to the DestinationNode attribute
491: */
492: public void addDestinationNode(ICanvasNode node) {
493: mDestNodeList.add(node);
494: }
495:
496: /**
497: * add a canvas node to this node.
498: *
499: * @param node the canvas of this node
500: */
501: public void addNode(ICanvasNode node) {
502: synchronized (mFieldNodeList) {
503: mFieldNodeList.add(node);
504: node.setContainer(this );
505: }
506: }
507:
508: /**
509: * Insert a chid node to this container with the specified index
510: *
511: * @param node the node to be added
512: * @param index the index to add the node
513: */
514: public void insertNode(ICanvasNode node, int index) {
515: synchronized (mFieldNodeList) {
516: mFieldNodeList.add(index, node);
517: node.setContainer(this );
518: }
519: }
520:
521: /**
522: * Adds a new source node
523: *
524: * @param node The feature to be added to the SourceNode attribute
525: */
526: public void addSourceNode(ICanvasNode node) {
527: mSourceNodeList.add(node);
528: }
529:
530: /**
531: * Retrun the canvas node that is repersenting the collapse canvas node.
532: *
533: * @return the canvas node that is repersenting the collapse canvas node.
534: */
535: public ICanvasNode collapse() {
536: mIsExpanded = false;
537: return this ;
538: }
539:
540: /**
541: * Retrun the canvas node that is repersenting the expand canvas node.
542: *
543: * @return the canvas node that is repersenting the expand canvas node.
544: */
545: public ICanvasNode expand() {
546: mIsExpanded = true;
547:
548: return this ;
549: }
550:
551: /**
552: * Refresh the node image.
553: *
554: * @param icon the icon of this node.
555: */
556: public void refreshNodeImage(javax.swing.Icon icon) {
557: }
558:
559: /**
560: * Removes a destination node
561: *
562: * @param node Description of the Parameter
563: */
564: public void removeDestinationNode(ICanvasNode node) {
565: mDestNodeList.remove(node);
566: }
567:
568: /**
569: * Remove a canvas node
570: *
571: * @param node the canvas node to be removed
572: */
573: public void removeNode(ICanvasNode node) {
574: mFieldNodeList.remove(node);
575: node.setContainer(null);
576: }
577:
578: /**
579: * Removes a source node
580: *
581: * @param node the source node to be removed
582: */
583: public void removeSourceNode(ICanvasNode node) {
584: mSourceNodeList.remove(node);
585: }
586:
587: /**
588: * update the text label
589: *
590: * @param text update the text label
591: */
592: public void updateLabel(String text) {
593: }
594:
595: /**
596: * Description of the Method
597: *
598: * @param docPoint Description of the Parameter
599: * @return Description of the Return Value
600: */
601: public ICanvasNode findNodeByPoint(Point docPoint) {
602: synchronized (mFieldNodeList) {
603: for (int i = 0; i < mFieldNodeList.size(); i++) {
604: if (((JGoObject) mFieldNodeList.get(i))
605: .isPointInObj(docPoint)) {
606: return (ICanvasNode) mFieldNodeList.get(i);
607: }
608: }
609: }
610: return null;
611: }
612:
613: /**
614: * Return the modifiable node list
615: *
616: * @return the modifiable node list
617: */
618: protected List getModifiableNodeList() {
619: return mFieldNodeList;
620: }
621:
622: public void setTitle(String title) {
623: }
624:
625: public String getTitle() {
626: return mName;
627: }
628: }
|