elementAt instead of get for 1.1 compatibility
[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 import java.awt.BorderLayout;\r
28 \r
29 public class GFinder\r
30     extends JPanel\r
31 {\r
32   JLabel jLabel1 = new JLabel();\r
33   protected JButton findAll = new JButton();\r
34   protected JButton findNext = new JButton();\r
35   JPanel jPanel1 = new JPanel();\r
36   GridLayout gridLayout1 = new GridLayout();\r
37   protected JButton createNewGroup = new JButton();\r
38   JScrollPane jScrollPane1 = new JScrollPane();\r
39   protected JTextArea textfield = new JTextArea();\r
40   BorderLayout borderLayout1 = new BorderLayout();\r
41   JPanel jPanel2 = new JPanel();\r
42   JPanel jPanel3 = new JPanel();\r
43   JPanel jPanel4 = new JPanel();\r
44   BorderLayout borderLayout2 = new BorderLayout();\r
45   JPanel jPanel6 = new JPanel();\r
46   protected JCheckBox caseSensitive = new JCheckBox();\r
47   public GFinder()\r
48   {\r
49     try\r
50     {\r
51       jbInit();\r
52     }\r
53     catch (Exception e)\r
54     {\r
55       e.printStackTrace();\r
56     }\r
57   }\r
58 \r
59   private void jbInit()\r
60       throws Exception\r
61   {\r
62     jLabel1.setFont(new java.awt.Font("Verdana", 0, 12));\r
63     jLabel1.setText("Find");\r
64     this.setLayout(borderLayout1);\r
65     findAll.setFont(new java.awt.Font("Verdana", 0, 12));\r
66     findAll.setText("Find all");\r
67     findAll.addActionListener(new java.awt.event.ActionListener()\r
68     {\r
69       public void actionPerformed(ActionEvent e)\r
70       {\r
71         findAll_actionPerformed(e);\r
72       }\r
73     });\r
74     findNext.setEnabled(false);\r
75     findNext.setFont(new java.awt.Font("Verdana", 0, 12));\r
76     findNext.setText("Find Next");\r
77     findNext.addActionListener(new java.awt.event.ActionListener()\r
78     {\r
79       public void actionPerformed(ActionEvent e)\r
80       {\r
81         findNext_actionPerformed(e);\r
82       }\r
83     });\r
84     jPanel1.setLayout(gridLayout1);\r
85     gridLayout1.setHgap(0);\r
86     gridLayout1.setRows(3);\r
87     gridLayout1.setVgap(2);\r
88     createNewGroup.setEnabled(false);\r
89     createNewGroup.setFont(new java.awt.Font("Verdana", 0, 12));\r
90     createNewGroup.setToolTipText("");\r
91     createNewGroup.setMargin(new Insets(0, 0, 0, 0));\r
92     createNewGroup.setText("New Feature");\r
93     createNewGroup.addActionListener(new java.awt.event.ActionListener()\r
94     {\r
95       public void actionPerformed(ActionEvent e)\r
96       {\r
97         createNewGroup_actionPerformed(e);\r
98       }\r
99     });\r
100     textfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 12));\r
101     textfield.setText("");\r
102     textfield.setLineWrap(true);\r
103     textfield.addCaretListener(new CaretListener()\r
104     {\r
105       public void caretUpdate(CaretEvent e)\r
106       {\r
107         textfield_caretUpdate(e);\r
108       }\r
109     });\r
110     textfield.addKeyListener(new java.awt.event.KeyAdapter() {\r
111         public void keyPressed(KeyEvent e) {\r
112             textfield_keyPressed(e);\r
113         }\r
114     });\r
115 \r
116     borderLayout1.setHgap(5);\r
117     borderLayout1.setVgap(5);\r
118     jPanel4.setLayout(borderLayout2);\r
119     jPanel2.setPreferredSize(new Dimension(10, 1));\r
120     jPanel3.setPreferredSize(new Dimension(10, 1));\r
121     caseSensitive.setHorizontalAlignment(SwingConstants.LEFT);\r
122     caseSensitive.setText("Match Case");\r
123     jPanel1.add(findNext, null);\r
124     jPanel1.add(findAll, null);\r
125     jPanel1.add(createNewGroup, null);\r
126     this.add(jLabel1, java.awt.BorderLayout.WEST);\r
127     this.add(jPanel1, java.awt.BorderLayout.EAST);\r
128     this.add(jPanel2, java.awt.BorderLayout.SOUTH);\r
129     this.add(jPanel3, java.awt.BorderLayout.NORTH);\r
130     this.add(jPanel4, java.awt.BorderLayout.CENTER);\r
131     jPanel4.add(jScrollPane1, java.awt.BorderLayout.CENTER);\r
132     jScrollPane1.getViewport().add(textfield);\r
133     jPanel4.add(jPanel6, java.awt.BorderLayout.NORTH);\r
134     jPanel4.add(caseSensitive, java.awt.BorderLayout.SOUTH);\r
135   }\r
136 \r
137   protected void findNext_actionPerformed(ActionEvent e)\r
138   {\r
139   }\r
140 \r
141   protected void findAll_actionPerformed(ActionEvent e)\r
142   {\r
143   }\r
144 \r
145 \r
146   protected void textfield_keyPressed(KeyEvent e)\r
147   {\r
148 \r
149     if(e.getKeyCode()==KeyEvent.VK_ENTER)\r
150     {\r
151       e.consume();\r
152       findNext_actionPerformed(null);\r
153     }\r
154     findNext.setEnabled(true);\r
155   }\r
156 \r
157   public void createNewGroup_actionPerformed(ActionEvent e)\r
158   {\r
159   }\r
160 \r
161   public void textfield_caretUpdate(CaretEvent e)\r
162   {\r
163     if (textfield.getText().indexOf(">") > -1)\r
164     {\r
165       SwingUtilities.invokeLater(new Runnable()\r
166       {\r
167         public void run()\r
168         {\r
169           String str = textfield.getText();\r
170           SequenceI[] sequences = null;\r
171           try{sequences = new FormatAdapter().readFile(str, "Paste", "FASTA");}\r
172           catch(Exception ex){}\r
173           if(sequences!=null && sequences.length>0)\r
174           {\r
175             str = jalview.analysis.AlignSeq.extractGaps(\r
176                 jalview.util.Comparison.GapChars, sequences[0].getSequence());\r
177 \r
178             textfield.setText(str);\r
179           }\r
180         }\r
181       });\r
182     }\r
183   }\r
184 }\r