Author: scooter
Date: 2012-06-01 19:15:29 -0700 (Fri, 01 Jun 2012)
New Revision: 29431

Added:
   
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/api/BoundedTextAnnotation.java
   
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/ImageAnnotationDialog.java
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/dialogs/ImageAnnotationPanel.java
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/ImageAnnotationImpl.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/api/ImageAnnotation.java
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/dialogs/PreviewPanel.java
   
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/dialogs/ShapeAnnotationPanel.java
Log:
Hooked up image annotation modification and first shot at adding bounded text 
annotations


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 00:16:11 UTC (rev 29430)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/AbstractAnnotation.java
     2012-06-02 02:15:29 UTC (rev 29431)
@@ -242,7 +242,7 @@
        }
 
        public void update() {
-               cyAnnotator.update();
+               getCanvas().repaint();
        }
 
        // Component overrides
@@ -250,16 +250,18 @@
        public void paint(Graphics g) {
                Graphics2D g2 = (Graphics2D)g;
 
-               // Set up all of our anti-aliasing, etc. here to avoid doing it 
redundantly
-               g2.setComposite(AlphaComposite.Src);
+               if (!usedForPreviews()) {
+                       // Set up all of our anti-aliasing, etc. here to avoid 
doing it redundantly
+                       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);
+                       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);
+                       for (ArrowAnnotation arrow: arrowList) {
+                               arrow.paint(g);
+                       }
                }
        }
 

Added: 
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
                              (rev 0)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/BoundedTextAnnotationImpl.java
      2012-06-02 02:15:29 UTC (rev 29431)
@@ -0,0 +1,233 @@
+package org.cytoscape.ding.impl.cyannotator.annotations;
+
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Paint;
+import java.awt.RenderingHints;
+import java.awt.geom.Rectangle2D;
+
+import java.util.Map;
+
+import javax.swing.JFrame;
+
+import org.cytoscape.ding.impl.DGraphView;
+import org.cytoscape.ding.impl.cyannotator.CyAnnotator;
+import org.cytoscape.ding.impl.cyannotator.api.Annotation;
+import org.cytoscape.ding.impl.cyannotator.api.BoundedTextAnnotation;
+import org.cytoscape.ding.impl.cyannotator.api.TextAnnotation;
+import org.cytoscape.ding.impl.cyannotator.api.ShapeAnnotation;
+import org.cytoscape.ding.impl.cyannotator.dialogs.BoundedTextAnnotationDialog;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BoundedTextAnnotationImpl extends ShapeAnnotationImpl 
+                                       implements BoundedTextAnnotation, 
TextAnnotation {
+       private String text;
+
+       public static final String NAME="BOUNDED";
+       public static final String FONTCOLOR="fontColor";
+       public static final String TEXT="text";
+       public static final String COLOR="color";
+       public static final String FONTFAMILY="fontFamily";
+       public static final String FONTSIZE="fontSize";
+       public static final String FONTSTYLE="fontStyle";
+
+       private Font scaledFont = null;
+       private double lastScaleFactor = -1;
+
+       protected float fontSize = 0.0f;
+       protected Font font = null;
+       protected int initialFontSize=12;
+       protected Color textColor = Color.BLACK;
+       
+       public BoundedTextAnnotationImpl(CyAnnotator cyAnnotator, DGraphView 
view, double width, double height) { 
+               super(cyAnnotator, view, width, height);
+               this.font=new Font("Arial", Font.PLAIN, initialFontSize);
+               this.fontSize = (float)initialFontSize;
+               this.text = "Text Annotation";
+       }
+
+       public BoundedTextAnnotationImpl(BoundedTextAnnotationImpl c, double 
width, double height) { 
+               super(c, width, height);
+               this.text = c.getText();
+               this.textColor = c.getTextColor();
+               this.fontSize = (float)c.getFontSize();
+               this.font = c.getFont();
+       }
+
+       public BoundedTextAnnotationImpl(CyAnnotator cyAnnotator, DGraphView 
view,
+                                   double x, double y, ShapeType shapeType,
+                                   double width, double height,
+                                   Paint fillColor, Paint edgeColor,
+                                   float edgeThickness, String text, int 
compCount, double zoom){
+               super(cyAnnotator, view, x, y, shapeType, width, height, 
fillColor, edgeColor, edgeThickness);
+               this.text=text;
+               this.font=new Font("Arial", Font.PLAIN, initialFontSize);
+               this.fontSize = (float)initialFontSize;
+               updateAnnotationAttributes();
+       }
+
+       public BoundedTextAnnotationImpl(CyAnnotator cyAnnotator, DGraphView 
view, 
+                                        Map<String, String> argMap) {
+               super(cyAnnotator, view, argMap);
+               this.font = getArgFont(argMap);
+               this.textColor = getColor(argMap.get(COLOR));
+               this.text = argMap.get(TEXT);
+               this.fontSize = font.getSize2D();
+               updateAnnotationAttributes();
+       }
+
+       public Map<String,String> getArgMap() {
+               Map<String, String> argMap = super.getArgMap();
+               argMap.put(TYPE, NAME);
+               argMap.put(TEXT,this.text);
+               argMap.put(COLOR,convertColor(this.textColor));
+               argMap.put(FONTFAMILY,this.font.getFamily());
+               argMap.put(FONTSIZE,Integer.toString(this.font.getSize()));
+               argMap.put(FONTSTYLE,Integer.toString(this.font.getStyle()));
+               return argMap;
+       }
+       
+       public JFrame getModifyDialog() {
+                       return new BoundedTextAnnotationDialog(this);
+       }
+
+       @Override
+       public void drawAnnotation(Graphics g, double x, double y, double 
scaleFactor) {
+               super.drawAnnotation(g, x, y, scaleFactor);
+
+               // For now, we put the text in the middle of the shape.  At 
some point, we may
+               // want to add other options
+               Graphics2D g2 = (Graphics2D) g;
+               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;
+               g2.setFont(tFont);
+               g2.drawChars(getText().toCharArray(), 0, getText().length(),
+                            (int)(x*scaleFactor), (int)(y*scaleFactor));
+       }
+
+       @Override
+       public void paint(Graphics g) {
+               super.paint(g);
+
+               Graphics2D g2=(Graphics2D)g;
+               g2.setColor(textColor);
+               g2.setFont(font);
+
+               if(usedForPreviews) {
+                       g2.drawChars(getText().toCharArray(), 0, 
getText().length(),
+                                    
getX()+(int)(getWidth()-getTextWidth(g2))/2,
+                                    
getY()+(int)(getHeight()+getTextHeight(g2))/2 );
+                       return;
+               }
+
+               g2.drawChars(getText().toCharArray(), 0, getText().length(),
+                                  getX()+(int)(getWidth()-getTextWidth(g2))/2,
+                                  
getY()+(int)(getHeight()+getTextHeight(g2))/2 );
+       }
+
+       @Override
+       public void setSpecificZoom(double zoom) {
+               
font=font.deriveFont(((float)(zoom/getSpecificZoom()))*font.getSize2D());
+               super.setSpecificZoom(zoom);            
+       }
+
+       @Override
+       public void setZoom(double zoom) {
+               
font=font.deriveFont(((float)(zoom/getZoom()))*font.getSize2D());
+               super.setZoom(zoom);
+       }
+
+       @Override
+       public void setText(String text) {
+               this.text = text;
+               updateAnnotationAttributes();
+       }
+
+       @Override
+       public String getText() { return this.text; }
+
+
+       @Override
+       public void setTextColor(Color color) {
+               this.textColor = color;
+               updateAnnotationAttributes();
+       }
+
+       @Override
+       public Color getTextColor() { return textColor; }
+
+       @Override
+       public void setFontSize(double size) {
+               this.fontSize = (float)size;
+               scaledFont = 
font.deriveFont((float)(fontSize*getSpecificZoom()));
+               updateAnnotationAttributes();
+       }
+
+       @Override
+       public double getFontSize() { return this.fontSize; }
+
+
+       @Override
+       public void setFontStyle(int style) {
+               font = font.deriveFont(style, fontSize);
+               scaledFont = 
font.deriveFont((float)(fontSize*getSpecificZoom()));
+               updateAnnotationAttributes();
+       }
+
+       @Override
+       public int getFontStyle() {
+               return font.getStyle();
+       }
+
+       @Override
+       public void setFontFamily(String family) {
+               font = new Font(family, font.getStyle(), (int)fontSize);
+               scaledFont = 
font.deriveFont((float)(fontSize*getSpecificZoom()));
+               updateAnnotationAttributes();
+       }
+
+       @Override
+       public String getFontFamily() {
+               return font.getFamily();
+       }
+
+       public Font getFont() { return this.font; }
+
+       public void setFont(Font font) { 
+               this.font = font; 
+       }
+
+       int getTextWidth(Graphics2D g2) {
+               if (g2 != null) {
+                       FontMetrics fontMetrics=g2.getFontMetrics(font);
+                       return fontMetrics.stringWidth(text);
+               }
+               // If we don't have a graphics context, yet, make some 
assumptions
+               return (int)(text.length()*fontSize);
+       }
+
+       int getTextHeight(Graphics2D g2) {
+               if (g2 != null) {
+                       FontMetrics fontMetrics=g2.getFontMetrics(font);
+                       return fontMetrics.getHeight();
+               }
+               // If we don't have a graphics context, yet, make some 
assumptions
+               return (int)(fontSize*1.5);
+       }
+
+       Font getArgFont(Map<String, String> argMap) {
+               String family = argMap.get(FONTFAMILY);
+               int size = Integer.parseInt(argMap.get(FONTSIZE));
+               int style = Integer.parseInt(argMap.get(FONTSTYLE));
+               return new Font(family, style, size);
+       }
+
+}

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/ImageAnnotationImpl.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/ImageAnnotationImpl.java
    2012-06-02 00:16:11 UTC (rev 29430)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/ImageAnnotationImpl.java
    2012-06-02 02:15:29 UTC (rev 29431)
