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