01: package com.opensymphony.webwork.sitegraph.model;
02:
03: import java.io.IOException;
04:
05: /**
06: * User: plightbo
07: * Date: Jun 26, 2005
08: * Time: 4:50:33 PM
09: */
10: public class Link implements Render, Comparable {
11: public static final int TYPE_FORM = 0;
12: public static final int TYPE_ACTION = 1;
13: public static final int TYPE_HREF = 2;
14: public static final int TYPE_RESULT = 3;
15: public static final int TYPE_REDIRECT = 4;
16:
17: private SiteGraphNode from;
18: private SiteGraphNode to;
19: private int type;
20: private String label;
21:
22: public Link(SiteGraphNode from, SiteGraphNode to, int type,
23: String label) {
24: this .from = from;
25: this .to = to;
26: this .type = type;
27: this .label = label;
28: }
29:
30: public void render(IndentWriter writer) throws IOException {
31: writer.write(from.getFullName() + " -> " + to.getFullName()
32: + " [label=\"" + getRealLabel() + "\"" + getColor()
33: + "];");
34: }
35:
36: private String getRealLabel() {
37: switch (type) {
38: case TYPE_ACTION:
39: return "action" + label;
40: case TYPE_FORM:
41: return "form" + label;
42: case TYPE_HREF:
43: return "href" + label;
44: case TYPE_REDIRECT:
45: return "redirect: " + label;
46: case TYPE_RESULT:
47: return label;
48: }
49:
50: return "";
51: }
52:
53: private String getColor() {
54: if (type == TYPE_RESULT || type == TYPE_ACTION) {
55: return ",color=\"darkseagreen2\"";
56: } else {
57: return "";
58: }
59: }
60:
61: public int compareTo(Object o) {
62: Link other = (Link) o;
63: int result = from.compareTo(other.from);
64: if (result != 0) {
65: return result;
66: }
67:
68: result = to.compareTo(other.to);
69: if (result != 0) {
70: return result;
71: }
72:
73: result = label.compareTo(other.label);
74: if (result != 0) {
75: return result;
76: }
77:
78: return new Integer(type).compareTo(new Integer(other.type));
79: }
80: }
|