Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.gui

File AlignViewport.java

 

Coverage histogram

../../img/srcFileCovDistChart6.png
35% of files have more coverage

Code metrics

102
248
49
1
1,057
642
116
0.47
5.06
49
2.37

Classes

Class Line # Actions
AlignViewport 72 248 116 166
0.583959958.4%
 

Contributing tests

This file is covered by 120 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.gui;
22   
23    import jalview.analysis.AlignmentUtils;
24    import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
25    import jalview.api.AlignViewportI;
26    import jalview.api.AlignmentViewPanel;
27    import jalview.api.FeatureColourI;
28    import jalview.api.FeatureSettingsModelI;
29    import jalview.api.FeaturesDisplayedI;
30    import jalview.api.ViewStyleI;
31    import jalview.bin.Cache;
32    import jalview.commands.CommandI;
33    import jalview.datamodel.AlignedCodonFrame;
34    import jalview.datamodel.Alignment;
35    import jalview.datamodel.AlignmentI;
36    import jalview.datamodel.ColumnSelection;
37    import jalview.datamodel.HiddenColumns;
38    import jalview.datamodel.SearchResults;
39    import jalview.datamodel.SearchResultsI;
40    import jalview.datamodel.SequenceGroup;
41    import jalview.datamodel.SequenceI;
42    import jalview.renderer.ResidueShader;
43    import jalview.schemes.ColourSchemeI;
44    import jalview.schemes.ColourSchemeProperty;
45    import jalview.schemes.ResidueColourScheme;
46    import jalview.schemes.UserColourScheme;
47    import jalview.structure.SelectionSource;
48    import jalview.structure.StructureSelectionManager;
49    import jalview.structure.VamsasSource;
50    import jalview.util.MessageManager;
51    import jalview.util.dialogrunner.RunResponse;
52    import jalview.viewmodel.AlignmentViewport;
53    import jalview.ws.params.AutoCalcSetting;
54   
55    import java.awt.Container;
56    import java.awt.Dimension;
57    import java.awt.Font;
58    import java.awt.FontMetrics;
59    import java.awt.Rectangle;
60    import java.util.Hashtable;
61    import java.util.Iterator;
62    import java.util.List;
63   
64    import javax.swing.JInternalFrame;
65   
66    /**
67    * DOCUMENT ME!
68    *
69    * @author $author$
70    * @version $Revision: 1.141 $
71    */
 
72    public class AlignViewport extends AlignmentViewport
73    implements SelectionSource
74    {
75    Font font;
76   
77    boolean cursorMode = false;
78   
79    boolean antiAlias = false;
80   
81    private Rectangle explodedGeometry;
82   
83    String viewName;
84   
85    /*
86    * Flag set true on the view that should 'gather' multiple views of the same
87    * sequence set id when a project is reloaded. Set false on all views when
88    * they are 'exploded' into separate windows. Set true on the current view
89    * when 'Gather' is performed, and also on the first tab when the first new
90    * view is created.
91    */
92    private boolean gatherViewsHere = false;
93   
94    private AnnotationColumnChooser annotationColumnSelectionState;
95   
96    /**
97    * Creates a new AlignViewport object.
98    *
99    * @param al
100    * alignment to view
101    */
 
102  33 toggle public AlignViewport(AlignmentI al)
103    {
104  33 super(al);
105  33 init();
106    }
107   
108    /**
109    * Create a new AlignViewport object with a specific sequence set ID
110    *
111    * @param al
112    * @param seqsetid
113    * (may be null - but potential for ambiguous constructor exception)
114    */
 
115  0 toggle public AlignViewport(AlignmentI al, String seqsetid)
116    {
117  0 this(al, seqsetid, null);
118    }
119   
 
120  0 toggle public AlignViewport(AlignmentI al, String seqsetid, String viewid)
121    {
122  0 super(al);
123  0 sequenceSetID = seqsetid;
124  0 viewId = viewid;
125    // TODO remove these once 2.4.VAMSAS release finished
126  0 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
127    {
128  0 Cache.log.debug(
129    "Setting viewport's sequence set id : " + sequenceSetID);
130    }
131  0 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
132    {
133  0 Cache.log.debug("Setting viewport's view id : " + viewId);
134    }
135  0 init();
136   
137    }
138   
139    /**
140    * Create a new AlignViewport with hidden regions
141    *
142    * @param al
143    * AlignmentI
144    * @param hiddenColumns
145    * ColumnSelection
146    */
 
147  25 toggle public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns)
148    {
149  25 super(al);
150  25 if (hiddenColumns != null)
151    {
152  25 al.setHiddenColumns(hiddenColumns);
153    }
154  25 init();
155    }
156   
157    /**
158    * New viewport with hidden columns and an existing sequence set id
159    *
160    * @param al
161    * @param hiddenColumns
162    * @param seqsetid
163    * (may be null)
164    */
 
