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.
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 import java.util.concurrent.Callable;
31 import javax.swing.JCheckBox;
32 import javax.swing.JPanel;
34 import jalview.api.AlignExportSettingsI;
35 import jalview.api.AlignViewportI;
36 import jalview.io.FileFormatI;
37 import jalview.util.MessageManager;
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
44 @SuppressWarnings("serial")
45 public class AlignExportOptions extends JPanel
47 protected JCheckBox chkHiddenSeqs = new JCheckBox();
49 protected JCheckBox chkHiddenCols = new JCheckBox();
51 protected JCheckBox chkExportAnnots = new JCheckBox();
53 protected JCheckBox chkExportFeats = new JCheckBox();
55 protected JCheckBox chkExportGrps = new JCheckBox();
57 protected AlignExportSettingsI settings;
59 private boolean isComplexAlignFile;
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
73 public static boolean isNeeded(AlignViewportI viewport,
76 if (viewport.hasHiddenColumns() || viewport.hasHiddenRows()
77 || format.isComplexAlignFile())
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>.
94 public AlignExportOptions(AlignViewportI viewport, FileFormatI format,
95 AlignExportSettingsI defaults)
97 this.settings = defaults;
98 this.isComplexAlignFile = format.isComplexAlignFile();
99 init(viewport.hasHiddenRows(), viewport.hasHiddenColumns());
100 dialog = JvOptionPane.newOptionDialog(Desktop.desktop);
104 * Shows the dialog, and runs any registered response actions that correspond
107 public void showDialog()
109 Object[] options = new Object[] { MessageManager.getString("action.ok"),
110 MessageManager.getString("action.cancel") };
111 dialog.showInternalDialog(this,
112 MessageManager.getString("label.export_settings"),
113 JvOptionPane.OK_CANCEL_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
114 options, MessageManager.getString("action.ok"));
118 * Registers a Runnable action to be performed for a particular user response
123 public void setResponseAction(Object response, Callable action)
125 dialog.setResponseHandler(response, action);
129 * Selects/deselects all enabled and shown options on 'Check all' selected or
134 void checkAllAction(boolean isSelected)
136 boolean set = chkHiddenSeqs.isEnabled() && isSelected;
137 chkHiddenSeqs.setSelected(set);
138 settings.setExportHiddenSequences(set);
140 set = chkHiddenCols.isEnabled() && isSelected;
141 chkHiddenCols.setSelected(set);
142 settings.setExportHiddenColumns(set);
144 set = isComplexAlignFile && chkExportAnnots.isEnabled() && isSelected;
145 chkExportAnnots.setSelected(set);
146 settings.setExportAnnotations(set);
148 set = isComplexAlignFile && chkExportFeats.isEnabled() && isSelected;
149 chkExportFeats.setSelected(set);
150 settings.setExportFeatures(set);
152 set = isComplexAlignFile && chkExportGrps.isEnabled() && isSelected;
153 chkExportGrps.setSelected(set);
154 settings.setExportGroups(set);
158 * Initialises the components of the display
160 * @param hasHiddenSeq
161 * @param hasHiddenCols
163 private void init(boolean hasHiddenSeq, boolean hasHiddenCols)
165 chkHiddenSeqs.setText(
166 MessageManager.getString("action.export_hidden_sequences"));
167 chkHiddenSeqs.addActionListener(new ActionListener()
170 public void actionPerformed(ActionEvent e)
172 settings.setExportHiddenSequences(chkHiddenSeqs.isSelected());
176 chkHiddenCols.setText(
177 MessageManager.getString("action.export_hidden_columns"));
178 chkHiddenCols.addActionListener(new ActionListener()
181 public void actionPerformed(ActionEvent e)
183 settings.setExportHiddenColumns(chkHiddenCols.isSelected());
188 .setText(MessageManager.getString("action.export_annotations"));
189 chkExportAnnots.addActionListener(new ActionListener()
192 public void actionPerformed(ActionEvent e)
194 settings.setExportAnnotations(chkExportAnnots.isSelected());
199 .setText(MessageManager.getString("action.export_features"));
200 chkExportFeats.addActionListener(new ActionListener()
203 public void actionPerformed(ActionEvent e)
205 settings.setExportFeatures(chkExportFeats.isSelected());
209 chkExportGrps.setText(MessageManager.getString("action.export_groups"));
210 chkExportGrps.addActionListener(new ActionListener()
213 public void actionPerformed(ActionEvent e)
215 settings.setExportGroups(chkExportGrps.isSelected());
219 JCheckBox chkAll = new JCheckBox(
220 MessageManager.getString("action.select_all"));
222 JPanel hiddenRegionConfPanel = new JPanel(new BorderLayout());
223 JPanel complexExportPanel = new JPanel(new BorderLayout());
224 this.setLayout(new BorderLayout());
226 chkAll.addItemListener(new ItemListener()
229 public void itemStateChanged(ItemEvent e)
231 checkAllAction(chkAll.isSelected());
235 hiddenRegionConfPanel.add(chkHiddenSeqs, BorderLayout.CENTER);
236 hiddenRegionConfPanel.add(chkHiddenCols, BorderLayout.SOUTH);
237 chkHiddenSeqs.setEnabled(hasHiddenSeq);
238 chkHiddenCols.setEnabled(hasHiddenCols);
240 complexExportPanel.add(chkExportAnnots, BorderLayout.NORTH);
241 complexExportPanel.add(chkExportFeats, BorderLayout.CENTER);
242 complexExportPanel.add(chkExportGrps, BorderLayout.SOUTH);
244 JPanel actionPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
245 actionPanel.add(chkAll);
247 JPanel optionsPanel = new JPanel();
248 if (this.isComplexAlignFile)
250 optionsPanel.add(complexExportPanel);
253 if (hasHiddenSeq || hasHiddenCols)
255 optionsPanel.add(hiddenRegionConfPanel);
258 add(optionsPanel, BorderLayout.NORTH);
259 add(actionPanel, BorderLayout.SOUTH);