23 |
23 |
import org.eclipse.swt.browser.ProgressListener;
|
24 |
24 |
import org.eclipse.swt.events.MenuEvent;
|
25 |
25 |
import org.eclipse.swt.events.MenuListener;
|
|
26 |
import org.eclipse.swt.events.MouseEvent;
|
|
27 |
import org.eclipse.swt.events.MouseListener;
|
26 |
28 |
import org.eclipse.swt.events.SelectionEvent;
|
27 |
29 |
import org.eclipse.swt.events.SelectionListener;
|
28 |
30 |
import org.eclipse.swt.widgets.Composite;
|
... | ... | |
42 |
44 |
import org.txm.utils.logger.Log;
|
43 |
45 |
|
44 |
46 |
public class EditionPanel extends BrowserViewer implements ISelectionProvider {
|
45 |
|
|
46 |
|
|
|
47 |
|
|
48 |
|
47 |
49 |
private ProgressListener progresslistener;
|
48 |
50 |
// private List<String> wordids;
|
49 |
51 |
// private List<String> lineids;
|
... | ... | |
54 |
56 |
protected SynopticEditionEditor synopticEditionEditor;
|
55 |
57 |
private ISelectionProvider selProvider;
|
56 |
58 |
private MenuManager menuManager;
|
57 |
|
|
|
59 |
|
58 |
60 |
private HashSet<int[]> highlightedAreas = null;
|
59 |
|
|
|
61 |
|
60 |
62 |
//HashMap<String, ArrayList<RGBA>> highlightedColorSpans = new HashMap<String, ArrayList<RGBA>>(); // background color
|
61 |
|
|
|
63 |
|
62 |
64 |
HashMap<String, ArrayList<RGBA>> highlightedColorPerWordIDS = new HashMap<String, ArrayList<RGBA>>(); // background color
|
63 |
65 |
public static final String STYLE_NORMAL = "normal"; //$NON-NLS-1$
|
64 |
66 |
public static final String STYLE_ITALIC = "italic"; //$NON-NLS-1$
|
... | ... | |
82 |
84 |
public static final String VARIANT_SMALLCAPS = "small-caps"; //$NON-NLS-1$
|
83 |
85 |
HashMap<String, String> fontVariantPerWordIDS = new HashMap<String, String>();
|
84 |
86 |
String focusedWordID = null;
|
85 |
|
|
|
87 |
|
86 |
88 |
public static final String highlightscript = "try { var elt = document.getElementById(\"%s\");" + //$NON-NLS-1$ //$NON-NLS-2$
|
87 |
89 |
"elt.style.backgroundColor=\"rgb(%s,%s,%s)\";" + //$NON-NLS-1$
|
88 |
90 |
//"elt.style.paddingLeft=\"3px\";" + //$NON-NLS-1$
|
... | ... | |
97 |
99 |
public static final String variantscriptRuleFast = "sheet.insertRule(\"#%s {font-variant:%s;}\", 0);"; //$NON-NLS-1$
|
98 |
100 |
public static final String famillyscriptRuleFast = "sheet.insertRule(\"#%s {font-familly:%s;}\", 0);"; //$NON-NLS-1$
|
99 |
101 |
public static final String weightscriptRuleFast = "sheet.insertRule(\"#%s {font-weight:%s;}\", 0);"; //$NON-NLS-1$
|
100 |
|
|
|
102 |
|
101 |
103 |
public static final String highlightscriptRule = "sheet.insertRule(\"span[id=\\\"%s\\\"] {background-color:rgba(%s,%s,%s,%s); }\", 0);"; //$NON-NLS-1$
|
102 |
|
|
|
104 |
|
103 |
105 |
public static final String clearhighlightscript = "try { var elt = document.getElementById(\"%s\"); elt.style.backgroundColor=\"white\";elt.style.fontWeight=\"\";" + //$NON-NLS-1$
|
104 |
106 |
"} catch (e) { };"; //$NON-NLS-1$
|
105 |
|
|
|
107 |
|
106 |
108 |
public String functions =
|
107 |
109 |
""//"alert(\"loading functions\");" //$NON-NLS-1$
|
108 |
|
+"\nfunction getNodeText(node) {" //$NON-NLS-1$
|
109 |
|
+"\n if (typeof node == 'string') return node;" //$NON-NLS-1$
|
110 |
|
+"\n else if (typeof node.innerText != 'undefined') return node.innerText;" //$NON-NLS-1$
|
111 |
|
+"\n else if (typeof node.InnerText != 'undefined') return node.InnerText;" //$NON-NLS-1$
|
112 |
|
+"\n else if (typeof node.textContent != 'undefined') return node.textContent;" //$NON-NLS-1$
|
113 |
|
+"\n else return null;" //$NON-NLS-1$
|
114 |
|
+"\n}" //$NON-NLS-1$
|
115 |
|
+"\nfunction txmGetParent(node) {" //$NON-NLS-1$
|
116 |
|
+"\n if (typeof node.parentNode != 'undefined') return node.parentNode;" //$NON-NLS-1$
|
117 |
|
+"\n else return null;" //$NON-NLS-1$
|
118 |
|
+"\n}" //$NON-NLS-1$
|
119 |
|
+"\nfunction txmGetChildren(node) {" //$NON-NLS-1$
|
120 |
|
+"\n if (typeof node == 'string') return 'STRING HTML';" //$NON-NLS-1$
|
121 |
|
+"\n else if (typeof node.children != 'undefined') return node.children;" //$NON-NLS-1$
|
122 |
|
+"\n else if (typeof node.ChildNodes != 'undefined') return node.ChildNodes;" //$NON-NLS-1$
|
123 |
|
+"\n else if (typeof node.childNodes != 'undefined') return node.childNodes;" //$NON-NLS-1$
|
124 |
|
+"\n else return null;" //$NON-NLS-1$
|
125 |
|
+"\n}" //$NON-NLS-1$
|
126 |
|
+"\nfunction txmGetSelection() {" //$NON-NLS-1$
|
127 |
|
+"\n if (typeof window.getSelection != 'undefined') {return window.getSelection();}" //$NON-NLS-1$
|
128 |
|
+"\n else if (typeof document.selection != 'undefined') { return document.selection;}" //$NON-NLS-1$
|
129 |
|
+"\n else return 'NO SELECTION';" //$NON-NLS-1$
|
130 |
|
+"\n}" //$NON-NLS-1$
|
131 |
|
+"\nfunction txmGetRangeSize(selection) {" //$NON-NLS-1$
|
132 |
|
+"\n if (typeof selection.rangeCount != 'undefined') {return selection.rangeCount;}" //$NON-NLS-1$
|
133 |
|
+"\n else if (typeof selection.createRangeCollection != 'undefined') { return selection.createRangeCollection().length();} // IE5 has no multiple selection" //$NON-NLS-1$
|
134 |
|
+"\n}" //$NON-NLS-1$
|
135 |
|
+"\nfunction txmGetRange(selection, i) {" //$NON-NLS-1$
|
136 |
|
+"\n if (typeof selection.getRangeAt != 'undefined') {return selection.getRangeAt(i);}" //$NON-NLS-1$
|
137 |
|
+"\n else if (typeof selection.createRangeCollection != 'undefined') {return selection.createRangeCollection().item(i);}" // IE > IE5 //$NON-NLS-1$
|
138 |
|
+"\n else if (typeof selection.createRange != 'undefined') { return selection.createRange();} // IE5 has no multiple selection" //$NON-NLS-1$
|
139 |
|
+"\n else return 'NO RANGE';" //$NON-NLS-1$
|
140 |
|
+"\n}" //$NON-NLS-1$
|
141 |
|
+"\nfunction txmGetParentElementRange(range) {" //$NON-NLS-1$
|
142 |
|
+"\n if (typeof range.parentElement != 'undefined') {return range.parentElement();}" //$NON-NLS-1$
|
143 |
|
+"\n else if (typeof range.startContainer != 'undefined') { return range.startContainer.parentNode;}" //$NON-NLS-1$
|
144 |
|
+"\n else return 'NO PARENT';" //$NON-NLS-1$
|
145 |
|
+"\n}" //$NON-NLS-1$
|
146 |
|
+"\nfunction txmGetFragment(range) {" //$NON-NLS-1$
|
147 |
|
+"\n if (typeof range.cloneContents != 'undefined') { return range.cloneContents();}" //$NON-NLS-1$
|
148 |
|
+"\n else if (typeof range.htmlText != 'undefined') {var node = document.createElement('sel'); node.innerHTML = range.htmlText; return node;" //$NON-NLS-1$
|
149 |
|
+"\n } else return 'NO FRAG';" //$NON-NLS-1$
|
150 |
|
+"\n}" //$NON-NLS-1$
|
151 |
|
+"\nfunction txmGetTagName(node) {" //$NON-NLS-1$
|
152 |
|
+"\n if (typeof node.tagName != 'undefined') {return node.tagName;}" //$NON-NLS-1$
|
153 |
|
+"\n else if (typeof node.nodeName != 'undefined') { return node.nodeName;}" //$NON-NLS-1$
|
154 |
|
+"\n else if (typeof node.name != 'undefined') { return node.name;}" //$NON-NLS-1$
|
155 |
|
+"\n else return 'NO TAGNAME';" //$NON-NLS-1$
|
156 |
|
+"\n}" //$NON-NLS-1$
|
157 |
|
+"\nfunction findSpans(children, all) {" //$NON-NLS-1$
|
158 |
|
+"\n for (var i = 0 ; i < children.length ; i++) {" //$NON-NLS-1$
|
159 |
|
+"\n var node = children.item(i);" //$NON-NLS-1$
|
160 |
|
+"\n if (node.nodeType == 1) {" //$NON-NLS-1$
|
161 |
|
+"\n var id = node.getAttribute('id');" //$NON-NLS-1$
|
162 |
|
+"\n if (node.tagName == 'SPAN' && id != null && id.indexOf('w_') == 0 && getNodeText(node).length > 0) {" //$NON-NLS-1$
|
163 |
|
+"\n if (id != null) all.push(id);" //$NON-NLS-1$
|
164 |
|
+"\n } else {" //$NON-NLS-1$
|
165 |
|
+"\n findSpans(txmGetChildren(node), all)" //$NON-NLS-1$
|
166 |
|
+"\n }" //$NON-NLS-1$
|
167 |
|
+"\n }" //$NON-NLS-1$
|
168 |
|
+"\n }" //$NON-NLS-1$
|
169 |
|
+"\n}" //$NON-NLS-1$
|
170 |
|
+"\nfunction findIdsInString(str, all) {" //$NON-NLS-1$
|
171 |
|
+"\n for (var i = 0 ; i < children.length ; i++) {" //$NON-NLS-1$
|
172 |
|
+"\n var node = children.item(i);" //$NON-NLS-1$
|
173 |
|
+"\n if (node.nodeType == 1) {" //$NON-NLS-1$
|
174 |
|
+"\n var id = node.getAttribute('id');" //$NON-NLS-1$
|
175 |
|
+"\n if (node.tagName == 'SPAN' && id != null && id.indexOf('w_') == 0 && getNodeText(node).length > 0) {" //$NON-NLS-1$
|
176 |
|
+"\n if (id != null) all.push(id);" //$NON-NLS-1$
|
177 |
|
+"\n } else {" //$NON-NLS-1$
|
178 |
|
+"\n findSpans(txmGetChildren(node), all)" //$NON-NLS-1$
|
179 |
|
+"\n }" //$NON-NLS-1$
|
180 |
|
+"\n }" //$NON-NLS-1$
|
181 |
|
+"\n }" //$NON-NLS-1$
|
182 |
|
+"\n}" //$NON-NLS-1$
|
183 |
|
+"\nfunction get_type(thing){if(thing===null)return \"[object Null]\"; return Object.prototype.toString.call(thing);}\n" //$NON-NLS-1$
|
184 |
|
+"\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" //$NON-NLS-1$
|
185 |
|
+"\nvar sheet = null;" //$NON-NLS-1$
|
186 |
|
+"\ntry{" //$NON-NLS-1$
|
187 |
|
+"\n var style = document.createElement(\"style\");" //$NON-NLS-1$
|
188 |
|
+"\n try { style.appendChild(document.createTextNode(\"\")); } catch (e) {};"//webkit hack //$NON-NLS-1$
|
189 |
|
+"\n document.body.appendChild(style);" //$NON-NLS-1$
|
190 |
|
+"\n sheet = style.sheet;" //$NON-NLS-1$
|
191 |
|
+"\n} catch(e) {sheet='error'}" //$NON-NLS-1$
|
192 |
|
+"\ntry{" //$NON-NLS-1$
|
193 |
|
+"\n" // define scrollIntoViewIfNeeded if absent //$NON-NLS-1$
|
194 |
|
+"\nif (!Element.prototype.scrollIntoViewIfNeeded) {" //$NON-NLS-1$
|
195 |
|
+"\n Element.prototype.scrollIntoViewIfNeeded = function (centerIfNeeded) {" //$NON-NLS-1$
|
196 |
|
+"\n centerIfNeeded = arguments.length === 0 ? true : !!centerIfNeeded;" //$NON-NLS-1$
|
197 |
|
+"\n var parent = this.parentNode," //$NON-NLS-1$
|
198 |
|
+"\n parentComputedStyle = window.getComputedStyle(parent, null)," //$NON-NLS-1$
|
199 |
|
+"\n parentBorderTopWidth = parseInt(parentComputedStyle.getPropertyValue('border-top-width'))," //$NON-NLS-1$
|
200 |
|
+"\n parentBorderLeftWidth = parseInt(parentComputedStyle.getPropertyValue('border-left-width'))," //$NON-NLS-1$
|
201 |
|
+"\n overTop = this.offsetTop - parent.offsetTop < parent.scrollTop," //$NON-NLS-1$
|
202 |
|
+"\n overBottom = (this.offsetTop - parent.offsetTop + this.clientHeight - parentBorderTopWidth) > (parent.scrollTop + parent.clientHeight)," //$NON-NLS-1$
|
203 |
|
+"\n overLeft = this.offsetLeft - parent.offsetLeft < parent.scrollLeft," //$NON-NLS-1$
|
204 |
|
+"\n overRight = (this.offsetLeft - parent.offsetLeft + this.clientWidth - parentBorderLeftWidth) > (parent.scrollLeft + parent.clientWidth)," //$NON-NLS-1$
|
205 |
|
+"\n alignWithTop = overTop && !overBottom;" //$NON-NLS-1$
|
206 |
|
+"\n if ((overTop || overBottom) && centerIfNeeded) {" //$NON-NLS-1$
|
207 |
|
+"\n parent.scrollTop = this.offsetTop - parent.offsetTop - parent.clientHeight / 2 - parentBorderTopWidth + this.clientHeight / 2;" //$NON-NLS-1$
|
208 |
|
+"\n }" //$NON-NLS-1$
|
209 |
|
+"\n if ((overLeft || overRight) && centerIfNeeded) {" //$NON-NLS-1$
|
210 |
|
+"\n parent.scrollLeft = this.offsetLeft - parent.offsetLeft - parent.clientWidth / 2 - parentBorderLeftWidth + this.clientWidth / 2;" //$NON-NLS-1$
|
211 |
|
+"\n }" //$NON-NLS-1$
|
212 |
|
+"\n if ((overTop || overBottom || overLeft || overRight) && !centerIfNeeded) {" //$NON-NLS-1$
|
213 |
|
+"\n this.scrollIntoView(alignWithTop);" //$NON-NLS-1$
|
214 |
|
+"\n }" //$NON-NLS-1$
|
215 |
|
+"\n };" //$NON-NLS-1$
|
216 |
|
+"\n}" //$NON-NLS-1$
|
217 |
|
+"\n} catch(e) {Element.prototype.scrollIntoViewIfNeeded = Element.prototype.scrollIntoView}"; //$NON-NLS-1$
|
|
110 |
+"\nfunction getNodeText(node) {" //$NON-NLS-1$
|
|
111 |
+"\n if (typeof node == 'string') return node;" //$NON-NLS-1$
|
|
112 |
+"\n else if (typeof node.innerText != 'undefined') return node.innerText;" //$NON-NLS-1$
|
|
113 |
+"\n else if (typeof node.InnerText != 'undefined') return node.InnerText;" //$NON-NLS-1$
|
|
114 |
+"\n else if (typeof node.textContent != 'undefined') return node.textContent;" //$NON-NLS-1$
|
|
115 |
+"\n else return null;" //$NON-NLS-1$
|
|
116 |
+"\n}" //$NON-NLS-1$
|
|
117 |
+"\nfunction txmGetParent(node) {" //$NON-NLS-1$
|
|
118 |
+"\n if (typeof node.parentNode != 'undefined') return node.parentNode;" //$NON-NLS-1$
|
|
119 |
+"\n else return null;" //$NON-NLS-1$
|
|
120 |
+"\n}" //$NON-NLS-1$
|
|
121 |
+"\nfunction txmGetChildren(node) {" //$NON-NLS-1$
|
|
122 |
+"\n if (typeof node == 'string') return 'STRING HTML';" //$NON-NLS-1$
|
|
123 |
+"\n else if (typeof node.children != 'undefined') return node.children;" //$NON-NLS-1$
|
|
124 |
+"\n else if (typeof node.ChildNodes != 'undefined') return node.ChildNodes;" //$NON-NLS-1$
|
|
125 |
+"\n else if (typeof node.childNodes != 'undefined') return node.childNodes;" //$NON-NLS-1$
|
|
126 |
+"\n else return null;" //$NON-NLS-1$
|
|
127 |
+"\n}" //$NON-NLS-1$
|
|
128 |
+"\nfunction txmGetSelection() {" //$NON-NLS-1$
|
|
129 |
+"\n if (typeof window.getSelection != 'undefined') {return window.getSelection();}" //$NON-NLS-1$
|
|
130 |
+"\n else if (typeof document.selection != 'undefined') { return document.selection;}" //$NON-NLS-1$
|
|
131 |
+"\n else return 'NO SELECTION';" //$NON-NLS-1$
|
|
132 |
+"\n}" //$NON-NLS-1$
|
|
133 |
+"\nfunction txmGetRangeSize(selection) {" //$NON-NLS-1$
|
|
134 |
+"\n if (typeof selection.rangeCount != 'undefined') {return selection.rangeCount;}" //$NON-NLS-1$
|
|
135 |
+"\n else if (typeof selection.createRangeCollection != 'undefined') { return selection.createRangeCollection().length();} // IE5 has no multiple selection" //$NON-NLS-1$
|
|
136 |
+"\n}" //$NON-NLS-1$
|
|
137 |
+"\nfunction txmGetRange(selection, i) {" //$NON-NLS-1$
|
|
138 |
+"\n if (typeof selection.getRangeAt != 'undefined') {return selection.getRangeAt(i);}" //$NON-NLS-1$
|
|
139 |
+"\n else if (typeof selection.createRangeCollection != 'undefined') {return selection.createRangeCollection().item(i);}" // IE > IE5 //$NON-NLS-1$
|
|
140 |
+"\n else if (typeof selection.createRange != 'undefined') { return selection.createRange();} // IE5 has no multiple selection" //$NON-NLS-1$
|
|
141 |
+"\n else return 'NO RANGE';" //$NON-NLS-1$
|
|
142 |
+"\n}" //$NON-NLS-1$
|
|
143 |
+"\nfunction txmGetParentElementRange(range) {" //$NON-NLS-1$
|
|
144 |
+"\n if (typeof range.parentElement != 'undefined') {return range.parentElement();}" //$NON-NLS-1$
|
|
145 |
+"\n else if (typeof range.startContainer != 'undefined') { return range.startContainer.parentNode;}" //$NON-NLS-1$
|
|
146 |
+"\n else return 'NO PARENT';" //$NON-NLS-1$
|
|
147 |
+"\n}" //$NON-NLS-1$
|
|
148 |
+"\nfunction txmGetFragment(range) {" //$NON-NLS-1$
|
|
149 |
+"\n if (typeof range.cloneContents != 'undefined') { return range.cloneContents();}" //$NON-NLS-1$
|
|
150 |
+"\n else if (typeof range.htmlText != 'undefined') {var node = document.createElement('sel'); node.innerHTML = range.htmlText; return node;" //$NON-NLS-1$
|
|
151 |
+"\n } else return 'NO FRAG';" //$NON-NLS-1$
|
|
152 |
+"\n}" //$NON-NLS-1$
|
|
153 |
+"\nfunction txmGetTagName(node) {" //$NON-NLS-1$
|
|
154 |
+"\n if (typeof node.tagName != 'undefined') {return node.tagName;}" //$NON-NLS-1$
|
|
155 |
+"\n else if (typeof node.nodeName != 'undefined') { return node.nodeName;}" //$NON-NLS-1$
|
|
156 |
+"\n else if (typeof node.name != 'undefined') { return node.name;}" //$NON-NLS-1$
|
|
157 |
+"\n else return 'NO TAGNAME';" //$NON-NLS-1$
|
|
158 |
+"\n}" //$NON-NLS-1$
|
|
159 |
+"\nfunction findSpans(children, all) {" //$NON-NLS-1$
|
|
160 |
+"\n for (var i = 0 ; i < children.length ; i++) {" //$NON-NLS-1$
|
|
161 |
+"\n var node = children.item(i);" //$NON-NLS-1$
|
|
162 |
+"\n if (node.nodeType == 1) {" //$NON-NLS-1$
|
|
163 |
+"\n var id = node.getAttribute('id');" //$NON-NLS-1$
|
|
164 |
+"\n if (node.tagName == 'SPAN' && id != null && id.indexOf('w_') == 0 && getNodeText(node).length > 0) {" //$NON-NLS-1$
|
|
165 |
+"\n if (id != null) all.push(id);" //$NON-NLS-1$
|
|
166 |
+"\n } else {" //$NON-NLS-1$
|
|
167 |
+"\n findSpans(txmGetChildren(node), all)" //$NON-NLS-1$
|
|
168 |
+"\n }" //$NON-NLS-1$
|
|
169 |
+"\n }" //$NON-NLS-1$
|
|
170 |
+"\n }" //$NON-NLS-1$
|
|
171 |
+"\n}" //$NON-NLS-1$
|
|
172 |
+"\nfunction findIdsInString(str, all) {" //$NON-NLS-1$
|
|
173 |
+"\n for (var i = 0 ; i < children.length ; i++) {" //$NON-NLS-1$
|
|
174 |
+"\n var node = children.item(i);" //$NON-NLS-1$
|
|
175 |
+"\n if (node.nodeType == 1) {" //$NON-NLS-1$
|
|
176 |
+"\n var id = node.getAttribute('id');" //$NON-NLS-1$
|
|
177 |
+"\n if (node.tagName == 'SPAN' && id != null && id.indexOf('w_') == 0 && getNodeText(node).length > 0) {" //$NON-NLS-1$
|
|
178 |
+"\n if (id != null) all.push(id);" //$NON-NLS-1$
|
|
179 |
+"\n } else {" //$NON-NLS-1$
|
|
180 |
+"\n findSpans(txmGetChildren(node), all)" //$NON-NLS-1$
|
|
181 |
+"\n }" //$NON-NLS-1$
|
|
182 |
+"\n }" //$NON-NLS-1$
|
|
183 |
+"\n }" //$NON-NLS-1$
|
|
184 |
+"\n}" //$NON-NLS-1$
|
|
185 |
+"\nfunction get_type(thing){if(thing===null)return \"[object Null]\"; return Object.prototype.toString.call(thing);}\n" //$NON-NLS-1$
|
|
186 |
+"\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" //$NON-NLS-1$
|
|
187 |
+"\nvar sheet = null;" //$NON-NLS-1$
|
|
188 |
+"\ntry{" //$NON-NLS-1$
|
|
189 |
+"\n var style = document.createElement(\"style\");" //$NON-NLS-1$
|
|
190 |
+"\n try { style.appendChild(document.createTextNode(\"\")); } catch (e) {};"//webkit hack //$NON-NLS-1$
|
|
191 |
+"\n document.body.appendChild(style);" //$NON-NLS-1$
|
|
192 |
+"\n sheet = style.sheet;" //$NON-NLS-1$
|
|
193 |
+"\n} catch(e) {sheet='error'}" //$NON-NLS-1$
|
|
194 |
+"\ntry{" //$NON-NLS-1$
|
|
195 |
+"\n" // define scrollIntoViewIfNeeded if absent //$NON-NLS-1$
|
|
196 |
+"\nif (!Element.prototype.scrollIntoViewIfNeeded) {" //$NON-NLS-1$
|
|
197 |
+"\n Element.prototype.scrollIntoViewIfNeeded = function (centerIfNeeded) {" //$NON-NLS-1$
|
|
198 |
+"\n centerIfNeeded = arguments.length === 0 ? true : !!centerIfNeeded;" //$NON-NLS-1$
|
|
199 |
+"\n var parent = this.parentNode," //$NON-NLS-1$
|
|
200 |
+"\n parentComputedStyle = window.getComputedStyle(parent, null)," //$NON-NLS-1$
|
|
201 |
+"\n parentBorderTopWidth = parseInt(parentComputedStyle.getPropertyValue('border-top-width'))," //$NON-NLS-1$
|
|
202 |
+"\n parentBorderLeftWidth = parseInt(parentComputedStyle.getPropertyValue('border-left-width'))," //$NON-NLS-1$
|
|
203 |
+"\n overTop = this.offsetTop - parent.offsetTop < parent.scrollTop," //$NON-NLS-1$
|
|
204 |
+"\n overBottom = (this.offsetTop - parent.offsetTop + this.clientHeight - parentBorderTopWidth) > (parent.scrollTop + parent.clientHeight)," //$NON-NLS-1$
|
|
205 |
+"\n overLeft = this.offsetLeft - parent.offsetLeft < parent.scrollLeft," //$NON-NLS-1$
|
|
206 |
+"\n overRight = (this.offsetLeft - parent.offsetLeft + this.clientWidth - parentBorderLeftWidth) > (parent.scrollLeft + parent.clientWidth)," //$NON-NLS-1$
|
|
207 |
+"\n alignWithTop = overTop && !overBottom;" //$NON-NLS-1$
|
|
208 |
+"\n if ((overTop || overBottom) && centerIfNeeded) {" //$NON-NLS-1$
|
|
209 |
+"\n parent.scrollTop = this.offsetTop - parent.offsetTop - parent.clientHeight / 2 - parentBorderTopWidth + this.clientHeight / 2;" //$NON-NLS-1$
|
|
210 |
+"\n }" //$NON-NLS-1$
|
|
211 |
+"\n if ((overLeft || overRight) && centerIfNeeded) {" //$NON-NLS-1$
|
|
212 |
+"\n parent.scrollLeft = this.offsetLeft - parent.offsetLeft - parent.clientWidth / 2 - parentBorderLeftWidth + this.clientWidth / 2;" //$NON-NLS-1$
|
|
213 |
+"\n }" //$NON-NLS-1$
|
|
214 |
+"\n if ((overTop || overBottom || overLeft || overRight) && !centerIfNeeded) {" //$NON-NLS-1$
|
|
215 |
+"\n this.scrollIntoView(alignWithTop);" //$NON-NLS-1$
|
|
216 |
+"\n }" //$NON-NLS-1$
|
|
217 |
+"\n };" //$NON-NLS-1$
|
|
218 |
+"\n}" //$NON-NLS-1$
|
|
219 |
+"\n} catch(e) {Element.prototype.scrollIntoViewIfNeeded = Element.prototype.scrollIntoView}"; //$NON-NLS-1$
|
|
220 |
|
218 |
221 |
protected boolean fastWordHighLight = SynopticEditionPreferences.getInstance().getBoolean(SynopticEditionPreferences.FAST_HIGHLIGHT);
|
219 |
222 |
private ArrayList<ProgressListener> beforeHighlighListeners;
|
220 |
223 |
public ArrayList<ProgressListener> getBeforeHighlighListeners() {
|
... | ... | |
237 |
240 |
this.synopticEditionEditor = synopticEditionEditor;
|
238 |
241 |
this.currentEdition = edition;
|
239 |
242 |
this.currentText = currentEdition.getText();
|
240 |
|
|
|
243 |
|
241 |
244 |
File functionsFile = null;
|
242 |
245 |
try {
|
243 |
|
|
244 |
246 |
Bundle bundle = Platform.getBundle("org.txm.edition.rcp"); //$NON-NLS-1$
|
245 |
247 |
URL fileURL = bundle.getEntry("res/js/functions.js"); //$NON-NLS-1$
|
246 |
248 |
URL r = FileLocator.resolve(fileURL);
|
247 |
249 |
Log.fine("Load JS functions from: "+r);
|
248 |
250 |
functions = IOUtils.getText(r, "UTF-8"); //$NON-NLS-1$
|
249 |
|
|
|
251 |
|
250 |
252 |
} catch (Exception e) {
|
251 |
253 |
Log.severe(EditionUIMessages.bind(EditionUIMessages.error_while_reading, functionsFile, e.getLocalizedMessage()));
|
252 |
254 |
Log.printStackTrace(e);
|
253 |
255 |
}
|
254 |
|
|
|
256 |
|
255 |
257 |
beforeHighlighListeners = new ArrayList<ProgressListener>();
|
256 |
258 |
afterHighlighListeners = new ArrayList<ProgressListener>();
|
257 |
259 |
|
258 |
260 |
progresslistener = new ProgressListener() {
|
259 |
|
|
|
261 |
|
260 |
262 |
@Override
|
261 |
263 |
public void changed(ProgressEvent event) { }
|
262 |
|
|
|
264 |
|
263 |
265 |
@Override
|
264 |
266 |
public void completed(ProgressEvent event) {
|
265 |
267 |
|
... | ... | |
269 |
271 |
if (!execute(functions)) { // build the sheet if not present in the HTML DOM
|
270 |
272 |
Log.fine("JS execution (init) error with="+functions); //$NON-NLS-1$
|
271 |
273 |
} else {
|
272 |
|
|
|
274 |
|
273 |
275 |
}
|
274 |
276 |
}
|
275 |
277 |
|
276 |
278 |
// do something before the highlight is done
|
277 |
279 |
for (ProgressListener pl : beforeHighlighListeners) { pl.completed(event);}
|
278 |
|
|
279 |
280 |
|
|
281 |
|
280 |
282 |
//System.out.println("highlight: "+highlightedColorPerWordIDS);
|
281 |
283 |
StringBuilder buffer = new StringBuilder();
|
282 |
284 |
//buffer.append("alert(\"\"+sheet);\n");
|
... | ... | |
287 |
289 |
} else {
|
288 |
290 |
buffer.append("try { while(sheet.cssRules.length > 0) sheet.deleteRule(0); } catch (e) {};\n"); // empty style //$NON-NLS-1$
|
289 |
291 |
}
|
290 |
|
|
|
292 |
|
291 |
293 |
if (buffer.length() > 0) {
|
292 |
294 |
if (!execute(buffer.toString())) {
|
293 |
295 |
Log.fine("JS execution error (delete cssRules) with="+buffer);
|
... | ... | |
296 |
298 |
|
297 |
299 |
|
298 |
300 |
buffer = new StringBuilder();
|
299 |
|
|
|
301 |
|
300 |
302 |
String firstWord = currentPage.getWordId();
|
301 |
303 |
Page nextPage = currentEdition.getNextPage(currentPage);
|
302 |
304 |
String lastWord = "w_999999999"; //$NON-NLS-1$
|
... | ... | |
319 |
321 |
for (String wordid : highlightedColorPerWordIDS.keySet()) {
|
320 |
322 |
//Log.finest("words to highlight: "+highlightedColorPerWordIDS);
|
321 |
323 |
if (highlightedColorPerWordIDS.get(wordid).size() == 0) continue; // error
|
322 |
|
|
|
324 |
|
323 |
325 |
//if (!slowWordHighLight) { //TODO: this code must be replaced with word position instead of word id comparaison
|
324 |
326 |
if (Edition.isFirstGTthanSecond(wordid, firstWord) < 0) continue; // skip the word to highlight
|
325 |
327 |
if (Edition.isFirstGTthanSecond(lastWord, wordid) < 0) continue; // skip the word to highlight
|
... | ... | |
327 |
329 |
//n++;
|
328 |
330 |
RGBA composite = new RGBA(0,0,0,0f);
|
329 |
331 |
int size = highlightedColorPerWordIDS.get(wordid).size();
|
330 |
|
|
|
332 |
|
331 |
333 |
for (RGBA color : highlightedColorPerWordIDS.get(wordid)) {
|
332 |
334 |
composite.r += color.r;
|
333 |
335 |
composite.g += color.g;
|
334 |
336 |
composite.b += color.b;
|
335 |
337 |
composite.a += color.a;
|
336 |
338 |
}
|
337 |
|
|
|
339 |
|
338 |
340 |
composite.r /= size;
|
339 |
341 |
composite.g /= size;
|
340 |
342 |
composite.b /= size;
|
341 |
|
|
|
343 |
|
342 |
344 |
String s = null;
|
343 |
345 |
if (!fastWordHighLight) {
|
344 |
346 |
//s = String.format(highlightscriptRule, wordid, composite.r, composite.g, composite.b, composite.a);
|
... | ... | |
354 |
356 |
s = String.format(highlightscriptRuleFast, wordid.replace(" ", "\\ "), composite.r, composite.g, composite.b, composite.a); //$NON-NLS-1$ //$NON-NLS-2$
|
355 |
357 |
// s = String.format(highlightscriptRuleFast, wordid, composite.r, composite.g, composite.b, composite.a);
|
356 |
358 |
}
|
357 |
|
|
|
359 |
|
358 |
360 |
buffer.append(s+"\n"); //$NON-NLS-1$
|
359 |
361 |
}
|
360 |
|
|
|
362 |
|
361 |
363 |
if (buffer.length() > 0) {
|
362 |
364 |
if (!execute(buffer.toString())) {
|
363 |
365 |
Log.fine("JS execution (highlight) error with="+buffer);
|
... | ... | |
366 |
368 |
|
367 |
369 |
|
368 |
370 |
buffer = new StringBuilder();
|
369 |
|
|
|
371 |
|
370 |
372 |
// for (String wordidslist : highlightedColorSpans.keySet()) {
|
371 |
373 |
// RGBA composite = new RGBA(0,0,0,0f);
|
372 |
374 |
// int size = highlightedColorSpans.get(wordidslist).size();
|
... | ... | |
386 |
388 |
// cmd += "wrap(l, \""+wordidslist+"\";\n";
|
387 |
389 |
// buffer.append(cmd+"\n");
|
388 |
390 |
// }
|
389 |
|
|
|
391 |
|
390 |
392 |
for (String wordid : fontColorPerWordIDS.keySet()) {
|
391 |
393 |
RGBA composite = new RGBA(0,0,0,0f);
|
392 |
394 |
int size = fontColorPerWordIDS.get(wordid).size();
|
393 |
|
|
|
395 |
|
394 |
396 |
for (RGBA color : fontColorPerWordIDS.get(wordid)) {
|
395 |
397 |
composite.r += color.r;
|
396 |
398 |
composite.g += color.g;
|
397 |
399 |
composite.b += color.b;
|
398 |
400 |
composite.a += color.a;
|
399 |
401 |
}
|
400 |
|
|
|
402 |
|
401 |
403 |
composite.r /= size;
|
402 |
404 |
composite.g /= size;
|
403 |
405 |
composite.b /= size;
|
404 |
|
|
|
406 |
|
405 |
407 |
String s = String.format(colorscriptRuleFast, wordid, composite.r, composite.g, composite.b, composite.a);
|
406 |
408 |
buffer.append(s+"\n"); //$NON-NLS-1$
|
407 |
409 |
}
|
408 |
|
|
|
410 |
|
409 |
411 |
if (buffer.length() > 0) {
|
410 |
412 |
if (!execute(buffer.toString())) {
|
411 |
413 |
Log.fine("JS execution (color) error with="+buffer);
|
... | ... | |
414 |
416 |
|
415 |
417 |
|
416 |
418 |
buffer = new StringBuilder();
|
417 |
|
|
|
419 |
|
418 |
420 |
for (String wordid : fontSizePerWordIDS.keySet()) {
|
419 |
421 |
String s = String.format(sizescriptRuleFast, wordid, fontSizePerWordIDS.get(wordid));
|
420 |
422 |
buffer.append(s+"\n"); //$NON-NLS-1$
|
421 |
423 |
}
|
422 |
|
|
|
424 |
|
423 |
425 |
for (String wordid : fontWeightPerWordIDS.keySet()) {
|
424 |
426 |
String s = null;
|
425 |
427 |
if (!fastWordHighLight) {
|
... | ... | |
444 |
446 |
}
|
445 |
447 |
buffer.append(s+"\n"); //$NON-NLS-1$
|
446 |
448 |
}
|
447 |
|
|
|
449 |
|
448 |
450 |
for (String wordid : fontFamillyPerWordIDS.keySet()) {
|
449 |
451 |
String s = String.format(famillyscriptRuleFast, wordid, fontFamillyPerWordIDS.get(wordid));
|
450 |
452 |
buffer.append(s+"\n"); //$NON-NLS-1$
|
451 |
453 |
}
|
452 |
|
|
|
454 |
|
453 |
455 |
if (buffer.length() > 0) {
|
454 |
456 |
if (!execute(buffer.toString())) {
|
455 |
457 |
Log.fine("JS execution (font) error with="+buffer);
|
... | ... | |
458 |
460 |
|
459 |
461 |
|
460 |
462 |
buffer = new StringBuilder();
|
461 |
|
|
|
463 |
|
462 |
464 |
if (focusedWordID != null) {
|
463 |
465 |
//System.out.println("Focus on: "+focusedWordID);
|
464 |
466 |
String s = "try { showElementIfNeeded(document.getElementById(\"" + focusedWordID + "\")); } catch (e) {document.getElementById(\"" + focusedWordID + "\").scrollIntoView();};"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
465 |
467 |
buffer.append(s+"\n"); //$NON-NLS-1$
|
466 |
468 |
}
|
467 |
|
|
|
469 |
|
468 |
470 |
if (buffer.length() > 0) {
|
469 |
471 |
if (execute(buffer.toString())) {
|
470 |
472 |
focusedWordID = null; // focus one time
|
... | ... | |
475 |
477 |
|
476 |
478 |
|
477 |
479 |
buffer = new StringBuilder();
|
478 |
|
|
|
480 |
|
479 |
481 |
if (highlightedAreas != null) {
|
480 |
482 |
for (int[] pos : highlightedAreas) {
|
481 |
483 |
if (pos == null || pos.length != 4) continue;
|
... | ... | |
484 |
486 |
break;// one word only for now
|
485 |
487 |
}
|
486 |
488 |
}
|
487 |
|
|
|
489 |
|
488 |
490 |
//System.out.println(buffer);
|
489 |
491 |
if (buffer.length() > 0) {
|
490 |
492 |
if (!execute(buffer.toString())) {
|
... | ... | |
497 |
499 |
for (ProgressListener pl : afterHighlighListeners) { pl.completed(event);}
|
498 |
500 |
}
|
499 |
501 |
};
|
|
502 |
|
|
503 |
getBrowser().addMouseListener(new MouseListener() {
|
|
504 |
|
|
505 |
boolean dblClick = false;
|
|
506 |
boolean debug = false;
|
|
507 |
private int t,x,y;
|
|
508 |
|
|
509 |
@Override
|
|
510 |
public void mouseDoubleClick(MouseEvent e) {
|
|
511 |
if (debug) System.out.println("DOUBLE CLICK"); //$NON-NLS-1$
|
|
512 |
dblClick= true;
|
|
513 |
}
|
|
514 |
|
|
515 |
@Override
|
|
516 |
public void mouseDown(MouseEvent e) {
|
|
517 |
if (debug) System.out.println("MOUSE DOWN"); //$NON-NLS-1$
|
|
518 |
dblClick = false;
|
|
519 |
t = e.time;
|
|
520 |
x = e.x;
|
|
521 |
y = e.y;
|
|
522 |
}
|
|
523 |
|
|
524 |
@Override
|
|
525 |
public void mouseUp(MouseEvent e) {
|
|
526 |
if (dblClick) { // doucle click raised by mouseDoubleClick
|
|
527 |
dblClick = false;
|
|
528 |
return; // stop right now ! :-o
|
|
529 |
}
|
|
530 |
if (debug) System.out.println("MOUSE UP"); //$NON-NLS-1$
|
|
531 |
EditionPanel panel = EditionPanel.this;
|
|
532 |
|
|
533 |
// filter click that are not a left simple click (no drag)
|
|
534 |
//System.out.println("click count="+e.count+" button="+e.button+" time="+e.time+" diff="+(e.time-t)+" dist="+(Math.abs(e.x - x) + Math.abs(e.y - y)));
|
|
535 |
if (e.count > 1) {
|
|
536 |
if (debug) System.out.println(" DOUBLE CLICK"); //$NON-NLS-1$
|
|
537 |
//System.out.println("not a simple click");
|
|
538 |
return;
|
|
539 |
}
|
|
540 |
|
|
541 |
int dist = Math.abs(e.x - x) + Math.abs(e.y - y);
|
|
542 |
int deltat = (e.time-t);
|
|
543 |
//System.out.println("deltat ="+deltat);
|
|
544 |
if (dist >= 0 && (deltat > 0 || dist > 0)) {
|
|
545 |
//System.out.println(" DRAG dist="+dist+" deltat="+deltat);
|
|
546 |
String[] ids = panel.getWordSelection(); // may be null
|
|
547 |
|
|
548 |
panel.expandSelectionTo(ids);
|
|
549 |
return;
|
|
550 |
}
|
|
551 |
}
|
|
552 |
});
|
|
553 |
|
500 |
554 |
getBrowser().addProgressListener(progresslistener);
|
501 |
555 |
new CommandLink (synopticEditionEditor, getBrowser());
|
502 |
556 |
new EditionLink (synopticEditionEditor, getBrowser());
|
503 |
557 |
}
|
504 |
|
|
|
558 |
|
505 |
559 |
/**
|
506 |
560 |
* Bypass BrowserViewer restriction on the getBrowser method
|
507 |
561 |
*/
|
508 |
562 |
public Browser getBrowser() {
|
509 |
563 |
return super.getBrowser();
|
510 |
564 |
}
|
511 |
|
|
|
565 |
|
512 |
566 |
/**
|
513 |
567 |
* Bypass BrowserViewer restriction on the getBrowser method
|
514 |
568 |
*/
|
515 |
569 |
public String getDOM() {
|
516 |
570 |
return "";//execute("return document.innerHTML"; //$NON-NLS-1$
|
517 |
571 |
}
|
518 |
|
|
|
572 |
|
519 |
573 |
public ISelectionProvider getSelectionProvider() {
|
520 |
574 |
return selProvider;
|
521 |
575 |
}
|
522 |
|
|
|
576 |
|
523 |
577 |
public void setHighlightWordsById(RGBA color, HashSet<String> wordids) {
|
524 |
578 |
for (String wordid : wordids) {
|
525 |
579 |
if (this.highlightedColorPerWordIDS.get(wordid) != null) {
|
... | ... | |
530 |
584 |
hs.add(color);
|
531 |
585 |
}
|
532 |
586 |
}
|
533 |
|
|
|
587 |
|
534 |
588 |
public void addHighlightWordsById(RGBA color, String wordid) {
|
535 |
589 |
if (!this.highlightedColorPerWordIDS.containsKey(wordid)) {
|
536 |
590 |
this.highlightedColorPerWordIDS.put(wordid, new ArrayList<RGBA>());
|
537 |
591 |
}
|
538 |
592 |
this.highlightedColorPerWordIDS.get(wordid).add(color);
|
539 |
593 |
}
|
540 |
|
|
|
594 |
|
541 |
595 |
/**
|
542 |
596 |
* Can be called to refresh the page word styles but only when the page is loaded
|
543 |
597 |
*/
|
544 |
598 |
public void updateWordStyles() {
|
545 |
599 |
progresslistener.completed(null);
|
546 |
600 |
}
|
547 |
|
|
|
601 |
|
548 |
602 |
public void addHighlightWordsById(RGBA color, Collection<String> wordids) {
|
549 |
603 |
for (String wordid : wordids) {
|
550 |
604 |
addHighlightWordsById(color, wordid);
|
551 |
605 |
}
|
552 |
606 |
}
|
553 |
|
|
|
607 |
|
554 |
608 |
public void removeHighlightWordsById(RGBA color, Collection<String> wordids) {
|
555 |
609 |
//System.out.println("Call removeHighlightWordsById: "+wordids+" color="+color);
|
556 |
610 |
StringBuffer buffer = new StringBuffer();
|
... | ... | |
560 |
614 |
buffer.append(String.format(clearhighlightscript, wordid)+"\n"); //$NON-NLS-1$
|
561 |
615 |
}
|
562 |
616 |
}
|
563 |
|
|
|
617 |
|
564 |
618 |
if (buffer.length() > 0) execute(buffer.toString());
|
565 |
619 |
}
|
566 |
|
|
|
620 |
|
567 |
621 |
public void removeHighlightWordsById(RGBA color, String wordid) {
|
568 |
622 |
if (highlightedColorPerWordIDS.get(wordid) == null) return; // nothing to do
|
569 |
|
|
|
623 |
|
570 |
624 |
//System.out.println("remove color="+color+" from id="+wordid);
|
571 |
625 |
this.highlightedColorPerWordIDS.get(wordid).remove(color);
|
572 |
|
|
|
626 |
|
573 |
627 |
if (this.highlightedColorPerWordIDS.get(wordid).size() == 0) {
|
574 |
628 |
this.highlightedColorPerWordIDS.remove(wordid);
|
575 |
629 |
}
|
576 |
630 |
}
|
577 |
|
|
|
631 |
|
578 |
632 |
/**
|
579 |
633 |
* Open the page containing the word with ID=$line_wordid
|
580 |
634 |
* @param line_wordid
|
581 |
635 |
* @return true if the page changed
|
582 |
636 |
*/
|
583 |
637 |
public boolean backToText(Text text, String line_wordid) {
|
584 |
|
|
|
638 |
|
585 |
639 |
String name = currentEdition.getName();
|
586 |
640 |
Edition edition = text.getEdition(name);
|
587 |
|
|
|
641 |
|
588 |
642 |
if (edition == null) {
|
589 |
643 |
String s = EditionUIMessages.bind(EditionUIMessages.noEditionFoundForTextEqualsP0AndEditionEqualsP1, text, name);
|
590 |
644 |
System.out.println(s);
|
... | ... | |
605 |
659 |
|
606 |
660 |
return false;
|
607 |
661 |
}
|
608 |
|
|
|
662 |
|
609 |
663 |
/**
|
610 |
664 |
* First page.
|
611 |
665 |
*/
|
... | ... | |
617 |
671 |
System.out.println(EditionUIMessages.bind(EditionUIMessages.failToRetrieveFirstPageOfEditionEqualsP0AndTextEqualsP1, currentEdition.getName(), currentText.getName()));
|
618 |
672 |
return;
|
619 |
673 |
}
|
620 |
|
|
|
674 |
|
621 |
675 |
this.setURL(currentPage.toURL());
|
622 |
|
|
|
676 |
|
623 |
677 |
//page_label.setText(makePageLabel());
|
624 |
678 |
}
|
625 |
|
|
|
679 |
|
626 |
680 |
public void setURL(String url) {
|
627 |
681 |
if (!this.browser.isDisposed()) {
|
628 |
682 |
super.setURL(url);
|
629 |
683 |
}
|
630 |
684 |
}
|
631 |
|
|
|
685 |
|
632 |
686 |
/**
|
633 |
687 |
* Last page.
|
634 |
688 |
*/
|
635 |
689 |
public void lastPage() {
|
636 |
690 |
// System.out.println(Messages.TxmBrowser_2+currentPage);
|
637 |
|
|
|
691 |
|
638 |
692 |
if (currentPage != null && currentPage.getFile().equals(currentEdition.getLastPage().getFile())) {
|
639 |
693 |
return;
|
640 |
694 |
}
|
... | ... | |
642 |
696 |
currentText = currentEdition.getText();
|
643 |
697 |
this.setURL(currentPage.toURL());
|
644 |
698 |
}
|
645 |
|
|
|
699 |
|
646 |
700 |
/**
|
647 |
701 |
* Previous page.
|
648 |
702 |
*/
|
... | ... | |
650 |
704 |
// System.out.println(Messages.TxmBrowser_3+currentPage);
|
651 |
705 |
if (currentPage != null) {
|
652 |
706 |
Page previous = currentEdition.getPreviousPage(currentPage);
|
653 |
|
|
|
707 |
|
654 |
708 |
if (previous == currentPage) {
|
655 |
709 |
previousText(true);
|
656 |
710 |
} else {
|
... | ... | |
663 |
717 |
}
|
664 |
718 |
//page_label.setText(makePageLabel());
|
665 |
719 |
}
|
666 |
|
|
667 |
|
|
668 |
|
|
|
720 |
|
|
721 |
|
|
722 |
|
669 |
723 |
/**
|
670 |
724 |
* Next page.
|
671 |
725 |
*/
|
... | ... | |
685 |
739 |
}
|
686 |
740 |
//page_label.setText(makePageLabel());
|
687 |
741 |
}
|
688 |
|
|
689 |
|
|
|
742 |
|
|
743 |
|
690 |
744 |
public void firstText() {
|
691 |
745 |
//Text current = this.currentPage.getEdition().getText();
|
692 |
746 |
Project project = currentText.getProject();
|
... | ... | |
698 |
752 |
return;
|
699 |
753 |
}
|
700 |
754 |
Text firstText = project.getText(id);
|
701 |
|
|
|
755 |
|
702 |
756 |
if (firstText != null) {
|
703 |
757 |
String editionName = currentEdition.getName();
|
704 |
758 |
Edition tmp = firstText.getEdition(editionName);
|
... | ... | |
716 |
770 |
this.setURL(currentPage.toURL());
|
717 |
771 |
}
|
718 |
772 |
}
|
719 |
|
|
|
773 |
|
720 |
774 |
/**
|
721 |
775 |
* Next text.
|
722 |
776 |
*/
|
... | ... | |
732 |
786 |
return;
|
733 |
787 |
}
|
734 |
788 |
Text lastText = project.getText(id);
|
735 |
|
|
|
789 |
|
736 |
790 |
if (lastText != null) {
|
737 |
791 |
String editionName = currentEdition.getName();
|
738 |
792 |
Edition tmp = lastText.getEdition(editionName);
|
... | ... | |
740 |
794 |
System.out.println(EditionUIMessages.bind(EditionUIMessages.noEditionWithNameEqualsP0AvailableForTextEqualsP1, editionName, lastText.getName()));
|
741 |
795 |
return;
|
742 |
796 |
}
|
743 |
|
|
|
797 |
|
744 |
798 |
currentEdition = tmp;
|
745 |
799 |
currentPage = currentEdition.getFirstPage();
|
746 |
800 |
currentText = lastText;
|
... | ... | |
748 |
802 |
StatusLine.setMessage("No text next"); //$NON-NLS-1$
|
749 |
803 |
return;
|
750 |
804 |
}
|
751 |
|
|
|
805 |
|
752 |
806 |
this.setURL(currentPage.toURL());
|
753 |
807 |
//page_label.setText(makePageLabel());
|
754 |
808 |
}
|
755 |
809 |
// System.out.println("Next texts "+nextText);
|
756 |
810 |
}
|
757 |
|
|
|
811 |
|
758 |
812 |
/**
|
759 |
813 |
* Previous text.
|
760 |
814 |
* @param fromNextText if true it means the user was reading the next text and then we show the last page of the previous text
|
761 |
815 |
*/
|
762 |
816 |
public void previousText(boolean fromNextText) {
|
763 |
|
|
|
817 |
|
764 |
818 |
Project project = currentText.getProject();
|
765 |
819 |
String id;
|
766 |
820 |
try {
|
... | ... | |
780 |
834 |
return;
|
781 |
835 |
}
|
782 |
836 |
Text previousText = project.getText(id);
|
783 |
|
|
|
837 |
|
784 |
838 |
if (previousText != null) {
|
785 |
839 |
String editionName = currentEdition.getName();
|
786 |
|
|
|
840 |
|
787 |
841 |
Edition tmp = previousText.getEdition(editionName);
|
788 |
842 |
if (tmp == null) {
|
789 |
843 |
System.out.println(EditionUIMessages.bind(EditionUIMessages.noEditionWithNameEqualsP0AvailableForTextEqualsP1, editionName, previousText.getName()));
|
... | ... | |
796 |
850 |
} else {
|
797 |
851 |
currentPage = currentEdition.getFirstPage();
|
798 |
852 |
}
|
799 |
|
|
|
853 |
|
800 |
854 |
if (currentPage == null) {
|
801 |
855 |
StatusLine.setMessage("No previous text"); //$NON-NLS-1$
|
802 |
856 |
return;
|
... | ... | |
805 |
859 |
}
|
806 |
860 |
// System.out.println("Previous texts "+previousText);
|
807 |
861 |
}
|
808 |
|
|
|
862 |
|
809 |
863 |
/**
|
810 |
864 |
* Next text.
|
811 |
865 |
*/
|
... | ... | |
830 |
884 |
return;
|
831 |
885 |
}
|
832 |
886 |
Text nextText = project.getText(id);
|
833 |
|
|
|
887 |
|
834 |
888 |
if (nextText != null) {
|
835 |
889 |
String editionName = currentEdition.getName();
|
836 |
890 |
Edition tmp = nextText.getEdition(editionName);
|
... | ... | |
839 |
893 |
return;
|
840 |
894 |
}
|
841 |
895 |
currentEdition = tmp;
|
842 |
|
|
|
896 |
|
843 |
897 |
currentPage = currentEdition.getFirstPage();
|
844 |
898 |
currentText = nextText;
|
845 |
899 |
if (currentPage == null) {
|
846 |
900 |
StatusLine.setMessage("No text next"); //$NON-NLS-1$
|
847 |
901 |
return;
|
848 |
902 |
}
|
849 |
|
|
|
903 |
|
850 |
904 |
this.setURL(currentPage.toURL());
|
851 |
905 |
//page_label.setText(makePageLabel());
|
852 |
906 |
}
|
853 |
907 |
// System.out.println("Next texts "+nextText);
|
854 |
908 |
}
|
855 |
|
|
856 |
|
|
|
909 |
|
|
910 |
|
857 |
911 |
public void setText(Text text, boolean refresh) {
|
858 |
912 |
String editionName = currentEdition.getName();
|
859 |
913 |
Edition tmp = text.getEdition(editionName);
|
... | ... | |
861 |
915 |
System.out.println(EditionUIMessages.bind(EditionUIMessages.noEditionWithNameEqualsP0AvailableForTextEqualsP1, editionName, text.getName()));
|
862 |
916 |
return;
|
863 |
917 |
}
|
864 |
|
|
|
918 |
|
865 |
919 |
currentEdition = tmp;
|
866 |
920 |
currentPage = currentEdition.getFirstPage();
|
867 |
921 |
currentText = text;
|
... | ... | |
869 |
923 |
StatusLine.setMessage("No text next"); //$NON-NLS-1$
|
870 |
924 |
return;
|
871 |
925 |
}
|
872 |
|
|
|
926 |
|
873 |
927 |
if (refresh) {
|
874 |
928 |
this.setURL(currentPage.toURL());
|
875 |
929 |
}
|
876 |
930 |
//page_label.setText(makePageLabel());
|
877 |
931 |
}
|
878 |
|
|
|
932 |
|
879 |
933 |
/**
|
880 |
934 |
* Gets the current page.
|
881 |
935 |
*
|
... | ... | |
884 |
938 |
public Page getCurrentPage() {
|
885 |
939 |
return currentPage;
|
886 |
940 |
}
|
887 |
|
|
|
941 |
|
888 |
942 |
/**
|
889 |
943 |
* Gets the current text.
|
890 |
944 |
*
|
... | ... | |
893 |
947 |
public Text getCurrentText() {
|
894 |
948 |
return currentText;
|
895 |
949 |
}
|
896 |
|
|
|
950 |
|
897 |
951 |
/**
|
898 |
952 |
* Make page label.
|
899 |
953 |
*
|
... | ... | |
902 |
956 |
public String makePageLabel() {
|
903 |
957 |
return currentPage.getName() + " / " + currentPage.getEdition().getNumPages(); //$NON-NLS-1$
|
904 |
958 |
}
|
905 |
|
|
|
959 |
|
906 |
960 |
/**
|
907 |
961 |
* Show page.
|
908 |
962 |
*
|
... | ... | |
915 |
969 |
currentPage = page;
|
916 |
970 |
this.setURL(currentPage.toURL());
|
917 |
971 |
}
|
918 |
|
|
|
972 |
|
919 |
973 |
public void reloadPage() {
|
920 |
974 |
this.setURL(currentPage.toURL());
|
921 |
975 |
}
|
922 |
|
|
|
976 |
|
923 |
977 |
// /**
|
924 |
978 |
// * Sets the edition.
|
925 |
979 |
// *
|
... | ... | |
928 |
982 |
// public void setEdition(Edition edition) {
|
929 |
983 |
// this.currentEdition = edition;
|
930 |
984 |
// }
|
931 |
|
|
|
985 |
|
932 |
986 |
static String SCRIPT01 = "var html = \"\";"+ //$NON-NLS-1$
|
933 |
987 |
"if (typeof window.getSelection != \"undefined\") {"+ // modern Web browsers //$NON-NLS-1$
|
934 |
988 |
"var sel = window.getSelection();"+ //$NON-NLS-1$
|
... | ... | |
945 |
999 |
"}" + //$NON-NLS-1$
|
946 |
1000 |
"}" + //$NON-NLS-1$
|
947 |
1001 |
"return html"; //$NON-NLS-1$
|
948 |
|
|
|
1002 |
|
949 |
1003 |
public String getTextSelectionDOM() {
|
950 |
1004 |
return ((String) evaluate(SCRIPT01));
|
951 |
1005 |
}
|
952 |
|
|
|
1006 |
|
953 |
1007 |
/**
|
954 |
1008 |
*
|
955 |
1009 |
* @return array of 2 word id, if only one word is selected 2nd value is null
|
956 |
1010 |
*/
|
957 |
1011 |
public String[] getWordSelection() {
|
958 |
|
|
|
1012 |
|
959 |
1013 |
//System.out.println("getWordSelection");
|
960 |
1014 |
String SCRIPT02_getspans = ""//functions //$NON-NLS-1$
|
961 |
1015 |
+"var all = [];" //$NON-NLS-1$
|
... | ... | |
990 |
1044 |
+"\n}" //$NON-NLS-1$
|
991 |
1045 |
//+"alert('result='+all)"
|
992 |
1046 |
+"\nreturn all;"; //$NON-NLS-1$
|
993 |
|
|
|
1047 |
|
994 |
1048 |
// System.out.println(functions);
|
995 |
1049 |
// System.out.println(SCRIPT02_getspans);
|
996 |
|
|
|
1050 |
|
997 |
1051 |
Object ret = evaluate(SCRIPT02_getspans);
|
998 |
1052 |
if (ret instanceof Object[]) {
|
999 |
1053 |
Log.finer("selection word ids="+Arrays.toString((Object[])ret)); //$NON-NLS-1$
|
... | ... | |
1014 |
1068 |
return null;
|
1015 |
1069 |
}
|
1016 |
1070 |
}
|
1017 |
|
|
|
1071 |
|
1018 |
1072 |
public String getTextSelection() {
|
1019 |
1073 |
//System.out.println("DOM="+getTextSelectionDOM());
|
1020 |
1074 |
String rez = getTextSelectionDOM().replaceAll("<[^>]+>", ""); //$NON-NLS-1$ //$NON-NLS-2$
|
1021 |
1075 |
//System.out.println("STR="+rez);
|
1022 |
1076 |
return rez;
|
1023 |
1077 |
}
|
1024 |
|
|
|
1078 |
|
1025 |
1079 |
@Override
|
1026 |
1080 |
public void addSelectionChangedListener(ISelectionChangedListener listener) { }
|
1027 |
|
|
|
1081 |
|
1028 |
1082 |
@Override
|
1029 |
1083 |
public ISelection getSelection() {
|
1030 |
1084 |
return new SynopticTextSelection(this);
|
1031 |
1085 |
}
|
1032 |
|
|
|
1086 |
|
1033 |
1087 |
@Override
|
1034 |
1088 |
public void removeSelectionChangedListener(
|
1035 |
1089 |
ISelectionChangedListener listener) { }
|
1036 |
|
|
|
1090 |
|
1037 |
1091 |
@Override
|
1038 |
1092 |
public void setSelection(ISelection selection) { }
|
1039 |
|
|
|
1093 |
|
1040 |
1094 |
static public class SynopticTextSelection implements ISelection {
|
1041 |
1095 |
String str;
|
1042 |
1096 |
public SynopticTextSelection(EditionPanel panel) {
|
1043 |
1097 |
this.str = panel.getTextSelection();
|
1044 |
1098 |
}
|
1045 |
|
|
|
1099 |
|
1046 |
1100 |
@Override
|
1047 |
1101 |
public boolean isEmpty() {
|
1048 |
1102 |
return str != null && str.length() > 0;
|
1049 |
1103 |
}
|
1050 |
|
|
|
1104 |
|
1051 |
1105 |
public String getTextSelection() {
|
1052 |
1106 |
return str;
|
1053 |
1107 |
}
|
1054 |
1108 |
}
|
1055 |
|
|
|
1109 |
|
1056 |
1110 |
public Edition getEdition() {
|
1057 |
1111 |
return currentEdition;
|
1058 |
1112 |
}
|
1059 |
|
|
|
1113 |
|
1060 |
1114 |
public MenuManager getMenuManager() {
|
1061 |
1115 |
return menuManager;
|
1062 |
1116 |
}
|
1063 |
|
|
|
1117 |
|
1064 |
1118 |
public void initMenu() {
|
1065 |
1119 |
// create a new menu
|
1066 |
1120 |
menuManager = new MenuManager(); //$NON-NLS-1$
|
1067 |
|
|
|
1121 |
|
1068 |
1122 |
Menu menu = menuManager.createContextMenu(this.getBrowser());
|
1069 |
|
|
|
1123 |
|
1070 |
1124 |
menu.addMenuListener(new MenuListener() {
|
1071 |
|
|
|
1125 |
|
1072 |
1126 |
@Override
|
1073 |
1127 |
public void menuShown(MenuEvent e) {
|
1074 |
1128 |
Menu menu = menuManager.getMenu();
|
1075 |
1129 |
if (menu == null) return;
|
1076 |
1130 |
new MenuItem(menu, SWT.SEPARATOR);
|
1077 |
|
|
|
1131 |
|
1078 |
1132 |
MenuItem copyItem = new MenuItem(menu, SWT.NONE);
|
1079 |
1133 |
copyItem.setText(EditionUIMessages.copyTextSelection);
|
1080 |
1134 |
copyItem.addSelectionListener(new SelectionListener() {
|
1081 |
|
|
|
1135 |
|
1082 |
1136 |
@Override
|
1083 |
1137 |
public void widgetSelected(SelectionEvent e) {
|
1084 |
1138 |
String text = EditionPanel.this.getTextSelection();
|
... | ... | |
1086 |
1140 |
IOClipboard.write(text);
|
1087 |
1141 |
}
|
1088 |
1142 |
}
|
1089 |
|
|
|
1143 |
|
1090 |
1144 |
@Override
|
1091 |
1145 |
public void widgetDefaultSelected(SelectionEvent e) { }
|
1092 |
1146 |
});
|
1093 |
1147 |
String text = EditionPanel.this.getTextSelection();
|
1094 |
1148 |
copyItem.setEnabled(text != null && text.length() > 0);
|
1095 |
|
|
|
1149 |
|
1096 |
1150 |
MenuItem reloadItem = new MenuItem(menu, SWT.NONE);
|
1097 |
1151 |
reloadItem.setText(EditionUIMessages.reload);
|
1098 |
1152 |
reloadItem.addSelectionListener(new SelectionListener() {
|
1099 |
|
|
|
1153 |
|
1100 |
1154 |
@Override
|
1101 |
1155 |
public void widgetSelected(SelectionEvent e) {
|
1102 |
1156 |
EditionPanel.this.getBrowser().refresh();
|
1103 |
1157 |
}
|
1104 |
|
|
|
1158 |
|
1105 |
1159 |
@Override
|
1106 |
1160 |
public void widgetDefaultSelected(SelectionEvent e) { }
|
1107 |
1161 |
});
|
1108 |
1162 |
MenuItem backItem = new MenuItem(menu, SWT.NONE);
|
1109 |
1163 |
backItem.setText(EditionUIMessages.back);
|
1110 |
1164 |
backItem.addSelectionListener(new SelectionListener() {
|
1111 |
|
|
|
1165 |
|
1112 |
1166 |
@Override
|
1113 |
1167 |
public void widgetSelected(SelectionEvent e) {
|
1114 |
1168 |
EditionPanel.this.getBrowser().back();
|
1115 |
1169 |
}
|
1116 |
|
|
|
1170 |
|
1117 |
1171 |
@Override
|
1118 |
1172 |
public void widgetDefaultSelected(SelectionEvent e) { }
|
1119 |
1173 |
});
|
1120 |
1174 |
MenuItem forwardItem = new MenuItem(menu, SWT.NONE);
|
1121 |
1175 |
forwardItem.setText(EditionUIMessages.forward);
|
1122 |
1176 |
forwardItem.addSelectionListener(new SelectionListener() {
|
1123 |
|
|
|
1177 |
|
1124 |
1178 |
@Override
|
1125 |
1179 |
public void widgetSelected(SelectionEvent e) {
|
1126 |
1180 |
EditionPanel.this.getBrowser().forward();
|
1127 |
1181 |
}
|
1128 |
|
|
|
1182 |
|
1129 |
1183 |
@Override
|
1130 |
1184 |
public void widgetDefaultSelected(SelectionEvent e) { }
|
1131 |
1185 |
});
|
1132 |
1186 |
}
|
1133 |
|
|
|
1187 |
|
1134 |
1188 |
@Override
|
1135 |
1189 |
public void menuHidden(MenuEvent e) {
|
1136 |
1190 |
// TODO Auto-generated method stub
|
... | ... | |
1154 |
1208 |
// replace the menu
|
1155 |
1209 |
this.getBrowser().setMenu(menu);
|
1156 |
1210 |
}
|
1157 |
|
|
|
1211 |
|
1158 |
1212 |
public void initSelectionProvider() {
|
1159 |
1213 |
selProvider = new ISelectionProvider() {
|
1160 |
1214 |
@Override
|
... | ... | |
1179 |
1233 |
};
|
1180 |
1234 |
return sel;
|
1181 |
1235 |
}
|
1182 |
|
|
|
1236 |
|
1183 |
1237 |
@Override
|
1184 |
1238 |
public void addSelectionChangedListener(ISelectionChangedListener listener) { }
|
1185 |
1239 |
};
|
1186 |
1240 |
}
|
1187 |
|
|
1188 |
|
|
1189 |
|
|
|
1241 |
|
|
1242 |
|
|
1243 |
|
1190 |
1244 |
public void goToPage(String name) {
|
1191 |
|
|
|
1245 |
|
1192 |
1246 |
Page next = currentEdition.get(name);
|
1193 |
1247 |
// System.out.println(Messages.TxmBrowser_4+currentPage);
|
1194 |
1248 |
if (next != null) {
|
... | ... | |
1198 |
1252 |
System.out.println(EditionUIMessages.bind(EditionUIMessages.pageNotFoundP0, name));
|
1199 |
1253 |
}
|
1200 |
1254 |
}
|
1201 |
|
|
|
1255 |
|
1202 |
1256 |
public void setFocusedWordID(String focusid) {
|
1203 |
1257 |
this.focusedWordID = focusid;
|
1204 |
1258 |
}
|
1205 |
|
|
|
1259 |
|
1206 |
1260 |
public void setHighlightedArea(HashSet<int[]> positions) {
|
1207 |
1261 |
Log.finer("Highlight area: not implemented");
|
1208 |
1262 |
}
|
1209 |
|
|
|
1263 |
|
1210 |
1264 |
public void expandSelectionTo(String[] ids) {
|
1211 |
1265 |
// expand selection
|
1212 |
1266 |
if (ids == null) return;
|
1213 |
1267 |
if (ids.length == 0) return;
|
1214 |
1268 |
//TODO: enable the feature for Windows computers
|
1215 |
1269 |
//if (System.getProperty("os.name").toLowerCase().contains("windows")) return;
|
1216 |
|
|
|
1270 |
|
1217 |
1271 |
//this.getBrowser().evaluate("alert('expand selection');");
|
1218 |
1272 |
//System.out.println("EXPAND SELECTION TO "+Arrays.toString(ids));
|
1219 |
1273 |
String id1 = ids[0];
|
... | ... | |
1237 |
1291 |
+"sel.addRange(range);\n" //$NON-NLS-1$
|
1238 |
1292 |
+ "\n" //$NON-NLS-1$
|
1239 |
1293 |
+ "return null;"; //$NON-NLS-1$
|
1240 |
|
|
|
1294 |
|
1241 |
1295 |
//System.out.println("Eval...\n"+SCRIPT02_expand);
|
1242 |
1296 |
evaluate(SCRIPT02_expand);
|
1243 |
1297 |
return;
|
1244 |
1298 |
}
|
1245 |
|
|
|
1299 |
|
1246 |
1300 |
public void addFontWeightWordsById(String weight, List<String> wordids) {
|
1247 |
1301 |
for (String wordid : wordids) {
|
1248 |
1302 |
addFontWeightWordsById(weight, wordid);
|
1249 |
1303 |
}
|
1250 |
1304 |
}
|
1251 |
|
|
|
1305 |
|
1252 |
1306 |
public void addFontWeightWordsById(String weight, String wordid) {
|
1253 |
1307 |
this.fontWeightPerWordIDS.put(wordid, weight);
|
1254 |
1308 |
}
|
1255 |
|
|
|
1309 |
|
1256 |
1310 |
public void removeFontWeightWordsById(String wordid) {
|
1257 |
1311 |
this.fontWeightPerWordIDS.remove(wordid);
|
1258 |
1312 |
}
|
1259 |
|
|
|
1313 |
|
1260 |
1314 |
public void removeFontWeightWordsById(List<String> wordids) {
|
1261 |
1315 |
for (String wordid : wordids) {
|
1262 |
1316 |
removeFontWeightWordsById(wordid);
|
1263 |
1317 |
}
|
1264 |
1318 |
}
|
1265 |
|
|
|
1319 |
|
1266 |
1320 |
/**
|
1267 |
1321 |
* Clears all highlighted words.
|
1268 |
1322 |
*/
|
1269 |
1323 |
public void removeHighlightWords() {
|
1270 |
1324 |
|
1271 |
1325 |
// FIXME: SJ: this code leads to a concurrency modification exception on Windows
|
1272 |
|
// Set<String> keys = highlightedColorPerWordIDS.keySet();
|
1273 |
|
// for (String key : keys) {
|
1274 |
|
// highlightedColorPerWordIDS.remove(key);
|
1275 |
|
// }
|
|
1326 |
// Set<String> keys = highlightedColorPerWordIDS.keySet();
|
|
1327 |
// for (String key : keys) {
|
|
1328 |
// highlightedColorPerWordIDS.remove(key);
|
|
1329 |
// }
|
1276 |
1330 |
|
1277 |
1331 |
// SJ: new version tests
|
1278 |
1332 |
highlightedColorPerWordIDS.clear();
|