165  0 toggle public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns,
166    String seqsetid)
167    {
168  0 this(al, hiddenColumns, seqsetid, null);
169    }
170   
171    /**
172    * New viewport with hidden columns and an existing sequence set id and viewid
173    *
174    * @param al
175    * @param hiddenColumns
176    * @param seqsetid
177    * (may be null)
178    * @param viewid
179    * (may be null)
180    */
 
181  186 toggle public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns,
182    String seqsetid, String viewid)
183    {
184  186 super(al);
185  186 sequenceSetID = seqsetid;
186  186 viewId = viewid;
187    // TODO remove these once 2.4.VAMSAS release finished
188  186 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
189    {
190  0 Cache.log.debug(
191    "Setting viewport's sequence set id : " + sequenceSetID);
192    }
193  186 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
194    {
195  0 Cache.log.debug("Setting viewport's view id : " + viewId);
196    }
197   
198  186 if (hiddenColumns != null)
199    {
200  0 al.setHiddenColumns(hiddenColumns);
201    }
202  186 init();
203    }
204   
205    /**
206    * Apply any settings saved in user preferences
207    */
 
208  244 toggle private void applyViewProperties()
209    {
210  244 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
211   
212  244 viewStyle.setShowJVSuffix(Cache.getDefault("SHOW_JVSUFFIX", true));
213  244 setShowAnnotation(Cache.getDefault("SHOW_ANNOTATIONS", true));
214   
215  244 setRightAlignIds(Cache.getDefault("RIGHT_ALIGN_IDS", false));
216  244 setCentreColumnLabels(Cache.getDefault("CENTRE_COLUMN_LABELS", false));
217  244 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
218   
219  244 setPadGaps(Cache.getDefault("PAD_GAPS", true));
220  244 setShowNPFeats(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
221  244 setShowDBRefs(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
222  244 viewStyle.setSeqNameItalics(Cache.getDefault("ID_ITALICS", true));
223  244 viewStyle.setWrapAlignment(Cache.getDefault("WRAP_ALIGNMENT", false));
224  244 viewStyle.setShowUnconserved(
225    Cache.getDefault("SHOW_UNCONSERVED", false));
226  244 sortByTree = Cache.getDefault("SORT_BY_TREE", false);
227  244 followSelection = Cache.getDefault("FOLLOW_SELECTIONS", true);
228  244 sortAnnotationsBy = SequenceAnnotationOrder
229    .valueOf(Cache.getDefault(Preferences.SORT_ANNOTATIONS,
230    SequenceAnnotationOrder.NONE.name()));
231  244 showAutocalculatedAbove = Cache
232    .getDefault(Preferences.SHOW_AUTOCALC_ABOVE, false);
233  244 viewStyle.setScaleProteinAsCdna(
234    Cache.getDefault(Preferences.SCALE_PROTEIN_TO_CDNA, true));
235    }
236   
 
237  244 toggle void init()
238    {
239  244 applyViewProperties();
240   
241  244 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
242  244 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
243  244 String fontSize = Cache.getDefault("FONT_SIZE", "10");
244   
245  244 int style = 0;
246   
247  244 if (fontStyle.equals("bold"))
248    {
249  0 style = 1;
250    }
251  244 else if (fontStyle.equals("italic"))
252    {
253  0 style = 2;
254    }
255   
256  244 setFont(new Font(fontName, style, Integer.parseInt(fontSize)), true);
257   
258  244 alignment
259    .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
260   
261    // We must set conservation and consensus before setting colour,
262    // as Blosum and Clustal require this to be done
263  244 if (hconsensus == null && !isDataset)
264    {
265  244 if (!alignment.isNucleotide())
266    {
267  206 showConservation = Cache.getDefault("SHOW_CONSERVATION", true);
268  206 showQuality = Cache.getDefault("SHOW_QUALITY", true);
269  206 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
270    false);
271    }
272  244 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
273    true);
274  244 showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
275  244 normaliseSequenceLogo = Cache.getDefault("NORMALISE_CONSENSUS_LOGO",
276    false);
277  244 showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
278  244 showConsensus = Cache.getDefault("SHOW_IDENTITY", true);
279   
280  244 showOccupancy = Cache.getDefault(Preferences.SHOW_OCCUPANCY, true);
281    }
282  244 initAutoAnnotation();
283  244 String colourProperty = alignment.isNucleotide()
284    ? Preferences.DEFAULT_COLOUR_NUC
285    : Preferences.DEFAULT_COLOUR_PROT;
286  244 String schemeName = Cache.getProperty(colourProperty);
287  244 if (schemeName == null)
288    {
289    // only DEFAULT_COLOUR available in Jalview before 2.9
290  236 schemeName = Cache.getDefault(Preferences.DEFAULT_COLOUR,
291    ResidueColourScheme.NONE);
292    }
293  244 ColourSchemeI colourScheme = ColourSchemeProperty
294    .getColourScheme(alignment, schemeName);
295  244 residueShading = new ResidueShader(colourScheme);
296   
297  244 if (colourScheme instanceof UserColourScheme)
298    {
299  0 residueShading = new ResidueShader(
300    UserDefinedColours.loadDefaultColours());
301  0 residueShading.setThreshold(0, isIgnoreGapsConsensus());
302    }
303   
304  244 if (residueShading != null)
305    {
306  244 residueShading.setConsensus(hconsensus);
307    }
308    }
309   
310    boolean validCharWidth;
311   
312    /**
313    * {@inheritDoc}
314    */
 
