diff --git a/trick_source/java/src/main/java/trick/sie/utils/SearchPanel.java b/trick_source/java/src/main/java/trick/sie/utils/SearchPanel.java index 34c7de17..2fe40178 100644 --- a/trick_source/java/src/main/java/trick/sie/utils/SearchPanel.java +++ b/trick_source/java/src/main/java/trick/sie/utils/SearchPanel.java @@ -115,7 +115,8 @@ public class SearchPanel extends JXPanel { listModel.clear(); searcher.search(textField.getText().trim(), caseSensitiveCheckBox.isSelected(), - regularExpressionCheckBox.isSelected()); + regularExpressionCheckBox.isSelected(), + greedySearchCheckBox.isSelected()); if (searcher.elementCount == 0) { progressBar.setIndeterminate(true); } @@ -136,6 +137,12 @@ public class SearchPanel extends JXPanel { setToolTipText("Toggle regular expression searching."); }}; + /** toggles case-insensitive searching */ + JCheckBox greedySearchCheckBox = new JCheckBox("Greedy Search") {{ + setName("greedySearchCheckBox"); + setToolTipText("Toggle multi-threaded search (Warning: may cause overruns)."); + }}; + /** search results list model */ EfficientListModel listModel = new EfficientListModel(); @@ -227,6 +234,7 @@ public class SearchPanel extends JXPanel { setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); add(caseSensitiveCheckBox); add(regularExpressionCheckBox); + add(greedySearchCheckBox); }}); }}, constraints); @@ -306,6 +314,7 @@ public class SearchPanel extends JXPanel { textField.setEnabled(enabled); caseSensitiveCheckBox.setEnabled(enabled); regularExpressionCheckBox.setEnabled(enabled); + greedySearchCheckBox.setEnabled(enabled); list.setEnabled(enabled); list.setComponentPopupMenu(enabled ? popupMenu : null); } diff --git a/trick_source/java/src/main/java/trick/sie/utils/Searcher.java b/trick_source/java/src/main/java/trick/sie/utils/Searcher.java index 04a2245c..aaf20e1b 100644 --- a/trick_source/java/src/main/java/trick/sie/utils/Searcher.java +++ b/trick_source/java/src/main/java/trick/sie/utils/Searcher.java @@ -89,9 +89,10 @@ public class Searcher { * @param targetText the text for which to search * @param caseSensitive enables case sensitive searching * @param regularExpression enables regular expression searching + * @param greedSearch enabled multi-threaded search */ public void search(final String targetText, final boolean caseSensitive, - final boolean regularExpression) { + final boolean regularExpression, final boolean greedySearch) { final SearchFunction searchFunction = regularExpression ? @@ -124,7 +125,11 @@ public class Searcher { cancelSearch(); count = 0; - threads = Runtime.getRuntime().availableProcessors(); + if (greedySearch) { + threads = Runtime.getRuntime().availableProcessors(); + } else { + threads = 1; + } propertyChangeListener.propertyChange(new PropertyChangeEvent(this, "progress", 0, 0)); final ConcurrentLinkedQueue roots = new ConcurrentLinkedQueue(rootTemplates); executorService = Executors.newFixedThreadPool(threads);