Author: mes
Date: 2010-11-20 16:58:13 -0800 (Sat, 20 Nov 2010)
New Revision: 22965

Added:
   core3/editor-impl/trunk/src/main/java/org/cytoscape/editor/internal/gui/
   
core3/editor-impl/trunk/src/main/java/org/cytoscape/editor/internal/gui/BasicCytoShapeEntity.java
   
core3/editor-impl/trunk/src/main/java/org/cytoscape/editor/internal/gui/BasicCytoShapeTransferHandler.java
   
core3/editor-impl/trunk/src/main/java/org/cytoscape/editor/internal/gui/DragSourceContextCursorSetter.java
   
core3/editor-impl/trunk/src/main/java/org/cytoscape/editor/internal/gui/EditorCytoPanelComponent.java
   
core3/editor-impl/trunk/src/main/java/org/cytoscape/editor/internal/gui/ShapePalette.java
   
core3/editor-impl/trunk/src/main/java/org/cytoscape/editor/internal/gui/StringTransferHandler.java
   core3/editor-impl/trunk/src/main/resources/images/
   core3/editor-impl/trunk/src/main/resources/images/edge.png
   core3/editor-impl/trunk/src/main/resources/images/network.png
   core3/editor-impl/trunk/src/main/resources/images/node.png
Modified:
   core3/editor-impl/trunk/pom.xml
   
core3/editor-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
   core3/editor-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
Log:
got editor GUI popping up

Modified: core3/editor-impl/trunk/pom.xml
===================================================================
--- core3/editor-impl/trunk/pom.xml     2010-11-20 23:28:01 UTC (rev 22964)
+++ core3/editor-impl/trunk/pom.xml     2010-11-21 00:58:13 UTC (rev 22965)
@@ -125,6 +125,11 @@
                        <artifactId>dnd-api</artifactId>
                        <version>1.0-SNAPSHOT</version>
                </dependency>
+               <dependency>
+                       <groupId>org.cytoscape</groupId>
+                       <artifactId>swing-application-api</artifactId>
+                       <version>1.0-SNAPSHOT</version>
+               </dependency>
 
        </dependencies>
 </project>

Added: 
core3/editor-impl/trunk/src/main/java/org/cytoscape/editor/internal/gui/BasicCytoShapeEntity.java
===================================================================
--- 
core3/editor-impl/trunk/src/main/java/org/cytoscape/editor/internal/gui/BasicCytoShapeEntity.java
                           (rev 0)
+++ 
core3/editor-impl/trunk/src/main/java/org/cytoscape/editor/internal/gui/BasicCytoShapeEntity.java
   2010-11-21 00:58:13 UTC (rev 22965)