@@ -11,6 +11,7 @@
 import java.awt.Shape;
 import java.awt.geom.Rectangle2D;
 import java.awt.image.BufferedImage;
+import java.awt.image.RescaleOp;
 import java.awt.image.VolatileImage;
 
 import java.util.Map;
@@ -29,12 +30,12 @@
 import org.cytoscape.ding.impl.cyannotator.api.Annotation;
 import org.cytoscape.ding.impl.cyannotator.api.ImageAnnotation;
 import org.cytoscape.ding.impl.cyannotator.api.ShapeAnnotation;
-import org.cytoscape.ding.impl.cyannotator.modify.mImageAnnotation;
+import org.cytoscape.ding.impl.cyannotator.dialogs.ImageAnnotationDialog;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class ImageAnnotationImpl extends AbstractAnnotation implements 
ImageAnnotation, ShapeAnnotation {
+public class ImageAnnotationImpl extends AbstractAnnotation implements 
ImageAnnotation {
        private BufferedImage image;
        private URL url = null;
 
@@ -42,15 +43,22 @@
        private static final String URL="URL";
        private static final String WIDTH="width";
        private static final String HEIGHT="height";
+       private static final String OPACITY="opacity";
+       private static final String CONTRAST="contrast";
+       private static final String LIGHTNESS="brightness";
+
+       private static final float MAX_CONTRAST=4.0f;
        
        protected double imageWidth=0, imageHeight=0;
        private BufferedImage resizedImage;
        private float opacity = 1.0f;
+       private int brightness = 0;
+       private int contrast = 0;
        private CyCustomGraphics cg = null;
        protected CustomGraphicsManager customGraphicsManager;
 
        private double borderWidth = 0.0;
-       private Paint borderColor = Color.BLACK;
+       private Paint borderColor = null;
 
        private static final Logger logger = 
LoggerFactory.getLogger(ImageAnnotationImpl.class);
 
@@ -82,7 +90,7 @@
                imageWidth=image.getWidth();
                imageHeight=image.getHeight();
                this.url = url;
-               resizedImage=resize(image, (int)imageWidth, (int)imageHeight);
+               resizedImage=resizeImage((int)imageWidth, (int)imageHeight);
                final Long id = customGraphicsManager.getNextAvailableID();
                this.cg = new URLImageCustomGraphics(id, url.toString(), image);
                customGraphicsManager.addCustomGraphics(cg, url);
@@ -109,12 +117,21 @@
                                this.image = 
ImageUtil.toBufferedImage(cg.getRenderedImage());
                                customGraphicsManager.addCustomGraphics(cg, 
this.url);
                                
customGraphicsManager.setUsedInCurrentSession(cg, true);
-                               resizedImage=resize(image, 
(int)image.getWidth(), (int)image.getHeight());
+                               resizedImage=resizeImage((int)image.getWidth(), 
(int)image.getHeight());
                        }
                } catch (Exception e) {
                        logger.warn("Unable to restore image 
'"+argMap.get(URL)+"'",e);
                        return;
                }
+               if (argMap.containsKey(OPACITY))
+                       opacity = Float.parseFloat(argMap.get(OPACITY));
+
+               if (argMap.containsKey(LIGHTNESS))
+                       brightness = Integer.parseInt(argMap.get(LIGHTNESS));
+
+               if (argMap.containsKey(CONTRAST))
+                       contrast = Integer.parseInt(argMap.get(CONTRAST));
+
                updateAnnotationAttributes();
        }
 
