View Javadoc
1   package org.vaadin.aceeditor.client;
2   
3   import java.io.Serializable;
4   import java.util.Map;
5   import java.util.Set;
6   
7   import org.vaadin.aceeditor.client.AceAnnotation.MarkerAnnotation;
8   import org.vaadin.aceeditor.client.AceAnnotation.RowAnnotation;
9   
10  /**
11   * 
12   * Classes to be used internally by the ace editor component,
13   * for transporting between client and server, etc.
14   * 
15   * This may seem a bit overkill???
16   * 
17   */
18  @SuppressWarnings("serial")
19  public class TransportDoc implements Serializable {
20  	
21  	public interface TransportableAs<T> {
22  		public T asTransport();
23  	}
24  	
25  	public interface TransportableOf<T> extends Serializable {
26  		public T fromTransport();
27  	}
28  
29  	public static class TransportMarker implements Serializable {
30  		public String markerId = null;
31  		public TransportRange range;
32  		public String onChange;
33  		public String cssClass;
34  		public String type;
35  		public boolean inFront = false;
36  		@Override
37  		public boolean equals(Object o) {
38  			if (o instanceof TransportMarker) {
39  				TransportMarker om = (TransportMarker)o;
40  				return markerId.equals(om.markerId) && range.equals(om.range) && onChange.equals(om.onChange) &&
41  						cssClass.equals(om.cssClass) && type.equals(om.type) && inFront==om.inFront;
42  			}
43  			return false;
44  		}
45  		@Override
46  		public int hashCode() {
47  			return range.hashCode(); // ?
48  		}
49  		@Override
50  		public String toString() {
51  			return "((Marker " + markerId + " at "+range+", " + cssClass + "))";
52  		}
53  	}
54  	
55  	public static class TransportRange implements Serializable {
56  		public int row1;
57  		public int col1;
58  		public int row2;
59  		public int col2;
60  		public TransportRange() {}
61  		public TransportRange(int row1, int col1, int row2, int col2) {
62  			this.row1 = row1;
63  			this.col1 = col1;
64  			this.row2 = row2;
65  			this.col2 = col2;
66  		}
67  		@Override
68  		public String toString() {
69  			return "[(" + row1+","+col1+")-(" + row2+","+col2+")]";
70  		}
71  	}
72  	
73  	public static class TransportAnnotation implements Serializable {
74  		public String message;
75  		public AceAnnotation.Type type;
76  		public TransportAnnotation() {}
77  		public TransportAnnotation(String message, AceAnnotation.Type type) {
78  			this.message = message;
79  			this.type = type;
80  		}
81  	}
82  	
83  	public static class TransportRowAnnotation implements TransportableOf<RowAnnotation> {
84  		public int row;
85  		public TransportAnnotation ann;
86  		public TransportRowAnnotation() {}
87  		public TransportRowAnnotation(int row, TransportAnnotation ann) {
88  			this.row = row;
89  			this.ann = ann;
90  		}
91  		@Override
92  		public RowAnnotation fromTransport() {
93  			return new RowAnnotation(row, AceAnnotation.fromTransport(ann));
94  		}
95  	}
96  	
97  	public static class TransportMarkerAnnotation implements TransportableOf<MarkerAnnotation> {
98  		public String markerId;
99  		public TransportAnnotation ann;
100 		public TransportMarkerAnnotation() {}
101 		public TransportMarkerAnnotation(String markerId, TransportAnnotation ann) {
102 			this.markerId = markerId;
103 			this.ann = ann;
104 		}
105 		@Override
106 		public MarkerAnnotation fromTransport() {
107 			return new MarkerAnnotation(markerId, AceAnnotation.fromTransport(ann));
108 		}
109 	}
110 	
111 	
112 	
113 	public String text;
114 	public Map<String, TransportMarker> markers;
115 	public Set<TransportRowAnnotation> rowAnnotations;
116 	public Set<TransportMarkerAnnotation> markerAnnotations;
117 	
118 	@Override
119 	public String toString() {
120 		return "doc text >>>>>>>>>>>\n"+text+"\n/////////////////\n"+markers+"\n<<<<<<<<<<<<<<<";
121 	}
122 	
123 }