From 781218e12641a89d5dd99906369d5b9807c1d203 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 24 Nov 2016 16:43:06 +0000 Subject: [PATCH] Distinguish text-only output formats and others (.jar/.jvp) --- src/jalview/appletgui/APopupMenu.java | 2 +- src/jalview/appletgui/AlignFrame.java | 2 +- src/jalview/gui/PopupMenu.java | 2 +- src/jalview/io/FileFormat.java | 26 +++++++++++++++++++------- src/jalview/io/FileFormatI.java | 24 ++++++++++++++++++++++++ src/jalview/jbgui/GAlignFrame.java | 2 +- 6 files changed, 47 insertions(+), 11 deletions(-) diff --git a/src/jalview/appletgui/APopupMenu.java b/src/jalview/appletgui/APopupMenu.java index 1b66e9c..fbdf241 100644 --- a/src/jalview/appletgui/APopupMenu.java +++ b/src/jalview/appletgui/APopupMenu.java @@ -217,7 +217,7 @@ public class APopupMenu extends java.awt.PopupMenu implements e.printStackTrace(); } - for (String ff : FileFormat.getWritableFormats()) + for (String ff : FileFormat.getWritableFormats(true)) { MenuItem item = new MenuItem(ff); diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index e1b01a8..fcdf9d2 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -3241,7 +3241,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, inputText.addActionListener(this); Menu outputTextboxMenu = new Menu( MessageManager.getString("label.out_to_textbox")); - for (String ff : FileFormat.getWritableFormats()) + for (String ff : FileFormat.getWritableFormats(true)) { MenuItem item = new MenuItem(ff); diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 4d9dc4d..9f65708 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -258,7 +258,7 @@ public class PopupMenu extends JPopupMenu colours.add(purinePyrimidineColour); colours.add(RNAInteractionColour); - for (String ff : FileFormat.getWritableFormats()) + for (String ff : FileFormat.getWritableFormats(true)) { JMenuItem item = new JMenuItem(ff); diff --git a/src/jalview/io/FileFormat.java b/src/jalview/io/FileFormat.java index a43bc22..d0ce86e 100644 --- a/src/jalview/io/FileFormat.java +++ b/src/jalview/io/FileFormat.java @@ -218,7 +218,7 @@ public enum FileFormat implements FileFormatI } }, - Pileup("PileUp", "pileup", false, true) + Pileup("PileUp", "pileup", true, true) { @Override public AlignmentFileI getAlignmentFile(String inFile, @@ -329,7 +329,7 @@ public enum FileFormat implements FileFormatI } }, - Features("GFF or Jalview features", "gff2,gff3", false, false) + Features("GFF or Jalview features", "gff2,gff3", true, false) { @Override public AlignmentFileI getAlignmentFile(String inFile, @@ -351,7 +351,7 @@ public enum FileFormat implements FileFormatI return new FeaturesFile(); } }, - PDB("PDB", "", false, false) + PDB("PDB", "pdb,ent", true, false) { @Override @@ -414,7 +414,7 @@ public enum FileFormat implements FileFormatI return new JmolParser(); // todo or null? } }, - MMCif("mmCIF", "cif", false, false) + MMCif("mmCIF", "cif", true, false) { @Override @@ -445,7 +445,7 @@ public enum FileFormat implements FileFormatI return new JmolParser(); // todo or null? } }, - Jalview("Jalview", "jar,jvp", true, false) + Jalview("Jalview", "jar,jvp", true, true) { @Override @@ -467,6 +467,12 @@ public enum FileFormat implements FileFormatI { return null; } + + @Override + public boolean isTextFormat() + { + return false; + } }; /** @@ -496,12 +502,12 @@ public enum FileFormat implements FileFormatI * * @return */ - public static List getWritableFormats() + public static List getWritableFormats(boolean textOnly) { List l = new ArrayList(); for (FileFormatI ff : values()) { - if (ff.isWritable()) + if (ff.isWritable() && (!textOnly || ff.isTextFormat())) { l.add(ff.toString()); } @@ -596,4 +602,10 @@ public enum FileFormat implements FileFormatI { return getAlignmentFile((AlignmentI) null); } + + @Override + public boolean isTextFormat() + { + return true; + } } diff --git a/src/jalview/io/FileFormatI.java b/src/jalview/io/FileFormatI.java index 082d9f1..319df9f 100644 --- a/src/jalview/io/FileFormatI.java +++ b/src/jalview/io/FileFormatI.java @@ -10,6 +10,7 @@ public interface FileFormatI AlignmentFileI getAlignmentFile(String inFile, DataSourceType sourceType) throws IOException; + // TODO can we get rid of one of these methods? AlignmentFileI getAlignmentFile(FileParse source) throws IOException; AlignmentFileI getAlignmentFile(AlignmentI al); @@ -26,7 +27,30 @@ public interface FileFormatI */ String getExtensions(); + /** + * Answers true if the format is one that Jalview can read. This implies that + * the format provides implementations for getAlignmentFile(FileParse) and + * getAlignmentFile(String, DataSourceType) which parse the data source for + * sequence data. + * + * @return + */ boolean isReadable(); + /** + * Answers true if the format is one that Jalview can write. This implies that + * the object returned by getAlignmentFile provides an implementation of the + * print() method. + * + * @return + */ boolean isWritable(); + + /** + * Answers true if the format is one that Jalview can output as text, e.g. to + * a text box + * + * @return + */ + boolean isTextFormat(); } diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index 73d1b3c..44c4192 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -245,7 +245,7 @@ public class GAlignFrame extends JInternalFrame setJMenuBar(alignFrameMenuBar); // dynamically fill save as menu with available formats - for (String ff : FileFormat.getWritableFormats()) + for (String ff : FileFormat.getWritableFormats(true)) { JMenuItem item = new JMenuItem(ff); -- 1.7.10.2