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