org.fenfire.loom
Class Cursor

java.lang.Object
  |
  +--org.fenfire.loom.Cursor

public class Cursor
extends java.lang.Object

A Loom cursor position in an RDF graph. Currently a focus and a rotation. The rotation is a number. Not stored in the structure.


Field Summary
 Resource focus
          The focused node, usually shown in the middle of the screen.
 NamespaceMap names
          The namespace prefix mappings used to render URIs.
protected  java.util.Comparator objOrder
          The comparator used to order statements by object.
 int rotation
          Index of the selection, "where you go next". 0 is the index in the middle, or one smaller if there are an even number of choices.
protected  StatementSelector statementSelector
          The statement selector used to choose which connections of a node to show.
protected  java.util.Comparator subjOrder
          The comparator used to order statements by subject.
 
Constructor Summary
Cursor(java.util.Comparator subjOrder, java.util.Comparator objOrder, StatementSelector statementSelector, NamespaceMap names)
          Create a new cursor without giving it a position yet.
Cursor(java.util.Comparator subjOrder, java.util.Comparator objOrder, StatementSelector statementSelector, NamespaceMap names, Resource focus)
          Create a new cursor and give it a focus.
Cursor(java.util.Comparator subjOrder, java.util.Comparator objOrder, StatementSelector statementSelector, NamespaceMap names, Resource focus, int dir, RDFNode rotation)
          Create a new cursor and give it a focus and a rotation.
 
Method Summary
 int getConnectionCount()
           
 java.util.SortedSet getConnections(int dir)
          Get the focus's connections in a given direction.
protected  java.util.SortedSet getConnections(Resource of, int dir)
          Get the connections of a given node in a given direction, as determined by the statementSelector, sorted according to the subjOrder/objOrder of this cursor.
protected static int getMiddle(int n)
          If there n connections, get the index of the 'middle' connection.
 java.util.Comparator getObjectOrder()
           
protected static int getOffsetFromMiddle(int i, int n)
          If i is an index in a list of n connections, return the distance of i from the middle.
 int getRotation()
          Get the rotation from the middle connection.
 int getRotationIndex(int dir)
          Get the index of the rotation in the list of left/right connections.
 RDFNode getRotationNode(int dir)
          Get the selected node in the given direction.
 NodeView.Nodespec getRotationNodespec(int dir)
           
protected  Statement getRotationStmt(int dir)
           
 StatementSelector getStatementSelector()
           
 java.util.Comparator getSubjectOrder()
           
 void move(int dir)
          Move left/right.
 void rotate(int dir)
          Rotate the view up or down.
 void set(Resource focus)
          Set the position of the cursor without setting a rotation.
 void set(Resource focus, int dir, RDFNode rotation)
          Set the position of the cursor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

names

public NamespaceMap names
The namespace prefix mappings used to render URIs.


focus

public Resource focus
The focused node, usually shown in the middle of the screen. "Where you are."


rotation

public int rotation
Index of the selection, "where you go next". 0 is the index in the middle, or one smaller if there are an even number of choices.


subjOrder

protected java.util.Comparator subjOrder
The comparator used to order statements by subject. The vertical order of subject nodes is determined by this Comparator.


objOrder

protected java.util.Comparator objOrder
The comparator used to order statements by object. The vertical order of object nodes is determined by this Comparator.


statementSelector

protected StatementSelector statementSelector
The statement selector used to choose which connections of a node to show.

Constructor Detail

Cursor

public Cursor(java.util.Comparator subjOrder,
              java.util.Comparator objOrder,
              StatementSelector statementSelector,
              NamespaceMap names)
Create a new cursor without giving it a position yet.


Cursor

public Cursor(java.util.Comparator subjOrder,
              java.util.Comparator objOrder,
              StatementSelector statementSelector,
              NamespaceMap names,
              Resource focus)
Create a new cursor and give it a focus.


Cursor

public Cursor(java.util.Comparator subjOrder,
              java.util.Comparator objOrder,
              StatementSelector statementSelector,
              NamespaceMap names,
              Resource focus,
              int dir,
              RDFNode rotation)
Create a new cursor and give it a focus and a rotation.

Method Detail

getSubjectOrder

public java.util.Comparator getSubjectOrder()

getObjectOrder

public java.util.Comparator getObjectOrder()

getStatementSelector

public StatementSelector getStatementSelector()

set

public void set(Resource focus)
Set the position of the cursor without setting a rotation. The rotation is set to the default, zero (the 'middle').


getMiddle

protected static int getMiddle(int n)
If there n connections, get the index of the 'middle' connection. If there is an odd number of connections, the 'middle' one is clear. If there is an even number, the 'middle' is defined as being the one above the actual middle (which lies between two connections).

As usual, indices are counted starting with zero.


getOffsetFromMiddle

protected static int getOffsetFromMiddle(int i,
                                         int n)
If i is an index in a list of n connections, return the distance of i from the middle. A negative number is returned when i is below the middle. This number is used as the value of rotation when i is selected by the cursor.


set

public void set(Resource focus,
                int dir,
                RDFNode rotation)
Set the position of the cursor.


getRotation

public int getRotation()
Get the rotation from the middle connection. E.g., when there are 5 connections and the second one is selected, rotation is -1.


getConnections

protected java.util.SortedSet getConnections(Resource of,
                                             int dir)
Get the connections of a given node in a given direction, as determined by the statementSelector, sorted according to the subjOrder/objOrder of this cursor. XXX make public once tested

Returns:
A set of statements, one for each connection.

getConnections

public java.util.SortedSet getConnections(int dir)
Get the focus's connections in a given direction.

Returns:
A set of statements, one for each connection.

getConnectionCount

public int getConnectionCount()

rotate

public void rotate(int dir)
Rotate the view up or down. This moves the rotation of the cursor up or down.


getRotationIndex

public int getRotationIndex(int dir)
Get the index of the rotation in the list of left/right connections. Can be out-of-bounds in that it is smaller than zero or larger than the number of items in the list: e.g. if you have 11 nodes connected to the right and 3 nodes connected to the left, when the last of the 11 nodes is selected, getRotationIndex(-1) will return +7. XXX


getRotationStmt

protected Statement getRotationStmt(int dir)

getRotationNode

public RDFNode getRotationNode(int dir)
Get the selected node in the given direction. getRotationNode(1) is the node we go to if we hit 'Right.' getRotationNode(-1) is the node we go to if we hit 'Left.' getRotationNode(0) is the focused node.


getRotationNodespec

public NodeView.Nodespec getRotationNodespec(int dir)

move

public void move(int dir)
Move left/right. Focuses the node currently selected in the given direction. The rotation is set so that the old focus becomes selected.