Author: scooter
Date: 2012-05-30 00:38:10 -0700 (Wed, 30 May 2012)
New Revision: 29388
Added:
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/GraphicsUtilities.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/annotations/TextAnnotationImpl.java
Log:
Oops -- missed these.
Added:
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
(rev 0)
+++
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/AbstractAnnotation.java
2012-05-30 07:38:10 UTC (rev 29388)
@@ -0,0 +1,325 @@
+package org.cytoscape.ding.impl.cyannotator.annotations;
+
+import java.awt.AlphaComposite;
+import java.awt.Canvas;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Paint;
+import java.awt.Point;
+import java.awt.RenderingHints;
+
+import java.awt.geom.Point2D;
+
+import java.util.List;
+import java.util.HashSet;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+
+import org.cytoscape.ding.impl.ArbitraryGraphicsCanvas;
+import org.cytoscape.ding.impl.ContentChangeListener;
+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.ArrowAnnotation;
+
+/**
+ *
+ * @author Avinash Thummala
+ */
+
+//A BasicAnnotation Class
+//
+
+public class AbstractAnnotation extends Component implements Annotation {
+ private static int nextAnnotationNumber = 0;
+
+ private boolean selected=false;
+
+ private double globalZoom = 1.0;
+ private double myZoom = 1.0;
+ protected boolean usedForPreviews=false;
+
+ private ArbitraryGraphicsCanvas canvas;
+ private DGraphView.Canvas canvasName;
+ private CyAnnotator cyAnnotator;
+ private DGraphView view;
+ private int annotationNumber;
+
+ private Set<ArrowAnnotation> arrowList;
+
+ protected static final String ID="id";
+ protected static final String ZOOM="zoom";
+ protected static final String X="x";
+ protected static final String Y="y";
+ protected static final String CANVAS="canvas";
+ protected static final String TYPE="type";
+
+ public AbstractAnnotation(CyAnnotator cyAnnotator, DGraphView view) {
+ this.view = view;
+ this.cyAnnotator = cyAnnotator;
+ arrowList = new HashSet<ArrowAnnotation>();
+ this.canvas =
(ArbitraryGraphicsCanvas)(view.getCanvas(DGraphView.Canvas.FOREGROUND_CANVAS));
+ this.canvasName = DGraphView.Canvas.FOREGROUND_CANVAS;
+ this.annotationNumber = nextAnnotationNumber++;
+ }
+
+ public AbstractAnnotation(AbstractAnnotation c) {
+ this.view = c.view;
+ this.cyAnnotator = c.cyAnnotator;
+ arrowList = new HashSet<ArrowAnnotation>(c.arrowList);
+ this.canvas = c.canvas;
+ this.canvasName = c.canvasName;
+ this.annotationNumber = nextAnnotationNumber++;
+ }
+
+ public AbstractAnnotation(CyAnnotator cyAnnotator, DGraphView view,
+ double x, double y, double zoom) {
+ this.cyAnnotator = cyAnnotator;
+ this.view = view;
+ this.globalZoom=zoom;
+ this.canvas =
(ArbitraryGraphicsCanvas)(view.getCanvas(DGraphView.Canvas.FOREGROUND_CANVAS));
+ this.canvasName = DGraphView.Canvas.FOREGROUND_CANVAS;
+ arrowList = new HashSet<ArrowAnnotation>();
+ // super.setBackground(Color.BLUE);
+ setLocation((int)x, (int)y);
+ this.annotationNumber = nextAnnotationNumber++;
+ }
+
+ public AbstractAnnotation(CyAnnotator cyAnnotator, DGraphView view,
Map<String, String> argMap) {
+ this.cyAnnotator = cyAnnotator;
+ this.view = view;
+ Point2D coords = getComponentCoordinates(argMap);
+ this.globalZoom = Double.parseDouble(argMap.get(ZOOM));
+ String canvasString = argMap.get(CANVAS);
+ if (canvasString != null && canvasString.equals(BACKGROUND)) {
+ this.canvas =
(ArbitraryGraphicsCanvas)(view.getCanvas(DGraphView.Canvas.BACKGROUND_CANVAS));
+ this.canvasName = DGraphView.Canvas.BACKGROUND_CANVAS;
+ } else {
+ this.canvas =
(ArbitraryGraphicsCanvas)(view.getCanvas(DGraphView.Canvas.FOREGROUND_CANVAS));
+ this.canvasName = DGraphView.Canvas.FOREGROUND_CANVAS;
+ }
+ arrowList = new HashSet<ArrowAnnotation>();
+ setLocation((int)coords.getX(), (int)coords.getY());
+ this.annotationNumber = nextAnnotationNumber++;
+ // super.setBackground(Color.YELLOW);
+ }
+
+ public String toString() {
+ return "annotation "+annotationNumber+" at "+getX()+",
"+getY()+" zoom="+globalZoom+" on canvas "+canvasName;
+ }
+
+ @Override
+ public String getCanvasName() {
+ if (canvasName.equals(DGraphView.Canvas.BACKGROUND_CANVAS))
+ return BACKGROUND;
+ else
+ return FOREGROUND;
+ }
+
+ @Override
+ public void setCanvas(String cnvs) {
+ if (cnvs.equals(BACKGROUND)) {
+ canvasName = DGraphView.Canvas.BACKGROUND_CANVAS;
+ } else {
+ canvasName = DGraphView.Canvas.FOREGROUND_CANVAS;
+ }
+ this.canvas =
(ArbitraryGraphicsCanvas)(view.getCanvas(canvasName));
+ for (ArrowAnnotation arrow: arrowList)
+ setCanvas(cnvs);
+ }
+
+ @Override
+ public void changeCanvas(String cnvs) {
+ // Are we really changing anything?
+ if ((cnvs.equals(BACKGROUND) &&
canvasName.equals(DGraphView.Canvas.BACKGROUND_CANVAS)) ||
+ (cnvs.equals(FOREGROUND) &&
canvasName.equals(DGraphView.Canvas.FOREGROUND_CANVAS)))
+ return;
+
+ for (ArrowAnnotation arrow: arrowList)
+ changeCanvas(cnvs);
+
+ // Remove ourselves from the current canvas
+ canvas.remove(this);
+
+ // Set the new canvas
+ setCanvas(cnvs);
+
+ // Add ourselves
+ canvas.add(this);
+ }
+
+ @Override
+ public JComponent getCanvas() {
+ return (JComponent)canvas;
+ }
+
+ public Component getComponent() {
+ return (Component)this;
+ }
+
+ @Override
+ public CyAnnotator getCyAnnotator() {return cyAnnotator;}
+
+ public void moveAnnotation(Point2D location) {
+ setLocation((int)location.getX(), (int)location.getY());
+ cyAnnotator.moveAnnotation(this);
+ }
+
+ public void setLocation(int x, int y) {
+ super.setLocation(x, y);
+ canvas.modifyComponentLocation(x, y, this);
+ }
+
+ public void removeAnnotation() {
+ canvas.remove(this);
+ cyAnnotator.removeAnnotation(this);
+ for (ArrowAnnotation arrow: arrowList)
+ removeAnnotation();
+ }
+
+ public void resizeAnnotation(double width, double height) {};
+
+ public double getZoom() { return globalZoom; }
+ public void setZoom(double zoom) {
+ globalZoom = zoom;
+ updateAnnotationAttributes();
+ }
+
+ public double getSpecificZoom() {return myZoom; }
+ public void setSpecificZoom(double zoom) {
+ myZoom = zoom;
+ updateAnnotationAttributes();
+ }
+
+ public boolean isSelected() { return selected; }
+ public void setSelected(boolean selected) {
+ this.selected = selected;
+ cyAnnotator.setSelectedAnnotation(this, selected);
+ updateAnnotationAttributes();
+ }
+
+ public void addArrow(ArrowAnnotation arrow) {
+ arrowList.add(arrow);
+ };
+ public void removeArrow(ArrowAnnotation arrow) {
+ arrowList.remove(arrow);
+ }
+ public Set<ArrowAnnotation> getArrows() { return arrowList; }
+
+ @Override
+ public Map<String,String> getArgMap() {
+ Map<String, String> argMap = new HashMap<String, String>();
+ addNodeCoordinates(argMap);
+ argMap.put(ZOOM,Double.toString(this.globalZoom));
+ if (canvasName.equals(DGraphView.Canvas.BACKGROUND_CANVAS))
+ argMap.put(CANVAS, BACKGROUND);
+ else
+ argMap.put(CANVAS, FOREGROUND);
+
+ return argMap;
+ }
+
+ public boolean usedForPreviews() { return usedForPreviews; }
+
+ public void setUsedForPreviews(boolean v) { usedForPreviews = v; }
+
+ public void drawAnnotation(Graphics g, double x,
+ double y, double scaleFactor) {
+ for (ArrowAnnotation arrow: arrowList) {
+ arrow.drawAnnotation(g, x, y, scaleFactor);
+ }
+ }
+
+ public void update() {
+ cyAnnotator.update();
+ }
+
+ // Component overrides
+ @Override
+ 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);
+
+ 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);
+ }
+ }
+
+ public JFrame getModifyDialog() {return null;}
+
+ // Protected methods
+ protected void updateAnnotationAttributes() {
+ if (!usedForPreviews) {
+ cyAnnotator.addAnnotation(this);
+ if (arrowList != null) {
+ for (ArrowAnnotation annotation: arrowList) {
+ cyAnnotator.addAnnotation(annotation);
+ }
+ }
+ contentChanged();
+ }
+ }
+
+ protected String convertColor(Paint clr) {
+ if (clr == null)
+ return null;
+ if (clr instanceof Color)
+ return Integer.toString(((Color)clr).getRGB());
+ return clr.toString();
+ }
+
+ protected Color getColor(String strColor) {
+ if (strColor == null)
+ return null;
+ return new Color(Integer.parseInt(strColor));
+ }
+
+ // Private methods
+ private void addNodeCoordinates(Map<String, String> argMap) {
+ Point2D xy = getNodeCoordinates(getX(), getY());
+ argMap.put(X,Double.toString(xy.getX()));
+ argMap.put(Y,Double.toString(xy.getY()));
+ }
+
+ private Point2D getComponentCoordinates(Map<String, String> argMap) {
+ // Get our current transform
+ double[] nextLocn = new double[2];
+ nextLocn[0] = Double.parseDouble(argMap.get(X));
+ nextLocn[1] = Double.parseDouble(argMap.get(Y));
+
+ view.xformNodeToComponentCoords(nextLocn);
+
+ return new Point2D.Double(nextLocn[0], nextLocn[1]);
+ }
+
+ private Point2D getNodeCoordinates(double x, double y) {
+ // Get our current transform
+ double[] nextLocn = new double[2];
+ nextLocn[0] = x;
+ nextLocn[1] = y;
+ view.xformComponentToNodeCoords(nextLocn);
+ return new Point2D.Double(nextLocn[0], nextLocn[1]);
+ }
+
+ public void contentChanged() {
+ if (view == null) return;
+ final ContentChangeListener lis =
view.getContentChangeListener();
+ if (lis != null)
+ lis.contentChanged();
+ }
+
+}
Added:
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/GraphicsUtilities.java
===================================================================
---
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/GraphicsUtilities.java
(rev 0)
+++
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/GraphicsUtilities.java
2012-05-30 07:38:10 UTC (rev 29388)
@@ -0,0 +1,216 @@
+package org.cytoscape.ding.impl.cyannotator.annotations;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Paint;
+import java.awt.Shape;
+import java.awt.geom.RoundRectangle2D;
+import java.awt.geom.Ellipse2D;
+import java.awt.geom.Path2D;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+
+import org.cytoscape.ding.impl.cyannotator.api.ShapeAnnotation;
+import org.cytoscape.ding.impl.cyannotator.api.ShapeAnnotation.ShapeType;
+
+class GraphicsUtilities {
+ private static double halfPI = Math.PI/2.0;
+
+ protected static final ShapeType supportedShapes[] = {
+ ShapeType.RECTANGLE, ShapeType.ROUNDEDRECTANGLE,
ShapeType.ELLIPSE, ShapeType.STAR5,
+ ShapeType.TRIANGLE, ShapeType.STAR6, ShapeType.HEXAGON,
ShapeType.PENTAGON
+ };
+
+ static public Shape getShape(ShapeType shapeType, double x,
double y, double width, double height) {
+ switch(shapeType) {
+ case RECTANGLE: return rectangleShape(x, y,
width, height);
+ case ROUNDEDRECTANGLE: return
roundedRectangleShape(x, y, width, height);
+ case ELLIPSE: return ellipseShape(x, y, width,
height);
+ case STAR5: return starShape(5, x, y, width,
height); // 5 pointed star
+ case STAR6: return starShape(6, x, y, width,
height); // 6 pointed star
+ case TRIANGLE: return regularPolygon(3, x, y,
width, height); // Pentagon
+ case PENTAGON: return regularPolygon(5, x, y,
width, height); // Pentagon
+ case HEXAGON: return regularPolygon(6, x, y,
width, height); // Hexagon
+ default: return rectangleShape(x, y, width,
height);
+ }
+ }
+
+ static public ShapeType getShapeType(String shapeName) {
+ for (ShapeType type: supportedShapes) {
+ if (shapeName.equals(type.shapeName()))
+ return type;
+ }
+ return ShapeType.RECTANGLE; // If we can't do anything
else...
+ }
+
+ static public ShapeType getShapeType(int shapeNumber) {
+ for (ShapeType type: supportedShapes) {
+ if (shapeNumber == type.ordinal())
+ return type;
+ }
+ return ShapeType.RECTANGLE; // If we can't do anything
else...
+ }
+
+ static public ShapeType[] getSupportedShapes() {
+ return supportedShapes;
+ }
+
+ // Given a position and a size, draw a shape. We use the
ShapeAnnotation to get the
+ // shape itself, colors, strokes, etc.
+ static public void drawShape(Graphics g, double x, double y,
double width, double height,
+ ShapeAnnotation annotation) {
+ Graphics2D g2 = (Graphics2D)g;
+
+ // System.out.println("drawShape:
("+x+","+y+","+width+"x"+height+")");
+
+ // Get the shape
+ Shape shape = getShape(annotation.getShapeType(), x, y,
width, height);
+ // System.out.println("drawShape: shape =
"+shape.toString());
+
+ // Stroke it
+ float border = (float)annotation.getBorderWidth();
+ if (border < 1.0f) border = 1.0f;
+
+ // Set our fill color
+ if (annotation.getFillColor() != null) {
+ // System.out.println("drawShape: fill color =
"+annotation.getFillColor());
+ // System.out.println("drawShape: fill opacity
= "+annotation.getFillOpacity());
+ g2.setPaint(mixColor(annotation.getFillColor(),
annotation.getFillOpacity()));
+ g2.fill(shape);
+ }
+
+ if (annotation.getBorderColor() != null &&
!annotation.isSelected()) {
+ // System.out.println("drawShape: border color
= "+annotation.getBorderColor());
+ // System.out.println("drawShape: border
opacity = "+annotation.getBorderOpacity());
+
g2.setPaint(mixColor(annotation.getBorderColor(),
annotation.getBorderOpacity()));
+ g2.setStroke(new BasicStroke(border));
+ g2.draw(shape);
+ } else if (annotation.isSelected()) {
+ // Create a yellow border around the shape
+ BasicStroke stroke = new BasicStroke(border);
+ Shape strokedShape =
stroke.createStrokedShape(shape);
+ g2.setPaint(Color.YELLOW);
+ g2.draw(strokedShape);
+ } else {
+ g2.draw(shape);
+ }
+ }
+
+ // Assign opacity
+ static Paint mixColor(Paint p, double opacity) {
+ if (p instanceof Color) {
+ Color c = (Color)p;
+ return new Color(c.getRed(), c.getGreen(),
c.getBlue(), (int)(opacity*(255.0)/100.0));
+ }
+ return p;
+ }
+
+
+ // Shapes.
+ static private Shape rectangleShape(double x, double y, double
width, double height) {
+ // System.out.println("Drawing rectangle: "+x+","+y+"
"+width+"x"+height);
+ return new Rectangle2D.Double(x, y, width, height);
+
+ }
+
+ static private Shape roundedRectangleShape(double x, double y,
double width, double height) {
+ return new RoundRectangle2D.Double(x, y, width, height,
width/10, width/10);
+ }
+
+ static private Shape ellipseShape(double x, double y, double
width, double height) {
+ return new Ellipse2D.Double(x, y, width, height);
+ }
+
+ static private Shape regularPolygon(int sides, double x, double
y, double width, double height) {
+ Path2D poly = new Path2D.Double(Path2D.WIND_EVEN_ODD,
12);
+ width = width/2;
+ height = height/2;
+ x = x+width;
+ y = y+height;
+ Point2D.Double points[] = new Point2D.Double[sides];
+ for (int i = 0; i < sides; i++) {
+ double x1 = circleX(sides, i) * width + x;
+ double y1 = circleY(sides, i) * height + y;
+ double x2 = circleX(sides, (i+1)%sides) * width
+ x;
+ double y2 = circleY(sides, (i+1)%sides) *
height + y;
+ points[i] = new Point2D.Double(x1, y1);
+ points[(i+1)%sides] = new Point2D.Double(x2,
y2);
+ }
+ // Now, add the points
+ poly.moveTo(points[0].getX(), points[0].getY());
+ for (int i = 1; i < sides; i++) {
+ poly.lineTo(points[i].getX(), points[i].getY());
+ }
+ poly.closePath();
+ return poly;
+ }
+
+ static private Shape starShape(int sides, double x, double y,
double width, double height) {
+ Path2D poly = new Path2D.Double(Path2D.WIND_EVEN_ODD,
12);
+ width = width/2;
+ height = height/2;
+ x = x+width;
+ y = y+height;
+ int nPoints = sides*2;
+ Point2D.Double points[] = new Point2D.Double[nPoints];
+ for (int i = 0; i < sides; i++) {
+ double x1 = circleX(sides, i) * width + x;
+ double y1 = circleY(sides, i) * height + y;
+ double x2 = circleX(sides, (i+2)%sides) * width
+ x;
+ double y2 = circleY(sides, (i+2)%sides) *
height + y;
+ points[i*2] = new Point2D.Double(x1, y1);
+ points[(i*2+4)%nPoints] = new
Point2D.Double(x2, y2);
+ }
+
+ // Fill in the intersection points
+ for (int i = 0; i < nPoints; i=i+2) {
+ int p1 = i;
+ int p2 = (i+4)%nPoints;
+ int p3 = (i+2)%nPoints;
+ int p4 = (p3+nPoints-4)%nPoints;
+
+ points[(i+1)%nPoints] =
findIntersection(points[p1],points[p2],
+
points[p3], points[p4]);
+ }
+
+ // Now, add the points
+ poly.moveTo(points[0].getX(), points[0].getY());
+ for (int i = 1; i < nPoints; i++) {
+ poly.lineTo(points[i].getX(), points[i].getY());
+ }
+ poly.closePath();
+ return poly;
+ }
+
+ static double circleX(int sides, int angle) {
+ double coeff = (double)angle/(double)sides;
+ return epsilon(Math.cos(2*coeff*Math.PI-halfPI));
+ }
+
+ static double circleY(int sides, int angle) {
+ double coeff = (double)angle/(double)sides;
+ return epsilon(Math.sin(2*coeff*Math.PI-halfPI));
+ }
+
+ static double epsilon(double v) {
+ if (Math.abs(v) < 1.0E-10) return 0.0;
+ return v;
+ }
+
+ static Point2D.Double findIntersection(Point2D.Double p1,
Point2D.Double p2,
+ Point2D.Double p3,
Point2D.Double p4) {
+
+ double denominator = (p4.getY()-p3.getY())*(p2.getX() -
p1.getX()) -
+ (p4.getX()-p3.getX())*(p2.getY() -
p1.getY());
+
+ double ua = ((p4.getX()-p3.getX())*(p1.getY() -
p3.getY()) -
+ (p4.getY()-p3.getY())*(p1.getX() -
p3.getX()))/denominator;
+
+ double x = epsilon(p1.getX() + ua * (p2.getX() -
p1.getX()));
+ double y = epsilon(p1.getY() + ua * (p2.getY() -
p1.getY()));
+ return new Point2D.Double(x, y);
+ }
+
+}
Added:
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
(rev 0)
+++
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/ImageAnnotationImpl.java
2012-05-30 07:38:10 UTC (rev 29388)
@@ -0,0 +1,276 @@
+package org.cytoscape.ding.impl.cyannotator.annotations;
+
+import java.awt.AlphaComposite;
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Image;
+import java.awt.RenderingHints;
+import java.awt.image.BufferedImage;
+import java.awt.image.VolatileImage;
+
+import java.util.Map;
+
+import java.net.URL;
+
+import javax.swing.JFrame;
+
+import org.cytoscape.ding.customgraphics.CyCustomGraphics;
+import org.cytoscape.ding.customgraphics.CustomGraphicsManager;
+import org.cytoscape.ding.customgraphics.ImageUtil;
+import org.cytoscape.ding.customgraphics.bitmap.URLImageCustomGraphics;
+
+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.ImageAnnotation;
+import org.cytoscape.ding.impl.cyannotator.modify.mImageAnnotation;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ImageAnnotationImpl extends AbstractAnnotation implements
ImageAnnotation {
+ private BufferedImage image;
+ private URL url = null;
+
+ public static final String NAME="IMAGE";
+ private static final String URL="URL";
+ private static final String WIDTH="width";
+ private static final String HEIGHT="height";
+
+ protected double imageWidth=0, imageHeight=0;
+ private BufferedImage resizedImage;
+ private CyCustomGraphics cg = null;
+ protected CustomGraphicsManager customGraphicsManager;
+
+ private static final Logger logger =
LoggerFactory.getLogger(ImageAnnotationImpl.class);
+
+
+ // XXX HACK to force the custom graphics manager to respect these
graphics
+ public void preserveCustomGraphics() {
+ for (CyCustomGraphics cg:
customGraphicsManager.getAllCustomGraphics()) {
+ customGraphicsManager.setUsedInCurrentSession(cg, true);
+ }
+ }
+
+ public ImageAnnotationImpl(CyAnnotator cyAnnotator, DGraphView view) {
super(cyAnnotator, view); }
+
+ public ImageAnnotationImpl(ImageAnnotationImpl c) {
+ super(c);
+ this.image = c.image;
+ this.customGraphicsManager = c.customGraphicsManager;
+ imageWidth=image.getWidth();
+ imageHeight=image.getHeight();
+ this.url = c.url;
+ }
+
+ public ImageAnnotationImpl(CyAnnotator cyAnnotator, DGraphView view,
int x, int y,
+ URL url, BufferedImage image, double zoom,
+ CustomGraphicsManager customGraphicsManager)
{
+ super(cyAnnotator, view, x, y, zoom);
+ this.image=image;
+ this.customGraphicsManager = customGraphicsManager;
+ imageWidth=image.getWidth();
+ imageHeight=image.getHeight();
+ this.url = url;
+ resizedImage=resize(image, (int)imageWidth, (int)imageHeight);
+ final Long id = customGraphicsManager.getNextAvailableID();
+ this.cg = new URLImageCustomGraphics(id, url.toString(), image);
+ customGraphicsManager.addCustomGraphics(cg, url);
+ customGraphicsManager.setUsedInCurrentSession(cg, true);
+ updateAnnotationAttributes();
+ }
+
+ public ImageAnnotationImpl(CyAnnotator cyAnnotator, DGraphView view,
+ Map<String, String> argMap,
CustomGraphicsManager customGraphicsManager) {
+ super(cyAnnotator, view, argMap);
+ this.customGraphicsManager = customGraphicsManager;
+
+ imageWidth = Double.parseDouble(argMap.get(WIDTH));
+ imageHeight = Double.parseDouble(argMap.get(HEIGHT));
+
+ this.image = null;
+ this.resizedImage = null;
+
+ // Get the image from the image pool
+ try {
+ this.url = new URL(argMap.get(URL));
+ this.cg =
customGraphicsManager.getCustomGraphicsBySourceURL(this.url);
+ if (cg != null) {
+ this.image =
ImageUtil.toBufferedImage(cg.getRenderedImage());
+ customGraphicsManager.addCustomGraphics(cg,
this.url);
+
customGraphicsManager.setUsedInCurrentSession(cg, true);
+ resizedImage=resize(image,
(int)image.getWidth(), (int)image.getHeight());
+ }
+ } catch (Exception e) {
+ logger.warn("Unable to restore image
'"+argMap.get(URL)+"'",e);
+ return;
+ }
+ updateAnnotationAttributes();
+ }
+
+ public Map<String,String> getArgMap() {
+ Map<String, String> argMap = super.getArgMap();
+ argMap.put(TYPE, NAME);
+ argMap.put(URL, url.toString());
+ argMap.put(WIDTH, Double.toString(imageWidth));
+ argMap.put(HEIGHT, Double.toString(imageHeight));
+ customGraphicsManager.setUsedInCurrentSession(cg, true);
+
+ return argMap;
+ }
+
+ public void reloadImage()
+ {
+ // Get the image from the image pool again
+ try {
+ this.cg =
customGraphicsManager.getCustomGraphicsBySourceURL(this.url);
+ if (cg != null) {
+ this.image =
ImageUtil.toBufferedImage(cg.getRenderedImage());
+ customGraphicsManager.addCustomGraphics(cg,
this.url);
+
customGraphicsManager.setUsedInCurrentSession(cg, true);
+ } else {
+ return;
+ }
+ } catch (Exception e) {
+ logger.warn("Unable to restore image '"+this.url+"'",e);
+ return;
+ }
+ resizedImage=resize(image, (int)imageWidth, (int)imageHeight);
+
+ updateAnnotationAttributes();
+ }
+
+ public Image getImage() {
+ return image;
+ }
+
+ public void setImage(Image image) {
+ if (image instanceof BufferedImage)
+ this.image = (BufferedImage)image;
+ else if (image instanceof VolatileImage)
+ this.image = ((VolatileImage)image).getSnapshot();
+ else
+ return;
+
+ this.imageWidth=this.image.getWidth();
+ this.imageHeight=this.image.getHeight();
+ resizedImage=resize(this.image, (int)resizedImage.getWidth(),
(int)resizedImage.getHeight());
+ getCyAnnotator().update();
+ }
+
+ public void setImage(URL url) {
+ this.url = url;
+ reloadImage();
+ }
+
+ //Returns a resized high quality BufferedImage
+ private static BufferedImage resize(BufferedImage image, 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);
+ }
+
+ int type = image.getType() == 0? BufferedImage.TYPE_INT_ARGB :
image.getType();
+ if(height==0)
+ height++;
+ if(width==0)
+ width++;
+ BufferedImage resizedImage = new BufferedImage(width, height,
type);
+ Graphics2D g = resizedImage.createGraphics();
+ g.setComposite(AlphaComposite.Src);
+
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);
+
+ g.drawImage(image, 0, 0, width, height, null);
+ g.dispose();
+ return resizedImage;
+ }
+
+ public void dropImage() {
+ customGraphicsManager.setUsedInCurrentSession(cg, false);
+ }
+
+ public JFrame getModifyDialog(Annotation annotation) {
+ return new mImageAnnotation(this);
+ }
+
+ @Override
+ public void drawAnnotation(Graphics g, double x, double y, double
scaleFactor) {
+ super.drawAnnotation(g, x, y, scaleFactor);
+
+ Graphics2D g2=(Graphics2D)g;
+
+ int width = (int)Math.round(imageWidth*scaleFactor/getZoom());
+ int height = (int)Math.round(imageHeight*scaleFactor/getZoom());
+ BufferedImage newImage =resize(image, width, height);
+ if (newImage == null) return;
+
+ boolean selected = isSelected();
+ setSelected(false);
+ g2.drawImage(newImage, (int)(x*scaleFactor),
(int)(y*scaleFactor), null);
+ setSelected(selected);
+ }
+
+ @Override
+ public void paint(Graphics g) {
+ super.paint(g);
+
+ Graphics2D g2=(Graphics2D)g;
+
+ if (resizedImage == null) return;
+
+ g2.drawImage(resizedImage, getX(), getY(), null);
+
+ if(isSelected()) {
+ g2.setColor(Color.YELLOW);
+ g2.setStroke(new BasicStroke(2.0f));
+ g2.drawRect(getX()-1, getY()-1, getAnnotationWidth()+1,
getAnnotationHeight()+1);
+ }
+ }
+
+
+ @Override
+ public void setSpecificZoom(double newZoom) {
+
+ double factor=newZoom/getSpecificZoom();
+
+ imageWidth=imageWidth*factor;
+ imageHeight=imageHeight*factor;
+
+ resizedImage=resize(image, (int)Math.round(imageWidth),
(int)Math.round(imageHeight));
+
+ setBounds(getX(), getY(), getAnnotationWidth(),
getAnnotationHeight());
+
+ super.setSpecificZoom(newZoom);
+ }
+
+
+ @Override
+ public void setZoom(double newZoom) {
+
+ double factor=newZoom/getZoom();
+
+ imageWidth=imageWidth*factor;
+ imageHeight=imageHeight*factor;
+
+ resizedImage=resize(image, (int)Math.round(imageWidth),
(int)Math.round(imageHeight));
+
+ setBounds(getX(), getY(), getAnnotationWidth(),
getAnnotationHeight());
+
+ super.setZoom(newZoom);
+ }
+
+
+ public int getAnnotationWidth() {
+ return (int)Math.round(imageWidth);
+ }
+
+ public int getAnnotationHeight() {
+ return (int)Math.round(imageHeight);
+ }
+}
Added:
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
(rev 0)
+++
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/ShapeAnnotationImpl.java
2012-05-30 07:38:10 UTC (rev 29388)
@@ -0,0 +1,217 @@
+package org.cytoscape.ding.impl.cyannotator.annotations;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Paint;
+import java.awt.Rectangle;
+import java.awt.Shape;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+
+import javax.swing.JFrame;
+
+import java.util.Map;
+
+import org.cytoscape.ding.impl.DGraphView;
+import org.cytoscape.ding.impl.cyannotator.CyAnnotator;
+import org.cytoscape.ding.impl.cyannotator.api.ShapeAnnotation;
+import org.cytoscape.ding.impl.cyannotator.api.ShapeAnnotation.ShapeType;
+import org.cytoscape.ding.impl.cyannotator.modify.mShapeAnnotation;
+
+public class ShapeAnnotationImpl extends AbstractAnnotation implements
ShapeAnnotation {
+ private ShapeType shapeType;
+ private double borderWidth;
+ private Paint borderColor = Color.BLACK; // These are paint's so we can
do gradients
+ private Paint fillColor = null; // These are paint's so we can do
gradients
+ private double borderOpacity = 100.0;
+ private double fillOpacity = 100.0;
+ private Shape shape = null;
+ private double shapeWidth = 0.0;
+ private double shapeHeight = 0.0;
+
+ public static final String NAME="SHAPE";
+ protected static final String WIDTH="width";
+ protected static final String HEIGHT="height";
+ protected static final String EDGECOLOR = "edgeColor";
+ protected static final String EDGETHICKNESS = "edgeThickness";
+ protected static final String EDGEOPACITY = "edgeOpacity";
+ protected static final String FILLCOLOR = "fillColor";
+ protected static final String FILLOPACITY = "fillOpacity";
+ protected static final String SHAPETYPE = "shapeType";
+
+
+ public ShapeAnnotationImpl(CyAnnotator cyAnnotator, DGraphView view,
double width, double height) {
+ super(cyAnnotator, view);
+ shapeWidth=width/2;
+ shapeHeight=height/3;
+ shapeType = ShapeType.RECTANGLE;
+ }
+
+ public ShapeAnnotationImpl(ShapeAnnotationImpl c, double width, double
height) {
+ super(c);
+ shapeWidth=width/2;
+ shapeHeight=height/3;
+ shapeType = c.getShapeType();
+ borderColor = c.getBorderColor();
+ borderWidth = c.getBorderWidth();
+ borderOpacity = c.getBorderOpacity();
+ fillOpacity = c.getFillOpacity();
+ fillColor = c.getFillColor();
+ shape = GraphicsUtilities.getShape(shapeType, 0.0, 0.0,
shapeWidth, shapeHeight);
+ }
+
+ public ShapeAnnotationImpl(CyAnnotator cyAnnotator, DGraphView view,
+ double x, double y, ShapeType shapeType,
+ double width, double height,
+ Paint fillColor, Paint edgeColor,
+ float edgeThickness) {
+ super(cyAnnotator, view, x, y, view.getZoom());
+
+ this.shapeType=shapeType;
+ this.fillColor=fillColor;
+ setFillColor(fillColor);
+ this.borderColor=edgeColor;
+ this.borderWidth=edgeThickness;
+ this.shapeWidth = width;
+ this.shapeHeight = height;
+ this.shape = GraphicsUtilities.getShape(shapeType, 0.0, 0.0,
shapeWidth, shapeHeight);
+ setSize((int)shapeWidth, (int)shapeHeight);
+ updateAnnotationAttributes();
+ }
+
+ public ShapeAnnotationImpl(CyAnnotator cyAnnotator, DGraphView view,
Map<String, String> argMap) {
+ super(cyAnnotator, view, argMap);
+ this.borderColor = getColor(argMap.get(EDGECOLOR));
+ this.fillColor = getColor(argMap.get(FILLCOLOR));
+ setFillColor(fillColor);
+ if (argMap.containsKey(FILLOPACITY))
+ this.fillOpacity = Double.parseDouble(argMap.get(FILLOPACITY));
+
+ this.shapeWidth = Double.parseDouble(argMap.get(WIDTH));
+ this.shapeHeight = Double.parseDouble(argMap.get(HEIGHT));
+ this.borderWidth = Double.parseDouble(argMap.get(EDGETHICKNESS));
+
+ if (argMap.containsKey(EDGEOPACITY))
+ this.borderOpacity = Double.parseDouble(argMap.get(EDGEOPACITY));
+
+ 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);
+ updateAnnotationAttributes();
+ }
+
+ public Map<String,String> getArgMap() {
+ Map<String, String> argMap = super.getArgMap();
+ argMap.put(TYPE,NAME);
+ if (this.fillColor != null)
+ argMap.put(FILLCOLOR,convertColor(this.fillColor));
+ argMap.put(FILLOPACITY, Double.toString(this.fillOpacity));
+
+ if (this.borderColor != null)
+ argMap.put(EDGECOLOR,convertColor(this.borderColor));
+ argMap.put(EDGETHICKNESS,Double.toString(this.borderWidth));
+ argMap.put(EDGEOPACITY, Double.toString(this.borderOpacity));
+ argMap.put(SHAPETYPE,
Integer.toString(this.shapeType.ordinal()));
+ argMap.put(WIDTH, Double.toString(this.shapeWidth));
+ argMap.put(HEIGHT, Double.toString(this.shapeHeight));
+ return argMap;
+ }
+
+ public ShapeType[] getSupportedShapes() {
+ return GraphicsUtilities.getSupportedShapes();
+ }
+
+ @Override
+ public void setZoom(double zoom) {
+ float factor=(float)(zoom/getZoom());
+
+ borderWidth*=factor;
+
+ shapeWidth*=factor;
+ shapeHeight*=factor;
+ // System.out.println("setZoom: size =
"+shapeWidth+"x"+shapeHeight);
+
+ setSize((int)shapeWidth, (int)shapeHeight);
+ super.setZoom(zoom);
+ }
+
+ @Override
+ public void setSpecificZoom(double zoom) {
+ float factor=(float)(zoom/getSpecificZoom());
+
+ shapeWidth*=factor;
+ shapeHeight*=factor;
+
+ setSize((int)shapeWidth, (int)shapeHeight);
+ super.setSpecificZoom(zoom);
+ }
+
+ public Rectangle getBounds() {
+ return new Rectangle(getX(), getY(), getWidth(), getHeight());
+ }
+
+ public Rectangle2D getBounds2D() {
+ return new Rectangle2D.Double(getX(), getY(), getWidth(),
getHeight());
+ }
+
+ public Shape getShape() {
+ return shape;
+ }
+
+ public ShapeType getShapeType() {return shapeType;}
+
+ public void setShapeType(ShapeType type) {
+ shapeType = type;
+ this.shape = GraphicsUtilities.getShape(shapeType, 0.0, 0.0,
shapeWidth, shapeHeight);
+ }
+
+ public double getBorderWidth() {return borderWidth;}
+ public void setBorderWidth(double width) { borderWidth = width; }
+
+ public Paint getBorderColor() {return borderColor;}
+ public Paint getFillColor() {return fillColor;}
+
+ public void setBorderColor(Paint border) {borderColor = border;}
+ public void setFillColor(Paint fill) {fillColor = fill;}
+
+ public double getBorderOpacity() {return borderOpacity;}
+ public double getFillOpacity() {return fillOpacity;}
+
+ public void setBorderOpacity(double opacity) {borderOpacity = opacity;}
+ public void setFillOpacity(double opacity) {fillOpacity = opacity;}
+
+ public void drawAnnotation(Graphics g, double x, double y, double
scaleFactor) {
+ super.drawAnnotation(g, x, y, scaleFactor);
+
+ int width = (int)(shapeWidth*scaleFactor/getZoom());
+ int height = (int)(shapeHeight*scaleFactor/getZoom());
+
+ boolean selected = isSelected();
+ setSelected(false);
+ GraphicsUtilities.drawShape(g, (int)(x*scaleFactor),
(int)(y*scaleFactor),
+ width, height, this);
+ setSelected(selected);
+ }
+
+ public void paint(Graphics g) {
+ super.paint(g);
+
+ Point2D p1 = getLocation();
+ if (usedForPreviews) {
+ p1 = new Point2D.Double(p1.getX()+shapeWidth/2,
p1.getY()+shapeHeight);
+ }
+ GraphicsUtilities.drawShape(g, (int)p1.getX(), (int)p1.getY(),
shapeWidth, shapeHeight, this);
+ }
+
+ public void setSize(double width, double height) {
+ shapeWidth = width;
+ shapeHeight = height;
+ setSize((int)shapeWidth, (int)shapeHeight);
+ }
+
+ public JFrame getModifyDialog() {
+ return new mShapeAnnotation(this);
+ }
+
+}
Added:
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
(rev 0)
+++
core3/impl/trunk/ding-impl/ding-presentation-impl/src/main/java/org/cytoscape/ding/impl/cyannotator/annotations/TextAnnotationImpl.java
2012-05-30 07:38:10 UTC (rev 29388)
@@ -0,0 +1,223 @@
+package org.cytoscape.ding.impl.cyannotator.annotations;
+
+import java.awt.BasicStroke;
+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 javax.swing.JFrame;
+
+import java.util.Map;
+
+import org.cytoscape.ding.impl.DGraphView;
+import org.cytoscape.ding.impl.cyannotator.CyAnnotator;
+import org.cytoscape.ding.impl.cyannotator.api.TextAnnotation;
+import org.cytoscape.ding.impl.cyannotator.modify.mTextAnnotation;
+
+public class TextAnnotationImpl extends AbstractAnnotation implements
TextAnnotation {
+ private String text;
+
+ public static final String NAME="TEXT";
+ 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 TextAnnotationImpl(CyAnnotator cyAnnotator, DGraphView view) {
super(cyAnnotator, view); }
+
+ public TextAnnotationImpl(TextAnnotationImpl c) {
+ super(c);
+ this.text = c.getText();
+ this.textColor = c.getTextColor();
+ this.fontSize = (float)c.getFontSize();
+ this.font = c.getFont();
+ }
+
+ public TextAnnotationImpl(CyAnnotator cyAnnotator, DGraphView view,
+ int x, int y, String text, int compCount,
double zoom){
+ super(cyAnnotator, view, x, y, zoom);
+ this.text=text;
+ this.font=new Font("Arial", Font.PLAIN, initialFontSize);
+ this.fontSize = (float)initialFontSize;
+ updateAnnotationAttributes();
+ }
+
+ // This constructor is used to construct a text annotation from an
+ // argument map.
+ public TextAnnotationImpl(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;
+ }
+
+ @Override
+ public void setZoom(double zoom) {
+
font=font.deriveFont(((float)(zoom/getZoom()))*font.getSize2D());
+
+ setSize(getAnnotationWidth(), getAnnotationHeight());
+ super.setZoom(zoom);
+ }
+
+ @Override
+ public void setSpecificZoom(double zoom) {
+
font=font.deriveFont(((float)(zoom/getSpecificZoom()))*font.getSize2D());
+
+ setSize(getAnnotationWidth(), getAnnotationHeight());
+ 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;
+ }
+
+ public JFrame getModifyDialog() {
+ return new mTextAnnotation(this);
+ }
+
+
+ public void drawAnnotation(Graphics g, double x, double y, double
scaleFactor) {
+ super.drawAnnotation(g, x, y, scaleFactor);
+
+ Graphics2D g2 = (Graphics2D) g;
+ g2.setColor(textColor);
+ Font tFont =
font.deriveFont(((float)(scaleFactor/getZoom()))*font.getSize2D());
+ FontMetrics fontMetrics=g.getFontMetrics(tFont);
+ g2.setFont(tFont);
+ g2.drawChars(getText().toCharArray(), 0, getText().length(),
+ (int)(x*scaleFactor),
(int)(y*scaleFactor)+fontMetrics.getHeight());
+ }
+
+ 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(), getY()+getTextHeight(g2));
+
+ if(isSelected()) {
+ //Selected Annotations will have a yellow border
+ g2.setColor(Color.YELLOW);
+ g2.setStroke(new BasicStroke(2.0f));
+ g2.drawRect(getX()-4, getY()-4, getTextWidth(g2)+8,
getTextHeight(g2)+8);
+ }
+ }
+
+ int getAnnotationWidth() {
+ return getTextWidth((Graphics2D)this.getGraphics());
+ }
+
+ int getAnnotationHeight() {
+ return getTextHeight((Graphics2D)this.getGraphics());
+ }
+
+ int getTextWidth(Graphics2D g2) {
+ FontMetrics fontMetrics=g2.getFontMetrics(font);
+ return fontMetrics.stringWidth(text);
+ }
+
+ int getTextHeight(Graphics2D g2) {
+ FontMetrics fontMetrics=g2.getFontMetrics(font);
+ return fontMetrics.getHeight();
+ }
+
+ 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);
+ }
+
+}
--
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.