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;
47 public class GFinder extends JPanel
49 private static final java.awt.Font VERDANA_12 = new Font("Verdana",
52 private static final String FINDER_CACHE_KEY = "CACHE.FINDER";
55 * if more checkboxes are wanted, increase this value
56 * and add to centrePanel in jbInit()
58 private static final int PANEL_ROWS = 4;
60 protected JButton createFeatures;
62 protected JvCacheableInputBox<String> searchBox;
64 protected JCheckBox caseSensitive;
66 protected JCheckBox searchDescription;
68 protected JCheckBox ignoreHidden;
82 * Constructs the widgets and adds them to the layout
84 private void jbInit() throws Exception
90 * remaining rows empty
92 * first row search box
93 * second row 'match case' checkbox
94 * third row 'include description' checkbox
95 * fourth row 'ignore hidden' checkbox
97 * first row 'find next' button
98 * second row 'find all' button
99 * third row 'new feature' button
102 this.setLayout(new BorderLayout());
103 JPanel eastPanel = new JPanel();
104 eastPanel.setLayout(new GridLayout(PANEL_ROWS, 1));
105 this.add(eastPanel, BorderLayout.EAST);
106 JPanel centrePanel = new JPanel();
107 centrePanel.setLayout(new GridLayout(PANEL_ROWS, 1));
108 this.add(centrePanel, BorderLayout.CENTER);
109 JPanel westPanel = new JPanel();
110 westPanel.setLayout(new GridLayout(PANEL_ROWS, 1));
111 this.add(westPanel, BorderLayout.WEST);
114 * 'Find' prompt goes top left
116 JLabel findLabel = new JLabel(
117 " " + MessageManager.getString("label.find") + " ");
118 findLabel.setFont(VERDANA_12);
119 westPanel.add(findLabel);
124 searchBox = new JvCacheableInputBox<>(FINDER_CACHE_KEY, 25);
125 searchBox.getComponent().setFont(VERDANA_12);
126 searchBox.addCaretListener(new CaretListener()
129 public void caretUpdate(CaretEvent e)
131 textfield_caretUpdate();
134 searchBox.addKeyListener(new KeyAdapter()
137 public void keyPressed(KeyEvent e)
139 textfield_keyPressed(e);
142 centrePanel.add(searchBox.getComponent());
145 * search options checkboxes
147 caseSensitive = new JCheckBox();
148 caseSensitive.setHorizontalAlignment(SwingConstants.LEFT);
149 caseSensitive.setText(MessageManager.getString("label.match_case"));
151 searchDescription = new JCheckBox();
153 .setText(MessageManager.getString("label.include_description"));
155 ignoreHidden = new JCheckBox();
156 ignoreHidden.setText(MessageManager.getString("label.ignore_hidden"));
157 ignoreHidden.setToolTipText(
158 MessageManager.getString("label.ignore_hidden_tooltip"));
160 centrePanel.add(caseSensitive);
161 centrePanel.add(searchDescription);
162 centrePanel.add(ignoreHidden);
167 JButton findAll = new JButton(
168 MessageManager.getString("action.find_all"));
169 findAll.setFont(VERDANA_12);
170 findAll.addActionListener(new ActionListener()
173 public void actionPerformed(ActionEvent e)
175 findAll_actionPerformed();
178 JButton findNext = new JButton(
179 MessageManager.getString("action.find_next"));
180 findNext.setFont(VERDANA_12);
181 findNext.addActionListener(new ActionListener()
184 public void actionPerformed(ActionEvent e)
186 findNext_actionPerformed();
189 createFeatures = new JButton();
190 createFeatures.setEnabled(false);
191 createFeatures.setFont(VERDANA_12);
192 createFeatures.setText(MessageManager.getString("label.new_feature"));
193 createFeatures.addActionListener(new ActionListener()
196 public void actionPerformed(ActionEvent e)
198 createFeatures_actionPerformed();
201 eastPanel.add(findNext);
202 eastPanel.add(findAll);
203 eastPanel.add(createFeatures);
206 protected void textfield_keyPressed(KeyEvent e)
208 if (e.getKeyCode() == KeyEvent.VK_ENTER)
210 if (!searchBox.isPopupVisible())
213 findNext_actionPerformed();
218 protected void findNext_actionPerformed()
222 protected void findAll_actionPerformed()
226 public void createFeatures_actionPerformed()
230 public void textfield_caretUpdate()
232 // disabled as appears to be running a non-functional
233 if (false && searchBox.getUserInput().indexOf(">") > -1)
235 SwingUtilities.invokeLater(new Runnable()
240 String str = searchBox.getUserInput();
241 AlignmentI al = null;
244 al = new FormatAdapter().readFile(str, DataSourceType.PASTE,
246 } catch (Exception ex)
249 if (al != null && al.getHeight() > 0)
251 str = jalview.analysis.AlignSeq.extractGaps(
252 jalview.util.Comparison.GapChars,
253 al.getSequenceAt(0).getSequenceAsString());
254 // todo and what? set str as searchBox text?