315  392 toggle @Override
316    public void setFont(Font f, boolean setGrid)
317    {
318  392 font = f;
319   
320  392 Container c = new Container();
321   
322  392 if (setGrid)
323    {
324  319 FontMetrics fm = c.getFontMetrics(font);
325  319 int ww = fm.charWidth('M');
326  319 setCharHeight(fm.getHeight());
327  319 setCharWidth(ww);
328    }
329  392 viewStyle.setFontName(font.getName());
330  392 viewStyle.setFontStyle(font.getStyle());
331  392 viewStyle.setFontSize(font.getSize());
332   
333  392 validCharWidth = true;
334    }
335   
 
336  73 toggle @Override
337    public void setViewStyle(ViewStyleI settingsForView)
338    {
339  73 super.setViewStyle(settingsForView);
340  73 setFont(new Font(viewStyle.getFontName(), viewStyle.getFontStyle(),
341    viewStyle.getFontSize()), false);
342    }
343   
344    /**
345    * DOCUMENT ME!
346    *
347    * @return DOCUMENT ME!
348    */
 
349  8864 toggle public Font getFont()
350    {
351  8864 return font;
352    }
353   
354    /**
355    * DOCUMENT ME!
356    *
357    * @param align
358    * DOCUMENT ME!
359    */
 
360  335 toggle @Override
361    public void setAlignment(AlignmentI align)
362    {
363  335 replaceMappings(align);
364  335 super.setAlignment(align);
365    }
366   
367    /**
368    * Replace any codon mappings for this viewport with those for the given
369    * viewport
370    *
371    * @param align
372    */
 
373  338 toggle public void replaceMappings(AlignmentI align)
374    {
375   
376    /*
377    * Deregister current mappings (if any)
378    */
379  338 deregisterMappings();
380   
381    /*
382    * Register new mappings (if any)
383    */
384  338 if (align != null)
385    {
386  247 StructureSelectionManager ssm = StructureSelectionManager
387    .getStructureSelectionManager(Desktop.instance);
388  247 ssm.registerMappings(align.getCodonFrames());
389    }
390   
391    /*
392    * replace mappings on our alignment
393    */
394  338 if (alignment != null && align != null)
395    {
396  3 alignment.setCodonFrames(align.getCodonFrames());
397    }
398    }
399   
 
