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.Cacheable;
29 import jalview.util.MessageManager;
31 import java.awt.BorderLayout;
32 import java.awt.Dimension;
34 import java.awt.GridLayout;
35 import java.awt.Insets;
36 import java.awt.event.ActionEvent;
37 import java.awt.event.KeyEvent;
39 import javax.swing.JButton;
40 import javax.swing.JCheckBox;
41 import javax.swing.JComboBox;
42 import javax.swing.JComponent;
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();
66 protected JComboBox<String> searchBox = new JComboBox<String>();
68 BorderLayout mainBorderLayout = new BorderLayout();
70 JPanel jPanel2 = new JPanel();
72 JPanel jPanel3 = new JPanel();
74 JPanel jPanel4 = new JPanel();
76 BorderLayout borderLayout2 = new BorderLayout();
78 JPanel jPanel6 = new JPanel();
80 protected JCheckBox caseSensitive = new JCheckBox();
82 protected JCheckBox searchDescription = new JCheckBox();
84 GridLayout optionsGridLayout = new GridLayout();
86 private static final String FINDER_CACHE_KEY = "FINDER_CACHE_KEY";
99 private void jbInit() throws Exception
101 jLabelFind.setFont(new java.awt.Font("Verdana", 0, 12));
102 jLabelFind.setText(MessageManager.getString("label.find"));
103 this.setLayout(mainBorderLayout);
104 findAll.setFont(new java.awt.Font("Verdana", 0, 12));
105 findAll.setText(MessageManager.getString("action.find_all"));
106 findAll.addActionListener(new java.awt.event.ActionListener()
109 public void actionPerformed(ActionEvent e)
111 findAll_actionPerformed(e);
114 findNext.setFont(new java.awt.Font("Verdana", 0, 12));
115 findNext.setText(MessageManager.getString("action.find_next"));
116 findNext.addActionListener(new java.awt.event.ActionListener()
119 public void actionPerformed(ActionEvent e)
121 findNext_actionPerformed(e);
124 actionsPanel.setLayout(gridLayout1);
125 gridLayout1.setHgap(0);
126 gridLayout1.setRows(3);
127 gridLayout1.setVgap(2);
128 createNewGroup.setEnabled(false);
129 createNewGroup.setFont(new java.awt.Font("Verdana", 0, 12));
130 createNewGroup.setMargin(new Insets(0, 0, 0, 0));
131 createNewGroup.setText(MessageManager.getString("label.new_feature"));
132 createNewGroup.addActionListener(new java.awt.event.ActionListener()
135 public void actionPerformed(ActionEvent e)
137 createNewGroup_actionPerformed(e);
140 searchBox.setFont(new java.awt.Font("Verdana", Font.PLAIN, 12));
141 searchBox.setEditable(true);
143 .setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXXXXXXX");
144 ((JTextComponent) searchBox.getEditor().getEditorComponent())
145 .addCaretListener(new CaretListener()
148 public void caretUpdate(CaretEvent e)
150 textfield_caretUpdate(e);
153 searchBox.getEditor().getEditorComponent()
154 .addKeyListener(new java.awt.event.KeyAdapter()
157 public void keyPressed(KeyEvent e)
159 textfield_keyPressed(e);
163 mainBorderLayout.setHgap(5);
164 mainBorderLayout.setVgap(5);
165 jPanel4.setLayout(borderLayout2);
166 jPanel2.setPreferredSize(new Dimension(10, 1));
167 jPanel3.setPreferredSize(new Dimension(10, 1));
168 caseSensitive.setHorizontalAlignment(SwingConstants.LEFT);
169 caseSensitive.setText(MessageManager.getString("label.match_case"));
171 searchDescription.setText(MessageManager
172 .getString("label.include_description"));
174 actionsPanel.add(findNext, null);
175 actionsPanel.add(findAll, null);
176 actionsPanel.add(createNewGroup, null);
177 this.add(jLabelFind, java.awt.BorderLayout.WEST);
178 this.add(actionsPanel, java.awt.BorderLayout.EAST);
179 this.add(jPanel2, java.awt.BorderLayout.SOUTH);
180 this.add(jPanel3, java.awt.BorderLayout.NORTH);
181 this.add(jPanel4, java.awt.BorderLayout.CENTER);
182 jPanel4.add(searchBox, java.awt.BorderLayout.NORTH);
184 JPanel optionsPanel = new JPanel();
186 optionsGridLayout.setHgap(0);
187 optionsGridLayout.setRows(2);
188 optionsGridLayout.setVgap(2);
189 optionsPanel.setLayout(optionsGridLayout);
190 optionsPanel.add(caseSensitive, null);
191 optionsPanel.add(searchDescription, null);
193 jPanel4.add(optionsPanel, java.awt.BorderLayout.WEST);
197 protected void findNext_actionPerformed(ActionEvent e)
201 protected void findAll_actionPerformed(ActionEvent e)
205 protected void textfield_keyPressed(KeyEvent e)
207 if (e.getKeyCode() == KeyEvent.VK_ENTER)
210 findNext_actionPerformed(null);
215 public void createNewGroup_actionPerformed(ActionEvent e)
219 public void textfield_caretUpdate(CaretEvent e)
221 if (searchBox.getEditor().getItem().toString().indexOf(">") > -1)
223 SwingUtilities.invokeLater(new Runnable()
228 String str = searchBox.getEditor().getItem().toString();
229 AlignmentI al = null;
232 al = new FormatAdapter().readFile(str, DataSourceType.PASTE,
234 } catch (Exception ex)
237 if (al != null && al.getHeight() > 0)
239 str = jalview.analysis.AlignSeq.extractGaps(
240 jalview.util.Comparison.GapChars, al.getSequenceAt(0)
241 .getSequenceAsString());
243 searchBox.setSelectedItem(str);
251 protected void fireCache()
253 AppCache.getInstance().updateCache(this);
259 // TODO Auto-generated method stub
263 public JComboBox<String> getCacheComboBox()
269 public String getCacheKey()
271 return FINDER_CACHE_KEY;
275 public JComponent getNextFocusableElement()