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