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;
016:
017: import java.awt.Point;
018: import java.awt.datatransfer.Transferable;
019: import java.awt.dnd.DropTarget;
020: import java.awt.dnd.DropTargetContext;
021: import java.awt.dnd.DropTargetDragEvent;
022: import java.awt.dnd.DropTargetDropEvent;
023: import java.awt.dnd.DropTargetEvent;
024: import java.awt.dnd.DropTargetListener;
025:
026: /* Graph Panel drop target class */
027:
028: public class BaseGraphDropTarget implements DropTargetListener {
029: protected BaseGraphPanel mGraphPanel = null;
030: protected DropTarget mTarget = null;
031:
032: public BaseGraphDropTarget(BaseGraphPanel aGraphPanel) {
033: mGraphPanel = aGraphPanel;
034: mTarget = (mGraphPanel != null) ? new DropTarget(mGraphPanel
035: .getGraph(), this ) : null;
036: }
037:
038: // check drag event and allow to drop
039: protected boolean isDropAllowed(DropTargetDragEvent e) {
040: boolean lResult = false;
041: if (mGraphPanel != null) {
042: DropTargetContext lContext = e.getDropTargetContext();
043: if (lContext != null) {
044: DropTargetDropEvent lDropEvent = new DropTargetDropEvent(
045: lContext, new Point(0, 0), 0, 0);
046: Transferable lTransferable = lDropEvent
047: .getTransferable();
048: if (lTransferable != null) {
049: try {
050: Object lObject = lTransferable
051: .getTransferData(BaseUserObject.USEROBJECT_FLAVOR);
052: if (lObject != null
053: && lObject instanceof BaseUserObject) {
054: BaseUserObject lUserOBject = (BaseUserObject) lObject;
055: lResult = mGraphPanel
056: .isObjectExcepted(lUserOBject);
057: }
058: } catch (Exception ex) {
059: ex.printStackTrace();
060: }
061: }
062: }
063: }
064: return lResult;
065: }
066:
067: /* DropTargetListener interface implementation */
068:
069: public void dragEnter(DropTargetDragEvent e) {
070: if (isDropAllowed(e))
071: e.acceptDrag(e.getDropAction());
072: else
073: e.rejectDrag();
074: }
075:
076: public void dragOver(DropTargetDragEvent e) {
077: if (isDropAllowed(e))
078: e.acceptDrag(e.getDropAction());
079: else
080: e.rejectDrag();
081: }
082:
083: public void dragExit(DropTargetEvent e) {
084: //???
085: }
086:
087: public void dropActionChanged(DropTargetDragEvent e) {
088: //???
089: }
090:
091: public void drop(DropTargetDropEvent e) {
092: Transferable lTransferable = e.getTransferable();
093: if (lTransferable != null && mGraphPanel != null) {
094: try {
095: Object lObject = lTransferable
096: .getTransferData(BaseUserObject.USEROBJECT_FLAVOR);
097: if (lObject != null
098: && lObject instanceof BaseUserObject) {
099: BaseUserObject lUserOBject = (BaseUserObject) lObject;
100: mGraphPanel
101: .dropObject(lUserOBject, e.getLocation());
102: }
103: } catch (Exception ex) {
104: ex.printStackTrace();
105: }
106: }
107: }
108: }
|