@@ -124,6 +141,9 @@
                argMap.put(URL, url.toString());
                argMap.put(WIDTH, Double.toString(imageWidth));
                argMap.put(HEIGHT, Double.toString(imageHeight));
+               argMap.put(OPACITY, Float.toString(opacity));
+               argMap.put(LIGHTNESS, Integer.toString(brightness));
+               argMap.put(CONTRAST, Integer.toString(contrast));
                customGraphicsManager.setUsedInCurrentSession(cg, true);
 
                return argMap;
@@ -145,7 +165,7 @@
                        logger.warn("Unable to restore image '"+this.url+"'",e);
                        return;
                }
-               resizedImage=resize(image, (int)imageWidth, (int)imageHeight);
+               resizedImage=resizeImage((int)imageWidth, (int)imageHeight);
 
                updateAnnotationAttributes();
        }
@@ -164,8 +184,16 @@
 
                this.imageWidth=this.image.getWidth();
                this.imageHeight=this.image.getHeight();
-               resizedImage=resize(this.image, (int)resizedImage.getWidth(), 
(int)resizedImage.getHeight());
-               getCanvas().repaint();
+               
+               int width = (int)this.image.getWidth();
+               int height = (int)this.image.getHeight();
+               if (resizedImage != null) {
+                       width = (int)resizedImage.getWidth();
+                       height = (int)resizedImage.getHeight();
+               }
+               resizedImage=resizeImage((int)width, (int)height);
+               if (!usedForPreviews())
+                       getCanvas().repaint();
        }
 
        public void setImage(URL url) {
@@ -173,13 +201,29 @@
                reloadImage();
        }
 
+       public URL getImageURL() {
+               return url;
+       }
+
        public void setImageOpacity(float opacity) {
                this.opacity = opacity;
+               resizedImage=null;
        }
-
        public float getImageOpacity() { return this.opacity; }
 
-       // Shape annotation methods.  We add these so we can get resize 
functionality
+       public void setImageBrightness(int brightness) {
+               this.brightness = brightness;
+               resizedImage=null;
+       }
+       public int getImageBrightness() { return this.brightness; }
+
+       public void setImageContrast(int contrast) {
+               this.contrast = contrast;
+               resizedImage=null;
+       }
+       public int getImageContrast() { return this.contrast; }
+
+       // Shape annotation methods.  We add these so we can get resizeImage 
functionality
        public ShapeType[] getSupportedShapes() {
                ShapeType[] types = {ShapeType.RECTANGLE};
                return types;
@@ -190,8 +234,11 @@
                this.imageHeight = height;
 
                // Resize the image
-               resizedImage=resize(this.image, (int)imageWidth, 
(int)imageHeight);
-               getCanvas().repaint();
+               resizedImage=resizeImage((int)imageWidth, (int)imageHeight);
+               if (!usedForPreviews())
+                       getCanvas().repaint();
+
+               setSize((int)width, (int)height);
        }
 
        public ShapeType getShapeType() {
@@ -204,7 +251,7 @@
        }
 
        public void setBorderWidth(double width) {
-               borderWidth = width;
+               borderWidth = width*getZoom();
        }
 
        public Paint getBorderColor() {return borderColor;}
@@ -218,43 +265,73 @@
        }
        
 
-       //Returns a resized high quality BufferedImage
-       private BufferedImage resize(BufferedImage image, int width, int height)
+       //Returns a resizeImaged high quality BufferedImage
+       private BufferedImage resizeImage(int width, int height)
        {
                if (image == null) {
                        if (width == 0) width = 1;
                        if (height == 0) height = 1;
-                       return new BufferedImage(width, height, 
BufferedImage.TYPE_INT_ARGB);
+                       return new BufferedImage(width, height, 
BufferedImage.TYPE_INT_RGB);
                }
 
-               int type = image.getType() == 0? BufferedImage.TYPE_INT_ARGB : 
image.getType();
+               int type = image.getType() == 0? BufferedImage.TYPE_INT_RGB : 
image.getType();
                if(height==0)
                        height++;
                if(width==0)
                        width++;
-               BufferedImage resizedImage = new BufferedImage(width, height, 
type);
-               Graphics2D g = resizedImage.createGraphics();
+
+               BufferedImage adjustedImage = image;
+
+               // Handle image adjustments
+               if (contrast != 0 || brightness != 0) {
+                       BufferedImage source = image;
+                       // This only works for RGB
+                       if (type != BufferedImage.TYPE_INT_RGB) {
+                               BufferedImage rgbImage = new 
BufferedImage(image.getWidth(), image.getHeight(), 
+                                                                          
BufferedImage.TYPE_INT_RGB);
+                               Graphics2D g = rgbImage.createGraphics();
+                               g.drawImage(image, 0, 0, image.getWidth(), 
image.getHeight(), this);
+                               source = rgbImage;
+                       }
+                       adjustedImage = new BufferedImage(image.getWidth(), 
image.getHeight(), 
+                                                               
BufferedImage.TYPE_INT_RGB);
+
+                       // Do Brightness first...
+                       // offset goes from -255 - 255 for RGB
+                       float offset = (float)brightness*255.0f/100.0f;
+                       RescaleOp op = new RescaleOp(1.0f, offset, null);
+                       op.filter(source, adjustedImage);
+
+                       float scaleFactor = 1.0f;
+                       // scaleFactor goes from 0-4.0 with a 
+                       if (contrast <= 0) {
+                               scaleFactor = (1.0f + (float)contrast)/100.0f;
+                       } else
+                               scaleFactor = ((float)contrast)*4.0f/100.0f;
+               
+                       op = new RescaleOp(scaleFactor, 0.0f, null);
+                       op.filter(adjustedImage, adjustedImage);
+
+               }
+               BufferedImage newImage = new BufferedImage(width, height, type);
+               Graphics2D g = newImage.createGraphics();
                
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
                
g.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
                
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
 
-               if (borderWidth > 0.0 && borderColor != null) {
-                       g.setPaint(borderColor);
-                       g.setStroke(new BasicStroke((float)borderWidth));
-               }
                AlphaComposite ac = 
AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity);
                g.setComposite(ac);
