00001 package edu.ksu.cis.bandera.pdgslicer.dependency;
00002
00003 import java.awt.*;
00004 import java.awt.dnd.*;
00005 import java.awt.datatransfer.*;
00006 import javax.swing.*;
00007 import java.io.*;
00008 import java.util.*;
00009 import java.util.List;
00010 import edu.ksu.cis.bandera.annotation.*;
00011 import edu.ksu.cis.bandera.pdgslicer.datastructure.SlicePoint;
00012
00013
00014
00015
00016
00017 public class DroppableLocationsList extends DroppableList {
00018
00019
00020
00021 public DroppableLocationsList() {
00022 super();
00023 }
00024 public void dragEnter(DropTargetDragEvent dropTargetDragEvent) {
00025 Transferable tr = DraggableTree.currentDraggingTreeNode;
00026 if (tr == null) {
00027 dropTargetDragEvent.rejectDrag();
00028 return;
00029 }
00030 Object userObject = null;
00031 try {
00032 userObject = tr.getTransferData(TransferableTreeNode.DEFAULT_MUTABLE_TREENODE_FLAVOR);
00033 } catch (IOException io) {
00034 io.printStackTrace();
00035 dropTargetDragEvent.rejectDrag();
00036 } catch (UnsupportedFlavorException ufe) {
00037 ufe.printStackTrace();
00038 dropTargetDragEvent.rejectDrag();
00039 }
00040 if (userObject instanceof FieldDeclarationAnnotation)
00041 dropTargetDragEvent.rejectDrag();
00042 else
00043 dropTargetDragEvent.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
00044 }
00045 public void drop(DropTargetDropEvent dropTargetDropEvent) {
00046 try {
00047 Transferable tr = DraggableTree.currentDraggingTreeNode;
00048 if (tr.isDataFlavorSupported(TransferableTreeNode.DEFAULT_MUTABLE_TREENODE_FLAVOR)) {
00049 dropTargetDropEvent.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
00050 Object userObject = tr.getTransferData(TransferableTreeNode.DEFAULT_MUTABLE_TREENODE_FLAVOR);
00051
00052 SlicePoint sp = criterionViewer.calculateSlicePoint(userObject);
00053 if (sp != null) {
00054 boolean isStatementNode = false;
00055 criterionViewer.addLocationToCriterion(sp, (Annotation) userObject);
00056 }
00057 dropTargetDropEvent.getDropTargetContext().dropComplete(true);
00058 } else {
00059 System.err.println("Rejected");
00060 dropTargetDropEvent.rejectDrop();
00061 }
00062 } catch (IOException io) {
00063 io.printStackTrace();
00064 dropTargetDropEvent.rejectDrop();
00065 } catch (UnsupportedFlavorException ufe) {
00066 ufe.printStackTrace();
00067 dropTargetDropEvent.rejectDrop();
00068 }
00069 }
00070 }