viewport.setSelectionGroup(null);\r
viewport.getColumnSelection().clear();\r
viewport.setSelectionGroup(null);\r
+ alignPanel.idPanel.idCanvas.searchResults = null;\r
alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);\r
alignPanel.repaint();\r
PaintRefresher.Refresh(null, viewport.alignment);\r
return new Dimension(idWidth, idPanel.idCanvas.getSize().height);\r
}\r
\r
- public void highlightSearchResults(int[] results)\r
+ public void highlightSearchResults(SearchResults results)\r
{\r
seqPanel.seqCanvas.highlightSearchResults(results);\r
\r
- // do we need to scroll the panel?\r
+ // do we need to scroll the panel?\r
if (results != null)\r
{\r
- SequenceI seq = av.alignment.getSequenceAt(results[0]);\r
- int start = seq.findIndex(results[1]) - 1;\r
- int end = seq.findIndex(results[2]) - 1;\r
+ SequenceI seq = results.getResultSequence(0);\r
+ int seqIndex = av.alignment.findIndex(seq);\r
+ int start = seq.findIndex(results.getResultStart(0)) - 1;\r
+ int end = seq.findIndex(results.getResultEnd(0)) - 1;\r
\r
- if(!av.wrapAlignment)\r
- {\r
- if ( (av.getStartRes() > start) || (av.getEndRes() < end) ||\r
- ( (av.getStartSeq() > results[0]) ||\r
- (av.getEndSeq() < results[0])))\r
+ if(!av.wrapAlignment)\r
{\r
- int newy = results[0];\r
- if(start > av.alignment.getWidth() - hextent)\r
- {\r
- start = av.alignment.getWidth() - hextent;\r
- if(start<0)\r
- start = 0;\r
- }\r
- if(newy > av.alignment.getHeight() - vextent)\r
+ if ( (av.getStartRes() > end) || (av.getEndRes() < start) ||\r
+ ( (av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex)))\r
{\r
- newy = av.alignment.getHeight() - vextent;\r
- if(newy<0)\r
- newy = 0;\r
+ if (start > av.alignment.getWidth() - hextent)\r
+ {\r
+ start = av.alignment.getWidth() - hextent;\r
+ if (start < 0)\r
+ start = 0;\r
+ }\r
+ if (seqIndex > av.alignment.getHeight() - vextent)\r
+ {\r
+ seqIndex = av.alignment.getHeight() - vextent;\r
+ if (seqIndex < 0)\r
+ seqIndex = 0;\r
+ }\r
+ setScrollValues(start, seqIndex);\r
}\r
- setScrollValues(start, newy);\r
}\r
- }\r
- else\r
- {\r
- int cwidth = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width);\r
- if( start<av.getStartRes() || start>(av.getStartRes()+cwidth) )\r
+ else\r
{\r
-\r
- vscroll.setValue(start / cwidth);\r
- av.startRes = vscroll.getValue() * cwidth;\r
+ int cwidth = seqPanel.seqCanvas.getWrappedCanvasWidth(seqPanel.\r
+ seqCanvas.getSize().width);\r
+ if (start < av.getStartRes() || start > (av.getStartRes() + cwidth))\r
+ {\r
+ vscroll.setValue(start / cwidth);\r
+ av.startRes = vscroll.getValue() * cwidth;\r
+ }\r
}\r
- }\r
}\r
\r
repaint();\r
AlignmentPanel ap;\r
Frame frame;\r
SuperGroup searchGroup;\r
- Vector searchResults;\r
+\r
+ SearchResults searchResults;\r
\r
int seqIndex = 0;\r
int resIndex = 0;\r
\r
searchGroup = new SuperGroup(searchString, ucs, true, true, false);\r
\r
- for (int i = 0; i < searchResults.size(); i += 3)\r
+ for (int i = 0; i < searchResults.getSize(); i ++ )\r
{\r
// its possible edits may have occurred since search was performed\r
// account for this here\r
\r
- SequenceI seq = av.alignment.getSequenceAt(Integer.parseInt(searchResults.\r
- elementAt(i).toString()));\r
- int startRes = seq.findIndex(Integer.parseInt(searchResults.elementAt(i +\r
- 1).toString())) - 1;\r
- int endRes = seq.findIndex(Integer.parseInt(searchResults.elementAt(i + 2).\r
- toString())) - 1;\r
+ SequenceI seq = searchResults.getResultSequence(i);\r
+ int startRes = seq.findIndex(searchResults.getResultStart(i)) - 1;\r
+ int endRes = seq.findIndex(searchResults.getResultEnd(i)) - 1;\r
\r
SequenceGroup sg = new SequenceGroup(searchString, ucs, true, true, false,\r
startRes, endRes);\r
\r
com.stevesoft.pat.Regex regex = new com.stevesoft.pat.Regex(searchString);\r
\r
- searchResults = new Vector();\r
- int[] allResults = null;\r
+ searchResults = new SearchResults();\r
\r
Sequence seq;\r
String item = null;\r
seq = (Sequence) (av.getSelectionGroup().getSequenceAt(0));\r
}\r
\r
- searchResults.addElement(Integer.toString(av.getAlignment().findIndex(seq)));\r
- searchResults.addElement(String.valueOf(res));\r
- searchResults.addElement(String.valueOf(res));\r
+\r
+ searchResults.addResult(seq, res, res);\r
\r
}\r
catch (NumberFormatException ex)\r
continue;\r
}\r
\r
- searchResults.addElement(Integer.toString(seqIndex));\r
+\r
int sres = seq.findPosition(resIndex +\r
Integer.parseInt(spaces.\r
elementAt(resIndex).toString()));\r
Integer.parseInt(\r
spaces.elementAt(regex.matchedTo() - 1).\r
toString()));\r
- searchResults.addElement(sres + "");\r
- searchResults.addElement(eres + "");\r
+\r
+ searchResults.addResult(seq, sres, eres);\r
\r
if (!findAll)\r
{\r
}\r
}\r
\r
- if (searchResults.size() == 0 && idMatch.size() > 0)\r
+ if (searchResults.getSize() == 0 && idMatch.size() > 0)\r
{\r
ap.idPanel.highlightSearchResults(idMatch);\r
}\r
\r
- if (searchResults.size() > 0)\r
+ if (searchResults.getSize() > 0)\r
{\r
- allResults = new int[searchResults.size()];\r
- for (int i = 0; i < searchResults.size(); i++)\r
- {\r
- allResults[i] = Integer.parseInt(searchResults.elementAt(i).toString());\r
- }\r
-\r
createNewGroup.setEnabled(true);\r
}\r
else\r
{\r
+ searchResults = null;\r
resIndex = 0;\r
seqIndex = 0;\r
}\r
\r
// if allResults is null, this effectively switches displaySearch flag in seqCanvas\r
- ap.highlightSearchResults(allResults);\r
+ ap.highlightSearchResults(searchResults);\r
\r
if (findAll)\r
{\r
- String message = (searchResults.size() / 3) + " matches found.";\r
+ String message = (searchResults.getSize()) + " matches found.";\r
System.out.println(message);\r
}\r
\r
\r
AlignViewport av;\r
\r
- boolean displaySearch = false;\r
- int[] searchResults = null;\r
+ SearchResults searchResults = null;\r
\r
int chunkHeight;\r
int chunkWidth;\r
(i - starty) * av.charHeight,\r
av.charWidth, av.charHeight);\r
}\r
+ /// Highlight search Results once all sequences have been drawn\r
+ //////////////////////////////////////////////////////////\r
+ if (searchResults != null)\r
+ {\r
+ int[] visibleResults = searchResults.getResults(nextSeq, x1, x2);\r
+ if (visibleResults != null)\r
+ for (int r = 0; r < visibleResults.length; r += 2)\r
+ {\r
+ sr.drawHighlightedText(nextSeq, visibleResults[r],\r
+ visibleResults[r + 1],\r
+ (visibleResults[r] - startx) * av.charWidth,\r
+ offset + ( (i - starty) * av.charHeight),\r
+ av.charWidth, av.charHeight);\r
+ }\r
+ }\r
}\r
\r
/////////////////////////////////////\r
}\r
while (groupIndex < groups.size());\r
}\r
-\r
- /// Highlight search Results once all sequences have been drawn\r
- //////////////////////////////////////////////////////////\r
- if (displaySearch)\r
- {\r
- for (int r = 0; r < searchResults.length; r += 3)\r
- {\r
- int searchSeq = searchResults[r];\r
-\r
- if (searchSeq >= y1 && searchSeq < y2)\r
- {\r
- SequenceI seq = av.getAlignment().getSequenceAt(searchSeq);\r
-\r
- int searchStart = seq.findIndex(searchResults[r + 1]) - 1;\r
- int searchEnd = seq.findIndex(searchResults[r + 2]) - 1;\r
-\r
- SequenceRenderer ssr = (SequenceRenderer) sr;\r
- if (searchStart < x1)\r
- {\r
- searchStart = x1;\r
- }\r
- if (searchEnd > x2)\r
- {\r
- searchEnd = x2;\r
- }\r
-\r
- ssr.drawHighlightedText(seq,\r
- searchStart,\r
- searchEnd,\r
- (searchStart - startx) * av.charWidth,\r
- offset +\r
- (searchSeq-starty)*av.charHeight,\r
- av.charWidth,\r
- av.charHeight);\r
- }\r
- }\r
- }\r
-\r
}\r
\r
- public void highlightSearchResults(int[] results)\r
+ public void highlightSearchResults(SearchResults results)\r
{\r
- // results are in the order sequence, startRes, endRes\r
- if (results == null)\r
- {\r
- displaySearch = false;\r
- }\r
- else\r
- {\r
- displaySearch = true;\r
- }\r
-\r
searchResults = results;\r
\r
repaint();\r
--- /dev/null
+/*\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
+ */\r
+package jalview.datamodel;\r
+\r
+public class SearchResults\r
+{\r
+\r
+ Match [] matches;\r
+\r
+ /**\r
+ * This method replaces the old search results which merely\r
+ * held an alignment index of search matches. This broke\r
+ * when sequences were moved around the alignment\r
+ * @param seq Sequence\r
+ * @param start int\r
+ * @param end int\r
+ */\r
+ public void addResult(SequenceI seq, int start, int end)\r
+ {\r
+ if(matches == null)\r
+ {\r
+ matches = new Match[]{new Match(seq, start, end)};\r
+ return;\r
+ }\r
+\r
+ int mSize = matches.length;\r
+\r
+ Match [] tmp = new Match[mSize+1];\r
+ int m;\r
+ for(m=0; m<mSize; m++)\r
+ {\r
+ tmp[m] = matches[m];\r
+ }\r
+\r
+ tmp[m] = new Match(seq, start, end);\r
+\r
+ matches = tmp;\r
+ }\r
+\r
+ /**\r
+ * This Method returns the search matches which lie between the\r
+ * start and end points of the sequence in question. It is\r
+ * optimised for returning objects for drawing on SequenceCanvas\r
+ */\r
+ public int [] getResults(SequenceI sequence, int start, int end)\r
+ {\r
+ if(matches==null)\r
+ return null;\r
+\r
+ int [] result = null;\r
+ int [] tmp = null;\r
+ int resultLength;\r
+\r
+ for(int m=0; m<matches.length; m++)\r
+ {\r
+ if( matches[m].sequence == sequence )\r
+ {\r
+ int matchStart = matches[m].sequence.findIndex( matches[m].start ) - 1;\r
+ int matchEnd = matches[m].sequence.findIndex( matches[m].end ) - 1;\r
+\r
+ if(matchStart<=end && matchEnd>=start)\r
+ {\r
+ if(matchStart<start)\r
+ matchStart = start;\r
+\r
+ if(matchEnd>end)\r
+ matchEnd = end;\r
+\r
+\r
+ if(result==null)\r
+ result = new int[]{matchStart, matchEnd};\r
+ else\r
+ {\r
+ resultLength = result.length;\r
+ tmp = new int[resultLength+2];\r
+ System.arraycopy(result,0,tmp,0,resultLength);\r
+ result = tmp;\r
+ result[resultLength] = matchStart;\r
+ result[resultLength+1] = matchEnd;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ return result;\r
+ }\r
+\r
+ public int getSize()\r
+ {\r
+ return matches==null ? 0 : matches.length;\r
+ }\r
+\r
+ public SequenceI getResultSequence(int index)\r
+ { return matches[index].sequence; }\r
+\r
+ public int getResultStart(int index)\r
+ { return matches[index].start; }\r
+\r
+ public int getResultEnd(int index)\r
+ { return matches[index].end; }\r
+\r
+ class Match\r
+ {\r
+ SequenceI sequence;\r
+ int start;\r
+ int end;\r
+\r
+ public Match(SequenceI seq, int start, int end)\r
+ {\r
+ sequence = seq;\r
+ this.start = start;\r
+ this.end = end;\r
+ }\r
+ }\r
+}\r
viewport.getColumnSelection().clear();\r
viewport.setSelectionGroup(null);\r
alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);\r
+ alignPanel.idPanel.idCanvas.searchResults = null;\r
alignPanel.annotationPanel.activeRes = null;\r
PaintRefresher.Refresh(null, viewport.alignment);\r
}\r
*\r
* @param results DOCUMENT ME!\r
*/\r
- public void highlightSearchResults(int[] results)\r
+ public void highlightSearchResults(SearchResults results)\r
{\r
seqPanel.seqCanvas.highlightSearchResults(results);\r
\r
// do we need to scroll the panel?\r
if (results != null)\r
{\r
- SequenceI seq = av.alignment.getSequenceAt(results[0]);\r
- int start = seq.findIndex(results[1]) - 1;\r
- int end = seq.findIndex(results[2]) - 1;\r
+ SequenceI seq = results.getResultSequence(0);\r
+ int seqIndex = av.alignment.findIndex(seq);\r
+ int start = seq.findIndex(results.getResultStart(0)) - 1;\r
+ int end = seq.findIndex(results.getResultEnd(0)) - 1;\r
\r
if(!av.wrapAlignment)\r
{\r
- if ( (av.getStartRes() > start) || (av.getEndRes() < end) ||\r
- ( (av.getStartSeq() > results[0]) ||\r
- (av.getEndSeq() < results[0])))\r
+ if ( (av.getStartRes() > end) || (av.getEndRes() < start) ||\r
+ ( (av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex)))\r
{\r
- setScrollValues(start, results[0]);\r
+ setScrollValues(start, seqIndex);\r
}\r
}\r
else\r
if( start<av.getStartRes() || start>(av.getStartRes()+cwidth) )\r
{\r
vscroll.setValue(start / cwidth);\r
+ av.startRes = vscroll.getValue() * cwidth;\r
}\r
}\r
}\r
AlignmentPanel ap;\r
JInternalFrame frame;\r
SuperGroup searchGroup;\r
- Vector searchResults;\r
int seqIndex = 0;\r
int resIndex = 0;\r
\r
+ SearchResults searchResults;\r
+\r
/**\r
* Creates a new Finder object.\r
*\r
}\r
});\r
}\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param evt DOCUMENT ME!\r
- */\r
- public void internalFrameClosing(InternalFrameEvent evt)\r
- {\r
- cancel_actionPerformed(null);\r
- }\r
});\r
}\r
\r
doSearch(true);\r
}\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void cancel_actionPerformed(ActionEvent e)\r
- {\r
- try\r
- {\r
- // if allResults is null, this effectively switches displaySearch flag in seqCanvas\r
- ap.highlightSearchResults(null);\r
- ap.idPanel.highlightSearchResults(null);\r
-\r
- // frame.setClosed(true);\r
- }\r
- catch (Exception ex)\r
- {\r
- }\r
- }\r
\r
/**\r
* DOCUMENT ME!\r
\r
searchGroup = new SuperGroup(searchString, ucs, true, true, false);\r
\r
- for (int i = 0; i < searchResults.size(); i += 3)\r
+ for (int i = 0; i < searchResults.getSize(); i ++ )\r
{\r
// its possible edits may have occurred since search was performed\r
// account for this here\r
- SequenceI seq = av.alignment.getSequenceAt(Integer.parseInt(\r
- searchResults.elementAt(i).toString()));\r
- int startRes = seq.findIndex(Integer.parseInt(\r
- searchResults.elementAt(i + 1).toString())) - 1;\r
- int endRes = seq.findIndex(Integer.parseInt(\r
- searchResults.elementAt(i + 2).toString())) - 1;\r
+ SequenceI seq = searchResults.getResultSequence(i);\r
+ int startRes = seq.findIndex(searchResults.getResultStart(i)) - 1;\r
+ int endRes = seq.findIndex(searchResults.getResultEnd(i)) - 1;\r
\r
SequenceGroup sg = new SequenceGroup(searchString, ucs, true, true,\r
false, startRes, endRes);\r
\r
com.stevesoft.pat.Regex regex = new com.stevesoft.pat.Regex(searchString);\r
\r
- searchResults = new Vector();\r
-\r
- int[] allResults = null;\r
+ searchResults = new SearchResults();\r
\r
Sequence seq;\r
String item = null;\r
seq = (Sequence) (av.getSelectionGroup().getSequenceAt(0));\r
}\r
\r
- searchResults.add(Integer.toString(av.getAlignment().findIndex(seq)));\r
- searchResults.add(res+"");\r
- searchResults.add(res+"");\r
+ searchResults.addResult(seq, res, res);\r
}\r
catch (NumberFormatException ex)\r
{\r
item = seq.getSequence().toUpperCase();\r
\r
if ((selection != null) &&\r
- (selection.getEndRes() < av.alignment.getWidth()))\r
+ (selection.getEndRes() < av.alignment.getWidth()-1))\r
{\r
item = item.substring(0, selection.getEndRes() + 1);\r
}\r
continue;\r
}\r
\r
- searchResults.add(Integer.toString(seqIndex));\r
\r
int sres = seq.findPosition(resIndex +\r
Integer.parseInt(spaces.elementAt(resIndex)\r
Integer.parseInt(spaces.elementAt(regex.matchedTo() -\r
1).toString()));\r
\r
- searchResults.addElement(sres + "");\r
- searchResults.addElement(eres + "");\r
+ searchResults.addResult(seq, sres, eres);\r
\r
if (!findAll)\r
{\r
}\r
}\r
\r
- if ((searchResults.size() == 0) && (idMatch.size() > 0))\r
+ if ((searchResults.getSize() == 0) && (idMatch.size() > 0))\r
{\r
ap.idPanel.highlightSearchResults(idMatch);\r
}\r
\r
- if (searchResults.size() > 0)\r
- {\r
- allResults = new int[searchResults.size()];\r
\r
- for (int i = 0; i < searchResults.size(); i++)\r
- {\r
- allResults[i] = Integer.parseInt(searchResults.get(i).toString());\r
- }\r
+ int resultSize = searchResults.getSize();\r
\r
- createNewGroup.setEnabled(true);\r
- }\r
+ if (searchResults.getSize() > 0)\r
+ createNewGroup.setEnabled(true);\r
else\r
+ searchResults = null;\r
+\r
+ // if allResults is null, this effectively switches displaySearch flag in seqCanvas\r
+ ap.highlightSearchResults(searchResults);\r
+\r
+ if(!findAll && resultSize==0)\r
{\r
JOptionPane.showInternalMessageDialog(this, "Finished searching",\r
null, JOptionPane.INFORMATION_MESSAGE);\r
seqIndex = 0;\r
}\r
\r
- // if allResults is null, this effectively switches displaySearch flag in seqCanvas\r
- ap.highlightSearchResults(allResults);\r
-\r
if (findAll)\r
{\r
- String message = (searchResults.size() / 3) + " matches found.";\r
- JOptionPane.showInternalMessageDialog(this, message, null,\r
- JOptionPane.INFORMATION_MESSAGE);\r
+ String message = resultSize + " matches found.";\r
+ JOptionPane.showInternalMessageDialog(this, message, null,\r
+ JOptionPane.INFORMATION_MESSAGE);\r
}\r
+\r
}\r
}\r
int imgWidth;\r
int imgHeight;\r
AlignViewport av;\r
- boolean displaySearch = false;\r
- int[] searchResults = null;\r
+ SearchResults searchResults = null;\r
boolean fastPaint = false;\r
int LABEL_WEST;\r
int LABEL_EAST;\r
offset + ((i - starty) * av.charHeight), av.charWidth,\r
av.charHeight);\r
}\r
- }\r
+\r
+ /// Highlight search Results once all sequences have been drawn\r
+ //////////////////////////////////////////////////////////\r
+ if (searchResults != null)\r
+ {\r
+ int[] visibleResults = searchResults.getResults(nextSeq, x1, x2);\r
+ if (visibleResults != null)\r
+ for (int r = 0; r < visibleResults.length; r += 2)\r
+ {\r
+ sr.drawHighlightedText(nextSeq, visibleResults[r],\r
+ visibleResults[r + 1],\r
+ (visibleResults[r] - startx) * av.charWidth,\r
+ offset + ( (i - starty) * av.charHeight),\r
+ av.charWidth, av.charHeight);\r
+ }\r
+ }\r
+ }\r
\r
//\r
/////////////////////////////////////\r
}\r
while (groupIndex < av.alignment.getGroups().size());\r
}\r
-\r
- /// Highlight search Results once all sequences have been drawn\r
- //////////////////////////////////////////////////////////\r
- if (displaySearch)\r
- {\r
- for (int r = 0; r < searchResults.length; r += 3)\r
- {\r
- int searchSeq = searchResults[r];\r
-\r
- if ((searchSeq >= y1) && (searchSeq < y2))\r
- {\r
- SequenceI seq = av.getAlignment().getSequenceAt(searchSeq);\r
-\r
- int searchStart = seq.findIndex(searchResults[r + 1]) - 1;\r
- int searchEnd = seq.findIndex(searchResults[r + 2]) - 1;\r
-\r
- SequenceRenderer ssr = (SequenceRenderer) sr;\r
-\r
- if (searchStart < x1)\r
- {\r
- searchStart = x1;\r
- }\r
-\r
- if (searchEnd > x2)\r
- {\r
- searchEnd = x2;\r
- }\r
-\r
- ssr.drawHighlightedText(seq, searchStart, searchEnd,\r
- (searchStart - startx) * av.charWidth,\r
- offset + ((searchSeq - starty) * av.charHeight),\r
- av.charWidth, av.charHeight);\r
- }\r
- }\r
- }\r
}\r
\r
/**\r
*\r
* @param results DOCUMENT ME!\r
*/\r
- public void highlightSearchResults(int[] results)\r
+ public void highlightSearchResults(SearchResults results)\r
{\r
- // results are in the order sequence, startRes, endRes\r
- if (results == null)\r
- {\r
- displaySearch = false;\r
- }\r
- else\r
- {\r
- displaySearch = true;\r
- }\r
+ img = null;\r
\r
searchResults = results;\r
\r