400  338 toggle protected void deregisterMappings()
401    {
402  338 AlignmentI al = getAlignment();
403  338 if (al != null)
404    {
405  94 List<AlignedCodonFrame> mappings = al.getCodonFrames();
406  94 if (mappings != null)
407    {
408  94 StructureSelectionManager ssm = StructureSelectionManager
409    .getStructureSelectionManager(Desktop.instance);
410  94 for (AlignedCodonFrame acf : mappings)
411    {
412  6 if (noReferencesTo(acf))
413    {
414  3 ssm.deregisterMapping(acf);
415    }
416    }
417    }
418    }
419    }
420   
421    /**
422    * DOCUMENT ME!
423    *
424    * @return DOCUMENT ME!
425    */
 
426  29 toggle @Override
427    public char getGapCharacter()
428    {
429  29 return getAlignment().getGapCharacter();
430    }
431   
432    /**
433    * DOCUMENT ME!
434    *
435    * @param gap
436    * DOCUMENT ME!
437    */
 
438  0 toggle public void setGapCharacter(char gap)
439    {
440  0 if (getAlignment() != null)
441    {
442  0 getAlignment().setGapCharacter(gap);
443    }
444    }
445   
446    /**
447    * returns the visible column regions of the alignment
448    *
449    * @param selectedRegionOnly
450    * true to just return the contigs intersecting with the selected
451    * area
452    * @return
453    */
 
454  0 toggle public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
455    {
456  0 int start = 0;
457  0 int end = 0;
458  0 if (selectedRegionOnly && selectionGroup != null)
459    {
460  0 start = selectionGroup.getStartRes();
461  0 end = selectionGroup.getEndRes() + 1;
462    }
463    else
464    {
465  0 end = alignment.getWidth();
466    }
467  0 return (alignment.getHiddenColumns().getVisContigsIterator(start, end,
468    false));
469    }
470   
471    /**
472    * get hash of undo and redo list for the alignment
473    *
474    * @return long[] { historyList.hashCode, redoList.hashCode };
475    */
 
476  1 toggle public long[] getUndoRedoHash()
477    {
478    // TODO: JAL-1126
479  1 if (historyList == null || redoList == null)
480    {
481  0 return new long[] { -1, -1 };
482    }
483  1 return new long[] { historyList.hashCode(), this.redoList.hashCode() };
484    }
485   
486    /**
487    * test if a particular set of hashcodes are different to the hashcodes for
488    * the undo and redo list.
489    *
490    * @param undoredo
491    * the stored set of hashcodes as returned by getUndoRedoHash
492    * @return true if the hashcodes differ (ie the alignment has been edited) or
493    * the stored hashcode array differs in size
494    */
 
495  0 toggle public boolean isUndoRedoHashModified(long[] undoredo)
496    {
497  0 if (undoredo == null)
498    {
499  0 return true;
500    }
501  0 long[] cstate = getUndoRedoHash();
502  0 if (cstate.length != undoredo.length)
503    {
504  0 return true;
505    }
506   
507  0 for (int i = 0; i < cstate.length; i++)
508    {
509  0 if (cstate[i] != undoredo[i])
510    {
511  0 return true;
512    }
513    }
514  0 return false;
515    }
516   
517    public boolean followSelection = true;
518   
519    /**
520    * @return true if view selection should always follow the selections
521    * broadcast by other selection sources
522    */
 
523  0 toggle public boolean getFollowSelection()
524    {
525  0 return followSelection;
526    }
527   
528    /**
529    * Send the current selection to be broadcast to any selection listeners.
530    */
 
531  13 toggle @Override
532    public void sendSelection()
533    {
534  13 jalview.structure.StructureSelectionManager
535    .getStructureSelectionManager(Desktop.instance)
536    .sendSelection(new SequenceGroup(getSelectionGroup()),
537    new ColumnSelection(getColumnSelection()),
538    new HiddenColumns(getAlignment().getHiddenColumns()),
539    this);
540    }
541   
542    /**
543    * return the alignPanel containing the given viewport. Use this to get the
544    * components currently handling the given viewport.
545    *
546    * @param av
547    * @return null or an alignPanel guaranteed to have non-null alignFrame
548    * reference
549    */
 
550  247 toggle public AlignmentPanel getAlignPanel()
551    {
552  247 AlignmentPanel[] aps = PaintRefresher
553    .getAssociatedPanels(this.getSequenceSetId());
554  453 for (int p = 0; aps != null && p < aps.length; p++)
555    {
556  265 if (aps[p].av == this)
557    {
558  59 return aps[p];
559    }
560    }
561  188 return null;
562    }
563   
 
