/[fenfire]/fenfire/org/fenfire/demo/mm.py
ViewVC logotype

Diff of /fenfire/org/fenfire/demo/mm.py

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

revision 1.32 by tjl, Thu Aug 21 18:31:02 2003 UTC revision 1.33 by humppake, Sun Aug 24 09:19:57 2003 UTC
# Line 60  the terms of the GNU Lesser General Publ Line 60  the terms of the GNU Lesser General Publ
60  the Free Software Foundation; either version 2 of the License, or  the Free Software Foundation; either version 2 of the License, or
61  (at your option) any later version.  (at your option) any later version.
62    
63  Fenfire is distributed in the hope that it will be useful, but WITHOUT  sFenfire is distributed in the hope that it will be useful, but WITHOUT
64  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
65  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
66  Public License for more details.  Public License for more details.
# Line 92  else: Line 92  else:
92      print 'Creating a new RDF graph.'      print 'Creating a new RDF graph.'
93      do_load_graph = 0      do_load_graph = 0
94    
95  # Now, before reading the xu stuff, render something  # Now, before reading the xu stuff, render something
96  # to try to prevent NV driver  # to try to prevent NV driver fallback to software rendering.
 # fallback to software rendering.  
 # Might be that it only reserves screen memory when starting to render  
 # and if we reserve it all for textures, ... splat ...  
97  vs = w.createVobScene()  vs = w.createVobScene()
98  vs.put(background((.5, .5, .5)))  vs.put(background((.5, .5, .5)))
99  w.renderStill(vs, 0)  w.renderStill(vs, 0)
# Line 107  if do_load_graph: Line 104  if do_load_graph:
104      m = ModelMem()      m = ModelMem()
105      m.read(java.io.FileReader(FILE), None);      m.read(java.io.FileReader(FILE), None);
106      fen.constgraph = fen.graph = ff.swamp.Graphs.toGraph(m);      fen.constgraph = fen.graph = ff.swamp.Graphs.toGraph(m);
107  else:  else: fen.graph = fen.constgraph = ff.swamp.impl.HashGraph()
     fen.graph = fen.constgraph = ff.swamp.impl.HashGraph()  
108    
109  fen.txt = ff.impl.SimpleNodeContent(fen, myalph);  fen.txt = ff.impl.SimpleNodeContent(fen, myalph);
110  fen.txtfunc = fen.txt.getNodeFunction()  fen.txtfunc = fen.txt.getNodeFunction()
111  fen.enfiladeOverlap = fen.txt.getTransclusionIndex()  fen.enfiladeOverlap = fen.txt.getTransclusionIndex()
 alphContent = ff.util.AlphContent(fen)  
   
112    
113  textstyle = vob.GraphicsAPI.getInstance().getTextStyle("sansserif", 0, 24)  style = vob.GraphicsAPI.getInstance().getTextStyle("sansserif", 0, 24)
114    
115  # normal  # nodeview for normal nodes
116  normal_text = ff.view.TextNodeView(fen.txtfunc, textstyle, java.awt.Color(0., 0., 0.))  normal_text = ff.view.TextNodeView(fen.txtfunc, style, java.awt.Color(0., 0., 0.))
117  normal_text_bg = ff.fenmm.WhiteNodeView(normal_text, java.awt.Color(.6, .6, .6))  normal_text_bg = ff.fenmm.WhiteNodeView(normal_text, java.awt.Color(.6, .6, .6))
118  normal = ff.swamp.CachedPureNodeFunction(100, fen.constgraph, normal_text_bg)  normal = ff.swamp.CachedPureNodeFunction(100, fen.graph, normal_text_bg)
119    
120  # accursed  # nodeview for accursed nodes
121  accursed_text = ff.view.TextNodeView(fen.txtfunc, textstyle, java.awt.Color.black)  accursed_text = ff.view.TextNodeView(fen.txtfunc, style, java.awt.Color.black)
122  accursed_text_bg = ff.fenmm.WhiteNodeView(accursed_text, java.awt.Color(.9, .9, .9))  accursed_text_bg = ff.fenmm.WhiteNodeView(accursed_text, java.awt.Color(.9, .9, .9))
123  accursed = ff.swamp.CachedPureNodeFunction(100, fen.constgraph, accursed_text_bg)  accursed = ff.swamp.CachedPureNodeFunction(100, fen.graph, accursed_text_bg)
124  multiplexer = ff.swamp.MultiplexerNodeFunction(normal, accursed)  multiplexer = ff.swamp.MultiplexerNodeFunction(normal, accursed)
125    
126  mindView = ff.view.lava.mindMapView2D.MindMapView2D(fen, multiplexer)  structLink = ff.structure.StructLink.create(fen.graph)
   
 structLink = ff.structure.StructLink(fen.graph)  
