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";
56 * if more checkboxes are wanted, increase this value
57 * and add to centrePanel in jbInit()
59 private static final int PANEL_ROWS = 4;
61 protected JButton createFeatures;
63 protected JvCacheableInputBox<String> searchBox;
65 protected JCheckBox caseSensitive;
67 protected JCheckBox searchDescription;
69 protected JCheckBox ignoreHidden;
83 * Constructs the widgets and adds them to the layout
85 private void jbInit() throws Exception
91 * remaining rows empty
93 * first row search box
94 * second row 'match case' checkbox
95 * third row 'include description' checkbox
96 * fourth row 'ignore hidden' checkbox
98 * first row 'find next' button
99 * second row 'find all' button
100 * third row 'new feature' button
103 this.setLayout(new BorderLayout());
104 JPanel eastPanel = new JPanel();
105 eastPanel.setLayout(new GridLayout(PANEL_ROWS, 1));
106 this.add(eastPanel, BorderLayout.EAST);
107 JPanel centrePanel = new JPanel();
108 centrePanel.setLayout(new GridLayout(PANEL_ROWS, 1));
109 this.add(centrePanel, BorderLayout.CENTER);
110 JPanel westPanel = new JPanel();
111 westPanel.setLayout(new GridLayout(PANEL_ROWS, 1));
112 this.add(westPanel, BorderLayout.WEST);
115 * 'Find' prompt goes top left
117 JLabel findLabel = new JLabel(
118 " " + MessageManager.getString("label.find") + " ");
119 findLabel.setFont(VERDANA_12);
120 westPanel.add(findLabel);
125 searchBox = new JvCacheableInputBox<>(FINDER_CACHE_KEY, 25);
126 searchBox.setFont(VERDANA_12);
127 ((JTextComponent) searchBox.getEditor().getEditorComponent())
128 .addCaretListener(new CaretListener()
131 public void caretUpdate(CaretEvent e)
133 textfield_caretUpdate();
136 searchBox.getEditor().getEditorComponent()
137 .addKeyListener(new KeyAdapter()
140 public void keyPressed(KeyEvent e)
142 textfield_keyPressed(e);
145 centrePanel.add(searchBox);
148 * search options checkboxes
150 caseSensitive = new JCheckBox();
151 caseSensitive.setHorizontalAlignment(SwingConstants.LEFT);
152 caseSensitive.setText(MessageManager.getString("label.match_case"));
154 searchDescription = new JCheckBox();
156 .setText(MessageManager.getString("label.include_description"));
158 ignoreHidden = new JCheckBox();
159 ignoreHidden.setText(MessageManager.getString("label.ignore_hidden"));
160 ignoreHidden.setToolTipText(
161 MessageManager.getString("label.ignore_hidden_tooltip"));
163 centrePanel.add(caseSensitive);
164 centrePanel.add(searchDescription);
165 centrePanel.add(ignoreHidden);
170 JButton findAll = new JButton(
171 MessageManager.getString("action.find_all"));
172 findAll.setFont(VERDANA_12);
173 findAll.addActionListener(new ActionListener()
176 public void actionPerformed(ActionEvent e)
178 findAll_actionPerformed();
181 JButton findNext = new JButton(
182 MessageManager.getString("action.find_next"));
183 findNext.setFont(VERDANA_12);
184 findNext.addActionListener(new ActionListener()
187 public void actionPerformed(ActionEvent e)
189 findNext_actionPerformed();
192 createFeatures = new JButton();
193 createFeatures.setEnabled(false);
194 createFeatures.setFont(VERDANA_12);
195 createFeatures.setText(MessageManager.getString("label.new_feature"));
196 createFeatures.addActionListener(new ActionListener()
199 public void actionPerformed(ActionEvent e)
201 createFeatures_actionPerformed();
204 eastPanel.add(findNext);
205 eastPanel.add(findAll);
206 eastPanel.add(createFeatures);
209 protected void textfield_keyPressed(KeyEvent e)
211 if (e.getKeyCode() == KeyEvent.VK_ENTER)
213 if (!searchBox.isPopupVisible())
216 findNext_actionPerformed();
221 protected void findNext_actionPerformed()
225 protected void findAll_actionPerformed()
229 public void createFeatures_actionPerformed()
233 public void textfield_caretUpdate()
235 // disabled as appears to be running a non-functional
236 if (false && searchBox.getUserInput().indexOf(">") > -1)
238 SwingUtilities.invokeLater(new Runnable()
243 String str = searchBox.getUserInput();
244 AlignmentI al = null;
247 al = new FormatAdapter().readFile(str, DataSourceType.PASTE,
249 } catch (Exception ex)
252 if (al != null && al.getHeight() > 0)
254 str = jalview.analysis.AlignSeq.extractGaps(
255 jalview.util.Comparison.GapChars,
256 al.getSequenceAt(0).getSequenceAsString());
257 // todo and what? set str as searchBox text?