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<AlignmentPanel>
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()),
532 public boolean getSortByTree()
537 public void setSortByTree(boolean sort)
543 * Returns the (Desktop) instance of the StructureSelectionManager
546 public StructureSelectionManager getStructureSelectionManager()
548 return StructureSelectionManager
549 .getStructureSelectionManager(Desktop.getInstance());
554 public boolean isNormaliseSequenceLogo()
556 return normaliseSequenceLogo;
560 public void setNormaliseSequenceLogo(boolean state)
562 normaliseSequenceLogo = state;
567 * @return true if alignment characters should be displayed
570 public boolean isValidCharWidth()
572 return validCharWidth;
576 private Hashtable<String, AutoCalcSetting> calcIdParams = new Hashtable<>();
578 public AutoCalcSetting getCalcIdSettingsFor(String calcId)
580 return calcIdParams.get(calcId);
583 public void setCalcIdSettingsFor(String calcId, AutoCalcSetting settings,
586 calcIdParams.put(calcId, settings);
587 // TODO: create a restart list to trigger any calculations that need to be
588 // restarted after load
589 // calculator.getRegisteredWorkersOfClass(settings.getWorkerClass())
592 Console.debug("trigger update for " + calcId);
597 * Method called when another alignment's edit (or possibly other) command is
600 * To allow for sequence mappings (e.g. protein to cDNA), we have to first
601 * 'unwind' the command on the source sequences (in simulation, not in fact),
602 * and then for each edit in turn:
604 * <li>compute the equivalent edit on the mapped sequences</li>
605 * <li>apply the mapped edit</li>
606 * <li>'apply' the source edit to the working copy of the source
615 public void mirrorCommand(CommandI command, boolean undo,
616 StructureSelectionManager ssm, VamsasSource source)
619 * Do nothing unless we are a 'complement' of the source. May replace this
620 * with direct calls not via SSM.
622 if (source instanceof AlignViewportI
623 && ((AlignViewportI) source).getCodingComplement() == this)
632 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
634 if (mappedCommand != null)
636 AlignmentI[] views = getAlignPanel().alignFrame.getViewAlignments();
637 mappedCommand.doCommand(views);
638 getAlignPanel().alignmentChanged();
643 * Add the sequences from the given alignment to this viewport. Optionally,
644 * may give the user the option to open a new frame, or split panel, with cDNA
645 * and protein linked.
650 public void addAlignment(AlignmentI toAdd, String title)
652 // TODO: promote to AlignViewportI? applet CutAndPasteTransfer is different
654 // JBPComment: title is a largely redundant parameter at the moment
655 // JBPComment: this really should be an 'insert/pre/append' controller
656 // JBPComment: but the DNA/Protein check makes it a bit more complex
658 // refactored from FileLoader / CutAndPasteTransfer / SequenceFetcher with
660 // TODO: create undo object for this JAL-1101
663 * Ensure datasets are created for the new alignment as
664 * mappings operate on dataset sequences
666 toAdd.setDataset(null);
669 * Check if any added sequence could be the object of a mapping or
670 * cross-reference; if so, make the mapping explicit
672 getAlignment().realiseMappings(toAdd.getSequences());
675 * If any cDNA/protein mappings exist or can be made between the alignments,
676 * offer to open a split frame with linked alignments
678 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
680 if (AlignmentUtils.isMappable(toAdd, getAlignment()))
682 openLinkedAlignment(toAdd, title);
686 addDataToAlignment(toAdd);
690 * adds sequences to this alignment
694 void addDataToAlignment(AlignmentI toAdd)
696 // TODO: JAL-407 regardless of above - identical sequences (based on ID and
697 // provenance) should share the same dataset sequence
699 AlignmentI al = getAlignment();
700 String gap = String.valueOf(al.getGapCharacter());
701 for (int i = 0; i < toAdd.getHeight(); i++)
703 SequenceI seq = toAdd.getSequenceAt(i);
706 * - 'align' any mapped sequences as per existing
707 * e.g. cdna to genome, domain hit to protein sequence
708 * very experimental! (need a separate menu option for this)
709 * - only add mapped sequences ('select targets from a dataset')
711 if (true /*AlignmentUtils.alignSequenceAs(seq, al, gap, true, true)*/)
717 ranges.setEndSeq(getAlignment().getHeight() - 1); // BH 2019.04.18
722 * Show a dialog with the option to open and link (cDNA <-> protein) as a new
723 * alignment, either as a standalone alignment or in a split frame. Returns
724 * true if the new alignment was opened, false if not, because the user
725 * declined the offer.
730 protected void openLinkedAlignment(AlignmentI al, String title)
732 String[] options = new String[] { MessageManager.getString("action.no"),
733 MessageManager.getString("label.split_window"),
734 MessageManager.getString("label.new_window"), };
735 final String question = JvSwingUtils.wrapTooltip(true,
736 MessageManager.getString("label.open_split_window?"));
737 final AlignViewport us = this;
740 * options No, Split Window, New Window correspond to
741 * dialog responses 0, 1, 2 (even though JOptionPane shows them
744 JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.getDesktopPane())
745 .setResponseHandler(NO_SPLIT, new Runnable()
750 addDataToAlignment(al);
752 }).setResponseHandler(SPLIT_FRAME, new Runnable()
757 // Make a copy of this one to open it in a splitframe
758 openLinkedAlignmentAs(getAlignPanel().alignFrame,
759 new Alignment(getAlignment()), al, title,
762 }).setResponseHandler(NEW_WINDOW, new Runnable()
767 openLinkedAlignmentAs(null, getAlignment(), al, title,
771 dialog.showDialog(question,
772 MessageManager.getString("label.open_split_window"),
773 JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
774 options, options[0]);
778 * Open a split frame or a new window
783 * SPLIT_FRAME or NEW_WINDOW
785 public static void openLinkedAlignmentAs(AlignFrame thisFrame,
786 AlignmentI thisAlignment, AlignmentI al, String title, int mode)
789 * Identify protein and dna alignments.
791 AlignmentI protein = al.isNucleotide() ? thisAlignment : al;
792 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);
821 if (mode == NEW_WINDOW)
823 Desktop.addInternalFrame(newAlignFrame, title,
824 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
829 newAlignFrame.setMaximum(Cache.getDefault("SHOW_FULLSCREEN", false));
830 } catch (java.beans.PropertyVetoException ex)
834 if (mode == SPLIT_FRAME)
836 al.alignAs(thisAlignment);
837 openSplitFrame(thisFrame, newAlignFrame, thisAlignment);
842 * Helper method to open a new SplitFrame holding linked dna and protein
845 * @param newAlignFrame
846 * containing a new alignment to be shown
848 * cdna/protein complement alignment to show in the other split half
849 * @return the protein alignment in the split frame
851 static protected AlignmentI openSplitFrame(AlignFrame thisFrame,
852 AlignFrame newAlignFrame, AlignmentI complement)
855 * Make a new frame with a copy of the alignment we are adding to. If this
856 * is protein, the mappings to cDNA will be registered with
857 * StructureSelectionManager as a side-effect.
859 AlignFrame copyMe = new AlignFrame(complement, AlignFrame.DEFAULT_WIDTH,
860 AlignFrame.DEFAULT_HEIGHT);
861 copyMe.setTitle(thisFrame.getTitle());
863 AlignmentI al = newAlignFrame.viewport.getAlignment();
864 final AlignFrame proteinFrame = al.isNucleotide() ? copyMe
866 final AlignFrame cdnaFrame = al.isNucleotide() ? newAlignFrame : copyMe;
867 cdnaFrame.setVisible(true);
868 proteinFrame.setVisible(true);
869 String linkedTitle = MessageManager
870 .getString("label.linked_view_title");
873 * Open in split pane. DNA sequence above, protein below.
875 JInternalFrame splitFrame = new SplitFrame(cdnaFrame, proteinFrame);
876 Desktop.addInternalFrame(splitFrame, linkedTitle, -1, -1);
878 return proteinFrame.viewport.getAlignment();
881 public AnnotationColumnChooser getAnnotationColumnSelectionState()
883 return annotationColumnSelectionState;
886 public void setAnnotationColumnSelectionState(
887 AnnotationColumnChooser currentAnnotationColumnSelectionState)
889 this.annotationColumnSelectionState = currentAnnotationColumnSelectionState;
893 public void setIdWidth(int i)
896 AlignmentPanel ap = getAlignPanel();
899 // modify GUI elements to reflect geometry change
900 Dimension idw = ap.getIdPanel().getIdCanvas().getPreferredSize();
902 ap.getIdPanel().getIdCanvas().setPreferredSize(idw);
906 public Rectangle getExplodedGeometry()
908 return explodedGeometry;
911 public void setExplodedGeometry(Rectangle explodedPosition)
913 this.explodedGeometry = explodedPosition;
916 public boolean isGatherViewsHere()
918 return gatherViewsHere;
921 public void setGatherViewsHere(boolean gatherViewsHere)
923 this.gatherViewsHere = gatherViewsHere;
927 * If this viewport has a (Protein/cDNA) complement, then scroll the
928 * complementary alignment to match this one.
930 public void scrollComplementaryAlignment()
933 * Populate a SearchResults object with the mapped location to scroll to. If
934 * there is no complement, or it is not following highlights, or no mapping
935 * is found, the result will be empty.
937 SearchResultsI sr = new SearchResults();
938 int verticalOffset = findComplementScrollTarget(sr);
941 // TODO would like next line without cast but needs more refactoring...
942 final AlignmentPanel complementPanel = ((AlignViewport) getCodingComplement())
944 complementPanel.setToScrollComplementPanel(false);
945 complementPanel.scrollToCentre(sr, verticalOffset);
946 complementPanel.setToScrollComplementPanel(true);
951 * Answers true if no alignment holds a reference to the given mapping
956 protected boolean noReferencesTo(AlignedCodonFrame acf)
958 AlignFrame[] frames = Desktop.getAlignFrames();
963 for (AlignFrame af : frames)
967 for (AlignmentViewPanel ap : af.getAlignPanels())
969 AlignmentI al = ap.getAlignment();
970 if (al != null && al.getCodonFrames().contains(acf))
981 * Applies the supplied feature settings descriptor to currently known
982 * features. This supports an 'initial configuration' of feature colouring
983 * based on a preset or user favourite. This may then be modified in the usual
984 * way using the Feature Settings dialogue.
986 * @param featureSettings
989 public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
991 transferFeaturesStyles(featureSettings, false);
995 * Applies the supplied feature settings descriptor to currently known
996 * features. This supports an 'initial configuration' of feature colouring
997 * based on a preset or user favourite. This may then be modified in the usual
998 * way using the Feature Settings dialogue.
1000 * @param featureSettings
1003 public void mergeFeaturesStyle(FeatureSettingsModelI featureSettings)
1005 transferFeaturesStyles(featureSettings, true);
1009 * when mergeOnly is set, then group and feature visibility or feature colours
1010 * are not modified for features and groups already known to the feature
1011 * renderer. Feature ordering is always adjusted, and transparency is always
1014 * @param featureSettings
1017 private void transferFeaturesStyles(FeatureSettingsModelI featureSettings,
1020 if (featureSettings == null)
1024 FeatureRenderer fr = getAlignPanel().getSeqPanel().seqCanvas
1025 .getFeatureRenderer();
1026 List<String> origRenderOrder = new ArrayList(),
1027 origGroups = new ArrayList();
1028 // preserve original render order - allows differentiation between user
1029 // configured colours and autogenerated ones
1030 origRenderOrder.addAll(fr.getRenderOrder());
1031 origGroups.addAll(fr.getFeatureGroups());
1033 fr.findAllFeatures(true);
1034 List<String> renderOrder = fr.getRenderOrder();
1035 FeaturesDisplayedI displayed = fr.getFeaturesDisplayed();
1038 // only clear displayed features if we are mergeing
1041 // TODO this clears displayed.featuresRegistered - do we care?
1043 // JAL-3330 - JBP - yes we do - calling applyFeatureStyle to a view where
1044 // feature visibility has already been configured is not very friendly
1046 * set feature colour if specified by feature settings
1047 * set visibility of all features
1049 for (String type : renderOrder)
1051 FeatureColourI preferredColour = featureSettings
1052 .getFeatureColour(type);
1053 FeatureMatcherSetI preferredFilters = featureSettings
1054 .getFeatureFilters(type);
1055 FeatureColourI origColour = fr.getFeatureStyle(type);
1056 if (!mergeOnly || (!origRenderOrder.contains(type)
1057 || origColour == null
1058 || (!origColour.isGraduatedColour()
1059 && origColour.getColour() != null
1060 && origColour.getColour().equals(
1061 ColorUtils.createColourFromName(type)))))
1063 // if we are merging, only update if there wasn't already a colour
1066 if (preferredColour != null)
1068 fr.setColour(type, preferredColour);
1070 if (preferredFilters != null
1071 && (!mergeOnly || fr.getFeatureFilter(type) != null))
1073 fr.setFeatureFilter(type, preferredFilters);
1075 if (featureSettings.isFeatureDisplayed(type))
1077 displayed.setVisible(type);
1079 else if (featureSettings.isFeatureHidden(type))
1081 displayed.setHidden(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
1095 fr.setGroupVisibility(group,
1096 featureSettings.isGroupDisplayed(group));
1101 * order the features
1103 if (featureSettings.optimiseOrder())
1105 // TODO not supported (yet?)
1109 fr.orderFeatures(featureSettings);
1111 fr.setTransparency(featureSettings.getTransparency());
1113 fr.notifyFeaturesChanged();
1116 public String getViewName()
1121 public void setViewName(String viewName)
1123 this.viewName = viewName;