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 java.awt.BorderLayout;
25 import java.awt.GridLayout;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28 import java.awt.event.KeyAdapter;
29 import java.awt.event.KeyEvent;
31 import javax.swing.JButton;
32 import javax.swing.JCheckBox;
33 import javax.swing.JLabel;
34 import javax.swing.JPanel;
35 import javax.swing.SwingConstants;
36 import javax.swing.SwingUtilities;
37 import javax.swing.event.CaretEvent;
38 import javax.swing.event.CaretListener;
40 import jalview.datamodel.AlignmentI;
41 import jalview.io.DataSourceType;
42 import jalview.io.FileFormat;
43 import jalview.io.FormatAdapter;
44 import jalview.io.cache.JvCacheableInputBox;
45 import jalview.util.MessageManager;
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 JButton copyToClipboard;
64 protected JvCacheableInputBox<String> searchBox;
66 protected JCheckBox caseSensitive;
68 protected JCheckBox searchDescription;
70 protected JCheckBox searchFeatures;
72 protected JCheckBox ignoreHidden;
86 * Constructs the widgets and adds them to the layout
88 private void jbInit() throws Exception
94 * remaining rows empty
96 * first row search box
97 * second row 'match case' checkbox
98 * third row 'include description' checkbox
99 * fourth row 'ignore hidden' checkbox
101 * first row 'find next' button
102 * second row 'find all' button
103 * third row 'new feature' button
106 this.setLayout(new BorderLayout());
107 JPanel eastPanel = new JPanel();
108 eastPanel.setLayout(new GridLayout(PANEL_ROWS, 1));
109 this.add(eastPanel, BorderLayout.EAST);
110 JPanel centrePanel = new JPanel();
111 centrePanel.setLayout(new GridLayout(PANEL_ROWS, 1));
112 this.add(centrePanel, BorderLayout.CENTER);
113 JPanel westPanel = new JPanel();
114 westPanel.setLayout(new GridLayout(PANEL_ROWS, 1));
115 this.add(westPanel, BorderLayout.WEST);
118 * 'Find' prompt goes top left
120 JLabel findLabel = new JLabel(
121 " " + MessageManager.getString("label.find") + " ");
122 findLabel.setFont(VERDANA_12);
123 westPanel.add(findLabel);
128 searchBox = new JvCacheableInputBox<>(FINDER_CACHE_KEY, 25);
129 searchBox.getComponent().setFont(VERDANA_12);
130 searchBox.addCaretListener(new CaretListener()
133 public void caretUpdate(CaretEvent e)
135 textfield_caretUpdate();
138 searchBox.addKeyListener(new KeyAdapter()
141 public void keyPressed(KeyEvent e)
143 textfield_keyPressed(e);
146 centrePanel.add(searchBox.getComponent());
149 * search options checkboxes
151 caseSensitive = new JCheckBox();
152 caseSensitive.setHorizontalAlignment(SwingConstants.LEFT);
153 caseSensitive.setText(MessageManager.getString("label.match_case"));
155 searchDescription = new JCheckBox();
157 .setText(MessageManager.getString("label.include_description"));
159 searchFeatures = new JCheckBox();
161 .setText(MessageManager.getString("label.include_features"));
163 ignoreHidden = new JCheckBox();
164 ignoreHidden.setText(MessageManager.getString("label.ignore_hidden"));
165 ignoreHidden.setToolTipText(
166 MessageManager.getString("label.ignore_hidden_tooltip"));
168 centrePanel.add(caseSensitive);
169 centrePanel.add(searchDescription);
170 centrePanel.add(searchFeatures);
171 centrePanel.add(ignoreHidden);
176 JButton findAll = new JButton(
177 MessageManager.getString("action.find_all"));
178 findAll.setFont(VERDANA_12);
179 findAll.addActionListener(new ActionListener()
182 public void actionPerformed(ActionEvent e)
184 findAll_actionPerformed();
187 JButton findNext = new JButton(
188 MessageManager.getString("action.find_next"));
189 findNext.setFont(VERDANA_12);
190 findNext.addActionListener(new ActionListener()
193 public void actionPerformed(ActionEvent e)
195 findNext_actionPerformed();
198 createFeatures = new JButton();
199 createFeatures.setEnabled(false);
200 createFeatures.setFont(VERDANA_12);
201 createFeatures.setText(MessageManager.getString("label.new_feature"));
202 createFeatures.addActionListener(new ActionListener()
205 public void actionPerformed(ActionEvent e)
207 createFeatures_actionPerformed();
210 copyToClipboard = new JButton();
211 copyToClipboard.setEnabled(false);
212 copyToClipboard.setFont(VERDANA_12);
213 copyToClipboard.setText(MessageManager.getString("label.copy"));
214 copyToClipboard.addActionListener(new ActionListener()
217 public void actionPerformed(ActionEvent e)
219 copyToClipboard_actionPerformed();
222 eastPanel.add(findNext);
223 eastPanel.add(findAll);
224 eastPanel.add(createFeatures);
225 eastPanel.add(copyToClipboard);
228 protected void copyToClipboard_actionPerformed()
232 protected void textfield_keyPressed(KeyEvent e)
234 if (e.getKeyCode() == KeyEvent.VK_ENTER)
236 if (!searchBox.isPopupVisible())
239 findNext_actionPerformed();
244 protected void findNext_actionPerformed()
248 protected void findAll_actionPerformed()
252 public void createFeatures_actionPerformed()
256 public void textfield_caretUpdate()
258 // disabled as appears to be running a non-functional
259 if (false && searchBox.getUserInput().indexOf(">") > -1)
261 SwingUtilities.invokeLater(new Runnable()
266 String str = searchBox.getUserInput();
267 AlignmentI al = null;
270 al = new FormatAdapter().readFile(str, DataSourceType.PASTE,
272 } catch (Exception ex)
275 if (al != null && al.getHeight() > 0)
277 str = jalview.analysis.AlignSeq.extractGaps(
278 jalview.util.Comparison.GapChars,
279 al.getSequenceAt(0).getSequenceAsString());
280 // todo and what? set str as searchBox text?