Clover icon

Coverage Report

  1. Project Clover database Thu Dec 11 2025 10:57:44 GMT
  2. Package jalview.gui

File AlignExportOptions.java

 

Coverage histogram

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

Code metrics

4
60
12
1
257
156
15
0.25
5
12
1.25

Classes

Class Line # Actions
AlignExportOptions 45 60 15
0.026315792.6%
 

Contributing tests

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