+ createNewGroup.setEnabled(false);\r
+\r
+ String searchString = textfield.getText().trim();\r
+ if(!caseSensitive.isSelected())\r
+ searchString = searchString.toUpperCase();\r
+\r
+ if(searchString.length()<1)\r
+ return;\r
+\r
+ com.stevesoft.pat.Regex regex = new com.stevesoft.pat.Regex(searchString);\r
+\r
+ searchResults = new SearchResults();\r
+\r
+ Sequence seq;\r
+ String item = null;\r
+ boolean found = false;\r
+\r
+ ////// is the searchString a residue number?\r
+ try\r
+ {\r
+ int res = Integer.parseInt(searchString);\r
+ found = true;\r
+ if (av.getSelectionGroup() == null || av.getSelectionGroup().getSize(false) < 1)\r
+ {\r
+ seq = (Sequence) av.getAlignment().getSequenceAt(0);\r
+ }\r
+ else\r
+ {\r
+ seq = (Sequence) (av.getSelectionGroup().getSequenceAt(0));\r
+ }\r
+\r
+ searchResults.addResult(seq, res, res);\r
+ }\r
+ catch (NumberFormatException ex)\r
+ {\r
+ }\r
+\r
+ ///////////////////////////////////////////////\r
+\r
+ int end = av.alignment.getHeight();\r
+\r
+ SequenceGroup selection = av.getSelectionGroup();\r
+\r
+ if (selection != null)\r
+ {\r
+ if ((selection.getSize(false) < 1) ||\r
+ ((selection.getEndRes() - selection.getStartRes()) < 2))\r
+ {\r
+ selection = null;\r
+ }\r
+ }\r
+\r
+ while (!found && (seqIndex < end))\r
+ {\r
+ seq = (Sequence) av.alignment.getSequenceAt(seqIndex);\r
+\r
+ if ((selection != null) && !selection.getSequences(false).contains(seq))\r
+ {\r
+ seqIndex++;\r
+ resIndex = 0;\r
+\r
+ continue;\r
+ }\r
+\r
+ item = seq.getSequence();\r
+ if(!caseSensitive.isSelected())\r
+ item = item.toUpperCase();\r
+\r
+ if ((selection != null) &&\r
+ (selection.getEndRes() < av.alignment.getWidth()-1))\r
+ {\r
+ item = item.substring(0, selection.getEndRes() + 1);\r
+ }\r
+\r
+ ///Shall we ignore gaps????\r
+ StringBuffer noGapsSB = new StringBuffer();\r
+ int insertCount = 0;\r
+ Vector spaces = new Vector();\r
+\r
+ for (int j = 0; j < item.length(); j++)\r
+ {\r
+ if (!jalview.util.Comparison.isGap(item.charAt(j)))\r
+ {\r
+ noGapsSB.append(item.charAt(j));\r
+ spaces.add(new Integer(insertCount));\r
+ }\r
+ else\r
+ {\r
+ insertCount++;\r
+ }\r
+ }\r
+\r
+ String noGaps = noGapsSB.toString();\r
+\r
+ for (int r = resIndex; r < noGaps.length(); r++)\r
+ {\r
+\r
+ if (regex.searchFrom(noGaps, r))\r
+ {\r
+ resIndex = regex.matchedFrom();\r
+\r
+ if ((selection != null) &&\r
+ ((resIndex +\r
+ Integer.parseInt(spaces.get(resIndex).toString())) < selection.getStartRes()))\r
+ {\r
+ continue;\r
+ }\r