Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.gui

File AlignExportOptions.java

 

Coverage histogram

../../img/srcFileCovDistChart1.png
52% of files have more coverage

Code metrics

6
62
12
1
260
159
18
0.29
5.17
12
1.5

Classes

Class Line # Actions
AlignExportOptions 44 62 18
0.055%
 

Contributing tests

This file is covered by 4 tests. .

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.gui;
22   
23    import jalview.api.AlignExportSettingsI;
24    import jalview.api.AlignViewportI;
25    import jalview.io.FileFormatI;
26    import jalview.util.MessageManager;
27   
28    import java.awt.BorderLayout;
29    import java.awt.FlowLayout;
30    import java.awt.event.ActionEvent;
31    import java.awt.event.ActionListener;
32    import java.awt.event.ItemEvent;
33    import java.awt.event.ItemListener;
34   
35    import javax.swing.JCheckBox;
36    import javax.swing.JPanel;
37   
38    /**
39    * A dialog that allows the user to specify whether to include hidden columns or
40    * sequences in an alignment export, and possibly features, annotations and
41    * groups, if applicable to the output file format
42    */
43    @SuppressWarnings("serial")
 
44    public class AlignExportOptions extends JPanel
45    {
46    protected JCheckBox chkHiddenSeqs = new JCheckBox();
47   
48    protected JCheckBox chkHiddenCols = new JCheckBox();
49   
50    protected JCheckBox chkExportAnnots = new JCheckBox();
51   
52    protected JCheckBox chkExportFeats = new JCheckBox();
53   
54    protected JCheckBox chkExportGrps = new JCheckBox();
55   
56    protected AlignExportSettingsI settings;
57   
58    private boolean isComplexAlignFile;
59   
60    JvOptionPane dialog;
61   
62    /**
63    * A convenience method that answers true if this dialog should be shown -
64    * that is, if the alignment has any hidden rows or columns, or if the file
65    * format is one that can (optionally) represent annotations, features or
66    * groups data - else false
67    *
68    * @param viewport
69    * @param format
70    * @return
71    */
 
72  43 toggle public static boolean isNeeded(AlignViewportI viewport,
73    FileFormatI format)
74    {
75  43 if (viewport.hasHiddenColumns() || viewport.hasHiddenRows()
76    || format.isComplexAlignFile())
77    {
78  0 return true;
79    }
80  43 return false;
81    }
82   
83    /**
84    * Constructor that passes in an initial set of export options. User choices
85    * in the dialog should update this object, and the <em>same</em> object
86    * should be used in any action handler set by calling
87    * <code>setResponseAction</code>.
88    *
89    * @param viewport
90    * @param format
91    * @param defaults
92    */
 
93  0 toggle public AlignExportOptions(AlignViewportI viewport, FileFormatI format,
94    AlignExportSettingsI defaults)
95    {
96  0 this.settings = defaults;
97  0 this.isComplexAlignFile = format.isComplexAlignFile();
98  0 init(viewport.hasHiddenRows(), viewport.hasHiddenColumns());
99  0 dialog = JvOptionPane.newOptionDialog(Desktop.desktop);
100    }
101   
102    /**
103    * Shows the dialog, and runs any registered response actions that correspond
104    * to user choices
105    */
 
106  0 toggle public void showDialog()
107    {
108  0 Object[] options = new Object[] { MessageManager.getString("action.ok"),
109    MessageManager.getString("action.cancel") };
110  0 dialog.showInternalDialog(this,
111    MessageManager.getString("label.export_settings"),
112    JvOptionPane.OK_CANCEL_OPTION, JvOptionPane.PLAIN_MESSAGE,
113    null, options, MessageManager.getString("action.ok"));
114    }
115   
116    /**
117    * Registers a Runnable action to be performed for a particular user response
118    * in the dialog
119    *
120    * @param action
121    */
 
122  0 toggle public void setResponseAction(Object response, Runnable action)
123    {
124  0 dialog.setResponseHandler(response, action);
125    }
126   
127    /**
128    * Selects/deselects all enabled and shown options on 'Check all' selected or
129    * deselected
130    *
131    * @param isSelected
132    */
 
133  0 toggle void checkAllAction(boolean isSelected)
134    {
135  0 boolean set = chkHiddenSeqs.isEnabled() && isSelected;
136  0 chkHiddenSeqs.setSelected(set);
137  0 settings.setExportHiddenSequences(set);
138   
139  0 set = chkHiddenCols.isEnabled() && isSelected;
140  0 chkHiddenCols.setSelected(set);
141  0 settings.setExportHiddenColumns(set);
142   
143  0 set = isComplexAlignFile && chkExportAnnots.isEnabled() && isSelected;
144  0 chkExportAnnots.setSelected(set);
145  0 settings.setExportAnnotations(set);
146   
147  0 set = isComplexAlignFile && chkExportFeats.isEnabled() && isSelected;
148  0 chkExportFeats.setSelected(set);
149  0 settings.setExportFeatures(set);
150   
151  0 set = isComplexAlignFile && chkExportGrps.isEnabled() && isSelected;
152  0 chkExportGrps.setSelected(set);
153  0 settings.setExportGroups(set);
154    }
155   
156    /**
157    * Initialises the components of the display
158    *
159    * @param hasHiddenSeq
160    * @param hasHiddenCols
161    */
 
162  0 toggle private void init(boolean hasHiddenSeq, boolean hasHiddenCols)
163    {
164  0 chkHiddenSeqs.setText(
165    MessageManager.getString("action.export_hidden_sequences"));
166  0 chkHiddenSeqs.addActionListener(new ActionListener()
167    {
 
168  0 toggle @Override
169    public void actionPerformed(ActionEvent e)
170    {
171  0 settings.setExportHiddenSequences(chkHiddenSeqs.isSelected());
172    }
173    });
174   
175  0 chkHiddenCols.setText(
176    MessageManager.getString("action.export_hidden_columns"));
177  0 chkHiddenCols.addActionListener(new ActionListener()
178    {
 
179  0 toggle @Override
180    public void actionPerformed(ActionEvent e)
181    {
182  0 settings.setExportHiddenColumns(chkHiddenCols.isSelected());
183    }
184    });
185   
186  0 chkExportAnnots
187    .setText(MessageManager.getString("action.export_annotations"));
188  0 chkExportAnnots.addActionListener(new ActionListener()
189    {
 
190  0 toggle @Override
191    public void actionPerformed(ActionEvent e)
192    {
193  0 settings.setExportAnnotations(chkExportAnnots.isSelected());
194    }
195    });
196   
197  0 chkExportFeats
198    .setText(MessageManager.getString("action.export_features"));
199  0 chkExportFeats.addActionListener(new ActionListener()
200    {
 
201  0 toggle @Override
202    public void actionPerformed(ActionEvent e)
203    {
204  0 settings.setExportFeatures(chkExportFeats.isSelected());
205    }
206    });
207   
208  0 chkExportGrps.setText(MessageManager.getString("action.export_groups"));
209  0 chkExportGrps.addActionListener(new ActionListener()
210    {
 
211  0 toggle @Override
212    public void actionPerformed(ActionEvent e)
213    {
214  0 settings.setExportGroups(chkExportGrps.isSelected());
215    }
216    });
217   
218  0 JCheckBox chkAll = new JCheckBox(
219    MessageManager.getString("action.select_all"));
220   
221  0 JPanel hiddenRegionConfPanel = new JPanel(new BorderLayout());
222  0 JPanel complexExportPanel = new JPanel(new BorderLayout());
223  0 this.setLayout(new BorderLayout());
224   
225  0 chkAll.addItemListener(new ItemListener()
226    {
 
227  0 toggle @Override
228    public void itemStateChanged(ItemEvent e)
229    {
230  0 checkAllAction(chkAll.isSelected());
231    }
232    });
233   
234  0 hiddenRegionConfPanel.add(chkHiddenSeqs, BorderLayout.CENTER);
235  0 hiddenRegionConfPanel.add(chkHiddenCols, BorderLayout.SOUTH);
236  0 chkHiddenSeqs.setEnabled(hasHiddenSeq);
237  0 chkHiddenCols.setEnabled(hasHiddenCols);
238   
239  0 complexExportPanel.add(chkExportAnnots, BorderLayout.NORTH);
240  0 complexExportPanel.add(chkExportFeats, BorderLayout.CENTER);
241  0 complexExportPanel.add(chkExportGrps, BorderLayout.SOUTH);
242   
243  0 JPanel actionPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
244  0 actionPanel.add(chkAll);
245   
246  0 JPanel optionsPanel = new JPanel();
247  0 if (this.isComplexAlignFile)
248    {
249  0 optionsPanel.add(complexExportPanel);
250    }
251   
252  0 if (hasHiddenSeq || hasHiddenCols)
253    {
254  0 optionsPanel.add(hiddenRegionConfPanel);
255    }
256   
257  0 add(optionsPanel, BorderLayout.NORTH);
258  0 add(actionPanel, BorderLayout.SOUTH);
259    }
260    }