127    
128  class Context(ff.view.buoy.AbstractMainNode2D.Context):  class Context(ff.view.buoy.AbstractMainNode2D.Context):
129      def __init__(self):      def __init__(self, fen, w, home, multiplexer, style):
130            self.fen = fen
131            self.w = w
132            self.home = home
133            self.multiplexer = multiplexer
134            self.style = style
135    
136          self.rmb_switch = [ 'go', 'link' ]          self.rmb_switch = [ 'go', 'link' ]
137          self.oldVS = None          self.oldVS = None
138          self.replaceVS = None          self.replaceVS = None
139    
140          self.main = None    # MainNode2D          self.main = None    # MainNode2D
141          self.fastMouseChg = 0  # callback from abstractmainnode2d when called mouse          self.fastMouseChg = 0  # callback from abstractmainnode2d when called mouse
         self._accursed = None  
142          self.bgcolor = (.4, .7, 1.0)          self.bgcolor = (.4, .7, 1.0)
143          self.offset = 0          self.c = ff.fenmm.MMTextCursor(style)
144          self.scale = 1  
145          self.home = None          self.alphContent = ff.util.AlphContent(self.fen)
146    
147      def nextRmb(self):      def nextRmb(self):
148          rmb = self.rmb_switch          rmb = self.rmb_switch
149          rmb.append(rmb.pop(0))          rmb.append(rmb.pop(0))
150          rmb = rmb[0]          rmb = rmb[0]
151          if rmb == 'go': self.bgcolor = (.4, .7, 1.0); w.setCursor('default')  
152          elif rmb == 'link': self.bgcolor = (.4, .8, .4); w.setCursor('hand')          if rmb == 'go': self.bgcolor = (.4, .7, 1.0); self.w.setCursor('default')
153          else: raise 'no good cursor!?'          elif rmb == 'link': self.bgcolor = (.4, .8, .4); self.w.setCursor('hand')
154            else: raise 'Undefined state!'
155      def drawCursor(self, vs, node, cs):  
156          xy = jarray.zeros(2, 'f')      def insertText(self, text):        
157          normal_text.getXY(fen.graph, context.getAccursed(), self.offset, xy)          if self.c.getAccursed() == None:
158          cs = vs.orthoCS(cs, "CURSOR", 0, xy[0]*self.scale, xy[1]*self.scale,              self.c.setAccursed(ff.util.RDFUtil.N(self.fen.graph, MINDSTRUCT.Data))
159                          0, -textstyle.getHeight(self.scale))              self.c.setOffset(0)
160          vs.put(vob.vobs.LineVob(0,0,0,1, java.awt.Color.black), cs)          offset = self.c.getOffset()
161            self.alphContent.insertText(self.c.getAccursed(), offset, text, 1)
162      def insertText(self, text):          self.c.setOffset(offset + len(text))
         if self._accursed == None:  
             self.setAccursed(ff.util.RDFUtil.N(fen.graph, MINDSTRUCT.Data))  
             self.offset = 0  
         alphContent.insertText(self._accursed, self.offset, text, 1)  
         self.offset += len(text)  
163    
164      def deleteText(self):      def deleteText(self):
165          if dbg: p('offs:', self.offset)          if dbg: p('offs:', self.offset)
166          if self._accursed == None: return          accursed = self.c.getAccursed()
167            if self.c.getAccursed() == None: return
168            offset = self.c.getOffset()
169                    
170          alphContent.deleteText(self._accursed, self.offset-1,  self.offset)          self.alphContent.deleteText(accursed, offset-1, offset)
171          self.offset -= 1          self.c.setOffset(offset-1)
172          l = len(alphContent.getText(fen.graph, self._accursed))          l = len(self.alphContent.getText(self.fen.graph, accursed))
173          if self.offset == 0 and l == 0:  
174              fen.graph.rm_111(self._accursed, RDF.type, MINDSTRUCT.Data)          offset = self.c.getOffset()
175              it = fen.graph.findN_X11_Iter(RDF.type, MINDSTRUCT.Data)          if offset == 0 and l == 0:
176              self.setAccursed(None)              self.fen.graph.rm_111(accursed, RDF.type, MINDSTRUCT.Data)
177                it = self.fen.graph.findN_X11_Iter(RDF.type, MINDSTRUCT.Data)
178                self.c.setAccursed(None)
179              while it.hasNext():              while it.hasNext():
180                  node = it.next()                  node = it.next()
181                  if structLink.isLinked(node): continue                  if structLink.isLinked(node): continue
182                  else: self.setAccursed(node)                  else: self.c.setAccursed(node)
183              if dbg: p('offs:', self.offset, l)              if dbg: p('Offset after deleteText:', self.getOffset(), l)
   
     def setAccursed(self, node, multiplexer = None):  
         set = java.util.HashSet()  
         set.add(node)  
         if multiplexer:  
             multiplexer.setMultiplexerNodes(set)  
         self.main.multiplexer.setMultiplexerNodes(set)  
   
         self._accursed = node  
         if self._accursed != None:  
             self.offset = len(alphContent.getText(fen.graph, self._accursed))  
         else:  
             self.offset = 0  
     def getAccursed(self):  
         return self._accursed  
   
