X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FFileLoader.java;h=b41073c340fec150aaee9434e7203f55298b9d9e;hb=55f6f8a9ddd0b8bb4445d1cc582297af1d0aa4c5;hp=c3afe1fdae41e4988ff19eaeff3f24acc34a74df;hpb=9df9ea39635e009b54078c300e8270ca45415410;p=jalview.git diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index c3afe1f..b41073c 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -37,6 +37,7 @@ import jalview.gui.JvOptionPane; import jalview.json.binding.biojson.v1.ColourSchemeMapper; import jalview.project.Jalview2XML; import jalview.schemes.ColourSchemeI; +import jalview.structure.StructureSelectionManager; import jalview.util.MessageManager; import jalview.util.Platform; import jalview.ws.utils.UrlDownloadClient; @@ -280,6 +281,8 @@ public class FileLoader implements Runnable @Override public void run() { + + String title = protocol == DataSourceType.PASTE ? "Copied From Clipboard" : file; @@ -298,7 +301,8 @@ public class FileLoader implements Runnable format = new IdentifyFile().identify(source, false); // identify stream and rewind rather than close } - else if (selectedFile != null) { + else if (selectedFile != null) + { format = new IdentifyFile().identify(selectedFile, protocol); } else @@ -324,9 +328,11 @@ public class FileLoader implements Runnable } return; } + // TODO: cache any stream datasources as a temporary file (eg. PDBs // retrieved via URL) - if (Desktop.getDesktopPane() != null && Desktop.getDesktopPane().isShowMemoryUsage()) + if (Desktop.getDesktopPane() != null + && Desktop.getDesktopPane().isShowMemoryUsage()) { System.gc(); memused = (rt.maxMemory() - rt.totalMemory() + rt.freeMemory()); // free @@ -348,7 +354,8 @@ public class FileLoader implements Runnable } // BH 2018 switch to File object here instead of filename Platform.timeCheck(null, Platform.TIME_MARK); - alignFrame = new Jalview2XML(raiseGUI).loadJalviewAlign(selectedFile == null ? file : selectedFile); + alignFrame = new Jalview2XML(raiseGUI).loadJalviewAlign( + selectedFile == null ? file : selectedFile); Platform.timeCheck("JVP loaded", Platform.TIME_MARK); } @@ -378,27 +385,29 @@ public class FileLoader implements Runnable file.lastIndexOf(".")); String tempStructureFileStr = createNamedJvTempFile( urlLeafName, structExt); - + // BH - switching to File object here so as to hold // .秘bytes array directly File tempFile = new File(tempStructureFileStr); UrlDownloadClient.download(file, tempFile); - - al = fa.readFile(tempFile, DataSourceType.FILE, - format); + + al = fa.readFile(tempFile, DataSourceType.FILE, format); source = fa.getAlignFile(); } else { - if (selectedFile == null) { + if (selectedFile == null) + { al = fa.readFile(file, protocol, format); - - } else { + + } + else + { al = fa.readFile(selectedFile, protocol, format); - } + } source = fa.getAlignFile(); // keep reference for later if - - // necessary. + + // necessary. } } } catch (java.io.IOException ex) @@ -406,9 +415,17 @@ public class FileLoader implements Runnable error = ex.getMessage(); } + System.out.println("OK1"); + + if ((al != null) && (al.getHeight() > 0) && al.hasValidSequence()) { + + // construct and register dataset sequences + + StructureSelectionManager ssm = StructureSelectionManager + .getStructureSelectionManager(Desktop.getInstance()); for (SequenceI sq : al.getSequences()) { while (sq.getDatasetSequence() != null) @@ -421,16 +438,17 @@ public class FileLoader implements Runnable { // register PDB entries with desktop's structure selection // manager - Desktop.getInstance().getStructureSelectionManager() - .registerPDBEntry(pdbe); + ssm.registerPDBEntry(pdbe); } } } FeatureSettingsModelI proxyColourScheme = source .getFeatureColourScheme(); + if (viewport != null) { + if (proxyColourScheme != null) { viewport.applyFeaturesStyle(proxyColourScheme); @@ -440,6 +458,8 @@ public class FileLoader implements Runnable } else { + + System.out.println("OK9"); // otherwise construct the alignFrame if (source instanceof ComplexAlignFile) @@ -452,8 +472,10 @@ public class FileLoader implements Runnable .getGlobalColourScheme(); FeaturesDisplayedI fd = ((ComplexAlignFile) source) .getDisplayedFeatures(); + alignFrame = new AlignFrame(al, hiddenSeqs, colSel, AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); + alignFrame.getViewport().setFeaturesDisplayed(fd); alignFrame.getViewport().setShowSequenceFeatures( ((ComplexAlignFile) source).isShowSeqFeatures()); @@ -466,28 +488,64 @@ public class FileLoader implements Runnable } else { - alignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH, - AlignFrame.DEFAULT_HEIGHT); + + // Headless start fails here in Windows + + // Sorry, no JInternalFrame when headless, at least in Windows. + // Not clear why that would be, since an InternalFrame is not a + // top-level component. But maybe it is + + System.out.println("FileLoader test1"); + + try + { + // + alignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH, + AlignFrame.DEFAULT_HEIGHT); + + System.out.println("FileLoader test2"); + + } catch (Throwable t) + { + System.out.println(t); + t.printStackTrace(); + } + if (source instanceof FeaturesSourceI) { + + System.out.println("FileLoader test3"); + alignFrame.getViewport().setShowSequenceFeatures(true); } } // add metadata and update ui + + System.out.println("FileLoader test4"); + if (!(protocol == DataSourceType.PASTE)) { + + System.out.println("FileLoader test5"); alignFrame.setFileName(file, format); alignFrame.setFileObject(selectedFile); // BH 2018 SwingJS } + + System.out.println("FileLoader test6"); + if (proxyColourScheme != null) { alignFrame.getViewport() .applyFeaturesStyle(proxyColourScheme); } + + System.out.println("FileLoader test7"); + alignFrame.setStatus(MessageManager.formatMessage( "label.successfully_loaded_file", new String[] { title })); + System.out.println("FileLoader test8" + raiseGUI); if (raiseGUI) { // add the window to the GUI @@ -510,6 +568,9 @@ public class FileLoader implements Runnable } else { + + System.out.println("OK10"); + if (Desktop.getInstance() != null) { Desktop.getInstance().stopLoading(); @@ -519,15 +580,15 @@ public class FileLoader implements Runnable "label.couldnt_load_file") + " " + title + "\n" + error; // TODO: refactor FileLoader to be independent of Desktop / Applet GUI // bits ? - if (raiseGUI && Desktop.getDesktopPane() != null) + if (raiseGUI) { javax.swing.SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(), - errorMessage, + JvOptionPane.showInternalMessageDialog( + Desktop.getDesktopPane(), errorMessage, MessageManager .getString("label.error_loading_file"), JvOptionPane.WARNING_MESSAGE); @@ -541,6 +602,7 @@ public class FileLoader implements Runnable } } + updateRecentlyOpened(); } catch (Exception er) @@ -589,6 +651,7 @@ public class FileLoader implements Runnable } loadtime += System.currentTimeMillis(); + // TODO: Estimate percentage of memory used by a newly loaded alignment - // warn if more memory will be needed to work with it // System.gc(); @@ -598,7 +661,8 @@ public class FileLoader implements Runnable // memory // after // load - if (Desktop.getDesktopPane() != null && Desktop.getDesktopPane().isShowMemoryUsage()) + if (Desktop.getDesktopPane() != null + && Desktop.getDesktopPane().isShowMemoryUsage()) { if (alignFrame != null) {