2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
22 * Jalview - A Sequence Alignment Editor and Viewer
23 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
25 * This program is free software; you can redistribute it and/or
26 * modify it under the terms of the GNU General Public License
27 * as published by the Free Software Foundation; either version 2
28 * of the License, or (at your option) any later version.
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public License
36 * along with this program; if not, write to the Free Software
37 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
41 import jalview.analysis.AlignmentUtils;
42 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
43 import jalview.analysis.NJTree;
44 import jalview.api.AlignViewportI;
45 import jalview.api.AlignmentViewPanel;
46 import jalview.api.FeatureColourI;
47 import jalview.api.FeatureSettingsModelI;
48 import jalview.api.FeaturesDisplayedI;
49 import jalview.api.ViewStyleI;
50 import jalview.bin.Cache;
51 import jalview.commands.CommandI;
52 import jalview.datamodel.AlignedCodonFrame;
53 import jalview.datamodel.Alignment;
54 import jalview.datamodel.AlignmentI;
55 import jalview.datamodel.ColumnSelection;
56 import jalview.datamodel.PDBEntry;
57 import jalview.datamodel.SearchResults;
58 import jalview.datamodel.Sequence;
59 import jalview.datamodel.SequenceGroup;
60 import jalview.datamodel.SequenceI;
61 import jalview.schemes.ColourSchemeProperty;
62 import jalview.schemes.UserColourScheme;
63 import jalview.structure.CommandListener;
64 import jalview.structure.SelectionSource;
65 import jalview.structure.StructureSelectionManager;
66 import jalview.structure.VamsasSource;
67 import jalview.util.MessageManager;
68 import jalview.viewmodel.AlignmentViewport;
69 import jalview.ws.params.AutoCalcSetting;
71 import java.awt.Container;
72 import java.awt.Dimension;
74 import java.awt.Rectangle;
75 import java.util.ArrayList;
76 import java.util.Hashtable;
77 import java.util.List;
78 import java.util.Vector;
80 import javax.swing.JInternalFrame;
81 import javax.swing.JOptionPane;
87 * @version $Revision: 1.141 $
89 public class AlignViewport extends AlignmentViewport implements
90 SelectionSource, CommandListener
94 NJTree currentTree = null;
96 boolean cursorMode = false;
98 boolean antiAlias = false;
100 private Rectangle explodedGeometry;
105 * Flag set true on the view that should 'gather' multiple views of the same
106 * sequence set id when a project is reloaded. Set false on all views when
107 * they are 'exploded' into separate windows. Set true on the current view
108 * when 'Gather' is performed, and also on the first tab when the first new
111 private boolean gatherViewsHere = false;
113 private AnnotationColumnChooser annotationColumnSelectionState;
116 * Creates a new AlignViewport object.
121 public AlignViewport(AlignmentI al)
128 * Create a new AlignViewport object with a specific sequence set ID
132 * (may be null - but potential for ambiguous constructor exception)
134 public AlignViewport(AlignmentI al, String seqsetid)
136 this(al, seqsetid, null);
139 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
141 sequenceSetID = seqsetid;
143 // TODO remove these once 2.4.VAMSAS release finished
144 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
146 Cache.log.debug("Setting viewport's sequence set id : "
149 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
151 Cache.log.debug("Setting viewport's view id : " + viewId);
158 * Create a new AlignViewport with hidden regions
162 * @param hiddenColumns
165 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
168 if (hiddenColumns != null)
170 colSel = hiddenColumns;
176 * New viewport with hidden columns and an existing sequence set id
179 * @param hiddenColumns
183 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
186 this(al, hiddenColumns, seqsetid, null);
190 * New viewport with hidden columns and an existing sequence set id and viewid
193 * @param hiddenColumns
199 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
200 String seqsetid, String viewid)
202 sequenceSetID = seqsetid;
204 // TODO remove these once 2.4.VAMSAS release finished
205 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
207 Cache.log.debug("Setting viewport's sequence set id : "
210 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
212 Cache.log.debug("Setting viewport's view id : " + viewId);
215 if (hiddenColumns != null)
217 colSel = hiddenColumns;
223 * Apply any settings saved in user preferences
225 private void applyViewProperties()
227 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
229 viewStyle.setShowJVSuffix(Cache.getDefault("SHOW_JVSUFFIX", true));
230 setShowAnnotation(Cache.getDefault("SHOW_ANNOTATIONS", true));
232 setRightAlignIds(Cache.getDefault("RIGHT_ALIGN_IDS", false));
233 setCentreColumnLabels(Cache.getDefault("CENTRE_COLUMN_LABELS", false));
234 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
236 setPadGaps(Cache.getDefault("PAD_GAPS", true));
237 setShowNPFeats(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
238 setShowDBRefs(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
239 viewStyle.setSeqNameItalics(Cache.getDefault("ID_ITALICS", true));
240 viewStyle.setWrapAlignment(Cache.getDefault("WRAP_ALIGNMENT", false));
241 viewStyle.setShowUnconserved(Cache
242 .getDefault("SHOW_UNCONSERVED", false));
243 sortByTree = Cache.getDefault("SORT_BY_TREE", false);
244 followSelection = Cache.getDefault("FOLLOW_SELECTIONS", true);
245 sortAnnotationsBy = SequenceAnnotationOrder.valueOf(Cache.getDefault(
246 Preferences.SORT_ANNOTATIONS,
247 SequenceAnnotationOrder.NONE.name()));
248 showAutocalculatedAbove = Cache.getDefault(
249 Preferences.SHOW_AUTOCALC_ABOVE, false);
250 viewStyle.setScaleProteinAsCdna(Cache.getDefault(
251 Preferences.SCALE_PROTEIN_TO_CDNA, true));
257 this.endRes = alignment.getWidth() - 1;
259 this.endSeq = alignment.getHeight() - 1;
260 applyViewProperties();
262 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
263 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
264 String fontSize = Cache.getDefault("FONT_SIZE", "10");
268 if (fontStyle.equals("bold"))
272 else if (fontStyle.equals("italic"))
277 setFont(new Font(fontName, style, Integer.parseInt(fontSize)), true);
280 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
282 // We must set conservation and consensus before setting colour,
283 // as Blosum and Clustal require this to be done
284 if (hconsensus == null && !isDataset)
286 if (!alignment.isNucleotide())
288 showConservation = Cache.getDefault("SHOW_CONSERVATION", true);
289 showQuality = Cache.getDefault("SHOW_QUALITY", true);
290 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
293 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
295 showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
296 normaliseSequenceLogo = Cache.getDefault("NORMALISE_CONSENSUS_LOGO",
298 showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
299 showConsensus = Cache.getDefault("SHOW_IDENTITY", true);
301 initAutoAnnotation();
302 String colourProperty = alignment.isNucleotide() ? Preferences.DEFAULT_COLOUR_NUC
303 : Preferences.DEFAULT_COLOUR_PROT;
304 String propertyValue = Cache.getProperty(colourProperty);
305 if (propertyValue == null)
307 // fall back on this property for backwards compatibility
308 propertyValue = Cache.getProperty(Preferences.DEFAULT_COLOUR);
310 if (propertyValue != null)
312 globalColourScheme = ColourSchemeProperty.getColour(alignment,
315 if (globalColourScheme instanceof UserColourScheme)
317 globalColourScheme = UserDefinedColours.loadDefaultColours();
318 ((UserColourScheme) globalColourScheme).setThreshold(0,
319 isIgnoreGapsConsensus());
322 if (globalColourScheme != null)
324 globalColourScheme.setConsensus(hconsensus);
330 * get the consensus sequence as displayed under the PID consensus annotation
333 * @return consensus sequence as a new sequence object
335 public SequenceI getConsensusSeq()
337 if (consensus == null)
339 updateConsensus(null);
341 if (consensus == null)
345 StringBuffer seqs = new StringBuffer();
346 for (int i = 0; i < consensus.annotations.length; i++)
348 if (consensus.annotations[i] != null)
350 if (consensus.annotations[i].description.charAt(0) == '[')
352 seqs.append(consensus.annotations[i].description.charAt(1));
356 seqs.append(consensus.annotations[i].displayCharacter);
361 SequenceI sq = new Sequence("Consensus", seqs.toString());
362 sq.setDescription("Percentage Identity Consensus "
363 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
367 boolean validCharWidth;
370 * update view settings with the given font. You may need to call
371 * alignPanel.fontChanged to update the layout geometry
374 * when true, charWidth/height is set according to font mentrics
376 public void setFont(Font f, boolean setGrid)
380 Container c = new Container();
382 java.awt.FontMetrics fm = c.getFontMetrics(font);
383 int w = viewStyle.getCharWidth(), ww = fm.charWidth('M'), h = viewStyle
387 setCharHeight(fm.getHeight());
390 viewStyle.setFontName(font.getName());
391 viewStyle.setFontStyle(font.getStyle());
392 viewStyle.setFontSize(font.getSize());
394 validCharWidth = true;
398 public void setViewStyle(ViewStyleI settingsForView)
400 super.setViewStyle(settingsForView);
401 setFont(new Font(viewStyle.getFontName(), viewStyle.getFontStyle(),
402 viewStyle.getFontSize()), false);
409 * @return DOCUMENT ME!
411 public Font getFont()
423 public void setAlignment(AlignmentI align)
425 replaceMappings(align);
426 super.setAlignment(align);
430 * Replace any codon mappings for this viewport with those for the given
435 public void replaceMappings(AlignmentI align)
439 * Deregister current mappings (if any)
441 deregisterMappings();
444 * Register new mappings (if any)
448 StructureSelectionManager ssm = StructureSelectionManager
449 .getStructureSelectionManager(Desktop.instance);
450 ssm.registerMappings(align.getCodonFrames());
454 * replace mappings on our alignment
456 if (alignment != null && align != null)
458 alignment.setCodonFrames(align.getCodonFrames());
462 protected void deregisterMappings()
464 AlignmentI al = getAlignment();
467 List<AlignedCodonFrame> mappings = al.getCodonFrames();
468 if (mappings != null)
470 StructureSelectionManager ssm = StructureSelectionManager
471 .getStructureSelectionManager(Desktop.instance);
472 for (AlignedCodonFrame acf : mappings)
474 if (noReferencesTo(acf))
476 ssm.deregisterMapping(acf);
486 * @return DOCUMENT ME!
489 public char getGapCharacter()
491 return getAlignment().getGapCharacter();
500 public void setGapCharacter(char gap)
502 if (getAlignment() != null)
504 getAlignment().setGapCharacter(gap);
514 public void setCurrentTree(NJTree tree)
522 * @return DOCUMENT ME!
524 public NJTree getCurrentTree()
530 * returns the visible column regions of the alignment
532 * @param selectedRegionOnly
533 * true to just return the contigs intersecting with the selected
537 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
539 int[] viscontigs = null;
540 int start = 0, end = 0;
541 if (selectedRegionOnly && selectionGroup != null)
543 start = selectionGroup.getStartRes();
544 end = selectionGroup.getEndRes() + 1;
548 end = alignment.getWidth();
550 viscontigs = colSel.getVisibleContigs(start, end);
555 * get hash of undo and redo list for the alignment
557 * @return long[] { historyList.hashCode, redoList.hashCode };
559 public long[] getUndoRedoHash()
562 if (historyList == null || redoList == null)
564 return new long[] { -1, -1 };
566 return new long[] { historyList.hashCode(), this.redoList.hashCode() };
570 * test if a particular set of hashcodes are different to the hashcodes for
571 * the undo and redo list.
574 * the stored set of hashcodes as returned by getUndoRedoHash
575 * @return true if the hashcodes differ (ie the alignment has been edited) or
576 * the stored hashcode array differs in size
578 public boolean isUndoRedoHashModified(long[] undoredo)
580 if (undoredo == null)
584 long[] cstate = getUndoRedoHash();
585 if (cstate.length != undoredo.length)
590 for (int i = 0; i < cstate.length; i++)
592 if (cstate[i] != undoredo[i])
600 public boolean followSelection = true;
603 * @return true if view selection should always follow the selections
604 * broadcast by other selection sources
606 public boolean getFollowSelection()
608 return followSelection;
612 * Send the current selection to be broadcast to any selection listeners.
615 public void sendSelection()
617 jalview.structure.StructureSelectionManager
618 .getStructureSelectionManager(Desktop.instance).sendSelection(
619 new SequenceGroup(getSelectionGroup()),
620 new ColumnSelection(getColumnSelection()), this);
624 * return the alignPanel containing the given viewport. Use this to get the
625 * components currently handling the given viewport.
628 * @return null or an alignPanel guaranteed to have non-null alignFrame
631 public AlignmentPanel getAlignPanel()
633 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this
634 .getSequenceSetId());
635 for (int p = 0; aps != null && p < aps.length; p++)
637 if (aps[p].av == this)
645 public boolean getSortByTree()
650 public void setSortByTree(boolean sort)
656 * Returns the (Desktop) instance of the StructureSelectionManager
659 public StructureSelectionManager getStructureSelectionManager()
661 return StructureSelectionManager
662 .getStructureSelectionManager(Desktop.instance);
668 * @return an array of SequenceI arrays, one for each PDBEntry, listing which
669 * sequences in the alignment hold a reference to it
671 public SequenceI[][] collateForPDB(PDBEntry[] pdbEntries)
673 List<SequenceI[]> seqvectors = new ArrayList<SequenceI[]>();
674 for (PDBEntry pdb : pdbEntries)
676 List<SequenceI> choosenSeqs = new ArrayList<SequenceI>();
677 for (SequenceI sq : alignment.getSequences())
679 Vector<PDBEntry> pdbRefEntries = sq.getDatasetSequence().getAllPDBEntries();
680 if (pdbRefEntries == null)
684 for (PDBEntry pdbRefEntry : pdbRefEntries)
686 if (pdbRefEntry.getId().equals(pdb.getId()))
688 if (pdbRefEntry.getChainCode() != null
689 && pdb.getChainCode() != null)
691 if (pdbRefEntry.getChainCode().equalsIgnoreCase(
693 && !choosenSeqs.contains(sq))
701 if (!choosenSeqs.contains(sq))
711 seqvectors.add(choosenSeqs.toArray(new SequenceI[choosenSeqs.size()]));
713 return seqvectors.toArray(new SequenceI[seqvectors.size()][]);
717 public boolean isNormaliseSequenceLogo()
719 return normaliseSequenceLogo;
722 public void setNormaliseSequenceLogo(boolean state)
724 normaliseSequenceLogo = state;
729 * @return true if alignment characters should be displayed
732 public boolean isValidCharWidth()
734 return validCharWidth;
737 private Hashtable<String, AutoCalcSetting> calcIdParams = new Hashtable<String, AutoCalcSetting>();
739 public AutoCalcSetting getCalcIdSettingsFor(String calcId)
741 return calcIdParams.get(calcId);
744 public void setCalcIdSettingsFor(String calcId, AutoCalcSetting settings,
747 calcIdParams.put(calcId, settings);
748 // TODO: create a restart list to trigger any calculations that need to be
749 // restarted after load
750 // calculator.getRegisteredWorkersOfClass(settings.getWorkerClass())
753 Cache.log.debug("trigger update for " + calcId);
758 * Method called when another alignment's edit (or possibly other) command is
761 * To allow for sequence mappings (e.g. protein to cDNA), we have to first
762 * 'unwind' the command on the source sequences (in simulation, not in fact),
763 * and then for each edit in turn:
765 * <li>compute the equivalent edit on the mapped sequences</li>
766 * <li>apply the mapped edit</li>
767 * <li>'apply' the source edit to the working copy of the source sequences</li>
775 public void mirrorCommand(CommandI command, boolean undo,
776 StructureSelectionManager ssm, VamsasSource source)
779 * Do nothing unless we are a 'complement' of the source. May replace this
780 * with direct calls not via SSM.
782 if (source instanceof AlignViewportI
783 && ((AlignViewportI) source).getCodingComplement() == this)
792 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
794 if (mappedCommand != null)
796 AlignmentI[] views = getAlignPanel().alignFrame.getViewAlignments();
797 mappedCommand.doCommand(views);
798 getAlignPanel().alignmentChanged();
803 * Add the sequences from the given alignment to this viewport. Optionally,
804 * may give the user the option to open a new frame, or split panel, with cDNA
805 * and protein linked.
810 public void addAlignment(AlignmentI toAdd, String title)
812 // TODO: promote to AlignViewportI? applet CutAndPasteTransfer is different
814 // JBPComment: title is a largely redundant parameter at the moment
815 // JBPComment: this really should be an 'insert/pre/append' controller
816 // JBPComment: but the DNA/Protein check makes it a bit more complex
818 // refactored from FileLoader / CutAndPasteTransfer / SequenceFetcher with
820 // TODO: create undo object for this JAL-1101
823 * Ensure datasets are created for the new alignment as
824 * mappings operate on dataset sequences
826 toAdd.setDataset(null);
829 * Check if any added sequence could be the object of a mapping or
830 * cross-reference; if so, make the mapping explicit
832 getAlignment().realiseMappings(toAdd.getSequences());
835 * If any cDNA/protein mappings exist or can be made between the alignments,
836 * offer to open a split frame with linked alignments
838 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
840 if (AlignmentUtils.isMappable(toAdd, getAlignment()))
842 if (openLinkedAlignment(toAdd, title))
850 * No mappings, or offer declined - add sequences to this alignment
852 // TODO: JAL-407 regardless of above - identical sequences (based on ID and
853 // provenance) should share the same dataset sequence
855 AlignmentI al = getAlignment();
856 String gap = String.valueOf(al.getGapCharacter());
857 for (int i = 0; i < toAdd.getHeight(); i++)
859 SequenceI seq = toAdd.getSequenceAt(i);
862 * - 'align' any mapped sequences as per existing
863 * e.g. cdna to genome, domain hit to protein sequence
864 * very experimental! (need a separate menu option for this)
865 * - only add mapped sequences ('select targets from a dataset')
867 if (true /*AlignmentUtils.alignSequenceAs(seq, al, gap, true, true)*/)
873 setEndSeq(getAlignment().getHeight());
874 firePropertyChange("alignment", null, getAlignment().getSequences());
878 * Show a dialog with the option to open and link (cDNA <-> protein) as a new
879 * alignment, either as a standalone alignment or in a split frame. Returns
880 * true if the new alignment was opened, false if not, because the user
881 * declined the offer.
886 protected boolean openLinkedAlignment(AlignmentI al, String title)
888 String[] options = new String[] {
889 MessageManager.getString("action.no"),
890 MessageManager.getString("label.split_window"),
891 MessageManager.getString("label.new_window"), };
892 final String question = JvSwingUtils.wrapTooltip(true,
893 MessageManager.getString("label.open_split_window?"));
894 int response = JOptionPane.showOptionDialog(Desktop.desktop, question,
895 MessageManager.getString("label.open_split_window"),
896 JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null,
897 options, options[0]);
899 if (response != 1 && response != 2)
903 final boolean openSplitPane = (response == 1);
904 final boolean openInNewWindow = (response == 2);
907 * Identify protein and dna alignments. Make a copy of this one if opening
908 * in a new split pane.
910 AlignmentI thisAlignment = openSplitPane ? new Alignment(getAlignment())
912 AlignmentI protein = al.isNucleotide() ? thisAlignment : al;
913 final AlignmentI cdna = al.isNucleotide() ? al : thisAlignment;
916 * Map sequences. At least one should get mapped as we have already passed
917 * the test for 'mappability'. Any mappings made will be added to the
918 * protein alignment. Note creating dataset sequences on the new alignment
919 * is a pre-requisite for building mappings.
922 AlignmentUtils.mapProteinAlignmentToCdna(protein, cdna);
925 * Create the AlignFrame for the added alignment. If it is protein, mappings
926 * are registered with StructureSelectionManager as a side-effect.
928 AlignFrame newAlignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
929 AlignFrame.DEFAULT_HEIGHT);
930 newAlignFrame.setTitle(title);
931 newAlignFrame.statusBar.setText(MessageManager.formatMessage(
932 "label.successfully_loaded_file", new Object[] { title }));
934 // TODO if we want this (e.g. to enable reload of the alignment from file),
935 // we will need to add parameters to the stack.
936 // if (!protocol.equals(AppletFormatAdapter.PASTE))
938 // alignFrame.setFileName(file, format);
943 Desktop.addInternalFrame(newAlignFrame, title,
944 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
949 newAlignFrame.setMaximum(jalview.bin.Cache.getDefault(
950 "SHOW_FULLSCREEN", false));
951 } catch (java.beans.PropertyVetoException ex)
957 al.alignAs(thisAlignment);
958 protein = openSplitFrame(newAlignFrame, thisAlignment);
965 * Helper method to open a new SplitFrame holding linked dna and protein
968 * @param newAlignFrame
969 * containing a new alignment to be shown
971 * cdna/protein complement alignment to show in the other split half
972 * @return the protein alignment in the split frame
974 protected AlignmentI openSplitFrame(AlignFrame newAlignFrame,
975 AlignmentI complement)
978 * Make a new frame with a copy of the alignment we are adding to. If this
979 * is protein, the mappings to cDNA will be registered with
980 * StructureSelectionManager as a side-effect.
982 AlignFrame copyMe = new AlignFrame(complement,
983 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
984 copyMe.setTitle(getAlignPanel().alignFrame.getTitle());
986 AlignmentI al = newAlignFrame.viewport.getAlignment();
987 final AlignFrame proteinFrame = al.isNucleotide() ? copyMe
989 final AlignFrame cdnaFrame = al.isNucleotide() ? newAlignFrame : copyMe;
990 cdnaFrame.setVisible(true);
991 proteinFrame.setVisible(true);
992 String linkedTitle = MessageManager
993 .getString("label.linked_view_title");
996 * Open in split pane. DNA sequence above, protein below.
998 JInternalFrame splitFrame = new SplitFrame(cdnaFrame, proteinFrame);
999 Desktop.addInternalFrame(splitFrame, linkedTitle, -1, -1);
1001 return proteinFrame.viewport.getAlignment();
1004 public AnnotationColumnChooser getAnnotationColumnSelectionState()
1006 return annotationColumnSelectionState;
1009 public void setAnnotationColumnSelectionState(
1010 AnnotationColumnChooser currentAnnotationColumnSelectionState)
1012 this.annotationColumnSelectionState = currentAnnotationColumnSelectionState;
1016 public void setIdWidth(int i)
1018 super.setIdWidth(i);
1019 AlignmentPanel ap = getAlignPanel();
1022 // modify GUI elements to reflect geometry change
1023 Dimension idw = getAlignPanel().getIdPanel().getIdCanvas()
1024 .getPreferredSize();
1026 getAlignPanel().getIdPanel().getIdCanvas().setPreferredSize(idw);
1030 public Rectangle getExplodedGeometry()
1032 return explodedGeometry;
1035 public void setExplodedGeometry(Rectangle explodedPosition)
1037 this.explodedGeometry = explodedPosition;
1040 public boolean isGatherViewsHere()
1042 return gatherViewsHere;
1045 public void setGatherViewsHere(boolean gatherViewsHere)
1047 this.gatherViewsHere = gatherViewsHere;
1051 * If this viewport has a (Protein/cDNA) complement, then scroll the
1052 * complementary alignment to match this one.
1054 public void scrollComplementaryAlignment()
1057 * Populate a SearchResults object with the mapped location to scroll to. If
1058 * there is no complement, or it is not following highlights, or no mapping
1059 * is found, the result will be empty.
1061 SearchResults sr = new SearchResults();
1062 int verticalOffset = findComplementScrollTarget(sr);
1065 // TODO would like next line without cast but needs more refactoring...
1066 final AlignmentPanel complementPanel = ((AlignViewport) getCodingComplement())
1068 complementPanel.setDontScrollComplement(true);
1069 complementPanel.scrollToCentre(sr, verticalOffset);
1074 * Answers true if no alignment holds a reference to the given mapping
1079 protected boolean noReferencesTo(AlignedCodonFrame acf)
1081 AlignFrame[] frames = Desktop.getAlignFrames();
1086 for (AlignFrame af : frames)
1090 for (AlignmentViewPanel ap : af.getAlignPanels())
1092 AlignmentI al = ap.getAlignment();
1093 if (al != null && al.getCodonFrames().contains(acf))
1104 * Applies the supplied feature settings descriptor to currently known
1105 * features. This supports an 'initial configuration' of feature colouring
1106 * based on a preset or user favourite. This may then be modified in the usual
1107 * way using the Feature Settings dialogue.
1109 * @param featureSettings
1112 public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
1114 if (featureSettings == null)
1119 FeatureRenderer fr = getAlignPanel().getSeqPanel().seqCanvas
1120 .getFeatureRenderer();
1121 fr.findAllFeatures(true);
1122 List<String> renderOrder = fr.getRenderOrder();
1123 FeaturesDisplayedI displayed = fr.getFeaturesDisplayed();
1125 // TODO this clears displayed.featuresRegistered - do we care?
1128 * set feature colour if specified by feature settings
1129 * set visibility of all features
1131 for (String type : renderOrder)
1133 FeatureColourI preferredColour = featureSettings
1134 .getFeatureColour(type);
1135 if (preferredColour != null)
1137 fr.setColour(type, preferredColour);
1139 if (featureSettings.isFeatureDisplayed(type))
1141 displayed.setVisible(type);
1146 * set visibility of feature groups
1148 for (String group : fr.getFeatureGroups())
1150 fr.setGroupVisibility(group, featureSettings.isGroupDisplayed(group));
1154 * order the features
1156 if (featureSettings.optimiseOrder())
1158 // TODO not supported (yet?)
1162 fr.orderFeatures(featureSettings);
1164 fr.setTransparency(featureSettings.getTransparency());