X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignFrame.java;h=63620e5cceedbfc0fc45dc970116d26e90983178;hb=37de9310bec3501cbc6381e0c3dcb282fcaad812;hp=b0debf89e450084cf8fa36419ef063817c622fea;hpb=0f40a8334651302a74a223ecd3e583451302bb42;p=jalview.git diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index b0debf8..63620e5 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -32,7 +32,6 @@ import jalview.api.AlignViewControllerI; import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.api.FeatureSettingsControllerI; -import jalview.api.FeatureSettingsModelI; import jalview.api.SplitContainerI; import jalview.api.ViewStyleI; import jalview.api.analysis.ScoreModelI; @@ -54,7 +53,6 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentOrder; import jalview.datamodel.AlignmentView; import jalview.datamodel.ColumnSelection; -import jalview.datamodel.DBRefSource; import jalview.datamodel.HiddenSequences; import jalview.datamodel.PDBEntry; import jalview.datamodel.SeqCigar; @@ -74,7 +72,6 @@ import jalview.io.JalviewFileView; import jalview.io.JnetAnnotationMaker; import jalview.io.NewickFile; import jalview.io.TCoffeeScoreFile; -import jalview.io.gff.SequenceOntologyI; import jalview.jbgui.GAlignFrame; import jalview.schemes.Blosum62ColourScheme; import jalview.schemes.BuriedColourScheme; @@ -94,12 +91,10 @@ import jalview.schemes.TaylorColourScheme; import jalview.schemes.TurnColourScheme; import jalview.schemes.UserColourScheme; import jalview.schemes.ZappoColourScheme; -import jalview.structure.StructureSelectionManager; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; import jalview.ws.DBRefFetcher; import jalview.ws.DBRefFetcher.FetchFinishedListenerI; -import jalview.ws.SequenceFetcher; import jalview.ws.jws1.Discoverer; import jalview.ws.jws2.Jws2Discoverer; import jalview.ws.jws2.jabaws2.Jws2Instance; @@ -113,6 +108,7 @@ import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.Transferable; +import java.awt.dnd.DnDConstants; import java.awt.dnd.DropTargetDragEvent; import java.awt.dnd.DropTargetDropEvent; import java.awt.dnd.DropTargetEvent; @@ -849,8 +845,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, showGroupConservation.setEnabled(!nucleotide); rnahelicesColour.setEnabled(nucleotide); purinePyrimidineColour.setEnabled(nucleotide); - showComplementMenuItem.setText(MessageManager - .getString(nucleotide ? "label.protein" : "label.nucleotide")); + showComplementMenuItem.setText(nucleotide ? MessageManager + .getString("label.protein") : MessageManager + .getString("label.nucleotide")); setColourSelected(jalview.bin.Cache.getDefault( nucleotide ? Preferences.DEFAULT_COLOUR_NUC : Preferences.DEFAULT_COLOUR_PROT, "None")); @@ -2981,9 +2978,7 @@ 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.getColumnSelection() != null - && viewport.getColumnSelection().getSelected() != null && viewport - .getColumnSelection().getSelected().size() > 0) + if (viewport.hasSelectedColumns() || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg .getEndRes())) { @@ -3011,8 +3006,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, hideSelSequences_actionPerformed(null); hide = true; } - else if (!(toggleCols && viewport.getColumnSelection().getSelected() - .size() > 0)) + else if (!(toggleCols && viewport.hasSelectedColumns())) { showAllSeqs_actionPerformed(null); } @@ -3020,7 +3014,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (toggleCols) { - if (viewport.getColumnSelection().getSelected().size() > 0) + if (viewport.hasSelectedColumns()) { hideSelColumns_actionPerformed(null); if (!toggleSeqs) @@ -3219,30 +3213,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } /** - * Set or clear 'Show Sequence Features' - * - * @param evt - * DOCUMENT ME! - */ - @Override - public void showSeqFeaturesHeight_actionPerformed(ActionEvent evt) - { - viewport.setShowSequenceFeaturesHeight(showSeqFeaturesHeight - .isSelected()); - if (viewport.isShowSequenceFeaturesHeight()) - { - // ensure we're actually displaying features - viewport.setShowSequenceFeatures(true); - showSeqFeatures.setSelected(true); - } - alignPanel.paintAlignment(true); - if (alignPanel.getOverviewPanel() != null) - { - alignPanel.getOverviewPanel().updateOverviewImage(); - } - } - - /** * Action on toggle of the 'Show annotations' menu item. This shows or hides * the annotations panel as a whole. * @@ -3648,34 +3618,50 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void mousePressed(MouseEvent evt) { - if (evt.isPopupTrigger()) + if (evt.isPopupTrigger()) // Mac { - radioItem.removeActionListener(radioItem.getActionListeners()[0]); + offerRemoval(radioItem); + } + } - int option = JOptionPane.showInternalConfirmDialog( - jalview.gui.Desktop.desktop, - MessageManager - .getString("label.remove_from_default_list"), - MessageManager - .getString("label.remove_user_defined_colour"), - JOptionPane.YES_NO_OPTION); - if (option == JOptionPane.YES_OPTION) - { - jalview.gui.UserDefinedColours - .removeColourFromDefaults(radioItem.getText()); - colourMenu.remove(radioItem); - } - else + @Override + public void mouseReleased(MouseEvent evt) + { + if (evt.isPopupTrigger()) // Windows + { + offerRemoval(radioItem); + } + } + + /** + * @param radioItem + */ + void offerRemoval(final JRadioButtonMenuItem radioItem) + { + radioItem.removeActionListener(radioItem.getActionListeners()[0]); + + int option = JOptionPane.showInternalConfirmDialog( + jalview.gui.Desktop.desktop, MessageManager + .getString("label.remove_from_default_list"), + MessageManager + .getString("label.remove_user_defined_colour"), + JOptionPane.YES_NO_OPTION); + if (option == JOptionPane.YES_OPTION) + { + jalview.gui.UserDefinedColours + .removeColourFromDefaults(radioItem.getText()); + colourMenu.remove(radioItem); + } + else + { + radioItem.addActionListener(new ActionListener() { - radioItem.addActionListener(new ActionListener() + @Override + public void actionPerformed(ActionEvent evt) { - @Override - public void actionPerformed(ActionEvent evt) - { - userDefinedColour_actionPerformed(evt); - } - }); - } + userDefinedColour_actionPerformed(evt); + } + }); } } }); @@ -4467,22 +4453,18 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // object broker mechanism. final Vector wsmenu = new Vector(); final IProgressIndicator af = me; + + /* + * do not i18n these strings - they are hard-coded in class + * compbio.data.msa.Category, Jws2Discoverer.isRecalculable() and + * SequenceAnnotationWSClient.initSequenceAnnotationWSClient() + */ final JMenu msawsmenu = new JMenu("Alignment"); final JMenu secstrmenu = new JMenu( "Secondary Structure Prediction"); final JMenu seqsrchmenu = new JMenu("Sequence Database Search"); final JMenu analymenu = new JMenu("Analysis"); final JMenu dismenu = new JMenu("Protein Disorder"); - // final JMenu msawsmenu = new - // JMenu(MessageManager.getString("label.alignment")); - // final JMenu secstrmenu = new - // JMenu(MessageManager.getString("label.secondary_structure_prediction")); - // final JMenu seqsrchmenu = new - // JMenu(MessageManager.getString("label.sequence_database_search")); - // final JMenu analymenu = new - // JMenu(MessageManager.getString("label.analysis")); - // final JMenu dismenu = new - // JMenu(MessageManager.getString("label.protein_disorder")); // JAL-940 - only show secondary structure prediction services from // the legacy server if (// Cache.getDefault("SHOW_JWS1_SERVICES", true) @@ -4653,14 +4635,21 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { SequenceI[] seqs = viewport.getAlignment().getSequencesArray(); AlignmentI dataset = viewport.getAlignment().getDataset(); + + showProducts.removeAll(); + final boolean dna = viewport.getAlignment().isNucleotide(); + + if (seqs == null || seqs.length == 0) + { + // nothing to see here. + return false; + } + boolean showp = false; try { - showProducts.removeAll(); - final boolean dna = viewport.getAlignment().isNucleotide(); - List ptypes = (seqs == null || seqs.length == 0) ? null - : new CrossRef(seqs, dataset) - .findXrefSourcesForSequences(dna); + List ptypes = new CrossRef(seqs, dataset) + .findXrefSourcesForSequences(dna); for (final String source : ptypes) { @@ -4703,231 +4692,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void showProductsFor(final SequenceI[] sel, final boolean _odna, final String source) { - Runnable foo = new Runnable() - { - - @Override - public void run() - { - final long sttime = System.currentTimeMillis(); - AlignFrame.this.setProgressBar(MessageManager.formatMessage( - "status.searching_for_sequences_from", - new Object[] { source }), sttime); - try - { - AlignmentI alignment = AlignFrame.this.getViewport() - .getAlignment(); - AlignmentI dataset = alignment.getDataset() == null ? alignment - : alignment.getDataset(); - boolean dna = alignment.isNucleotide(); - if (_odna != dna) - { - System.err - .println("Conflict: showProducts for alignment originally " - + "thought to be " - + (_odna ? "DNA" : "Protein") - + " now searching for " - + (dna ? "DNA" : "Protein") + " Context."); - } - AlignmentI xrefs = new CrossRef(sel, dataset).findXrefSequences( - source, dna); - if (xrefs == null) - { - return; - } - /* - * get display scheme (if any) to apply to features - */ - FeatureSettingsModelI featureColourScheme = new SequenceFetcher() - .getFeatureColourScheme(source); - - AlignmentI xrefsAlignment = makeCrossReferencesAlignment(dataset, - xrefs); - if (!dna) - { - xrefsAlignment = AlignmentUtils.makeCdsAlignment( - xrefsAlignment.getSequencesArray(), dataset, sel); - xrefsAlignment.alignAs(alignment); - } - - /* - * If we are opening a splitframe, make a copy of this alignment (sharing the same dataset - * sequences). If we are DNA, drop introns and update mappings - */ - AlignmentI copyAlignment = null; - - if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true)) - { - boolean copyAlignmentIsAligned = false; - if (dna) - { - copyAlignment = AlignmentUtils.makeCdsAlignment(sel, dataset, - xrefsAlignment.getSequencesArray()); - if (copyAlignment.getHeight() == 0) - { - System.err.println("Failed to make CDS alignment"); - } - - /* - * pending getting Embl transcripts to 'align', - * we are only doing this for Ensembl - */ - // TODO proper criteria for 'can align as cdna' - if (DBRefSource.ENSEMBL.equalsIgnoreCase(source) - || AlignmentUtils.looksLikeEnsembl(alignment)) - { - copyAlignment.alignAs(alignment); - copyAlignmentIsAligned = true; - } - } - else - { - copyAlignment = AlignmentUtils.makeCopyAlignment(sel, - xrefs.getSequencesArray(), dataset); - } - copyAlignment.setGapCharacter(AlignFrame.this.viewport - .getGapCharacter()); - - StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(Desktop.instance); - - /* - * register any new mappings for sequence mouseover etc - * (will not duplicate any previously registered mappings) - */ - ssm.registerMappings(dataset.getCodonFrames()); - - if (copyAlignment.getHeight() <= 0) - { - System.err.println("No Sequences generated for xRef type " - + source); - return; - } - /* - * align protein to dna - */ - if (dna && copyAlignmentIsAligned) - { - xrefsAlignment.alignAs(copyAlignment); - } - else - { - /* - * align cdna to protein - currently only if - * fetching and aligning Ensembl transcripts! - */ - // TODO: generalise for other sources of locus/transcript/cds data - if (dna && DBRefSource.ENSEMBL.equalsIgnoreCase(source)) - { - copyAlignment.alignAs(xrefsAlignment); - } - } - } - /* - * build AlignFrame(s) according to available alignment data - */ - AlignFrame newFrame = new AlignFrame(xrefsAlignment, - DEFAULT_WIDTH, DEFAULT_HEIGHT); - if (Cache.getDefault("HIDE_INTRONS", true)) - { - newFrame.hideFeatureColumns(SequenceOntologyI.EXON, false); - } - String newtitle = String.format("%s %s %s", MessageManager - .getString(dna ? "label.proteins" : "label.nucleotides"), - MessageManager.getString("label.for"), getTitle()); - newFrame.setTitle(newtitle); - - if (copyAlignment == null) - { - /* - * split frame display is turned off in preferences file - */ - Desktop.addInternalFrame(newFrame, newtitle, DEFAULT_WIDTH, - DEFAULT_HEIGHT); - return; // via finally clause - } - AlignFrame copyThis = new AlignFrame(copyAlignment, - AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); - copyThis.setTitle(AlignFrame.this.getTitle()); - - boolean showSequenceFeatures = viewport.isShowSequenceFeatures(); - newFrame.setShowSeqFeatures(showSequenceFeatures); - copyThis.setShowSeqFeatures(showSequenceFeatures); - FeatureRenderer myFeatureStyling = alignPanel.getSeqPanel().seqCanvas - .getFeatureRenderer(); - - /* - * copy feature rendering settings to split frame - */ - newFrame.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer() - .transferSettings(myFeatureStyling); - copyThis.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer() - .transferSettings(myFeatureStyling); - - /* - * apply 'database source' feature configuration - * if any was found - */ - // TODO is this the feature colouring for the original - // alignment or the fetched xrefs? either could be Ensembl - newFrame.getViewport().applyFeaturesStyle(featureColourScheme); - copyThis.getViewport().applyFeaturesStyle(featureColourScheme); - - SplitFrame sf = new SplitFrame(dna ? copyThis : newFrame, - dna ? newFrame : copyThis); - newFrame.setVisible(true); - copyThis.setVisible(true); - String linkedTitle = MessageManager - .getString("label.linked_view_title"); - Desktop.addInternalFrame(sf, linkedTitle, -1, -1); - sf.adjustDivider(); - } catch (OutOfMemoryError e) - { - new OOMWarning("whilst fetching crossreferences", e); - } catch (Throwable e) - { - Cache.log.error("Error when finding crossreferences", e); - } finally - { - AlignFrame.this.setProgressBar(MessageManager.formatMessage( - "status.finished_searching_for_sequences_from", - new Object[] { source }), sttime); - } - } - - /** - * Makes an alignment containing the given sequences, and adds them to the - * given dataset, which is also set as the dataset for the new alignment - * - * TODO: refactor to DatasetI method - * - * @param dataset - * @param seqs - * @return - */ - protected AlignmentI makeCrossReferencesAlignment(AlignmentI dataset, - AlignmentI seqs) - { - SequenceI[] sprods = new SequenceI[seqs.getHeight()]; - for (int s = 0; s < sprods.length; s++) - { - sprods[s] = (seqs.getSequenceAt(s)).deriveSequence(); - if (dataset.getSequences() == null - || !dataset.getSequences().contains( - sprods[s].getDatasetSequence())) - { - dataset.addSequence(sprods[s].getDatasetSequence()); - } - sprods[s].updatePDBIds(); - } - Alignment al = new Alignment(sprods); - al.setDataset(dataset); - return al; - } - - }; - Thread frunner = new Thread(foo); - frunner.start(); + new Thread(CrossRefAction.showProductsFor(sel, _odna, source, this)) + .start(); } /** @@ -5049,6 +4815,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void drop(DropTargetDropEvent evt) { + // JAL-1552 - acceptDrop required before getTransferable call for + // Java's Transferable for native dnd + evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); Transferable t = evt.getTransferable(); java.util.List files = new ArrayList(), protocols = new ArrayList();