@@ -0,0 +1,380 @@
+/* -*-Java-*-
+********************************************************************************
+*
+* File:         BasicCytoShapeEntity.java
+* RCS:          $Header: $
+* Description:
+* Author:       Allan Kuchinsky
+* Created:      Sun May 29 11:22:33 2005
+* Modified:     Sun Dec 17 05:29:24 2006 (Michael L. Creech) 
cre...@w235krbza760
+* Language:     Java
+* Package:
+/*
+ 
+ Copyright (c) 2006, 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications.  In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage.  See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ 
+********************************************************************************
+*
+* Revisions:
+*
+* Sat Dec 16 14:50:40 2006 (Michael L. Creech) cre...@w235krbza760
+*  Completely rewrote TestDragSourceListener (now is EntityDragSourceListener) 
to
+*  allow for intelligent setting of the drag cursor. Changed constructor to
+*  take a DragSourceContextCursorSetter.
+*  Changed all instance variables to be private.
+* Tue Dec 05 04:39:09 2006 (Michael L. Creech) cre...@w235krbza760
+*  Changed computation of BasicCytoShapeEntity size to allow for
+*  larger CytoShapeIcons.
+* Sun Aug 06 11:22:50 2006 (Michael L. Creech) cre...@w235krbza760
+*  Added generated serial version UUID for serializable classes.
+********************************************************************************
+*/
+package org.cytoscape.editor.internal.gui;
+
+import java.awt.Component;
+import java.awt.Cursor;
+import java.awt.Dimension;
+import java.awt.GridLayout;
+import java.awt.Image;
+import java.awt.Point;
+import java.awt.dnd.DnDConstants;
+import java.awt.dnd.DragGestureEvent;
+import java.awt.dnd.DragGestureListener;
+import java.awt.dnd.DragSource;
+import java.awt.dnd.DragSourceAdapter;
+import java.awt.dnd.DragSourceContext;
+import java.awt.dnd.DragSourceDragEvent;
+import java.awt.dnd.DragSourceEvent;
+
+import javax.swing.BorderFactory;
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.SwingConstants;
+import javax.swing.SwingUtilities;
+import javax.swing.border.TitledBorder;
+
+
+import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.application.swing.CySwingApplication;
+
+
+/**
+ *
+ * The <b>BasicCytoShapeEntity</b> class defines draggable/droppable visual 
components in the
+ * Cytoscape editor framework.  The framework provides for dragging and 
dropping graphical
+ * entities from palette onto the canvas.   BasicCytoShapeEntity objects 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
+ * @version 1.0
+ *
+ */
+public class BasicCytoShapeEntity extends JComponent implements 
DragGestureListener {
+       // MLC 07/27/06:
+       private static final long serialVersionUID = -5229827235046946347L;
+
+       // MLC 12/16/06 BEGIN:
+       private static DragSourceContextCursorSetter defaultCursorSetter = new 
DragSourceContextCursorSetter() {
+               // The default shows that a drop is possible anywhere on the 
netView:
+               public Cursor computeCursor(Point netViewLoc, 
DragSourceDragEvent dsde) {
+                       return DragSource.DefaultCopyDrop;
+               }
+       };
+
+       /**
+       * used for setting tooltip text
+       */
+       private JLabel _cytoShape;
+
+       /**
+        * the title of the shape
+        */
+       private String title;
+
+       /**
+        * attribute name for the shape
+        * should be one of "NodeType" or "EdgeType"
+        */
+       private String attributeName;
+
+       /**
+        * value for the attribute assigned to the shape
+        * for example a "NodeType" of "protein"
+        */
+       private String attributeValue;
+
+       /**
+        * the icon associated with the shape
+        */
+       private Icon _image;
+
+       /**
+        * the source of a drag event
+        */
+       private DragSource myDragSource;
+
+       private BasicCytoShapeTransferHandler handler;
+
+       /**
+        * the image associated with the Icon for the shape
+        */
+       private Image _img;
+
+       private final CySwingApplication app;
+
+       /**
+        *
+        * @param attributeName attribute name for the shape, should be one of 
"NodeType" or "EdgeType"
+        * @param attributeValue value for the attribute assigned to the shape, 
for example a "NodeType" of "protein"
+        * @param image the icon for the shape
+        * @param title the title of the shape
+        * @param cursorSetter a possibly null DragSourceContextCursorSetter 
used to specify
+        *                     the cursor so show when dragging over the 
current network view.
+        *                     If null, a default cursor setter is used shows 
its ok
+        *                     to drop anywhere on the network view.
+        */
+       public BasicCytoShapeEntity(CySwingApplication app, String 
attributeName, String attributeValue, Icon image, String title) {
+               super();
+               this.setTitle(title);
+               this.app = app;
+               _image = image;
+
+               this.attributeName = attributeName;
+               this.attributeValue = attributeValue;
+
+               if (image instanceof ImageIcon) {
+                       _img = ((ImageIcon) image).getImage();
+               }
+
+               _cytoShape = new JLabel(image);
+
+               if (this.attributeName != null) {
+                       if (this.attributeName.equals("NODE_TYPE")) {
+                               _cytoShape.setToolTipText("<html>To add a node 
to a network,<br>"
+                                                             + "drag and drop 
a shape<br>"
+                                                                               
      + "from the palette onto the canvas<br>"
+                                                                               
          + "OR<br>"
+                                                                               
      + "simply CTRL-click on the canvas.</html>");
+                       } else if (this.attributeName.equals("EDGE_TYPE")) {
+                               _cytoShape.setToolTipText("<html>To connect two 
nodes with an edge<br>"
+                                                         + "drag and drop the 
arrow onto a node<br>"
+                                                                               
  + "on the canvas, then move the cursor<br>"
+                                                                               
  + "over a second node and click the mouse.<br>"
+                                                                               
  + "OR<br>"
+                                                                               
  + "CTRL-click on the first node and then<br>"
+                                                                               
  + "click on the second node. </html>");
+                       } else if (this.attributeName.equals("NETWORK_TYPE")) {
+                               _cytoShape.setToolTipText("<html>To create a 
nested network<br>"
+                                                         + "drag and drop the 
network onto a node<br>"
+                                                                               
  + "to assign a nested network,<br>" 
+                                                                               
  + "or on the canvas to create a new node and<br>"
+                                                                               
  + "assign a nested network. </html>");
+                       }
+               }
+
+               this.setLayout(new GridLayout(1, 1));
+
+               TitledBorder t2 = BorderFactory.createTitledBorder(title);
+               this.add(_cytoShape);
+               this.setBorder(t2);
+
+               myDragSource = new DragSource();
+               myDragSource.addDragSourceListener(new 
EntityDragSourceListener());
+               myDragSource.createDefaultDragGestureRecognizer(_cytoShape, 
DnDConstants.ACTION_COPY, this);
+               handler = (new BasicCytoShapeTransferHandler(this, null));
+               this.setTransferHandler(handler);
+/*
+               Dimension mySize = new Dimension(((JPanel) 
Cytoscape.getDesktop()
+                                                                   
.getCytoPanel(SwingConstants.WEST))
+                                                                               
                                                                                
                                                                                
         .getSize().width
+                                                - 5,
+                                                
Math.max(_image.getIconHeight(),
+                                                         
CytoShapeIcon.DEFAULT_HEIGHT)
+                                                + 
CytoShapeIcon.DEFAULT_HEIGHT);
+
+               this.setMaximumSize(mySize);
+               this.setMinimumSize(mySize);
+               this.setPreferredSize(mySize);
+               */
+
+
+       }
+
+       /**
+        * @return Returns the title.
+        */
+       public String getTitle() {
+               return title;
+       }
+
+       /**
+        * @param title The title to set.
+        *
+        */
+       public void setTitle(String title) {
+               this.title = title;
+       }
+
+       /**
+        * @return Returns the DragSource.
+        */
+       public DragSource getMyDragSource() {
+               return myDragSource;
+       }
+
+       /**
+        * @param myDragSource The DragSource to set.
+        */
+       public void setMyDragSource(DragSource myDragSource) {
+               this.myDragSource = myDragSource;
+       }
+
+       /**
+        * @return Returns the icon associated with the shape
+        */
+       public Icon getIcon() {
+               return _image;
+       }
+
+       /**
+        * @param _image the icon to set for the shape
+        *
+        */
+       public void setIcon(Icon _image) {
+               this._image = _image;
+       }
+
+       /**
+        * @return Returns the image associated with the shape's icon
+        */
+       public Image get_image() {
+               return _img;
+       }
+
+       /**
+        * @param _img The _img to set.
+        */
+       public void set_image(Image _img) {
+               this._img = _img;
+       }
+
+       /**
+        * @return Returns the attributeName.
+        */
+       public String getAttributeName() {
+               return attributeName;
+       }
+
+       /**
+        * @param attributeName The attributeName to set.
+        */
+       public void setAttributeName(String attributeName) {
+               this.attributeName = attributeName;
+       }
+
+       /**
+        * @return Returns the attributeValue.
+        */
+       public String getAttributeValue() {
+               return attributeValue;
+       }
+
+       /**
+        * @param attributeValue The attributeValue to set.
+        */
+       public void setAttributeValue(String attributeValue) {
+               this.attributeValue = attributeValue;
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param e DOCUMENT ME!
+        */
+       public void dragGestureRecognized(DragGestureEvent e) {
+               e.startDrag(DragSource.DefaultCopyDrop, 
handler.createTransferable(this));
+       }
+
+       private class EntityDragSourceListener extends DragSourceAdapter {
+               public void dragEnter(DragSourceDragEvent dsde) {
+                       determineCursor(dsde);
+               }
+
+               public void dragOver(DragSourceDragEvent dsde) {
+                       determineCursor(dsde);
+               }
+
+               private void determineCursor(DragSourceDragEvent dsde) {
+                       DragSourceContext dsc = dsde.getDragSourceContext();
+                       Point compLoc = 
getLocationInsideComponent(app.getJFrame(), dsde.getLocation());
+
+                       if (compLoc != null) {
+                               Cursor newCursor = 
defaultCursorSetter.computeCursor(compLoc, dsde);
+
+                               if (newCursor == null) {
+                                       newCursor = 
DragSource.DefaultCopyNoDrop;
+                               }
+
+                               dsc.setCursor(newCursor);
+                       } else {
+                               // check if on the drag source. We want to show 
ok cursor
+                               // for it:
+                               // sourceLoc now now in source component 
coordinates:
+                               Point paletteLoc = 
getLocationInsideComponent(dsc.getComponent(), dsde.getLocation());
+
+                               if (paletteLoc != null) {
+                                       
dsc.setCursor(DragSource.DefaultCopyDrop);
+                               } else {
+                                       
dsc.setCursor(DragSource.DefaultCopyNoDrop);
+                               }
+                       }
+               }
+
+               // return the point in component coordinates of a given point
+               // in screen ccordinates only if the point is within the 
component.
+               // Otherwise return null;
+               private Point getLocationInsideComponent(Component desiredComp, 
Point screenLoc) {
+                       // loc now component location
+                       Point compLoc = new Point(screenLoc);
+                       SwingUtilities.convertPointFromScreen(compLoc, 
desiredComp);
+
+                       if (desiredComp.contains(compLoc)) {
+                               // the point is in desiredComp:
+                               return compLoc;
+                       }
+
+                       return null;
+               }
+
+               public void dragExit(DragSourceEvent dse) {
+                       
dse.getDragSourceContext().setCursor(DragSource.DefaultCopyNoDrop);
+               }
+       }
+}

Added: 
core3/editor-impl/trunk/src/main/java/org/cytoscape/editor/internal/gui/BasicCytoShapeTransferHandler.java
===================================================================
--- 
core3/editor-impl/trunk/src/main/java/org/cytoscape/editor/internal/gui/BasicCytoShapeTransferHandler.java
                          (rev 0)
+++ 
core3/editor-impl/trunk/src/main/java/org/cytoscape/editor/internal/gui/BasicCytoShapeTransferHandler.java
  2010-11-21 00:58:13 UTC (rev 22965)
@@ -0,0 +1,212 @@
+/*
+ * Created on May 31, 2005
+ *
+ */
+package org.cytoscape.editor.internal.gui;
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.Transferable;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.awt.dnd.DragGestureListener;
+
+import javax.swing.JComponent;
+import javax.swing.TransferHandler;
+
+import org.slf4j.Logger; 
+import org.slf4j.LoggerFactory; 
+
+
+/**
+ * transfer handler for shapes that are dragged from the palette onto the 
canvas.
+ * Creates appropriate data flavor and transferrable.
+ * part of drag/drop editor framework.
+ *
+ * @author Allan Kuchinsky
+ * @version 1.0
+ * @see cytoscape.editor.GraphicalEntity 
+ * @see cytoscape.editor.impl.BasicCytoShapeEntity
+ *
+ */
+public class BasicCytoShapeTransferHandler extends TransferHandler {
+       // MLC 09/14/06:
+       private static final long serialVersionUID = 778042405547689517L;
+       private static final Logger logger = 
LoggerFactory.getLogger(BasicCytoShapeTransferHandler.class); 
+       DataFlavor basicCytoShapeFlavor;
+       DragGestureListener _cytoShape;
+
+       /**
+        * @return Returns the _attributeName.
+        */
+       public String get_attributeName() {
+               return _attributeName;
+       }
+
+       /**
+        * @return Returns the _attributeValue.
+        */
+       public String get_attributeValue() {
+               return _attributeValue;
+       }
+
+       String _attributeName;
+       String _attributeValue;
+       Object[] _args;
+
+       /**
+        * creates a DataFlavor for the BasicCytoShapeEntity class
+        *
+        */
+       public BasicCytoShapeTransferHandler() {
+               try {
+                       basicCytoShapeFlavor = new 
DataFlavor(BasicCytoShapeEntity.class, "BasicCytoShapeEntity");
+               } catch (Exception e) {
+                       logger.warn("Unable to create data flavor for 
BasicCytoShapeEntity",e);
+               }
+       }
+
+       /**
+        * creates a DataFlavor and sets instance variables for a 
BasicCytoShapeEntity that is
+        * added to the palette
+        * @param cytoShape shape that is added to the palette
+        * @param args arbitrary list of arguments that can be passed in
+        */
+       public BasicCytoShapeTransferHandler(BasicCytoShapeEntity cytoShape, 
Object[] args) {
+               try {
+                       basicCytoShapeFlavor = new 
DataFlavor(BasicCytoShapeEntity.class, "BasicCytoShapeEntity");
+               } catch (Exception e) {
+                       logger.warn("Unable to create data flavor for 
BasicCytoShapeEntity",e);
+               }
+
+               _cytoShape = cytoShape;
+               _args = args;
+               _attributeName = cytoShape.getAttributeName();
+               _attributeValue = cytoShape.getAttributeValue();
+       }
+
+       /**
+        * @return Returns the _args.
+        */
+       public Object[] get_args() {
+               return _args;
+       }
+
+       /**
+        * sets the _args instance variable
+        * @param _args The _args to set.
+        */
+       public void set_args(Object[] _args) {
+               this._args = _args;
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param c DOCUMENT ME!
+        * @param t DOCUMENT ME!
+        *
+        * @return  DOCUMENT ME!
+        */
+       public boolean importData(JComponent c, Transferable t) {
+
+               if (canImport(c, t.getTransferDataFlavors())) {
+               }
+
+               return false;
+       }
+
+       // AJK: 11/13/05 BEGIN
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param val DOCUMENT ME!
+        *
+        * @return  DOCUMENT ME!
+        */
+       public String exportString(Object val) {
+               if (val instanceof BasicCytoShapeEntity) {
+                       return ((BasicCytoShapeEntity) val).getTitle();
+               } else {
+                       return null;
+               }
+       }
+
+       // AJK: 11/13/05 END
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param c DOCUMENT ME!
+        *
+        * @return  DOCUMENT ME!
+        */
+       public Transferable createTransferable(JComponent c) {
+               return new BasicCytoShapeTransferable(c);
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param c DOCUMENT ME!
+        * @param flavors DOCUMENT ME!
+        *
+        * @return  DOCUMENT ME!
+        */
+       public boolean canImport(JComponent c, DataFlavor[] flavors) {
+               for (int i = 0; i < flavors.length; i++) {
+                       if (basicCytoShapeFlavor.equals(flavors[i])) {
+                               return true;
+                       }
+               }
+
+               return false;
+       }
+
+       /**
+        * packages the BasicCytoShapeEntity for transfer upon a drag/drop 
operation
+        * @author Allan Kuchinsky
+        * @version 1.0
+        *
+        *
+        */
+       class BasicCytoShapeTransferable implements Transferable {
+               private BasicCytoShapeEntity _cytoShape;
+
+               BasicCytoShapeTransferable(JComponent obj) {
+                       if (obj instanceof BasicCytoShapeEntity) {
+                               _cytoShape = (BasicCytoShapeEntity) obj;
+                               _attributeName = _cytoShape.getAttributeName();
+                               _attributeValue = 
_cytoShape.getAttributeValue();
+                       }
+               }
+
+               public Object getTransferData(DataFlavor flavor) throws 
UnsupportedFlavorException {
+                       if (!isDataFlavorSupported(flavor)) {
+                               throw new UnsupportedFlavorException(flavor);
+                       }
+
+                       return exportString(_cytoShape);
+               }
+
+               public DataFlavor[] getTransferDataFlavors() {
+                       return new DataFlavor[] { basicCytoShapeFlavor };
+               }
+
+               public boolean isDataFlavorSupported(DataFlavor flavor) {
+                       return basicCytoShapeFlavor.equals(flavor);
+               }
+       }
+
+       /**
+        * @return Returns the _cytoShape.
+        */
+       public DragGestureListener get_cytoShape() {
+               return _cytoShape;
+       }
+
+       /**
+        * sets the instance variable for a BasicCytoShapeEntity
+        * @param shape The _cytoShape to set.
+        */
+       public void set_cytoShape(DragGestureListener shape) {
+               _cytoShape = shape;
+       }
+}

Added: 
core3/editor-impl/trunk/src/main/java/org/cytoscape/editor/internal/gui/DragSourceContextCursorSetter.java
===================================================================
--- 
core3/editor-impl/trunk/src/main/java/org/cytoscape/editor/internal/gui/DragSourceContextCursorSetter.java
                          (rev 0)
+++ 
core3/editor-impl/trunk/src/main/java/org/cytoscape/editor/internal/gui/DragSourceContextCursorSetter.java
  2010-11-21 00:58:13 UTC (rev 22965)
@@ -0,0 +1,69 @@
+/* -*-Java-*-
+********************************************************************************
+*
+* File:         DragSourceContextCurorSetter.java
+* RCS:          $Header: $
+* Description:
+* Author:       Michael L. Creech
+* Created:      Sat Dec 16 14:54:45 2006
+* Modified:     Sun Dec 17 05:41:06 2006 (Michael L. Creech) 
cre...@w235krbza760
+* Language:     Java
+* Package:
+/*
+ 
+ Copyright (c) 2006, 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications.  In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage.  See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+********************************************************************************
+*/
+package org.cytoscape.editor.internal.gui;
+
+import java.awt.Cursor;
+import java.awt.Point;
+import java.awt.dnd.DragSourceDragEvent;
+
+
+
+/**
+ * Interface used to allow a general computation to determine
+ * the cursor to show during a drag operation originating
+ * from a BasicCytoShapeEntity (palette entry) that is dragged over a
+ * CyNetworkView of interest.
+ * @author Michael L. Creech
+ */
+public interface DragSourceContextCursorSetter {
+       /**
+        * Used to determine the cursor to show during a drag operation 
originating
+        * from a BasicCytoShapeEntity (palette entry) that is dragged over a
+        * CyNetworkView of interest. For example, we might want to show that
+        * it is illegal to drop on certain objects, such as Edges.
+        * @param netView the CyNetworkView that is being dragged over.
+        * @param netViewLoc the location within netView of the cursor, in 
netView coordinates.
+        * @param dsde the DragSourceDragEvent that describes this particular
+        *        drag operation.
+        * @return the Cursor to display during this drag (e.g, 
DragSource.DefaultCopyNoDrop).
+        */
+       public Cursor computeCursor(Point netViewLoc, DragSourceDragEvent dsde);
+}

Added: 
core3/editor-impl/trunk/src/main/java/org/cytoscape/editor/internal/gui/EditorCytoPanelComponent.java
===================================================================
--- 
core3/editor-impl/trunk/src/main/java/org/cytoscape/editor/internal/gui/EditorCytoPanelComponent.java
                               (rev 0)
+++ 
core3/editor-impl/trunk/src/main/java/org/cytoscape/editor/internal/gui/EditorCytoPanelComponent.java
       2010-11-21 00:58:13 UTC (rev 22965)
@@ -0,0 +1,41 @@
+
+package org.cytoscape.editor.internal.gui;
+
+import java.awt.Component;
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+
+import org.cytoscape.application.swing.CytoPanelName;
+import org.cytoscape.application.swing.CytoPanelComponent;
+import org.cytoscape.application.swing.CySwingApplication;
+
+public class EditorCytoPanelComponent implements CytoPanelComponent {
+
+       private ShapePalette panel;
+
+       private final ImageIcon nodeIcon; 
+       private final ImageIcon edgeIcon;
+       private final ImageIcon netIcon;
+
+       public EditorCytoPanelComponent(CySwingApplication app) {
+
+               nodeIcon = new 
ImageIcon(getClass().getResource("/images/node.png"));
+               edgeIcon = new 
ImageIcon(getClass().getResource("/images/edge.png"));
+               netIcon = new 
ImageIcon(getClass().getResource("/images/network.png"));
+
+               panel = new ShapePalette();
+
+               panel.addShape(app,"NODE_TYPE","unknown", nodeIcon, "Node");
+               panel.addShape(app,"EDGE_TYPE","unknown", edgeIcon, "Edge");
+               panel.addShape(app,"NETWORK_TYPE","unknown", netIcon, 
"Network");
+       }
+
+    public Component getComponent() { return panel; }
+
+    public CytoPanelName getCytoPanelName() { return CytoPanelName.WEST; } 
+
+    public String getTitle() { return "Editor"; }
+
+    public Icon getIcon() { return null; }
+}
+

Added: 
core3/editor-impl/trunk/src/main/java/org/cytoscape/editor/internal/gui/ShapePalette.java
===================================================================
--- 
core3/editor-impl/trunk/src/main/java/org/cytoscape/editor/internal/gui/ShapePalette.java
                           (rev 0)
+++ 
core3/editor-impl/trunk/src/main/java/org/cytoscape/editor/internal/gui/ShapePalette.java
   2010-11-21 00:58:13 UTC (rev 22965)
@@ -0,0 +1,325 @@
+/* -*-Java-*-
+********************************************************************************
+*
+* File:         ShapePalette.java
+* RCS:          $Header: $
+* Description:
+* Author:       Allan Kuchinsky
+* Created:      Sun May 29 11:18:17 2005
+* Modified:     Sun Dec 17 05:33:30 2006 (Michael L. Creech) 
cre...@w235krbza760
+* Language:     Java
+* Package:
+/*
+ 
+ Copyright (c) 2006, 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications.  In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage.  See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ 
+********************************************************************************
+*
+* Revisions:
+*
+* Sun Dec 17 05:30:11 2006 (Michael L. Creech) cre...@w235krbza760
+*  Added DragSourceContextCursorSetter parameter to addShape().
+* Mon Dec 04 11:57:11 2006 (Michael L. Creech) cre...@w235krbza760
+*  Changed the JList to no longer use
+*  setFixedCellHeight() since BasicCytoShapeEntitys can now have
+*  different sizes.
+* Sun Aug 06 11:19:38 2006 (Michael L. Creech) cre...@w235krbza760
+*  Added generated serial version UUID for serializable classes.
+********************************************************************************
+*/
+package org.cytoscape.editor.internal.gui;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Color;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.swing.BorderFactory;
+import javax.swing.BoxLayout;
+import javax.swing.DefaultListModel;
+import javax.swing.Icon;
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.JEditorPane;
+import javax.swing.ListCellRenderer;
+import javax.swing.border.TitledBorder;
+
+import org.cytoscape.application.swing.CySwingApplication;
+
+/**
+ *
+ * The <b>ShapePalette</b> class implements a palette from which the user 
drags and drops shapes onto the canvas
+ * The dropping of shapes onto the canvas results in the addition of nodes and 
edges to the current Cytoscape
+ * network, as defined by the behavior of the event handler that responds to 
the drop events.  For example, in the
+ * simple "BioPAX-like" editor, there are node types for proteins, catalysis, 
small molecules, and biochemical
+ * reactions, as well as a directed edge type.
+ * <p>
+ * The user interface for the ShapePalette is built upon the JList class.
+ *
+ * @author Allan Kuchinsky
+ * @version 1.0
+ *
+ */
+public class ShapePalette extends JPanel {
+
+       private static final long serialVersionUID = -4018789452330887392L;
+
+       /**
+        * mapping of shapes to their titles
+        */
+       static Map<String, BasicCytoShapeEntity> shapeMap = new HashMap<String, 
BasicCytoShapeEntity>();
+
+       /**
+        * the user interface for the ShapePalette
+        */
+       protected JList dataList;
+       protected DefaultListModel listModel;
+       private JPanel controlPane;
+       protected JScrollPane scrollPane;
+       protected JPanel shapePane;
+
+       /**
+        * Creates a new ShapePalette object.
+        */
+       public ShapePalette() {
+               super();
+
+               controlPane = new JPanel();
+               controlPane.setLayout(new BoxLayout(controlPane, 
BoxLayout.Y_AXIS));
+               TitledBorder t2 = 
BorderFactory.createTitledBorder("Instructions:");
+               controlPane.setBorder(t2);
+               String instructions = "<html><style type='text/css'>body{ 
font-family: sans-serif; font-size: 11pt; }</style><b>Drag and Drop:</b> <ul> 
<li>A node shape onto the network view.  <li>An edge shape onto the source 
node, then click on the target node.  </ul> <b>Double-click:</b> <ul> <li>To 
add nodes and edges specified in SIF format </ul>" + 
(System.getProperty("os.name").startsWith("Mac") ? "<b>CMD-click:</b>" : 
"<b>CTRL-click:</b>") + "<ul> <li>On empty space to create a node.  <li>On a 
node to begin an edge and specify the source node. Then click on the target 
node to finish the edge.  </ul></html>";
+               
+               JEditorPane instructionsArea = new 
JEditorPane("text/html",instructions);
+               // 32767 ????
+               instructionsArea.setPreferredSize(new java.awt.Dimension(32767, 
400));
+               instructionsArea.setBackground(Color.white);
+               controlPane.add(instructionsArea);
+               controlPane.setBackground(Color.white);
+               
+               JPanel pnlSpecifyIdentifier = new JPanel();
+               pnlSpecifyIdentifier.setBackground(Color.white);
+
+               pnlSpecifyIdentifier.setMaximumSize(new 
java.awt.Dimension(32767, 100));
+               JLabel chkSpecifyLabel = new JLabel("Specify Identifier:");
+               chkSpecifyIdentifier = new javax.swing.JCheckBox();
+               chkSpecifyIdentifier.setToolTipText("Checking the box will 
allow you to choose the identifier for added nodes and edges.");
+               pnlSpecifyIdentifier.setLayout(new java.awt.GridBagLayout());
+               
pnlSpecifyIdentifier.setBorder(BorderFactory.createTitledBorder(""));
+               chkSpecifyIdentifier.addChangeListener(new 
javax.swing.event.ChangeListener() {
+                               public void 
stateChanged(javax.swing.event.ChangeEvent evt) {
+                                       
CheckBoxSpecifyIdentifierStateChanged(evt);
+                               }
+                       });
+               pnlSpecifyIdentifier.add(chkSpecifyLabel);
+               pnlSpecifyIdentifier.add(chkSpecifyIdentifier);
+               
chkSpecifyIdentifier.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 
0, 0, 0));
+               
chkSpecifyIdentifier.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
+               
chkSpecifyIdentifier.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
+               chkSpecifyIdentifier.setMargin(new java.awt.Insets(0, 0, 0, 0));
+               java.awt.GridBagConstraints gridBagConstraints = new 
java.awt.GridBagConstraints();
+               gridBagConstraints.fill = 
java.awt.GridBagConstraints.HORIZONTAL;
+               gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
+               gridBagConstraints.weightx = 1.0;
+               pnlSpecifyIdentifier.add(chkSpecifyIdentifier, 
gridBagConstraints);
+               
+               listModel = new DefaultListModel();
+               dataList = new JList(listModel);
+               dataList.setCellRenderer(new MyCellRenderer());
+               dataList.setDragEnabled(true);
+
+               dataList.setTransferHandler(new PaletteListTransferHandler());
+               shapePane = new JPanel();
+               shapePane.setBackground(Color.white); 
+               shapePane.setLayout(new BoxLayout(shapePane, BoxLayout.Y_AXIS));
+
+               scrollPane = new JScrollPane(shapePane);
+
+               scrollPane.setBorder(BorderFactory.createEtchedBorder());
+               dataList.setBackground(Color.white);
+               scrollPane.setBackground(Color.white);
+ 
+               
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
+               
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+               
+               this.setLayout(new java.awt.GridBagLayout());
+               gridBagConstraints = new java.awt.GridBagConstraints();
+               gridBagConstraints.fill = 
java.awt.GridBagConstraints.HORIZONTAL;
+               add(controlPane, gridBagConstraints);
+
+               gridBagConstraints = new java.awt.GridBagConstraints();
+               gridBagConstraints.gridy = 1;
+               gridBagConstraints.fill = 
java.awt.GridBagConstraints.HORIZONTAL;
+               add(pnlSpecifyIdentifier, gridBagConstraints);
+
+               gridBagConstraints = new java.awt.GridBagConstraints();
+               gridBagConstraints.gridy = 2;
+               gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
+               gridBagConstraints.weightx = 1.0;
+               gridBagConstraints.weighty = 1.0;
+               this.add(scrollPane, gridBagConstraints);
+
+               this.setBackground(Color.white);
+               this.setVisible(true);
+       }
+
+       private javax.swing.JCheckBox chkSpecifyIdentifier;
+       public void 
CheckBoxSpecifyIdentifierStateChanged(javax.swing.event.ChangeEvent evt){
+               if (chkSpecifyIdentifier.isSelected()){
+                       specifyIdentifier = true;
+               } else {
+                       specifyIdentifier = false;
+               }
+       }
+    
+       public static boolean specifyIdentifier = false;
+    
+       /**
+        * clear the ShapePalette by removing all its shape components
+        *
+        */
+       public void clear() {
+               shapePane.removeAll();
+       }
+
+    public void addShape(CySwingApplication app, String attributeName, String 
attributeValue, Icon img, String name) {
+        BasicCytoShapeEntity cytoShape = new BasicCytoShapeEntity(app, 
attributeName, attributeValue,
+                                                                  img, name);
+        cytoShape.setTransferHandler(new 
BasicCytoShapeTransferHandler(cytoShape, null));
+        shapeMap.put(cytoShape.getTitle(), cytoShape);
+/*
+        if (attributeName.equals(CytoscapeEditorManager.EDGE_TYPE)) {
+            
CytoscapeEditorManager.addEdgeTypeForVisualStyle(Cytoscape.getCurrentNetworkView()
+                                     .getVisualStyle(), attributeValue);
+        }
+               */
+
+        shapePane.add(cytoShape);
+    }
+
+
+       /**
+        * show the palette in the WEST cytopanel
+        *
+        */
+       public void showPalette() {
+               this.setVisible(true);
+       }
+
+    /**
+     *
+     * @param key the name of the shape to be returned
+     * @return return the BasicCytoShapeEntity associated with the input shape 
name
+     */
+    public static BasicCytoShapeEntity getBasicCytoShapeEntity(String key) {
+        Object val = shapeMap.get(key);
+
+        if (val instanceof BasicCytoShapeEntity) {
+            return ((BasicCytoShapeEntity) val);
+        } else {
+            return null;
+        }
+    }
+
+       /**
+        * renders each cell of the ShapePalette
+        * @author Allan Kuchinsky
+        * @version 1.0
+        *
+        */
+       class MyCellRenderer extends JLabel implements ListCellRenderer {
+               // This is the only method defined by ListCellRenderer.
+               // We just reconfigure the JLabel each time we're called.
+               // MLC 08/06/06:
+               private static final long serialVersionUID = 
-4704405703871398609L;
+
+               public Component getListCellRendererComponent(JList list, 
Object value, // value to display
+                                                             int index, // 
cell index
+                                                             boolean 
isSelected, // is the cell selected
+                                                             boolean 
cellHasFocus) // the list and the cell have the focus
+               {
+                       if (value instanceof BasicCytoShapeEntity) {
+                               BasicCytoShapeEntity cytoShape = 
(BasicCytoShapeEntity) value;
+                               setText(cytoShape.getTitle());
+                               setIcon(cytoShape.getIcon());
+                               setToolTipText(cytoShape.getToolTipText());
+                       }
+
+                       if (isSelected) {
+                               //setBackground(list.getSelectionBackground());
+                               setBackground(Color.white);
+                               setForeground(list.getSelectionForeground());
+                       } else {
+                               //setBackground(list.getBackground());
+                               setBackground(Color.white);
+                               setForeground(list.getForeground());
+                       }
+
+                       setEnabled(list.isEnabled());
+                       setFont(list.getFont());
+                       setOpaque(true);
+
+                       return this;
+               }
+       }
+
+       /**
+        * bundles up the name of the BasicCytoShapeEntity for export via 
drag/drop from the palette
+        * @author Allan Kuchinsky
+        * @version 1.0
+        *
+        */
+       class PaletteListTransferHandler extends StringTransferHandler {
+               // MLC 08/06/06:
+               private static final long serialVersionUID = 
-3858539899491771525L;
+
+               protected void cleanup(JComponent c, boolean remove) {
+               }
+
+               protected void importString(JComponent c, String str) {
+               }
+
+               //Bundle up the selected items in the list
+               //as a single string, for export.
+               protected String exportString(JComponent c) {
+                       JList list = (JList) c;
+                       Object val = list.getSelectedValue();
+
+                       if (val instanceof BasicCytoShapeEntity) {
+                               return ((BasicCytoShapeEntity) val).getTitle();
+                       } else {
+                               return null;
+                       }
+               }
+       }
+}

Added: 
core3/editor-impl/trunk/src/main/java/org/cytoscape/editor/internal/gui/StringTransferHandler.java
===================================================================
--- 
core3/editor-impl/trunk/src/main/java/org/cytoscape/editor/internal/gui/StringTransferHandler.java
                          (rev 0)
+++ 
core3/editor-impl/trunk/src/main/java/org/cytoscape/editor/internal/gui/StringTransferHandler.java
  2010-11-21 00:58:13 UTC (rev 22965)
@@ -0,0 +1,87 @@
+/*
+ * Created on Jun 1, 2005
+ *
+ */
+package org.cytoscape.editor.internal.gui;
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.StringSelection;
+import java.awt.datatransfer.Transferable;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.io.IOException;
+
+import javax.swing.JComponent;
+import javax.swing.TransferHandler;
+
+
+/**
+ * base class for the PaletteListTransferHandler of the ShapePalette
+ * taken from Java drag and drop tutorial, see 
http://java.sun.com/docs/books/tutorial/uiswing/misc/dnd.html
+ */
+public abstract class StringTransferHandler extends TransferHandler {
+       protected abstract String exportString(JComponent c);
+
+       protected abstract void importString(JComponent c, String str);
+
+       protected abstract void cleanup(JComponent c, boolean remove);
+
+       protected Transferable createTransferable(JComponent c) {
+               return new StringSelection(exportString(c));
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param c DOCUMENT ME!
+        *
+        * @return  DOCUMENT ME!
+        */
+       public int getSourceActions(JComponent c) {
+               return COPY_OR_MOVE;
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param c DOCUMENT ME!
+        * @param t DOCUMENT ME!
+        *
+        * @return  DOCUMENT ME!
+        */
+       public boolean importData(JComponent c, Transferable t) {
+               if (canImport(c, t.getTransferDataFlavors())) {
+                       try {
+                               String str = (String) 
t.getTransferData(DataFlavor.stringFlavor);
+                               importString(c, str);
+
+                               return true;
+                       } catch (UnsupportedFlavorException ufe) {
+                       } catch (IOException ioe) {
+                       }
+               }
+
+               return false;
+       }
+
+       protected void exportDone(JComponent c, Transferable data, int action) {
+               cleanup(c, action == MOVE);
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param c DOCUMENT ME!
+        * @param flavors DOCUMENT ME!
+        *
+        * @return  DOCUMENT ME!
+        */
+       public boolean canImport(JComponent c, DataFlavor[] flavors) {
+               for (int i = 0; i < flavors.length; i++) {
+                       if (DataFlavor.stringFlavor.equals(flavors[i])) {
+                               return true;
+                       }
+               }
+
+               return false;
+       }
+}

Modified: 
core3/editor-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
===================================================================
--- 
core3/editor-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
  2010-11-20 23:28:01 UTC (rev 22964)
+++ 
core3/editor-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
  2010-11-21 00:58:13 UTC (rev 22965)
@@ -5,7 +5,12 @@
                       http://www.springframework.org/schema/osgi 
http://www.springframework.org/schema/osgi/spring-osgi-1.0.xsd";
        default-lazy-init="false">
 
+       <osgi:reference id="cySwingApplicationServiceRef" 
+                       
interface="org.cytoscape.application.swing.CySwingApplication"/>
 
+       <osgi:service id="editorCytoPanelComponentService" 
ref="editorCytoPanelComponent"
+               interface="org.cytoscape.application.swing.CytoPanelComponent"/>
+
        <osgi:service id="sifInterpreterTaskFactoryService" 
ref="sifInterpreterTaskFactory"
                interface="org.cytoscape.task.NetworkViewTaskFactory">
         <osgi:service-properties>

Modified: 
core3/editor-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
===================================================================
--- 
core3/editor-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml   
    2010-11-20 23:28:01 UTC (rev 22964)
+++ 
core3/editor-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml   
    2010-11-21 00:58:13 UTC (rev 22965)
@@ -21,4 +21,9 @@
                
class="org.cytoscape.editor.internal.DropNodeViewTaskFactoryImpl">
        </bean>
 
+       <bean id="editorCytoPanelComponent"
+               
class="org.cytoscape.editor.internal.gui.EditorCytoPanelComponent">
+               <constructor-arg ref="cySwingApplicationServiceRef" />
+       </bean>
+
 </beans>

Added: core3/editor-impl/trunk/src/main/resources/images/edge.png
===================================================================
(Binary files differ)


Property changes on: core3/editor-impl/trunk/src/main/resources/images/edge.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: core3/editor-impl/trunk/src/main/resources/images/network.png
===================================================================
(Binary files differ)


Property changes on: 
core3/editor-impl/trunk/src/main/resources/images/network.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: core3/editor-impl/trunk/src/main/resources/images/node.png
===================================================================
(Binary files differ)


Property changes on: core3/editor-impl/trunk/src/main/resources/images/node.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

-- 
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