Source code: org/bdgp/apps/dagedit/gui/FindPanel.java
1 package org.bdgp.apps.dagedit.gui;
2
3 import java.util.*;
4 import java.awt.event.*;
5 import java.awt.*;
6 import javax.swing.*;
7 import javax.swing.border.*;
8 import javax.swing.tree.*;
9 import org.bdgp.util.*;
10 import org.bdgp.swing.*;
11 import org.apache.oro.text.regex.*;
12
13 import org.bdgp.apps.dagedit.gui.event.*;
14 import org.bdgp.apps.dagedit.datamodel.*;
15 import org.bdgp.cv.datamodel.*;
16
17 public class FindPanel extends JPanel {
18
19 public final int MAX_HITS = 150;
20 public final int HISTORY_SIZE = 10;
21 public final String [] fieldLists = { "ID", "NAME", "NAME_OR_SYNONYM",
22 "SYNONYM", "DEFINITION", "COMMENT",
23 "DBXREF" };
24 PatternCompiler compiler = new Perl5Compiler();
25 PatternMatcher matcher = new Perl5Matcher();
26
27 private SearchField ID_FIELD =
28 new SearchField("ID", true);
29 private SearchField NAME_FIELD =
30 new SearchField("Term name", true);
31 private SearchField NAME_OR_SYNONYM_FIELD =
32 new SearchField("Any synonym or term name", false);
33 private SearchField SYNONYM_FIELD =
34 new SearchField("Any synonym", false);
35 private SearchField DEFINITION_FIELD =
36 new SearchField("Definition", true);
37 private SearchField COMMENT_FIELD =
38 new SearchField("Comment", true);
39 private SearchField DBXREF_FIELD =
40 new SearchField("Any dbxref", false);
41
42 private ComparisonType EQUALS_COMPARISON =
43 new ComparisonType("equals", false);
44 private ComparisonType STARTS_WITH_COMPARISON =
45 new ComparisonType("starts with", false);
46 private ComparisonType ENDS_WITH_COMPARISON =
47 new ComparisonType("ends with", false);
48 private ComparisonType CONTAINS_COMPARISON =
49 new ComparisonType("contains", false);
50 private ComparisonType MATCHES_WILDCARD_COMPARISON =
51 new ComparisonType("matches (wildcard)", false);
52 private ComparisonType MATCHES_REGEXP_COMPARISON =
53 new ComparisonType("matches (regexp)", false);
54
55 private boolean haltThread = false;
56 private boolean searching = false;
57
58 private class TermFilter implements VectorFilter {
59 private SearchField field;
60 private ComparisonType comparison;
61 private boolean caseSensitive;
62 private String value;
63 private Pattern pattern;
64
65 public TermFilter(SearchField field, boolean caseSensitive,
66 ComparisonType comparison,
67 String value) {
68 this.field = field;
69 this.caseSensitive = caseSensitive;
70 this.comparison = comparison;
71 this.value = value;
72 if (comparison.equals(MATCHES_REGEXP_COMPARISON) ||
73 comparison.equals(MATCHES_WILDCARD_COMPARISON) ||
74 comparison.equals(STARTS_WITH_COMPARISON) ||
75 comparison.equals(ENDS_WITH_COMPARISON) ||
76 comparison.equals(CONTAINS_COMPARISON)) {
77 try {
78 int mask = Perl5Compiler.DEFAULT_MASK;
79 if (!caseSensitive)
80 mask ^= Perl5Compiler.CASE_INSENSITIVE_MASK;
81 if (comparison.equals(STARTS_WITH_COMPARISON))
82 value = value+"*";
83 else if (comparison.equals(ENDS_WITH_COMPARISON))
84 value = "*"+value;
85 else if (comparison.equals(CONTAINS_COMPARISON))
86 value = "*"+value+"*";
87
88 if (comparison.equals(MATCHES_WILDCARD_COMPARISON) ||
89 comparison.equals(STARTS_WITH_COMPARISON) ||
90 comparison.equals(ENDS_WITH_COMPARISON) ||
91 comparison.equals(CONTAINS_COMPARISON))
92 value = convertClassicToRegexp(value);
93 pattern = compiler.compile(value, mask);
94 } catch (MalformedPatternException e) {
95 System.err.println("Malformed pattern");
96 pattern = null;
97 }
98 }
99 }
100
101 private String convertClassicToRegexp(String in) {
102 StringBuffer out = new StringBuffer();
103 for(int i=0; i < in.length(); i++) {
104 char c = in.charAt(i);
105 if (c == '*')
106 out.append(".*");
107 else if (Character.isLetterOrDigit(c))
108 out.append(c);
109 else {
110 out.append('\\');
111 out.append(c);
112 }
113 }
114 return out.toString();
115 }
116
117 public boolean satisfies(Object o) {
118 Term term = (Term) o;
119
120 if (comparison.equals(EQUALS_COMPARISON)) {
121 return equals(term, field, value, caseSensitive);
122 } else if (comparison.equals(MATCHES_REGEXP_COMPARISON) ||
123 comparison.equals(MATCHES_WILDCARD_COMPARISON) ||
124 comparison.equals(STARTS_WITH_COMPARISON) ||
125 comparison.equals(ENDS_WITH_COMPARISON) ||
126 comparison.equals(CONTAINS_COMPARISON)) {
127 if (field.equals(SYNONYM_FIELD))
128 return synonymMatch(term);
129 else if (field.equals(NAME_OR_SYNONYM_FIELD))
130 return synonymMatch(term) || regexpMatch(term, NAME_FIELD);
131 else if (field.equals(DBXREF_FIELD))
132 return dbxrefMatch(term);
133 else
134 return regexpMatch(term, field);
135 } else
136 return false;
137 }
138
139 public boolean synonymMatch(Term term) {
140 for(int i=0; i < term.getSynonyms().size(); i++) {
141 Synonym s = (Synonym) term.getSynonyms().elementAt(i);
142 String name = s.getText();
143 String id = s.getID();
144 if ((name != null && matcher.matches(name, pattern)) ||
145 (id != null && matcher.matches(id, pattern)))
146 return true;
147 }
148 return false;
149 }
150
151 public boolean dbxrefMatch(Term term) {
152 for(int i=0; i < term.getDbxrefs().size(); i++) {
153 Dbxref ref = (Dbxref) term.getDbxrefs().elementAt(i);
154 if (matcher.matches(ref.toString(), pattern))
155 return true;
156 }
157 for(int i=0; i < term.getDefDbxrefs().size(); i++) {
158 Dbxref ref = (Dbxref) term.getDefDbxrefs().elementAt(i);
159 if (matcher.matches(ref.toString(), pattern))
160 return true;
161 }
162 for(int i=0; i < term.getSynonyms().size(); i++) {
163 Synonym s = (Synonym) term.getSynonyms().elementAt(i);
164 for(int j=0; j < s.getDbxrefs().size(); j++) {
165 Dbxref ref = (Dbxref) s.getDbxrefs().elementAt(j);
166 if (matcher.matches(ref.toString(), pattern))
167 return true;
168 }
169 }
170 return false;
171 }
172
173 public String getValueForField(Term term, SearchField field) {
174 if (field.equals(ID_FIELD))
175 return term.getID();
176 else if (field.equals(NAME_FIELD))
177 return term.getTerm();
178 else if (field.equals(DEFINITION_FIELD))
179 return term.getDefinition();
180 else if (field.equals(COMMENT_FIELD))
181 return term.getComment();
182 else
183 return null;
184 }
185
186 public boolean regexpMatch(Term term,
187 SearchField field) {
188 String termVal = getValueForField(term, field);
189 return matcher.matches(termVal, pattern);
190 }
191
192 public boolean equals(Term term,
193 SearchField field,
194 String value,
195 boolean caseSensitive) {
196 if (field.equals(SYNONYM_FIELD)) {
197 for(int i=0; i < term.getSynonyms().size(); i++) {
198 Synonym s = (Synonym) term.getSynonyms().elementAt(i);
199 String name = s.getText();
200 String id = s.getID();
201 if (!caseSensitive) {
202 if ((name != null && name.equalsIgnoreCase(value)) ||
203 (id != null && id.equalsIgnoreCase(value)))
204 return true;
205 } else {
206 if ((name != null && name.equals(value)) ||
207 (id != null && id.equals(value)))
208 return true;
209 }
210 }
211 return false;
212 } else if (field.equals(NAME_OR_SYNONYM_FIELD)) {
213 for(int i=0; i < term.getSynonyms().size(); i++) {
214 Synonym s = (Synonym) term.getSynonyms().elementAt(i);
215 String name = s.getText();
216 String id = s.getID();
217 if (!caseSensitive) {
218 if ((name != null && name.equalsIgnoreCase(value)) ||
219 (id != null && id.equalsIgnoreCase(value)))
220 return true;
221 } else {
222 if ((name != null && name.equals(value)) ||
223 (id != null && id.equals(value)))
224 return true;
225 }
226 }
227 String termVal = getValueForField(term, field);
228 if (termVal == null)
229 return false;
230 return strcmp(termVal,
231 value,
232 caseSensitive) == 0;
233 } else if (field.equals(DBXREF_FIELD)) {
234 for(int i=0; i < term.getDbxrefs().size(); i++) {
235 Dbxref ref = (Dbxref) term.getDbxrefs().elementAt(i);
236 if (!caseSensitive) {
237 if (ref.toString().equalsIgnoreCase(value))
238 return true;
239 } else {
240 if (ref.toString().equalsIgnoreCase(value))
241 return true;
242 }
243 }
244 for(int i=0; i < term.getDefDbxrefs().size(); i++) {
245 Dbxref ref = (Dbxref) term.getDefDbxrefs().elementAt(i);
246 if (!caseSensitive) {
247 if (ref.toString().equalsIgnoreCase(value))
248 return true;
249 } else {
250 if (ref.toString().equalsIgnoreCase(value))
251 return true;
252 }
253 }
254 for(int i=0; i < term.getSynonyms().size(); i++) {
255 Synonym s = (Synonym) term.getSynonyms().elementAt(i);
256 for(int j=0; j < s.getDbxrefs().size(); j++) {
257 Dbxref ref = (Dbxref) s.getDbxrefs().elementAt(j);
258 if (!caseSensitive) {
259 if (ref.toString().equalsIgnoreCase(value))
260 return true;
261 } else {
262 if (ref.toString().equalsIgnoreCase(value))
263 return true;
264 }
265 }
266 }
267 return false;
268 } else {
269 String termVal = getValueForField(term, field);
270 if (termVal == null)
271 return false;
272 return strcmp(termVal,
273 value,
274 caseSensitive) == 0;
275 }
276 }
277
278 public int strcmp(String a, String b, boolean caseSensitive) {
279 if (!caseSensitive) {
280 a = a.toUpperCase();
281 b = b.toUpperCase();
282 }
283 return a.compareTo(b);
284 }
285 }
286
287 private class SearchField {
288 private String name;
289 private boolean allowRangeComparisons;
290
291 public SearchField(String name, boolean allowRangeComparisons) {
292 this.name = name;
293 this.allowRangeComparisons = allowRangeComparisons;
294 }
295
296 public String toString() {
297 return name;
298 }
299
300 public boolean equals(Object o) {
301 return this == o;
302 }
303 }
304
305 private class ComparisonType {
306 private String name;
307 private boolean isRangeComparison;
308
309 public ComparisonType(String name, boolean isRangeComparison) {
310 this.name = name;
311 this.isRangeComparison = isRangeComparison;
312 }
313
314 public String toString() {
315 return name;
316 }
317
318 public boolean equals(Object o) {
319 return this == o;
320 }
321 }
322
323 protected class SearchRecord {
324 protected SearchField searchField;
325 protected ComparisonType type;
326 protected String value;
327
328 public SearchRecord(SearchField searchField,
329 ComparisonType type,
330 String value) {
331 this.searchField = searchField;
332 this.type = type;
333 this.value = value;
334 }
335
336 public SearchField getSearchField() {
337 return searchField;
338 }
339
340 public ComparisonType getType() {
341 return type;
342 }
343
344 public String getValue() {
345 return value;
346 }
347
348 public boolean equals(Object o) {
349 if (o instanceof SearchRecord) {
350 SearchRecord sr = (SearchRecord) o;
351 return sr.getValue().equals(value) &&
352 sr.getSearchField().equals(searchField);
353 } else
354 return false;
355 }
356
357 public String toString() {
358 return value;
359 }
360 }
361
362 JComboBox fieldBox;
363 JComboBox comparisonBox;
364 JComboBox valueField;
365 JButton findButton;
366 JRadioButton searchAllButton;
367 JRadioButton searchChildrenButton;
368 JRadioButton searchSelectionButton;
369 JCheckBox caseSensitiveButton;
370 JProgressBar progressMeter;
371
372 private Vector fields;
373 private Vector comparisons;
374 // private Term root;
375 private Controller controller;
376 private SearchThread searchThread;
377
378 protected HashMap previousSearches = new HashMap();
379
380
381
382 public FindPanel(Controller controller) {
383 buildFields();
384 buildComparisons();
385 this.controller = controller;
386 fieldBox = new JComboBox(fields);
387 comparisonBox = new JComboBox(comparisons);
388 valueField = new JComboBox();
389 valueField.setEditable(true);
390 findButton = new JButton("Find");
391 searchAllButton = new JRadioButton("Search all terms", null, true);
392 searchChildrenButton = new JRadioButton("Search children of selection",
393 null, false);
394 searchSelectionButton = new JRadioButton("Search selection",
395 null, false);
396 caseSensitiveButton = new JCheckBox("Case sensitive search");
397
398 progressMeter = new JProgressBar();
399 progressMeter.setString("No search performed");
400 progressMeter.setStringPainted(true);
401 progressMeter.setOpaque(false);
402 ButtonGroup bg = new ButtonGroup();
403 bg.add(searchAllButton);
404 bg.add(searchChildrenButton);
405 bg.add(searchSelectionButton);
406 buildGUI();
407 setSearching(false);
408 installListeners();
409 populatePreviousSearches();
410 setupField();
411 }
412
413 protected void populatePreviousSearches() {
414 MultiProperties props = controller.getConfig();
415 for(int i=0; i < fieldLists.length; i++) {
416 MultiProperties fieldProps = props.
417 getProperties("SEARCHES_"+fieldLists[i]);
418 SearchField searchField = null;
419 if (fieldLists[i].equals("ID"))
420 searchField = ID_FIELD;
421 else if (fieldLists[i].equals("NAME"))
422 searchField = NAME_FIELD;
423 else if (fieldLists[i].equals("NAME_OR_SYNONYM"))
424 searchField = NAME_OR_SYNONYM_FIELD;
425 else if (fieldLists[i].equals("SYNONYM"))
426 searchField = SYNONYM_FIELD;
427 else if (fieldLists[i].equals("DEFINITION"))
428 searchField = DEFINITION_FIELD;
429 else if (fieldLists[i].equals("COMMENT"))
430 searchField = COMMENT_FIELD;
431 else if (fieldLists[i].equals("DBXREF"))
432 searchField = DBXREF_FIELD;
433 Vector vector = new Vector();
434 previousSearches.put(searchField, vector);
435 String count_str = (String) fieldProps.getProperty("count");
436 int count = 0;
437 try {
438 count = Integer.parseInt(count_str);
439 } catch (NumberFormatException ex) {
440 }
441 for(int j=0; j < count; j++) {
442 String type_str = (String) fieldProps.getProperty("type_"+j);
443 String value = (String) fieldProps.getProperty("value_"+j);
444
445 ComparisonType type = null;
446 if (type_str.equals("EQUALS"))
447 type = EQUALS_COMPARISON;
448 else if (type_str.equals("STARTS_WITH"))
449 type = STARTS_WITH_COMPARISON;
450 else if (type_str.equals("ENDS_WITH"))
451 type = ENDS_WITH_COMPARISON;
452 else if (type_str.equals("CONTAINS"))
453 type = CONTAINS_COMPARISON;
454 else if (type_str.equals("WILDCARD"))
455 type = MATCHES_WILDCARD_COMPARISON;
456 else if (type_str.equals("REGEXP"))
457 type = MATCHES_REGEXP_COMPARISON;
458 SearchRecord record = new SearchRecord(searchField,
459 type,
460 value);
461 vector.add(record);
462 }
463 }
464 }
465
466 protected void flushPreviousSearches() {
467 MultiProperties props = controller.getConfig();
468 Iterator it = previousSearches.keySet().iterator();
469 while(it.hasNext()) {
470 SearchField searchField = (SearchField) it.next();
471 String searchFieldStr = "";
472 if (searchField == ID_FIELD)
473 searchFieldStr = "ID";
474 else if (searchField == NAME_FIELD)
475 searchFieldStr = "NAME";
476 else if (searchField == NAME_OR_SYNONYM_FIELD)
477 searchFieldStr = "NAME_OR_SYNONYM";
478 else if (searchField == SYNONYM_FIELD)
479 searchFieldStr = "SYNONYM";
480 else if (searchField == DEFINITION_FIELD)
481 searchFieldStr = "DEFINITION";
482 else if (searchField == COMMENT_FIELD)
483 searchFieldStr = "COMMENT";
484 else if (searchField == DBXREF_FIELD)
485 searchFieldStr = "DBXREF";
486 Vector vector = (Vector) previousSearches.get(searchField);
487 MultiProperties out = new MultiProperties();
488 out.setProperty("count", vector.size()+"");
489 for(int i=0; i < vector.size(); i++) {
490 SearchRecord record = (SearchRecord) vector.get(i);
491 String typeStr = "";
492 if (record.getType() == EQUALS_COMPARISON)
493 typeStr = "EQUALS";
494 else if (record.getType() == MATCHES_WILDCARD_COMPARISON)
495 typeStr = "WILDCARD";
496 else if (record.getType() == MATCHES_REGEXP_COMPARISON)
497 typeStr = "REGEXP";
498 else if (record.getType() == STARTS_WITH_COMPARISON)
499 typeStr = "STARTS_WITH";
500 else if (record.getType() == ENDS_WITH_COMPARISON)
501 typeStr = "ENDS_WITH";
502 else if (record.getType() == CONTAINS_COMPARISON)
503 typeStr = "CONTAINS";
504
505 out.setProperty("type_"+i, typeStr);
506 out.setProperty("value_"+i, record.getValue());
507 }
508 props.setProperties("SEARCHES_"+searchFieldStr, out);
509 }
510 controller.flushConfig();
511 }
512
513 protected void setupField() {
514 SearchField searchField = (SearchField) fieldBox.getSelectedItem();
515 Vector fieldSet = (Vector) previousSearches.get(searchField);
516 valueField.removeAllItems();
517 if (fieldSet == null)
518 return;
519 for(int i=0; i < fieldSet.size(); i++) {
520 SearchRecord record = (SearchRecord) fieldSet.get(i);
521 valueField.addItem(record);
522 }
523 }
524
525 public void installListeners() {
526 ActionListener listener = new ActionListener() {
527 public void actionPerformed(ActionEvent e) {
528 if (searching)
529 searchThread.halt();
530 else {
531 searchThread = new SearchThread();
532 searchThread.start();
533 }
534 }
535 };
536 valueField.getEditor().addActionListener(new ActionListener() {
537 public void actionPerformed(ActionEvent e) {
538 searchThread = new SearchThread();
539 searchThread.start();
540 }
541 });
542
543 findButton.addActionListener(listener);
544 fieldBox.addItemListener(new ItemListener() {
545 public void itemStateChanged(ItemEvent e) {
546 setupField();
547 }
548 });
549 valueField.addActionListener(new ActionListener() {
550 public void actionPerformed(ActionEvent e) {
551 Object obj = valueField.getSelectedItem();
552 if (obj instanceof SearchRecord) {
553 SearchRecord record = (SearchRecord) obj;
554 comparisonBox.setSelectedItem(record.getType());
555 }
556 }
557 });
558 }
559
560 protected class SearchThread extends Thread {
561 public void run() {
562 haltThread = false;
563 setSearching(true);
564 search();
565 setSearching(false);
566 }
567
568 public void halt() {
569 haltThread = true;
570 setSearching(false);
571 Runnable updateGUI = new Runnable() {
572 public void run() {
573 progressMeter.setValue(0);
574 progressMeter.setString("Search cancelled");
575 }
576 };
577 try {
578 if (!SwingUtilities.isEventDispatchThread())
579 SwingUtilities.invokeAndWait(updateGUI);
580 else
581 updateGUI.run();
582 } catch (Exception ex) {
583 ex.printStackTrace();
584 }
585 }
586 }
587
588 protected void setSearching(boolean search) {
589 final JRootPane pane = SwingUtilities.getRootPane(this);
590 this.searching = search;
591 Runnable updateGUI = new Runnable() {
592 public void run() {
593 if (searching) {
594 findButton.setText("Cancel");
595 if (pane != null)
596 pane.setCursor(Cursor.
597 getPredefinedCursor(
598 Cursor.WAIT_CURSOR));
599 fieldBox.setEnabled(false);
600 comparisonBox.setEnabled(false);
601 valueField.setEnabled(false);
602 searchAllButton.setEnabled(false);
603 searchChildrenButton.setEnabled(false);
604 searchSelectionButton.setEnabled(false);
605 caseSensitiveButton.setEnabled(false);
606 progressMeter.setBorderPainted(true);
607 } else {
608 findButton.setText("Find");
609 if (pane != null)
610 pane.setCursor(Cursor.
611 getPredefinedCursor(
612 Cursor.DEFAULT_CURSOR));
613 fieldBox.setEnabled(true);
614 comparisonBox.setEnabled(true);
615 valueField.setEnabled(true);
616 searchAllButton.setEnabled(true);
617 searchChildrenButton.setEnabled(true);
618 searchSelectionButton.setEnabled(true);
619 caseSensitiveButton.setEnabled(true);
620 progressMeter.setBorderPainted(false);
621 }
622 }
623 };
624 try {
625 if (!SwingUtilities.isEventDispatchThread())
626 SwingUtilities.invokeAndWait(updateGUI);
627 else
628 updateGUI.run();
629 } catch (Exception ex) {
630 ex.printStackTrace();
631 }
632 // repaint();
633 }
634
635 public void search() {
636 Runnable updateProgress = new Runnable() {
637 public void run() {
638 controller.fireDisableGUI(new DisableGUIEvent(this));
639 }
640 };
641 try {
642 SwingUtilities.invokeAndWait(updateProgress);
643 } catch (Exception ex) {
644 ex.printStackTrace();
645 }
646 final String value = SwingUtil.getComboBoxValue(valueField);
647
648 TermFilter filter = new TermFilter((SearchField) fieldBox.
649 getSelectedItem(),
650 caseSensitiveButton.isSelected(),
651 (ComparisonType) comparisonBox.
652 getSelectedItem(),
653 value);
654
655 Vector searchSet;
656 if (searchAllButton.isSelected())
657 searchSet = VectorUtil.getVector(
658 controller.getRoot().getAllDescendants());
659 else if (searchSelectionButton.isSelected())
660 searchSet = controller.getSelectedTerms();
661 else if (searchChildrenButton.isSelected()) {
662 HashSet items = new HashSet();
663 for(int i=0; i < controller.getSelectedTerms().size(); i++) {
664 if (haltThread)
665 return;
666 Term term = ((TermRelationship) controller.getSelectedTerms().
667 elementAt(i)).getChild();
668 items.add(term);
669 Enumeration e = term.getAllDescendants();
670 while(e.hasMoreElements()) {
671 if (haltThread)
672 return;
673 Term t = (Term) e.nextElement();
674 items.add(t);
675 }
676 }
677 searchSet = new Vector(items);
678 } else
679 searchSet = new Vector();
680
681 int hitcount = 0;
682 HashSet hitHash = new HashSet();
683 TermModel model = new TermModel(controller.getRoot(), controller);
684 boolean cutoff = false;
685
686 for(int i=0; i < searchSet.size(); i++) {
687 if (haltThread)
688 return;
689 final int percent = (int) Math.round(100 * ((double) i /
690 (double) searchSet.size()));
691 final int currentIndex = i;
692 final int searchSize = searchSet.size();
693 updateProgress = new Runnable() {
694 public void run() {
695 progressMeter.setValue(percent);
696 progressMeter.setString("Searching term "+
697 (currentIndex+1)+" of "+
698 searchSize);
699 }
700 };
701 try {
702 SwingUtilities.invokeLater(updateProgress);
703 } catch (Exception ex) {
704 ex.printStackTrace();
705 }
706 Term term = (Term) searchSet.elementAt(i);
707 TermRelationship termRel = null;
708 if (term.getParents().size() == 0)
709 termRel = new TermRelationship(term, null, null);
710 else
711 termRel = (TermRelationship) term.getParents().elementAt(0);
712
713 if (filter.satisfies(term)) {
714 hitcount++;
715 hitHash.add(term);
716 if (hitcount >= MAX_HITS) {
717 cutoff = true;
718 break;
719 }
720 }
721 }
722
723 final Vector hits = new Vector(hitHash);
724 final int finalhits = hitcount;
725 final boolean finalcutoff = cutoff;
726
727 updateProgress = new Runnable() {
728 public void run() {
729 controller.fireEnableGUI(new DisableGUIEvent(this));
730 if (finalcutoff) {
731 progressMeter.setString(
732 "Too many hits, selected first "+finalhits+
733 " results.");
734 } else
735 progressMeter.setString("Found "+finalhits+" hits.");
736 controller.fireTermSelect(new DETermSelectEvent(this,
737 hits));
738 progressMeter.setValue(0);
739 SearchField searchField = (SearchField) fieldBox.
740 getSelectedItem();
741 ComparisonType type = (ComparisonType) comparisonBox.
742 getSelectedItem();
743 Vector fieldSet = (Vector) previousSearches.
744 get(searchField);
745 SearchRecord record = new SearchRecord(searchField,
746 type, value);
747 if (fieldSet != null) {
748 if (fieldSet.size() > HISTORY_SIZE ||
749 fieldSet.contains(record)) {
750 fieldSet.remove(fieldSet.size() - 1);
751 }
752 } else {
753 fieldSet = new Vector();
754 previousSearches.put(searchField, fieldSet);
755 }
756 fieldSet.insertElementAt(record, 0);
757 flushPreviousSearches();
758 setupField();
759 }
760 };
761 try {
762 SwingUtilities.invokeAndWait(updateProgress);
763 } catch (Exception ex) {
764 ex.printStackTrace();
765 }
766 }
767
768 protected void buildComparisons() {
769 comparisons = new Vector();
770 comparisons.add(EQUALS_COMPARISON);
771 comparisons.add(STARTS_WITH_COMPARISON);
772 comparisons.add(ENDS_WITH_COMPARISON);
773 comparisons.add(CONTAINS_COMPARISON);
774 comparisons.add(MATCHES_WILDCARD_COMPARISON);
775 comparisons.add(MATCHES_REGEXP_COMPARISON);
776 }
777
778 protected void buildFields() {
779 fields = new Vector();
780 fields.addElement(ID_FIELD);
781 fields.addElement(NAME_FIELD);
782 fields.addElement(NAME_OR_SYNONYM_FIELD);
783 fields.addElement(SYNONYM_FIELD);
784 fields.addElement(DEFINITION_FIELD);
785 fields.addElement(COMMENT_FIELD);
786 fields.addElement(DBXREF_FIELD);
787 }
788
789 protected void buildGUI() {
790 fieldBox.setFont(controller.getDefaultFont());
791 comparisonBox.setFont(controller.getDefaultFont());
792 valueField.setFont(controller.getDefaultFont());
793 findButton.setFont(controller.getDefaultFont());
794 searchAllButton.setFont(controller.getDefaultFont());
795 searchChildrenButton.setFont(controller.getDefaultFont());
796 searchSelectionButton.setFont(controller.getDefaultFont());
797 caseSensitiveButton.setFont(controller.getDefaultFont());
798 progressMeter.setFont(controller.getDefaultFont());
799
800 fieldBox.setBackground(Preferences.defaultButtonColor());
801 comparisonBox.setBackground(Preferences.defaultButtonColor());
802 findButton.setBackground(Preferences.defaultButtonColor());
803 searchAllButton.setBackground(Preferences.defaultButtonColor());
804 searchChildrenButton.setBackground(Preferences.defaultButtonColor());
805 searchSelectionButton.setBackground(Preferences.defaultButtonColor());
806 caseSensitiveButton.setBackground(Preferences.defaultButtonColor());
807
808 searchAllButton.setOpaque(false);
809 searchChildrenButton.setOpaque(false);
810 searchSelectionButton.setOpaque(false);
811 caseSensitiveButton.setOpaque(false);
812
813 setBackground(Preferences.defaultBackgroundColor());
814 setBorder(new TitledBorder("Find terms"));
815 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
816 Box searchLine = new Box(BoxLayout.X_AXIS);
817 searchLine.add(fieldBox);
818 searchLine.add(comparisonBox);
819 searchLine.add(valueField);
820 searchLine.add(findButton);
821
822 Box optionLine = new Box(BoxLayout.X_AXIS);
823 optionLine.add(searchAllButton);
824 optionLine.add(searchChildrenButton);
825 optionLine.add(searchSelectionButton);
826 optionLine.add(caseSensitiveButton);
827
828 add(searchLine);
829 add(optionLine);
830 add(progressMeter);
831 }
832 }