Author: scooter
Date: 2012-05-16 16:33:40 -0700 (Wed, 16 May 2012)
New Revision: 29281

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/cyannotator/annotations/Annotation.java
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/BoundedAnnotation.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
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/create/BoundedAnnotationFactory.java
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/modify/mBoundedAnnotation.java
Log:
More annotation work.  Added bounded annotations and moved some shared 
functionality 
into Annotation.java.  This should eventually become AbstractAnnotation.java 
and a 
new interface Annotation.java should be created.  Still having problems with 
getting
the font scaling right when setFont is called, though...


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-16 23:03:26 UTC (rev 29280)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/CyActivator.java
 2012-05-16 23:33:40 UTC (rev 29281)
@@ -36,6 +36,7 @@
 import org.cytoscape.ding.impl.cyannotator.create.AnnotationFactoryManager;
 import org.cytoscape.ding.impl.cyannotator.create.ImageAnnotationFactory;
 import org.cytoscape.ding.impl.cyannotator.create.ShapeAnnotationFactory;
+import org.cytoscape.ding.impl.cyannotator.create.BoundedAnnotationFactory;
 import org.cytoscape.ding.impl.cyannotator.create.TextAnnotationFactory;
 import org.cytoscape.ding.impl.cyannotator.tasks.AddAnnotationTaskFactory;
 import org.cytoscape.ding.impl.editor.EdgeBendEditor;
@@ -153,9 +154,14 @@
                AnnotationFactory textAnnotationFactory = new 
TextAnnotationFactory();
                
annotationFactoryManager.addAnnotationFactory(textAnnotationFactory, null);
 
+               AnnotationFactory boundedAnnotationFactory = new 
BoundedAnnotationFactory();
+               
annotationFactoryManager.addAnnotationFactory(boundedAnnotationFactory, null);
+
                AddAnnotationTaskFactory addImageTaskFactory = new 
AddAnnotationTaskFactory(imageAnnotationFactory);
                AddAnnotationTaskFactory addShapeTaskFactory = new 
AddAnnotationTaskFactory(shapeAnnotationFactory);
                AddAnnotationTaskFactory addTextTaskFactory = new 
AddAnnotationTaskFactory(textAnnotationFactory);
+               AddAnnotationTaskFactory addBoundedTextTaskFactory = 
+                       new AddAnnotationTaskFactory(boundedAnnotationFactory);
 
                
                Properties dingRenderingEngineFactoryProps = new Properties();
@@ -210,6 +216,14 @@
                addTextTaskFactoryProps.setProperty(TITLE, "Add Text");
                registerService(bc, addTextTaskFactory, 
NetworkViewLocationTaskFactory.class, addTextTaskFactoryProps);
 
+               Properties addBoundedTextTaskFactoryProps = new Properties();
+               addBoundedTextTaskFactoryProps.setProperty(PREFERRED_ACTION, 
"NEW");
+               addBoundedTextTaskFactoryProps.setProperty(MENU_GRAVITY, "1.5");
+               addBoundedTextTaskFactoryProps.setProperty(PREFERRED_MENU, 
"Add");
+               addBoundedTextTaskFactoryProps.setProperty(TITLE, "Add Bounded 
Text");
+               registerService(bc, addBoundedTextTaskFactory, 
NetworkViewLocationTaskFactory.class, 
+                               addBoundedTextTaskFactoryProps);
+
                registerServiceListener(bc, vtfListener, 
"addNodeViewTaskFactory", "removeNodeViewTaskFactory",
                                NodeViewTaskFactory.class);
                registerServiceListener(bc, vtfListener, 
"addEdgeViewTaskFactory", "removeEdgeViewTaskFactory",

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-16 23:03:26 UTC (rev 29280)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/Annotation.java
     2012-05-16 23:33:40 UTC (rev 29281)
@@ -62,6 +62,11 @@
        protected boolean drawArrow=false, arrowDrawn=false;
        protected int arrowIndex=0;
 
+       // These allow us to have a shared shape drawing routine
+       protected int rVal=5;
+       protected int shapeType=1;
+       protected Color fillColor=null, edgeColor=Color.BLACK;
+
        // arguments that are common to more than one annotation type
        protected static final String TYPE="type";
        protected static final String X="x";
@@ -141,6 +146,7 @@
                                        cyAnnotator.addAnnotation(annotation);
                                }
                        }
