36 |
public class Cursor { |
public class Cursor { |
37 |
|
|
38 |
public Resource focus; |
public Resource focus; |
39 |
|
public int dir; |
40 |
public RDFNode rotation; |
public RDFNode rotation; |
41 |
|
|
42 |
/** The comparator used to order the nodes in the graph. |
/** The comparator used to order the nodes in the graph. |
48 |
this.order = order; |
this.order = order; |
49 |
} |
} |
50 |
|
|
51 |
public Cursor(Comparator order, Resource focus, RDFNode rotation) { |
public Cursor(Comparator order, Resource focus, int dir, RDFNode rotation) { |
52 |
this(order); |
this(order); |
53 |
set(focus, rotation); |
set(focus, dir, rotation); |
54 |
} |
} |
55 |
|
|
56 |
public void set(Resource focus, RDFNode rotation) { |
public void set(Resource focus, int dir, RDFNode rotation) { |
57 |
this.focus = focus; |
this.focus = focus; |
58 |
|
this.dir = dir; |
59 |
this.rotation = rotation; |
this.rotation = rotation; |
60 |
} |
} |
61 |
|
|
67 |
public int getRotationIndex() { |
public int getRotationIndex() { |
68 |
if(rotation == null) |
if(rotation == null) |
69 |
return 0; |
return 0; |
70 |
else if(getConnections(1).contains(rotation)) |
else if(getConnections(dir).contains(rotation)) |
71 |
return getConnections(1).headSet(rotation).size(); |
return getConnections(dir).headSet(rotation).size(); |
|
else if(getConnections(-1).contains(rotation)) |
|
|
return getConnections(-1).headSet(rotation).size(); |
|
72 |
else |
else |
73 |
return 0; |
return 0; |
74 |
} |
} |
103 |
/** Rotate the view up or down. |
/** Rotate the view up or down. |
104 |
* This moves the rotation of the cursor one step up or down. XXX |
* This moves the rotation of the cursor one step up or down. XXX |
105 |
*/ |
*/ |
106 |
public void rotate(int dir) { |
public void rotate(int rdir) { |
107 |
SortedSet |
SortedSet |
108 |
neg = getConnections(-1), |
neg = getConnections(-1), |
109 |
pos = getConnections(1); |
pos = getConnections(1); |
110 |
|
|
111 |
|
if(rotation == null) { |
112 |
|
if(pos.size() > 0) { |
113 |
|
rotation = (RDFNode)pos.iterator().next(); |
114 |
|
dir = 1; |
115 |
|
} else if(neg.size() > 0) { |
116 |
|
rotation = (RDFNode)neg.iterator().next(); |
117 |
|
dir = -1; |
118 |
|
} else |
119 |
|
return; |
120 |
|
} |
121 |
|
|
122 |
int i = getRotationIndex(); |
int i = getRotationIndex(); |
123 |
|
|
124 |
if(dir < 0) i--; |
if(rdir < 0) i--; |
125 |
else i++; |
else i++; |
126 |
|
|
127 |
if(i < 0) return; |
if(i < 0) return; |
128 |
if(i >= getConnections(-1).size() && |
if(i >= neg.size() && i >= pos.size()) return; |
|
i >= getConnections(1).size()) return; |
|
129 |
|
|
130 |
List l; |
List l; |
131 |
if(pos.contains(rotation)) { |
if(dir > 0) { |
132 |
if(pos.size() > i) |
if(pos.size() > i) |
133 |
l = new ArrayList(pos); |
l = new ArrayList(pos); |
134 |
else |
else { |
135 |
l = new ArrayList(neg); |
l = new ArrayList(neg); |
136 |
|
dir = -1; |
137 |
|
} |
138 |
} else { |
} else { |
139 |
if(neg.size() > i) |
if(neg.size() > i) |
140 |
l = new ArrayList(neg); |
l = new ArrayList(neg); |
141 |
else |
else { |
142 |
l = new ArrayList(pos); |
l = new ArrayList(pos); |
143 |
|
dir = 1; |
144 |
|
} |
145 |
} |
} |
146 |
|
|
147 |
rotation = (RDFNode)l.get(i); |
rotation = (RDFNode)l.get(i); |
149 |
|
|
150 |
/** Move left/right. XXX |
/** Move left/right. XXX |
151 |
*/ |
*/ |
152 |
public void move(int dir) { |
public void move(int mdir) { |
153 |
Iterator iter = getConnections(dir).iterator(); |
Iterator iter = getConnections(mdir).iterator(); |
154 |
int n = getRotationIndex(); |
int n = getRotationIndex(); |
155 |
for(int i=0; i<n; i++) if(iter.hasNext()) iter.next(); |
for(int i=0; i<n; i++) if(iter.hasNext()) iter.next(); |
156 |
if(!iter.hasNext()) |
if(!iter.hasNext()) |
158 |
return; |
return; |
159 |
rotation = focus; |
rotation = focus; |
160 |
focus = (Resource)iter.next(); |
focus = (Resource)iter.next(); |
161 |
|
dir = -mdir; |
162 |
} |
} |
163 |
} |
} |