184    
185      def rmLinkTo(self, obj, with):      def rmLinkTo(self, obj, with):
186          rm = 0          totRemoved = 0
187          iter = fen.graph.findN_11X_Iter(obj, STRUCTLINK.linkedTo)          iter = self.fen.graph.findN_11X_Iter(obj, STRUCTLINK.linkedTo)
188          try:          try:
189              while (iter.hasNext()):              while (iter.hasNext()):
190                  if with == iter.next():                  if with == iter.next():
191                      fen.graph.rm_111(obj, STRUCTLINK.linkedTo, with)                      self.fen.graph.rm_111(obj, STRUCTLINK.linkedTo, with)
192                      rm += 1                      totRemoved += 1
193              iter = fen.graph.findN_11X_Iter(with, STRUCTLINK.linkedTo)              iter = self.fen.graph.findN_11X_Iter(with, STRUCTLINK.linkedTo)
194              while (iter.hasNext()):              while (iter.hasNext()):
195                  if obj == iter.next():                  if obj == iter.next():
196                      fen.graph.rm_111(with, STRUCTLINK.linkedTo, obj)                      self.fen.graph.rm_111(with, STRUCTLINK.linkedTo, obj)
197                      rm += 1                      totRemoved += 1
198          except: pass          except: pass
199          return rm          return totRemoved
200    
201      def mainNodeToBeRender(self, vs,into, main): pass      def mainNodeToBeRender(self, vs,into, main): pass
202      def changeFastAfterMouseEvent(self):      def changeFastAfterMouseEvent(self):
203          if dbg: p('returning', self.fastMouseChg, 'as fast or slow')          if dbg: p('Returning', self.fastMouseChg, 'as fast or slow.')
204          return self.fastMouseChg          return self.fastMouseChg
   
205      def setFastAnimation(self):      def setFastAnimation(self):
206          self.fastMouseChg = 1          self.fastMouseChg = 1
207          self.replaceVS = self.oldVS          self.replaceVS = self.oldVS
208      def setSlowAnimation(self):      def setSlowAnimation(self):
209          self.fastMouseChg = 0          self.fastMouseChg = 0
210          self.replaceVS = None          self.replaceVS = None
211        def getScale(self, depth):
212            return 1-(Math.log(depth+1)/Math.E)
213  context = Context()      def getTextScale(self, depth):
214            return 1-(Math.log(depth+1)/Math.E)/2
 if not do_load_graph:  
     context.home = ff.util.RDFUtil.N(fen.graph, MINDSTRUCT.Data)  
     alphContent.insertText(context.home, 0, 'home', 1)  
 else: context.home = fen.graph.findN_X1A_Iter(STRUCTLINK.linkedTo).next()  
   