+                       contentChanged();
                }
        }
 
@@ -659,11 +665,58 @@
        }
 
        public void contentChanged() {
+               if (view == null) return;
                final ContentChangeListener lis = 
view.getContentChangeListener();
                if (lis != null)
                        lis.contentChanged();
        }
 
+       protected void drawShape(Graphics2D g2, int x, int y, int width, int 
height, float stroke) {
+               // System.out.println("drawShape: x,y="+x+","+y+" 
"+width+"x"+height);
+               if(shapeType==0) {//Rectangle
+                       if(fillColor!=null) {
+                               g2.setColor(fillColor);
+                               g2.fillRect( x, y, width, height);
+                       }
+
+                       if(isSelected())
+                               g2.setColor(Color.YELLOW);
+                       else
+                               g2.setColor(edgeColor);
+
+                       g2.setStroke(new BasicStroke(stroke));
+                       g2.drawRect(x, y, width, height);
+                               
+               } else if(shapeType==1) {//Rounded Rectangle
+                       if(fillColor!=null) {
+                               g2.setColor(fillColor);
+                               g2.fillRoundRect(x, y, width, height, rVal, 
rVal);
+                       }
+
+                       if(isSelected())
+                               g2.setColor(Color.YELLOW);
+                       else
+                               g2.setColor(edgeColor);
+                       
+                       g2.setStroke(new BasicStroke(stroke));
+                       g2.drawRoundRect(x, y, width, height, rVal, rVal);
+
+               } else if(shapeType==2) {//Oval
+                       if(fillColor!=null) {
+                               g2.setColor(fillColor);
+                               g2.fillOval( x, y, width, height);
+                       }
+
+                       if(isSelected())
+                               g2.setColor(Color.YELLOW);
+                       else
+                               g2.setColor(edgeColor);
+                       
+                       g2.setStroke(new BasicStroke(stroke));
+                       g2.drawOval(x, y, width, height);
+               }
+               //Now draw the arrows associated with this annotation
+       }
        
        class removeArrowListener implements ActionListener {
                public void actionPerformed(ActionEvent e) {

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/BoundedAnnotation.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/BoundedAnnotation.java
      2012-05-16 23:03:26 UTC (rev 29280)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/BoundedAnnotation.java
      2012-05-16 23:33:40 UTC (rev 29281)
@@ -22,11 +22,8 @@
 import org.cytoscape.ding.impl.ArbitraryGraphicsCanvas;
 
 public class BoundedAnnotation extends TextAnnotation {
-
-       private int shapeType=1; //0-Rect 1-RoundRect 2-Ovel
-       private Color fillColor=null, edgeColor=Color.BLACK;
-       private boolean fillVal=false;
        private float edgeThickness=2.0f;
+       private boolean fillVal = false;
 
        private static String EDGECOLOR = "edgeColor";
        private static String EDGETHICKNESS = "edgeThickness";
@@ -37,13 +34,15 @@
 
        public BoundedAnnotation() { super(); }
        
-       public BoundedAnnotation(CyAnnotator cyAnnotator, DGraphView view, int 
x, int y, String text, int compCount, double zoom, 
+       public BoundedAnnotation(CyAnnotator cyAnnotator, DGraphView view, int 
x, int y, 
+                                String text, int compCount, double zoom, 
                                 Color fillColor, Color edgeColor, int 
shapeType, float edgeThickness){
                super(cyAnnotator, view, x, y, text, compCount, zoom);
                this.shapeType=shapeType;
                setFillColor(fillColor);
                this.edgeColor=edgeColor;
                this.edgeThickness=edgeThickness;
+               updateAnnotationAttributes();
        }
 
        public BoundedAnnotation(CyAnnotator cyAnnotator, DGraphView view, 
Map<String, String> argMap) {
@@ -55,6 +54,7 @@
                setFillColor(fillColor);
                this.edgeThickness = 
Float.parseFloat(argMap.get(EDGETHICKNESS));
                this.shapeType = Integer.parseInt(argMap.get(SHAPETYPE));
+               updateAnnotationAttributes();
        }
 
        public Map<String,String> getArgMap() {
@@ -67,11 +67,48 @@
                argMap.put(SHAPETYPE, Integer.toString(this.shapeType));
                return argMap;
        }
+
+       @Override
+       public void drawAnnotation(Graphics g, double x, double y, double 
scaleFactor) {
+               super.drawAnnotation(g, x, y, scaleFactor);
+               Graphics2D g2=(Graphics2D)g;
+               float stroke = (float)(edgeThickness*scaleFactor);
+               if (stroke < 1.0f) stroke = 1.0f;
+
+               //Setting up anti-aliasing for high quality rendering
+               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);
+
+               int width = 
(int)(getAnnotationWidth()*scaleFactor/view.getZoom());
+               int height = 
(int)(getAnnotationHeight()*scaleFactor/view.getZoom());
+
+                       x -= (getAnnotationWidth(g2)-getTextWidth(g2))/2; // 
Provide a little padding
+
+               // Get the scaled font metrics
+               int tWidth = getTextWidth(g2, scaleFactor);
+               int offset = (width - tWidth) / 2;
+
+               boolean selected = isSelected();
+               setSelected(false);
+               drawShape(g2, (int)(x*scaleFactor)-offset, 
(int)(y*scaleFactor), 
+                         width, height, stroke);
+               setSelected(selected);
+       }
        
        public void paint(Graphics g) {
                Graphics2D g2=(Graphics2D)g;
+
+               // Disable the selection for our parent
+               boolean selected = isSelected();
+               setSelected(false);
                super.paint(g);         
+               setSelected(selected);
 
+               float stroke = edgeThickness;
+               if (stroke < 1.0f) stroke = 1.0f;
+
                //Setting up anti-aliasing for high quality rendering
                g2.setComposite(AlphaComposite.Src);
                
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
@@ -82,92 +119,32 @@
                if(usedForPreviews){
                        x+=(int)(getWidth()-getAnnotationWidth(g2))/2;
                        y+=(int)(getHeight()-getAnnotationHeight(g2))/2;
+               } else {
+                       x -= (getAnnotationWidth(g2)-getTextWidth(g2))/2; // 
Provide a little padding
                }
-                                               
-               if(shapeType==0) {                      
-                       //Rectangle
-                       if(fillVal)
-                       {
-                               g2.setColor(fillColor);
-                               g2.fillRect(x, y, getAnnotationWidth(), 
getAnnotationHeight());
-                       }
-                       
-                       if(isSelected())
-                               g2.setColor(Color.YELLOW);
-                       else
-                               g2.setColor(edgeColor);
-                       
-                       g2.setStroke(new BasicStroke(edgeThickness));
-                       g2.drawRect(x, y, getAnnotationWidth(), 
getAnnotationHeight());
-               } else if(shapeType==1) {
-                       //Rounded Rectangle
-                       if(fillVal)
-                       {
-                               g2.setColor(fillColor);
-                               g2.fillRoundRect(x, y, getAnnotationWidth(), 
getAnnotationHeight(), 10, 10);
-                       }
-                       
-                       if(isSelected())
-                               g2.setColor(Color.YELLOW);
-                       else
-                               g2.setColor(edgeColor);
-                       
-                       g2.setStroke(new BasicStroke(edgeThickness));
-                       g2.drawRoundRect(x, y, getAnnotationWidth(), 
getAnnotationHeight(), 10, 10);
-               } else if(shapeType==2) {
-                       //Oval
-                       if(fillVal)
-                       {
-                               g2.setColor(fillColor);
-                               g2.fillOval(x, y, getAnnotationWidth(), 
getAnnotationHeight());
-                       }
-                       
-                       if(isSelected())
-                               g2.setColor(Color.YELLOW);
-                       else
-                               g2.setColor(edgeColor);
-                       
-                       g2.setStroke(new BasicStroke(edgeThickness));
-                       g2.drawOval(x, y, getAnnotationWidth(), 
getAnnotationHeight());                                         
-               }
-               
-               //To draw Text
-               
-               g2.setColor(getTextColor());
-               g2.setFont(getFont());
-               
-               g2.drawChars(getText().toCharArray(), 0, getText().length(), 
x+(getAnnotationWidth()-getTextWidth())/2, y+getTextHeight());             
+
+               drawShape(g2, x, y, getAnnotationWidth(), 
getAnnotationHeight(), stroke);
        }       
        
-       public void adjustSpecificZoom(double newZoom){
-               float factor=((float)(newZoom/tempZoom));
-               
-               font=font.deriveFont(factor*font.getSize2D());
-               tempZoom=newZoom;
-               
-               setSize(getAnnotationWidth(), getAnnotationHeight());           
-       }       
-       
        public void adjustZoom(double newZoom){
-               float factor=((float)(newZoom/zoom));
-               
-               font=font.deriveFont(factor*font.getSize2D());
+               float factor=((float)(newZoom/getZoom()));
                edgeThickness*=factor;
-               adjustArrowThickness(newZoom);
-               setSize(getAnnotationWidth(), getAnnotationHeight());           
-               zoom=newZoom;      
+               super.adjustZoom(newZoom);
        }       
-       
+
        public void setEdgeThickness(float val){
                edgeThickness=val;
+               updateAnnotationAttributes();
        }
        
        public void setShapeType(int val){
                shapeType=val;
+               updateAnnotationAttributes();
        }
 
        public void setFillVal(boolean val){
                fillVal=val;
+               updateAnnotationAttributes();
        }
        
        public void setFillColor(Color newColor){
@@ -178,10 +155,13 @@
                }
                else
                        this.fillVal=false;
+
+               updateAnnotationAttributes();
        } 
        
        public void setEdgeColor(Color newColor){
                this.edgeColor=newColor;
+               updateAnnotationAttributes();
        }       
 
        public boolean getFillVal(){
@@ -209,10 +189,8 @@
         
        @Override
        public int getAnnotationWidth(){
-
                if(shapeType==0 || shapeType==1)
                        return getTextWidth()+getTextHeight()/2;
-
                else
                        return getTextWidth()*3/2;
        }
@@ -223,10 +201,8 @@
        }
    
        public int getAnnotationWidth(Graphics2D g2){
-
                if(shapeType==0 || shapeType==1)
                        return getTextWidth(g2)+getTextHeight(g2)/2;
-
                else
                        return getTextWidth(g2)*3/2;
        }

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-16 23:03:26 UTC (rev 29280)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/ImageAnnotation.java
        2012-05-16 23:33:40 UTC (rev 29281)
@@ -64,7 +64,6 @@
                customGraphicsManager.addCustomGraphics(cg, url);
                customGraphicsManager.setUsedInCurrentSession(cg, true);
                updateAnnotationAttributes();
-               contentChanged();
        }
 
        public ImageAnnotation(CyAnnotator cyAnnotator, DGraphView view, 
@@ -87,7 +86,6 @@
                imageHeight = Double.parseDouble(argMap.get(HEIGHT));
                resizedImage=resize(image, (int)image.getWidth(), 
(int)image.getHeight());
                updateAnnotationAttributes();
-               contentChanged();
        }
 
        public Map<String,String> getArgMap() {
@@ -180,7 +178,6 @@
           
                setTempZoom(newZoom);           
                updateAnnotationAttributes();
-               contentChanged();
        }
 
 
@@ -200,7 +197,6 @@
                                
                setZoom(newZoom);               
                updateAnnotationAttributes();
-               contentChanged();
        }
 
 

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-16 23:03:26 UTC (rev 29280)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/ShapeAnnotation.java
        2012-05-16 23:33:40 UTC (rev 29281)
