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.
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.bin.Console;
33 import jalview.commands.CommandI;
34 import jalview.datamodel.AlignedCodonFrame;
35 import jalview.datamodel.Alignment;
36 import jalview.datamodel.AlignmentI;
37 import jalview.datamodel.ColumnSelection;
38 import jalview.datamodel.HiddenColumns;
39 import jalview.datamodel.SearchResults;
40 import jalview.datamodel.SearchResultsI;
41 import jalview.datamodel.SequenceGroup;
42 import jalview.datamodel.SequenceI;
43 import jalview.datamodel.features.FeatureMatcherSetI;
44 import jalview.renderer.ResidueShader;
45 import jalview.schemes.ColourSchemeI;
46 import jalview.schemes.ColourSchemeProperty;
47 import jalview.schemes.ResidueColourScheme;
48 import jalview.schemes.UserColourScheme;
49 import jalview.structure.SelectionSource;
50 import jalview.structure.StructureSelectionManager;
51 import jalview.structure.VamsasSource;
52 import jalview.util.ColorUtils;
53 import jalview.util.MessageManager;
54 import jalview.viewmodel.AlignmentViewport;
55 import jalview.ws.params.AutoCalcSetting;
57 import java.awt.Container;
58 import java.awt.Dimension;
60 import java.awt.FontMetrics;
61 import java.awt.Rectangle;
62 import java.util.ArrayList;
63 import java.util.Hashtable;
64 import java.util.Iterator;
65 import java.util.List;
67 import javax.swing.JInternalFrame;
73 * @version $Revision: 1.141 $
75 public class AlignViewport extends AlignmentViewport
76 implements SelectionSource
78 public final static int NO_SPLIT = 0;
80 public final static int SPLIT_FRAME = 1;
82 public final static int NEW_WINDOW = 2;
85 boolean cursorMode = false;
87 boolean antiAlias = false;
89 private Rectangle explodedGeometry = null;
91 private String viewName = null;
94 * Flag set true on the view that should 'gather' multiple views of the same
95 * sequence set id when a project is reloaded. Set false on all views when
96 * they are 'exploded' into separate windows. Set true on the current view
97 * when 'Gather' is performed, and also on the first tab when the first new
100 private boolean gatherViewsHere = false;
102 private AnnotationColumnChooser annotationColumnSelectionState;
105 * Creates a new AlignViewport object.
110 public AlignViewport(AlignmentI al)
117 * Create a new AlignViewport object with a specific sequence set ID
121 * (may be null - but potential for ambiguous constructor exception)
123 public AlignViewport(AlignmentI al, String seqsetid)
125 this(al, seqsetid, null);
128 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
131 sequenceSetID = seqsetid;
133 // TODO remove these once 2.4.VAMSAS release finished
134 if (seqsetid != null)
137 "Setting viewport's sequence set id : " + sequenceSetID);
141 Console.debug("Setting viewport's view id : " + viewId);
148 * Create a new AlignViewport with hidden regions
152 * @param hiddenColumns
155 public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns)
158 if (hiddenColumns != null)
160 al.setHiddenColumns(hiddenColumns);
166 * New viewport with hidden columns and an existing sequence set id
169 * @param hiddenColumns
173 public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns,
176 this(al, hiddenColumns, seqsetid, null);
180 * New viewport with hidden columns and an existing sequence set id and viewid
183 * @param hiddenColumns
189 public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns,
190 String seqsetid, String viewid)
193 sequenceSetID = seqsetid;
195 // TODO remove these once 2.4.VAMSAS release finished
196 if (seqsetid != null)
199 "Setting viewport's sequence set id : " + sequenceSetID);
203 Console.debug("Setting viewport's view id : " + viewId);
206 if (hiddenColumns != null)
208 al.setHiddenColumns(hiddenColumns);
214 * Apply any settings saved in user preferences
216 private void applyViewProperties()
218 antiAlias = Cache.getDefault("ANTI_ALIAS", true);
220 viewStyle.setShowJVSuffix(Cache.getDefault("SHOW_JVSUFFIX", true));
221 setShowAnnotation(Cache.getDefault("SHOW_ANNOTATIONS", true));
223 setRightAlignIds(Cache.getDefault("RIGHT_ALIGN_IDS", false));
224 setCentreColumnLabels(Cache.getDefault("CENTRE_COLUMN_LABELS", false));
225 autoCalculateConsensusAndConservation = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
227 setPadGaps(Cache.getDefault("PAD_GAPS", true));
228 setShowNPFeats(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
229 setShowDBRefs(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
230 viewStyle.setSeqNameItalics(Cache.getDefault("ID_ITALICS", true));
231 viewStyle.setWrapAlignment(Cache.getDefault("WRAP_ALIGNMENT", false));
232 viewStyle.setShowUnconserved(
233 Cache.getDefault("SHOW_UNCONSERVED", false));
234 sortByTree = Cache.getDefault("SORT_BY_TREE", false);
235 followSelection = Cache.getDefault("FOLLOW_SELECTIONS", true);
236 sortAnnotationsBy = SequenceAnnotationOrder
237 .valueOf(Cache.getDefault(Preferences.SORT_ANNOTATIONS,
238 SequenceAnnotationOrder.NONE.name()));
239 showAutocalculatedAbove = Cache
240 .getDefault(Preferences.SHOW_AUTOCALC_ABOVE, false);
241 viewStyle.setScaleProteinAsCdna(
242 Cache.getDefault(Preferences.SCALE_PROTEIN_TO_CDNA, true));
247 applyViewProperties();
249 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
250 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
251 String fontSize = Cache.getDefault("FONT_SIZE", "10");
255 if (fontStyle.equals("bold"))
259 else if (fontStyle.equals("italic"))
264 setFont(new Font(fontName, style, Integer.parseInt(fontSize)), true);
266 alignment.setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
268 // We must set conservation and consensus before setting colour,
269 // as Blosum and Clustal require this to be done
270 if (hconsensus == null && !isDataset)
272 if (!alignment.isNucleotide())
274 showConservation = Cache.getDefault("SHOW_CONSERVATION", true);
275 showQuality = Cache.getDefault("SHOW_QUALITY", true);
276 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
279 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
281 showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
282 normaliseSequenceLogo = Cache.getDefault("NORMALISE_CONSENSUS_LOGO",
284 // for now, use consensus options for Information till it gets its own
285 setShowHMMSequenceLogo(showSequenceLogo);
286 setNormaliseHMMSequenceLogo(normaliseSequenceLogo);
287 setShowInformationHistogram(showConsensusHistogram);
288 showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
289 showConsensus = Cache.getDefault("SHOW_IDENTITY", true);
291 showOccupancy = Cache.getDefault(Preferences.SHOW_OCCUPANCY, true);
293 initAutoAnnotation();
294 // initInformation();
296 String colourProperty = alignment.isNucleotide()
297 ? Preferences.DEFAULT_COLOUR_NUC
298 : Preferences.DEFAULT_COLOUR_PROT;
299 String schemeName = Cache.getProperty(colourProperty);
300 if (schemeName == null)
302 // only DEFAULT_COLOUR available in Jalview before 2.9
303 schemeName = Cache.getDefault(Preferences.DEFAULT_COLOUR,
304 ResidueColourScheme.NONE);
306 ColourSchemeI colourScheme = ColourSchemeProperty.getColourScheme(this,
307 alignment, schemeName);
308 residueShading = new ResidueShader(colourScheme);
310 if (colourScheme instanceof UserColourScheme)
312 residueShading = new ResidueShader(
313 UserDefinedColours.loadDefaultColours());
314 residueShading.setThreshold(0, isIgnoreGapsConsensus());
317 if (residueShading != null)
319 residueShading.setConsensus(hconsensus);
321 setColourAppliesToAllGroups(true);
325 boolean validCharWidth;
331 public void setFont(Font f, boolean setGrid)
335 Container c = new Container();
339 FontMetrics fm = c.getFontMetrics(font);
340 int ww = fm.charWidth('M');
341 setCharHeight(fm.getHeight());
344 viewStyle.setFontName(font.getName());
345 viewStyle.setFontStyle(font.getStyle());
346 viewStyle.setFontSize(font.getSize());
348 validCharWidth = true;
352 public void setViewStyle(ViewStyleI settingsForView)
354 super.setViewStyle(settingsForView);
355 setFont(new Font(viewStyle.getFontName(), viewStyle.getFontStyle(),
356 viewStyle.getFontSize()), false);
362 * @return DOCUMENT ME!
364 public Font getFont()
376 public void setAlignment(AlignmentI align)
378 replaceMappings(align);
379 super.setAlignment(align);
383 * Replace any codon mappings for this viewport with those for the given
388 public void replaceMappings(AlignmentI align)
392 * Deregister current mappings (if any)
394 deregisterMappings();
397 * Register new mappings (if any)
401 StructureSelectionManager ssm = StructureSelectionManager
402 .getStructureSelectionManager(Desktop.getInstance());
403 ssm.registerMappings(align.getCodonFrames());
407 * replace mappings on our alignment
409 if (alignment != null && align != null)
411 alignment.setCodonFrames(align.getCodonFrames());
415 protected void deregisterMappings()
417 AlignmentI al = getAlignment();
420 List<AlignedCodonFrame> mappings = al.getCodonFrames();
421 if (mappings != null)
423 StructureSelectionManager ssm = StructureSelectionManager
424 .getStructureSelectionManager(Desktop.getInstance());
425 for (AlignedCodonFrame acf : mappings)
427 if (noReferencesTo(acf))
429 ssm.deregisterMapping(acf);
439 * @return DOCUMENT ME!
442 public char getGapCharacter()
444 return getAlignment().getGapCharacter();
453 public void setGapCharacter(char gap)
455 if (getAlignment() != null)
457 getAlignment().setGapCharacter(gap);
462 * get hash of undo and redo list for the alignment
464 * @return long[] { historyList.hashCode, redoList.hashCode };
466 public long[] getUndoRedoHash()
469 if (historyList == null || redoList == null)
471 return new long[] { -1, -1 };
473 return new long[] { historyList.hashCode(), this.redoList.hashCode() };
477 * test if a particular set of hashcodes are different to the hashcodes for
478 * the undo and redo list.
481 * the stored set of hashcodes as returned by getUndoRedoHash
482 * @return true if the hashcodes differ (ie the alignment has been edited) or
483 * the stored hashcode array differs in size
485 public boolean isUndoRedoHashModified(long[] undoredo)
487 if (undoredo == null)
491 long[] cstate = getUndoRedoHash();
492 if (cstate.length != undoredo.length)
497 for (int i = 0; i < cstate.length; i++)
499 if (cstate[i] != undoredo[i])
507 public boolean followSelection = true;
510 * @return true if view selection should always follow the selections
511 * broadcast by other selection sources
513 public boolean getFollowSelection()
515 return followSelection;
519 * Send the current selection to be broadcast to any selection listeners.
522 public void sendSelection()
524 jalview.structure.StructureSelectionManager
525 .getStructureSelectionManager(Desktop.getInstance())
526 .sendSelection(new SequenceGroup(getSelectionGroup()),
527 new ColumnSelection(getColumnSelection()),
528 new HiddenColumns(getAlignment().getHiddenColumns()),
533 * return the alignPanel containing the given viewport. Use this to get the
534 * components currently handling the given viewport.
537 * @return null or an alignPanel guaranteed to have non-null alignFrame
540 public AlignmentPanel getAlignPanel()
542 AlignmentPanel[] aps = PaintRefresher
543 .getAssociatedPanels(this.getSequenceSetId());
544 for (int p = 0; aps != null && p < aps.length; p++)
546 if (aps[p].av == this)
554 public boolean getSortByTree()
559 public void setSortByTree(boolean sort)
565 * Returns the (Desktop) instance of the StructureSelectionManager
568 public StructureSelectionManager getStructureSelectionManager()
570 return StructureSelectionManager
571 .getStructureSelectionManager(Desktop.getInstance());
576 public boolean isNormaliseSequenceLogo()
578 return normaliseSequenceLogo;
582 public void setNormaliseSequenceLogo(boolean state)
584 normaliseSequenceLogo = state;
589 * @return true if alignment characters should be displayed
592 public boolean isValidCharWidth()
594 return validCharWidth;
598 private Hashtable<String, AutoCalcSetting> calcIdParams = new Hashtable<>();
600 public AutoCalcSetting getCalcIdSettingsFor(String calcId)
602 return calcIdParams.get(calcId);
605 public void setCalcIdSettingsFor(String calcId, AutoCalcSetting settings,
608 calcIdParams.put(calcId, settings);
609 // TODO: create a restart list to trigger any calculations that need to be
610 // restarted after load
611 // calculator.getRegisteredWorkersOfClass(settings.getWorkerClass())
614 Console.debug("trigger update for " + calcId);
619 * Method called when another alignment's edit (or possibly other) command is
622 * To allow for sequence mappings (e.g. protein to cDNA), we have to first
623 * 'unwind' the command on the source sequences (in simulation, not in fact),
624 * and then for each edit in turn:
626 * <li>compute the equivalent edit on the mapped sequences</li>
627 * <li>apply the mapped edit</li>
628 * <li>'apply' the source edit to the working copy of the source
637 public void mirrorCommand(CommandI command, boolean undo,
638 StructureSelectionManager ssm, VamsasSource source)
641 * Do nothing unless we are a 'complement' of the source. May replace this
642 * with direct calls not via SSM.
644 if (source instanceof AlignViewportI
645 && ((AlignViewportI) source).getCodingComplement() == this)
654 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
656 if (mappedCommand != null)
658 AlignmentI[] views = getAlignPanel().alignFrame.getViewAlignments();
659 mappedCommand.doCommand(views);
660 getAlignPanel().alignmentChanged();
665 * Add the sequences from the given alignment to this viewport. Optionally,
666 * may give the user the option to open a new frame, or split panel, with cDNA
667 * and protein linked.
672 public void addAlignment(AlignmentI toAdd, String title)
674 // TODO: promote to AlignViewportI? applet CutAndPasteTransfer is different
676 // JBPComment: title is a largely redundant parameter at the moment
677 // JBPComment: this really should be an 'insert/pre/append' controller
678 // JBPComment: but the DNA/Protein check makes it a bit more complex
680 // refactored from FileLoader / CutAndPasteTransfer / SequenceFetcher with
682 // TODO: create undo object for this JAL-1101
685 * Ensure datasets are created for the new alignment as
686 * mappings operate on dataset sequences
688 toAdd.setDataset(null);
691 * Check if any added sequence could be the object of a mapping or
692 * cross-reference; if so, make the mapping explicit
694 getAlignment().realiseMappings(toAdd.getSequences());
697 * If any cDNA/protein mappings exist or can be made between the alignments,
698 * offer to open a split frame with linked alignments
700 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
702 if (AlignmentUtils.isMappable(toAdd, getAlignment()))
704 openLinkedAlignment(toAdd, title);
708 addDataToAlignment(toAdd);
712 * adds sequences to this alignment
716 void addDataToAlignment(AlignmentI toAdd)
718 // TODO: JAL-407 regardless of above - identical sequences (based on ID and
719 // provenance) should share the same dataset sequence
721 AlignmentI al = getAlignment();
722 String gap = String.valueOf(al.getGapCharacter());
723 for (int i = 0; i < toAdd.getHeight(); i++)
725 SequenceI seq = toAdd.getSequenceAt(i);
728 * - 'align' any mapped sequences as per existing
729 * e.g. cdna to genome, domain hit to protein sequence
730 * very experimental! (need a separate menu option for this)
731 * - only add mapped sequences ('select targets from a dataset')
733 if (true /*AlignmentUtils.alignSequenceAs(seq, al, gap, true, true)*/)
739 ranges.setEndSeq(getAlignment().getHeight() - 1); // BH 2019.04.18
744 * Show a dialog with the option to open and link (cDNA <-> protein) as a new
745 * alignment, either as a standalone alignment or in a split frame. Returns
746 * true if the new alignment was opened, false if not, because the user
747 * declined the offer.
752 protected void openLinkedAlignment(AlignmentI al, String title)
754 String[] options = new String[] { MessageManager.getString("action.no"),
755 MessageManager.getString("label.split_window"),
756 MessageManager.getString("label.new_window"), };
757 final String question = JvSwingUtils.wrapTooltip(true,
758 MessageManager.getString("label.open_split_window?"));
759 final AlignViewport us = this;
762 * options No, Split Window, New Window correspond to
763 * dialog responses 0, 1, 2 (even though JOptionPane shows them
766 JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.getDesktopPane())
767 .setResponseHandler(NO_SPLIT, new Runnable()
772 addDataToAlignment(al);
774 }).setResponseHandler(SPLIT_FRAME, new Runnable()
779 // Make a copy of this one to open it in a splitframe
780 openLinkedAlignmentAs(getAlignPanel().alignFrame,
781 new Alignment(getAlignment()), al, title,
784 }).setResponseHandler(NEW_WINDOW, new Runnable()
789 openLinkedAlignmentAs(null, getAlignment(), al, title,
793 dialog.showDialog(question,
794 MessageManager.getString("label.open_split_window"),
795 JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
796 options, options[0]);
800 * Open a split frame or a new window
805 * SPLIT_FRAME or NEW_WINDOW
807 public static void openLinkedAlignmentAs(AlignFrame thisFrame,
808 AlignmentI thisAlignment, AlignmentI al, String title, int mode)
811 * Identify protein and dna alignments.
813 AlignmentI protein = al.isNucleotide() ? thisAlignment : al;
814 AlignmentI cdna = al.isNucleotide() ? al : thisAlignment;
817 * Map sequences. At least one should get mapped as we have already passed
818 * the test for 'mappability'. Any mappings made will be added to the
819 * protein alignment. Note creating dataset sequences on the new alignment
820 * is a pre-requisite for building mappings.
823 AlignmentUtils.mapProteinAlignmentToCdna(protein, cdna);
826 * Create the AlignFrame for the added alignment. If it is protein, mappings
827 * are registered with StructureSelectionManager as a side-effect.
829 AlignFrame newAlignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
830 AlignFrame.DEFAULT_HEIGHT);
831 newAlignFrame.setTitle(title);
832 newAlignFrame.setStatus(MessageManager
833 .formatMessage("label.successfully_loaded_file", new Object[]
836 // TODO if we want this (e.g. to enable reload of the alignment from file),
837 // we will need to add parameters to the stack.
838 // if (!protocol.equals(DataSourceType.PASTE))
840 // alignFrame.setFileName(file, format);
843 if (mode == NEW_WINDOW)
845 Desktop.addInternalFrame(newAlignFrame, title,
846 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
851 newAlignFrame.setMaximum(Cache.getDefault("SHOW_FULLSCREEN", false));
852 } catch (java.beans.PropertyVetoException ex)
856 if (mode == SPLIT_FRAME)
858 al.alignAs(thisAlignment);
859 openSplitFrame(thisFrame, newAlignFrame, thisAlignment);
864 * Helper method to open a new SplitFrame holding linked dna and protein
867 * @param newAlignFrame
868 * containing a new alignment to be shown
870 * cdna/protein complement alignment to show in the other split half
871 * @return the protein alignment in the split frame
873 static protected AlignmentI openSplitFrame(AlignFrame thisFrame,
874 AlignFrame newAlignFrame, AlignmentI complement)
877 * Make a new frame with a copy of the alignment we are adding to. If this
878 * is protein, the mappings to cDNA will be registered with
879 * StructureSelectionManager as a side-effect.
881 AlignFrame copyMe = new AlignFrame(complement, AlignFrame.DEFAULT_WIDTH,
882 AlignFrame.DEFAULT_HEIGHT);
883 copyMe.setTitle(thisFrame.getTitle());
885 AlignmentI al = newAlignFrame.viewport.getAlignment();
886 final AlignFrame proteinFrame = al.isNucleotide() ? copyMe
888 final AlignFrame cdnaFrame = al.isNucleotide() ? newAlignFrame : copyMe;
889 cdnaFrame.setVisible(true);
890 proteinFrame.setVisible(true);
891 String linkedTitle = MessageManager
892 .getString("label.linked_view_title");
895 * Open in split pane. DNA sequence above, protein below.
897 JInternalFrame splitFrame = new SplitFrame(cdnaFrame, proteinFrame);
898 Desktop.addInternalFrame(splitFrame, linkedTitle, -1, -1);
900 return proteinFrame.viewport.getAlignment();
903 public AnnotationColumnChooser getAnnotationColumnSelectionState()
905 return annotationColumnSelectionState;
908 public void setAnnotationColumnSelectionState(
909 AnnotationColumnChooser currentAnnotationColumnSelectionState)
911 this.annotationColumnSelectionState = currentAnnotationColumnSelectionState;
915 public void setIdWidth(int i)
918 AlignmentPanel ap = getAlignPanel();
921 // modify GUI elements to reflect geometry change
922 Dimension idw = ap.getIdPanel().getIdCanvas().getPreferredSize();
924 ap.getIdPanel().getIdCanvas().setPreferredSize(idw);
928 public Rectangle getExplodedGeometry()
930 return explodedGeometry;
933 public void setExplodedGeometry(Rectangle explodedPosition)
935 this.explodedGeometry = explodedPosition;
938 public boolean isGatherViewsHere()
940 return gatherViewsHere;
943 public void setGatherViewsHere(boolean gatherViewsHere)
945 this.gatherViewsHere = gatherViewsHere;
949 * If this viewport has a (Protein/cDNA) complement, then scroll the
950 * complementary alignment to match this one.
952 public void scrollComplementaryAlignment()
955 * Populate a SearchResults object with the mapped location to scroll to. If
956 * there is no complement, or it is not following highlights, or no mapping
957 * is found, the result will be empty.
959 SearchResultsI sr = new SearchResults();
960 int verticalOffset = findComplementScrollTarget(sr);
963 // TODO would like next line without cast but needs more refactoring...
964 final AlignmentPanel complementPanel = ((AlignViewport) getCodingComplement())
966 complementPanel.setToScrollComplementPanel(false);
967 complementPanel.scrollToCentre(sr, verticalOffset);
968 complementPanel.setToScrollComplementPanel(true);
973 * Answers true if no alignment holds a reference to the given mapping
978 protected boolean noReferencesTo(AlignedCodonFrame acf)
980 AlignFrame[] frames = Desktop.getAlignFrames();
985 for (AlignFrame af : frames)
989 for (AlignmentViewPanel ap : af.getAlignPanels())
991 AlignmentI al = ap.getAlignment();
992 if (al != null && al.getCodonFrames().contains(acf))
1003 * Applies the supplied feature settings descriptor to currently known
1004 * features. This supports an 'initial configuration' of feature colouring
1005 * based on a preset or user favourite. This may then be modified in the usual
1006 * way using the Feature Settings dialogue.
1008 * @param featureSettings
1011 public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
1013 transferFeaturesStyles(featureSettings, false);
1017 * Applies the supplied feature settings descriptor to currently known
1018 * features. This supports an 'initial configuration' of feature colouring
1019 * based on a preset or user favourite. This may then be modified in the usual
1020 * way using the Feature Settings dialogue.
1022 * @param featureSettings
1025 public void mergeFeaturesStyle(FeatureSettingsModelI featureSettings)
1027 transferFeaturesStyles(featureSettings, true);
1031 * when mergeOnly is set, then group and feature visibility or feature colours
1032 * are not modified for features and groups already known to the feature
1033 * renderer. Feature ordering is always adjusted, and transparency is always
1036 * @param featureSettings
1039 private void transferFeaturesStyles(FeatureSettingsModelI featureSettings,
1042 if (featureSettings == null)
1046 FeatureRenderer fr = getAlignPanel().getSeqPanel().seqCanvas
1047 .getFeatureRenderer();
1048 List<String> origRenderOrder = new ArrayList(),
1049 origGroups = new ArrayList();
1050 // preserve original render order - allows differentiation between user
1051 // configured colours and autogenerated ones
1052 origRenderOrder.addAll(fr.getRenderOrder());
1053 origGroups.addAll(fr.getFeatureGroups());
1055 fr.findAllFeatures(true);
1056 List<String> renderOrder = fr.getRenderOrder();
1057 FeaturesDisplayedI displayed = fr.getFeaturesDisplayed();
1060 // only clear displayed features if we are mergeing
1063 // TODO this clears displayed.featuresRegistered - do we care?
1065 // JAL-3330 - JBP - yes we do - calling applyFeatureStyle to a view where
1066 // feature visibility has already been configured is not very friendly
1068 * set feature colour if specified by feature settings
1069 * set visibility of all features
1071 for (String type : renderOrder)
1073 FeatureColourI preferredColour = featureSettings
1074 .getFeatureColour(type);
1075 FeatureMatcherSetI preferredFilters = featureSettings
1076 .getFeatureFilters(type);
1077 FeatureColourI origColour = fr.getFeatureStyle(type);
1078 if (!mergeOnly || (!origRenderOrder.contains(type)
1079 || origColour == null
1080 || (!origColour.isGraduatedColour()
1081 && origColour.getColour() != null
1082 && origColour.getColour().equals(
1083 ColorUtils.createColourFromName(type)))))
1085 // if we are merging, only update if there wasn't already a colour
1088 if (preferredColour != null)
1090 fr.setColour(type, preferredColour);
1092 if (preferredFilters != null
1093 && (!mergeOnly || fr.getFeatureFilter(type) != null))
1095 fr.setFeatureFilter(type, preferredFilters);
1097 if (featureSettings.isFeatureDisplayed(type))
1099 displayed.setVisible(type);
1101 else if (featureSettings.isFeatureHidden(type))
1103 displayed.setHidden(type);
1109 * set visibility of feature groups
1111 for (String group : fr.getFeatureGroups())
1113 if (!mergeOnly || !origGroups.contains(group))
1115 // when merging, display groups only if the aren't already marked as not
1117 fr.setGroupVisibility(group,
1118 featureSettings.isGroupDisplayed(group));
1123 * order the features
1125 if (featureSettings.optimiseOrder())
1127 // TODO not supported (yet?)
1131 fr.orderFeatures(featureSettings);
1133 fr.setTransparency(featureSettings.getTransparency());
1135 fr.notifyFeaturesChanged();
1138 public String getViewName()
1143 public void setViewName(String viewName)
1145 this.viewName = viewName;