X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignViewport.java;h=a8bc815a62a6bbf3c668159bf337095c3ba86922;hb=HEAD;hp=aa536d84f7c27bbc78674e559cf70d5c8a21f274;hpb=4a59f639cf5769d9ec66142ebecfa4961c5d3b04;p=jalview.git diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index aa536d8..a8bc815 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -25,6 +25,7 @@ import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Rectangle; +import java.io.File; import java.util.ArrayList; import java.util.Hashtable; import java.util.List; @@ -52,6 +53,13 @@ import jalview.datamodel.SearchResults; import jalview.datamodel.SearchResultsI; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; +import jalview.io.AppletFormatAdapter; +import jalview.io.DataSourceType; +import jalview.io.FileFormatException; +import jalview.io.FileFormatI; +import jalview.io.FileFormats; +import jalview.io.FileLoader; +import jalview.io.IdentifyFile; import jalview.renderer.ResidueShader; import jalview.schemes.ColourSchemeI; import jalview.schemes.ColourSchemeProperty; @@ -729,6 +737,53 @@ public class AlignViewport extends AlignmentViewport } /** + * Load a File into this AlignViewport attempting to detect format if not + * given or given as null. + * + * @param file + * @param format + */ + public void addFile(File file, FileFormatI format) + { + addFile(file, format, true); + } + + public void addFile(File file, FileFormatI format, boolean async) + { + DataSourceType protocol = AppletFormatAdapter.checkProtocol(file); + + if (format == null) + { + try + { + format = new IdentifyFile().identify(file, protocol); + } catch (FileFormatException e1) + { + jalview.bin.Console.error("Unknown file format for '" + file + "'"); + } + } + else if (FileFormats.getInstance().isIdentifiable(format)) + { + try + { + format = new IdentifyFile().identify(file, protocol); + } catch (FileFormatException e) + { + jalview.bin.Console.error("Unknown file format for '" + file + "'", + e); + } + } + + new FileLoader().LoadFile(this, file, DataSourceType.FILE, format, + async); + } + + public void addFile(File file) + { + addFile(file, null); + } + + /** * Show a dialog with the option to open and link (cDNA <-> protein) as a new * alignment, either as a standalone alignment or in a split frame. Returns * true if the new alignment was opened, false if not, because the user @@ -754,13 +809,10 @@ public class AlignViewport extends AlignmentViewport JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.desktop) .setResponseHandler(0, () -> { addDataToAlignment(al); - return null; }).setResponseHandler(1, () -> { us.openLinkedAlignmentAs(al, title, true); - return null; }).setResponseHandler(2, () -> { us.openLinkedAlignmentAs(al, title, false); - return null; }); dialog.showDialog(question, MessageManager.getString("label.open_split_window"), @@ -945,7 +997,7 @@ public class AlignViewport extends AlignmentViewport */ protected boolean noReferencesTo(AlignedCodonFrame acf) { - AlignFrame[] frames = Desktop.getAlignFrames(); + AlignFrame[] frames = Desktop.getDesktopAlignFrames(); if (frames == null) { return true; @@ -1106,4 +1158,5 @@ public class AlignViewport extends AlignmentViewport { this.viewName = viewName; } + }