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.AlignmentI;
24 import jalview.io.DataSourceType;
25 import jalview.io.FileFormat;
26 import jalview.io.FormatAdapter;
27 import jalview.util.MessageManager;
29 import java.awt.BorderLayout;
30 import java.awt.Dimension;
32 import java.awt.GridLayout;
33 import java.awt.Insets;
34 import java.awt.event.ActionEvent;
35 import java.awt.event.KeyEvent;
37 import javax.swing.JButton;
38 import javax.swing.JCheckBox;
39 import javax.swing.JLabel;
40 import javax.swing.JPanel;
41 import javax.swing.JScrollPane;
42 import javax.swing.JTextArea;
43 import javax.swing.SwingConstants;
44 import javax.swing.SwingUtilities;
45 import javax.swing.event.CaretEvent;
46 import javax.swing.event.CaretListener;
48 public class GFinder extends JPanel
50 JLabel jLabelFind = new JLabel();
52 protected JButton findAll = new JButton();
54 protected JButton findNext = new JButton();
56 JPanel actionsPanel = new JPanel();
58 GridLayout gridLayout1 = new GridLayout();
60 protected JButton createNewGroup = new JButton();
62 JScrollPane jScrollPane1 = new JScrollPane();
64 protected JTextArea textfield = new JTextArea();
66 BorderLayout mainBorderLayout = new BorderLayout();
68 JPanel jPanel2 = new JPanel();
70 JPanel jPanel3 = new JPanel();
72 JPanel jPanel4 = new JPanel();
74 BorderLayout borderLayout2 = new BorderLayout();
76 JPanel jPanel6 = new JPanel();
78 protected JCheckBox caseSensitive = new JCheckBox();
80 protected JCheckBox searchDescription = new JCheckBox();
82 GridLayout optionsGridLayout = new GridLayout();
95 private void jbInit() throws Exception
97 jLabelFind.setFont(new java.awt.Font("Verdana", 0, 12));
98 jLabelFind.setText(MessageManager.getString("label.find"));
99 this.setLayout(mainBorderLayout);
100 findAll.setFont(new java.awt.Font("Verdana", 0, 12));
101 findAll.setText(MessageManager.getString("action.find_all"));
102 findAll.addActionListener(new java.awt.event.ActionListener()
105 public void actionPerformed(ActionEvent e)
107 findAll_actionPerformed(e);
110 findNext.setFont(new java.awt.Font("Verdana", 0, 12));
111 findNext.setText(MessageManager.getString("action.find_next"));
112 findNext.addActionListener(new java.awt.event.ActionListener()
115 public void actionPerformed(ActionEvent e)
117 findNext_actionPerformed(e);
120 actionsPanel.setLayout(gridLayout1);
121 gridLayout1.setHgap(0);
122 gridLayout1.setRows(3);
123 gridLayout1.setVgap(2);
124 createNewGroup.setEnabled(false);
125 createNewGroup.setFont(new java.awt.Font("Verdana", 0, 12));
126 createNewGroup.setMargin(new Insets(0, 0, 0, 0));
127 createNewGroup.setText(MessageManager.getString("label.new_feature"));
128 createNewGroup.addActionListener(new java.awt.event.ActionListener()
131 public void actionPerformed(ActionEvent e)
133 createNewGroup_actionPerformed(e);
136 textfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 12));
137 textfield.setText("");
138 textfield.setLineWrap(true);
139 textfield.addCaretListener(new CaretListener()
142 public void caretUpdate(CaretEvent e)
144 textfield_caretUpdate(e);
147 textfield.addKeyListener(new java.awt.event.KeyAdapter()
150 public void keyPressed(KeyEvent e)
152 textfield_keyPressed(e);
156 mainBorderLayout.setHgap(5);
157 mainBorderLayout.setVgap(5);
158 jPanel4.setLayout(borderLayout2);
159 jPanel2.setPreferredSize(new Dimension(10, 1));
160 jPanel3.setPreferredSize(new Dimension(10, 1));
161 caseSensitive.setHorizontalAlignment(SwingConstants.LEFT);
162 caseSensitive.setText(MessageManager.getString("label.match_case"));
164 searchDescription.setText(MessageManager
165 .getString("label.include_description"));
167 actionsPanel.add(findNext, null);
168 actionsPanel.add(findAll, null);
169 actionsPanel.add(createNewGroup, null);
170 this.add(jLabelFind, java.awt.BorderLayout.WEST);
171 this.add(actionsPanel, java.awt.BorderLayout.EAST);
172 this.add(jPanel2, java.awt.BorderLayout.SOUTH);
173 this.add(jPanel3, java.awt.BorderLayout.NORTH);
174 this.add(jPanel4, java.awt.BorderLayout.CENTER);
175 jPanel4.add(jScrollPane1, java.awt.BorderLayout.NORTH);
176 jScrollPane1.getViewport().add(textfield);
178 JPanel optionsPanel = new JPanel();
180 optionsGridLayout.setHgap(0);
181 optionsGridLayout.setRows(2);
182 optionsGridLayout.setVgap(2);
183 optionsPanel.setLayout(optionsGridLayout);
184 optionsPanel.add(caseSensitive, null);
185 optionsPanel.add(searchDescription, null);
187 jPanel4.add(optionsPanel, java.awt.BorderLayout.WEST);
190 protected void findNext_actionPerformed(ActionEvent e)
194 protected void findAll_actionPerformed(ActionEvent e)
198 protected void textfield_keyPressed(KeyEvent e)
200 if (e.getKeyCode() == KeyEvent.VK_ENTER)
203 findNext_actionPerformed(null);
207 public void createNewGroup_actionPerformed(ActionEvent e)
211 public void textfield_caretUpdate(CaretEvent e)
213 if (textfield.getText().indexOf(">") > -1)
215 SwingUtilities.invokeLater(new Runnable()
220 String str = textfield.getText();
221 AlignmentI al = null;
224 al = new FormatAdapter().readFile(str, DataSourceType.PASTE,
226 } catch (Exception ex)
229 if (al != null && al.getHeight() > 0)
231 str = jalview.analysis.AlignSeq.extractGaps(
232 jalview.util.Comparison.GapChars, al.getSequenceAt(0)
233 .getSequenceAsString());
235 textfield.setText(str);