Révision 3904
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMBrowserEditor.java (revision 3904) | ||
---|---|---|
43 | 43 |
import org.eclipse.swt.events.MenuEvent; |
44 | 44 |
import org.eclipse.swt.events.MenuListener; |
45 | 45 |
import org.eclipse.swt.events.MouseEvent; |
46 |
import org.eclipse.swt.events.MouseListener; |
|
46 | 47 |
import org.eclipse.swt.events.MouseWheelListener; |
47 | 48 |
import org.eclipse.swt.events.SelectionEvent; |
48 | 49 |
import org.eclipse.swt.events.SelectionListener; |
... | ... | |
52 | 53 |
import org.eclipse.swt.widgets.MenuItem; |
53 | 54 |
import org.eclipse.ui.internal.browser.BrowserViewer; |
54 | 55 |
import org.eclipse.ui.internal.browser.WebBrowserEditor; |
56 |
import org.txm.rcp.commands.OpenBrowser; |
|
55 | 57 |
import org.txm.rcp.commands.ShowSelected; |
56 | 58 |
import org.txm.rcp.editors.menu.PagePropertiesMenu; |
57 | 59 |
import org.txm.rcp.messages.TXMUIMessages; |
... | ... | |
107 | 109 |
*/ |
108 | 110 |
public void initializeProgressListener() { |
109 | 111 |
|
110 |
|
|
111 | 112 |
ProgressListener progresslistener = new ProgressListener() { |
112 | 113 |
|
113 | 114 |
@Override |
... | ... | |
123 | 124 |
} |
124 | 125 |
cmdLink = new CommandLink(TXMBrowserEditor.this, TXMBrowserEditor.this.getBrowser()); |
125 | 126 |
} |
127 |
|
|
128 |
TXMBrowserEditor.this.getBrowser().execute(""" |
|
129 |
document.addEventListener('mouseover', function (e) { |
|
130 |
document.currentHoverElement = e.target |
|
131 |
}); """); |
|
126 | 132 |
} |
127 | 133 |
}; |
128 | 134 |
getBrowser().addProgressListener(progresslistener); |
... | ... | |
143 | 149 |
public static void zoom(Browser b, float diff) { |
144 | 150 |
|
145 | 151 |
if (b == null || b.isDisposed()) return; |
146 |
|
|
147 |
// b.evaluate("alert(document);"); |
|
148 |
// b.evaluate("alert(document.children[0].style);"); |
|
149 |
// b.evaluate("alert(document.children[0].children[1]);"); |
|
152 |
|
|
153 |
// b.evaluate("alert(document);");
|
|
154 |
// b.evaluate("alert(document.children[0].style);");
|
|
155 |
// b.evaluate("alert(document.children[0].children[1]);");
|
|
150 | 156 |
boolean isHTML = (boolean) b.evaluate("return document.getElementsByTagName('body')[0] != null;"); //$NON-NLS-1$ |
151 | 157 |
if (isHTML) { |
152 | 158 |
String zoom = (String) b.evaluate("return document.getElementsByTagName('body')[0].style.zoom;"); //$NON-NLS-1$ |
... | ... | |
175 | 181 |
} |
176 | 182 |
} |
177 | 183 |
|
184 |
MenuItem sep1; |
|
185 |
MenuItem copyItem; |
|
186 |
MenuItem copyLink; |
|
187 |
MenuItem openLink; |
|
188 |
MenuItem zoomInItem; |
|
189 |
MenuItem zoomOutItem; |
|
190 |
MenuItem zoomResetItem; |
|
191 |
MenuItem reloadItem; |
|
192 |
MenuItem backItem; |
|
193 |
MenuItem forwardItem; |
|
194 |
MenuItem propertiesItem; |
|
195 |
|
|
178 | 196 |
public void initMenu() { |
179 | 197 |
|
180 | 198 |
// create a new menu |
... | ... | |
189 | 207 |
|
190 | 208 |
Menu menu = menuManager.getMenu(); |
191 | 209 |
if (menu == null) return; |
192 |
new MenuItem(menu, SWT.SEPARATOR); |
|
193 | 210 |
|
194 |
MenuItem copyItem = new MenuItem(menu, SWT.NONE); |
|
195 |
copyItem.setText(TXMUIMessages.Copy); |
|
196 |
copyItem.addSelectionListener(new SelectionListener() { |
|
211 |
if (sep1 == null) { |
|
197 | 212 |
|
198 |
@Override |
|
199 |
public void widgetSelected(SelectionEvent e) { |
|
213 |
sep1 = new MenuItem(menu, SWT.SEPARATOR); |
|
214 |
|
|
215 |
copyItem = new MenuItem(menu, SWT.NONE); |
|
216 |
copyItem.setText(TXMUIMessages.Copy); |
|
217 |
copyItem.addSelectionListener(new SelectionListener() { |
|
200 | 218 |
|
201 |
String text = TXMBrowserEditor.this.getTextSelection(); |
|
202 |
if (text != null && text.length() > 0) { |
|
203 |
IOClipboard.write(text); |
|
219 |
@Override |
|
220 |
public void widgetSelected(SelectionEvent e) { |
|
221 |
|
|
222 |
String text = TXMBrowserEditor.this.getTextSelection(); |
|
223 |
if (text != null && text.length() > 0) { |
|
224 |
IOClipboard.write(text); |
|
225 |
} |
|
204 | 226 |
} |
205 |
} |
|
227 |
|
|
228 |
@Override |
|
229 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
230 |
}); |
|
206 | 231 |
|
207 |
@Override |
|
208 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
209 |
}); |
|
210 |
String text = TXMBrowserEditor.this.getTextSelection(); |
|
211 |
copyItem.setEnabled(text != null && text.length() > 0); |
|
212 |
|
|
213 |
MenuItem zoomInItem = new MenuItem(menu, SWT.NONE); |
|
214 |
zoomInItem.setText(TXMUIMessages.zoomIn); |
|
215 |
zoomInItem.addSelectionListener(new SelectionListener() { |
|
232 |
openLink = new MenuItem(menu, SWT.NONE); |
|
233 |
openLink.setText("Open link"); |
|
234 |
openLink.addSelectionListener(new SelectionListener() { |
|
235 |
|
|
236 |
@Override |
|
237 |
public void widgetSelected(SelectionEvent e) { |
|
238 |
|
|
239 |
Object currentHref = TXMBrowserEditor.this.getBrowser().evaluate("return document.currentHoverElement.getAttribute('href')"); |
|
240 |
if (currentHref != null) { |
|
241 |
OpenBrowser.openfile(currentHref.toString()); |
|
242 |
} |
|
243 |
} |
|
244 |
|
|
245 |
@Override |
|
246 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
247 |
}); |
|
216 | 248 |
|
217 |
@Override |
|
218 |
public void widgetSelected(SelectionEvent e) { |
|
219 |
zoomIn(getBrowser()); |
|
220 |
} |
|
221 |
|
|
222 |
@Override |
|
223 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
224 |
}); |
|
225 |
|
|
226 |
MenuItem zoomOutItem = new MenuItem(menu, SWT.NONE); |
|
227 |
zoomOutItem.setText(TXMUIMessages.zoomOut); |
|
228 |
zoomOutItem.addSelectionListener(new SelectionListener() { |
|
229 |
|
|
230 |
@Override |
|
231 |
public void widgetSelected(SelectionEvent e) { |
|
249 |
copyLink = new MenuItem(menu, SWT.NONE); |
|
250 |
copyLink.setText("Copy link"); |
|
251 |
copyLink.addSelectionListener(new SelectionListener() { |
|
232 | 252 |
|
233 |
zoomOut(getBrowser()); |
|
234 |
} |
|
253 |
@Override |
|
254 |
public void widgetSelected(SelectionEvent e) { |
|
255 |
|
|
256 |
Object currentHref = TXMBrowserEditor.this.getBrowser().evaluate("return document.currentHoverElement.getAttribute('href')"); |
|
257 |
if (currentHref != null) { |
|
258 |
IOClipboard.write(currentHref.toString()); |
|
259 |
} |
|
260 |
} |
|
261 |
|
|
262 |
@Override |
|
263 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
264 |
}); |
|
235 | 265 |
|
236 |
@Override |
|
237 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
238 |
}); |
|
239 |
|
|
240 |
MenuItem zoomResetItem = new MenuItem(menu, SWT.NONE); |
|
241 |
zoomResetItem.setText(TXMUIMessages.initialZoom); |
|
242 |
zoomResetItem.addSelectionListener(new SelectionListener() { |
|
243 |
|
|
244 |
@Override |
|
245 |
public void widgetSelected(SelectionEvent e) { |
|
266 |
zoomInItem = new MenuItem(menu, SWT.NONE); |
|
267 |
zoomInItem.setText(TXMUIMessages.zoomIn); |
|
268 |
zoomInItem.addSelectionListener(new SelectionListener() { |
|
246 | 269 |
|
247 |
zoomReset(getBrowser()); |
|
248 |
} |
|
270 |
@Override |
|
271 |
public void widgetSelected(SelectionEvent e) { |
|
272 |
zoomIn(getBrowser()); |
|
273 |
} |
|
274 |
|
|
275 |
@Override |
|
276 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
277 |
}); |
|
249 | 278 |
|
250 |
@Override |
|
251 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
252 |
}); |
|
253 |
|
|
254 |
MenuItem reloadItem = new MenuItem(menu, SWT.NONE); |
|
255 |
reloadItem.setText(TXMUIMessages.Reload); |
|
256 |
reloadItem.addSelectionListener(new SelectionListener() { |
|
257 |
|
|
258 |
@Override |
|
259 |
public void widgetSelected(SelectionEvent e) { |
|
279 |
zoomOutItem = new MenuItem(menu, SWT.NONE); |
|
280 |
zoomOutItem.setText(TXMUIMessages.zoomOut); |
|
281 |
zoomOutItem.addSelectionListener(new SelectionListener() { |
|
260 | 282 |
|
261 |
TXMBrowserEditor.this.getBrowser().refresh(); |
|
262 |
} |
|
283 |
@Override |
|
284 |
public void widgetSelected(SelectionEvent e) { |
|
285 |
|
|
286 |
zoomOut(getBrowser()); |
|
287 |
} |
|
288 |
|
|
289 |
@Override |
|
290 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
291 |
}); |
|
263 | 292 |
|
264 |
@Override |
|
265 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
266 |
}); |
|
267 |
MenuItem backItem = new MenuItem(menu, SWT.NONE); |
|
268 |
backItem.setText(TXMUIMessages.Back); |
|
269 |
backItem.addSelectionListener(new SelectionListener() { |
|
270 |
|
|
271 |
@Override |
|
272 |
public void widgetSelected(SelectionEvent e) { |
|
293 |
zoomResetItem = new MenuItem(menu, SWT.NONE); |
|
294 |
zoomResetItem.setText(TXMUIMessages.initialZoom); |
|
295 |
zoomResetItem.addSelectionListener(new SelectionListener() { |
|
273 | 296 |
|
274 |
TXMBrowserEditor.this.getBrowser().back(); |
|
275 |
} |
|
297 |
@Override |
|
298 |
public void widgetSelected(SelectionEvent e) { |
|
299 |
|
|
300 |
zoomReset(getBrowser()); |
|
301 |
} |
|
302 |
|
|
303 |
@Override |
|
304 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
305 |
}); |
|
276 | 306 |
|
277 |
@Override |
|
278 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
279 |
}); |
|
280 |
MenuItem forwardItem = new MenuItem(menu, SWT.NONE); |
|
281 |
forwardItem.setText(TXMUIMessages.Forward); |
|
282 |
forwardItem.addSelectionListener(new SelectionListener() { |
|
283 |
|
|
284 |
@Override |
|
285 |
public void widgetSelected(SelectionEvent e) { |
|
307 |
reloadItem = new MenuItem(menu, SWT.NONE); |
|
308 |
reloadItem.setText(TXMUIMessages.Reload); |
|
309 |
reloadItem.addSelectionListener(new SelectionListener() { |
|
286 | 310 |
|
287 |
TXMBrowserEditor.this.getBrowser().forward(); |
|
288 |
} |
|
311 |
@Override |
|
312 |
public void widgetSelected(SelectionEvent e) { |
|
313 |
|
|
314 |
TXMBrowserEditor.this.getBrowser().refresh(); |
|
315 |
} |
|
316 |
|
|
317 |
@Override |
|
318 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
319 |
}); |
|
320 |
backItem = new MenuItem(menu, SWT.NONE); |
|
321 |
backItem.setText(TXMUIMessages.Back); |
|
322 |
backItem.addSelectionListener(new SelectionListener() { |
|
323 |
|
|
324 |
@Override |
|
325 |
public void widgetSelected(SelectionEvent e) { |
|
326 |
|
|
327 |
TXMBrowserEditor.this.getBrowser().back(); |
|
328 |
} |
|
329 |
|
|
330 |
@Override |
|
331 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
332 |
}); |
|
333 |
forwardItem = new MenuItem(menu, SWT.NONE); |
|
334 |
forwardItem.setText(TXMUIMessages.Forward); |
|
335 |
forwardItem.addSelectionListener(new SelectionListener() { |
|
336 |
|
|
337 |
@Override |
|
338 |
public void widgetSelected(SelectionEvent e) { |
|
339 |
|
|
340 |
TXMBrowserEditor.this.getBrowser().forward(); |
|
341 |
} |
|
342 |
|
|
343 |
@Override |
|
344 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
345 |
}); |
|
289 | 346 |
|
290 |
@Override |
|
291 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
292 |
}); |
|
347 |
propertiesItem = new PagePropertiesMenu(getBrowser(), menu, SWT.NONE); |
|
348 |
} |
|
293 | 349 |
|
294 |
MenuItem propertiesItem = new PagePropertiesMenu(getBrowser(), menu, SWT.NONE); |
|
350 |
String dom = TXMBrowserEditor.this.getTextSelectionDOM(); |
|
351 |
copyItem.setEnabled(dom != null && dom.length() > 0); |
|
352 |
|
|
353 |
Object currentHref = TXMBrowserEditor.this.getBrowser().evaluate("return document.currentHoverElement.getAttribute('href')"); |
|
354 |
copyLink.setEnabled(currentHref != null); |
|
355 |
openLink.setEnabled(currentHref != null); |
|
295 | 356 |
} |
296 | 357 |
|
297 | 358 |
@Override |
298 |
public void menuHidden(MenuEvent e) { |
|
299 |
// TODO Auto-generated method stub |
|
300 |
} |
|
359 |
public void menuHidden(MenuEvent e) { } |
|
301 | 360 |
}); |
302 | 361 |
// // restore old listeners |
303 | 362 |
// Menu origMenu = this.browser.getMenu(); |
... | ... | |
317 | 376 |
// replace the menu |
318 | 377 |
this.getBrowser().setMenu(menu); |
319 | 378 |
} |
320 |
|
|
321 |
// /** |
|
322 |
// * Sets the edition. |
|
323 |
// * |
|
324 |
// * @param edition the new edition |
|
325 |
// */ |
|
326 |
// public void setEdition(Edition edition) { |
|
327 |
// this.edition = edition; |
|
328 |
// } |
|
329 |
|
|
330 |
// /** |
|
331 |
// * Make page label. |
|
332 |
// * |
|
333 |
// * @return the string |
|
334 |
// */ |
|
335 |
// public String makePageLabel() { |
|
336 |
// return currentPage.getName() |
|
337 |
// + " / " + currentPage.getEdition().getNumPages(); //$NON-NLS-1$ |
|
338 |
// } |
|
339 |
// |
|
340 |
// /** |
|
341 |
// * Show page. |
|
342 |
// * |
|
343 |
// * @param page the page |
|
344 |
// */ |
|
345 |
// public void showPage(Page page) { |
|
346 |
// edition = page.getEdition(); |
|
347 |
// currentPage = page; |
|
348 |
// this.webBrowser.setURL(currentPage.toURL()); |
|
349 |
// page_label.setText(makePageLabel()); |
|
350 |
// } |
|
351 |
|
|
352 |
// /** |
|
353 |
// * First text. |
|
354 |
// */ |
|
355 |
// public void firstText() { |
|
356 |
// Text current = this.currentPage.getEdition().getText(); |
|
357 |
// Project corpus = current.getProject(); |
|
358 |
// Text firstText = corpus.getFirstText(); |
|
359 |
// |
|
360 |
// if (firstText != null) { |
|
361 |
// String editionName = corpus.getDefaultEditionName(); |
|
362 |
// currentPage = firstText.getEdition(editionName).getFirstPage(); |
|
363 |
// if (currentPage == null) { |
|
364 |
// StatusLine.setMessage(TXMUIMessages.noPreviousText); |
|
365 |
// return; |
|
366 |
// } |
|
367 |
// this.setEdition(firstText.getEdition(editionName)); |
|
368 |
// this.webBrowser.setURL(currentPage.toURL()); |
|
369 |
// page_label.setText(makePageLabel()); |
|
370 |
// } |
|
371 |
// } |
|
372 |
// |
|
373 |
// /** |
|
374 |
// * Last text. |
|
375 |
// */ |
|
376 |
// public void lastText() { |
|
377 |
// Text current = this.currentPage.getEdition().getText(); |
|
378 |
// Project b = current.getProject(); |
|
379 |
// Text lastText = b.getLastText(); |
|
380 |
// |
|
381 |
// if (lastText != null) { |
|
382 |
// currentPage = lastText.getEdition(b.getDefaultEditionName()).getFirstPage(); |
|
383 |
// if (currentPage == null) { |
|
384 |
// StatusLine.setMessage(TXMUIMessages.noTextNext); |
|
385 |
// return; |
|
386 |
// } |
|
387 |
// this.setEdition(lastText.getEdition(b.getDefaultEditionName())); |
|
388 |
// this.webBrowser.setURL(currentPage.toURL()); |
|
389 |
// page_label.setText(makePageLabel()); |
|
390 |
// } |
|
391 |
// } |
|
392 |
// |
|
393 |
// /** |
|
394 |
// * First page. |
|
395 |
// */ |
|
396 |
// public void firstPage() { |
|
397 |
// // System.out.println(Messages.TxmBrowser_1+currentPage); |
|
398 |
// currentPage = edition.getFirstPage(); |
|
399 |
// this.webBrowser.setURL(currentPage.toURL()); |
|
400 |
// page_label.setText(makePageLabel()); |
|
401 |
// } |
|
402 |
// |
|
403 |
// /** |
|
404 |
// * Last page. |
|
405 |
// */ |
|
406 |
// public void lastPage() { |
|
407 |
// // System.out.println(Messages.TxmBrowser_2+currentPage); |
|
408 |
// |
|
409 |
// if (currentPage != null && currentPage.getFile().equals(edition.getLastPage().getFile())) |
|
410 |
// return; |
|
411 |
// currentPage = edition.getLastPage(); |
|
412 |
// this.webBrowser.setURL(currentPage.toURL()); |
|
413 |
// page_label.setText(makePageLabel()); |
|
414 |
// } |
|
415 |
// |
|
416 |
// /** |
|
417 |
// * Previous page. |
|
418 |
// */ |
|
419 |
// public void previousPage() { |
|
420 |
// // System.out.println(Messages.TxmBrowser_3+currentPage); |
|
421 |
// if (currentPage != null) { |
|
422 |
// Page previous = edition.getPreviousPage(currentPage); |
|
423 |
// if (previous == currentPage) { |
|
424 |
// previousText(true); |
|
425 |
// } |
|
426 |
// else { |
|
427 |
// currentPage = previous; |
|
428 |
// this.webBrowser.setURL(currentPage.toURL()); |
|
429 |
// } |
|
430 |
// } |
|
431 |
// else |
|
432 |
// firstPage(); |
|
433 |
// page_label.setText(makePageLabel()); |
|
434 |
// } |
|
435 |
// |
|
436 |
// /** |
|
437 |
// * Next page. |
|
438 |
// */ |
|
439 |
// public void nextPage() { |
|
440 |
// // System.out.println(Messages.TxmBrowser_4+currentPage); |
|
441 |
// if (currentPage != null) { |
|
442 |
// Page next = edition.getNextPage(currentPage); |
|
443 |
// if (currentPage == next) { |
|
444 |
// nextText(); |
|
445 |
// } |
|
446 |
// else { |
|
447 |
// currentPage = next; |
|
448 |
// this.webBrowser.setURL(currentPage.toURL()); |
|
449 |
// } |
|
450 |
// |
|
451 |
// } |
|
452 |
// else |
|
453 |
// firstPage(); |
|
454 |
// page_label.setText(makePageLabel()); |
|
455 |
// } |
|
456 |
// |
|
457 |
// /** |
|
458 |
// * Previous text. |
|
459 |
// * |
|
460 |
// * @param fromNextText |
|
461 |
// */ |
|
462 |
// public void previousText(boolean fromNextText) { |
|
463 |
// |
|
464 |
// Text current = this.currentPage.getEdition().getText(); |
|
465 |
// Project corpus = current.getProject(); |
|
466 |
// Text previousText = corpus.getPreviousText(current); |
|
467 |
// |
|
468 |
// if (previousText != null) { |
|
469 |
// String editionName = corpus.getDefaultEditionName(); |
|
470 |
// if (fromNextText) { |
|
471 |
// currentPage = previousText.getEdition(editionName).getLastPage(); |
|
472 |
// } |
|
473 |
// else { |
|
474 |
// currentPage = previousText.getEdition(editionName).getFirstPage(); |
|
475 |
// } |
|
476 |
// if (currentPage == null) { |
|
477 |
// StatusLine.setMessage(TXMUIMessages.noPreviousText); |
|
478 |
// return; |
|
479 |
// } |
|
480 |
// this.setEdition(previousText.getEdition(editionName)); |
|
481 |
// this.webBrowser.setURL(currentPage.toURL()); |
|
482 |
// page_label.setText(makePageLabel()); |
|
483 |
// } |
|
484 |
// // System.out.println("Previous texts "+previousText); |
|
485 |
// } |
|
486 |
// |
|
487 |
// /** |
|
488 |
// * Next text. |
|
489 |
// */ |
|
490 |
// public void nextText() { |
|
491 |
// Text current = this.currentPage.getEdition().getText(); |
|
492 |
// Project b = current.getProject(); |
|
493 |
// Text nextText = b.getNextText(current); |
|
494 |
// |
|
495 |
// if (nextText != null) { |
|
496 |
// currentPage = nextText.getEdition(b.getDefaultEditionName()).getFirstPage(); |
|
497 |
// if (currentPage == null) { |
|
498 |
// StatusLine.setMessage(TXMUIMessages.noTextNext); |
|
499 |
// return; |
|
500 |
// } |
|
501 |
// this.setEdition(nextText.getEdition(b.getDefaultEditionName())); |
|
502 |
// this.webBrowser.setURL(currentPage.toURL()); |
|
503 |
// page_label.setText(makePageLabel()); |
|
504 |
// } |
|
505 |
// // System.out.println("Next texts "+nextText); |
|
506 |
// } |
|
507 |
|
|
379 |
|
|
508 | 380 |
public static void installZoomControls(Browser browser, Menu menu) { |
509 | 381 |
|
510 | 382 |
browser.addMouseWheelListener(new MouseWheelListener() { |
... | ... | |
522 | 394 |
} |
523 | 395 |
}); |
524 | 396 |
|
525 |
|
|
397 |
|
|
526 | 398 |
MenuItem zoomInItem = new MenuItem(menu, SWT.NONE); |
527 | 399 |
zoomInItem.setText(TXMUIMessages.zoomIn); |
528 | 400 |
zoomInItem.addSelectionListener(new SelectionListener() { |
... | ... | |
777 | 649 |
|
778 | 650 |
initMenu(); |
779 | 651 |
|
652 |
// getBrowser().addMouseListener(new MouseListener() { |
|
653 |
// |
|
654 |
// @Override |
|
655 |
// public void mouseUp(MouseEvent e) { } |
|
656 |
// |
|
657 |
// @Override |
|
658 |
// public void mouseDown(MouseEvent e) { } |
|
659 |
// |
|
660 |
// @Override |
|
661 |
// public void mouseDoubleClick(MouseEvent e) { |
|
662 |
// |
|
663 |
// Browser b = TXMBrowserEditor.this.webBrowser.getBrowser(); |
|
664 |
// b.evaluate(SCRIPT01) |
|
665 |
// } |
|
666 |
// }); |
|
667 |
|
|
780 | 668 |
getBrowser().addMouseWheelListener(new MouseWheelListener() { |
781 | 669 |
|
782 | 670 |
@Override |
TXM/trunk/bundles/org.txm.edition.rcp/src/org/txm/edition/rcp/editors/EditionPanel.java (revision 3904) | ||
---|---|---|
45 | 45 |
import org.txm.objects.Project; |
46 | 46 |
import org.txm.objects.Text; |
47 | 47 |
import org.txm.rcp.StatusLine; |
48 |
import org.txm.rcp.commands.OpenBrowser; |
|
48 | 49 |
import org.txm.rcp.editors.CommandLink; |
49 | 50 |
import org.txm.rcp.editors.TXMBrowserEditor; |
50 | 51 |
import org.txm.rcp.editors.menu.PagePropertiesMenu; |
... | ... | |
53 | 54 |
import org.txm.utils.logger.Log; |
54 | 55 |
|
55 | 56 |
public class EditionPanel extends BrowserViewer implements ISelectionProvider { |
56 |
|
|
57 |
|
|
57 | 58 |
private ProgressListener progressListener; |
58 |
|
|
59 |
|
|
59 | 60 |
// private List<String> wordids; |
60 | 61 |
// private List<String> lineids; |
61 | 62 |
/** The edition. */ |
62 | 63 |
Text currentText; |
63 |
|
|
64 |
|
|
64 | 65 |
String editionName; |
65 |
|
|
66 |
|
|
66 | 67 |
Edition currentEdition; |
67 |
|
|
68 |
|
|
68 | 69 |
Page currentPage; |
69 |
|
|
70 |
|
|
70 | 71 |
protected SynopticEditionEditor synopticEditionEditor; |
71 |
|
|
72 |
|
|
72 | 73 |
private ISelectionProvider selProvider; |
73 |
|
|
74 |
|
|
74 | 75 |
private MenuManager menuManager; |
75 |
|
|
76 |
|
|
76 | 77 |
private HashSet<int[]> highlightedAreas = null; |
77 |
|
|
78 |
|
|
78 | 79 |
// HashMap<String, ArrayList<RGBA>> highlightedColorSpans = new HashMap<String, ArrayList<RGBA>>(); // background color |
79 |
|
|
80 |
|
|
80 | 81 |
HashMap<String, ArrayList<RGBA>> highlightedColorPerWordIDS = new HashMap<>(); // background color |
81 |
|
|
82 |
|
|
82 | 83 |
public static final String STYLE_NORMAL = "normal"; //$NON-NLS-1$ |
83 |
|
|
84 |
|
|
84 | 85 |
public static final String STYLE_ITALIC = "italic"; //$NON-NLS-1$ |
85 |
|
|
86 |
|
|
86 | 87 |
public static final String STYLE_OBLIQUE = "oblique"; //$NON-NLS-1$ |
87 |
|
|
88 |
|
|
88 | 89 |
HashMap<String, String> fontStylePerWordIDS = new HashMap<>(); |
89 |
|
|
90 |
|
|
90 | 91 |
public static final String WEIGHT_NORMAL = "normal"; //$NON-NLS-1$ |
91 |
|
|
92 |
|
|
92 | 93 |
public static final String WEIGHT_BOLD = "bold"; //$NON-NLS-1$ |
93 |
|
|
94 |
|
|
94 | 95 |
HashMap<String, String> fontWeightPerWordIDS = new HashMap<>(); |
95 |
|
|
96 |
|
|
96 | 97 |
HashMap<String, ArrayList<RGBA>> fontColorPerWordIDS = new HashMap<>(); |
97 |
|
|
98 |
|
|
98 | 99 |
public static final String SIZE_SMALL = "small"; //$NON-NLS-1$ |
99 |
|
|
100 |
|
|
100 | 101 |
public static final String SIZE_MEDIUM = "medium"; //$NON-NLS-1$ |
101 |
|
|
102 |
|
|
102 | 103 |
public static final String SIZE_LARGE = "larger"; //$NON-NLS-1$ |
103 |
|
|
104 |
|
|
104 | 105 |
public static final String SIZE_SMALLER = "smaller"; //$NON-NLS-1$ |
105 |
|
|
106 |
|
|
106 | 107 |
public static final String SIZE_LARGER = "larger"; //$NON-NLS-1$ |
107 |
|
|
108 |
|
|
108 | 109 |
HashMap<String, String> fontSizePerWordIDS = new HashMap<>(); |
109 |
|
|
110 |
|
|
110 | 111 |
public static final String FAMILLY_TIMES = "\"Times New Roman\", Times"; //$NON-NLS-1$ |
111 |
|
|
112 |
|
|
112 | 113 |
public static final String FAMILLY_ARIAL = "Arial"; //$NON-NLS-1$ |
113 |
|
|
114 |
|
|
114 | 115 |
public static final String FAMILLY_COURIER = "\"Courier New\", Courier"; //$NON-NLS-1$ |
115 |
|
|
116 |
|
|
116 | 117 |
HashMap<String, String> fontFamillyPerWordIDS = new HashMap<>(); |
117 |
|
|
118 |
|
|
118 | 119 |
public static final String VARIANT_NORMAL = "normal"; //$NON-NLS-1$ |
119 |
|
|
120 |
|
|
120 | 121 |
public static final String VARIANT_SMALLCAPS = "small-caps"; //$NON-NLS-1$ |
121 |
|
|
122 |
|
|
122 | 123 |
HashMap<String, String> fontVariantPerWordIDS = new HashMap<>(); |
123 |
|
|
124 |
|
|
124 | 125 |
String focusedWordID = null; |
125 |
|
|
126 |
|
|
126 | 127 |
public static final String highlightscript = "try { var elt = document.getElementById(\"%s\");" + //$NON-NLS-1$ |
127 | 128 |
"elt.style.backgroundColor=\"rgb(%s,%s,%s)\";" + //$NON-NLS-1$ |
128 | 129 |
// "elt.style.paddingLeft=\"3px\";" + //$NON-NLS-1$ |
... | ... | |
130 | 131 |
// "elt.style.paddingTop=\"1px\";" + //$NON-NLS-1$ |
131 | 132 |
// "elt.style.paddingBottom=\"1px\";" + //$NON-NLS-1$ |
132 | 133 |
"} catch (e) { };"; //$NON-NLS-1$ |
133 |
|
|
134 |
|
|
134 | 135 |
public static final String highlightscriptRuleFast = "sheet.insertRule(\"#%s {background-color:rgba(%s,%s,%s,%s);}\", 0);"; //$NON-NLS-1$ |
135 |
|
|
136 |
|
|
136 | 137 |
public static final String colorscriptRuleFast = "sheet.insertRule(\"#%s {color:rgba(%s,%s,%s,%s);}\", 0);"; //$NON-NLS-1$ |
137 |
|
|
138 |
|
|
138 | 139 |
public static final String sizescriptRuleFast = "sheet.insertRule(\"#%s {font-size:%s;}\", 0);"; //$NON-NLS-1$ |
139 |
|
|
140 |
|
|
140 | 141 |
public static final String stylescriptRuleFast = "sheet.insertRule(\"#%s {font-style:%s;}\", 0);"; //$NON-NLS-1$ |
141 |
|
|
142 |
|
|
142 | 143 |
public static final String variantscriptRuleFast = "sheet.insertRule(\"#%s {font-variant:%s;}\", 0);"; //$NON-NLS-1$ |
143 |
|
|
144 |
|
|
144 | 145 |
public static final String famillyscriptRuleFast = "sheet.insertRule(\"#%s {font-familly:%s;}\", 0);"; //$NON-NLS-1$ |
145 |
|
|
146 |
|
|
146 | 147 |
public static final String weightscriptRuleFast = "sheet.insertRule(\"#%s {font-weight:%s;}\", 0);"; //$NON-NLS-1$ |
147 |
|
|
148 |
|
|
148 | 149 |
public static final String highlightscriptRule = "sheet.insertRule(\"span[id=\\\"%s\\\"] {background-color:rgba(%s,%s,%s,%s); }\", 0);"; //$NON-NLS-1$ |
149 |
|
|
150 |
|
|
150 | 151 |
public static final String clearhighlightscript = "try { var elt = document.getElementById(\"%s\"); elt.style.backgroundColor=\"white\";elt.style.fontWeight=\"\";" + //$NON-NLS-1$ |
151 | 152 |
"} catch (e) { };"; //$NON-NLS-1$ |
152 |
|
|
153 |
|
|
153 | 154 |
public String functions = ""// "alert(\"loading functions\");" //$NON-NLS-1$ |
154 | 155 |
+ "\ngetNodeText = function getNodeText(node) {" //$NON-NLS-1$ |
155 | 156 |
+ "\n if (typeof node == 'string') return node;" //$NON-NLS-1$ |
... | ... | |
261 | 262 |
+ "\n };" //$NON-NLS-1$ |
262 | 263 |
+ "\n}" //$NON-NLS-1$ |
263 | 264 |
+ "\n} catch(e) {Element.prototype.scrollIntoViewIfNeeded = Element.prototype.scrollIntoView}"; //$NON-NLS-1$ |
264 |
|
|
265 |
|
|
265 | 266 |
protected boolean fastWordHighLight = SynopticEditionPreferences.getInstance().getBoolean(SynopticEditionPreferences.FAST_HIGHLIGHT); |
266 |
|
|
267 |
|
|
267 | 268 |
private ArrayList<ProgressListener> beforeHighlighListeners; |
268 |
|
|
269 |
|
|
269 | 270 |
public ArrayList<ProgressListener> getBeforeHighlighListeners() { |
270 |
|
|
271 |
|
|
271 | 272 |
return beforeHighlighListeners; |
272 | 273 |
} |
273 |
|
|
274 |
|
|
274 | 275 |
private ArrayList<ProgressListener> afterHighlighListeners; |
275 |
|
|
276 |
|
|
276 | 277 |
private CommandLink cmdLink; |
277 |
|
|
278 |
|
|
278 | 279 |
private EditionLink editionLink; |
279 |
|
|
280 |
|
|
280 | 281 |
public ArrayList<ProgressListener> getAfterHighlighListeners() { |
281 |
|
|
282 |
|
|
282 | 283 |
return beforeHighlighListeners; |
283 | 284 |
} |
284 |
|
|
285 |
|
|
285 | 286 |
public Object evaluate(String code) { |
286 |
|
|
287 |
|
|
287 | 288 |
if (Log.getLevel().intValue() <= Level.FINEST.intValue()) System.out.println(code); |
288 |
|
|
289 |
|
|
289 | 290 |
try { |
290 | 291 |
if (getBrowser() == null) return null; |
291 | 292 |
return getBrowser().evaluate(code); |
... | ... | |
297 | 298 |
} |
298 | 299 |
return null; |
299 | 300 |
} |
300 |
|
|
301 |
|
|
301 | 302 |
public boolean execute(String code) { |
302 |
|
|
303 |
|
|
303 | 304 |
if (Log.getLevel().intValue() <= Level.FINEST.intValue()) System.out.println(code); |
304 | 305 |
try { |
305 | 306 |
//System.out.println("EXECUTE: "+code.replace("\n", " RET ").subSequence(0, Math.min(200, code.length()))); |
... | ... | |
311 | 312 |
} |
312 | 313 |
return false; |
313 | 314 |
} |
314 |
|
|
315 |
|
|
315 | 316 |
public EditionPanel(SynopticEditionEditor synopticEditionEditor, Composite parent, int style, String editionName) { |
316 |
|
|
317 |
|
|
317 | 318 |
super(parent, style); |
318 | 319 |
this.synopticEditionEditor = synopticEditionEditor; |
319 | 320 |
this.editionName = editionName; |
320 | 321 |
// this.currentEdition = edition; |
321 | 322 |
// this.currentText = currentEdition.getText(); |
322 |
|
|
323 |
|
|
323 | 324 |
File functionsFile = null; |
324 | 325 |
try { |
325 | 326 |
Bundle bundle = Platform.getBundle("org.txm.edition.rcp"); //$NON-NLS-1$ |
... | ... | |
332 | 333 |
Log.severe(EditionUIMessages.bind(EditionUIMessages.error_while_readingP0P1, functionsFile, e.getLocalizedMessage())); |
333 | 334 |
Log.printStackTrace(e); |
334 | 335 |
} |
335 |
|
|
336 |
|
|
336 | 337 |
beforeHighlighListeners = new ArrayList<>(); |
337 | 338 |
afterHighlighListeners = new ArrayList<>(); |
338 |
|
|
339 |
|
|
339 | 340 |
// this.browser.addLocationListener(new LocationListener() { |
340 | 341 |
// |
341 | 342 |
// @Override |
... | ... | |
351 | 352 |
// if (editionLink != null) cmdLink.dispose(); |
352 | 353 |
// } |
353 | 354 |
// }); |
354 |
|
|
355 |
|
|
355 |
|
|
356 |
|
|
356 | 357 |
this.addDisposeListener(new DisposeListener() { // clean the BrowserFunction s |
357 |
|
|
358 |
|
|
358 | 359 |
@Override |
359 | 360 |
public void widgetDisposed(DisposeEvent e) { |
360 | 361 |
// System.out.println("dispose listener called"); |
... | ... | |
363 | 364 |
if (browser!= null && !browser.isDisposed()) browser.dispose(); |
364 | 365 |
} |
365 | 366 |
}); |
366 |
|
|
367 |
|
|
367 | 368 |
if (cmdLink == null) { |
368 | 369 |
cmdLink = new CommandLink(synopticEditionEditor, browser); |
369 | 370 |
} |
... | ... | |
388 | 389 |
// editionLink = new EditionLink(synopticEditionEditor, browser); |
389 | 390 |
// } |
390 | 391 |
// }); |
391 |
|
|
392 |
|
|
392 | 393 |
progressListener = new ProgressListener() { |
393 |
|
|
394 |
|
|
394 | 395 |
@Override |
395 | 396 |
public void changed(ProgressEvent event) {} |
396 |
|
|
397 |
|
|
397 | 398 |
@Override |
398 | 399 |
public synchronized void completed(ProgressEvent event) { |
399 |
|
|
400 |
|
|
400 | 401 |
Browser browser = getBrowser(); |
401 | 402 |
Object o = browser.evaluate("return typeof " + CommandLink.FCT + ";"); //$NON-NLS-1$ //$NON-NLS-2$ |
402 | 403 |
if ("undefined".equals(o)) { //$NON-NLS-1$ |
... | ... | |
414 | 415 |
editionLink = new EditionLink(synopticEditionEditor, browser); |
415 | 416 |
//System.out.println("rebuild editionLink"); |
416 | 417 |
} |
417 |
|
|
418 |
|
|
419 |
|
|
418 |
|
|
419 |
EditionPanel.this.getBrowser().execute(""" |
|
420 |
document.addEventListener('mouseover', function (e) { |
|
421 |
document.currentHoverElement = e.target |
|
422 |
}); """); |
|
423 |
|
|
424 |
|
|
425 |
|
|
420 | 426 |
Object rez = evaluate("return typeof sheet;"); //$NON-NLS-1$ |
421 | 427 |
if ("undefined".equals(rez)) { //$NON-NLS-1$ |
422 | 428 |
Object loadResult = evaluate(functions); |
... | ... | |
428 | 434 |
Log.finer("JS functions loaded."); //$NON-NLS-1$ |
429 | 435 |
} |
430 | 436 |
} |
431 |
|
|
437 |
|
|
432 | 438 |
// do something before the highlight is done |
433 | 439 |
for (ProgressListener pl : beforeHighlighListeners) { |
434 | 440 |
pl.completed(event); |
435 | 441 |
} |
436 |
|
|
442 |
|
|
437 | 443 |
// System.out.println("highlight: "+highlightedColorPerWordIDS); |
438 | 444 |
StringBuilder buffer = new StringBuilder(); |
439 | 445 |
// buffer.append("alert(\"\"+sheet);\n"); |
... | ... | |
445 | 451 |
else { |
446 | 452 |
buffer.append("try { while(sheet.cssRules.length > 0) sheet.deleteRule(0); } catch (e) {};\n"); // empty style //$NON-NLS-1$ |
447 | 453 |
} |
448 |
|
|
454 |
|
|
449 | 455 |
if (buffer.length() > 0) { |
450 | 456 |
if (!execute(buffer.toString())) { |
451 | 457 |
Log.fine("JS execution error (delete cssRules) with=" + buffer); //$NON-NLS-1$ |
452 | 458 |
} |
453 | 459 |
} |
454 |
|
|
455 |
|
|
460 |
|
|
461 |
|
|
456 | 462 |
buffer = new StringBuilder(); |
457 | 463 |
Log.finest("EditionPanel " + currentEdition + " reload " + currentPage); //$NON-NLS-1$ //$NON-NLS-2$ |
458 | 464 |
if (currentPage != null && currentEdition != null) { // avoid null pointer |
459 |
|
|
465 |
|
|
460 | 466 |
String firstWord = currentPage.getWordId(); |
461 | 467 |
Page nextPage = currentEdition.getNextPage(currentPage); |
462 | 468 |
String lastWord = "w_999999999"; //$NON-NLS-1$ |
... | ... | |
475 | 481 |
// System.out.println("firstWord="+firstWord+" lastWord="+lastWord); |
476 | 482 |
// int n = 0; |
477 | 483 |
// long start = System.currentTimeMillis(); |
478 |
|
|
484 |
|
|
479 | 485 |
for (String wordid : highlightedColorPerWordIDS.keySet()) { |
480 | 486 |
// Log.finest("words to highlight: "+highlightedColorPerWordIDS); |
481 | 487 |
if (highlightedColorPerWordIDS.get(wordid).size() == 0) continue; // error |
482 |
|
|
488 |
|
|
483 | 489 |
// if (!slowWordHighLight) { //TODO: this code must be replaced with word position instead of word id comparaison |
484 | 490 |
if (Edition.isFirstGTthanSecond(wordid, firstWord) < 0) continue; // skip the word to highlight |
485 | 491 |
if (Edition.isFirstGTthanSecond(lastWord, wordid) < 0) continue; // skip the word to highlight |
... | ... | |
487 | 493 |
// n++; |
488 | 494 |
RGBA composite = new RGBA(0, 0, 0, 0f); |
489 | 495 |
int size = highlightedColorPerWordIDS.get(wordid).size(); |
490 |
|
|
496 |
|
|
491 | 497 |
for (RGBA color : highlightedColorPerWordIDS.get(wordid)) { |
492 | 498 |
composite.r += color.r; |
493 | 499 |
composite.g += color.g; |
494 | 500 |
composite.b += color.b; |
495 | 501 |
composite.a += color.a; |
496 | 502 |
} |
497 |
|
|
503 |
|
|
498 | 504 |
composite.r /= size; |
499 | 505 |
composite.g /= size; |
500 | 506 |
composite.b /= size; |
501 |
|
|
507 |
|
|
502 | 508 |
String s = null; |
503 | 509 |
if (!fastWordHighLight) { |
504 | 510 |
// s = String.format(highlightscriptRule, wordid, composite.r, composite.g, composite.b, composite.a); |
... | ... | |
515 | 521 |
s = String.format(highlightscriptRuleFast, wordid.replace(" ", "\\ "), composite.r, composite.g, composite.b, composite.a); //$NON-NLS-1$ //$NON-NLS-2$ |
516 | 522 |
// s = String.format(highlightscriptRuleFast, wordid, composite.r, composite.g, composite.b, composite.a); |
517 | 523 |
} |
518 |
|
|
524 |
|
|
519 | 525 |
buffer.append(s + "\n"); //$NON-NLS-1$ |
520 | 526 |
} |
521 | 527 |
} |
522 |
|
|
528 |
|
|
523 | 529 |
if (buffer.length() > 0) { |
524 | 530 |
if (!execute(buffer.toString())) { |
525 | 531 |
Log.fine("JS execution (highlight) error with=" + buffer); //$NON-NLS-1$ |
526 | 532 |
} |
527 | 533 |
} |
528 |
|
|
529 |
|
|
534 |
|
|
535 |
|
|
530 | 536 |
buffer = new StringBuilder(); |
531 |
|
|
537 |
|
|
532 | 538 |
// for (String wordidslist : highlightedColorSpans.keySet()) { |
533 | 539 |
// RGBA composite = new RGBA(0,0,0,0f); |
534 | 540 |
// int size = highlightedColorSpans.get(wordidslist).size(); |
... | ... | |
548 | 554 |
// cmd += "wrap(l, \""+wordidslist+"\";\n"; |
549 | 555 |
// buffer.append(cmd+"\n"); |
550 | 556 |
// } |
551 |
|
|
557 |
|
|
552 | 558 |
for (String wordid : fontColorPerWordIDS.keySet()) { |
553 | 559 |
RGBA composite = new RGBA(0, 0, 0, 0f); |
554 | 560 |
int size = fontColorPerWordIDS.get(wordid).size(); |
555 |
|
|
561 |
|
|
556 | 562 |
for (RGBA color : fontColorPerWordIDS.get(wordid)) { |
557 | 563 |
composite.r += color.r; |
558 | 564 |
composite.g += color.g; |
559 | 565 |
composite.b += color.b; |
560 | 566 |
composite.a += color.a; |
561 | 567 |
} |
562 |
|
|
568 |
|
|
563 | 569 |
composite.r /= size; |
564 | 570 |
composite.g /= size; |
565 | 571 |
composite.b /= size; |
566 |
|
|
572 |
|
|
567 | 573 |
String s = String.format(colorscriptRuleFast, wordid, composite.r, composite.g, composite.b, composite.a); |
568 | 574 |
buffer.append(s + "\n"); //$NON-NLS-1$ |
569 | 575 |
} |
570 |
|
|
576 |
|
|
571 | 577 |
if (buffer.length() > 0) { |
572 | 578 |
if (!execute(buffer.toString())) { |
573 | 579 |
Log.fine("JS execution (color) error with=" + buffer); //$NON-NLS-1$ |
574 | 580 |
} |
575 | 581 |
} |
576 |
|
|
577 |
|
|
582 |
|
|
583 |
|
|
578 | 584 |
buffer = new StringBuilder(); |
579 |
|
|
585 |
|
|
580 | 586 |
for (String wordid : fontSizePerWordIDS.keySet()) { |
581 | 587 |
String s = String.format(sizescriptRuleFast, wordid, fontSizePerWordIDS.get(wordid)); |
582 | 588 |
buffer.append(s + "\n"); //$NON-NLS-1$ |
583 | 589 |
} |
584 |
|
|
590 |
|
|
585 | 591 |
for (String wordid : fontWeightPerWordIDS.keySet()) { |
586 | 592 |
String s = null; |
587 | 593 |
if (!fastWordHighLight) { |
... | ... | |
607 | 613 |
} |
608 | 614 |
buffer.append(s + "\n"); //$NON-NLS-1$ |
609 | 615 |
} |
610 |
|
|
616 |
|
|
611 | 617 |
for (String wordid : fontFamillyPerWordIDS.keySet()) { |
612 | 618 |
String s = String.format(famillyscriptRuleFast, wordid, fontFamillyPerWordIDS.get(wordid)); |
613 | 619 |
buffer.append(s + "\n"); //$NON-NLS-1$ |
614 | 620 |
} |
615 |
|
|
621 |
|
|
616 | 622 |
if (buffer.length() > 0) { |
617 | 623 |
if (!execute(buffer.toString())) { |
618 | 624 |
Log.fine("JS execution (font) error with=" + buffer); //$NON-NLS-1$ |
619 | 625 |
} |
620 | 626 |
} |
621 |
|
|
622 |
|
|
627 |
|
|
628 |
|
|
623 | 629 |
buffer = new StringBuilder(); |
624 |
|
|
630 |
|
|
625 | 631 |
if (focusedWordID != null) { |
626 | 632 |
// System.out.println("Focus on: "+focusedWordID); |
627 | 633 |
String s = "try { showElementIfNeeded(document.getElementById(\"" + focusedWordID + "\")); } catch (e) {document.getElementById(\"" + focusedWordID + "\").scrollIntoView();};"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
628 | 634 |
//String s = "document.getElementById(\"" + focusedWordID + "\").scrollIntoView();"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
629 | 635 |
buffer.append(s + "\n"); //$NON-NLS-1$ |
630 | 636 |
} |
631 |
|
|
637 |
|
|
632 | 638 |
if (buffer.length() > 0) { |
633 | 639 |
//Object rez2 = execute(buffer.toString()); |
634 | 640 |
if (execute(buffer.toString())) { |
... | ... | |
638 | 644 |
Log.fine("JS execution (focus) error with script=" + buffer); //$NON-NLS-1$ |
639 | 645 |
} |
640 | 646 |
} |
641 |
|
|
647 |
|
|
642 | 648 |
buffer = new StringBuilder(); |
643 |
|
|
649 |
|
|
644 | 650 |
if (highlightedAreas != null) { |
645 | 651 |
for (int[] pos : highlightedAreas) { |
646 | 652 |
if (pos == null || pos.length != 4) continue; |
... | ... | |
649 | 655 |
break;// one word only for now |
650 | 656 |
} |
651 | 657 |
} |
652 |
|
|
658 |
|
|
653 | 659 |
// System.out.println(buffer); |
654 | 660 |
if (buffer.length() > 0) { |
655 | 661 |
if (!execute(buffer.toString())) { |
... | ... | |
657 | 663 |
} |
658 | 664 |
} |
659 | 665 |
// System.out.println("n="+n+" time="+(System.currentTimeMillis()-start)); |
660 |
|
|
666 |
|
|
661 | 667 |
// do something after the highlight is done |
662 | 668 |
for (ProgressListener pl : afterHighlighListeners) { |
663 | 669 |
pl.completed(event); |
664 | 670 |
} |
665 | 671 |
} |
666 | 672 |
}; |
667 |
|
|
673 |
|
|
668 | 674 |
getBrowser().addMouseListener(new MouseListener() { |
669 |
|
|
675 |
|
|
670 | 676 |
boolean dblClick = false; |
671 |
|
|
677 |
|
|
672 | 678 |
boolean debug = true; |
673 |
|
|
679 |
|
|
674 | 680 |
private int t, x, y; |
675 |
|
|
681 |
|
|
676 | 682 |
@Override |
677 | 683 |
public void mouseDoubleClick(MouseEvent e) { |
678 |
|
|
684 |
|
|
679 | 685 |
if (debug) Log.finest("DOUBLE CLICK"); //$NON-NLS-1$ |
680 | 686 |
dblClick = true; |
681 | 687 |
} |
682 |
|
|
688 |
|
|
683 | 689 |
@Override |
684 | 690 |
public void mouseDown(MouseEvent e) { |
685 |
|
|
691 |
|
|
686 | 692 |
if (debug) Log.finest("MOUSE DOWN"); //$NON-NLS-1$ |
687 | 693 |
dblClick = false; |
688 | 694 |
t = e.time; |
689 | 695 |
x = e.x; |
690 | 696 |
y = e.y; |
691 | 697 |
} |
692 |
|
|
698 |
|
|
693 | 699 |
@Override |
694 | 700 |
public void mouseUp(MouseEvent e) { |
695 |
|
|
701 |
|
|
696 | 702 |
if (dblClick) { // doucle click raised by mouseDoubleClick |
697 | 703 |
dblClick = false; |
698 | 704 |
return; // stop right now ! :-o |
699 | 705 |
} |
700 | 706 |
if (debug) Log.finest("MOUSE UP"); //$NON-NLS-1$ |
701 | 707 |
EditionPanel panel = EditionPanel.this; |
702 |
|
|
708 |
|
|
703 | 709 |
// filter click that are not a left simple click (no drag) |
704 | 710 |
// 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))); |
705 | 711 |
if (e.count > 1) { |
... | ... | |
707 | 713 |
// System.out.println("not a simple click"); |
708 | 714 |
return; |
709 | 715 |
} |
710 |
|
|
716 |
|
|
711 | 717 |
int dist = Math.abs(e.x - x) + Math.abs(e.y - y); |
712 | 718 |
int deltat = (e.time - t); |
713 | 719 |
// System.out.println("deltat ="+deltat); |
714 | 720 |
if (dist >= 0 && (deltat > 0 || dist > 0)) { |
715 | 721 |
// System.out.println(" DRAG dist="+dist+" deltat="+deltat); |
716 | 722 |
String[] ids = panel.getWordSelection(); // may be null |
717 |
|
|
723 |
|
|
718 | 724 |
panel.expandSelectionTo(ids); |
719 | 725 |
return; |
720 | 726 |
} |
721 | 727 |
} |
722 | 728 |
}); |
723 |
|
|
729 |
|
|
724 | 730 |
browser.addMouseWheelListener(new MouseWheelListener() { |
725 |
|
|
731 |
|
|
726 | 732 |
@Override |
727 | 733 |
public void mouseScrolled(MouseEvent e) { |
728 |
|
|
734 |
|
|
729 | 735 |
if ((e.stateMask & SWT.CTRL) == SWT.CTRL) { |
730 | 736 |
if (e.count > 0) { |
731 | 737 |
TXMBrowserEditor.zoomIn(getBrowser()); |
... | ... | |
735 | 741 |
} |
736 | 742 |
} |
737 | 743 |
}); |
738 |
|
|
744 |
|
|
739 | 745 |
KeyListener kListener = new KeyListener() { |
740 |
|
|
746 |
|
|
741 | 747 |
boolean debug = true; |
742 |
|
|
748 |
|
|
743 | 749 |
@Override |
744 | 750 |
public void keyReleased(KeyEvent e) { |
745 |
|
|
751 |
|
|
746 | 752 |
if (debug) Log.finest(" KEY RELEASED: " + e); //$NON-NLS-1$ |
747 | 753 |
} |
748 |
|
|
754 |
|
|
749 | 755 |
@Override |
750 | 756 |
public void keyPressed(KeyEvent e) { |
751 |
|
|
757 |
|
|
752 | 758 |
if (debug) Log.finest(" KEY PRESSED: " + e); //$NON-NLS-1$ |
753 | 759 |
if (e.keyCode == 'f' && (e.stateMask & SWT.CTRL) != 0) { |
754 | 760 |
synopticEditionEditor.getSearchEditionToolbar().openSearch(getTextSelection()); |
... | ... | |
757 | 763 |
}; |
758 | 764 |
getBrowser().setCapture(true); |
759 | 765 |
getBrowser().addKeyListener(kListener); |
760 |
|
|
766 |
|
|
761 | 767 |
getBrowser().addProgressListener(progressListener); |
762 | 768 |
} |
763 |
|
|
769 |
|
|
764 | 770 |
/** |
765 | 771 |
* Bypass BrowserViewer restriction on the getBrowser method |
766 | 772 |
*/ |
767 | 773 |
@Override |
768 | 774 |
public Browser getBrowser() { |
769 |
|
|
775 |
|
|
770 | 776 |
return super.getBrowser(); |
771 | 777 |
} |
772 |
|
|
778 |
|
|
773 | 779 |
/** |
774 | 780 |
* Bypass BrowserViewer restriction on the getBrowser method |
775 | 781 |
*/ |
776 | 782 |
public String getDOM() { |
777 |
|
|
783 |
|
|
778 | 784 |
return "";// execute("return document.innerHTML"; //$NON-NLS-1$ |
779 | 785 |
} |
780 |
|
|
786 |
|
|
781 | 787 |
public ISelectionProvider getSelectionProvider() { |
782 |
|
|
788 |
|
|
783 | 789 |
return selProvider; |
784 | 790 |
} |
785 |
|
|
791 |
|
|
786 | 792 |
public void setHighlightWordsById(RGBA color, HashSet<String> wordids) { |
787 |
|
|
793 |
|
|
788 | 794 |
for (String wordid : wordids) { |
789 | 795 |
if (this.highlightedColorPerWordIDS.get(wordid) != null) { |
790 | 796 |
removeHighlightWordsById(color, wordid); |
... | ... | |
794 | 800 |
hs.add(color); |
795 | 801 |
} |
796 | 802 |
} |
797 |
|
|
803 |
|
|
798 | 804 |
public void addHighlightWordsById(RGBA color, String wordid) { |
799 |
|
|
805 |
|
|
800 | 806 |
if (!this.highlightedColorPerWordIDS.containsKey(wordid)) { |
801 | 807 |
this.highlightedColorPerWordIDS.put(wordid, new ArrayList<RGBA>()); |
802 | 808 |
} |
803 | 809 |
this.highlightedColorPerWordIDS.get(wordid).add(color); |
804 | 810 |
} |
805 |
|
|
811 |
|
|
806 | 812 |
/** |
807 | 813 |
* Can be called to refresh the page word styles but only when the page is loaded |
808 | 814 |
*/ |
809 | 815 |
public void updateWordStyles() { |
810 |
|
|
816 |
|
|
811 | 817 |
progressListener.completed(null); |
812 | 818 |
} |
813 |
|
|
819 |
|
|
814 | 820 |
public void addHighlightWordsById(RGBA color, Collection<String> wordids) { |
815 |
|
|
821 |
|
|
816 | 822 |
for (String wordid : wordids) { |
817 | 823 |
addHighlightWordsById(color, wordid); |
818 | 824 |
} |
819 | 825 |
} |
820 |
|
|
826 |
|
|
821 | 827 |
public void removeHighlightWordsById(RGBA color, Collection<String> wordids) { |
822 |
|
|
828 |
|
|
823 | 829 |
// System.out.println("Call removeHighlightWordsById: "+wordids+" color="+color); |
824 | 830 |
StringBuffer buffer = new StringBuffer(); |
825 | 831 |
for (String wordid : wordids) { |
... | ... | |
828 | 834 |
buffer.append(String.format(clearhighlightscript, wordid) + "\n"); //$NON-NLS-1$ |
829 | 835 |
} |
830 | 836 |
} |
831 |
|
|
837 |
|
|
832 | 838 |
if (buffer.length() > 0) execute(buffer.toString()); |
833 | 839 |
} |
834 |
|
|
840 |
|
|
835 | 841 |
public void removeHighlightWordsById(RGBA color, String wordid) { |
836 |
|
|
842 |
|
|
837 | 843 |
if (highlightedColorPerWordIDS.get(wordid) == null) return; // nothing to do |
838 |
|
|
844 |
|
|
839 | 845 |
// System.out.println("remove color="+color+" from id="+wordid); |
840 | 846 |
this.highlightedColorPerWordIDS.get(wordid).remove(color); |
841 |
|
|
847 |
|
|
842 | 848 |
if (this.highlightedColorPerWordIDS.get(wordid).size() == 0) { |
843 | 849 |
this.highlightedColorPerWordIDS.remove(wordid); |
844 | 850 |
} |
845 | 851 |
} |
846 |
|
|
852 |
|
|
847 | 853 |
/** |
848 | 854 |
* Open the page containing the word with ID=$line_wordid |
849 | 855 |
* |
... | ... | |
851 | 857 |
* @return true if the page changed |
852 | 858 |
*/ |
853 | 859 |
public boolean backToText(Text text, String line_wordid) { |
854 |
|
|
860 |
|
|
855 | 861 |
// String name = currentEdition.getName(); |
856 | 862 |
Edition edition = text.getEdition(editionName); |
857 |
|
|
863 |
|
|
858 | 864 |
if (edition == null) { |
859 | 865 |
String s = EditionUIMessages.bind(EditionUIMessages.noEditionFoundForTextEqualsP0AndEditionEqualsP1, text, editionName); |
860 | 866 |
Log.warning(s); |
... | ... | |
876 | 882 |
updateWordStyles(); // no need to change the page, but still update the focus&styles |
877 | 883 |
} |
878 | 884 |
} |
879 |
|
|
885 |
|
|
880 | 886 |
return false; |
881 | 887 |
} |
882 |
|
|
888 |
|
|
883 | 889 |
/** |
884 | 890 |
* First page. |
885 | 891 |
*/ |
886 | 892 |
public void firstPage() { |
887 |
|
|
893 |
|
|
888 | 894 |
if (currentEdition == null) return; |
889 |
|
|
895 |
|
|
890 | 896 |
// System.out.println(Messages.TxmBrowser_1+currentPage); |
891 | 897 |
currentPage = currentEdition.getFirstPage(); |
892 | 898 |
currentText = currentEdition.getText(); |
... | ... | |
894 | 900 |
System.out.println(EditionUIMessages.bind(EditionUIMessages.failToRetrieveFirstPageOfEditionEqualsP0AndTextEqualsP1, currentEdition.getName(), currentText.getName())); |
895 | 901 |
return; |
896 | 902 |
} |
897 |
|
|
903 |
|
|
898 | 904 |
reloadPage(); |
899 |
|
|
905 |
|
|
900 | 906 |
// page_label.setText(makePageLabel()); |
901 | 907 |
} |
902 |
|
|
908 |
|
|
903 | 909 |
public static String fromEncodeString = "\"-&-'-<->-`- -¡-¢-£-¥-§-©-«-®-°-±-´-µ-¶-·-»-¿-À-Á-Â-Ã-Ä-Æ-Ç-È-É-Ê-Ë-Ì-Í-Î-Ï-Ñ-Ò-Ó-Ô-Õ-Ö-Ø-Ù-Ú-Û-Ü-ß-à-á-â-ã-ä-å-æ-ç-è-é-ê-ë-ì-í-î-ï-ð-ñ-ò-ó-ô-õ-ö-÷-ø-ù-ú-û-ü-ý-ÿ-Ā-ā-ĉ-Č-č-ē-ĝ-ģ-ĥ-Ī-ī-ĵ-ő-œ-ŕ-ř-ŝ-Š-š-Ū-ū-ŭ-ű-ŵ-ŷ-π-ḧ-ẅ-ẍ-ẑ-ỳ- - -–-—-‘-’-•-′-″-€-™-←-↑-→-↓-↖-↗-↘-↙-⌘-⏏-☑-✔"; //$NON-NLS-1$ |
904 | 910 |
public static String toEncodeString = "%22-%26-%27-%3C-%3E-%60-%C2%A0-%C2%A1-%C2%A2-%C2%A3-%C2%A5-%C2%A7-%C2%A9-%C2%AB-%C2%AE-%C2%B0-%C2%B1-%C2%B4-%C2%B5-%C2%B6-%C2%B7-%C2%BB-%C2%BF-%C3%80-%C3%81-%C3%82-%C3%83-%C3%84-%C3%86-%C3%87-%C3%88-%C3%89-%C3%8A-%C3%8B-%C3%8C-%C3%8D-%C3%8E-%C3%8F-%C3%91-%C3%92-%C3%93-%C3%94-%C3%95-%C3%96-%C3%98-%C3%99-%C3%9A-%C3%9B-%C3%9C-%C3%9F-%C3%A0-%C3%A1-%C3%A2-%C3%A3-%C3%A4-%C3%A5-%C3%A6-%C3%A7-%C3%A8-%C3%A9-%C3%AA-%C3%AB-%C3%AC-%C3%AD-%C3%AE-%C3%AF-%C3%B0-%C3%B1-%C3%B2-%C3%B3-%C3%B4-%C3%B5-%C3%B6-%C3%B7-%C3%B8-%C3%B9-%C3%BA-%C3%BB-%C3%BC-%C3%BD-%C3%BF-%C4%80-%C4%81-%C4%89-%C4%8C-%C4%8D-%C4%93-%C4%9D-%C4%A3-%C4%A5-%C4%AA-%C4%AB-%C4%B5-%C5%91-%C5%93-%C5%95-%C5%99-%C5%9D-%C5%A0-%C5%A1-%C5%AA-%C5%AB-%C5%AD-%C5%B1-%C5%B5-%C5%B7-%CF%80-%E1%B8%A7-%E1%BA%85-%E1%BA%8D-%E1%BA%91-%E1%BB%B3-%E2%80%82-%E2%80%83-%E2%80%93-%E2%80%94-%E2%80%98-%E2%80%99-%E2%80%A2-%E2%80%B2-%E2%80%B3-%E2%82%AC-%E2%84%A2-%E2%86%90-%E2%86%91-%E2%86%92-%E2%86%93-%E2%86%96-%E2%86%97-%E2%86%98-%E2%86%99-%E2%8C%98-%E2%8F%8F-%E2%98%91-%E2%9C%94"; //$NON-NLS-1$ |
905 | 911 |
private static String[] fromEncode, toEncode; |
... | ... | |
916 | 922 |
} |
917 | 923 |
return url; |
918 | 924 |
} |
919 |
|
|
925 |
|
|
920 | 926 |
@Override |
921 | 927 |
public void setURL(String url) { |
922 |
|
|
928 |
|
|
923 | 929 |
if (!this.browser.isDisposed()) { |
924 | 930 |
if (fromEncode != null) { |
925 | 931 |
url = encodeURL(url); |
926 | 932 |
} |
927 | 933 |
super.setURL(url); |
928 |
|
|
934 |
|
|
929 | 935 |
// if ("webkit".equals(this.browser.getBrowserType())) { |
930 | 936 |
// String u = URLUtils.encodeURL(url); |
931 | 937 |
// Log.finer("setting encoded URL: "+u); |
... | ... | |
946 | 952 |
// // TODO Auto-generated catch block |
947 | 953 |
// e.printStackTrace(); |
948 | 954 |
// } |
949 |
|
|
955 |
|
|
950 | 956 |
} |
951 | 957 |
} |
952 |
|
|
958 |
|
|
953 | 959 |
/** |
954 | 960 |
* Last page. |
955 | 961 |
*/ |
956 | 962 |
public void lastPage() { |
957 | 963 |
// System.out.println(Messages.TxmBrowser_2+currentPage); |
958 | 964 |
if (currentEdition == null) return; |
959 |
|
|
965 |
|
|
960 | 966 |
if (currentPage != null && currentPage.getFile().equals(currentEdition.getLastPage().getFile())) { |
961 | 967 |
return; |
962 | 968 |
} |
... | ... | |
964 | 970 |
currentText = currentEdition.getText(); |
965 | 971 |
reloadPage(); |
966 | 972 |
} |
967 |
|
|
973 |
|
|
968 | 974 |
/** |
969 | 975 |
* Previous page. |
970 | 976 |
*/ |
971 | 977 |
public void previousPage() { |
972 |
|
|
978 |
|
|
973 | 979 |
if (currentEdition == null) return; |
974 |
|
|
980 |
|
|
975 | 981 |
// System.out.println(Messages.TxmBrowser_3+currentPage); |
976 | 982 |
if (currentPage != null) { |
977 | 983 |
Page previous = currentEdition.getPreviousPage(currentPage); |
978 |
|
|
984 |
|
|
979 | 985 |
if (previous == currentPage) { |
980 | 986 |
previousText(true); |
981 | 987 |
} |
... | ... | |
990 | 996 |
} |
991 | 997 |
// page_label.setText(makePageLabel()); |
992 | 998 |
} |
993 |
|
|
994 |
|
|
995 |
|
|
999 |
|
|
1000 |
|
|
1001 |
|
|
996 | 1002 |
/** |
997 | 1003 |
* Next page. |
998 | 1004 |
*/ |
999 | 1005 |
public void nextPage() { |
1000 |
|
|
1006 |
|
|
1001 | 1007 |
if (currentEdition == null) return; |
1002 |
|
|
1008 |
|
|
1003 | 1009 |
// System.out.println(Messages.TxmBrowser_4+currentPage); |
1004 | 1010 |
if (currentPage != null) { |
1005 | 1011 |
Page next = currentEdition.getNextPage(currentPage); |
... | ... | |
1017 | 1023 |
} |
1018 | 1024 |
// page_label.setText(makePageLabel()); |
1019 | 1025 |
} |
1020 |
|
|
1021 |
|
|
1026 |
|
|
1027 |
|
|
1022 | 1028 |
public void firstText() { |
1023 |
|
|
1029 |
|
|
1024 | 1030 |
// Text current = this.currentPage.getEdition().getText(); |
1025 | 1031 |
Project project = currentText.getProject(); |
1026 | 1032 |
String id; |
... | ... | |
1032 | 1038 |
return; |
1033 | 1039 |
} |
1034 | 1040 |
Text firstText = project.getText(id); |
1035 |
|
|
1041 |
|
|
1036 | 1042 |
if (firstText != null) { |
1037 | 1043 |
String editionName = currentEdition.getName(); |
1038 | 1044 |
Edition tmp = firstText.getEdition(editionName); |
... | ... | |
1050 | 1056 |
reloadPage(); |
1051 | 1057 |
} |
1052 | 1058 |
} |
1053 |
|
|
1059 |
|
|
1054 | 1060 |
/** |
1055 | 1061 |
* Next text. |
1056 | 1062 |
*/ |
1057 | 1063 |
public void lastText() { |
1058 |
|
|
1064 |
|
|
1059 | 1065 |
// Text current = this.currentPage.getEdition().getText(); |
1060 | 1066 |
Project project = currentText.getProject(); |
1061 | 1067 |
String id; |
... | ... | |
1068 | 1074 |
return; |
1069 | 1075 |
} |
1070 | 1076 |
Text lastText = project.getText(id); |
1071 |
|
|
1077 |
|
|
1072 | 1078 |
if (lastText != null) { |
1073 | 1079 |
String editionName = currentEdition.getName(); |
1074 | 1080 |
Edition tmp = lastText.getEdition(editionName); |
... | ... | |
1076 | 1082 |
System.out.println(EditionUIMessages.bind(EditionUIMessages.noEditionWithNameEqualsP0AvailableForTextEqualsP1, editionName, lastText.getName())); |
1077 | 1083 |
return; |
1078 | 1084 |
} |
1079 |
|
|
1085 |
|
|
1080 | 1086 |
currentEdition = tmp; |
1081 | 1087 |
currentPage = currentEdition.getFirstPage(); |
1082 | 1088 |
currentText = lastText; |
... | ... | |
1084 | 1090 |
StatusLine.setMessage("No text next"); //$NON-NLS-1$ |
1085 | 1091 |
return; |
1086 | 1092 |
} |
1087 |
|
|
1093 |
|
|
1088 | 1094 |
reloadPage(); |
1089 | 1095 |
// page_label.setText(makePageLabel()); |
1090 | 1096 |
} |
1091 | 1097 |
// System.out.println("Next texts "+nextText); |
1092 | 1098 |
} |
Formats disponibles : Unified diff