package jalview.api;
+import jalview.datamodel.AlignExportSettingBeanI;
+import jalview.datamodel.AlignmentExportData;
+
+import java.awt.event.ActionListener;
+
/**
- * Abstract interface implemented by Alignment Export dialog to retrieve user
- * configurations
- *
- * @author tcnofoegbu
+ * additional methods implemented by the export settings dialog
*
*/
-public interface AlignExportSettingI
+public interface AlignExportSettingI extends AlignExportSettingBeanI
{
- /**
- * Checks if hidden sequences should be exported
- *
- * @return
- */
- public boolean isExportHiddenSequences();
+ AlignmentExportData getAlignExportData();
+
/**
- * Checks if hidden columns shoulb be exported
- *
- * @return
+ * the export data action to be performed - make sure you check isCancelled in this method first
+ * @param actionListener
*/
- 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();
+ public void addActionListener(ActionListener actionListener);
/**
- * Checks if SequenceFeatures should be exported, note this is available for
- * complex flat file exports like JSON, HTML, GFF
- *
- * @return
+ * show the dialog
*/
- 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();
+ public void doShowSettings();
}
continue;
}
- if (af.saveAlignment(file, format))
+ af.saveAlignment(file, format);
+ if (af.isSaveAlignmentSuccessful())
{
System.out.println("Written alignment in " + format
+ " format to " + file);
--- /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();
+}
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.WindowAdapter;
-import java.awt.event.WindowEvent;
+import java.awt.event.ActionListener;
-import javax.swing.JDialog;
import javax.swing.JOptionPane;
@SuppressWarnings("serial")
{
boolean cancelled = false;
- JDialog dialog;
+ JvOptionPane dialog;
- public AlignExportSettings(boolean hasHiddenSeq, boolean hasHiddenCols,
- FileFormatI format)
+ AlignmentPanel alignPanel;
+
+ /**
+ * settings provided at construction override the GUI
+ */
+ AlignExportSettingBeanI override=null;
+
+ public AlignExportSettings(AlignmentPanel alignmentPanel,
+ FileFormatI format, AlignExportSettingBeanI exportSettings)
{
- super(hasHiddenSeq, hasHiddenCols, format);
- if (!Jalview.isHeadlessMode() && isShowDialog())
- {
+ 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();
- JOptionPane pane = new JOptionPane(null, JOptionPane.DEFAULT_OPTION,
- JvOptionPane.DEFAULT_OPTION, null, new Object[]
- { this });
- dialog = pane.createDialog(Desktop.desktop,
- MessageManager.getString("label.export_settings"));
- dialog.addWindowListener(new WindowAdapter()
- {
- @Override
- public void windowClosing(WindowEvent e)
- {
- cancelled = true;
- }
- });
- dialog.pack();
- dialog.setVisible(true);
- dialog.setContentPane(this);
- dialog.validate();
+ 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;
- dialog.setVisible(false);
- dialog.dispose();
}
@Override
public void cancel_actionPerformed(ActionEvent e)
{
cancelled = true;
- dialog.setVisible(false);
- dialog.dispose();
}
@Override
public boolean isExportHiddenSequences()
{
- return chkHiddenSeqs.isSelected();
+ return override!=null ? override.isExportHiddenSequences() : chkHiddenSeqs.isSelected();
}
@Override
public boolean isExportHiddenColumns()
{
- return chkHiddenCols.isSelected();
+ return override!=null ? override.isExportHiddenColumns() : chkHiddenCols.isSelected();
}
@Override
public boolean isExportAnnotations()
{
- return chkExportAnnots.isSelected();
+ return override!=null ? override.isExportAnnotations() : chkExportAnnots.isSelected();
}
@Override
public boolean isExportFeatures()
{
- return chkExportFeats.isSelected();
+ return override!=null ? override.isExportFeatures() : chkExportFeats.isSelected();
}
@Override
public boolean isExportGroups()
{
- return chkExportGrps.isSelected();
+ return override!=null ? override.isExportGroups() : chkExportGrps.isSelected();
}
@Override
public boolean isCancelled()
{
- return cancelled;
+ 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.commands.RemoveGapsCommand;
import jalview.commands.SlideSequencesCommand;
import jalview.commands.TrimRegionCommand;
+import jalview.datamodel.AlignExportSettingBeanI;
import jalview.datamodel.AlignedCodonFrame;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentView;
import jalview.datamodel.ColumnSelection;
import jalview.datamodel.HiddenColumns;
-import jalview.datamodel.HiddenSequences;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SeqCigar;
import jalview.datamodel.Sequence;
}).showSaveDialog(this);
}
- public boolean saveAlignment(String file, FileFormatI format)
+ private boolean lastSaveSuccessful = false;
+
+ private FileFormatI lastFormatSaved;
+
+ private String lastFilenameSaved;
+
+ /**
+ * Raise a dialog or status message for the last call to saveAlignment.
+ *
+ * @return true if last call to saveAlignment(file, format) was successful.
+ */
+ public boolean isSaveAlignmentSuccessful()
{
- boolean success = true;
+ if (!lastSaveSuccessful)
+ {
+ JvOptionPane.showInternalMessageDialog(this, MessageManager
+ .formatMessage("label.couldnt_save_file", new Object[]
+ { lastFilenameSaved }),
+ MessageManager.getString("label.error_saving_file"),
+ JvOptionPane.WARNING_MESSAGE);
+ }
+ else
+ {
+
+ statusBar.setText(MessageManager.formatMessage(
+ "label.successfully_saved_to_file_in_format", new Object[]
+ { lastFilenameSaved, lastFormatSaved }));
+
+ }
+ return lastSaveSuccessful;
+ }
+
+ public void saveAlignment(String file, FileFormatI format)
+ {
+ lastSaveSuccessful = false;
+ lastFilenameSaved = file;
+ lastFormatSaved = format;
+ AlignFrame us = this;
if (FileFormat.Jalview.equals(format))
{
String shortName = title;
shortName.lastIndexOf(java.io.File.separatorChar) + 1);
}
- success = new Jalview2XML().saveAlignment(this, file, shortName);
-
- statusBar.setText(MessageManager.formatMessage(
- "label.successfully_saved_to_file_in_format", new Object[]
- { fileName, format }));
-
+ lastSaveSuccessful = new Jalview2XML().saveAlignment(this, file,
+ shortName);
}
else
{
- AlignmentExportData exportData = getAlignmentForExport(format,
- viewport, null);
- if (exportData.getSettings().isCancelled())
+ AlignExportSettingI settings = getAlignmentForExport(format,
+ alignPanel, null);
+ settings.addActionListener(new ActionListener()
{
- return false;
- }
- 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)
- {
- success = false;
- }
- else
- {
- try
- {
- PrintWriter out = new PrintWriter(new FileWriter(file));
-
- out.print(output);
- out.close();
- this.setTitle(file);
- statusBar.setText(MessageManager.formatMessage(
- "label.successfully_saved_to_file_in_format", new Object[]
- { fileName, format.getName() }));
- } catch (Exception ex)
+ @Override
+ public void actionPerformed(ActionEvent e)
{
- success = false;
- ex.printStackTrace();
+
+ if (settings.isCancelled())
+ {
+ 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)
+ {
+ 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();
+ }
+ }
}
- }
- }
+ });
- if (!success)
- {
- JvOptionPane.showInternalMessageDialog(this, MessageManager
- .formatMessage("label.couldnt_save_file", new Object[]
- { fileName }),
- MessageManager.getString("label.error_saving_file"),
- JvOptionPane.WARNING_MESSAGE);
+ settings.doShowSettings();
}
-
- return success;
}
/**
{
FileFormatI fileFormat = FileFormats.getInstance()
.forName(e.getActionCommand());
- AlignmentExportData exportData = getAlignmentForExport(fileFormat,
- viewport, null);
- if (exportData.getSettings().isCancelled())
+ AlignExportSettingI settings = getAlignmentForExport(fileFormat,
+ alignPanel, null);
+ settings.addActionListener(new ActionListener()
{
- return;
- }
- CutAndPasteTransfer cap = new CutAndPasteTransfer();
- cap.setForInput(null);
- try
- {
- FileFormatI format = fileFormat;
- cap.setText(new FormatAdapter(alignPanel, exportData.getSettings())
- .formatSequences(format, exportData.getAlignment(),
- exportData.getOmitHidden(),
- exportData.getStartEndPostions(),
- viewport.getAlignment().getHiddenColumns()));
- Desktop.addInternalFrame(cap, MessageManager
- .formatMessage("label.alignment_output_command", new Object[]
- { e.getActionCommand() }), 600, 500);
- } catch (OutOfMemoryError oom)
- {
- new OOMWarning("Outputting alignment as " + e.getActionCommand(),
- oom);
- cap.dispose();
- }
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ if (settings.isCancelled())
+ {
+ return;
+ }
+ AlignmentExportData exportData = settings.getAlignExportData();
+ CutAndPasteTransfer cap = new CutAndPasteTransfer();
+ cap.setForInput(null);
+ try
+ {
+ FileFormatI format = fileFormat;
+ cap.setText(new FormatAdapter(alignPanel, settings)
+ .formatSequences(format, exportData.getAlignment(),
+ exportData.getOmitHidden(),
+ exportData.getStartEndPostions(),
+ viewport.getAlignment().getHiddenColumns()));
+ Desktop.addInternalFrame(cap, MessageManager.formatMessage(
+ "label.alignment_output_command", new Object[]
+ { fileFormat.getName() }), 600, 500);
+ } catch (OutOfMemoryError oom)
+ {
+ new OOMWarning("Outputting alignment as " + fileFormat.getName(),
+ oom);
+ cap.dispose();
+ }
+ // TODO Auto-generated method stub
+ }
+ });
+ settings.doShowSettings();
}
- public static AlignmentExportData getAlignmentForExport(
- FileFormatI format, AlignViewportI viewport,
- AlignExportSettingI exportSettings)
+ public static AlignExportSettingI getAlignmentForExport(
+ FileFormatI format, AlignmentPanel alignPanel,
+ AlignExportSettingBeanI exportSettings)
{
- AlignmentI alignmentToExport = null;
- AlignExportSettingI settings = exportSettings;
- String[] omitHidden = null;
-
- HiddenSequences hiddenSeqs = viewport.getAlignment()
- .getHiddenSequences();
-
- alignmentToExport = viewport.getAlignment();
- boolean hasHiddenSeqs = hiddenSeqs.getSize() > 0;
- if (settings == null)
- {
- settings = new AlignExportSettings(hasHiddenSeqs,
- viewport.hasHiddenColumns(), format);
- }
- // settings.isExportAnnotations();
-
- if (viewport.hasHiddenColumns() && !settings.isExportHiddenColumns())
- {
- omitHidden = viewport.getViewAsString(false,
- settings.isExportHiddenSequences());
- }
-
- int[] alignmentStartEnd = new int[2];
- if (hasHiddenSeqs && settings.isExportHiddenSequences())
- {
- alignmentToExport = hiddenSeqs.getFullAlignment();
- }
- else
- {
- alignmentToExport = viewport.getAlignment();
- }
- alignmentStartEnd = viewport.getAlignment().getHiddenColumns()
- .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
- AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
- omitHidden, alignmentStartEnd, settings);
- return ed;
+ return new AlignExportSettings(alignPanel, format, exportSettings);
}
/**
package jalview.io;
import jalview.api.AlignExportSettingI;
+import jalview.datamodel.AlignExportSettingBeanI;
import jalview.datamodel.AlignmentExportData;
import jalview.exceptions.NoFileSelectedException;
import jalview.gui.AlignmentPanel;
import jalview.gui.IProgressIndicator;
import jalview.util.MessageManager;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
}
}
+ String _bioJson=null;
public String getBioJSONData()
{
- return getBioJSONData(null);
+ if (_bioJson==null) {
+ getBioJSONData(null);
+ }
+ return _bioJson;
}
- public String getBioJSONData(AlignExportSettingI exportSettings)
+ public void getBioJSONData(AlignExportSettingBeanI exportSettings)
{
if (!isEmbedData())
{
- return null;
+ return;
}
if (exportSettings == null)
{
- exportSettings = new AlignExportSettingI()
+ exportSettings = new AlignExportSettingBeanI()
{
@Override
public boolean isExportHiddenSequences()
{
return false;
}
+
};
}
- AlignmentExportData exportData = jalview.gui.AlignFrame
- .getAlignmentForExport(FileFormat.Json, ap.getAlignViewport(),
+ AlignExportSettingI exportDataSettings = jalview.gui.AlignFrame
+ .getAlignmentForExport(FileFormat.Json, ap,
exportSettings);
- String bioJSON = new FormatAdapter(ap, exportData.getSettings())
- .formatSequences(FileFormat.Json, exportData.getAlignment(),
- exportData.getOmitHidden(),
- exportData.getStartEndPostions(), ap.getAlignViewport()
- .getAlignment().getHiddenColumns());
- return bioJSON;
+ exportDataSettings.addActionListener(new ActionListener()
+ {
+
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ AlignmentExportData exportData = exportDataSettings.getAlignExportData();
+ _bioJson = new FormatAdapter(ap, exportData.getSettings())
+ .formatSequences(FileFormat.Json, exportData.getAlignment(),
+ exportData.getOmitHidden(),
+ exportData.getStartEndPostions(), ap.getAlignViewport()
+ .getAlignment().getHiddenColumns());
+
+ }
+
+
+ });
+ exportDataSettings.doShowSettings();
}
/**
import jalview.api.FeatureSettingsModelI;
import jalview.api.FeaturesDisplayedI;
import jalview.bin.BuildDetails;
+import jalview.datamodel.AlignExportSettingBeanI;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.Annotation;
try
{
AlignmentPojo jsonAlignmentPojo = new AlignmentPojo();
- AlignExportSettingI exportSettings = getExportSettings();
+ AlignExportSettingBeanI exportSettings = getExportSettings();
// if no export settings were supplied use the following with all values
// defaulting to true
if (exportSettings == null)
{
- exportSettings = new AlignExportSettingI()
+ exportSettings = new AlignExportSettingBeanI()
{
@Override
public boolean isExportHiddenSequences()
protected JCheckBox chkExportGrps = new JCheckBox();
- JButton btnOk = new JButton();
-
- JButton btnCancel = new JButton();
-
private boolean hasHiddenSeq, hasHiddenCols, isComplexAlignFile,
showDialog;
chkExportFeats
.setText(MessageManager.getString("action.export_features"));
chkExportGrps.setText(MessageManager.getString("action.export_groups"));
- btnOk.setText(MessageManager.getString("action.ok"));
- btnCancel.setText(MessageManager.getString("action.cancel"));
chkAll.setText(MessageManager.getString("action.select_all"));
hiddenRegionConfPanel.setLayout(hiddenRegionLayout);
}
});
- btnOk.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- ok_actionPerformed(e);
- }
- });
-
- btnCancel.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- cancel_actionPerformed(e);
- }
- });
-
// hiddenRegionConfPanel.add(chkAll, BorderLayout.NORTH);
hiddenRegionConfPanel.add(chkHiddenSeqs, BorderLayout.CENTER);
hiddenRegionConfPanel.add(chkHiddenCols, BorderLayout.SOUTH);
optionsPanel.add(hiddenRegionConfPanel);
}
- actionPanel.add(btnCancel);
- actionPanel.add(btnOk);
-
add(optionsPanel, BorderLayout.NORTH);
add(actionPanel, BorderLayout.SOUTH);