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;
46 import javax.swing.text.JTextComponent;
48 public class GFinder extends JPanel
50 private static final java.awt.Font VERDANA_12 = new java.awt.Font("Verdana", 0,
53 private static final String FINDER_CACHE_KEY = "CACHE.FINDER";
55 protected JButton createFeatures = new JButton();
57 protected JvCacheableInputBox<String> searchBox = new JvCacheableInputBox<>(
60 protected JCheckBox caseSensitive = new JCheckBox();
62 protected JCheckBox searchDescription = new JCheckBox();
75 private void jbInit() throws Exception
77 BorderLayout mainBorderLayout = new BorderLayout();
78 this.setLayout(mainBorderLayout);
79 mainBorderLayout.setHgap(5);
80 mainBorderLayout.setVgap(5);
82 JLabel jLabelFind = new JLabel(MessageManager.getString("label.find"));
83 jLabelFind.setFont(VERDANA_12);
85 JButton findAll = new JButton(
86 MessageManager.getString("action.find_all"));
87 findAll.setFont(VERDANA_12);
88 findAll.addActionListener(new java.awt.event.ActionListener()
91 public void actionPerformed(ActionEvent e)
93 findAll_actionPerformed();
97 JButton findNext = new JButton(
98 MessageManager.getString("action.find_next"));
99 findNext.setFont(VERDANA_12);
100 findNext.addActionListener(new java.awt.event.ActionListener()
103 public void actionPerformed(ActionEvent e)
105 findNext_actionPerformed();
109 JPanel actionsPanel = new JPanel();
110 GridLayout gridLayout1 = new GridLayout();
111 actionsPanel.setLayout(gridLayout1);
112 gridLayout1.setHgap(0);
113 gridLayout1.setRows(3);
114 gridLayout1.setVgap(2);
116 createFeatures.setEnabled(false);
117 createFeatures.setFont(VERDANA_12);
118 createFeatures.setMargin(new Insets(0, 0, 0, 0));
119 createFeatures.setText(MessageManager.getString("label.new_feature"));
120 createFeatures.addActionListener(new java.awt.event.ActionListener()
123 public void actionPerformed(ActionEvent e)
125 createFeatures_actionPerformed();
128 searchBox.setFont(new java.awt.Font("Verdana", Font.PLAIN, 12));
129 ((JTextComponent) searchBox.getEditor().getEditorComponent())
130 .addCaretListener(new CaretListener()
133 public void caretUpdate(CaretEvent e)
135 textfield_caretUpdate();
138 searchBox.getEditor().getEditorComponent()
139 .addKeyListener(new java.awt.event.KeyAdapter()
142 public void keyPressed(KeyEvent e)
144 textfield_keyPressed(e);
148 caseSensitive.setHorizontalAlignment(SwingConstants.LEFT);
149 caseSensitive.setText(MessageManager.getString("label.match_case"));
152 .setText(MessageManager.getString("label.include_description"));
154 actionsPanel.add(findNext, null);
155 actionsPanel.add(findAll, null);
156 actionsPanel.add(createFeatures, null);
157 this.add(jLabelFind, java.awt.BorderLayout.WEST);
158 this.add(actionsPanel, java.awt.BorderLayout.EAST);
160 JPanel jPanel2 = new JPanel();
161 jPanel2.setPreferredSize(new Dimension(10, 1));
162 JPanel jPanel3 = new JPanel();
163 jPanel3.setPreferredSize(new Dimension(10, 1));
164 JPanel jPanel4 = new JPanel();
165 jPanel4.setLayout(new BorderLayout());
166 this.add(jPanel2, java.awt.BorderLayout.SOUTH);
167 this.add(jPanel3, java.awt.BorderLayout.NORTH);
168 this.add(jPanel4, java.awt.BorderLayout.CENTER);
169 jPanel4.add(searchBox, java.awt.BorderLayout.NORTH);
171 JPanel optionsPanel = new JPanel();
173 GridLayout optionsGridLayout = new GridLayout();
174 optionsGridLayout.setHgap(0);
175 optionsGridLayout.setRows(2);
176 optionsGridLayout.setVgap(2);
177 optionsPanel.setLayout(optionsGridLayout);
178 optionsPanel.add(caseSensitive, null);
179 optionsPanel.add(searchDescription, null);
181 jPanel4.add(optionsPanel, java.awt.BorderLayout.WEST);
184 protected void textfield_keyPressed(KeyEvent e)
186 if (e.getKeyCode() == KeyEvent.VK_ENTER)
188 if (!searchBox.isPopupVisible())
191 findNext_actionPerformed();
196 protected void findNext_actionPerformed()
200 protected void findAll_actionPerformed()
204 public void createFeatures_actionPerformed()
208 public void textfield_caretUpdate()
210 // disabled as appears to be running a non-functional
211 if (false && searchBox.getUserInput().indexOf(">") > -1)
213 SwingUtilities.invokeLater(new Runnable()
218 String str = searchBox.getUserInput();
219 AlignmentI al = null;
222 al = new FormatAdapter().readFile(str, DataSourceType.PASTE,
224 } catch (Exception ex)
227 if (al != null && al.getHeight() > 0)
229 str = jalview.analysis.AlignSeq.extractGaps(
230 jalview.util.Comparison.GapChars,
231 al.getSequenceAt(0).getSequenceAsString());
232 // todo and what? set str as searchBox text?
240 * Returns unique key used for storing Finder cache items in the cache data
245 public String getCacheKey()
247 return FINDER_CACHE_KEY;