/[gzz]/gzz/lava/gzz/loom/Cursor.java
ViewVC logotype

Diff of /gzz/lava/gzz/loom/Cursor.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by benja, Sun Feb 23 23:00:54 2003 UTC revision 1.8 by benja, Sun Feb 23 23:44:56 2003 UTC
# Line 36  import com.hp.hpl.mesa.rdf.jena.model.*; Line 36  import com.hp.hpl.mesa.rdf.jena.model.*;
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.
# Line 47  public class Cursor { Line 48  public class Cursor {
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    
# Line 65  public class Cursor { Line 67  public class Cursor {
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      }      }
# Line 103  public class Cursor { Line 103  public class Cursor {
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);
# Line 135  public class Cursor { Line 149  public class Cursor {
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())
# Line 144  public class Cursor { Line 158  public class Cursor {
158              return;              return;
159          rotation = focus;          rotation = focus;
160          focus = (Resource)iter.next();          focus = (Resource)iter.next();
161            dir = -mdir;
162      }      }
163  }  }

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26