001: //THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: //CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: //BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: //FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: //OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: //INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: //LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: //OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: //LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: //NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: //EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: //POSSIBILITY OF SUCH DAMAGE.
013: //
014: //Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.applications.designstudio.designtree;
016:
017: import java.awt.dnd.DnDConstants;
018: import java.awt.dnd.DragGestureEvent;
019: import java.awt.dnd.DragGestureListener;
020: import java.awt.dnd.DragGestureRecognizer;
021: import java.awt.dnd.DragSource;
022: import java.awt.dnd.DragSourceContext;
023: import java.awt.dnd.DragSourceDragEvent;
024: import java.awt.dnd.DragSourceDropEvent;
025: import java.awt.dnd.DragSourceEvent;
026: import java.awt.dnd.DragSourceListener;
027:
028: import javax.swing.JTree;
029: import javax.swing.tree.DefaultMutableTreeNode;
030: import javax.swing.tree.TreePath;
031:
032: import com.metaboss.applications.designstudio.BaseUserObject;
033:
034: /* Drag Data Source class for design tree elements */
035:
036: public class DesignTreeDragSource implements DragSourceListener,
037: DragGestureListener {
038: protected JTree mTree = null;
039: protected DragSource mDragSource = null;
040: protected DragGestureRecognizer mRecognizer = null;
041: protected DefaultMutableTreeNode mOldNode = null;
042:
043: public DesignTreeDragSource(JTree aTree, int actions) {
044: mTree = aTree;
045: mDragSource = new DragSource();
046: mRecognizer = mDragSource.createDefaultDragGestureRecognizer(
047: mTree, actions, this );
048: }
049:
050: // Drag Gesture Handler
051: public void dragGestureRecognized(DragGestureEvent dge) {
052: TreePath path = mTree.getSelectionPath();
053: if ((path == null) || (path.getPathCount() <= 1))
054: return;
055: mOldNode = (DefaultMutableTreeNode) path.getLastPathComponent();
056: if (mOldNode != null) {
057: Object lObject = mOldNode.getUserObject();
058: if (lObject != null && lObject instanceof BaseUserObject) {
059: BaseUserObject lUserObject = (BaseUserObject) lObject;
060: mDragSource
061: .startDrag(dge, DragSource.DefaultMoveNoDrop,
062: lUserObject, this );
063: }
064: }
065: }
066:
067: /*
068: * Drag Event Handlers
069: */
070: public void dragEnter(DragSourceDragEvent e) {
071: //???
072: }
073:
074: public void dragExit(DragSourceEvent e) {
075: DragSourceContext context = e.getDragSourceContext();
076: context.setCursor(null);
077: context.setCursor(DragSource.DefaultMoveNoDrop);
078: }
079:
080: public void dragOver(DragSourceDragEvent e) {
081: DragSourceContext context = e.getDragSourceContext();
082: int iAction = e.getDropAction();
083: if ((iAction & DnDConstants.ACTION_MOVE) != 0) {
084: context.setCursor(null); // Do this to fix swing flicker bug
085: context.setCursor(DragSource.DefaultMoveDrop);
086: } else if ((iAction & DnDConstants.ACTION_COPY) != 0) {
087: context.setCursor(null); // Do this to fix swing flicker bug
088: context.setCursor(DragSource.DefaultCopyDrop);
089: } else
090: context.setCursor(DragSource.DefaultMoveNoDrop);
091: }
092:
093: public void dropActionChanged(DragSourceDragEvent e) {
094: //???
095: }
096:
097: public void dragDropEnd(DragSourceDropEvent e) {
098: //???
099: }
100: }
|