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 searchFeatures;
70 protected JCheckBox ignoreHidden;
84 * Constructs the widgets and adds them to the layout
86 private void jbInit() throws Exception
92 * remaining rows empty
94 * first row search box
95 * second row 'match case' checkbox
96 * third row 'include description' checkbox
97 * fourth row 'ignore hidden' checkbox
99 * first row 'find next' button
100 * second row 'find all' button
101 * third row 'new feature' button
104 this.setLayout(new BorderLayout());
105 JPanel eastPanel = new JPanel();
106 eastPanel.setLayout(new GridLayout(PANEL_ROWS, 1));
107 this.add(eastPanel, BorderLayout.EAST);
108 JPanel centrePanel = new JPanel();
109 centrePanel.setLayout(new GridLayout(PANEL_ROWS, 1));
110 this.add(centrePanel, BorderLayout.CENTER);
111 JPanel westPanel = new JPanel();
112 westPanel.setLayout(new GridLayout(PANEL_ROWS, 1));
113 this.add(westPanel, BorderLayout.WEST);
116 * 'Find' prompt goes top left
118 JLabel findLabel = new JLabel(
119 " " + MessageManager.getString("label.find") + " ");
120 findLabel.setFont(VERDANA_12);
121 westPanel.add(findLabel);
126 searchBox = new JvCacheableInputBox<>(FINDER_CACHE_KEY, 25);
127 searchBox.getComponent().setFont(VERDANA_12);
128 searchBox.addCaretListener(new CaretListener()
131 public void caretUpdate(CaretEvent e)
133 textfield_caretUpdate();
136 searchBox.addKeyListener(new KeyAdapter()
139 public void keyPressed(KeyEvent e)
141 textfield_keyPressed(e);
144 centrePanel.add(searchBox.getComponent());
147 * search options checkboxes
149 caseSensitive = new JCheckBox();
150 caseSensitive.setHorizontalAlignment(SwingConstants.LEFT);
151 caseSensitive.setText(MessageManager.getString("label.match_case"));
153 searchDescription = new JCheckBox();
155 .setText(MessageManager.getString("label.include_description"));
157 searchFeatures = new JCheckBox();
159 .setText(MessageManager.getString("label.include_features"));
161 ignoreHidden = new JCheckBox();
162 ignoreHidden.setText(MessageManager.getString("label.ignore_hidden"));
163 ignoreHidden.setToolTipText(
164 MessageManager.getString("label.ignore_hidden_tooltip"));
166 centrePanel.add(caseSensitive);
167 centrePanel.add(searchDescription);
168 centrePanel.add(searchFeatures);
169 centrePanel.add(ignoreHidden);
174 JButton findAll = new JButton(
175 MessageManager.getString("action.find_all"));
176 findAll.setFont(VERDANA_12);
177 findAll.addActionListener(new ActionListener()
180 public void actionPerformed(ActionEvent e)
182 findAll_actionPerformed();
185 JButton findNext = new JButton(
186 MessageManager.getString("action.find_next"));
187 findNext.setFont(VERDANA_12);
188 findNext.addActionListener(new ActionListener()
191 public void actionPerformed(ActionEvent e)
193 findNext_actionPerformed();
196 createFeatures = new JButton();
197 createFeatures.setEnabled(false);
198 createFeatures.setFont(VERDANA_12);
199 createFeatures.setText(MessageManager.getString("label.new_feature"));
200 createFeatures.addActionListener(new ActionListener()
203 public void actionPerformed(ActionEvent e)
205 createFeatures_actionPerformed();
208 eastPanel.add(findNext);
209 eastPanel.add(findAll);
210 eastPanel.add(createFeatures);
213 protected void textfield_keyPressed(KeyEvent e)
215 if (e.getKeyCode() == KeyEvent.VK_ENTER)
217 if (!searchBox.isPopupVisible())
220 findNext_actionPerformed();
225 protected void findNext_actionPerformed()
229 protected void findAll_actionPerformed()
233 public void createFeatures_actionPerformed()
237 public void textfield_caretUpdate()
239 // disabled as appears to be running a non-functional
240 if (false && searchBox.getUserInput().indexOf(">") > -1)
242 SwingUtilities.invokeLater(new Runnable()
247 String str = searchBox.getUserInput();
248 AlignmentI al = null;
251 al = new FormatAdapter().readFile(str, DataSourceType.PASTE,
253 } catch (Exception ex)
256 if (al != null && al.getHeight() > 0)
258 str = jalview.analysis.AlignSeq.extractGaps(
259 jalview.util.Comparison.GapChars,
260 al.getSequenceAt(0).getSequenceAsString());
261 // todo and what? set str as searchBox text?