Author: kono
Date: 2010-12-20 16:50:53 -0800 (Mon, 20 Dec 2010)
New Revision: 23253

Added:
   
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/customgraphics/CustomGraphicsPositionCalculator.java
Modified:
   
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/Label.java
   
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/NodeView.java
   
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DGraphView.java
   
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DNodeView.java
   
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DVisualLexicon.java
   
core3/ding-presentation-impl/trunk/src/test/java/org/cytoscape/view/DVisualLexiconTest.java
Log:
Still porting custom graphics position code.

Modified: 
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/Label.java
===================================================================
--- 
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/Label.java  
    2010-12-21 00:16:04 UTC (rev 23252)
+++ 
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/Label.java  
    2010-12-21 00:50:53 UTC (rev 23253)
@@ -83,24 +83,24 @@
        public void setFont(Font aFont) ;
 
 
-       /**
-        *
-        */
-       public void setTextAnchor ( int position );
+//     /**
+//      *
+//      */
+//     public void setTextAnchor ( int position );
+//
+//     /**
+//      *
+//      */
+//     public int getTextAnchor ( );
+//
+//     /**
+//      *
+//      */
+//     public void setJustify ( int justify );
+//
+//     /**
+//      *
+//      */
+//     public int getJustify ( );
 
-       /**
-        *
-        */
-       public int getTextAnchor ( );
-
-       /**
-        *
-        */
-       public void setJustify ( int justify );
-
-       /**
-        *
-        */
-       public int getJustify ( );
-
 }

Modified: 
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/NodeView.java
===================================================================
--- 
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/NodeView.java
   2010-12-21 00:16:04 UTC (rev 23252)
+++ 
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/NodeView.java
   2010-12-21 00:50:53 UTC (rev 23253)
@@ -13,15 +13,17 @@
  * @author Rowan Christmas
  */
 public interface NodeView  extends GraphViewObject {
-       public static final int TRIANGLE = 0;
-       public static final int DIAMOND = 1;
-       public static final int ELLIPSE = 2;
-       public static final int HEXAGON = 3;
-       public static final int OCTAGON = 4;
-       public static final int PARALELLOGRAM = 5;
-       public static final int RECTANGLE = 6;
-       public static final int ROUNDED_RECTANGLE = 7;
-       public static final int VEE = 8;
+       
+       
+//     public static final int TRIANGLE = 0;
+//     public static final int DIAMOND = 1;
+//     public static final int ELLIPSE = 2;
+//     public static final int HEXAGON = 3;
+//     public static final int OCTAGON = 4;
+//     public static final int PARALELLOGRAM = 5;
+//     public static final int RECTANGLE = 6;
+//     public static final int ROUNDED_RECTANGLE = 7;
+//     public static final int VEE = 8;
 
        /**
         * @return The Node we are a view on
@@ -241,12 +243,17 @@
         * Sets what the tooltip will be for this NodeView
         */
        public void setToolTip ( String tip );
+       
+       ObjectPosition getLabelPosition();
+       void setLabelPosition(final ObjectPosition p);
 
-       public void setLabelOffsetX(double x);
-       public void setLabelOffsetY(double y);
-       public void setNodeLabelAnchor(int position);
-
-       public double getLabelOffsetX();
-       public double getLabelOffsetY();
-       public int getNodeLabelAnchor();
+       
+        
+//     public void setLabelOffsetX(double x);
+//     public void setLabelOffsetY(double y);
+//     public void setNodeLabelAnchor(int position);
+//
+//     public double getLabelOffsetX();
+//     public double getLabelOffsetY();
+//     public int getNodeLabelAnchor();
 }

Modified: 
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DGraphView.java
===================================================================
--- 
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DGraphView.java
    2010-12-21 00:16:04 UTC (rev 23252)
+++ 
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DGraphView.java
    2010-12-21 00:50:53 UTC (rev 23253)
