0001: /*
0002: * The contents of this file are subject to the terms of the Common Development
0003: * and Distribution License (the License). You may not use this file except in
0004: * compliance with the License.
0005: *
0006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
0007: * or http://www.netbeans.org/cddl.txt.
0008: *
0009: * When distributing Covered Code, include this CDDL Header Notice in each file
0010: * and include the License file at http://www.netbeans.org/cddl.txt.
0011: * If applicable, add the following below the CDDL Header, with the fields
0012: * enclosed by brackets [] replaced by your own identifying information:
0013: * "Portions Copyrighted [year] [name of copyright owner]"
0014: *
0015: * The Original Software is NetBeans. The Initial Developer of the Original
0016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0017: * Microsystems, Inc. All Rights Reserved.
0018: */
0019:
0020: package org.netbeans.modules.soa.mapper.basicmapper.canvas.jgo;
0021:
0022: import java.awt.Color;
0023: import java.awt.Cursor;
0024: import java.awt.Dimension;
0025: import java.awt.Point;
0026: import java.awt.dnd.DragGestureEvent;
0027: import java.awt.dnd.DragGestureListener;
0028: import java.awt.dnd.DragSourceDragEvent;
0029: import java.awt.dnd.DragSourceDropEvent;
0030: import java.awt.dnd.DragSourceEvent;
0031: import java.awt.dnd.DragSourceListener;
0032: import java.awt.dnd.DropTargetDragEvent;
0033: import java.awt.dnd.DropTargetDropEvent;
0034: import java.awt.dnd.DropTargetEvent;
0035: import java.awt.dnd.DropTargetListener;
0036:
0037: import javax.swing.Icon;
0038:
0039: import com.nwoods.jgo.JGoBrush;
0040: import com.nwoods.jgo.JGoLayer;
0041: import com.nwoods.jgo.JGoLink;
0042: import com.nwoods.jgo.JGoListPosition;
0043: import com.nwoods.jgo.JGoObject;
0044: import com.nwoods.jgo.JGoPen;
0045: import com.nwoods.jgo.JGoPort;
0046: import com.nwoods.jgo.JGoView;
0047: import java.awt.AWTKeyStroke;
0048: import java.awt.KeyboardFocusManager;
0049: import java.awt.Rectangle;
0050: import java.awt.event.ActionEvent;
0051: import java.awt.event.KeyEvent;
0052: import java.util.Collection;
0053: import java.util.HashSet;
0054: import java.util.List;
0055: import java.util.Set;
0056: import javax.swing.AbstractAction;
0057: import javax.swing.KeyStroke;
0058: import org.netbeans.modules.soa.mapper.common.basicmapper.canvas.IMapperCanvasView;
0059: import org.netbeans.modules.soa.mapper.common.basicmapper.canvas.gtk.ICanvasMapperLink;
0060: import org.netbeans.modules.soa.mapper.common.basicmapper.canvas.gtk.ICanvasView;
0061: import org.netbeans.modules.soa.mapper.common.basicmapper.dnd.IBasicDragController;
0062: import org.netbeans.modules.soa.mapper.common.basicmapper.dnd.IDnDHandler;
0063: import org.netbeans.modules.soa.mapper.common.gtk.CanvasModelUpdateEvent;
0064: import org.netbeans.modules.soa.mapper.common.gtk.DefaultCanvasPalette;
0065: import org.netbeans.modules.soa.mapper.common.gtk.ICanvasController;
0066: import org.netbeans.modules.soa.mapper.common.gtk.ICanvasGroupNode;
0067: import org.netbeans.modules.soa.mapper.common.gtk.ICanvasLink;
0068: import org.netbeans.modules.soa.mapper.common.gtk.ICanvasModel;
0069: import org.netbeans.modules.soa.mapper.common.gtk.ICanvasNode;
0070:
0071: /**
0072: * <p>
0073: *
0074: * Title: </p> AbstractCanvasView<p>
0075: *
0076: * Description: </p> AbstractCanvasView provides an implementation of
0077: * ICanvasView back by an JGoView. Since JGoView also is the controller for
0078: * JGoObjects. This class provides a defautl DnDHanlder that warps all the
0079: * JGoView DnD methods for the IBasicViewController. <p>
0080: *
0081: * @author Un Seng Leong
0082: * @created December 31, 2002
0083: */
0084: public abstract class AbstractCanvasView extends JGoView implements
0085: ICanvasView, IDnDHandler {
0086:
0087: /**
0088: * The location of the drag starts. This point can locate the drag object.
0089: */
0090: private Point mDnDDragOrginPoint;
0091:
0092: /**
0093: * the node border color
0094: */
0095: private Color mNodeBorderColor = Color.lightGray;
0096:
0097: /**
0098: * the mapper view contains this canvas
0099: */
0100: private IMapperCanvasView mMapperView;
0101:
0102: /**
0103: * Zoom factor controls the zoom of this view. Does not user in this
0104: * application.
0105: */
0106: private double mZoomFactor;
0107:
0108: /**
0109: * the DragGestureListener for default IDnDHandler
0110: */
0111: private DragGestureListener mDragGestureListener;
0112:
0113: /**
0114: * the DragSourceListener for default IDnDHandler
0115: */
0116: private DragSourceListener mDragSourceListener;
0117:
0118: /**
0119: * the DropTargetListener for default IDnDHandler
0120: */
0121: private DropTargetListener mDropTargetListener;
0122:
0123: /**
0124: * the dnd handler to use (current dnd handler)
0125: */
0126: private IDnDHandler mHandler;
0127:
0128: /**
0129: * The controller of this canvas. This view will forward most of the
0130: * controller handle to this controller.
0131: */
0132: private ICanvasController mController;
0133:
0134: // cuurent object under mouse
0135: private static JGoObject currentObj = null;
0136:
0137: /**
0138: * Whether an entire chain of connected links/node elements will
0139: * appear highlighted upon selection of any element in the chain.
0140: */
0141: private boolean mIsPathHighlightingEnabled;
0142:
0143: /**
0144: * Constructor an AbstractCanvasView with no visiual appearing.
0145: *
0146: * @param mapperView Description of the Parameter
0147: */
0148: public AbstractCanvasView(IMapperCanvasView mapperView) {
0149: mMapperView = mapperView;
0150: mDragGestureListener = new DragGestureListenerWapper();
0151: mDragSourceListener = new DragSourceListenerWapper();
0152: mDropTargetListener = new DropTargetListenerWapper();
0153: setDnDHandler(getDefaultDnDHandler());
0154: mIsPathHighlightingEnabled = false;
0155: configureFocusTravers();
0156: }
0157:
0158: /**
0159: * Return the canvas mapper view that contains this canvas.
0160: *
0161: * @return the canvas mapper view that contains this canvas.
0162: */
0163: public IMapperCanvasView getParentView() {
0164: return mMapperView;
0165: }
0166:
0167: /**
0168: * Gets the defaultDnDHandler attribute of the AbstractCanvasView object
0169: *
0170: * @return The defaultDnDHandler value
0171: */
0172: public IDnDHandler getDefaultDnDHandler() {
0173: return this ;
0174: }
0175:
0176: /**
0177: * Sets the dnDHanlder attribute of the AbstractCanvasView object
0178: *
0179: * @param handler The new dnDHanlder value
0180: */
0181: public void setDnDHandler(IDnDHandler handler) {
0182: mHandler = handler;
0183: }
0184:
0185: /**
0186: * Gets the dnDHanlder attribute of the AbstractCanvasView object
0187: *
0188: * @return The dnDHanlder value
0189: */
0190: public IDnDHandler getDnDHanlder() {
0191: return mHandler;
0192: }
0193:
0194: /**
0195: * Close this handler and release all the system resource.
0196: */
0197: public void releaseHandler() {
0198: // unless is not using the JGo default DnD Handler. Otherwise,
0199: // JGo should release its own DnD objects.
0200: if (mHandler != this ) {
0201: mHandler.releaseHandler();
0202: }
0203: }
0204:
0205: /**
0206: * Return the canvas controller of this canvas.
0207: *
0208: * @return the canvas controller of this canvas.
0209: */
0210: public ICanvasController getCanvasController() {
0211: return mController;
0212: }
0213:
0214: /**
0215: * Set the canvas controller to this view receive events.
0216: *
0217: * @param controller the canvas controller.
0218: */
0219: public void setCanvasController(ICanvasController controller) {
0220: mController = controller;
0221: }
0222:
0223: /**
0224: * Return the default canvas palette of this canvas. This method is not
0225: * applicable to this canvas. It always returns null.
0226: *
0227: * @return always null.
0228: */
0229: public DefaultCanvasPalette getCanvasPalette() {
0230: return null;
0231: }
0232:
0233: /**
0234: * Return the model of the canvas. This method is not applicable to this
0235: * canvas. It always return null.
0236: *
0237: * @return always null
0238: */
0239: public ICanvasModel getModel() {
0240: return null;
0241: }
0242:
0243: /**
0244: * Get the canvas node border color.
0245: *
0246: * @return the canvas node border color.
0247: */
0248: public Color getNodeBorderColor() {
0249: return mNodeBorderColor;
0250: }
0251:
0252: /**
0253: * Gets the dnDDragOrginPoint attribute of the AbstractCanvasView object
0254: *
0255: * @return The dnDDragOrginPoint value
0256: */
0257: public Point getDnDDragOrginPoint() {
0258: return mDnDDragOrginPoint;
0259: }
0260:
0261: /**
0262: * Return true if link label is visible, false otherwise. This method is not
0263: * applicable to this canvas. It always return false.
0264: *
0265: * @return false
0266: */
0267: public boolean isLinkLabelVisible() {
0268: return false;
0269: }
0270:
0271: /**
0272: * Retrieves whether this canvas pass mouse event to the controller. This
0273: * method is not applicable to this Cavnas. It always returns true.
0274: *
0275: * @return true
0276: */
0277: public boolean isPassMouseEventToController() {
0278: return true;
0279: }
0280:
0281: /**
0282: * Set the defautl canvas palette of this canvas. This method is not
0283: * applicable to this canvas. It returns immediately.
0284: *
0285: * @param palette the palette of this canvas.
0286: */
0287: public void setCanvasPalette(DefaultCanvasPalette palette) {
0288: }
0289:
0290: /**
0291: * Sets the link's label visiblity to the given value. This method is not
0292: * applicable to this canvas. It returns immediately.
0293: *
0294: * @param val the value
0295: */
0296: public void setLinkLabelVisible(boolean val) {
0297: }
0298:
0299: /**
0300: * This method is not applicable to this view. It returns immediately.
0301: *
0302: * @param model the model
0303: */
0304: public void setModel(ICanvasModel model) {
0305: }
0306:
0307: /**
0308: * Set the canvas node border color.
0309: *
0310: * @param color the canvas node border color.
0311: */
0312: public void setNodeBorderColor(Color color) {
0313: mNodeBorderColor = color;
0314: }
0315:
0316: /**
0317: * Sets whether to pass mouse event to controller. This method is not
0318: * applicable to this Cavnas. It returns immediately.
0319: *
0320: * @param val the value
0321: */
0322: public void setPassMouseEventToController(boolean val) {
0323: }
0324:
0325: /**
0326: * This method is not applicable to this view. It always return null.
0327: *
0328: * @param location the loc of the node.
0329: * @param size the size of the node.
0330: * @param icon the icon of the node.
0331: * @param label the label of the node.
0332: * @param labelIcon the icon of the label
0333: * @return null
0334: */
0335: public ICanvasGroupNode createCanvasGroupNode(Point location,
0336: Dimension size, Icon icon, String label, Icon labelIcon) {
0337: return null;
0338: }
0339:
0340: /**
0341: * This method is not applicable to this view. It always return null.
0342: *
0343: * @param src source node
0344: * @param dest dest node
0345: * @return always null
0346: */
0347: public ICanvasLink createCanvasLink(ICanvasNode src,
0348: ICanvasNode dest) {
0349: return null;
0350: }
0351:
0352: /**
0353: * This method is not applicable to this view. It always return null.
0354: *
0355: * @param src source node
0356: * @param dest dest node
0357: * @param isComponentNode is component node
0358: * @param isWithBinding is with binding
0359: * @return always null
0360: */
0361: public ICanvasLink createCanvasLink(ICanvasNode src,
0362: ICanvasNode dest, boolean isComponentNode,
0363: boolean isWithBinding) {
0364: return null;
0365: }
0366:
0367: /**
0368: * Create a Canvas node. This method is not applicable to this view. It
0369: * always return null.
0370: *
0371: * @param location the loc of the node.
0372: * @param size the size of the node
0373: * @param label the label of the node.
0374: * @return always null
0375: */
0376: public ICanvasNode createCanvasNode(Point location, Dimension size,
0377: String label) {
0378: return null;
0379: }
0380:
0381: /**
0382: * This method is not applicable to this view. It always return null.
0383: *
0384: * @param location the loc of the node.
0385: * @param size the size of the node.
0386: * @param icon the icon of the node.
0387: * @param label the label of the node.
0388: * @return always null
0389: */
0390: public ICanvasNode createCanvasNode(Point location, Dimension size,
0391: Icon icon, String label) {
0392: return null;
0393: }
0394:
0395: /**
0396: * Listens on the model event, execute when group node is loaded from the
0397: * model. This method is not applicable to this canvas. It returns
0398: * immediately.
0399: *
0400: * @param event CanvasModelUpdateEvent.
0401: */
0402: public void groupNodeLoaded(CanvasModelUpdateEvent event) {
0403: }
0404:
0405: /**
0406: * Listens on the model event, execute when link is loaded from the model.
0407: * This method is not applicable to this canvas. It returns immediately.
0408: *
0409: * @param event the CanvasModelUpdateEvent event
0410: */
0411: public void linkLoaded(CanvasModelUpdateEvent event) {
0412: }
0413:
0414: /**
0415: * Listens on the model event, execute when node is loaded from the model.
0416: * This method is not applicable to this canvas. It returns immediately.
0417: *
0418: * @param event CanvasModelUpdateEvent
0419: */
0420: public void nodeLoaded(CanvasModelUpdateEvent event) {
0421: }
0422:
0423: /**
0424: * Finds and updates parent node, this method is not applicable to this implemenation.
0425: * This method returns immediately.
0426: *
0427: * @param node - the node whose parent node will be updated
0428: * @param nodes -- the list of potentional parents node to be set
0429: */
0430: public void updatesParentNode(Object node, Object nodes[]) {
0431: }
0432:
0433: /**
0434: * Toggle to another link mode. This method is not applicable to this
0435: * canvas. It returns immediately.
0436: *
0437: * @param val the value
0438: */
0439: public void toggleLinkMode(boolean val) {
0440: }
0441:
0442: /**
0443: * Return the zoom factor of ths view.
0444: *
0445: * @return the zoom factor of ths view.
0446: */
0447: public double getZoomFactor() {
0448: return mZoomFactor;
0449: }
0450:
0451: /**
0452: * Set the zoon factor of this view.
0453: *
0454: * @param factor the zoom factor of this view
0455: */
0456: public void setZoomFactor(double factor) {
0457: mZoomFactor = factor;
0458: }
0459:
0460: /**
0461: * Gets the dragGestureListener attribute of the IDnDHandler object
0462: *
0463: * @return The dragGestureListener value
0464: */
0465: public DragGestureListener getDragGestureListener() {
0466: return mDragGestureListener;
0467: }
0468:
0469: /**
0470: * Gets the dragSourceListener attribute of the IDnDHandler object
0471: *
0472: * @return The dragSourceListener value
0473: */
0474: public DragSourceListener getDragSourceListener() {
0475: return mDragSourceListener;
0476: }
0477:
0478: /**
0479: * Gets the dropTargetListener attribute of the IDnDHandler object
0480: *
0481: * @return The dropTargetListener value
0482: */
0483: public DropTargetListener getDropTargetListener() {
0484: return mDropTargetListener;
0485: }
0486:
0487: /**
0488: * Return an int representing the type of action used in this Drag
0489: * operation.
0490: *
0491: * @return an int representing the type of action used in this Drag
0492: * operation. See <code>java.awt.dnd.DnDConstants</code> for a list of
0493: * available drag actions.
0494: */
0495: public int getDragAction() {
0496: return java.awt.dnd.DnDConstants.ACTION_COPY_OR_MOVE;
0497: }
0498:
0499: /**
0500: * Return the cursor to use when start draging on the component of this
0501: * handler.
0502: *
0503: * @return the cursor to use when start draging. See <code>java.awt.dnd.DragSource</code>
0504: * for a list of avaiable drag cursor.
0505: */
0506: public Cursor getDragCursor() {
0507: return java.awt.dnd.DragSource.DefaultCopyDrop;
0508: }
0509:
0510: /**
0511: * Overrides java.awt.dnd.DragGestureListener.dragGestureRecognized, this
0512: * method delegates to IDnDHandler.getDragGestureListener.dragGestureRecognized.
0513: *
0514: * @param e the DragGestureEvent
0515: */
0516: public void dragGestureRecognized(DragGestureEvent e) {
0517: if (mHandler != null
0518: && mHandler.getDragGestureListener() != null) {
0519: mHandler.getDragGestureListener().dragGestureRecognized(e);
0520: getCanvasController().handleDragGestureRecognized(e);
0521: }
0522: }
0523:
0524: /**
0525: * Overrides java.awt.dnd.DropTargetListener.dragEnter, this method
0526: * delegates to IDnDHandler.getDropTargetListener.dragEnter.
0527: *
0528: * @param dtde the DropTargetDragEvent
0529: */
0530: public void dragEnter(DropTargetDragEvent dtde) {
0531: if (mHandler != null
0532: && mHandler.getDropTargetListener() != null) {
0533: mHandler.getDropTargetListener().dragEnter(dtde);
0534: getCanvasController().handleDragEnter(dtde);
0535: }
0536: }
0537:
0538: /**
0539: * Overrides java.awt.dnd.DropTargetListener.dragExit, this method delegates
0540: * to IDnDHandler.getDropTargetListener.dragExit.
0541: *
0542: * @param dte the DropTargetEvent
0543: */
0544: public void dragExit(DropTargetEvent dte) {
0545: if (mHandler != null
0546: && mHandler.getDropTargetListener() != null) {
0547: mHandler.getDropTargetListener().dragExit(dte);
0548: getCanvasController().handleDragExit(dte);
0549: }
0550: }
0551:
0552: /**
0553: * Overrides java.awt.dnd.DropTargetListener.dragOver, this method delegates
0554: * to IDnDHandler.getDropTargetListener.dragOver.
0555: *
0556: * @param dtde the DropTargetDragEvent
0557: */
0558: public void dragOver(DropTargetDragEvent dtde) {
0559: if (mHandler != null
0560: && mHandler.getDropTargetListener() != null) {
0561: mHandler.getDropTargetListener().dragOver(dtde);
0562: getCanvasController().handleDragOver(dtde);
0563: }
0564: }
0565:
0566: /**
0567: * Overrides java.awt.dnd.DropTargetListener.drop, this method delegates to
0568: * IDnDHandler.getDropTargetListener.drop.
0569: *
0570: * @param event the DropTargetDropEvent
0571: */
0572: public void drop(DropTargetDropEvent event) {
0573: if (mHandler != null
0574: && mHandler.getDropTargetListener() != null) {
0575: mHandler.getDropTargetListener().drop(event);
0576: }
0577: }
0578:
0579: /**
0580: * Overrides java.awt.dnd.DropTargetListener.dropActionChanged, this method
0581: * delegates to IDnDHandler.getDropTargetListener.dropActionChanged.
0582: *
0583: * @param dtde the DropTargetDragEvent
0584: */
0585: public void dropActionChanged(DropTargetDragEvent dtde) {
0586: if (mHandler != null
0587: && mHandler.getDropTargetListener() != null) {
0588: mHandler.getDropTargetListener().dropActionChanged(dtde);
0589: }
0590: }
0591:
0592: /**
0593: * Overrides java.awt.dnd.DragSourceListener.dragDropEnd, this method
0594: * delegates to IDnDHandler.getDragSourceListener.dragDropEnd.
0595: *
0596: * @param dsde Description of the Parameter
0597: */
0598: public void dragDropEnd(DragSourceDropEvent dsde) {
0599: if (mHandler != null
0600: && mHandler.getDragSourceListener() != null) {
0601: mHandler.getDragSourceListener().dragDropEnd(dsde);
0602: }
0603: }
0604:
0605: /**
0606: * Overrides java.awt.dnd.DragSourceListener.dragEnter, this method
0607: * delegates to IDnDHandler.getDragSourceListener.dragEnter.
0608: *
0609: * @param dsde Description of the Parameter
0610: */
0611: public void dragEnter(DragSourceDragEvent dsde) {
0612: if (mHandler != null
0613: && mHandler.getDragSourceListener() != null) {
0614: mHandler.getDragSourceListener().dragEnter(dsde);
0615: }
0616: }
0617:
0618: /**
0619: * Overrides java.awt.dnd.DragSourceListener.dragExit, this method delegates
0620: * to IDnDHandler.getDragSourceListener.dragExit.
0621: *
0622: * @param dse Description of the Parameter
0623: */
0624: public void dragExit(DragSourceEvent dse) {
0625: if (mHandler != null
0626: && mHandler.getDragSourceListener() != null) {
0627: mHandler.getDragSourceListener().dragExit(dse);
0628: }
0629: }
0630:
0631: /**
0632: * Overrides java.awt.dnd.DragSourceListener.dragOver, this method delegates
0633: * to IDnDHandler.getDragSourceListener.dragOver.
0634: *
0635: * @param dsde Description of the Parameter
0636: */
0637: public void dragOver(DragSourceDragEvent dsde) {
0638: if (mHandler != null
0639: && mHandler.getDragSourceListener() != null) {
0640: mHandler.getDragSourceListener().dragOver(dsde);
0641: }
0642: }
0643:
0644: /**
0645: * Overrides java.awt.dnd.DragSourceListener.dropActionChanged, this method
0646: * delegates to IDnDHandler.getDragSourceListener.dropActionChanged.
0647: *
0648: * @param dsde Description of the Parameter
0649: */
0650: public void dropActionChanged(DragSourceDragEvent dsde) {
0651: if (mHandler != null
0652: && mHandler.getDragSourceListener() != null) {
0653: mHandler.getDragSourceListener().dropActionChanged(dsde);
0654: }
0655: }
0656:
0657: /**
0658: * This method delegates to super.dragEnter.
0659: *
0660: * @param dtde the DropTargetDragEvent
0661: */
0662: private void super DragEnter(DropTargetDragEvent dtde) {
0663: super .dragEnter(dtde);
0664: }
0665:
0666: /**
0667: * This method delegates to super.dragExit.
0668: *
0669: * @param dte the DropTargetEvent
0670: */
0671: private void super DragExit(DropTargetEvent dte) {
0672: super .dragExit(dte);
0673: }
0674:
0675: /**
0676: * This method delegates to super.dragGestureRecognized.
0677: *
0678: * @param e the DragGestureEvent
0679: */
0680: private void super DragGestureRecognized(DragGestureEvent e) {
0681: super .dragGestureRecognized(e);
0682: }
0683:
0684: /**
0685: * This method delegates to super.dragOver.
0686: *
0687: * @param dtde the DropTargetDragEvent
0688: */
0689: private void super DragOver(DropTargetDragEvent dtde) {
0690: super .dragOver(dtde);
0691: }
0692:
0693: /**
0694: * This method delegates to super.drop.
0695: *
0696: * @param event the DropTargetDropEvent
0697: */
0698: private void super Drop(DropTargetDropEvent event) {
0699: super .drop(event);
0700: }
0701:
0702: /**
0703: * This method delegates to super.dropActionChanged.
0704: *
0705: * @param dtde the DropTargetDragEvent
0706: */
0707: private void super DropActionChanged(DropTargetDragEvent dtde) {
0708: super .dropActionChanged(dtde);
0709: }
0710:
0711: /**
0712: * This method delegates to super.dragDropEnd.
0713: *
0714: * @param dsde Description of the Parameter
0715: */
0716: private void super DragDropEnd(DragSourceDropEvent dsde) {
0717: super .dragDropEnd(dsde);
0718: }
0719:
0720: /**
0721: * This method delegates to super.dragEnter.
0722: *
0723: * @param dsde Description of the Parameter
0724: */
0725: private void super DragEnter(DragSourceDragEvent dsde) {
0726: super .dragEnter(dsde);
0727: }
0728:
0729: /**
0730: * This method delegates to super.dragExit.
0731: *
0732: * @param dse Description of the Parameter
0733: */
0734: private void super DragExit(DragSourceEvent dse) {
0735: super .dragExit(dse);
0736: }
0737:
0738: /**
0739: * This method delegates to super.dragOver.
0740: *
0741: * @param dsde Description of the Parameter
0742: */
0743: private void super DragOver(DragSourceDragEvent dsde) {
0744: super .dragOver(dsde);
0745: }
0746:
0747: /**
0748: * This method delegates to super.dropActionChanged.
0749: *
0750: * @param dsde Description of the Parameter
0751: */
0752: private void super DropActionChanged(DragSourceDragEvent dsde) {
0753: super .dropActionChanged(dsde);
0754: }
0755:
0756: /**
0757: * DragGestureListener of default IDnDHanlder. Delagates all coorsponding
0758: * methods to default JGoView methods.
0759: *
0760: * @author sleong
0761: * @created December 31, 2002
0762: */
0763: private class DragGestureListenerWapper implements
0764: DragGestureListener {
0765: /**
0766: * Overrides java.awt.dnd.DragGestureListener.dragGestureRecognized,
0767: * this method delegates to superDragGestureRecognized. It also set the
0768: * drag orgin point for the drag event to provide a way to search for
0769: * dragged object in JGoView.
0770: *
0771: * @param e the DragGestureEvent
0772: */
0773: public void dragGestureRecognized(DragGestureEvent e) {
0774: if (!AbstractCanvasView.this .isEnabled()
0775: || !AbstractCanvasView.this .isVisible()) {
0776: return;
0777: }
0778:
0779: mDnDDragOrginPoint = new Point(e.getDragOrigin());
0780: super DragGestureRecognized(e);
0781: }
0782: }
0783:
0784: /**
0785: * DragSourceListener of default IDnDHanlder. Delagates all coorsponding
0786: * methods to default JGoView methods.
0787: *
0788: * @author sleong
0789: * @created December 31, 2002
0790: */
0791: private class DragSourceListenerWapper implements
0792: DragSourceListener {
0793: /**
0794: * Overrides java.awt.dnd.DragSourceListener.dragDropEnd, this method
0795: * delegates to getCanvasController().handleDragDropEnd(DragSourceDropEvent).
0796: * If controller is null, superDragDropEnd is called.
0797: *
0798: * @param dsde Description of the Parameter
0799: */
0800: public void dragDropEnd(DragSourceDropEvent dsde) {
0801: if (getCanvasController() != null) {
0802: getCanvasController().handleDragDropEnd(dsde);
0803: } else {
0804: super DragDropEnd(dsde);
0805: }
0806: }
0807:
0808: /**
0809: * Overrides java.awt.dnd.DragSourceListener.dragEnter, this method
0810: * delegates to superDragEnter.
0811: *
0812: * @param dsde Description of the Parameter
0813: */
0814: public void dragEnter(DragSourceDragEvent dsde) {
0815: super DragEnter(dsde);
0816: }
0817:
0818: /**
0819: * Overrides java.awt.dnd.DragSourceListener.dragExit, this method
0820: * delegates to superDragExit.
0821: *
0822: * @param dse Description of the Parameter
0823: */
0824: public void dragExit(DragSourceEvent dse) {
0825: super DragExit(dse);
0826: }
0827:
0828: /**
0829: * Overrides java.awt.dnd.DragSourceListener.dragOver, this method
0830: * delegates to superDragOver.
0831: *
0832: * @param dsde Description of the Parameter
0833: */
0834: public void dragOver(DragSourceDragEvent dsde) {
0835: super DragOver(dsde);
0836: }
0837:
0838: /**
0839: * Overrides java.awt.dnd.DragSourceListener.dropActionChanged, this
0840: * method delegates to superDropActionChanged.
0841: *
0842: * @param dsde Description of the Parameter
0843: */
0844: public void dropActionChanged(DragSourceDragEvent dsde) {
0845: super DropActionChanged(dsde);
0846: }
0847: }
0848:
0849: /**
0850: * DropTargetListener of default IDnDHanlder. Delagates all coorsponding
0851: * methods to default JGoView methods.
0852: *
0853: * @author sleong
0854: * @created December 31, 2002
0855: */
0856: private class DropTargetListenerWapper implements
0857: DropTargetListener {
0858:
0859: /**
0860: * Overrides java.awt.dnd.DropTargetListener.dragEnter, this method
0861: * delegates to superDragEnter.
0862: *
0863: * @param dtde the DropTargetDragEvent
0864: */
0865: public void dragEnter(DropTargetDragEvent dtde) {
0866: super DragEnter(dtde);
0867: }
0868:
0869: /**
0870: * Overrides java.awt.dnd.DropTargetListener.dragExit, this method
0871: * delegates to superDragExit.
0872: *
0873: * @param dte the DropTargetEvent
0874: */
0875: public void dragExit(DropTargetEvent dte) {
0876: super DragExit(dte);
0877: }
0878:
0879: /**
0880: * Overrides java.awt.dnd.DropTargetListener.dragOver, this method is
0881: * empty because the super method always rejects drag.
0882: *
0883: * @param dtde the DropTargetDragEvent
0884: */
0885: public void dragOver(DropTargetDragEvent dtde) {
0886: }
0887:
0888: /**
0889: * Handles drop action - actual work is delegated to the controller
0890: *
0891: * @param event Description of the Parameter
0892: */
0893:
0894: /**
0895: * Overrides java.awt.dnd.DropTargetListener.drop, this method delegates
0896: * to getCanvasController.handleDrop(DropTargetDropEvent).
0897: *
0898: * @param event the DropTargetDropEvent
0899: */
0900: public void drop(DropTargetDropEvent event) {
0901: if (getCanvasController() != null) {
0902: if (getCanvasController().handleDrop(event)) {
0903: event.dropComplete(true);
0904:
0905: // Canvas will have focus so that the mouse over Cursor icons
0906: // will function
0907: AbstractCanvasView.this .grabFocus();
0908: } else {
0909: event.dropComplete(false);
0910: }
0911: }
0912: }
0913:
0914: /**
0915: * Overrides java.awt.dnd.DropTargetListener.dropActionChanged, this
0916: * method delegates to superDropActionChanged.
0917: *
0918: * @param dtde the DropTargetDragEvent
0919: */
0920: public void dropActionChanged(DropTargetDragEvent dtde) {
0921: super DropActionChanged(dtde);
0922: }
0923: }
0924:
0925: /**
0926: * @see com.nwoods.jgo.JGoView#isDropFlavorAcceptable
0927: */
0928: public boolean isDropFlavorAcceptable(DropTargetDragEvent e) {
0929: return true;
0930: }
0931:
0932: public void addRawLink(ICanvasLink link) {
0933: addObjectAtTail((JGoObject) link);
0934: }
0935:
0936: public void removeRawLink(ICanvasLink link) {
0937: removeObject((JGoObject) link);
0938: }
0939:
0940: protected JGoPort pickPort(Point dc) {
0941: return pickNearestPort(dc);
0942: }
0943:
0944: // Delegate to our custom port picking method.
0945: public JGoPort pickNearestPort(Point dc) {
0946: JGoObject obj = pickAnyNearestPort(dc);
0947: if (obj instanceof JGoPort) {
0948: return (JGoPort) obj;
0949: }
0950: return null;
0951: }
0952:
0953: private JGoPort pickAnyNearestPort(Point point) {
0954: JGoPort bestPort = null;
0955: double bestDistance = getPortGravity();
0956: bestDistance *= bestDistance;
0957: for (JGoLayer jgolayer = getFirstLayer(); jgolayer != null; jgolayer = getNextLayer(jgolayer)) {
0958: if (jgolayer.isVisible()) {
0959: JGoListPosition jgolistposition = jgolayer
0960: .getFirstObjectPos();
0961: Point linkPoint = new Point(0, 0);
0962: while (jgolistposition != null) {
0963: JGoObject jgoobject = jgolayer
0964: .getObjectAtPos(jgolistposition);
0965: jgolistposition = jgolayer
0966: .getNextObjectPos(jgolistposition);
0967: if (jgoobject instanceof JGoPort) {
0968: JGoPort iterPort = (JGoPort) jgoobject;
0969: if (iterPort.isPointInObj(point)) {
0970: if (iterPort.getParent() instanceof ICanvasGroupNode) {
0971: ICanvasGroupNode groupNode = (ICanvasGroupNode) iterPort
0972: .getParent();
0973: if (groupNode.isExpanded()) {
0974: // If our ports are shown (expanded), then
0975: // if the point is directly on a port
0976: // it's obviously the best one.
0977: return iterPort;
0978: }
0979: }
0980: } else {
0981: int position = JGoObject.Center;
0982: if (iterPort instanceof BasicCanvasPort) {
0983: // BasicCanvasPorts span the entire width of
0984: // the field node, so the gravity should
0985: // react to the left or right sides of
0986: // the ports (i.e. not the center).
0987: position = ((BasicCanvasPort) iterPort)
0988: .getLinkPosition();
0989: }
0990: linkPoint = iterPort.getLinkPoint(position,
0991: linkPoint);
0992: }
0993: double dx = point.x - linkPoint.x;
0994: double dy = point.y - linkPoint.y;
0995: double distance = dx * dx + dy * dy;
0996: if (distance <= bestDistance) {
0997: // the port with the smallest distance wins
0998: bestPort = iterPort;
0999: bestDistance = distance;
1000: }
1001: }
1002: }
1003: }
1004: }
1005:
1006: return bestPort;
1007: }
1008:
1009: public JGoLink createTemporaryLinkForNewLink(JGoPort from,
1010: JGoPort to) {
1011: BasicCanvasSimpleLink link = new BasicCanvasSimpleLink(from, to);
1012: link.setPen(JGoPen
1013: .makeStockPen(ICanvasMapperLink.DEFAULT_LINK_COLOR));
1014: link.setBrush(JGoBrush
1015: .makeStockBrush(ICanvasMapperLink.DEFAULT_LINK_COLOR));
1016:
1017: link.setArrowHeads(from.isValidDestination()
1018: && !from.isValidSource(), to.isValidDestination()
1019: && !to.isValidSource());
1020: AbstractCanvasLink.initializeArrowHeads(link);
1021: IBasicDragController dragController = ((BasicCanvasController) mController)
1022: .getMapperDragController();
1023: dragController.setDragLink(link);
1024: return link;
1025: }
1026:
1027: /**
1028: * Whether an entire chain of connected links/node elements will
1029: * appear highlighted upon selection of any element in the chain.
1030: */
1031: public boolean isPathHighlightingEnabled() {
1032: return mIsPathHighlightingEnabled;
1033: }
1034:
1035: /**
1036: * Sets whether chains of linked nodes are highlighted.
1037:
1038: */
1039: public void setPathHighlightingEnabled(boolean isEnabled) {
1040: mIsPathHighlightingEnabled = isEnabled;
1041: }
1042:
1043: public boolean doMouseMove(int modifiers, Point dc, Point vc) {
1044: boolean result = super .doMouseMove(modifiers, dc, vc);
1045:
1046: //handle mouse event and delegate to child object under mouse point
1047: if (getState() != MouseStateCreateLinkFrom
1048: && getState() != MouseStateCreateLink
1049: && getState() != MouseStateDragBoxSelection)
1050: doMouseHandling(modifiers, dc, vc);
1051:
1052: return result;
1053: }
1054:
1055: private boolean doMouseHandling(int modifiers, Point dc, Point vc) {
1056: boolean returnStatus = false;
1057:
1058: // if we're over a port, start drawing a new link
1059: JGoObject obj = pickPort(dc);
1060:
1061: if (obj == null)
1062: obj = pickDocObject(dc, false);
1063:
1064: while (obj != null) {
1065: if (obj instanceof BasicCanvasPort
1066: && ((BasicCanvasPort) obj).doMouseEntered(
1067: modifiers, dc, vc, this )) {
1068: returnStatus = true;
1069: break;
1070: } else {
1071: obj = obj.getParent();
1072: }
1073: }
1074:
1075: //fire mouseExisted event
1076: if (currentObj instanceof BasicCanvasPort && currentObj != obj) {
1077: ((BasicCanvasPort) currentObj).doMouseExited(modifiers, dc,
1078: vc, this );
1079: }
1080: //this is the curent obj where mouse has entered
1081: currentObj = obj;
1082:
1083: return returnStatus;
1084: }
1085:
1086: private void configureFocusTravers() {
1087: KeyStroke tabForward = KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
1088: 0);
1089: KeyStroke tabBackward = KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
1090: KeyEvent.SHIFT_DOWN_MASK);
1091:
1092: Set<AWTKeyStroke> oldForwardTK = getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
1093: Set<AWTKeyStroke> oldBackwardTK = getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
1094:
1095: Set<AWTKeyStroke> newForwardTK = new HashSet<AWTKeyStroke>(
1096: oldForwardTK);
1097: Set<AWTKeyStroke> newBackwardTK = new HashSet<AWTKeyStroke>(
1098: oldBackwardTK);
1099:
1100: newForwardTK.remove(tabForward);
1101: newBackwardTK.remove(tabBackward);
1102:
1103: setFocusTraversalKeys(
1104: KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
1105: newForwardTK);
1106: setFocusTraversalKeys(
1107: KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
1108: newBackwardTK);
1109:
1110: getInputMap().put(tabForward, "tabNextAction"); // NOI18N
1111: getInputMap().put(tabBackward, "tabPrevAction"); // NOI18N
1112:
1113: getActionMap().put("tabNextAction", new TabNextAction());
1114: getActionMap().put("tabPrevAction", new TabPrevAction());
1115: }
1116:
1117: public AbstractCanvasMethoidNode getNextNode() {
1118: AbstractCanvasMethoidNode firstSelected = null;
1119: int selectedCount = 0;
1120:
1121: Collection<?> selection = getSelectedNodes();
1122:
1123: if (selection != null) {
1124: for (Object o : selection) {
1125: if (o instanceof AbstractCanvasMethoidNode) {
1126: if (firstSelected == null) {
1127: firstSelected = (AbstractCanvasMethoidNode) o;
1128: }
1129: selectedCount++;
1130: }
1131: }
1132: }
1133:
1134: if (selectedCount > 1) {
1135: return firstSelected;
1136: }
1137:
1138: List<?> nodes = getNodes();
1139: int size = (nodes == null) ? 0 : nodes.size();
1140:
1141: if (size != 0) {
1142: if (firstSelected == null) {
1143: for (int i = 0; i < size; i++) {
1144: Object o = nodes.get(i);
1145: if (o instanceof AbstractCanvasMethoidNode) {
1146: return (AbstractCanvasMethoidNode) o;
1147: }
1148: }
1149: } else {
1150: for (int i = 0; i < size; i++) {
1151: if (nodes.get(i) == firstSelected) {
1152: for (int j = i + 1; j < size; j++) {
1153: Object o = nodes.get(j);
1154: if (o instanceof AbstractCanvasMethoidNode) {
1155: return (AbstractCanvasMethoidNode) o;
1156: }
1157: }
1158:
1159: return null;
1160: }
1161: }
1162: }
1163: }
1164:
1165: return null;
1166: }
1167:
1168: public AbstractCanvasMethoidNode getPrevNode() {
1169: AbstractCanvasMethoidNode lastSelected = null;
1170: int selectedCount = 0;
1171:
1172: Collection<?> selection = getSelectedNodes();
1173:
1174: if (selection != null) {
1175: for (Object o : selection) {
1176: if (o instanceof AbstractCanvasMethoidNode) {
1177: lastSelected = (AbstractCanvasMethoidNode) o;
1178: selectedCount++;
1179: }
1180: }
1181: }
1182:
1183: if (selectedCount > 1) {
1184: return lastSelected;
1185: }
1186:
1187: List<?> nodes = getNodes();
1188: int size = (nodes == null) ? 0 : nodes.size();
1189:
1190: if (size != 0) {
1191: if (lastSelected == null) {
1192: for (int i = size - 1; i >= 0; i--) {
1193: Object o = nodes.get(i);
1194: if (o instanceof AbstractCanvasMethoidNode) {
1195: return (AbstractCanvasMethoidNode) o;
1196: }
1197: }
1198: } else {
1199: for (int i = size - 1; i >= 0; i--) {
1200: if (nodes.get(i) == lastSelected) {
1201: for (int j = i - 1; j >= 0; j--) {
1202: Object o = nodes.get(j);
1203: if (o instanceof AbstractCanvasMethoidNode) {
1204: return (AbstractCanvasMethoidNode) o;
1205: }
1206: }
1207:
1208: return null;
1209: }
1210: }
1211: }
1212: }
1213:
1214: return null;
1215: }
1216:
1217: private void scrollNodeToBeVisible(AbstractCanvasMethoidNode node) {
1218: Rectangle bounds = node.getBoundingRect();
1219: if (bounds != null) {
1220: scrollRectToVisible(bounds);
1221: }
1222: }
1223:
1224: private class TabNextAction extends AbstractAction {
1225: public void actionPerformed(ActionEvent e) {
1226: AbstractCanvasMethoidNode nextNode = getNextNode();
1227: if (nextNode != null) {
1228: selectObject(nextNode);
1229: scrollNodeToBeVisible(nextNode);
1230: } else {
1231: transferFocus();
1232: }
1233: }
1234: }
1235:
1236: private class TabPrevAction extends AbstractAction {
1237: public void actionPerformed(ActionEvent e) {
1238: AbstractCanvasMethoidNode prevNode = getPrevNode();
1239: if (prevNode != null) {
1240: selectObject(prevNode);
1241: scrollNodeToBeVisible(prevNode);
1242: } else {
1243: transferFocusBackward();
1244: }
1245: }
1246: }
1247: }
|