KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > designer > views > InitialActionView


1 package com.opensymphony.workflow.designer.views;
2
3 import java.awt.*;
4 import java.awt.geom.Rectangle2D JavaDoc;
5
6 import org.jgraph.JGraph;
7 import org.jgraph.graph.CellMapper;
8 import org.jgraph.graph.CellViewRenderer;
9 import org.jgraph.graph.VertexView;
10
11 public class InitialActionView extends VertexView
12 {
13   private Object JavaDoc cell;
14   private static final InitialActionRenderer renderer = new InitialActionRenderer();
15
16   public InitialActionView(Object JavaDoc cell, JGraph graph, CellMapper mapper)
17   {
18     super(cell, graph, mapper);
19     this.cell = cell;
20   }
21
22   public String JavaDoc toString()
23   {
24     return cell.toString();
25   }
26
27   /**
28    * Returns the intersection of the bounding rectangle and the
29    * straight line between the source and the specified point p.
30    * The specified point is expected not to intersect the bounds.
31    */

32   public Point getPerimeterPoint(Point source, Point p)
33   {
34     // Compute relative bounds
35
Rectangle2D JavaDoc r = getBounds();
36     double a = (r.getWidth() + 1) / 2;
37     double b = (r.getHeight() + 1) / 2;
38
39     // Get center
40
int xCenter = (int)r.getCenterX();
41     int yCenter = (int)r.getCenterY();
42
43     // Compute angle
44
int dx = p.x - xCenter;
45     int dy = p.y - yCenter;
46     double t = Math.atan2(dy, dx);
47
48     // Compute Perimeter Point
49
int xout = xCenter + (int)(a * Math.cos(t)) - 1;
50     int yout = yCenter + (int)(b * Math.sin(t)) - 1;
51
52     // Return perimeter point
53
return new Point(xout, yout);
54   }
55
56   public CellViewRenderer getRenderer()
57   {
58     return renderer;
59   }
60
61 }
62
Popular Tags