-               g.drawImage(image, 0, 0, width, height, null);
+               g.drawImage(adjustedImage, 0, 0, width, height, this);
                g.dispose();
-               return resizedImage;
+               return newImage;
        }
 
        public void dropImage() {
                customGraphicsManager.setUsedInCurrentSession(cg, false);
        }
 
-       public JFrame getModifyDialog(Annotation annotation) {
-                       return new mImageAnnotation(this);
+       public JFrame getModifyDialog() {
+                       return new ImageAnnotationDialog(this);
        }
 
        @Override
@@ -265,7 +342,7 @@
 
                int width = (int)Math.round(imageWidth*scaleFactor/getZoom());
                int height = (int)Math.round(imageHeight*scaleFactor/getZoom());
-               BufferedImage newImage =resize(image, width, height);
+               BufferedImage newImage =resizeImage(width, height);
                if (newImage == null) return;
 
                boolean selected = isSelected();
@@ -280,9 +357,26 @@
 
                Graphics2D g2=(Graphics2D)g;
 
-               if (resizedImage == null) return;
+               if (image == null)
+                       return;
 
-               g2.drawImage(resizedImage, getX(), getY(), null);
+               if (resizedImage == null)
+                       resizedImage = resizeImage((int)imageWidth, 
(int)imageHeight);
+
+               int x = getX();
+               int y = getY();
+
+               if (usedForPreviews()) {
+                       x = 0; y = 0;
+               }
+
+               g2.drawImage(resizedImage, x, y, this);
+
+               if (borderColor != null && borderWidth > 0.0) {
+                       g2.setPaint(borderColor);
+                       g2.setStroke(new BasicStroke((float)borderWidth));
+                       g2.drawRect(x, y, getAnnotationWidth(), 
getAnnotationHeight());
+               }
                
                if(isSelected()) {
                        g2.setColor(Color.YELLOW);
@@ -291,7 +385,6 @@
                }
        }
 
-
        @Override
        public void setSpecificZoom(double newZoom) {
 
@@ -300,14 +393,13 @@
                imageWidth=imageWidth*factor;
                imageHeight=imageHeight*factor;
 
-               resizedImage=resize(image, (int)Math.round(imageWidth), 
(int)Math.round(imageHeight));
+               resizedImage=resizeImage((int)Math.round(imageWidth), 
(int)Math.round(imageHeight));
 
                setBounds(getX(), getY(), getAnnotationWidth(), 
getAnnotationHeight());
           
                super.setSpecificZoom(newZoom);         
        }
 
-
        @Override
        public void setZoom(double newZoom) {
 
@@ -316,8 +408,10 @@
                imageWidth=imageWidth*factor;
                imageHeight=imageHeight*factor;
 
-               resizedImage=resize(image, (int)Math.round(imageWidth), 
(int)Math.round(imageHeight));
+               borderWidth*=factor;
 
+               resizedImage=resizeImage((int)Math.round(imageWidth), 
(int)Math.round(imageHeight));
+
                setBounds(getX(), getY(), getAnnotationWidth(), 
getAnnotationHeight());
                                
                super.setZoom(newZoom);         

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 00:16:11 UTC (rev 29430)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/ShapeAnnotationImpl.java
    2012-06-02 02:15:29 UTC (rev 29431)
@@ -165,7 +165,9 @@
        }
   
   public double getBorderWidth() {return borderWidth;}
-  public void setBorderWidth(double width) { borderWidth = width; }
+  public void setBorderWidth(double width) { 
+               borderWidth = width*getZoom();
+       }
   
   public Paint getBorderColor() {return borderColor;}
   public Paint getFillColor() {return fillColor;}

Added: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/api/BoundedTextAnnotation.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/api/BoundedTextAnnotation.java
                          (rev 0)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/api/BoundedTextAnnotation.java
  2012-06-02 02:15:29 UTC (rev 29431)
@@ -0,0 +1,25 @@
+package org.cytoscape.ding.impl.cyannotator.api;
+
+import java.awt.Color;
+import java.awt.Font;
+
+// NOTE: all implementations should implement TextAnnotation also
+public interface BoundedTextAnnotation extends ShapeAnnotation {
+       public void setText(String text);
+       public String getText();
+
+       public void setTextColor(Color color);
+       public Color getTextColor();
+
+       public void setFontSize(double size);
+       public double getFontSize();
+
+       public void setFontStyle(int style);
+       public int getFontStyle();
+
+       public void setFontFamily(String family);
+       public String getFontFamily();
+
+       public Font getFont();
+       public void setFont(Font font);
+}

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/api/ImageAnnotation.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/api/ImageAnnotation.java
        2012-06-02 00:16:11 UTC (rev 29430)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/api/ImageAnnotation.java
        2012-06-02 02:15:29 UTC (rev 29431)
@@ -3,13 +3,20 @@
 import java.awt.Image;
 import java.net.URL;
 