@@ -18,11 +18,9 @@
 
 public class ShapeAnnotation extends Annotation {
 
-       private int otherCornerX=0, otherCornerY=0, shapeType=1;
-       private Color fillColor=null, edgeColor=Color.BLACK;
+       private int otherCornerX=0, otherCornerY=0;
        private float edgeThickness=2.0f;
        public boolean cornersAdjusted=false;
-       private int rVal=5;
        private double shapeWidth=0.0, shapeHeight=0.0;
 
        private static String EDGECOLOR = "edgeColor";
@@ -60,7 +58,6 @@
                otherCornerY = y+(int)shapeHeight;
                setSize((int)shapeWidth, (int)shapeHeight);
                updateAnnotationAttributes();
-               contentChanged();
        }
 
        public ShapeAnnotation(CyAnnotator cyAnnotator, DGraphView view, 
Map<String, String> argMap) {
@@ -77,7 +74,6 @@
                setSize((int)shapeWidth, (int)shapeHeight);
                cornersAdjusted = true;
                updateAnnotationAttributes();
-               contentChanged();
        }
 
        public Map<String,String> getArgMap() {
@@ -160,54 +156,6 @@
                drawShape(g2, p1.x, p1.y, width, height, stroke);
        }
 
-       private void drawShape(Graphics2D g2, int x, int y, int width, int 
height, float stroke) {
-               // System.out.println("drawShape: x,y="+x+","+y+" 
"+width+"x"+height);
-               if(shapeType==0) {//Rectangle
-                       if(fillColor!=null) {
-                               g2.setColor(fillColor);
-                               g2.fillRect( x, y, width, height);
-                       }
-
-                       if(isSelected())
-                               g2.setColor(Color.YELLOW);
-                       else
-                               g2.setColor(edgeColor);
-
-                       g2.setStroke(new BasicStroke(stroke));
-                       g2.drawRect(x, y, width, height);
-                               
-               } else if(shapeType==1) {//Rounded Rectangle
-                       if(fillColor!=null) {
-                               g2.setColor(fillColor);
-                               g2.fillRoundRect(x, y, width, height, rVal, 
rVal);
-                       }
-
-                       if(isSelected())
-                               g2.setColor(Color.YELLOW);
-                       else
-                               g2.setColor(edgeColor);
-                       
-                       g2.setStroke(new BasicStroke(stroke));
-                       g2.drawRoundRect(x, y, width, height, rVal, rVal);
-
-               } else if(shapeType==2) {//Oval
-                       if(fillColor!=null) {
-                               g2.setColor(fillColor);
-                               g2.fillOval( x, y, width, height);
-                       }
-
-                       if(isSelected())
-                               g2.setColor(Color.YELLOW);
-                       else
-                               g2.setColor(edgeColor);
-                       
-                       g2.setStroke(new BasicStroke(stroke));
-                       g2.drawOval(x, y, width, height);
-               }
-               //Now draw the arrows associated with this annotation
-       }
-
-
        public boolean isShapeAnnotation() {
                return true;
        }
