Author: scooter
Date: 2012-06-02 15:28:57 -0700 (Sat, 02 Jun 2012)
New Revision: 29435

Modified:
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/AbstractAnnotation.java
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/BoundedTextAnnotationImpl.java
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/ShapeAnnotationImpl.java
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/TextAnnotationImpl.java
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/dialogs/BoundedTextAnnotationDialog.java
Log:
OK, I think we're pretty much there.  Only leaves arrows and the image creation 
dialog


Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/AbstractAnnotation.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/AbstractAnnotation.java
     2012-06-02 16:59:40 UTC (rev 29434)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/AbstractAnnotation.java
     2012-06-02 22:28:57 UTC (rev 29435)
@@ -248,15 +248,16 @@
        public void paint(Graphics g) {
                Graphics2D g2 = (Graphics2D)g;
 
+               // Set up all of our anti-aliasing, etc. here to avoid doing it 
redundantly
+               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);
+
                if (!usedForPreviews()) {
-                       // Set up all of our anti-aliasing, etc. here to avoid 
doing it redundantly
+                       // We need to control composite ourselves for 
previews...
                        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);
-
                        for (ArrowAnnotation arrow: arrowList) {
                                arrow.paint(g);
                        }

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/BoundedTextAnnotationImpl.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/BoundedTextAnnotationImpl.java
      2012-06-02 16:59:40 UTC (rev 29434)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/BoundedTextAnnotationImpl.java
      2012-06-02 22:28:57 UTC (rev 29435)
@@ -50,7 +50,8 @@
                this.font=new Font("Arial", Font.PLAIN, initialFontSize);
                this.fontSize = (float)initialFontSize;
                this.text = "Text Annotation";
-               super.setSize(getTextWidth(null)+4, getTextHeight(null)+4);
+               super.setSize(getTextWidth((Graphics2D)this.getGraphics())+4, 
+                             getTextHeight((Graphics2D)this.getGraphics())+4);
        }
 
        public BoundedTextAnnotationImpl(CyAnnotator cyAnnotator, DGraphView 
view, double width, double height) { 
@@ -87,8 +88,8 @@
                this.text = argMap.get(TEXT);
                this.fontSize = font.getSize2D();
                if (!argMap.containsKey(ShapeAnnotationImpl.WIDTH)) {
-                       double width = getTextWidth(null)+8;
-                       double height = getTextHeight(null)+8;
+                       double width = 
getTextWidth((Graphics2D)this.getGraphics())+8;
+                       double height = 
getTextHeight((Graphics2D)this.getGraphics())+8;
                        super.setSize(width, height);
                }
        }
@@ -105,25 +106,27 @@
        }
 
        public void fitShapeToText() {
-               double width = getTextWidth(null)+8;
-               double height = getTextHeight(null)+8;
+               double width = getTextWidth((Graphics2D)this.getGraphics())+8;
+               double height = getTextHeight((Graphics2D)this.getGraphics())+8;
                shapeIsFit = true;
 
+               System.out.println("Fitting shape to text: "+width+"x"+height);
+
                // Different depending on the type...
                switch (getShapeType()) {
                case ELLIPSE:
-                       width = getTextWidth(null)*3/2+8;
-                       height = getTextHeight(null)*2;
+                       width = 
getTextWidth((Graphics2D)this.getGraphics())*3/2+8;
+                       height = 
getTextHeight((Graphics2D)this.getGraphics())*2;
                        break;
                case TRIANGLE:
-                       width = getTextWidth(null)*3/2+8;
-                       height = getTextHeight(null)*2;
+                       width = 
getTextWidth((Graphics2D)this.getGraphics())*3/2+8;
+                       height = 
getTextHeight((Graphics2D)this.getGraphics())*2;
                        break;
                case PENTAGON:
                case HEXAGON:
                case STAR5:
                case STAR6:
-                       width = getTextWidth(null)*9/7+8;
+                       width = 
getTextWidth((Graphics2D)this.getGraphics())*9/7+8;
                        height = width;
                        break;
                }
@@ -146,11 +149,13 @@
                g2.setColor(textColor);
                Font tFont = 
font.deriveFont(((float)(scaleFactor/getZoom()))*font.getSize2D());
                FontMetrics fontMetrics=g.getFontMetrics(tFont);
-               x = x + (getWidth()-getTextWidth(g2))/2;
-               y = y + (getHeight()-getTextHeight(g2))/2;
+               int halfWidth = 
((int)(getWidth()*scaleFactor)-fontMetrics.stringWidth(text))/2;
+               // Note, this is + because we start at the baseline
+               int halfHeight = 
((int)(getHeight()*scaleFactor)+fontMetrics.getHeight()/2)/2;
+               int xLoc = (int)(x*scaleFactor) + halfWidth;
+               int yLoc = (int)(y*scaleFactor) + halfHeight;
                g2.setFont(tFont);
-               g2.drawChars(getText().toCharArray(), 0, getText().length(),
-                            (int)(x*scaleFactor), (int)(y*scaleFactor));
+               g2.drawString(text, xLoc, yLoc);
        }
 
        @Override
