KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > antlr > works > visualization > graphics > shape > GLink


1 /*
2
3 [The "BSD licence"]
4 Copyright (c) 2005 Jean Bovet
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions
9 are met:
10
11 1. Redistributions of source code must retain the above copyright
12 notice, this list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
16 3. The name of the author may not be used to endorse or promote products
17 derived from this software without specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 */

31
32 package org.antlr.works.visualization.graphics.shape;
33
34 import org.antlr.works.visualization.fa.FATransition;
35 import org.antlr.works.visualization.graphics.GObject;
36 import org.antlr.works.visualization.graphics.primitive.GDimension;
37 import org.antlr.works.visualization.graphics.primitive.GPoint;
38
39 import java.awt.*;
40
41 public class GLink extends GObject {
42
43     public FATransition transition;
44     public GNode source;
45     public GNode target;
46
47     // Global dimension of a branch in an alternative
48
public GDimension branchDim;
49
50     // Position for a single-link when both source and target state are on the same y-axis value
51
public GPoint virtualPosition;
52
53     // This flag indicates that this link is the last transition and should
54
// be displayed differently
55
public boolean last = false;
56
57     public GLink() {
58
59     }
60     
61     public GLink(FATransition transition, GNode target) {
62         this.transition = transition;
63         this.target = target;
64     }
65
66     public void setSource(GNode source) {
67         this.source = source;
68     }
69
70     public void setVirtualPosition(GPoint position) {
71         this.virtualPosition = new GPoint(position);
72     }
73
74     public void setBranchDimension(GDimension dimension) {
75         this.branchDim = new GDimension(dimension);
76     }
77
78     public void setLast(boolean flag) {
79         this.last = flag;
80     }
81
82     public float getVirtualY() {
83         return virtualPosition.getY(null);
84     }
85
86     public boolean containsStateNumber(int n) {
87         return transition.containsStateNumber(n);
88     }
89
90     public boolean containsPoint(Point p) {
91         return context.objectContainsPoint(this, p);
92     }
93
94     public void render(float ox, float oy) {
95         if(branchDim != null)
96             branchDim.cache(context);
97         if(virtualPosition != null)
98             virtualPosition.cache(context, ox, oy);
99     }
100
101     public Rectangle getBounds() {
102         int x1 = (int) source.getBeginX();
103         int y1 = (int) source.getBeginY();
104         int x2 = (int) target.getEndX();
105         int y2 = (int) target.getEndY();
106         return new Rectangle(x1, y1, Math.max(1, x2-x1), Math.max(1, y2-y1));
107     }
108
109     public void draw() {
110         context.drawLink(this);
111     }
112
113 }
114
Popular Tags