Author: mes
Date: 2010-12-07 14:27:59 -0800 (Tue, 07 Dec 2010)
New Revision: 23115

Added:
   core3/dnd-api/trunk/src/main/java/org/cytoscape/dnd/DropUtil.java
   core3/dnd-api/trunk/src/main/java/org/cytoscape/dnd/GraphicalEntity.java
Log:
added code to support editor

Added: core3/dnd-api/trunk/src/main/java/org/cytoscape/dnd/DropUtil.java
===================================================================
--- core3/dnd-api/trunk/src/main/java/org/cytoscape/dnd/DropUtil.java           
                (rev 0)
+++ core3/dnd-api/trunk/src/main/java/org/cytoscape/dnd/DropUtil.java   
2010-12-07 22:27:59 UTC (rev 23115)
@@ -0,0 +1,86 @@
+package org.cytoscape.dnd;
+
+
+import java.awt.geom.Point2D;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.Transferable;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A stateless, static utility class that provides a few methods useful for
+ * interacting with Drag-n-Drop related objects.
+ */
+public final class DropUtil {
+
+       private static final Logger logger = 
LoggerFactory.getLogger(DropUtil.class);
+       private DropUtil() {};
+
+       /**
+        * A utility method to check whether the Transferable is of the type
+        * we care about.
+        * @param t The transferable object containing the data we will check.
+        * @param type The string representation of the data that we're hoping 
to
+        * match in the transferable.
+        * @return True if the transferable data flavors contain data that 
matches
+        * the specified type, false otherwise.
+        */
+       public static boolean transferableMatches(Transferable t, String type) 
{ 
+               try {
+                       if ( t==null) 
+                               return false;
+
+                       DataFlavor[] dfl = t.getTransferDataFlavors();
+
+                       if ( dfl==null) 
+                               return false;
+
+                       for (DataFlavor d : dfl) {
+                               if ( 
GraphicalEntity.class.isAssignableFrom(d.getRepresentationClass()) ) {
+                                       String myShape = 
t.getTransferData(d).toString();
+                                       if ( myShape.equals(type) ) {
+                                               return true;
+                                       } 
+                               }
+                       }
+               } catch (Exception e) { 
+                       logger.warn("Exception matching transferable",e);
+               }
+               return false;
+       }
+
+       /**
+        * Returns an array containing strings describing the transfer data 
+        * contained in each DataFlavor specified by the Transferable. 
+        * @param t The Transferable object to be processed.
+        * @return An array containing strings describing the transfer data 
+        * contained in each DataFlavor specified by the Transferable. Will
+        * never return null, but may return an empty array.
+        */
+       public static String[] getTransferableDataStrings(Transferable t) { 
+        try {
+            DataFlavor[] dfl = t.getTransferDataFlavors();
+
+            if ( dfl==null) {
+                               logger.warn("DataFlavors is null for specified 
Transferable.");
+                return new String[0];
+            }
+
+                       String[] names = new String[dfl.length]; 
+
+                       for (int i = 0; i < dfl.length; i++ ) {
+                               DataFlavor d = dfl[i];
+                if ( 
GraphicalEntity.class.isAssignableFrom(d.getRepresentationClass()) ) {
+                                       names[i] = 
t.getTransferData(d).toString();
+                }
+            }
+
+                       return names;
+
+        } catch (Exception e) { 
+                       logger.warn("Exception accessing transferable data",e);
+                       return new String[0];
+               }
+       }
+}

Added: core3/dnd-api/trunk/src/main/java/org/cytoscape/dnd/GraphicalEntity.java
===================================================================
--- core3/dnd-api/trunk/src/main/java/org/cytoscape/dnd/GraphicalEntity.java    
                        (rev 0)
+++ core3/dnd-api/trunk/src/main/java/org/cytoscape/dnd/GraphicalEntity.java    
2010-12-07 22:27:59 UTC (rev 23115)
@@ -0,0 +1,59 @@
+package org.cytoscape.dnd;
+
+import java.awt.Image;
+import java.awt.dnd.DragSource;
+import javax.swing.Icon;
+
+
+/**
+ *
+ * Interface for defining draggable/droppable visual components in the
+ * Cytoscape editor framework.  The framework provides for dragging and 
dropping graphical
+ * entities from palette onto the canvas.   Graphical entities are associated 
with
+ * semantic objects, i.e. nodes and edges, that are created when the graphical 
entities
+ * are dropped onto the canvas.
+ *
+ * @author Allan Kuchinsky, Agilent Technologies
+ */
+public interface GraphicalEntity {
+
+       /**
+        * get the Title of the graphical entity
+        * @return the Title
+        */
+       public String getTitle();
+
+       /**
+        * retrieves the source of the drag operation, used when dragging a 
graphical entity from the palette onto
+        * the canvas
+        * @return the drag source
+        */
+       public DragSource getMyDragSource();
+
+       /**
+        * get the image for the icon used on the palette to represent the 
graphical entity
+        * @return the image
+        */
+       public Image getImage();
+
+       /**
+        * get the icon used on the palette to represent the graphical entity
+        * @return the icon used on the palette to represent the graphical 
entity
+        */
+       public Icon getIcon();
+
+       /**
+        * returns the name of the attribute associated with the Graphical 
Entity.
+        * This is used to determine whether a Node or an Edge has been dropped 
on the canvas.
+        * This attribute will also be set for the CyNode or CyEdge created as 
a result of the drop operation.
+        * @return the attribute name
+        */
+       public String getAttributeName();
+
+       /**
+        * returns the value of the attribute associated with the Graphical 
Entity.
+        * This attribute will be set for the CyNode or CyEdge created as a 
result of the drop operation.
+        * @return the attribute value
+        */
+       public String getAttributeValue();
+}

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to