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;
31 import java.awt.Dimension;
33 import java.awt.GridLayout;
34 import java.awt.Insets;
35 import java.awt.event.ActionEvent;
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 java.awt.Font("Verdana", 0,
52 private static final String FINDER_CACHE_KEY = "CACHE.FINDER";
54 protected JButton createFeatures = new JButton();
56 protected JvCacheableInputBox<String> searchBox = new JvCacheableInputBox<>(
59 protected JCheckBox caseSensitive = new JCheckBox();
61 protected JCheckBox searchDescription = new JCheckBox();
74 private void jbInit() throws Exception
76 BorderLayout mainBorderLayout = new BorderLayout();
77 this.setLayout(mainBorderLayout);
78 mainBorderLayout.setHgap(5);
79 mainBorderLayout.setVgap(5);
81 JLabel jLabelFind = new JLabel(MessageManager.getString("label.find"));
82 jLabelFind.setFont(VERDANA_12);
84 JButton findAll = new JButton(
85 MessageManager.getString("action.find_all"));
86 findAll.setFont(VERDANA_12);
87 findAll.addActionListener(new java.awt.event.ActionListener()
90 public void actionPerformed(ActionEvent e)
92 findAll_actionPerformed();
96 JButton findNext = new JButton(
97 MessageManager.getString("action.find_next"));
98 findNext.setFont(VERDANA_12);
99 findNext.addActionListener(new java.awt.event.ActionListener()
102 public void actionPerformed(ActionEvent e)
104 findNext_actionPerformed();
108 JPanel actionsPanel = new JPanel();
109 GridLayout gridLayout1 = new GridLayout();
110 actionsPanel.setLayout(gridLayout1);
111 gridLayout1.setHgap(0);
112 gridLayout1.setRows(3);
113 gridLayout1.setVgap(2);
115 createFeatures.setEnabled(false);
116 createFeatures.setFont(VERDANA_12);
117 createFeatures.setMargin(new Insets(0, 0, 0, 0));
118 createFeatures.setText(MessageManager.getString("label.new_feature"));
119 createFeatures.addActionListener(new java.awt.event.ActionListener()
122 public void actionPerformed(ActionEvent e)
124 createFeatures_actionPerformed();
127 searchBox.getComponent()
128 .setFont(new java.awt.Font("Verdana", Font.PLAIN, 12));
129 searchBox.addCaretListener(new CaretListener()
132 public void caretUpdate(CaretEvent e)
134 textfield_caretUpdate();
137 searchBox.addKeyListener(new java.awt.event.KeyAdapter()
140 public void keyPressed(KeyEvent e)
142 textfield_keyPressed(e);
146 caseSensitive.setHorizontalAlignment(SwingConstants.LEFT);
147 caseSensitive.setText(MessageManager.getString("label.match_case"));
150 .setText(MessageManager.getString("label.include_description"));
152 actionsPanel.add(findNext, null);
153 actionsPanel.add(findAll, null);
154 actionsPanel.add(createFeatures, null);
155 this.add(jLabelFind, java.awt.BorderLayout.WEST);
156 this.add(actionsPanel, java.awt.BorderLayout.EAST);
158 JPanel jPanel2 = new JPanel();
159 jPanel2.setPreferredSize(new Dimension(10, 1));
160 JPanel jPanel3 = new JPanel();
161 jPanel3.setPreferredSize(new Dimension(10, 1));
162 JPanel jPanel4 = new JPanel();
163 jPanel4.setLayout(new BorderLayout());
164 this.add(jPanel2, java.awt.BorderLayout.SOUTH);
165 this.add(jPanel3, java.awt.BorderLayout.NORTH);
166 this.add(jPanel4, java.awt.BorderLayout.CENTER);
167 jPanel4.add(searchBox.getComponent(), java.awt.BorderLayout.NORTH);
169 JPanel optionsPanel = new JPanel();
171 GridLayout optionsGridLayout = new GridLayout();
172 optionsGridLayout.setHgap(0);
173 optionsGridLayout.setRows(2);
174 optionsGridLayout.setVgap(2);
175 optionsPanel.setLayout(optionsGridLayout);
176 optionsPanel.add(caseSensitive, null);
177 optionsPanel.add(searchDescription, null);
179 jPanel4.add(optionsPanel, java.awt.BorderLayout.WEST);
182 protected void textfield_keyPressed(KeyEvent e)
184 if (e.getKeyCode() == KeyEvent.VK_ENTER)
186 if (!searchBox.isPopupVisible())
189 findNext_actionPerformed();
194 protected void findNext_actionPerformed()
198 protected void findAll_actionPerformed()
202 public void createFeatures_actionPerformed()
206 public void textfield_caretUpdate()
208 // disabled as appears to be running a non-functional
209 if (false && searchBox.getUserInput().indexOf(">") > -1)
211 SwingUtilities.invokeLater(new Runnable()
216 String str = searchBox.getUserInput();
217 AlignmentI al = null;
220 al = new FormatAdapter().readFile(str, DataSourceType.PASTE,
222 } catch (Exception ex)
225 if (al != null && al.getHeight() > 0)
227 str = jalview.analysis.AlignSeq.extractGaps(
228 jalview.util.Comparison.GapChars,
229 al.getSequenceAt(0).getSequenceAsString());
230 // todo and what? set str as searchBox text?
238 * Returns unique key used for storing Finder cache items in the cache data
243 public String getCacheKey()
245 return FINDER_CACHE_KEY;