@@ -161,16 +166,15 @@
                g2.setColor(textColor);
                g2.setFont(font);
 
+               int halfWidth = (getWidth()-getTextWidth(g2))/2;
+               int halfHeight = (getHeight()+getTextHeight(g2)/2)/2; // Note, 
this is + because we start at the baseline
+
                if(usedForPreviews) {
-                       g2.drawChars(getText().toCharArray(), 0, 
getText().length(),
-                                    (int)(getWidth()-getTextWidth(g2))/2,
-                                    (int)(getHeight())/2 );
+                       g2.drawString(text, halfWidth, halfHeight);
                        return;
                }
 
-               g2.drawChars(getText().toCharArray(), 0, getText().length(),
-                                  getX()+(int)(getWidth()-getTextWidth(g2))/2,
-                                  getY()+(int)(getHeight())/2 );
+               g2.drawString(text, getX()+halfWidth, getY()+halfHeight);
        }
 
        @Override
@@ -243,12 +247,17 @@
 
        public void setFont(Font font) { 
                this.font = font; 
+               updateBounds();
        }
 
        private void updateBounds() {
+               if (shapeIsFit) {
+                       fitShapeToText();
+                       return;
+               }
                // Our bounds should be the larger of the shape or the text
-               int xBound = Math.max(getTextWidth(null), (int)shapeWidth);
-               int yBound = Math.max(getTextHeight(null), (int)shapeHeight);
+               int xBound = 
Math.max(getTextWidth((Graphics2D)this.getGraphics()), (int)shapeWidth);
+               int yBound = 
Math.max(getTextHeight((Graphics2D)this.getGraphics()), (int)shapeHeight);
                setSize(xBound+4, yBound+4);
        }
 

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/ShapeAnnotationImpl.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/ShapeAnnotationImpl.java
    2012-06-02 16:59:40 UTC (rev 29434)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/ShapeAnnotationImpl.java
    2012-06-02 22:28:57 UTC (rev 29435)
@@ -74,7 +74,7 @@
                this.shapeWidth = width;
                this.shapeHeight = height;
                this.shape = GraphicsUtilities.getShape(shapeType, 0.0, 0.0, 
shapeWidth, shapeHeight);
-    setSize((int)shapeWidth, (int)shapeHeight);
+    setSize((int)(shapeWidth+borderWidth*2), (int)(shapeHeight+borderWidth*2));
   }
 
   public ShapeAnnotationImpl(CyAnnotator cyAnnotator, DGraphView view, 
Map<String, String> argMap) {
@@ -103,7 +103,7 @@
 
     this.shapeType = 
GraphicsUtilities.getShapeType(Integer.parseInt(argMap.get(SHAPETYPE)));
                this.shape = GraphicsUtilities.getShape(shapeType, 0.0, 0.0, 
shapeWidth, shapeHeight);
-    setSize((int)shapeWidth, (int)shapeHeight);
+    setSize((int)(shapeWidth+borderWidth*2), (int)(shapeHeight+borderWidth*2));
   }
 
        public Map<String,String> getArgMap() {
@@ -137,7 +137,7 @@
                shapeHeight*=factor;
                // System.out.println("setZoom: size = 
"+shapeWidth+"x"+shapeHeight);
                
-               setSize((int)shapeWidth, (int)shapeHeight);
+    setSize((int)(shapeWidth+borderWidth*2), (int)(shapeHeight+borderWidth*2));
                super.setZoom(zoom);
        }
 
