+++ /dev/null
-/*
- * 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 <http://www.gnu.org/licenses/>.
- * The Jalview Authors are detailed in the 'AUTHORS' file.
- */
-
-package jalview.api;
-
-import jalview.datamodel.AlignExportSettingBeanI;
-import jalview.datamodel.AlignmentExportData;
-
-import java.awt.event.ActionListener;
-
-/**
- * additional methods implemented by the export settings dialog
- *
- */
-public interface AlignExportSettingI extends AlignExportSettingBeanI
-{
-
- AlignmentExportData getAlignExportData();
-
- /**
- * the export data action to be performed - make sure you check isCancelled in this method first
- * @param actionListener
- */
-
- public void addActionListener(ActionListener actionListener);
-
- /**
- * show the dialog
- */
- public void doShowSettings();
-
-}
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+
+package jalview.api;
+
+/**
+ * An interface describing settings for including or excluding data when an
+ * alignment is output
+ *
+ */
+public interface AlignExportSettingsI
+{
+ /**
+ * Answers true if hidden sequences should be exported, false if not
+ *
+ * @return
+ */
+ boolean isExportHiddenSequences();
+
+ /**
+ * Answers true if hidden columns should be exported, false if not
+ *
+ * @return
+ */
+ boolean isExportHiddenColumns();
+
+ /**
+ * Answers true if Annotations should be exported. This is available for
+ * complex flat file exports like JSON, HTML, GFF.
+ *
+ * @return
+ */
+ boolean isExportAnnotations();
+
+ /**
+ * Answers true if Sequence Features should be exported. This is available for
+ * complex flat file exports like JSON, HTML, GFF.
+ *
+ * @return
+ */
+ boolean isExportFeatures();
+
+ /**
+ * Answers true if Sequence Groups should be exported. This is available for
+ * complex flat file exports like JSON, HTML, GFF.
+ *
+ * @return
+ */
+ boolean isExportGroups();
+
+ void setExportHiddenSequences(boolean b);
+
+ void setExportHiddenColumns(boolean b);
+
+ void setExportAnnotations(boolean b);
+
+ void setExportFeatures(boolean b);
+
+ void setExportGroups(boolean b);
+}
import jalview.analysis.Conservation;
import jalview.analysis.TreeModel;
import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentExportData;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.AlignmentView;
import jalview.datamodel.ColumnSelection;
@Override
void setProteinFontAsCdna(boolean b);
- public abstract TreeModel getCurrentTree();
+ TreeModel getCurrentTree();
- public abstract void setCurrentTree(TreeModel tree);
+ void setCurrentTree(TreeModel tree);
+
+ /**
+ * Answers a data bean containing data for export as configured by the
+ * supplied options
+ *
+ * @param options
+ * @return
+ */
+ AlignmentExportData getAlignExportData(AlignExportSettingsI options);
}
+++ /dev/null
-package jalview.datamodel;
-
-/**
- * * Abstract interface implemented by Alignment Export dialog to retrieve user
- * configurations
- *
- * @author tcnofoegbu
- *
- */
-public interface AlignExportSettingBeanI
-{
-
- /**
- * 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();
-
- public boolean isCancelled();
-}
--- /dev/null
+package jalview.datamodel;
+
+import jalview.api.AlignExportSettingsI;
+
+/**
+ * Export options that may be constructed as 'all' or 'none' (and further
+ * adjusted if wanted)
+ */
+public class AlignExportSettingsAdapter implements AlignExportSettingsI
+{
+ private boolean exportHiddenSeqs;
+
+ private boolean exportHiddenCols;
+
+ private boolean exportAnnotations;
+
+ private boolean exportFeatures;
+
+ private boolean exportGroups;
+
+ /**
+ * Constructor sets all options to either true or false
+ *
+ * @param defaultOption
+ */
+ public AlignExportSettingsAdapter(boolean defaultOption)
+ {
+ exportAnnotations = defaultOption;
+ exportFeatures = defaultOption;
+ exportGroups = defaultOption;
+ exportHiddenCols = defaultOption;
+ exportHiddenSeqs = defaultOption;
+ }
+
+ @Override
+ public boolean isExportHiddenSequences()
+ {
+ return exportHiddenSeqs;
+ }
+
+ @Override
+ public boolean isExportHiddenColumns()
+ {
+ return exportHiddenCols;
+ }
+
+ @Override
+ public boolean isExportAnnotations()
+ {
+ return exportAnnotations;
+ }
+
+ @Override
+ public boolean isExportFeatures()
+ {
+ return exportFeatures;
+ }
+
+ @Override
+ public boolean isExportGroups()
+ {
+ return exportGroups;
+ }
+
+ public void setExportHiddenSequences(boolean exportHiddenSeqs)
+ {
+ this.exportHiddenSeqs = exportHiddenSeqs;
+ }
+
+ public void setExportHiddenColumns(boolean exportHiddenCols)
+ {
+ this.exportHiddenCols = exportHiddenCols;
+ }
+
+ public void setExportAnnotations(boolean exportAnnotations)
+ {
+ this.exportAnnotations = exportAnnotations;
+ }
+
+ public void setExportFeatures(boolean exportFeatures)
+ {
+ this.exportFeatures = exportFeatures;
+ }
+
+ public void setExportGroups(boolean exportGroups)
+ {
+ this.exportGroups = exportGroups;
+ }
+
+}
*/
package jalview.datamodel;
-import jalview.api.AlignExportSettingI;
-
public class AlignmentExportData
{
private AlignmentI alignment;
private int[] startEnd;
- private AlignExportSettingI settings;
-
public AlignmentExportData(AlignmentI align, String[] ommit,
- int[] startEnd, AlignExportSettingI settings)
+ int[] startEnd)
{
this.alignment = align;
this.omitHidden = ommit;
this.startEnd = startEnd;
- this.settings = settings;
}
public AlignmentI getAlignment()
{
this.startEnd = startEnd;
}
-
- public AlignExportSettingI getSettings()
- {
- return settings;
- }
-
- public void setSettings(AlignExportSettingI settings)
- {
- this.settings = settings;
- }
}
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.gui;
+
+import jalview.api.AlignExportSettingsI;
+import jalview.api.AlignViewportI;
+import jalview.io.FileFormatI;
+import jalview.util.MessageManager;
+import jalview.util.dialogrunner.RunResponse;
+
+import java.awt.BorderLayout;
+import java.awt.FlowLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+
+import javax.swing.JCheckBox;
+import javax.swing.JPanel;
+
+/**
+ * A dialog that allows the user to specify whether to include hidden columns or
+ * sequences in an alignment export, and possibly features, annotations and
+ * groups, if applicable to the output file format
+ */
+@SuppressWarnings("serial")
+public class AlignExportOptions extends JPanel
+{
+ protected JCheckBox chkHiddenSeqs = new JCheckBox();
+
+ protected JCheckBox chkHiddenCols = new JCheckBox();
+
+ protected JCheckBox chkExportAnnots = new JCheckBox();
+
+ protected JCheckBox chkExportFeats = new JCheckBox();
+
+ protected JCheckBox chkExportGrps = new JCheckBox();
+
+ protected AlignExportSettingsI settings;
+
+ private boolean isComplexAlignFile;
+
+ JvOptionPane dialog;
+
+ /**
+ * A convenience method that answers true if this dialog should be shown -
+ * that is, if the alignment has any hidden rows or columns, or if the file
+ * format is one that can (optionally) represent annotations, features or
+ * groups data - else false
+ *
+ * @param viewport
+ * @param format
+ * @return
+ */
+ public static boolean isNeeded(AlignViewportI viewport,
+ FileFormatI format)
+ {
+ if (viewport.hasHiddenColumns() || viewport.hasHiddenRows()
+ || format.isComplexAlignFile())
+ {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Constructor that passes in an initial set of export options. User choices
+ * in the dialog should update this object, and the <em>same</em> object
+ * should be used in any action handler set by calling
+ * <code>setResponseAction</code>.
+ *
+ * @param viewport
+ * @param format
+ * @param defaults
+ */
+ public AlignExportOptions(AlignViewportI viewport, FileFormatI format,
+ AlignExportSettingsI defaults)
+ {
+ this.settings = defaults;
+ this.isComplexAlignFile = format.isComplexAlignFile();
+ init(viewport.hasHiddenRows(), viewport.hasHiddenColumns());
+ dialog = JvOptionPane.newOptionDialog(Desktop.desktop);
+ }
+
+ /**
+ * Shows the dialog, and runs any registered response actions that correspond
+ * to user choices
+ */
+ public void showDialog()
+ {
+ Object[] options = new Object[] { MessageManager.getString("action.ok"),
+ MessageManager.getString("action.cancel") };
+ dialog.showInternalDialog(this,
+ MessageManager.getString("label.export_settings"),
+ JvOptionPane.OK_CANCEL_OPTION, JvOptionPane.PLAIN_MESSAGE,
+ null, options, MessageManager.getString("action.ok"));
+ }
+
+ /**
+ * Registers a Runnable action to be performed for a particular user response
+ * in the dialog
+ *
+ * @param action
+ */
+ public void setResponseAction(RunResponse action)
+ {
+ dialog.response(action);
+ }
+
+ /**
+ * Selects/deselects all enabled and shown options on 'Check all' selected or
+ * deselected
+ *
+ * @param isSelected
+ */
+ void checkAllAction(boolean isSelected)
+ {
+ boolean set = chkHiddenSeqs.isEnabled() && isSelected;
+ chkHiddenSeqs.setSelected(set);
+ settings.setExportHiddenSequences(set);
+
+ set = chkHiddenCols.isEnabled() && isSelected;
+ chkHiddenCols.setSelected(set);
+ settings.setExportHiddenColumns(set);
+
+ set = isComplexAlignFile && chkExportAnnots.isEnabled() && isSelected;
+ chkExportAnnots.setSelected(set);
+ settings.setExportAnnotations(set);
+
+ set = isComplexAlignFile && chkExportFeats.isEnabled() && isSelected;
+ chkExportFeats.setSelected(set);
+ settings.setExportFeatures(set);
+
+ set = isComplexAlignFile && chkExportGrps.isEnabled() && isSelected;
+ chkExportGrps.setSelected(set);
+ settings.setExportGroups(set);
+ }
+
+ /**
+ * Initialises the components of the display
+ *
+ * @param hasHiddenSeq
+ * @param hasHiddenCols
+ */
+ private void init(boolean hasHiddenSeq, boolean hasHiddenCols)
+ {
+ chkHiddenSeqs.setText(
+ MessageManager.getString("action.export_hidden_sequences"));
+ chkHiddenSeqs.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ settings.setExportHiddenSequences(chkHiddenSeqs.isSelected());
+ }
+ });
+
+ chkHiddenCols.setText(
+ MessageManager.getString("action.export_hidden_columns"));
+ chkHiddenCols.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ settings.setExportHiddenColumns(chkHiddenCols.isSelected());
+ }
+ });
+
+ chkExportAnnots
+ .setText(MessageManager.getString("action.export_annotations"));
+ chkExportAnnots.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ settings.setExportAnnotations(chkExportAnnots.isSelected());
+ }
+ });
+
+ chkExportFeats
+ .setText(MessageManager.getString("action.export_features"));
+ chkExportFeats.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ settings.setExportFeatures(chkExportFeats.isSelected());
+ }
+ });
+
+ chkExportGrps.setText(MessageManager.getString("action.export_groups"));
+ chkExportGrps.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ settings.setExportGroups(chkExportGrps.isSelected());
+ }
+ });
+
+ JCheckBox chkAll = new JCheckBox(
+ MessageManager.getString("action.select_all"));
+
+ JPanel hiddenRegionConfPanel = new JPanel(new BorderLayout());
+ JPanel complexExportPanel = new JPanel(new BorderLayout());
+ this.setLayout(new BorderLayout());
+
+ chkAll.addItemListener(new ItemListener()
+ {
+ @Override
+ public void itemStateChanged(ItemEvent e)
+ {
+ checkAllAction(chkAll.isSelected());
+ }
+ });
+
+ 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);
+
+ JPanel actionPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
+ actionPanel.add(chkAll);
+
+ JPanel optionsPanel = new JPanel();
+ if (this.isComplexAlignFile)
+ {
+ optionsPanel.add(complexExportPanel);
+ }
+
+ if (hasHiddenSeq || hasHiddenCols)
+ {
+ optionsPanel.add(hiddenRegionConfPanel);
+ }
+
+ add(optionsPanel, BorderLayout.NORTH);
+ add(actionPanel, BorderLayout.SOUTH);
+ }
+}
+++ /dev/null
-/*
- * 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 <http://www.gnu.org/licenses/>.
- * The Jalview Authors are detailed in the 'AUTHORS' file.
- */
-package jalview.gui;
-
-import jalview.api.AlignExportSettingI;
-import jalview.api.AlignViewportI;
-import jalview.bin.Jalview;
-import jalview.datamodel.AlignExportSettingBeanI;
-import jalview.datamodel.AlignmentExportData;
-import jalview.datamodel.AlignmentI;
-import jalview.datamodel.HiddenSequences;
-import jalview.io.FileFormatI;
-import jalview.jbgui.GAlignExportSettings;
-import jalview.util.MessageManager;
-import jalview.util.dialogrunner.RunResponse;
-
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-
-import javax.swing.JOptionPane;
-
-@SuppressWarnings("serial")
-public class AlignExportSettings extends GAlignExportSettings
- implements AlignExportSettingI
-{
- boolean cancelled = false;
-
- JvOptionPane dialog;
-
- AlignmentPanel alignPanel;
-
- /**
- * settings provided at construction override the GUI
- */
- AlignExportSettingBeanI override=null;
-
- public AlignExportSettings(AlignmentPanel alignmentPanel,
- FileFormatI format, AlignExportSettingBeanI exportSettings)
- {
- super(alignmentPanel.getAlignViewport().hasHiddenRows(),
- alignmentPanel.getAlignViewport().hasHiddenColumns(), format);
- this.alignPanel = alignmentPanel;
- override = exportSettings;
- }
-
- /**
- * @param viewport
- * @return a bean with data for export
- */
- @Override
- public AlignmentExportData getAlignExportData()
- {
- // settings.isExportAnnotations();
-
- AlignmentI alignmentToExport = null;
- String[] omitHidden = null;
- AlignViewportI viewport = alignPanel.getAlignViewport();
-
- alignmentToExport = viewport.getAlignment();
-
- if (viewport.hasHiddenColumns() && !isExportHiddenColumns())
- {
- omitHidden = viewport.getViewAsString(false,
- isExportHiddenSequences());
- }
-
- int[] alignmentStartEnd = new int[2];
- if (viewport.hasHiddenRows() && isExportHiddenSequences())
- {
- alignmentToExport = viewport.getAlignment().getHiddenSequences()
- .getFullAlignment();
- }
- else
- {
- alignmentToExport = viewport.getAlignment();
- }
- alignmentStartEnd = viewport.getAlignment().getHiddenColumns()
- .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
- AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
- omitHidden, alignmentStartEnd, this);
- return ed;
- }
-
- @Override
- public void ok_actionPerformed(ActionEvent e)
- {
- cancelled = false;
- }
-
- @Override
- public void cancel_actionPerformed(ActionEvent e)
- {
- cancelled = true;
- }
-
- @Override
- public boolean isExportHiddenSequences()
- {
- return override!=null ? override.isExportHiddenSequences() : chkHiddenSeqs.isSelected();
- }
-
- @Override
- public boolean isExportHiddenColumns()
- {
- return override!=null ? override.isExportHiddenColumns() : chkHiddenCols.isSelected();
- }
-
- @Override
- public boolean isExportAnnotations()
- {
- return override!=null ? override.isExportAnnotations() : chkExportAnnots.isSelected();
- }
-
- @Override
- public boolean isExportFeatures()
- {
- return override!=null ? override.isExportFeatures() : chkExportFeats.isSelected();
- }
-
- @Override
- public boolean isExportGroups()
- {
- return override!=null ? override.isExportGroups() : chkExportGrps.isSelected();
- }
-
- @Override
- public boolean isCancelled()
- {
- return override!=null ? override.isCancelled() : cancelled;
- }
-
- ActionListener afterShownAction = null;
-
- @Override
- public void addActionListener(ActionListener actionListener)
- {
- afterShownAction = actionListener;
- }
-
- @Override
- public void doShowSettings()
- {
- if (!Jalview.isHeadlessMode() && override==null && isShowDialog())
- {
-
- dialog = JvOptionPane.newOptionDialog(alignPanel);
-
- dialog.response(new RunResponse(JvOptionPane.OK_OPTION)
- {
- public void run()
- {
- ok_actionPerformed(null);
- afterShownAction.actionPerformed(null);
- }
- }).defaultResponse(new Runnable()
- {
- @Override
- public void run()
- {
- cancelled=true;
- afterShownAction.actionPerformed(null);
- }
- });
- String ok = MessageManager.getString("action.ok"),
- cancel = MessageManager.getString("action.cancel");
- dialog.showInternalDialog(this,
- MessageManager.getString("label.export_settings"),
- JOptionPane.DEFAULT_OPTION, JvOptionPane.DEFAULT_OPTION, null,
- new Object[]
- { ok, cancel }, ok);
- }
- else
- {
- afterShownAction.actionPerformed(null);
- }
- }
-
-}
import jalview.analysis.Dna;
import jalview.analysis.ParseProperties;
import jalview.analysis.SequenceIdMatcher;
-import jalview.api.AlignExportSettingI;
+import jalview.api.AlignExportSettingsI;
import jalview.api.AlignViewControllerGuiI;
import jalview.api.AlignViewControllerI;
import jalview.api.AlignViewportI;
import jalview.commands.RemoveGapsCommand;
import jalview.commands.SlideSequencesCommand;
import jalview.commands.TrimRegionCommand;
-import jalview.datamodel.AlignExportSettingBeanI;
+import jalview.datamodel.AlignExportSettingsAdapter;
import jalview.datamodel.AlignedCodonFrame;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentAnnotation;
int value = chooser.showSaveDialog(this);
- if (value == JalviewFileChooser.APPROVE_OPTION)
+ if (value != JalviewFileChooser.APPROVE_OPTION)
{
+ return;
+ }
+ currentFileFormat = chooser.getSelectedFormat();
+ // todo is this (2005) test now obsolete - value is never null?
+ while (currentFileFormat == null)
+ {
+ JvOptionPane.showInternalMessageDialog(Desktop.desktop,
+ MessageManager
+ .getString("label.select_file_format_before_saving"),
+ MessageManager.getString("label.file_format_not_specified"),
+ JvOptionPane.WARNING_MESSAGE);
currentFileFormat = chooser.getSelectedFormat();
- while (currentFileFormat == null)
+ value = chooser.showSaveDialog(this);
+ if (value != JalviewFileChooser.APPROVE_OPTION)
{
- JvOptionPane.showInternalMessageDialog(Desktop.desktop,
- MessageManager.getString(
- "label.select_file_format_before_saving"),
- MessageManager.getString("label.file_format_not_specified"),
- JvOptionPane.WARNING_MESSAGE);
- currentFileFormat = chooser.getSelectedFormat();
- value = chooser.showSaveDialog(this);
- if (value != JalviewFileChooser.APPROVE_OPTION)
- {
- return;
- }
+ return;
}
+ }
- fileName = chooser.getSelectedFile().getPath();
+ fileName = chooser.getSelectedFile().getPath();
- Cache.setProperty("DEFAULT_FILE_FORMAT", currentFileFormat.getName());
- Cache.setProperty("LAST_DIRECTORY", fileName);
- saveAlignment(fileName, currentFileFormat);
- }
+ Cache.setProperty("DEFAULT_FILE_FORMAT", currentFileFormat.getName());
+ Cache.setProperty("LAST_DIRECTORY", fileName);
+ saveAlignment(fileName, currentFileFormat);
}
- private boolean lastSaveSuccessful = false;
+ boolean lastSaveSuccessful = false;
- private FileFormatI lastFormatSaved;
+ FileFormatI lastFormatSaved;
- private String lastFilenameSaved;
+ String lastFilenameSaved;
/**
* Raise a dialog or status message for the last call to saveAlignment.
return lastSaveSuccessful;
}
+ /**
+ * Saves the alignment to the specified file path, in the specified format,
+ * which may be an alignment format, or Jalview project format. If the
+ * alignment has hidden regions, or the format is one capable of including
+ * non-sequence data (features, annotations, groups), then the user may be
+ * prompted to specify what to include in the output.
+ *
+ * @param file
+ * @param format
+ */
public void saveAlignment(String file, FileFormatI format)
{
lastSaveSuccessful = false;
lastFilenameSaved = file;
lastFormatSaved = format;
- AlignFrame us = this;
+
if (FileFormat.Jalview.equals(format))
{
String shortName = title;
-
- if (shortName.indexOf(java.io.File.separatorChar) > -1)
+ if (shortName.indexOf(File.separatorChar) > -1)
{
shortName = shortName.substring(
- shortName.lastIndexOf(java.io.File.separatorChar) + 1);
+ shortName.lastIndexOf(File.separatorChar) + 1);
}
-
lastSaveSuccessful = new Jalview2XML().saveAlignment(this, file,
shortName);
+ return;
}
- else
+
+ AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
+ RunResponse cancelAction = new RunResponse(JvOptionPane.CANCEL_OPTION)
{
- AlignExportSettingI settings = getAlignmentForExport(format,
- alignPanel, null);
- settings.addActionListener(new ActionListener()
+ @Override
+ public void run()
{
- @Override
- public void actionPerformed(ActionEvent e)
+ lastSaveSuccessful = false;
+ }
+ };
+ RunResponse outputAction = new RunResponse(JvOptionPane.OK_OPTION)
+ {
+ @Override
+ public void run()
+ {
+ // todo defer this to inside formatSequences (or later)
+ AlignmentExportData exportData = viewport
+ .getAlignExportData(options);
+ String output = new FormatAdapter(alignPanel, options)
+ .formatSequences(format, exportData.getAlignment(),
+ exportData.getOmitHidden(),
+ exportData.getStartEndPostions(),
+ viewport.getAlignment().getHiddenColumns());
+ if (output == null)
{
-
- if (settings.isCancelled())
+ lastSaveSuccessful = false;
+ }
+ else
+ {
+ try
{
- lastSaveSuccessful = false;
- return;
- }
- AlignmentExportData exportData = settings.getAlignExportData();
- FormatAdapter f = new FormatAdapter(alignPanel,
- exportData.getSettings());
- String output = f.formatSequences(format,
- exportData.getAlignment(), // class
- // cast
- // exceptions
- // will
- // occur in the distant future
- exportData.getOmitHidden(),
- exportData.getStartEndPostions(),
- f.getCacheSuffixDefault(format),
- viewport.getAlignment().getHiddenColumns());
-
- if (output == null)
+ PrintWriter out = new PrintWriter(new FileWriter(file));
+ out.print(output);
+ out.close();
+ AlignFrame.this.setTitle(file);
+ statusBar.setText(MessageManager.formatMessage(
+ "label.successfully_saved_to_file_in_format",
+ new Object[]
+ { fileName, format.getName() }));
+ } catch (Exception ex)
{
lastSaveSuccessful = false;
- }
- else
- {
- try
- {
- PrintWriter out = new PrintWriter(new FileWriter(file));
-
- out.print(output);
- out.close();
- us.setTitle(file);
- statusBar.setText(MessageManager.formatMessage(
- "label.successfully_saved_to_file_in_format",
- new Object[]
- { fileName, format.getName() }));
- } catch (Exception ex)
- {
- lastSaveSuccessful = false;
- ex.printStackTrace();
- }
+ ex.printStackTrace();
}
}
- });
+ }
+ };
- settings.doShowSettings();
+ /*
+ * show dialog with export options if applicable; else just do it
+ */
+ if (AlignExportOptions.isNeeded(viewport, format))
+ {
+ AlignExportOptions choices = new AlignExportOptions(
+ alignPanel.getAlignViewport(), format, options);
+ choices.setResponseAction(outputAction);
+ choices.setResponseAction(cancelAction);
+ choices.showDialog();
+ }
+ else
+ {
+ outputAction.run();
}
}
/**
- * DOCUMENT ME!
+ * Outputs the alignment to textbox in the requested format, if necessary
+ * first prompting the user for whether to include hidden regions or
+ * non-sequence data
*
- * @param e
- * DOCUMENT ME!
+ * @param fileFormatName
*/
@Override
- protected void outputText_actionPerformed(ActionEvent e)
+ protected void outputText_actionPerformed(String fileFormatName)
{
FileFormatI fileFormat = FileFormats.getInstance()
- .forName(e.getActionCommand());
- AlignExportSettingI settings = getAlignmentForExport(fileFormat,
- alignPanel, null);
- settings.addActionListener(new ActionListener()
+ .forName(fileFormatName);
+ AlignExportSettingsI options = new AlignExportSettingsAdapter(false);
+ RunResponse outputAction = new RunResponse(JvOptionPane.OK_OPTION)
{
@Override
- public void actionPerformed(ActionEvent e)
+ public void run()
{
- if (settings.isCancelled())
- {
- return;
- }
- AlignmentExportData exportData = settings.getAlignExportData();
+ // todo defer this to inside formatSequences (or later)
+ AlignmentExportData exportData = viewport
+ .getAlignExportData(options);
CutAndPasteTransfer cap = new CutAndPasteTransfer();
cap.setForInput(null);
try
{
FileFormatI format = fileFormat;
- cap.setText(new FormatAdapter(alignPanel, settings)
+ cap.setText(new FormatAdapter(alignPanel, options)
.formatSequences(format, exportData.getAlignment(),
exportData.getOmitHidden(),
exportData.getStartEndPostions(),
oom);
cap.dispose();
}
- // TODO Auto-generated method stub
-
}
- });
- settings.doShowSettings();
- }
+ };
- public static AlignExportSettingI getAlignmentForExport(
- FileFormatI format, AlignmentPanel alignPanel,
- AlignExportSettingBeanI exportSettings)
- {
-
- return new AlignExportSettings(alignPanel, format, exportSettings);
+ /*
+ * show dialog with export options if applicable; else just do it
+ */
+ if (AlignExportOptions.isNeeded(viewport, fileFormat))
+ {
+ AlignExportOptions choices = new AlignExportOptions(
+ alignPanel.getAlignViewport(), fileFormat, options);
+ choices.setResponseAction(outputAction);
+ choices.showDialog();
+ }
+ else
+ {
+ outputAction.run();
+ }
}
/**
dialog.showInternalDialog(mainPanel, title,
JvOptionPane.YES_NO_CANCEL_OPTION,
- JvOptionPane.QUESTION_MESSAGE, null, options,
+ JvOptionPane.PLAIN_MESSAGE, null, options,
MessageManager.getString("action.ok"));
}
*/
package jalview.io;
-import jalview.api.AlignExportSettingI;
+import jalview.api.AlignExportSettingsI;
import jalview.api.AlignmentViewPanel;
import jalview.api.FeatureSettingsModelI;
import jalview.datamodel.AlignmentI;
*/
package jalview.io;
-import jalview.api.AlignExportSettingI;
+import jalview.api.AlignExportSettingsI;
import jalview.api.AlignmentViewPanel;
import jalview.api.FeatureSettingsModelI;
import jalview.datamodel.AlignmentI;
void setNewlineString(String newline);
- void setExportSettings(AlignExportSettingI exportSettings);
+ void setExportSettings(AlignExportSettingsI exportSettings);
void configureForView(AlignmentViewPanel viewpanel);
*/
package jalview.io;
-import jalview.api.AlignExportSettingI;
+import jalview.api.AlignExportSettingsI;
import jalview.api.AlignmentViewPanel;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentAnnotation;
*/
protected String newline = System.getProperty("line.separator");
- private AlignExportSettingI exportSettings;
+ private AlignExportSettingsI exportSettings;
private File selectedFile;
}
public AppletFormatAdapter(AlignmentViewPanel alignPanel,
- AlignExportSettingI settings)
+ AlignExportSettingsI settings)
{
viewpanel = alignPanel;
exportSettings = settings;
*/
package jalview.io;
-import jalview.api.AlignExportSettingI;
+import jalview.api.AlignExportSettingsI;
import jalview.api.AlignViewportI;
import jalview.api.AlignmentViewPanel;
import jalview.api.FeatureSettingsModelI;
/**
* specific settings for exporting data from the current context
*/
- private AlignExportSettingI exportSettings;
+ private AlignExportSettingsI exportSettings;
/**
* sequence counter for FileParse object created from same data source
/**
* @return the currently configured exportSettings for writing data.
*/
- public AlignExportSettingI getExportSettings()
+ public AlignExportSettingsI getExportSettings()
{
return exportSettings;
}
* @param exportSettings
* the exportSettings to set
*/
- public void setExportSettings(AlignExportSettingI exportSettings)
+ public void setExportSettings(AlignExportSettingsI exportSettings)
{
this.exportSettings = exportSettings;
}
*/
package jalview.io;
-import jalview.api.AlignExportSettingI;
+import jalview.api.AlignExportSettingsI;
import jalview.api.AlignmentViewPanel;
import jalview.bin.Cache;
import jalview.datamodel.Alignment;
}
public FormatAdapter(AlignmentViewPanel alignPanel,
- AlignExportSettingI settings)
+ AlignExportSettingsI settings)
{
super(alignPanel, settings);
}
package jalview.io;
-import jalview.api.AlignExportSettingI;
+import jalview.api.AlignExportSettingsI;
import jalview.api.AlignViewportI;
import jalview.api.AlignmentViewPanel;
import jalview.api.ComplexAlignFile;
import jalview.api.FeatureSettingsModelI;
import jalview.api.FeaturesDisplayedI;
import jalview.bin.BuildDetails;
-import jalview.datamodel.AlignExportSettingBeanI;
+import jalview.datamodel.AlignExportSettingsAdapter;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.Annotation;
try
{
AlignmentPojo jsonAlignmentPojo = new AlignmentPojo();
- AlignExportSettingBeanI exportSettings = getExportSettings();
+ AlignExportSettingsI exportSettings = getExportSettings();
- // if no export settings were supplied use the following with all values
- // defaulting to true
+ /*
+ * if no export settings were supplied, provide an 'export all' setting
+ */
if (exportSettings == null)
{
- exportSettings = new AlignExportSettingBeanI()
- {
- @Override
- public boolean isExportHiddenSequences()
- {
- return true;
- }
-
- @Override
- public boolean isExportHiddenColumns()
- {
- return true;
- }
-
- @Override
- public boolean isExportGroups()
- {
- return true;
- }
-
- @Override
- public boolean isExportFeatures()
- {
- return true;
- }
-
- @Override
- public boolean isExportAnnotations()
- {
- return true;
- }
-
- @Override
- public boolean isCancelled()
- {
- return false;
- }
- };
+ exportSettings = new AlignExportSettingsAdapter(true);
}
int count = 0;
+++ /dev/null
-/*
- * 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 <http://www.gnu.org/licenses/>.
- * The Jalview Authors are detailed in the 'AUTHORS' file.
- */
-package jalview.jbgui;
-
-import jalview.io.FileFormatI;
-import jalview.util.MessageManager;
-
-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();
-
- protected JCheckBox chkHiddenSeqs = new JCheckBox();
-
- protected JCheckBox chkHiddenCols = new JCheckBox();
-
- protected JCheckBox chkExportAnnots = new JCheckBox();
-
- protected JCheckBox chkExportFeats = new JCheckBox();
-
- protected JCheckBox chkExportGrps = new JCheckBox();
-
- private boolean hasHiddenSeq, hasHiddenCols, isComplexAlignFile,
- showDialog;
-
- public GAlignExportSettings(boolean hasHiddenSeq, boolean hasHiddenCols,
- FileFormatI format)
- {
- this.hasHiddenSeq = hasHiddenSeq;
- this.hasHiddenCols = hasHiddenCols;
- this.isComplexAlignFile = format.isComplexAlignFile();
- if (this.hasHiddenCols || this.hasHiddenSeq || this.isComplexAlignFile)
- {
- this.showDialog = true;
- }
- init();
- }
-
- public void init()
- {
- chkHiddenSeqs.setText(
- MessageManager.getString("action.export_hidden_sequences"));
- chkHiddenCols.setText(
- MessageManager.getString("action.export_hidden_columns"));
- chkExportAnnots
- .setText(MessageManager.getString("action.export_annotations"));
- chkExportFeats
- .setText(MessageManager.getString("action.export_features"));
- chkExportGrps.setText(MessageManager.getString("action.export_groups"));
- chkAll.setText(MessageManager.getString("action.select_all"));
-
- hiddenRegionConfPanel.setLayout(hiddenRegionLayout);
- complexExportPanel.setLayout(complexExportLayout);
- setLayout(mainLayout);
-
- chkAll.addItemListener(new ItemListener()
- {
- @Override
- public void itemStateChanged(ItemEvent e)
- {
- checkAllAction();
- }
- });
-
- // 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);
-
- actionPanel.add(chkAll);
-
- if (this.isComplexAlignFile)
- {
- optionsPanel.add(complexExportPanel);
- }
-
- if (hasHiddenSeq || hasHiddenCols)
- {
- optionsPanel.add(hiddenRegionConfPanel);
- }
-
- 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 boolean isShowDialog()
- {
- return showDialog;
- }
-
- public void setShowDialog(boolean showDialog)
- {
- this.showDialog = showDialog;
- }
-
- public abstract void ok_actionPerformed(ActionEvent e);
-
- public abstract void cancel_actionPerformed(ActionEvent e);
-}
@Override
public void actionPerformed(ActionEvent e)
{
- outputText_actionPerformed(e);
+ outputText_actionPerformed(e.getActionCommand());
}
});
{
}
- protected void outputText_actionPerformed(ActionEvent e)
+ protected void outputText_actionPerformed(String formatName)
{
}
public static String formatMessage(String key, Object... params)
{
- return MessageFormat.format(rb.getString(key), params);
+ return MessageFormat.format(getString(key), params);
}
public static String formatMessage(String key, String[] params)
{
- return MessageFormat.format(rb.getString(key), (Object[]) params);
+ return MessageFormat.format(getString(key), (Object[]) params);
}
/**
- * lookup and return a key given a root and a human-readable(ish) name that
+ * Looks up and returns a key given a root and a human-readable(ish) name that
* when combined might resolve to an i18n string. If the key doesn't resolve,
- * then name is returned.if the key doesn't exist. Use this for
- * programatically constructed keys that have have a human readable
- * alternative used in the program (e.g. BLOSUM62 and label.score_blosum62)
+ * then name is returned. Use this for programmatically constructed keys that
+ * have a human readable alternative used in the program (e.g. BLOSUM62 and
+ * label.score_blosum62).
*
* @param keyroot
* @param name
import jalview.analysis.Conservation;
import jalview.analysis.TreeModel;
import jalview.api.AlignCalcManagerI;
+import jalview.api.AlignExportSettingsI;
import jalview.api.AlignViewportI;
import jalview.api.AlignmentViewPanel;
import jalview.api.FeaturesDisplayedI;
import jalview.commands.CommandI;
import jalview.datamodel.AlignedCodonFrame;
import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentExportData;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.AlignmentView;
import jalview.datamodel.Annotation;
{
return currentTree;
}
+
+ @Override
+ public AlignmentExportData getAlignExportData(AlignExportSettingsI options)
+ {
+ AlignmentI alignmentToExport = null;
+ String[] omitHidden = null;
+ alignmentToExport = null;
+
+ if (hasHiddenColumns() && !options.isExportHiddenColumns())
+ {
+ omitHidden = getViewAsString(false,
+ options.isExportHiddenSequences());
+ }
+
+ int[] alignmentStartEnd = new int[2];
+ if (hasHiddenRows() && options.isExportHiddenSequences())
+ {
+ alignmentToExport = getAlignment().getHiddenSequences()
+ .getFullAlignment();
+ }
+ else
+ {
+ alignmentToExport = getAlignment();
+ }
+ alignmentStartEnd = getAlignment().getHiddenColumns()
+ .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
+ AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
+ omitHidden, alignmentStartEnd);
+ return ed;
+ }
}