[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ff-cvs] fenfire/org/fenfire demo/mm.py fenmm/MMTextCurs...
From: |
Asko Soukka |
Subject: |
[ff-cvs] fenfire/org/fenfire demo/mm.py fenmm/MMTextCurs... |
Date: |
Sun, 24 Aug 2003 05:19:58 -0400 |
CVSROOT: /cvsroot/fenfire
Module name: fenfire
Branch:
Changes by: Asko Soukka <address@hidden> 03/08/24 05:19:58
Modified files:
org/fenfire/demo: mm.py
org/fenfire/fenmm: MMTextCursor.java
org/fenfire/view/lava: mindMapView2D.py
Log message:
refactoring
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/demo/mm.py.diff?tr1=1.32&tr2=1.33&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/fenmm/MMTextCursor.java.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/view/lava/mindMapView2D.py.diff?tr1=1.35&tr2=1.36&r1=text&r2=text
Patches:
Index: fenfire/org/fenfire/demo/mm.py
diff -u fenfire/org/fenfire/demo/mm.py:1.32 fenfire/org/fenfire/demo/mm.py:1.33
--- fenfire/org/fenfire/demo/mm.py:1.32 Thu Aug 21 14:31:02 2003
+++ fenfire/org/fenfire/demo/mm.py Sun Aug 24 05:19:57 2003
@@ -60,7 +60,7 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
-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
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
Public License for more details.
@@ -92,11 +92,8 @@
print 'Creating a new RDF graph.'
do_load_graph = 0
-# Now, before reading the xu stuff, render something
-# to try to prevent NV driver
-# 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 ...
+# Now, before reading the xu stuff, render something
+# to try to prevent NV driver fallback to software rendering.
vs = w.createVobScene()
vs.put(background((.5, .5, .5)))
w.renderStill(vs, 0)
@@ -107,139 +104,118 @@
m = ModelMem()
m.read(java.io.FileReader(FILE), None);
fen.constgraph = fen.graph = ff.swamp.Graphs.toGraph(m);
-else:
- fen.graph = fen.constgraph = ff.swamp.impl.HashGraph()
+else: fen.graph = fen.constgraph = ff.swamp.impl.HashGraph()
fen.txt = ff.impl.SimpleNodeContent(fen, myalph);
fen.txtfunc = fen.txt.getNodeFunction()
fen.enfiladeOverlap = fen.txt.getTransclusionIndex()
-alphContent = ff.util.AlphContent(fen)
-
-textstyle = vob.GraphicsAPI.getInstance().getTextStyle("sansserif", 0, 24)
+style = vob.GraphicsAPI.getInstance().getTextStyle("sansserif", 0, 24)
-# normal
-normal_text = ff.view.TextNodeView(fen.txtfunc, textstyle, java.awt.Color(0.,
0., 0.))
+# nodeview for normal nodes
+normal_text = ff.view.TextNodeView(fen.txtfunc, style, java.awt.Color(0., 0.,
0.))
normal_text_bg = ff.fenmm.WhiteNodeView(normal_text, java.awt.Color(.6, .6,
.6))
-normal = ff.swamp.CachedPureNodeFunction(100, fen.constgraph, normal_text_bg)
+normal = ff.swamp.CachedPureNodeFunction(100, fen.graph, normal_text_bg)
-# accursed
-accursed_text = ff.view.TextNodeView(fen.txtfunc, textstyle,
java.awt.Color.black)
+# nodeview for accursed nodes
+accursed_text = ff.view.TextNodeView(fen.txtfunc, style, java.awt.Color.black)
accursed_text_bg = ff.fenmm.WhiteNodeView(accursed_text, java.awt.Color(.9,
.9, .9))
-accursed = ff.swamp.CachedPureNodeFunction(100, fen.constgraph,
accursed_text_bg)
+accursed = ff.swamp.CachedPureNodeFunction(100, fen.graph, accursed_text_bg)
multiplexer = ff.swamp.MultiplexerNodeFunction(normal, accursed)
-mindView = ff.view.lava.mindMapView2D.MindMapView2D(fen, multiplexer)
-
-structLink = ff.structure.StructLink(fen.graph)
+structLink = ff.structure.StructLink.create(fen.graph)
class Context(ff.view.buoy.AbstractMainNode2D.Context):
- def __init__(self):
+ def __init__(self, fen, w, home, multiplexer, style):
+ self.fen = fen
+ self.w = w
+ self.home = home
+ self.multiplexer = multiplexer
+ self.style = style
+
self.rmb_switch = [ 'go', 'link' ]
self.oldVS = None
self.replaceVS = None
+
self.main = None # MainNode2D
self.fastMouseChg = 0 # callback from abstractmainnode2d when called
mouse
- self._accursed = None
self.bgcolor = (.4, .7, 1.0)
- self.offset = 0
- self.scale = 1
- self.home = None
+ self.c = ff.fenmm.MMTextCursor(style)
+
+ self.alphContent = ff.util.AlphContent(self.fen)
def nextRmb(self):
rmb = self.rmb_switch
rmb.append(rmb.pop(0))
rmb = rmb[0]
- if rmb == 'go': self.bgcolor = (.4, .7, 1.0); w.setCursor('default')
- elif rmb == 'link': self.bgcolor = (.4, .8, .4); w.setCursor('hand')
- else: raise 'no good cursor!?'
-
- def drawCursor(self, vs, node, cs):
- xy = jarray.zeros(2, 'f')
- normal_text.getXY(fen.graph, context.getAccursed(), self.offset, xy)
- cs = vs.orthoCS(cs, "CURSOR", 0, xy[0]*self.scale, xy[1]*self.scale,
- 0, -textstyle.getHeight(self.scale))
- vs.put(vob.vobs.LineVob(0,0,0,1, java.awt.Color.black), cs)
-
- def insertText(self, 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)
+
+ if rmb == 'go': self.bgcolor = (.4, .7, 1.0);
self.w.setCursor('default')
+ elif rmb == 'link': self.bgcolor = (.4, .8, .4);
self.w.setCursor('hand')
+ else: raise 'Undefined state!'
+
+ def insertText(self, text):
+ if self.c.getAccursed() == None:
+ self.c.setAccursed(ff.util.RDFUtil.N(self.fen.graph,
MINDSTRUCT.Data))
+ self.c.setOffset(0)
+ offset = self.c.getOffset()
+ self.alphContent.insertText(self.c.getAccursed(), offset, text, 1)
+ self.c.setOffset(offset + len(text))
def deleteText(self):
if dbg: p('offs:', self.offset)
- if self._accursed == None: return
+ accursed = self.c.getAccursed()
+ if self.c.getAccursed() == None: return
+ offset = self.c.getOffset()
- alphContent.deleteText(self._accursed, self.offset-1, self.offset)
- self.offset -= 1
- l = len(alphContent.getText(fen.graph, self._accursed))
- if self.offset == 0 and l == 0:
- fen.graph.rm_111(self._accursed, RDF.type, MINDSTRUCT.Data)
- it = fen.graph.findN_X11_Iter(RDF.type, MINDSTRUCT.Data)
- self.setAccursed(None)
+ self.alphContent.deleteText(accursed, offset-1, offset)
+ self.c.setOffset(offset-1)
+ l = len(self.alphContent.getText(self.fen.graph, accursed))
+
+ offset = self.c.getOffset()
+ if offset == 0 and l == 0:
+ self.fen.graph.rm_111(accursed, RDF.type, MINDSTRUCT.Data)
+ it = self.fen.graph.findN_X11_Iter(RDF.type, MINDSTRUCT.Data)
+ self.c.setAccursed(None)
while it.hasNext():
node = it.next()
if structLink.isLinked(node): continue
- else: self.setAccursed(node)
- if dbg: p('offs:', self.offset, 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
-
+ else: self.c.setAccursed(node)
+ if dbg: p('Offset after deleteText:', self.getOffset(), l)
def rmLinkTo(self, obj, with):
- rm = 0
- iter = fen.graph.findN_11X_Iter(obj, STRUCTLINK.linkedTo)
+ totRemoved = 0
+ iter = self.fen.graph.findN_11X_Iter(obj, STRUCTLINK.linkedTo)
try:
while (iter.hasNext()):
if with == iter.next():
- fen.graph.rm_111(obj, STRUCTLINK.linkedTo, with)
- rm += 1
- iter = fen.graph.findN_11X_Iter(with, STRUCTLINK.linkedTo)
+ self.fen.graph.rm_111(obj, STRUCTLINK.linkedTo, with)
+ totRemoved += 1
+ iter = self.fen.graph.findN_11X_Iter(with, STRUCTLINK.linkedTo)
while (iter.hasNext()):
if obj == iter.next():
- fen.graph.rm_111(with, STRUCTLINK.linkedTo, obj)
- rm += 1
+ self.fen.graph.rm_111(with, STRUCTLINK.linkedTo, obj)
+ totRemoved += 1
except: pass
- return rm
+ return totRemoved
def mainNodeToBeRender(self, vs,into, main): pass
def changeFastAfterMouseEvent(self):
- if dbg: p('returning', self.fastMouseChg, 'as fast or slow')
+ if dbg: p('Returning', self.fastMouseChg, 'as fast or slow.')
return self.fastMouseChg
-
def setFastAnimation(self):
self.fastMouseChg = 1
self.replaceVS = self.oldVS
def setSlowAnimation(self):
self.fastMouseChg = 0
self.replaceVS = None
-
-
-context = Context()
-
-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()
-
+ def getScale(self, depth):
+ return 1-(Math.log(depth+1)/Math.E)
+ def getTextScale(self, depth):
+ return 1-(Math.log(depth+1)/Math.E)/2
class Action:
- def __init__(self, context):
+ def __init__(self, fen, context):
+ self.fen = fen
self.context = context
class RMB(Action, vob.mouse.MouseClickListener):
@@ -247,98 +223,111 @@
self.context.nextRmb()
self.context.setSlowAnimation()
-class Click(Action, vob.mouse.MouseClickListener):
+class LMB(Action, vob.mouse.MouseClickListener):
def clicked(self, x,y):
self.context.setSlowAnimation()
- vs = context.oldVS
+ vs = self.context.oldVS
node = vs.getKeyAt(0, x,y, None)
- p('key', node)
+ p('LBM click:', node)
if node == None: return
- rmb = context.rmb_switch[0]
+ rmb = self.context.rmb_switch[0]
+ main = self.context.main
if rmb == 'go':
- self.context.setAccursed(node, multiplexer)
+ self.context.c.setAccursed(node)
+
+ ### something easier to allow setOffset(x,y) before rendering
+ nodeview = ff.view.TextNodeView(self.fen.txtfunc,
self.context.style)
+ self.context.c.setTextPlaceable(nodeview.f(fen.graph, node))
# set cursor, transitions between zoomed and normal should be
accounted
cs = vs.getCSAt(0, x,y, None)
into = jarray.zeros(3, 'f')
vs.coords.transformPoints3(cs, [0,0,0], into)
+ scale = 1./main.getFocus().getZoom()
+ cursor = self.context.c
+ accursed = cursor.getAccursed()
+
# scaling
- nodeScale = (100+into[2])+4
- if mindView.maxDepth > 40: nodeScale *= 40./mindView.maxDepth
- nodeScale = 1-math.log10(nodeScale/4.)
-
- if node == self.context.main.getPlane():
- # from border to 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)
- 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)
+ nodeScale = self.context.getTextScale(100+into[2])
+
+ if node == self.context.main.getPlane(): # from border to linked
+ cursor.setOffset((x-into[0])/scale/nodeScale,
(y-into[1])/scale/nodeScale)
+ elif structLink.isLinked(node): # from linked or border to another
linked
+ cursor.setOffset((x-into[0])/scale/nodeScale,
(y-into[1])/scale/nodeScale)
+ main.setNewPlane(node, 0,0,1)
+ else: # from border to border
+ cursor.setOffset((x-into[0])/nodeScale, (y-into[1])/nodeScale)
+
elif rmb == 'link':
- if node == self.context.main.getPlane(): pass
- elif self.context.rmLinkTo(node, self.context.main.getPlane()) ==
0:
- fen.graph.add(self.context.main.getPlane(),
STRUCTLINK.linkedTo, node)
+ if node == main.getPlane(): pass
+ elif self.context.rmLinkTo(node, main.getPlane()) == 0:
+ self.fen.graph.add(main.getPlane(), STRUCTLINK.linkedTo, node)
class ZoomPan(vob.input.RelativeAxisListener, Action,
vob.mouse.MousePressListener):
+ def __init__(self, fen, context):
+ Action.__init__(self, fen, context)
+ self.oldZoom = 1.
def pressed(self, x,y):
return self
def changedRelative(self, x):
- self.context.main.changeZoom(x)
- self.context.main.chgFast(self.context.oldVS, -1)
+ main = self.context.main
+ f = main.getFocus()
+ fX, fY = f.getPanX(), f.getPanY()
+
+ dimensions = w.getSize()
+ fX -= dimensions.width*(-.5/self.oldZoom + .5)
+ fY -= dimensions.height*(-.5/self.oldZoom + .5)
+ fX += dimensions.width*(-.5/f.zoom + .5)
+ fY += dimensions.height*(-.5/f.zoom + .5)
+ f.setPan(fX, fY)
+ self.oldZoom = f.zoom
+
+ if x: main.changeZoom(1./x)
+ else: main.changeZoom(0)
+ main.chgFast(self.context.oldVS, -1)
+
self.context.fastMouseChg = 1
- if self.context.getAccursed() and \
- structLink.isLinked(self.context.getAccursed()):
- self.context.scale = self.context.main.getFocus().getZoom()
+ accursed = self.context.c.getAccursed()
self.context.setFastAnimation()
class PanMover(Action, vob.mouse.RelativeAdapter,
vob.mouse.MousePressListener):
def pressed(self, x,y):
return self
def changedRelative(self, x,y='foo'):
- f = self.context.main.getFocus()
+ main = self.context.main
+ f = main.getFocus()
fX, fY = f.getPanX(), f.getPanY()
- f.setPan(fX-x/f.zoom,
- fY-y/f.zoom)
- self.context.main.chgFast(self.context.oldVS, -1)
+ f.setPan(fX+x/f.zoom,
+ fY+y/f.zoom)
+ main.chgFast(self.context.oldVS, -1)
self.context.setFastAnimation()
+class MMScene:
+ def __init__(self):
+ self.alphContent = ff.util.AlphContent(fen)
+ if do_load_graph:
+ self.home = fen.graph.findN_X1A_Iter(STRUCTLINK.linkedTo).next()
+ else:
+ self.home = ff.util.RDFUtil.N(fen.graph, MINDSTRUCT.Data)
+ self.alphContent.insertText(self.home, 0, 'Home', 1)
-mindMouse = vob.mouse.MouseMultiplexer()
-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))
+ self.context = Context(fen, w, self.home, multiplexer, style)
-class VeryStupidBuoyManager:
- def __init__(self):
- self.main = ff.view.lava.mindMapView2D.MindMapMainNode2D(context.home,
mindView,
- ff.view.buoy.AbstractMainNode2D.SimpleFocus(0,0), mindMouse)
- self.main.init(fen, multiplexer)
- context.main = self.main
-
- # contexts for e.g. drawCursor callbacks and delivering accursedNode
- self.main.context = context
- self.main.setColors(fen)
- mindView.context = context
+ self.mindMouse = vob.mouse.MouseMultiplexer()
+ self.mindMouse.setListener(3, 0, 'Right mouse button switching.',
RMB(fen, self.context))
+ self.mindMouse.setListener(3, 0, self.mindMouse.VERTICAL, 1.0, \
+ 'Zooming the main view.', ZoomPan(fen, self.context))
+ self.mindMouse.setListener(1, 0, 'Left mouse button action.', LMB(fen,
self.context))
+ self.mindMouse.setListener(1, 0,'Moving the pan around or the node if
accursed.', \
+ PanMover(fen, self.context))
+
+ self.view = ff.view.lava.mindMapView2D.MindMapView2D(fen,
self.context, 5)
+ self.main = ff.view.lava.mindMapView2D.MindMapMainNode2D(fen,
self.context, self.view, self.mindMouse)
+ self.context.main = self.main
# flag for cursor('wait')
self.startup = 1
@@ -346,17 +335,21 @@
### custom controller support
self.naxes = 0
self.calibrating = 0
+
try:
- self.ps2 = vob.input.impl.PS2MouseDevice("/dev/input/mouse0",
"main",
- vob.input.impl.PS2MouseDevice.IMPS_PROTO)
+ self.ps2 = vob.input.impl.PS2MouseDevice( \
+ java.lang.System.getProperty("cc.device",
"/dev/input/mouse0"), \
+ "main", vob.input.impl.PS2MouseDevice.IMPS_PROTO)
+
self.naxes = len(self.ps2.getAxes())
if self.naxes > 3: self.naxes = 3
self.axes = [None, None, None]
+
if self.naxes >= 1:
- 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,
actionPerformed = lambda x:
vob.AbstractUpdateManager.chg())
if self.naxes >= 2:
- 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,
actionPerformed = lambda x:
vob.AbstractUpdateManager.chg())
if self.naxes >= 3:
self.axes[2] = vob.input.impl.WrappingBoundedFloatModel(0,
Math.PI*2,
@@ -368,52 +361,69 @@
except java.io.FileNotFoundException: pass
def scene(self, vs):
- if context.replaceVS:
- VobScene = context.replaceVS
- context.replaceVS = None
+ if self.context.replaceVS:
+ VobScene = self.context.replaceVS
+ self.context.replaceVS = None
return VobScene
- context.oldVS = vs
-
+ self.context.oldVS = vs
# custom controller support
- if self.naxes >= 1: mindView.nodeScale = self.axes[0].getValue()
- if self.naxes >= 2: mindView.distanceScale = self.axes[1].getValue()
- if self.naxes >= 3: mindView.rotation = -self.axes[2].getValue()
-
- vs.put(background(context.bgcolor))
- cs = vs.orthoBoxCS(0, "foo",0, 50,50, 1,1, 750,650)
+ if self.naxes >= 1: self.view.filletWidth = self.axes[0].getValue()
+ if self.naxes >= 2: self.view.filletLength = self.axes[1].getValue()
+ if self.naxes >= 3: self.view.rotation = -self.axes[2].getValue()
+
+ accursed = self.context.c.getAccursed()
+ # adding accursed to multiplexer
+ if accursed:
+ set = java.util.HashSet()
+ set.add(accursed)
+ self.context.multiplexer.setMultiplexerNodes(set);
+
+ vs.put(background(self.context.bgcolor))
+ dimensions = w.getSize()
+ cs = vs.orthoBoxCS(0, "foo",0, 0,0, 1,1, dimensions.width,
dimensions.height)
self.main.renderMain(vs, cs)
- if self.startup: w.setCursor('default'); self.startup = 0
+ # draw cursor
+ if accursed:
+ nodeview = ff.view.TextNodeView(fen.txtfunc, style)
+ if structLink.isLinked(accursed):
+ if hasattr(self.view, "zoomPanCS"):
+ self.context.c.render(vs, cs, self.view.zoomPanCS,
nodeview.f(fen.graph, accursed))
+ else: self.context.c.render(vs, cs, nodeview.f(fen.graph,
accursed))
+ else: self.context.c.render(vs, 0, nodeview.f(fen.graph, accursed))
+ if self.startup: w.setCursor('default'); self.startup = 0
def mouse(self, ev):
if ev.getType() in [vob.VobMouseEvent.MOUSE_CLICKED,
vob.VobMouseEvent.MOUSE_DRAGGED]:
- if self.main.mouse(ev, context.oldVS):
+ if self.main.mouse(ev, self.context.oldVS):
vob.AbstractUpdateManager.setNoAnimation()
vob.AbstractUpdateManager.chg()
else:
- self.main.mouse(ev, context.oldVS)
+ self.main.mouse(ev, self.context.oldVS)
def key(self, key):
- context.setSlowAnimation()
- p("key: ", key)
+ self.context.setSlowAnimation()
+ p("Entered key: ", key)
if key == 'Escape' or key == 'Tab':
"""Removes the focus from the current accursed node and sets no
new accursed node."""
- context.setAccursed(None)
+ self.context.c.setAccursed(None)
elif key == 'Backspace':
"""Removes a character before the cursor."""
- if context.getAccursed() != None \
- and context.offset > 0:
- context.deleteText()
+ if self.context.c.getAccursed() != None \
+ and self.context.c.getOffset() > 0:
+ self.context.deleteText()
elif key == 'Delete':
"""Removes a character next to the cursor."""
- if context.getAccursed() != None:
- text = alphContent.getText(fen.graph, context.getAccursed())
- if context.offset < len(text):
- context.offset += 1
- context.deleteText()
+ accursed = self.context.c.getAccursed()
+ offset = self.context.c.getOffset()
+ if accursed:
+ text = self.alphContent.getText(fen.graph, accursed)
+ if offset < len(text):
+ self.context.c.setOffset(offset+1)
+ self.context.deleteText()
elif key == "Ctrl-S":
"""Save the structure."""
p("going to save");
@@ -430,68 +440,45 @@
vob.putil.demo.loadScenes()
elif key == "Return":
"""Add a linebreak."""
- context.insertText("\n")
- text = alphContent.getText(fen.graph, context.getAccursed())
+ self.context.insertText("\n")
+ text = self.alphContent.getText(fen.graph,
self.context.c.getAccursed())
# small hack to show the new line on NodeView, without content it
would be shrank
- if len(text) == context.offset:
- context.insertText(" ")
- context.offset -= 1
+ offset = self.context.c.getOffset()
+ if len(text) == offset:
+ self.context.insertText(" ")
+ self.context.c.setOffset(offset)
elif key == 'Up':
"""Move the cursor to the previous line."""
- xy = jarray.zeros(2, 'f')
- 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])
+ self.context.c.moveUp()
elif key == 'Down':
"""Move the cursor to the next line."""
- xy = jarray.zeros(2, 'f')
- 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])
+ self.context.c.moveDown()
elif key == 'Left':
"""Move the cursor a character to the left."""
- if context.offset > 0: context.offset -= 1
+ self.context.c.moveLeft()
elif key == 'Right':
"""Move the cursor a character to the right."""
- text = alphContent.getText(fen.graph, context.getAccursed())
- if context.offset < len(text):
- context.offset += 1
+ self.context.c.moveRight()
if key == "Ctrl-HomE":
"""Move the cursor into the beginning of the text."""
- context.offset = 0
+ self.context.c.moveBegin()
if key == "Ctrl-EnD":
"""Move the cursor to the end of the text."""
- text = alphContent.getText(fen.graph, context.getAccursed())
- context.offset = len(text)
+ self.context.c.moveEnd()
if key == "Ctrl-C" or "Ctrl-K":
"""Copy the content of the node into the clipboard."""
- text = alphContent.getText(fen.graph, context.getAccursed())
+ text = self.alphContent.getText(fen.graph,
self.context.c.getAccursed())
PUIClipboard.puiCopy(text)
if key == "Ctrl-V" or key=="Ctrl-Y":
"""Paste the content the clipboard just after the cursor."""
- context.insertText(PUIClipboard.getText())
+ self.context.insertText(PUIClipboard.getText())
print 'PUI', PUIClipboard.getText()
if key == "Home" or key == "Ctrl-A":
"""Move the cursor into the beginning of the line."""
- xy = jarray.zeros(2, 'f')
- 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])
+ self.context.c.moveBeginLine()
if key == "End" or key == "Ctrl-E":
"""Move the cursor to the end of the line."""
- # the end of line is reached by going to home of the line below
- # 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
+ self.context.c.moveEndLine()
if key == "Ctrl-0":
"""Set calibrating state of custom controller on / off."""
if self.calibrating and self.naxes:
@@ -506,13 +493,12 @@
axe.setState(vob.input.InputDeviceManager.STATE_CALIBRATING)
elif len(key) == 1:
"""Enter a character into the cursor position."""
- context.scale = 1
- context.insertText(key)
+ self.context.insertText(key)
if dbg:
- text = alphContent.getText(fen.graph, context.getAccursed())
- print text[0:context.offset], '[cursor]'
+ text = drlg.alphContent.getText(fen.graph,
self.context.c.getAccursed())
+ print text[0:self.context.c.getOffset()], '[cursor]'
-currentScene = VeryStupidBuoyManager()
+currentScene = MMScene()
vob.putil.demo.usingNormalBindings = 0
Index: fenfire/org/fenfire/fenmm/MMTextCursor.java
diff -u fenfire/org/fenfire/fenmm/MMTextCursor.java:1.1
fenfire/org/fenfire/fenmm/MMTextCursor.java:1.2
--- fenfire/org/fenfire/fenmm/MMTextCursor.java:1.1 Wed Aug 20 02:11:37 2003
+++ fenfire/org/fenfire/fenmm/MMTextCursor.java Sun Aug 24 05:19:57 2003
@@ -10,10 +10,12 @@
import org.nongnu.libvob.VobScene;
import org.nongnu.libvob.TextStyle;
import org.nongnu.libvob.vobs.LineVob;
+import org.fenfire.swamp.MultiplexerNodeFunction;
import org.nongnu.libvob.lava.placeable.TextPlaceable;
import java.awt.Color;
+import java.util.HashSet;
public class MMTextCursor {
public static final String rcsid = "$Id:";
@@ -43,6 +45,17 @@
}
public void setAccursed(Object node) { accursed = node; offset = 0; }
+
+ /** unnecessary
+ public HashSet setAccursed(Object node, MultiplexerNodeFunction
multiplexer) {
+ HashSet set = new HashSet();
+ set.add(node);
+ setAccursed(node);
+ if (multiplexer != null) multiplexer.setMultiplexerNodes(set);
+ return set;
+ }
+ */
+
public Object getAccursed() { return accursed; }
public int setOffset(int offset) { this.offset = offset; return
this.offset; }
public int setOffset(float x, float y) throws NotYetRenderedException {
@@ -124,21 +137,33 @@
this.length = 0;
}
- public void render(VobScene vs, int rootCS, TextPlaceable p) {
+ public void render(VobScene vs, int into, TextPlaceable p) {
+ render(vs, into, 0, p);
+ }
+ public void render(VobScene vs, int matchCS, int zoomPanCS, TextPlaceable
p) {
setTextPlaceable(p);
- int nodeCS = vs.matcher.getCS(accursed);
- float nodeXY[] = {0f, 0f, 0f};
- vs.coords.transformPoints3(nodeCS, nodeXY, nodeXY);
-
float cursorXY[] = new float[2];
this.p.getCursorXY(offset, cursorXY);
- int cursorCS = vs.orthoCS(rootCS, "CURSOR", -1000,
- nodeXY[0] + cursorXY[0],
- nodeXY[1] + cursorXY[1],
- 1, -style.getHeight(scale));
-
+ int nodeCS;
+ int cursorCS;
+ if (zoomPanCS > 0) {
+ cursorCS = vs.coords.ortho(zoomPanCS, -1000,
+ -p.getWidth()/2 + cursorXY[0],
+ -p.getHeight()/2 + cursorXY[1],
+ 1, -style.getHeight(scale));
+ vs.matcher.add(matchCS, cursorCS, "CURSOR");
+ } else {
+ nodeCS = vs.matcher.getCS(accursed);
+ float nodeXY[] = {0f, 0f, 0f};
+ vs.coords.transformPoints3(nodeCS, nodeXY, nodeXY);
+
+ cursorCS = vs.orthoCS(matchCS, "CURSOR", -1000,
+ nodeXY[0] + cursorXY[0],
+ nodeXY[1] + cursorXY[1],
+ 1, -style.getHeight(scale));
+ }
vs.put(new LineVob(0,0,0,1, color), cursorCS);
}
Index: fenfire/org/fenfire/view/lava/mindMapView2D.py
diff -u fenfire/org/fenfire/view/lava/mindMapView2D.py:1.35
fenfire/org/fenfire/view/lava/mindMapView2D.py:1.36
--- fenfire/org/fenfire/view/lava/mindMapView2D.py:1.35 Thu Aug 21 14:31:02 2003
+++ fenfire/org/fenfire/view/lava/mindMapView2D.py Sun Aug 24 05:19:58 2003
@@ -19,15 +19,13 @@
#
from __future__ import nested_scopes
-import java, jarray, math
+import java, jarray
from java.lang import Math
import vob
import org.fenfire as ff
-import org.fenfire.vocab.STRUCTLINK as LINK
-from org.fenfire.vocab import *
-from org.fenfire.vocab.lava import MINDSTRUCT as MIND
-from org.fenfire.swamp import Nodes
+from org.fenfire.vocab import STRUCTLINK, RDF
+from org.fenfire.vocab.lava import MINDSTRUCT
from org.fenfire.fenmm import MindNet
@@ -37,49 +35,62 @@
dbg = 0
class MindMapMainNode2D(ff.view.buoy.MainNode2D):
- def __init__(self, plane, view2d, focus, controller):
- ff.view.buoy.MainNode2D.__init__(self, plane, view2d, controller);
- self.context = None
+ def __init__(self, fen, context, view2d, controller):
+ ff.view.buoy.MainNode2D.__init__(self, context.home, view2d,
controller);
+ self.fen = fen
+ self.context = context
+ self.structLink = ff.structure.StructLink.create(self.fen.graph)
- def setColors(self, fen):
- textstyle = vob.GraphicsAPI.getInstance().getTextStyle("sansserif", 0,
24)
-
- # normal
- normal_text = ff.view.TextNodeView(fen.txtfunc, textstyle,
java.awt.Color(0., 0., 0.))
+ style = self.context.style
+
+ # node view normal nodes of floating buffer
+ normal_text = ff.view.TextNodeView(self.fen.txtfunc, style,
java.awt.Color(0., 0., 0.))
normal_text_bg = ff.fenmm.WhiteNodeView(normal_text,
java.awt.Color(.6, .6, 0))
- normal = ff.swamp.CachedPureNodeFunction(100, fen.constgraph,
normal_text_bg)
+ normal = ff.swamp.CachedPureNodeFunction(100, self.fen.graph,
normal_text_bg)
- # accursed
- accursed_text = ff.view.TextNodeView(fen.txtfunc, textstyle,
java.awt.Color.black)
+ # node view for accursed nodes of floating buffer
+ accursed_text = ff.view.TextNodeView(self.fen.txtfunc, style,
java.awt.Color.black)
accursed_text_bg = ff.fenmm.WhiteNodeView(accursed_text,
java.awt.Color(.9, .9, .9))
- accursed = ff.swamp.CachedPureNodeFunction(100, fen.constgraph,
accursed_text_bg)
+ accursed = ff.swamp.CachedPureNodeFunction(100, self.fen.graph,
accursed_text_bg)
self.multiplexer = ff.swamp.MultiplexerNodeFunction(normal, accursed)
- def init(self, fen, nodeview):
- self.fen, self.viewfunc = fen, nodeview
- self.structLink = ff.structure.StructLink(self.fen.graph)
-
-
def renderMain(self, vs, into):
ff.view.buoy.MainNode2D.renderMain(self, vs, into)
- # then draw unused mind data around.
- unused = []
- iter = self.fen.graph.findN_X11_Iter(RDF.type, MIND.Data)
+ accursed = self.context.c.getAccursed()
+ # adding accursed to multiplexer
+ if accursed:
+ set = java.util.HashSet()
+ set.add(accursed)
+ self.multiplexer.setMultiplexerNodes(set);
+
+ # then draw unused mind data into floating buffer.
+ buffer = []
+ home = self.context.home
+ iter = self.fen.graph.findN_X11_Iter(RDF.type, MINDSTRUCT.Data)
while (iter.hasNext()):
obj = iter.next()
- if self.structLink.isLinked(self.fen.graph, obj): continue
- if self.context and obj == self.context.home: continue
- unused.append(obj)
-
- if len(unused) == 0: return
- d = 360.0/len(unused)
- for i in range(len(unused)):
- self.makeCSforUnusedAround(unused[i], vs, Math.toRadians(i*d))
+ if self.structLink.isLinked(obj): continue
+ if obj == home: continue
+ buffer.append(obj)
-
- def makeCSforUnusedAround(self, key, vs, angle):
+ floating = self.floatingBuffer(vs, buffer)
+ i = floating.keySet().iterator()
+ while i.hasNext():
+ node = i.next()
+ self.place(vs, node, floating.get(node))
+
+ def floatingBuffer(self, vs, buffer):
+ map = java.util.HashMap()
+ if len(buffer) == 0: return map
+
+ d = 360.0/len(buffer)
+ for i in range(len(buffer)):
+ map.put(buffer[i], self.singleCS(vs, buffer[i],
Math.toRadians(i*d)))
+ return map
+
+ def singleCS(self, vs, node, angle):
angle += 0.5 * Math.PI
angle %= 2.0 * Math.PI
wi, h = vs.size.width, vs.size.height
@@ -94,37 +105,35 @@
x = r * Math.cos(angle) + x0
y = -r * Math.sin(angle) + y0
- cs = vs.orthoBoxCS(0, key, -100,x-bx/2,y-by/2, 1,1, bx,by)
- self.place(key, vs, cs)
+ cs = vs.orthoBoxCS(0, node, -100, x-bx/2,y-by/2, 1,1, bx,by)
+ return cs
- def place(self, node, vs, cs):
+ def place(self, vs, node, cs):
p = self.multiplexer.f(self.fen.graph, node)
-
cs = vs.orthoBoxCS(cs,node,0, 0, 0, 1,1, p.getWidth(), p.getHeight())
p.place(vs, cs)
vs.coords.activate(cs)
- # draw cursor
- if self.context and self.context.getAccursed() == node:
- self.context.drawCursor(vs, node, cs)
-
class MindMapView2D(ff.view.View2D):
- def __init__(self, fen, nodef):
+ def __init__(self, fen, context, depth):
self.fen = fen
- self.alphContent = ff.util.AlphContent(fen)
- self.box = None
- self.nodef = nodef
- self.context = None
- self.maxDepth = 5
- self.nodeScale = 15
- self.distanceScale = 4.
+ self.context = context
+
+ self.multiplexer = self.context.multiplexer
+
+ self.filletWidth = 15. # divider
+ self.filletLength = 4. # divider
self.rotation = 0.
+ self.maxDepth = depth
+
+ self.box = None
+
# Stored data to help interpolation to nodes next to accursed
self.current = {'centerNode': None, 'startAngle': 0., 'rotationAngle':
0.}
self.previous = {'centerNode': None, 'startAngle': 0.,
'rotationAngle': 0.}
- ### fillet set up
+ # fillet set up
self.angle = 1
self.thick = 1
self.drawEdge = 0
@@ -135,9 +144,7 @@
self.stretched = 1
self.curvature = 0
self.sectors = 1
- #self.N", 21, 3, "N", "N", "n"),
self.fillets = 1
- #self.size", 100, 10, "Node size", "K", "k"),
self.dice = 10
self.fillet3d = 1
self.blend3d = 0
@@ -149,23 +156,20 @@
self.mode = 0
def getNodeSize(self, depth):
- """Node size is relative to depth as 1-math.log10(depth)."""
+ """Node size is relative to depth as 1-(Math.log(depth)/Math.E)."""
assert depth <= self.maxDepth, 'Depth is greater than maxDepth.'
- if depth < 1: depth = 1 # same size for center and the first depth
- if self.maxDepth > 10: depth = depth * (10/self.maxDepth)
- s =(self.box[1] * 1./self.nodeScale) * (1-math.log10(depth))
- if dbg: p('size:', s)
+ s =(self.box[1] * 1./self.filletWidth) * self.context.getScale(depth)
+ if dbg: p('fillet size:', s)
return s
def getDistance(self, depth):
- """Distance is relative to depth as 1-math.log10(depth)."""
+ """Node distance is relative to depth as 1-(Math.log(depth)/Math.E)."""
assert depth <= self.maxDepth, 'Depth is greater than maxDepth.'
if depth == 0: return 0
- if self.maxDepth > 10: depth = depth * (10/self.maxDepth)
- d = (self.box[0] * 1./self.distanceScale) * (1-math.log10(depth))
- if dbg: p('dist: ', d)
+ d = (self.box[0] * 1./self.filletLength) * self.context.getScale(depth)
+ if dbg: p('fillet length: ', d)
return d
def render(self, vs, node,
@@ -173,22 +177,29 @@
self.matchingParent = matchingParent
p("Rendering view.")
- if dbg:
- dbg1 = vs.unitSqCS(box2screen, "U")
- vs.put(coloredQuad((0,1,0)), dbg1)
- p('foo')
+# if dbg:
+# p('Drawing screenbox')
+# dbg1 = vs.unitSqCS(box2screen, "UNIT_SCREEN")
+# vs.put(vob.coloredQuad((0,1,0)), dbg1)
+
+# paper2box = vs.invertCS(box2plane, "minMap_INv")
+# paper2screen = vs.concatCS(box2screen, 'mindMap_CONCAT',
+# paper2box)
- paper2box = vs.invertCS(box2plane, "minMap_INv")
paper2screen = vs.concatCS(box2screen, 'mindMap_CONCAT',
- paper2box)
+ box2plane)
+ box = jarray.zeros(2, 'f')
+ vs.coords.getSqSize(box2screen, box)
+ self.box = box
+ paper2screen = vs.translateCS(paper2screen, 'mindMap_TRANS',
+ box[0], box[1], 0)
+ # XXX
+ self.zoomPanCS = paper2screen
+
# links between nodes and also storin nodes currently.
self.net = MindNet()
- box = jarray.zeros(2, 'f')
- vs.coords.getSqSize(box2screen, box)
- x, y = box[0]/2.0, box[1]/2.0
- self.box = box
### Get the cs for center node
pl = self.getPlace(vs, paper2screen, 0,0, node, 0,0)
@@ -245,10 +256,9 @@
c.append(pl2[0])
if dbg: p('info:', pl2[0], pl2[1], pl2[2])
- if dbg: p('fillet..', c, )
-
+ if dbg: p('Fillet coordinates:', c)
def pc(conns, cs):
- if self.context and self.context.getAccursed() == node:
+ if self.context.c.getAccursed() == node:
vs.put(vob.putil.misc.getDListNocoords("""Color 1. 0.
0."""))
vs.put(conns, cs+c)
@@ -261,15 +271,15 @@
self.putNodeContent(vs, node, cs)
def getLinks(self, fen, node):
- """ Get all links available with node."""
+ """Get all links available with node."""
nodes = []
- iter = fen.graph.findN_11X_Iter(node, LINK.linkedTo)
+ iter = fen.graph.findN_11X_Iter(node, STRUCTLINK.linkedTo)
while iter.hasNext():
nodes.append(iter.next())
- iter = fen.graph.findN_X11_Iter(LINK.linkedTo, node)
+ iter = fen.graph.findN_X11_Iter(STRUCTLINK.linkedTo, node)
while iter.hasNext():
nodes.append(iter.next())
- if dbg: p('linked nodes: ', nodes)
+ if dbg: p('Found linked nodes: ', nodes)
return nodes
def doMindMapCS(self, vs, into, centerNode, oldCenter, links, x, y,
@@ -286,39 +296,31 @@
if self.net.getPlace(link) == None:
pl = self.getPlace(vs, into, x, y, link,
startAngle+rotationAngle*i, depth)
- if dbg: p('new node', pl)
+ if dbg: p('Add a new node', pl)
self.net.put(link, pl, depth)
else:
pl = self.net.getPlace(link)
- if dbg: p('old node', pl)
-
- # debugging..
- if dbg:
- p('main node:',self.alphContent.getText(centerNode))
- for link in links:
- p('
',self.alphContent.getText(link),self.net.getPlace(link))
+ if dbg: p('Reached an old node', pl)
if depth >= maxDepth: return
for i in range(len(links)):
link = links[i]
if link == oldCenter: continue
- if 1: # Ask mudyc about this, how this will affect
-# if self.doLink.get(link) != None:
-# self.doLink.put(link, None)
- place = self.net.getPlace(link)
- newLinks = self.getLinks(fen, link)
- newAngle = Math.PI*2./float(len(newLinks))
-
- fromIndex = None
- try: fromIndex = newLinks.index(centerNode)
- except ValueError: pass
- if fromIndex != None:
- newStartAngle = (startAngle+rotationAngle*i-Math.PI) \
- + newAngle*float(len(newLinks)-fromIndex)
- else: newStartAngle = 0
-
- self.doMindMapCS(vs, into, link, centerNode, newLinks,
place[1], place[2],
- newStartAngle, newAngle, depth + 1, maxDepth)
+
+ place = self.net.getPlace(link)
+ newLinks = self.getLinks(fen, link)
+ newAngle = Math.PI*2./float(len(newLinks))
+
+ fromIndex = None
+ try: fromIndex = newLinks.index(centerNode)
+ except ValueError: pass
+ if fromIndex != None:
+ newStartAngle = (startAngle+rotationAngle*i-Math.PI) \
+ + newAngle*float(len(newLinks)-fromIndex)
+ else: newStartAngle = 0
+
+ self.doMindMapCS(vs, into, link, centerNode, newLinks, place[1],
place[2],
+ newStartAngle, newAngle, depth + 1, maxDepth)
def getPlace(self, vs, into, x0,y0, key, angle, depth):
xy = self.getXY(x0,y0, angle, depth)
@@ -328,8 +330,8 @@
if (dbg): print 'size', s
cs = vs.orthoBoxCS(into,'foo'+str(key),depth, x-s/2.0,y-s/2.0, 1,1,
s,s)
if dbg:
- p('come:',x0,y0, angle)
- p(cs, xy, angle, s)
+ p('Place seed:',x0, y0, angle)
+ p('Constructed place:',cs, xy, angle, s)
return [cs, x, y, angle]
def getXY(self, x0, y0, angle, depth):
@@ -342,14 +344,11 @@
def putNodeContent(self, vs, node, cs):
-
- # scaling
+ # scaling after depth
depth = self.net.getDepth(node)
- scale = depth+4
- if self.maxDepth > 40: scale *= 40./self.maxDepth
- scale = 1-math.log10(scale/4.)
+ scale = self.context.getTextScale(depth)
- p = self.nodef.f(self.fen.graph, node)
+ p = self.multiplexer.f(self.fen.graph, node)
x = self.getNodeSize(depth)/2 - (p.getWidth()*scale)/2.0
y = self.getNodeSize(depth)/2 - (p.getHeight()*scale)/2.0
@@ -357,10 +356,3 @@
cs = vs.orthoBoxCS(cs,node,0, x,y, scale, scale, p.getWidth(),
p.getHeight())
p.place(vs, cs)
vs.coords.activate(cs)
-
- # draw cursor
- if self.context and self.context.getAccursed() == node:
- into = jarray.zeros(3, 'f')
- vs.coords.transformPoints3(cs, [0,0,0], into)
- cs = vs.orthoCS(0, 0, -100, into[0], into[1], 1, 1)
- self.context.drawCursor(vs, node, cs)
- [ff-cvs] fenfire/org/fenfire demo/mm.py fenmm/MMTextCurs...,
Asko Soukka <=