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.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.List;
65 import javax.swing.JInternalFrame;
71 * @version $Revision: 1.141 $
73 public class AlignViewport extends AlignmentViewport
74 implements SelectionSource
78 boolean cursorMode = false;
80 boolean antiAlias = false;
82 private Rectangle explodedGeometry = null;
84 private String viewName = null;
87 * Flag set true on the view that should 'gather' multiple views of the same
88 * sequence set id when a project is reloaded. Set false on all views when
89 * they are 'exploded' into separate windows. Set true on the current view
90 * when 'Gather' is performed, and also on the first tab when the first new
93 private boolean gatherViewsHere = false;
95 private AnnotationColumnChooser annotationColumnSelectionState;
98 * Creates a new AlignViewport object.
103 public AlignViewport(AlignmentI al)
110 * Create a new AlignViewport object with a specific sequence set ID
114 * (may be null - but potential for ambiguous constructor exception)
116 public AlignViewport(AlignmentI al, String seqsetid)
118 this(al, seqsetid, null);
121 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
124 sequenceSetID = seqsetid;
126 // TODO remove these once 2.4.VAMSAS release finished
127 if (seqsetid != null)
130 "Setting viewport's sequence set id : " + sequenceSetID);
134 Console.debug("Setting viewport's view id : " + viewId);
141 * Create a new AlignViewport with hidden regions
145 * @param hiddenColumns
148 public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns)
151 if (hiddenColumns != null)
153 al.setHiddenColumns(hiddenColumns);
159 * New viewport with hidden columns and an existing sequence set id
162 * @param hiddenColumns
166 public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns,
169 this(al, hiddenColumns, seqsetid, null);
173 * New viewport with hidden columns and an existing sequence set id and viewid
176 * @param hiddenColumns
182 public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns,
183 String seqsetid, String viewid)
186 sequenceSetID = seqsetid;
188 // TODO remove these once 2.4.VAMSAS release finished
189 if (seqsetid != null)
192 "Setting viewport's sequence set id : " + sequenceSetID);
196 Console.debug("Setting viewport's view id : " + viewId);
199 if (hiddenColumns != null)
201 al.setHiddenColumns(hiddenColumns);
207 * Apply any settings saved in user preferences
209 private void applyViewProperties()
211 antiAlias = Cache.getDefault("ANTI_ALIAS", true);
213 viewStyle.setShowJVSuffix(Cache.getDefault("SHOW_JVSUFFIX", true));
214 setShowAnnotation(Cache.getDefault("SHOW_ANNOTATIONS", true));
216 setRightAlignIds(Cache.getDefault("RIGHT_ALIGN_IDS", false));
217 setCentreColumnLabels(Cache.getDefault("CENTRE_COLUMN_LABELS", false));
218 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
220 setPadGaps(Cache.getDefault("PAD_GAPS", true));
221 setShowNPFeats(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
222 setShowDBRefs(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
223 viewStyle.setSeqNameItalics(Cache.getDefault("ID_ITALICS", true));
224 viewStyle.setWrapAlignment(Cache.getDefault("WRAP_ALIGNMENT", false));
225 viewStyle.setShowUnconserved(
226 Cache.getDefault("SHOW_UNCONSERVED", false));
227 sortByTree = Cache.getDefault("SORT_BY_TREE", false);
228 followSelection = Cache.getDefault("FOLLOW_SELECTIONS", true);
229 sortAnnotationsBy = SequenceAnnotationOrder
230 .valueOf(Cache.getDefault(Preferences.SORT_ANNOTATIONS,
231 SequenceAnnotationOrder.NONE.name()));
232 showAutocalculatedAbove = Cache
233 .getDefault(Preferences.SHOW_AUTOCALC_ABOVE, false);
234 viewStyle.setScaleProteinAsCdna(
235 Cache.getDefault(Preferences.SCALE_PROTEIN_TO_CDNA, true));
240 applyViewProperties();
242 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
243 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
244 String fontSize = Cache.getDefault("FONT_SIZE", "10");
248 if (fontStyle.equals("bold"))
252 else if (fontStyle.equals("italic"))
257 setFont(new Font(fontName, style, Integer.parseInt(fontSize)), true);
260 .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 showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
279 showConsensus = Cache.getDefault("SHOW_IDENTITY", true);
281 showOccupancy = Cache.getDefault(Preferences.SHOW_OCCUPANCY, true);
283 initAutoAnnotation();
284 String colourProperty = alignment.isNucleotide()
285 ? Preferences.DEFAULT_COLOUR_NUC
286 : Preferences.DEFAULT_COLOUR_PROT;
287 String schemeName = Cache.getProperty(colourProperty);
288 if (schemeName == null)
290 // only DEFAULT_COLOUR available in Jalview before 2.9
291 schemeName = Cache.getDefault(Preferences.DEFAULT_COLOUR,
292 ResidueColourScheme.NONE);
294 ColourSchemeI colourScheme = ColourSchemeProperty.getColourScheme(this,
295 alignment, schemeName);
296 residueShading = new ResidueShader(colourScheme);
298 if (colourScheme instanceof UserColourScheme)
300 residueShading = new ResidueShader(
301 UserDefinedColours.loadDefaultColours());
302 residueShading.setThreshold(0, isIgnoreGapsConsensus());
305 if (residueShading != null)
307 residueShading.setConsensus(hconsensus);
309 setColourAppliesToAllGroups(true);
312 boolean validCharWidth;
318 public void setFont(Font f, boolean setGrid)
322 Container c = new Container();
326 FontMetrics fm = c.getFontMetrics(font);
327 int ww = fm.charWidth('M');
328 setCharHeight(fm.getHeight());
331 viewStyle.setFontName(font.getName());
332 viewStyle.setFontStyle(font.getStyle());
333 viewStyle.setFontSize(font.getSize());
335 validCharWidth = true;
339 public void setViewStyle(ViewStyleI settingsForView)
341 super.setViewStyle(settingsForView);
342 setFont(new Font(viewStyle.getFontName(), viewStyle.getFontStyle(),
343 viewStyle.getFontSize()), false);
349 * @return DOCUMENT ME!
351 public Font getFont()
363 public void setAlignment(AlignmentI align)
365 replaceMappings(align);
366 super.setAlignment(align);
370 * Replace any codon mappings for this viewport with those for the given
375 public void replaceMappings(AlignmentI align)
379 * Deregister current mappings (if any)
381 deregisterMappings();
384 * Register new mappings (if any)
388 StructureSelectionManager ssm = StructureSelectionManager
389 .getStructureSelectionManager(Desktop.instance);
390 ssm.registerMappings(align.getCodonFrames());
394 * replace mappings on our alignment
396 if (alignment != null && align != null)
398 alignment.setCodonFrames(align.getCodonFrames());
402 protected void deregisterMappings()
404 AlignmentI al = getAlignment();
407 List<AlignedCodonFrame> mappings = al.getCodonFrames();
408 if (mappings != null)
410 StructureSelectionManager ssm = StructureSelectionManager
411 .getStructureSelectionManager(Desktop.instance);
412 for (AlignedCodonFrame acf : mappings)
414 if (noReferencesTo(acf))
416 ssm.deregisterMapping(acf);
426 * @return DOCUMENT ME!
429 public char getGapCharacter()
431 return getAlignment().getGapCharacter();
440 public void setGapCharacter(char gap)
442 if (getAlignment() != null)
444 getAlignment().setGapCharacter(gap);
449 * get hash of undo and redo list for the alignment
451 * @return long[] { historyList.hashCode, redoList.hashCode };
453 public long[] getUndoRedoHash()
456 if (historyList == null || redoList == null)
458 return new long[] { -1, -1 };
460 return new long[] { historyList.hashCode(), this.redoList.hashCode() };
464 * test if a particular set of hashcodes are different to the hashcodes for
465 * the undo and redo list.
468 * the stored set of hashcodes as returned by getUndoRedoHash
469 * @return true if the hashcodes differ (ie the alignment has been edited) or
470 * the stored hashcode array differs in size
472 public boolean isUndoRedoHashModified(long[] undoredo)
474 if (undoredo == null)
478 long[] cstate = getUndoRedoHash();
479 if (cstate.length != undoredo.length)
484 for (int i = 0; i < cstate.length; i++)
486 if (cstate[i] != undoredo[i])
494 public boolean followSelection = true;
497 * @return true if view selection should always follow the selections
498 * broadcast by other selection sources
500 public boolean getFollowSelection()
502 return followSelection;
506 * Send the current selection to be broadcast to any selection listeners.
509 public void sendSelection()
511 jalview.structure.StructureSelectionManager
512 .getStructureSelectionManager(Desktop.instance)
513 .sendSelection(new SequenceGroup(getSelectionGroup()),
514 new ColumnSelection(getColumnSelection()),
515 new HiddenColumns(getAlignment().getHiddenColumns()),
520 * return the alignPanel containing the given viewport. Use this to get the
521 * components currently handling the given viewport.
524 * @return null or an alignPanel guaranteed to have non-null alignFrame
527 public AlignmentPanel getAlignPanel()
529 AlignmentPanel[] aps = PaintRefresher
530 .getAssociatedPanels(this.getSequenceSetId());
531 for (int p = 0; aps != null && p < aps.length; p++)
533 if (aps[p].av == this)
541 public boolean getSortByTree()
546 public void setSortByTree(boolean sort)
552 * Returns the (Desktop) instance of the StructureSelectionManager
555 public StructureSelectionManager getStructureSelectionManager()
557 return StructureSelectionManager
558 .getStructureSelectionManager(Desktop.instance);
562 public boolean isNormaliseSequenceLogo()
564 return normaliseSequenceLogo;
567 public void setNormaliseSequenceLogo(boolean state)
569 normaliseSequenceLogo = state;
574 * @return true if alignment characters should be displayed
577 public boolean isValidCharWidth()
579 return validCharWidth;
582 private Hashtable<String, AutoCalcSetting> calcIdParams = new Hashtable<>();
584 public AutoCalcSetting getCalcIdSettingsFor(String calcId)
586 return calcIdParams.get(calcId);
589 public void setCalcIdSettingsFor(String calcId, AutoCalcSetting settings,
592 calcIdParams.put(calcId, settings);
593 // TODO: create a restart list to trigger any calculations that need to be
594 // restarted after load
595 // calculator.getRegisteredWorkersOfClass(settings.getWorkerClass())
598 Console.debug("trigger update for " + calcId);
603 * Method called when another alignment's edit (or possibly other) command is
606 * To allow for sequence mappings (e.g. protein to cDNA), we have to first
607 * 'unwind' the command on the source sequences (in simulation, not in fact),
608 * and then for each edit in turn:
610 * <li>compute the equivalent edit on the mapped sequences</li>
611 * <li>apply the mapped edit</li>
612 * <li>'apply' the source edit to the working copy of the source
621 public void mirrorCommand(CommandI command, boolean undo,
622 StructureSelectionManager ssm, VamsasSource source)
625 * Do nothing unless we are a 'complement' of the source. May replace this
626 * with direct calls not via SSM.
628 if (source instanceof AlignViewportI
629 && ((AlignViewportI) source).getCodingComplement() == this)
638 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
640 if (mappedCommand != null)
642 AlignmentI[] views = getAlignPanel().alignFrame.getViewAlignments();
643 mappedCommand.doCommand(views);
644 getAlignPanel().alignmentChanged();
649 * Add the sequences from the given alignment to this viewport. Optionally,
650 * may give the user the option to open a new frame, or split panel, with cDNA
651 * and protein linked.
656 public void addAlignment(AlignmentI toAdd, String title)
658 // TODO: promote to AlignViewportI? applet CutAndPasteTransfer is different
660 // JBPComment: title is a largely redundant parameter at the moment
661 // JBPComment: this really should be an 'insert/pre/append' controller
662 // JBPComment: but the DNA/Protein check makes it a bit more complex
664 // refactored from FileLoader / CutAndPasteTransfer / SequenceFetcher with
666 // TODO: create undo object for this JAL-1101
669 * Ensure datasets are created for the new alignment as
670 * mappings operate on dataset sequences
672 toAdd.setDataset(null);
675 * Check if any added sequence could be the object of a mapping or
676 * cross-reference; if so, make the mapping explicit
678 getAlignment().realiseMappings(toAdd.getSequences());
681 * If any cDNA/protein mappings exist or can be made between the alignments,
682 * offer to open a split frame with linked alignments
684 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
686 if (AlignmentUtils.isMappable(toAdd, getAlignment()))
688 openLinkedAlignment(toAdd, title);
692 addDataToAlignment(toAdd);
696 * adds sequences to this alignment
700 void addDataToAlignment(AlignmentI toAdd)
702 // TODO: JAL-407 regardless of above - identical sequences (based on ID and
703 // provenance) should share the same dataset sequence
705 AlignmentI al = getAlignment();
706 String gap = String.valueOf(al.getGapCharacter());
707 for (int i = 0; i < toAdd.getHeight(); i++)
709 SequenceI seq = toAdd.getSequenceAt(i);
712 * - 'align' any mapped sequences as per existing
713 * e.g. cdna to genome, domain hit to protein sequence
714 * very experimental! (need a separate menu option for this)
715 * - only add mapped sequences ('select targets from a dataset')
717 if (true /*AlignmentUtils.alignSequenceAs(seq, al, gap, true, true)*/)
723 ranges.setEndSeq(getAlignment().getHeight() - 1); // BH 2019.04.18
724 firePropertyChange("alignment", null, getAlignment().getSequences());
728 * Show a dialog with the option to open and link (cDNA <-> protein) as a new
729 * alignment, either as a standalone alignment or in a split frame. Returns
730 * true if the new alignment was opened, false if not, because the user
731 * declined the offer.
736 protected void openLinkedAlignment(AlignmentI al, String title)
738 String[] options = new String[] { MessageManager.getString("action.no"),
739 MessageManager.getString("label.split_window"),
740 MessageManager.getString("label.new_window"), };
741 final String question = JvSwingUtils.wrapTooltip(true,
742 MessageManager.getString("label.open_split_window?"));
743 final AlignViewport us = this;
746 * options No, Split Window, New Window correspond to
747 * dialog responses 0, 1, 2 (even though JOptionPane shows them
750 JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.desktop)
751 .setResponseHandler(0, new Runnable()
756 addDataToAlignment(al);
758 }).setResponseHandler(1, new Runnable()
763 us.openLinkedAlignmentAs(al, title, true);
765 }).setResponseHandler(2, new Runnable()
770 us.openLinkedAlignmentAs(al, title, false);
773 dialog.showDialog(question,
774 MessageManager.getString("label.open_split_window"),
775 JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
776 options, options[0]);
779 protected void openLinkedAlignmentAs(AlignmentI al, String title,
780 boolean newWindowOrSplitPane)
783 * Identify protein and dna alignments. Make a copy of this one if opening
784 * in a new split pane.
786 AlignmentI thisAlignment = newWindowOrSplitPane
787 ? new Alignment(getAlignment())
789 AlignmentI protein = al.isNucleotide() ? thisAlignment : al;
790 final AlignmentI cdna = al.isNucleotide() ? al : thisAlignment;
793 * Map sequences. At least one should get mapped as we have already passed
794 * the test for 'mappability'. Any mappings made will be added to the
795 * protein alignment. Note creating dataset sequences on the new alignment
796 * is a pre-requisite for building mappings.
799 AlignmentUtils.mapProteinAlignmentToCdna(protein, cdna);
802 * Create the AlignFrame for the added alignment. If it is protein, mappings
803 * are registered with StructureSelectionManager as a side-effect.
805 AlignFrame newAlignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
806 AlignFrame.DEFAULT_HEIGHT);
807 newAlignFrame.setTitle(title);
808 newAlignFrame.setStatus(MessageManager
809 .formatMessage("label.successfully_loaded_file", new Object[]
812 // TODO if we want this (e.g. to enable reload of the alignment from file),
813 // we will need to add parameters to the stack.
814 // if (!protocol.equals(DataSourceType.PASTE))
816 // alignFrame.setFileName(file, format);
819 if (!newWindowOrSplitPane)
821 Desktop.addInternalFrame(newAlignFrame, title,
822 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
827 newAlignFrame.setMaximum(Cache.getDefault("SHOW_FULLSCREEN", false));
828 } catch (java.beans.PropertyVetoException ex)
832 if (newWindowOrSplitPane)
834 al.alignAs(thisAlignment);
835 protein = openSplitFrame(newAlignFrame, thisAlignment);
840 * Helper method to open a new SplitFrame holding linked dna and protein
843 * @param newAlignFrame
844 * containing a new alignment to be shown
846 * cdna/protein complement alignment to show in the other split half
847 * @return the protein alignment in the split frame
849 protected AlignmentI openSplitFrame(AlignFrame newAlignFrame,
850 AlignmentI complement)
853 * Make a new frame with a copy of the alignment we are adding to. If this
854 * is protein, the mappings to cDNA will be registered with
855 * StructureSelectionManager as a side-effect.
857 AlignFrame copyMe = new AlignFrame(complement, AlignFrame.DEFAULT_WIDTH,
858 AlignFrame.DEFAULT_HEIGHT);
859 copyMe.setTitle(getAlignPanel().alignFrame.getTitle());
861 AlignmentI al = newAlignFrame.viewport.getAlignment();
862 final AlignFrame proteinFrame = al.isNucleotide() ? copyMe
864 final AlignFrame cdnaFrame = al.isNucleotide() ? newAlignFrame : copyMe;
865 cdnaFrame.setVisible(true);
866 proteinFrame.setVisible(true);
867 String linkedTitle = MessageManager
868 .getString("label.linked_view_title");
871 * Open in split pane. DNA sequence above, protein below.
873 JInternalFrame splitFrame = new SplitFrame(cdnaFrame, proteinFrame);
874 Desktop.addInternalFrame(splitFrame, linkedTitle, -1, -1);
876 return proteinFrame.viewport.getAlignment();
879 public AnnotationColumnChooser getAnnotationColumnSelectionState()
881 return annotationColumnSelectionState;
884 public void setAnnotationColumnSelectionState(
885 AnnotationColumnChooser currentAnnotationColumnSelectionState)
887 this.annotationColumnSelectionState = currentAnnotationColumnSelectionState;
891 public void setIdWidth(int i)
894 AlignmentPanel ap = getAlignPanel();
897 // modify GUI elements to reflect geometry change
898 Dimension idw = ap.getIdPanel().getIdCanvas().getPreferredSize();
900 ap.getIdPanel().getIdCanvas().setPreferredSize(idw);
904 public Rectangle getExplodedGeometry()
906 return explodedGeometry;
909 public void setExplodedGeometry(Rectangle explodedPosition)
911 this.explodedGeometry = explodedPosition;
914 public boolean isGatherViewsHere()
916 return gatherViewsHere;
919 public void setGatherViewsHere(boolean gatherViewsHere)
921 this.gatherViewsHere = gatherViewsHere;
925 * If this viewport has a (Protein/cDNA) complement, then scroll the
926 * complementary alignment to match this one.
928 public void scrollComplementaryAlignment()
931 * Populate a SearchResults object with the mapped location to scroll to. If
932 * there is no complement, or it is not following highlights, or no mapping
933 * is found, the result will be empty.
935 SearchResultsI sr = new SearchResults();
936 int verticalOffset = findComplementScrollTarget(sr);
939 // TODO would like next line without cast but needs more refactoring...
940 final AlignmentPanel complementPanel = ((AlignViewport) getCodingComplement())
942 complementPanel.setToScrollComplementPanel(false);
943 complementPanel.scrollToCentre(sr, verticalOffset);
944 complementPanel.setToScrollComplementPanel(true);
949 * Answers true if no alignment holds a reference to the given mapping
954 protected boolean noReferencesTo(AlignedCodonFrame acf)
956 AlignFrame[] frames = Desktop.getAlignFrames();
961 for (AlignFrame af : frames)
965 for (AlignmentViewPanel ap : af.getAlignPanels())
967 AlignmentI al = ap.getAlignment();
968 if (al != null && al.getCodonFrames().contains(acf))
979 * Applies the supplied feature settings descriptor to currently known
980 * features. This supports an 'initial configuration' of feature colouring
981 * based on a preset or user favourite. This may then be modified in the usual
982 * way using the Feature Settings dialogue.
984 * @param featureSettings
987 public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
989 transferFeaturesStyles(featureSettings, false);
993 * Applies the supplied feature settings descriptor to currently known
994 * features. This supports an 'initial configuration' of feature colouring
995 * based on a preset or user favourite. This may then be modified in the usual
996 * way using the Feature Settings dialogue.
998 * @param featureSettings
1001 public void mergeFeaturesStyle(FeatureSettingsModelI featureSettings)
1003 transferFeaturesStyles(featureSettings, true);
1007 * when mergeOnly is set, then group and feature visibility or feature colours
1008 * are not modified for features and groups already known to the feature
1009 * renderer. Feature ordering is always adjusted, and transparency is always
1012 * @param featureSettings
1015 private void transferFeaturesStyles(FeatureSettingsModelI featureSettings,
1018 if (featureSettings == null)
1023 FeatureRenderer fr = getAlignPanel().getSeqPanel().seqCanvas
1024 .getFeatureRenderer();
1025 List<String> origRenderOrder = new ArrayList<>();
1026 List<String> origGroups = new ArrayList<>();
1027 // preserve original render order - allows differentiation between user
1028 // configured colours and autogenerated ones
1029 origRenderOrder.addAll(fr.getRenderOrder());
1030 origGroups.addAll(fr.getFeatureGroups());
1032 fr.findAllFeatures(true);
1033 List<String> renderOrder = fr.getRenderOrder();
1034 FeaturesDisplayedI displayed = fr.getFeaturesDisplayed();
1037 // only clear displayed features if we are mergeing
1038 // displayed.clear();
1040 // TODO this clears displayed.featuresRegistered - do we care?
1042 // JAL-3330 - JBP - yes we do - calling applyFeatureStyle to a view where
1043 // feature visibility has already been configured is not very friendly
1045 * set feature colour if specified by feature settings
1046 * set visibility of all features
1048 for (String type : renderOrder)
1050 FeatureColourI preferredColour = featureSettings
1051 .getFeatureColour(type);
1052 FeatureColourI origColour = fr.getFeatureStyle(type);
1053 if (!mergeOnly || (!origRenderOrder.contains(type)
1054 || origColour == null
1055 || (!origColour.isGraduatedColour()
1056 && origColour.getColour() != null
1057 && origColour.getColour().equals(
1058 ColorUtils.createColourFromName(type)))))
1060 // if we are merging, only update if there wasn't already a colour
1063 if (preferredColour != null)
1065 fr.setColour(type, preferredColour);
1067 if (featureSettings.isFeatureDisplayed(type))
1069 displayed.setVisible(type);
1071 else if (featureSettings.isFeatureHidden(type))
1073 displayed.setHidden(type);
1079 * set visibility of feature groups
1081 for (String group : fr.getFeatureGroups())
1083 if (!mergeOnly || !origGroups.contains(group))
1085 // when merging, display groups only if the aren't already marked as not
1087 fr.setGroupVisibility(group,
1088 featureSettings.isGroupDisplayed(group));
1093 * order the features
1095 if (featureSettings.optimiseOrder())
1097 // TODO not supported (yet?)
1101 fr.orderFeatures(featureSettings);
1103 fr.setTransparency(featureSettings.getTransparency());
1105 fr.notifyFeaturesChanged();
1108 public String getViewName()
1113 public void setViewName(String viewName)
1115 this.viewName = viewName;