Author: scooter
Date: 2012-05-14 16:16:01 -0700 (Mon, 14 May 2012)
New Revision: 29265

Modified:
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/CyActivator.java
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/ArbitraryGraphicsCanvas.java
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DGraphView.java
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/InternalFrameComponent.java
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/CyAnnotator.java
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/Annotation.java
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/ImageAnnotation.java
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/ShapeAnnotation.java
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/TextAnnotation.java
Log:
Annotations work in progress.  Can now save and restore annotations, but still 
don't have
things working right with the BirdsEyeView. 


Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/CyActivator.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/CyActivator.java
 2012-05-14 23:14:31 UTC (rev 29264)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/CyActivator.java
 2012-05-14 23:16:01 UTC (rev 29265)
@@ -145,8 +145,13 @@
                EdgeBendEditor edgeBendEditor = new 
EdgeBendEditor(edgeBendValueEditor);
 
                AnnotationFactory imageAnnotationFactory = new 
ImageAnnotationFactory(customGraphicsManagerServiceRef);
+               
annotationFactoryManager.addAnnotationFactory(imageAnnotationFactory, null);
+
                AnnotationFactory shapeAnnotationFactory = new 
ShapeAnnotationFactory();
+               
annotationFactoryManager.addAnnotationFactory(shapeAnnotationFactory, null);
+
                AnnotationFactory textAnnotationFactory = new 
TextAnnotationFactory();
+               
annotationFactoryManager.addAnnotationFactory(textAnnotationFactory, null);
 
                AddAnnotationTaskFactory addImageTaskFactory = new 
AddAnnotationTaskFactory(imageAnnotationFactory);
                AddAnnotationTaskFactory addShapeTaskFactory = new 
AddAnnotationTaskFactory(shapeAnnotationFactory);

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/ArbitraryGraphicsCanvas.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/ArbitraryGraphicsCanvas.java
        2012-05-14 23:14:31 UTC (rev 29264)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/ArbitraryGraphicsCanvas.java
        2012-05-14 23:16:01 UTC (rev 29265)
@@ -44,6 +44,7 @@
 import java.util.Map;
 
 import org.cytoscape.ding.impl.events.ViewportChangeListener;
+import org.cytoscape.ding.impl.cyannotator.annotations.Annotation;
 import org.cytoscape.model.CyNetwork;
 import org.cytoscape.model.CyNode;
 
@@ -123,7 +124,11 @@
                m_componentToPointMap.put(component, nodePos);
 
                // do our stuff