564  12 toggle public boolean getSortByTree()
565    {
566  12 return sortByTree;
567    }
568   
 
569  0 toggle public void setSortByTree(boolean sort)
570    {
571  0 sortByTree = sort;
572    }
573   
574    /**
575    * Returns the (Desktop) instance of the StructureSelectionManager
576    */
 
577  1659 toggle @Override
578    public StructureSelectionManager getStructureSelectionManager()
579    {
580  1659 return StructureSelectionManager
581    .getStructureSelectionManager(Desktop.instance);
582    }
583   
 
584  1435 toggle @Override
585    public boolean isNormaliseSequenceLogo()
586    {
587  1435 return normaliseSequenceLogo;
588    }
589   
 
590  22 toggle public void setNormaliseSequenceLogo(boolean state)
591    {
592  22 normaliseSequenceLogo = state;
593    }
594   
595    /**
596    *
597    * @return true if alignment characters should be displayed
598    */
 
599  33007 toggle @Override
600    public boolean isValidCharWidth()
601    {
602  33007 return validCharWidth;
603    }
604   
605    private Hashtable<String, AutoCalcSetting> calcIdParams = new Hashtable<>();
606   
 
607  3 toggle public AutoCalcSetting getCalcIdSettingsFor(String calcId)
608    {
609  3 return calcIdParams.get(calcId);
610    }
611   
 
612  0 toggle public void setCalcIdSettingsFor(String calcId, AutoCalcSetting settings,
613    boolean needsUpdate)
614    {
615  0 calcIdParams.put(calcId, settings);
616    // TODO: create a restart list to trigger any calculations that need to be
617    // restarted after load
618    // calculator.getRegisteredWorkersOfClass(settings.getWorkerClass())
619  0 if (needsUpdate)
620    {
621  0 Cache.log.debug("trigger update for " + calcId);
622    }
623    }
624   
625    /**
626    * Method called when another alignment's edit (or possibly other) command is
627    * broadcast to here.
628    *
629    * To allow for sequence mappings (e.g. protein to cDNA), we have to first
630    * 'unwind' the command on the source sequences (in simulation, not in fact),
631    * and then for each edit in turn:
632    * <ul>
633    * <li>compute the equivalent edit on the mapped sequences</li>
634    * <li>apply the mapped edit</li>
635    * <li>'apply' the source edit to the working copy of the source
636    * sequences</li>
637    * </ul>
638    *
639    * @param command
640    * @param undo
641    * @param ssm
642    */
 
643  0 toggle @Override
644    public void mirrorCommand(CommandI command, boolean undo,
645    StructureSelectionManager ssm, VamsasSource source)
646    {
647    /*
648    * Do nothing unless we are a 'complement' of the source. May replace this
649    * with direct calls not via SSM.
650    */
651  0 if (source instanceof AlignViewportI
652    && ((AlignViewportI) source).getCodingComplement() == this)
653    {
654    // ok to continue;
655    }
656    else
657    {
658  0 return;
659    }
660   
661  0 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
662    getGapCharacter());
663  0 if (mappedCommand != null)
664    {
665  0 AlignmentI[] views = getAlignPanel().alignFrame.getViewAlignments();
666  0 mappedCommand.doCommand(views);
667  0 getAlignPanel().alignmentChanged();
668    }
669    }
670   
671    /**
672    * Add the sequences from the given alignment to this viewport. Optionally,
673    * may give the user the option to open a new frame, or split panel, with cDNA
674    * and protein linked.
675    *
676    * @param toAdd
677    * @param title
678    */
 
