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.AppCache;
28 import jalview.io.cache.CacheBoxI;
29 import jalview.io.cache.Cacheable;
30 import jalview.util.MessageManager;
32 import java.awt.BorderLayout;
33 import java.awt.Dimension;
35 import java.awt.GridLayout;
36 import java.awt.Insets;
37 import java.awt.event.ActionEvent;
38 import java.awt.event.KeyEvent;
40 import javax.swing.JButton;
41 import javax.swing.JCheckBox;
42 import javax.swing.JComboBox;
43 import javax.swing.JLabel;
44 import javax.swing.JPanel;
45 import javax.swing.SwingConstants;
46 import javax.swing.SwingUtilities;
47 import javax.swing.event.CaretEvent;
48 import javax.swing.event.CaretListener;
49 import javax.swing.text.JTextComponent;
51 public class GFinder extends JPanel implements Cacheable
53 JLabel jLabelFind = new JLabel();
55 protected JButton findAll = new JButton();
57 protected JButton findNext = new JButton();
59 JPanel actionsPanel = new JPanel();
61 GridLayout gridLayout1 = new GridLayout();
63 protected JButton createNewGroup = new JButton();
65 protected JComboBox<String> searchBox = new JComboBox<String>();
67 BorderLayout mainBorderLayout = new BorderLayout();
69 JPanel jPanel2 = new JPanel();
71 JPanel jPanel3 = new JPanel();
73 JPanel jPanel4 = new JPanel();
75 BorderLayout borderLayout2 = new BorderLayout();
77 JPanel jPanel6 = new JPanel();
79 protected JCheckBox caseSensitive = new JCheckBox();
81 protected JCheckBox searchDescription = new JCheckBox();
83 GridLayout optionsGridLayout = new GridLayout();
85 private static final String FINDER_CACHE_KEY = "FINDER_CACHE_KEY";
98 private void jbInit() throws Exception
100 jLabelFind.setFont(new java.awt.Font("Verdana", 0, 12));
101 jLabelFind.setText(MessageManager.getString("label.find"));
102 this.setLayout(mainBorderLayout);
103 findAll.setFont(new java.awt.Font("Verdana", 0, 12));
104 findAll.setText(MessageManager.getString("action.find_all"));
105 findAll.addActionListener(new java.awt.event.ActionListener()
108 public void actionPerformed(ActionEvent e)
110 findAll_actionPerformed(e);
113 findNext.setFont(new java.awt.Font("Verdana", 0, 12));
114 findNext.setText(MessageManager.getString("action.find_next"));
115 findNext.addActionListener(new java.awt.event.ActionListener()
118 public void actionPerformed(ActionEvent e)
120 findNext_actionPerformed(e);
123 actionsPanel.setLayout(gridLayout1);
124 gridLayout1.setHgap(0);
125 gridLayout1.setRows(3);
126 gridLayout1.setVgap(2);
127 createNewGroup.setEnabled(false);
128 createNewGroup.setFont(new java.awt.Font("Verdana", 0, 12));
129 createNewGroup.setMargin(new Insets(0, 0, 0, 0));
130 createNewGroup.setText(MessageManager.getString("label.new_feature"));
131 createNewGroup.addActionListener(new java.awt.event.ActionListener()
134 public void actionPerformed(ActionEvent e)
136 createNewGroup_actionPerformed(e);
139 searchBox.setFont(new java.awt.Font("Verdana", Font.PLAIN, 12));
140 searchBox.setEditable(true);
142 .setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXXXXXXX");
143 ((JTextComponent) searchBox.getEditor().getEditorComponent())
144 .addCaretListener(new CaretListener()
147 public void caretUpdate(CaretEvent e)
149 textfield_caretUpdate(e);
152 searchBox.getEditor().getEditorComponent()
153 .addKeyListener(new java.awt.event.KeyAdapter()
156 public void keyPressed(KeyEvent e)
158 textfield_keyPressed(e);
162 mainBorderLayout.setHgap(5);
163 mainBorderLayout.setVgap(5);
164 jPanel4.setLayout(borderLayout2);
165 jPanel2.setPreferredSize(new Dimension(10, 1));
166 jPanel3.setPreferredSize(new Dimension(10, 1));
167 caseSensitive.setHorizontalAlignment(SwingConstants.LEFT);
168 caseSensitive.setText(MessageManager.getString("label.match_case"));
170 searchDescription.setText(MessageManager
171 .getString("label.include_description"));
173 actionsPanel.add(findNext, null);
174 actionsPanel.add(findAll, null);
175 actionsPanel.add(createNewGroup, null);
176 this.add(jLabelFind, java.awt.BorderLayout.WEST);
177 this.add(actionsPanel, java.awt.BorderLayout.EAST);
178 this.add(jPanel2, java.awt.BorderLayout.SOUTH);
179 this.add(jPanel3, java.awt.BorderLayout.NORTH);
180 this.add(jPanel4, java.awt.BorderLayout.CENTER);
181 jPanel4.add(searchBox, java.awt.BorderLayout.NORTH);
183 JPanel optionsPanel = new JPanel();
185 optionsGridLayout.setHgap(0);
186 optionsGridLayout.setRows(2);
187 optionsGridLayout.setVgap(2);
188 optionsPanel.setLayout(optionsGridLayout);
189 optionsPanel.add(caseSensitive, null);
190 optionsPanel.add(searchDescription, null);
192 jPanel4.add(optionsPanel, java.awt.BorderLayout.WEST);
196 protected void findNext_actionPerformed(ActionEvent e)
200 protected void findAll_actionPerformed(ActionEvent e)
204 protected void textfield_keyPressed(KeyEvent e)
206 if (e.getKeyCode() == KeyEvent.VK_ENTER)
209 findNext_actionPerformed(null);
214 public void createNewGroup_actionPerformed(ActionEvent e)
218 public void textfield_caretUpdate(CaretEvent e)
220 if (searchBox.getEditor().getItem().toString().indexOf(">") > -1)
222 SwingUtilities.invokeLater(new Runnable()
227 String str = searchBox.getEditor().getItem().toString();
228 AlignmentI al = null;
231 al = new FormatAdapter().readFile(str, DataSourceType.PASTE,
233 } catch (Exception ex)
236 if (al != null && al.getHeight() > 0)
238 str = jalview.analysis.AlignSeq.extractGaps(
239 jalview.util.Comparison.GapChars, al.getSequenceAt(0)
240 .getSequenceAsString());
242 searchBox.setSelectedItem(str);
250 protected void fireCache()
252 AppCache.getInstance().updateCache(this);
258 // TODO Auto-generated method stub
262 public CacheBoxI<String> getCacheComboBox()
264 return new CacheBoxI<String>()
268 public void setSelectedItem(Object anObject)
270 searchBox.setSelectedItem(anObject);
274 public void requestFocus()
276 searchBox.requestFocusInWindow();
280 public void looseFocus()
282 jPanel6.requestFocusInWindow();
286 public void addItem(String item)
288 searchBox.addItem(item);
292 public void removeAllItems()
294 searchBox.removeAllItems();
298 public int getItemCount()
300 return searchBox.getItemCount();
304 public String getUserInput()
306 return searchBox.getEditor().getItem() == null ? "" : searchBox
307 .getEditor().getItem().toString().trim();
313 public String getCacheKey()
315 return FINDER_CACHE_KEY;