@@ -249,7 +197,6 @@
                
                setSize((int)shapeWidth, (int)shapeHeight);
                updateAnnotationAttributes();
-               contentChanged();
        }
 
        @Override
@@ -263,7 +210,6 @@
                
                setSize((int)shapeWidth, (int)shapeHeight);
                updateAnnotationAttributes();
-               contentChanged();
        }
        
        public void addModifyMenuItem(JPopupMenu popup) {
@@ -304,7 +250,6 @@
 
                cornersAdjusted=true;
                updateAnnotationAttributes();
-               contentChanged();
        }
 
        public Point getFirstCorner() {
@@ -357,23 +302,28 @@
                
        public void setFillColor(Color val) {
                fillColor=val;
+               updateAnnotationAttributes();
        }
        
        public void setEdgeColor(Color val) {
                edgeColor=val;
+               updateAnnotationAttributes();
        }
 
        public void setOtherCorner(int x, int y) {
                otherCornerX=x;
                otherCornerY=y;
+               updateAnnotationAttributes();
        }
        
        public void setEdgeThickness(int val) {
                edgeThickness=val;
+               updateAnnotationAttributes();
        }
 
        public void setShapeType(int val) {
                shapeType=val;
+               updateAnnotationAttributes();
        }
                
 }

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-16 23:03:26 UTC (rev 29280)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/TextAnnotation.java
 2012-05-16 23:33:40 UTC (rev 29281)
