X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=8f7b61bbe53384b5bcc80dfc79397928872afd90;hb=d80f1e36b72435aa94d9de8811eb43e184eb435c;hp=e00bbda8411d45ae1853bb9cb96be081eca03d60;hpb=78c87253cd1ecb58a59bd70071daf0464dc9b9e8;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index e00bbda..8f7b61b 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -26,7 +26,7 @@ import jalview.analysis.CrossRef; import jalview.analysis.Dna; import jalview.analysis.ParseProperties; import jalview.analysis.SequenceIdMatcher; -import jalview.api.AlignExportSettingI; +import jalview.api.AlignExportSettingsI; import jalview.api.AlignViewControllerGuiI; import jalview.api.AlignViewControllerI; import jalview.api.AlignViewportI; @@ -45,6 +45,7 @@ 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; @@ -54,7 +55,6 @@ import jalview.datamodel.AlignmentOrder; import jalview.datamodel.AlignmentView; import jalview.datamodel.ColumnSelection; import jalview.datamodel.HiddenColumns; -import jalview.datamodel.HiddenSequences; import jalview.datamodel.PDBEntry; import jalview.datamodel.SeqCigar; import jalview.datamodel.Sequence; @@ -81,11 +81,13 @@ 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; import jalview.schemes.ResidueColourScheme; import jalview.schemes.TCoffeeColourScheme; +import jalview.util.ImageMaker.TYPE; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; import jalview.viewmodel.ViewportRanges; @@ -97,6 +99,7 @@ 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.Rectangle; import java.awt.Toolkit; @@ -134,11 +137,14 @@ import java.util.List; import java.util.Vector; import javax.swing.JCheckBoxMenuItem; +import javax.swing.JComponent; 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; @@ -163,11 +169,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, AlignViewport viewport; - ViewportRanges vpRanges; - public AlignViewControllerI avc; - List alignPanels = new ArrayList(); + List alignPanels = new ArrayList<>(); /** * Last format used to load or save alignments in this window @@ -179,6 +183,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, */ String fileName = null; + File fileObject; + /** * Creates a new AlignFrame object with specific width and height. * @@ -234,8 +240,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param height * height of frame. */ - public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, - int width, int height) + public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width, + int height) { this(al, hiddenColumns, width, height, null); } @@ -251,8 +257,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param sequenceSetId * (may be null) */ - public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, - int width, int height, String sequenceSetId) + public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width, + int height, String sequenceSetId) { this(al, hiddenColumns, width, height, sequenceSetId, null); } @@ -270,8 +276,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param viewId * (may be null) */ - public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, - int width, int height, String sequenceSetId, String viewId) + public AlignFrame(AlignmentI al, HiddenColumns hiddenColumns, int width, + int height, String sequenceSetId, String viewId) { setSize(width, height); @@ -336,7 +342,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, progressBar = new ProgressBar(this.statusPanel, this.statusBar); } - vpRanges = viewport.getRanges(); avc = new jalview.controller.AlignViewController(this, viewport, alignPanel); if (viewport.getAlignmentConservationAnnotation() == null) @@ -380,7 +385,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (Desktop.desktop != null) { this.setDropTarget(new java.awt.dnd.DropTarget(this, this)); - addServiceListeners(); + /** + * BH 2018 ignore service listeners + * + * @j2sNative + * + */ + { + addServiceListeners(); + } setGUINucleotide(); } @@ -396,8 +409,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, addKeyListener(); - final List selviews = new ArrayList(); - final List origview = new ArrayList(); + final List selviews = new ArrayList<>(); + final List origview = new ArrayList<>(); final String menuLabel = MessageManager .getString("label.copy_format_from"); ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel, @@ -410,7 +423,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, origview.clear(); origview.add(alignPanel); // make an array of all alignment panels except for this one - List aps = new ArrayList( + List aps = new ArrayList<>( Arrays.asList(Desktop.getAlignmentPanels(null))); aps.remove(AlignFrame.this.alignPanel); return aps.toArray(new AlignmentPanel[aps.size()]); @@ -499,6 +512,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 */ @@ -510,9 +534,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void keyPressed(KeyEvent evt) { if (viewport.cursorMode - && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt - .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt - .getKeyCode() <= KeyEvent.VK_NUMPAD9)) + && ((evt.getKeyCode() >= KeyEvent.VK_0 + && evt.getKeyCode() <= KeyEvent.VK_9) + || (evt.getKeyCode() >= KeyEvent.VK_NUMPAD0 + && evt.getKeyCode() <= KeyEvent.VK_NUMPAD9)) && Character.isDigit(evt.getKeyChar())) { alignPanel.getSeqPanel().numberPressed(evt.getKeyChar()); @@ -552,7 +577,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, case KeyEvent.VK_LEFT: if (evt.isAltDown() || !viewport.cursorMode) { - slideSequences(false, alignPanel.getSeqPanel().getKeyboardNo1()); + slideSequences(false, + alignPanel.getSeqPanel().getKeyboardNo1()); } else { @@ -575,9 +601,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, case KeyEvent.VK_SPACE: if (viewport.cursorMode) { - alignPanel.getSeqPanel().insertGapAtCursor( - evt.isControlDown() || evt.isShiftDown() - || evt.isAltDown()); + alignPanel.getSeqPanel().insertGapAtCursor(evt.isControlDown() + || evt.isShiftDown() || evt.isAltDown()); } break; @@ -600,9 +625,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } else { - alignPanel.getSeqPanel().deleteGapAtCursor( - evt.isControlDown() || evt.isShiftDown() - || evt.isAltDown()); + alignPanel.getSeqPanel().deleteGapAtCursor(evt.isControlDown() + || evt.isShiftDown() || evt.isAltDown()); } break; @@ -649,14 +673,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, case KeyEvent.VK_F2: viewport.cursorMode = !viewport.cursorMode; - statusBar.setText(MessageManager.formatMessage( - "label.keyboard_editing_mode", - new String[] { (viewport.cursorMode ? "on" : "off") })); + setStatus(MessageManager + .formatMessage("label.keyboard_editing_mode", new String[] + { (viewport.cursorMode ? "on" : "off") })); if (viewport.cursorMode) { - alignPanel.getSeqPanel().seqCanvas.cursorX = vpRanges + ViewportRanges ranges = viewport.getRanges(); + alignPanel.getSeqPanel().seqCanvas.cursorX = ranges .getStartRes(); - alignPanel.getSeqPanel().seqCanvas.cursorY = vpRanges + alignPanel.getSeqPanel().seqCanvas.cursorY = ranges .getStartSeq(); } alignPanel.getSeqPanel().seqCanvas.repaint(); @@ -689,24 +714,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, break; } case KeyEvent.VK_PAGE_UP: - if (viewport.getWrapAlignment()) - { - vpRanges.scrollUp(true); - } - else - { - vpRanges.pageUp(); - } + viewport.getRanges().pageUp(); break; case KeyEvent.VK_PAGE_DOWN: - if (viewport.getWrapAlignment()) - { - vpRanges.scrollUp(false); - } - else - { - vpRanges.pageDown(); - } + viewport.getRanges().pageDown(); break; } } @@ -719,16 +730,16 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, case KeyEvent.VK_LEFT: if (evt.isAltDown() || !viewport.cursorMode) { - viewport.firePropertyChange("alignment", null, viewport - .getAlignment().getSequences()); + viewport.firePropertyChange("alignment", null, + viewport.getAlignment().getSequences()); } break; case KeyEvent.VK_RIGHT: if (evt.isAltDown() || !viewport.cursorMode) { - viewport.firePropertyChange("alignment", null, viewport - .getAlignment().getSequences()); + viewport.firePropertyChange("alignment", null, + viewport.getAlignment().getSequences()); } break; } @@ -748,9 +759,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); } @@ -763,7 +774,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); } @@ -786,7 +797,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); } @@ -814,8 +825,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void run() { - System.err - .println("Rebuild WS Menu for service change"); + System.err.println( + "Rebuild WS Menu for service change"); BuildWebServiceMenu(); } @@ -855,17 +866,18 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, AlignmentI al = getViewport().getAlignment(); boolean nucleotide = al.isNucleotide(); + loadVcf.setVisible(nucleotide); showTranslation.setVisible(nucleotide); showReverse.setVisible(nucleotide); showReverseComplement.setVisible(nucleotide); conservationMenuItem.setEnabled(!nucleotide); - modifyConservation.setEnabled(!nucleotide - && conservationMenuItem.isSelected()); + modifyConservation + .setEnabled(!nucleotide && conservationMenuItem.isSelected()); showGroupConservation.setEnabled(!nucleotide); - showComplementMenuItem.setText(nucleotide ? MessageManager - .getString("label.protein") : MessageManager - .getString("label.nucleotide")); + showComplementMenuItem + .setText(nucleotide ? MessageManager.getString("label.protein") + : MessageManager.getString("label.nucleotide")); } /** @@ -886,7 +898,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()); @@ -980,7 +992,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void setStatus(String text) { - statusBar.setText(text); + // BH note: If text width and height are 0, then the layout manager + // will dispense of it and change the frame height. + // In JavaScript, we use \u00A0 -- unicode "non-breaking space" + // which is the unicode encoding of   + + statusBar.setText(text.length() == 0 ? " " : text); } /* @@ -997,9 +1014,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 @@ -1039,7 +1056,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, Desktop.instance.closeAssociatedWindows(); FileLoader loader = new FileLoader(); - DataSourceType protocol = fileName.startsWith("http:") ? DataSourceType.URL + DataSourceType protocol = fileName.startsWith("http:") + ? DataSourceType.URL : DataSourceType.FILE; loader.LoadFile(viewport, fileName, protocol, currentFileFormat); } @@ -1048,10 +1066,23 @@ 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()) @@ -1080,8 +1111,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void addFromText_actionPerformed(ActionEvent e) { - Desktop.instance.inputTextboxMenuItem_actionPerformed(viewport - .getAlignPanel()); + Desktop.instance + .inputTextboxMenuItem_actionPerformed(viewport.getAlignPanel()); } @Override @@ -1096,7 +1127,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (fileName == null || (currentFileFormat == null) || fileName.startsWith("http")) { - saveAs_actionPerformed(null); + saveAs_actionPerformed(); } else { @@ -1105,228 +1136,240 @@ 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(); - JalviewFileChooser chooser = JalviewFileChooser.forWrite( - Cache.getProperty("LAST_DIRECTORY"), format); + String format = currentFileFormat == null ? null + : currentFileFormat.getName(); + JalviewFileChooser chooser = JalviewFileChooser + .forWrite(Cache.getProperty("LAST_DIRECTORY"), format); chooser.setFileView(new JalviewFileView()); - chooser.setDialogTitle(MessageManager - .getString("label.save_alignment_to_file")); + 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) + 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) + { + JvOptionPane.showInternalMessageDialog(this, MessageManager + .formatMessage("label.couldnt_save_file", new Object[] + { lastFilenameSaved }), + MessageManager.getString("label.error_saving_file"), + JvOptionPane.WARNING_MESSAGE); + } + 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 = false; + 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 jalview.project.Jalview2XML().saveAlignment(this, file, + shortName); + statusBar.setText(MessageManager.formatMessage( - "label.successfully_saved_to_file_in_format", new Object[] { - fileName, format })); - + "label.successfully_saved_to_file_in_format", new Object[] + { fileName, 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) + lastSaveSuccessful = false; + } + else { - success = false; - ex.printStackTrace(); + try + { + PrintWriter out = new PrintWriter(new FileWriter(file)); + out.print(output); + out.close(); + AlignFrame.this.setTitle(file); + setStatus(MessageManager.formatMessage( + "label.successfully_saved_to_file_in_format", + new Object[] + { fileName, format.getName() })); + } catch (Exception ex) + { + lastSaveSuccessful = false; + ex.printStackTrace(); + } } } - } - - if (!success) - { - JvOptionPane.showInternalMessageDialog(this, MessageManager - .formatMessage("label.couldnt_save_file", - new Object[] { fileName }), MessageManager - .getString("label.error_saving_file"), - JvOptionPane.WARNING_MESSAGE); - } - - return success; - } + }; - private void warningMessage(String warning, String title) - { - if (new jalview.util.Platform().isHeadless()) + /* + * show dialog with export options if applicable; else just do it + */ + if (AlignExportOptions.isNeeded(viewport, format)) { - System.err.println("Warning: " + title + "\nWarning: " + warning); - + 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) - { - 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) + protected void outputText_actionPerformed(String fileFormatName) { - 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) + FileFormatI fileFormat = FileFormats.getInstance() + .forName(fileFormatName); + AlignExportSettingsI options = new AlignExportSettingsAdapter(false); + Runnable outputAction = new Runnable() { - settings = new AlignExportSettings(hasHiddenSeqs, - viewport.hasHiddenColumns(), format); - } - // settings.isExportAnnotations(); - - if (viewport.hasHiddenColumns() && !settings.isExportHiddenColumns()) - { - 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 = alignmentToExport - .getVisibleStartAndEndIndex(viewport.getAlignment() - .getHiddenColumns() - .getHiddenRegions()); - AlignmentExportData ed = new AlignmentExportData(alignmentToExport, - omitHidden, alignmentStartEnd, settings); - return ed; } /** @@ -1355,33 +1398,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 @@ -1408,36 +1457,37 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void exportFeatures_actionPerformed(ActionEvent e) { - new AnnotationExporter().exportFeatures(alignPanel); + new AnnotationExporter(alignPanel).exportFeatures(); } @Override public void exportAnnotations_actionPerformed(ActionEvent e) { - new AnnotationExporter().exportAnnotations(alignPanel); + new AnnotationExporter(alignPanel).exportAnnotations(); } @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")); - - int value = chooser.showOpenDialog(null); - - if (value == JalviewFileChooser.APPROVE_OPTION) + chooser.setDialogTitle( + MessageManager.getString("label.load_jalview_annotations")); + chooser.setToolTipText( + MessageManager.getString("label.load_jalview_annotations")); + 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(); + jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); + loadJalviewDataFile(chooser.getSelectedFile(), null, null, null); + } + }); + chooser.showOpenDialog(this); } /** @@ -1526,9 +1576,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { undoMenuItem.setEnabled(true); CommandI command = viewport.getHistoryList().peek(); - undoMenuItem.setText(MessageManager.formatMessage( - "label.undo_command", - new Object[] { command.getDescription() })); + undoMenuItem.setText(MessageManager + .formatMessage("label.undo_command", new Object[] + { command.getDescription() })); } else { @@ -1541,9 +1591,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, redoMenuItem.setEnabled(true); CommandI command = viewport.getRedoList().peek(); - redoMenuItem.setText(MessageManager.formatMessage( - "label.redo_command", - new Object[] { command.getDescription() })); + redoMenuItem.setText(MessageManager + .formatMessage("label.redo_command", new Object[] + { command.getDescription() })); } else { @@ -1615,8 +1665,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { if (originalSource != viewport) { - Cache.log - .warn("Implementation worry: mismatch of viewport origin for undo"); + Cache.log.warn( + "Implementation worry: mismatch of viewport origin for undo"); } originalSource.updateHiddenColumns(); // originalSource.hasHiddenColumns = (viewport.getColumnSelection() != @@ -1624,8 +1674,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // && viewport.getColumnSelection().getHiddenColumns() != null && // viewport.getColumnSelection() // .getHiddenColumns().size() > 0); - originalSource.firePropertyChange("alignment", null, originalSource - .getAlignment().getSequences()); + originalSource.firePropertyChange("alignment", null, + originalSource.getAlignment().getSequences()); } } @@ -1655,8 +1705,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (originalSource != viewport) { - Cache.log - .warn("Implementation worry: mismatch of viewport origin for redo"); + Cache.log.warn( + "Implementation worry: mismatch of viewport origin for redo"); } originalSource.updateHiddenColumns(); // originalSource.hasHiddenColumns = (viewport.getColumnSelection() != @@ -1664,8 +1714,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // && viewport.getColumnSelection().getHiddenColumns() != null && // viewport.getColumnSelection() // .getHiddenColumns().size() > 0); - originalSource.firePropertyChange("alignment", null, originalSource - .getAlignment().getSequences()); + originalSource.firePropertyChange("alignment", null, + originalSource.getAlignment().getSequences()); } } @@ -1680,8 +1730,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { EditCommand editCommand = (EditCommand) command; al = editCommand.getAlignment(); - List comps = PaintRefresher.components.get(viewport - .getSequenceSetId()); + List comps = PaintRefresher.components + .get(viewport.getSequenceSetId()); for (Component comp : comps) { @@ -1727,23 +1777,23 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } viewport.getAlignment().moveSelectedSequencesByOne(sg, viewport.getHiddenRepSequences(), up); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); } synchronized void slideSequences(boolean right, int size) { - List sg = new ArrayList(); + List sg = new ArrayList<>(); if (viewport.cursorMode) { - sg.add(viewport.getAlignment().getSequenceAt( - alignPanel.getSeqPanel().seqCanvas.cursorY)); + sg.add(viewport.getAlignment() + .getSequenceAt(alignPanel.getSeqPanel().seqCanvas.cursorY)); } else if (viewport.getSelectionGroup() != null && viewport.getSelectionGroup().getSize() != viewport .getAlignment().getHeight()) { - sg = viewport.getSelectionGroup().getSequences( - viewport.getHiddenRepSequences()); + sg = viewport.getSelectionGroup() + .getSequences(viewport.getHiddenRepSequences()); } if (sg.size() < 1) @@ -1751,7 +1801,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return; } - List invertGroup = new ArrayList(); + List invertGroup = new ArrayList<>(); for (SequenceI seq : viewport.getAlignment().getSequences()) { @@ -1772,13 +1822,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, SlideSequencesCommand ssc; if (right) { - ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1, - size, viewport.getGapCharacter()); + ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1, size, + viewport.getGapCharacter()); } else { - ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2, - size, viewport.getGapCharacter()); + ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2, size, + viewport.getGapCharacter()); } int groupAdjustment = 0; @@ -1823,9 +1873,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (!inSplitFrame && historyList != null && historyList.size() > 0 && historyList.peek() instanceof SlideSequencesCommand) { - appendHistoryItem = ssc - .appendSlideCommand((SlideSequencesCommand) historyList - .peek()); + appendHistoryItem = ssc.appendSlideCommand( + (SlideSequencesCommand) historyList.peek()); } if (!appendHistoryItem) @@ -1845,7 +1894,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override protected void copy_actionPerformed(ActionEvent e) { - System.gc(); if (viewport.getSelectionGroup() == null) { return; @@ -1873,36 +1921,32 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, Toolkit.getDefaultToolkit().getSystemClipboard() .setContents(new StringSelection(""), null); - Toolkit.getDefaultToolkit().getSystemClipboard() - .setContents(ss, Desktop.instance); + Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, + Desktop.instance); } catch (OutOfMemoryError er) { new OOMWarning("copying region", er); return; } - ArrayList hiddenColumns = null; + HiddenColumns hiddenColumns = null; if (viewport.hasHiddenColumns()) { - hiddenColumns = new ArrayList(); - int hiddenOffset = viewport.getSelectionGroup().getStartRes(), hiddenCutoff = viewport - .getSelectionGroup().getEndRes(); - for (int[] region : viewport.getAlignment().getHiddenColumns() - .getHiddenRegions()) - { - if (region[0] >= hiddenOffset && region[1] <= hiddenCutoff) - { - hiddenColumns.add(new int[] { region[0] - hiddenOffset, - region[1] - hiddenOffset }); - } - } + int hiddenOffset = viewport.getSelectionGroup().getStartRes(); + int hiddenCutoff = viewport.getSelectionGroup().getEndRes(); + + // create new HiddenColumns object with copy of hidden regions + // between startRes and endRes, offset by startRes + hiddenColumns = new HiddenColumns( + viewport.getAlignment().getHiddenColumns(), hiddenOffset, + hiddenCutoff, hiddenOffset); } Desktop.jalviewClipboard = new Object[] { seqs, viewport.getAlignment().getDataset(), hiddenColumns }; - statusBar.setText(MessageManager.formatMessage( - "label.copied_sequences_to_clipboard", new Object[] { Integer - .valueOf(seqs.length).toString() })); + setStatus(MessageManager.formatMessage( + "label.copied_sequences_to_clipboard", new Object[] + { Integer.valueOf(seqs.length).toString() })); } /** @@ -1994,7 +2038,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } int alwidth = 0; - ArrayList newGraphGroups = new ArrayList(); + ArrayList newGraphGroups = new ArrayList<>(); int fgroup = -1; if (newAlignment) @@ -2052,8 +2096,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { // copy and derive new dataset sequence sequences[i] = sequences[i].deriveSequence(); - alignment.getDataset().addSequence( - sequences[i].getDatasetSequence()); + alignment.getDataset() + .addSequence(sequences[i].getDatasetSequence()); // TODO: avoid creation of duplicate dataset sequences with a // 'contains' method using SequenceI.equals()/SequenceI.contains() } @@ -2083,18 +2127,20 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, annotationAdded = true; if (alann[i].sequenceRef == null && !alann[i].autoCalculated) { - AlignmentAnnotation newann = new AlignmentAnnotation(alann[i]); + AlignmentAnnotation newann = new AlignmentAnnotation( + alann[i]); if (newann.graphGroup > -1) { if (newGraphGroups.size() <= newann.graphGroup || newGraphGroups.get(newann.graphGroup) == null) { - for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++) + for (int q = newGraphGroups + .size(); q <= newann.graphGroup; q++) { newGraphGroups.add(q, null); } - newGraphGroups.set(newann.graphGroup, new Integer( - ++fgroup)); + newGraphGroups.set(newann.graphGroup, + new Integer(++fgroup)); } newann.graphGroup = newGraphGroups.get(newann.graphGroup) .intValue(); @@ -2113,7 +2159,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // addHistoryItem(new EditCommand( MessageManager.getString("label.add_sequences"), - Action.PASTE, sequences, 0, alignment.getWidth(), alignment)); + Action.PASTE, sequences, 0, alignment.getWidth(), + alignment)); } // Add any annotations attached to sequences for (int i = 0; i < sequences.length; i++) @@ -2134,12 +2181,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (newGraphGroups.size() <= newann.graphGroup || newGraphGroups.get(newann.graphGroup) == null) { - for (int q = newGraphGroups.size(); q <= newann.graphGroup; q++) + for (int q = newGraphGroups + .size(); q <= newann.graphGroup; q++) { newGraphGroups.add(q, null); } - newGraphGroups.set(newann.graphGroup, new Integer( - ++fgroup)); + newGraphGroups.set(newann.graphGroup, + new Integer(++fgroup)); } newann.graphGroup = newGraphGroups.get(newann.graphGroup) .intValue(); @@ -2149,8 +2197,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // was // duplicated // earlier - alignment - .setAnnotationIndex(sequences[i].getAnnotation()[a], a); + alignment.setAnnotationIndex(sequences[i].getAnnotation()[a], + a); } } } @@ -2158,7 +2206,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { // propagate alignment changed. - vpRanges.setEndSeq(alignment.getHeight()); + viewport.getRanges().setEndSeq(alignment.getHeight()); if (annotationAdded) { // Duplicate sequence annotation in all views. @@ -2220,19 +2268,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (Desktop.jalviewClipboard != null && Desktop.jalviewClipboard[2] != null) { - List hc = (List) Desktop.jalviewClipboard[2]; - for (int[] region : hc) - { - af.viewport.hideColumns(region[0], region[1]); - } + HiddenColumns hc = (HiddenColumns) Desktop.jalviewClipboard[2]; + af.viewport.setHiddenColumns(hc); } // >>>This is a fix for the moment, until a better solution is // found!!<<< af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer() - .transferSettings( - alignPanel.getSeqPanel().seqCanvas - .getFeatureRenderer()); + .transferSettings(alignPanel.getSeqPanel().seqCanvas + .getFeatureRenderer()); // TODO: maintain provenance of an alignment, rather than just make the // title a concatenation of operations. @@ -2271,8 +2315,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { try { - AlignmentI alignment = AlignmentUtils.expandContext(getViewport() - .getAlignment(), -1); + AlignmentI alignment = AlignmentUtils + .expandContext(getViewport().getAlignment(), -1); AlignFrame af = new AlignFrame(alignment, DEFAULT_WIDTH, DEFAULT_HEIGHT); String newtitle = new String("Flanking alignment"); @@ -2280,19 +2324,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (Desktop.jalviewClipboard != null && Desktop.jalviewClipboard[2] != null) { - List hc = (List) Desktop.jalviewClipboard[2]; - for (int region[] : hc) - { - af.viewport.hideColumns(region[0], region[1]); - } + HiddenColumns hc = (HiddenColumns) Desktop.jalviewClipboard[2]; + af.viewport.setHiddenColumns(hc); } // >>>This is a fix for the moment, until a better solution is // found!!<<< af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer() - .transferSettings( - alignPanel.getSeqPanel().seqCanvas - .getFeatureRenderer()); + .transferSettings(alignPanel.getSeqPanel().seqCanvas + .getFeatureRenderer()); // TODO: maintain provenance of an alignment, rather than just make the // title a concatenation of operations. @@ -2354,8 +2394,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, */ if (sg.getSize() == viewport.getAlignment().getHeight()) { - boolean isEntireAlignWidth = (((sg.getEndRes() - sg.getStartRes()) + 1) == viewport - .getAlignment().getWidth()) ? true : false; + boolean isEntireAlignWidth = (((sg.getEndRes() - sg.getStartRes()) + + 1) == viewport.getAlignment().getWidth()) ? true : false; if (isEntireAlignWidth) { int confirm = JvOptionPane.showConfirmDialog(this, @@ -2384,8 +2424,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport.sendSelection(); viewport.getAlignment().deleteGroup(sg); - viewport.firePropertyChange("alignment", null, viewport.getAlignment() - .getSequences()); + viewport.firePropertyChange("alignment", null, + viewport.getAlignment().getSequences()); if (viewport.getAlignment().getHeight() < 1) { try @@ -2410,7 +2450,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { PaintRefresher.Refresh(this, viewport.getSequenceSetId()); alignPanel.updateAnnotation(); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, true); } } @@ -2436,7 +2476,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // JAL-2034 - should delegate to // alignPanel to decide if overview needs // updating. - alignPanel.paintAlignment(false); + alignPanel.paintAlignment(false, false); PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId()); } @@ -2461,7 +2501,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // JAL-2034 - should delegate to // alignPanel to decide if overview needs // updating. - alignPanel.paintAlignment(false); + alignPanel.paintAlignment(false, false); PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId()); viewport.sendSelection(); } @@ -2492,7 +2532,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // alignPanel to decide if overview needs // updating. - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId()); viewport.sendSelection(); } @@ -2501,7 +2541,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void invertColSel_actionPerformed(ActionEvent e) { viewport.invertColumnSelection(); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); viewport.sendSelection(); } @@ -2548,8 +2588,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, SequenceI[] seqs; if (viewport.getSelectionGroup() != null) { - seqs = viewport.getSelectionGroup().getSequencesAsArray( - viewport.getHiddenRepSequences()); + seqs = viewport.getSelectionGroup() + .getSequencesAsArray(viewport.getHiddenRepSequences()); } else { @@ -2561,7 +2601,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { trimRegion = new TrimRegionCommand("Remove Left", true, seqs, column, viewport.getAlignment()); - vpRanges.setStartRes(0); + viewport.getRanges().setStartRes(0); } else { @@ -2569,10 +2609,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, column, viewport.getAlignment()); } - statusBar.setText(MessageManager.formatMessage( - "label.removed_columns", - new String[] { Integer.valueOf(trimRegion.getSize()) - .toString() })); + setStatus(MessageManager + .formatMessage("label.removed_columns", new String[] + { Integer.valueOf(trimRegion.getSize()).toString() })); addHistoryItem(trimRegion); @@ -2585,8 +2624,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } } - viewport.firePropertyChange("alignment", null, viewport - .getAlignment().getSequences()); + viewport.firePropertyChange("alignment", null, + viewport.getAlignment().getSequences()); } } @@ -2604,8 +2643,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, SequenceI[] seqs; if (viewport.getSelectionGroup() != null) { - seqs = viewport.getSelectionGroup().getSequencesAsArray( - viewport.getHiddenRepSequences()); + seqs = viewport.getSelectionGroup() + .getSequencesAsArray(viewport.getHiddenRepSequences()); start = viewport.getSelectionGroup().getStartRes(); end = viewport.getSelectionGroup().getEndRes(); } @@ -2620,23 +2659,23 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, addHistoryItem(removeGapCols); - statusBar.setText(MessageManager.formatMessage( - "label.removed_empty_columns", - new Object[] { Integer.valueOf(removeGapCols.getSize()) - .toString() })); + setStatus(MessageManager + .formatMessage("label.removed_empty_columns", new Object[] + { Integer.valueOf(removeGapCols.getSize()).toString() })); // This is to maintain viewport position on first residue // of first sequence SequenceI seq = viewport.getAlignment().getSequenceAt(0); - int startRes = seq.findPosition(vpRanges.getStartRes()); + ViewportRanges ranges = viewport.getRanges(); + int startRes = seq.findPosition(ranges.getStartRes()); // ShiftList shifts; // viewport.getAlignment().removeGaps(shifts=new ShiftList()); // edit.alColumnChanges=shifts.getInverse(); // if (viewport.hasHiddenColumns) // viewport.getColumnSelection().compensateForEdits(shifts); - vpRanges.setStartRes(seq.findIndex(startRes) - 1); - viewport.firePropertyChange("alignment", null, viewport.getAlignment() - .getSequences()); + ranges.setStartRes(seq.findIndex(startRes) - 1); + viewport.firePropertyChange("alignment", null, + viewport.getAlignment().getSequences()); } @@ -2654,8 +2693,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, SequenceI[] seqs; if (viewport.getSelectionGroup() != null) { - seqs = viewport.getSelectionGroup().getSequencesAsArray( - viewport.getHiddenRepSequences()); + seqs = viewport.getSelectionGroup() + .getSequencesAsArray(viewport.getHiddenRepSequences()); start = viewport.getSelectionGroup().getStartRes(); end = viewport.getSelectionGroup().getEndRes(); } @@ -2667,15 +2706,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // This is to maintain viewport position on first residue // of first sequence SequenceI seq = viewport.getAlignment().getSequenceAt(0); - int startRes = seq.findPosition(vpRanges.getStartRes()); + int startRes = seq.findPosition(viewport.getRanges().getStartRes()); addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end, viewport.getAlignment())); - vpRanges.setStartRes(seq.findIndex(startRes) - 1); + viewport.getRanges().setStartRes(seq.findIndex(startRes) - 1); - viewport.firePropertyChange("alignment", null, viewport.getAlignment() - .getSequences()); + viewport.firePropertyChange("alignment", null, + viewport.getAlignment().getSequences()); } @@ -2689,8 +2728,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void padGapsMenuitem_actionPerformed(ActionEvent e) { viewport.setPadGaps(padGapsMenuitem.isSelected()); - viewport.firePropertyChange("alignment", null, viewport.getAlignment() - .getSequences()); + viewport.firePropertyChange("alignment", null, + viewport.getAlignment().getSequences()); } /** @@ -2728,8 +2767,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, /* * Create a new AlignmentPanel (with its own, new Viewport) */ - AlignmentPanel newap = new Jalview2XML().copyAlignPanel(alignPanel, - true); + AlignmentPanel newap = new jalview.project.Jalview2XML() + .copyAlignPanel(alignPanel); if (!copyAnnotation) { /* @@ -2741,10 +2780,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")); } /* @@ -2768,7 +2807,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,8 +2843,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } String newViewName = viewTitle + ((addFirstIndex) ? " " + index : ""); - List comps = PaintRefresher.components.get(viewport - .getSequenceSetId()); + List comps = PaintRefresher.components + .get(viewport.getSequenceSetId()); List existingNames = getExistingViewNames(comps); @@ -2825,15 +2864,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, */ protected List getExistingViewNames(List comps) { - List existingNames = new ArrayList(); + List existingNames = new ArrayList<>(); for (Component comp : comps) { 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()); } } } @@ -2883,21 +2922,21 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, alignPanel.getIdPanel().getIdCanvas() .setPreferredSize(alignPanel.calculateIdWidth()); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); } @Override public void idRightAlign_actionPerformed(ActionEvent e) { viewport.setRightAlignIds(idRightAlign.isSelected()); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(false, false); } @Override public void centreColumnLabels_actionPerformed(ActionEvent e) { viewport.setCentreColumnLabels(centreColumnLabelsMenuItem.getState()); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(false, false); } /* @@ -2930,7 +2969,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void colourTextMenuItem_actionPerformed(ActionEvent e) { viewport.setColourText(colourTextMenuItem.isSelected()); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(false, false); } /** @@ -2959,7 +2998,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void showAllColumns_actionPerformed(ActionEvent e) { viewport.showAllHiddenColumns(); - repaint(); + alignPanel.paintAlignment(true, true); viewport.sendSelection(); } @@ -2967,7 +3006,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void hideSelSequences_actionPerformed(ActionEvent e) { viewport.hideAllSelectedSeqs(); - // alignPanel.paintAlignment(true); } /** @@ -2986,9 +3024,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // Hide everything by the current selection - this is a hack - we do the // invert and then hide // first check that there will be visible columns after the invert. - if (viewport.hasSelectedColumns() - || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg - .getEndRes())) + if (viewport.hasSelectedColumns() || (sg != null && sg.getSize() > 0 + && sg.getStartRes() <= sg.getEndRes())) { // now invert the sequence set, if required - empty selection implies // that no hiding is required. @@ -3065,7 +3102,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport.expandColSelection(sg, false); viewport.hideAllSelectedSeqs(); viewport.hideSelectedColumns(); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, true); viewport.sendSelection(); } @@ -3081,7 +3118,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { viewport.showAllHiddenColumns(); viewport.showAllHiddenSeqs(); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, true); viewport.sendSelection(); } @@ -3089,7 +3126,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void hideSelColumns_actionPerformed(ActionEvent e) { viewport.hideSelectedColumns(); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, true); viewport.sendSelection(); } @@ -3110,7 +3147,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void scaleAbove_actionPerformed(ActionEvent e) { viewport.setScaleAboveWrapped(scaleAbove.isSelected()); - alignPanel.paintAlignment(true); + // TODO: do we actually need to update overview for scale above change ? + alignPanel.paintAlignment(true, false); } /** @@ -3123,7 +3161,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void scaleLeft_actionPerformed(ActionEvent e) { viewport.setScaleLeftWrapped(scaleLeft.isSelected()); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); } /** @@ -3136,7 +3174,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void scaleRight_actionPerformed(ActionEvent e) { viewport.setScaleRightWrapped(scaleRight.isSelected()); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); } /** @@ -3149,7 +3187,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void viewBoxesMenuItem_actionPerformed(ActionEvent e) { viewport.setShowBoxes(viewBoxesMenuItem.isSelected()); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(false, false); } /** @@ -3162,7 +3200,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void viewTextMenuItem_actionPerformed(ActionEvent e) { viewport.setShowText(viewTextMenuItem.isSelected()); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(false, false); } /** @@ -3175,7 +3213,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void renderGapsMenuItem_actionPerformed(ActionEvent e) { viewport.setRenderGaps(renderGapsMenuItem.isSelected()); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(false, false); } public FeatureSettings featureSettings; @@ -3213,11 +3251,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void showSeqFeatures_actionPerformed(ActionEvent evt) { viewport.setShowSequenceFeatures(showSeqFeatures.isSelected()); - alignPanel.paintAlignment(true); - if (alignPanel.getOverviewPanel() != null) - { - alignPanel.getOverviewPanel().updateOverviewImage(); - } + alignPanel.paintAlignment(true, true); } /** @@ -3244,18 +3278,41 @@ 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 (Jalview.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 + { + JEditorPane editPane = new JEditorPane("text/html", ""); + editPane.setEditable(false); + editPane.setText(content); + pane = editPane; + } + JInternalFrame frame = new JInternalFrame(); - frame.getContentPane().add(new JScrollPane(editPane)); - Desktop.addInternalFrame(frame, MessageManager.formatMessage( - "label.alignment_properties", new Object[] { getTitle() }), - 500, 400); + frame.getContentPane().add(new JScrollPane(pane)); + + Desktop.addInternalFrame(frame, MessageManager + .formatMessage("label.alignment_properties", new Object[] + { getTitle() }), 500, 400); } /** @@ -3273,22 +3330,29 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } JInternalFrame frame = new JInternalFrame(); - OverviewPanel overview = new OverviewPanel(alignPanel); + final OverviewPanel overview = new OverviewPanel(alignPanel); frame.setContentPane(overview); - Desktop.addInternalFrame(frame, MessageManager.formatMessage( - "label.overview_params", new Object[] { this.getTitle() }), - true, frame.getWidth(), frame.getHeight(), true, true); + Desktop.addInternalFrame(frame, MessageManager + .formatMessage("label.overview_params", new Object[] + { this.getTitle() }), true, frame.getWidth(), frame.getHeight(), + true, true); frame.pack(); frame.setLayer(JLayeredPane.PALETTE_LAYER); - frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() + frame.addInternalFrameListener( + new javax.swing.event.InternalFrameAdapter() + { + @Override + public void internalFrameClosed( + javax.swing.event.InternalFrameEvent evt) + { + overview.dispose(); + alignPanel.setOverviewPanel(null); + }; + }); + if (getKeyListeners().length > 0) { - @Override - public void internalFrameClosed( - javax.swing.event.InternalFrameEvent evt) - { - alignPanel.setOverviewPanel(null); - }; - }); + frame.addKeyListener(getKeyListeners()[0]); + } alignPanel.setOverviewPanel(overview); } @@ -3343,7 +3407,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * 'User Defined' opens a panel to configure or load a * user-defined colour scheme */ - if (ResidueColourScheme.USER_DEFINED.equals(name)) + if (ResidueColourScheme.USER_DEFINED_MENU.equals(name)) { new UserDefinedColours(alignPanel); return; @@ -3370,7 +3434,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport.setGlobalColourScheme(cs); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, true); } /** @@ -3379,8 +3443,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override protected void modifyPID_actionPerformed() { - SliderPanel.setPIDSliderSource(alignPanel, - viewport.getResidueShading(), alignPanel.getViewName()); + SliderPanel.setPIDSliderSource(alignPanel, viewport.getResidueShading(), + alignPanel.getViewName()); SliderPanel.showPIDSlider(); } @@ -3451,11 +3515,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void sortPairwiseMenuItem_actionPerformed(ActionEvent e) { SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray(); - AlignmentSorter.sortByPID(viewport.getAlignment(), viewport - .getAlignment().getSequenceAt(0)); + AlignmentSorter.sortByPID(viewport.getAlignment(), + viewport.getAlignment().getSequenceAt(0)); addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder, viewport.getAlignment())); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); } /** @@ -3469,9 +3533,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray(); AlignmentSorter.sortByID(viewport.getAlignment()); - addHistoryItem(new OrderCommand("ID Sort", oldOrder, - viewport.getAlignment())); - alignPanel.paintAlignment(true); + addHistoryItem( + new OrderCommand("ID Sort", oldOrder, viewport.getAlignment())); + alignPanel.paintAlignment(true, false); } /** @@ -3487,7 +3551,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, AlignmentSorter.sortByLength(viewport.getAlignment()); addHistoryItem(new OrderCommand("Length Sort", oldOrder, viewport.getAlignment())); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); } /** @@ -3504,7 +3568,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, addHistoryItem(new OrderCommand("Group Sort", oldOrder, viewport.getAlignment())); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); } /** @@ -3531,8 +3595,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if ((viewport.getSelectionGroup() == null) || (viewport.getSelectionGroup().getSize() < 2)) { - JvOptionPane.showInternalMessageDialog(this, MessageManager - .getString("label.you_must_select_least_two_sequences"), + JvOptionPane.showInternalMessageDialog(this, + MessageManager.getString( + "label.you_must_select_least_two_sequences"), MessageManager.getString("label.invalid_selection"), JvOptionPane.WARNING_MESSAGE); } @@ -3552,8 +3617,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport.autoCalculateConsensus = autoCalculate.isSelected(); if (viewport.autoCalculateConsensus) { - viewport.firePropertyChange("alignment", null, viewport - .getAlignment().getSequences()); + viewport.firePropertyChange("alignment", null, + viewport.getAlignment().getSequences()); } } @@ -3579,7 +3644,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param options * parameters for the distance or similarity calculation */ - void newTreePanel(String type, String modelName, SimilarityParamsI options) + void newTreePanel(String type, String modelName, + SimilarityParamsI options) { String frameTitle = ""; TreePanel tp; @@ -3595,14 +3661,12 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { if (_s.getLength() < sg.getEndRes()) { - JvOptionPane - .showMessageDialog( - Desktop.desktop, - MessageManager - .getString("label.selected_region_to_tree_may_only_contain_residues_or_gaps"), - MessageManager - .getString("label.sequences_selection_not_aligned"), - JvOptionPane.WARNING_MESSAGE); + JvOptionPane.showMessageDialog(Desktop.desktop, + MessageManager.getString( + "label.selected_region_to_tree_may_only_contain_residues_or_gaps"), + MessageManager.getString( + "label.sequences_selection_not_aligned"), + JvOptionPane.WARNING_MESSAGE); return; } @@ -3622,9 +3686,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, frameTitle += " from "; - if (viewport.viewName != null) + if (viewport.getViewName() != null) { - frameTitle += viewport.viewName + " of "; + frameTitle += viewport.getViewName() + " of "; } frameTitle += this.title; @@ -3643,8 +3707,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void addSortByOrderMenuItem(String title, final AlignmentOrder order) { - final JMenuItem item = new JMenuItem(MessageManager.formatMessage( - "action.by_title_param", new Object[] { title })); + final JMenuItem item = new JMenuItem(MessageManager + .formatMessage("action.by_title_param", new Object[] + { title })); sort.add(item); item.addActionListener(new java.awt.event.ActionListener() { @@ -3657,10 +3722,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // pointers AlignmentSorter.sortBy(viewport.getAlignment(), order); - addHistoryItem(new OrderCommand(order.getName(), oldOrder, viewport - .getAlignment())); + addHistoryItem(new OrderCommand(order.getName(), oldOrder, + viewport.getAlignment())); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); } }); } @@ -3689,7 +3754,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport.getAlignment());// ,viewport.getSelectionGroup()); addHistoryItem(new OrderCommand("Sort by " + scoreLabel, oldOrder, viewport.getAlignment())); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); } }); } @@ -3714,7 +3779,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return; } - if (viewport.getAlignment().getAlignmentAnnotation().hashCode() != _annotationScoreVectorHash) + if (viewport.getAlignment().getAlignmentAnnotation() + .hashCode() != _annotationScoreVectorHash) { sortByAnnotScore.removeAll(); // almost certainly a quicker way to do this - but we keep it simple @@ -3757,9 +3823,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { sortByTreeMenu.removeAll(); - List comps = PaintRefresher.components.get(viewport - .getSequenceSetId()); - List treePanels = new ArrayList(); + List comps = PaintRefresher.components + .get(viewport.getSequenceSetId()); + List treePanels = new ArrayList<>(); for (Component comp : comps) { if (comp instanceof TreePanel) @@ -3803,7 +3869,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, addHistoryItem(new OrderCommand(undoname, oldOrder, viewport.getAlignment())); } - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); return true; } @@ -3897,40 +3963,43 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, JalviewFileChooser chooser = new JalviewFileChooser( jalview.bin.Cache.getProperty("LAST_DIRECTORY")); chooser.setFileView(new JalviewFileView()); - chooser.setDialogTitle(MessageManager - .getString("label.select_newick_like_tree_file")); - chooser.setToolTipText(MessageManager.getString("label.load_tree_file")); + chooser.setDialogTitle( + MessageManager.getString("label.select_newick_like_tree_file")); + chooser.setToolTipText( + MessageManager.getString("label.load_tree_file")); - int value = chooser.showOpenDialog(null); - - if (value == JalviewFileChooser.APPROVE_OPTION) + chooser.setResponseHandler(0,new Runnable() { - 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()) + @Override + public void run() { - JvOptionPane.showMessageDialog(Desktop.desktop, fin - .getWarningMessage(), MessageManager - .getString("label.possible_problem_with_tree_file"), - JvOptionPane.WARNING_MESSAGE); + 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); + } } - } + }); + chooser.showOpenDialog(this); } public TreePanel showNewickTree(NewickFile nf, String treeTitle) @@ -4019,7 +4088,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void run() { - final List legacyItems = new ArrayList(); + final List legacyItems = new ArrayList<>(); try { // System.err.println("Building ws menu again " @@ -4034,7 +4103,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // TODO: group services by location as well as function and/or // introduce // object broker mechanism. - final Vector wsmenu = new Vector(); + final Vector wsmenu = new Vector<>(); final IProgressIndicator af = me; /* @@ -4157,9 +4226,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } } catch (Exception e) { - Cache.log - .debug("Exception during web service menu building process.", - e); + Cache.log.debug( + "Exception during web service menu building process.", + e); } } }); @@ -4244,7 +4313,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void actionPerformed(ActionEvent e) { - showProductsFor(af.viewport.getSequenceSelection(), dna, source); + showProductsFor(af.viewport.getSequenceSelection(), dna, + source); } }); showProducts.add(xtype); @@ -4253,9 +4323,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, showProducts.setEnabled(showp); } catch (Exception e) { - Cache.log - .warn("canShowProducts threw an exception - please report to help@jalview.org", - e); + Cache.log.warn( + "canShowProducts threw an exception - please report to help@jalview.org", + e); return false; } return showp; @@ -4272,10 +4342,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * @param source * the database to show cross-references for */ - protected void showProductsFor(final SequenceI[] sel, - final boolean _odna, final String source) + protected void showProductsFor(final SequenceI[] sel, final boolean _odna, + final String source) { - new Thread(CrossRefAction.showProductsFor(sel, _odna, source, this)) + new Thread(CrossRefAction.getHandlerFor(sel, _odna, source, this)) .start(); } @@ -4296,8 +4366,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { jalview.bin.Cache.log.error( "Exception during translation. Please report this !", ex); - final String msg = MessageManager - .getString("label.error_when_translating_sequences_submit_bug_report"); + final String msg = MessageManager.getString( + "label.error_when_translating_sequences_submit_bug_report"); final String errorTitle = MessageManager .getString("label.implementation_error") + MessageManager.getString("label.translation_failed"); @@ -4307,8 +4377,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } if (al == null || al.getHeight() == 0) { - final String msg = MessageManager - .getString("label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation"); + final String msg = MessageManager.getString( + "label.select_at_least_three_bases_in_at_least_one_sequence_to_cDNA_translation"); final String errorTitle = MessageManager .getString("label.translation_failed"); JvOptionPane.showMessageDialog(Desktop.desktop, msg, errorTitle, @@ -4318,9 +4388,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { AlignFrame af = new AlignFrame(al, DEFAULT_WIDTH, DEFAULT_HEIGHT); af.setFileFormat(this.currentFileFormat); - final String newTitle = MessageManager.formatMessage( - "label.translation_of_params", - new Object[] { this.getTitle() }); + final String newTitle = MessageManager + .formatMessage("label.translation_of_params", new Object[] + { this.getTitle() }); af.setTitle(newTitle); if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true)) { @@ -4349,13 +4419,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)); @@ -4402,8 +4473,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // Java's Transferable for native dnd evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); Transferable t = evt.getTransferable(); - List files = new ArrayList(); - List protocols = new ArrayList(); + + final AlignFrame thisaf = this; + final List files = new ArrayList<>(); + List protocols = new ArrayList<>(); try { @@ -4414,145 +4487,166 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } if (files != null) { - try + new Thread(new Runnable() { - // check to see if any of these files have names matching sequences in - // the alignment - SequenceIdMatcher idm = new SequenceIdMatcher(viewport - .getAlignment().getSequencesArray()); - /** - * Object[] { String,SequenceI} - */ - ArrayList filesmatched = new ArrayList(); - ArrayList filesnotmatched = new ArrayList(); - for (int i = 0; i < files.size(); i++) + @Override + public void run() { - String file = files.get(i).toString(); - String pdbfn = ""; - DataSourceType protocol = FormatAdapter.checkProtocol(file); - if (protocol == DataSourceType.FILE) - { - File fl = new File(file); - pdbfn = fl.getName(); - } - else if (protocol == DataSourceType.URL) - { - URL url = new URL(file); - pdbfn = url.getFile(); - } - if (pdbfn.length() > 0) + try { - // attempt to find a match in the alignment - SequenceI[] mtch = idm.findAllIdMatches(pdbfn); - int l = 0, c = pdbfn.indexOf("."); - while (mtch == null && c != -1) + // check to see if any of these files have names matching sequences + // in + // the alignment + SequenceIdMatcher idm = new SequenceIdMatcher( + viewport.getAlignment().getSequencesArray()); + /** + * Object[] { String,SequenceI} + */ + ArrayList filesmatched = new ArrayList<>(); + ArrayList filesnotmatched = new ArrayList<>(); + for (int i = 0; i < files.size(); i++) { - do + // BH 2018 + Object file = files.get(i); + String fileName = file.toString(); + String pdbfn = ""; + DataSourceType protocol = (file instanceof File + ? DataSourceType.FILE + : FormatAdapter.checkProtocol(fileName)); + if (protocol == DataSourceType.FILE) { - l = c; - } while ((c = pdbfn.indexOf(".", l)) > l); - if (l > -1) + File fl = (file instanceof File ? (File) file + : new File(fileName)); + pdbfn = fl.getName(); + } + else if (protocol == DataSourceType.URL) + { + URL url = new URL(fileName); + pdbfn = url.getFile(); + } + if (pdbfn.length() > 0) { - pdbfn = pdbfn.substring(0, l); + // attempt to find a match in the alignment + SequenceI[] mtch = idm.findAllIdMatches(pdbfn); + int l = 0, c = pdbfn.indexOf("."); + while (mtch == null && c != -1) + { + do + { + l = c; + } while ((c = pdbfn.indexOf(".", l)) > l); + if (l > -1) + { + pdbfn = pdbfn.substring(0, l); + } + mtch = idm.findAllIdMatches(pdbfn); + } + if (mtch != null) + { + FileFormatI type; + try + { + type = new IdentifyFile().identify(file, protocol); + } catch (Exception ex) + { + type = null; + } + if (type != null && type.isStructureFile()) + { + filesmatched.add(new Object[] { file, protocol, mtch }); + continue; + } + } + // File wasn't named like one of the sequences or wasn't a PDB + // file. + filesnotmatched.add(file); } - mtch = idm.findAllIdMatches(pdbfn); } - if (mtch != null) + int assocfiles = 0; + if (filesmatched.size() > 0) { - FileFormatI type = null; - try + boolean autoAssociate = Cache + .getDefault("AUTOASSOCIATE_PDBANDSEQS", false); + if (!autoAssociate) { - type = new IdentifyFile().identify(file, protocol); - } catch (Exception ex) + String msg = MessageManager.formatMessage( + "label.automatically_associate_structure_files_with_sequences_same_name", + new Object[] + { Integer.valueOf(filesmatched.size()) + .toString() }); + String ttl = MessageManager.getString( + "label.automatically_associate_structure_files_by_name"); + int choice = JvOptionPane.showConfirmDialog(thisaf, msg, + ttl, JvOptionPane.YES_NO_OPTION); + autoAssociate = choice == JvOptionPane.YES_OPTION; + } + if (autoAssociate) { - type = null; + for (Object[] fm : filesmatched) + { + // try and associate + // TODO: may want to set a standard ID naming formalism for + // associating PDB files which have no IDs. + for (SequenceI toassoc : (SequenceI[]) fm[2]) + { + PDBEntry pe = new AssociatePdbFileWithSeq() + .associatePdbWithSeq(fm[0].toString(), + (DataSourceType) fm[1], toassoc, false, + Desktop.instance); + if (pe != null) + { + System.err.println("Associated file : " + + (fm[0].toString()) + " with " + + toassoc.getDisplayId(true)); + assocfiles++; + } + } + // TODO: do we need to update overview ? only if features are + // shown I guess + alignPanel.paintAlignment(true, false); + } } - if (type != null && type.isStructureFile()) + else { - filesmatched.add(new Object[] { file, protocol, mtch }); - continue; + /* + * add declined structures as sequences + */ + for (Object[] o : filesmatched) + { + filesnotmatched.add(o[0]); + } } } - // File wasn't named like one of the sequences or wasn't a PDB file. - filesnotmatched.add(file); - } - } - int assocfiles = 0; - if (filesmatched.size() > 0) - { - if (Cache.getDefault("AUTOASSOCIATE_PDBANDSEQS", false) - || JvOptionPane - .showConfirmDialog( - this, - MessageManager - .formatMessage( - "label.automatically_associate_structure_files_with_sequences_same_name", - new Object[] { Integer - .valueOf( - filesmatched - .size()) - .toString() }), - MessageManager - .getString("label.automatically_associate_structure_files_by_name"), - JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION) - - { - for (Object[] fm : filesmatched) + if (filesnotmatched.size() > 0) { - // try and associate - // TODO: may want to set a standard ID naming formalism for - // associating PDB files which have no IDs. - for (SequenceI toassoc : (SequenceI[]) fm[2]) + if (assocfiles > 0 && (Cache.getDefault( + "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) + || JvOptionPane.showConfirmDialog(thisaf, + "" + MessageManager.formatMessage( + "label.ignore_unmatched_dropped_files_info", + new Object[] + { Integer.valueOf( + filesnotmatched.size()) + .toString() }) + + "", + MessageManager.getString( + "label.ignore_unmatched_dropped_files"), + JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION)) { - PDBEntry pe = new AssociatePdbFileWithSeq() - .associatePdbWithSeq((String) fm[0], - (DataSourceType) fm[1], toassoc, false, - Desktop.instance); - if (pe != null) - { - System.err.println("Associated file : " - + ((String) fm[0]) + " with " - + toassoc.getDisplayId(true)); - assocfiles++; - } + return; + } + for (Object fn : filesnotmatched) + { + loadJalviewDataFile(fn, null, null, null); } - alignPanel.paintAlignment(true); + } - } - } - if (filesnotmatched.size() > 0) - { - if (assocfiles > 0 - && (Cache.getDefault( - "AUTOASSOCIATE_PDBANDSEQS_IGNOREOTHERS", false) || JvOptionPane - .showConfirmDialog( - this, - "" - + MessageManager - .formatMessage( - "label.ignore_unmatched_dropped_files_info", - new Object[] { Integer - .valueOf( - filesnotmatched - .size()) - .toString() }) - + "", - MessageManager - .getString("label.ignore_unmatched_dropped_files"), - JvOptionPane.YES_NO_OPTION) == JvOptionPane.YES_OPTION)) - { - return; - } - for (String fn : filesnotmatched) + } catch (Exception ex) { - loadJalviewDataFile(fn, null, null, null); + ex.printStackTrace(); } - } - } catch (Exception ex) - { - ex.printStackTrace(); - } + }).start(); } } @@ -4568,9 +4662,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) @@ -4580,9 +4675,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // if the file isn't identified, or not positively identified as some // other filetype (PFAM is default unidentified alignment file type) then // try to parse as annotation. - boolean isAnnotation = (format == null || FileFormat.Pfam - .equals(format)) ? new AnnotationFile() - .annotateAlignmentView(viewport, file, sourceType) : false; + boolean isAnnotation = (format == null + || FileFormat.Pfam.equals(format)) + ? new AnnotationFile().annotateAlignmentView(viewport, + file, sourceType) + : false; if (!isAnnotation) { @@ -4596,25 +4693,24 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (tcf.annotateAlignment(viewport.getAlignment(), true)) { buildColourMenu(); - changeColour(new TCoffeeColourScheme(viewport.getAlignment())); + changeColour( + new TCoffeeColourScheme(viewport.getAlignment())); isAnnotation = true; - statusBar - .setText(MessageManager - .getString("label.successfully_pasted_tcoffee_scores_to_alignment")); + setStatus(MessageManager.getString( + "label.successfully_pasted_tcoffee_scores_to_alignment")); } else { // some problem - if no warning its probable that the ID matching // process didn't work - JvOptionPane - .showMessageDialog( - Desktop.desktop, - tcf.getWarningMessage() == null ? MessageManager - .getString("label.check_file_matches_sequence_ids_alignment") - : tcf.getWarningMessage(), - MessageManager - .getString("label.problem_reading_tcoffee_score_file"), - JvOptionPane.WARNING_MESSAGE); + JvOptionPane.showMessageDialog(Desktop.desktop, + tcf.getWarningMessage() == null + ? MessageManager.getString( + "label.check_file_matches_sequence_ids_alignment") + : tcf.getWarningMessage(), + MessageManager.getString( + "label.problem_reading_tcoffee_score_file"), + JvOptionPane.WARNING_MESSAGE); } } else @@ -4623,9 +4719,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } } catch (Exception x) { - Cache.log - .debug("Exception when processing data source as T-COFFEE score file", - x); + Cache.log.debug( + "Exception when processing data source as T-COFFEE score file", + x); tcf = null; } if (tcf == null) @@ -4639,14 +4735,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } if (FileFormat.ScoreMatrix == format) { - ScoreMatrixFile sm = new ScoreMatrixFile(new FileParse(file, - sourceType)); + ScoreMatrixFile sm = new ScoreMatrixFile( + new FileParse(file, sourceType)); sm.parse(); // todo: i18n this message - statusBar - .setText(MessageManager.formatMessage( - "label.successfully_loaded_matrix", - sm.getMatrixName())); + setStatus(MessageManager.formatMessage( + "label.successfully_loaded_matrix", + sm.getMatrixName())); } else if (FileFormat.Jnet.equals(format)) { @@ -4654,11 +4749,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, new JnetAnnotationMaker(); JnetAnnotationMaker.add_annotation(predictions, viewport.getAlignment(), 0, false); - SequenceI repseq = viewport.getAlignment().getSequenceAt(0); - viewport.getAlignment().setSeqrep(repseq); - HiddenColumns cs = new HiddenColumns(); - cs.hideInsertionsFor(repseq); - viewport.getAlignment().setHiddenColumns(cs); + viewport.getAlignment().setupJPredAlignment(); isAnnotation = true; } // else if (IdentifyFile.FeaturesFile.equals(format)) @@ -4666,7 +4757,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { if (parseFeaturesFile(file, sourceType)) { - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, true); } } else @@ -4681,7 +4772,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, alignPanel.adjustAnnotationHeight(); viewport.updateSequenceIdColours(); buildSortByAnnotationScoresMenu(); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, true); } } catch (Exception ex) { @@ -4696,11 +4787,16 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } new OOMWarning( "loading data " - + (sourceType != null ? (sourceType == DataSourceType.PASTE ? "from clipboard." - : "using " + sourceType + " from " + file) + + (sourceType != null + ? (sourceType == DataSourceType.PASTE + ? "from clipboard." + : "using " + sourceType + " from " + + file) : ".") - + (format != null ? "(parsing as '" + format - + "' file)" : ""), oom, Desktop.desktop); + + (format != null + ? "(parsing as '" + format + "' file)" + : ""), + oom, Desktop.desktop); } } @@ -4751,7 +4847,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, final AlignViewportI peer = viewport.getCodingComplement(); if (peer != null) { - AlignFrame linkedAlignFrame = ((AlignViewport) peer).getAlignPanel().alignFrame; + AlignFrame linkedAlignFrame = ((AlignViewport) peer) + .getAlignPanel().alignFrame; if (linkedAlignFrame.tabbedPane.getTabCount() > index) { linkedAlignFrame.tabbedPane.setSelectedIndex(index); @@ -4768,12 +4865,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); } @@ -4866,30 +4963,31 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // here final JMenu rfetch = new JMenu( MessageManager.getString("action.fetch_db_references")); - rfetch.setToolTipText(MessageManager - .getString("label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences")); + rfetch.setToolTipText(MessageManager.getString( + "label.retrieve_parse_sequence_database_records_alignment_or_selected_sequences")); webService.add(rfetch); final JCheckBoxMenuItem trimrs = new JCheckBoxMenuItem( MessageManager.getString("option.trim_retrieved_seqs")); - trimrs.setToolTipText(MessageManager - .getString("label.trim_retrieved_sequences")); - trimrs.setSelected(Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true)); + trimrs.setToolTipText( + MessageManager.getString("label.trim_retrieved_sequences")); + trimrs.setSelected( + Cache.getDefault(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES, true)); trimrs.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { trimrs.setSelected(trimrs.isSelected()); - Cache.setProperty("TRIM_FETCHED_DATASET_SEQS", + Cache.setProperty(DBRefFetcher.TRIM_RETRIEVED_SEQUENCES, Boolean.valueOf(trimrs.isSelected()).toString()); }; }); rfetch.add(trimrs); JMenuItem fetchr = new JMenuItem( MessageManager.getString("label.standard_databases")); - fetchr.setToolTipText(MessageManager - .getString("label.fetch_embl_uniprot")); + fetchr.setToolTipText( + MessageManager.getString("label.fetch_embl_uniprot")); fetchr.addActionListener(new ActionListener() { @@ -4903,8 +5001,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { boolean isNucleotide = alignPanel.alignFrame.getViewport() .getAlignment().isNucleotide(); - DBRefFetcher dbRefFetcher = new DBRefFetcher(alignPanel.av - .getSequenceSelection(), alignPanel.alignFrame, null, + DBRefFetcher dbRefFetcher = new DBRefFetcher( + alignPanel.av.getSequenceSelection(), + alignPanel.alignFrame, null, alignPanel.alignFrame.featureSettings, isNucleotide); dbRefFetcher.addListener(new FetchFinishedListenerI() { @@ -4922,22 +5021,19 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, }); 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(); @@ -4954,12 +5050,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; @@ -5007,8 +5097,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, }); fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage( - "label.fetch_retrieve_from", - new Object[] { src.getDbName() }))); + "label.fetch_retrieve_from", new Object[] + { src.getDbName() }))); dfetch.add(fetchr); comp++; } @@ -5018,9 +5108,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, .toArray(new DbSourceProxy[0]); // fetch all entry DbSourceProxy src = otherdb.get(0); - fetchr = new JMenuItem(MessageManager.formatMessage( - "label.fetch_all_param", - new Object[] { src.getDbSource() })); + fetchr = new JMenuItem(MessageManager + .formatMessage("label.fetch_all_param", new Object[] + { src.getDbSource() })); fetchr.addActionListener(new ActionListener() { @Override @@ -5058,30 +5148,33 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, fetchr.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage( "label.fetch_retrieve_from_all_sources", - new Object[] { - Integer.valueOf(otherdb.size()) - .toString(), src.getDbSource(), - src.getDbName() }))); + new Object[] + { Integer.valueOf(otherdb.size()) + .toString(), + src.getDbSource(), src.getDbName() }))); dfetch.add(fetchr); comp++; // and then build the rest of the individual menus ifetch = new JMenu(MessageManager.formatMessage( - "label.source_from_db_source", - new Object[] { src.getDbSource() })); + "label.source_from_db_source", new Object[] + { src.getDbSource() })); icomp = 0; String imname = null; int i = 0; for (DbSourceProxy sproxy : otherdb) { String dbname = sproxy.getDbName(); - String sname = dbname.length() > 5 ? dbname.substring(0, - 5) + "..." : dbname; - String msname = dbname.length() > 10 ? dbname.substring( - 0, 10) + "..." : dbname; + String sname = dbname.length() > 5 + ? dbname.substring(0, 5) + "..." + : dbname; + String msname = dbname.length() > 10 + ? dbname.substring(0, 10) + "..." + : dbname; if (imname == null) { - imname = MessageManager.formatMessage( - "label.from_msname", new Object[] { sname }); + imname = MessageManager + .formatMessage("label.from_msname", new Object[] + { sname }); } fetchr = new JMenuItem(msname); final DbSourceProxy[] dassrc = { sproxy }; @@ -5120,8 +5213,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } }); - fetchr.setToolTipText("" - + MessageManager.formatMessage( + fetchr.setToolTipText( + "" + MessageManager.formatMessage( "label.fetch_retrieve_from", new Object[] { dbname })); ifetch.add(fetchr); @@ -5196,7 +5289,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void showUnconservedMenuItem_actionPerformed(ActionEvent e) { viewport.setShowUnconserved(showNonconservedMenuItem.getState()); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(false, false); } /* @@ -5285,7 +5378,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { PaintRefresher.Refresh(this, viewport.getSequenceSetId()); alignPanel.updateAnnotation(); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, true); } } @@ -5297,7 +5390,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, viewport.getAlignment().setSeqrep(null); PaintRefresher.Refresh(this, viewport.getSequenceSetId()); alignPanel.updateAnnotation(); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, true); } } @@ -5306,6 +5399,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { if (avc.createGroup()) { + if (applyAutoAnnotationSettings.isSelected()) + { + alignPanel.updateAnnotation(true, false); + } alignPanel.alignmentChanged(); } } @@ -5326,17 +5423,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, */ public void setDisplayedView(AlignmentPanel alignmentPanel) { - if (!viewport.getSequenceSetId().equals( - alignmentPanel.av.getSequenceSetId())) + if (!viewport.getSequenceSetId() + .equals(alignmentPanel.av.getSequenceSetId())) { - throw new Error( - MessageManager - .getString("error.implementation_error_cannot_show_view_alignment_frame")); + throw new Error(MessageManager.getString( + "error.implementation_error_cannot_show_view_alignment_frame")); } - if (tabbedPane != null - && tabbedPane.getTabCount() > 0 - && alignPanels.indexOf(alignmentPanel) != tabbedPane - .getSelectedIndex()) + if (tabbedPane != null && tabbedPane.getTabCount() > 0 && alignPanels + .indexOf(alignmentPanel) != tabbedPane.getSelectedIndex()) { tabbedPane.setSelectedIndex(alignPanels.indexOf(alignmentPanel)); } @@ -5390,7 +5484,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder()); this.alignPanel.av .setShowAutocalculatedAbove(isShowAutoCalculatedAbove()); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(false, false); } /** @@ -5399,7 +5493,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; } /** @@ -5415,7 +5511,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { return; } - List cdnaSeqs = new ArrayList(); + List cdnaSeqs = new ArrayList<>(); for (SequenceI aaSeq : alignment.getSequences()) { for (AlignedCodonFrame acf : mappings) @@ -5439,15 +5535,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // show a warning dialog no mapped cDNA return; } - AlignmentI cdna = new Alignment(cdnaSeqs.toArray(new SequenceI[cdnaSeqs - .size()])); + AlignmentI cdna = new Alignment( + cdnaSeqs.toArray(new SequenceI[cdnaSeqs.size()])); GAlignFrame alignFrame = new AlignFrame(cdna, AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); cdna.alignAs(alignment); String newtitle = "cDNA " + MessageManager.getString("label.for") + " " + this.title; - Desktop.addInternalFrame(alignFrame, newtitle, - AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); + Desktop.addInternalFrame(alignFrame, newtitle, AlignFrame.DEFAULT_WIDTH, + AlignFrame.DEFAULT_HEIGHT); } /** @@ -5480,8 +5576,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, al = dna.reverseCdna(complement); viewport.addAlignment(al, ""); addHistoryItem(new EditCommand( - MessageManager.getString("label.add_sequences"), - Action.PASTE, al.getSequencesArray(), 0, al.getWidth(), + MessageManager.getString("label.add_sequences"), Action.PASTE, + al.getSequencesArray(), 0, al.getWidth(), viewport.getAlignment())); } catch (Exception ex) { @@ -5508,12 +5604,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } catch (Exception ex) { System.err.println((ex.toString())); - JvOptionPane - .showInternalMessageDialog(Desktop.desktop, MessageManager - .getString("label.couldnt_run_groovy_script"), - MessageManager - .getString("label.groovy_support_failed"), - JvOptionPane.ERROR_MESSAGE); + JvOptionPane.showInternalMessageDialog(Desktop.desktop, + MessageManager.getString("label.couldnt_run_groovy_script"), + MessageManager.getString("label.groovy_support_failed"), + JvOptionPane.ERROR_MESSAGE); } } else @@ -5553,9 +5647,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { // include key modifier check in case user selects from menu avc.markHighlightedColumns( - (actionEvent.getModifiers() & ActionEvent.ALT_MASK) != 0, - true, - (actionEvent.getModifiers() & (ActionEvent.META_MASK | ActionEvent.CTRL_MASK)) != 0); + (actionEvent.getModifiers() & ActionEvent.ALT_MASK) != 0, true, + (actionEvent.getModifiers() & (ActionEvent.META_MASK + | ActionEvent.CTRL_MASK)) != 0); } /** @@ -5570,8 +5664,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, colourMenu.add(textColour); colourMenu.addSeparator(); - ColourMenuHelper.addMenuItems(colourMenu, this, - viewport.getAlignment(), false); + ColourMenuHelper.addMenuItems(colourMenu, this, viewport.getAlignment(), + false); colourMenu.addSeparator(); colourMenu.add(conservationMenuItem); @@ -5595,6 +5689,31 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, new CalculationChooser(AlignFrame.this); } } + + @Override + protected void loadVcf_actionPerformed() + { + 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.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); + + } + } class PrintThread extends Thread