-public interface ImageAnnotation extends Annotation {
+public interface ImageAnnotation extends ShapeAnnotation {
        public void reloadImage();
 
        public Image getImage();
        public void setImage(Image image);
+       public URL getImageURL();
        public void setImage(URL url);
 
        public void setImageOpacity(float opacity);
        public float getImageOpacity();
+
+       public void setImageBrightness(int brightness);
+       public int getImageBrightness();
+
+       public void setImageContrast(int contrast);
+       public int getImageContrast();
 }

Added: 
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
                                (rev 0)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/dialogs/BoundedTextAnnotationDialog.java
        2012-06-02 02:15:29 UTC (rev 29431)
@@ -0,0 +1,151 @@
+package org.cytoscape.ding.impl.cyannotator.dialogs;
+
+import java.awt.Point;
+import java.awt.Robot;
+import java.awt.geom.Point2D;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+
+import org.cytoscape.ding.impl.DGraphView;
+import org.cytoscape.ding.impl.cyannotator.CyAnnotator;
+import org.cytoscape.ding.impl.cyannotator.api.BoundedTextAnnotation;
+import org.cytoscape.ding.impl.cyannotator.api.ShapeAnnotation;
+import org.cytoscape.ding.impl.cyannotator.api.TextAnnotation;
+import 
org.cytoscape.ding.impl.cyannotator.annotations.BoundedTextAnnotationImpl;
+
+public class BoundedTextAnnotationDialog extends javax.swing.JFrame {
+
+       private javax.swing.JButton applyButton;
+       private javax.swing.JButton cancelButton;
+
+       private ShapeAnnotationPanel shapeAnnotation1;  
+       private TextAnnotationPanel textAnnotation1;  
+
+       private final CyAnnotator cyAnnotator;    
+       private final DGraphView view;    
+       private final Point2D startingLocation;
+       private final BoundedTextAnnotation mAnnotation;
+       private BoundedTextAnnotation preview;
+       private final boolean create;
+               
+       public BoundedTextAnnotationDialog(DGraphView view, Point2D start) {
+               this.view = view;
+               this.cyAnnotator = view.getCyAnnotator();
+               this.startingLocation = start;
+               this.mAnnotation = new BoundedTextAnnotationImpl(cyAnnotator, 
view, 400, 400);
+               this.create = true;
+
+               initComponents();                       
+       }
+
+       public BoundedTextAnnotationDialog(BoundedTextAnnotation mAnnotation) {
+               this.mAnnotation=mAnnotation;
+               this.cyAnnotator = mAnnotation.getCyAnnotator();
+               this.view = cyAnnotator.getView();
+               this.create = false;
+               this.startingLocation = null;
+
+               initComponents();       
+       }
+    
+       private void initComponents() {
+               int SHAPE_HEIGHT = 220;
+               int SHAPE_WIDTH = 500;
+               int TEXT_HEIGHT = 220;
+               int TEXT_WIDTH = 500;
+               int PREVIEW_WIDTH = 500;
+               int PREVIEW_HEIGHT = 220;
+
+               // Create the preview panel
+               preview = new BoundedTextAnnotationImpl(cyAnnotator, view, 150, 
150);
+               preview.setUsedForPreviews(true);
+               preview.getComponent().setSize(150,150);
+               PreviewPanel previewPanel = new PreviewPanel(preview, 
PREVIEW_WIDTH, PREVIEW_HEIGHT);
+
+               shapeAnnotation1 = new 
ShapeAnnotationPanel((ShapeAnnotation)mAnnotation, previewPanel, SHAPE_WIDTH, 
SHAPE_HEIGHT);
+               textAnnotation1 = new 
TextAnnotationPanel((TextAnnotation)mAnnotation, previewPanel, TEXT_WIDTH, 
TEXT_HEIGHT);
+
+               applyButton = new javax.swing.JButton();
+               cancelButton = new javax.swing.JButton();
+
+               if (create)
+                       setTitle("Create Bounded Text Annotation");
+               else
+                       setTitle("Modify Bounded Text Annotation");
+
+               setResizable(false);
+               getContentPane().setLayout(null);
+
+               getContentPane().add(shapeAnnotation1);
+               shapeAnnotation1.setBounds(5, 0, shapeAnnotation1.getWidth(), 
shapeAnnotation1.getHeight());
+               getContentPane().add(textAnnotation1);
+               textAnnotation1.setBounds(5, SHAPE_HEIGHT, 
textAnnotation1.getWidth(), textAnnotation1.getHeight());
+
+               getContentPane().add(previewPanel);
+               previewPanel.setBounds(5, SHAPE_HEIGHT+TEXT_HEIGHT+5, 
PREVIEW_WIDTH, PREVIEW_HEIGHT);
+
+               int y = PREVIEW_HEIGHT+SHAPE_HEIGHT+TEXT_HEIGHT+10;
+
+               applyButton.setText("OK");
+               applyButton.addActionListener(new 
java.awt.event.ActionListener() {
+                       public void actionPerformed(java.awt.event.ActionEvent 
evt) {
+                               applyButtonActionPerformed(evt);
+                       }
+               });
+               getContentPane().add(applyButton);
+               applyButton.setBounds(350, y+20, 
applyButton.getPreferredSize().width, 23);
+
+               cancelButton.setText("Cancel");
+               cancelButton.addActionListener(new 
java.awt.event.ActionListener() {
+                       public void actionPerformed(java.awt.event.ActionEvent 
evt) {
+                               cancelButtonActionPerformed(evt);
+                       }
+               });
+
+               getContentPane().add(cancelButton);
+               cancelButton.setBounds(430, y+20, 
cancelButton.getPreferredSize().width, 23);
+
+               pack();
+               setSize(520, 525);
+               setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+       }
+
+       private void applyButtonActionPerformed(java.awt.event.ActionEvent evt) 
{
+               dispose();           
+               //Apply
+               mAnnotation.setFont(textAnnotation1.getNewFont());
+               mAnnotation.setTextColor(textAnnotation1.getTextColor());
+               mAnnotation.setText(textAnnotation1.getText());
+               mAnnotation.setShapeType(preview.getShapeType());
+               mAnnotation.setFillColor(preview.getFillColor());
+               mAnnotation.setBorderColor(preview.getBorderColor());
+               mAnnotation.setBorderWidth((int)preview.getBorderWidth());
+
+               if (!create) {
+                       mAnnotation.update(); 
+                       return;
+               }
+
+               
mAnnotation.getComponent().setLocation((int)startingLocation.getX(), 
(int)startingLocation.getY());
+               
view.getCanvas(DGraphView.Canvas.FOREGROUND_CANVAS).add(mAnnotation.getComponent());
+
+               // Update the canvas
+               view.getCanvas(DGraphView.Canvas.FOREGROUND_CANVAS).repaint();
+
+               // Set this shape to be resized
+               cyAnnotator.resizeShape(mAnnotation);
+
+               try {
+                       // Warp the mouse to the starting location (if 
supported)
+                       Point start = 
mAnnotation.getComponent().getLocationOnScreen();
+                       Robot robot = new Robot();
+                       robot.mouseMove((int)start.getX()+100, 
(int)start.getY()+100);
+               } catch (Exception e) {}
+       }
+
+       private void cancelButtonActionPerformed(java.awt.event.ActionEvent 
evt) {
+               //Cancel
+               dispose();
+       }
+}
+

Added: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/dialogs/ImageAnnotationDialog.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/dialogs/ImageAnnotationDialog.java
                              (rev 0)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/dialogs/ImageAnnotationDialog.java
      2012-06-02 02:15:29 UTC (rev 29431)
