Use visible id for sorting
[jalview.git] / src / jalview / jbgui / GFinder.java
1 /*\r
2  * Jalview - A Sequence Alignment Editor and Viewer\r
3  * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4  *\r
5  * This program is free software; you can redistribute it and/or\r
6  * modify it under the terms of the GNU General Public License\r
7  * as published by the Free Software Foundation; either version 2\r
8  * of the License, or (at your option) any later version.\r
9  *\r
10  * This program is distributed in the hope that it will be useful,\r
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13  * GNU General Public License for more details.\r
14  *\r
15  * You should have received a copy of the GNU General Public License\r
16  * along with this program; if not, write to the Free Software\r
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
18  */\r
19 package jalview.jbgui;\r
20 \r
21 import java.awt.*;\r
22 import java.awt.event.*;\r
23 import javax.swing.*;\r
24 import javax.swing.event.*;\r
25 import jalview.io.FormatAdapter;\r
26 import jalview.datamodel.SequenceI;\r
27 \r
28 public class GFinder\r
29     extends JPanel\r
30 {\r
31   JLabel jLabel1 = new JLabel();\r
32   protected JButton findAll = new JButton();\r
33   protected JButton findNext = new JButton();\r
34   JPanel jPanel1 = new JPanel();\r
35   GridLayout gridLayout1 = new GridLayout();\r
36   protected JButton createNewGroup = new JButton();\r
37   JScrollPane jScrollPane1 = new JScrollPane();\r
38   protected JTextArea textfield = new JTextArea();\r
39   BorderLayout borderLayout1 = new BorderLayout();\r
40   JPanel jPanel2 = new JPanel();\r
41   JPanel jPanel3 = new JPanel();\r
42   JPanel jPanel4 = new JPanel();\r
43   BorderLayout borderLayout2 = new BorderLayout();\r
44   JPanel jPanel5 = new JPanel();\r
45   JPanel jPanel6 = new JPanel();\r
46   public GFinder()\r
47   {\r
48     try\r
49     {\r
50       jbInit();\r
51     }\r
52     catch (Exception e)\r
53     {\r
54       e.printStackTrace();\r
55     }\r
56   }\r
57 \r
58   private void jbInit()\r
59       throws Exception\r
60   {\r
61     jLabel1.setFont(new java.awt.Font("Verdana", 0, 12));\r
62     jLabel1.setText("Find");\r
63     this.setLayout(borderLayout1);\r
64     findAll.setFont(new java.awt.Font("Verdana", 0, 12));\r
65     findAll.setText("Find all");\r
66     findAll.addActionListener(new java.awt.event.ActionListener()\r
67     {\r
68       public void actionPerformed(ActionEvent e)\r
69       {\r
70         findAll_actionPerformed(e);\r
71       }\r
72     });\r
73     findNext.setEnabled(false);\r
74     findNext.setFont(new java.awt.Font("Verdana", 0, 12));\r
75     findNext.setText("Find Next");\r
76     findNext.addActionListener(new java.awt.event.ActionListener()\r
77     {\r
78       public void actionPerformed(ActionEvent e)\r
79       {\r
80         findNext_actionPerformed(e);\r
81       }\r
82     });\r
83     jPanel1.setLayout(gridLayout1);\r
84     gridLayout1.setHgap(0);\r
85     gridLayout1.setRows(3);\r
86     gridLayout1.setVgap(2);\r
87     createNewGroup.setEnabled(false);\r
88     createNewGroup.setFont(new java.awt.Font("Verdana", 0, 12));\r
89     createNewGroup.setToolTipText("");\r
90     createNewGroup.setMargin(new Insets(0, 0, 0, 0));\r
91     createNewGroup.setText("Create new group");\r
92     createNewGroup.addActionListener(new java.awt.event.ActionListener()\r
93     {\r
94       public void actionPerformed(ActionEvent e)\r
95       {\r
96         createNewGroup_actionPerformed(e);\r
97       }\r
98     });\r
99     textfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 12));\r
100     textfield.setText("");\r
101     textfield.setLineWrap(true);\r
102     textfield.addCaretListener(new CaretListener()\r
103     {\r
104       public void caretUpdate(CaretEvent e)\r
105       {\r
106         textfield_caretUpdate(e);\r
107       }\r
108     });\r
109     textfield.addKeyListener(new java.awt.event.KeyAdapter() {\r
110         public void keyPressed(KeyEvent e) {\r
111             textfield_keyPressed(e);\r
112         }\r
113     });\r
114 \r
115     borderLayout1.setHgap(5);\r
116     borderLayout1.setVgap(5);\r
117     jPanel4.setLayout(borderLayout2);\r
118     jPanel2.setPreferredSize(new Dimension(10, 1));\r
119     jPanel3.setPreferredSize(new Dimension(10, 1));\r
120     jPanel1.add(findNext, null);\r
121     jPanel1.add(findAll, null);\r
122     jPanel1.add(createNewGroup, null);\r
123     this.add(jLabel1, java.awt.BorderLayout.WEST);\r
124     this.add(jPanel1, java.awt.BorderLayout.EAST);\r
125     this.add(jPanel2, java.awt.BorderLayout.SOUTH);\r
126     this.add(jPanel3, java.awt.BorderLayout.NORTH);\r
127     this.add(jPanel4, java.awt.BorderLayout.CENTER);\r
128     jPanel4.add(jScrollPane1, java.awt.BorderLayout.CENTER);\r
129     jPanel4.add(jPanel5, java.awt.BorderLayout.SOUTH);\r
130     jPanel4.add(jPanel6, java.awt.BorderLayout.NORTH);\r
131     jScrollPane1.getViewport().add(textfield);\r
132   }\r
133 \r
134   protected void findNext_actionPerformed(ActionEvent e)\r
135   {\r
136   }\r
137 \r
138   protected void findAll_actionPerformed(ActionEvent e)\r
139   {\r
140   }\r
141 \r
142 \r
143   protected void textfield_keyPressed(KeyEvent e)\r
144   {\r
145 \r
146     if(e.getKeyCode()==KeyEvent.VK_ENTER)\r
147     {\r
148       e.consume();\r
149       findNext_actionPerformed(null);\r
150     }\r
151     findNext.setEnabled(true);\r
152   }\r
153 \r
154   public void createNewGroup_actionPerformed(ActionEvent e)\r
155   {\r
156   }\r
157 \r
158   public void textfield_caretUpdate(CaretEvent e)\r
159   {\r
160     if (textfield.getText().indexOf(">") > -1)\r
161     {\r
162       SwingUtilities.invokeLater(new Runnable()\r
163       {\r
164         public void run()\r
165         {\r
166           String str = textfield.getText();\r
167           SequenceI[] sequences = new FormatAdapter().readFile(str, "Paste", "FASTA");\r
168           if(sequences!=null && sequences.length>0)\r
169           {\r
170             str = jalview.analysis.AlignSeq.extractGaps(\r
171                 jalview.util.Comparison.GapChars, sequences[0].getSequence());\r
172 \r
173             textfield.setText(str);\r
174           }\r
175         }\r
176       });\r
177     }\r
178   }\r
179 }\r