X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FAppletFormatAdapter.java;h=9a4e9823ce1999d4054e8447502679f7d3c4a81d;hb=2f36a546ff554e3db3d7cb6bcc899dcd01dd242c;hp=2362010dbd073f50f363dc59ba8017f06c8b473b;hpb=f14071cd4c32feeacdb6d4638ef4e3b52071f2f3;p=jalview.git diff --git a/src/jalview/io/AppletFormatAdapter.java b/src/jalview/io/AppletFormatAdapter.java index 2362010..9a4e982 100755 --- a/src/jalview/io/AppletFormatAdapter.java +++ b/src/jalview/io/AppletFormatAdapter.java @@ -20,22 +20,23 @@ */ package jalview.io; -import jalview.api.AlignExportSettingI; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Locale; + +import jalview.api.AlignExportSettingsI; import jalview.api.AlignmentViewPanel; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentView; -import jalview.datamodel.SeqDistanceContactMatrix; import jalview.datamodel.PDBEntry.Type; import jalview.datamodel.SequenceI; import jalview.ext.jmol.JmolParser; import jalview.structure.StructureImportSettings; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; +import jalview.util.Platform; /** * A low level class for alignment and feature IO with alignment formatting @@ -74,7 +75,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"; @@ -99,7 +102,7 @@ public class AppletFormatAdapter } public AppletFormatAdapter(AlignmentViewPanel alignPanel, - AlignExportSettingI settings) + AlignExportSettingsI settings) { viewpanel = alignPanel; exportSettings = settings; @@ -148,7 +151,23 @@ public class AppletFormatAdapter public AlignmentI readFile(String file, DataSourceType sourceType, FileFormatI fileFormat) throws IOException { - this.inFile = file; + return readFile(null, file, sourceType, fileFormat); + } + + public AlignmentI readFile(File selectedFile, String file, + DataSourceType sourceType, FileFormatI fileFormat) + throws IOException + { + return readFile(selectedFile, file, sourceType, fileFormat, null); + } + + public AlignmentI readFile(File selectedFile, String file, + DataSourceType sourceType, FileFormatI fileFormat, + StructureImportSettings.TFType tempfacType) throws IOException + { + + this.selectedFile = selectedFile; + this.inFile = selectedFile != null ? selectedFile.getPath() : file; try { if (fileFormat.isStructureFile()) @@ -160,21 +179,33 @@ public class AppletFormatAdapter .toString()); StructureImportSettings.addSettings(annotFromStructure, localSecondaryStruct, serviceSecondaryStruct); + if (tempfacType != null) + { + StructureImportSettings.setTemperatureFactorType(tempfacType); + } if (isParseWithJMOL) { - alignFile = new JmolParser(inFile, sourceType); + // needs a File option + alignFile = new JmolParser( + selectedFile == null ? inFile : selectedFile, sourceType, + StructureImportSettings.getTemperatureFactorType()); } 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 if (selectedFile != null) + { + alignFile = fileFormat + .getReader(new FileParse(selectedFile, sourceType)); + } else { // alignFile = fileFormat.getAlignmentFile(inFile, sourceType); @@ -251,7 +282,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); @@ -318,8 +349,6 @@ public class AppletFormatAdapter alignFile.addGroups(al); - al.addContactList(new SeqDistanceContactMatrix(al.getWidth())); - return al; } @@ -412,19 +441,32 @@ public class AppletFormatAdapter /** * 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(); + String ft = data.toLowerCase(Locale.ROOT).trim(); if (ft.indexOf("http:") == 0 || ft.indexOf("https:") == 0 || ft.indexOf("file:") == 0) { protocol = DataSourceType.URL; } + else if (Platform.isJS()) + { + protocol = DataSourceType.RELATIVE_URL; + } else if (new File(data).exists()) { protocol = DataSourceType.FILE; @@ -432,6 +474,10 @@ public class AppletFormatAdapter return protocol; } + /** + * @param args + * @j2sIgnore + */ public static void main(String[] args) { int i = 0;