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.renderer.ResidueShader;
43 import jalview.schemes.ColourSchemeI;
44 import jalview.schemes.ColourSchemeProperty;
45 import jalview.schemes.ResidueColourScheme;
46 import jalview.schemes.UserColourScheme;
47 import jalview.structure.SelectionSource;
48 import jalview.structure.StructureSelectionManager;
49 import jalview.structure.VamsasSource;
50 import jalview.util.ColorUtils;
51 import jalview.util.MessageManager;
52 import jalview.viewmodel.AlignmentViewport;
53 import jalview.ws.params.AutoCalcSetting;
55 import java.awt.Container;
56 import java.awt.Dimension;
58 import java.awt.FontMetrics;
59 import java.awt.Rectangle;
60 import java.util.ArrayList;
61 import java.util.Hashtable;
62 import java.util.List;
64 import javax.swing.JInternalFrame;
70 * @version $Revision: 1.141 $
72 public class AlignViewport extends AlignmentViewport
73 implements SelectionSource
77 boolean cursorMode = false;
79 boolean antiAlias = false;
81 private Rectangle explodedGeometry = null;
83 private String viewName = null;
86 * Flag set true on the view that should 'gather' multiple views of the same
87 * sequence set id when a project is reloaded. Set false on all views when
88 * they are 'exploded' into separate windows. Set true on the current view
89 * when 'Gather' is performed, and also on the first tab when the first new
92 private boolean gatherViewsHere = false;
94 private AnnotationColumnChooser annotationColumnSelectionState;
97 * Creates a new AlignViewport object.
102 public AlignViewport(AlignmentI al)
109 * Create a new AlignViewport object with a specific sequence set ID
113 * (may be null - but potential for ambiguous constructor exception)
115 public AlignViewport(AlignmentI al, String seqsetid)
117 this(al, seqsetid, null);
120 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
123 sequenceSetID = seqsetid;
125 // TODO remove these once 2.4.VAMSAS release finished
126 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
129 "Setting viewport's sequence set id : " + sequenceSetID);
131 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
133 Cache.log.debug("Setting viewport's view id : " + viewId);
140 * Create a new AlignViewport with hidden regions
144 * @param hiddenColumns
147 public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns)
150 if (hiddenColumns != null)
152 al.setHiddenColumns(hiddenColumns);
158 * New viewport with hidden columns and an existing sequence set id
161 * @param hiddenColumns
165 public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns,
168 this(al, hiddenColumns, seqsetid, null);
172 * New viewport with hidden columns and an existing sequence set id and viewid
175 * @param hiddenColumns
181 public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns,
182 String seqsetid, String viewid)
185 sequenceSetID = seqsetid;
187 // TODO remove these once 2.4.VAMSAS release finished
188 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
191 "Setting viewport's sequence set id : " + sequenceSetID);
193 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
195 Cache.log.debug("Setting viewport's view id : " + viewId);
198 if (hiddenColumns != null)
200 al.setHiddenColumns(hiddenColumns);
206 * Apply any settings saved in user preferences
208 private void applyViewProperties()
210 antiAlias = Cache.getDefault("ANTI_ALIAS", true);
212 viewStyle.setShowJVSuffix(Cache.getDefault("SHOW_JVSUFFIX", true));
213 setShowAnnotation(Cache.getDefault("SHOW_ANNOTATIONS", true));
215 setRightAlignIds(Cache.getDefault("RIGHT_ALIGN_IDS", false));
216 setCentreColumnLabels(Cache.getDefault("CENTRE_COLUMN_LABELS", false));
217 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
219 setPadGaps(Cache.getDefault("PAD_GAPS", true));
220 setShowNPFeats(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
221 setShowDBRefs(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
222 viewStyle.setSeqNameItalics(Cache.getDefault("ID_ITALICS", true));
223 viewStyle.setWrapAlignment(Cache.getDefault("WRAP_ALIGNMENT", false));
224 viewStyle.setShowUnconserved(
225 Cache.getDefault("SHOW_UNCONSERVED", false));
226 sortByTree = Cache.getDefault("SORT_BY_TREE", false);
227 followSelection = Cache.getDefault("FOLLOW_SELECTIONS", true);
228 sortAnnotationsBy = SequenceAnnotationOrder
229 .valueOf(Cache.getDefault(Preferences.SORT_ANNOTATIONS,
230 SequenceAnnotationOrder.NONE.name()));
231 showAutocalculatedAbove = Cache
232 .getDefault(Preferences.SHOW_AUTOCALC_ABOVE, false);
233 viewStyle.setScaleProteinAsCdna(
234 Cache.getDefault(Preferences.SCALE_PROTEIN_TO_CDNA, true));
239 applyViewProperties();
241 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
242 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
243 String fontSize = Cache.getDefault("FONT_SIZE", "10");
247 if (fontStyle.equals("bold"))
251 else if (fontStyle.equals("italic"))
256 setFont(new Font(fontName, style, Integer.parseInt(fontSize)), true);
259 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
261 // We must set conservation and consensus before setting colour,
262 // as Blosum and Clustal require this to be done
263 if (hconsensus == null && !isDataset)
265 if (!alignment.isNucleotide())
267 showConservation = Cache.getDefault("SHOW_CONSERVATION", true);
268 showQuality = Cache.getDefault("SHOW_QUALITY", true);
269 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
272 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
274 showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
275 normaliseSequenceLogo = Cache.getDefault("NORMALISE_CONSENSUS_LOGO",
277 showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
278 showConsensus = Cache.getDefault("SHOW_IDENTITY", true);
280 showOccupancy = Cache.getDefault(Preferences.SHOW_OCCUPANCY, true);
282 initAutoAnnotation();
283 String colourProperty = alignment.isNucleotide()
284 ? Preferences.DEFAULT_COLOUR_NUC
285 : Preferences.DEFAULT_COLOUR_PROT;
286 String schemeName = Cache.getProperty(colourProperty);
287 if (schemeName == null)
289 // only DEFAULT_COLOUR available in Jalview before 2.9
290 schemeName = Cache.getDefault(Preferences.DEFAULT_COLOUR,
291 ResidueColourScheme.NONE);
293 ColourSchemeI colourScheme = ColourSchemeProperty
294 .getColourScheme(this, alignment, schemeName);
295 residueShading = new ResidueShader(colourScheme);
297 if (colourScheme instanceof UserColourScheme)
299 residueShading = new ResidueShader(
300 UserDefinedColours.loadDefaultColours());
301 residueShading.setThreshold(0, isIgnoreGapsConsensus());
304 if (residueShading != null)
306 residueShading.setConsensus(hconsensus);
308 setColourAppliesToAllGroups(true);
311 boolean validCharWidth;
317 public void setFont(Font f, boolean setGrid)
321 Container c = new Container();
325 FontMetrics fm = c.getFontMetrics(font);
326 int ww = fm.charWidth('M');
327 setCharHeight(fm.getHeight());
330 viewStyle.setFontName(font.getName());
331 viewStyle.setFontStyle(font.getStyle());
332 viewStyle.setFontSize(font.getSize());
334 validCharWidth = true;
338 public void setViewStyle(ViewStyleI settingsForView)
340 super.setViewStyle(settingsForView);
341 setFont(new Font(viewStyle.getFontName(), viewStyle.getFontStyle(),
342 viewStyle.getFontSize()), false);
348 * @return DOCUMENT ME!
350 public Font getFont()
362 public void setAlignment(AlignmentI align)
364 replaceMappings(align);
365 super.setAlignment(align);
369 * Replace any codon mappings for this viewport with those for the given
374 public void replaceMappings(AlignmentI align)
378 * Deregister current mappings (if any)
380 deregisterMappings();
383 * Register new mappings (if any)
387 StructureSelectionManager ssm = StructureSelectionManager
388 .getStructureSelectionManager(Desktop.instance);
389 ssm.registerMappings(align.getCodonFrames());
393 * replace mappings on our alignment
395 if (alignment != null && align != null)
397 alignment.setCodonFrames(align.getCodonFrames());
401 protected void deregisterMappings()
403 AlignmentI al = getAlignment();
406 List<AlignedCodonFrame> mappings = al.getCodonFrames();
407 if (mappings != null)
409 StructureSelectionManager ssm = StructureSelectionManager
410 .getStructureSelectionManager(Desktop.instance);
411 for (AlignedCodonFrame acf : mappings)
413 if (noReferencesTo(acf))
415 ssm.deregisterMapping(acf);
425 * @return DOCUMENT ME!
428 public char getGapCharacter()
430 return getAlignment().getGapCharacter();
439 public void setGapCharacter(char gap)
441 if (getAlignment() != null)
443 getAlignment().setGapCharacter(gap);
448 * get hash of undo and redo list for the alignment
450 * @return long[] { historyList.hashCode, redoList.hashCode };
452 public long[] getUndoRedoHash()
455 if (historyList == null || redoList == null)
457 return new long[] { -1, -1 };
459 return new long[] { historyList.hashCode(), this.redoList.hashCode() };
463 * test if a particular set of hashcodes are different to the hashcodes for
464 * the undo and redo list.
467 * the stored set of hashcodes as returned by getUndoRedoHash
468 * @return true if the hashcodes differ (ie the alignment has been edited) or
469 * the stored hashcode array differs in size
471 public boolean isUndoRedoHashModified(long[] undoredo)
473 if (undoredo == null)
477 long[] cstate = getUndoRedoHash();
478 if (cstate.length != undoredo.length)
483 for (int i = 0; i < cstate.length; i++)
485 if (cstate[i] != undoredo[i])
493 public boolean followSelection = true;
496 * @return true if view selection should always follow the selections
497 * broadcast by other selection sources
499 public boolean getFollowSelection()
501 return followSelection;
505 * Send the current selection to be broadcast to any selection listeners.
508 public void sendSelection()
510 jalview.structure.StructureSelectionManager
511 .getStructureSelectionManager(Desktop.instance)
512 .sendSelection(new SequenceGroup(getSelectionGroup()),
513 new ColumnSelection(getColumnSelection()),
514 new HiddenColumns(getAlignment().getHiddenColumns()),
519 * return the alignPanel containing the given viewport. Use this to get the
520 * components currently handling the given viewport.
523 * @return null or an alignPanel guaranteed to have non-null alignFrame
526 public AlignmentPanel getAlignPanel()
528 AlignmentPanel[] aps = PaintRefresher
529 .getAssociatedPanels(this.getSequenceSetId());
530 for (int p = 0; aps != null && p < aps.length; p++)
532 if (aps[p].av == this)
540 public boolean getSortByTree()
545 public void setSortByTree(boolean sort)
551 * Returns the (Desktop) instance of the StructureSelectionManager
554 public StructureSelectionManager getStructureSelectionManager()
556 return StructureSelectionManager
557 .getStructureSelectionManager(Desktop.instance);
561 public boolean isNormaliseSequenceLogo()
563 return normaliseSequenceLogo;
566 public void setNormaliseSequenceLogo(boolean state)
568 normaliseSequenceLogo = state;
573 * @return true if alignment characters should be displayed
576 public boolean isValidCharWidth()
578 return validCharWidth;
581 private Hashtable<String, AutoCalcSetting> calcIdParams = new Hashtable<>();
583 public AutoCalcSetting getCalcIdSettingsFor(String calcId)
585 return calcIdParams.get(calcId);
588 public void setCalcIdSettingsFor(String calcId, AutoCalcSetting settings,
591 calcIdParams.put(calcId, settings);
592 // TODO: create a restart list to trigger any calculations that need to be
593 // restarted after load
594 // calculator.getRegisteredWorkersOfClass(settings.getWorkerClass())
597 Cache.log.debug("trigger update for " + calcId);
602 * Method called when another alignment's edit (or possibly other) command is
605 * To allow for sequence mappings (e.g. protein to cDNA), we have to first
606 * 'unwind' the command on the source sequences (in simulation, not in fact),
607 * and then for each edit in turn:
609 * <li>compute the equivalent edit on the mapped sequences</li>
610 * <li>apply the mapped edit</li>
611 * <li>'apply' the source edit to the working copy of the source
620 public void mirrorCommand(CommandI command, boolean undo,
621 StructureSelectionManager ssm, VamsasSource source)
624 * Do nothing unless we are a 'complement' of the source. May replace this
625 * with direct calls not via SSM.
627 if (source instanceof AlignViewportI
628 && ((AlignViewportI) source).getCodingComplement() == this)
637 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
639 if (mappedCommand != null)
641 AlignmentI[] views = getAlignPanel().alignFrame.getViewAlignments();
642 mappedCommand.doCommand(views);
643 getAlignPanel().alignmentChanged();
648 * Add the sequences from the given alignment to this viewport. Optionally,
649 * may give the user the option to open a new frame, or split panel, with cDNA
650 * and protein linked.
655 public void addAlignment(AlignmentI toAdd, String title)
657 // TODO: promote to AlignViewportI? applet CutAndPasteTransfer is different
659 // JBPComment: title is a largely redundant parameter at the moment
660 // JBPComment: this really should be an 'insert/pre/append' controller
661 // JBPComment: but the DNA/Protein check makes it a bit more complex
663 // refactored from FileLoader / CutAndPasteTransfer / SequenceFetcher with
665 // TODO: create undo object for this JAL-1101
668 * Ensure datasets are created for the new alignment as
669 * mappings operate on dataset sequences
671 toAdd.setDataset(null);
674 * Check if any added sequence could be the object of a mapping or
675 * cross-reference; if so, make the mapping explicit
677 getAlignment().realiseMappings(toAdd.getSequences());
680 * If any cDNA/protein mappings exist or can be made between the alignments,
681 * offer to open a split frame with linked alignments
683 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
685 if (AlignmentUtils.isMappable(toAdd, getAlignment()))
687 if (openLinkedAlignment(toAdd, title))
695 * No mappings, or offer declined - add sequences to this alignment
697 // TODO: JAL-407 regardless of above - identical sequences (based on ID and
698 // provenance) should share the same dataset sequence
700 AlignmentI al = getAlignment();
701 String gap = String.valueOf(al.getGapCharacter());
702 for (int i = 0; i < toAdd.getHeight(); i++)
704 SequenceI seq = toAdd.getSequenceAt(i);
707 * - 'align' any mapped sequences as per existing
708 * e.g. cdna to genome, domain hit to protein sequence
709 * very experimental! (need a separate menu option for this)
710 * - only add mapped sequences ('select targets from a dataset')
712 if (true /*AlignmentUtils.alignSequenceAs(seq, al, gap, true, true)*/)
718 ranges.setEndSeq(getAlignment().getHeight());
719 firePropertyChange("alignment", null, getAlignment().getSequences());
723 * Show a dialog with the option to open and link (cDNA <-> protein) as a new
724 * alignment, either as a standalone alignment or in a split frame. Returns
725 * true if the new alignment was opened, false if not, because the user
726 * declined the offer.
731 protected boolean openLinkedAlignment(AlignmentI al, String title)
733 String[] options = new String[] { MessageManager.getString("action.no"),
734 MessageManager.getString("label.split_window"),
735 MessageManager.getString("label.new_window"), };
736 final String question = JvSwingUtils.wrapTooltip(true,
737 MessageManager.getString("label.open_split_window?"));
738 int response = JvOptionPane.showOptionDialog(Desktop.desktop, question,
739 MessageManager.getString("label.open_split_window"),
740 JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
741 options, options[0]);
743 if (response != 1 && response != 2)
747 final boolean openSplitPane = (response == 1);
748 final boolean openInNewWindow = (response == 2);
751 * Identify protein and dna alignments. Make a copy of this one if opening
752 * in a new split pane.
754 AlignmentI thisAlignment = openSplitPane ? new Alignment(getAlignment())
756 AlignmentI protein = al.isNucleotide() ? thisAlignment : al;
757 final AlignmentI cdna = al.isNucleotide() ? al : thisAlignment;
760 * Map sequences. At least one should get mapped as we have already passed
761 * the test for 'mappability'. Any mappings made will be added to the
762 * protein alignment. Note creating dataset sequences on the new alignment
763 * is a pre-requisite for building mappings.
766 AlignmentUtils.mapProteinAlignmentToCdna(protein, cdna);
769 * Create the AlignFrame for the added alignment. If it is protein, mappings
770 * are registered with StructureSelectionManager as a side-effect.
772 AlignFrame newAlignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
773 AlignFrame.DEFAULT_HEIGHT);
774 newAlignFrame.setTitle(title);
775 newAlignFrame.setStatus(MessageManager
776 .formatMessage("label.successfully_loaded_file", new Object[]
779 // TODO if we want this (e.g. to enable reload of the alignment from file),
780 // we will need to add parameters to the stack.
781 // if (!protocol.equals(DataSourceType.PASTE))
783 // alignFrame.setFileName(file, format);
788 Desktop.addInternalFrame(newAlignFrame, title,
789 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
794 newAlignFrame.setMaximum(
795 jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false));
796 } catch (java.beans.PropertyVetoException ex)
802 al.alignAs(thisAlignment);
803 protein = openSplitFrame(newAlignFrame, thisAlignment);
810 * Helper method to open a new SplitFrame holding linked dna and protein
813 * @param newAlignFrame
814 * containing a new alignment to be shown
816 * cdna/protein complement alignment to show in the other split half
817 * @return the protein alignment in the split frame
819 protected AlignmentI openSplitFrame(AlignFrame newAlignFrame,
820 AlignmentI complement)
823 * Make a new frame with a copy of the alignment we are adding to. If this
824 * is protein, the mappings to cDNA will be registered with
825 * StructureSelectionManager as a side-effect.
827 AlignFrame copyMe = new AlignFrame(complement, AlignFrame.DEFAULT_WIDTH,
828 AlignFrame.DEFAULT_HEIGHT);
829 copyMe.setTitle(getAlignPanel().alignFrame.getTitle());
831 AlignmentI al = newAlignFrame.viewport.getAlignment();
832 final AlignFrame proteinFrame = al.isNucleotide() ? copyMe
834 final AlignFrame cdnaFrame = al.isNucleotide() ? newAlignFrame : copyMe;
835 cdnaFrame.setVisible(true);
836 proteinFrame.setVisible(true);
837 String linkedTitle = MessageManager
838 .getString("label.linked_view_title");
841 * Open in split pane. DNA sequence above, protein below.
843 JInternalFrame splitFrame = new SplitFrame(cdnaFrame, proteinFrame);
844 Desktop.addInternalFrame(splitFrame, linkedTitle, -1, -1);
846 return proteinFrame.viewport.getAlignment();
849 public AnnotationColumnChooser getAnnotationColumnSelectionState()
851 return annotationColumnSelectionState;
854 public void setAnnotationColumnSelectionState(
855 AnnotationColumnChooser currentAnnotationColumnSelectionState)
857 this.annotationColumnSelectionState = currentAnnotationColumnSelectionState;
861 public void setIdWidth(int i)
864 AlignmentPanel ap = getAlignPanel();
867 // modify GUI elements to reflect geometry change
868 Dimension idw = ap.getIdPanel().getIdCanvas().getPreferredSize();
870 ap.getIdPanel().getIdCanvas().setPreferredSize(idw);
874 public Rectangle getExplodedGeometry()
876 return explodedGeometry;
879 public void setExplodedGeometry(Rectangle explodedPosition)
881 this.explodedGeometry = explodedPosition;
884 public boolean isGatherViewsHere()
886 return gatherViewsHere;
889 public void setGatherViewsHere(boolean gatherViewsHere)
891 this.gatherViewsHere = gatherViewsHere;
895 * If this viewport has a (Protein/cDNA) complement, then scroll the
896 * complementary alignment to match this one.
898 public void scrollComplementaryAlignment()
901 * Populate a SearchResults object with the mapped location to scroll to. If
902 * there is no complement, or it is not following highlights, or no mapping
903 * is found, the result will be empty.
905 SearchResultsI sr = new SearchResults();
906 int verticalOffset = findComplementScrollTarget(sr);
909 // TODO would like next line without cast but needs more refactoring...
910 final AlignmentPanel complementPanel = ((AlignViewport) getCodingComplement())
912 complementPanel.setToScrollComplementPanel(false);
913 complementPanel.scrollToCentre(sr, verticalOffset);
914 complementPanel.setToScrollComplementPanel(true);
919 * Answers true if no alignment holds a reference to the given mapping
924 protected boolean noReferencesTo(AlignedCodonFrame acf)
926 AlignFrame[] frames = Desktop.getAlignFrames();
931 for (AlignFrame af : frames)
935 for (AlignmentViewPanel ap : af.getAlignPanels())
937 AlignmentI al = ap.getAlignment();
938 if (al != null && al.getCodonFrames().contains(acf))
949 * Applies the supplied feature settings descriptor to currently known
950 * features. This supports an 'initial configuration' of feature colouring
951 * based on a preset or user favourite. This may then be modified in the usual
952 * way using the Feature Settings dialogue.
954 * @param featureSettings
957 public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
959 transferFeaturesStyles(featureSettings, false);
963 * Applies the supplied feature settings descriptor to currently known features.
964 * This supports an 'initial configuration' of feature colouring based on a
965 * preset or user favourite. This may then be modified in the usual way using
966 * the Feature Settings dialogue.
968 * @param featureSettings
971 public void mergeFeaturesStyle(FeatureSettingsModelI featureSettings)
973 transferFeaturesStyles(featureSettings, true);
977 * when mergeOnly is set, then group and feature visibility or feature colours
978 * are not modified for features and groups already known to the feature
979 * renderer. Feature ordering is always adjusted, and transparency is always set
982 * @param featureSettings
985 private void transferFeaturesStyles(FeatureSettingsModelI featureSettings,
988 if (featureSettings == null)
993 FeatureRenderer fr = getAlignPanel().getSeqPanel().seqCanvas
994 .getFeatureRenderer();
995 List<String> origRenderOrder = new ArrayList<>();
996 List<String> origGroups = new ArrayList<>();
997 // preserve original render order - allows differentiation between user configured colours and autogenerated ones
998 origRenderOrder.addAll(fr.getRenderOrder());
999 origGroups.addAll(fr.getFeatureGroups());
1001 fr.findAllFeatures(true);
1002 List<String> renderOrder = fr.getRenderOrder();
1003 FeaturesDisplayedI displayed = fr.getFeaturesDisplayed();
1006 // only clear displayed features if we are mergeing
1007 // displayed.clear();
1009 // TODO this clears displayed.featuresRegistered - do we care?
1011 // JAL-3330 - JBP - yes we do - calling applyFeatureStyle to a view where
1012 // feature visibility has already been configured is not very friendly
1014 * set feature colour if specified by feature settings
1015 * set visibility of all features
1017 for (String type : renderOrder)
1019 FeatureColourI preferredColour = featureSettings
1020 .getFeatureColour(type);
1021 FeatureColourI origColour = fr.getFeatureStyle(type);
1022 if (!mergeOnly || (!origRenderOrder.contains(type)
1023 || origColour == null
1024 || (!origColour.isGraduatedColour()
1025 && origColour.getColour() != null
1026 && origColour.getColour().equals(
1027 ColorUtils.createColourFromName(type)))))
1029 // if we are merging, only update if there wasn't already a colour defined for
1031 if (preferredColour != null)
1033 fr.setColour(type, preferredColour);
1035 if (featureSettings.isFeatureDisplayed(type))
1037 displayed.setVisible(type);
1039 else if (featureSettings.isFeatureHidden(type))
1041 displayed.setHidden(type);
1047 * set visibility of feature groups
1049 for (String group : fr.getFeatureGroups())
1051 if (!mergeOnly || !origGroups.contains(group))
1053 // when merging, display groups only if the aren't already marked as not visible
1054 fr.setGroupVisibility(group,
1055 featureSettings.isGroupDisplayed(group));
1060 * order the features
1062 if (featureSettings.optimiseOrder())
1064 // TODO not supported (yet?)
1068 fr.orderFeatures(featureSettings);
1070 fr.setTransparency(featureSettings.getTransparency());
1072 fr.notifyFeaturesChanged();
1075 public String getViewName()
1080 public void setViewName(String viewName)
1082 this.viewName = viewName;