215    
216  class Action:  class Action:
217      def __init__(self, context):      def __init__(self, fen, context):
218            self.fen = fen
219          self.context = context          self.context = context
220    
221  class RMB(Action, vob.mouse.MouseClickListener):  class RMB(Action, vob.mouse.MouseClickListener):
# Line 247  class RMB(Action, vob.mouse.MouseClickLi Line 223  class RMB(Action, vob.mouse.MouseClickLi
223          self.context.nextRmb()          self.context.nextRmb()
224          self.context.setSlowAnimation()          self.context.setSlowAnimation()
225                    
226  class Click(Action, vob.mouse.MouseClickListener):  class LMB(Action, vob.mouse.MouseClickListener):
227      def clicked(self, x,y):      def clicked(self, x,y):
228          self.context.setSlowAnimation()          self.context.setSlowAnimation()
229          vs = context.oldVS          vs = self.context.oldVS
230          node = vs.getKeyAt(0, x,y, None)          node = vs.getKeyAt(0, x,y, None)
231          p('key', node)          p('LBM click:', node)
232    
233          if node == None: return          if node == None: return
234    
235          rmb = context.rmb_switch[0]          rmb = self.context.rmb_switch[0]
236            main = self.context.main
237          if rmb == 'go':          if rmb == 'go':
238              self.context.setAccursed(node, multiplexer)              self.context.c.setAccursed(node)
239    
240                ### something easier to allow setOffset(x,y) before rendering
241                nodeview = ff.view.TextNodeView(self.fen.txtfunc, self.context.style)
242                self.context.c.setTextPlaceable(nodeview.f(fen.graph, node))
243    
244              # set cursor, transitions between zoomed and normal should be accounted              # set cursor, transitions between zoomed and normal should be accounted
245              cs = vs.getCSAt(0, x,y, None)              cs = vs.getCSAt(0, x,y, None)
246              into = jarray.zeros(3, 'f')              into = jarray.zeros(3, 'f')
247              vs.coords.transformPoints3(cs, [0,0,0], into)              vs.coords.transformPoints3(cs, [0,0,0], into)
248    
249                scale = 1./main.getFocus().getZoom()
250                cursor = self.context.c
251                accursed = cursor.getAccursed()
252    
253              # scaling              # scaling
254              nodeScale = (100+into[2])+4              nodeScale = self.context.getTextScale(100+into[2])
255              if mindView.maxDepth > 40: nodeScale *= 40./mindView.maxDepth  
256              nodeScale = 1-math.log10(nodeScale/4.)              if node == self.context.main.getPlane(): # from border to linked
257                    cursor.setOffset((x-into[0])/scale/nodeScale, (y-into[1])/scale/nodeScale)
258              if node == self.context.main.getPlane():              elif structLink.isLinked(node): # from linked or border to another linked
259                  # from border to linked                  cursor.setOffset((x-into[0])/scale/nodeScale, (y-into[1])/scale/nodeScale)
260                  self.context.scale = self.context.main.getFocus().getZoom()                  main.setNewPlane(node, 0,0,1)
261                  self.context.offset = normal_text.getPos(fen.graph, context.getAccursed(),              else: # from border to border
262                                                           (x-into[0])/self.context.scale/nodeScale,                  cursor.setOffset((x-into[0])/nodeScale, (y-into[1])/nodeScale)
263                                                           (y-into[1])/self.context.scale/nodeScale)  
             elif structLink.isLinked(node):  
                 # from linked or border to another linked  
                 self.context.scale = self.context.main.getFocus().getZoom()  
                 self.context.offset = normal_text.getPos(fen.graph, context.getAccursed(),  
                                                          (x-into[0])/self.context.scale/nodeScale,  
                                                          (y-into[1])/self.context.scale/nodeScale)  
                 self.context.scale = 1  
                 self.context.main.setNewPlane(node, 0,0,1)  
             else:  
                 # from border to border  
                 self.context.scale = 1  
                 self.context.offset = normal_text.getPos(fen.graph, context.getAccursed(),  
                                                          (x-into[0])/self.context.scale/nodeScale,  
                                                          (y-into[1])/self.context.scale/nodeScale)  
264          elif rmb == 'link':          elif rmb == 'link':
265              if node == self.context.main.getPlane(): pass              if node == main.getPlane(): pass
266              elif self.context.rmLinkTo(node, self.context.main.getPlane()) == 0:              elif self.context.rmLinkTo(node, main.getPlane()) == 0:
267                  fen.graph.add(self.context.main.getPlane(), STRUCTLINK.linkedTo, node)                  self.fen.graph.add(main.getPlane(), STRUCTLINK.linkedTo, node)
268    
269    
270  class ZoomPan(vob.input.RelativeAxisListener, Action, vob.mouse.MousePressListener):  class ZoomPan(vob.input.RelativeAxisListener, Action, vob.mouse.MousePressListener):
271        def __init__(self, fen, context):
272            Action.__init__(self, fen, context)
273            self.oldZoom = 1.
274      def pressed(self, x,y):      def pressed(self, x,y):
275          return self          return self
276      def changedRelative(self, x):      def changedRelative(self, x):
277          self.context.main.changeZoom(x)          main = self.context.main
278          self.context.main.chgFast(self.context.oldVS, -1)          f = main.getFocus()
279            fX, fY = f.getPanX(), f.getPanY()
280    
281            dimensions = w.getSize()
282            fX -= dimensions.width*(-.5/self.oldZoom + .5)
283            fY -= dimensions.height*(-.5/self.oldZoom + .5)
284            fX += dimensions.width*(-.5/f.zoom + .5)
285            fY += dimensions.height*(-.5/f.zoom + .5)
286            f.setPan(fX, fY)
287            self.oldZoom = f.zoom
288            
289            if x: main.changeZoom(1./x)
290            else: main.changeZoom(0)
291            main.chgFast(self.context.oldVS, -1)
292    
293          self.context.fastMouseChg = 1          self.context.fastMouseChg = 1
294          if self.context.getAccursed() and \          accursed = self.context.c.getAccursed()
                structLink.isLinked(self.context.getAccursed()):  
             self.context.scale = self.context.main.getFocus().getZoom()  