@@ -0,0 +1,150 @@
+package org.cytoscape.ding.impl.cyannotator.dialogs;
+
+import java.awt.Image;
+import java.awt.Point;
+import java.awt.Robot;
+import java.awt.geom.Point2D;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+
+import org.cytoscape.ding.impl.DGraphView;
+import org.cytoscape.ding.impl.cyannotator.CyAnnotator;
+import org.cytoscape.ding.impl.cyannotator.api.ImageAnnotation;
+import org.cytoscape.ding.impl.cyannotator.annotations.ImageAnnotationImpl;
+
+public class ImageAnnotationDialog extends javax.swing.JFrame {
+
+       private javax.swing.JButton applyButton;
+       private javax.swing.JButton cancelButton;
+
+       private ImageAnnotationPanel imageAnnotation1;  
+
+       private final CyAnnotator cyAnnotator;    
+       private final DGraphView view;    
+       private final Point2D startingLocation;
+       private final ImageAnnotation mAnnotation;
+       private ImageAnnotation preview;
+       private final boolean create;
+               
+       public ImageAnnotationDialog(DGraphView view, Point2D start) {
+               this.view = view;
+               this.cyAnnotator = view.getCyAnnotator();
+               this.startingLocation = start;
+               this.mAnnotation = new ImageAnnotationImpl(cyAnnotator, view);
+               this.create = true;
+
+               initComponents();                       
+       }
+
+       public ImageAnnotationDialog(ImageAnnotation mAnnotation) {
+               this.mAnnotation=mAnnotation;
+               this.cyAnnotator = mAnnotation.getCyAnnotator();
+               this.view = cyAnnotator.getView();
+               this.create = false;
+               this.startingLocation = null;
+
+               initComponents();       
+       }
+    
+       private void initComponents() {
+               int IMAGE_HEIGHT = 350;
+               int IMAGE_WIDTH = 500;
+               int PREVIEW_WIDTH = 500;
+               int PREVIEW_HEIGHT = 350;
+
+               // Create the preview panel
+               preview = new ImageAnnotationImpl(cyAnnotator, view);
+               Image img = mAnnotation.getImage();
+               double width = (double)img.getWidth(this);
+               double height = (double)img.getHeight(this);
+               double scale = (Math.max(width, height))/(PREVIEW_HEIGHT-50);
+
+               preview.setImage(img);
+               preview.setUsedForPreviews(true);
+               preview.setSize(width/scale, height/scale);
+               PreviewPanel previewPanel = new PreviewPanel(preview, 
PREVIEW_WIDTH, PREVIEW_HEIGHT);
+
+               imageAnnotation1 = new ImageAnnotationPanel(mAnnotation, 
previewPanel, IMAGE_WIDTH, IMAGE_HEIGHT);
+
+               applyButton = new javax.swing.JButton();
+               cancelButton = new javax.swing.JButton();
+
+               if (create)
+                       setTitle("Create Image Annotation");
+               else
+                       setTitle("Modify Image Annotation");
+
+               setResizable(false);
+               getContentPane().setLayout(null);
+
+               getContentPane().add(imageAnnotation1);
+               imageAnnotation1.setBounds(5, 0, imageAnnotation1.getWidth(), 
imageAnnotation1.getHeight());
+
+               getContentPane().add(previewPanel);
+               previewPanel.setBounds(5, imageAnnotation1.getHeight()+5, 
PREVIEW_WIDTH, PREVIEW_HEIGHT);
+
+               int y = PREVIEW_HEIGHT+IMAGE_HEIGHT+10;
+
+               applyButton.setText("OK");
+               applyButton.addActionListener(new 
java.awt.event.ActionListener() {
+                       public void actionPerformed(java.awt.event.ActionEvent 
evt) {
+                               applyButtonActionPerformed(evt);
+                       }
+               });
+               getContentPane().add(applyButton);
+               applyButton.setBounds(350, y+20, 
applyButton.getPreferredSize().width, 23);
+
+               cancelButton.setText("Cancel");
+               cancelButton.addActionListener(new 
java.awt.event.ActionListener() {
+                       public void actionPerformed(java.awt.event.ActionEvent 
evt) {
+                               cancelButtonActionPerformed(evt);
+                       }
+               });
+
+               getContentPane().add(cancelButton);
+               cancelButton.setBounds(430, y+20, 
cancelButton.getPreferredSize().width, 23);
+
+               pack();
+               setSize(520, y+80);
+               setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+       }
+
+       private void applyButtonActionPerformed(java.awt.event.ActionEvent evt) 
{
+               dispose();           
+
+               //Apply
+               mAnnotation.setBorderColor(preview.getBorderColor());
+               mAnnotation.setBorderWidth((int)preview.getBorderWidth());
+               mAnnotation.setImageOpacity(preview.getImageOpacity());
+               mAnnotation.setImageBrightness(preview.getImageBrightness());
+               mAnnotation.setImageContrast(preview.getImageContrast());
+
+               if (!create) {
+                       mAnnotation.update(); 
+                       return;
+               }
+
+               mAnnotation.setImage(preview.getImageURL());
+               
mAnnotation.getComponent().setLocation((int)startingLocation.getX(), 
(int)startingLocation.getY());
+               
view.getCanvas(DGraphView.Canvas.FOREGROUND_CANVAS).add(mAnnotation.getComponent());
+
+               // Update the canvas
+               view.getCanvas(DGraphView.Canvas.FOREGROUND_CANVAS).repaint();
+
+               // Set this shape to be resized
+               cyAnnotator.resizeShape(mAnnotation);
+
+               try {
+                       // Warp the mouse to the starting location (if 
supported)
+                       Point start = 
mAnnotation.getComponent().getLocationOnScreen();
+                       Robot robot = new Robot();
+                       robot.mouseMove((int)start.getX()+100, 
(int)start.getY()+100);
+               } catch (Exception e) {}
+       }
+
+       private void cancelButtonActionPerformed(java.awt.event.ActionEvent 
evt) {
+               //Cancel
+               dispose();
+       }
+}
+

Added: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/dialogs/ImageAnnotationPanel.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/dialogs/ImageAnnotationPanel.java
                               (rev 0)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/dialogs/ImageAnnotationPanel.java
       2012-06-02 02:15:29 UTC (rev 29431)
