JAL-1503 update version in GPL header
[jalview.git] / src / jalview / jbgui / GFinder.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
3  * Copyright (C) 2014 The Jalview Authors
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  * The Jalview Authors are detailed in the 'AUTHORS' file.
18  */
19 package jalview.jbgui;
20
21 import java.awt.*;
22 import java.awt.event.*;
23 import javax.swing.*;
24 import javax.swing.event.*;
25
26 import jalview.datamodel.*;
27 import jalview.io.*;
28 import jalview.util.MessageManager;
29
30 public class GFinder extends JPanel
31 {
32   JLabel jLabel1 = new JLabel();
33
34   protected JButton findAll = new JButton();
35
36   protected JButton findNext = new JButton();
37
38   JPanel jPanel1 = new JPanel();
39
40   GridLayout gridLayout1 = new GridLayout();
41
42   protected JButton createNewGroup = new JButton();
43
44   JScrollPane jScrollPane1 = new JScrollPane();
45
46   protected JTextArea textfield = new JTextArea();
47
48   BorderLayout borderLayout1 = new BorderLayout();
49
50   JPanel jPanel2 = new JPanel();
51
52   JPanel jPanel3 = new JPanel();
53
54   JPanel jPanel4 = new JPanel();
55
56   BorderLayout borderLayout2 = new BorderLayout();
57
58   JPanel jPanel6 = new JPanel();
59
60   protected JCheckBox caseSensitive = new JCheckBox();
61
62   public GFinder()
63   {
64     try
65     {
66       jbInit();
67     } catch (Exception e)
68     {
69       e.printStackTrace();
70     }
71   }
72
73   private void jbInit() throws Exception
74   {
75     jLabel1.setFont(new java.awt.Font("Verdana", 0, 12));
76     jLabel1.setText(MessageManager.getString("action.find"));
77     this.setLayout(borderLayout1);
78     findAll.setFont(new java.awt.Font("Verdana", 0, 12));
79     findAll.setText(MessageManager.getString("action.find_all"));
80     findAll.addActionListener(new java.awt.event.ActionListener()
81     {
82       public void actionPerformed(ActionEvent e)
83       {
84         findAll_actionPerformed(e);
85       }
86     });
87     findNext.setFont(new java.awt.Font("Verdana", 0, 12));
88     findNext.setText(MessageManager.getString("action.find_next"));
89     findNext.addActionListener(new java.awt.event.ActionListener()
90     {
91       public void actionPerformed(ActionEvent e)
92       {
93         findNext_actionPerformed(e);
94       }
95     });
96     jPanel1.setLayout(gridLayout1);
97     gridLayout1.setHgap(0);
98     gridLayout1.setRows(3);
99     gridLayout1.setVgap(2);
100     createNewGroup.setEnabled(false);
101     createNewGroup.setFont(new java.awt.Font("Verdana", 0, 12));
102     createNewGroup.setMargin(new Insets(0, 0, 0, 0));
103     createNewGroup.setText(MessageManager.getString("label.new_feature"));
104     createNewGroup.addActionListener(new java.awt.event.ActionListener()
105     {
106       public void actionPerformed(ActionEvent e)
107       {
108         createNewGroup_actionPerformed(e);
109       }
110     });
111     textfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 12));
112     textfield.setText("");
113     textfield.setLineWrap(true);
114     textfield.addCaretListener(new CaretListener()
115     {
116       public void caretUpdate(CaretEvent e)
117       {
118         textfield_caretUpdate(e);
119       }
120     });
121     textfield.addKeyListener(new java.awt.event.KeyAdapter()
122     {
123       public void keyPressed(KeyEvent e)
124       {
125         textfield_keyPressed(e);
126       }
127     });
128
129     borderLayout1.setHgap(5);
130     borderLayout1.setVgap(5);
131     jPanel4.setLayout(borderLayout2);
132     jPanel2.setPreferredSize(new Dimension(10, 1));
133     jPanel3.setPreferredSize(new Dimension(10, 1));
134     caseSensitive.setHorizontalAlignment(SwingConstants.LEFT);
135     caseSensitive.setText(MessageManager.getString("label.match_case"));
136     jPanel1.add(findNext, null);
137     jPanel1.add(findAll, null);
138     jPanel1.add(createNewGroup, null);
139     this.add(jLabel1, java.awt.BorderLayout.WEST);
140     this.add(jPanel1, java.awt.BorderLayout.EAST);
141     this.add(jPanel2, java.awt.BorderLayout.SOUTH);
142     this.add(jPanel3, java.awt.BorderLayout.NORTH);
143     this.add(jPanel4, java.awt.BorderLayout.CENTER);
144     jPanel4.add(jScrollPane1, java.awt.BorderLayout.CENTER);
145     jScrollPane1.getViewport().add(textfield);
146     jPanel4.add(jPanel6, java.awt.BorderLayout.NORTH);
147     jPanel4.add(caseSensitive, java.awt.BorderLayout.SOUTH);
148   }
149
150   protected void findNext_actionPerformed(ActionEvent e)
151   {
152   }
153
154   protected void findAll_actionPerformed(ActionEvent e)
155   {
156   }
157
158   protected void textfield_keyPressed(KeyEvent e)
159   {
160     if (e.getKeyCode() == KeyEvent.VK_ENTER)
161     {
162       e.consume();
163       findNext_actionPerformed(null);
164     }
165   }
166
167   public void createNewGroup_actionPerformed(ActionEvent e)
168   {
169   }
170
171   public void textfield_caretUpdate(CaretEvent e)
172   {
173     if (textfield.getText().indexOf(">") > -1)
174     {
175       SwingUtilities.invokeLater(new Runnable()
176       {
177         public void run()
178         {
179           String str = textfield.getText();
180           Alignment al = null;
181           try
182           {
183             al = new FormatAdapter().readFile(str, "Paste", "FASTA");
184           } catch (Exception ex)
185           {
186           }
187           if (al != null && al.getHeight() > 0)
188           {
189             str = jalview.analysis.AlignSeq.extractGaps(
190                     jalview.util.Comparison.GapChars, al.getSequenceAt(0)
191                             .getSequenceAsString());
192
193             textfield.setText(str);
194           }
195         }
196       });
197     }
198   }
199 }