@@ -133,6 +133,7 @@
        
        private static enum ZOrder {
                BACKGROUND_PANE, NETWORK_PANE, FOREGROUND_PANE;
+               
                int layer() {
                        if (this == BACKGROUND_PANE)
                                return -30000;
@@ -385,7 +386,7 @@
        public DGraphView(final CyNetworkView view, CyTableFactory dataFactory,
                        CyRootNetworkFactory cyRoot, UndoSupport undo,
                        SpacialIndex2DFactory spacialFactory,
-                       VisualLexicon dingLexicon,
+                       final VisualLexicon dingLexicon,
                        Map<NodeViewTaskFactory, Map> nodeViewTFs,
                        Map<EdgeViewTaskFactory, Map> edgeViewTFs,
                        Map<NetworkViewTaskFactory, Map> emptySpaceTFs,
@@ -780,7 +781,7 @@
                m_drawPersp.addNode(node);
 
                final View<CyNode> nodeViewModel = 
cyNetworkView.getNodeView(node);
-               final NodeView dNodeView = new DNodeView(this, nodeInx, 
nodeViewModel);
+               final NodeView dNodeView = new DNodeView(dingLexicon, this, 
nodeInx, nodeViewModel);
 
                m_nodeViewMap.put(nodeInx, dNodeView);
                m_spacial.insert(nodeInx, m_defaultNodeXMin, m_defaultNodeYMin,

Modified: 
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DNodeView.java
===================================================================
--- 
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DNodeView.java
     2010-12-21 00:16:04 UTC (rev 23252)
+++ 
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DNodeView.java
     2010-12-21 00:50:53 UTC (rev 23253)
@@ -42,10 +42,13 @@
 import java.awt.image.BufferedImage;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import javax.imageio.ImageIO;
@@ -60,16 +63,20 @@
 import org.cytoscape.ding.customgraphics.CyCustomGraphics;
 import org.cytoscape.ding.customgraphics.Layer;
 import org.cytoscape.ding.customgraphics.NullCustomGraphics;
+import org.cytoscape.ding.impl.customgraphics.CustomGraphicsPositionCalculator;
 import org.cytoscape.ding.impl.visualproperty.CustomGraphicsVisualProperty;
 import org.cytoscape.graph.render.immed.GraphGraphics;
 import org.cytoscape.graph.render.stateful.CustomGraphic;
 import org.cytoscape.model.CyEdge;
 import org.cytoscape.model.CyNode;
 import org.cytoscape.view.model.View;
+import org.cytoscape.view.model.VisualLexicon;
+import org.cytoscape.view.model.VisualLexiconNode;
 import org.cytoscape.view.model.VisualProperty;
 import org.cytoscape.view.presentation.property.TwoDVisualLexicon;
 
 
+
 /**
  * Ding implementation of node presentation.
  *
@@ -111,7 +118,7 @@
        static final Paint DEFAULT_LABEL_PAINT = Color.black;
        static final double DEFAULT_LABEL_WIDTH = 100.0;
 
-       final DGraphView graphView;
+       private final DGraphView graphView;
 
        static final int DEFAULT_TRANSPARENCY = 255;
 
@@ -154,26 +161,43 @@
        // use an array
        // object assuming it takes up the least amount of memory:
        private final Object[] CG_LOCK = new Object[0];
-       private final static HashSet<CustomGraphic> EMPTY_CUSTOM_GRAPHICS = new 
LinkedHashSet<CustomGraphic>(
-                       0);
+       
+       private final static Set<CustomGraphic> EMPTY_CUSTOM_GRAPHICS = new 
LinkedHashSet<CustomGraphic>(0);
 
        // View Model for this presentation.
        private final View<CyNode> nodeViewModel;
        
        // Custom Graphics layers.
-       private final Set<CustomGraphic> targets;
+       //private final Set<CustomGraphic> customGraphicsSet;
+       
+       private final Map<CyCustomGraphics, Set<CustomGraphic>> cgMap;
+       
+       private ObjectPosition labelPosition;
+       private Map<CustomGraphic, ObjectPosition> graphicsPositions;
+       
+       private final VisualLexicon lexicon;
 
        /*
         * @param inx the RootGraph index of node (a negative number).
         */
-       DNodeView(DGraphView view, int inx, View<CyNode> nv) {
-               if (view == null)
-                       throw new NullPointerException("view must never be 
null!");
+       DNodeView(final VisualLexicon lexicon, final DGraphView graphView, int 
inx, final View<CyNode> viewModel) {
+               if (graphView == null)
+                       throw new NullPointerException("View must never be 
null!");
+               if (viewModel == null)
+                       throw new NullPointerException("View model must never 
be null!");
+               if (lexicon == null)
+                       throw new NullPointerException("Lexicon must never be 
null!");
+               
+               this.lexicon = lexicon;
+               this.labelPosition = new ObjectPositionImpl();
 
-               targets = new HashSet<CustomGraphic>();
-               graphView = view;
+               // Initialize custom graphics pool.
+               cgMap = new HashMap<CyCustomGraphics, Set<CustomGraphic>>();
+               
+               this.graphView = graphView;
+               
                m_inx = inx;
-               nodeViewModel = nv;
+               nodeViewModel = viewModel;
                m_selected = false;
                m_unselectedPaint = graphView.m_nodeDetails.fillPaint(m_inx);
                m_selectedPaint = Color.yellow;
@@ -183,12 +207,8 @@
                transparency = DEFAULT_TRANSPARENCY;
        }
 
-       /**
-        * DOCUMENT ME!
-        *
-        * @return DOCUMENT ME!
-        */
-       public GraphView getGraphView() {
+       
+       @Override public GraphView getGraphView() {
                return graphView;
        }
 
@@ -197,17 +217,18 @@
         *
         * @return DOCUMENT ME!
         */
-       public CyNode getNode() {
-if (graphView == null) 
System.err.println("++++++++++++++++++++++++++++++++++++++ in 
DNodeView.getNode(): graphView is NULL!!");
+       @Override public CyNode getNode() {
                synchronized (graphView.m_lock) {
                        return graphView.networkModel.getNode(m_inx);
                }
        }
 
-       public View<CyNode> getNodeViewModel() {
+       
+       @Override public View<CyNode> getNodeViewModel() {
                return nodeViewModel;
        }
 
+       
        /**
         * DOCUMENT ME!
         *
@@ -247,9 +268,7 @@
         */
        public int getShape() {
                synchronized (graphView.m_lock) {
-                       final int nativeShape = 
graphView.m_nodeDetails.shape(m_inx);
-
-                       return nativeShape;
+                       return graphView.m_nodeDetails.shape(m_inx);
                }
        }
 
@@ -1069,32 +1088,6 @@
                }
        }
 
-//     /**
-//      * Adds a custom graphic, <EM>in draw order</EM>, to this DNodeView in a
-//      * thread-safe way. This is a convenience method that is equivalent to
-//      * calling: <CODE>
-//      *   addCustomGraphic (new CustomGraphic (shape,paint,anchor))
-//      * </CODE> except the the new CustomGraphic created is returned.
-//      *
-//      * @param shape
-//      * @param paint
-//      * @param anchor
-//      *            The int value from NodeDetails, that defines where the 
graphic
-//      *            anchor point lies on this DNodeView's extents rectangle. A
-//      *            common anchor is NodeDetails.ANCHOR_CENTER.
-//      * @since Cytoscape 2.6
-//      * @throws IllegalArgumentException
-//      *             if shape or paint are null or anchor is not in the range 
0 <=
-//      *             anchor <= NodeDetails.MAX_ANCHOR_VAL.
-//      * @return The CustomGraphic added to this DNodeView.
-//      * @see #addCustomGraphic(CustomGraphic)
-//      * @see org.cytoscape.graph.render.stateful.CustomGraphic
-//      */
-//     public CustomGraphic addCustomGraphic(Shape shape, Paint paint, int 
anchor) {
-//             CustomGraphic cg = new CustomGraphic(shape, paint, anchor);
-//             addCustomGraphic(cg);
-//             return cg;
-//     }
 
        /**
         * Adds a given CustomGraphic, <EM>in draw order</EM>, to this 
DNodeView in
@@ -1119,17 +1112,16 @@
         */
        public boolean addCustomGraphic(CustomGraphic cg) {
                boolean retVal = false;
-               // CG_RW_LOCK.writeLock().lock();
-               // if (_customGraphics == null) {
-               // _customGraphics = new LinkedHashSet<CustomGraphic>();
-               // }
-               // retVal = _customGraphics.add (cg);
-               // CG_RW_LOCK.writeLock().unlock();
                synchronized (CG_LOCK) {
                        if (_customGraphics == null) {
                                _customGraphics = new 
LinkedHashSet<CustomGraphic>();
+                               graphicsPositions = new HashMap<CustomGraphic, 
ObjectPosition>();
                        }
-                       retVal = _customGraphics.add(cg);
+                       if (_customGraphics.contains(cg))
+                               retVal = false;
+                       else {
+                               retVal = _customGraphics.add(cg);
+                       }
                }
                ensureContentChanged();
                return retVal;
@@ -1144,13 +1136,6 @@
         * @since Cytoscape 2.6
         */
        public boolean containsCustomGraphic(CustomGraphic cg) {
-               // CG_RW_LOCK.readLock().lock();
-               // boolean retVal = false;
-               // if (_customGraphics != null) {
-               // retVal = _customGraphics.contains (cg);
-               // }
-               // CG_RW_LOCK.readLock().unlock();
-               // return retVal;
                synchronized (CG_LOCK) {
                        if (_customGraphics == null) {
                                return false;
@@ -1172,25 +1157,7 @@
         * @since Cytoscape 2.6
         */
        public Iterator<CustomGraphic> customGraphicIterator() {
-               Iterator<CustomGraphic> retVal = null;
                final Iterable<CustomGraphic> toIterate;
-               // CG_RW_LOCK.readLock().lock();
-               // if (_customGraphics == null) {
-               // toIterate = EMPTY_CUSTOM_GRAPHICS;
-               // } else {
-               // toIterate = _customGraphics;
-               // }
-               // retVal = new LockingIterator<CustomGraphic>(toIterate);
-               // retVal = new Iterator<CustomGraphic>() {
-               // Iterator<? extends CustomGraphic> i = toIterate.iterator();
-               // public boolean hasNext() {return i.hasNext();}
-               // public CustomGraphic next() {return i.next();}
-               // public void remove() {
-               // throw new UnsupportedOperationException();
-               // }
-               // };
-               // CG_RW_LOCK.readLock().unlock();
-               // return retVal;
                synchronized (CG_LOCK) {
                        if (_customGraphics == null) {
                                toIterate = EMPTY_CUSTOM_GRAPHICS;
@@ -1212,20 +1179,27 @@
         */
        public boolean removeCustomGraphic(CustomGraphic cg) {
                boolean retVal = false;
-               // CG_RW_LOCK.writeLock().lock();
-               // if (_customGraphics != null) {
-               // retVal = _customGraphics.remove (cg);
-               // }
-               // CG_RW_LOCK.writeLock().unlock();
                synchronized (CG_LOCK) {
                        if (_customGraphics != null) {
                                retVal = _customGraphics.remove(cg);
+                               graphicsPositions.remove(cg);
                        }
                }
                ensureContentChanged();
                return retVal;
        }
+       
+       public void removeAllCustomGraphics() {
+               synchronized (CG_LOCK) {
+                       if (_customGraphics != null) {
+                               _customGraphics.clear();
+                               graphicsPositions.clear();
+                       }
+               }
+               ensureContentChanged();
+       }
 
+
        /**
         * A thread-safe method returning the number of custom graphics 
associated
         * with this DNodeView. If none are associated, zero is returned.
@@ -1233,17 +1207,9 @@
         * @since Cytoscape 2.6
         */
        public int getNumCustomGraphics() {
-               // CG_RW_LOCK.readLock().lock();
-               // int retVal = 0;
-               // if (_customGraphics != null) {
-               // retVal = _customGraphics.size();
-               // }
-               // CG_RW_LOCK.readLock().unlock();
-               // return retVal;
                synchronized (CG_LOCK) {
-                       if (_customGraphics == null) {
+                       if (_customGraphics == null)
                                return 0;
-                       }
                        return _customGraphics.size();
                }
        }
@@ -1308,142 +1274,142 @@
                }
        };
 
-       /**
-        * DOCUMENT ME!
-        *
-        * @param position
-        *            DOCUMENT ME!
-        */
-       public void setTextAnchor(int position) {
-               synchronized (graphView.m_lock) {
-                       graphView.m_nodeDetails.overrideLabelTextAnchor(m_inx, 
0, position);
-                       graphView.m_contentChanged = true;
-               }
-       }
+//     /**
+//      * DOCUMENT ME!
+//      *
+//      * @param position
+//      *            DOCUMENT ME!
+//      */
+//     public void setTextAnchor(int position) {
+//             synchronized (graphView.m_lock) {
+//                     graphView.m_nodeDetails.overrideLabelTextAnchor(m_inx, 
0, position);
+//                     graphView.m_contentChanged = true;
+//             }
+//     }
+//
+//     /**
+//      * DOCUMENT ME!
+//      *
+//      * @return DOCUMENT ME!
+//      */
+//     public int getTextAnchor() {
+//             synchronized (graphView.m_lock) {
+//                     return DNodeDetails.convertND2G(graphView.m_nodeDetails
+//                                     .labelTextAnchor(m_inx, 0));
+//             }
+//     }
+//
+//     /**
+//      * DOCUMENT ME!
+//      *
+//      * @param justify
+//      *            DOCUMENT ME!
+//      */
+//     public void setJustify(int justify) {
+//             synchronized (graphView.m_lock) {
+//                     graphView.m_nodeDetails.overrideLabelJustify(m_inx, 0, 
justify);
+//                     graphView.m_contentChanged = true;
+//             }
+//     }
+//
+//     /**
+//      * DOCUMENT ME!
+//      *
+//      * @return DOCUMENT ME!
+//      */
+//     public int getJustify() {
+//             synchronized (graphView.m_lock) {
+//                     return 
DNodeDetails.convertND2G(graphView.m_nodeDetails.labelJustify(
+//                                     m_inx, 0));
+//             }
+//     }
+//
+//     /**
+//      * DOCUMENT ME!
+//      *
+//      * @param x
+//      *            DOCUMENT ME!
+//      */
+//     public void setLabelOffsetX(double x) {
+//             synchronized (graphView.m_lock) {
+//                     
graphView.m_nodeDetails.overrideLabelOffsetVectorX(m_inx, 0, x);
+//                     graphView.m_contentChanged = true;
+//             }
+//     }
+//
+//     /**
+//      * DOCUMENT ME!
+//      *
+//      * @return DOCUMENT ME!
+//      */
+//     public double getLabelOffsetX() {
+//             synchronized (graphView.m_lock) {
+//                     return 
graphView.m_nodeDetails.labelOffsetVectorX(m_inx, 0);
+//             }
+//     }
+//
+//     /**
+//      * DOCUMENT ME!
+//      *
+//      * @param y
+//      *            DOCUMENT ME!
+//      */
+//     public void setLabelOffsetY(double y) {
+//             synchronized (graphView.m_lock) {
+//                     
graphView.m_nodeDetails.overrideLabelOffsetVectorY(m_inx, 0, y);
+//                     graphView.m_contentChanged = true;
+//             }
+//     }
+//
+//     /**
+//      * DOCUMENT ME!
+//      *
+//      * @return DOCUMENT ME!
+//      */
+//     public double getLabelOffsetY() {
+//             synchronized (graphView.m_lock) {
+//                     return 
graphView.m_nodeDetails.labelOffsetVectorY(m_inx, 0);
+//             }
+//     }
+//
+//     /**
+//      * DOCUMENT ME!
+//      *
+//      * @param position
+//      *            DOCUMENT ME!
+//      */
+//     public void setNodeLabelAnchor(int position) {
+//             synchronized (graphView.m_lock) {
+//                     graphView.m_nodeDetails.overrideLabelNodeAnchor(m_inx, 
0, position);
+//                     graphView.m_contentChanged = true;
+//             }
+//     }
+//
+//     /**
+//      * DOCUMENT ME!
+//      *
+//      * @return DOCUMENT ME!
+//      */
+//     public int getNodeLabelAnchor() {
+//             synchronized (graphView.m_lock) {
+//                     return DNodeDetails.convertND2G(graphView.m_nodeDetails
+//                                     .labelNodeAnchor(m_inx, 0));
+//             }
+//     }
 
-       /**
-        * DOCUMENT ME!
-        *
-        * @return DOCUMENT ME!
-        */
-       public int getTextAnchor() {
+       public double getLabelWidth() {
                synchronized (graphView.m_lock) {
-                       return DNodeDetails.convertND2G(graphView.m_nodeDetails
-                                       .labelTextAnchor(m_inx, 0));
+                       return graphView.m_nodeDetails.labelWidth(m_inx);
                }
        }
 
-       /**
-        * DOCUMENT ME!
-        *
-        * @param justify
-        *            DOCUMENT ME!
-        */
-       public void setJustify(int justify) {
+       public void setLabelWidth(double width) {
                synchronized (graphView.m_lock) {
-                       graphView.m_nodeDetails.overrideLabelJustify(m_inx, 0, 
justify);
+                       graphView.m_nodeDetails.overrideLabelWidth(m_inx, 
width);
                        graphView.m_contentChanged = true;
                }
        }
 
-       /**
-        * DOCUMENT ME!
-        *
-        * @return DOCUMENT ME!
-        */
-       public int getJustify() {
-               synchronized (graphView.m_lock) {
-                       return 
DNodeDetails.convertND2G(graphView.m_nodeDetails.labelJustify(
-                                       m_inx, 0));
-               }
-       }
-
-       /**
-        * DOCUMENT ME!
-        *
-        * @param x
-        *            DOCUMENT ME!
-        */
-       public void setLabelOffsetX(double x) {
-               synchronized (graphView.m_lock) {
-                       
graphView.m_nodeDetails.overrideLabelOffsetVectorX(m_inx, 0, x);
-                       graphView.m_contentChanged = true;
-               }
-       }
-
-       /**
-        * DOCUMENT ME!
-        *
-        * @return DOCUMENT ME!
-        */
-       public double getLabelOffsetX() {
-               synchronized (graphView.m_lock) {
-                       return 
graphView.m_nodeDetails.labelOffsetVectorX(m_inx, 0);
-               }
-       }
-
-       /**
-        * DOCUMENT ME!
-        *
-        * @param y
-        *            DOCUMENT ME!
-        */
-       public void setLabelOffsetY(double y) {
-               synchronized (graphView.m_lock) {
-                       
graphView.m_nodeDetails.overrideLabelOffsetVectorY(m_inx, 0, y);
-                       graphView.m_contentChanged = true;
-               }
-       }
-
-       /**
-        * DOCUMENT ME!
-        *
-        * @return DOCUMENT ME!
-        */
-       public double getLabelOffsetY() {
-               synchronized (graphView.m_lock) {
-                       return 
graphView.m_nodeDetails.labelOffsetVectorY(m_inx, 0);
-               }
-       }
-
-       /**
-        * DOCUMENT ME!
-        *
-        * @param position
-        *            DOCUMENT ME!
-        */
-       public void setNodeLabelAnchor(int position) {
-               synchronized (graphView.m_lock) {
-                       graphView.m_nodeDetails.overrideLabelNodeAnchor(m_inx, 
0, position);
-                       graphView.m_contentChanged = true;
-               }
-       }
-
-       /**
-        * DOCUMENT ME!
-        *
-        * @return DOCUMENT ME!
-        */
-       public int getNodeLabelAnchor() {
-               synchronized (graphView.m_lock) {
-                       return DNodeDetails.convertND2G(graphView.m_nodeDetails
-                                       .labelNodeAnchor(m_inx, 0));
-               }
-       }
-
-        public double getLabelWidth() {
-                synchronized (graphView.m_lock) {
-                        return graphView.m_nodeDetails.labelWidth(m_inx);
-                }
-        }
-
-        public void setLabelWidth(double width) {
-                synchronized (graphView.m_lock) {
-                        graphView.m_nodeDetails.overrideLabelWidth(m_inx, 
width);
-                        graphView.m_contentChanged = true;
-                }
-        }
-
        TexturePaint getNestedNetworkTexturePaint() {
                synchronized (graphView.m_lock) {
                        ++nestedNetworkPaintingDepth;
@@ -1514,7 +1480,60 @@
        public void showNestedNetwork(final boolean makeVisible) {
                nestedNetworkVisible = makeVisible;
        }
+       
+       // from Label interface
+       @Override public ObjectPosition getLabelPosition() {
+               return labelPosition;
+       }
 
+       // from Label interface
+       @Override public void setLabelPosition(final ObjectPosition p) {
+               this.labelPosition = p;
+               updateLabelPosition();
+       }
+
+       private void updateLabelPosition() {
+               synchronized (graphView.m_lock) {
+                       graphView.m_nodeDetails.overrideLabelTextAnchor(m_inx, 
0,
+                                       
labelPosition.getAnchor().getConversionConstant());
+                       graphView.m_nodeDetails.overrideLabelNodeAnchor(m_inx, 
0,
+                                       
labelPosition.getTargetAnchor().getConversionConstant());
+                       graphView.m_nodeDetails.overrideLabelJustify(m_inx, 0,
+                                       
labelPosition.getJustify().getConversionConstant());
+                       
graphView.m_nodeDetails.overrideLabelOffsetVectorX(m_inx, 0,
+                                       labelPosition.getOffsetX());
+                       
graphView.m_nodeDetails.overrideLabelOffsetVectorY(m_inx, 0,
+                                       labelPosition.getOffsetY());
+
+                       graphView.m_contentChanged = true;
+               }
+       }
+       
+       
+       public CustomGraphic setCustomGraphicsPosition(CustomGraphic cg,
+                       final ObjectPosition p) {
+               if (cg == null || p == null)
+                       throw new IllegalArgumentException(
+                                       "CustomGraphic and Position cannot be 
null.");
+
+               _customGraphics.remove(cg);
+               graphicsPositions.remove(cg);
+
+               CustomGraphic newCg = 
CustomGraphicsPositionCalculator.transform(p, this, cg);
+               
+               _customGraphics.add(newCg);
+               graphicsPositions.put(newCg, p);
+
+               return newCg;
+       }
+
+       public ObjectPosition getCustomGraphicsPosition(final CustomGraphic cg) 
{
+               if (cg == null)
+                       return ObjectPositionImpl.DEFAULT_POSITION;
+
+               return graphicsPositions.get(cg);
+       }
+
        @Override
        public void setVisualPropertyValue(VisualProperty<?> vp, Object value) {
 
@@ -1557,35 +1576,38 @@
                        setFont((Font) value);
                } else if (vp == DVisualLexicon.NODE_LABEL_FONT_SIZE) {
                        setFont(getFont().deriveFont(((Integer) 
value).floatValue()));
-//             } else if (vp == DVisualLexicon.NODE_LABEL_ANCHOR_X_OFFSET) {
-//                     setLabelOffsetX(((Double) value).doubleValue());
-//             } else if (vp == DVisualLexicon.NODE_LABEL_ANCHOR_Y_OFFSET) {
-//                     setLabelOffsetY(((Double) value).doubleValue());
-//             } else if (vp == DVisualLexicon.NODE_LABEL_JUSTIFY) {
-//                     setJustify(((Justify) value).getNativeValue());
                } else if (vp == DVisualLexicon.NODE_LABEL_POSITION) {
                        //FIXME
                        final ObjectPosition op = (ObjectPosition) value;
-                       setTextAnchor(op.getAnchor().getConversionConstant());
-                       
setNodeLabelAnchor(op.getTargetAnchor().getConversionConstant());
-                       setJustify(op.getJustify().getConversionConstant());
-                       setLabelOffsetX(op.getOffsetX());
-                       setLabelOffsetY(op.getOffsetY());
+                       this.setLabelPosition(op);
+//                     setTextAnchor(op.getAnchor().getConversionConstant());
+//                     
setNodeLabelAnchor(op.getTargetAnchor().getConversionConstant());
+//                     setJustify(op.getJustify().getConversionConstant());
+//                     setLabelOffsetX(op.getOffsetX());
+//                     setLabelOffsetY(op.getOffsetY());
                } else if(vp instanceof CustomGraphicsVisualProperty) {
-                       final CyCustomGraphics cg = (CyCustomGraphics) value;
-                       applyCustomGraphics(cg);
+                       applyCustomGraphics((CyCustomGraphics) value);
+               } else if(DVisualLexicon.getGraphicsPositionVP().contains(vp)) {
+                       System.out.print("Applying CG Position: " + 
vp.getDisplayName());
+                       System.out.println(" Value = " + value);
+                       applyCustomGraphicsPosition(vp, (ObjectPosition) value);
                }
        }
        
        
        private void applyCustomGraphics(final CyCustomGraphics customGraphics) 
{
 
+               Set<CustomGraphic> dCustomGraphicsSet = 
cgMap.get(customGraphics);
+               
                // Remove current layers associated with this Custom Graphics
-               if (targets.size() != 0) {
-                       for (CustomGraphic cg : targets)
+               if(dCustomGraphicsSet == null) {
+                       dCustomGraphicsSet = new HashSet<CustomGraphic>();
+                       cgMap.put(customGraphics, dCustomGraphicsSet);
+               } else if (dCustomGraphicsSet.size() != 0) {
+                       for (CustomGraphic cg : dCustomGraphicsSet)
                                removeCustomGraphic(cg);
 
-                       targets.clear();
+                       dCustomGraphicsSet.clear();
                }
 
                // For these cases, remove current layers.
@@ -1617,7 +1639,7 @@
 //                             targets.add(resized);
 //                     } else {
                                addCustomGraphic(cg);
-                               targets.add(cg);
+                               dCustomGraphicsSet.add(cg);
 //                     }
                }
                //this.currentMap.put(dv, targets);
@@ -1625,5 +1647,43 @@
                // Flag this as used Custom Graphics
                
//Cytoscape.getVisualMappingManager().getCustomGraphicsManager().setUsedInCurrentSession(graphics,
 true);
        }
+       
+       private void applyCustomGraphicsPosition(final VisualProperty<?> vp, 
final ObjectPosition position) {
 
+               // No need to modify
+               if (position == null)
+                       return;
+               
+               // Use dependency to retrieve its parent.
+               VisualLexiconNode lexNode = lexicon.getVisualLexiconNode(vp);
+               final Collection<VisualLexiconNode> leavs = 
lexNode.getParent().getChildren();
+               
+               VisualProperty<?> parent = null;
+               for(VisualLexiconNode vlNode:leavs) {
+                       
if(vlNode.getVisualProperty().getRange().getType().equals(CyCustomGraphics.class))
 {
+                               parent = vlNode.getVisualProperty();
+                               break;
+                       }
+               }
+               
+               if(parent == null)
+                       throw new NullPointerException("Associated Custom 
Graphics VP is missing for " + vp.getDisplayName());
+               
+               final Set<CustomGraphic> currentCG = cgMap.get(parent);
+               
+               if (currentCG == null || currentCG.size() == 0) {
+                       // Ignore if no CG is available.
+                       return;
+               }
+
+               final List<CustomGraphic> newList = new 
ArrayList<CustomGraphic>();
+               for (CustomGraphic g : currentCG) {
+                       newList.add(this.setCustomGraphicsPosition(g, 
position));
+                       this.removeCustomGraphic(g);
+               }
+
+               currentCG.clear();
+               currentCG.addAll(newList);
+       }
+
 }

Modified: 
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DVisualLexicon.java
===================================================================
--- 
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DVisualLexicon.java
        2010-12-21 00:16:04 UTC (rev 23252)
+++ 
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DVisualLexicon.java
        2010-12-21 00:50:53 UTC (rev 23253)
@@ -38,6 +38,8 @@
 import java.awt.Font;
 import java.awt.Paint;
 import java.awt.Stroke;
+import java.util.HashSet;
+import java.util.Set;
 
 import org.cytoscape.ding.ArrowShape;
 import org.cytoscape.ding.NodeShape;
@@ -58,7 +60,9 @@
 import org.cytoscape.model.CyNode;
 import org.cytoscape.view.model.NullDataType;
 import org.cytoscape.view.model.VisualProperty;
+import org.cytoscape.view.model.Visualizable;
 import org.cytoscape.view.presentation.property.BooleanVisualProperty;
+import 
org.cytoscape.view.presentation.property.DefaultVisualizableVisualProperty;
 import org.cytoscape.view.presentation.property.DoubleVisualProperty;
 import org.cytoscape.view.presentation.property.NullVisualProperty;
 import org.cytoscape.view.presentation.property.PaintVisualProperty;
@@ -71,6 +75,8 @@
        private static final int DEF_FONT_SIZE = 12;
        private static final double DEF_BORDER_WIDTH = 2.0d;
        
+       private static final Set<VisualProperty<?>> CG_POSITIONS = new 
HashSet<VisualProperty<?>>();
+       
        // Root of Ding's VP tree.
        public static final VisualProperty<NullDataType> DING_ROOT = new 
NullVisualProperty(
                        "DING_RENDERING_ENGINE_ROOT", "Ding Rndering Engine 
Root Visual Property");
@@ -111,10 +117,76 @@
                        200, "NODE_TRANSPARENCY", "Node Transparency", 
CyNode.class);
        
        
+       // Range object for custom graphics.
        private static final CustomGraphicsRange CG_RANGE = new 
CustomGraphicsRange();
+       
+       public static final VisualProperty<Visualizable> NODE_CUSTOMPAINT_1 = 
new DefaultVisualizableVisualProperty(
+                       "NODE_CUSTOMPAINT_1", "Node Custom Paint 1", 
CyNode.class);
+       public static final VisualProperty<Visualizable> NODE_CUSTOMPAINT_2 = 
new DefaultVisualizableVisualProperty(
+                       "NODE_CUSTOMPAINT_2", "Node Custom Paint 2", 
CyNode.class);
+       public static final VisualProperty<Visualizable> NODE_CUSTOMPAINT_3 = 
new DefaultVisualizableVisualProperty(
+                       "NODE_CUSTOMPAINT_3", "Node Custom Paint 3", 
CyNode.class);
+       public static final VisualProperty<Visualizable> NODE_CUSTOMPAINT_4 = 
new DefaultVisualizableVisualProperty(
+                       "NODE_CUSTOMPAINT_4", "Node Custom Paint 4", 
CyNode.class);
+       public static final VisualProperty<Visualizable> NODE_CUSTOMPAINT_5 = 
new DefaultVisualizableVisualProperty(
+                       "NODE_CUSTOMPAINT_5", "Node Custom Paint 5", 
CyNode.class);
+       public static final VisualProperty<Visualizable> NODE_CUSTOMPAINT_6 = 
new DefaultVisualizableVisualProperty(
+                       "NODE_CUSTOMPAINT_6", "Node Custom Paint 6", 
CyNode.class);
+       public static final VisualProperty<Visualizable> NODE_CUSTOMPAINT_7 = 
new DefaultVisualizableVisualProperty(
+                       "NODE_CUSTOMPAINT_7", "Node Custom Paint 7", 
CyNode.class);
+       public static final VisualProperty<Visualizable> NODE_CUSTOMPAINT_8 = 
new DefaultVisualizableVisualProperty(
+                       "NODE_CUSTOMPAINT_8", "Node Custom Paint 8", 
CyNode.class);
+       public static final VisualProperty<Visualizable> NODE_CUSTOMPAINT_9 = 
new DefaultVisualizableVisualProperty(
+                       "NODE_CUSTOMPAINT_9", "Node Custom Paint 9", 
CyNode.class);
+       
+       
        public static final VisualProperty<CyCustomGraphics> 
NODE_CUSTOMGRAPHICS_1 = new CustomGraphicsVisualProperty(
                        NullCustomGraphics.getNullObject(), CG_RANGE, 
"NODE_CUSTOMGRAPHICS_1", "Node Custom Graphics 1", CyNode.class);
+       public static final VisualProperty<CyCustomGraphics> 
NODE_CUSTOMGRAPHICS_2 = new CustomGraphicsVisualProperty(
+                       NullCustomGraphics.getNullObject(), CG_RANGE, 
"NODE_CUSTOMGRAPHICS_2", "Node Custom Graphics 2", CyNode.class);
+       public static final VisualProperty<CyCustomGraphics> 
NODE_CUSTOMGRAPHICS_3 = new CustomGraphicsVisualProperty(
+                       NullCustomGraphics.getNullObject(), CG_RANGE, 
"NODE_CUSTOMGRAPHICS_3", "Node Custom Graphics 3", CyNode.class);
+       public static final VisualProperty<CyCustomGraphics> 
NODE_CUSTOMGRAPHICS_4 = new CustomGraphicsVisualProperty(
+                       NullCustomGraphics.getNullObject(), CG_RANGE, 
"NODE_CUSTOMGRAPHICS_4", "Node Custom Graphics 4", CyNode.class);
+       public static final VisualProperty<CyCustomGraphics> 
NODE_CUSTOMGRAPHICS_5 = new CustomGraphicsVisualProperty(
+                       NullCustomGraphics.getNullObject(), CG_RANGE, 
"NODE_CUSTOMGRAPHICS_5", "Node Custom Graphics 5", CyNode.class);
+       public static final VisualProperty<CyCustomGraphics> 
NODE_CUSTOMGRAPHICS_6 = new CustomGraphicsVisualProperty(
+                       NullCustomGraphics.getNullObject(), CG_RANGE, 
"NODE_CUSTOMGRAPHICS_6", "Node Custom Graphics 6", CyNode.class);
+       public static final VisualProperty<CyCustomGraphics> 
NODE_CUSTOMGRAPHICS_7 = new CustomGraphicsVisualProperty(
+                       NullCustomGraphics.getNullObject(), CG_RANGE, 
"NODE_CUSTOMGRAPHICS_7", "Node Custom Graphics 7", CyNode.class);
+       public static final VisualProperty<CyCustomGraphics> 
NODE_CUSTOMGRAPHICS_8 = new CustomGraphicsVisualProperty(
+                       NullCustomGraphics.getNullObject(), CG_RANGE, 
"NODE_CUSTOMGRAPHICS_8", "Node Custom Graphics 8", CyNode.class);
+       public static final VisualProperty<CyCustomGraphics> 
NODE_CUSTOMGRAPHICS_9 = new CustomGraphicsVisualProperty(
+                       NullCustomGraphics.getNullObject(), CG_RANGE, 
"NODE_CUSTOMGRAPHICS_9", "Node Custom Graphics 9", CyNode.class);
        
+       // Location of custom graphics
+       public static final VisualProperty<ObjectPosition> 
NODE_CUSTOMGRAPHICS_POSITION_1 = new ObjectPositionVisualProperty(
+                       ObjectPositionImpl.DEFAULT_POSITION, 
"NODE_CUSTOMGRAPHICS_POSITION_1",
+                       "Node Custom Graphics Position 1", CyNode.class);
+       public static final VisualProperty<ObjectPosition> 
NODE_CUSTOMGRAPHICS_POSITION_2 = new ObjectPositionVisualProperty(
+                       ObjectPositionImpl.DEFAULT_POSITION, 
"NODE_CUSTOMGRAPHICS_POSITION_2",
+                       "Node Custom Graphics Position 2", CyNode.class);
+       public static final VisualProperty<ObjectPosition> 
NODE_CUSTOMGRAPHICS_POSITION_3 = new ObjectPositionVisualProperty(
+                       ObjectPositionImpl.DEFAULT_POSITION, 
"NODE_CUSTOMGRAPHICS_POSITION_3",
+                       "Node Custom Graphics Position 3", CyNode.class);
+       public static final VisualProperty<ObjectPosition> 
NODE_CUSTOMGRAPHICS_POSITION_4 = new ObjectPositionVisualProperty(
+                       ObjectPositionImpl.DEFAULT_POSITION, 
"NODE_CUSTOMGRAPHICS_POSITION_4",
+                       "Node Custom Graphics Position 4", CyNode.class);
+       public static final VisualProperty<ObjectPosition> 
NODE_CUSTOMGRAPHICS_POSITION_5 = new ObjectPositionVisualProperty(
+                       ObjectPositionImpl.DEFAULT_POSITION, 
"NODE_CUSTOMGRAPHICS_POSITION_5",
+                       "Node Custom Graphics Position 5", CyNode.class);
+       public static final VisualProperty<ObjectPosition> 
NODE_CUSTOMGRAPHICS_POSITION_6 = new ObjectPositionVisualProperty(
+                       ObjectPositionImpl.DEFAULT_POSITION, 
"NODE_CUSTOMGRAPHICS_POSITION_6",
+                       "Node Custom Graphics Position 6", CyNode.class);
+       public static final VisualProperty<ObjectPosition> 
NODE_CUSTOMGRAPHICS_POSITION_7 = new ObjectPositionVisualProperty(
+                       ObjectPositionImpl.DEFAULT_POSITION, 
"NODE_CUSTOMGRAPHICS_POSITION_7",
+                       "Node Custom Graphics Position 7", CyNode.class);
+       public static final VisualProperty<ObjectPosition> 
NODE_CUSTOMGRAPHICS_POSITION_8 = new ObjectPositionVisualProperty(
+                       ObjectPositionImpl.DEFAULT_POSITION, 
"NODE_CUSTOMGRAPHICS_POSITION_8",
+                       "Node Custom Graphics Position 8", CyNode.class);
+       public static final VisualProperty<ObjectPosition> 
NODE_CUSTOMGRAPHICS_POSITION_9 = new ObjectPositionVisualProperty(
+                       ObjectPositionImpl.DEFAULT_POSITION, 
"NODE_CUSTOMGRAPHICS_POSITION_9",
+                       "Node Custom Graphics Position 9", CyNode.class);
 
        
        // Edge VPs
@@ -157,6 +229,18 @@
                        ObjectPositionImpl.DEFAULT_POSITION, 
"EDGE_LABEL_POSITION",
                        "Edge Label Position", CyEdge.class);
        
+       static {
+               CG_POSITIONS.add(NODE_CUSTOMGRAPHICS_POSITION_1);
+               CG_POSITIONS.add(NODE_CUSTOMGRAPHICS_POSITION_2);
+               CG_POSITIONS.add(NODE_CUSTOMGRAPHICS_POSITION_3);
+               CG_POSITIONS.add(NODE_CUSTOMGRAPHICS_POSITION_4);
+               CG_POSITIONS.add(NODE_CUSTOMGRAPHICS_POSITION_5);
+               CG_POSITIONS.add(NODE_CUSTOMGRAPHICS_POSITION_6);
+               CG_POSITIONS.add(NODE_CUSTOMGRAPHICS_POSITION_7);
+               CG_POSITIONS.add(NODE_CUSTOMGRAPHICS_POSITION_8);
+               CG_POSITIONS.add(NODE_CUSTOMGRAPHICS_POSITION_9);
+       }
+       
 
        public DVisualLexicon(final CustomGraphicsManager manager) {
                super(DING_ROOT);
@@ -181,8 +265,40 @@
                addVisualProperty(NODE_BORDER_STROKE, NODE);
                addVisualProperty(NODE_TRANSPARENCY, NODE);
                
-               addVisualProperty(NODE_CUSTOMGRAPHICS_1, NODE_PAINT);
                
+               //
+               addVisualProperty(NODE_CUSTOMPAINT_1, NODE_PAINT);
+               addVisualProperty(NODE_CUSTOMPAINT_2, NODE_PAINT);
+               addVisualProperty(NODE_CUSTOMPAINT_3, NODE_PAINT);
+               addVisualProperty(NODE_CUSTOMPAINT_4, NODE_PAINT);
+               addVisualProperty(NODE_CUSTOMPAINT_5, NODE_PAINT);
+               addVisualProperty(NODE_CUSTOMPAINT_6, NODE_PAINT);
+               addVisualProperty(NODE_CUSTOMPAINT_7, NODE_PAINT);
+               addVisualProperty(NODE_CUSTOMPAINT_8, NODE_PAINT);
+               addVisualProperty(NODE_CUSTOMPAINT_9, NODE_PAINT);
+               
+               // Custom Graphics.  Currently Cytoscape supports 9 
objects/node.
+               addVisualProperty(NODE_CUSTOMGRAPHICS_1, NODE_CUSTOMPAINT_1);
+               addVisualProperty(NODE_CUSTOMGRAPHICS_2, NODE_CUSTOMPAINT_2);
+               addVisualProperty(NODE_CUSTOMGRAPHICS_3, NODE_CUSTOMPAINT_3);
+               addVisualProperty(NODE_CUSTOMGRAPHICS_4, NODE_CUSTOMPAINT_4);
+               addVisualProperty(NODE_CUSTOMGRAPHICS_5, NODE_CUSTOMPAINT_5);
+               addVisualProperty(NODE_CUSTOMGRAPHICS_6, NODE_CUSTOMPAINT_6);
+               addVisualProperty(NODE_CUSTOMGRAPHICS_7, NODE_CUSTOMPAINT_7);
+               addVisualProperty(NODE_CUSTOMGRAPHICS_8, NODE_CUSTOMPAINT_8);
+               addVisualProperty(NODE_CUSTOMGRAPHICS_9, NODE_CUSTOMPAINT_9);
+               
+               // These are children of NODE_CUSTOMGRAPHICS.
+               addVisualProperty(NODE_CUSTOMGRAPHICS_POSITION_1, 
NODE_CUSTOMPAINT_1);
+               addVisualProperty(NODE_CUSTOMGRAPHICS_POSITION_2, 
NODE_CUSTOMPAINT_2);
+               addVisualProperty(NODE_CUSTOMGRAPHICS_POSITION_3, 
NODE_CUSTOMPAINT_3);
+               addVisualProperty(NODE_CUSTOMGRAPHICS_POSITION_4, 
NODE_CUSTOMPAINT_4);
+               addVisualProperty(NODE_CUSTOMGRAPHICS_POSITION_5, 
NODE_CUSTOMPAINT_5);
+               addVisualProperty(NODE_CUSTOMGRAPHICS_POSITION_6, 
NODE_CUSTOMPAINT_6);
+               addVisualProperty(NODE_CUSTOMGRAPHICS_POSITION_7, 
NODE_CUSTOMPAINT_7);
+               addVisualProperty(NODE_CUSTOMGRAPHICS_POSITION_8, 
NODE_CUSTOMPAINT_8);
+               addVisualProperty(NODE_CUSTOMGRAPHICS_POSITION_9, 
NODE_CUSTOMPAINT_9);
+               
                addVisualProperty(EDGE_SELECTED_PAINT, EDGE_PAINT);
                addVisualProperty(EDGE_STROKE, EDGE);
                addVisualProperty(EDGE_SOURCE_ARROW_SELECTED_PAINT, EDGE_PAINT);
@@ -194,8 +310,10 @@
                addVisualProperty(EDGE_TOOLTIP, EDGE_TEXT);
                addVisualProperty(EDGE_LABEL_POSITION, EDGE);
                addVisualProperty(EDGE_LABEL_FONT_FACE, EDGE);
-               addVisualProperty(EDGE_LABEL_FONT_SIZE, EDGE);
-               
-               
+               addVisualProperty(EDGE_LABEL_FONT_SIZE, EDGE);  
        }
+       
+       static Set<VisualProperty<?>> getGraphicsPositionVP() {
+               return CG_POSITIONS;
+       }
 }

Added: 
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/customgraphics/CustomGraphicsPositionCalculator.java
===================================================================
--- 
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/customgraphics/CustomGraphicsPositionCalculator.java
                               (rev 0)
+++ 
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/customgraphics/CustomGraphicsPositionCalculator.java
       2010-12-21 00:50:53 UTC (rev 23253)
@@ -0,0 +1,72 @@
+package org.cytoscape.ding.impl.customgraphics;
+
+import java.awt.Shape;
+import java.awt.geom.AffineTransform;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.cytoscape.ding.ObjectPosition;
+import org.cytoscape.ding.Position;
+import org.cytoscape.ding.impl.DNodeView;
+import org.cytoscape.graph.render.stateful.CustomGraphic;
+import org.cytoscape.graph.render.stateful.PaintFactory;
+
+public class CustomGraphicsPositionCalculator {
+       
+       /**
+        * Defines displacement.
+        */
+       private static final Map<Position, Float[]> DISPLACEMENT_MAP;
+       
+       static {
+               DISPLACEMENT_MAP = new HashMap<Position, Float[]>();
+               
+               DISPLACEMENT_MAP.put(Position.CENTER, new Float[]{0f, 0f} );
+               
+               DISPLACEMENT_MAP.put(Position.NORTH,  new Float[]{0f, -0.5f});
+               DISPLACEMENT_MAP.put(Position.NORTH_WEST, new Float[]{-0.5f, 
-0.5f});
+               DISPLACEMENT_MAP.put(Position.NORTH_EAST, new Float[]{0.5f, 
-0.5f});
+               
+               DISPLACEMENT_MAP.put(Position.SOUTH,  new Float[]{0f, 0.5f});
+               DISPLACEMENT_MAP.put(Position.SOUTH_WEST,  new Float[]{-0.5f, 
0.5f});
+               DISPLACEMENT_MAP.put(Position.SOUTH_EAST,  new Float[]{0.5f, 
0.5f});
+               
+               DISPLACEMENT_MAP.put(Position.WEST,  new Float[]{-0.5f, 0f});
+               
+               DISPLACEMENT_MAP.put(Position.EAST,  new Float[]{0.5f, 0f});
+       }
+       
+       
+       
+       public static CustomGraphic transform(final ObjectPosition p, final 
DNodeView nv, CustomGraphic cg) {           
+               final Position anc = p.getAnchor();
+               final Position ancN = p.getTargetAnchor();
+               
+               final double nodeW = nv.getWidth();
+               final double nodeH = nv.getHeight();
+               final double cgW = cg.getShape().getBounds().getWidth();
+               final double cgH = cg.getShape().getBounds().getHeight();
+               
+               final Float[] disp1 = DISPLACEMENT_MAP.get(anc);
+               final Float[] disp2 = DISPLACEMENT_MAP.get(ancN);
+               
+               // 1. Displacement for graphics
+               final double dispX = -disp1[0] * nodeW;
+               final double dispY = -disp1[1] * nodeH;
+               
+               final double dispNX = disp2[0] * cgW;
+               final double dispNY = disp2[1] * cgH;
+               
+               // calc total and apply transform
+               double totalDispX = dispX + dispNX + p.getOffsetX();
+               double totalDispY = dispY + dispNY + p.getOffsetY();
+               
+               final AffineTransform tf = 
AffineTransform.getTranslateInstance(totalDispX, totalDispY);
+               final Shape newShape = tf.createTransformedShape(cg.getShape());
+               
+               final PaintFactory newFactory = cg.getPaintFactory();
+               
+               return new CustomGraphic(newShape, newFactory); 
+               
+       }
+}

Modified: 
core3/ding-presentation-impl/trunk/src/test/java/org/cytoscape/view/DVisualLexiconTest.java
===================================================================
--- 
core3/ding-presentation-impl/trunk/src/test/java/org/cytoscape/view/DVisualLexiconTest.java
 2010-12-21 00:16:04 UTC (rev 23252)
+++ 
core3/ding-presentation-impl/trunk/src/test/java/org/cytoscape/view/DVisualLexiconTest.java
 2010-12-21 00:50:53 UTC (rev 23253)
@@ -6,7 +6,6 @@
 
 import org.cytoscape.ding.customgraphics.CustomGraphicsManager;
 import org.cytoscape.ding.impl.DVisualLexicon;
-import org.cytoscape.view.model.CyNetworkView;
 import org.cytoscape.view.model.NullDataType;
 import org.cytoscape.view.model.VisualLexicon;
 import org.cytoscape.view.model.VisualProperty;
@@ -39,7 +38,7 @@
 
                assertEquals(1, 
dLexicon.getVisualLexiconNode(root).getChildren().size());
                
-               assertEquals(61, dLexicon.getAllVisualProperties().size());
+               assertEquals(87, dLexicon.getAllVisualProperties().size());
        }
 
        @Test

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