X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FFinder.java;h=869755280b39292b96b631e045839322191e7cd1;hb=cc1cf5811cbf77dd7ee545be68eadd707eb26ff0;hp=1aceb80e734677eb339ee9ef8aa175d27ab08fc8;hpb=efc31b4a8d5cee63555586804a2b79c06bdb5a14;p=jalview.git diff --git a/src/jalview/gui/Finder.java b/src/jalview/gui/Finder.java index 1aceb80..8697552 100755 --- a/src/jalview/gui/Finder.java +++ b/src/jalview/gui/Finder.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -42,11 +42,11 @@ public class Finder extends GFinder AlignViewport av; AlignmentPanel ap; JInternalFrame frame; - SuperGroup searchGroup; - Vector searchResults; int seqIndex = 0; int resIndex = 0; + SearchResults searchResults; + /** * Creates a new Finder object. * @@ -74,28 +74,9 @@ public class Finder extends GFinder } }); } - - /** - * DOCUMENT ME! - * - * @param evt DOCUMENT ME! - */ - public void internalFrameClosing(InternalFrameEvent evt) - { - cancel_actionPerformed(null); - } }); } - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void textfield_actionPerformed(ActionEvent e) - { - doSearch(false); - } /** * DOCUMENT ME! @@ -119,25 +100,6 @@ public class Finder extends GFinder doSearch(true); } - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void cancel_actionPerformed(ActionEvent e) - { - try - { - // if allResults is null, this effectively switches displaySearch flag in seqCanvas - ap.highlightSearchResults(null); - ap.idPanel.highlightSearchResults(null); - - // frame.setClosed(true); - } - catch (Exception ex) - { - } - } /** * DOCUMENT ME! @@ -146,38 +108,35 @@ public class Finder extends GFinder */ public void createNewGroup_actionPerformed(ActionEvent e) { - Color[] newColors = new Color[24]; + JLabel label = new JLabel("Enter name of new sequence feature"); + JTextField textinput = new JTextField(textfield.getText()); + JPanel panel = new JPanel(new BorderLayout()); + panel.add(label, BorderLayout.NORTH); + panel.add(textinput, BorderLayout.SOUTH); - for (int i = 0; i < 24; i++) - { - newColors[i] = new Color(60, 160, 115); - } - jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(newColors); - String searchString = textfield.getText(); + SequenceI [] seqs = new SequenceI[searchResults.getSize()]; + SequenceFeature [] features = new SequenceFeature[searchResults.getSize()]; - searchGroup = new SuperGroup(searchString, ucs, true, true, false); - for (int i = 0; i < searchResults.size(); i += 3) + for (int i = 0; i < searchResults.getSize(); i ++ ) { - // its possible edits may have occurred since search was performed - // account for this here - SequenceI seq = av.alignment.getSequenceAt(Integer.parseInt( - searchResults.elementAt(i).toString())); - int startRes = seq.findIndex(Integer.parseInt( - searchResults.elementAt(i + 1).toString())) - 1; - int endRes = seq.findIndex(Integer.parseInt( - searchResults.elementAt(i + 2).toString())) - 1; - - SequenceGroup sg = new SequenceGroup(searchString, ucs, true, true, - false, startRes, endRes); - sg.addSequence(seq, false); - av.alignment.addGroup(sg); - searchGroup.addGroup(sg); + seqs[i] = searchResults.getResultSequence(i).getDatasetSequence(); + + features[i] = new SequenceFeature(textinput.getText(), + "Search Results", null, + searchResults.getResultStart(i), + searchResults.getResultEnd(i), + "Search Results"); } - ap.av.alignment.addSuperGroup(searchGroup); - ap.highlightSearchResults(null); + if( ap.seqPanel.seqCanvas.getFeatureRenderer() + .createNewFeatures(seqs, features)) + { + ap.alignFrame.showSeqFeatures.setSelected(true); + av.setShowSequenceFeatures(true); + ap.highlightSearchResults(null); + } } /** @@ -189,13 +148,16 @@ public class Finder extends GFinder { createNewGroup.setEnabled(false); - String searchString = textfield.getText().toUpperCase(); + String searchString = textfield.getText().trim(); + if(!caseSensitive.isSelected()) + searchString = searchString.toUpperCase(); - com.stevesoft.pat.Regex regex = new com.stevesoft.pat.Regex(searchString); + if(searchString.length()<1) + return; - searchResults = new Vector(); + com.stevesoft.pat.Regex regex = new com.stevesoft.pat.Regex(searchString); - int[] allResults = null; + searchResults = new SearchResults(); Sequence seq; String item = null; @@ -206,35 +168,22 @@ public class Finder extends GFinder { int res = Integer.parseInt(searchString); found = true; - - if (av.getSelectionGroup().getSize() > 0) + if (av.getSelectionGroup() == null || av.getSelectionGroup().getSize(false) < 1) { - seq = (Sequence) (av.getSelectionGroup().getSequenceAt(0)); + seq = (Sequence) av.getAlignment().getSequenceAt(0); } else { - seq = (Sequence) av.getAlignment().getSequenceAt(0); + seq = (Sequence) (av.getSelectionGroup().getSequenceAt(0)); } - searchResults.add(Integer.toString(av.getAlignment().findIndex(seq))); - searchResults.add(Integer.toString(seq.findIndex(res) - 1)); - searchResults.add(Integer.toString(seq.findIndex(res) - 1)); + searchResults.addResult(seq, res, res); } catch (NumberFormatException ex) { } /////////////////////////////////////////////// - Color[] newColors = new Color[24]; - - for (int i = 0; i < 24; i++) - { - newColors[i] = new Color(60, 160, 115); - } - - jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(newColors); - - searchGroup = new SuperGroup(searchString, ucs, true, true, false); int end = av.alignment.getHeight(); @@ -242,7 +191,7 @@ public class Finder extends GFinder if (selection != null) { - if ((selection.getSize() < 1) || + if ((selection.getSize(false) < 1) || ((selection.getEndRes() - selection.getStartRes()) < 2)) { selection = null; @@ -253,7 +202,7 @@ public class Finder extends GFinder { seq = (Sequence) av.alignment.getSequenceAt(seqIndex); - if ((selection != null) && !selection.sequences.contains(seq)) + if ((selection != null) && !selection.getSequences(false).contains(seq)) { seqIndex++; resIndex = 0; @@ -261,16 +210,18 @@ public class Finder extends GFinder continue; } - item = seq.getSequence().toUpperCase(); + item = seq.getSequence(); + if(!caseSensitive.isSelected()) + item = item.toUpperCase(); if ((selection != null) && - (selection.getEndRes() < av.alignment.getWidth())) + (selection.getEndRes() < av.alignment.getWidth()-1)) { item = item.substring(0, selection.getEndRes() + 1); } ///Shall we ignore gaps???? - StringBuffer noGaps = new StringBuffer(); + StringBuffer noGapsSB = new StringBuffer(); int insertCount = 0; Vector spaces = new Vector(); @@ -278,7 +229,7 @@ public class Finder extends GFinder { if (!jalview.util.Comparison.isGap(item.charAt(j))) { - noGaps.append(item.charAt(j)); + noGapsSB.append(item.charAt(j)); spaces.add(new Integer(insertCount)); } else @@ -287,9 +238,12 @@ public class Finder extends GFinder } } + String noGaps = noGapsSB.toString(); + for (int r = resIndex; r < noGaps.length(); r++) { - if (regex.searchFrom(noGaps.toString(), r)) + + if (regex.searchFrom(noGaps, r)) { resIndex = regex.matchedFrom(); @@ -300,7 +254,6 @@ public class Finder extends GFinder continue; } - searchResults.add(Integer.toString(seqIndex)); int sres = seq.findPosition(resIndex + Integer.parseInt(spaces.elementAt(resIndex) @@ -309,8 +262,7 @@ public class Finder extends GFinder Integer.parseInt(spaces.elementAt(regex.matchedTo() - 1).toString())); - searchResults.addElement(sres + ""); - searchResults.addElement(eres + ""); + searchResults.addResult(seq, sres, eres); if (!findAll) { @@ -323,6 +275,10 @@ public class Finder extends GFinder r = resIndex; } + else + { + break; + } } if (!found) @@ -342,23 +298,23 @@ public class Finder extends GFinder } } - if ((searchResults.size() == 0) && (idMatch.size() > 0)) + if ((searchResults.getSize() == 0) && (idMatch.size() > 0)) { ap.idPanel.highlightSearchResults(idMatch); } - if (searchResults.size() > 0) - { - allResults = new int[searchResults.size()]; - for (int i = 0; i < searchResults.size(); i++) - { - allResults[i] = Integer.parseInt(searchResults.get(i).toString()); - } + int resultSize = searchResults.getSize(); - createNewGroup.setEnabled(true); - } + if (searchResults.getSize() > 0) + createNewGroup.setEnabled(true); else + searchResults = null; + + // if allResults is null, this effectively switches displaySearch flag in seqCanvas + ap.highlightSearchResults(searchResults); + + if(!findAll && resultSize==0) { JOptionPane.showInternalMessageDialog(this, "Finished searching", null, JOptionPane.INFORMATION_MESSAGE); @@ -366,14 +322,12 @@ public class Finder extends GFinder seqIndex = 0; } - // if allResults is null, this effectively switches displaySearch flag in seqCanvas - ap.highlightSearchResults(allResults); - if (findAll) { - String message = (searchResults.size() / 3) + " matches found."; - JOptionPane.showInternalMessageDialog(this, message, null, - JOptionPane.INFORMATION_MESSAGE); + String message = resultSize + " matches found."; + JOptionPane.showInternalMessageDialog(this, message, null, + JOptionPane.INFORMATION_MESSAGE); } + } }