From 2e2e6d269fbaa505151fe777374f41111f2910d5 Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Wed, 17 Jun 2015 11:22:22 +0100 Subject: [PATCH] JAL-1780 more support for export setting for flatfile output --- src/jalview/api/AlignViewportI.java | 17 ++++++- src/jalview/appletgui/AlignFrame.java | 1 - src/jalview/appletgui/AlignViewport.java | 12 +++-- src/jalview/gui/AlignFrame.java | 78 ++++++++++++++++-------------- src/jalview/gui/AlignViewport.java | 12 +++-- src/jalview/io/JSONFile.java | 71 ++++++++++----------------- 6 files changed, 100 insertions(+), 91 deletions(-) diff --git a/src/jalview/api/AlignViewportI.java b/src/jalview/api/AlignViewportI.java index 34ee209..fa73194 100644 --- a/src/jalview/api/AlignViewportI.java +++ b/src/jalview/api/AlignViewportI.java @@ -373,10 +373,25 @@ public interface AlignViewportI extends ViewStyleI */ void setFollowHighlight(boolean b); + /** + * Returns a FeatureRenderer instance + * + * @return + */ public FeatureRenderer getFeatureRenderer(); + /** + * Sets a FeatureRenderer for a viewport + * + * @param featureRenderer + */ public void setFeatureRenderer(FeatureRenderer featureRenderer); - public boolean isIncludeHiddenRegion(); + /** + * Returns Settings for exporting an Alignment + * + * @return + */ + public AlignExportSettingI getExportSettings(); } diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index 1510a14..4f7e2b9 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -1341,7 +1341,6 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, FeatureRenderer fr = this.alignPanel.cloneFeatureRenderer(); viewport.setFeatureRenderer(fr); - viewport.setIncludeHiddenRegion(false); cap.setText(new AppletFormatAdapter(viewport).formatSequences( e.getActionCommand(), viewport.getAlignment(), viewport.getShowJVSuffix())); diff --git a/src/jalview/appletgui/AlignViewport.java b/src/jalview/appletgui/AlignViewport.java index 607dc05..d7ec681 100644 --- a/src/jalview/appletgui/AlignViewport.java +++ b/src/jalview/appletgui/AlignViewport.java @@ -23,6 +23,7 @@ package jalview.appletgui; import java.awt.Font; import jalview.analysis.NJTree; +import jalview.api.AlignExportSettingI; import jalview.api.AlignViewportI; import jalview.api.FeatureRenderer; import jalview.bin.JalviewLite; @@ -60,7 +61,7 @@ public class AlignViewport extends AlignmentViewport implements private FeatureRenderer featureRenderer; - private boolean includeHiddenRegion = true; + private AlignExportSettingI exportSettings; public void finalize() { @@ -485,14 +486,15 @@ public class AlignViewport extends AlignmentViewport implements } - public boolean isIncludeHiddenRegion() + public AlignExportSettingI getExportSettings() { - return includeHiddenRegion; + return exportSettings; } - public void setIncludeHiddenRegion(boolean includeHiddenRegion) + public void setExportSettings(AlignExportSettingI exportSettings) { - this.includeHiddenRegion = includeHiddenRegion; + this.exportSettings = exportSettings; } + } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index db61f77..85b6767 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -74,6 +74,7 @@ import jalview.analysis.CrossRef; import jalview.analysis.Dna; import jalview.analysis.ParseProperties; import jalview.analysis.SequenceIdMatcher; +import jalview.api.AlignExportSettingI; import jalview.api.AlignViewControllerGuiI; import jalview.api.AlignViewControllerI; import jalview.api.AlignViewportI; @@ -1140,7 +1141,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return false; } - ExportData exportData = getAlignmentForExport(); + ExportData exportData = getAlignmentForExport(format); FormatAdapter f = new FormatAdapter(viewport); String output = f.formatSequences(format, exportData.getAlignment(), // class cast exceptions will @@ -1213,10 +1214,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void outputText_actionPerformed(ActionEvent e) { - ExportData exportData = getAlignmentForExport(); + ExportData exportData = getAlignmentForExport(e.getActionCommand()); + if (exportData.getSettings().isCancelled()) + { + return; + } CutAndPasteTransfer cap = new CutAndPasteTransfer(); cap.setForInput(null); - try { cap.setText(new FormatAdapter(viewport).formatSequences( @@ -1235,7 +1239,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } - public ExportData getAlignmentForExport() + public ExportData getAlignmentForExport(String exportFomat) { AlignmentI alignmentToExport = null; String[] omitHidden = null; @@ -1250,36 +1254,29 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, alignmentStartEnd = new int[] { 0, alignmentToExport.getWidth() - 1 }; - if (viewport.hasHiddenColumns() || hiddenSeqs.getSize() > 0) - { - int reply = JOptionPane - .showInternalConfirmDialog( - Desktop.desktop, - MessageManager - .getString("label.alignment_contains_hidden_columns"), - MessageManager - .getString("action.save_omit_hidden_columns"), - JOptionPane.YES_NO_OPTION, - JOptionPane.QUESTION_MESSAGE); + boolean hasHiddenSeqs = hiddenSeqs.getSize() > 0; + AlignExportSettingI settings = new AlignExportSettings(hasHiddenSeqs, + viewport.hasHiddenColumns(), exportFomat); + viewport.setExportSettings(settings); + settings.isExportAnnotations(); - if (reply == JOptionPane.YES_OPTION) - { - // export only visible region - omitHidden = viewport.getViewAsString(false); - alignmentToExport = viewport.getAlignment(); - alignmentStartEnd = getStartEnd(alignmentStartEnd, viewport - .getColumnSelection().getHiddenColumns()); - viewport.setIncludeHiddenRegion(false); - } - else - { - // export all region including visible - alignmentToExport = hiddenSeqs.getFullAlignment(); - viewport.setIncludeHiddenRegion(true); - } + if (viewport.hasHiddenColumns() && !settings.isExportHiddenColumns()) + { + omitHidden = viewport.getViewAsString(false); } - return new ExportData(alignmentToExport, omitHidden, alignmentStartEnd); + if (hasHiddenSeqs && settings.isExportHiddenSequences()) + { + alignmentToExport = hiddenSeqs.getFullAlignment(); + } + else + { + alignmentToExport = viewport.getAlignment(); + alignmentStartEnd = getStartEnd(alignmentStartEnd, viewport + .getColumnSelection().getHiddenColumns()); + } + return new ExportData(alignmentToExport, omitHidden, alignmentStartEnd, + settings); } private static int[] getStartEnd(int[] aligmentStartEnd, @@ -1352,9 +1349,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override protected void htmlMenuItem_actionPerformed(ActionEvent e) { - // new HTMLOutput(alignPanel, - // alignPanel.getSeqPanel().seqCanvas.getSequenceRenderer(), - // alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()); new HtmlSvgOutput(null, alignPanel); } @@ -6094,11 +6088,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, private int[] startEnd; - public ExportData(AlignmentI align, String[] ommit, int[] startEnd) + private AlignExportSettingI settings; + + public ExportData(AlignmentI align, String[] ommit, int[] startEnd, + AlignExportSettingI settings) { this.alignment = align; this.omitHidden = ommit; this.startEnd = startEnd; + this.settings = settings; } public AlignmentI getAlignment() @@ -6130,6 +6128,16 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { this.startEnd = startEnd; } + + public AlignExportSettingI getSettings() + { + return settings; + } + + public void setSettings(AlignExportSettingI settings) + { + this.settings = settings; + } } } diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 2224021..a6f7d41 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -54,6 +54,7 @@ import javax.swing.JOptionPane; import jalview.analysis.AlignmentUtils; import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.analysis.NJTree; +import jalview.api.AlignExportSettingI; import jalview.api.AlignViewportI; import jalview.api.FeatureRenderer; import jalview.api.ViewStyleI; @@ -100,6 +101,9 @@ public class AlignViewport extends AlignmentViewport implements private FeatureRenderer featureRenderer; private boolean includeHiddenRegion = true; + + private AlignExportSettingI exportSettings; + String viewName; /* @@ -1053,13 +1057,13 @@ public class AlignViewport extends AlignmentViewport implements this.featureRenderer = featureRenderer; } - public boolean isIncludeHiddenRegion() + public AlignExportSettingI getExportSettings() { - return includeHiddenRegion; + return exportSettings; } - public void setIncludeHiddenRegion(boolean includeHiddenRegion) + public void setExportSettings(AlignExportSettingI exportSettings) { - this.includeHiddenRegion = includeHiddenRegion; + this.exportSettings = exportSettings; } } diff --git a/src/jalview/io/JSONFile.java b/src/jalview/io/JSONFile.java index d2b8412..f977b04 100644 --- a/src/jalview/io/JSONFile.java +++ b/src/jalview/io/JSONFile.java @@ -79,8 +79,6 @@ public class JSONFile extends AlignFile implements ComplexAlignFile private FeatureRenderer fr; - private JSONExportSettings jsonExportSettings; - private List hiddenColumns; private ColumnSelection columnSelection; @@ -123,15 +121,6 @@ public class JSONFile extends AlignFile implements ComplexAlignFile String jsonOutput = null; try { - if (getJsonExportSettings() == null) - { - jsonExportSettings = new JSONExportSettings(); - jsonExportSettings.setExportAnnotations(true); - jsonExportSettings.setExportGroups(true); - jsonExportSettings.setExportJalviewSettings(true); - jsonExportSettings.setExportSequenceFeatures(true); - } - AlignmentPojo jsonAlignmentPojo = new AlignmentPojo(); if (getViewport() != null) { @@ -159,44 +148,46 @@ public class JSONFile extends AlignFile implements ComplexAlignFile jsonAlignmentPojo.getSeqs().add(jsonSeqPojo); } - if (jsonExportSettings.isExportJalviewSettings()) + jsonAlignmentPojo.setGlobalColorScheme(globalColorScheme); + jsonAlignmentPojo.getAppSettings().put("application", application); + jsonAlignmentPojo.getAppSettings().put("version", version); + jsonAlignmentPojo.getAppSettings().put("webStartUrl", webstartUrl); + jsonAlignmentPojo.getAppSettings().put("showSeqFeatures", + String.valueOf(showSeqFeatures)); + + String[] hiddenSections = getHiddenSections(); + if (hiddenSections != null) { - jsonAlignmentPojo.setGlobalColorScheme(globalColorScheme); - jsonAlignmentPojo.getAppSettings().put("application", application); - jsonAlignmentPojo.getAppSettings().put("version", version); - jsonAlignmentPojo.getAppSettings().put("webStartUrl", webstartUrl); - jsonAlignmentPojo.getAppSettings().put("showSeqFeatures", - String.valueOf(showSeqFeatures)); - - String[] hiddenSections = exportHiddenSections(); - if (hiddenSections != null && getViewport().isIncludeHiddenRegion()) + if (hiddenSections[0] != null + && getViewport().getExportSettings() + .isExportHiddenColumns()) { - if (hiddenSections[0] != null) - { - jsonAlignmentPojo.getAppSettings().put("hiddenCols", - String.valueOf(hiddenSections[0])); - } - if (hiddenSections[1] != null) - { - jsonAlignmentPojo.getAppSettings().put("hiddenSeqs", - String.valueOf(hiddenSections[1])); - } + jsonAlignmentPojo.getAppSettings().put("hiddenCols", + String.valueOf(hiddenSections[0])); + } + if (hiddenSections[1] != null + && getViewport().getExportSettings() + .isExportHiddenSequences()) + { + jsonAlignmentPojo.getAppSettings().put("hiddenSeqs", + String.valueOf(hiddenSections[1])); } } - if (jsonExportSettings.isExportAnnotations()) + if (getViewport().getExportSettings().isExportAnnotations()) { jsonAlignmentPojo .setAlignAnnotation(annotationToJsonPojo(annotations)); } - if (jsonExportSettings.isExportSequenceFeatures()) + if (getViewport().getExportSettings().isExportFeatures()) { jsonAlignmentPojo .setSeqFeatures(sequenceFeatureToJsonPojo(seqs, fr)); } - if (jsonExportSettings.isExportGroups() && seqGroups != null + if (getViewport().getExportSettings().isExportGroups() + && seqGroups != null && seqGroups.size() > 0) { for (SequenceGroup seqGrp : seqGroups) @@ -231,7 +222,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile return jsonOutput; } - public String[] exportHiddenSections() + public String[] getHiddenSections() { String[] hiddenSections = new String[2]; if (getViewport() == null) @@ -614,16 +605,6 @@ public class JSONFile extends AlignFile implements ComplexAlignFile this.displayedFeatures = displayedFeatures; } - public JSONExportSettings getJsonExportSettings() - { - return jsonExportSettings; - } - - public void setJsonExportSettings(JSONExportSettings jsonExportSettings) - { - this.jsonExportSettings = jsonExportSettings; - } - public static String getJSONData(AlignViewportI av) { -- 1.7.10.2