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.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.datamodel.features.FeatureMatcherSetI;
43 import jalview.renderer.ResidueShader;
44 import jalview.schemes.ColourSchemeI;
45 import jalview.schemes.ColourSchemeProperty;
46 import jalview.schemes.ResidueColourScheme;
47 import jalview.schemes.UserColourScheme;
48 import jalview.structure.SelectionSource;
49 import jalview.structure.StructureSelectionManager;
50 import jalview.structure.VamsasSource;
51 import jalview.util.ColorUtils;
52 import jalview.util.MessageManager;
53 import jalview.viewmodel.AlignmentViewport;
54 import jalview.ws.params.AutoCalcSetting;
56 import java.awt.Container;
57 import java.awt.Dimension;
59 import java.awt.FontMetrics;
60 import java.awt.Rectangle;
61 import java.util.ArrayList;
62 import java.util.Hashtable;
63 import java.util.Iterator;
64 import java.util.List;
66 import javax.swing.JInternalFrame;
72 * @version $Revision: 1.141 $
74 public class AlignViewport extends AlignmentViewport
75 implements SelectionSource
79 boolean cursorMode = false;
81 boolean antiAlias = false;
83 private Rectangle explodedGeometry;
85 private String viewName;
88 * Flag set true on the view that should 'gather' multiple views of the same
89 * sequence set id when a project is reloaded. Set false on all views when
90 * they are 'exploded' into separate windows. Set true on the current view
91 * when 'Gather' is performed, and also on the first tab when the first new
94 private boolean gatherViewsHere = false;
96 private AnnotationColumnChooser annotationColumnSelectionState;
99 * Creates a new AlignViewport object.
104 public AlignViewport(AlignmentI al)
111 * Create a new AlignViewport object with a specific sequence set ID
115 * (may be null - but potential for ambiguous constructor exception)
117 public AlignViewport(AlignmentI al, String seqsetid)
119 this(al, seqsetid, null);
122 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
125 sequenceSetID = seqsetid;
127 // TODO remove these once 2.4.VAMSAS release finished
128 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
131 "Setting viewport's sequence set id : " + sequenceSetID);
133 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
135 Cache.log.debug("Setting viewport's view id : " + viewId);
142 * Create a new AlignViewport with hidden regions
146 * @param hiddenColumns
149 public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns)
152 if (hiddenColumns != null)
154 al.setHiddenColumns(hiddenColumns);
160 * New viewport with hidden columns and an existing sequence set id
163 * @param hiddenColumns
167 public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns,
170 this(al, hiddenColumns, seqsetid, null);
174 * New viewport with hidden columns and an existing sequence set id and viewid
177 * @param hiddenColumns
183 public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns,
184 String seqsetid, String viewid)
187 sequenceSetID = seqsetid;
189 // TODO remove these once 2.4.VAMSAS release finished
190 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
193 "Setting viewport's sequence set id : " + sequenceSetID);
195 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
197 Cache.log.debug("Setting viewport's view id : " + viewId);
200 if (hiddenColumns != null)
202 al.setHiddenColumns(hiddenColumns);
208 * Apply any settings saved in user preferences
210 private void applyViewProperties()
212 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
214 viewStyle.setShowJVSuffix(Cache.getDefault("SHOW_JVSUFFIX", true));
215 setShowAnnotation(Cache.getDefault("SHOW_ANNOTATIONS", true));
217 setRightAlignIds(Cache.getDefault("RIGHT_ALIGN_IDS", false));
218 setCentreColumnLabels(Cache.getDefault("CENTRE_COLUMN_LABELS", false));
219 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
221 setPadGaps(Cache.getDefault("PAD_GAPS", true));
222 setShowNPFeats(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
223 setShowDBRefs(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
224 viewStyle.setSeqNameItalics(Cache.getDefault("ID_ITALICS", true));
225 viewStyle.setWrapAlignment(Cache.getDefault("WRAP_ALIGNMENT", false));
226 viewStyle.setShowUnconserved(
227 Cache.getDefault("SHOW_UNCONSERVED", false));
228 sortByTree = Cache.getDefault("SORT_BY_TREE", false);
229 followSelection = Cache.getDefault("FOLLOW_SELECTIONS", true);
230 sortAnnotationsBy = SequenceAnnotationOrder
231 .valueOf(Cache.getDefault(Preferences.SORT_ANNOTATIONS,
232 SequenceAnnotationOrder.NONE.name()));
233 showAutocalculatedAbove = Cache
234 .getDefault(Preferences.SHOW_AUTOCALC_ABOVE, false);
235 viewStyle.setScaleProteinAsCdna(
236 Cache.getDefault(Preferences.SCALE_PROTEIN_TO_CDNA, true));
241 applyViewProperties();
243 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
244 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
245 String fontSize = Cache.getDefault("FONT_SIZE", "10");
249 if (fontStyle.equals("bold"))
253 else if (fontStyle.equals("italic"))
258 setFont(new Font(fontName, style, Integer.parseInt(fontSize)), true);
260 alignment.setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
262 // We must set conservation and consensus before setting colour,
263 // as Blosum and Clustal require this to be done
264 if (hconsensus == null && !isDataset)
266 if (!alignment.isNucleotide())
268 showConservation = Cache.getDefault("SHOW_CONSERVATION", true);
269 showQuality = Cache.getDefault("SHOW_QUALITY", true);
270 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
273 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
275 showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
276 normaliseSequenceLogo = Cache.getDefault("NORMALISE_CONSENSUS_LOGO",
278 // for now, use consensus options for Information till it gets its own
279 setShowHMMSequenceLogo(showSequenceLogo);
280 setNormaliseHMMSequenceLogo(normaliseSequenceLogo);
281 setShowInformationHistogram(showConsensusHistogram);
282 showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
283 showConsensus = Cache.getDefault("SHOW_IDENTITY", true);
285 showOccupancy = Cache.getDefault(Preferences.SHOW_OCCUPANCY, true);
287 initAutoAnnotation();
288 // initInformation();
290 String colourProperty = alignment.isNucleotide()
291 ? Preferences.DEFAULT_COLOUR_NUC
292 : Preferences.DEFAULT_COLOUR_PROT;
293 String schemeName = Cache.getProperty(colourProperty);
294 if (schemeName == null)
296 // only DEFAULT_COLOUR available in Jalview before 2.9
297 schemeName = Cache.getDefault(Preferences.DEFAULT_COLOUR,
298 ResidueColourScheme.NONE);
300 ColourSchemeI colourScheme = ColourSchemeProperty
301 .getColourScheme(this, alignment, schemeName);
302 residueShading = new ResidueShader(colourScheme);
304 if (colourScheme instanceof UserColourScheme)
306 residueShading = new ResidueShader(
307 UserDefinedColours.loadDefaultColours());
308 residueShading.setThreshold(0, isIgnoreGapsConsensus());
311 if (residueShading != null)
313 residueShading.setConsensus(hconsensus);
315 setColourAppliesToAllGroups(true);
318 boolean validCharWidth;
324 public void setFont(Font f, boolean setGrid)
328 Container c = new Container();
332 FontMetrics fm = c.getFontMetrics(font);
333 int ww = fm.charWidth('M');
334 setCharHeight(fm.getHeight());
337 viewStyle.setFontName(font.getName());
338 viewStyle.setFontStyle(font.getStyle());
339 viewStyle.setFontSize(font.getSize());
341 validCharWidth = true;
345 public void setViewStyle(ViewStyleI settingsForView)
347 super.setViewStyle(settingsForView);
348 setFont(new Font(viewStyle.getFontName(), viewStyle.getFontStyle(),
349 viewStyle.getFontSize()), false);
355 * @return DOCUMENT ME!
357 public Font getFont()
369 public void setAlignment(AlignmentI align)
371 replaceMappings(align);
372 super.setAlignment(align);
376 * Replace any codon mappings for this viewport with those for the given
381 public void replaceMappings(AlignmentI align)
385 * Deregister current mappings (if any)
387 deregisterMappings();
390 * Register new mappings (if any)
394 StructureSelectionManager ssm = StructureSelectionManager
395 .getStructureSelectionManager(Desktop.instance);
396 ssm.registerMappings(align.getCodonFrames());
400 * replace mappings on our alignment
402 if (alignment != null && align != null)
404 alignment.setCodonFrames(align.getCodonFrames());
408 protected void deregisterMappings()
410 AlignmentI al = getAlignment();
413 List<AlignedCodonFrame> mappings = al.getCodonFrames();
414 if (mappings != null)
416 StructureSelectionManager ssm = StructureSelectionManager
417 .getStructureSelectionManager(Desktop.instance);
418 for (AlignedCodonFrame acf : mappings)
420 if (noReferencesTo(acf))
422 ssm.deregisterMapping(acf);
432 * @return DOCUMENT ME!
435 public char getGapCharacter()
437 return getAlignment().getGapCharacter();
446 public void setGapCharacter(char gap)
448 if (getAlignment() != null)
450 getAlignment().setGapCharacter(gap);
455 * Returns an iterator over the visible column regions of the alignment
457 * @param selectedRegionOnly
458 * true to just return the contigs intersecting with the selected
462 public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
466 if (selectedRegionOnly && selectionGroup != null)
468 start = selectionGroup.getStartRes();
469 end = selectionGroup.getEndRes() + 1;
473 end = alignment.getWidth();
476 return (alignment.getHiddenColumns().getVisContigsIterator(start,
481 * get hash of undo and redo list for the alignment
483 * @return long[] { historyList.hashCode, redoList.hashCode };
485 public long[] getUndoRedoHash()
488 if (historyList == null || redoList == null)
490 return new long[] { -1, -1 };
492 return new long[] { historyList.hashCode(), this.redoList.hashCode() };
496 * test if a particular set of hashcodes are different to the hashcodes for
497 * the undo and redo list.
500 * the stored set of hashcodes as returned by getUndoRedoHash
501 * @return true if the hashcodes differ (ie the alignment has been edited) or
502 * the stored hashcode array differs in size
504 public boolean isUndoRedoHashModified(long[] undoredo)
506 if (undoredo == null)
510 long[] cstate = getUndoRedoHash();
511 if (cstate.length != undoredo.length)
516 for (int i = 0; i < cstate.length; i++)
518 if (cstate[i] != undoredo[i])
526 public boolean followSelection = true;
529 * @return true if view selection should always follow the selections
530 * broadcast by other selection sources
532 public boolean getFollowSelection()
534 return followSelection;
538 * Send the current selection to be broadcast to any selection listeners.
541 public void sendSelection()
543 jalview.structure.StructureSelectionManager
544 .getStructureSelectionManager(Desktop.instance)
545 .sendSelection(new SequenceGroup(getSelectionGroup()),
546 new ColumnSelection(getColumnSelection()),
547 new HiddenColumns(getAlignment().getHiddenColumns()),
552 * return the alignPanel containing the given viewport. Use this to get the
553 * components currently handling the given viewport.
556 * @return null or an alignPanel guaranteed to have non-null alignFrame
559 public AlignmentPanel getAlignPanel()
561 AlignmentPanel[] aps = PaintRefresher
562 .getAssociatedPanels(this.getSequenceSetId());
563 for (int p = 0; aps != null && p < aps.length; p++)
565 if (aps[p].av == this)
573 public boolean getSortByTree()
578 public void setSortByTree(boolean sort)
584 * Returns the (Desktop) instance of the StructureSelectionManager
587 public StructureSelectionManager getStructureSelectionManager()
589 return StructureSelectionManager
590 .getStructureSelectionManager(Desktop.instance);
594 public boolean isNormaliseSequenceLogo()
596 return normaliseSequenceLogo;
600 public void setNormaliseSequenceLogo(boolean state)
602 normaliseSequenceLogo = state;
608 * @return true if alignment characters should be displayed
611 public boolean isValidCharWidth()
613 return validCharWidth;
616 private Hashtable<String, AutoCalcSetting> calcIdParams = new Hashtable<>();
618 public AutoCalcSetting getCalcIdSettingsFor(String calcId)
620 return calcIdParams.get(calcId);
623 public void setCalcIdSettingsFor(String calcId, AutoCalcSetting settings,
626 calcIdParams.put(calcId, settings);
627 // TODO: create a restart list to trigger any calculations that need to be
628 // restarted after load
629 // calculator.getRegisteredWorkersOfClass(settings.getWorkerClass())
632 Cache.log.debug("trigger update for " + calcId);
637 * Method called when another alignment's edit (or possibly other) command is
640 * To allow for sequence mappings (e.g. protein to cDNA), we have to first
641 * 'unwind' the command on the source sequences (in simulation, not in fact),
642 * and then for each edit in turn:
644 * <li>compute the equivalent edit on the mapped sequences</li>
645 * <li>apply the mapped edit</li>
646 * <li>'apply' the source edit to the working copy of the source
655 public void mirrorCommand(CommandI command, boolean undo,
656 StructureSelectionManager ssm, VamsasSource source)
659 * Do nothing unless we are a 'complement' of the source. May replace this
660 * with direct calls not via SSM.
662 if (source instanceof AlignViewportI
663 && ((AlignViewportI) source).getCodingComplement() == this)
672 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
674 if (mappedCommand != null)
676 AlignmentI[] views = getAlignPanel().alignFrame.getViewAlignments();
677 mappedCommand.doCommand(views);
678 getAlignPanel().alignmentChanged();
683 * Add the sequences from the given alignment to this viewport. Optionally,
684 * may give the user the option to open a new frame, or split panel, with cDNA
685 * and protein linked.
690 public void addAlignment(AlignmentI toAdd, String title)
692 // TODO: promote to AlignViewportI? applet CutAndPasteTransfer is different
694 // JBPComment: title is a largely redundant parameter at the moment
695 // JBPComment: this really should be an 'insert/pre/append' controller
696 // JBPComment: but the DNA/Protein check makes it a bit more complex
698 // refactored from FileLoader / CutAndPasteTransfer / SequenceFetcher with
700 // TODO: create undo object for this JAL-1101
703 * Ensure datasets are created for the new alignment as
704 * mappings operate on dataset sequences
706 toAdd.setDataset(null);
709 * Check if any added sequence could be the object of a mapping or
710 * cross-reference; if so, make the mapping explicit
712 getAlignment().realiseMappings(toAdd.getSequences());
715 * If any cDNA/protein mappings exist or can be made between the alignments,
716 * offer to open a split frame with linked alignments
718 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
720 if (AlignmentUtils.isMappable(toAdd, getAlignment()))
722 if (openLinkedAlignment(toAdd, title))
730 * No mappings, or offer declined - add sequences to this alignment
732 // TODO: JAL-407 regardless of above - identical sequences (based on ID and
733 // provenance) should share the same dataset sequence
735 AlignmentI al = getAlignment();
736 String gap = String.valueOf(al.getGapCharacter());
737 for (int i = 0; i < toAdd.getHeight(); i++)
739 SequenceI seq = toAdd.getSequenceAt(i);
742 * - 'align' any mapped sequences as per existing
743 * e.g. cdna to genome, domain hit to protein sequence
744 * very experimental! (need a separate menu option for this)
745 * - only add mapped sequences ('select targets from a dataset')
747 if (true /*AlignmentUtils.alignSequenceAs(seq, al, gap, true, true)*/)
753 ranges.setEndSeq(getAlignment().getHeight());
754 firePropertyChange("alignment", null, getAlignment().getSequences());
758 * Show a dialog with the option to open and link (cDNA <-> protein) as a new
759 * alignment, either as a standalone alignment or in a split frame. Returns
760 * true if the new alignment was opened, false if not, because the user
761 * declined the offer.
766 protected boolean openLinkedAlignment(AlignmentI al, String title)
768 String[] options = new String[] { MessageManager.getString("action.no"),
769 MessageManager.getString("label.split_window"),
770 MessageManager.getString("label.new_window"), };
771 final String question = JvSwingUtils.wrapTooltip(true,
772 MessageManager.getString("label.open_split_window?"));
773 int response = JvOptionPane.showOptionDialog(Desktop.desktop, question,
774 MessageManager.getString("label.open_split_window"),
775 JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
776 options, options[0]);
778 if (response != 1 && response != 2)
782 final boolean openSplitPane = (response == 1);
783 final boolean openInNewWindow = (response == 2);
786 * Identify protein and dna alignments. Make a copy of this one if opening
787 * in a new split pane.
789 AlignmentI thisAlignment = openSplitPane ? new Alignment(getAlignment())
791 AlignmentI protein = al.isNucleotide() ? thisAlignment : al;
792 final AlignmentI cdna = al.isNucleotide() ? al : thisAlignment;
795 * Map sequences. At least one should get mapped as we have already passed
796 * the test for 'mappability'. Any mappings made will be added to the
797 * protein alignment. Note creating dataset sequences on the new alignment
798 * is a pre-requisite for building mappings.
801 AlignmentUtils.mapProteinAlignmentToCdna(protein, cdna);
804 * Create the AlignFrame for the added alignment. If it is protein, mappings
805 * are registered with StructureSelectionManager as a side-effect.
807 AlignFrame newAlignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
808 AlignFrame.DEFAULT_HEIGHT);
809 newAlignFrame.setTitle(title);
810 newAlignFrame.setStatus(MessageManager
811 .formatMessage("label.successfully_loaded_file", new Object[]
814 // TODO if we want this (e.g. to enable reload of the alignment from file),
815 // we will need to add parameters to the stack.
816 // if (!protocol.equals(DataSourceType.PASTE))
818 // alignFrame.setFileName(file, format);
823 Desktop.addInternalFrame(newAlignFrame, title,
824 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
829 newAlignFrame.setMaximum(
830 jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false));
831 } catch (java.beans.PropertyVetoException ex)
837 al.alignAs(thisAlignment);
838 protein = openSplitFrame(newAlignFrame, thisAlignment);
845 * Helper method to open a new SplitFrame holding linked dna and protein
848 * @param newAlignFrame
849 * containing a new alignment to be shown
851 * cdna/protein complement alignment to show in the other split half
852 * @return the protein alignment in the split frame
854 protected AlignmentI openSplitFrame(AlignFrame newAlignFrame,
855 AlignmentI complement)
858 * Make a new frame with a copy of the alignment we are adding to. If this
859 * is protein, the mappings to cDNA will be registered with
860 * StructureSelectionManager as a side-effect.
862 AlignFrame copyMe = new AlignFrame(complement, AlignFrame.DEFAULT_WIDTH,
863 AlignFrame.DEFAULT_HEIGHT);
864 copyMe.setTitle(getAlignPanel().alignFrame.getTitle());
866 AlignmentI al = newAlignFrame.viewport.getAlignment();
867 final AlignFrame proteinFrame = al.isNucleotide() ? copyMe
869 final AlignFrame cdnaFrame = al.isNucleotide() ? newAlignFrame : copyMe;
870 cdnaFrame.setVisible(true);
871 proteinFrame.setVisible(true);
872 String linkedTitle = MessageManager
873 .getString("label.linked_view_title");
876 * Open in split pane. DNA sequence above, protein below.
878 JInternalFrame splitFrame = new SplitFrame(cdnaFrame, proteinFrame);
879 Desktop.addInternalFrame(splitFrame, linkedTitle, -1, -1);
881 return proteinFrame.viewport.getAlignment();
884 public AnnotationColumnChooser getAnnotationColumnSelectionState()
886 return annotationColumnSelectionState;
889 public void setAnnotationColumnSelectionState(
890 AnnotationColumnChooser currentAnnotationColumnSelectionState)
892 this.annotationColumnSelectionState = currentAnnotationColumnSelectionState;
896 public void setIdWidth(int i)
899 AlignmentPanel ap = getAlignPanel();
902 // modify GUI elements to reflect geometry change
903 Dimension idw = getAlignPanel().getIdPanel().getIdCanvas()
906 getAlignPanel().getIdPanel().getIdCanvas().setPreferredSize(idw);
910 public Rectangle getExplodedGeometry()
912 return explodedGeometry;
915 public void setExplodedGeometry(Rectangle explodedPosition)
917 this.explodedGeometry = explodedPosition;
920 public boolean isGatherViewsHere()
922 return gatherViewsHere;
925 public void setGatherViewsHere(boolean gatherViewsHere)
927 this.gatherViewsHere = gatherViewsHere;
931 * If this viewport has a (Protein/cDNA) complement, then scroll the
932 * complementary alignment to match this one.
934 public void scrollComplementaryAlignment()
937 * Populate a SearchResults object with the mapped location to scroll to. If
938 * there is no complement, or it is not following highlights, or no mapping
939 * is found, the result will be empty.
941 SearchResultsI sr = new SearchResults();
942 int verticalOffset = findComplementScrollTarget(sr);
945 // TODO would like next line without cast but needs more refactoring...
946 final AlignmentPanel complementPanel = ((AlignViewport) getCodingComplement())
948 complementPanel.setToScrollComplementPanel(false);
949 complementPanel.scrollToCentre(sr, verticalOffset);
950 complementPanel.setToScrollComplementPanel(true);
955 * Answers true if no alignment holds a reference to the given mapping
960 protected boolean noReferencesTo(AlignedCodonFrame acf)
962 AlignFrame[] frames = Desktop.getAlignFrames();
967 for (AlignFrame af : frames)
971 for (AlignmentViewPanel ap : af.getAlignPanels())
973 AlignmentI al = ap.getAlignment();
974 if (al != null && al.getCodonFrames().contains(acf))
985 * Applies the supplied feature settings descriptor to currently known
986 * features. This supports an 'initial configuration' of feature colouring
987 * based on a preset or user favourite. This may then be modified in the usual
988 * way using the Feature Settings dialogue.
990 * @param featureSettings
993 public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
995 transferFeaturesStyles(featureSettings, false);
999 * Applies the supplied feature settings descriptor to currently known features.
1000 * This supports an 'initial configuration' of feature colouring based on a
1001 * preset or user favourite. This may then be modified in the usual way using
1002 * the Feature Settings dialogue.
1004 * @param featureSettings
1007 public void mergeFeaturesStyle(FeatureSettingsModelI featureSettings)
1009 transferFeaturesStyles(featureSettings, true);
1013 * when mergeOnly is set, then group and feature visibility or feature colours
1014 * are not modified for features and groups already known to the feature
1015 * renderer. Feature ordering is always adjusted, and transparency is always set
1018 * @param featureSettings
1021 private void transferFeaturesStyles(FeatureSettingsModelI featureSettings,
1024 if (featureSettings == null)
1029 FeatureRenderer fr = getAlignPanel().getSeqPanel().seqCanvas
1030 .getFeatureRenderer();
1031 List<String> origRenderOrder = new ArrayList(),
1032 origGroups = new ArrayList();
1033 // preserve original render order - allows differentiation between user configured colours and autogenerated ones
1034 origRenderOrder.addAll(fr.getRenderOrder());
1035 origGroups.addAll(fr.getFeatureGroups());
1037 fr.findAllFeatures(true);
1038 List<String> renderOrder = fr.getRenderOrder();
1039 FeaturesDisplayedI displayed = fr.getFeaturesDisplayed();
1042 // only clear displayed features if we are mergeing
1045 // TODO this clears displayed.featuresRegistered - do we care?
1047 // JAL-3330 - JBP - yes we do - calling applyFeatureStyle to a view where
1048 // feature visibility has already been configured is not very friendly
1050 * set feature colour if specified by feature settings
1051 * set visibility of all features
1053 for (String type : renderOrder)
1055 FeatureColourI preferredColour = featureSettings
1056 .getFeatureColour(type);
1057 FeatureMatcherSetI preferredFilters = featureSettings
1058 .getFeatureFilters(type);
1060 FeatureColourI origColour = fr.getFeatureStyle(type);
1061 if (!mergeOnly || (!origRenderOrder.contains(type)
1062 || origColour == null
1063 || (!origColour.isGraduatedColour()
1064 && origColour.getColour() != null
1065 && origColour.getColour().equals(
1066 ColorUtils.createColourFromName(type)))))
1068 // if we are merging, only update if there wasn't already a colour defined for
1070 if (preferredColour != null)
1072 fr.setColour(type, preferredColour);
1074 if (preferredFilters != null
1075 && (!mergeOnly || fr.getFeatureFilter(type) != null))
1077 fr.setFeatureFilter(type, preferredFilters);
1079 if (featureSettings.isFeatureDisplayed(type))
1081 displayed.setVisible(type);
1087 * set visibility of feature groups
1089 for (String group : fr.getFeatureGroups())
1091 if (!mergeOnly || !origGroups.contains(group))
1093 // when merging, display groups only if the aren't already marked as not visible
1094 fr.setGroupVisibility(group,
1095 featureSettings.isGroupDisplayed(group));
1100 * order the features
1102 if (featureSettings.optimiseOrder())
1104 // TODO not supported (yet?)
1108 fr.orderFeatures(featureSettings);
1110 fr.setTransparency(featureSettings.getTransparency());
1113 public String getViewName()
1118 public void setViewName(String viewName)
1120 this.viewName = viewName;