63 |
* this returns 2. |
* this returns 2. |
64 |
*/ |
*/ |
65 |
public int getRotationIndex() { |
public int getRotationIndex() { |
66 |
if(rotation != null) |
if(rotation == null) |
67 |
|
return 0; |
68 |
|
else if(getConnections(1).contains(rotation)) |
69 |
return getConnections(1).headSet(rotation).size(); |
return getConnections(1).headSet(rotation).size(); |
70 |
|
else if(getConnections(-1).contains(rotation)) |
71 |
|
return getConnections(-1).headSet(rotation).size(); |
72 |
else |
else |
73 |
return 0; |
return 0; |
74 |
} |
} |
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 dir) { |
107 |
SortedSet s = getConnections(1); |
SortedSet |
108 |
if(dir < 0) { |
neg = getConnections(-1), |
109 |
try { |
pos = getConnections(1); |
110 |
rotation = (RDFNode)s.headSet(rotation).last(); |
|
111 |
} catch(NoSuchElementException _) { |
int i = getRotationIndex(); |
112 |
} |
|
113 |
} else if(dir > 0) { |
if(dir < 0) i--; |
114 |
Iterator i = s.tailSet(rotation).iterator(); |
else i++; |
115 |
if(!i.hasNext()) return; i.next(); |
|
116 |
if(!i.hasNext()) return; |
if(i < 0) return; |
117 |
rotation = (RDFNode)i.next(); |
if(i >= getConnections(-1).size() && |
118 |
|
i >= getConnections(1).size()) return; |
119 |
|
|
120 |
|
List l; |
121 |
|
if(pos.contains(rotation)) { |
122 |
|
if(pos.size() > i) |
123 |
|
l = new ArrayList(pos); |
124 |
|
else |
125 |
|
l = new ArrayList(neg); |
126 |
|
} else { |
127 |
|
if(neg.size() > i) |
128 |
|
l = new ArrayList(neg); |
129 |
|
else |
130 |
|
l = new ArrayList(pos); |
131 |
} |
} |
132 |
|
|
133 |
|
rotation = (RDFNode)l.get(i); |
134 |
} |
} |
135 |
|
|
136 |
/** Move left/right. XXX |
/** Move left/right. XXX |
137 |
*/ |
*/ |
138 |
public void move(int dir) { |
public void move(int dir) { |
139 |
if(dir < 0) { |
Iterator iter = getConnections(dir).iterator(); |
140 |
rotation = focus; |
int n = getRotationIndex(); |
141 |
focus = (Resource)getConnections(-1).first(); |
for(int i=0; i<n; i++) if(iter.hasNext()) iter.next(); |
142 |
} else { |
if(!iter.hasNext()) |
143 |
focus = (Resource)rotation; |
// cannot move there |
144 |
try { |
return; |
145 |
rotation = (RDFNode)getConnections(1).first(); |
rotation = focus; |
146 |
} catch(NoSuchElementException _) { |
focus = (Resource)iter.next(); |
|
rotation = null; |
|
|
} |
|
|
} |
|
147 |
} |
} |
148 |
} |
} |