From: gmungoc Date: Tue, 25 Apr 2017 13:13:53 +0000 (+0100) Subject: JAL-2476 ability to drag and drop score matrix file to desktop, simplify X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=e4496f5b27c5a01a1cc494653bd3f9f49080d544;p=jalview.git JAL-2476 ability to drag and drop score matrix file to desktop, simplify FileLoader overloads --- diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 26cc4b5..d3cf8db 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -336,7 +336,7 @@ label.colour_residues_above_occurrence = Colour residues above % occurrence label.set_this_label_text = set this label text label.sequences_from = Sequences from {0} label.successfully_loaded_file = Successfully loaded file {0} -label.successfully_loaded_matrix = Successfully loaded score matrix {0} +label.successfully_loaded_file_type = Successfully loaded {0} file

{1} label.successfully_saved_to_file_in_format = Successfully saved to file: {0} in {1} format. label.copied_sequences_to_clipboard = Copied {0} sequences to clipboard. label.check_file_matches_sequence_ids_alignment = Check that the file matches sequence IDs in the alignment. diff --git a/src/jalview/analysis/scoremodels/ScoreModels.java b/src/jalview/analysis/scoremodels/ScoreModels.java index 494d09f..3b46f11 100644 --- a/src/jalview/analysis/scoremodels/ScoreModels.java +++ b/src/jalview/analysis/scoremodels/ScoreModels.java @@ -14,14 +14,14 @@ import java.util.Map; */ public class ScoreModels { + private static ScoreModels instance = new ScoreModels(); + private final ScoreMatrix BLOSUM62; private final ScoreMatrix PAM250; private final ScoreMatrix DNA; - private static ScoreModels instance = new ScoreModels(); - private Map models; public static ScoreModels getInstance() @@ -68,7 +68,7 @@ public class ScoreModels * delegate parsing to ScoreMatrixFile */ FileParse fp = new FileParse(resourcePath, DataSourceType.CLASSLOADER); - ScoreMatrix sm = new ScoreMatrixFile(fp).parseMatrix(); + ScoreMatrix sm = new ScoreMatrixFile(false, fp).parseMatrix(); registerScoreModel(sm); return sm; } catch (IOException e) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index bed434d..6635ef0 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -4682,14 +4682,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } if (FileFormat.ScoreMatrix == format) { + // load and register the score matrix ScoreMatrixFile sm = new ScoreMatrixFile(new FileParse(file, sourceType)); - sm.parse(); - // todo: i18n this message - statusBar - .setText(MessageManager.formatMessage( - "label.successfully_loaded_matrix", - sm.getMatrixName())); + statusBar.setText(MessageManager.formatMessage( + "label.successfully_loaded_file_type", + format.getName(), sm.getMatrixName())); } else if (FileFormat.Jnet.equals(format)) { diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 7d0eb7f..207bba0 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -716,7 +716,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements FileFormatI format = new IdentifyFile().identify(file, DataSourceType.PASTE); - new FileLoader().LoadFile(file, DataSourceType.PASTE, format); + new FileLoader().LoadFile(null, file, DataSourceType.PASTE, format); } } catch (Exception ex) @@ -1016,7 +1016,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements format = new IdentifyFile().identify(file, protocol); } - new FileLoader().LoadFile(file, protocol, format); + new FileLoader().LoadFile(null, file, protocol, format); } } catch (Exception ex) @@ -1072,15 +1072,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements } } - if (viewport != null) - { - new FileLoader().LoadFile(viewport, choice, DataSourceType.FILE, - format); - } - else - { - new FileLoader().LoadFile(choice, DataSourceType.FILE, format); - } + new FileLoader().LoadFile(viewport, choice, DataSourceType.FILE, + format); } } @@ -1133,16 +1126,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements if (url.toLowerCase().endsWith(".jar")) { - if (viewport != null) - { new FileLoader().LoadFile(viewport, url, DataSourceType.URL, FileFormat.Jalview); - } - else - { - new FileLoader().LoadFile(url, DataSourceType.URL, - FileFormat.Jalview); - } } else { @@ -1167,15 +1152,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements return; } - if (viewport != null) - { - new FileLoader() - .LoadFile(viewport, url, DataSourceType.URL, format); - } - else - { - new FileLoader().LoadFile(url, DataSourceType.URL, format); - } + new FileLoader().LoadFile(viewport, url, DataSourceType.URL, format); } } diff --git a/src/jalview/io/FileFormat.java b/src/jalview/io/FileFormat.java index 3354b88..d562222 100644 --- a/src/jalview/io/FileFormat.java +++ b/src/jalview/io/FileFormat.java @@ -255,6 +255,12 @@ public enum FileFormat implements FileFormatI { return new FeaturesFile(); } + + @Override + public boolean hasSequenceData() + { + return false; + } }, ScoreMatrix("Substitution matrix", "", false, false) { @@ -270,6 +276,12 @@ public enum FileFormat implements FileFormatI { return null; } + + @Override + public boolean hasSequenceData() + { + return false; + } }, PDB("PDB", "pdb,ent", true, false) { @@ -436,4 +448,10 @@ public enum FileFormat implements FileFormatI { return true; } + + @Override + public boolean hasSequenceData() + { + return true; + } } diff --git a/src/jalview/io/FileFormatI.java b/src/jalview/io/FileFormatI.java index e6f390d..ca2de4b 100644 --- a/src/jalview/io/FileFormatI.java +++ b/src/jalview/io/FileFormatI.java @@ -60,4 +60,12 @@ public interface FileFormatI * @return */ boolean isStructureFile(); + + /** + * Answers true if the file format can provide sequence data (that could form + * an alignment) + * + * @return + */ + boolean hasSequenceData(); } diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index 4f83ab1..e41403c 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -35,6 +35,7 @@ import jalview.gui.AlignViewport; import jalview.gui.Desktop; import jalview.gui.Jalview2XML; import jalview.gui.JvOptionPane; +import jalview.gui.JvSwingUtils; import jalview.json.binding.biojson.v1.ColourSchemeMapper; import jalview.schemes.ColourSchemeI; import jalview.structure.StructureSelectionManager; @@ -91,18 +92,12 @@ public class FileLoader implements Runnable DataSourceType protocol, FileFormatI format) { this.viewport = viewport; - LoadFile(file, protocol, format); - } - - public void LoadFile(String file, DataSourceType protocol, - FileFormatI format) - { this.file = file; this.protocol = protocol; this.format = format; - + final Thread loader = new Thread(this); - + SwingUtilities.invokeLater(new Runnable() { @Override @@ -114,17 +109,6 @@ public class FileLoader implements Runnable } /** - * Load a (file, protocol) source of unknown type - * - * @param file - * @param protocol - */ - public void LoadFile(String file, DataSourceType protocol) - { - LoadFile(file, protocol, null); - } - - /** * Load alignment from (file, protocol) and wait till loaded * * @param file @@ -155,24 +139,6 @@ public class FileLoader implements Runnable } /** - * Load alignment from FileParse source of type format and wait till loaded - * - * @param source - * @param format - * @return alignFrame constructed from file contents - */ - public AlignFrame LoadFileWaitTillLoaded(AlignmentFileReaderI source, - FileFormatI format) - { - this.source = source; - - file = source.getInFile(); - protocol = source.getDataSourceType(); - this.format = format; - return _LoadFileWaitTillLoaded(); - } - - /** * start thread and wait until finished, then return the alignFrame that's * (hopefully) been read. * @@ -245,7 +211,7 @@ public class FileLoader implements Runnable @Override public void run() { - String title = protocol == DataSourceType.PASTE ? "Copied From Clipboard" + final String title = protocol == DataSourceType.PASTE ? "Copied From Clipboard" : file; Runtime rt = Runtime.getRuntime(); try @@ -291,10 +257,8 @@ public class FileLoader implements Runnable if (Desktop.desktop != null && Desktop.desktop.isShowMemoryUsage()) { System.gc(); - memused = (rt.maxMemory() - rt.totalMemory() + rt.freeMemory()); // free - // memory - // before - // load + // free memory before loading file + memused = (rt.maxMemory() - rt.totalMemory() + rt.freeMemory()); } loadtime = -System.currentTimeMillis(); AlignmentI al = null; @@ -334,7 +298,22 @@ public class FileLoader implements Runnable error = ex.getMessage(); } - if ((al != null) && (al.getHeight() > 0) && al.hasValidSequence()) + if (!format.hasSequenceData()) + { + javax.swing.SwingUtilities.invokeLater(new Runnable() + { + @Override + public void run() + { + String msg = MessageManager.formatMessage("label.successfully_loaded_file_type", format.getName(), title); + msg = JvSwingUtils.wrapTooltip(true, msg); + JvOptionPane.showInternalMessageDialog(Desktop.desktop, msg, + "", JvOptionPane.INFORMATION_MESSAGE); + } + }); + } + else if ((al != null) && (al.getHeight() > 0) + && al.hasValidSequence()) { // construct and register dataset sequences for (SequenceI sq : al.getSequences()) @@ -347,8 +326,6 @@ public class FileLoader implements Runnable { for (PDBEntry pdbe : sq.getAllPDBEntries()) { - // register PDB entries with desktop's structure selection - // manager StructureSelectionManager.getStructureSelectionManager( Desktop.instance).registerPDBEntry(pdbe); } @@ -368,71 +345,7 @@ public class FileLoader implements Runnable } else { - // otherwise construct the alignFrame - - if (source instanceof ComplexAlignFile) - { - ColumnSelection colSel = ((ComplexAlignFile) source) - .getColumnSelection(); - SequenceI[] hiddenSeqs = ((ComplexAlignFile) source) - .getHiddenSequences(); - String colourSchemeName = ((ComplexAlignFile) source) - .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()); - ColourSchemeI cs = ColourSchemeMapper.getJalviewColourScheme( - colourSchemeName, al); - if (cs != null) - { - alignFrame.changeColour(cs); - } - } - else - { - alignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH, - AlignFrame.DEFAULT_HEIGHT); - if (source instanceof FeaturesSourceI) - { - alignFrame.getViewport().setShowSequenceFeatures(true); - } - } - // add metadata and update ui - if (!(protocol == DataSourceType.PASTE)) - { - alignFrame.setFileName(file, format); - } - if (proxyColourScheme != null) - { - alignFrame.getViewport() - .applyFeaturesStyle(proxyColourScheme); - } - alignFrame.statusBar.setText(MessageManager.formatMessage( - "label.successfully_loaded_file", - new String[] { title })); - - if (raiseGUI) - { - // add the window to the GUI - // note - this actually should happen regardless of raiseGUI - // status in Jalview 3 - // TODO: define 'virtual desktop' for benefit of headless scripts - // that perform queries to find the 'current working alignment' - Desktop.addInternalFrame(alignFrame, title, - AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); - } - - try - { - alignFrame.setMaximum(jalview.bin.Cache.getDefault( - "SHOW_FULLSCREEN", false)); - } catch (java.beans.PropertyVetoException ex) - { - } + addAlignFrame(al, title); } } else @@ -449,7 +362,8 @@ public class FileLoader implements Runnable + "\n" + error; // TODO: refactor FileLoader to be independent of Desktop / Applet GUI // bits ? - if (raiseGUI && Desktop.desktop != null) + if (format.hasSequenceData() && raiseGUI + && Desktop.desktop != null) { javax.swing.SwingUtilities.invokeLater(new Runnable() { @@ -556,18 +470,81 @@ public class FileLoader implements Runnable } - /* - * (non-Javadoc) + /** + * Helper method that adds the alignment as a new frame on the Desktop * - * @see java.lang.Object#finalize() + * @param al + * @param title */ - @Override - protected void finalize() throws Throwable + protected void addAlignFrame(AlignmentI al, String title) { - source = null; - alignFrame = null; - viewport = null; - super.finalize(); + // otherwise construct the alignFrame + + if (source instanceof ComplexAlignFile) + { + ColumnSelection colSel = ((ComplexAlignFile) source) + .getColumnSelection(); + SequenceI[] hiddenSeqs = ((ComplexAlignFile) source) + .getHiddenSequences(); + String colourSchemeName = ((ComplexAlignFile) source) + .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()); + ColourSchemeI cs = ColourSchemeMapper.getJalviewColourScheme( + colourSchemeName, al); + if (cs != null) + { + alignFrame.changeColour(cs); + } + } + else + { + alignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH, + AlignFrame.DEFAULT_HEIGHT); + if (source instanceof FeaturesSourceI) + { + alignFrame.getViewport().setShowSequenceFeatures(true); + } + } + // add metadata and update ui + if (!(protocol == DataSourceType.PASTE)) + { + alignFrame.setFileName(file, format); + } + FeatureSettingsModelI proxyColourScheme = source + .getFeatureColourScheme(); + if (proxyColourScheme != null) + { + alignFrame.getViewport() + .applyFeaturesStyle(proxyColourScheme); + } + alignFrame.statusBar.setText(MessageManager.formatMessage( + "label.successfully_loaded_file", + new String[] { title })); + + if (raiseGUI) + { + // add the window to the GUI + // note - this actually should happen regardless of raiseGUI + // status in Jalview 3 + // TODO: define 'virtual desktop' for benefit of headless scripts + // that perform queries to find the 'current working alignment' + Desktop.addInternalFrame(alignFrame, title, + AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); + } + + try + { + alignFrame.setMaximum(jalview.bin.Cache.getDefault( + "SHOW_FULLSCREEN", false)); + } catch (java.beans.PropertyVetoException ex) + { + } } } diff --git a/src/jalview/io/ScoreMatrixFile.java b/src/jalview/io/ScoreMatrixFile.java index 3a7ff4f..d28c511 100644 --- a/src/jalview/io/ScoreMatrixFile.java +++ b/src/jalview/io/ScoreMatrixFile.java @@ -53,14 +53,28 @@ public class ScoreMatrixFile extends AlignFile implements boolean hasGuideColumn; /** - * Constructor + * Constructor given a file reader. The file is parsed immediately and if + * successful, the score model registered with the ScoreModels singleton. * * @param source * @throws IOException */ public ScoreMatrixFile(FileParse source) throws IOException { - super(false, source); + super(true, source); + } + + /** + * Constructor given a file reader. The data is optionally parsed immediately. + * + * @param parseImmediately + * @param source + * @throws IOException + */ + public ScoreMatrixFile(boolean parseImmediately, FileParse source) + throws IOException + { + super(parseImmediately, source); } @Override