679  1 toggle public void addAlignment(AlignmentI toAdd, String title)
680    {
681    // TODO: promote to AlignViewportI? applet CutAndPasteTransfer is different
682   
683    // JBPComment: title is a largely redundant parameter at the moment
684    // JBPComment: this really should be an 'insert/pre/append' controller
685    // JBPComment: but the DNA/Protein check makes it a bit more complex
686   
687    // refactored from FileLoader / CutAndPasteTransfer / SequenceFetcher with
688    // this comment:
689    // TODO: create undo object for this JAL-1101
690   
691    /*
692    * Ensure datasets are created for the new alignment as
693    * mappings operate on dataset sequences
694    */
695  1 toAdd.setDataset(null);
696   
697    /*
698    * Check if any added sequence could be the object of a mapping or
699    * cross-reference; if so, make the mapping explicit
700    */
701  1 getAlignment().realiseMappings(toAdd.getSequences());
702   
703    /*
704    * If any cDNA/protein mappings exist or can be made between the alignments,
705    * offer to open a split frame with linked alignments
706    */
707  1 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
708    {
709  1 if (AlignmentUtils.isMappable(toAdd, getAlignment()))
710    {
711  0 openLinkedAlignment(toAdd, title);
712  0 return;
713    }
714    }
715  1 alignmentDataAdded(toAdd);
716    }
717   
 
718  1 toggle private void alignmentDataAdded(AlignmentI toAdd)
719    {
720    /*
721    * No mappings, or offer declined - add sequences to this alignment
722    */
723    // TODO: JAL-407 regardless of above - identical sequences (based on ID and
724    // provenance) should share the same dataset sequence
725   
726  1 AlignmentI al = getAlignment();
727  1 String gap = String.valueOf(al.getGapCharacter());
728  5 for (int i = 0; i < toAdd.getHeight(); i++)
729    {
730  4 SequenceI seq = toAdd.getSequenceAt(i);
731    /*
732    * experimental!
733    * - 'align' any mapped sequences as per existing
734    * e.g. cdna to genome, domain hit to protein sequence
735    * very experimental! (need a separate menu option for this)
736    * - only add mapped sequences ('select targets from a dataset')
737    */
738  4 if (true /*AlignmentUtils.alignSequenceAs(seq, al, gap, true, true)*/)
739    {
740  4 al.addSequence(seq);
741    }
742    }
743   
744  1 ranges.setEndSeq(getAlignment().getHeight());
745  1 firePropertyChange("alignment", null, getAlignment().getSequences());
746    }
747   
748    /**
749    * Show a dialog with the option to open and link (cDNA <-> protein) as a new
750    * alignment, either as a standalone alignment or in a split frame. Returns
751    * true if the new alignment was opened, false if not, because the user
752    * declined the offer.
753    *
754    * @param al
755    * @param title
756    */
 
757  0 toggle protected void openLinkedAlignment(AlignmentI al, String title)
758    {
759  0 String[] options = new String[] { MessageManager.getString("action.no"),
760    MessageManager.getString("label.split_window"),
761    MessageManager.getString("label.new_window"), };
762  0 final String question = JvSwingUtils.wrapTooltip(true,
763    MessageManager.getString("label.open_split_window?"));
764  0 final AlignViewport us = this;
765  0 JvOptionPane.newOptionDialog(Desktop.desktop)
766    .response(new RunResponse(1)
767    {
 
768  0 toggle @Override
769    public void run()
770    {
771  0 us.openLinkedAlignmentAs(al, title, true);
772    }
773    }).response(new RunResponse(2)
774    {
 
775  0 toggle @Override
776    public void run()
777    {
778  0 us.openLinkedAlignmentAs(al, title, false);
779    }
780    }).defaultResponse(new Runnable()
781    {
 
782  0 toggle @Override
783    public void run()
784    {
785  0 alignmentDataAdded(al);
786    }
787    }).showDialog(question,
788    MessageManager.getString("label.open_split_window"),
789    JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
790    options, options[0]);
791    }
792   
 
