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