Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.gui

File AlignExportOptions.java

 

Coverage histogram

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

Code metrics

6
62
12
1
261
160
18
0.29
5.17
12
1.5

Classes

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