001: package org.enhydra.jawe.components.graph;
002:
003: import java.awt.BasicStroke;
004: import java.awt.Dimension;
005: import java.awt.Graphics;
006: import java.awt.Graphics2D;
007: import java.awt.RenderingHints;
008: import java.awt.geom.Point2D;
009: import java.awt.geom.Rectangle2D;
010:
011: import org.jgraph.graph.GraphConstants;
012: import org.jgraph.graph.VertexRenderer;
013: import org.jgraph.graph.VertexView;
014:
015: /**
016: * Class used to display end object.
017: */
018: public class DefaultGraphBubbleActivityRenderer extends VertexRenderer
019: implements GraphActivityRendererInterface {
020:
021: private BasicStroke borderStroke = new BasicStroke(1);
022:
023: /**
024: * Paints End. Overrides super class paint
025: * to add specific painting.
026: */
027: public void paint(Graphics g) {
028: if (((GraphBubbleActivityInterface) view.getCell()).isStart())
029: setIcon(GraphUtilities.getGraphController()
030: .getGraphSettings().getBubbleStartIcon());
031: else
032: setIcon(GraphUtilities.getGraphController()
033: .getGraphSettings().getBubbleEndIcon());
034: setText(null);
035:
036: int b = borderWidth;
037: Graphics2D g2 = (Graphics2D) g;
038: Object AntiAlias = RenderingHints.VALUE_ANTIALIAS_ON;//Harald Meister
039: g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, AntiAlias);//Harald Meister
040: Dimension d = getSize();
041: boolean tmp = selected;
042:
043: if (super .isOpaque()) {
044: g.setColor(GraphUtilities.getGraphController()
045: .getGraphSettings().getBubbleColor());
046: g.fillOval(b - 1, b - 1, d.height - b, d.height - b);
047: }
048: try {
049: setBorder(null);
050: setOpaque(false);
051: selected = false;
052: super .paint(g);
053: } finally {
054: selected = tmp;
055: }
056:
057: g.setColor(GraphUtilities.getGraphController()
058: .getGraphSettings().getBubbleConectionColor());
059: g2.setStroke(borderStroke);
060: g.drawOval(b - 1, b - 1, d.height - b, d.height - b);
061:
062: if (selected) {
063: g2.setStroke(GraphConstants.SELECTION_STROKE);
064: g.setColor(graph.getHighlightColor());
065: g.drawOval(b - 1, b - 1, d.height - b, d.height - b);
066: }
067: }
068:
069: public Point2D getPerimeterPoint(VertexView pView, Point2D p) {
070: Rectangle2D bounds = pView.getBounds();
071: double x = bounds.getX();
072: double y = bounds.getY();
073: double width = bounds.getWidth();
074: double height = bounds.getHeight();
075: double xCenter = x + width / 2;
076: double yCenter = y + height / 2;
077: double dx = p.getX() - xCenter; // Compute Angle
078: double dy = p.getY() - yCenter;
079: double alpha = Math.atan2(dy, dx);
080: double xout = 0, yout = 0;
081: double pi = Math.PI;
082: double pi2 = Math.PI / 2.0;
083: double beta = pi2 - alpha;
084: double t = Math.atan2(height, width);
085: if (alpha < -pi + t || alpha > pi - t) { // Left edge
086: xout = x;
087: yout = yCenter - width * Math.tan(alpha) / 2;
088: } else if (alpha < -t) { // Top Edge
089: yout = y;
090: xout = xCenter - height * Math.tan(beta) / 2;
091: } else if (alpha < t) { // Right Edge
092: xout = x + width;
093: yout = yCenter + width * Math.tan(alpha) / 2;
094: } else { // Bottom Edge
095: yout = y + height;
096: xout = xCenter + height * Math.tan(beta) / 2;
097: }
098: return new Point2D.Double(xout, yout);
099: }
100: }
|