-               return super.add(component);
+               Component c = super.add(component);
+
+               contentChanged();
+
+               return c;
        }
 
        /**
@@ -134,6 +139,8 @@
                m_componentToPointMap.remove(component);
 
                super.remove(component);
+
+               contentChanged();
        }
         
        /**
@@ -156,6 +163,8 @@
 
                nodePos.x=(int)nodeCanvasCoordinates[0];
                nodePos.y=(int)nodeCanvasCoordinates[1];
+
+               contentChanged();
        }
 
        /**
@@ -219,9 +228,65 @@
                return true;
        }
 
-       public void drawCanvas(VolatileImage image, double xCenter, double 
yCenter, double scaleFactor) {
+       public void drawCanvas(VolatileImage image, double xCenter, double 
yCenter, 
+                              double scaleFactor) {
+/*
                // get image graphics
                final Graphics2D image2D = image.createGraphics();
+               System.out.println("drawCanvas: new scaleFactor = 
"+scaleFactor+", xCenter = "+xCenter+", yCenter = "+yCenter);
+               double x = m_dGraphView.m_networkCanvas.m_xCenter;
+               double y = m_dGraphView.m_networkCanvas.m_yCenter;
+               double deltaX = x-xCenter;
+               double deltaY = y-yCenter;
+               System.out.println("drawCanvas: xCenter = "+x+", yCenter = "+y);
+
+               // get list of child components
+               Component[] components = getComponents();
+
+               // no components, outta here
+               if (components.length == 0)
+                       return;
+
+               // interate through the components
+               for (Component c : components) {
+                       // get position of this component in network coordinates
+                       Point position = m_componentToPointMap.get(c);
+                       int xOrig = position.x;
+                       int yOrig = position.y;
+
+                       final double[] nodeCanvasCoordinates = new double[2];
+                       nodeCanvasCoordinates[0] = position.getX();
+                       nodeCanvasCoordinates[1] = position.getY();
+                       System.out.println("   component is at: 
"+position.getX()+","+position.getY());
+
+                       // Scale & Translate
+                       nodeCanvasCoordinates[0] = 
(nodeCanvasCoordinates[0]+deltaX) * scaleFactor;
+                       nodeCanvasCoordinates[1] = 
(nodeCanvasCoordinates[1]+deltaY) * scaleFactor;
+
+                       // Move it into position
+                       c.setLocation((int)nodeCanvasCoordinates[0], 
(int)nodeCanvasCoordinates[1]);
+
+                       System.out.println("   transformed component is at: 
"+nodeCanvasCoordinates[0]+","+nodeCanvasCoordinates[1]);
+
+                       // If we're painting an annotation, set the zoom
+                       if (c instanceof Annotation) {
+                               Annotation a = (Annotation)c;
+                               double zoom = a.getZoom();
+                               // a.adjustZoom(scaleFactor);
+                               a.paint(image2D);
+                               // a.adjustZoom(zoom);
+                       } else {
+                               c.paint(image2D);
+                       }
+
+                       // Move it back
+                       position.x = xOrig;
+                       position.y = yOrig;
+                       c.setLocation(xOrig, yOrig);
+                       System.out.println("   done");
+               }
+               System.out.println("drawCanvas: done");
+*/
        }
 
        /**
@@ -331,4 +396,11 @@
                image2D.fillRect(0, 0, m_img.getWidth(null), 
m_img.getHeight(null));
                image2D.setComposite(origComposite);
        }
+
+       private void contentChanged() {
+               ContentChangeListener lis = m_dGraphView.m_cLis[0];
+
+               if (lis != null)
+                       lis.contentChanged();
+       }
 }

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DGraphView.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DGraphView.java
     2012-05-14 23:14:31 UTC (rev 29264)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/DGraphView.java
     2012-05-14 23:16:01 UTC (rev 29265)
@@ -44,6 +44,7 @@
 import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
 import java.awt.image.BufferedImage;
+import java.awt.image.VolatileImage;
 import java.awt.print.PageFormat;
 import java.awt.print.Printable;
 import java.io.ByteArrayInputStream;
@@ -178,8 +179,6 @@
        static final Paint DEFAULT_ANCHOR_SELECTED_PAINT = Color.red;
        static final Paint DEFAULT_ANCHOR_UNSELECTED_PAINT = Color.DARK_GRAY;
 
-       boolean calledFromGetSnapshot = false;
-       
        private final CyEventHelper cyEventHelper;
 
        // Size of snapshot image
@@ -401,7 +400,10 @@
        private final NodeViewDefaultSupport m_nodeViewDefaultSupport;
        private final EdgeViewDefaultSupport m_edgeViewDefaultSupport;
        private final CyAnnotator cyAnnotator;
+       private final AnnotationFactoryManager annMgr;
 
+       private boolean annotationsLoaded = false;
+
        /**
         * Create presentation from View Model
         * 
@@ -461,6 +463,7 @@
                
                this.manager = manager;
                this.cyEventHelper = cyEventHelper;
+               this.annMgr = annMgr;
 
                // creating empty subnetworks
                m_drawPersp = cyRoot.getRootNetwork(model).addSubNetwork();
@@ -504,9 +507,11 @@
                // Used to synchronize ding's internal selection state with the 
rest of Cytoscape.
                new FlagAndSelectionHandler(this); 
 
-               cyAnnotator = new CyAnnotator(this,annMgr);
                logger.debug("Phase 4: Everything created: time = " + 
(System.currentTimeMillis() - start));
                setGraphLOD(dingGraphLOD);
+
+               // Finally, intialize our annotations
+               this.cyAnnotator = new CyAnnotator(this, annMgr);
        }
 
        
@@ -1121,10 +1126,6 @@
                                                      ((double) 
m_networkCanvas.getHeight()) / 
                                                     (m_extentsBuffD[3] - 
m_extentsBuffD[1])) * 0.98;
                        m_networkCanvas.m_scaleFactor = 
checkZoom(zoom,m_networkCanvas.m_scaleFactor);
-                       if (calledFromGetSnapshot) {
-                               calledFromGetSnapshot = false;
-                               m_networkCanvas.m_scaleFactor = 1.0;
-                       }
                        m_viewportChanged = true;
                        
                        // Update view model.  Zoom Level should be modified.
@@ -1884,13 +1885,19 @@
         *            DOCUMENT ME!
         */
 //TODO: Need to fix up scaling and sizing.  
