Clover icon

Coverage Report

  1. Project Clover database Thu Nov 7 2024 10:11:34 GMT
  2. Package jalview.jbgui

File GFinder.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
60% of files have more coverage

Code metrics

8
73
15
1
287
200
23
0.32
4.87
15
1.53

Classes

Class Line # Actions
GFinder 47 73 23
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.jbgui;
22   
23    import java.awt.BorderLayout;
24    import java.awt.Font;
25    import java.awt.GridLayout;
26    import java.awt.event.ActionEvent;
27    import java.awt.event.ActionListener;
28    import java.awt.event.KeyAdapter;
29    import java.awt.event.KeyEvent;
30   
31    import javax.swing.JButton;
32    import javax.swing.JCheckBox;
33    import javax.swing.JLabel;
34    import javax.swing.JPanel;
35    import javax.swing.SwingConstants;
36    import javax.swing.SwingUtilities;
37    import javax.swing.event.CaretEvent;
38    import javax.swing.event.CaretListener;
39   
40    import jalview.datamodel.AlignmentI;
41    import jalview.io.DataSourceType;
42    import jalview.io.FileFormat;
43    import jalview.io.FormatAdapter;
44    import jalview.io.cache.JvCacheableInputBox;
45    import jalview.util.MessageManager;
46   
 