295          self.context.setFastAnimation()          self.context.setFastAnimation()
296    
297  class PanMover(Action, vob.mouse.RelativeAdapter, vob.mouse.MousePressListener):  class PanMover(Action, vob.mouse.RelativeAdapter, vob.mouse.MousePressListener):
298      def pressed(self, x,y):      def pressed(self, x,y):
299          return self          return self
300      def changedRelative(self, x,y='foo'):      def changedRelative(self, x,y='foo'):
301          f = self.context.main.getFocus()          main = self.context.main
302            f = main.getFocus()
303          fX, fY = f.getPanX(), f.getPanY()          fX, fY = f.getPanX(), f.getPanY()
304          f.setPan(fX-x/f.zoom,          f.setPan(fX+x/f.zoom,
305                   fY-y/f.zoom)                   fY+y/f.zoom)
306          self.context.main.chgFast(self.context.oldVS, -1)          main.chgFast(self.context.oldVS, -1)
307          self.context.setFastAnimation()          self.context.setFastAnimation()
308    
309    class MMScene:
310        def __init__(self):
311            self.alphContent = ff.util.AlphContent(fen)
312            if do_load_graph:
313                self.home = fen.graph.findN_X1A_Iter(STRUCTLINK.linkedTo).next()
314            else:
315                self.home = ff.util.RDFUtil.N(fen.graph, MINDSTRUCT.Data)
316                self.alphContent.insertText(self.home, 0, 'Home', 1)
317    
318  mindMouse = vob.mouse.MouseMultiplexer()          self.context = Context(fen, w, self.home, multiplexer, style)
 mindMouse.setListener(3, 0, 'Right mouse button switching.', RMB(context))  
 mindMouse.setListener(3, 0, mindMouse.VERTICAL, 1.0, \  
                       'Zooming the main view.', ZoomPan(context))  
 mindMouse.setListener(1, 0, 'Foo', Click(context))  
 mindMouse.setListener(1, 0,'Moving the pan around or the node if accursed.', \  
                       PanMover(context))  
