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 jalview.api.AlignExportSettingsI;
24 import jalview.api.AlignViewportI;
25 import jalview.io.FileFormatI;
26 import jalview.util.MessageManager;
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;
35 import javax.swing.JCheckBox;
36 import javax.swing.JPanel;
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
43 @SuppressWarnings("serial")
44 public class AlignExportOptions extends JPanel
46 protected JCheckBox chkHiddenSeqs = new JCheckBox();
48 protected JCheckBox chkHiddenCols = new JCheckBox();
50 protected JCheckBox chkExportAnnots = new JCheckBox();
52 protected JCheckBox chkExportFeats = new JCheckBox();
54 protected JCheckBox chkExportGrps = new JCheckBox();
56 protected AlignExportSettingsI settings;
58 private boolean isComplexAlignFile;
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
72 public static boolean isNeeded(AlignViewportI viewport,
75 if (viewport.hasHiddenColumns() || viewport.hasHiddenRows()
76 || format.isComplexAlignFile())
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>.
93 public AlignExportOptions(AlignViewportI viewport, FileFormatI format,
94 AlignExportSettingsI defaults)
96 this.settings = defaults;
97 this.isComplexAlignFile = format.isComplexAlignFile();
98 init(viewport.hasHiddenRows(), viewport.hasHiddenColumns());
99 dialog = JvOptionPane.newOptionDialog(Desktop.getDesktopPane());
103 * Shows the dialog, and runs any registered response actions that correspond
106 public void showDialog()
108 Object[] options = new Object[] { MessageManager.getString("action.ok"),
109 MessageManager.getString("action.cancel") };
110 dialog.showInternalDialog(this,
111 MessageManager.getString("label.export_settings"),
112 JvOptionPane.OK_CANCEL_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
113 options, MessageManager.getString("action.ok"));
117 * Registers a Runnable action to be performed for a particular user response
122 public void setResponseAction(Object response, Runnable action)
124 dialog.setResponseHandler(response, action);
128 * Selects/deselects all enabled and shown options on 'Check all' selected or
133 void checkAllAction(boolean isSelected)
135 boolean set = chkHiddenSeqs.isEnabled() && isSelected;
136 chkHiddenSeqs.setSelected(set);
137 settings.setExportHiddenSequences(set);
139 set = chkHiddenCols.isEnabled() && isSelected;
140 chkHiddenCols.setSelected(set);
141 settings.setExportHiddenColumns(set);
143 set = isComplexAlignFile && chkExportAnnots.isEnabled() && isSelected;
144 chkExportAnnots.setSelected(set);
145 settings.setExportAnnotations(set);
147 set = isComplexAlignFile && chkExportFeats.isEnabled() && isSelected;
148 chkExportFeats.setSelected(set);
149 settings.setExportFeatures(set);
151 set = isComplexAlignFile && chkExportGrps.isEnabled() && isSelected;
152 chkExportGrps.setSelected(set);
153 settings.setExportGroups(set);
157 * Initialises the components of the display
159 * @param hasHiddenSeq
160 * @param hasHiddenCols
162 private void init(boolean hasHiddenSeq, boolean hasHiddenCols)
164 chkHiddenSeqs.setText(
165 MessageManager.getString("action.export_hidden_sequences"));
166 chkHiddenSeqs.addActionListener(new ActionListener()
169 public void actionPerformed(ActionEvent e)
171 settings.setExportHiddenSequences(chkHiddenSeqs.isSelected());
175 chkHiddenCols.setText(
176 MessageManager.getString("action.export_hidden_columns"));
177 chkHiddenCols.addActionListener(new ActionListener()
180 public void actionPerformed(ActionEvent e)
182 settings.setExportHiddenColumns(chkHiddenCols.isSelected());
187 .setText(MessageManager.getString("action.export_annotations"));
188 chkExportAnnots.addActionListener(new ActionListener()
191 public void actionPerformed(ActionEvent e)
193 settings.setExportAnnotations(chkExportAnnots.isSelected());
198 .setText(MessageManager.getString("action.export_features"));
199 chkExportFeats.addActionListener(new ActionListener()
202 public void actionPerformed(ActionEvent e)
204 settings.setExportFeatures(chkExportFeats.isSelected());
208 chkExportGrps.setText(MessageManager.getString("action.export_groups"));
209 chkExportGrps.addActionListener(new ActionListener()
212 public void actionPerformed(ActionEvent e)
214 settings.setExportGroups(chkExportGrps.isSelected());
218 JCheckBox chkAll = new JCheckBox(
219 MessageManager.getString("action.select_all"));
221 JPanel hiddenRegionConfPanel = new JPanel(new BorderLayout());
222 JPanel complexExportPanel = new JPanel(new BorderLayout());
223 this.setLayout(new BorderLayout());
225 chkAll.addItemListener(new ItemListener()
228 public void itemStateChanged(ItemEvent e)
230 checkAllAction(chkAll.isSelected());
234 hiddenRegionConfPanel.add(chkHiddenSeqs, BorderLayout.CENTER);
235 hiddenRegionConfPanel.add(chkHiddenCols, BorderLayout.SOUTH);
236 chkHiddenSeqs.setEnabled(hasHiddenSeq);
237 chkHiddenCols.setEnabled(hasHiddenCols);
239 complexExportPanel.add(chkExportAnnots, BorderLayout.NORTH);
240 complexExportPanel.add(chkExportFeats, BorderLayout.CENTER);
241 complexExportPanel.add(chkExportGrps, BorderLayout.SOUTH);
243 JPanel actionPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
244 actionPanel.add(chkAll);
246 JPanel optionsPanel = new JPanel();
247 if (this.isComplexAlignFile)
249 optionsPanel.add(complexExportPanel);
252 if (hasHiddenSeq || hasHiddenCols)
254 optionsPanel.add(hiddenRegionConfPanel);
257 add(optionsPanel, BorderLayout.NORTH);
258 add(actionPanel, BorderLayout.SOUTH);