From: tcofoegbu Date: Wed, 17 Jun 2015 10:16:58 +0000 (+0100) Subject: JAL-1780 Export settings for flatfile output X-Git-Tag: Release_2_10_0~296^2~137^2~22 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=60bf4c4778ecca475a951c4dd00731933d0b7c59;p=jalview.git JAL-1780 Export settings for flatfile output --- diff --git a/src/jalview/api/AlignExportSettingI.java b/src/jalview/api/AlignExportSettingI.java new file mode 100644 index 0000000..cf56bf3 --- /dev/null +++ b/src/jalview/api/AlignExportSettingI.java @@ -0,0 +1,77 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ + +package jalview.api; + +/** + * Abstract interface implemented by Alignment Export dialog to retrieve user + * configurations + * + * @author tcnofoegbu + * + */ +public interface AlignExportSettingI +{ + /** + * Checks if hidden sequences should be exported + * + * @return + */ + public boolean isExportHiddenSequences(); + + /** + * Checks if hidden columns shoulb be exported + * + * @return + */ + public boolean isExportHiddenColumns(); + + /** + * Checks if Annotations should be exported, note this is available for + * complex flat file exports like JSON, HTML, GFF + * + * @return + */ + public boolean isExportAnnotations(); + + /** + * Checks if SequenceFeatures should be exported, note this is available for + * complex flat file exports like JSON, HTML, GFF + * + * @return + */ + public boolean isExportFeatures(); + + /** + * Checks if SequenceGroups should be exported, note this is available for + * complex flat file exports like JSON, HTML, GFF + * + * @return + */ + public boolean isExportGroups(); + + /** + * Checks if settings/export process is cancelled + * + * @return + */ + public boolean isCancelled(); +} diff --git a/src/jalview/gui/AlignExportSettings.java b/src/jalview/gui/AlignExportSettings.java new file mode 100644 index 0000000..fe7c940 --- /dev/null +++ b/src/jalview/gui/AlignExportSettings.java @@ -0,0 +1,115 @@ +package jalview.gui; + +import java.awt.event.ActionEvent; + +import javax.swing.JDialog; +import javax.swing.JInternalFrame; +import javax.swing.JOptionPane; + +import jalview.api.AlignExportSettingI; +import jalview.jbgui.GAlignExportSettings; + +@SuppressWarnings("serial") +public class AlignExportSettings extends GAlignExportSettings implements + AlignExportSettingI +{ + protected JInternalFrame frame; + + boolean cancelled = false; + + private int width = 450; + + private int height = 200; + + JDialog dialog; + + public AlignExportSettings(boolean hasHiddenSeq, boolean hasHiddenCols, + String alignFileFormat) + { + super(hasHiddenSeq, hasHiddenCols, alignFileFormat); + + // frame = new JInternalFrame(); + // frame.setContentPane(this); + // frame.setLayer(JLayeredPane.PALETTE_LAYER); + // Desktop.addInternalFrame(frame, "Export Settings", width, height); + + JOptionPane pane = new JOptionPane(null, JOptionPane.DEFAULT_OPTION, + JOptionPane.DEFAULT_OPTION, null, new Object[] + { this }); + dialog = pane.createDialog(Desktop.desktop, "Export Settings"); + + // dialog = new JDialog(Desktop.instance, true); + // dialog.setTitle("Export Settings"); + + dialog.pack(); + dialog.setVisible(true); + + dialog.setContentPane(this); + dialog.validate(); + + } + + // public static void main(String[] args) + // { + // new AlignExportSettings(false, false, false); + // } + + // public void cancel_actionPerformed(ActionEvent e) + // { + // try + // { + // frame.setClosed(true); + // } catch (Exception ex) + // { + // } + // } + + public void ok_actionPerformed(ActionEvent e) + { + cancelled = false; + dialog.setVisible(false); + } + + public void cancel_actionPerformed(ActionEvent e) + { + cancelled = true; + dialog.setVisible(false); + } + + @Override + public boolean isExportHiddenSequences() + { + return chkHiddenSeqs.isSelected(); + } + + @Override + public boolean isExportHiddenColumns() + { + return chkHiddenCols.isSelected(); + } + + @Override + public boolean isExportAnnotations() + { + return chkExportAnnots.isSelected(); + } + + @Override + public boolean isExportFeatures() + { + return chkExportFeats.isSelected(); + } + + @Override + public boolean isExportGroups() + { + return chkExportGrps.isSelected(); + } + + @Override + public boolean isCancelled() + { + return cancelled; + } + +} diff --git a/src/jalview/jbgui/GAlignExportSettings.java b/src/jalview/jbgui/GAlignExportSettings.java new file mode 100644 index 0000000..2583b6b --- /dev/null +++ b/src/jalview/jbgui/GAlignExportSettings.java @@ -0,0 +1,146 @@ +package jalview.jbgui; + +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; + +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JPanel; + +@SuppressWarnings("serial") +public abstract class GAlignExportSettings extends JPanel +{ + protected JPanel hiddenRegionConfPanel = new JPanel(); + + protected JPanel complexExportPanel = new JPanel(); + + protected JPanel optionsPanel = new JPanel(); + + protected JPanel actionPanel = new JPanel(); + + protected BorderLayout hiddenRegionLayout = new BorderLayout(); + + protected BorderLayout complexExportLayout = new BorderLayout(); + + protected BorderLayout mainLayout = new BorderLayout(); + + protected JCheckBox chkAll = new JCheckBox("Check All"); + + protected JCheckBox chkHiddenSeqs = new JCheckBox( + "Export Hidden Sequences"); + + protected JCheckBox chkHiddenCols = new JCheckBox("Export Hidden Columns"); + + protected JCheckBox chkExportAnnots = new JCheckBox("Export Annotations"); + + protected JCheckBox chkExportFeats = new JCheckBox("Export Features"); + + protected JCheckBox chkExportGrps = new JCheckBox("Export Groups"); + + JButton btnOk = new JButton("Ok"); + + JButton btnCancel = new JButton("Cancel"); + + private boolean hasHiddenSeq, hasHiddenCols, isComplexAlignFile; + + boolean isComplexFormat = false; + + public GAlignExportSettings(boolean hasHiddenSeq, boolean hasHiddenCols, + String alignFileFormat) + { + this.hasHiddenSeq = hasHiddenSeq; + this.hasHiddenCols = hasHiddenCols; + String[] complexFormats = + { "JSON", "HTML" }; + + for (String format : complexFormats) + { + if (format.equalsIgnoreCase(alignFileFormat)) + { + this.isComplexAlignFile = true; + break; + } + } + + init(); + } + + public void init() + { + hiddenRegionConfPanel.setLayout(hiddenRegionLayout); + complexExportPanel.setLayout(complexExportLayout); + setLayout(mainLayout); + + chkAll.addItemListener(new ItemListener() + { + public void itemStateChanged(ItemEvent e) + { + checkAllAction(); + } + }); + + btnOk.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + ok_actionPerformed(e); + } + }); + + btnCancel.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + cancel_actionPerformed(e); + } + }); + + hiddenRegionConfPanel.add(chkAll, BorderLayout.NORTH); + hiddenRegionConfPanel.add(chkHiddenSeqs, BorderLayout.CENTER); + hiddenRegionConfPanel.add(chkHiddenCols, BorderLayout.SOUTH); + chkHiddenSeqs.setEnabled(hasHiddenSeq); + chkHiddenCols.setEnabled(hasHiddenCols); + + complexExportPanel.add(chkExportAnnots, BorderLayout.NORTH); + complexExportPanel.add(chkExportFeats, BorderLayout.CENTER); + complexExportPanel.add(chkExportGrps, BorderLayout.SOUTH); + + if (hasHiddenSeq || hasHiddenCols) + { + optionsPanel.add(hiddenRegionConfPanel); + } + + if (isComplexAlignFile) + { + optionsPanel.add(complexExportPanel); + } + actionPanel.add(btnCancel); + actionPanel.add(btnOk); + + add(optionsPanel, BorderLayout.NORTH); + add(actionPanel, BorderLayout.SOUTH); + + } + + + + private void checkAllAction() + { + boolean isSelected = chkAll.isSelected(); + chkHiddenSeqs.setSelected(chkHiddenSeqs.isEnabled() && isSelected); + chkHiddenCols.setSelected(chkHiddenCols.isEnabled() && isSelected); + chkExportAnnots.setSelected(isComplexAlignFile + && chkExportAnnots.isEnabled() && isSelected); + chkExportFeats.setSelected(isComplexAlignFile + && chkExportFeats.isEnabled() && isSelected); + chkExportGrps.setSelected(isComplexAlignFile + && chkExportGrps.isEnabled() && isSelected); + } + + public abstract void ok_actionPerformed(ActionEvent e); + + public abstract void cancel_actionPerformed(ActionEvent e); +}