X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=95f1ed19f6fc33535d98855f30ea4893fd866d4d;hb=bf448d3b8794da07525adedec9f1ff04428e84cb;hp=a40044aadda4df2ada2c7cc7eb9186ba611caf24;hpb=9f55824dd20f0ffcf10d4a751140198e910e5393;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index a40044a..95f1ed1 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -88,6 +88,7 @@ import jalview.schemes.ColourSchemes; import jalview.schemes.ResidueColourScheme; import jalview.schemes.TCoffeeColourScheme; import jalview.util.MessageManager; +import jalview.util.dialogrunner.RunResponse; import jalview.viewmodel.AlignmentViewport; import jalview.viewmodel.ViewportRanges; import jalview.ws.DBRefFetcher; @@ -181,6 +182,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, */ String fileName = null; + File fileObject; + /** * Creates a new AlignFrame object with specific width and height. * @@ -333,6 +336,27 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, Desktop.getDesktop().propertyChange(evt); } + + /** + * BH 2018 + * + * @return true if we have any features + */ + @Override + protected boolean haveAlignmentFeatures() { + AlignmentI alignment = getViewport().getAlignment(); + + for (int i = 0; i < alignment.getHeight(); i++) + { + SequenceI seq = alignment.getSequenceAt(i); + for (String group : seq.getFeatures().getFeatureGroups(true)) + { + if (group != null)return true; + } + } + return false; + } + /** * initalise the alignframe from the underlying viewport data and the * configurations @@ -512,6 +536,16 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, setFileFormat(format); reload.setEnabled(true); } + + /** + * JavaScript will have this, maybe others. More dependable than a file name + * and maintains a reference to the actual bytes loaded. + * + * @param file + */ + public void setFileObject(File file) { + this.fileObject = file; + } /** * Add a KeyListener with handlers for various KeyPressed and KeyReleased @@ -1043,8 +1077,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, FileLoader loader = new FileLoader(); DataSourceType protocol = fileName.startsWith("http:") - ? DataSourceType.URL - : DataSourceType.FILE; + ? DataSourceType.URL : DataSourceType.FILE; loader.LoadFile(viewport, fileName, protocol, currentFileFormat); } else @@ -1052,11 +1085,21 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, Rectangle bounds = this.getBounds(); FileLoader loader = new FileLoader(); - DataSourceType protocol = fileName.startsWith("http:") - ? DataSourceType.URL - : DataSourceType.FILE; - AlignFrame newframe = loader.LoadFileWaitTillLoaded(fileName, - protocol, currentFileFormat); + + AlignFrame newframe = null; + + if (fileObject == null) + { + + DataSourceType protocol = (fileName.startsWith("http:") + ? DataSourceType.URL : DataSourceType.FILE); + newframe = loader.LoadFileWaitTillLoaded(fileName, protocol, + currentFileFormat); + } + else + { + newframe = loader.LoadFileWaitTillLoaded(fileObject, DataSourceType.FILE, currentFileFormat); + } newframe.setBounds(bounds); if (featureSettings != null && featureSettings.isShowing()) @@ -1120,42 +1163,41 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { String format = currentFileFormat == null ? null : currentFileFormat.getName(); - JalviewFileChooser chooser = JalviewFileChooser + final JalviewFileChooser chooser = JalviewFileChooser .forWrite(Cache.getProperty("LAST_DIRECTORY"), format); - + final AlignFrame us = this; chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle( MessageManager.getString("label.save_alignment_to_file")); chooser.setToolTipText(MessageManager.getString("action.save")); - int value = chooser.showSaveDialog(this); - - - if (value == JalviewFileChooser.APPROVE_OPTION) + chooser.response(new RunResponse(JalviewFileChooser.APPROVE_OPTION) { - currentFileFormat = chooser.getSelectedFormat(); - while (currentFileFormat == null) - { - JvOptionPane.showInternalMessageDialog(Desktop.desktop, - MessageManager.getString( - "label.select_file_format_before_saving"), - MessageManager.getString("label.file_format_not_specified"), - JvOptionPane.WARNING_MESSAGE); + @Override + public void run() + { currentFileFormat = chooser.getSelectedFormat(); - value = chooser.showSaveDialog(this); - if (value != JalviewFileChooser.APPROVE_OPTION) + while (currentFileFormat == null) { - return; + JvOptionPane.showInternalMessageDialog(Desktop.desktop, + MessageManager.getString( + "label.select_file_format_before_saving"), + MessageManager + .getString("label.file_format_not_specified"), + JvOptionPane.WARNING_MESSAGE); + currentFileFormat = chooser.getSelectedFormat(); + chooser.showSaveDialog(us); } - } - fileName = chooser.getSelectedFile().getPath(); + fileName = chooser.getSelectedFile().getPath(); - Cache.setProperty("DEFAULT_FILE_FORMAT", currentFileFormat.getName()); + Cache.setProperty("DEFAULT_FILE_FORMAT", + currentFileFormat.getName()); - Cache.setProperty("LAST_DIRECTORY", fileName); - saveAlignment(fileName, currentFileFormat); - } + Cache.setProperty("LAST_DIRECTORY", fileName); + saveAlignment(fileName, currentFileFormat); + } + }).showSaveDialog(this); } public boolean saveAlignment(String file, FileFormatI format) @@ -1422,40 +1464,27 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void associatedData_actionPerformed(ActionEvent e) { - // Pick the tree file - JalviewFileChooser chooser = new JalviewFileChooser( + final JalviewFileChooser chooser = new JalviewFileChooser( jalview.bin.Cache.getProperty("LAST_DIRECTORY")); chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle( MessageManager.getString("label.load_jalview_annotations")); chooser.setToolTipText( MessageManager.getString("label.load_jalview_annotations")); - - Desktop.getDesktop().dialogData = new Object[] { "SelectedFile", - new Runnable() + chooser.response(new RunResponse(JalviewFileChooser.APPROVE_OPTION) { @Override public void run() { - Object[] data = Desktop.getDesktop().dialogData; - int value = ((Integer) data[0]).intValue(); - - if (value == JFileChooser.APPROVE_OPTION) - { - JalviewFileChooser chooser = (JalviewFileChooser) data[2]; - String choice = chooser.getSelectedFile().getPath(); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); - loadJalviewDataFile(choice, null, null, null); - } + String choice = chooser.getSelectedFile().getPath(); + jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); + loadJalviewDataFile(chooser.getSelectedFile(), null, null, null); } - }, chooser }; - - chooser.showOpenDialog(null); - - + }); + chooser.openDialog(this); } /** @@ -3913,33 +3942,40 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, chooser.setToolTipText( MessageManager.getString("label.load_tree_file")); - int value = chooser.showOpenDialog(null); - - if (value == JalviewFileChooser.APPROVE_OPTION) - { - String filePath = chooser.getSelectedFile().getPath(); - Cache.setProperty("LAST_DIRECTORY", filePath); - NewickFile fin = null; - try - { - fin = new NewickFile(filePath, DataSourceType.FILE); - viewport.setCurrentTree(showNewickTree(fin, filePath).getTree()); - } catch (Exception ex) - { - JvOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(), - MessageManager.getString("label.problem_reading_tree_file"), - JvOptionPane.WARNING_MESSAGE); - ex.printStackTrace(); - } - if (fin != null && fin.hasWarningMessage()) - { - JvOptionPane.showMessageDialog(Desktop.desktop, - fin.getWarningMessage(), - MessageManager - .getString("label.possible_problem_with_tree_file"), - JvOptionPane.WARNING_MESSAGE); - } - } + chooser.response( + new jalview.util.dialogrunner.RunResponse(JalviewFileChooser.APPROVE_OPTION) + { + @Override + public void run() + { + String filePath = chooser.getSelectedFile().getPath(); + Cache.setProperty("LAST_DIRECTORY", filePath); + NewickFile fin = null; + try + { + fin = new NewickFile(new FileParse( + chooser.getSelectedFile(), DataSourceType.FILE)); + viewport.setCurrentTree( + showNewickTree(fin, filePath).getTree()); + } catch (Exception ex) + { + JvOptionPane.showMessageDialog(Desktop.desktop, + ex.getMessage(), + MessageManager.getString( + "label.problem_reading_tree_file"), + JvOptionPane.WARNING_MESSAGE); + ex.printStackTrace(); + } + if (fin != null && fin.hasWarningMessage()) + { + JvOptionPane.showMessageDialog(Desktop.desktop, + fin.getWarningMessage(), + MessageManager.getString( + "label.possible_problem_with_tree_file"), + JvOptionPane.WARNING_MESSAGE); + } + } + }).openDialog(this); } public TreePanel showNewickTree(NewickFile nf, String treeTitle) @@ -4550,7 +4586,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, */ for (Object[] o : filesmatched) { - filesnotmatched.add((String) o[0]); + filesnotmatched.add(o[0]); } } } @@ -5633,22 +5669,27 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override protected void loadVcf_actionPerformed() { - // TODO: JAL-3048 - No VCF support in JsJalview JalviewFileChooser chooser = new JalviewFileChooser( Cache.getProperty("LAST_DIRECTORY")); chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle(MessageManager.getString("label.load_vcf_file")); chooser.setToolTipText(MessageManager.getString("label.load_vcf_file")); + final AlignFrame us = this; + chooser.response(new RunResponse(JalviewFileChooser.APPROVE_OPTION) + { + @Override + public void run() + { - int value = chooser.showOpenDialog(null); + { + String choice = chooser.getSelectedFile().getPath(); + Cache.setProperty("LAST_DIRECTORY", choice); + SequenceI[] seqs = viewport.getAlignment().getSequencesArray(); + new VCFLoader(choice).loadVCF(seqs, us); + } - if (value == JalviewFileChooser.APPROVE_OPTION) - { - String choice = chooser.getSelectedFile().getPath(); - Cache.setProperty("LAST_DIRECTORY", choice); - SequenceI[] seqs = viewport.getAlignment().getSequencesArray(); - new VCFLoader(choice).loadVCF(seqs, this); - } + }; + }).openDialog(null); }