-       public void drawSnapshot(Image img, GraphLOD lod, Paint bgPaint, double 
xCenter,
+       public void drawSnapshot(VolatileImage img, GraphLOD lod, Paint 
bgPaint, double xCenter,
                                 double yCenter, double scaleFactor) {
+               // First paint the background
+               m_backgroundCanvas.drawCanvas(img, xCenter, yCenter, 
scaleFactor);
+
                synchronized (m_lock) {
                        GraphRenderer.renderGraph(m_drawPersp, m_spacial, lod, 
m_nodeDetails,
                                                  m_edgeDetails, m_hash, new 
GraphGraphics(img, false),
                                                  bgPaint, xCenter, yCenter, 
scaleFactor);
                }
+
+               // Finally, draw the foreground
+               m_foregroundCanvas.drawCanvas(img, xCenter, yCenter, 
scaleFactor);
        }
 
        /**
@@ -2024,7 +2031,8 @@
         * @return Image
         * @throws IllegalArgumentException
         */
-       private Image createImage(final int width, final int height, double 
shrink, final boolean skipBackground) {
+       private Image createImage(final int width, final int height, 
+                                 double shrink, final boolean skipBackground) {
                // Validate arguments
                if (width < 0 || height < 0) {
                        throw new 
IllegalArgumentException("DGraphView.createImage(int width, int height): "
@@ -2256,6 +2264,13 @@
                m_backgroundCanvas.setBounds(x, y, width, height);
                m_networkCanvas.setBounds(x, y, width, height);
                m_foregroundCanvas.setBounds(x, y, width, height);
+       
+               // If this is the first call to setBounds, load any annotations
+               if (!annotationsLoaded) {
+                       annotationsLoaded = true;
+                       cyAnnotator.loadAnnotations();
+               }
+
        }
 
        @Override

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/InternalFrameComponent.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/InternalFrameComponent.java
 2012-05-14 23:14:31 UTC (rev 29264)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/InternalFrameComponent.java
 2012-05-14 23:16:01 UTC (rev 29265)
@@ -104,6 +104,11 @@
        private DingCanvas foregroundCanvas;
 
        /**
+        * ref to the graph view
+        */
+       private DGraphView dGraphView;
+
+       /**
         * Constructor.
         *
         * @param layeredPane JLayedPane
@@ -115,6 +120,7 @@
                this.backgroundCanvas = 
dGraphView.getCanvas(DGraphView.Canvas.BACKGROUND_CANVAS);
                this.networkCanvas = 
dGraphView.getCanvas(DGraphView.Canvas.NETWORK_CANVAS);
                this.foregroundCanvas = 
dGraphView.getCanvas(DGraphView.Canvas.FOREGROUND_CANVAS);
+               this.dGraphView = dGraphView;
 
                // set default ordering
                initLayeredPane();
@@ -131,10 +137,7 @@
         */
        public void setBounds(int x, int y, int width, int height) {
                super.setBounds(x, y, width, height);
-               // call reshape on each innercanvas
-               backgroundCanvas.setBounds(x, y, width, height);
-               networkCanvas.setBounds(x, y, width, height);
-               foregroundCanvas.setBounds(x, y, width, height);
+               dGraphView.setBounds(x, y, width, height);
        }
 
        /**

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/CyAnnotator.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/CyAnnotator.java
        2012-05-14 23:14:31 UTC (rev 29264)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/CyAnnotator.java
        2012-05-14 23:16:01 UTC (rev 29265)
@@ -55,7 +55,8 @@
 
        private static final String ANNOTATION_ATTRIBUTE="__Annotations";
 
-       private Map<Annotation, Map<String,String>> annotationMap = new 
HashMap<Annotation, Map<String,String>>();
+       private Map<Annotation, Map<String,String>> annotationMap = 
+               new HashMap<Annotation, Map<String,String>>();
 
        private List<Annotation> selectedAnnotations=new 
ArrayList<Annotation>();
        private double prevZoom=1;
@@ -69,7 +70,8 @@
 
        public CyAnnotator(DGraphView view, AnnotationFactoryManager 
annotationFactoryManager) {
                this.view = view;
-               this.foreGroundCanvas = 
(ArbitraryGraphicsCanvas)(view.getCanvas(DGraphView.Canvas.FOREGROUND_CANVAS));
+               this.foreGroundCanvas = 
+                       
(ArbitraryGraphicsCanvas)(view.getCanvas(DGraphView.Canvas.FOREGROUND_CANVAS));
                this.networkCanvas = view.getCanvas();
                this.annotationFactoryManager = annotationFactoryManager;
                initListeners();  
@@ -83,6 +85,7 @@
 
                //Set up the foreGroundCanvas as a dropTarget, so that we can 
drag and drop JPanels, created Annotations onto it.
                //We also set it up as a DragSource, so that we can drag 
created Annotations
+               // TODO: This should be replaced with a drag of the component
                DropTargetComponent dtarget=new DropTargetComponent();
                DragSourceComponent dsource=new DragSourceComponent();
 
@@ -92,18 +95,29 @@
                //We also setup this class as a ViewportChangeListener to the 
current networkview
                myViewportChangeListener=new MyViewportChangeListener();
                view.addViewportChangeListener(myViewportChangeListener);
+       }
 
+
+       public void loadAnnotations() {
+               CyNetwork network = view.getModel();
                // Now, see if this network has any existing annotations
-               final CyTable networkAttributes = 
view.getModel().getDefaultNetworkTable();
+               final CyTable networkAttributes = 
network.getDefaultNetworkTable();
 
+               // This should be in the HIDDEN_ATTRS namespace, but we can't 
get to it
+               // without a pointer to the CyNetworkTableManager
                if (networkAttributes.getColumn(ANNOTATION_ATTRIBUTE) == null) {
-                       
networkAttributes.createListColumn(ANNOTATION_ATTRIBUTE,String.class,false,Collections.EMPTY_LIST);
+                       networkAttributes.createListColumn(ANNOTATION_ATTRIBUTE,
+                                                          
String.class,false,Collections.EMPTY_LIST);
                }
 
-               List<String> annotations = 
view.getModel().getRow(view.getModel()).getList(ANNOTATION_ATTRIBUTE,String.class);
-               Map<Integer, Annotation> idMap = new HashMap<Integer, 
Annotation>(); // Keep a map of the original annotation ID's
-               List<Map<String,String>> arrowList = new ArrayList<Map<String, 
String>>(); // Keep a list of arrows
+               List<String> annotations = network.getRow(network).
+                                                         
getList(ANNOTATION_ATTRIBUTE,String.class);
+               Map<Integer, Annotation> idMap = 
+                   new HashMap<Integer, Annotation>(); // Keep a map of the 
original annotation ID's
 
+               List<Map<String,String>> arrowList = 
+                   new ArrayList<Map<String, String>>(); // Keep a list of 
arrows
+
                if (annotations != null) {
                        for (String s: annotations) {
                                Map<String, String> argMap = createArgMap(s);
@@ -134,8 +148,6 @@
                                
arrow.setSource(annotation.getComponentNumber());
                        }
                }
-               
-               view.updateView();      
        }
 
        public Component getComponentAt(int x, int y) {
@@ -226,6 +238,7 @@
                //createShape will have all the properties associated with the 
shape to be drawn
                //Create a shapeAnnotattion based on these properties and add 
it to foreGroundCanvas
                newShape= new ShapeAnnotation(this,view, x, y, 
createShape.getShapeType(), 
+                                             10, 10,
                                              createShape.getFillColor(), 
                                              createShape.getEdgeColor(), 
createShape.getEdgeThickness());
                foreGroundCanvas.add(newShape);

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/Annotation.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/Annotation.java
     2012-05-14 23:14:31 UTC (rev 29264)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/Annotation.java
     2012-05-14 23:16:01 UTC (rev 29265)
@@ -4,6 +4,7 @@
 import org.cytoscape.ding.impl.cyannotator.modify.mArrow;
 import org.cytoscape.ding.impl.ArbitraryGraphicsCanvas;
 import org.cytoscape.ding.impl.DGraphView;
+import org.cytoscape.ding.impl.InnerCanvas;
 import org.cytoscape.model.CyNetwork;
 
 import java.awt.AlphaComposite;
@@ -21,6 +22,8 @@
 import java.awt.event.ActionListener;
 import java.awt.event.MouseEvent;
 
+import java.awt.geom.AffineTransform;
+
 import javax.swing.JFrame;
 import javax.swing.JMenuItem;
 import javax.swing.JPopupMenu;
@@ -118,8 +121,12 @@
                nextLocn[0] = Double.parseDouble(argMap.get(X));
                nextLocn[1] = Double.parseDouble(argMap.get(Y));
                // Transform the coordinates
-               
cyAnnotator.getNetworkCanvas().getAffineTransform().transform(nextLocn, 0, 
nextLocn, 0, 1);
+               AffineTransform t = 
((InnerCanvas)view.getCanvas()).getAffineTransform();
+               if (t != null) {
+                       t.transform(nextLocn, 0, nextLocn, 0, 1);
+               }
                this.setLocation((int)nextLocn[0],(int)nextLocn[1]);
+
        }
 
        public void updateAnnotationAttributes() {
@@ -149,10 +156,14 @@
        }
 
   protected Color getColor(String strColor) {
+               if (strColor == null)
+                       return null;
                return new Color(Integer.parseInt(strColor));
   }
 
   protected String convertColor(Color clr) {
+               if (clr == null)
+                       return null;
                return Integer.toString(clr.getRGB());
   }
 

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/ImageAnnotation.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/ImageAnnotation.java
        2012-05-14 23:14:31 UTC (rev 29264)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/ImageAnnotation.java
        2012-05-14 23:16:01 UTC (rev 29265)
@@ -49,7 +49,9 @@
 
        public ImageAnnotation() { super(); }
 
-       public ImageAnnotation(CyAnnotator cyAnnotator, DGraphView view, int x, 
int y, URL url, BufferedImage image, int compCount, double zoom, 
CustomGraphicsManager customGraphicsManager) {
+       public ImageAnnotation(CyAnnotator cyAnnotator, DGraphView view, int x, 
int y, 
+                              URL url, BufferedImage image, int compCount, 
double zoom, 
+                              CustomGraphicsManager customGraphicsManager) {
                super(cyAnnotator, view, x, y, compCount, zoom);
                this.image=image;
                this.customGraphicsManager = customGraphicsManager;
@@ -61,9 +63,11 @@
                this.cg = new URLImageCustomGraphics(id, url.toString(), image);
                customGraphicsManager.addCustomGraphics(cg, url);
                customGraphicsManager.setUsedInCurrentSession(cg, true);
+               updateAnnotationAttributes();
        }
 
-       public ImageAnnotation(CyAnnotator cyAnnotator, DGraphView view, 
Map<String, String> argMap, CustomGraphicsManager customGraphicsManager) {
+       public ImageAnnotation(CyAnnotator cyAnnotator, DGraphView view, 
+                              Map<String, String> argMap, 
CustomGraphicsManager customGraphicsManager) {
                super(cyAnnotator, view, argMap);
                this.customGraphicsManager = customGraphicsManager;
                // Get the image from the image pool
@@ -81,6 +85,7 @@
                imageWidth = Double.parseDouble(argMap.get(WIDTH));
                imageHeight = Double.parseDouble(argMap.get(HEIGHT));
                resizedImage=resize(image, (int)image.getWidth(), 
(int)image.getHeight());
+               updateAnnotationAttributes();
        }
 
        public Map<String,String> getArgMap() {

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/ShapeAnnotation.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/ShapeAnnotation.java
        2012-05-14 23:14:31 UTC (rev 29264)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/ShapeAnnotation.java
        2012-05-14 23:16:01 UTC (rev 29265)
@@ -23,40 +23,59 @@
        private float edgeThickness=2.0f;
        public boolean cornersAdjusted=false;
        private int rVal=5;
-       private double shapeWidth=0, shapeHeight=0;
+       private int shapeWidth=0, shapeHeight=0;
 
        private static String EDGECOLOR = "edgeColor";
        private static String EDGETHICKNESS = "edgeThickness";
        private static String FILLCOLOR = "fillColor";
        private static String SHAPETYPE = "shapeType";
+       private static String WIDTH = "width";
+       private static String HEIGHT = "height";
 
        public static final String NAME="SHAPE";
 
-       public ShapeAnnotation(int width, int height){
+       public ShapeAnnotation(int width, int height) {
                super();
                shapeWidth=width/2;
                shapeHeight=height/3;
                rVal=10;
        }
        
-       public ShapeAnnotation(CyAnnotator cyAnnotator, DGraphView view, int x, 
int y, int shapeType, 
+       public ShapeAnnotation(CyAnnotator cyAnnotator, DGraphView view, 
+                              int x, int y, int shapeType, 
+                              int width, int height,
                               Color fillColor, Color edgeColor, 
                               float edgeThickness) {
-               super(cyAnnotator, view, x, y, 
cyAnnotator.getForeGroundCanvas().getComponentCount(), view.getZoom());
+               super(cyAnnotator, view, x, y, 
+               cyAnnotator.getForeGroundCanvas().getComponentCount(), 
view.getZoom());
 
                this.shapeType=shapeType;
                this.fillColor=fillColor;
+               setFillColor(fillColor);
                this.edgeColor=edgeColor;
                this.edgeThickness=edgeThickness;
+               this.shapeWidth = width;
+               this.shapeHeight = height;
+               otherCornerX = x+shapeWidth;
+               otherCornerY = y+shapeHeight;
+               setSize(shapeWidth, shapeHeight);
+               updateAnnotationAttributes();
        }
 
        public ShapeAnnotation(CyAnnotator cyAnnotator, DGraphView view, 
Map<String, String> argMap) {
                super(cyAnnotator, view, argMap);
                this.edgeColor = getColor(argMap.get(EDGECOLOR));
                this.fillColor = getColor(argMap.get(FILLCOLOR));
+               this.shapeWidth = Integer.parseInt(argMap.get(WIDTH));
+               this.shapeHeight = Integer.parseInt(argMap.get(HEIGHT));
                setFillColor(fillColor);
                this.edgeThickness = 
Float.parseFloat(argMap.get(EDGETHICKNESS));
                this.shapeType = Integer.parseInt(argMap.get(SHAPETYPE));
+               otherCornerX = getX()+shapeWidth;
+               otherCornerY = getY()+shapeHeight;
+               setSize(shapeWidth, shapeHeight);
+               cornersAdjusted = true;
+               updateAnnotationAttributes();
        }
 
        public Map<String,String> getArgMap() {
@@ -64,33 +83,31 @@
                argMap.put(TYPE,NAME);
                if (this.fillColor != null)
                        argMap.put(FILLCOLOR,convertColor(this.fillColor));
-               argMap.put(EDGECOLOR,convertColor(this.edgeColor));
+               if (this.edgeColor != null)
+                       argMap.put(EDGECOLOR,convertColor(this.edgeColor));
                argMap.put(EDGETHICKNESS,Float.toString(this.edgeThickness));
                argMap.put(SHAPETYPE, Integer.toString(this.shapeType));
+               argMap.put(WIDTH, Integer.toString(this.shapeWidth));
+               argMap.put(HEIGHT, Integer.toString(this.shapeHeight));
                return argMap;
        }
 
        @Override
        public void paint(Graphics g) {
-
                Graphics2D g2=(Graphics2D)g;
                
                if(getArrowDrawn())
                        super.paint(g);         
 
                g2.setComposite(AlphaComposite.Src);
-
                
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
-
                
g2.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
-
                
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
 
                Point p1;
                int width, height;
 
-               if(!cornersAdjusted){
-
+               if(!cornersAdjusted) {
                        //We haven't finalized the shape yet
                        //Comes into play when we created a ShapeAnnotation and 
move the mouse
 
@@ -99,23 +116,20 @@
 
                        width=Math.abs(p2.x-p1.x);
                        height=Math.abs(p2.y-p1.y);
-               }
-
-               else{
-                       
+               } else {
                        if(usedForPreviews)
-                               p1=new Point(getX()+(int)shapeWidth/2, 
getY()+(int)shapeHeight);
+                               p1=new Point(getX()+shapeWidth/2, 
getY()+shapeHeight);
                        else
                                p1=new Point(getX(), getY());
 
-                       width=(int)shapeWidth;
-                       height=(int)shapeHeight;                        
+                       width=shapeWidth;
+                       height=shapeHeight;                     
                }
-                       
-               if(shapeType==0){//Rectangle
-                       
-                       if(fillColor!=null){
 
+               // System.out.println("Drawing rectangle: x="+p1.x+", 
y="+p1.y+" size="+width+"x"+height+", edgeThickness = "+edgeThickness);
+                       
+               if(shapeType==0) {//Rectangle
+                       if(fillColor!=null) {
                                g2.setColor(fillColor);
                                g2.fillRect( p1.x, p1.y, width, height);
                        }
@@ -128,12 +142,8 @@
                        g2.setStroke(new BasicStroke(edgeThickness));
                        g2.drawRect(p1.x, p1.y, width, height);
                                
-               }
-
-               else if(shapeType==1){//Rounded Rectangle
-
-                       if(fillColor!=null){
-
+               } else if(shapeType==1) {//Rounded Rectangle
+                       if(fillColor!=null) {
                                g2.setColor(fillColor);
                                g2.fillRoundRect( p1.x, p1.y, width, height, 
rVal, rVal);
                        }
@@ -145,13 +155,8 @@
                        
                        g2.setStroke(new BasicStroke(edgeThickness));
                        g2.drawRoundRect(p1.x, p1.y, width, height, rVal, rVal);
-
-               }
-
-               else if(shapeType==2){//Oval
-
-                       if(fillColor!=null){
-
+               } else if(shapeType==2) {//Oval
+                       if(fillColor!=null) {
                                g2.setColor(fillColor);
                                g2.fillOval( p1.x, p1.y, width, height);
                        }
@@ -164,48 +169,42 @@
                        g2.setStroke(new BasicStroke(edgeThickness));
                        g2.drawOval(p1.x, p1.y, width, height);
                }
-
                //Now draw the arrows associated with this annotation
-
        }
 
 
-       public boolean isShapeAnnotation(){
-
+       public boolean isShapeAnnotation() {
                return true;
        }
 
-       public boolean isTextAnnotation(){
+       public boolean isTextAnnotation() {
                return false;
        }       
        
        public boolean isPointInComponentOnly(int pX, int pY) {
-
                int x=getX(), y=getY();
 
-               if(pX>=x && pX<=(x+(int)shapeWidth) && pY>=y && 
pY<=(y+(int)shapeHeight))
+               if(pX>=x && pX<=(x+shapeWidth) && pY>=y && pY<=(y+shapeHeight))
                        return true;
                else
                        return false;
        }       
 
        public int getAnnotationWidth() {
-
-               return (int)shapeWidth;
+               return shapeWidth;
        }
 
 
        public int getAnnotationHeight() {
-
-               return (int)shapeHeight;
+               return shapeHeight;
        }
 
        @Override
        public void adjustZoom(double newZoom) {
-
                float factor=(float)(newZoom/getZoom());
                
                edgeThickness*=factor;
+               if (edgeThickness < 1.0f) edgeThickness = 1.0f;
                
                adjustArrowThickness(newZoom);
                
@@ -214,12 +213,12 @@
                shapeWidth*=factor;
                shapeHeight*=factor;
                
-               setSize((int)shapeWidth, (int)shapeHeight);
+               setSize(shapeWidth, shapeHeight);
+               updateAnnotationAttributes();
        }
 
        @Override
        public void adjustSpecificZoom(double newZoom) {
-
                float factor=(float)(newZoom/getTempZoom());
                
                setTempZoom(newZoom);           
@@ -227,10 +226,11 @@
                shapeWidth*=factor;
                shapeHeight*=factor;
                
-               setSize((int)shapeWidth, (int)shapeHeight);
+               setSize(shapeWidth, shapeHeight);
+               updateAnnotationAttributes();
        }
        
-       public void addModifyMenuItem(JPopupMenu popup){
+       public void addModifyMenuItem(JPopupMenu popup) {
                
                JMenuItem modify=new JMenuItem("Modify Properties");
                modify.addActionListener(new modifyShapeAnnotationListener());
@@ -240,7 +240,7 @@
        
        class modifyShapeAnnotationListener implements ActionListener{
 
-               public void actionPerformed(ActionEvent e){
+               public void actionPerformed(ActionEvent e) {
 
                        mShapeAnnotation mSAnnotation=new 
mShapeAnnotation(ShapeAnnotation.this);
 
@@ -255,7 +255,6 @@
        }          
        
        public void adjustCorners() {
-
                //Comes into play when the shape has been created completely
                //We finalize the topLeft and bottomRight corners of the shape
 
@@ -269,10 +268,10 @@
                shapeHeight=Math.abs(p2.y-p1.y);
 
                cornersAdjusted=true;
+               updateAnnotationAttributes();
        }
 
-       public Point getFirstCorner(){
-
+       public Point getFirstCorner() {
                int x=getX(), y=getY();
 
                if(x<=otherCornerX && y<=otherCornerY)
@@ -288,8 +287,7 @@
                        return new Point(otherCornerX, otherCornerY);
        }
 
-       public Point getSecondCorner(){
-
+       public Point getSecondCorner() {
                int x=getX(), y=getY();
 
                if(x<=otherCornerX && y<=otherCornerY)
@@ -303,48 +301,42 @@
 
                else
                        return new Point(x, y);
-
        }
        
-       public float getEdgeThickness(){
-               
+       public float getEdgeThickness() {
                return this.edgeThickness;
        }
        
-       public Color getFillColor(){
-               
+       public Color getFillColor() {
                return fillColor;
        }
        
-       public Color getEdgeColor(){
-               
+       public Color getEdgeColor() {
                return edgeColor;
        }
        
-       public int getShapeType(){
-               
+       public int getShapeType() {
                return this.shapeType;
        }
                
-       public void setFillColor(Color val){
+       public void setFillColor(Color val) {
                fillColor=val;
        }
        
-       public void setEdgeColor(Color val){
+       public void setEdgeColor(Color val) {
                edgeColor=val;
        }
 
-       public void setOtherCorner(int x, int y){
-
+       public void setOtherCorner(int x, int y) {
                otherCornerX=x;
                otherCornerY=y;
        }
        
-       public void setEdgeThickness(int val){
+       public void setEdgeThickness(int val) {
                edgeThickness=val;
        }
 
-       public void setShapeType(int val){
+       public void setShapeType(int val) {
                shapeType=val;
        }
                

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/TextAnnotation.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/TextAnnotation.java
 2012-05-14 23:14:31 UTC (rev 29264)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/TextAnnotation.java
 2012-05-14 23:16:01 UTC (rev 29265)
@@ -50,10 +50,12 @@
 
        public TextAnnotation() { super(); }
 
-       public TextAnnotation(CyAnnotator cyAnnotator, DGraphView view, int x, 
int y, String text, int compCount, double zoom){
+       public TextAnnotation(CyAnnotator cyAnnotator, DGraphView view, 
+                             int x, int y, String text, int compCount, double 
zoom){
                super(cyAnnotator, view, x, y, compCount, zoom);
                this.text=text;
                this.font=new Font("Arial", Font.PLAIN, initialFontSize);
+               updateAnnotationAttributes();
        }
 
        // This constructor is used to construct a text annotation from an
@@ -63,6 +65,7 @@
                this.font = getArgFont(argMap);
                this.color = getColor(argMap.get(COLOR));
                this.text = argMap.get(TEXT);
+               updateAnnotationAttributes();
        }
 
        public Map<String,String> getArgMap() {

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