47    public class GFinder extends JPanel
48    {
49    private static final java.awt.Font VERDANA_12 = new Font("Verdana",
50    Font.PLAIN, 12);
51   
52    private static final String FINDER_CACHE_KEY = "CACHE.FINDER";
53   
54    /*
55    * if more checkboxes are wanted, increase this value
56    * and add to centrePanel in jbInit()
57    */
58    private static final int PANEL_ROWS = 4;
59   
60    protected JButton createFeatures;
61   
62    protected JButton copyToClipboard;
63   
64    protected JvCacheableInputBox<String> searchBox;
65   
66    protected JCheckBox caseSensitive;
67   
68    protected JCheckBox searchDescription;
69   
70    protected JCheckBox searchFeatures;
71   
72    protected JCheckBox ignoreHidden;
73   
 
74  0 toggle public GFinder()
75    {
76  0 try
77    {
78  0 jbInit();
79    } catch (Exception e)
80    {
81  0 e.printStackTrace();
82    }
83    }
84   
85    /**
86    * Constructs the widgets and adds them to the layout
87    */
 
88  0 toggle private void jbInit() throws Exception
89    {
90    /*
91    * border layout
92    * West: 4 rows
93    * first row 'Find'
94    * remaining rows empty
95    * Center: 4 rows
96    * first row search box
97    * second row 'match case' checkbox
98    * third row 'include description' checkbox
99    * fourth row 'ignore hidden' checkbox
100    * East: four rows
101    * first row 'find next' button
102    * second row 'find all' button
103    * third row 'new feature' button
104    * fourth row empty
105    */
106  0 this.setLayout(new BorderLayout());
107  0 JPanel eastPanel = new JPanel();
108  0 eastPanel.setLayout(new GridLayout(PANEL_ROWS, 1));
109  0 this.add(eastPanel, BorderLayout.EAST);
110  0 JPanel centrePanel = new JPanel();
111  0 centrePanel.setLayout(new GridLayout(PANEL_ROWS, 1));
112  0 this.add(centrePanel, BorderLayout.CENTER);
113  0 JPanel westPanel = new JPanel();
114  0 westPanel.setLayout(new GridLayout(PANEL_ROWS, 1));
115  0 this.add(westPanel, BorderLayout.WEST);
116   
117    /*
118    * 'Find' prompt goes top left
119    */
120  0 JLabel findLabel = new JLabel(
121    " " + MessageManager.getString("label.find") + " ");
122  0 findLabel.setFont(VERDANA_12);
123  0 westPanel.add(findLabel);
124   
125    /*
126    * search box
127    */
128  0 searchBox = new JvCacheableInputBox<>(FINDER_CACHE_KEY, 25);
129  0 searchBox.getComponent().setFont(VERDANA_12);
130  0 searchBox.addCaretListener(new CaretListener()
131    {
 
132  0 toggle @Override
133    public void caretUpdate(CaretEvent e)
134    {
135  0 textfield_caretUpdate();
136    }
137    });
138  0 searchBox.addKeyListener(new KeyAdapter()
139    {
 
140  0 toggle @Override
141    public void keyPressed(KeyEvent e)
142    {
143  0 textfield_keyPressed(e);
144    }
145    });
146  0 centrePanel.add(searchBox.getComponent());
147   
148    /*
149    * search options checkboxes
150    */
151  0 caseSensitive = new JCheckBox();
152  0 caseSensitive.setHorizontalAlignment(SwingConstants.LEFT);
153  0 caseSensitive.setText(MessageManager.getString("label.match_case"));
154   
155  0 searchDescription = new JCheckBox();
156  0 searchDescription
157    .setText(MessageManager.getString("label.include_description"));
158   
159  0 searchFeatures = new JCheckBox();
160  0 searchFeatures
161    .setText(MessageManager.getString("label.include_features"));
162   
163  0 ignoreHidden = new JCheckBox();
164  0 ignoreHidden.setText(MessageManager.getString("label.ignore_hidden"));
165  0 ignoreHidden.setToolTipText(
166    MessageManager.getString("label.ignore_hidden_tooltip"));
167   
168  0 centrePanel.add(caseSensitive);
169  0 centrePanel.add(searchDescription);
170  0 centrePanel.add(searchFeatures);
171  0 centrePanel.add(ignoreHidden);
172   
173    /*
174    * action buttons
175    */
176  0 JButton findAll = new JButton(
177    MessageManager.getString("action.find_all"));
178  0 findAll.setFont(VERDANA_12);
179  0 findAll.addActionListener(new ActionListener()
180    {
 
181  0 toggle @Override
182    public void actionPerformed(ActionEvent e)
183    {
184  0 findAll_actionPerformed();
185    }
186    });
187  0 JButton findNext = new JButton(
188    MessageManager.getString("action.find_next"));
189  0 findNext.setFont(VERDANA_12);
190  0 findNext.addActionListener(new ActionListener()
191    {
 
192  0 toggle @Override
193    public void actionPerformed(ActionEvent e)
194    {
195  0 findNext_actionPerformed();
196    }
197    });
198  0 createFeatures = new JButton();
199  0 createFeatures.setEnabled(false);
200  0 createFeatures.setFont(VERDANA_12);
201  0 createFeatures.setText(MessageManager.getString("label.new_feature"));
202  0 createFeatures.addActionListener(new ActionListener()
203    {
 
204  0 toggle @Override
205    public void actionPerformed(ActionEvent e)
206    {
207  0 createFeatures_actionPerformed();
208    }
209    });
210  0 copyToClipboard = new JButton();
211  0 copyToClipboard.setEnabled(false);
212  0 copyToClipboard.setFont(VERDANA_12);
213  0 copyToClipboard.setText(MessageManager.getString("label.copy"));
214  0 copyToClipboard.addActionListener(new ActionListener()
215    {
 
216  0 toggle @Override
217    public void actionPerformed(ActionEvent e)
218    {
219  0 copyToClipboard_actionPerformed();
220    }
221    });
222  0 eastPanel.add(findNext);
223  0 eastPanel.add(findAll);
224  0 eastPanel.add(createFeatures);
225  0 eastPanel.add(copyToClipboard);
226    }
227   
 
228  0 toggle protected void copyToClipboard_actionPerformed()
229    {
230    }
231   
 
232  0 toggle protected void textfield_keyPressed(KeyEvent e)
233    {
234  0 if (e.getKeyCode() == KeyEvent.VK_ENTER)
235    {
236  0 if (!searchBox.isPopupVisible())
237    {
238  0 e.consume();
239  0 findNext_actionPerformed();
240    }
241    }
242    }
243   
 
244  0 toggle protected void findNext_actionPerformed()
245    {
246    }
247   
 
248  0 toggle protected void findAll_actionPerformed()
249    {
250    }
251   
 
252  0 toggle public void createFeatures_actionPerformed()
253    {
254    }
255   
 
256  0 toggle public void textfield_caretUpdate()
257    {
258    // disabled as appears to be running a non-functional
259  0 if (false && searchBox.getUserInput().indexOf(">") > -1)
260    {
261  0 SwingUtilities.invokeLater(new Runnable()
262    {
 
263  0 toggle @Override
264    public void run()
265    {
266  0 String str = searchBox.getUserInput();
267  0 AlignmentI al = null;
268  0 try
269    {
270  0 al = new FormatAdapter().readFile(str, DataSourceType.PASTE,
271    FileFormat.Fasta);
272    } catch (Exception ex)
273    {
274    }
275  0 if (al != null && al.getHeight() > 0)
276    {
277  0 str = jalview.analysis.AlignSeq.extractGaps(
278    jalview.util.Comparison.GapChars,
279    al.getSequenceAt(0).getSequenceAsString());
280    // todo and what? set str as searchBox text?
281    }
282    }
283    });
284    }
285    }
286   
287    }