47 |
47 |
|
48 |
48 |
|
49 |
49 |
private ProgressListener progresslistener;
|
50 |
|
// private List<String> wordids;
|
51 |
|
// private List<String> lineids;
|
|
50 |
|
|
51 |
// private List<String> wordids;
|
|
52 |
// private List<String> lineids;
|
52 |
53 |
/** The edition. */
|
53 |
54 |
Text currentText;
|
|
55 |
|
54 |
56 |
Edition currentEdition;
|
|
57 |
|
55 |
58 |
Page currentPage;
|
|
59 |
|
56 |
60 |
protected SynopticEditionEditor synopticEditionEditor;
|
|
61 |
|
57 |
62 |
private ISelectionProvider selProvider;
|
|
63 |
|
58 |
64 |
private MenuManager menuManager;
|
59 |
65 |
|
60 |
66 |
private HashSet<int[]> highlightedAreas = null;
|
61 |
67 |
|
62 |
|
//HashMap<String, ArrayList<RGBA>> highlightedColorSpans = new HashMap<String, ArrayList<RGBA>>(); // background color
|
|
68 |
// HashMap<String, ArrayList<RGBA>> highlightedColorSpans = new HashMap<String, ArrayList<RGBA>>(); // background color
|
63 |
69 |
|
64 |
|
HashMap<String, ArrayList<RGBA>> highlightedColorPerWordIDS = new HashMap<String, ArrayList<RGBA>>(); // background color
|
|
70 |
HashMap<String, ArrayList<RGBA>> highlightedColorPerWordIDS = new HashMap<>(); // background color
|
|
71 |
|
65 |
72 |
public static final String STYLE_NORMAL = "normal"; //$NON-NLS-1$
|
|
73 |
|
66 |
74 |
public static final String STYLE_ITALIC = "italic"; //$NON-NLS-1$
|
|
75 |
|
67 |
76 |
public static final String STYLE_OBLIQUE = "oblique"; //$NON-NLS-1$
|
68 |
|
HashMap<String, String> fontStylePerWordIDS = new HashMap<String, String>();
|
|
77 |
|
|
78 |
HashMap<String, String> fontStylePerWordIDS = new HashMap<>();
|
|
79 |
|
69 |
80 |
public static final String WEIGHT_NORMAL = "normal"; //$NON-NLS-1$
|
|
81 |
|
70 |
82 |
public static final String WEIGHT_BOLD = "bold"; //$NON-NLS-1$
|
71 |
|
HashMap<String, String> fontWeightPerWordIDS = new HashMap<String, String>();
|
72 |
|
HashMap<String, ArrayList<RGBA>> fontColorPerWordIDS = new HashMap<String, ArrayList<RGBA>>();
|
|
83 |
|
|
84 |
HashMap<String, String> fontWeightPerWordIDS = new HashMap<>();
|
|
85 |
|
|
86 |
HashMap<String, ArrayList<RGBA>> fontColorPerWordIDS = new HashMap<>();
|
|
87 |
|
73 |
88 |
public static final String SIZE_SMALL = "small"; //$NON-NLS-1$
|
|
89 |
|
74 |
90 |
public static final String SIZE_MEDIUM = "medium"; //$NON-NLS-1$
|
|
91 |
|
75 |
92 |
public static final String SIZE_LARGE = "larger"; //$NON-NLS-1$
|
|
93 |
|
76 |
94 |
public static final String SIZE_SMALLER = "smaller"; //$NON-NLS-1$
|
|
95 |
|
77 |
96 |
public static final String SIZE_LARGER = "larger"; //$NON-NLS-1$
|
78 |
|
HashMap<String, String> fontSizePerWordIDS = new HashMap<String, String>();
|
|
97 |
|
|
98 |
HashMap<String, String> fontSizePerWordIDS = new HashMap<>();
|
|
99 |
|
79 |
100 |
public static final String FAMILLY_TIMES = "\"Times New Roman\", Times"; //$NON-NLS-1$
|
|
101 |
|
80 |
102 |
public static final String FAMILLY_ARIAL = "Arial"; //$NON-NLS-1$
|
|
103 |
|
81 |
104 |
public static final String FAMILLY_COURIER = "\"Courier New\", Courier"; //$NON-NLS-1$
|
82 |
|
HashMap<String, String> fontFamillyPerWordIDS = new HashMap<String, String>();
|
|
105 |
|
|
106 |
HashMap<String, String> fontFamillyPerWordIDS = new HashMap<>();
|
|
107 |
|
83 |
108 |
public static final String VARIANT_NORMAL = "normal"; //$NON-NLS-1$
|
|
109 |
|
84 |
110 |
public static final String VARIANT_SMALLCAPS = "small-caps"; //$NON-NLS-1$
|
85 |
|
HashMap<String, String> fontVariantPerWordIDS = new HashMap<String, String>();
|
|
111 |
|
|
112 |
HashMap<String, String> fontVariantPerWordIDS = new HashMap<>();
|
|
113 |
|
86 |
114 |
String focusedWordID = null;
|
87 |
115 |
|
88 |
|
public static final String highlightscript = "try { var elt = document.getElementById(\"%s\");" + //$NON-NLS-1$ //$NON-NLS-2$
|
|
116 |
public static final String highlightscript = "try { var elt = document.getElementById(\"%s\");" + //$NON-NLS-1$
|
89 |
117 |
"elt.style.backgroundColor=\"rgb(%s,%s,%s)\";" + //$NON-NLS-1$
|
90 |
|
//"elt.style.paddingLeft=\"3px\";" + //$NON-NLS-1$
|
91 |
|
//"elt.style.paddingRight=\"3px\";" + //$NON-NLS-1$
|
92 |
|
//"elt.style.paddingTop=\"1px\";" + //$NON-NLS-1$
|
93 |
|
//"elt.style.paddingBottom=\"1px\";" + //$NON-NLS-1$
|
|
118 |
// "elt.style.paddingLeft=\"3px\";" + //$NON-NLS-1$
|
|
119 |
// "elt.style.paddingRight=\"3px\";" + //$NON-NLS-1$
|
|
120 |
// "elt.style.paddingTop=\"1px\";" + //$NON-NLS-1$
|
|
121 |
// "elt.style.paddingBottom=\"1px\";" + //$NON-NLS-1$
|
94 |
122 |
"} catch (e) { };"; //$NON-NLS-1$
|
|
123 |
|
95 |
124 |
public static final String highlightscriptRuleFast = "sheet.insertRule(\"#%s {background-color:rgba(%s,%s,%s,%s);}\", 0);"; //$NON-NLS-1$
|
|
125 |
|
96 |
126 |
public static final String colorscriptRuleFast = "sheet.insertRule(\"#%s {color:rgba(%s,%s,%s,%s);}\", 0);"; //$NON-NLS-1$
|
|
127 |
|
97 |
128 |
public static final String sizescriptRuleFast = "sheet.insertRule(\"#%s {font-size:%s;}\", 0);"; //$NON-NLS-1$
|
|
129 |
|
98 |
130 |
public static final String stylescriptRuleFast = "sheet.insertRule(\"#%s {font-style:%s;}\", 0);"; //$NON-NLS-1$
|
|
131 |
|
99 |
132 |
public static final String variantscriptRuleFast = "sheet.insertRule(\"#%s {font-variant:%s;}\", 0);"; //$NON-NLS-1$
|
|
133 |
|
100 |
134 |
public static final String famillyscriptRuleFast = "sheet.insertRule(\"#%s {font-familly:%s;}\", 0);"; //$NON-NLS-1$
|
|
135 |
|
101 |
136 |
public static final String weightscriptRuleFast = "sheet.insertRule(\"#%s {font-weight:%s;}\", 0);"; //$NON-NLS-1$
|
102 |
137 |
|
103 |
138 |
public static final String highlightscriptRule = "sheet.insertRule(\"span[id=\\\"%s\\\"] {background-color:rgba(%s,%s,%s,%s); }\", 0);"; //$NON-NLS-1$
|
... | ... | |
105 |
140 |
public static final String clearhighlightscript = "try { var elt = document.getElementById(\"%s\"); elt.style.backgroundColor=\"white\";elt.style.fontWeight=\"\";" + //$NON-NLS-1$
|
106 |
141 |
"} catch (e) { };"; //$NON-NLS-1$
|
107 |
142 |
|
108 |
|
public String functions =
|
109 |
|
""//"alert(\"loading functions\");" //$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$
|
|
143 |
public String functions = ""// "alert(\"loading functions\");" //$NON-NLS-1$
|
|
144 |
+ "\nfunction getNodeText(node) {" //$NON-NLS-1$
|
|
145 |
+ "\n if (typeof node == 'string') return node;" //$NON-NLS-1$
|
|
146 |
+ "\n else if (typeof node.innerText != 'undefined') return node.innerText;" //$NON-NLS-1$
|
|
147 |
+ "\n else if (typeof node.InnerText != 'undefined') return node.InnerText;" //$NON-NLS-1$
|
|
148 |
+ "\n else if (typeof node.textContent != 'undefined') return node.textContent;" //$NON-NLS-1$
|
|
149 |
+ "\n else return null;" //$NON-NLS-1$
|
|
150 |
+ "\n}" //$NON-NLS-1$
|
|
151 |
+ "\nfunction txmGetParent(node) {" //$NON-NLS-1$
|
|
152 |
+ "\n if (typeof node.parentNode != 'undefined') return node.parentNode;" //$NON-NLS-1$
|
|
153 |
+ "\n else return null;" //$NON-NLS-1$
|
|
154 |
+ "\n}" //$NON-NLS-1$
|
|
155 |
+ "\nfunction txmGetChildren(node) {" //$NON-NLS-1$
|
|
156 |
+ "\n if (typeof node == 'string') return 'STRING HTML';" //$NON-NLS-1$
|
|
157 |
+ "\n else if (typeof node.children != 'undefined') return node.children;" //$NON-NLS-1$
|
|
158 |
+ "\n else if (typeof node.ChildNodes != 'undefined') return node.ChildNodes;" //$NON-NLS-1$
|
|
159 |
+ "\n else if (typeof node.childNodes != 'undefined') return node.childNodes;" //$NON-NLS-1$
|
|
160 |
+ "\n else return null;" //$NON-NLS-1$
|
|
161 |
+ "\n}" //$NON-NLS-1$
|
|
162 |
+ "\nfunction txmGetSelection() {" //$NON-NLS-1$
|
|
163 |
+ "\n if (typeof window.getSelection != 'undefined') {return window.getSelection();}" //$NON-NLS-1$
|
|
164 |
+ "\n else if (typeof document.selection != 'undefined') { return document.selection;}" //$NON-NLS-1$
|
|
165 |
+ "\n else return 'NO SELECTION';" //$NON-NLS-1$
|
|
166 |
+ "\n}" //$NON-NLS-1$
|
|
167 |
+ "\nfunction txmGetRangeSize(selection) {" //$NON-NLS-1$
|
|
168 |
+ "\n if (typeof selection.rangeCount != 'undefined') {return selection.rangeCount;}" //$NON-NLS-1$
|
|
169 |
+ "\n else if (typeof selection.createRangeCollection != 'undefined') { return selection.createRangeCollection().length();} // IE5 has no multiple selection" //$NON-NLS-1$
|
|
170 |
+ "\n}" //$NON-NLS-1$
|
|
171 |
+ "\nfunction txmGetRange(selection, i) {" //$NON-NLS-1$
|
|
172 |
+ "\n if (typeof selection.getRangeAt != 'undefined') {return selection.getRangeAt(i);}" //$NON-NLS-1$
|
|
173 |
+ "\n else if (typeof selection.createRangeCollection != 'undefined') {return selection.createRangeCollection().item(i);}" // IE > IE5 //$NON-NLS-1$
|
|
174 |
+ "\n else if (typeof selection.createRange != 'undefined') { return selection.createRange();} // IE5 has no multiple selection" //$NON-NLS-1$
|
|
175 |
+ "\n else return 'NO RANGE';" //$NON-NLS-1$
|
|
176 |
+ "\n}" //$NON-NLS-1$
|
|
177 |
+ "\nfunction txmGetParentElementRange(range) {" //$NON-NLS-1$
|
|
178 |
+ "\n if (typeof range.parentElement != 'undefined') {return range.parentElement();}" //$NON-NLS-1$
|
|
179 |
+ "\n else if (typeof range.startContainer != 'undefined') { return range.startContainer.parentNode;}" //$NON-NLS-1$
|
|
180 |
+ "\n else return 'NO PARENT';" //$NON-NLS-1$
|
|
181 |
+ "\n}" //$NON-NLS-1$
|
|
182 |
+ "\nfunction txmGetFragment(range) {" //$NON-NLS-1$
|
|
183 |
+ "\n if (typeof range.cloneContents != 'undefined') { return range.cloneContents();}" //$NON-NLS-1$
|
|
184 |
+ "\n else if (typeof range.htmlText != 'undefined') {var node = document.createElement('sel'); node.innerHTML = range.htmlText; return node;" //$NON-NLS-1$
|
|
185 |
+ "\n } else return 'NO FRAG';" //$NON-NLS-1$
|
|
186 |
+ "\n}" //$NON-NLS-1$
|
|
187 |
+ "\nfunction txmGetTagName(node) {" //$NON-NLS-1$
|
|
188 |
+ "\n if (typeof node.tagName != 'undefined') {return node.tagName;}" //$NON-NLS-1$
|
|
189 |
+ "\n else if (typeof node.nodeName != 'undefined') { return node.nodeName;}" //$NON-NLS-1$
|
|
190 |
+ "\n else if (typeof node.name != 'undefined') { return node.name;}" //$NON-NLS-1$
|
|
191 |
+ "\n else return 'NO TAGNAME';" //$NON-NLS-1$
|
|
192 |
+ "\n}" //$NON-NLS-1$
|
|
193 |
+ "\nfunction findSpans(children, all) {" //$NON-NLS-1$
|
|
194 |
+ "\n for (var i = 0 ; i < children.length ; i++) {" //$NON-NLS-1$
|
|
195 |
+ "\n var node = children.item(i);" //$NON-NLS-1$
|
|
196 |
+ "\n if (node.nodeType == 1) {" //$NON-NLS-1$
|
|
197 |
+ "\n var id = node.getAttribute('id');" //$NON-NLS-1$
|
|
198 |
+ "\n if (node.tagName == 'SPAN' && id != null && id.indexOf('w_') == 0 && getNodeText(node).length > 0) {" //$NON-NLS-1$
|
|
199 |
+ "\n if (id != null) all.push(id);" //$NON-NLS-1$
|
|
200 |
+ "\n } else {" //$NON-NLS-1$
|
|
201 |
+ "\n findSpans(txmGetChildren(node), all)" //$NON-NLS-1$
|
|
202 |
+ "\n }" //$NON-NLS-1$
|
|
203 |
+ "\n }" //$NON-NLS-1$
|
|
204 |
+ "\n }" //$NON-NLS-1$
|
|
205 |
+ "\n}" //$NON-NLS-1$
|
|
206 |
+ "\nfunction findIdsInString(str, all) {" //$NON-NLS-1$
|
|
207 |
+ "\n for (var i = 0 ; i < children.length ; i++) {" //$NON-NLS-1$
|
|
208 |
+ "\n var node = children.item(i);" //$NON-NLS-1$
|
|
209 |
+ "\n if (node.nodeType == 1) {" //$NON-NLS-1$
|
|
210 |
+ "\n var id = node.getAttribute('id');" //$NON-NLS-1$
|
|
211 |
+ "\n if (node.tagName == 'SPAN' && id != null && id.indexOf('w_') == 0 && getNodeText(node).length > 0) {" //$NON-NLS-1$
|
|
212 |
+ "\n if (id != null) all.push(id);" //$NON-NLS-1$
|
|
213 |
+ "\n } else {" //$NON-NLS-1$
|
|
214 |
+ "\n findSpans(txmGetChildren(node), all)" //$NON-NLS-1$
|
|
215 |
+ "\n }" //$NON-NLS-1$
|
|
216 |
+ "\n }" //$NON-NLS-1$
|
|
217 |
+ "\n }" //$NON-NLS-1$
|
|
218 |
+ "\n}" //$NON-NLS-1$
|
|
219 |
+ "\nfunction get_type(thing){if(thing===null)return \"[object Null]\"; return Object.prototype.toString.call(thing);}\n" //$NON-NLS-1$
|
|
220 |
+ "\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$
|
|
221 |
+ "\nvar sheet = null;" //$NON-NLS-1$
|
|
222 |
+ "\ntry{" //$NON-NLS-1$
|
|
223 |
+ "\n var style = document.createElement(\"style\");" //$NON-NLS-1$
|
|
224 |
+ "\n try { style.appendChild(document.createTextNode(\"\")); } catch (e) {};"// webkit hack //$NON-NLS-1$
|
|
225 |
+ "\n document.body.appendChild(style);" //$NON-NLS-1$
|
|
226 |
+ "\n sheet = style.sheet;" //$NON-NLS-1$
|
|
227 |
+ "\n} catch(e) {sheet='error'}" //$NON-NLS-1$
|
|
228 |
+ "\ntry{" //$NON-NLS-1$
|
|
229 |
+ "\n" // define scrollIntoViewIfNeeded if absent //$NON-NLS-1$
|
|
230 |
+ "\nif (!Element.prototype.scrollIntoViewIfNeeded) {" //$NON-NLS-1$
|
|
231 |
+ "\n Element.prototype.scrollIntoViewIfNeeded = function (centerIfNeeded) {" //$NON-NLS-1$
|
|
232 |
+ "\n centerIfNeeded = arguments.length === 0 ? true : !!centerIfNeeded;" //$NON-NLS-1$
|
|
233 |
+ "\n var parent = this.parentNode," //$NON-NLS-1$
|
|
234 |
+ "\n parentComputedStyle = window.getComputedStyle(parent, null)," //$NON-NLS-1$
|
|
235 |
+ "\n parentBorderTopWidth = parseInt(parentComputedStyle.getPropertyValue('border-top-width'))," //$NON-NLS-1$
|
|
236 |
+ "\n parentBorderLeftWidth = parseInt(parentComputedStyle.getPropertyValue('border-left-width'))," //$NON-NLS-1$
|
|
237 |
+ "\n overTop = this.offsetTop - parent.offsetTop < parent.scrollTop," //$NON-NLS-1$
|
|
238 |
+ "\n overBottom = (this.offsetTop - parent.offsetTop + this.clientHeight - parentBorderTopWidth) > (parent.scrollTop + parent.clientHeight)," //$NON-NLS-1$
|
|
239 |
+ "\n overLeft = this.offsetLeft - parent.offsetLeft < parent.scrollLeft," //$NON-NLS-1$
|
|
240 |
+ "\n overRight = (this.offsetLeft - parent.offsetLeft + this.clientWidth - parentBorderLeftWidth) > (parent.scrollLeft + parent.clientWidth)," //$NON-NLS-1$
|
|
241 |
+ "\n alignWithTop = overTop && !overBottom;" //$NON-NLS-1$
|
|
242 |
+ "\n if ((overTop || overBottom) && centerIfNeeded) {" //$NON-NLS-1$
|
|
243 |
+ "\n parent.scrollTop = this.offsetTop - parent.offsetTop - parent.clientHeight / 2 - parentBorderTopWidth + this.clientHeight / 2;" //$NON-NLS-1$
|
|
244 |
+ "\n }" //$NON-NLS-1$
|
|
245 |
+ "\n if ((overLeft || overRight) && centerIfNeeded) {" //$NON-NLS-1$
|
|
246 |
+ "\n parent.scrollLeft = this.offsetLeft - parent.offsetLeft - parent.clientWidth / 2 - parentBorderLeftWidth + this.clientWidth / 2;" //$NON-NLS-1$
|
|
247 |
+ "\n }" //$NON-NLS-1$
|
|
248 |
+ "\n if ((overTop || overBottom || overLeft || overRight) && !centerIfNeeded) {" //$NON-NLS-1$
|
|
249 |
+ "\n this.scrollIntoView(alignWithTop);" //$NON-NLS-1$
|
|
250 |
+ "\n }" //$NON-NLS-1$
|
|
251 |
+ "\n };" //$NON-NLS-1$
|
|
252 |
+ "\n}" //$NON-NLS-1$
|
|
253 |
+ "\n} catch(e) {Element.prototype.scrollIntoViewIfNeeded = Element.prototype.scrollIntoView}"; //$NON-NLS-1$
|
220 |
254 |
|
221 |
255 |
protected boolean fastWordHighLight = SynopticEditionPreferences.getInstance().getBoolean(SynopticEditionPreferences.FAST_HIGHLIGHT);
|
|
256 |
|
222 |
257 |
private ArrayList<ProgressListener> beforeHighlighListeners;
|
|
258 |
|
223 |
259 |
public ArrayList<ProgressListener> getBeforeHighlighListeners() {
|
224 |
260 |
return beforeHighlighListeners;
|
225 |
261 |
}
|
|
262 |
|
226 |
263 |
private ArrayList<ProgressListener> afterHighlighListeners;
|
|
264 |
|
227 |
265 |
public ArrayList<ProgressListener> getAfterHighlighListeners() {
|
228 |
266 |
return beforeHighlighListeners;
|
229 |
267 |
}
|
|
268 |
|
230 |
269 |
public Object evaluate(String code) {
|
231 |
270 |
if (Log.getLevel().intValue() <= Level.FINEST.intValue()) System.out.println(code);
|
232 |
271 |
return getBrowser().evaluate(code);
|
233 |
272 |
}
|
|
273 |
|
234 |
274 |
public boolean execute(String code) {
|
235 |
275 |
if (Log.getLevel().intValue() <= Level.FINEST.intValue()) System.out.println(code);
|
236 |
276 |
return getBrowser().execute(code);
|
237 |
277 |
}
|
|
278 |
|
238 |
279 |
public EditionPanel(SynopticEditionEditor synopticEditionEditor, Composite parent, int style, Edition edition) {
|
239 |
280 |
super(parent, style);
|
240 |
281 |
this.synopticEditionEditor = synopticEditionEditor;
|
... | ... | |
246 |
287 |
Bundle bundle = Platform.getBundle("org.txm.edition.rcp"); //$NON-NLS-1$
|
247 |
288 |
URL fileURL = bundle.getEntry("res/js/functions.js"); //$NON-NLS-1$
|
248 |
289 |
URL r = FileLocator.resolve(fileURL);
|
249 |
|
Log.fine("Load JS functions from: "+r);
|
|
290 |
Log.fine("Load JS functions from: " + r);
|
250 |
291 |
functions = IOUtils.getText(r, "UTF-8"); //$NON-NLS-1$
|
251 |
292 |
|
252 |
|
} catch (Exception e) {
|
|
293 |
}
|
|
294 |
catch (Exception e) {
|
253 |
295 |
Log.severe(EditionUIMessages.bind(EditionUIMessages.error_while_reading, functionsFile, e.getLocalizedMessage()));
|
254 |
296 |
Log.printStackTrace(e);
|
255 |
297 |
}
|
256 |
298 |
|
257 |
|
beforeHighlighListeners = new ArrayList<ProgressListener>();
|
258 |
|
afterHighlighListeners = new ArrayList<ProgressListener>();
|
|
299 |
beforeHighlighListeners = new ArrayList<>();
|
|
300 |
afterHighlighListeners = new ArrayList<>();
|
259 |
301 |
|
260 |
302 |
progresslistener = new ProgressListener() {
|
261 |
303 |
|
262 |
304 |
@Override
|
263 |
|
public void changed(ProgressEvent event) { }
|
|
305 |
public void changed(ProgressEvent event) {}
|
264 |
306 |
|
265 |
307 |
@Override
|
266 |
308 |
public void completed(ProgressEvent event) {
|
267 |
309 |
|
268 |
|
//System.out.println("EditionPanel "+currentEdition.getName()+" reload "+getCurrentPage().getName());
|
|
310 |
// System.out.println("EditionPanel "+currentEdition.getName()+" reload "+getCurrentPage().getName());
|
269 |
311 |
Object rez = evaluate("return typeof sheet;"); //$NON-NLS-1$
|
270 |
312 |
if ("undefined".equals(rez)) { //$NON-NLS-1$
|
271 |
313 |
if (!execute(functions)) { // build the sheet if not present in the HTML DOM
|
272 |
|
Log.fine("JS execution (init) error with="+functions); //$NON-NLS-1$
|
273 |
|
} else {
|
|
314 |
Log.fine("JS execution (init) error with=" + functions); //$NON-NLS-1$
|
|
315 |
}
|
|
316 |
else {
|
274 |
317 |
|
275 |
318 |
}
|
276 |
319 |
}
|
277 |
320 |
|
278 |
321 |
// do something before the highlight is done
|
279 |
|
for (ProgressListener pl : beforeHighlighListeners) { pl.completed(event);}
|
|
322 |
for (ProgressListener pl : beforeHighlighListeners) {
|
|
323 |
pl.completed(event);
|
|
324 |
}
|
280 |
325 |
|
281 |
326 |
|
282 |
|
//System.out.println("highlight: "+highlightedColorPerWordIDS);
|
|
327 |
// System.out.println("highlight: "+highlightedColorPerWordIDS);
|
283 |
328 |
StringBuilder buffer = new StringBuilder();
|
284 |
|
//buffer.append("alert(\"\"+sheet);\n");
|
|
329 |
// buffer.append("alert(\"\"+sheet);\n");
|
285 |
330 |
if (!fastWordHighLight) {
|
286 |
|
// for (String wordid : highlightedColorPerWordIDS.keySet()) {
|
287 |
|
// buffer.append(String.format(clearhighlightscript, wordid)+"\n");
|
288 |
|
// }
|
289 |
|
} else {
|
|
331 |
// for (String wordid : highlightedColorPerWordIDS.keySet()) {
|
|
332 |
// buffer.append(String.format(clearhighlightscript, wordid)+"\n");
|
|
333 |
// }
|
|
334 |
}
|
|
335 |
else {
|
290 |
336 |
buffer.append("try { while(sheet.cssRules.length > 0) sheet.deleteRule(0); } catch (e) {};\n"); // empty style //$NON-NLS-1$
|
291 |
337 |
}
|
292 |
338 |
|
293 |
339 |
if (buffer.length() > 0) {
|
294 |
340 |
if (!execute(buffer.toString())) {
|
295 |
|
Log.fine("JS execution error (delete cssRules) with="+buffer);
|
|
341 |
Log.fine("JS execution error (delete cssRules) with=" + buffer);
|
296 |
342 |
}
|
297 |
343 |
}
|
298 |
344 |
|
... | ... | |
304 |
350 |
String lastWord = "w_999999999"; //$NON-NLS-1$
|
305 |
351 |
while (nextPage != null && currentPage != nextPage) {
|
306 |
352 |
lastWord = nextPage.getWordId();
|
307 |
|
if (!("w_0".equals(lastWord))) { // this is a word id
|
308 |
|
break; // ok
|
|
353 |
if (!("w_0".equals(lastWord))) { // this is a word id
|
|
354 |
break; // ok
|
309 |
355 |
}
|
310 |
356 |
Page p = currentEdition.getNextPage(nextPage);
|
311 |
357 |
if (p == nextPage) { // end of pages
|
... | ... | |
314 |
360 |
}
|
315 |
361 |
nextPage = p;
|
316 |
362 |
}
|
317 |
|
//System.out.println("firstWord="+firstWord+" lastWord="+lastWord);
|
318 |
|
//int n = 0;
|
319 |
|
//long start = System.currentTimeMillis();
|
|
363 |
// System.out.println("firstWord="+firstWord+" lastWord="+lastWord);
|
|
364 |
// int n = 0;
|
|
365 |
// long start = System.currentTimeMillis();
|
320 |
366 |
|
321 |
367 |
for (String wordid : highlightedColorPerWordIDS.keySet()) {
|
322 |
|
//Log.finest("words to highlight: "+highlightedColorPerWordIDS);
|
|
368 |
// Log.finest("words to highlight: "+highlightedColorPerWordIDS);
|
323 |
369 |
if (highlightedColorPerWordIDS.get(wordid).size() == 0) continue; // error
|
324 |
370 |
|
325 |
|
//if (!slowWordHighLight) { //TODO: this code must be replaced with word position instead of word id comparaison
|
|
371 |
// if (!slowWordHighLight) { //TODO: this code must be replaced with word position instead of word id comparaison
|
326 |
372 |
if (Edition.isFirstGTthanSecond(wordid, firstWord) < 0) continue; // skip the word to highlight
|
327 |
373 |
if (Edition.isFirstGTthanSecond(lastWord, wordid) < 0) continue; // skip the word to highlight
|
328 |
|
//}
|
329 |
|
//n++;
|
330 |
|
RGBA composite = new RGBA(0,0,0,0f);
|
|
374 |
// }
|
|
375 |
// n++;
|
|
376 |
RGBA composite = new RGBA(0, 0, 0, 0f);
|
331 |
377 |
int size = highlightedColorPerWordIDS.get(wordid).size();
|
332 |
378 |
|
333 |
379 |
for (RGBA color : highlightedColorPerWordIDS.get(wordid)) {
|
... | ... | |
343 |
389 |
|
344 |
390 |
String s = null;
|
345 |
391 |
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$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
|
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$
|
|
392 |
// s = String.format(highlightscriptRule, wordid, composite.r, composite.g, composite.b, composite.a);
|
|
393 |
s = "try { document.getElementById(\"" + wordid + "\").style.backgroundColor=\"rgba(" + composite.r + "," + composite.g + "," + composite.b + "," + composite.a + ")\";" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
|
|
394 |
+
|
|
395 |
// "elt.style.paddingLeft=\"3px\";" + //$NON-NLS-1$
|
|
396 |
// "elt.style.paddingRight=\"3px\";" + //$NON-NLS-1$
|
|
397 |
// "elt.style.paddingTop=\"1px\";" + //$NON-NLS-1$
|
|
398 |
// "elt.style.paddingBottom=\"1px\";" + //$NON-NLS-1$
|
353 |
399 |
"} catch (e) { };"; //$NON-NLS-1$
|
354 |
|
} else {
|
355 |
|
//TODO: replace this line with the next one for TXM 0.7.9
|
|
400 |
}
|
|
401 |
else {
|
|
402 |
// TODO: replace this line with the next one for TXM 0.7.9
|
356 |
403 |
s = String.format(highlightscriptRuleFast, wordid.replace(" ", "\\ "), composite.r, composite.g, composite.b, composite.a); //$NON-NLS-1$ //$NON-NLS-2$
|
357 |
|
// s = String.format(highlightscriptRuleFast, wordid, composite.r, composite.g, composite.b, composite.a);
|
|
404 |
// s = String.format(highlightscriptRuleFast, wordid, composite.r, composite.g, composite.b, composite.a);
|
358 |
405 |
}
|
359 |
406 |
|
360 |
|
buffer.append(s+"\n"); //$NON-NLS-1$
|
|
407 |
buffer.append(s + "\n"); //$NON-NLS-1$
|
361 |
408 |
}
|
362 |
409 |
|
363 |
410 |
if (buffer.length() > 0) {
|
364 |
411 |
if (!execute(buffer.toString())) {
|
365 |
|
Log.fine("JS execution (highlight) error with="+buffer);
|
|
412 |
Log.fine("JS execution (highlight) error with=" + buffer);
|
366 |
413 |
}
|
367 |
414 |
}
|
368 |
415 |
|
369 |
416 |
|
370 |
417 |
buffer = new StringBuilder();
|
371 |
418 |
|
372 |
|
// for (String wordidslist : highlightedColorSpans.keySet()) {
|
373 |
|
// RGBA composite = new RGBA(0,0,0,0f);
|
374 |
|
// int size = highlightedColorSpans.get(wordidslist).size();
|
375 |
|
//
|
376 |
|
// for (RGBA color : highlightedColorSpans.get(wordidslist)) {
|
377 |
|
// composite.r += color.r;
|
378 |
|
// composite.g += color.g;
|
379 |
|
// composite.b += color.b;
|
380 |
|
// composite.a += color.a;
|
381 |
|
// }
|
382 |
|
//
|
383 |
|
// composite.r /= size;
|
384 |
|
// composite.g /= size;
|
385 |
|
// composite.b /= size;
|
386 |
|
//
|
387 |
|
// String cmd = "var l = "+wordidslist+";\n";
|
388 |
|
// cmd += "wrap(l, \""+wordidslist+"\";\n";
|
389 |
|
// buffer.append(cmd+"\n");
|
390 |
|
// }
|
|
419 |
// for (String wordidslist : highlightedColorSpans.keySet()) {
|
|
420 |
// RGBA composite = new RGBA(0,0,0,0f);
|
|
421 |
// int size = highlightedColorSpans.get(wordidslist).size();
|
|
422 |
//
|
|
423 |
// for (RGBA color : highlightedColorSpans.get(wordidslist)) {
|
|
424 |
// composite.r += color.r;
|
|
425 |
// composite.g += color.g;
|
|
426 |
// composite.b += color.b;
|
|
427 |
// composite.a += color.a;
|
|
428 |
// }
|
|
429 |
//
|
|
430 |
// composite.r /= size;
|
|
431 |
// composite.g /= size;
|
|
432 |
// composite.b /= size;
|
|
433 |
//
|
|
434 |
// String cmd = "var l = "+wordidslist+";\n";
|
|
435 |
// cmd += "wrap(l, \""+wordidslist+"\";\n";
|
|
436 |
// buffer.append(cmd+"\n");
|
|
437 |
// }
|
391 |
438 |
|
392 |
439 |
for (String wordid : fontColorPerWordIDS.keySet()) {
|
393 |
|
RGBA composite = new RGBA(0,0,0,0f);
|
|
440 |
RGBA composite = new RGBA(0, 0, 0, 0f);
|
394 |
441 |
int size = fontColorPerWordIDS.get(wordid).size();
|
395 |
442 |
|
396 |
443 |
for (RGBA color : fontColorPerWordIDS.get(wordid)) {
|
... | ... | |
405 |
452 |
composite.b /= size;
|
406 |
453 |
|
407 |
454 |
String s = String.format(colorscriptRuleFast, wordid, composite.r, composite.g, composite.b, composite.a);
|
408 |
|
buffer.append(s+"\n"); //$NON-NLS-1$
|
|
455 |
buffer.append(s + "\n"); //$NON-NLS-1$
|
409 |
456 |
}
|
410 |
457 |
|
411 |
458 |
if (buffer.length() > 0) {
|
412 |
459 |
if (!execute(buffer.toString())) {
|
413 |
|
Log.fine("JS execution (color) error with="+buffer);
|
|
460 |
Log.fine("JS execution (color) error with=" + buffer);
|
414 |
461 |
}
|
415 |
462 |
}
|
416 |
463 |
|
... | ... | |
419 |
466 |
|
420 |
467 |
for (String wordid : fontSizePerWordIDS.keySet()) {
|
421 |
468 |
String s = String.format(sizescriptRuleFast, wordid, fontSizePerWordIDS.get(wordid));
|
422 |
|
buffer.append(s+"\n"); //$NON-NLS-1$
|
|
469 |
buffer.append(s + "\n"); //$NON-NLS-1$
|
423 |
470 |
}
|
424 |
471 |
|
425 |
472 |
for (String wordid : fontWeightPerWordIDS.keySet()) {
|
426 |
473 |
String s = null;
|
427 |
474 |
if (!fastWordHighLight) {
|
428 |
|
//s = String.format(highlightscriptRule, wordid, composite.r, composite.g, composite.b, composite.a);
|
429 |
|
s = "try { document.getElementById(\"" + wordid + "\").style.fontWeight=\""+fontWeightPerWordIDS.get(wordid)+"\";" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
430 |
|
+
|
431 |
|
// "elt.style.paddingLeft=\"3px\";" + //$NON-NLS-1$
|
432 |
|
// "elt.style.paddingRight=\"3px\";" + //$NON-NLS-1$
|
433 |
|
// "elt.style.paddingTop=\"1px\";" + //$NON-NLS-1$
|
434 |
|
// "elt.style.paddingBottom=\"1px\";" + //$NON-NLS-1$
|
|
475 |
// s = String.format(highlightscriptRule, wordid, composite.r, composite.g, composite.b, composite.a);
|
|
476 |
s = "try { document.getElementById(\"" + wordid + "\").style.fontWeight=\"" + fontWeightPerWordIDS.get(wordid) + "\";" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
477 |
+
|
|
478 |
// "elt.style.paddingLeft=\"3px\";" + //$NON-NLS-1$
|
|
479 |
// "elt.style.paddingRight=\"3px\";" + //$NON-NLS-1$
|
|
480 |
// "elt.style.paddingTop=\"1px\";" + //$NON-NLS-1$
|
|
481 |
// "elt.style.paddingBottom=\"1px\";" + //$NON-NLS-1$
|
435 |
482 |
"} catch (e) { };"; //$NON-NLS-1$
|
436 |
|
//s = String.format(highlightscriptRule, wordid, composite.r, composite.g, composite.b, composite.a);
|
437 |
|
// s = "try { var elt = document.getElementById(\"" + wordid + "\");" + //$NON-NLS-1$ //$NON-NLS-2$
|
438 |
|
// "elt.style.fontWeight=\""+fontWeightPerWordIDS.get(wordid)+"\";" + //$NON-NLS-1$
|
439 |
|
//// "elt.style.paddingLeft=\"3px\";" + //$NON-NLS-1$
|
440 |
|
//// "elt.style.paddingRight=\"3px\";" + //$NON-NLS-1$
|
441 |
|
//// "elt.style.paddingTop=\"1px\";" + //$NON-NLS-1$
|
442 |
|
//// "elt.style.paddingBottom=\"1px\";" + //$NON-NLS-1$
|
443 |
|
// "} catch (e) { };"; //$NON-NLS-1$
|
444 |
|
} else {
|
|
483 |
// s = String.format(highlightscriptRule, wordid, composite.r, composite.g, composite.b, composite.a);
|
|
484 |
// s = "try { var elt = document.getElementById(\"" + wordid + "\");" + //$NON-NLS-1$ //$NON-NLS-2$
|
|
485 |
// "elt.style.fontWeight=\""+fontWeightPerWordIDS.get(wordid)+"\";" + //$NON-NLS-1$
|
|
486 |
//// "elt.style.paddingLeft=\"3px\";" + //$NON-NLS-1$
|
|
487 |
//// "elt.style.paddingRight=\"3px\";" + //$NON-NLS-1$
|
|
488 |
//// "elt.style.paddingTop=\"1px\";" + //$NON-NLS-1$
|
|
489 |
//// "elt.style.paddingBottom=\"1px\";" + //$NON-NLS-1$
|
|
490 |
// "} catch (e) { };"; //$NON-NLS-1$
|
|
491 |
}
|
|
492 |
else {
|
445 |
493 |
s = String.format(weightscriptRuleFast, wordid, fontWeightPerWordIDS.get(wordid));
|
446 |
494 |
}
|
447 |
|
buffer.append(s+"\n"); //$NON-NLS-1$
|
|
495 |
buffer.append(s + "\n"); //$NON-NLS-1$
|
448 |
496 |
}
|
449 |
497 |
|
450 |
498 |
for (String wordid : fontFamillyPerWordIDS.keySet()) {
|
451 |
499 |
String s = String.format(famillyscriptRuleFast, wordid, fontFamillyPerWordIDS.get(wordid));
|
452 |
|
buffer.append(s+"\n"); //$NON-NLS-1$
|
|
500 |
buffer.append(s + "\n"); //$NON-NLS-1$
|
453 |
501 |
}
|
454 |
502 |
|
455 |
503 |
if (buffer.length() > 0) {
|
456 |
504 |
if (!execute(buffer.toString())) {
|
457 |
|
Log.fine("JS execution (font) error with="+buffer);
|
|
505 |
Log.fine("JS execution (font) error with=" + buffer);
|
458 |
506 |
}
|
459 |
507 |
}
|
460 |
508 |
|
... | ... | |
462 |
510 |
buffer = new StringBuilder();
|
463 |
511 |
|
464 |
512 |
if (focusedWordID != null) {
|
465 |
|
//System.out.println("Focus on: "+focusedWordID);
|
|
513 |
// System.out.println("Focus on: "+focusedWordID);
|
466 |
514 |
String s = "try { showElementIfNeeded(document.getElementById(\"" + focusedWordID + "\")); } catch (e) {document.getElementById(\"" + focusedWordID + "\").scrollIntoView();};"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
467 |
|
buffer.append(s+"\n"); //$NON-NLS-1$
|
|
515 |
buffer.append(s + "\n"); //$NON-NLS-1$
|
468 |
516 |
}
|
469 |
517 |
|
470 |
518 |
if (buffer.length() > 0) {
|
471 |
519 |
if (execute(buffer.toString())) {
|
472 |
520 |
focusedWordID = null; // focus one time
|
473 |
|
} else {
|
474 |
|
Log.fine("JS execution (focus) error with="+buffer);
|
475 |
521 |
}
|
|
522 |
else {
|
|
523 |
Log.fine("JS execution (focus) error with=" + buffer);
|
|
524 |
}
|
476 |
525 |
}
|
477 |
526 |
|
478 |
527 |
|
... | ... | |
481 |
530 |
if (highlightedAreas != null) {
|
482 |
531 |
for (int[] pos : highlightedAreas) {
|
483 |
532 |
if (pos == null || pos.length != 4) continue;
|
484 |
|
String s = "try {v.setFocusOn("+pos[0]+", "+pos[1]+", "+pos[2]+", "+pos[3]+");} catch (e) { };"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
|
485 |
|
buffer.append(s+"\n"); //$NON-NLS-1$
|
|
533 |
String s = "try {v.setFocusOn(" + pos[0] + ", " + pos[1] + ", " + pos[2] + ", " + pos[3] + ");} catch (e) { };"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
|
|
534 |
buffer.append(s + "\n"); //$NON-NLS-1$
|
486 |
535 |
break;// one word only for now
|
487 |
536 |
}
|
488 |
537 |
}
|
489 |
538 |
|
490 |
|
//System.out.println(buffer);
|
|
539 |
// System.out.println(buffer);
|
491 |
540 |
if (buffer.length() > 0) {
|
492 |
541 |
if (!execute(buffer.toString())) {
|
493 |
|
Log.fine("JS execution (area focus) error with="+buffer);
|
|
542 |
Log.fine("JS execution (area focus) error with=" + buffer);
|
494 |
543 |
}
|
495 |
544 |
}
|
496 |
|
//System.out.println("n="+n+" time="+(System.currentTimeMillis()-start));
|
|
545 |
// System.out.println("n="+n+" time="+(System.currentTimeMillis()-start));
|
497 |
546 |
|
498 |
547 |
// do something after the highlight is done
|
499 |
|
for (ProgressListener pl : afterHighlighListeners) { pl.completed(event);}
|
|
548 |
for (ProgressListener pl : afterHighlighListeners) {
|
|
549 |
pl.completed(event);
|
|
550 |
}
|
500 |
551 |
}
|
501 |
552 |
};
|
502 |
553 |
|
503 |
554 |
getBrowser().addMouseListener(new MouseListener() {
|
504 |
555 |
|
505 |
556 |
boolean dblClick = false;
|
|
557 |
|
506 |
558 |
boolean debug = false;
|
507 |
|
private int t,x,y;
|
508 |
559 |
|
|
560 |
private int t, x, y;
|
|
561 |
|
509 |
562 |
@Override
|
510 |
563 |
public void mouseDoubleClick(MouseEvent e) {
|
511 |
564 |
if (debug) System.out.println("DOUBLE CLICK"); //$NON-NLS-1$
|
512 |
|
dblClick= true;
|
|
565 |
dblClick = true;
|
513 |
566 |
}
|
514 |
567 |
|
515 |
568 |
@Override
|
... | ... | |
531 |
584 |
EditionPanel panel = EditionPanel.this;
|
532 |
585 |
|
533 |
586 |
// 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)));
|
|
587 |
// 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 |
588 |
if (e.count > 1) {
|
536 |
589 |
if (debug) System.out.println(" DOUBLE CLICK"); //$NON-NLS-1$
|
537 |
|
//System.out.println("not a simple click");
|
|
590 |
// System.out.println("not a simple click");
|
538 |
591 |
return;
|
539 |
592 |
}
|
540 |
593 |
|
541 |
594 |
int dist = Math.abs(e.x - x) + Math.abs(e.y - y);
|
542 |
|
int deltat = (e.time-t);
|
543 |
|
//System.out.println("deltat ="+deltat);
|
|
595 |
int deltat = (e.time - t);
|
|
596 |
// System.out.println("deltat ="+deltat);
|
544 |
597 |
if (dist >= 0 && (deltat > 0 || dist > 0)) {
|
545 |
|
//System.out.println(" DRAG dist="+dist+" deltat="+deltat);
|
|
598 |
// System.out.println(" DRAG dist="+dist+" deltat="+deltat);
|
546 |
599 |
String[] ids = panel.getWordSelection(); // may be null
|
547 |
600 |
|
548 |
601 |
panel.expandSelectionTo(ids);
|
... | ... | |
552 |
605 |
});
|
553 |
606 |
|
554 |
607 |
getBrowser().addProgressListener(progresslistener);
|
555 |
|
new CommandLink (synopticEditionEditor, getBrowser());
|
556 |
|
new EditionLink (synopticEditionEditor, getBrowser());
|
|
608 |
new CommandLink(synopticEditionEditor, getBrowser());
|
|
609 |
new EditionLink(synopticEditionEditor, getBrowser());
|
557 |
610 |
}
|
558 |
611 |
|
559 |
612 |
/**
|
560 |
613 |
* Bypass BrowserViewer restriction on the getBrowser method
|
561 |
614 |
*/
|
|
615 |
@Override
|
562 |
616 |
public Browser getBrowser() {
|
563 |
617 |
return super.getBrowser();
|
564 |
618 |
}
|
... | ... | |
567 |
621 |
* Bypass BrowserViewer restriction on the getBrowser method
|
568 |
622 |
*/
|
569 |
623 |
public String getDOM() {
|
570 |
|
return "";//execute("return document.innerHTML"; //$NON-NLS-1$
|
|
624 |
return "";// execute("return document.innerHTML"; //$NON-NLS-1$
|
571 |
625 |
}
|
572 |
626 |
|
573 |
627 |
public ISelectionProvider getSelectionProvider() {
|
... | ... | |
579 |
633 |
if (this.highlightedColorPerWordIDS.get(wordid) != null) {
|
580 |
634 |
removeHighlightWordsById(color, wordid);
|
581 |
635 |
}
|
582 |
|
ArrayList<RGBA> hs = new ArrayList<RGBA>();
|
|
636 |
ArrayList<RGBA> hs = new ArrayList<>();
|
583 |
637 |
this.highlightedColorPerWordIDS.put(wordid, hs);
|
584 |
638 |
hs.add(color);
|
585 |
639 |
}
|
... | ... | |
606 |
660 |
}
|
607 |
661 |
|
608 |
662 |
public void removeHighlightWordsById(RGBA color, Collection<String> wordids) {
|
609 |
|
//System.out.println("Call removeHighlightWordsById: "+wordids+" color="+color);
|
|
663 |
// System.out.println("Call removeHighlightWordsById: "+wordids+" color="+color);
|
610 |
664 |
StringBuffer buffer = new StringBuffer();
|
611 |
665 |
for (String wordid : wordids) {
|
612 |
666 |
removeHighlightWordsById(color, wordid);
|
613 |
667 |
if (!fastWordHighLight) {
|
614 |
|
buffer.append(String.format(clearhighlightscript, wordid)+"\n"); //$NON-NLS-1$
|
|
668 |
buffer.append(String.format(clearhighlightscript, wordid) + "\n"); //$NON-NLS-1$
|
615 |
669 |
}
|
616 |
670 |
}
|
617 |
671 |
|
... | ... | |
621 |
675 |
public void removeHighlightWordsById(RGBA color, String wordid) {
|
622 |
676 |
if (highlightedColorPerWordIDS.get(wordid) == null) return; // nothing to do
|
623 |
677 |
|
624 |
|
//System.out.println("remove color="+color+" from id="+wordid);
|
|
678 |
// System.out.println("remove color="+color+" from id="+wordid);
|
625 |
679 |
this.highlightedColorPerWordIDS.get(wordid).remove(color);
|
626 |
680 |
|
627 |
681 |
if (this.highlightedColorPerWordIDS.get(wordid).size() == 0) {
|
... | ... | |
631 |
685 |
|
632 |
686 |
/**
|
633 |
687 |
* Open the page containing the word with ID=$line_wordid
|
|
688 |
*
|
634 |
689 |
* @param line_wordid
|
635 |
690 |
* @return true if the page changed
|
636 |
691 |
*/
|
... | ... | |
644 |
699 |
System.out.println(s);
|
645 |
700 |
StatusLine.setMessage(s);
|
646 |
701 |
Log.severe(s);
|
647 |
|
} else {
|
|
702 |
}
|
|
703 |
else {
|
648 |
704 |
Page openedPage = null;
|
649 |
705 |
if (line_wordid != null && line_wordid.length() > 0) {
|
650 |
706 |
openedPage = edition.getPageForWordId(line_wordid);
|
651 |
|
} else {
|
|
707 |
}
|
|
708 |
else {
|
652 |
709 |
openedPage = edition.getFirstPage();
|
653 |
710 |
}
|
654 |
711 |
if (openedPage != null && openedPage != currentPage) {
|
... | ... | |
674 |
731 |
|
675 |
732 |
this.setURL(currentPage.toURL());
|
676 |
733 |
|
677 |
|
//page_label.setText(makePageLabel());
|
|
734 |
// page_label.setText(makePageLabel());
|
678 |
735 |
}
|
679 |
736 |
|
|
737 |
@Override
|
680 |
738 |
public void setURL(String url) {
|
681 |
739 |
if (!this.browser.isDisposed()) {
|
682 |
740 |
super.setURL(url);
|
... | ... | |
707 |
765 |
|
708 |
766 |
if (previous == currentPage) {
|
709 |
767 |
previousText(true);
|
710 |
|
} else {
|
|
768 |
}
|
|
769 |
else {
|
711 |
770 |
currentPage = previous;
|
712 |
771 |
this.setURL(currentPage.toURL());
|
713 |
772 |
}
|
714 |
773 |
currentText = currentEdition.getText();
|
715 |
|
} else {
|
|
774 |
}
|
|
775 |
else {
|
716 |
776 |
firstPage();
|
717 |
777 |
}
|
718 |
|
//page_label.setText(makePageLabel());
|
|
778 |
// page_label.setText(makePageLabel());
|
719 |
779 |
}
|
720 |
780 |
|
721 |
781 |
|
... | ... | |
729 |
789 |
Page next = currentEdition.getNextPage(currentPage);
|
730 |
790 |
if (next == currentPage) {
|
731 |
791 |
nextText();
|
732 |
|
} else {
|
|
792 |
}
|
|
793 |
else {
|
733 |
794 |
currentPage = next;
|
734 |
795 |
this.setURL(currentPage.toURL());
|
735 |
796 |
}
|
736 |
797 |
currentText = currentEdition.getText();
|
737 |
|
} else {
|
|
798 |
}
|
|
799 |
else {
|
738 |
800 |
firstPage();
|
739 |
801 |
}
|
740 |
|
//page_label.setText(makePageLabel());
|
|
802 |
// page_label.setText(makePageLabel());
|
741 |
803 |
}
|
742 |
804 |
|
743 |
805 |
|
744 |
806 |
public void firstText() {
|
745 |
|
//Text current = this.currentPage.getEdition().getText();
|
|
807 |
// Text current = this.currentPage.getEdition().getText();
|
746 |
808 |
Project project = currentText.getProject();
|
747 |
809 |
String id;
|
748 |
810 |
try {
|
749 |
811 |
id = this.synopticEditionEditor.getCorpus().getCorpusTextIdsList()[0];
|
750 |
|
} catch (Exception e) {
|
|
812 |
}
|
|
813 |
catch (Exception e) {
|
751 |
814 |
Log.printStackTrace(e);
|
752 |
815 |
return;
|
753 |
816 |
}
|
... | ... | |
761 |
824 |
return;
|
762 |
825 |
}
|
763 |
826 |
currentEdition = tmp;
|
764 |
|
currentPage = currentEdition.getFirstPage();
|
|
827 |
currentPage = currentEdition.getFirstPage();
|
765 |
828 |
currentText = firstText;
|
766 |
829 |
if (currentPage == null) {
|
767 |
830 |
StatusLine.setMessage("No previous text"); //$NON-NLS-1$
|
... | ... | |
775 |
838 |
* Next text.
|
776 |
839 |
*/
|
777 |
840 |
public void lastText() {
|
778 |
|
//Text current = this.currentPage.getEdition().getText();
|
|
841 |
// Text current = this.currentPage.getEdition().getText();
|
779 |
842 |
Project project = currentText.getProject();
|
780 |
843 |
String id;
|
781 |
844 |
try {
|
782 |
845 |
String[] ids = this.synopticEditionEditor.getCorpus().getCorpusTextIdsList();
|
783 |
|
id = ids[ids.length-1];
|
784 |
|
} catch (Exception e) {
|
|
846 |
id = ids[ids.length - 1];
|
|
847 |
}
|
|
848 |
catch (Exception e) {
|
785 |
849 |
Log.printStackTrace(e);
|
786 |
850 |
return;
|
787 |
851 |
}
|
... | ... | |
796 |
860 |
}
|
797 |
861 |
|
798 |
862 |
currentEdition = tmp;
|
799 |
|
currentPage = currentEdition.getFirstPage();
|
|
863 |
currentPage = currentEdition.getFirstPage();
|
800 |
864 |
currentText = lastText;
|
801 |
865 |
if (currentPage == null) {
|
802 |
866 |
StatusLine.setMessage("No text next"); //$NON-NLS-1$
|
... | ... | |
804 |
868 |
}
|
805 |
869 |
|
806 |
870 |
this.setURL(currentPage.toURL());
|
807 |
|
//page_label.setText(makePageLabel());
|
|
871 |
// page_label.setText(makePageLabel());
|
808 |
872 |
}
|
809 |
873 |
// System.out.println("Next texts "+nextText);
|
810 |
874 |
}
|
811 |
875 |
|
812 |
876 |
/**
|
813 |
877 |
* Previous text.
|
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
|
|
878 |
*
|
|
879 |
* @param fromNextText if true it means the user was reading the next text and then we show the last page of the previous text
|
815 |
880 |
*/
|
816 |
881 |
public void previousText(boolean fromNextText) {
|
817 |
882 |
|
... | ... | |
821 |
886 |
String[] ids = this.synopticEditionEditor.getCorpus().getCorpusTextIdsList();
|
822 |
887 |
String currentId = currentText.getName();
|
823 |
888 |
int idx = 0;
|
824 |
|
for (int i = 0 ; i < ids.length ;i++) {
|
|
889 |
for (int i = 0; i < ids.length; i++) {
|
825 |
890 |
if (currentId.equals(ids[i])) {
|
826 |
891 |
idx = i;
|
827 |
892 |
break;
|
... | ... | |
829 |
894 |
}
|
830 |
895 |
if (idx > 0) idx--;
|
831 |
896 |
id = ids[idx];
|
832 |
|
} catch (Exception e) {
|
|
897 |
}
|
|
898 |
catch (Exception e) {
|
833 |
899 |
e.printStackTrace();
|
834 |
900 |
return;
|
835 |
901 |
}
|
... | ... | |
846 |
912 |
currentEdition = tmp;
|
847 |
913 |
currentText = previousText;
|
848 |
914 |
if (fromNextText) {
|
849 |
|
currentPage = currentEdition.getLastPage();
|
850 |
|
} else {
|
851 |
|
currentPage = currentEdition.getFirstPage();
|
|
915 |
currentPage = currentEdition.getLastPage();
|
852 |
916 |
}
|
|
917 |
else {
|
|
918 |
currentPage = currentEdition.getFirstPage();
|
|
919 |
}
|
853 |
920 |
|
854 |
921 |
if (currentPage == null) {
|
855 |
922 |
StatusLine.setMessage("No previous text"); //$NON-NLS-1$
|
... | ... | |
864 |
931 |
* Next text.
|
865 |
932 |
*/
|
866 |
933 |
public void nextText() {
|
867 |
|
//Text current = this.currentPage.getEdition().getText();
|
|
934 |
// Text current = this.currentPage.getEdition().getText();
|
868 |
935 |
Project project = currentText.getProject();
|
869 |
936 |
String id;
|
870 |
937 |
try {
|
871 |
938 |
String[] ids = this.synopticEditionEditor.getCorpus().getCorpusTextIdsList();
|
872 |
939 |
String currentId = currentText.getName();
|
873 |
940 |
int idx = 0;
|
874 |
|
for (int i = 0 ; i < ids.length ;i++) {
|
|
941 |
for (int i = 0; i < ids.length; i++) {
|
875 |
942 |
if (currentId.equals(ids[i])) {
|
876 |
943 |
idx = i;
|
877 |
944 |
break;
|
... | ... | |
879 |
946 |
}
|
880 |
947 |
if (idx < ids.length - 1) idx++;
|
881 |
948 |
id = ids[idx];
|
882 |
|
} catch (Exception e) {
|
|
949 |
}
|
|
950 |
catch (Exception e) {
|
883 |
951 |
e.printStackTrace();
|
884 |
952 |
return;
|
885 |
953 |
}
|
... | ... | |
894 |
962 |
}
|
895 |
963 |
currentEdition = tmp;
|
896 |
964 |
|
897 |
|
currentPage = currentEdition.getFirstPage();
|
|
965 |
currentPage = currentEdition.getFirstPage();
|
898 |
966 |
currentText = nextText;
|
899 |
967 |
if (currentPage == null) {
|
900 |
968 |
StatusLine.setMessage("No text next"); //$NON-NLS-1$
|
... | ... | |
902 |
970 |
}
|
903 |
971 |
|
904 |
972 |
this.setURL(currentPage.toURL());
|
905 |
|
//page_label.setText(makePageLabel());
|
|
973 |
// page_label.setText(makePageLabel());
|
906 |
974 |
}
|
907 |
975 |
// System.out.println("Next texts "+nextText);
|
908 |
976 |
}
|
... | ... | |
917 |
985 |
}
|
918 |
986 |
|
919 |
987 |
currentEdition = tmp;
|
920 |
|
currentPage = currentEdition.getFirstPage();
|
|
988 |
currentPage = currentEdition.getFirstPage();
|
921 |
989 |
currentText = text;
|
922 |
990 |
if (currentPage == null) {
|
923 |
991 |
StatusLine.setMessage("No text next"); //$NON-NLS-1$
|
... | ... | |
927 |
995 |
if (refresh) {
|
928 |
996 |
this.setURL(currentPage.toURL());
|
929 |
997 |
}
|
930 |
|
//page_label.setText(makePageLabel());
|
|
998 |
// page_label.setText(makePageLabel());
|
931 |
999 |
}
|
932 |
1000 |
|
933 |
1001 |
/**
|
... | ... | |
963 |
1031 |
* @param page the page
|
964 |
1032 |
*/
|
965 |
1033 |
public void showPage(Page page) {
|
966 |
|
//System.out.println("SHOW PAGE "+page);
|
|
1034 |
// System.out.println("SHOW PAGE "+page);
|
967 |
1035 |
currentEdition = page.getEdition();
|
968 |
1036 |
currentText = currentEdition.getText();
|
969 |
1037 |
currentPage = page;
|
... | ... | |
974 |
1042 |
this.setURL(currentPage.toURL());
|
975 |
1043 |
}
|
976 |
1044 |
|
977 |
|
// /**
|
978 |
|
// * Sets the edition.
|
979 |
|
// *
|
980 |
|
// * @param edition the new edition
|
981 |
|
// */
|
982 |
|
// public void setEdition(Edition edition) {
|
983 |
|
// this.currentEdition = edition;
|
984 |
|
// }
|
|
1045 |
// /**
|
|
1046 |
// * Sets the edition.
|
|
1047 |
// *
|
|
1048 |
// * @param edition the new edition
|
|
1049 |
// */
|
|
1050 |
// public void setEdition(Edition edition) {
|
|
1051 |
// this.currentEdition = edition;
|
|
1052 |
// }
|
985 |
1053 |
|
986 |
|
static String SCRIPT01 = "var html = \"\";"+ //$NON-NLS-1$
|
987 |
|
"if (typeof window.getSelection != \"undefined\") {"+ // modern Web browsers //$NON-NLS-1$
|
988 |
|
"var sel = window.getSelection();"+ //$NON-NLS-1$
|
989 |
|
"if (sel.rangeCount) {"+ //$NON-NLS-1$
|
990 |
|
"var container = document.createElement(\"div\");"+ //$NON-NLS-1$
|
991 |
|
"for (var i = 0, len = sel.rangeCount; i < len; ++i) {"+ //$NON-NLS-1$
|
992 |
|
"container.appendChild(sel.getRangeAt(i).cloneContents());"+ //$NON-NLS-1$
|
993 |
|
"}"+ //$NON-NLS-1$
|
994 |
|
"html = container.innerHTML;"+ //$NON-NLS-1$
|
995 |
|
"}"+ //$NON-NLS-1$
|
996 |
|
"} else if (typeof document.selection != \"undefined\") {"+ // for IE < 11 //$NON-NLS-1$
|
997 |
|
"if (document.selection.type == \"Text\") {"+ //$NON-NLS-1$
|
998 |
|
"html = document.selection.createRange().htmlText;"+ //$NON-NLS-1$
|
|
1054 |
static String SCRIPT01 = "var html = \"\";" + //$NON-NLS-1$
|
|
1055 |
"if (typeof window.getSelection != \"undefined\") {" + // modern Web browsers //$NON-NLS-1$
|
|
1056 |
"var sel = window.getSelection();" + //$NON-NLS-1$
|
|
1057 |
"if (sel.rangeCount) {" + //$NON-NLS-1$
|
|
1058 |
"var container = document.createElement(\"div\");" + //$NON-NLS-1$
|
|
1059 |
"for (var i = 0, len = sel.rangeCount; i < len; ++i) {" + //$NON-NLS-1$
|
|
1060 |
"container.appendChild(sel.getRangeAt(i).cloneContents());" + //$NON-NLS-1$
|
999 |
1061 |
"}" + //$NON-NLS-1$
|
|
1062 |
"html = container.innerHTML;" + //$NON-NLS-1$
|
1000 |
1063 |
"}" + //$NON-NLS-1$
|
|
1064 |
"} else if (typeof document.selection != \"undefined\") {" + // for IE < 11 //$NON-NLS-1$
|
|
1065 |
"if (document.selection.type == \"Text\") {" + //$NON-NLS-1$
|
|
1066 |
"html = document.selection.createRange().htmlText;" + //$NON-NLS-1$
|
|
1067 |
"}" + //$NON-NLS-1$
|
|
1068 |
"}" + //$NON-NLS-1$
|
1001 |
1069 |
"return html"; //$NON-NLS-1$
|
1002 |
1070 |
|
1003 |
1071 |
public String getTextSelectionDOM() {
|
... | ... | |
1010 |
1078 |
*/
|
1011 |
1079 |
public String[] getWordSelection() {
|
1012 |
1080 |
|
1013 |
|
//System.out.println("getWordSelection");
|
1014 |
|
String SCRIPT02_getspans = ""//functions //$NON-NLS-1$
|
1015 |
|
+"var all = [];" //$NON-NLS-1$
|
1016 |
|
+"\nvar sel = txmGetSelection();" //$NON-NLS-1$
|
1017 |
|
+"\nif (sel.rangeCount == 0) {return all;}" //$NON-NLS-1$
|
1018 |
|
//+"\nalert('sel='+sel);"
|
1019 |
|
+"\nvar range = txmGetRange(sel, 0);" //$NON-NLS-1$
|
1020 |
|
//+"\nalert('range='+range);"
|
1021 |
|
+"\nvar frag = txmGetFragment(range);" //$NON-NLS-1$
|
1022 |
|
//+"\nalert('frag='+frag);"
|
1023 |
|
+"\nvar children = txmGetChildren(frag);" //$NON-NLS-1$
|
1024 |
|
//+"\nalert('children='+children);"
|
1025 |
|
//+"\nalert('children.length='+children.length);"
|
1026 |
|
+"\nif ((children.length == 0) || (children.length == 1 && children.item(0).nodeType == 3)) {" //$NON-NLS-1$
|
1027 |
|
+"\n var parent = txmGetParentElementRange(range);" //$NON-NLS-1$
|
1028 |
|
//+"\n if (parent instanceof HTMLHtmlElement) {alert('HTMLHtmlElement parent='+parent);return findIdsInString(parent, all);}"
|
1029 |
|
+"\n if (typeof parent.getAttribute == 'undefined') {return all}" //$NON-NLS-1$
|
1030 |
|
+"\n var id = parent.getAttribute('id');" //$NON-NLS-1$
|
1031 |
|
+"\n if (txmGetTagName(parent) == 'SPAN' && id != null && id.indexOf('w_') == 0) {" //$NON-NLS-1$
|
1032 |
|
+"\n all.push(id);" //$NON-NLS-1$
|
1033 |
|
+"\n } else {" // try with the parent's parent //$NON-NLS-1$
|
1034 |
|
+"\n var parent = txmGetParent(parent);" //$NON-NLS-1$
|
1035 |
|
//+"\n alert('text selection, parent='+txmGetTagName(parent))"
|
1036 |
|
+"\n if (typeof parent.getAttribute == 'undefined') {return all}" //$NON-NLS-1$
|
1037 |
|
+"\n var id = parent.getAttribute('id');" //$NON-NLS-1$
|
1038 |
|
+"\n if (txmGetTagName(parent) == 'SPAN' && id != null && id.indexOf('w_') == 0) {" //$NON-NLS-1$
|
1039 |
|
+"\n all.push(id);" //$NON-NLS-1$
|
1040 |
|
+"\n }" //$NON-NLS-1$
|
1041 |
|
+"\n }" //$NON-NLS-1$
|
1042 |
|
+"\n} else {" //$NON-NLS-1$
|
1043 |
|
+"\n findSpans(children, all);" //$NON-NLS-1$
|
1044 |
|
+"\n}" //$NON-NLS-1$
|
1045 |
|
//+"alert('result='+all)"
|
1046 |
|
+"\nreturn all;"; //$NON-NLS-1$
|
|
1081 |
// System.out.println("getWordSelection");
|
|
1082 |
String SCRIPT02_getspans = ""// functions //$NON-NLS-1$
|
|
1083 |
+ "var all = [];" //$NON-NLS-1$
|
|
1084 |
+ "\nvar sel = txmGetSelection();" //$NON-NLS-1$
|
|
1085 |
+ "\nif (sel.rangeCount == 0) {return all;}" //$NON-NLS-1$
|
|
1086 |
// +"\nalert('sel='+sel);"
|
|
1087 |
+ "\nvar range = txmGetRange(sel, 0);" //$NON-NLS-1$
|
|
1088 |
// +"\nalert('range='+range);"
|
|
1089 |
+ "\nvar frag = txmGetFragment(range);" //$NON-NLS-1$
|
|
1090 |
// +"\nalert('frag='+frag);"
|
|
1091 |
+ "\nvar children = txmGetChildren(frag);" //$NON-NLS-1$
|
|
1092 |
// +"\nalert('children='+children);"
|
|
1093 |
// +"\nalert('children.length='+children.length);"
|
|
1094 |
+ "\nif ((children.length == 0) || (children.length == 1 && children.item(0).nodeType == 3)) {" //$NON-NLS-1$
|
|
1095 |
+ "\n var parent = txmGetParentElementRange(range);" //$NON-NLS-1$
|
|
1096 |
// +"\n if (parent instanceof HTMLHtmlElement) {alert('HTMLHtmlElement parent='+parent);return findIdsInString(parent, all);}"
|
|
1097 |
+ "\n if (typeof parent.getAttribute == 'undefined') {return all}" //$NON-NLS-1$
|
|
1098 |
+ "\n var id = parent.getAttribute('id');" //$NON-NLS-1$
|
|
1099 |
+ "\n if (txmGetTagName(parent) == 'SPAN' && id != null && id.indexOf('w_') == 0) {" //$NON-NLS-1$
|
|
1100 |
+ "\n all.push(id);" //$NON-NLS-1$
|
|
1101 |
+ "\n } else {" // try with the parent's parent //$NON-NLS-1$
|
|
1102 |
+ "\n var parent = txmGetParent(parent);" //$NON-NLS-1$
|
|
1103 |
// +"\n alert('text selection, parent='+txmGetTagName(parent))"
|
|
1104 |
+ "\n if (typeof parent.getAttribute == 'undefined') {return all}" //$NON-NLS-1$
|
|
1105 |
+ "\n var id = parent.getAttribute('id');" //$NON-NLS-1$
|
|
1106 |
+ "\n if (txmGetTagName(parent) == 'SPAN' && id != null && id.indexOf('w_') == 0) {" //$NON-NLS-1$
|
|
1107 |
+ "\n all.push(id);" //$NON-NLS-1$
|
|
1108 |
+ "\n }" //$NON-NLS-1$
|
|
1109 |
+ "\n }" //$NON-NLS-1$
|
|
1110 |
+ "\n} else {" //$NON-NLS-1$
|
|
1111 |
+ "\n findSpans(children, all);" //$NON-NLS-1$
|
|
1112 |
+ "\n}" //$NON-NLS-1$
|
|
1113 |
// +"alert('result='+all)"
|
|
1114 |
+ "\nreturn all;"; //$NON-NLS-1$
|
|
1115 |
|
|
1116 |
// System.out.println(functions);
|
|
1117 |
// System.out.println(SCRIPT02_getspans);
|
1047 |
1118 |
|
1048 |
|
// System.out.println(functions);
|
1049 |
|
// System.out.println(SCRIPT02_getspans);
|
1050 |
|
|
1051 |
1119 |
Object ret = evaluate(SCRIPT02_getspans);
|
1052 |
1120 |
if (ret instanceof Object[]) {
|
1053 |
|
Log.finer("selection word ids="+Arrays.toString((Object[])ret)); //$NON-NLS-1$
|
1054 |
|
Object[] array = (Object[])ret;
|
|
1121 |
Log.finer("selection word ids=" + Arrays.toString((Object[]) ret)); //$NON-NLS-1$
|
|
1122 |
Object[] array = (Object[]) ret;
|
1055 |
1123 |
String[] sel = new String[2];
|
1056 |
1124 |
if (array.length == 0) {
|
1057 |
1125 |
return null;
|
1058 |
|
} else if (array.length == 1) {
|
|
1126 |
}
|
|
1127 |
else if (array.length == 1) {
|
1059 |
1128 |
sel[0] = array[0].toString();
|
1060 |
1129 |
return sel;
|
1061 |
|
} else {
|
|
1130 |
}
|
|
1131 |
else {
|
1062 |
1132 |
sel[0] = array[0].toString();
|
1063 |
|
sel[1] = array[array.length-1].toString();
|
|
1133 |
sel[1] = array[array.length - 1].toString();
|
1064 |
1134 |
return sel;
|
1065 |
1135 |
}
|
1066 |
|
} else {
|
|
1136 |
}
|
|
1137 |
else {
|
1067 |
1138 |
Log.severe(EditionUIMessages.bind(EditionUIMessages.sCRIPTRETURNEDEqualsP0, ret));
|
1068 |
1139 |
return null;
|
1069 |
1140 |
}
|
1070 |
1141 |
}
|
1071 |
1142 |
|
1072 |
1143 |
public String getTextSelection() {
|
1073 |
|
//System.out.println("DOM="+getTextSelectionDOM());
|
1074 |
|
String rez = getTextSelectionDOM().replaceAll("<[^>]+>", ""); //$NON-NLS-1$ //$NON-NLS-2$
|
1075 |
|
//System.out.println("STR="+rez);
|
|
1144 |
// System.out.println("DOM="+getTextSelectionDOM());
|
|
1145 |
String rez = getTextSelectionDOM().replaceAll("<[^>]+>", ""); //$NON-NLS-1$ //$NON-NLS-2$
|
|
1146 |
// System.out.println("STR="+rez);
|
1076 |
1147 |
return rez;
|
1077 |
1148 |
}
|
1078 |
1149 |
|
1079 |
1150 |
@Override
|
1080 |
|
public void addSelectionChangedListener(ISelectionChangedListener listener) { }
|
|
1151 |
public void addSelectionChangedListener(ISelectionChangedListener listener) {}
|
1081 |
1152 |
|
1082 |
1153 |
@Override
|
1083 |
1154 |
public ISelection getSelection() {
|
... | ... | |
1086 |
1157 |
|
1087 |
1158 |
@Override
|
1088 |
1159 |
public void removeSelectionChangedListener(
|
1089 |
|
ISelectionChangedListener listener) { }
|
|
1160 |
ISelectionChangedListener listener) {}
|
1090 |
1161 |
|
1091 |
1162 |
@Override
|
1092 |
|
public void setSelection(ISelection selection) { }
|
|
1163 |
public void setSelection(ISelection selection) {}
|
1093 |
1164 |
|
1094 |
|
static public class SynopticTextSelection implements ISelection {
|
|
1165 |
static public class SynopticTextSelection implements ISelection {
|
|
1166 |
|
1095 |
1167 |
String str;
|
|
1168 |
|
1096 |
1169 |
public SynopticTextSelection(EditionPanel panel) {
|
1097 |
1170 |
this.str = panel.getTextSelection();
|
1098 |
1171 |
}
|
... | ... | |
1111 |
1184 |
return currentEdition;
|
1112 |
1185 |
}
|
1113 |
1186 |
|
1114 |
|
public MenuManager getMenuManager() {
|
|
1187 |
public MenuManager getMenuManager() {
|
1115 |
1188 |
return menuManager;
|
1116 |
1189 |
}
|
1117 |
1190 |
|
1118 |
1191 |
public void initMenu() {
|
1119 |
|
// create a new menu
|
1120 |
|
menuManager = new MenuManager(); //$NON-NLS-1$
|
|
1192 |
// create a new menu
|
|
1193 |
menuManager = new MenuManager();
|
1121 |
1194 |
|
1122 |
1195 |
Menu menu = menuManager.createContextMenu(this.getBrowser());
|
1123 |
1196 |
|
... | ... | |
1142 |
1215 |
}
|
1143 |
1216 |
|
1144 |
1217 |
@Override
|
1145 |
|
public void widgetDefaultSelected(SelectionEvent e) { }
|
|
1218 |
public void widgetDefaultSelected(SelectionEvent e) {}
|
1146 |
1219 |
});
|
1147 |
1220 |
String text = EditionPanel.this.getTextSelection();
|
1148 |
1221 |
copyItem.setEnabled(text != null && text.length() > 0);
|
... | ... | |
1157 |
1230 |
}
|
1158 |
1231 |
|
1159 |
1232 |
@Override
|
1160 |
|
public void widgetDefaultSelected(SelectionEvent e) { }
|
|
1233 |
public void widgetDefaultSelected(SelectionEvent e) {}
|
1161 |
1234 |
});
|
1162 |
1235 |
MenuItem backItem = new MenuItem(menu, SWT.NONE);
|
1163 |
1236 |
backItem.setText(EditionUIMessages.back);
|
... | ... | |
1169 |
1242 |
}
|
1170 |
1243 |
|
1171 |
1244 |
@Override
|
1172 |
|
public void widgetDefaultSelected(SelectionEvent e) { }
|
|
1245 |
public void widgetDefaultSelected(SelectionEvent e) {}
|
1173 |
1246 |
});
|
1174 |
1247 |
MenuItem forwardItem = new MenuItem(menu, SWT.NONE);
|
1175 |
1248 |
forwardItem.setText(EditionUIMessages.forward);
|
... | ... | |
1181 |
1254 |
}
|
1182 |
1255 |
|
1183 |
1256 |
@Override
|
1184 |
|
public void widgetDefaultSelected(SelectionEvent e) { }
|
|
1257 |
public void widgetDefaultSelected(SelectionEvent e) {}
|
1185 |
1258 |
});
|
1186 |
1259 |
}
|
1187 |
1260 |
|
... | ... | |
1190 |
1263 |
// TODO Auto-generated method stub
|
1191 |
1264 |
}
|
1192 |
1265 |
});
|
1193 |
|
// // restore old listeners
|
1194 |
|
// Menu origMenu = this.browser.getMenu();
|
1195 |
|
// if (origMenu != null) {
|
1196 |
|
// if (origMenu.getListeners(SWT.Hide) != null)
|
1197 |
|
// for (Listener listener : origMenu.getListeners(SWT.Hide)) menu.addListener(SWT.Hide, listener);
|
1198 |
|
// if (origMenu.getListeners(SWT.Show) != null)
|
1199 |
|
// for (Listener listener : origMenu.getListeners(SWT.Show)) menu.addListener(SWT.Show, listener);
|
1200 |
|
// for (MenuItem origItem : origMenu.getItems()) { // restore old menu items
|