@@ -48,6 +48,9 @@
 
        public static final String NAME="TEXT";
 
+       private Font scaledFont = null;
+       private double lastScaleFactor = -1;
+
        public TextAnnotation() { super(); }
 
        public TextAnnotation(CyAnnotator cyAnnotator, DGraphView view, 
@@ -56,7 +59,6 @@
                this.text=text;
                this.font=new Font("Arial", Font.PLAIN, initialFontSize);
                updateAnnotationAttributes();
-               contentChanged();
        }
 
        // This constructor is used to construct a text annotation from an
@@ -67,7 +69,6 @@
                this.color = getColor(argMap.get(COLOR));
                this.text = argMap.get(TEXT);
                updateAnnotationAttributes();
-               contentChanged();
        }
 
        public Map<String,String> getArgMap() {
@@ -129,6 +130,22 @@
                FontMetrics fontMetrics=this.getGraphics().getFontMetrics(font);
                return fontMetrics.getHeight();
        }
+
+       public int getTextHeight(Graphics2D g2, double scaleFactor) {
+               if (scaleFactor == lastScaleFactor || scaledFont == null) {
+                       scaledFont = getScaledFont(scaleFactor);
+                       lastScaleFactor = scaleFactor;
+               }
+               return g2.getFontMetrics(scaledFont).getHeight();
+       }
+
+       public int getTextWidth(Graphics2D g2, double scaleFactor) {
+               if (scaleFactor == lastScaleFactor || scaledFont == null) {
+                       scaledFont = getScaledFont(scaleFactor);
+                       lastScaleFactor = scaleFactor;
+               }
+               return g2.getFontMetrics(scaledFont).stringWidth(text);
+       }
        
        public int getTextWidth(Graphics2D g2){
                FontMetrics fontMetrics=g2.getFontMetrics(font);
@@ -140,41 +157,50 @@
                return fontMetrics.getHeight();
        }       
 
