X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=a71d75fe4f08d0c42940306f4bbf1dc3b7cd0678;hb=f96e6a945e2df8a844f428c08cfc08210d937fc0;hp=b5298aef35aa21bfa698fd32db65767ba8d2e924;hpb=f1f528a731ee18c62c4f1944ea3eda41960f16f9;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index b5298ae..a71d75f 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -20,12 +20,14 @@ */ package jalview.gui; +import java.util.Locale; import jalview.analysis.AlignmentSorter; import jalview.analysis.AlignmentUtils; import jalview.analysis.CrossRef; import jalview.analysis.Dna; import jalview.analysis.ParseProperties; import jalview.analysis.SequenceIdMatcher; +import jalview.analysis.TreeModel; import jalview.api.AlignExportSettingI; import jalview.api.AlignViewControllerGuiI; import jalview.api.AlignViewControllerI; @@ -34,7 +36,6 @@ import jalview.api.AlignmentViewPanel; import jalview.api.FeatureSettingsControllerI; import jalview.api.SplitContainerI; import jalview.api.ViewStyleI; -import jalview.api.analysis.SimilarityParamsI; import jalview.bin.Cache; import jalview.bin.Jalview; import jalview.commands.CommandI; @@ -60,6 +61,9 @@ import jalview.datamodel.SeqCigar; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; +import jalview.ext.archaeopteryx.AptxInit; +import jalview.ext.forester.io.SupportedTreeFileFilter; +import jalview.ext.forester.io.TreeParser; import jalview.gui.ColourMenuHelper.ColourChangeListener; import jalview.gui.ViewSelectionMenu.ViewSetProvider; import jalview.io.AlignmentProperties; @@ -81,7 +85,6 @@ import jalview.io.JnetAnnotationMaker; import jalview.io.NewickFile; import jalview.io.ScoreMatrixFile; import jalview.io.TCoffeeScoreFile; -import jalview.io.vcf.VCFLoader; import jalview.jbgui.GAlignFrame; import jalview.schemes.ColourSchemeI; import jalview.schemes.ColourSchemes; @@ -98,7 +101,10 @@ import jalview.ws.jws2.jabaws2.Jws2Instance; import jalview.ws.seqfetcher.DbSourceProxy; import java.awt.BorderLayout; +import java.awt.Color; import java.awt.Component; +import java.awt.Dimension; +import java.awt.GridLayout; import java.awt.Rectangle; import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; @@ -124,6 +130,7 @@ import java.awt.print.PrinterJob; import java.beans.PropertyChangeEvent; import java.io.File; import java.io.FileWriter; +import java.io.IOException; import java.io.PrintWriter; import java.net.URL; import java.util.ArrayList; @@ -132,23 +139,116 @@ import java.util.Deque; import java.util.Enumeration; import java.util.Hashtable; import java.util.List; +import java.util.StringTokenizer; import java.util.Vector; +import javax.swing.ButtonGroup; import javax.swing.JCheckBoxMenuItem; +import javax.swing.JComponent; +import javax.swing.JComboBox; import javax.swing.JEditorPane; import javax.swing.JInternalFrame; +import javax.swing.JLabel; import javax.swing.JLayeredPane; import javax.swing.JMenu; import javax.swing.JMenuItem; +import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.SwingUtilities; +import ext.vamsas.ServiceHandle; +import jalview.analysis.AlignmentSorter; +import jalview.analysis.AlignmentUtils; +import jalview.analysis.CrossRef; +import jalview.analysis.Dna; +import jalview.analysis.GeneticCodeI; +import jalview.analysis.ParseProperties; +import jalview.analysis.SequenceIdMatcher; +import jalview.api.AlignExportSettingsI; +import jalview.api.AlignViewControllerGuiI; +import jalview.api.AlignViewControllerI; +import jalview.api.AlignViewportI; +import jalview.api.AlignmentViewPanel; +import jalview.api.FeatureSettingsControllerI; +import jalview.api.FeatureSettingsModelI; +import jalview.api.SplitContainerI; +import jalview.api.ViewStyleI; +import jalview.api.analysis.SimilarityParamsI; +import jalview.bin.Cache; +import jalview.bin.Console; +import jalview.bin.Jalview; +import jalview.commands.CommandI; +import jalview.commands.EditCommand; +import jalview.commands.EditCommand.Action; +import jalview.commands.OrderCommand; +import jalview.commands.RemoveGapColCommand; +import jalview.commands.RemoveGapsCommand; +import jalview.commands.SlideSequencesCommand; +import jalview.commands.TrimRegionCommand; +import jalview.datamodel.AlignExportSettingsAdapter; +import jalview.datamodel.AlignedCodonFrame; +import jalview.datamodel.Alignment; +import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.AlignmentExportData; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.AlignmentOrder; +import jalview.datamodel.AlignmentView; +import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; +import jalview.datamodel.PDBEntry; +import jalview.datamodel.SeqCigar; +import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceGroup; +import jalview.datamodel.SequenceI; +import jalview.gui.ColourMenuHelper.ColourChangeListener; +import jalview.gui.ViewSelectionMenu.ViewSetProvider; +import jalview.io.AlignmentProperties; +import jalview.io.AnnotationFile; +import jalview.io.BackupFiles; +import jalview.io.BioJsHTMLOutput; +import jalview.io.DataSourceType; +import jalview.io.FileFormat; +import jalview.io.FileFormatI; +import jalview.io.FileFormats; +import jalview.io.FileLoader; +import jalview.io.FileParse; +import jalview.io.FormatAdapter; +import jalview.io.HtmlSvgOutput; +import jalview.io.IdentifyFile; +import jalview.io.JPredFile; +import jalview.io.JalviewFileChooser; +import jalview.io.JalviewFileView; +import jalview.io.JnetAnnotationMaker; +import jalview.io.NewickFile; +import jalview.io.ScoreMatrixFile; +import jalview.io.TCoffeeScoreFile; +import jalview.io.vcf.VCFLoader; +import jalview.jbgui.GAlignFrame; +import jalview.project.Jalview2XML; +import jalview.schemes.ColourSchemeI; +import jalview.schemes.ColourSchemes; +import jalview.schemes.ResidueColourScheme; +import jalview.schemes.TCoffeeColourScheme; +import jalview.util.HttpUtils; +import jalview.util.ImageMaker.TYPE; +import jalview.util.MessageManager; +import jalview.util.Platform; +import jalview.viewmodel.AlignmentViewport; +import jalview.viewmodel.ViewportRanges; +import jalview.ws.DBRefFetcher; +import jalview.ws.DBRefFetcher.FetchFinishedListenerI; +import jalview.ws.jws1.Discoverer; +import jalview.ws.jws2.Jws2Discoverer; +import jalview.ws.jws2.jabaws2.Jws2Instance; +import jalview.ws.seqfetcher.DbSourceProxy; + /** * DOCUMENT ME! * * @author $author$ * @version $Revision$ */ +@SuppressWarnings("serial") public class AlignFrame extends GAlignFrame implements DropTargetListener, IProgressIndicator, AlignViewControllerGuiI, ColourChangeListener { @@ -178,6 +278,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, */ String fileName = null; + File fileObject; + /** * Creates a new AlignFrame object with specific width and height. * @@ -330,6 +432,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, */ void init() { + // setBackground(Color.white); // BH 2019 + if (!Jalview.isHeadlessMode()) { progressBar = new ProgressBar(this.statusPanel, this.statusBar); @@ -347,8 +451,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // modifyPID.setEnabled(false); } - String sortby = jalview.bin.Cache.getDefault("SORT_ALIGNMENT", - "No sort"); + String sortby = Cache.getDefault("SORT_ALIGNMENT", "No sort"); if (sortby.equals("Id")) { @@ -378,7 +481,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (Desktop.desktop != null) { this.setDropTarget(new java.awt.dnd.DropTarget(this, this)); - addServiceListeners(); + if (!Platform.isJS()) + { + addServiceListeners(); + } setGUINucleotide(); } @@ -387,14 +493,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, wrapMenuItem_actionPerformed(null); } - if (jalview.bin.Cache.getDefault("SHOW_OVERVIEW", false)) + if (Cache.getDefault("SHOW_OVERVIEW", false)) { this.overviewMenuItem_actionPerformed(null); } addKeyListener(); - final List selviews = new ArrayList<>(); + final List selviews = new ArrayList<>(); final List origview = new ArrayList<>(); final String menuLabel = MessageManager .getString("label.copy_format_from"); @@ -462,10 +568,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } } }); - if (Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase() + if (Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase(Locale.ROOT) .indexOf("devel") > -1 - || Cache.getDefault("VERSION", "DEVELOPMENT").toLowerCase() - .indexOf("test") > -1) + || Cache.getDefault("VERSION", "DEVELOPMENT") + .toLowerCase(Locale.ROOT).indexOf("test") > -1) { formatMenu.add(vsel); } @@ -497,6 +603,17 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } /** + * 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 * events */ @@ -532,7 +649,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } if (viewport.cursorMode) { - alignPanel.getSeqPanel().moveCursor(0, 1); + alignPanel.getSeqPanel().moveCursor(0, 1, evt.isShiftDown()); } break; @@ -543,7 +660,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } if (viewport.cursorMode) { - alignPanel.getSeqPanel().moveCursor(0, -1); + alignPanel.getSeqPanel().moveCursor(0, -1, evt.isShiftDown()); } break; @@ -556,7 +673,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } else { - alignPanel.getSeqPanel().moveCursor(-1, 0); + alignPanel.getSeqPanel().moveCursor(-1, 0, evt.isShiftDown()); } break; @@ -568,7 +685,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } else { - alignPanel.getSeqPanel().moveCursor(1, 0); + alignPanel.getSeqPanel().moveCursor(1, 0, evt.isShiftDown()); } break; @@ -595,7 +712,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, case KeyEvent.VK_BACK_SPACE: if (!viewport.cursorMode) { - cut_actionPerformed(null); + cut_actionPerformed(); } else { @@ -647,7 +764,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, case KeyEvent.VK_F2: viewport.cursorMode = !viewport.cursorMode; - statusBar.setText(MessageManager + setStatus(MessageManager .formatMessage("label.keyboard_editing_mode", new String[] { (viewport.cursorMode ? "on" : "off") })); if (viewport.cursorMode) @@ -733,9 +850,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, int aSize = alignPanels.size(); - tabbedPane.setVisible(aSize > 1 || ap.av.viewName != null); + tabbedPane.setVisible(aSize > 1 || ap.av.getViewName() != null); - if (aSize == 1 && ap.av.viewName == null) + if (aSize == 1 && ap.av.getViewName() == null) { this.getContentPane().add(ap, BorderLayout.CENTER); } @@ -748,7 +865,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, expandViews.setEnabled(true); gatherViews.setEnabled(true); - tabbedPane.addTab(ap.av.viewName, ap); + tabbedPane.addTab(ap.av.getViewName(), ap); ap.setVisible(false); } @@ -771,7 +888,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, gatherViews.setEnabled(true); tabbedPane.setVisible(true); AlignmentPanel first = alignPanels.get(0); - tabbedPane.addTab(first.av.viewName, first); + tabbedPane.addTab(first.av.getViewName(), first); this.getContentPane().add(tabbedPane, BorderLayout.CENTER); } @@ -818,7 +935,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, Desktop.instance.removeJalviewPropertyChangeListener("services", thisListener); closeMenuItem_actionPerformed(true); - }; + } }); // Finally, build the menu once to get current service state new Thread(new Runnable() @@ -872,7 +989,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param av * AlignViewport */ - void setMenusFromViewport(AlignViewport av) + public void setMenusFromViewport(AlignViewport av) { padGapsMenuitem.setSelected(av.isPadGaps()); colourTextMenuItem.setSelected(av.isShowColourText()); @@ -963,10 +1080,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return progressBar.operationInProgress(); } + /** + * Sets the text of the status bar. Note that setting a null or empty value + * will cause the status bar to be hidden, with possibly undesirable flicker + * of the screen layout. + */ @Override public void setStatus(String text) { - statusBar.setText(text); + statusBar.setText(text == null || text.isEmpty() ? " " : text); } /* @@ -974,7 +1096,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, */ public String getVersion() { - return jalview.bin.Cache.getProperty("VERSION"); + return Cache.getProperty("VERSION"); } public FeatureRenderer getFeatureRenderer() @@ -983,9 +1105,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } @Override - public void fetchSequence_actionPerformed(ActionEvent e) + public void fetchSequence_actionPerformed() { - new jalview.gui.SequenceFetcher(this); + new SequenceFetcher(this); } @Override @@ -1025,7 +1147,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, Desktop.instance.closeAssociatedWindows(); FileLoader loader = new FileLoader(); - DataSourceType protocol = fileName.startsWith("http:") + DataSourceType protocol = HttpUtils.startsWithHttpOrHttps(fileName) ? DataSourceType.URL : DataSourceType.FILE; loader.LoadFile(viewport, fileName, protocol, currentFileFormat); @@ -1035,11 +1157,22 @@ 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 = HttpUtils.startsWithHttpOrHttps( + fileName) ? 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()) @@ -1082,9 +1215,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void save_actionPerformed(ActionEvent e) { if (fileName == null || (currentFileFormat == null) - || fileName.startsWith("http")) + || HttpUtils.startsWithHttpOrHttps(fileName)) { - saveAs_actionPerformed(null); + saveAs_actionPerformed(); } else { @@ -1093,13 +1226,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } /** - * DOCUMENT ME! - * - * @param e - * DOCUMENT ME! + * Saves the alignment to a file with a name chosen by the user, if necessary + * warning if a file would be overwritten */ @Override - public void saveAs_actionPerformed(ActionEvent e) + public void saveAs_actionPerformed() { String format = currentFileFormat == null ? null : currentFileFormat.getName(); @@ -1113,204 +1244,278 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, int value = chooser.showSaveDialog(this); - if (value == JalviewFileChooser.APPROVE_OPTION) + if (value != JalviewFileChooser.APPROVE_OPTION) { + return; + } + currentFileFormat = chooser.getSelectedFormat(); + // todo is this (2005) test now obsolete - value is never null? + 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); currentFileFormat = chooser.getSelectedFormat(); - while (currentFileFormat == null) + value = chooser.showSaveDialog(this); + if (value != JalviewFileChooser.APPROVE_OPTION) { - 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(); - value = chooser.showSaveDialog(this); - if (value != JalviewFileChooser.APPROVE_OPTION) - { - return; - } + return; } + } - 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); + } + + boolean lastSaveSuccessful = false; + + FileFormatI lastFormatSaved; + + String lastFilenameSaved; + + /** + * Raise a dialog or status message for the last call to saveAlignment. + * + * @return true if last call to saveAlignment(file, format) was successful. + */ + public boolean isSaveAlignmentSuccessful() + { + + if (!lastSaveSuccessful) + { + if (!Platform.isHeadless()) + { + JvOptionPane.showInternalMessageDialog(this, MessageManager + .formatMessage("label.couldnt_save_file", new Object[] + { lastFilenameSaved }), + MessageManager.getString("label.error_saving_file"), + JvOptionPane.WARNING_MESSAGE); + } + else + { + Console.error(MessageManager + .formatMessage("label.couldnt_save_file", new Object[] + { lastFilenameSaved })); + } + } + else + { + + setStatus(MessageManager.formatMessage( + "label.successfully_saved_to_file_in_format", new Object[] + { lastFilenameSaved, lastFormatSaved })); - Cache.setProperty("LAST_DIRECTORY", fileName); - saveAlignment(fileName, currentFileFormat); } + return lastSaveSuccessful; } - public boolean saveAlignment(String file, FileFormatI format) + /** + * Saves the alignment to the specified file path, in the specified format, + * which may be an alignment format, or Jalview project format. If the + * alignment has hidden regions, or the format is one capable of including + * non-sequence data (features, annotations, groups), then the user may be + * prompted to specify what to include in the output. + * + * @param file + * @param format + */ + public void saveAlignment(String file, FileFormatI format) { - boolean success = true; + lastSaveSuccessful = true; + lastFilenameSaved = file; + lastFormatSaved = format; if (FileFormat.Jalview.equals(format)) { String shortName = title; - - if (shortName.indexOf(java.io.File.separatorChar) > -1) + if (shortName.indexOf(File.separatorChar) > -1) { - shortName = shortName.substring( - shortName.lastIndexOf(java.io.File.separatorChar) + 1); + shortName = shortName + .substring(shortName.lastIndexOf(File.separatorChar) + 1); } - - success = new Jalview2XML().saveAlignment(this, file, shortName); + lastSaveSuccessful = new Jalview2XML().saveAlignment(this, file, + shortName); statusBar.setText(MessageManager.formatMessage( "label.successfully_saved_to_file_in_format", new Object[] - { fileName, format })); + { file, format })); + return; } - else + + AlignExportSettingsI options = new AlignExportSettingsAdapter(false); + Runnable cancelAction = new Runnable() { - AlignmentExportData exportData = getAlignmentForExport(format, - viewport, null); - if (exportData.getSettings().isCancelled()) - { - return false; - } - FormatAdapter f = new FormatAdapter(alignPanel, - exportData.getSettings()); - String output = f.formatSequences(format, exportData.getAlignment(), // class - // cast - // exceptions - // will - // occur in the distant future - exportData.getOmitHidden(), exportData.getStartEndPostions(), - f.getCacheSuffixDefault(format), - viewport.getAlignment().getHiddenColumns()); - - if (output == null) + @Override + public void run() { - success = false; + lastSaveSuccessful = false; } - else + }; + Runnable outputAction = new Runnable() + { + @Override + public void run() { - try + // todo defer this to inside formatSequences (or later) + AlignmentExportData exportData = viewport + .getAlignExportData(options); + String output = new FormatAdapter(alignPanel, options) + .formatSequences(format, exportData.getAlignment(), + exportData.getOmitHidden(), + exportData.getStartEndPostions(), + viewport.getAlignment().getHiddenColumns()); + if (output == null) { - PrintWriter out = new PrintWriter(new FileWriter(file)); - - out.print(output); - out.close(); - this.setTitle(file); - statusBar.setText(MessageManager.formatMessage( - "label.successfully_saved_to_file_in_format", new Object[] - { fileName, format.getName() })); - } catch (Exception ex) - { - success = false; - ex.printStackTrace(); + lastSaveSuccessful = false; } - } - } + else + { + // create backupfiles object and get new temp filename destination + boolean doBackup = BackupFiles.getEnabled(); + BackupFiles backupfiles = null; + if (doBackup) + { + Console.trace( + "ALIGNFRAME making backupfiles object for " + file); + backupfiles = new BackupFiles(file); + } + try + { + String tempFilePath = doBackup ? backupfiles.getTempFilePath() + : file; + Console.trace("ALIGNFRAME setting PrintWriter"); + PrintWriter out = new PrintWriter(new FileWriter(tempFilePath)); - if (!success) - { - JvOptionPane.showInternalMessageDialog(this, MessageManager - .formatMessage("label.couldnt_save_file", new Object[] - { fileName }), - MessageManager.getString("label.error_saving_file"), - JvOptionPane.WARNING_MESSAGE); - } + if (backupfiles != null) + { + Console.trace("ALIGNFRAME about to write to temp file " + + backupfiles.getTempFilePath()); + } - return success; - } + out.print(output); + Console.trace("ALIGNFRAME about to close file"); + out.close(); + Console.trace("ALIGNFRAME closed file"); + AlignFrame.this.setTitle(file); + statusBar.setText(MessageManager.formatMessage( + "label.successfully_saved_to_file_in_format", + new Object[] + { fileName, format.getName() })); + lastSaveSuccessful = true; + } catch (IOException e) + { + lastSaveSuccessful = false; + Console.error( + "ALIGNFRAME Something happened writing the temp file"); + Console.error(e.getMessage()); + Console.debug(Cache.getStackTraceString(e)); + } catch (Exception ex) + { + lastSaveSuccessful = false; + Console.error( + "ALIGNFRAME Something unexpected happened writing the temp file"); + Console.error(ex.getMessage()); + Console.debug(Cache.getStackTraceString(ex)); + } - private void warningMessage(String warning, String title) - { - if (new jalview.util.Platform().isHeadless()) - { - System.err.println("Warning: " + title + "\nWarning: " + warning); + if (doBackup) + { + backupfiles.setWriteSuccess(lastSaveSuccessful); + Console.debug("ALIGNFRAME writing temp file was " + + (lastSaveSuccessful ? "" : "NOT ") + "successful"); + // do the backup file roll and rename the temp file to actual file + Console.trace( + "ALIGNFRAME about to rollBackupsAndRenameTempFile"); + lastSaveSuccessful = backupfiles.rollBackupsAndRenameTempFile(); + Console.debug( + "ALIGNFRAME performed rollBackupsAndRenameTempFile " + + (lastSaveSuccessful ? "" : "un") + + "successfully"); + } + } + } + }; + /* + * show dialog with export options if applicable; else just do it + */ + if (AlignExportOptions.isNeeded(viewport, format)) + { + AlignExportOptions choices = new AlignExportOptions( + alignPanel.getAlignViewport(), format, options); + choices.setResponseAction(0, outputAction); + choices.setResponseAction(1, cancelAction); + choices.showDialog(); } else { - JvOptionPane.showInternalMessageDialog(this, warning, title, - JvOptionPane.WARNING_MESSAGE); + outputAction.run(); } - return; } /** - * DOCUMENT ME! + * Outputs the alignment to textbox in the requested format, if necessary + * first prompting the user for whether to include hidden regions or + * non-sequence data * - * @param e - * DOCUMENT ME! + * @param fileFormatName */ @Override - protected void outputText_actionPerformed(ActionEvent e) + protected void outputText_actionPerformed(String fileFormatName) { FileFormatI fileFormat = FileFormats.getInstance() - .forName(e.getActionCommand()); - AlignmentExportData exportData = getAlignmentForExport(fileFormat, - viewport, null); - if (exportData.getSettings().isCancelled()) - { - return; - } - CutAndPasteTransfer cap = new CutAndPasteTransfer(); - cap.setForInput(null); - try - { - FileFormatI format = fileFormat; - cap.setText(new FormatAdapter(alignPanel, exportData.getSettings()) - .formatSequences(format, exportData.getAlignment(), - exportData.getOmitHidden(), - exportData.getStartEndPostions(), - viewport.getAlignment().getHiddenColumns())); - Desktop.addInternalFrame(cap, MessageManager - .formatMessage("label.alignment_output_command", new Object[] - { e.getActionCommand() }), 600, 500); - } catch (OutOfMemoryError oom) - { - new OOMWarning("Outputting alignment as " + e.getActionCommand(), - oom); - cap.dispose(); - } - - } - - public static AlignmentExportData getAlignmentForExport( - FileFormatI format, AlignViewportI viewport, - AlignExportSettingI exportSettings) - { - AlignmentI alignmentToExport = null; - AlignExportSettingI settings = exportSettings; - String[] omitHidden = null; - - HiddenSequences hiddenSeqs = viewport.getAlignment() - .getHiddenSequences(); - - alignmentToExport = viewport.getAlignment(); - - boolean hasHiddenSeqs = hiddenSeqs.getSize() > 0; - if (settings == null) - { - settings = new AlignExportSettings(hasHiddenSeqs, - viewport.hasHiddenColumns(), format); - } - // settings.isExportAnnotations(); - - if (viewport.hasHiddenColumns() && !settings.isExportHiddenColumns()) + .forName(fileFormatName); + AlignExportSettingsI options = new AlignExportSettingsAdapter(false); + Runnable outputAction = new Runnable() { - omitHidden = viewport.getViewAsString(false, - settings.isExportHiddenSequences()); - } + @Override + public void run() + { + // todo defer this to inside formatSequences (or later) + AlignmentExportData exportData = viewport + .getAlignExportData(options); + CutAndPasteTransfer cap = new CutAndPasteTransfer(); + cap.setForInput(null); + try + { + FileFormatI format = fileFormat; + cap.setText(new FormatAdapter(alignPanel, options) + .formatSequences(format, exportData.getAlignment(), + exportData.getOmitHidden(), + exportData.getStartEndPostions(), + viewport.getAlignment().getHiddenColumns())); + Desktop.addInternalFrame(cap, MessageManager.formatMessage( + "label.alignment_output_command", new Object[] + { fileFormat.getName() }), 600, 500); + } catch (OutOfMemoryError oom) + { + new OOMWarning("Outputting alignment as " + fileFormat.getName(), + oom); + cap.dispose(); + } + } + }; - int[] alignmentStartEnd = new int[2]; - if (hasHiddenSeqs && settings.isExportHiddenSequences()) + /* + * show dialog with export options if applicable; else just do it + */ + if (AlignExportOptions.isNeeded(viewport, fileFormat)) { - alignmentToExport = hiddenSeqs.getFullAlignment(); + AlignExportOptions choices = new AlignExportOptions( + alignPanel.getAlignViewport(), fileFormat, options); + choices.setResponseAction(0, outputAction); + choices.showDialog(); } else { - alignmentToExport = viewport.getAlignment(); + outputAction.run(); } - alignmentStartEnd = viewport.getAlignment().getHiddenColumns() - .getVisibleStartAndEndIndex(alignmentToExport.getWidth()); - AlignmentExportData ed = new AlignmentExportData(alignmentToExport, - omitHidden, alignmentStartEnd, settings); - return ed; } /** @@ -1339,33 +1544,39 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } /** - * DOCUMENT ME! + * Creates a PNG image of the alignment and writes it to the given file. If + * the file is null, the user is prompted to choose a file. * - * @param e - * DOCUMENT ME! + * @param f */ @Override public void createPNG(File f) { - alignPanel.makePNG(f); + alignPanel.makeAlignmentImage(TYPE.PNG, f); } /** - * DOCUMENT ME! + * Creates an EPS image of the alignment and writes it to the given file. If + * the file is null, the user is prompted to choose a file. * - * @param e - * DOCUMENT ME! + * @param f */ @Override public void createEPS(File f) { - alignPanel.makeEPS(f); + alignPanel.makeAlignmentImage(TYPE.EPS, f); } + /** + * Creates an SVG image of the alignment and writes it to the given file. If + * the file is null, the user is prompted to choose a file. + * + * @param f + */ @Override public void createSVG(File f) { - alignPanel.makeSVG(f); + alignPanel.makeAlignmentImage(TYPE.SVG, f); } @Override @@ -1404,24 +1615,25 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void associatedData_actionPerformed(ActionEvent e) { - // Pick the tree file - JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY")); + final JalviewFileChooser chooser = new JalviewFileChooser( + Cache.getProperty("LAST_DIRECTORY")); chooser.setFileView(new JalviewFileView()); - chooser.setDialogTitle( - MessageManager.getString("label.load_jalview_annotations")); - chooser.setToolTipText( - MessageManager.getString("label.load_jalview_annotations")); - - int value = chooser.showOpenDialog(null); - - if (value == JalviewFileChooser.APPROVE_OPTION) + String tooltip = MessageManager + .getString("label.load_jalview_annotations"); + chooser.setDialogTitle(tooltip); + chooser.setToolTipText(tooltip); + chooser.setResponseHandler(0, new Runnable() { - String choice = chooser.getSelectedFile().getPath(); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); - loadJalviewDataFile(choice, null, null, null); - } + @Override + public void run() + { + String choice = chooser.getSelectedFile().getPath(); + Cache.setProperty("LAST_DIRECTORY", choice); + loadJalviewDataFile(chooser.getSelectedFile(), null, null, null); + } + }); + chooser.showOpenDialog(this); } /** @@ -1460,9 +1672,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, closeView(alignPanel); } } - if (closeAllTabs) { + if (featureSettings != null && featureSettings.isOpen()) + { + featureSettings.close(); + featureSettings = null; + } /* * this will raise an INTERNAL_FRAME_CLOSED event and this method will * be called recursively, with the frame now in 'closed' state @@ -1599,7 +1815,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { if (originalSource != viewport) { - Cache.log.warn( + Console.warn( "Implementation worry: mismatch of viewport origin for undo"); } originalSource.updateHiddenColumns(); @@ -1639,7 +1855,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (originalSource != viewport) { - Cache.log.warn( + Console.warn( "Implementation worry: mismatch of viewport origin for redo"); } originalSource.updateHiddenColumns(); @@ -1696,10 +1912,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } /** - * DOCUMENT ME! + * Calls AlignmentI.moveSelectedSequencesByOne with current sequence selection + * or the sequence under cursor in keyboard mode * * @param up - * DOCUMENT ME! + * or down (if !up) */ public void moveSelectedSequences(boolean up) { @@ -1707,8 +1924,25 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (sg == null) { + if (viewport.cursorMode) + { + sg = new SequenceGroup(); + sg.addSequence(viewport.getAlignment().getSequenceAt( + alignPanel.getSeqPanel().seqCanvas.cursorY), false); + } + else + { + return; + } + } + + if (sg.getSize() < 1) + { return; } + + // TODO: JAL-3733 - add an event to the undo buffer for this ! + viewport.getAlignment().moveSelectedSequencesByOne(sg, viewport.getHiddenRepSequences(), up); alignPanel.paintAlignment(true, false); @@ -1826,7 +2060,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * DOCUMENT ME! */ @Override - protected void copy_actionPerformed(ActionEvent e) + protected void copy_actionPerformed() { if (viewport.getSelectionGroup() == null) { @@ -1878,7 +2112,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, Desktop.jalviewClipboard = new Object[] { seqs, viewport.getAlignment().getDataset(), hiddenColumns }; - statusBar.setText(MessageManager.formatMessage( + setStatus(MessageManager.formatMessage( "label.copied_sequences_to_clipboard", new Object[] { Integer.valueOf(seqs.length).toString() })); } @@ -2001,7 +2235,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, && Desktop.jalviewClipboard[1] != alignment.getDataset(); // importDs==true instructs us to copy over new dataset sequences from // an existing alignment - Vector newDs = (importDs) ? new Vector() : null; // used to create + Vector newDs = (importDs) ? new Vector<>() : null; // used to + // create // minimum dataset set for (int i = 0; i < sequences.length; i++) @@ -2074,7 +2309,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, newGraphGroups.add(q, null); } newGraphGroups.set(newann.graphGroup, - new Integer(++fgroup)); + Integer.valueOf(++fgroup)); } newann.graphGroup = newGraphGroups.get(newann.graphGroup) .intValue(); @@ -2121,7 +2356,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, newGraphGroups.add(q, null); } newGraphGroups.set(newann.graphGroup, - new Integer(++fgroup)); + Integer.valueOf(++fgroup)); } newann.graphGroup = newGraphGroups.get(newann.graphGroup) .intValue(); @@ -2140,7 +2375,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { // propagate alignment changed. - viewport.getRanges().setEndSeq(alignment.getHeight()); + viewport.getRanges().setEndSeq(alignment.getHeight() - 1); if (annotationAdded) { // Duplicate sequence annotation in all views. @@ -2295,26 +2530,20 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } /** - * DOCUMENT ME! - * - * @param e - * DOCUMENT ME! + * Action Cut (delete and copy) the selected region */ @Override - protected void cut_actionPerformed(ActionEvent e) + protected void cut_actionPerformed() { - copy_actionPerformed(null); - delete_actionPerformed(null); + copy_actionPerformed(); + delete_actionPerformed(); } /** - * DOCUMENT ME! - * - * @param e - * DOCUMENT ME! + * Performs menu option to Delete the currently selected region */ @Override - protected void delete_actionPerformed(ActionEvent evt) + protected void delete_actionPerformed() { SequenceGroup sg = viewport.getSelectionGroup(); @@ -2323,51 +2552,60 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return; } - /* - * If the cut affects all sequences, warn, remove highlighted columns - */ - if (sg.getSize() == viewport.getAlignment().getHeight()) + Runnable okAction = new Runnable() { - boolean isEntireAlignWidth = (((sg.getEndRes() - sg.getStartRes()) - + 1) == viewport.getAlignment().getWidth()) ? true : false; - if (isEntireAlignWidth) + @Override + public void run() { - int confirm = JvOptionPane.showConfirmDialog(this, - MessageManager.getString("warn.delete_all"), // $NON-NLS-1$ - MessageManager.getString("label.delete_all"), // $NON-NLS-1$ - JvOptionPane.OK_CANCEL_OPTION); + SequenceI[] cut = sg.getSequences() + .toArray(new SequenceI[sg.getSize()]); + + addHistoryItem(new EditCommand( + MessageManager.getString("label.cut_sequences"), Action.CUT, + cut, sg.getStartRes(), + sg.getEndRes() - sg.getStartRes() + 1, + viewport.getAlignment())); - if (confirm == JvOptionPane.CANCEL_OPTION - || confirm == JvOptionPane.CLOSED_OPTION) + viewport.setSelectionGroup(null); + viewport.sendSelection(); + viewport.getAlignment().deleteGroup(sg); + + viewport.firePropertyChange("alignment", null, + viewport.getAlignment().getSequences()); + if (viewport.getAlignment().getHeight() < 1) { - return; + try + { + AlignFrame.this.setClosed(true); + } catch (Exception ex) + { + } } } - viewport.getColumnSelection().removeElements(sg.getStartRes(), - sg.getEndRes() + 1); - } - SequenceI[] cut = sg.getSequences() - .toArray(new SequenceI[sg.getSize()]); + }; - addHistoryItem(new EditCommand( - MessageManager.getString("label.cut_sequences"), Action.CUT, - cut, sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1, - viewport.getAlignment())); - - viewport.setSelectionGroup(null); - viewport.sendSelection(); - viewport.getAlignment().deleteGroup(sg); - - viewport.firePropertyChange("alignment", null, - viewport.getAlignment().getSequences()); - if (viewport.getAlignment().getHeight() < 1) + /* + * If the cut affects all sequences, prompt for confirmation + */ + boolean wholeHeight = sg.getSize() == viewport.getAlignment() + .getHeight(); + boolean wholeWidth = (((sg.getEndRes() - sg.getStartRes()) + + 1) == viewport.getAlignment().getWidth()) ? true : false; + if (wholeHeight && wholeWidth) + { + JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.desktop); + dialog.setResponseHandler(0, okAction); // 0 = OK_OPTION + Object[] options = new Object[] { + MessageManager.getString("action.ok"), + MessageManager.getString("action.cancel") }; + dialog.showDialog(MessageManager.getString("warn.delete_all"), + MessageManager.getString("label.delete_all"), + JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null, + options, options[0]); + } + else { - try - { - this.setClosed(true); - } catch (Exception ex) - { - } + okAction.run(); } } @@ -2397,12 +2635,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void selectAllSequenceMenuItem_actionPerformed(ActionEvent e) { - SequenceGroup sg = new SequenceGroup(); - - for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++) - { - sg.addSequence(viewport.getAlignment().getSequenceAt(i), false); - } + SequenceGroup sg = new SequenceGroup( + viewport.getAlignment().getSequences()); sg.setEndRes(viewport.getAlignment().getWidth() - 1); viewport.setSelectionGroup(sg); @@ -2431,7 +2665,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } viewport.setSelectionGroup(null); viewport.getColumnSelection().clear(); - viewport.setSelectionGroup(null); + viewport.setSearchResults(null); alignPanel.getIdPanel().getIdCanvas().searchResults = null; // JAL-2034 - should delegate to // alignPanel to decide if overview needs @@ -2544,8 +2778,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, column, viewport.getAlignment()); } - statusBar.setText(MessageManager - .formatMessage("label.removed_columns", new String[] + setStatus(MessageManager.formatMessage("label.removed_columns", + new String[] { Integer.valueOf(trimRegion.getSize()).toString() })); addHistoryItem(trimRegion); @@ -2594,8 +2828,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, addHistoryItem(removeGapCols); - statusBar.setText(MessageManager - .formatMessage("label.removed_empty_columns", new Object[] + setStatus(MessageManager.formatMessage("label.removed_empty_columns", + new Object[] { Integer.valueOf(removeGapCols.getSize()).toString() })); // This is to maintain viewport position on first residue @@ -2668,15 +2902,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } /** - * DOCUMENT ME! + * Opens a Finder dialog * * @param e - * DOCUMENT ME! */ @Override public void findMenuItem_actionPerformed(ActionEvent e) { - new Finder(); + new Finder(alignPanel, false, null); } /** @@ -2702,7 +2935,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, /* * Create a new AlignmentPanel (with its own, new Viewport) */ - AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel); + AlignmentPanel newap = new jalview.project.Jalview2XML() + .copyAlignPanel(alignPanel); if (!copyAnnotation) { /* @@ -2714,10 +2948,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, newap.av.setGatherViewsHere(false); - if (viewport.viewName == null) + if (viewport.getViewName() == null) { - viewport.viewName = MessageManager - .getString("label.view_name_original"); + viewport.setViewName( + MessageManager.getString("label.view_name_original")); } /* @@ -2727,6 +2961,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, newap.av.setRedoList(viewport.getRedoList()); /* + * copy any visualisation settings that are not saved in the project + */ + newap.av.setColourAppliesToAllGroups( + viewport.getColourAppliesToAllGroups()); + + /* * Views share the same mappings; need to deregister any new mappings * created by copyAlignPanel, and register the new reference to the shared * mappings @@ -2741,7 +2981,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, newap.refresh(true); // adjust layout of annotations } - newap.av.viewName = getNewViewName(viewTitle); + newap.av.setViewName(getNewViewName(viewTitle)); addAlignmentPanel(newap, true); newap.alignmentChanged(); @@ -2804,9 +3044,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (comp instanceof AlignmentPanel) { AlignmentPanel ap = (AlignmentPanel) comp; - if (!existingNames.contains(ap.av.viewName)) + if (!existingNames.contains(ap.av.getViewName())) { - existingNames.add(ap.av.viewName); + existingNames.add(ap.av.getViewName()); } } } @@ -2889,7 +3129,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport.setFollowHighlight(state); if (state) { - alignPanel.scrollToPosition(viewport.getSearchResults(), false); + alignPanel.scrollToPosition(viewport.getSearchResults()); } } @@ -2948,7 +3188,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param toggleSeqs * @param toggleCols */ - private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols) + protected void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols) { boolean hide = false; @@ -3036,6 +3276,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport.expandColSelection(sg, false); viewport.hideAllSelectedSeqs(); viewport.hideSelectedColumns(); + alignPanel.updateLayout(); alignPanel.paintAlignment(true, true); viewport.sendSelection(); } @@ -3060,6 +3301,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void hideSelColumns_actionPerformed(ActionEvent e) { viewport.hideSelectedColumns(); + alignPanel.updateLayout(); alignPanel.paintAlignment(true, true); viewport.sendSelection(); } @@ -3081,7 +3323,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void scaleAbove_actionPerformed(ActionEvent e) { viewport.setScaleAboveWrapped(scaleAbove.isSelected()); - // TODO: do we actually need to update overview for scale above change ? + alignPanel.updateLayout(); alignPanel.paintAlignment(true, false); } @@ -3095,6 +3337,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void scaleLeft_actionPerformed(ActionEvent e) { viewport.setScaleLeftWrapped(scaleLeft.isSelected()); + alignPanel.updateLayout(); alignPanel.paintAlignment(true, false); } @@ -3108,6 +3351,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void scaleRight_actionPerformed(ActionEvent e) { viewport.setScaleRightWrapped(scaleRight.isSelected()); + alignPanel.updateLayout(); alignPanel.paintAlignment(true, false); } @@ -3161,9 +3405,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void featureSettings_actionPerformed(ActionEvent e) { + showFeatureSettingsUI(); + } + + @Override + public FeatureSettingsControllerI showFeatureSettingsUI() + { if (featureSettings != null) { - featureSettings.close(); + featureSettings.closeOldSettings(); featureSettings = null; } if (!showSeqFeatures.isSelected()) @@ -3173,6 +3423,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, showSeqFeatures_actionPerformed(null); } featureSettings = new FeatureSettings(this); + return featureSettings; } /** @@ -3212,15 +3463,42 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void alignmentProperties() { - JEditorPane editPane = new JEditorPane("text/html", ""); - editPane.setEditable(false); + JComponent pane; StringBuffer contents = new AlignmentProperties(viewport.getAlignment()) + .formatAsHtml(); - editPane.setText( - MessageManager.formatMessage("label.html_content", new Object[] - { contents.toString() })); + String content = MessageManager.formatMessage("label.html_content", + new Object[] + { contents.toString() }); + contents = null; + + if (Platform.isJS()) + { + JLabel textLabel = new JLabel(); + textLabel.setText(content); + textLabel.setBackground(Color.WHITE); + + pane = new JPanel(new BorderLayout()); + ((JPanel) pane).setOpaque(true); + pane.setBackground(Color.WHITE); + ((JPanel) pane).add(textLabel, BorderLayout.NORTH); + } + else + /** + * Java only + * + * @j2sIgnore + */ + { + JEditorPane editPane = new JEditorPane("text/html", ""); + editPane.setEditable(false); + editPane.setText(content); + pane = editPane; + } + JInternalFrame frame = new JInternalFrame(); - frame.getContentPane().add(new JScrollPane(editPane)); + + frame.getContentPane().add(new JScrollPane(pane)); Desktop.addInternalFrame(frame, MessageManager .formatMessage("label.alignment_properties", new Object[] @@ -3259,7 +3537,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { overview.dispose(); alignPanel.setOverviewPanel(null); - }; + } }); if (getKeyListeners().length > 0) { @@ -3329,7 +3607,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * otherwise set the chosen colour scheme (or null for 'None') */ ColourSchemeI cs = ColourSchemes.getInstance().getColourScheme(name, - viewport.getAlignment(), viewport.getHiddenRepSequences()); + viewport, viewport.getAlignment(), + viewport.getHiddenRepSequences()); changeColour(cs); } @@ -3549,15 +3828,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, /** * Constructs a tree panel and adds it to the desktop * - * @param type - * tree type (NJ or AV) - * @param modelName - * name of score model used to compute the tree - * @param options - * parameters for the distance or similarity calculation + * @param params + * @param treeAlgo + * + * @param tree + * + * */ - void newTreePanel(String type, String modelName, - SimilarityParamsI options) + void newTreePanel(TreeModel tree, String treeAlgo, + String substitutionMatrix) { String frameTitle = ""; TreePanel tp; @@ -3569,7 +3848,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, SequenceGroup sg = viewport.getSelectionGroup(); /* Decide if the selection is a column region */ - for (SequenceI _s : sg.getSequences()) + for (SequenceI _s : sg.getSequences()) // port this to Archaeopteryx? { if (_s.getLength() < sg.getEndRes()) { @@ -3593,14 +3872,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } } - tp = new TreePanel(alignPanel, type, modelName, options); + tp = new TreePanel(alignPanel, tree, treeAlgo, substitutionMatrix); frameTitle = tp.getPanelTitle() + (onSelection ? " on region" : ""); frameTitle += " from "; - if (viewport.viewName != null) + if (viewport.getViewName() != null) { - frameTitle += viewport.viewName + " of "; + frameTitle += viewport.getViewName() + " of "; } frameTitle += this.title; @@ -3696,7 +3975,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { sortByAnnotScore.removeAll(); // almost certainly a quicker way to do this - but we keep it simple - Hashtable scoreSorts = new Hashtable(); + Hashtable scoreSorts = new Hashtable<>(); AlignmentAnnotation aann[]; for (SequenceI sqa : viewport.getAlignment().getSequences()) { @@ -3709,11 +3988,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } } } - Enumeration labels = scoreSorts.keys(); + Enumeration labels = scoreSorts.keys(); while (labels.hasMoreElements()) { - addSortByAnnotScoreMenuItem(sortByAnnotScore, - (String) labels.nextElement()); + addSortByAnnotScoreMenuItem(sortByAnnotScore, labels.nextElement()); } sortByAnnotScore.setVisible(scoreSorts.size() > 0); scoreSorts.clear(); @@ -3762,6 +4040,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void actionPerformed(ActionEvent e) { + // adapt to Aptx tp.sortByTree_actionPerformed(); addHistoryItem(tp.sortAlignmentIn(alignPanel)); @@ -3871,42 +4150,169 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override protected void loadTreeMenuItem_actionPerformed(ActionEvent e) { + chooseTreeFile(); + } + + @Override + protected void loadTreeUrlItem_actionPerformed(ActionEvent e) + { + chooseTreeUrl(); + } + + @Override + protected void loadTreeBaseStudy_actionPerformed(ActionEvent e) + { + chooseTreeDb(); + + } + + @Override + protected void loadTreeOfLife_actionPerformed(ActionEvent e) + { + chooseTreeDb(); + + } + + @Override + protected void loadTreeFam_actionPerformed(ActionEvent e) + { + chooseTreeDb(); + + } + + @Override + protected void loadTreePfam_actionPerformed(ActionEvent e) + { + chooseTreeDb(); + + } + + @Override + protected void loadTreeBase_actionPerformed(ActionEvent e) + { + chooseTreeDb(); + + } + + + public void chooseTreeFile() + { // Pick the tree file JalviewFileChooser chooser = new JalviewFileChooser( - jalview.bin.Cache.getProperty("LAST_DIRECTORY")); + Cache.getProperty("LAST_DIRECTORY")); chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle( - MessageManager.getString("label.select_newick_like_tree_file")); + MessageManager.getString("label.select_tree_file")); // modify chooser.setToolTipText( - MessageManager.getString("label.load_tree_file")); - - int value = chooser.showOpenDialog(null); + MessageManager.getString("label.load_tree_for_sequence_set")); + for (SupportedTreeFileFilter treeFormat : SupportedTreeFileFilter + .values()) + { + chooser.setFileFilter(treeFormat.getTreeFilter()); + } - if (value == JalviewFileChooser.APPROVE_OPTION) + chooser.setResponseHandler(0, new Runnable() { - String filePath = chooser.getSelectedFile().getPath(); - Cache.setProperty("LAST_DIRECTORY", filePath); - NewickFile fin = null; - try + @Override + public void run() { - fin = new NewickFile(filePath, DataSourceType.FILE); - viewport.setCurrentTree(showNewickTree(fin, filePath).getTree()); - } catch (Exception ex) + String filePath = chooser.getSelectedFile().getPath(); + Cache.setProperty("LAST_DIRECTORY", filePath); + TreeParser treeParser = null; + try { + treeParser = new TreeParser(filePath); + treeParser.loadTree(viewport); + } 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.showOpenDialog(this); + } + } + + /** + * Break up and move to TreeParser? + */ + public void chooseTreeUrl() + { + + JLabel label = new JLabel( + MessageManager.getString("label.tree_url_example")); + // add "example" button + final JComboBox history = new JComboBox<>(); + + JPanel panel = new JPanel(new GridLayout(2, 1)); + panel.add(label); + panel.add(history); + history.setPreferredSize(new Dimension(400, 20)); + history.setEditable(true); + history.addItem("http://www."); + + String historyItems = jalview.bin.Cache.getProperty("RECENT_URL"); + + StringTokenizer st; + + if (historyItems != null) { - JvOptionPane.showMessageDialog(Desktop.desktop, ex.getMessage(), - MessageManager.getString("label.problem_reading_tree_file"), - JvOptionPane.WARNING_MESSAGE); - ex.printStackTrace(); + st = new StringTokenizer(historyItems, "\t"); + + while (st.hasMoreTokens()) + { + history.addItem(st.nextToken()); + } } - if (fin != null && fin.hasWarningMessage()) + + int reply = JvOptionPane.showInternalConfirmDialog(this, panel, + MessageManager.getString("label.load_tree_url"), + JvOptionPane.OK_CANCEL_OPTION); + + if (reply == JvOptionPane.OK_OPTION) + { + + String urlString = history.getSelectedItem().toString(); + URL treeUrl; + + try { - JvOptionPane.showMessageDialog(Desktop.desktop, - fin.getWarningMessage(), - MessageManager - .getString("label.possible_problem_with_tree_file"), - JvOptionPane.WARNING_MESSAGE); + FileFormatI format = null; + + format = new IdentifyFile().identify(urlString, DataSourceType.URL); + // add actual use for the format identification (jalview .jar files) + treeUrl = new URL(urlString); + AptxInit.createInstanceFromUrl(treeUrl, viewport); + + } catch (IOException | RuntimeException e) + { + JvOptionPane.showMessageDialog(this, MessageManager.formatMessage( + "exception.failed_to_read_data_from_source", new String[] + { urlString }), + MessageManager.getString("label.url_not_found"), + JvOptionPane.ERROR_MESSAGE); + e.printStackTrace(); } } + else + { + + } + } + + public void chooseTreeDb() + { } public TreePanel showNewickTree(NewickFile nf, String treeTitle) @@ -4024,6 +4430,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, final JMenu seqsrchmenu = new JMenu("Sequence Database Search"); final JMenu analymenu = new JMenu("Analysis"); final JMenu dismenu = new JMenu("Protein Disorder"); + final JMenu phylogenmenu = new JMenu("Phylogenetic inference"); + // JAL-940 - only show secondary structure prediction services from // the legacy server if (// Cache.getDefault("SHOW_JWS1_SERVICES", true) @@ -4036,15 +4444,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // No MSAWS used any more: // Vector msaws = null; // (Vector) // Discoverer.services.get("MsaWS"); - Vector secstrpr = (Vector) Discoverer.services + Vector secstrpr = Discoverer.services .get("SecStrPred"); if (secstrpr != null) { // Add any secondary structure prediction services for (int i = 0, j = secstrpr.size(); i < j; i++) { - final ext.vamsas.ServiceHandle sh = (ext.vamsas.ServiceHandle) secstrpr - .get(i); + final ext.vamsas.ServiceHandle sh = secstrpr.get(i); jalview.ws.WSMenuEntryProviderI impl = jalview.ws.jws1.Discoverer .getServiceClient(sh); int p = secstrmenu.getItemCount(); @@ -4064,6 +4471,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, wsmenu.add(secstrmenu); wsmenu.add(dismenu); wsmenu.add(analymenu); + wsmenu.add(phylogenmenu); // No search services yet // wsmenu.add(seqsrchmenu); @@ -4088,9 +4496,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, webService.add(me.webServiceNoServices); } // TODO: move into separate menu builder class. - boolean new_sspred = false; - if (Cache.getDefault("SHOW_JWS2_SERVICES", true)) { + // logic for 2.11.1.4 is + // always look to see if there is a discover. if there isn't + // we can't show any Jws2 services + // if there are services available, show them - regardless of + // the 'show JWS2 preference' + // if the discoverer is running then say so + // otherwise offer to trigger discovery if 'show JWS2' is not + // enabled Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer(); if (jws2servs != null) { @@ -4099,7 +4513,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, jws2servs.attachWSMenuEntry(webService, me); for (Jws2Instance sv : jws2servs.getServices()) { - if (sv.description.toLowerCase().contains("jpred")) + if (sv.description.toLowerCase(Locale.ROOT) + .contains("jpred")) { for (JMenuItem jmi : legacyItems) { @@ -4107,8 +4522,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } } } - } + if (jws2servs.isRunning()) { JMenuItem tm = new JMenuItem( @@ -4116,6 +4531,26 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, tm.setEnabled(false); webService.add(tm); } + else if (!Cache.getDefault("SHOW_JWS2_SERVICES", true)) + { + JMenuItem enableJws2 = new JMenuItem( + "Discover Web Services"); + enableJws2.setToolTipText( + "Select to start JABA Web Service discovery (or enable option in Web Service preferences)"); + enableJws2.setEnabled(true); + enableJws2.addActionListener(new ActionListener() + { + + @Override + public void actionPerformed(ActionEvent e) + { + // start service discoverer, but ignore preference + Desktop.instance.startServiceDiscovery(false, + true); + } + }); + webService.add(enableJws2); + } } } build_urlServiceMenu(me.webService); @@ -4133,7 +4568,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } } catch (Exception e) { - Cache.log.debug( + Console.debug( "Exception during web service menu building process.", e); } @@ -4144,7 +4579,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } buildingMenu = false; } - }).start(); + }, "BuildWebServiceThread").start(); } @@ -4153,7 +4588,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @param webService */ - private void build_urlServiceMenu(JMenu webService) + protected void build_urlServiceMenu(JMenu webService) { // TODO: remove this code when 2.7 is released // DEBUG - alignmentView @@ -4230,7 +4665,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, showProducts.setEnabled(showp); } catch (Exception e) { - Cache.log.warn( + Console.warn( "canShowProducts threw an exception - please report to help@jalview.org", e); return false; @@ -4252,7 +4687,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void showProductsFor(final SequenceI[] sel, final boolean _odna, final String source) { - new Thread(CrossRefAction.getHandlerFor(sel, _odna, source, this)) + new Thread(CrossRefAction.getHandlerFor(sel, _odna, source, this), + "CrossReferencesThread") .start(); } @@ -4261,18 +4697,18 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * frame's DNA sequences to their aligned protein (amino acid) equivalents. */ @Override - public void showTranslation_actionPerformed(ActionEvent e) + public void showTranslation_actionPerformed(GeneticCodeI codeTable) { AlignmentI al = null; try { Dna dna = new Dna(viewport, viewport.getViewAsVisibleContigs(true)); - al = dna.translateCdna(); + al = dna.translateCdna(codeTable); } catch (Exception ex) { - jalview.bin.Cache.log.error( - "Exception during translation. Please report this !", ex); + Console.error("Exception during translation. Please report this !", + ex); final String msg = MessageManager.getString( "label.error_when_translating_sequences_submit_bug_report"); final String errorTitle = MessageManager @@ -4297,7 +4733,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, af.setFileFormat(this.currentFileFormat); final String newTitle = MessageManager .formatMessage("label.translation_of_params", new Object[] - { this.getTitle() }); + { this.getTitle(), codeTable.getId() }); af.setTitle(newTitle); if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true)) { @@ -4326,13 +4762,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * Try to load a features file onto the alignment. * * @param file - * contents or path to retrieve file + * contents or path to retrieve file or a File object * @param sourceType * access mode of file (see jalview.io.AlignFile) * @return true if features file was parsed correctly. */ - public boolean parseFeaturesFile(String file, DataSourceType sourceType) + public boolean parseFeaturesFile(Object file, DataSourceType sourceType) { + // BH 2018 return avc.parseFeaturesFile(file, sourceType, Cache.getDefault("RELAXEDSEQIDMATCHING", false)); @@ -4379,8 +4816,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // Java's Transferable for native dnd evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); Transferable t = evt.getTransferable(); + final AlignFrame thisaf = this; - final List files = new ArrayList<>(); + final List files = new ArrayList<>(); List protocols = new ArrayList<>(); try @@ -4408,20 +4846,33 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * Object[] { String,SequenceI} */ ArrayList filesmatched = new ArrayList<>(); - ArrayList filesnotmatched = new ArrayList<>(); + ArrayList filesnotmatched = new ArrayList<>(); for (int i = 0; i < files.size(); i++) { - String file = files.get(i).toString(); + // BH 2018 + Object file = files.get(i); + String fileName = file.toString(); String pdbfn = ""; - DataSourceType protocol = FormatAdapter.checkProtocol(file); + DataSourceType protocol = (file instanceof File + ? DataSourceType.FILE + : FormatAdapter.checkProtocol(fileName)); if (protocol == DataSourceType.FILE) { - File fl = new File(file); + File fl; + if (file instanceof File) + { + fl = (File) file; + Platform.cacheFileData(fl); + } + else + { + fl = new File(fileName); + } pdbfn = fl.getName(); } else if (protocol == DataSourceType.URL) { - URL url = new URL(file); + URL url = new URL(fileName); pdbfn = url.getFile(); } if (pdbfn.length() > 0) @@ -4443,7 +4894,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } if (mtch != null) { - FileFormatI type = null; + FileFormatI type; try { type = new IdentifyFile().identify(file, protocol); @@ -4465,7 +4916,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, int assocfiles = 0; if (filesmatched.size() > 0) { - boolean autoAssociate = Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false); + boolean autoAssociate = Cache + .getDefault("AUTOASSOCIATE_PDBANDSEQS", false); if (!autoAssociate) { String msg = MessageManager.formatMessage( @@ -4489,13 +4941,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, for (SequenceI toassoc : (SequenceI[]) fm[2]) { PDBEntry pe = new AssociatePdbFileWithSeq() - .associatePdbWithSeq((String) fm[0], + .associatePdbWithSeq(fm[0].toString(), (DataSourceType) fm[1], toassoc, false, Desktop.instance); if (pe != null) { System.err.println("Associated file : " - + ((String) fm[0]) + " with " + + (fm[0].toString()) + " with " + toassoc.getDisplayId(true)); assocfiles++; } @@ -4512,7 +4964,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, */ for (Object[] o : filesmatched) { - filesnotmatched.add((String) o[0]); + filesnotmatched.add(o[0]); } } } @@ -4534,7 +4986,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { return; } - for (String fn : filesnotmatched) + for (Object fn : filesnotmatched) { loadJalviewDataFile(fn, null, null, null); } @@ -4545,7 +4997,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, ex.printStackTrace(); } } - }).start(); + }, "DropFileThread").start(); } } @@ -4561,9 +5013,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param file * either a filename or a URL string. */ - public void loadJalviewDataFile(String file, DataSourceType sourceType, + public void loadJalviewDataFile(Object file, DataSourceType sourceType, FileFormatI format, SequenceI assocSeq) { + // BH 2018 was String file try { if (sourceType == null) @@ -4594,7 +5047,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, changeColour( new TCoffeeColourScheme(viewport.getAlignment())); isAnnotation = true; - statusBar.setText(MessageManager.getString( + setStatus(MessageManager.getString( "label.successfully_pasted_tcoffee_scores_to_alignment")); } else @@ -4617,7 +5070,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } } catch (Exception x) { - Cache.log.debug( + Console.debug( "Exception when processing data source as T-COFFEE score file", x); tcf = null; @@ -4637,7 +5090,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, new FileParse(file, sourceType)); sm.parse(); // todo: i18n this message - statusBar.setText(MessageManager.formatMessage( + setStatus(MessageManager.formatMessage( "label.successfully_loaded_matrix", sm.getMatrixName())); } @@ -4655,7 +5108,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { if (parseFeaturesFile(file, sourceType)) { - alignPanel.paintAlignment(true, true); + SplitFrame splitFrame = (SplitFrame) getSplitViewContainer(); + if (splitFrame != null) + { + splitFrame.repaint(); + } + else + { + alignPanel.paintAlignment(true, true); + } } } else @@ -4711,6 +5172,21 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport = alignPanel.av; avc.setViewportAndAlignmentPanel(viewport, alignPanel); setMenusFromViewport(viewport); + if (featureSettings != null && featureSettings.isOpen() + && featureSettings.fr.getViewport() != viewport) + { + if (viewport.isShowSequenceFeatures()) + { + // refresh the featureSettings to reflect UI change + showFeatureSettingsUI(); + } + else + { + // close feature settings for this view. + featureSettings.close(); + } + } + } /* @@ -4763,12 +5239,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (e.isPopupTrigger()) { String msg = MessageManager.getString("label.enter_view_name"); - String reply = JvOptionPane.showInternalInputDialog(this, msg, msg, - JvOptionPane.QUESTION_MESSAGE); + String ttl = tabbedPane.getTitleAt(tabbedPane.getSelectedIndex()); + String reply = JvOptionPane.showInputDialog(msg, ttl); if (reply != null) { - viewport.viewName = reply; + viewport.setViewName(reply); // TODO warn if reply is in getExistingViewNames()? tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), reply); } @@ -4879,7 +5355,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, trimrs.setSelected(trimrs.isSelected()); Cache.setProperty(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES, Boolean.valueOf(trimrs.isSelected()).toString()); - }; + } }); rfetch.add(trimrs); JMenuItem fetchr = new JMenuItem( @@ -4908,33 +5384,37 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void finished() { + + for (FeatureSettingsModelI srcSettings : dbRefFetcher + .getFeatureSettingsModels()) + { + + alignPanel.av.mergeFeaturesStyle(srcSettings); + } AlignFrame.this.setMenusForViewport(); } }); dbRefFetcher.fetchDBRefs(false); } - }).start(); + }, "BuildFetchDBMenuThread").start(); } }); rfetch.add(fetchr); - final AlignFrame me = this; new Thread(new Runnable() { @Override public void run() { final jalview.ws.SequenceFetcher sf = jalview.gui.SequenceFetcher - .getSequenceFetcherSingleton(me); + .getSequenceFetcherSingleton(); javax.swing.SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - String[] dbclasses = sf.getOrderedSupportedSources(); - // sf.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class); - // jalview.util.QuickSort.sort(otherdb, otherdb); + String[] dbclasses = sf.getNonAlignmentSources(); List otherdb; JMenu dfetch = new JMenu(); JMenu ifetch = new JMenu(); @@ -4951,12 +5431,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { continue; } - // List dbs=otherdb; - // otherdb=new ArrayList(); - // for (DbSourceProxy db:dbs) - // { - // if (!db.isA(DBRefSource.ALIGNMENTDB) - // } if (mname == null) { mname = "From " + dbclass; @@ -4993,6 +5467,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void finished() { + FeatureSettingsModelI srcSettings = dassource[0] + .getFeatureColourScheme(); + alignPanel.av.mergeFeaturesStyle( + srcSettings); AlignFrame.this.setMenusForViewport(); } }); @@ -5285,7 +5763,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { PaintRefresher.Refresh(this, viewport.getSequenceSetId()); alignPanel.updateAnnotation(); - alignPanel.paintAlignment(true, true); + alignPanel.paintAlignment(true, + viewport.needToUpdateStructureViews()); } } @@ -5400,7 +5879,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, */ public List getAlignPanels() { - return alignPanels == null ? Arrays.asList(alignPanel) : alignPanels; + // alignPanels is never null + // return alignPanels == null ? Arrays.asList(alignPanel) : alignPanels; + return alignPanels; } /** @@ -5569,15 +6050,16 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, colourMenu.add(textColour); colourMenu.addSeparator(); - ColourMenuHelper.addMenuItems(colourMenu, this, viewport.getAlignment(), - false); + ButtonGroup bg = ColourMenuHelper.addMenuItems(colourMenu, this, + viewport.getAlignment(), false); + colourMenu.add(annotationColour); + bg.add(annotationColour); colourMenu.addSeparator(); colourMenu.add(conservationMenuItem); colourMenu.add(modifyConservation); colourMenu.add(abovePIDThreshold); colourMenu.add(modifyPID); - colourMenu.add(annotationColour); ColourSchemeI colourScheme = viewport.getGlobalColourScheme(); ColourMenuHelper.setColourSelected(colourMenu, colourScheme); @@ -5603,17 +6085,34 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, 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.setResponseHandler(0, new Runnable() + { + @Override + public void run() + { + String choice = chooser.getSelectedFile().getPath(); + Cache.setProperty("LAST_DIRECTORY", choice); + SequenceI[] seqs = viewport.getAlignment().getSequencesArray(); + new VCFLoader(choice).loadVCF(seqs, us); + } + }); + chooser.showOpenDialog(null); - int value = chooser.showOpenDialog(null); + } - 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); - } + private Rectangle lastFeatureSettingsBounds = null; + @Override + public void setFeatureSettingsGeometry(Rectangle bounds) + { + lastFeatureSettingsBounds = bounds; + } + + @Override + public Rectangle getFeatureSettingsGeometry() + { + return lastFeatureSettingsBounds; } }