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.io.cache.JvCacheableInputBox;
28 import jalview.util.MessageManager;
30 import java.awt.BorderLayout;
32 import java.awt.GridLayout;
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ActionListener;
35 import java.awt.event.KeyAdapter;
36 import java.awt.event.KeyEvent;
38 import javax.swing.JButton;
39 import javax.swing.JCheckBox;
40 import javax.swing.JLabel;
41 import javax.swing.JPanel;
42 import javax.swing.SwingConstants;
43 import javax.swing.SwingUtilities;
44 import javax.swing.event.CaretEvent;
45 import javax.swing.event.CaretListener;
46 import javax.swing.text.JTextComponent;
48 public class GFinder extends JPanel
50 private static final java.awt.Font VERDANA_12 = new Font("Verdana",
53 private static final String FINDER_CACHE_KEY = "CACHE.FINDER";
55 protected JButton createFeatures;
57 protected JvCacheableInputBox<String> searchBox;
59 protected JCheckBox caseSensitive;
61 protected JCheckBox searchDescription;
63 protected JCheckBox ignoreHidden;
77 * Constructs the widgets and adds them to the layout
79 private void jbInit() throws Exception
85 * remaining rows empty
87 * first row search box
88 * second row 'match case' checkbox
89 * third row 'include description' checkbox
90 * fourth row 'ignore hidden' checkbox
92 * first row 'find next' button
93 * second row 'find all' button
94 * third row 'new feature' button
97 this.setLayout(new BorderLayout());
98 JPanel eastPanel = new JPanel();
99 eastPanel.setLayout(new GridLayout(4, 1));
100 this.add(eastPanel, BorderLayout.EAST);
101 JPanel centrePanel = new JPanel();
102 centrePanel.setLayout(new GridLayout(4, 1));
103 this.add(centrePanel, BorderLayout.CENTER);
104 JPanel westPanel = new JPanel();
105 westPanel.setLayout(new GridLayout(4, 1));
106 this.add(westPanel, BorderLayout.WEST);
109 * 'Find' prompt goes top left
111 JLabel findLabel = new JLabel(
112 " " + MessageManager.getString("label.find") + " ");
113 findLabel.setFont(VERDANA_12);
114 westPanel.add(findLabel);
119 searchBox = new JvCacheableInputBox<>(FINDER_CACHE_KEY, 25);
120 searchBox.setFont(VERDANA_12);
121 ((JTextComponent) searchBox.getEditor().getEditorComponent())
122 .addCaretListener(new CaretListener()
125 public void caretUpdate(CaretEvent e)
127 textfield_caretUpdate();
130 searchBox.getEditor().getEditorComponent()
131 .addKeyListener(new KeyAdapter()
134 public void keyPressed(KeyEvent e)
136 textfield_keyPressed(e);
139 centrePanel.add(searchBox);
142 * search options checkboxes
144 caseSensitive = new JCheckBox();
145 caseSensitive.setHorizontalAlignment(SwingConstants.LEFT);
146 caseSensitive.setText(MessageManager.getString("label.match_case"));
148 searchDescription = new JCheckBox();
150 .setText(MessageManager.getString("label.include_description"));
152 ignoreHidden = new JCheckBox();
153 ignoreHidden.setText(MessageManager.getString("label.ignore_hidden"));
154 ignoreHidden.setToolTipText(
155 MessageManager.getString("label.ignore_hidden_tooltip"));
157 centrePanel.add(caseSensitive);
158 centrePanel.add(searchDescription);
159 centrePanel.add(ignoreHidden);
164 JButton findAll = new JButton(
165 MessageManager.getString("action.find_all"));
166 findAll.setFont(VERDANA_12);
167 findAll.addActionListener(new ActionListener()
170 public void actionPerformed(ActionEvent e)
172 findAll_actionPerformed();
175 JButton findNext = new JButton(
176 MessageManager.getString("action.find_next"));
177 findNext.setFont(VERDANA_12);
178 findNext.addActionListener(new ActionListener()
181 public void actionPerformed(ActionEvent e)
183 findNext_actionPerformed();
186 createFeatures = new JButton();
187 createFeatures.setEnabled(false);
188 createFeatures.setFont(VERDANA_12);
189 createFeatures.setText(MessageManager.getString("label.new_feature"));
190 createFeatures.addActionListener(new ActionListener()
193 public void actionPerformed(ActionEvent e)
195 createFeatures_actionPerformed();
198 eastPanel.add(findNext);
199 eastPanel.add(findAll);
200 eastPanel.add(createFeatures);
203 protected void textfield_keyPressed(KeyEvent e)
205 if (e.getKeyCode() == KeyEvent.VK_ENTER)
207 if (!searchBox.isPopupVisible())
210 findNext_actionPerformed();
215 protected void findNext_actionPerformed()
219 protected void findAll_actionPerformed()
223 public void createFeatures_actionPerformed()
227 public void textfield_caretUpdate()
229 // disabled as appears to be running a non-functional
230 if (false && searchBox.getUserInput().indexOf(">") > -1)
232 SwingUtilities.invokeLater(new Runnable()
237 String str = searchBox.getUserInput();
238 AlignmentI al = null;
241 al = new FormatAdapter().readFile(str, DataSourceType.PASTE,
243 } catch (Exception ex)
246 if (al != null && al.getHeight() > 0)
248 str = jalview.analysis.AlignSeq.extractGaps(
249 jalview.util.Comparison.GapChars,
250 al.getSequenceAt(0).getSequenceAsString());
251 // todo and what? set str as searchBox text?