+       private Font getScaledFont(double scaleFactor) {
+               return 
font.deriveFont(((float)(scaleFactor/zoom))*font.getSize2D());
+       }
+
        //Set methods
        public void setText(String newText) {
                this.text=newText;
                updateAnnotationAttributes();
-               contentChanged();
        }
 
        public void setTextColor(Color color) {
                this.color = color;
+               updateAnnotationAttributes();
        }
 
        @Override
-       public void setFont(Font font) {
-               this.font = font;
+       public void setFont(Font tFont) {
+               double tZoom = getTempZoom();
+               if(usedForPreviews) {                   
+                       tZoom = 1.0;
+               }
+               // Don't lose our current zoom
+               // TODO: this is still not quite right....
+               
this.font=tFont.deriveFont(((float)(1.0/tZoom))*tFont.getSize2D());
+               updateAnnotationAttributes();
        }
 
        public void adjustSpecificZoom(double newZoom){
-               
font=font.deriveFont(((float)(newZoom/tempZoom))*font.getSize2D());
-               tempZoom=newZoom;
+               
font=font.deriveFont(((float)(newZoom/getTempZoom()))*font.getSize2D());
+               setTempZoom(newZoom);
 
                setBounds(getX(), getY(), getAnnotationWidth(), 
getAnnotationHeight());
                updateAnnotationAttributes();
-               contentChanged();
        }
 
        public void adjustZoom(double newZoom){
-               font=font.deriveFont(((float)(newZoom/zoom))*font.getSize2D());
+               
font=font.deriveFont(((float)(newZoom/getZoom()))*font.getSize2D());
 
                setBounds(getX(), getY(), getAnnotationWidth(), 
getAnnotationHeight());
                
                adjustArrowThickness(newZoom);
                
-               zoom=newZoom;
+               setZoom(newZoom);
                updateAnnotationAttributes();
-               contentChanged();
        }
 
        @Override
@@ -182,7 +208,7 @@
                super.paint(g);
                Graphics2D g2=(Graphics2D)g;
                g2.setColor(color);
-               Font 
tFont=font.deriveFont(((float)(scaleFactor/zoom))*font.getSize2D());
+               Font tFont=getScaledFont(scaleFactor);
                FontMetrics fontMetrics=g.getFontMetrics(tFont);
                g2.setFont(tFont);
                g2.drawChars(getText().toCharArray(), 0, getText().length(), 

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/create/BoundedAnnotationFactory.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/create/BoundedAnnotationFactory.java
    2012-05-16 23:03:26 UTC (rev 29280)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/create/BoundedAnnotationFactory.java
    2012-05-16 23:33:40 UTC (rev 29281)
@@ -17,7 +17,7 @@
 
        public Annotation createAnnotation(String type, CyAnnotator 
cyAnnotator, DGraphView view, Map<String, String> argMap) {
                if ( type.equals(BoundedAnnotation.NAME) ) 
-                       return new BoundedAnnotation(cyAnnotator, view,argMap);
+                       return new BoundedAnnotation(cyAnnotator, view, argMap);
                else 
                        return null;
        }

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/modify/mBoundedAnnotation.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/modify/mBoundedAnnotation.java
  2012-05-16 23:03:26 UTC (rev 29280)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/modify/mBoundedAnnotation.java
  2012-05-16 23:33:40 UTC (rev 29281)
@@ -10,14 +10,12 @@
 
        
     public mBoundedAnnotation(BoundedAnnotation mAnnotation) {
-       
        this.mAnnotation=mAnnotation;
-        initComponents();
+       initComponents();
     }
     
 
     private void initComponents() {
-       
         jScrollPane1 = new javax.swing.JScrollPane();
         boundedAnnotation1 = new mBoundedAnnotationPanel(mAnnotation);
         applyButton = new javax.swing.JButton();

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