30 |
|
|
31 |
private Fen fen; |
private Fen fen; |
32 |
private AlphContent alphContent; |
private AlphContent alphContent; |
33 |
private RSTActionsImpl rst; |
private PPActions ppAct; |
34 |
private NodeFunction nodef; |
private NodeFunction nodef; |
35 |
public FenPDFContext(Fen fen, RSTActions rst, NodeFunction nodef) { |
public FenPDFContext(Fen fen, PPActions act, NodeFunction nodef) { |
36 |
this.fen = fen; |
this.fen = fen; |
37 |
this.rst = (RSTActionsImpl)rst; |
this.ppAct = act; |
38 |
this.nodef = nodef; |
this.nodef = nodef; |
39 |
this.alphContent = new AlphContent(fen); |
this.alphContent = new AlphContent(fen); |
40 |
} |
} |
77 |
} |
} |
78 |
|
|
79 |
|
|
80 |
private Object rstNode; |
public void handleKeyStroke(String stroke, AbstractMainNode2D main) |
|
public void setRSTNode(Object node) { |
|
|
if (RDFUtil.isNodeType(fen, node, RST.Canvas) || |
|
|
RDFUtil.isNodeType(fen, node, RST.Paragraph) || |
|
|
RDFUtil.isNodeType(fen, node, RST.Sentence) || |
|
|
RDFUtil.isNodeType(fen, node, RST.Node)) |
|
|
rstNode = node; // do nothing else |
|
|
else throw new Error("No rst node to set!"); |
|
|
} |
|
|
|
|
|
public void handleKeyStroke(String stroke, View2D view) |
|
81 |
{ try { |
{ try { |
82 |
// synchronized(fen) XXX |
// synchronized(fen) XXX |
83 |
if (accursed == null) |
|
|
throw new Error("no accursed set!"); |
|
84 |
if (cursorOffset < 0) |
if (cursorOffset < 0) |
85 |
throw new Error("no cursoroffset!! "+ cursorOffset); |
throw new Error("no cursoroffset!! "+ cursorOffset); |
86 |
p("s: "+stroke+", v: "+view); |
p("s: "+stroke+", v: "+main); |
87 |
|
|
|
if (RDFUtil.isNodeType(fen, rstNode, RST.Sentence)) { |
|
|
p("rstNode is set to sentence - no other node handlers implemented"); |
|
88 |
|
|
|
Object sentence = rstNode; |
|
89 |
|
|
90 |
if (stroke.equals(" ")) { |
if (stroke.equals("Return")) { |
91 |
p("space pressed!"); |
if (accursed==null) return; |
|
|
|
|
if (needForNewSentence(stroke, view)) |
|
|
; |
|
|
else { |
|
|
int num = getNodeNumInSentence(accursed); |
|
|
Object split = accursed; |
|
|
/* |
|
|
p("content: `"+((Enfilade1D)fen.txtfunc.f(fen.constgraph, accursed)).makeString()+"`"); |
|
|
|
|
|
Object prev = fen.graph.find1_X11(RST.nextNode, accursed); |
|
|
String spaceTest = ((Enfilade1D)fen.txtfunc. |
|
|
f(fen.constgraph, prev)).makeString(); |
|
|
*/ |
|
|
if (cursorOffset == 0) { |
|
|
p("No pre nodes!"); |
|
|
alphContent.insertText(accursed, 0, " ", true); |
|
|
} else { |
|
|
split = RDFUtil.splitNode(fen, accursed, cursorOffset); |
|
|
alphContent.insertText(split, 0, " ", true); |
|
|
Object next = fen.graph.find1_11X(split, RST.nextNode); |
|
|
if (next != null) { |
|
|
fen.graph.rm_111(split, RST.nextNode, next); |
|
|
} |
|
|
rst.insertNode(sentence, split, num + 1); |
|
|
} |
|
|
num = getNodeNumInSentence(split); |
|
|
Object split2 = RDFUtil.splitNode(fen, split, 1); |
|
|
rst.insertNode(sentence, split2, num + 1); |
|
|
|
|
|
// set correct attributes after changes |
|
|
accursed = split2; |
|
|
rstNode = sentence; |
|
|
cursorOffset = 0; |
|
|
generateCoords(split2); |
|
|
} |
|
|
return; |
|
|
} |
|
|
else if (stroke.equals("Return")) { |
|
|
p("enter makes a new sentence."); |
|
|
int num = getSentenceNum(sentence); |
|
|
Object para = rst.util.getParagraph(sentence); |
|
|
Object prev = accursed; |
|
|
sentence = rst.newSentence(para, num+1); |
|
|
|
|
|
int spaces = getPrevIntend(sentence); |
|
|
|
|
|
Object split = accursed; |
|
|
if (cursorOffset > 0) { |
|
|
split = RDFUtil.splitNode(fen, accursed, cursorOffset); |
|
|
rst.insertNode(sentence, split, 0); |
|
|
} |
|
|
Object next = fen.graph.find1_11X(accursed, RST.nextNode); |
|
|
// synchronized(fen) XXX |
|
|
if (next != null) |
|
|
fen.graph.rm_111(accursed, RST.nextNode, next); |
|
|
|
|
|
rst.insertNode(rstNode, RST.NewLine, |
|
|
getNodeNumInSentence(prev)+1); |
|
|
|
|
|
// set correct attributes after changes |
|
|
accursed = split; |
|
|
rstNode = sentence; |
|
|
cursorOffset = 0; |
|
92 |
|
|
93 |
// XXX ReturnPressed()... indent or smth |
String acc = Nodes.toString(accursed); |
94 |
for (int i=0; i<spaces; i++) |
ppAct.insertText(acc, cursorOffset, "\n"); |
95 |
handleKeyStroke(" ", view); |
cursorOffset++; |
96 |
generateCoords(accursed); |
return; |
97 |
return; |
} |
98 |
} |
else if (stroke.equals("Backspace") || |
99 |
else if (stroke.equals("Backspace") || |
stroke.equals("Tab")) { |
100 |
stroke.equals("Tab")) { |
p("not implemented. "+stroke); |
101 |
p("not implemented. "+stroke); |
} |
102 |
} |
else if (stroke.equals("Left") || |
103 |
else if (stroke.equals("Left") || |
stroke.equals("Right")) { |
104 |
stroke.equals("Right")) { |
p("not implemented. "+stroke); |
105 |
p("not implemented. "+stroke); |
} |
106 |
} |
else if (stroke.length() == 1) { |
107 |
else if (stroke.length() == 1) { |
if (accursed==null) { |
108 |
alphContent.insertText(accursed, cursorOffset, stroke, true); |
String paper = Nodes.toString(main.getPlane()); |
109 |
cursorOffset++; |
String note = ppAct.newNote(paper, (int)main.getPanX(), |
110 |
generateCoords(accursed); |
(int)main.getPanY(), ""); |
111 |
return; |
cursorOffset = 0; |
112 |
|
accursed = Nodes.get(note); |
113 |
} |
} |
114 |
|
String acc = Nodes.toString(accursed); |
115 |
|
ppAct.insertText(acc, cursorOffset, stroke); |
116 |
|
cursorOffset++; |
117 |
|
return; |
118 |
} else p("No keystroke defined!"); |
} else p("No keystroke defined!"); |
119 |
} catch (RemoteException e) { |
} catch (RemoteException e) { |
120 |
p("RemoteException ocurred! "+e); |
p("RemoteException ocurred! "+e); |
121 |
return; |
return; |
122 |
}} |
}} |
123 |
|
|
|
protected boolean needForNewSentence(String stroke, View2D view) { |
|
|
return false; } |
|
|
|
|
|
protected int getPrevIntend(Object sentence) { |
|
|
return 0; |
|
|
} |
|
|
|
|
|
|
|
|
private void generateCoords(Object node) |
|
|
throws RemoteException |
|
|
{ |
|
|
Object canvas = node; |
|
|
if (! RDFUtil.isNodeType(fen, canvas, RST.Canvas)) { |
|
|
if (! RDFUtil.isNodeType(fen, canvas, RST.Paragraph)){ |
|
|
if (! RDFUtil.isNodeType(fen, canvas, RST.Sentence)){ |
|
|
if (RDFUtil.isNodeType(fen, canvas, RST.Node)) |
|
|
canvas = rst.util.getSentence(canvas); |
|
|
else throw new Error("Not RST node!"+ node); |
|
|
} |
|
|
canvas = rst.util.getParagraph(canvas); |
|
|
} |
|
|
canvas = rst.util.getCanvas(canvas); |
|
|
} |
|
|
rst.util.generateBasicSpatialCoords(canvas, nodef); |
|
|
} |
|
|
|
|
|
private Object getFirstNode(Object sentence) |
|
|
throws RemoteException |
|
|
{ |
|
|
if (! RDFUtil.isNodeType(fen, sentence, RST.Sentence)) |
|
|
throw new Error("sentence is not sentence! "+sentence); |
|
|
return fen.graph.find1_11X(sentence, RST.nextNode); |
|
|
} |
|
|
|
|
|
private Object getLastNode(Object sentence) |
|
|
throws RemoteException |
|
|
{ |
|
|
p("go last"); |
|
|
Object n = getFirstNode(sentence); |
|
|
if (n == null) return null; |
|
|
|
|
|
Object next = fen.graph.find1_11X(n, RST.nextNode); |
|
|
while (next != null) { |
|
|
n = next; |
|
|
next = fen.graph.find1_11X(n, RST.nextNode); |
|
|
} |
|
|
p("go last DONE"); |
|
|
return n; |
|
|
} |
|
|
|
|
|
private int getNodeNumInSentence(Object node) |
|
|
throws RemoteException |
|
|
{ |
|
|
p("go node"); |
|
|
Object n = getFirstNode(rst.util.getSentence(node)); |
|
|
Object next = fen.graph.find1_11X(n, RST.nextNode); |
|
|
int i = 0; |
|
|
while (n != node || next != null) { |
|
|
n = next; |
|
|
next = fen.graph.find1_11X(n, RST.nextNode); |
|
|
i++; |
|
|
} |
|
|
p("go node DONE"); |
|
|
if (n != node && next == null) |
|
|
throw new Error("node not found in sentence"); |
|
|
return i; |
|
|
} |
|
|
|
|
|
private int getSentenceNum(Object sentence) { |
|
|
if (! RDFUtil.isNodeType(fen, sentence, RST.Sentence)) |
|
|
throw new Error("sentence is not sentence! "+sentence); |
|
|
|
|
|
Object n = sentence; |
|
|
Object prev = fen.graph.find1_X11(RST.nextSentence, n); |
|
|
while (prev != null) { |
|
|
n = prev; |
|
|
prev = fen.graph.find1_X11(RST.nextSentence, n); |
|
|
} |
|
|
int i=0; |
|
|
for (i=0; n!=sentence; i++) { |
|
|
n = fen.graph.find1_11X(n, RST.nextSentence); |
|
|
} |
|
|
return i; |
|
|
} |
|
124 |
|
|
125 |
} |
} |