793  0 toggle protected void openLinkedAlignmentAs(AlignmentI al, String title,
794    boolean newWindowOrSplitPane)
795    {
796    /*
797    * Identify protein and dna alignments. Make a copy of this one if opening
798    * in a new split pane.
799    */
800  0 AlignmentI thisAlignment = newWindowOrSplitPane
801    ? new Alignment(getAlignment())
802    : getAlignment();
803  0 AlignmentI protein = al.isNucleotide() ? thisAlignment : al;
804  0 final AlignmentI cdna = al.isNucleotide() ? al : thisAlignment;
805   
806    /*
807    * Map sequences. At least one should get mapped as we have already passed
808    * the test for 'mappability'. Any mappings made will be added to the
809    * protein alignment. Note creating dataset sequences on the new alignment
810    * is a pre-requisite for building mappings.
811    */
812  0 al.setDataset(null);
813  0 AlignmentUtils.mapProteinAlignmentToCdna(protein, cdna);
814   
815    /*
816    * Create the AlignFrame for the added alignment. If it is protein, mappings
817    * are registered with StructureSelectionManager as a side-effect.
818    */
819  0 AlignFrame newAlignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
820    AlignFrame.DEFAULT_HEIGHT);
821  0 newAlignFrame.setTitle(title);
822  0 newAlignFrame.setStatus(MessageManager
823    .formatMessage("label.successfully_loaded_file", new Object[]
824    { title }));
825   
826    // TODO if we want this (e.g. to enable reload of the alignment from file),
827    // we will need to add parameters to the stack.
828    // if (!protocol.equals(DataSourceType.PASTE))
829    // {
830    // alignFrame.setFileName(file, format);
831    // }
832   
833  0 if (!newWindowOrSplitPane)
834    {
835  0 Desktop.addInternalFrame(newAlignFrame, title,
836    AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
837    }
838   
839  0 try
840    {
841  0 newAlignFrame.setMaximum(
842    jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false));
843    } catch (java.beans.PropertyVetoException ex)
844    {
845    }
846   
847  0 if (newWindowOrSplitPane)
848    {
849  0 al.alignAs(thisAlignment);
850  0 protein = openSplitFrame(newAlignFrame, thisAlignment);
851    }
852    }
853   
854    /**
855    * Helper method to open a new SplitFrame holding linked dna and protein
856    * alignments.
857    *
858    * @param newAlignFrame
859    * containing a new alignment to be shown
860    * @param complement
861    * cdna/protein complement alignment to show in the other split half
862    * @return the protein alignment in the split frame
863    */
 
864  0 toggle protected AlignmentI openSplitFrame(AlignFrame newAlignFrame,
865    AlignmentI complement)
866    {
867    /*
868    * Make a new frame with a copy of the alignment we are adding to. If this
869    * is protein, the mappings to cDNA will be registered with
870    * StructureSelectionManager as a side-effect.
871    */
872  0 AlignFrame copyMe = new AlignFrame(complement, AlignFrame.DEFAULT_WIDTH,
873    AlignFrame.DEFAULT_HEIGHT);
874  0 copyMe.setTitle(getAlignPanel().alignFrame.getTitle());
875   
876  0 AlignmentI al = newAlignFrame.viewport.getAlignment();
877  0 final AlignFrame proteinFrame = al.isNucleotide() ? copyMe
878    : newAlignFrame;
879  0 final AlignFrame cdnaFrame = al.isNucleotide() ? newAlignFrame : copyMe;
880  0 cdnaFrame.setVisible(true);
881  0 proteinFrame.setVisible(true);
882  0 String linkedTitle = MessageManager
883    .getString("label.linked_view_title");
884   
885    /*
886    * Open in split pane. DNA sequence above, protein below.
887    */
888  0 JInternalFrame splitFrame = new SplitFrame(cdnaFrame, proteinFrame);
889  0 Desktop.addInternalFrame(splitFrame, linkedTitle, -1, -1);
890   
891  0 return proteinFrame.viewport.getAlignment();
892    }
893   
 
894  7 toggle public AnnotationColumnChooser getAnnotationColumnSelectionState()
895    {
896  7 return annotationColumnSelectionState;
897    }
898   
 
899  1 toggle public void setAnnotationColumnSelectionState(
900    AnnotationColumnChooser currentAnnotationColumnSelectionState)
901    {
902  1 this.annotationColumnSelectionState = currentAnnotationColumnSelectionState;
903    }
904   
 
905  188 toggle @Override
906    public void setIdWidth(int i)
907    {
908  188 super.setIdWidth(i);
909  188 AlignmentPanel ap = getAlignPanel();
910  188 if (ap != null)
911    {
912    // modify GUI elements to reflect geometry change
913  0 Dimension idw = getAlignPanel().getIdPanel().getIdCanvas()
914    .getPreferredSize();
915  0 idw.width = i;
916  0 getAlignPanel().getIdPanel().getIdCanvas().setPreferredSize(idw);
917    }
918    }
919   
 
920  27 toggle public Rectangle getExplodedGeometry()
921    {
922  27 return explodedGeometry;
923    }
924   
 
