64 |
64 |
import visuAnalec.elements.Unite;
|
65 |
65 |
|
66 |
66 |
public class UnitToolbar extends URSAnnotationToolbar {
|
67 |
|
|
68 |
|
//boolean AnalecUnitLimitCorrectionScheme = TxmPreferences.getBoolean(AnalecPreferencePage.ANALEC_LIMIT_CORRECTION_SCHEME); // use Analec scheme to fix unit limits or TXM's
|
69 |
|
|
|
67 |
|
|
68 |
// boolean AnalecUnitLimitCorrectionScheme = TxmPreferences.getBoolean(AnalecPreferencePage.ANALEC_LIMIT_CORRECTION_SCHEME); // use Analec scheme to fix unit limits or TXM's
|
|
69 |
|
70 |
70 |
public RGBA highlighted_unit_color = new RGBA(183, 191, 237, 0.7f);
|
|
71 |
|
71 |
72 |
public RGBA selected_unit_color = new RGBA(255, 255, 0, 0.5f);
|
72 |
|
|
|
73 |
|
73 |
74 |
private Button createButton;
|
|
75 |
|
74 |
76 |
private Button deleteButton;
|
|
77 |
|
75 |
78 |
private Button editButton;
|
76 |
|
|
|
79 |
|
77 |
80 |
private KeyListener editorKeyListener;
|
|
81 |
|
78 |
82 |
private MouseListener editorMouseListener;
|
|
83 |
|
79 |
84 |
private int fixingAnnotationLimits = 0;
|
|
85 |
|
80 |
86 |
private NavigationField navigationField;
|
|
87 |
|
81 |
88 |
private Label l;
|
|
89 |
|
82 |
90 |
private MenuListener menuListener;
|
|
91 |
|
83 |
92 |
private List<String> previousSelectedTypeUnitIDS;
|
84 |
|
|
|
93 |
|
85 |
94 |
private List<String> previousSelectedUnitIDS;
|
|
95 |
|
86 |
96 |
protected boolean startFixingUnitLimit;
|
|
97 |
|
87 |
98 |
private Combo typeCombo;
|
|
99 |
|
88 |
100 |
private Unite[] unites;
|
|
101 |
|
89 |
102 |
private String[] typesUnitesAVoir;
|
|
103 |
|
90 |
104 |
private int maxCorpusPosition;
|
91 |
|
|
|
105 |
|
92 |
106 |
private DragDetectListener dragDetectListener;
|
93 |
|
|
|
107 |
|
94 |
108 |
private Button drop_b;
|
|
109 |
|
95 |
110 |
private Button editLeftButton;
|
|
111 |
|
96 |
112 |
private Button editRightButton;
|
97 |
|
|
98 |
|
public UnitToolbar() { }
|
99 |
|
|
|
113 |
|
|
114 |
public UnitToolbar() {}
|
|
115 |
|
100 |
116 |
@Override
|
101 |
117 |
public boolean install(TXMEditor<? extends TXMResult> txmeditor, AnnotationExtension extension, Composite parent, int position) throws Exception {
|
102 |
118 |
super.install(txmeditor, extension, parent, position);
|
103 |
119 |
|
104 |
|
annotationArea.getLayout().numColumns = 10;
|
|
120 |
annotationArea.getLayout().numColumns = 11;
|
105 |
121 |
annotationArea.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
|
106 |
|
|
|
122 |
|
107 |
123 |
String color_palette = URSPreferences.getInstance().getString(URSPreferences.COLOR_PALETTE);
|
108 |
124 |
if ("yellow".equals(color_palette)) { //$NON-NLS-1$
|
109 |
125 |
this.highlighted_unit_color = URSAnnotationToolbar.lightyellow;
|
110 |
126 |
this.selected_unit_color = URSAnnotationToolbar.yellow;
|
111 |
|
} else if ("green".equals(color_palette)) { //$NON-NLS-1$
|
|
127 |
}
|
|
128 |
else if ("green".equals(color_palette)) { //$NON-NLS-1$
|
112 |
129 |
this.highlighted_unit_color = URSAnnotationToolbar.lightgreen;
|
113 |
130 |
this.selected_unit_color = URSAnnotationToolbar.green;
|
114 |
|
} else { // custom palette
|
115 |
|
// String highlighted_unit_color_pref = TxmPreferences.get(AnalecPreferencePage.HIGHLIGHTED_UNIT_COLOR, "255,255,176");
|
116 |
|
// String selected_unit_color_pref = TxmPreferences.get(AnalecPreferencePage.SELECTED_UNIT_COLOR, "255,255,96");
|
117 |
|
// this.highlighted_unit_color = new RGBA(highlighted_unit_color_pref, 0.7f);
|
118 |
|
// this.selected_unit_color = new RGBA(selected_unit_color_pref, 1f);
|
119 |
131 |
}
|
120 |
|
|
|
132 |
else { // custom palette
|
|
133 |
// String highlighted_unit_color_pref = TxmPreferences.get(AnalecPreferencePage.HIGHLIGHTED_UNIT_COLOR, "255,255,176");
|
|
134 |
// String selected_unit_color_pref = TxmPreferences.get(AnalecPreferencePage.SELECTED_UNIT_COLOR, "255,255,96");
|
|
135 |
// this.highlighted_unit_color = new RGBA(highlighted_unit_color_pref, 0.7f);
|
|
136 |
// this.selected_unit_color = new RGBA(selected_unit_color_pref, 1f);
|
|
137 |
}
|
|
138 |
|
121 |
139 |
this.button = extension.getSaveButton();
|
122 |
140 |
this.maincorpus = this.editor.getCorpus().getMainCorpus();
|
123 |
141 |
try {
|
124 |
142 |
maxCorpusPosition = maincorpus.getSize();
|
125 |
|
} catch (Exception e) {
|
|
143 |
}
|
|
144 |
catch (Exception e) {
|
126 |
145 |
System.out.println(NLS.bind(Messages.UnitToolbar_3, maincorpus, e.getLocalizedMessage()));
|
127 |
146 |
Log.printStackTrace(e);
|
128 |
147 |
}
|
129 |
148 |
analecCorpus.addEventListener(this);
|
130 |
|
|
131 |
|
|
|
149 |
|
|
150 |
|
132 |
151 |
l = new Label(annotationArea, SWT.NONE);
|
133 |
|
l.setText(Messages.UnitToolbar_6);
|
|
152 |
l.setText(Messages.UnitToolbar_6);
|
134 |
153 |
l.setToolTipText(Messages.UnitToolbar_6);
|
135 |
154 |
l.setLayoutData(new GridData(GridData.CENTER, GridData.CENTER, false, false));
|
136 |
|
|
137 |
|
typeCombo = new Combo(annotationArea, SWT.NONE|SWT.READ_ONLY);
|
|
155 |
|
|
156 |
typeCombo = new Combo(annotationArea, SWT.NONE | SWT.READ_ONLY);
|
138 |
157 |
typeCombo.setToolTipText(Messages.UnitToolbar_7);
|
139 |
158 |
GridData gdata = new GridData(GridData.CENTER, GridData.CENTER, false, false);
|
140 |
159 |
gdata.minimumWidth = 100;
|
141 |
160 |
gdata.widthHint = 100;
|
142 |
161 |
typeCombo.setLayoutData(gdata);
|
143 |
162 |
typeCombo.addSelectionListener(new SelectionListener() {
|
|
163 |
|
144 |
164 |
@Override
|
145 |
165 |
public void widgetDefaultSelected(SelectionEvent e) {}
|
146 |
|
|
|
166 |
|
147 |
167 |
@Override
|
148 |
168 |
public void widgetSelected(SelectionEvent e) {
|
149 |
169 |
onTypecomboSelected(e);
|
150 |
170 |
}
|
151 |
171 |
});
|
152 |
|
|
|
172 |
|
153 |
173 |
navigationField = new NavigationField(this, SWT.NONE);
|
154 |
174 |
gdata = new GridData(GridData.FILL, GridData.CENTER, true, false);
|
155 |
175 |
navigationField.setLayoutData(gdata);
|
156 |
176 |
navigationField.addListener(SWT.Selection, new Listener() {
|
|
177 |
|
157 |
178 |
@Override
|
158 |
179 |
public void handleEvent(Event event) {
|
159 |
180 |
onIdentifiantComboSelected(event);
|
160 |
181 |
}
|
161 |
182 |
});
|
162 |
|
|
163 |
|
//l = new Label(this, SWT.NONE);
|
164 |
|
|
|
183 |
|
|
184 |
// l = new Label(this, SWT.NONE);
|
|
185 |
|
165 |
186 |
createButton = new Button(annotationArea, SWT.PUSH);
|
166 |
187 |
createButton.setText(Messages.UnitToolbar_8);
|
167 |
188 |
gdata = new GridData(GridData.CENTER, GridData.CENTER, false, false);
|
168 |
189 |
createButton.setLayoutData(gdata);
|
169 |
190 |
createButton.addSelectionListener(new SelectionListener() {
|
|
191 |
|
170 |
192 |
@Override
|
171 |
193 |
public void widgetDefaultSelected(SelectionEvent e) {}
|
172 |
|
|
|
194 |
|
173 |
195 |
@Override
|
174 |
196 |
public void widgetSelected(SelectionEvent e) {
|
175 |
197 |
onCreateButtonSelected(e);
|
176 |
198 |
}
|
177 |
199 |
});
|
178 |
|
|
|
200 |
|
179 |
201 |
deleteButton = new Button(annotationArea, SWT.PUSH);
|
180 |
202 |
gdata = new GridData(GridData.CENTER, GridData.CENTER, false, false);
|
181 |
203 |
deleteButton.setLayoutData(gdata);
|
182 |
204 |
deleteButton.setImage(IImageKeys.getImage("platform:/plugin/org.txm.rcp/icons/cross.png")); //$NON-NLS-1$
|
183 |
205 |
deleteButton.setToolTipText(Messages.UnitToolbar_10);
|
184 |
206 |
deleteButton.addSelectionListener(new SelectionListener() {
|
|
207 |
|
185 |
208 |
@Override
|
186 |
209 |
public void widgetDefaultSelected(SelectionEvent e) {}
|
|
210 |
|
187 |
211 |
@Override
|
188 |
212 |
public void widgetSelected(SelectionEvent e) {
|
189 |
213 |
onDeleteComboSelected(e);
|
190 |
214 |
}
|
191 |
215 |
});
|
192 |
|
|
|
216 |
|
193 |
217 |
l = new Label(annotationArea, SWT.NONE);
|
194 |
|
|
|
218 |
|
195 |
219 |
editLeftButton = new Button(annotationArea, SWT.TOGGLE);
|
196 |
220 |
gdata = new GridData(GridData.CENTER, GridData.CENTER, false, false);
|
197 |
221 |
editLeftButton.setLayoutData(gdata);
|
198 |
222 |
editLeftButton.setText("[ ↔"); //$NON-NLS-1$
|
199 |
223 |
editLeftButton.setToolTipText(Messages.UnitToolbar_12);
|
200 |
224 |
editLeftButton.addSelectionListener(new SelectionListener() {
|
|
225 |
|
201 |
226 |
@Override
|
202 |
227 |
public void widgetDefaultSelected(SelectionEvent e) {}
|
|
228 |
|
203 |
229 |
@Override
|
204 |
230 |
public void widgetSelected(SelectionEvent e) {
|
205 |
|
onEditButtonSelected(e,1);
|
|
231 |
onEditButtonSelected(e, 1);
|
206 |
232 |
}
|
207 |
233 |
});
|
208 |
|
|
|
234 |
|
209 |
235 |
editButton = new Button(annotationArea, SWT.TOGGLE);
|
210 |
236 |
editButton.setText("[↔]"); //$NON-NLS-1$
|
211 |
237 |
editButton.setToolTipText(Messages.UnitToolbar_14);
|
212 |
238 |
editButton.addSelectionListener(new SelectionListener() {
|
|
239 |
|
213 |
240 |
@Override
|
214 |
241 |
public void widgetDefaultSelected(SelectionEvent e) {}
|
|
242 |
|
215 |
243 |
@Override
|
216 |
244 |
public void widgetSelected(SelectionEvent e) {
|
217 |
245 |
onEditButtonSelected(e);
|
218 |
246 |
}
|
219 |
247 |
});
|
220 |
|
|
|
248 |
|
221 |
249 |
editRightButton = new Button(annotationArea, SWT.TOGGLE);
|
222 |
250 |
editRightButton.setText("↔ ]"); //$NON-NLS-1$
|
223 |
251 |
editRightButton.setToolTipText(Messages.UnitToolbar_16);
|
224 |
252 |
editRightButton.addSelectionListener(new SelectionListener() {
|
|
253 |
|
225 |
254 |
@Override
|
226 |
255 |
public void widgetDefaultSelected(SelectionEvent e) {}
|
|
256 |
|
227 |
257 |
@Override
|
228 |
258 |
public void widgetSelected(SelectionEvent e) {
|
229 |
|
onEditButtonSelected(e,2);
|
|
259 |
onEditButtonSelected(e, 2);
|
230 |
260 |
}
|
231 |
261 |
});
|
232 |
|
|
|
262 |
|
233 |
263 |
annotationArea.layout();
|
234 |
264 |
annotationArea.getParent().layout(true);
|
235 |
265 |
editor.layout(true);
|
236 |
|
|
|
266 |
|
237 |
267 |
reloadUnits(); // reloads types
|
238 |
268 |
reloadIdentifiants();
|
239 |
|
|
|
269 |
|
240 |
270 |
createButton.setEnabled(false);
|
241 |
271 |
deleteButton.setEnabled(false);
|
242 |
272 |
editButton.setEnabled(false);
|
243 |
273 |
editLeftButton.setEnabled(false);
|
244 |
274 |
editRightButton.setEnabled(false);
|
245 |
|
|
246 |
|
//drop_b.setEnabled(false);
|
|
275 |
|
|
276 |
// drop_b.setEnabled(false);
|
247 |
277 |
if (typesUnitesAVoir.length > 0) {
|
248 |
278 |
typeCombo.select(1);
|
249 |
279 |
onTypecomboSelected(null);
|
250 |
|
|
|
280 |
|
251 |
281 |
testIfAwordSpanIsSelected();
|
252 |
282 |
}
|
253 |
|
|
|
283 |
|
254 |
284 |
ElementPropertiesView.openView();
|
255 |
285 |
editor.updateWordStyles();
|
256 |
|
|
|
286 |
|
257 |
287 |
return true;
|
258 |
288 |
}
|
259 |
|
|
|
289 |
|
|
290 |
@Override
|
260 |
291 |
public void clearHighlight() {
|
261 |
292 |
if (previousSelectedUnitIDS != null) {
|
262 |
|
if (editor.isDisposed()){
|
|
293 |
if (editor.isDisposed()) {
|
263 |
294 |
editor.removeHighlightWordsById(selected_unit_color, previousSelectedUnitIDS);
|
264 |
295 |
editor.removeFontWeightWordsById(previousSelectedUnitIDS);
|
265 |
296 |
}
|
... | ... | |
269 |
300 |
editor.removeHighlightWordsById(highlighted_unit_color, previousSelectedTypeUnitIDS);
|
270 |
301 |
previousSelectedTypeUnitIDS = null; // release memory
|
271 |
302 |
}
|
272 |
|
|
|
303 |
|
273 |
304 |
if (!createButton.isDisposed()) createButton.setEnabled(false);
|
274 |
305 |
if (!deleteButton.isDisposed()) deleteButton.setEnabled(false);
|
275 |
306 |
if (!editButton.isDisposed()) editButton.setEnabled(false);
|
276 |
|
//drop_b.setEnabled(false);
|
|
307 |
// drop_b.setEnabled(false);
|
277 |
308 |
}
|
278 |
|
|
|
309 |
|
|
310 |
@Override
|
279 |
311 |
public MouseListener getEditorClickListener() {
|
280 |
312 |
if (editorMouseListener != null) return editorMouseListener;
|
281 |
313 |
editorMouseListener = new MouseListener() {
|
282 |
|
|
|
314 |
|
283 |
315 |
boolean dblClick = false;
|
|
316 |
|
284 |
317 |
boolean debug = false;
|
285 |
|
private int t,x,y;
|
286 |
|
|
|
318 |
|
|
319 |
private int t, x, y;
|
|
320 |
|
287 |
321 |
@Override
|
288 |
322 |
public void mouseDoubleClick(MouseEvent e) {
|
289 |
323 |
if (debug) System.out.println("DOUBLE CLICK"); //$NON-NLS-1$
|
290 |
|
dblClick= true;
|
291 |
|
|
|
324 |
dblClick = true;
|
|
325 |
|
292 |
326 |
EditionPanel panel = editor.getEditionPanel(0);
|
293 |
327 |
if (panel == null) return;
|
294 |
328 |
String[] ids = panel.getWordSelection(); // may be null
|
295 |
|
//System.out.println("word id="+id);
|
296 |
|
// if (id != null) {
|
297 |
|
// org.txm.searchengine.cqp.corpus.Corpus c = UnitToolbar.this.editor.getCorpus();
|
298 |
|
// try {
|
299 |
|
// if (debug) System.out.println(" HIGHLIGHTING ANNOT IF ANY AT "+id);
|
300 |
|
// tryHighlightingWord(id,c );
|
301 |
|
// } catch (Exception ex) {
|
302 |
|
// ex.printStackTrace();
|
303 |
|
// }
|
304 |
|
// }
|
305 |
|
|
|
329 |
// System.out.println("word id="+id);
|
|
330 |
// if (id != null) {
|
|
331 |
// org.txm.searchengine.cqp.corpus.Corpus c = UnitToolbar.this.editor.getCorpus();
|
|
332 |
// try {
|
|
333 |
// if (debug) System.out.println(" HIGHLIGHTING ANNOT IF ANY AT "+id);
|
|
334 |
// tryHighlightingWord(id,c );
|
|
335 |
// } catch (Exception ex) {
|
|
336 |
// ex.printStackTrace();
|
|
337 |
// }
|
|
338 |
// }
|
|
339 |
|
306 |
340 |
if (ids != null && typeCombo.getSelectionIndex() > 0 && typeCombo.getEnabled()) {
|
307 |
341 |
createButton.setEnabled(true); // there is a text selection in the browser
|
308 |
342 |
}
|
309 |
343 |
}
|
310 |
|
|
|
344 |
|
311 |
345 |
@Override
|
312 |
346 |
public void mouseDown(MouseEvent e) {
|
313 |
347 |
if (debug) System.out.println("MOUSE DOWN"); //$NON-NLS-1$
|
... | ... | |
316 |
350 |
x = e.x;
|
317 |
351 |
y = e.y;
|
318 |
352 |
}
|
319 |
|
|
|
353 |
|
320 |
354 |
@Override
|
321 |
355 |
public void mouseUp(MouseEvent e) {
|
322 |
356 |
if (dblClick) { // doucle click raised by mouseDoubleClick
|
... | ... | |
326 |
360 |
if (debug) System.out.println("MOUSE UP"); //$NON-NLS-1$
|
327 |
361 |
EditionPanel panel = editor.getEditionPanel(0);
|
328 |
362 |
if (panel == null) return;
|
329 |
|
|
|
363 |
|
330 |
364 |
if (typeCombo.getSelectionIndex() <= 0) {
|
331 |
365 |
createButton.setEnabled(false);
|
332 |
366 |
deleteButton.setEnabled(false);
|
333 |
367 |
editLeftButton.setEnabled(false);
|
334 |
368 |
editButton.setEnabled(false);
|
335 |
369 |
editRightButton.setEnabled(false);
|
336 |
|
//drop_b.setEnabled(false);
|
|
370 |
// drop_b.setEnabled(false);
|
337 |
371 |
return; // nothing to do with annotations
|
338 |
372 |
}
|
339 |
|
|
|
373 |
|
340 |
374 |
// filter click that are not a left simple click (no drag)
|
341 |
|
//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)));
|
|
375 |
// 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)));
|
342 |
376 |
if (e.count > 1) {
|
343 |
377 |
if (debug) System.out.println(" DOUBLE CLICK"); //$NON-NLS-1$
|
344 |
|
//System.out.println("not a simple click");
|
|
378 |
// System.out.println("not a simple click");
|
345 |
379 |
return;
|
346 |
380 |
}
|
347 |
|
|
|
381 |
|
348 |
382 |
int dist = Math.abs(e.x - x) + Math.abs(e.y - y);
|
349 |
|
int deltat = (e.time-t);
|
350 |
|
//System.out.println("deltat ="+deltat);
|
|
383 |
int deltat = (e.time - t);
|
|
384 |
// System.out.println("deltat ="+deltat);
|
351 |
385 |
if (dist != 0 && (deltat > 120 || dist > 4)) {
|
352 |
|
//System.out.println(" DRAG dist="+dist+" deltat="+deltat);
|
353 |
|
|
|
386 |
// System.out.println(" DRAG dist="+dist+" deltat="+deltat);
|
|
387 |
|
354 |
388 |
String[] ids = panel.getWordSelection(); // may be null
|
355 |
|
|
356 |
|
if (fixingAnnotationLimits== 3) { // fixing limit with a mouse drag an drop
|
357 |
|
if (debug) System.out.println(" EDITING ANNOTATION POSITION mode="+fixingAnnotationLimits); //$NON-NLS-1$
|
|
389 |
|
|
390 |
if (fixingAnnotationLimits == 3) { // fixing limit with a mouse drag an drop
|
|
391 |
if (debug) System.out.println(" EDITING ANNOTATION POSITION mode=" + fixingAnnotationLimits); //$NON-NLS-1$
|
358 |
392 |
onFixingAnnotationLimits(ids);
|
359 |
393 |
return;
|
360 |
|
} else {
|
361 |
|
|
362 |
|
testIfAwordSpanIsSelected(ids);
|
363 |
|
|
364 |
|
//panel.expandSelectionTo(ids);
|
|
394 |
}
|
|
395 |
else {
|
|
396 |
|
|
397 |
testIfAwordSpanIsSelected(ids);
|
|
398 |
|
|
399 |
// panel.expandSelectionTo(ids);
|
365 |
400 |
return;
|
366 |
401 |
}
|
367 |
402 |
}
|
368 |
403 |
|
369 |
404 |
if (e.button != 1) {
|
370 |
405 |
if (debug) System.out.println(" NO LEFT"); //$NON-NLS-1$
|
371 |
|
//System.out.println("not a left click");
|
|
406 |
// System.out.println("not a left click");
|
372 |
407 |
return;
|
373 |
408 |
}
|
374 |
|
if ((e.time-t) > 200) {
|
|
409 |
if ((e.time - t) > 200) {
|
375 |
410 |
if (debug) System.out.println(" LONG"); //$NON-NLS-1$
|
376 |
|
//System.out.println("not a short click");
|
|
411 |
// System.out.println("not a short click");
|
377 |
412 |
return;
|
378 |
413 |
}
|
379 |
|
|
|
414 |
|
380 |
415 |
String[] ids = panel.getWordSelection(); // may be null
|
381 |
|
|
|
416 |
|
382 |
417 |
if (fixingAnnotationLimits > 0) {
|
383 |
|
if (debug) System.out.println(" EDITING ANNOTATION POSITION mode="+fixingAnnotationLimits); //$NON-NLS-1$
|
|
418 |
if (debug) System.out.println(" EDITING ANNOTATION POSITION mode=" + fixingAnnotationLimits); //$NON-NLS-1$
|
384 |
419 |
onFixingAnnotationLimits(ids);
|
385 |
420 |
return;
|
386 |
421 |
}
|
387 |
|
|
|
422 |
|
388 |
423 |
if (ids == null) { // clear selection
|
389 |
|
if (debug) System.out.println(" NO WORD SELECTION"); //$NON-NLS-1$
|
|
424 |
if (debug) System.out.println(" NO WORD SELECTION"); //$NON-NLS-1$
|
390 |
425 |
navigationField.setSelectionIndex(0); // clear selection
|
391 |
|
|
|
426 |
|
392 |
427 |
return;
|
393 |
428 |
}
|
394 |
|
|
|
429 |
|
395 |
430 |
org.txm.searchengine.cqp.corpus.CQPCorpus c = UnitToolbar.this.editor.getCorpus();
|
396 |
|
|
|
431 |
|
397 |
432 |
try {
|
398 |
|
if (debug) System.out.println(" HIGHLIGHTING ANNOT IF ANY AT "+ids[0]); //$NON-NLS-1$
|
399 |
|
if (tryHighlightingUnitsWord(ids[0],c )) {
|
|
433 |
if (debug) System.out.println(" HIGHLIGHTING ANNOT IF ANY AT " + ids[0]); //$NON-NLS-1$
|
|
434 |
if (tryHighlightingUnitsWord(ids[0], c)) {
|
400 |
435 |
editor.updateWordStyles();
|
401 |
|
} else { // a word have been clicked
|
402 |
|
testIfAwordSpanIsSelected(ids);
|
|
436 |
}
|
|
437 |
else { // a word have been clicked
|
|
438 |
testIfAwordSpanIsSelected(ids);
|
403 |
439 |
panel.expandSelectionTo(ids);
|
404 |
440 |
}
|
405 |
|
} catch (Exception ex) {
|
|
441 |
}
|
|
442 |
catch (Exception ex) {
|
406 |
443 |
ex.printStackTrace();
|
407 |
444 |
}
|
408 |
445 |
}
|
409 |
446 |
};
|
410 |
447 |
return editorMouseListener;
|
411 |
448 |
}
|
412 |
|
|
|
449 |
|
413 |
450 |
protected void testIfAwordSpanIsSelected() {
|
414 |
451 |
EditionPanel panel = editor.getEditionPanel(0);
|
415 |
452 |
if (panel == null) return;
|
416 |
453 |
String[] ids = panel.getWordSelection(); // may be null
|
417 |
454 |
testIfAwordSpanIsSelected(ids);
|
418 |
455 |
}
|
419 |
|
|
|
456 |
|
420 |
457 |
protected void testIfAwordSpanIsSelected(String[] ids) {
|
421 |
|
if (ids != null && typeCombo.getItemCount() > 1 && typeCombo.getEnabled() ) {
|
422 |
|
//System.out.println("ids:"+Arrays.toString(ids));
|
|
458 |
if (ids != null && typeCombo.getItemCount() > 1 && typeCombo.getEnabled()) {
|
|
459 |
// System.out.println("ids:"+Arrays.toString(ids));
|
423 |
460 |
if (navigationField.getSelectionIndex() > 0) {
|
424 |
461 |
deleteButton.setEnabled(true);
|
425 |
462 |
editLeftButton.setEnabled(true);
|
426 |
463 |
editButton.setEnabled(true);
|
427 |
464 |
editRightButton.setEnabled(true);
|
428 |
|
//drop_b.setEnabled(true);
|
|
465 |
// drop_b.setEnabled(true);
|
429 |
466 |
}
|
430 |
|
|
|
467 |
|
431 |
468 |
createButton.setEnabled(ids != null);
|
432 |
|
}
|
|
469 |
}
|
433 |
470 |
}
|
434 |
|
|
435 |
|
|
436 |
|
|
|
471 |
|
|
472 |
|
|
473 |
|
437 |
474 |
protected void onFixingAnnotationLimits(String[] ids) {
|
438 |
|
|
439 |
|
if (ids == null || ids.length == 0) { System.out.println(Messages.UnitToolbar_27);return; }
|
440 |
|
|
|
475 |
|
|
476 |
if (ids == null || ids.length == 0) {
|
|
477 |
System.out.println(Messages.UnitToolbar_27);
|
|
478 |
return;
|
|
479 |
}
|
|
480 |
|
441 |
481 |
boolean uniteFixed = false;
|
442 |
482 |
int i = navigationField.getSelectionIndex();
|
443 |
483 |
if (i > 0) {
|
444 |
|
Unite unite = unites[i-1];
|
445 |
|
|
|
484 |
Unite unite = unites[i - 1];
|
|
485 |
|
446 |
486 |
try {
|
447 |
487 |
uniteFixed = updateUniteLimits(unite, ids, fixingAnnotationLimits);
|
448 |
|
} catch (CqiClientException e1) {
|
|
488 |
}
|
|
489 |
catch (CqiClientException e1) {
|
449 |
490 |
System.out.println(NLS.bind(Messages.UnitToolbar_28, ids[0]));
|
450 |
491 |
Log.printStackTrace(e1);
|
451 |
492 |
}
|
452 |
|
|
|
493 |
|
453 |
494 |
editButton.setSelection(false);
|
454 |
495 |
editLeftButton.setSelection(false);
|
455 |
496 |
editRightButton.setSelection(false);
|
456 |
497 |
fixingAnnotationLimits = 0;
|
457 |
498 |
typeCombo.setEnabled(true);
|
458 |
|
|
|
499 |
|
459 |
500 |
navigationField.setEnabled(true);
|
460 |
501 |
createButton.setEnabled(true);
|
461 |
502 |
deleteButton.setEnabled(true);
|
462 |
|
|
|
503 |
|
463 |
504 |
if (uniteFixed) {
|
464 |
|
//button.setEnabled(analecCorpus.isModifie());
|
|
505 |
// button.setEnabled(analecCorpus.isModifie());
|
465 |
506 |
reloadIdentifiants();
|
466 |
507 |
highlightType();
|
467 |
|
//highlightUnite(unite, true);
|
|
508 |
// highlightUnite(unite, true);
|
468 |
509 |
navigationField.setSelectionIndex(i);
|
469 |
|
//updatePropertiesView(unite); // start-end may have changed
|
|
510 |
// updatePropertiesView(unite); // start-end may have changed
|
470 |
511 |
return;
|
471 |
512 |
}
|
472 |
513 |
}
|
473 |
514 |
}
|
474 |
|
|
475 |
|
|
476 |
|
|
|
515 |
|
|
516 |
|
|
517 |
|
|
518 |
@Override
|
477 |
519 |
public KeyListener getEditorKeyListener() {
|
478 |
520 |
if (editorKeyListener != null) return editorKeyListener;
|
479 |
521 |
editorKeyListener = new KeyListener() {
|
480 |
|
|
|
522 |
|
481 |
523 |
@Override
|
482 |
|
public void keyPressed(KeyEvent e) { }
|
483 |
|
|
|
524 |
public void keyPressed(KeyEvent e) {}
|
|
525 |
|
484 |
526 |
@Override
|
485 |
527 |
public void keyReleased(KeyEvent e) {
|
486 |
528 |
int mask = SWT.CTRL;
|
487 |
529 |
if (Util.isMac()) mask = SWT.COMMAND;
|
488 |
|
|
|
530 |
|
489 |
531 |
if (((e.stateMask & mask) == mask)) {
|
490 |
|
if (e.keyCode == SWT.SPACE) {
|
|
532 |
if (e.keyCode == SWT.SPACE) {
|
491 |
533 |
int i = navigationField.getSelectionIndex();
|
492 |
534 |
if (i > 0) {
|
493 |
535 |
onEditButtonSelected(null);
|
494 |
536 |
}
|
495 |
|
} else if (e.keyCode == SWT.ARROW_LEFT) {
|
|
537 |
}
|
|
538 |
else if (e.keyCode == SWT.ARROW_LEFT) {
|
496 |
539 |
selectPrevious();
|
497 |
|
} else if (e.keyCode == SWT.ARROW_RIGHT) {
|
|
540 |
}
|
|
541 |
else if (e.keyCode == SWT.ARROW_RIGHT) {
|
498 |
542 |
selectNext();
|
499 |
|
// } else if (e.keyCode == SWT.PAGE_UP) { // clash with Eclipse CTRL+PAGE_UP binding
|
500 |
|
// select10Previous();
|
501 |
|
// } else if (e.keyCode == SWT.PAGE_DOWN) { // clash with Eclipse CTRL+PAGE_DOWN binding
|
502 |
|
// select10Next();
|
503 |
|
} else if (e.keyCode == SWT.END) {
|
|
543 |
// } else if (e.keyCode == SWT.PAGE_UP) { // clash with Eclipse CTRL+PAGE_UP binding
|
|
544 |
// select10Previous();
|
|
545 |
// } else if (e.keyCode == SWT.PAGE_DOWN) { // clash with Eclipse CTRL+PAGE_DOWN binding
|
|
546 |
// select10Next();
|
|
547 |
}
|
|
548 |
else if (e.keyCode == SWT.END) {
|
504 |
549 |
selectLast();
|
505 |
|
} else if (e.keyCode == SWT.HOME) {
|
|
550 |
}
|
|
551 |
else if (e.keyCode == SWT.HOME) {
|
506 |
552 |
selectFirst();
|
507 |
553 |
}
|
508 |
|
} else {
|
509 |
|
if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
|
|
554 |
}
|
|
555 |
else {
|
|
556 |
if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
|
510 |
557 |
onCreateButtonSelected(null);
|
511 |
|
} else if (e.keyCode == SWT.DEL) {
|
|
558 |
}
|
|
559 |
else if (e.keyCode == SWT.DEL) {
|
512 |
560 |
int i = navigationField.getSelectionIndex();
|
513 |
561 |
if (i > 0) {
|
514 |
562 |
onDeleteComboSelected(e);
|
... | ... | |
519 |
567 |
};
|
520 |
568 |
return editorKeyListener;
|
521 |
569 |
}
|
522 |
|
|
|
570 |
|
|
571 |
@Override
|
523 |
572 |
public MenuListener getMenuListener() {
|
524 |
|
|
|
573 |
|
525 |
574 |
if (menuListener != null) return menuListener;
|
526 |
|
|
|
575 |
|
527 |
576 |
this.menuListener = new MenuListener() {
|
528 |
|
|
529 |
|
HashSet<MenuItem> entries = new HashSet<MenuItem>();
|
530 |
|
|
|
577 |
|
|
578 |
HashSet<MenuItem> entries = new HashSet<>();
|
|
579 |
|
531 |
580 |
@Override
|
532 |
|
public void menuHidden(MenuEvent e) { }
|
533 |
|
|
|
581 |
public void menuHidden(MenuEvent e) {}
|
|
582 |
|
534 |
583 |
@Override
|
535 |
584 |
public void menuShown(MenuEvent e) {
|
536 |
|
|
|
585 |
|
537 |
586 |
EditionPanel panel = editor.getEditionPanel(0);
|
538 |
587 |
if (panel == null) return;
|
539 |
588 |
Menu menu = panel.getBrowser().getMenu();
|
540 |
|
|
541 |
|
for (MenuItem item : entries) item.dispose();
|
542 |
|
|
|
589 |
|
|
590 |
for (MenuItem item : entries)
|
|
591 |
item.dispose();
|
|
592 |
|
543 |
593 |
String[] ids = panel.getWordSelection();
|
544 |
|
//System.out.println("Word under mouse: "+id);
|
|
594 |
// System.out.println("Word under mouse: "+id);
|
545 |
595 |
if (ids != null && ids.length > 0) {
|
546 |
596 |
int[] startend = getSelectionStartEndWordPositions(); // get the word start end positions
|
547 |
|
ArrayList<Unite> unitEntries = new ArrayList<Unite>(); // stores units covering the word
|
548 |
|
ArrayList<Integer> noEntries = new ArrayList<Integer>(); // stores units covering the word
|
|
597 |
ArrayList<Unite> unitEntries = new ArrayList<>(); // stores units covering the word
|
|
598 |
ArrayList<Integer> noEntries = new ArrayList<>(); // stores units covering the word
|
549 |
599 |
int i = 1;
|
550 |
600 |
for (Unite unit : unites) {
|
551 |
601 |
if (unit.getDeb() > startend[0]) break; // don't go further
|
... | ... | |
554 |
604 |
noEntries.add(i);
|
555 |
605 |
i++;
|
556 |
606 |
}
|
557 |
|
|
|
607 |
|
558 |
608 |
if (unitEntries.size() > 0) {
|
559 |
609 |
MenuItem item = new MenuItem(menu, SWT.SEPARATOR);
|
560 |
610 |
entries.add(item);
|
561 |
611 |
}
|
562 |
|
|
563 |
|
for (i = 0 ; i < unitEntries.size() ; i++) {
|
|
612 |
|
|
613 |
for (i = 0; i < unitEntries.size(); i++) {
|
564 |
614 |
final Unite unit = unitEntries.get(i);
|
565 |
|
final Integer unitNo = Arrays.binarySearch(unites, unit)+1;
|
566 |
|
|
|
615 |
final Integer unitNo = Arrays.binarySearch(unites, unit) + 1;
|
|
616 |
|
567 |
617 |
MenuItem item = new MenuItem(menu, SWT.NONE);
|
568 |
618 |
AbstractCqiClient CQI = CQPSearchEngine.getCqiClient();
|
569 |
619 |
try {
|
570 |
620 |
if (unit.getDeb() == unit.getFin()) {
|
571 |
|
String[] firstWords = CQI.cpos2Str(maincorpus.getWordProperty().getQualifiedName(), new int[]{unit.getDeb()});
|
572 |
|
item.setText(NLS.bind(Messages.UnitToolbar_29, unit.getType()+"-"+unitNo+ ":"+firstWords[0])); //$NON-NLS-2$ //$NON-NLS-3$
|
573 |
|
} else {
|
574 |
|
String[] firstWords = CQI.cpos2Str(maincorpus.getWordProperty().getQualifiedName(), new int[]{unit.getDeb(), unit.getDeb()+1});
|
575 |
|
item.setText(NLS.bind(Messages.UnitToolbar_32, unit.getType()+"-"+unitNo+ "="+firstWords[0]+" "+firstWords[1])); //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
|
|
621 |
String[] firstWords = CQI.cpos2Str(maincorpus.getWordProperty().getQualifiedName(), new int[] { unit.getDeb() });
|
|
622 |
item.setText(NLS.bind(Messages.UnitToolbar_29, unit.getType() + "-" + unitNo + ":" + firstWords[0])); //$NON-NLS-2$
|
576 |
623 |
}
|
577 |
|
} catch (Exception e1) {
|
|
624 |
else {
|
|
625 |
String[] firstWords = CQI.cpos2Str(maincorpus.getWordProperty().getQualifiedName(), new int[] { unit.getDeb(), unit.getDeb() + 1 });
|
|
626 |
item.setText(NLS.bind(Messages.UnitToolbar_32, unit.getType() + "-" + unitNo + "=" + firstWords[0] + " " + firstWords[1])); //$NON-NLS-2$ //$NON-NLS-3$
|
|
627 |
}
|
|
628 |
}
|
|
629 |
catch (Exception e1) {
|
578 |
630 |
e1.printStackTrace();
|
579 |
631 |
}
|
580 |
632 |
item.addSelectionListener(new SelectionListener() {
|
|
633 |
|
581 |
634 |
@Override
|
582 |
|
public void widgetDefaultSelected(SelectionEvent e) { }
|
|
635 |
public void widgetDefaultSelected(SelectionEvent e) {}
|
|
636 |
|
583 |
637 |
@Override
|
584 |
638 |
public void widgetSelected(SelectionEvent e) {
|
585 |
639 |
selectUniteInIdentifants(unit);
|
... | ... | |
590 |
644 |
}
|
591 |
645 |
}
|
592 |
646 |
};
|
593 |
|
|
|
647 |
|
594 |
648 |
return menuListener;
|
595 |
649 |
}
|
596 |
|
|
|
650 |
|
597 |
651 |
public String uniteToWords(Unite unit) {
|
598 |
652 |
AbstractCqiClient CQI = CQPSearchEngine.getCqiClient();
|
599 |
653 |
String[] firstWords = null;
|
600 |
654 |
try {
|
601 |
655 |
if (unit.getDeb() == unit.getFin()) {
|
602 |
|
firstWords = CQI.cpos2Str(maincorpus.getWordProperty().getQualifiedName(), new int[]{unit.getDeb()});
|
603 |
|
} else {
|
604 |
|
firstWords = CQI.cpos2Str(maincorpus.getWordProperty().getQualifiedName(), new int[]{unit.getDeb(), unit.getDeb()+1});
|
|
656 |
firstWords = CQI.cpos2Str(maincorpus.getWordProperty().getQualifiedName(), new int[] { unit.getDeb() });
|
605 |
657 |
}
|
606 |
|
} catch (Exception e) {
|
|
658 |
else {
|
|
659 |
firstWords = CQI.cpos2Str(maincorpus.getWordProperty().getQualifiedName(), new int[] { unit.getDeb(), unit.getDeb() + 1 });
|
|
660 |
}
|
|
661 |
}
|
|
662 |
catch (Exception e) {
|
607 |
663 |
e.printStackTrace();
|
608 |
664 |
}
|
609 |
665 |
return StringUtils.join(firstWords, " "); //$NON-NLS-1$
|
610 |
666 |
}
|
611 |
|
|
|
667 |
|
612 |
668 |
/**
|
613 |
669 |
* Highlight units of the current page
|
614 |
670 |
*/
|
615 |
671 |
protected void highlightType() {
|
616 |
672 |
if (unites == null) return;
|
617 |
|
|
|
673 |
|
618 |
674 |
try {
|
619 |
675 |
Page page = editor.getEditionPanel(0).getCurrentPage();
|
620 |
676 |
Edition e = page.getEdition();
|
621 |
677 |
Page next = e.getNextPage(page);
|
622 |
678 |
String id = page.getWordId();
|
623 |
679 |
if (id == null || id.length() == 0) return;
|
624 |
|
|
|
680 |
|
625 |
681 |
String qid = maincorpus.getProperty("id").getQualifiedName();
|
626 |
|
int first_ids[] = CQPSearchEngine.getCqiClient().str2Id(qid, new String[] {id}); //$NON-NLS-1$
|
627 |
|
|
|
682 |
int first_ids[] = CQPSearchEngine.getCqiClient().str2Id(qid, new String[] { id });
|
|
683 |
|
628 |
684 |
if (first_ids.length == 0) return;
|
629 |
685 |
int first_id = first_ids[0];
|
630 |
686 |
if (first_id == -1) return;
|
... | ... | |
632 |
688 |
int last_ids[] = null;
|
633 |
689 |
if (next != null && next != page) {
|
634 |
690 |
String next_id = next.getWordId();
|
635 |
|
last_ids = CQPSearchEngine.getCqiClient().str2Id(qid, new String[] {next_id}); //$NON-NLS-1$
|
|
691 |
last_ids = CQPSearchEngine.getCqiClient().str2Id(qid, new String[] { next_id });
|
636 |
692 |
}
|
637 |
|
|
|
693 |
|
638 |
694 |
int first_pos = CQPSearchEngine.getCqiClient().id2Cpos(qid, first_id)[0];
|
639 |
695 |
int last_pos = Integer.MAX_VALUE;
|
640 |
696 |
if (last_ids != null && last_ids.length > 0) {
|
641 |
697 |
last_pos = CQPSearchEngine.getCqiClient().id2Cpos(qid, last_ids[0])[0];
|
642 |
698 |
}
|
643 |
|
|
|
699 |
|
644 |
700 |
int n2 = 0;
|
645 |
|
for (int i = 0 ; i < unites.length ; i++) {
|
646 |
|
for (int p = unites[i].getDeb() ; p <= unites[i].getFin() ; p++) {
|
|
701 |
for (int i = 0; i < unites.length; i++) {
|
|
702 |
for (int p = unites[i].getDeb(); p <= unites[i].getFin(); p++) {
|
647 |
703 |
if (p >= first_pos && p <= last_pos) {
|
648 |
704 |
n2++;
|
649 |
705 |
}
|
650 |
706 |
}
|
651 |
707 |
}
|
652 |
|
|
|
708 |
|
653 |
709 |
int allpositions[] = new int[n2];
|
654 |
710 |
n2 = 0;
|
655 |
|
for (int i = 0 ; i < unites.length ; i++) {
|
656 |
|
for (int p = unites[i].getDeb() ; p <= unites[i].getFin() ; p++) {
|
|
711 |
for (int i = 0; i < unites.length; i++) {
|
|
712 |
for (int p = unites[i].getDeb(); p <= unites[i].getFin(); p++) {
|
657 |
713 |
if (p >= first_pos && p <= last_pos) {
|
658 |
714 |
allpositions[n2++] = p;
|
659 |
715 |
}
|
660 |
716 |
}
|
661 |
717 |
}
|
662 |
|
|
|
718 |
|
663 |
719 |
if (previousSelectedTypeUnitIDS != null) {
|
664 |
720 |
editor.removeHighlightWordsById(highlighted_unit_color, previousSelectedTypeUnitIDS);
|
665 |
721 |
editor.removeFontWeightWordsById(previousSelectedTypeUnitIDS);
|
... | ... | |
667 |
723 |
}
|
668 |
724 |
String ids2[] = CQPSearchEngine.getCqiClient().cpos2Str(maincorpus.getProperty("id").getQualifiedName(), allpositions); //$NON-NLS-1$
|
669 |
725 |
previousSelectedTypeUnitIDS = Arrays.asList(ids2);
|
670 |
|
|
|
726 |
|
671 |
727 |
editor.addHighlightWordsById(highlighted_unit_color, previousSelectedTypeUnitIDS);
|
672 |
|
} catch (Exception e) {
|
|
728 |
}
|
|
729 |
catch (Exception e) {
|
673 |
730 |
e.printStackTrace();
|
674 |
731 |
}
|
675 |
732 |
}
|
676 |
|
|
|
733 |
|
677 |
734 |
/**
|
678 |
735 |
* Highlight a unit and don't focus it
|
679 |
736 |
*
|
... | ... | |
683 |
740 |
private void highlightUnite(Unite unite, boolean focus, int clickedWordPosition) {
|
684 |
741 |
int start = unite.getDeb();
|
685 |
742 |
int end = unite.getFin();
|
686 |
|
// System.out.println("HU: start="+start+" end="+end+" -> "+(end-start+1));
|
687 |
|
int len = end-start+1;
|
|
743 |
// System.out.println("HU: start="+start+" end="+end+" -> "+(end-start+1));
|
|
744 |
int len = end - start + 1;
|
688 |
745 |
if (len < 0) {
|
689 |
|
System.out.println("Error: can not highlight unit="+unite+": start > end."); //$NON-NLS-1$ //$NON-NLS-2$
|
|
746 |
System.out.println("Error: can not highlight unit=" + unite + ": start > end."); //$NON-NLS-1$ //$NON-NLS-2$
|
690 |
747 |
return;
|
691 |
748 |
}
|
692 |
|
int positions [] = new int[len]; // build the positions array for CQP
|
|
749 |
int positions[] = new int[len]; // build the positions array for CQP
|
693 |
750 |
int n = 0;
|
694 |
|
for (int p = start ; p <= end ; p++) {
|
|
751 |
for (int p = start; p <= end; p++) {
|
695 |
752 |
positions[n++] = p;
|
696 |
753 |
}
|
697 |
|
|
|
754 |
|
698 |
755 |
try {
|
699 |
756 |
if (previousSelectedUnitIDS != null) { // remove previous highlighted words
|
700 |
757 |
editor.removeHighlightWordsById(selected_unit_color, previousSelectedUnitIDS);
|
701 |
758 |
editor.removeFontWeightWordsById(previousSelectedUnitIDS);
|
702 |
759 |
previousSelectedUnitIDS = null; // release memory
|
703 |
760 |
}
|
704 |
|
|
|
761 |
|
705 |
762 |
String ids[] = CQPSearchEngine.getCqiClient().cpos2Str(maincorpus.getProperty("id").getQualifiedName(), positions); //$NON-NLS-1$
|
706 |
|
// System.out.println("Highlight words with ids="+Arrays.toString(ids));
|
707 |
|
|
708 |
|
//positions = new int[]{positions[0]};
|
|
763 |
// System.out.println("Highlight words with ids="+Arrays.toString(ids));
|
|
764 |
|
|
765 |
// positions = new int[]{positions[0]};
|
709 |
766 |
Property text_id = maincorpus.getStructuralUnit("text").getProperty("id"); //$NON-NLS-1$ //$NON-NLS-2$
|
710 |
767 |
int[] text_strucs = CQPSearchEngine.getCqiClient().cpos2Struc(text_id.getQualifiedName(), positions);
|
711 |
768 |
String[] text_ids = CQPSearchEngine.getCqiClient().struc2Str(text_id.getQualifiedName(), text_strucs);
|
712 |
|
|
|
769 |
|
713 |
770 |
String firstWordId = ids[0];
|
714 |
771 |
String firstWordTextId = text_ids[0];
|
715 |
|
if (clickedWordPosition >= 0 && clickedWordPosition < ids.length) {
|
|
772 |
if (clickedWordPosition >= 0 && clickedWordPosition < ids.length) {
|
716 |
773 |
firstWordId = ids[clickedWordPosition];
|
717 |
774 |
firstWordTextId = text_ids[clickedWordPosition];
|
718 |
775 |
}
|
719 |
|
|
720 |
|
|
|
776 |
|
|
777 |
|
721 |
778 |
EditionPanel panel = editor.getEditionPanel(0);
|
722 |
779 |
Edition e = panel.getEdition();
|
723 |
780 |
Project corpus = e.getText().getProject();
|
724 |
|
// System.out.println("firstWordTextId="+firstWordTextId);
|
|
781 |
// System.out.println("firstWordTextId="+firstWordTextId);
|
725 |
782 |
Text newText = corpus.getText(firstWordTextId); // get the new text
|
726 |
|
// System.out.println("positions="+Arrays.toString(positions));
|
727 |
|
// System.out.println("firstWordId="+firstWordId);
|
728 |
|
// System.out.println("firstWordTextId="+firstWordTextId);
|
729 |
|
// System.out.println("newText="+newText+" e="+e);
|
|
783 |
// System.out.println("positions="+Arrays.toString(positions));
|
|
784 |
// System.out.println("firstWordId="+firstWordId);
|
|
785 |
// System.out.println("firstWordTextId="+firstWordTextId);
|
|
786 |
// System.out.println("newText="+newText+" e="+e);
|
730 |
787 |
Edition newEdition = newText.getEdition(e.getName()); // get the edition of the new text
|
731 |
788 |
Page p = newEdition.getPageForWordId(firstWordId); // find out the page containing the word
|
732 |
|
// System.out.println("page="+p+" current page="+panel.getCurrentPage());
|
733 |
|
|
|
789 |
// System.out.println("page="+p+" current page="+panel.getCurrentPage());
|
|
790 |
|
734 |
791 |
previousSelectedUnitIDS = Arrays.asList(ids);
|
735 |
792 |
editor.addHighlightWordsById(selected_unit_color, previousSelectedUnitIDS);
|
736 |
793 |
editor.addFontWeightWordsById(EditionPanel.WEIGHT_BOLD, previousSelectedUnitIDS);
|
737 |
|
|
|
794 |
|
738 |
795 |
if (previousSelectedUnitIDS.size() > 0 && focus) editor.setFocusedWordID(previousSelectedUnitIDS.get(0));
|
739 |
|
//System.out.println("Word page= "+p+" current="+panel.getCurrentPage());
|
|
796 |
// System.out.println("Word page= "+p+" current="+panel.getCurrentPage());
|
740 |
797 |
if (panel.getCurrentText() != newText) { // text changed
|
741 |
|
//System.out.println("TEXT CHANGED");
|
|
798 |
// System.out.println("TEXT CHANGED");
|
742 |
799 |
editor.setText(newText, false); // don't refresh right now
|
743 |
800 |
editor.goToPage(p.getName());
|
744 |
|
} else if (panel.getCurrentPage() != p) { // do we need to change page ?
|
|
801 |
}
|
|
802 |
else if (panel.getCurrentPage() != p) { // do we need to change page ?
|
745 |
803 |
editor.goToPage(p.getName());
|
746 |
|
} else { // just reload the page to highlight words
|
747 |
|
//System.out.println("NO CHANGE");
|
748 |
804 |
}
|
749 |
|
} catch (Exception e1) {
|
|
805 |
else { // just reload the page to highlight words
|
|
806 |
// System.out.println("NO CHANGE");
|
|
807 |
}
|
|
808 |
}
|
|
809 |
catch (Exception e1) {
|
750 |
810 |
e1.printStackTrace();
|
751 |
811 |
}
|
752 |
812 |
}
|
753 |
|
|
|
813 |
|
754 |
814 |
protected void onCreateButtonSelected(SelectionEvent e) {
|
755 |
|
//System.out.println("onCreateButtonSelected");
|
|
815 |
// System.out.println("onCreateButtonSelected");
|
756 |
816 |
int[] startend = getSelectionStartEndWordPositions();
|
757 |
817 |
if (startend != null) {
|
758 |
818 |
Log.info(NLS.bind(Messages.UnitToolbar_44, startend[0], startend[1]));
|
759 |
819 |
Unite unite = UnitToolbar.this.vue.getCorpus().addUniteSaisie(typeCombo.getText(), startend[0], startend[1]);
|
760 |
|
Structure structure = UnitToolbar.this.analecCorpus.getStructure();
|
|
820 |
Structure structure = UnitToolbar.this.analecCorpus.getStructure();
|
761 |
821 |
for (String prop : unite.getProps().keySet())
|
762 |
822 |
unite.getProps().put(prop, structure.getValeurParDefaut(unite.getClass(), unite.getType(), prop));
|
763 |
|
|
|
823 |
|
764 |
824 |
reloadIdentifiants();
|
765 |
825 |
selectUniteInIdentifants(unite);
|
766 |
|
//highlightUnite(unite, true, -1);
|
767 |
|
|
|
826 |
// highlightUnite(unite, true, -1);
|
|
827 |
|
768 |
828 |
deleteButton.setEnabled(true);
|
769 |
829 |
editLeftButton.setEnabled(true);
|
770 |
830 |
editButton.setEnabled(true);
|
771 |
831 |
editRightButton.setEnabled(true);
|
772 |
|
//drop_b.setEnabled(true);
|
773 |
|
//updatePropertiesView(unite, true);
|
|
832 |
// drop_b.setEnabled(true);
|
|
833 |
// updatePropertiesView(unite, true);
|
774 |
834 |
setFocusInPropertiesView();
|
775 |
835 |
this.extension.getSaveButton().setEnabled(true);
|
776 |
836 |
editor.fireIsDirty();
|
777 |
837 |
}
|
778 |
|
|
|
838 |
|
779 |
839 |
if (e != null) editor.updateWordStyles();
|
780 |
840 |
}
|
781 |
|
|
|
841 |
|
782 |
842 |
protected void onDeleteComboSelected(Object e) {
|
783 |
843 |
int i = navigationField.getSelectionIndex();
|
784 |
844 |
if (i <= 0) return;
|
785 |
|
//System.out.println("Delete unite at i="+i);
|
786 |
|
Unite unite = unites[i-1];
|
787 |
|
|
|
845 |
// System.out.println("Delete unite at i="+i);
|
|
846 |
Unite unite = unites[i - 1];
|
|
847 |
|
788 |
848 |
String id = navigationField.getText();
|
789 |
|
|
790 |
|
ConfirmDialog dialog = new ConfirmDialog(Display.getCurrent().getActiveShell(),
|
791 |
|
"org.txm.annotation.urs.delete",
|
792 |
|
NLS.bind(Messages.UnitToolbar_47, id),
|
|
849 |
|
|
850 |
ConfirmDialog dialog = new ConfirmDialog(Display.getCurrent().getActiveShell(),
|
|
851 |
"org.txm.annotation.urs.delete",
|
|
852 |
NLS.bind(Messages.UnitToolbar_47, id),
|
793 |
853 |
NLS.bind(Messages.UnitToolbar_48, id));
|
794 |
854 |
if (dialog.open() == ConfirmDialog.CANCEL) return;
|
795 |
|
|
796 |
|
//System.out.println("unite "+unite.toString());
|
|
855 |
|
|
856 |
// System.out.println("unite "+unite.toString());
|
797 |
857 |
UnitToolbar.this.vue.getCorpus().supUnite(unite);
|
798 |
858 |
reloadIdentifiants();
|
799 |
|
|
|
859 |
|
800 |
860 |
i = typeCombo.getSelectionIndex();
|
801 |
861 |
if (i > 0) {
|
802 |
862 |
highlightType();
|
803 |
863 |
}
|
804 |
864 |
this.extension.getSaveButton().setEnabled(true);
|
805 |
865 |
editor.fireIsDirty();
|
806 |
|
|
|
866 |
|
807 |
867 |
if (e != null) editor.updateWordStyles();
|
808 |
868 |
}
|
809 |
|
|
|
869 |
|
810 |
870 |
protected void onEditButtonSelected(SelectionEvent e) {
|
811 |
871 |
onEditButtonSelected(e, 3);
|
812 |
872 |
}
|
813 |
|
|
|
873 |
|
814 |
874 |
protected void onEditButtonSelected(SelectionEvent e, int mode) {
|
815 |
875 |
if (mode == 0) { // select unit, select words, click the edit button -> deprecated
|
816 |
876 |
int i = navigationField.getSelectionIndex();
|
817 |
877 |
if (i == -1) return;
|
818 |
|
//System.out.println("Delete unite at i="+i);
|
819 |
|
Unite unite = unites[i-1];
|
|
878 |
// System.out.println("Delete unite at i="+i);
|
|
879 |
Unite unite = unites[i - 1];
|
820 |
880 |
int[] startend = getSelectionStartEndWordPositions();
|
821 |
881 |
if (startend != null) {
|
822 |
882 |
analecCorpus.modifBornesUnite(unite, startend[0], startend[1]);
|
... | ... | |
824 |
884 |
highlightUnite(unite, false, -1);
|
825 |
885 |
updatePropertiesView(unite);
|
826 |
886 |
}
|
827 |
|
} else {
|
828 |
|
if (fixingAnnotationLimits > 0) {
|
|
887 |
}
|
|
888 |
else {
|
|
889 |
if (fixingAnnotationLimits > 0) {
|
829 |
890 |
typeCombo.setEnabled(true);
|
830 |
891 |
navigationField.setEnabled(true);
|
831 |
892 |
createButton.setEnabled(true);
|
832 |
893 |
deleteButton.setEnabled(true);
|
833 |
894 |
fixingAnnotationLimits = 0;
|
834 |
|
} else {
|
|
895 |
}
|
|
896 |
else {
|
835 |
897 |
typeCombo.setEnabled(false);
|
836 |
898 |
navigationField.setEnabled(false);
|
837 |
899 |
createButton.setEnabled(false);
|
... | ... | |
843 |
905 |
editor.fireIsDirty();
|
844 |
906 |
if (e != null) editor.updateWordStyles();
|
845 |
907 |
}
|
846 |
|
|
|
908 |
|
847 |
909 |
/**
|
848 |
910 |
* called when the NavigationField changed its selection
|
|
911 |
*
|
849 |
912 |
* @param e
|
850 |
913 |
*/
|
851 |
914 |
public void onIdentifiantComboSelected(Object e) {
|
... | ... | |
857 |
920 |
previousSelectedUnitIDS = null; // release memory
|
858 |
921 |
}
|
859 |
922 |
highlightType();
|
860 |
|
|
|
923 |
|
861 |
924 |
clearPropertiesView(); // unload the selected element if any
|
862 |
925 |
createButton.setEnabled(false);
|
863 |
926 |
deleteButton.setEnabled(false);
|
864 |
927 |
editLeftButton.setEnabled(false);
|
865 |
928 |
editButton.setEnabled(false);
|
866 |
929 |
editRightButton.setEnabled(false);
|
867 |
|
//drop_b.setEnabled(false);
|
868 |
|
//navigationField.setSelectionIndex(i);
|
869 |
|
} else {
|
|
930 |
// drop_b.setEnabled(false);
|
|
931 |
// navigationField.setSelectionIndex(i);
|
|
932 |
}
|
|
933 |
else {
|
870 |
934 |
createButton.setEnabled(false);
|
871 |
935 |
deleteButton.setEnabled(true);
|
872 |
936 |
editLeftButton.setEnabled(true);
|
873 |
937 |
editButton.setEnabled(true);
|
874 |
938 |
editRightButton.setEnabled(true);
|
875 |
|
//drop_b.setEnabled(true);
|
876 |
|
//System.out.println("i="+i);
|
877 |
|
Unite unite = unites[i-1];
|
878 |
|
//System.out.println("unite="+unite);
|
879 |
|
//System.out.println("unite str="+uniteToWords(unite));
|
|
939 |
// drop_b.setEnabled(true);
|
|
940 |
// System.out.println("i="+i);
|
|
941 |
Unite unite = unites[i - 1];
|
|
942 |
// System.out.println("unite="+unite);
|
|
943 |
// System.out.println("unite str="+uniteToWords(unite));
|
880 |
944 |
highlightUnite(unite, true, -1);
|
881 |
|
|
|
945 |
|
882 |
946 |
updatePropertiesView(unite);
|
883 |
947 |
deleteButton.setEnabled(true);
|
884 |
948 |
editLeftButton.setEnabled(true);
|
885 |
949 |
editButton.setEnabled(true);
|
886 |
950 |
editRightButton.setEnabled(true);
|
887 |
|
//drop_b.setEnabled(true);
|
|
951 |
// drop_b.setEnabled(true);
|
888 |
952 |
}
|
889 |
|
|
|
953 |
|
890 |
954 |
if (e != null) editor.updateWordStyles();
|
891 |
955 |
}
|
892 |
|
|
|
956 |
|
893 |
957 |
protected void onTypecomboSelected(SelectionEvent e) {
|
894 |
958 |
reloadIdentifiants();
|
895 |
|
|
|
959 |
|
896 |
960 |
if (typeCombo.getSelectionIndex() > 0) {
|
897 |
|
//String type = unitesAVoir[typeCombo.getSelectionIndex()-1];
|
|
961 |
// String type = unitesAVoir[typeCombo.getSelectionIndex()-1];
|
898 |
962 |
highlightType();
|
899 |
963 |
navigationField.setEnabled(true);
|
900 |
|
} else {
|
|
964 |
}
|
|
965 |
else {
|
901 |
966 |
clearHighlight();
|
902 |
967 |
navigationField.setEnabled(false);
|
903 |
968 |
}
|
904 |
|
|
|
969 |
|
905 |
970 |
createButton.setEnabled(false);
|
906 |
971 |
deleteButton.setEnabled(false);
|
907 |
972 |
editButton.setEnabled(false);
|
908 |
|
//drop_b.setEnabled(false);
|
|
973 |
// drop_b.setEnabled(false);
|
909 |
974 |
if (e != null) editor.updateWordStyles();
|
910 |
975 |
}
|
911 |
|
|
|
976 |
|
912 |
977 |
/**
|
913 |
978 |
* reload the identifiants combo
|
914 |
979 |
*
|
... | ... | |
921 |
986 |
navigationField.setIdentifiants(identifiants, type0, Unite.class);
|
922 |
987 |
navigationField.setSelectionIndex(0);
|
923 |
988 |
}
|
924 |
|
|
|
989 |
|
925 |
990 |
public void reloadUnits() {
|
926 |
|
|
|
991 |
|
927 |
992 |
typesUnitesAVoir = vue.getTypesUnitesAVoir();
|
928 |
|
String[] items = new String[typesUnitesAVoir.length +1];
|
|
993 |
String[] items = new String[typesUnitesAVoir.length + 1];
|
929 |
994 |
System.arraycopy(typesUnitesAVoir, 0, items, 1, typesUnitesAVoir.length);
|
930 |
995 |
items[0] = Messages.UnitToolbar_54;
|
931 |
996 |
typeCombo.setItems(items);
|
... | ... | |
933 |
998 |
typeCombo.select(0);
|
934 |
999 |
}
|
935 |
1000 |
typeCombo.layout();
|
936 |
|
|
|
1001 |
|
937 |
1002 |
onTypecomboSelected(null);
|
938 |
1003 |
}
|
939 |
|
|
|
1004 |
|
940 |
1005 |
protected void selectUniteInIdentifants(Unite unite) {
|
941 |
|
for (int i = 0 ; i < unites.length ; i++) {
|
942 |
|
//System.out.println("VS "+unites[i]);
|
|
1006 |
for (int i = 0; i < unites.length; i++) {
|
|
1007 |
// System.out.println("VS "+unites[i]);
|
943 |
1008 |
if (unites[i] == unite) {
|
944 |
|
navigationField.setSelectionIndex(i+1);
|
|
1009 |
navigationField.setSelectionIndex(i + 1);
|
945 |
1010 |
return; // no need to go further
|
946 |
1011 |
}
|
947 |
1012 |
}
|
948 |
1013 |
}
|
949 |
|
|
|
1014 |
|
950 |
1015 |
public void setEnable(boolean enable) {
|
951 |
1016 |
l.setEnabled(enable);
|
952 |
1017 |
typeCombo.setEnabled(enable);
|
... | ... | |
956 |
1021 |
editButton.setEnabled(enable);
|
957 |
1022 |
editLeftButton.setEnabled(enable);
|
958 |
1023 |
editRightButton.setEnabled(enable);
|
959 |
|
//drop_b.setEnabled(enable);
|
|
1024 |
// drop_b.setEnabled(enable);
|
960 |
1025 |
}
|
961 |
|
|
|
1026 |
|
962 |
1027 |
@Override
|
963 |
1028 |
public void traiterEvent(Message e) {
|
964 |
1029 |
if (annotationArea.isDisposed()) return;
|
965 |
|
|
|
1030 |
|
966 |
1031 |
if (e.getType().equals(TypeMessage.MODIF_STRUCTURE)) {
|
967 |
|
//System.out.println("UnitToolbar.traiterEvent: Update toolbar ");
|
|
1032 |
// System.out.println("UnitToolbar.traiterEvent: Update toolbar ");
|
968 |
1033 |
UnitToolbar.this.annotationArea.getDisplay().syncExec(new Runnable() {
|
|
1034 |
|
969 |
1035 |
@Override
|
970 |
1036 |
public void run() {
|
971 |
1037 |
setEnable(!analecCorpus.isVide());
|
972 |
|
//reloadUnits();
|
|
1038 |
// reloadUnits();
|
973 |
1039 |
}
|
974 |
1040 |
});
|
975 |
|
} else if (e.getType().equals(TypeMessage.MODIF_ELEMENT)) {
|
976 |
|
//System.out.println("UnitToolbar.traiterEvent: Update toolbar ");
|
|
1041 |
}
|
|
1042 |
else if (e.getType().equals(TypeMessage.MODIF_ELEMENT)) {
|
|
1043 |
// System.out.println("UnitToolbar.traiterEvent: Update toolbar ");
|
977 |
1044 |
UnitToolbar.this.annotationArea.getDisplay().syncExec(new Runnable() {
|
|
1045 |
|
978 |
1046 |
@Override
|
979 |
1047 |
public void run() {
|
980 |
|
//reloadUnits();
|
|
1048 |
// reloadUnits();
|
981 |
1049 |
}
|
982 |
1050 |
});
|
983 |
1051 |
}
|
984 |
1052 |
}
|
985 |
|
|
|
1053 |
|
986 |
1054 |
protected boolean tryHighlightingUnitsWord(String id, org.txm.searchengine.cqp.corpus.CQPCorpus c) throws CqiClientException {
|
987 |
1055 |
EditionPanel panel = editor.getEditionPanel(0);
|
988 |
1056 |
if (panel == null) return false;
|
989 |
1057 |
if (id != null) {
|
990 |
|
|
|
1058 |
|
991 |
1059 |
}
|
992 |
|
QueryResult r = c.query(new CQLQuery("[_.text_id=\""+panel.getEdition().getText().getName()+"\" & id=\""+id+"\"]"), "TMP", false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
|
1060 |
QueryResult r = c.query(new CQLQuery("[_.text_id=\"" + panel.getEdition().getText().getName() + "\" & id=\"" + id + "\"]"), "TMP", false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
993 |
1061 |
List<Match> matches = r.getMatches();
|
994 |
1062 |
if (matches.size() == 0) {
|
995 |
1063 |
System.out.println(NLS.bind(Messages.UnitToolbar_59, id));
|
996 |
1064 |
return false;
|
997 |
1065 |
}
|
998 |
1066 |
int start = matches.get(0).getStart();
|
999 |
|
//System.out.println("start="+start);
|
|
1067 |
// System.out.println("start="+start);
|
1000 |
1068 |
r.drop();
|
1001 |
1069 |
int i = 0;
|
1002 |
|
ArrayList<Integer> matching_units = new ArrayList<Integer>();
|
|
1070 |
ArrayList<Integer> matching_units = new ArrayList<>();
|
1003 |
1071 |
for (Unite u : unites) {
|
1004 |
|
if (u.getDeb() <= start && start <= u.getFin()) {
|
|
1072 |
if (u.getDeb() <= start && start <= u.getFin()) {
|
1005 |
1073 |
matching_units.add(i);
|
1006 |
|
} else if (u.getDeb() > start) { // no need to search further
|
|
1074 |
}
|
|
1075 |
else if (u.getDeb() > start) { // no need to search further
|
1007 |
1076 |
continue;
|
1008 |
1077 |
}
|
1009 |
1078 |
i++;
|
1010 |
1079 |
}
|
1011 |
|
|
|
1080 |
|
1012 |
1081 |
if (matching_units.size() > 0) {
|
1013 |
1082 |
// get index in matching_units of the current unit if any
|
1014 |
|
int iUnite = matching_units.indexOf(navigationField.getSelectionIndex()-1);
|
1015 |
|
|
|
1083 |
int iUnite = matching_units.indexOf(navigationField.getSelectionIndex() - 1);
|
|
1084 |
|
1016 |
1085 |
if (iUnite == -1) iUnite = 0; // current unit is not present, take the first in matching_units
|
1017 |
|
else iUnite = (iUnite+1)%matching_units.size(); // take the next unit in matching_units
|
1018 |
|
|
|
1086 |
else iUnite = (iUnite + 1) % matching_units.size(); // take the next unit in matching_units
|
|
1087 |
|
1019 |
1088 |
iUnite = matching_units.get(iUnite); // get the real unit position in 'unites'
|
1020 |
|
navigationField.setSelectionIndex(iUnite+1, false); // call onIndentifiantComboChanged(...)
|
1021 |
|
|
|
1089 |
navigationField.setSelectionIndex(iUnite + 1, false); // call onIndentifiantComboChanged(...)
|
|
1090 |
|
1022 |
1091 |
createButton.setEnabled(false);
|
1023 |
1092 |
deleteButton.setEnabled(true);
|
1024 |
1093 |
editLeftButton.setEnabled(true);
|
1025 |
1094 |
editButton.setEnabled(true);
|
1026 |
1095 |
editRightButton.setEnabled(true);
|
1027 |
|
|
|
1096 |
|
1028 |
1097 |
Unite unite = unites[iUnite];
|
1029 |
|
int offset = start-unite.getDeb(); // to select the right page when the unit words overlap with 2 pages
|
|
1098 |
int offset = start - unite.getDeb(); // to select the right page when the unit words overlap with 2 pages
|
1030 |
1099 |
highlightUnite(unite, true, offset);
|
1031 |
|
|
|
1100 |
|
1032 |
1101 |
updatePropertiesView(unite);
|
1033 |
|
|
|
1102 |
|
1034 |
1103 |
return true;
|
1035 |
1104 |
}
|
1036 |
|
|
1037 |
|
|
|
1105 |
|
|
1106 |
|
1038 |
1107 |
navigationField.setSelectionIndex(0);
|
1039 |
|
|
|
1108 |
|
1040 |
1109 |
return false;
|
1041 |
1110 |
}
|
1042 |
|
|
|
1111 |
|
1043 |
1112 |
protected boolean updateUniteLimits(Unite unite, String[] ids, int mode) throws CqiClientException {
|
1044 |
|
|
|
1113 |
|
1045 |
1114 |
EditionPanel panel = UnitToolbar.this.editor.getEditionPanel(0);
|
1046 |
1115 |
String text_name = panel.getEdition().getText().getName();
|
1047 |
|
|
|
1116 |
|
1048 |
1117 |
int[] startend = getStartEndWordPositions(maincorpus, ids, text_name);
|
1049 |
1118 |
if (startend == null) return false;
|
1050 |
|
|
|
1119 |
|
1051 |
1120 |
int pos = startend[0];
|
1052 |
|
|
|
1121 |
|
1053 |
1122 |
if (mode == 1) { // left
|
1054 |
1123 |
analecCorpus.modifBornesUnite(unite, pos, unite.getFin());
|
1055 |
|
} else if (mode == 2) { // right
|
|
1124 |
}
|
|
1125 |
else if (mode == 2) { // right
|