@@ -0,0 +1,295 @@
+package org.cytoscape.ding.impl.cyannotator.dialogs;
+
+import java.awt.Color;
+import java.awt.Paint;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import javax.swing.BorderFactory;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JSlider;
+import javax.swing.border.TitledBorder;
+import javax.swing.event.ChangeListener;
+import javax.swing.event.ChangeEvent;
+
+import java.awt.Component;
+
+import org.cytoscape.ding.impl.cyannotator.api.ImageAnnotation;
+import org.cytoscape.ding.impl.cyannotator.annotations.ImageAnnotationImpl;
+
+public class ImageAnnotationPanel extends javax.swing.JPanel {
+       private int WIDTH = 500;
+       private int HEIGHT = 200;
+       private int TOP = 10;
+       private int LEFT = 10;
+       private int COLUMN1 = 175;
+       private int COLUMN2 = 305;
+       private int RIGHT = WIDTH-10;
+
+       private javax.swing.JPanel jPanel1;
+       private JSlider borderOValue;
+       private JSlider opacityValue;
+       private JSlider contrastValue;
+       private JSlider brightnessValue;
+       private JComboBox eThickness;
+       private JCheckBox edgeColor;
+       private JButton sECButton;
+
+       private ImageAnnotation preview;
+       private PreviewPanel previewPanel;
+       
+       private ImageAnnotation mAnnotation;
+
+       public ImageAnnotationPanel(ImageAnnotation mAnnotation, PreviewPanel 
previewPanel, int width, int height) {
+               this.mAnnotation=mAnnotation;
+               this.previewPanel = previewPanel;
+               
this.preview=(ImageAnnotation)previewPanel.getPreviewAnnotation();
+               this.WIDTH = width;
+               this.HEIGHT = height;
+               initComponents();
+               setSize(width,height);
+       }
+
+       private void initComponents() {
+               setMaximumSize(new java.awt.Dimension(WIDTH, HEIGHT));
+               setMinimumSize(new java.awt.Dimension(WIDTH, HEIGHT));
+               setLayout(null);
+               setBorder(BorderFactory.createLoweredBevelBorder());
+
+               // Upper left components
+               //
+
+               int y = TOP;
+               // Border color
+               {
+                       // Border color
+                       edgeColor = new javax.swing.JCheckBox();
+                       edgeColor.setText("Border Color");
+                       if (mAnnotation.getBorderColor() != null) 
edgeColor.setSelected(true);
+                       edgeColor.addActionListener(new 
java.awt.event.ActionListener() {
+                               public void 
actionPerformed(java.awt.event.ActionEvent evt) {
+                                   edgeColorActionPerformed(evt);
+                               }
+                       });             
+                       add(edgeColor);
+                       edgeColor.setBounds(LEFT, y, 
edgeColor.getPreferredSize().width, 20);
+       
+                       sECButton = new javax.swing.JButton();
+                       sECButton.setText("Select Edge Color");
+                       if(edgeColor.isSelected())
+                               sECButton.setEnabled(true);
+                       else
+                               sECButton.setEnabled(false);
+       
+                       sECButton.addActionListener(new 
java.awt.event.ActionListener() {
+                               public void 
actionPerformed(java.awt.event.ActionEvent evt) {
+                                   sECButtonActionPerformed(evt);
+                               }
+                       });        
+                       add(sECButton);
+                       sECButton.setBounds(COLUMN1, y, 
sECButton.getPreferredSize().width, 20);
+               }
+       
+               // Border opacity
+               {
+                       y = y+25;
+                       JLabel borderOLabel = new JLabel("Border Opacity");
+                       borderOLabel.setBounds(LEFT, y, 
borderOLabel.getPreferredSize().width, 20);
+                       add(borderOLabel);
+       
+                       borderOValue = new JSlider(0, 100);
+                       borderOValue.setMajorTickSpacing(100);
+                       borderOValue.setPaintTicks(true);
+                       borderOValue.setPaintLabels(true);
+                       borderOValue.setValue(100);
+                       borderOValue.setBounds(COLUMN1, y, RIGHT-COLUMN1, 
borderOValue.getPreferredSize().height);
+                       borderOValue.setEnabled(false);
+                       borderOValue.addChangeListener(new ChangeListener() {
+                               public void stateChanged(ChangeEvent evt) {
+                                       
updateBorderOpacity(borderOValue.getValue());
+                               }
+                       });
+                       add(borderOValue);
+               }
+
+               // Border thickness
+               {
+                       y = y+50;
+                       JLabel jLabel6 = new JLabel();
+                       jLabel6.setText("Border Thickness");
+                       jLabel6.setBounds(LEFT, y, 
jLabel6.getPreferredSize().width, 14);
+                       add(jLabel6);
+
+                       eThickness = new javax.swing.JComboBox();
+                       eThickness.setModel(new 
javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", 
"6", "7", "8", "9", "10", "11", "12", "13" }));
+                       eThickness.setSelectedIndex(1);
+                       for(int i=0;i<eThickness.getModel().getSize();i++){
+                               if( 
((int)mAnnotation.getBorderWidth())==Integer.parseInt((String)eThickness.getModel().getElementAt(i))
 ){
+                                       eThickness.setSelectedIndex(i);
+                               break;
+                               }
+                       }
+                       eThickness.addActionListener(new 
java.awt.event.ActionListener() {
+                               public void 
actionPerformed(java.awt.event.ActionEvent evt) {
+                                   eThicknessActionPerformed(evt);
+                               }
+                       });      
+                       eThickness.setBounds(COLUMN1, y, 42, 20);
+                       add(eThickness);
+               }
+
+               y = y+35;
+               JLabel adjustmentsLabel = new JLabel("Image Adjustments");
+               adjustmentsLabel.setBounds(LEFT, y, 
adjustmentsLabel.getPreferredSize().width, 
+                                          
adjustmentsLabel.getPreferredSize().height);
+               add(adjustmentsLabel);
+               // Image opacity
+               {
+                       y = y+25;
+                       JLabel opacityLabel = new JLabel("Opacity");
+                       opacityLabel.setBounds(LEFT+5, y, 
opacityLabel.getPreferredSize().width, 20);
+                       add(opacityLabel);
+
+                       opacityValue = new JSlider(0, 100);
+                       opacityValue.setMajorTickSpacing(100);
+                       opacityValue.setPaintTicks(true);
+                       opacityValue.setPaintLabels(true);
+                       opacityValue.setValue(100);
+                       opacityValue.setBounds(COLUMN1, y, RIGHT-COLUMN1, 
opacityValue.getPreferredSize().height);
+                       opacityValue.addChangeListener(new ChangeListener() {
+                               public void stateChanged(ChangeEvent evt) {
+                                       updateOpacity(opacityValue.getValue());
+                               }
+                       });
+                       add(opacityValue);
+               }
+
+               // Brightness
+               {
+                       y = y+50;
+                       JLabel lightLabel = new JLabel("Brightness");
+                       lightLabel.setBounds(LEFT+5, y, 
lightLabel.getPreferredSize().width, 20);
+                       add(lightLabel);
+
+                       brightnessValue = new JSlider(-100, 100);
+                       brightnessValue.setMajorTickSpacing(100);
+                       brightnessValue.setPaintTicks(true);
+                       brightnessValue.setPaintLabels(true);
+                       brightnessValue.setValue(0);
+                       brightnessValue.setBounds(COLUMN1, y, RIGHT-COLUMN1, 
brightnessValue.getPreferredSize().height);
+                       brightnessValue.addChangeListener(new ChangeListener() {
+                               public void stateChanged(ChangeEvent evt) {
+                                       
updateBrightness(brightnessValue.getValue());
+                               }
+                       });
+                       add(brightnessValue);
+               }
+
+               // Contrast
+               {
+                       y = y+50;
+                       JLabel contrastLabel = new JLabel("Contrast");
+                       contrastLabel.setBounds(LEFT+5, y, 
contrastLabel.getPreferredSize().width, 20);
+                       add(contrastLabel);
+
+                       contrastValue = new JSlider(-100, 100);
+                       contrastValue.setMajorTickSpacing(100);
+                       contrastValue.setPaintTicks(true);
+                       contrastValue.setPaintLabels(true);
+                       contrastValue.setValue(0);
+                       contrastValue.setBounds(COLUMN1, y, RIGHT-COLUMN1, 
contrastValue.getPreferredSize().height);
+                       contrastValue.addChangeListener(new ChangeListener() {
+                               public void stateChanged(ChangeEvent evt) {
+                                       
updateContrast(contrastValue.getValue());
+                               }
+                       });
+                       add(contrastValue);
+               }
+
+               iModifySAPreview();     
+       }
+       
+       public ImageAnnotation getPreview(){
+               return preview;
+       }
+       
+       public void iModifySAPreview(){
+               preview.setBorderColor(mAnnotation.getBorderColor());
+               preview.setBorderWidth( Integer.parseInt( 
(String)(eThickness.getModel().getSelectedItem()) ) );
+               preview.setImageOpacity((float)opacityValue.getValue()/100.0f);
+               preview.setImageBrightness(brightnessValue.getValue());
+               preview.setImageContrast(contrastValue.getValue());
+               previewPanel.repaint();
+       }       
+       
+       public void modifySAPreview(){
+               preview.setBorderWidth( Integer.parseInt( 
(String)(eThickness.getModel().getSelectedItem()) ) );
+       
+               previewPanel.repaint();
+       }           
+
+       private void edgeColorActionPerformed(java.awt.event.ActionEvent evt) {
+               //Edge Color
+               if(edgeColor.isSelected()) {
+                       sECButton.setEnabled(true);
+                       borderOValue.setEnabled(true);
+               } else {
+                       sECButton.setEnabled(false);
+                       preview.setBorderColor(null);
+                       borderOValue.setEnabled(false);
+               }
+       }
+
+       private void eThicknessActionPerformed(java.awt.event.ActionEvent evt) {
+               //Edge Thickness
+               modifySAPreview();
+       }
+
+       private void sECButtonActionPerformed(java.awt.event.ActionEvent evt) {
+               //sECButton
+               final SelectColor sASelectColor=new 
SelectColor(mAnnotation.getBorderColor());
+               sASelectColor.setOKListener( new ActionListener() {
+                       public void actionPerformed(ActionEvent evt) {
+                               Color clr = sASelectColor.getColor();
+                               
preview.setBorderColor(mixColor(clr,borderOValue.getValue()));
+                               previewPanel.repaint();
+                       }
+               });
+       
+               sASelectColor.setVisible(true);
+               sASelectColor.setSize(435, 420);                
+               //2 -> EdgeColor
+       }
+
+       private void updateBorderOpacity(int opacity) {
+               
preview.setBorderColor(mixColor(preview.getBorderColor(),opacity));
+               previewPanel.repaint();
+       }
+
+       private void updateOpacity(int opacity) {
+               preview.setImageOpacity((float)opacity/100.0f); 
+               previewPanel.repaint();
+       }
+
+       private void updateBrightness(int brightness) {
+               preview.setImageBrightness(brightness); 
+               previewPanel.repaint();
+       }
+
+       private void updateContrast(int contrast) {
+               preview.setImageContrast(contrast); 
+               previewPanel.repaint();
+       }
+
+       private Paint mixColor(Paint p, int value) {
+               if (p == null || !(p instanceof Color)) return p;
+               Color c = (Color)p;
+               return new Color(c.getRed(), c.getGreen(), c.getBlue(), 
value*255/100);
+       }
+}
+

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/dialogs/PreviewPanel.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/dialogs/PreviewPanel.java
       2012-06-02 00:16:11 UTC (rev 29430)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/dialogs/PreviewPanel.java
       2012-06-02 02:15:29 UTC (rev 29431)