925  57 toggle public void setExplodedGeometry(Rectangle explodedPosition)
926    {
927  57 this.explodedGeometry = explodedPosition;
928    }
929   
 
930  91 toggle public boolean isGatherViewsHere()
931    {
932  91 return gatherViewsHere;
933    }
934   
 
935  140 toggle public void setGatherViewsHere(boolean gatherViewsHere)
936    {
937  140 this.gatherViewsHere = gatherViewsHere;
938    }
939   
940    /**
941    * If this viewport has a (Protein/cDNA) complement, then scroll the
942    * complementary alignment to match this one.
943    */
 
944  451 toggle public void scrollComplementaryAlignment()
945    {
946    /*
947    * Populate a SearchResults object with the mapped location to scroll to. If
948    * there is no complement, or it is not following highlights, or no mapping
949    * is found, the result will be empty.
950    */
951  451 SearchResultsI sr = new SearchResults();
952  451 int verticalOffset = findComplementScrollTarget(sr);
953  451 if (!sr.isEmpty())
954    {
955    // TODO would like next line without cast but needs more refactoring...
956  0 final AlignmentPanel complementPanel = ((AlignViewport) getCodingComplement())
957    .getAlignPanel();
958  0 complementPanel.setToScrollComplementPanel(false);
959  0 complementPanel.scrollToCentre(sr, verticalOffset);
960  0 complementPanel.setToScrollComplementPanel(true);
961    }
962    }
963   
964    /**
965    * Answers true if no alignment holds a reference to the given mapping
966    *
967    * @param acf
968    * @return
969    */
 
970  6 toggle protected boolean noReferencesTo(AlignedCodonFrame acf)
971    {
972  6 AlignFrame[] frames = Desktop.getAlignFrames();
973  6 if (frames == null)
974    {
975  0 return true;
976    }
977  6 for (AlignFrame af : frames)
978    {
979  12 if (!af.isClosed())
980    {
981  12 for (AlignmentViewPanel ap : af.getAlignPanels())
982    {
983  12 AlignmentI al = ap.getAlignment();
984  12 if (al != null && al.getCodonFrames().contains(acf))
985    {
986  3 return false;
987    }
988    }
989    }
990    }
991  3 return true;
992    }
993   
994    /**
995    * Applies the supplied feature settings descriptor to currently known
996    * features. This supports an 'initial configuration' of feature colouring
997    * based on a preset or user favourite. This may then be modified in the usual
998    * way using the Feature Settings dialogue.
999    *
1000    * @param featureSettings
1001    */
 
1002  10 toggle @Override
1003    public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
1004    {
1005  10 if (featureSettings == null)
1006    {
1007  0 return;
1008    }
1009   
1010  10 FeatureRenderer fr = getAlignPanel().getSeqPanel().seqCanvas
1011    .getFeatureRenderer();
1012  10 fr.findAllFeatures(true);
1013  10 List<String> renderOrder = fr.getRenderOrder();
1014  10 FeaturesDisplayedI displayed = fr.getFeaturesDisplayed();
1015  10 displayed.clear();
1016    // TODO this clears displayed.featuresRegistered - do we care?
1017   
1018    /*
1019    * set feature colour if specified by feature settings
1020    * set visibility of all features
1021    */
1022  10 for (String type : renderOrder)
1023    {
1024  10 FeatureColourI preferredColour = featureSettings
1025    .getFeatureColour(type);
1026  10 if (preferredColour != null)
1027    {
1028  0 fr.setColour(type, preferredColour);
1029    }
1030  10 if (featureSettings.isFeatureDisplayed(type))
1031    {
1032  10 displayed.setVisible(type);
1033    }
1034    }
1035   
1036    /*
1037    * set visibility of feature groups
1038    */
1039  10 for (String group : fr.getFeatureGroups())
1040    {
1041  10 fr.setGroupVisibility(group, featureSettings.isGroupDisplayed(group));
1042    }
1043   
1044    /*
1045    * order the features
1046    */
1047  10 if (featureSettings.optimiseOrder())
1048    {
1049    // TODO not supported (yet?)
1050    }
1051    else
1052    {
1053  10 fr.orderFeatures(featureSettings);
1054    }
1055  10 fr.setTransparency(featureSettings.getTransparency());
1056    }
1057    }