319    
320  class VeryStupidBuoyManager:          self.mindMouse = vob.mouse.MouseMultiplexer()
321      def __init__(self):          self.mindMouse.setListener(3, 0, 'Right mouse button switching.', RMB(fen, self.context))
322          self.main = ff.view.lava.mindMapView2D.MindMapMainNode2D(context.home, mindView,          self.mindMouse.setListener(3, 0, self.mindMouse.VERTICAL, 1.0, \
323               ff.view.buoy.AbstractMainNode2D.SimpleFocus(0,0), mindMouse)                            'Zooming the main view.', ZoomPan(fen, self.context))
324          self.main.init(fen, multiplexer)          self.mindMouse.setListener(1, 0, 'Left mouse button action.', LMB(fen, self.context))
325          context.main = self.main          self.mindMouse.setListener(1, 0,'Moving the pan around or the node if accursed.', \
326                              PanMover(fen, self.context))
327          # contexts for e.g. drawCursor callbacks and delivering accursedNode  
328          self.main.context = context          self.view = ff.view.lava.mindMapView2D.MindMapView2D(fen, self.context, 5)
329          self.main.setColors(fen)          self.main = ff.view.lava.mindMapView2D.MindMapMainNode2D(fen, self.context, self.view, self.mindMouse)
330          mindView.context = context          self.context.main = self.main
331    
332          # flag for cursor('wait')          # flag for cursor('wait')
333          self.startup = 1          self.startup = 1
# Line 346  class VeryStupidBuoyManager: Line 335  class VeryStupidBuoyManager:
335          ### custom controller support          ### custom controller support
336          self.naxes = 0          self.naxes = 0
337          self.calibrating = 0          self.calibrating = 0
338            
339          try:          try:
340              self.ps2 = vob.input.impl.PS2MouseDevice("/dev/input/mouse0", "main",              self.ps2 = vob.input.impl.PS2MouseDevice( \
341                         vob.input.impl.PS2MouseDevice.IMPS_PROTO)                         java.lang.System.getProperty("cc.device", "/dev/input/mouse0"), \
342                           "main", vob.input.impl.PS2MouseDevice.IMPS_PROTO)
343    
344              self.naxes = len(self.ps2.getAxes())              self.naxes = len(self.ps2.getAxes())
345              if self.naxes > 3: self.naxes = 3              if self.naxes > 3: self.naxes = 3
346              self.axes = [None, None, None]              self.axes = [None, None, None]
347    
348              if self.naxes >= 1:              if self.naxes >= 1:
349                  self.axes[0] = vob.input.impl.StandardBoundedFloatModel(0.001, mindView.nodeScale*2,                  self.axes[0] = vob.input.impl.StandardBoundedFloatModel(0.001, self.view.filletWidth*2,
350                      actionPerformed = lambda x: vob.AbstractUpdateManager.chg())                      actionPerformed = lambda x: vob.AbstractUpdateManager.chg())
351              if self.naxes >= 2:              if self.naxes >= 2:
352                  self.axes[1] = vob.input.impl.StandardBoundedFloatModel(0.001, mindView.distanceScale*2,                  self.axes[1] = vob.input.impl.StandardBoundedFloatModel(0.001, self.view.filletLength*2,
353                      actionPerformed = lambda x: vob.AbstractUpdateManager.chg())                      actionPerformed = lambda x: vob.AbstractUpdateManager.chg())
354              if self.naxes >= 3:              if self.naxes >= 3:
355                  self.axes[2] = vob.input.impl.WrappingBoundedFloatModel(0, Math.PI*2,                  self.axes[2] = vob.input.impl.WrappingBoundedFloatModel(0, Math.PI*2,
# Line 368  class VeryStupidBuoyManager: Line 361  class VeryStupidBuoyManager:
361          except java.io.FileNotFoundException: pass          except java.io.FileNotFoundException: pass
362    
363      def scene(self, vs):      def scene(self, vs):
364          if context.replaceVS:          if self.context.replaceVS:
365              VobScene = context.replaceVS              VobScene = self.context.replaceVS
366              context.replaceVS = None              self.context.replaceVS = None
367              return VobScene              return VobScene
368          context.oldVS = vs          self.context.oldVS = vs
           
369                    
370          # custom controller support          # custom controller support
371          if self.naxes >= 1: mindView.nodeScale = self.axes[0].getValue()          if self.naxes >= 1: self.view.filletWidth = self.axes[0].getValue()
372          if self.naxes >= 2: mindView.distanceScale = self.axes[1].getValue()          if self.naxes >= 2: self.view.filletLength = self.axes[1].getValue()
373          if self.naxes >= 3: mindView.rotation = -self.axes[2].getValue()          if self.naxes >= 3: self.view.rotation = -self.axes[2].getValue()
374    
375          vs.put(background(context.bgcolor))          accursed = self.context.c.getAccursed()
376          cs = vs.orthoBoxCS(0, "foo",0, 50,50, 1,1, 750,650)          # adding accursed to multiplexer
377            if accursed:
378                set = java.util.HashSet()
379                set.add(accursed)
380                self.context.multiplexer.setMultiplexerNodes(set);
381    
382            vs.put(background(self.context.bgcolor))
383            dimensions = w.getSize()
384            cs = vs.orthoBoxCS(0, "foo",0, 0,0, 1,1, dimensions.width, dimensions.height)
385          self.main.renderMain(vs, cs)          self.main.renderMain(vs, cs)
386    
387          if self.startup: w.setCursor('default'); self.startup = 0          # draw cursor
388            if accursed:
389                nodeview = ff.view.TextNodeView(fen.txtfunc, style)
390                if structLink.isLinked(accursed):
391                    if hasattr(self.view, "zoomPanCS"):
392                        self.context.c.render(vs, cs, self.view.zoomPanCS, nodeview.f(fen.graph, accursed))
393                    else: self.context.c.render(vs, cs, nodeview.f(fen.graph, accursed))
394                else: self.context.c.render(vs, 0, nodeview.f(fen.graph, accursed))
395    
396            if self.startup: w.setCursor('default'); self.startup = 0
397    
398      def mouse(self, ev):      def mouse(self, ev):
399          if ev.getType() in [vob.VobMouseEvent.MOUSE_CLICKED,          if ev.getType() in [vob.VobMouseEvent.MOUSE_CLICKED,
400                              vob.VobMouseEvent.MOUSE_DRAGGED]:                              vob.VobMouseEvent.MOUSE_DRAGGED]:
401              if self.main.mouse(ev, context.oldVS):              if self.main.mouse(ev, self.context.oldVS):
402                  vob.AbstractUpdateManager.setNoAnimation()                  vob.AbstractUpdateManager.setNoAnimation()
403              vob.AbstractUpdateManager.chg()              vob.AbstractUpdateManager.chg()
404          else:          else:
405              self.main.mouse(ev, context.oldVS)              self.main.mouse(ev, self.context.oldVS)
406                    
407      def key(self, key):      def key(self, key):
408          context.setSlowAnimation()          self.context.setSlowAnimation()
409          p("key: ", key)          p("Entered key: ", key)
410          if key == 'Escape' or key == 'Tab':          if key == 'Escape' or key == 'Tab':
411              """Removes the focus from the current accursed node and sets no new accursed node."""              """Removes the focus from the current accursed node and sets no new accursed node."""
412              context.setAccursed(None)              self.context.c.setAccursed(None)
413          elif key == 'Backspace':          elif key == 'Backspace':
414              """Removes a character before the cursor."""              """Removes a character before the cursor."""
415              if context.getAccursed() != None \              if self.context.c.getAccursed() != None \
416                     and context.offset > 0:                     and self.context.c.getOffset() > 0:
417                  context.deleteText()                  self.context.deleteText()
418          elif key == 'Delete':          elif key == 'Delete':
419              """Removes a character next to the cursor."""              """Removes a character next to the cursor."""
420              if context.getAccursed() != None:              accursed = self.context.c.getAccursed()
421                  text = alphContent.getText(fen.graph, context.getAccursed())              offset = self.context.c.getOffset()
422                  if context.offset < len(text):              if accursed:
423                      context.offset += 1                  text = self.alphContent.getText(fen.graph, accursed)
424                      context.deleteText()                  if offset < len(text):
425                        self.context.c.setOffset(offset+1)
426                        self.context.deleteText()
427          elif key == "Ctrl-S":          elif key == "Ctrl-S":
428              """Save the structure."""              """Save the structure."""
429              p("going to save");              p("going to save");
# Line 430  class VeryStupidBuoyManager: Line 440  class VeryStupidBuoyManager:
440              vob.putil.demo.loadScenes()              vob.putil.demo.loadScenes()
441          elif key == "Return":          elif key == "Return":
442              """Add a linebreak."""              """Add a linebreak."""
443              context.insertText("\n")              self.context.insertText("\n")
444              text = alphContent.getText(fen.graph, context.getAccursed())              text = self.alphContent.getText(fen.graph, self.context.c.getAccursed())
445              # small hack to show the new line on NodeView, without content it would be shrank              # small hack to show the new line on NodeView, without content it would be shrank
446              if len(text) == context.offset:              offset = self.context.c.getOffset()
447                  context.insertText(" ")              if len(text) == offset:
448                  context.offset -= 1                  self.context.insertText(" ")
449                    self.context.c.setOffset(offset)
450          elif key == 'Up':          elif key == 'Up':
451              """Move the cursor to the previous line."""              """Move the cursor to the previous line."""
452              xy = jarray.zeros(2, 'f')              self.context.c.moveUp()
             normal_text.getXY(fen.graph, context.getAccursed(),  
                                context.offset, xy)  
             xy[1] -= textstyle.getHeight(1)  
             context.offset = normal_text.getPos(fen.graph, context.getAccursed(), xy[0], xy[1])  
453          elif key == 'Down':          elif key == 'Down':
454              """Move the cursor to the next line."""              """Move the cursor to the next line."""
455              xy = jarray.zeros(2, 'f')              self.context.c.moveDown()
             normal_text.getXY(fen.graph, context.getAccursed(),  
                                context.offset, xy)  
             xy[1] += textstyle.getHeight(1)  
             context.offset = normal_text.getPos(fen.graph, context.getAccursed(), xy[0], xy[1])  
456          elif key == 'Left':          elif key == 'Left':
457              """Move the cursor a character to the left."""              """Move the cursor a character to the left."""
458              if context.offset > 0: context.offset -= 1              self.context.c.moveLeft()
459          elif key == 'Right':          elif key == 'Right':
460              """Move the cursor a character to the right."""              """Move the cursor a character to the right."""
461              text = alphContent.getText(fen.graph, context.getAccursed())              self.context.c.moveRight()
             if context.offset < len(text):  
                 context.offset += 1  
462          if key == "Ctrl-HomE":          if key == "Ctrl-HomE":
463              """Move the cursor into the beginning of the text."""              """Move the cursor into the beginning of the text."""
464              context.offset = 0              self.context.c.moveBegin()
465          if key == "Ctrl-EnD":          if key == "Ctrl-EnD":
466              """Move the cursor to the end of the text."""              """Move the cursor to the end of the text."""
467              text = alphContent.getText(fen.graph, context.getAccursed())              self.context.c.moveEnd()
             context.offset = len(text)  
468          if key == "Ctrl-C" or "Ctrl-K":          if key == "Ctrl-C" or "Ctrl-K":
469              """Copy the content of the node into the clipboard."""              """Copy the content of the node into the clipboard."""
470              text = alphContent.getText(fen.graph, context.getAccursed())              text = self.alphContent.getText(fen.graph, self.context.c.getAccursed())
471              PUIClipboard.puiCopy(text)              PUIClipboard.puiCopy(text)
472          if key == "Ctrl-V" or key=="Ctrl-Y":          if key == "Ctrl-V" or key=="Ctrl-Y":
473              """Paste the content the clipboard just after the cursor."""              """Paste the content the clipboard just after the cursor."""
474              context.insertText(PUIClipboard.getText())              self.context.insertText(PUIClipboard.getText())
475              print 'PUI', PUIClipboard.getText()              print 'PUI', PUIClipboard.getText()
476          if key == "Home" or key == "Ctrl-A":          if key == "Home" or key == "Ctrl-A":
477              """Move the cursor into the beginning of the line."""              """Move the cursor into the beginning of the line."""
478              xy = jarray.zeros(2, 'f')              self.context.c.moveBeginLine()
             normal_text.getXY(fen.graph, context.getAccursed(),  
                                context.offset, xy)  
             xy[0] = 0  
             context.offset = normal_text.getPos(fen.graph, context.getAccursed(), xy[0], xy[1])              
479          if key == "End" or key == "Ctrl-E":          if key == "End" or key == "Ctrl-E":
480              """Move the cursor to the end of the line."""              """Move the cursor to the end of the line."""
481              # the end of line is reached by going to home of the line below              self.context.c.moveEndLine()
             # and returning a single character back if not the end of text was reached  
             xy = jarray.zeros(2, 'f')  
             normal_text.getXY(fen.graph, context.getAccursed(),  
                                context.offset, xy)  
             xy[0] = 0  
             xy[1] += textstyle.getHeight(1)  
             context.offset = normal_text.getPos(fen.graph, context.getAccursed(), xy[0], xy[1])  
             text = alphContent.getText(fen.graph, context.getAccursed())  
             if context.offset < len(text): context.offset -= 1  
482          if key == "Ctrl-0":          if key == "Ctrl-0":
483              """Set calibrating state of custom controller on / off."""              """Set calibrating state of custom controller on / off."""
484              if self.calibrating and self.naxes:              if self.calibrating and self.naxes:
# Line 506  class VeryStupidBuoyManager: Line 493  class VeryStupidBuoyManager:
493                      axe.setState(vob.input.InputDeviceManager.STATE_CALIBRATING)                      axe.setState(vob.input.InputDeviceManager.STATE_CALIBRATING)
494          elif len(key) == 1:          elif len(key) == 1:
495              """Enter a character into the cursor position."""              """Enter a character into the cursor position."""
496              context.scale = 1              self.context.insertText(key)
             context.insertText(key)  
497    
498          if dbg:          if dbg:
499              text = alphContent.getText(fen.graph, context.getAccursed())              text = drlg.alphContent.getText(fen.graph, self.context.c.getAccursed())
500              print text[0:context.offset], '[cursor]'              print text[0:self.context.c.getOffset()], '[cursor]'
501                    
502    
503  currentScene = VeryStupidBuoyManager()  currentScene = MMScene()
504  vob.putil.demo.usingNormalBindings = 0  vob.putil.demo.usingNormalBindings = 0

Legend:
Removed from v.1.32  
changed lines
  Added in v.1.33

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