@@ -148,7 +148,7 @@
                shapeWidth*=factor;
                shapeHeight*=factor;
 
-               setSize((int)shapeWidth, (int)shapeHeight);
+    setSize((int)(shapeWidth+borderWidth*2), (int)(shapeHeight+borderWidth*2));
                super.setSpecificZoom(zoom);            
        }
 
@@ -212,7 +212,7 @@
        public void setSize(double width, double height) {
                shapeWidth = width;
                shapeHeight = height;
-               setSize((int)shapeWidth, (int)shapeHeight);
+    setSize((int)(shapeWidth+borderWidth*2), (int)(shapeHeight+borderWidth*2));
        }
 
        public JFrame getModifyDialog() {

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/TextAnnotationImpl.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/TextAnnotationImpl.java
     2012-06-02 16:59:40 UTC (rev 29434)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/TextAnnotationImpl.java
     2012-06-02 22:28:57 UTC (rev 29435)
@@ -166,9 +166,15 @@
                g2.setColor(textColor);
                Font tFont = 
font.deriveFont(((float)(scaleFactor/getZoom()))*font.getSize2D());
                FontMetrics fontMetrics=g.getFontMetrics(tFont);
+
+               int halfWidth = 
((int)(getWidth()*scaleFactor)-fontMetrics.stringWidth(text))/2;
+               // Note, this is + because we start at the baseline
+               int halfHeight = 
((int)(getHeight()*scaleFactor)+fontMetrics.getHeight()/2)/2;
+               int xLoc = (int)(x*scaleFactor) + halfWidth;
+               int yLoc = (int)(y*scaleFactor) + halfHeight;
+
                g2.setFont(tFont);
-               g2.drawChars(getText().toCharArray(), 0, getText().length(),
-                            (int)(x*scaleFactor), 
(int)(y*scaleFactor)+fontMetrics.getHeight());
+               g2.drawString(text, xLoc, yLoc);
        }
 
        public Rectangle getBounds() {
@@ -182,15 +188,15 @@
                g2.setColor(textColor);
                g2.setFont(font);
 
+               int halfWidth = (getWidth()-getTextWidth(g2))/2;
+               int halfHeight = (getHeight()+getTextHeight(g2)/2)/2; // Note, 
this is + because we start at the baseline
+
                if(usedForPreviews) {
-                       g2.drawChars(getText().toCharArray(), 0, 
getText().length(),
-                                    
getX()+(int)(getWidth()-getTextWidth(g2))/2,
-                                    
getY()+(int)(getHeight()+getTextHeight(g2))/2 );
+                       g2.drawString(text, halfWidth, halfHeight);
                        return;
                }
 
-               g2.drawChars(getText().toCharArray(), 0, getText().length(),
-                            getX(), getY()+getTextHeight(g2));
+               g2.drawString(text, getX()+halfWidth, getY()+halfHeight);
 
                if(isSelected()) {
       //Selected Annotations will have a yellow border

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/dialogs/BoundedTextAnnotationDialog.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/dialogs/BoundedTextAnnotationDialog.java
        2012-06-02 16:59:40 UTC (rev 29434)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/dialogs/BoundedTextAnnotationDialog.java
        2012-06-02 22:28:57 UTC (rev 29435)
@@ -60,6 +60,7 @@
                preview = new BoundedTextAnnotationImpl(cyAnnotator, view);
                preview.setUsedForPreviews(true);
                preview.setText(mAnnotation.getText());
+               preview.setFont(mAnnotation.getFont());
                preview.fitShapeToText();
                
                PreviewPanel previewPanel = new PreviewPanel(preview, 
PREVIEW_WIDTH, PREVIEW_HEIGHT);

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