Révision 653
tmp/org.txm.concordance.rcp/plugin.xml (revision 653) | ||
---|---|---|
67 | 67 |
</menuContribution> |
68 | 68 |
<menuContribution |
69 | 69 |
allPopups="false" |
70 |
locationURI="toolbar:org.txm.rcp.toolbartools"> |
|
70 |
locationURI="toolbar:org.txm.rcp.toolbartools?after=org.txm.index.rcp.handlers.ComputeIndex">
|
|
71 | 71 |
<command |
72 | 72 |
commandId="org.txm.concordance.rcp.handlers.ComputeConcordance" |
73 | 73 |
icon="icons/concordance.png" |
tmp/org.txm.synopticeditor.rcp/src/org/txm/synopticedition/rcp/handlers/BackToText.java (revision 653) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
4 |
// Sophia Antipolis, University of Paris 3. |
|
5 |
// |
|
6 |
// The TXM platform is free software: you can redistribute it |
|
7 |
// and/or modify it under the terms of the GNU General Public |
|
8 |
// License as published by the Free Software Foundation, |
|
9 |
// either version 2 of the License, or (at your option) any |
|
10 |
// later version. |
|
11 |
// |
|
12 |
// The TXM platform is distributed in the hope that it will be |
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
// PURPOSE. See the GNU General Public License for more |
|
16 |
// details. |
|
17 |
// |
|
18 |
// You should have received a copy of the GNU General |
|
19 |
// Public License along with the TXM platform. If not, see |
|
20 |
// http://www.gnu.org/licenses. |
|
21 |
// |
|
22 |
// |
|
23 |
// |
|
24 |
// $LastChangedDate:$ |
|
25 |
// $LastChangedRevision:$ |
|
26 |
// $LastChangedBy:$ |
|
27 |
// |
|
28 |
package org.txm.synopticedition.rcp.handlers; |
|
29 |
|
|
30 |
|
|
31 |
import java.util.ArrayList; |
|
32 |
import java.util.HashMap; |
|
33 |
import java.util.HashSet; |
|
34 |
import java.util.List; |
|
35 |
|
|
36 |
import javax.sound.sampled.Line; |
|
37 |
|
|
38 |
import org.eclipse.core.commands.ExecutionEvent; |
|
39 |
import org.eclipse.core.commands.ExecutionException; |
|
40 |
import org.eclipse.e4.ui.workbench.modeling.EModelService; |
|
41 |
import org.eclipse.jface.viewers.ISelection; |
|
42 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
43 |
import org.eclipse.osgi.util.NLS; |
|
44 |
import org.eclipse.ui.IEditorPart; |
|
45 |
import org.eclipse.ui.IWorkbenchPage; |
|
46 |
import org.eclipse.ui.IWorkbenchWindow; |
|
47 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
48 |
import org.txm.concordance.core.functions.Concordance; |
|
49 |
import org.txm.concordance.rcp.editors.ConcordanceEditor; |
|
50 |
import org.txm.concordance.rcp.handlers.BackToTextCommand; |
|
51 |
import org.txm.objects.Text; |
|
52 |
import org.txm.rcp.StatusLine; |
|
53 |
import org.txm.rcp.utils.SWTEditorsUtils; |
|
54 |
import org.txm.searchengine.cqp.AbstractCqiClient; |
|
55 |
import org.txm.searchengine.cqp.CQPEngine; |
|
56 |
import org.txm.searchengine.cqp.corpus.Corpus; |
|
57 |
import org.txm.searchengine.cqp.corpus.Property; |
|
58 |
import org.txm.searchengine.cqp.corpus.StructuralUnit; |
|
59 |
import org.txm.searchengine.cqp.corpus.query.Match; |
|
60 |
import org.txm.synopticedition.rcp.editors.SynopticEditionEditor; |
|
61 |
import org.txm.synopticedition.rcp.editors.EditionPanel.RGBA; |
|
62 |
import org.txm.synopticedition.rcp.messages.SynopticEditionUIMessages; |
|
63 |
import org.txm.utils.logger.Log; |
|
64 |
|
|
65 |
import cern.colt.Arrays; |
|
66 |
|
|
67 |
/** |
|
68 |
* Open a text edition from: a concordance Line |
|
69 |
* @author mdecorde. |
|
70 |
*/ |
|
71 |
public class BackToText extends BackToTextCommand { |
|
72 |
|
|
73 |
/** The Constant ID. */ |
|
74 |
public final static String ID = "org.txm.synopticedition.rcp.handlers.BackToText"; //$NON-NLS-1$ |
|
75 |
public final static RGBA lightred = new RGBA(249,208,208); |
|
76 |
public final static RGBA red = new RGBA(249, 160, 160); |
|
77 |
//TODO: this kind of link associations must be transfered to a TXMEditor class |
|
78 |
private static HashMap<ConcordanceEditor, SynopticEditionEditor> associatedEditors = new HashMap<ConcordanceEditor, SynopticEditionEditor>(); |
|
79 |
private static HashMap<ConcordanceEditor, List<String>> associatedEditorsPreviousOtherWordIDs = new HashMap<ConcordanceEditor, List<String>>(); |
|
80 |
private static HashMap<ConcordanceEditor, List<String>> associatedEditorsPreviousLineids = new HashMap<ConcordanceEditor, List<String>>(); |
|
81 |
|
|
82 |
/* (non-Javadoc) |
|
83 |
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
|
84 |
*/ |
|
85 |
@Override |
|
86 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
87 |
IWorkbenchWindow wb = HandlerUtil.getActiveWorkbenchWindow(event); |
|
88 |
IEditorPart ieditor = wb.getActivePage().getActiveEditor(); |
|
89 |
if (!(ieditor instanceof ConcordanceEditor)) { |
|
90 |
return null; |
|
91 |
} |
|
92 |
ConcordanceEditor concordanceEditor = (ConcordanceEditor)ieditor; |
|
93 |
ISelection sel = wb.getSelectionService().getSelection(); |
|
94 |
if (sel instanceof IStructuredSelection) { |
|
95 |
IStructuredSelection selection = (IStructuredSelection) sel; |
|
96 |
if (selection.getFirstElement() instanceof Match) { |
|
97 |
backToText(concordanceEditor, (Match)(selection.getFirstElement())); |
|
98 |
} else { |
|
99 |
System.out.println(SynopticEditionUIMessages.BackToText_1+selection); |
|
100 |
} |
|
101 |
} else { |
|
102 |
System.out.println(SynopticEditionUIMessages.BackToText_2); |
|
103 |
} |
|
104 |
return null; |
|
105 |
} |
|
106 |
|
|
107 |
/** |
|
108 |
* Open edition. |
|
109 |
* |
|
110 |
* @param corpus the corpus |
|
111 |
* @return the object |
|
112 |
*/ |
|
113 |
@Override |
|
114 |
public boolean backToText(ConcordanceEditor editor, Match match) { |
|
115 |
Concordance conc = editor.getConcordance(); |
|
116 |
Corpus corpus = editor.getCorpus(); |
|
117 |
|
|
118 |
try { |
|
119 |
if (match == null) return false; |
|
120 |
|
|
121 |
StructuralUnit textS = null; |
|
122 |
String textid = ""; //$NON-NLS-1$ |
|
123 |
String baseid = ""; //$NON-NLS-1$ |
|
124 |
|
|
125 |
Property xProperty = corpus.getProperty("x"), yProperty, wProperty, hProperty; |
|
126 |
String x="0",y="0",w="0",h="0"; |
|
127 |
int[] pos = null; |
|
128 |
if (xProperty != null) { |
|
129 |
yProperty = corpus.getProperty("y"); |
|
130 |
if (yProperty != null) { |
|
131 |
wProperty = corpus.getProperty("w"); |
|
132 |
if (wProperty != null) { |
|
133 |
AbstractCqiClient CQI = CQPEngine.getCqiClient(); |
|
134 |
int[] cpos = {match.getStart()}; |
|
135 |
hProperty = corpus.getProperty("h"); |
|
136 |
if (hProperty != null) { |
|
137 |
x = CQI.cpos2Str(xProperty.getQualifiedName(), cpos)[0]; |
|
138 |
y = CQI.cpos2Str(yProperty.getQualifiedName(), cpos)[0]; |
|
139 |
w = CQI.cpos2Str(wProperty.getQualifiedName(), cpos)[0]; |
|
140 |
h = CQI.cpos2Str(hProperty.getQualifiedName(), cpos)[0]; |
|
141 |
|
|
142 |
pos = new int[4]; |
|
143 |
pos[0] = Integer.parseInt(x); |
|
144 |
pos[1] = Integer.parseInt(y); |
|
145 |
pos[2] = Integer.parseInt(w); |
|
146 |
pos[3] = Integer.parseInt(h); |
|
147 |
} |
|
148 |
} |
|
149 |
} |
|
150 |
} |
|
151 |
|
|
152 |
|
|
153 |
String projectid = ""; //$NON-NLS-1$ |
|
154 |
try { |
|
155 |
textS = corpus.getStructuralUnit("text"); //$NON-NLS-1$ |
|
156 |
Property textP = textS.getProperty("id"); //$NON-NLS-1$ |
|
157 |
textid = match.getValueForProperty(textP);// get text via text struct property id |
|
158 |
} catch (Exception e2) { |
|
159 |
System.out.println("The corpus has no text_id property" + e2); //$NON-NLS-1$ |
|
160 |
org.txm.rcp.utils.Logger.printStackTrace(e2); |
|
161 |
return false; |
|
162 |
} |
|
163 |
|
|
164 |
Log.info("Loading line informations..."); //$NON-NLS-1$ |
|
165 |
|
|
166 |
SynopticEditionEditor attachedBrowserEditor = associatedEditors.get(editor); |
|
167 |
if (attachedBrowserEditor!= null && attachedBrowserEditor.isDisposed()) { |
|
168 |
associatedEditorsPreviousOtherWordIDs.put(editor, new ArrayList<String>()); |
|
169 |
associatedEditorsPreviousLineids.put(editor, new ArrayList<String>()); |
|
170 |
} |
|
171 |
List<String> previousOtherWordIDs = associatedEditorsPreviousOtherWordIDs.get(editor); |
|
172 |
List<String> previousLineids = associatedEditorsPreviousLineids.get(editor); |
|
173 |
|
|
174 |
if (attachedBrowserEditor == null || attachedBrowserEditor.isDisposed()) { |
|
175 |
String[] editionsToOpen = OpenEdition.getDefaultEditions(corpus); |
|
176 |
|
|
177 |
if (editionsToOpen.length == 0) { // the defaultEdition parameter is not set |
|
178 |
ArrayList<String> editionNames = corpus.getEditionNames(); |
|
179 |
if (editionNames.size() > 0) { // use the first edition declared |
|
180 |
editionsToOpen = new String[1]; |
|
181 |
editionsToOpen[0] = editionNames.get(0); |
|
182 |
Log.info(SynopticEditionUIMessages.BackToText_0+editionNames.get(0)); |
|
183 |
} else { // no edition in the corpus |
|
184 |
Log.info(SynopticEditionUIMessages.BackToText_4); |
|
185 |
editionsToOpen = new String[0]; |
|
186 |
return false; |
|
187 |
} |
|
188 |
} else { |
|
189 |
Log.info(SynopticEditionUIMessages.BackToText_5+Arrays.toString(editionsToOpen)); |
|
190 |
} |
|
191 |
|
|
192 |
attachedBrowserEditor = OpenEdition.openEdition(corpus, editionsToOpen); |
|
193 |
associatedEditors.put(editor, attachedBrowserEditor); |
|
194 |
SWTEditorsUtils.addEditor(editor, attachedBrowserEditor, EModelService.ABOVE); |
|
195 |
} |
|
196 |
|
|
197 |
// remove previous highlighted words |
|
198 |
if (previousOtherWordIDs != null) { |
|
199 |
//System.out.println("remove previousOtherWordIDs="+previousOtherWordIDs); |
|
200 |
attachedBrowserEditor.removeHighlightWordsById(lightred, previousOtherWordIDs); |
|
201 |
associatedEditorsPreviousOtherWordIDs.remove(editor); // free mem |
|
202 |
} |
|
203 |
if (previousLineids != null) { |
|
204 |
//System.out.println("remove previousLineids="+previousLineids); |
|
205 |
attachedBrowserEditor.removeHighlightWordsById(red, previousLineids); |
|
206 |
associatedEditorsPreviousLineids.remove(editor); // free mem |
|
207 |
} |
|
208 |
|
|
209 |
//System.out.println("getKeywordsId from "+editor.getTopLine()+" to "+editor.getBottomLine() + 1); |
|
210 |
List<String> otherWordIDs = conc.getKeywordsId(textid, editor.getTopLine(), editor.getBottomLine() + 1); |
|
211 |
//System.out.println("getKeywordsId="+otherWordIDs); |
|
212 |
List<String> lineids = null; |
|
213 |
try { |
|
214 |
lineids = match.getValuesForProperty(corpus.getProperty("id")); //$NON-NLS-1$ |
|
215 |
} catch (Exception e1) { |
|
216 |
org.txm.rcp.utils.Logger.printStackTrace(e1); |
|
217 |
return false; |
|
218 |
} |
|
219 |
Log.info(NLS.bind("Project id {0} Corpus (Base) id {1} Text id {2}", //$NON-NLS-1$ |
|
220 |
new Object[]{projectid, baseid, textid})); |
|
221 |
|
|
222 |
otherWordIDs.removeAll(lineids); // remove the pivot from others words |
|
223 |
|
|
224 |
Text text = corpus.getMainCorpus().getText(textid); |
|
225 |
if (text == null) { |
|
226 |
System.out.println(NLS.bind("BackToText: Text {0} is missing", textid)); //$NON-NLS-1$ |
|
227 |
StatusLine.setMessage(NLS.bind("BackToText: Text {0} is missing", textid)); //$NON-NLS-1$ |
|
228 |
Log.severe(NLS.bind("BackToText: Text {0} is missing", textid)); //$NON-NLS-1$ |
|
229 |
return false; |
|
230 |
} |
|
231 |
|
|
232 |
String line_wordid = lineids.get(0); |
|
233 |
if (line_wordid == null) { |
|
234 |
System.out.println(SynopticEditionUIMessages.BackToText_3); |
|
235 |
return false; |
|
236 |
} |
|
237 |
|
|
238 |
|
|
239 |
String focusid = null; |
|
240 |
if (lineids.size() > 0) focusid = lineids.get(0); |
|
241 |
|
|
242 |
//System.out.println("add otherWordIDs="+otherWordIDs); |
|
243 |
attachedBrowserEditor.addHighlightWordsById(lightred, otherWordIDs); |
|
244 |
|
|
245 |
//System.out.println("add linesids="+lineids); |
|
246 |
attachedBrowserEditor.addHighlightWordsById(red, lineids); |
|
247 |
|
|
248 |
associatedEditorsPreviousOtherWordIDs.put(editor, otherWordIDs); |
|
249 |
associatedEditorsPreviousLineids.put(editor, lineids); |
|
250 |
|
|
251 |
HashSet<int[]> posses = new HashSet<int[]>(); |
|
252 |
posses.add(pos); |
|
253 |
attachedBrowserEditor.setHighlightedArea(posses); |
|
254 |
|
|
255 |
attachedBrowserEditor.setFocusedWordID(focusid); |
|
256 |
|
|
257 |
// reload the page and styles |
|
258 |
attachedBrowserEditor.backToText(text, line_wordid);// open the page(S) containing the word with id=line_wordid |
|
259 |
|
|
260 |
IWorkbenchPage attachedPage = attachedBrowserEditor.getEditorSite().getPage(); |
|
261 |
attachedPage.activate(attachedBrowserEditor); |
|
262 |
|
|
263 |
return true; |
|
264 |
|
|
265 |
} catch (Exception err) { |
|
266 |
Log.severe(NLS.bind("Full text display failed: {0}", err)); //$NON-NLS-1$ |
|
267 |
Log.printStackTrace(err); |
|
268 |
} |
|
269 |
return false; |
|
270 |
} |
|
271 |
} |
|
0 | 272 |
tmp/org.txm.synopticeditor.rcp/src/org/txm/synopticedition/rcp/handlers/OpenEdition.java (revision 653) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
4 |
// Sophia Antipolis, University of Paris 3. |
|
5 |
// |
|
6 |
// The TXM platform is free software: you can redistribute it |
|
7 |
// and/or modify it under the terms of the GNU General Public |
|
8 |
// License as published by the Free Software Foundation, |
|
9 |
// either version 2 of the License, or (at your option) any |
|
10 |
// later version. |
|
11 |
// |
|
12 |
// The TXM platform is distributed in the hope that it will be |
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
// PURPOSE. See the GNU General Public License for more |
|
16 |
// details. |
|
17 |
// |
|
18 |
// You should have received a copy of the GNU General |
|
19 |
// Public License along with the TXM platform. If not, see |
|
20 |
// http://www.gnu.org/licenses. |
|
21 |
// |
|
22 |
// |
|
23 |
// |
|
24 |
// $LastChangedDate:$ |
|
25 |
// $LastChangedRevision:$ |
|
26 |
// $LastChangedBy:$ |
|
27 |
// |
|
28 |
package org.txm.synopticedition.rcp.handlers; |
|
29 |
|
|
30 |
import java.util.ArrayList; |
|
31 |
import java.util.List; |
|
32 |
|
|
33 |
import org.eclipse.core.commands.AbstractHandler; |
|
34 |
import org.eclipse.core.commands.ExecutionEvent; |
|
35 |
import org.eclipse.core.commands.ExecutionException; |
|
36 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
37 |
import org.eclipse.jface.window.Window; |
|
38 |
import org.eclipse.swt.widgets.Shell; |
|
39 |
import org.eclipse.ui.IWorkbenchPage; |
|
40 |
import org.eclipse.ui.IWorkbenchWindow; |
|
41 |
import org.eclipse.ui.PlatformUI; |
|
42 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
43 |
import org.txm.objects.BaseParameters; |
|
44 |
import org.txm.objects.Text; |
|
45 |
import org.txm.rcp.RCPMessages; |
|
46 |
import org.txm.searchengine.cqp.corpus.Corpus; |
|
47 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
|
48 |
import org.txm.searchengine.cqp.corpus.Property; |
|
49 |
import org.txm.searchengine.cqp.corpus.StructuralUnit; |
|
50 |
import org.txm.searchengine.cqp.corpus.Subcorpus; |
|
51 |
import org.txm.searchengine.cqp.corpus.query.Match; |
|
52 |
import org.txm.synopticedition.rcp.editors.EditionSelectorDialog; |
|
53 |
import org.txm.synopticedition.rcp.editors.SynopticEditionEditor; |
|
54 |
import org.txm.synopticedition.rcp.editors.SynopticEditorInput; |
|
55 |
import org.txm.synopticedition.rcp.messages.SynopticEditionUIMessages; |
|
56 |
import org.txm.utils.logger.Log; |
|
57 |
import org.w3c.dom.Element; |
|
58 |
import org.w3c.dom.NodeList; |
|
59 |
|
|
60 |
import cern.colt.Arrays; |
|
61 |
// TODO: Auto-generated Javadoc |
|
62 |
/** |
|
63 |
* Open a text edition from: a main corpus : the first text of the maincorpus a |
|
64 |
* sub-corpus : the first text of the subcorpus a partition : the user must |
|
65 |
* choose one of the text used in the partition @ author mdecorde. |
|
66 |
*/ |
|
67 |
public class OpenEdition extends AbstractHandler { |
|
68 |
|
|
69 |
/** The Constant ID. */ |
|
70 |
public final static String ID = "org.txm.synopticedition.rcp.handlers.OpenEdition"; //$NON-NLS-1$ |
|
71 |
|
|
72 |
/** The lastopenedfile. */ |
|
73 |
public static String lastopenedfile; |
|
74 |
|
|
75 |
/* (non-Javadoc) |
|
76 |
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
|
77 |
*/ |
|
78 |
@Override |
|
79 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
80 |
|
|
81 |
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event); |
|
82 |
if (selection.getFirstElement() instanceof Corpus) { |
|
83 |
try { |
|
84 |
Corpus c = (Corpus) selection.getFirstElement(); |
|
85 |
Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell(); |
|
86 |
|
|
87 |
EditionSelectorDialog d = new EditionSelectorDialog(shell, c, null); |
|
88 |
SynopticEditionEditor editor = null; |
|
89 |
// if (c.getEditionNames().size() > 1 && d.open() == Window.OK) { |
|
90 |
// Object[] rez = d.getResult(); |
|
91 |
// String[] rezS = new String[rez.length]; |
|
92 |
// for (int i =0 ; i < rez.length ; i++) rezS[i] = rez[i].toString(); |
|
93 |
// editor = openEdition(c, rezS); |
|
94 |
// } else |
|
95 |
String[] editionsToOpen = getDefaultEditions(c); |
|
96 |
|
|
97 |
if (editionsToOpen.length == 0) { // the defaultEdition parameter is not set |
|
98 |
ArrayList<String> editionNames = c.getEditionNames(); |
|
99 |
if (editionNames.size() > 0) { // use the first edition declared |
|
100 |
editionsToOpen = new String[1]; |
|
101 |
editionsToOpen[0] = editionNames.get(0); |
|
102 |
Log.info(SynopticEditionUIMessages.OpenEdition_0+editionNames.get(0)); |
|
103 |
} else { // no edition in the corpus |
|
104 |
Log.info(SynopticEditionUIMessages.OpenEdition_1); |
|
105 |
editionsToOpen = new String[0]; |
|
106 |
return false; |
|
107 |
} |
|
108 |
} else { |
|
109 |
Log.info(SynopticEditionUIMessages.OpenEdition_3+Arrays.toString(editionsToOpen)); |
|
110 |
} |
|
111 |
|
|
112 |
editor = openEdition(c, editionsToOpen); |
|
113 |
|
|
114 |
if (editor != null) |
|
115 |
editor.firstPage(); |
|
116 |
|
|
117 |
} catch (Exception e) { |
|
118 |
System.out.println(SynopticEditionUIMessages.OpenEdition_4+e); |
|
119 |
org.txm.rcp.utils.Logger.printStackTrace(e); |
|
120 |
} |
|
121 |
} else { |
|
122 |
System.out.println(SynopticEditionUIMessages.OpenEdition_9); |
|
123 |
} |
|
124 |
return null; |
|
125 |
} |
|
126 |
public static String[] getDefaultEditions(Corpus c) { |
|
127 |
BaseParameters params = c.getBase().getBaseParameters(); |
|
128 |
Element editionsElement = params.getEditionsElement(params.getCorpusElement()); |
|
129 |
return editionsElement.getAttribute("default").split(","); //$NON-NLS-1$ //$NON-NLS-2$ |
|
130 |
} |
|
131 |
|
|
132 |
/** |
|
133 |
* Open edition, but don't show a page |
|
134 |
* |
|
135 |
* @param corpus the corpus |
|
136 |
* @return the object |
|
137 |
*/ |
|
138 |
public static SynopticEditionEditor openEdition(Corpus corpus, String[] editions) { |
|
139 |
String textid = null; |
|
140 |
|
|
141 |
System.out.println("Opening edition of "+corpus); //$NON-NLS-1$ |
|
142 |
try { |
|
143 |
Text text = null; |
|
144 |
if (corpus instanceof Subcorpus) { |
|
145 |
Subcorpus sub = (Subcorpus)corpus; |
|
146 |
List<Match> matches = sub.getMatches(); |
|
147 |
if (matches.size() > 0) { |
|
148 |
StructuralUnit text_su = corpus.getStructuralUnit("text"); //$NON-NLS-1$ |
|
149 |
Property text_id = text_su.getProperty("id"); //$NON-NLS-1$ |
|
150 |
|
|
151 |
textid = matches.get(0).getValueForProperty(text_id); |
|
152 |
if (textid != null) text = corpus.getMainCorpus().getText(textid); |
|
153 |
} |
|
154 |
} |
|
155 |
// QueryResult result = corpus.query(new Query("<text> []"), "get_edition", false); //$NON-NLS-1$ //$NON-NLS-2$ |
|
156 |
// StructuralUnit text_su = corpus.getStructuralUnit("text"); //$NON-NLS-1$ |
|
157 |
// Property text_id = text_su.getProperty("id"); //$NON-NLS-1$ |
|
158 |
|
|
159 |
// if (result.getNMatch() > 0) textid = result.getMatches(0, 1).get(0).getValueForProperty(text_id); |
|
160 |
MainCorpus maincorpus = corpus.getMainCorpus(); |
|
161 |
|
|
162 |
// if (textid != null) text = maincorpus.getText(textid); |
|
163 |
|
|
164 |
if (text == null) { |
|
165 |
text = maincorpus.getFirstText(); |
|
166 |
|
|
167 |
if (text == null) { |
|
168 |
System.out.println("** Could not find first text of ID "+textid+SynopticEditionUIMessages.OpenEdition_7); //$NON-NLS-1$ //$NON-NLS-1$ |
|
169 |
return null; |
|
170 |
} |
|
171 |
|
|
172 |
textid = text.getName(); |
|
173 |
} |
|
174 |
|
|
175 |
//String[] editions = {maincorpus.getDefaultEdition()}; |
|
176 |
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
|
177 |
IWorkbenchPage page = window.getActivePage(); |
|
178 |
|
|
179 |
SynopticEditorInput editorInput = new SynopticEditorInput(corpus, text.getName(), editions); |
|
180 |
SynopticEditionEditor editor = (SynopticEditionEditor) page.openEditor(editorInput, |
|
181 |
SynopticEditionEditor.ID, true); |
|
182 |
|
|
183 |
return editor; |
|
184 |
|
|
185 |
} catch (Exception e) { |
|
186 |
Log.printStackTrace(e); |
|
187 |
System.out.println(SynopticEditionUIMessages.OpenEdition_10+e); |
|
188 |
return null; |
|
189 |
} |
|
190 |
} |
|
191 |
} |
|
0 | 192 |
tmp/org.txm.synopticeditor.rcp/src/org/txm/synopticedition/rcp/preferences/SynopticEditionPreferencePage.java (revision 653) | ||
---|---|---|
1 |
package org.txm.synopticedition.rcp.preferences; |
|
2 |
|
|
3 |
import org.eclipse.jface.preference.BooleanFieldEditor; |
|
4 |
import org.eclipse.jface.preference.FieldEditorPreferencePage; |
|
5 |
import org.eclipse.ui.IWorkbench; |
|
6 |
import org.eclipse.ui.IWorkbenchPreferencePage; |
|
7 |
import org.eclipse.ui.preferences.ScopedPreferenceStore; |
|
8 |
import org.txm.rcp.Application; |
|
9 |
|
|
10 |
public class SynopticEditionPreferencePage extends FieldEditorPreferencePage |
|
11 |
implements IWorkbenchPreferencePage { |
|
12 |
ScopedPreferenceStore preferences; |
|
13 |
|
|
14 |
private BooleanFieldEditor slow_highlight; |
|
15 |
|
|
16 |
|
|
17 |
public SynopticEditionPreferencePage() { |
|
18 |
super(); |
|
19 |
preferences = new ScopedPreferenceStore(org.eclipse.core.runtime.preferences.InstanceScope.INSTANCE, |
|
20 |
Application.PLUGIN_ID); |
|
21 |
setPreferenceStore(preferences); |
|
22 |
setTitle("Analec"); |
|
23 |
} |
|
24 |
|
|
25 |
@Override |
|
26 |
public void init(IWorkbench workbench) { } |
|
27 |
|
|
28 |
@Override |
|
29 |
protected void createFieldEditors() { |
|
30 |
slow_highlight = new BooleanFieldEditor(SynopticEditionPreferences.FAST_HIGHLIGHT, |
|
31 |
"Enable fast word highlight", getFieldEditorParent()); |
|
32 |
addField(slow_highlight); |
|
33 |
} |
|
34 |
} |
|
0 | 35 |
tmp/org.txm.synopticeditor.rcp/src/org/txm/synopticedition/rcp/preferences/SynopticEditionPreferences.java (revision 653) | ||
---|---|---|
1 |
package org.txm.synopticedition.rcp.preferences; |
|
2 |
|
|
3 |
import org.eclipse.core.runtime.preferences.DefaultScope; |
|
4 |
import org.osgi.service.prefs.Preferences; |
|
5 |
import org.txm.core.preferences.TXMPreferences; |
|
6 |
|
|
7 |
public class SynopticEditionPreferences extends TXMPreferences { |
|
8 |
|
|
9 |
public static String PREFERENCES_NODE = "org.txm.synopticedition.rcp.synoptic"; |
|
10 |
|
|
11 |
public static String FAST_HIGHLIGHT = "org.txm.synopticedition.rcp.synoptic.slow_highlight"; |
|
12 |
|
|
13 |
@Override |
|
14 |
public void initializeDefaultPreferences() { |
|
15 |
Preferences preferences = DefaultScope.INSTANCE.getNode(PREFERENCES_NODE); |
|
16 |
preferences.putBoolean(FAST_HIGHLIGHT, false); |
|
17 |
} |
|
18 |
} |
|
0 | 19 |
tmp/org.txm.synopticeditor.rcp/src/org/txm/synopticedition/rcp/messages/messages.properties (revision 653) | ||
---|---|---|
1 |
BackToText_0=Opening with first edition (no default edition set): |
|
2 |
BackToText_1=Aborting: selection is not a concordance line: |
|
3 |
BackToText_2=Aborting: error during selection. |
|
4 |
BackToText_3=Error: could not retrieve line word ids. Aborting back to text. |
|
5 |
BackToText_4=No edition to open. |
|
6 |
BackToText_5=Opening default editions: |
|
7 |
EditionPanel_0=No edition found for text= |
|
8 |
EditionPanel_1=Fail to retrieve first page of edition |
|
9 |
EditionPanel_2=\ and text |
|
10 |
EditionPanel_5=\ edition= |
|
11 |
EditionPanel_6=No edition with name |
|
12 |
EditionPanel_7=\ available for text |
|
13 |
EditionSelectorDialog_0=Editions |
|
14 |
EditionSelectorDialog_1=Select one or more editions |
|
15 |
OpenEdition_0=Opening with first edition (no default edition set): |
|
16 |
OpenEdition_1=No edition to open. |
|
17 |
OpenEdition_10=Error while opening editor: |
|
18 |
OpenEdition_2=No edition found |
|
19 |
OpenEdition_3=Opening default editions: |
|
20 |
OpenEdition_4=Error while opening edition: |
|
21 |
OpenEdition_7=\ in the corpus |
|
22 |
OpenEdition_9=Aborting: selection is not a corpus |
|
23 |
SynopticEditionEditor_0=First text of the corpus |
|
24 |
SynopticEditionEditor_1=Previous text |
|
25 |
SynopticEditionEditor_10=Next text |
|
26 |
SynopticEditionEditor_11=Last text of the corpus |
|
27 |
SynopticEditionEditor_2=Editions... |
|
28 |
SynopticEditionEditor_3=First page of the text |
|
29 |
SynopticEditionEditor_4=Previous page |
|
30 |
SynopticEditionEditor_5=No edition found |
|
31 |
SynopticEditionEditor_6=Error while getting available editions: |
|
32 |
SynopticEditionEditor_7=Next page |
|
33 |
SynopticEditionEditor_8=Last page of the text |
|
34 |
SynopticEditionEditor_9=Warning: could not find edition for name: |
|
0 | 35 |
tmp/org.txm.synopticeditor.rcp/src/org/txm/synopticedition/rcp/messages/messages_fr.properties (revision 653) | ||
---|---|---|
1 |
BackToText_0=Ouverture avec la premi?re ?dition (pas de d?faut) : |
|
2 |
BackToText_1=Abandon : la s?lection courante n''est pas une ligne de concordance : |
|
3 |
BackToText_2=Abandon : erreur de s?lection |
|
4 |
BackToText_3=Abandon : erreur pendant la r?cup?ration des identifiants de mot. |
|
5 |
BackToText_4=Pas d'?dition disponible. |
|
6 |
BackToText_5=Ouverture de l'?dition par d?faut : |
|
7 |
EditionPanel_0=Pas d''?dition trouv?e pour le texte : |
|
8 |
EditionPanel_1=?chec de la r?cup?ration de la premi?re page d'?dition |
|
9 |
EditionPanel_2=\ pour le texte |
|
10 |
EditionPanel_5=\ ?dition= |
|
11 |
EditionPanel_6=Pas d''?dition nomm?e |
|
12 |
EditionPanel_7=\ disponible pour le texte |
|
13 |
EditionSelectorDialog_0=?ditions |
|
14 |
EditionSelectorDialog_1=S?lectionner une ou plusieurs ?ditions. |
|
15 |
OpenEdition_0=Ouverture avec la premi?re ?dition (pas de d?faut) : |
|
16 |
OpenEdition_1=Pas d'?dition disponible. |
|
17 |
OpenEdition_10=Erreur lors de l''ouverture de l''?diteur : |
|
18 |
OpenEdition_2=Pas d''?dition trouv?e |
|
19 |
OpenEdition_3=Ouverture de l'?dition par d?faut : |
|
20 |
OpenEdition_4=Erreur lors de l''ouverture de l''?dition : |
|
21 |
OpenEdition_7=\ dans le corpus |
|
22 |
OpenEdition_9=Abandon : la s?lection n''est pas un corpus |
|
23 |
SynopticEditionEditor_0=Premier texte du corpus |
|
24 |
SynopticEditionEditor_1=Texte pr?c?dent |
|
25 |
SynopticEditionEditor_10=Texte suivant |
|
26 |
SynopticEditionEditor_11=Dernier texte du corpus |
|
27 |
SynopticEditionEditor_2=?ditions... |
|
28 |
SynopticEditionEditor_3=Premi?re page du texte |
|
29 |
SynopticEditionEditor_4=Page pr?c?dente |
|
30 |
SynopticEditionEditor_5=Pas d''?dition trouv?e |
|
31 |
SynopticEditionEditor_6=Erreur lors de la r?cup?ration des ?ditions disponibles : |
|
32 |
SynopticEditionEditor_7=Page suivante |
|
33 |
SynopticEditionEditor_8=Derni?re page du texte |
|
34 |
SynopticEditionEditor_9=Attention: ?chec de la r?cup?ration de l''?dition |
|
0 | 35 |
tmp/org.txm.synopticeditor.rcp/src/org/txm/synopticedition/rcp/messages/SynopticEditionUIMessages.java (revision 653) | ||
---|---|---|
1 |
package org.txm.synopticedition.rcp.messages; |
|
2 |
|
|
3 |
import org.eclipse.osgi.util.NLS; |
|
4 |
import org.txm.utils.messages.Utf8NLS; |
|
5 |
|
|
6 |
public class SynopticEditionUIMessages extends NLS { |
|
7 |
|
|
8 |
private static final String BUNDLE_NAME = "org.txm.synopticedition.rcp.messages.messages"; //$NON-NLS-1$ |
|
9 |
|
|
10 |
public static String BackToText_0; |
|
11 |
public static String BackToText_1; |
|
12 |
public static String BackToText_2; |
|
13 |
public static String BackToText_3; |
|
14 |
public static String BackToText_4; |
|
15 |
public static String BackToText_5; |
|
16 |
public static String EditionPanel_0; |
|
17 |
public static String EditionPanel_1; |
|
18 |
public static String EditionPanel_2; |
|
19 |
public static String EditionPanel_5; |
|
20 |
public static String EditionPanel_6; |
|
21 |
public static String EditionPanel_7; |
|
22 |
public static String EditionSelectorDialog_0; |
|
23 |
public static String EditionSelectorDialog_1; |
|
24 |
public static String OpenEdition_0; |
|
25 |
public static String OpenEdition_1; |
|
26 |
public static String OpenEdition_10; |
|
27 |
public static String OpenEdition_2; |
|
28 |
public static String OpenEdition_3; |
|
29 |
public static String OpenEdition_4; |
|
30 |
public static String OpenEdition_7; |
|
31 |
public static String OpenEdition_9; |
|
32 |
public static String SynopticEditionEditor_0; |
|
33 |
public static String SynopticEditionEditor_1; |
|
34 |
public static String SynopticEditionEditor_10; |
|
35 |
public static String SynopticEditionEditor_11; |
|
36 |
public static String SynopticEditionEditor_2; |
|
37 |
public static String SynopticEditionEditor_3; |
|
38 |
public static String SynopticEditionEditor_4; |
|
39 |
public static String SynopticEditionEditor_5; |
|
40 |
public static String SynopticEditionEditor_6; |
|
41 |
public static String SynopticEditionEditor_7; |
|
42 |
public static String SynopticEditionEditor_8; |
|
43 |
public static String SynopticEditionEditor_9; |
|
44 |
|
|
45 |
|
|
46 |
static { |
|
47 |
// initialize resource bundle |
|
48 |
Utf8NLS.initializeMessages(BUNDLE_NAME, SynopticEditionUIMessages.class); |
|
49 |
} |
|
50 |
|
|
51 |
private SynopticEditionUIMessages() { |
|
52 |
} |
|
53 |
} |
|
0 | 54 |
tmp/org.txm.synopticeditor.rcp/src/org/txm/synopticedition/rcp/editors/EditionPanel.java (revision 653) | ||
---|---|---|
1 |
package org.txm.synopticedition.rcp.editors; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.net.URL; |
|
5 |
import java.util.ArrayList; |
|
6 |
import java.util.Arrays; |
|
7 |
import java.util.Collection; |
|
8 |
import java.util.HashMap; |
|
9 |
import java.util.HashSet; |
|
10 |
import java.util.List; |
|
11 |
import java.util.Set; |
|
12 |
import java.util.logging.Level; |
|
13 |
|
|
14 |
import org.eclipse.core.commands.Command; |
|
15 |
import org.eclipse.core.commands.ExecutionException; |
|
16 |
import org.eclipse.core.commands.IParameter; |
|
17 |
import org.eclipse.core.commands.NotEnabledException; |
|
18 |
import org.eclipse.core.commands.NotHandledException; |
|
19 |
import org.eclipse.core.commands.Parameterization; |
|
20 |
import org.eclipse.core.commands.ParameterizedCommand; |
|
21 |
import org.eclipse.core.commands.common.NotDefinedException; |
|
22 |
import org.eclipse.core.runtime.FileLocator; |
|
23 |
import org.eclipse.core.runtime.Platform; |
|
24 |
import org.eclipse.jface.action.MenuManager; |
|
25 |
import org.eclipse.jface.text.ITextSelection; |
|
26 |
import org.eclipse.jface.viewers.ISelection; |
|
27 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
|
28 |
import org.eclipse.jface.viewers.ISelectionProvider; |
|
29 |
import org.eclipse.swt.SWT; |
|
30 |
import org.eclipse.swt.browser.Browser; |
|
31 |
import org.eclipse.swt.browser.BrowserFunction; |
|
32 |
import org.eclipse.swt.browser.ProgressEvent; |
|
33 |
import org.eclipse.swt.browser.ProgressListener; |
|
34 |
import org.eclipse.swt.events.MenuEvent; |
|
35 |
import org.eclipse.swt.events.MenuListener; |
|
36 |
import org.eclipse.swt.events.SelectionEvent; |
|
37 |
import org.eclipse.swt.events.SelectionListener; |
|
38 |
import org.eclipse.swt.widgets.Composite; |
|
39 |
import org.eclipse.swt.widgets.Menu; |
|
40 |
import org.eclipse.swt.widgets.MenuItem; |
|
41 |
import org.eclipse.ui.IWorkbenchWindow; |
|
42 |
import org.eclipse.ui.PlatformUI; |
|
43 |
import org.eclipse.ui.commands.ICommandService; |
|
44 |
import org.eclipse.ui.handlers.IHandlerService; |
|
45 |
import org.eclipse.ui.internal.browser.BrowserViewer; |
|
46 |
import org.osgi.framework.Bundle; |
|
47 |
import org.txm.core.preferences.TXMPreferences; |
|
48 |
import org.txm.objects.Corpus; |
|
49 |
import org.txm.objects.Edition; |
|
50 |
import org.txm.objects.Page; |
|
51 |
import org.txm.objects.Text; |
|
52 |
import org.txm.rcp.StatusLine; |
|
53 |
import org.txm.rcp.utils.IOClipboard; |
|
54 |
import org.txm.synopticedition.rcp.messages.SynopticEditionUIMessages; |
|
55 |
import org.txm.synopticedition.rcp.preferences.SynopticEditionPreferencePage; |
|
56 |
import org.txm.synopticedition.rcp.preferences.SynopticEditionPreferences; |
|
57 |
import org.txm.utils.io.IOUtils; |
|
58 |
import org.txm.utils.logger.Log; |
|
59 |
|
|
60 |
public class EditionPanel extends BrowserViewer implements ISelectionProvider { |
|
61 |
|
|
62 |
public static class RGBA { |
|
63 |
public int r=0, g=0, b=0; |
|
64 |
public float a = 1f; |
|
65 |
public RGBA(int r, int g, int b) { |
|
66 |
this.r =r;this.g=g; this.b =b; |
|
67 |
} |
|
68 |
public RGBA(String rgb) { |
|
69 |
String[] split = rgb.split(","); |
|
70 |
try{this.r =Integer.parseInt(split[0]);}catch(Exception e){} |
|
71 |
try{this.g =Integer.parseInt(split[1]);}catch(Exception e){} |
|
72 |
try{this.b =Integer.parseInt(split[2]);}catch(Exception e){} |
|
73 |
} |
|
74 |
public RGBA(String rgb, float a) { |
|
75 |
String[] split = rgb.split(","); |
|
76 |
try{this.r =Integer.parseInt(split[0]);}catch(Exception e){} |
|
77 |
try{this.g =Integer.parseInt(split[1]);}catch(Exception e){} |
|
78 |
try{this.b =Integer.parseInt(split[2]);}catch(Exception e){} |
|
79 |
this.a = a; |
|
80 |
} |
|
81 |
public RGBA(int r, int g, int b, float a) { |
|
82 |
this.r =r;this.g=g; this.b =b;this.a =a; |
|
83 |
} |
|
84 |
|
|
85 |
public String toString() {return "{"+r+", "+g+","+b+", "+a+"}";} |
|
86 |
} |
|
87 |
|
|
88 |
private ProgressListener progresslistener; |
|
89 |
// private List<String> wordids; |
|
90 |
// private List<String> lineids; |
|
91 |
/** The edition. */ |
|
92 |
Text currentText; |
|
93 |
Edition currentEdition; |
|
94 |
Page currentPage; |
|
95 |
protected SynopticEditionEditor synopticEditionEditor; |
|
96 |
private ISelectionProvider selProvider; |
|
97 |
private MenuManager menuManager; |
|
98 |
|
|
99 |
private HashSet<int[]> highlightedAreas = null; |
|
100 |
|
|
101 |
//HashMap<String, ArrayList<RGBA>> highlightedColorSpans = new HashMap<String, ArrayList<RGBA>>(); // background color |
|
102 |
|
|
103 |
HashMap<String, ArrayList<RGBA>> highlightedColorPerWordIDS = new HashMap<String, ArrayList<RGBA>>(); // background color |
|
104 |
public static final String STYLE_NORMAL = "normal"; |
|
105 |
public static final String STYLE_ITALIC = "italic"; |
|
106 |
public static final String STYLE_OBLIQUE = "oblique"; |
|
107 |
HashMap<String, String> fontStylePerWordIDS = new HashMap<String, String>(); |
|
108 |
public static final String WEIGHT_NORMAL = "normal"; |
|
109 |
public static final String WEIGHT_BOLD = "bold"; |
|
110 |
HashMap<String, String> fontWeightPerWordIDS = new HashMap<String, String>(); |
|
111 |
HashMap<String, ArrayList<RGBA>> fontColorPerWordIDS = new HashMap<String, ArrayList<RGBA>>(); |
|
112 |
public static final String SIZE_SMALL = "small"; |
|
113 |
public static final String SIZE_MEDIUM = "medium"; |
|
114 |
public static final String SIZE_LARGE = "larger"; |
|
115 |
public static final String SIZE_SMALLER = "smaller"; |
|
116 |
public static final String SIZE_LARGER = "larger"; |
|
117 |
HashMap<String, String> fontSizePerWordIDS = new HashMap<String, String>(); |
|
118 |
public static final String FAMILLY_TIMES = "\"Times New Roman\", Times"; |
|
119 |
public static final String FAMILLY_ARIAL = "Arial"; |
|
120 |
public static final String FAMILLY_COURIER = "\"Courier New\", Courier"; |
|
121 |
HashMap<String, String> fontFamillyPerWordIDS = new HashMap<String, String>(); |
|
122 |
public static final String VARIANT_NORMAL = "normal"; |
|
123 |
public static final String VARIANT_SMALLCAPS = "small-caps"; |
|
124 |
HashMap<String, String> fontVariantPerWordIDS = new HashMap<String, String>(); |
|
125 |
String focusedWordID = null; |
|
126 |
|
|
127 |
public static final String highlightscript = "try { var elt = document.getElementById(\"%s\");" + //$NON-NLS-1$ //$NON-NLS-2$ |
|
128 |
"elt.style.backgroundColor=\"rgb(%s,%s,%s)\";" + //$NON-NLS-1$ |
|
129 |
//"elt.style.paddingLeft=\"3px\";" + //$NON-NLS-1$ |
|
130 |
//"elt.style.paddingRight=\"3px\";" + //$NON-NLS-1$ |
|
131 |
//"elt.style.paddingTop=\"1px\";" + //$NON-NLS-1$ |
|
132 |
//"elt.style.paddingBottom=\"1px\";" + //$NON-NLS-1$ |
|
133 |
"} catch (e) { };"; //$NON-NLS-1$ |
|
134 |
public static final String highlightscriptRuleFast = "sheet.insertRule(\"#%s {background-color:rgba(%s,%s,%s,%s);}\", 0);"; |
|
135 |
public static final String colorscriptRuleFast = "sheet.insertRule(\"#%s {color:rgba(%s,%s,%s,%s);}\", 0);"; |
|
136 |
public static final String sizescriptRuleFast = "sheet.insertRule(\"#%s {font-size:%s;}\", 0);"; |
|
137 |
public static final String stylescriptRuleFast = "sheet.insertRule(\"#%s {font-style:%s;}\", 0);"; |
|
138 |
public static final String variantscriptRuleFast = "sheet.insertRule(\"#%s {font-variant:%s;}\", 0);"; |
|
139 |
public static final String famillyscriptRuleFast = "sheet.insertRule(\"#%s {font-familly:%s;}\", 0);"; |
|
140 |
public static final String weightscriptRuleFast = "sheet.insertRule(\"#%s {font-weight:%s;}\", 0);"; |
|
141 |
|
|
142 |
public static final String highlightscriptRule = "sheet.insertRule(\"span[id=\\\"%s\\\"] {background-color:rgba(%s,%s,%s,%s); }\", 0);"; |
|
143 |
|
|
144 |
public static final String clearhighlightscript = "try { var elt = document.getElementById(\"%s\"); elt.style.backgroundColor=\"white\";elt.style.fontWeight=\"\";" + //$NON-NLS-1$ |
|
145 |
"} catch (e) { };"; //$NON-NLS-1$ |
|
146 |
|
|
147 |
public String functions = |
|
148 |
""//"alert(\"loading functions\");" |
|
149 |
+"\nfunction getNodeText(node) {" |
|
150 |
+"\n if (typeof node == 'string') return node;" |
|
151 |
+"\n else if (typeof node.innerText != 'undefined') return node.innerText;" |
|
152 |
+"\n else if (typeof node.InnerText != 'undefined') return node.InnerText;" |
|
153 |
+"\n else if (typeof node.textContent != 'undefined') return node.textContent;" |
|
154 |
+"\n else return null;" |
|
155 |
+"\n}" |
|
156 |
+"\nfunction txmGetParent(node) {" |
|
157 |
+"\n if (typeof node.parentNode != 'undefined') return node.parentNode;" |
|
158 |
+"\n else return null;" |
|
159 |
+"\n}" |
|
160 |
+"\nfunction txmGetChildren(node) {" |
|
161 |
+"\n if (typeof node == 'string') return 'STRING HTML';" |
|
162 |
+"\n else if (typeof node.children != 'undefined') return node.children;" |
|
163 |
+"\n else if (typeof node.ChildNodes != 'undefined') return node.ChildNodes;" |
|
164 |
+"\n else if (typeof node.childNodes != 'undefined') return node.childNodes;" |
|
165 |
+"\n else return null;" |
|
166 |
+"\n}" |
|
167 |
+"\nfunction txmGetSelection() {" |
|
168 |
+"\n if (typeof window.getSelection != 'undefined') {return window.getSelection();}" |
|
169 |
+"\n else if (typeof document.selection != 'undefined') { return document.selection;}" |
|
170 |
+"\n else return 'NO SELECTION';" |
|
171 |
+"\n}" |
|
172 |
+"\nfunction txmGetRangeSize(selection) {" |
|
173 |
+"\n if (typeof selection.rangeCount != 'undefined') {return selection.rangeCount;}" |
|
174 |
+"\n else if (typeof selection.createRangeCollection != 'undefined') { return selection.createRangeCollection().length();} // IE5 has no multiple selection" |
|
175 |
+"\n}" |
|
176 |
+"\nfunction txmGetRange(selection, i) {" |
|
177 |
+"\n if (typeof selection.getRangeAt != 'undefined') {return selection.getRangeAt(i);}" |
|
178 |
+"\n else if (typeof selection.createRangeCollection != 'undefined') {return selection.createRangeCollection().item(i);}" // IE > IE5 |
|
179 |
+"\n else if (typeof selection.createRange != 'undefined') { return selection.createRange();} // IE5 has no multiple selection" |
|
180 |
+"\n else return 'NO RANGE';" |
|
181 |
+"\n}" |
|
182 |
+"\nfunction txmGetParentElementRange(range) {" |
|
183 |
+"\n if (typeof range.parentElement != 'undefined') {return range.parentElement();}" |
|
184 |
+"\n else if (typeof range.startContainer != 'undefined') { return range.startContainer.parentNode;}" |
|
185 |
+"\n else return 'NO PARENT';" |
|
186 |
+"\n}" |
|
187 |
+"\nfunction txmGetFragment(range) {" |
|
188 |
+"\n if (typeof range.cloneContents != 'undefined') { return range.cloneContents();}" |
|
189 |
+"\n else if (typeof range.htmlText != 'undefined') {var node = document.createElement('sel'); node.innerHTML = range.htmlText; return node;" |
|
190 |
+"\n } else return 'NO FRAG';" |
|
191 |
+"\n}" |
|
192 |
+"\nfunction txmGetTagName(node) {" |
|
193 |
+"\n if (typeof node.tagName != 'undefined') {return node.tagName;}" |
|
194 |
+"\n else if (typeof node.nodeName != 'undefined') { return node.nodeName;}" |
|
195 |
+"\n else if (typeof node.name != 'undefined') { return node.name;}" |
|
196 |
+"\n else return 'NO TAGNAME';" |
|
197 |
+"\n}" |
|
198 |
+"\nfunction findSpans(children, all) {" |
|
199 |
+"\n for (var i = 0 ; i < children.length ; i++) {" |
|
200 |
+"\n var node = children.item(i);" |
|
201 |
+"\n if (node.nodeType == 1) {" |
|
202 |
+"\n var id = node.getAttribute('id');" |
|
203 |
+"\n if (node.tagName == 'SPAN' && id != null && id.indexOf('w_') == 0 && getNodeText(node).length > 0) {" |
|
204 |
+"\n if (id != null) all.push(id);" |
|
205 |
+"\n } else {" |
|
206 |
+"\n findSpans(txmGetChildren(node), all)" |
|
207 |
+"\n }" |
|
208 |
+"\n }" |
|
209 |
+"\n }" |
|
210 |
+"\n}" |
|
211 |
+"\nfunction findIdsInString(str, all) {" |
|
212 |
+"\n for (var i = 0 ; i < children.length ; i++) {" |
|
213 |
+"\n var node = children.item(i);" |
|
214 |
+"\n if (node.nodeType == 1) {" |
|
215 |
+"\n var id = node.getAttribute('id');" |
|
216 |
+"\n if (node.tagName == 'SPAN' && id != null && id.indexOf('w_') == 0 && getNodeText(node).length > 0) {" |
|
217 |
+"\n if (id != null) all.push(id);" |
|
218 |
+"\n } else {" |
|
219 |
+"\n findSpans(txmGetChildren(node), all)" |
|
220 |
+"\n }" |
|
221 |
+"\n }" |
|
222 |
+"\n }" |
|
223 |
+"\n}" |
|
224 |
+"\nfunction get_type(thing){if(thing===null)return \"[object Null]\"; return Object.prototype.toString.call(thing);}\n" |
|
225 |
+"\nfunction getDetailedObject(inputObject) { var detailedObject = {}; var properties; \n do { properties = Object.getOwnPropertyNames( inputObject ); for (var o in properties) {detailedObject[properties[o]] = inputObject[properties[o]];}} while ( inputObject = Object.getPrototypeOf(inputObject) );return detailedObject;}\n" |
|
226 |
+"\nvar sheet = null;" |
|
227 |
+"\ntry{" |
|
228 |
+"\n var style = document.createElement(\"style\");" |
|
229 |
+"\n style.appendChild(document.createTextNode(\"\"));"//webkit hack |
|
230 |
+"\n document.head.appendChild(style);" |
|
231 |
+"\n sheet = style.sheet;" |
|
232 |
+"\n} catch(e) {sheet='error'}" |
|
233 |
+"\ntry{" |
|
234 |
+"\n" // define scrollIntoViewIfNeeded if absent |
|
235 |
+"\nif (!Element.prototype.scrollIntoViewIfNeeded) {" |
|
236 |
+"\n Element.prototype.scrollIntoViewIfNeeded = function (centerIfNeeded) {" |
|
237 |
+"\n centerIfNeeded = arguments.length === 0 ? true : !!centerIfNeeded;" |
|
238 |
+"\n var parent = this.parentNode," |
|
239 |
+"\n parentComputedStyle = window.getComputedStyle(parent, null)," |
|
240 |
+"\n parentBorderTopWidth = parseInt(parentComputedStyle.getPropertyValue('border-top-width'))," |
|
241 |
+"\n parentBorderLeftWidth = parseInt(parentComputedStyle.getPropertyValue('border-left-width'))," |
|
242 |
+"\n overTop = this.offsetTop - parent.offsetTop < parent.scrollTop," |
|
243 |
+"\n overBottom = (this.offsetTop - parent.offsetTop + this.clientHeight - parentBorderTopWidth) > (parent.scrollTop + parent.clientHeight)," |
|
244 |
+"\n overLeft = this.offsetLeft - parent.offsetLeft < parent.scrollLeft," |
|
245 |
+"\n overRight = (this.offsetLeft - parent.offsetLeft + this.clientWidth - parentBorderLeftWidth) > (parent.scrollLeft + parent.clientWidth)," |
|
246 |
+"\n alignWithTop = overTop && !overBottom;" |
|
247 |
+"\n if ((overTop || overBottom) && centerIfNeeded) {" |
|
248 |
+"\n parent.scrollTop = this.offsetTop - parent.offsetTop - parent.clientHeight / 2 - parentBorderTopWidth + this.clientHeight / 2;" |
|
249 |
+"\n }" |
|
250 |
+"\n if ((overLeft || overRight) && centerIfNeeded) {" |
|
251 |
+"\n parent.scrollLeft = this.offsetLeft - parent.offsetLeft - parent.clientWidth / 2 - parentBorderLeftWidth + this.clientWidth / 2;" |
|
252 |
+"\n }" |
|
253 |
+"\n if ((overTop || overBottom || overLeft || overRight) && !centerIfNeeded) {" |
|
254 |
+"\n this.scrollIntoView(alignWithTop);" |
|
255 |
+"\n }" |
|
256 |
+"\n };" |
|
257 |
+"\n}" |
|
258 |
+"\n} catch(e) {Element.prototype.scrollIntoViewIfNeeded = Element.prototype.scrollIntoView}"; |
|
259 |
protected boolean fastWordHighLight = TXMPreferences.getBoolean(SynopticEditionPreferences.FAST_HIGHLIGHT, SynopticEditionPreferences.PREFERENCES_NODE); |
|
260 |
|
|
261 |
public Object evaluate(String code) { |
|
262 |
if (Log.getLevel().intValue() <= Level.FINEST.intValue()) System.out.println(code); |
|
263 |
return getBrowser().evaluate(code); |
|
264 |
} |
|
265 |
public Object execute(String code) { |
|
266 |
if (Log.getLevel().intValue() <= Level.FINEST.intValue()) System.out.println(code); |
|
267 |
return getBrowser().execute(code); |
|
268 |
} |
|
269 |
public EditionPanel(SynopticEditionEditor synopticEditionEditor, Composite parent, int style, Edition edition) { |
|
270 |
super(parent, style); |
|
271 |
this.synopticEditionEditor = synopticEditionEditor; |
|
272 |
this.currentEdition = edition; |
|
273 |
this.currentText = currentEdition.getText(); |
|
274 |
|
|
275 |
File functionsFile = null; |
|
276 |
try { |
|
277 |
|
|
278 |
Bundle bundle = Platform.getBundle("SynopticEditorRCP"); |
|
279 |
URL fileURL = bundle.getEntry("res/js/functions.js"); |
|
280 |
URL r = FileLocator.resolve(fileURL); |
|
281 |
Log.info("Load JS functions from: "+r); |
|
282 |
functions = IOUtils.getText(r, "UTF-8"); |
|
283 |
|
|
284 |
} catch (Exception e) { |
|
285 |
System.out.println("Error while reading "+functionsFile+": "+e.getLocalizedMessage()); |
|
286 |
Log.printStackTrace(e); |
|
287 |
} |
|
288 |
|
|
289 |
progresslistener = new ProgressListener() { |
|
290 |
|
|
291 |
@Override |
|
292 |
public void changed(ProgressEvent event) { } |
|
293 |
|
|
294 |
@Override |
|
295 |
public void completed(ProgressEvent event) { |
|
296 |
// System.out.println("EditionPanel "+currentEdition.getName()+" reload "+getCurrentPage().getName()); |
|
297 |
Object rez = evaluate("return typeof sheet"); |
|
298 |
if ("undefined".equals(rez)) execute(functions); // build the sheet if not present in the HTML DOM |
|
299 |
|
|
300 |
//System.out.println("highlight: "+highlightedColorPerWordIDS); |
|
301 |
StringBuilder buffer = new StringBuilder(); |
|
302 |
//buffer.append("alert(\"\"+sheet);\n"); |
|
303 |
if (!fastWordHighLight) { |
|
304 |
// for (String wordid : highlightedColorPerWordIDS.keySet()) { |
|
305 |
// buffer.append(String.format(clearhighlightscript, wordid)+"\n"); |
|
306 |
// } |
|
307 |
} else { |
|
308 |
buffer.append("try { while(sheet.cssRules.length > 0) sheet.deleteRule(0); } catch (e) {};\n"); // empty style |
|
309 |
} |
|
310 |
|
|
311 |
if (buffer.length() > 0) execute(buffer.toString()); |
|
312 |
buffer = new StringBuilder(); |
|
313 |
|
|
314 |
String firstWord = currentPage.getWordId(); |
|
315 |
Page nextPage = currentEdition.getNextPage(currentPage); |
|
316 |
String lastWord = "w_999999999"; |
|
317 |
if (nextPage != null && currentPage != nextPage) lastWord = nextPage.getWordId(); |
|
318 |
//System.out.println("firstWord="+firstWord+" lastWord="+lastWord); |
|
319 |
//int n = 0; |
|
320 |
//long start = System.currentTimeMillis(); |
|
321 |
//System.out.println(highlightedColorPerWordIDS); |
|
322 |
for (String wordid : highlightedColorPerWordIDS.keySet()) { |
|
323 |
if (highlightedColorPerWordIDS.get(wordid).size() == 0) continue; // error |
|
324 |
|
|
325 |
//if (!slowWordHighLight) { //TODO: this code must be replaced with word position instead of word id comparaison |
|
326 |
if (Edition.isFirstGTthanSecond(wordid, firstWord) < 0) continue; // skip the word to highlight |
|
327 |
if (Edition.isFirstGTthanSecond(lastWord, wordid) < 0) continue; // skip the word to highlight |
|
328 |
//} |
|
329 |
//n++; |
|
330 |
RGBA composite = new RGBA(0,0,0,0f); |
|
331 |
int size = highlightedColorPerWordIDS.get(wordid).size(); |
|
332 |
|
|
333 |
for (RGBA color : highlightedColorPerWordIDS.get(wordid)) { |
|
334 |
composite.r += color.r; |
|
335 |
composite.g += color.g; |
|
336 |
composite.b += color.b; |
|
337 |
composite.a += color.a; |
|
338 |
} |
|
339 |
|
|
340 |
composite.r /= size; |
|
341 |
composite.g /= size; |
|
342 |
composite.b /= size; |
|
343 |
|
|
344 |
String s = null; |
|
345 |
if (!fastWordHighLight) { |
|
346 |
//s = String.format(highlightscriptRule, wordid, composite.r, composite.g, composite.b, composite.a); |
|
347 |
s = "try { document.getElementById(\"" + wordid + "\").style.backgroundColor=\"rgba("+composite.r+","+composite.g+","+composite.b+","+composite.a+")\";" //$NON-NLS-1$ |
|
348 |
+ |
|
349 |
// "elt.style.paddingLeft=\"3px\";" + //$NON-NLS-1$ |
|
350 |
// "elt.style.paddingRight=\"3px\";" + //$NON-NLS-1$ |
|
351 |
// "elt.style.paddingTop=\"1px\";" + //$NON-NLS-1$ |
|
352 |
// "elt.style.paddingBottom=\"1px\";" + //$NON-NLS-1$ |
|
353 |
"} catch (e) { };"; //$NON-NLS-1$ |
|
354 |
} else { |
|
355 |
//TODO: replace this line with the next one for TXM 0.7.9 |
|
356 |
s = String.format(highlightscriptRuleFast, wordid.replace(" ", "\\ "), composite.r, composite.g, composite.b, composite.a); |
|
357 |
// s = String.format(highlightscriptRuleFast, wordid, composite.r, composite.g, composite.b, composite.a); |
|
358 |
} |
|
359 |
|
|
360 |
buffer.append(s+"\n"); |
|
361 |
} |
|
362 |
|
|
363 |
if (buffer.length() > 0) execute(buffer.toString()); |
|
364 |
buffer = new StringBuilder(); |
|
365 |
|
|
366 |
// for (String wordidslist : highlightedColorSpans.keySet()) { |
|
367 |
// RGBA composite = new RGBA(0,0,0,0f); |
|
368 |
// int size = highlightedColorSpans.get(wordidslist).size(); |
|
369 |
// |
|
370 |
// for (RGBA color : highlightedColorSpans.get(wordidslist)) { |
|
371 |
// composite.r += color.r; |
|
372 |
// composite.g += color.g; |
|
373 |
// composite.b += color.b; |
|
374 |
// composite.a += color.a; |
|
375 |
// } |
|
376 |
// |
|
377 |
// composite.r /= size; |
|
378 |
// composite.g /= size; |
|
379 |
// composite.b /= size; |
|
380 |
// |
|
381 |
// String cmd = "var l = "+wordidslist+";\n"; |
|
382 |
// cmd += "wrap(l, \""+wordidslist+"\";\n"; |
|
383 |
// buffer.append(cmd+"\n"); |
|
384 |
// } |
|
385 |
|
|
386 |
for (String wordid : fontColorPerWordIDS.keySet()) { |
|
387 |
RGBA composite = new RGBA(0,0,0,0f); |
|
388 |
int size = fontColorPerWordIDS.get(wordid).size(); |
|
389 |
|
|
390 |
for (RGBA color : fontColorPerWordIDS.get(wordid)) { |
|
391 |
composite.r += color.r; |
|
392 |
composite.g += color.g; |
|
393 |
composite.b += color.b; |
|
394 |
composite.a += color.a; |
|
395 |
} |
|
396 |
|
|
397 |
composite.r /= size; |
|
398 |
composite.g /= size; |
|
399 |
composite.b /= size; |
|
400 |
|
|
401 |
String s = String.format(colorscriptRuleFast, wordid, composite.r, composite.g, composite.b, composite.a); |
|
402 |
buffer.append(s+"\n"); |
|
403 |
} |
|
404 |
|
|
405 |
if (buffer.length() > 0) execute(buffer.toString()); |
|
406 |
buffer = new StringBuilder(); |
|
407 |
|
|
408 |
for (String wordid : fontSizePerWordIDS.keySet()) { |
|
409 |
String s = String.format(sizescriptRuleFast, wordid, fontSizePerWordIDS.get(wordid)); |
|
410 |
buffer.append(s+"\n"); |
|
411 |
} |
|
412 |
|
|
413 |
for (String wordid : fontWeightPerWordIDS.keySet()) { |
|
414 |
String s = null; |
|
415 |
if (!fastWordHighLight) { |
|
416 |
//s = String.format(highlightscriptRule, wordid, composite.r, composite.g, composite.b, composite.a); |
|
417 |
s = "try { document.getElementById(\"" + wordid + "\").style.fontWeight=\""+fontWeightPerWordIDS.get(wordid)+"\";" //$NON-NLS-1$ |
|
418 |
+ |
|
419 |
// "elt.style.paddingLeft=\"3px\";" + //$NON-NLS-1$ |
|
420 |
// "elt.style.paddingRight=\"3px\";" + //$NON-NLS-1$ |
|
421 |
// "elt.style.paddingTop=\"1px\";" + //$NON-NLS-1$ |
|
422 |
// "elt.style.paddingBottom=\"1px\";" + //$NON-NLS-1$ |
|
423 |
"} catch (e) { };"; //$NON-NLS-1$ |
|
424 |
//s = String.format(highlightscriptRule, wordid, composite.r, composite.g, composite.b, composite.a); |
|
425 |
// s = "try { var elt = document.getElementById(\"" + wordid + "\");" + //$NON-NLS-1$ //$NON-NLS-2$ |
|
426 |
// "elt.style.fontWeight=\""+fontWeightPerWordIDS.get(wordid)+"\";" + //$NON-NLS-1$ |
|
427 |
//// "elt.style.paddingLeft=\"3px\";" + //$NON-NLS-1$ |
|
428 |
//// "elt.style.paddingRight=\"3px\";" + //$NON-NLS-1$ |
|
429 |
//// "elt.style.paddingTop=\"1px\";" + //$NON-NLS-1$ |
|
430 |
//// "elt.style.paddingBottom=\"1px\";" + //$NON-NLS-1$ |
|
431 |
// "} catch (e) { };"; //$NON-NLS-1$ |
|
432 |
} else { |
|
433 |
s = String.format(weightscriptRuleFast, wordid, fontWeightPerWordIDS.get(wordid)); |
|
434 |
} |
|
435 |
buffer.append(s+"\n"); |
|
436 |
} |
|
437 |
|
|
438 |
for (String wordid : fontFamillyPerWordIDS.keySet()) { |
|
439 |
String s = String.format(famillyscriptRuleFast, wordid, fontFamillyPerWordIDS.get(wordid)); |
|
440 |
buffer.append(s+"\n"); |
|
441 |
} |
|
442 |
|
|
443 |
if (buffer.length() > 0) execute(buffer.toString()); |
|
444 |
buffer = new StringBuilder(); |
|
445 |
|
|
446 |
if (focusedWordID != null) { |
|
447 |
//System.out.println("Focus on: "+focusedWordID); |
|
448 |
String s = "try { showElementIfNeeded(document.getElementById(\"" + focusedWordID + "\")); } catch (e) {document.getElementById(\"" + focusedWordID + "\").scrollIntoView();};"; //$NON-NLS-1$ //$NON-NLS-2$ |
|
449 |
buffer.append(s+"\n"); |
|
450 |
focusedWordID = null; // focus one time |
|
451 |
} |
|
452 |
|
|
453 |
if (buffer.length() > 0) execute(buffer.toString()); |
|
454 |
buffer = new StringBuilder(); |
|
455 |
|
|
456 |
if (highlightedAreas != null) { |
|
457 |
for (int[] pos : highlightedAreas ) { |
|
458 |
if (pos == null || pos.length != 4) continue; |
|
459 |
String s = "try {v.setFocusOn("+pos[0]+", "+pos[1]+", "+pos[2]+", "+pos[3]+");} catch (e) { };"; //$NON-NLS-1$ |
|
460 |
buffer.append(s+"\n"); |
|
461 |
break;// one word only for now |
|
462 |
} |
|
463 |
} |
|
464 |
|
|
465 |
//System.out.println(buffer); |
|
466 |
if (buffer.length() > 0) execute(buffer.toString()); |
|
467 |
//System.out.println("n="+n+" time="+(System.currentTimeMillis()-start)); |
|
468 |
} |
|
469 |
}; |
|
470 |
getBrowser().addProgressListener(progresslistener); |
|
471 |
new CommandLink (getBrowser()); |
|
472 |
} |
|
473 |
|
|
474 |
/** |
|
475 |
* Bypass BrowserViewer restriction on the getBrowser method |
|
476 |
*/ |
|
477 |
public Browser getBrowser() { |
|
478 |
return super.getBrowser(); |
|
479 |
} |
|
480 |
|
|
481 |
/** |
|
482 |
* Bypass BrowserViewer restriction on the getBrowser method |
|
483 |
*/ |
|
484 |
public String getDOM() { |
|
485 |
return "";//execute("return document.innerHTML"; |
|
486 |
} |
|
487 |
|
|
488 |
public ISelectionProvider getSelectionProvider() { |
|
489 |
return selProvider; |
|
490 |
} |
|
491 |
|
|
492 |
public void setHighlightWordsById(RGBA color, HashSet<String> wordids) { |
|
493 |
for (String wordid : wordids) { |
|
494 |
if (this.highlightedColorPerWordIDS.get(wordid) != null) { |
|
495 |
removeHighlightWordsById(color, wordid); |
|
496 |
} |
|
497 |
ArrayList<RGBA> hs = new ArrayList<RGBA>(); |
|
498 |
this.highlightedColorPerWordIDS.put(wordid, hs); |
|
499 |
hs.add(color); |
|
500 |
} |
|
501 |
} |
|
502 |
|
|
503 |
public void addHighlightWordsById(RGBA color, String wordid) { |
|
504 |
if (!this.highlightedColorPerWordIDS.containsKey(wordid)) { |
|
505 |
this.highlightedColorPerWordIDS.put(wordid, new ArrayList<RGBA>()); |
|
506 |
} |
|
507 |
this.highlightedColorPerWordIDS.get(wordid).add(color); |
|
508 |
} |
|
509 |
|
|
510 |
/** |
|
511 |
* Can be called to refresh the page word styles but only when the page is loaded |
|
512 |
*/ |
|
513 |
public void updateWordStyles() { |
|
514 |
progresslistener.completed(null); |
|
515 |
} |
|
516 |
|
|
517 |
public void addHighlightWordsById(RGBA color, Collection<String> wordids) { |
|
518 |
for (String wordid : wordids) { |
|
519 |
addHighlightWordsById(color, wordid); |
|
520 |
} |
|
521 |
} |
|
522 |
|
|
523 |
public void removeHighlightWordsById(RGBA color, Collection<String> wordids) { |
|
524 |
//System.out.println("Call removeHighlightWordsById: "+wordids+" color="+color); |
|
525 |
StringBuffer buffer = new StringBuffer(); |
|
526 |
for (String wordid : wordids) { |
|
527 |
removeHighlightWordsById(color, wordid); |
|
528 |
if (!fastWordHighLight) { |
|
529 |
buffer.append(String.format(clearhighlightscript, wordid)+"\n"); |
|
530 |
} |
|
531 |
} |
|
532 |
|
|
533 |
if (buffer.length() > 0) execute(buffer.toString()); |
|
534 |
} |
|
535 |
|
|
536 |
public void removeHighlightWordsById(RGBA color, String wordid) { |
|
537 |
if (highlightedColorPerWordIDS.get(wordid) == null) return; // nothing to do |
|
538 |
|
|
539 |
//System.out.println("remove color="+color+" from id="+wordid); |
|
540 |
this.highlightedColorPerWordIDS.get(wordid).remove(color); |
|
541 |
|
|
542 |
if (this.highlightedColorPerWordIDS.get(wordid).size() == 0) { |
|
543 |
this.highlightedColorPerWordIDS.remove(wordid); |
|
544 |
} |
|
545 |
} |
|
546 |
|
|
547 |
/** |
|
548 |
* Open the page containing the word with ID=$line_wordid |
|
549 |
* @param line_wordid |
|
550 |
* @return true if the page changed |
|
551 |
*/ |
|
552 |
public boolean backToText(Text text, String line_wordid) { |
|
553 |
|
|
554 |
String name = currentEdition.getName(); |
|
555 |
Edition edition = text.getEdition(name); |
|
556 |
|
|
557 |
if (edition == null) { |
|
558 |
String s = SynopticEditionUIMessages.EditionPanel_0+text+SynopticEditionUIMessages.EditionPanel_5+name; |
|
559 |
System.out.println(s); |
|
560 |
StatusLine.setMessage(s); |
|
561 |
Log.severe(s); |
|
562 |
} else { |
|
563 |
Page openedPage = edition.getPageForWordId(line_wordid); |
|
564 |
if (openedPage != null && openedPage != currentPage) { |
|
565 |
this.showPage(openedPage); |
|
566 |
return true; |
|
567 |
} |
|
568 |
} |
|
569 |
updateWordStyles(); // update styles if any new one |
|
570 |
return false; |
|
571 |
} |
|
572 |
|
|
573 |
/** |
|
574 |
* First page. |
|
575 |
*/ |
|
576 |
public void firstPage() { |
|
577 |
// System.out.println(Messages.TxmBrowser_1+currentPage); |
|
578 |
currentPage = currentEdition.getFirstPage(); |
|
579 |
currentText = currentEdition.getText(); |
|
580 |
if (currentPage == null) { |
|
581 |
System.out.println(SynopticEditionUIMessages.EditionPanel_1+currentEdition.getName()+SynopticEditionUIMessages.EditionPanel_2+currentText.getName()); |
|
582 |
} |
|
583 |
|
|
584 |
this.setURL(currentPage.toURL()); |
|
585 |
|
|
586 |
//page_label.setText(makePageLabel()); |
|
587 |
} |
|
588 |
|
|
589 |
public void setURL(String url) { |
|
590 |
super.setURL(url); |
|
591 |
} |
|
592 |
|
|
593 |
/** |
|
594 |
* Last page. |
|
595 |
*/ |
|
596 |
public void lastPage() { |
|
597 |
// System.out.println(Messages.TxmBrowser_2+currentPage); |
|
598 |
|
|
599 |
if (currentPage != null && currentPage.getFile().equals(currentEdition.getLastPage())) |
|
600 |
return; |
|
601 |
currentPage = currentEdition.getLastPage(); |
|
602 |
currentText = currentEdition.getText(); |
|
603 |
this.setURL(currentPage.toURL()); |
|
604 |
} |
|
605 |
|
|
606 |
/** |
|
607 |
* Previous page. |
|
608 |
*/ |
|
609 |
public void previousPage() { |
|
610 |
// System.out.println(Messages.TxmBrowser_3+currentPage); |
|
611 |
if (currentPage != null) { |
|
612 |
Page previous = currentEdition.getPreviousPage(currentPage); |
|
613 |
|
|
614 |
if (previous == currentPage) { |
|
615 |
previousText(true); |
|
616 |
} else { |
|
617 |
currentPage = previous; |
|
618 |
this.setURL(currentPage.toURL()); |
|
619 |
} |
|
620 |
currentText = currentEdition.getText(); |
|
621 |
} else |
|
622 |
firstPage(); |
|
623 |
//page_label.setText(makePageLabel()); |
|
624 |
} |
|
625 |
|
|
626 |
|
|
627 |
|
|
628 |
/** |
|
629 |
* Next page. |
|
630 |
*/ |
|
631 |
public void nextPage() { |
|
632 |
// System.out.println(Messages.TxmBrowser_4+currentPage); |
|
633 |
if (currentPage != null) { |
|
634 |
Page next = currentEdition.getNextPage(currentPage); |
|
635 |
if (next == currentPage) { |
|
636 |
nextText(); |
|
637 |
} else { |
|
638 |
currentPage = next; |
|
639 |
this.setURL(currentPage.toURL()); |
|
640 |
} |
|
641 |
currentText = currentEdition.getText(); |
|
642 |
} else |
|
643 |
firstPage(); |
|
644 |
//page_label.setText(makePageLabel()); |
|
645 |
} |
|
646 |
|
|
647 |
|
|
648 |
public void firstText() { |
|
649 |
//Text current = this.currentPage.getEdition().getText(); |
|
650 |
Corpus corpus = currentText.getCorpus(); |
|
651 |
Text firstText = corpus.getFirstText(); |
|
652 |
|
|
653 |
if (firstText != null) { |
|
654 |
String editionName = currentEdition.getName(); |
|
655 |
Edition tmp = firstText.getEdition(editionName); |
|
656 |
if (tmp == null) { |
|
657 |
System.out.println(SynopticEditionUIMessages.EditionPanel_6+editionName+SynopticEditionUIMessages.EditionPanel_7+firstText.getName()); |
|
658 |
return; |
|
659 |
} |
|
660 |
currentEdition = tmp; |
|
661 |
currentPage = currentEdition.getFirstPage(); |
|
662 |
currentText = firstText; |
|
663 |
if (currentPage == null) { |
|
664 |
StatusLine.setMessage("No previous text"); //$NON-NLS-1$ |
|
665 |
return; |
|
666 |
} |
|
667 |
this.setURL(currentPage.toURL()); |
|
668 |
} |
|
669 |
} |
|
670 |
|
|
671 |
/** |
|
672 |
* Next text. |
|
673 |
*/ |
|
674 |
public void lastText() { |
|
675 |
//Text current = this.currentPage.getEdition().getText(); |
|
676 |
Corpus b = currentText.getCorpus(); |
|
677 |
Text lastText = b.getLastText(); |
|
678 |
|
|
679 |
if (lastText != null) { |
|
680 |
String editionName = currentEdition.getName(); |
|
681 |
Edition tmp = lastText.getEdition(editionName); |
|
682 |
if (tmp == null) { |
|
683 |
System.out.println(SynopticEditionUIMessages.EditionPanel_6+editionName+SynopticEditionUIMessages.EditionPanel_7+lastText.getName()); |
|
684 |
return; |
|
685 |
} |
|
686 |
|
|
687 |
currentEdition = tmp; |
|
688 |
currentPage = currentEdition.getFirstPage(); |
|
689 |
currentText = lastText; |
|
690 |
if (currentPage == null) { |
|
691 |
StatusLine.setMessage("No text next"); //$NON-NLS-1$ |
|
692 |
return; |
|
693 |
} |
|
694 |
|
|
695 |
this.setURL(currentPage.toURL()); |
|
696 |
//page_label.setText(makePageLabel()); |
|
697 |
} |
|
698 |
// System.out.println("Next texts "+nextText); |
|
699 |
} |
|
700 |
|
|
701 |
/** |
|
702 |
* Previous text. |
|
703 |
* @param fromNextText if true it means the user was reading the next text and then we show the last page of the previous text |
|
704 |
*/ |
|
705 |
public void previousText(boolean fromNextText) { |
|
706 |
|
|
707 |
//Text current = this.currentPage.getEdition().getText(); |
|
708 |
Corpus corpus = currentText.getCorpus(); |
|
709 |
Text previousText = corpus.getPreviousText(currentText); |
|
710 |
|
|
711 |
if (previousText != null) { |
|
712 |
String editionName = currentEdition.getName(); |
|
713 |
|
|
714 |
Edition tmp = previousText.getEdition(editionName); |
|
715 |
if (tmp == null) { |
|
716 |
System.out.println(SynopticEditionUIMessages.EditionPanel_6+editionName+SynopticEditionUIMessages.EditionPanel_7+previousText.getName()); |
|
717 |
} |
|
718 |
currentEdition = tmp; |
|
719 |
currentText = previousText; |
|
720 |
if (fromNextText) { |
|
721 |
currentPage = currentEdition.getLastPage(); |
|
722 |
} else { |
|
723 |
currentPage = currentEdition.getFirstPage(); |
|
724 |
} |
|
725 |
|
|
726 |
if (currentPage == null) { |
|
727 |
StatusLine.setMessage("No previous text"); //$NON-NLS-1$ |
|
728 |
return; |
|
729 |
} |
|
730 |
this.setURL(currentPage.toURL()); |
|
731 |
} |
|
732 |
// System.out.println("Previous texts "+previousText); |
|
733 |
} |
|
734 |
|
|
735 |
/** |
|
736 |
* Next text. |
|
737 |
*/ |
|
738 |
public void nextText() { |
|
739 |
//Text current = this.currentPage.getEdition().getText(); |
|
740 |
Corpus b = currentText.getCorpus(); |
|
741 |
Text nextText = b.getNextText(currentText); |
|
742 |
|
|
743 |
if (nextText != null) { |
|
744 |
String editionName = currentEdition.getName(); |
|
745 |
Edition tmp = nextText.getEdition(editionName); |
|
746 |
if (tmp == null) { |
|
747 |
System.out.println(SynopticEditionUIMessages.EditionPanel_6+editionName+SynopticEditionUIMessages.EditionPanel_7+nextText.getName()); |
|
748 |
return; |
|
749 |
} |
|
750 |
currentEdition = tmp; |
|
751 |
|
|
752 |
currentPage = currentEdition.getFirstPage(); |
|
753 |
currentText = nextText; |
|
754 |
if (currentPage == null) { |
|
755 |
StatusLine.setMessage("No text next"); //$NON-NLS-1$ |
|
756 |
return; |
|
757 |
} |
|
758 |
|
|
759 |
this.setURL(currentPage.toURL()); |
|
760 |
//page_label.setText(makePageLabel()); |
|
761 |
} |
|
762 |
// System.out.println("Next texts "+nextText); |
|
763 |
} |
|
764 |
|
|
765 |
|
|
766 |
public void setText(Text text, boolean refresh) { |
|
767 |
String editionName = currentEdition.getName(); |
|
768 |
Edition tmp = text.getEdition(editionName); |
|
769 |
if (tmp == null) { |
Formats disponibles : Unified diff