2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.jbgui;
23 import jalview.datamodel.Alignment;
24 import jalview.io.FormatAdapter;
25 import jalview.util.MessageManager;
27 import java.awt.BorderLayout;
28 import java.awt.Dimension;
30 import java.awt.GridLayout;
31 import java.awt.Insets;
32 import java.awt.event.ActionEvent;
33 import java.awt.event.KeyEvent;
35 import javax.swing.JButton;
36 import javax.swing.JCheckBox;
37 import javax.swing.JLabel;
38 import javax.swing.JPanel;
39 import javax.swing.JScrollPane;
40 import javax.swing.JTextArea;
41 import javax.swing.SwingConstants;
42 import javax.swing.SwingUtilities;
43 import javax.swing.event.CaretEvent;
44 import javax.swing.event.CaretListener;
46 public class GFinder extends JPanel
48 JLabel jLabelFind = new JLabel();
50 protected JButton findAll = new JButton();
52 protected JButton findNext = new JButton();
54 JPanel actionsPanel = new JPanel();
56 GridLayout gridLayout1 = new GridLayout();
58 protected JButton createNewGroup = new JButton();
60 JScrollPane jScrollPane1 = new JScrollPane();
62 protected JTextArea textfield = new JTextArea();
64 BorderLayout mainBorderLayout = new BorderLayout();
66 JPanel jPanel2 = new JPanel();
68 JPanel jPanel3 = new JPanel();
70 JPanel jPanel4 = new JPanel();
72 BorderLayout borderLayout2 = new BorderLayout();
74 JPanel jPanel6 = new JPanel();
76 protected JCheckBox caseSensitive = new JCheckBox();
78 protected JCheckBox searchDescription = new JCheckBox();
80 GridLayout optionsGridLayout = new GridLayout();
94 private void jbInit() throws Exception
96 jLabelFind.setFont(new java.awt.Font("Verdana", 0, 12));
97 jLabelFind.setText(MessageManager.getString("label.find"));
98 this.setLayout(mainBorderLayout);
99 findAll.setFont(new java.awt.Font("Verdana", 0, 12));
100 findAll.setText(MessageManager.getString("action.find_all"));
101 findAll.addActionListener(new java.awt.event.ActionListener()
103 public void actionPerformed(ActionEvent e)
105 findAll_actionPerformed(e);
108 findNext.setFont(new java.awt.Font("Verdana", 0, 12));
109 findNext.setText(MessageManager.getString("action.find_next"));
110 findNext.addActionListener(new java.awt.event.ActionListener()
112 public void actionPerformed(ActionEvent e)
114 findNext_actionPerformed(e);
117 actionsPanel.setLayout(gridLayout1);
118 gridLayout1.setHgap(0);
119 gridLayout1.setRows(3);
120 gridLayout1.setVgap(2);
121 createNewGroup.setEnabled(false);
122 createNewGroup.setFont(new java.awt.Font("Verdana", 0, 12));
123 createNewGroup.setMargin(new Insets(0, 0, 0, 0));
124 createNewGroup.setText(MessageManager.getString("label.new_feature"));
125 createNewGroup.addActionListener(new java.awt.event.ActionListener()
127 public void actionPerformed(ActionEvent e)
129 createNewGroup_actionPerformed(e);
132 textfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 12));
133 textfield.setText("");
134 textfield.setLineWrap(true);
135 textfield.addCaretListener(new CaretListener()
137 public void caretUpdate(CaretEvent e)
139 textfield_caretUpdate(e);
142 textfield.addKeyListener(new java.awt.event.KeyAdapter()
144 public void keyPressed(KeyEvent e)
146 textfield_keyPressed(e);
150 mainBorderLayout.setHgap(5);
151 mainBorderLayout.setVgap(5);
152 jPanel4.setLayout(borderLayout2);
153 jPanel2.setPreferredSize(new Dimension(10, 1));
154 jPanel3.setPreferredSize(new Dimension(10, 1));
155 caseSensitive.setHorizontalAlignment(SwingConstants.LEFT);
156 caseSensitive.setText(MessageManager.getString("label.match_case"));
158 searchDescription.setText(MessageManager
159 .getString("label.include_description"));
161 actionsPanel.add(findNext, null);
162 actionsPanel.add(findAll, null);
163 actionsPanel.add(createNewGroup, null);
164 this.add(jLabelFind, java.awt.BorderLayout.WEST);
165 this.add(actionsPanel, java.awt.BorderLayout.EAST);
166 this.add(jPanel2, java.awt.BorderLayout.SOUTH);
167 this.add(jPanel3, java.awt.BorderLayout.NORTH);
168 this.add(jPanel4, java.awt.BorderLayout.CENTER);
169 jPanel4.add(jScrollPane1, java.awt.BorderLayout.NORTH);
170 jScrollPane1.getViewport().add(textfield);
172 JPanel optionsPanel = new JPanel();
174 optionsGridLayout.setHgap(0);
175 optionsGridLayout.setRows(2);
176 optionsGridLayout.setVgap(2);
177 optionsPanel.setLayout(optionsGridLayout);
178 optionsPanel.add(caseSensitive, null);
179 optionsPanel.add(searchDescription, null);
181 jPanel4.add(optionsPanel, java.awt.BorderLayout.WEST);
184 protected void findNext_actionPerformed(ActionEvent e)
188 protected void findAll_actionPerformed(ActionEvent e)
192 protected void textfield_keyPressed(KeyEvent e)
194 if (e.getKeyCode() == KeyEvent.VK_ENTER)
197 findNext_actionPerformed(null);
201 public void createNewGroup_actionPerformed(ActionEvent e)
205 public void textfield_caretUpdate(CaretEvent e)
207 if (textfield.getText().indexOf(">") > -1)
209 SwingUtilities.invokeLater(new Runnable()
213 String str = textfield.getText();
217 al = new FormatAdapter().readFile(str, "Paste", "FASTA");
218 } catch (Exception ex)
221 if (al != null && al.getHeight() > 0)
223 str = jalview.analysis.AlignSeq.extractGaps(
224 jalview.util.Comparison.GapChars, al.getSequenceAt(0)
225 .getSequenceAsString());
227 textfield.setText(str);