@@ -29,6 +29,7 @@
                // Get the background paint for this view
                Paint backgroundPaint = 
mAnnotation.getCyAnnotator().getView().getBackgroundPaint();
                setBackground((Color)backgroundPaint); // Set our background to 
match
+               c.setBackground(new Color(255,255,255,0)); // Make our 
background transparent
 
                // Border it
                TitledBorder title = 
BorderFactory.createTitledBorder("Preview");

Modified: 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/dialogs/ShapeAnnotationPanel.java
===================================================================
--- 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/dialogs/ShapeAnnotationPanel.java
       2012-06-02 00:16:11 UTC (rev 29430)
+++ 
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/dialogs/ShapeAnnotationPanel.java
       2012-06-02 02:15:29 UTC (rev 29431)
@@ -198,7 +198,7 @@
                        add(jLabel6);
 
                        eThickness = new javax.swing.JComboBox();
-                       eThickness.setModel(new 
javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", 
"7", "8", "9", "10", "11", "12", "13" }));
+                       eThickness.setModel(new 
javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", 
"6", "7", "8", "9", "10", "11", "12", "13" }));
                        eThickness.setSelectedIndex(1);
                        for(int i=0;i<eThickness.getModel().getSize();i++){
                                if( 
((int)mAnnotation.getBorderWidth())==Integer.parseInt((String)eThickness.getModel().getElementAt(i))
 ){

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