X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FAppletFormatAdapter.java;fp=src%2Fjalview%2Fio%2FAppletFormatAdapter.java;h=4916bb3b44b7bedda13e5869b2cdda36920e5c47;hb=65740880573a48adc758bec3939ece9d9ae104dd;hp=5e209e6569970c260d95410ebd1c853e4b0a37b0;hpb=71aa78b8a7d54e5aeb6b278310dfd735efb77477;p=jalview.git diff --git a/src/jalview/io/AppletFormatAdapter.java b/src/jalview/io/AppletFormatAdapter.java index 5e209e6..4916bb3 100755 --- a/src/jalview/io/AppletFormatAdapter.java +++ b/src/jalview/io/AppletFormatAdapter.java @@ -20,7 +20,7 @@ */ package jalview.io; -import jalview.api.AlignExportSettingI; +import jalview.api.AlignExportSettingsI; import jalview.api.AlignmentViewPanel; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; @@ -30,6 +30,7 @@ import jalview.datamodel.PDBEntry.Type; import jalview.datamodel.SequenceI; import jalview.ext.jmol.JmolParser; import jalview.structure.StructureImportSettings; +import jalview.util.Platform; import java.io.File; import java.io.IOException; @@ -73,7 +74,9 @@ public class AppletFormatAdapter */ protected String newline = System.getProperty("line.separator"); - private AlignExportSettingI exportSettings; + private AlignExportSettingsI exportSettings; + + private File selectedFile; public static String INVALID_CHARACTERS = "Contains invalid characters"; @@ -98,7 +101,7 @@ public class AppletFormatAdapter } public AppletFormatAdapter(AlignmentViewPanel alignPanel, - AlignExportSettingI settings) + AlignExportSettingsI settings) { viewpanel = alignPanel; exportSettings = settings; @@ -147,6 +150,18 @@ public class AppletFormatAdapter public AlignmentI readFile(String file, DataSourceType sourceType, FileFormatI fileFormat) throws IOException { + return readFile(null, file, sourceType, fileFormat); + } + + public AlignmentI readFile(File selectedFile, String file, DataSourceType sourceType, + FileFormatI fileFormat) throws IOException + { + + this.selectedFile = selectedFile; + if (selectedFile != null) + { + this.inFile = selectedFile.getPath(); + } this.inFile = file; try { @@ -161,20 +176,23 @@ public class AppletFormatAdapter localSecondaryStruct, serviceSecondaryStruct); if (isParseWithJMOL) { - alignFile = new JmolParser(inFile, sourceType); + // needs a File option + alignFile = new JmolParser(selectedFile == null ? inFile : selectedFile, sourceType); } else { - // todo is MCview parsing obsolete yet? JAL-2120 + // todo is mc_view parsing obsolete yet? JAL-2120 StructureImportSettings.setShowSeqFeatures(true); - alignFile = new MCview.PDBfile(annotFromStructure, + alignFile = new mc_view.PDBfile(annotFromStructure, localSecondaryStruct, serviceSecondaryStruct, inFile, sourceType); } ((StructureFile) alignFile).setDbRefType( FileFormat.PDB.equals(fileFormat) ? Type.PDB : Type.MMCIF); } - else + else if (selectedFile != null) { + alignFile = fileFormat.getReader(new FileParse(selectedFile, sourceType)); + } else { // alignFile = fileFormat.getAlignmentFile(inFile, sourceType); alignFile = fileFormat.getReader(new FileParse(inFile, sourceType)); @@ -250,7 +268,7 @@ public class AppletFormatAdapter else { StructureImportSettings.setShowSeqFeatures(true); - alignFile = new MCview.PDBfile(annotFromStructure, + alignFile = new mc_view.PDBfile(annotFromStructure, localSecondaryStruct, serviceSecondaryStruct, source); } ((StructureFile) alignFile).setDbRefType(Type.PDB); @@ -406,15 +424,24 @@ public class AppletFormatAdapter return null; } + /** * Determines the protocol (i.e DataSourceType.{FILE|PASTE|URL}) for the input * data + * + * BH 2018 allows File or String, and can return RELATIVE_URL * - * @param data + * @param dataObject File or String * @return the protocol for the input data */ - public static DataSourceType checkProtocol(String data) + public static DataSourceType checkProtocol(Object dataObject) { + if(dataObject instanceof File) + { + return DataSourceType.FILE; + } + + String data = dataObject.toString(); DataSourceType protocol = DataSourceType.PASTE; String ft = data.toLowerCase().trim(); if (ft.indexOf("http:") == 0 || ft.indexOf("https:") == 0 @@ -422,6 +449,10 @@ public class AppletFormatAdapter { protocol = DataSourceType.URL; } + else if (Platform.isJS()) + { + protocol = DataSourceType.RELATIVE_URL; + } else if (new File(data).exists()) { protocol = DataSourceType.FILE; @@ -429,6 +460,10 @@ public class AppletFormatAdapter return protocol; } + /** + * @param args + * @j2sIgnore + */ public static void main(String[] args) { int i = 0;