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.Iterator;
63 import java.util.List;
65 import javax.swing.JInternalFrame;
71 * @version $Revision: 1.141 $
73 public class AlignViewport extends AlignmentViewport
74 implements SelectionSource
77 public final static int NO_SPLIT = 0;
79 public final static int SPLIT_FRAME = 1;
81 public final static int NEW_WINDOW = 2;
86 boolean cursorMode = false;
88 boolean antiAlias = false;
90 private Rectangle explodedGeometry = null;
92 private String viewName = null;
95 * Flag set true on the view that should 'gather' multiple views of the same
96 * sequence set id when a project is reloaded. Set false on all views when
97 * they are 'exploded' into separate windows. Set true on the current view
98 * when 'Gather' is performed, and also on the first tab when the first new
101 private boolean gatherViewsHere = false;
103 private AnnotationColumnChooser annotationColumnSelectionState;
106 * Creates a new AlignViewport object.
111 public AlignViewport(AlignmentI al)
118 * Create a new AlignViewport object with a specific sequence set ID
122 * (may be null - but potential for ambiguous constructor exception)
124 public AlignViewport(AlignmentI al, String seqsetid)
126 this(al, seqsetid, null);
129 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
132 sequenceSetID = seqsetid;
134 // TODO remove these once 2.4.VAMSAS release finished
135 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
138 "Setting viewport's sequence set id : " + sequenceSetID);
140 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
142 Cache.log.debug("Setting viewport's view id : " + viewId);
149 * Create a new AlignViewport with hidden regions
153 * @param hiddenColumns
156 public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns)
159 if (hiddenColumns != null)
161 al.setHiddenColumns(hiddenColumns);
167 * New viewport with hidden columns and an existing sequence set id
170 * @param hiddenColumns
174 public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns,
177 this(al, hiddenColumns, seqsetid, null);
181 * New viewport with hidden columns and an existing sequence set id and viewid
184 * @param hiddenColumns
190 public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns,
191 String seqsetid, String viewid)
194 sequenceSetID = seqsetid;
196 // TODO remove these once 2.4.VAMSAS release finished
197 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
200 "Setting viewport's sequence set id : " + sequenceSetID);
202 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
204 Cache.log.debug("Setting viewport's view id : " + viewId);
207 if (hiddenColumns != null)
209 al.setHiddenColumns(hiddenColumns);
215 * Apply any settings saved in user preferences
217 private void applyViewProperties()
219 antiAlias = Cache.getDefault("ANTI_ALIAS", true);
221 viewStyle.setShowJVSuffix(Cache.getDefault("SHOW_JVSUFFIX", true));
222 setShowAnnotation(Cache.getDefault("SHOW_ANNOTATIONS", true));
224 setRightAlignIds(Cache.getDefault("RIGHT_ALIGN_IDS", false));
225 setCentreColumnLabels(Cache.getDefault("CENTRE_COLUMN_LABELS", false));
226 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
228 setPadGaps(Cache.getDefault("PAD_GAPS", true));
229 setShowNPFeats(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
230 setShowDBRefs(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
231 viewStyle.setSeqNameItalics(Cache.getDefault("ID_ITALICS", true));
232 viewStyle.setWrapAlignment(Cache.getDefault("WRAP_ALIGNMENT", false));
233 viewStyle.setShowUnconserved(
234 Cache.getDefault("SHOW_UNCONSERVED", false));
235 sortByTree = Cache.getDefault("SORT_BY_TREE", false);
236 followSelection = Cache.getDefault("FOLLOW_SELECTIONS", true);
237 sortAnnotationsBy = SequenceAnnotationOrder
238 .valueOf(Cache.getDefault(Preferences.SORT_ANNOTATIONS,
239 SequenceAnnotationOrder.NONE.name()));
240 showAutocalculatedAbove = Cache
241 .getDefault(Preferences.SHOW_AUTOCALC_ABOVE, false);
242 viewStyle.setScaleProteinAsCdna(
243 Cache.getDefault(Preferences.SCALE_PROTEIN_TO_CDNA, true));
248 applyViewProperties();
250 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
251 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
252 String fontSize = Cache.getDefault("FONT_SIZE", "10");
256 if (fontStyle.equals("bold"))
260 else if (fontStyle.equals("italic"))
265 setFont(new Font(fontName, style, Integer.parseInt(fontSize)), true);
268 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
270 // We must set conservation and consensus before setting colour,
271 // as Blosum and Clustal require this to be done
272 if (hconsensus == null && !isDataset)
274 if (!alignment.isNucleotide())
276 showConservation = Cache.getDefault("SHOW_CONSERVATION", true);
277 showQuality = Cache.getDefault("SHOW_QUALITY", true);
278 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
281 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
283 showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
284 normaliseSequenceLogo = Cache.getDefault("NORMALISE_CONSENSUS_LOGO",
286 showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
287 showConsensus = Cache.getDefault("SHOW_IDENTITY", true);
289 showOccupancy = Cache.getDefault(Preferences.SHOW_OCCUPANCY, true);
291 initAutoAnnotation();
292 String colourProperty = alignment.isNucleotide()
293 ? Preferences.DEFAULT_COLOUR_NUC
294 : Preferences.DEFAULT_COLOUR_PROT;
295 String schemeName = Cache.getProperty(colourProperty);
296 if (schemeName == null)
298 // only DEFAULT_COLOUR available in Jalview before 2.9
299 schemeName = Cache.getDefault(Preferences.DEFAULT_COLOUR,
300 ResidueColourScheme.NONE);
302 ColourSchemeI colourScheme = ColourSchemeProperty
303 .getColourScheme(this, alignment, schemeName);
304 residueShading = new ResidueShader(colourScheme);
306 if (colourScheme instanceof UserColourScheme)
308 residueShading = new ResidueShader(
309 UserDefinedColours.loadDefaultColours());
310 residueShading.setThreshold(0, isIgnoreGapsConsensus());
313 if (residueShading != null)
315 residueShading.setConsensus(hconsensus);
317 setColourAppliesToAllGroups(true);
320 boolean validCharWidth;
326 public void setFont(Font f, boolean setGrid)
330 Container c = new Container();
334 FontMetrics fm = c.getFontMetrics(font);
335 int ww = fm.charWidth('M');
336 setCharHeight(fm.getHeight());
339 viewStyle.setFontName(font.getName());
340 viewStyle.setFontStyle(font.getStyle());
341 viewStyle.setFontSize(font.getSize());
343 validCharWidth = true;
347 public void setViewStyle(ViewStyleI settingsForView)
349 super.setViewStyle(settingsForView);
350 setFont(new Font(viewStyle.getFontName(), viewStyle.getFontStyle(),
351 viewStyle.getFontSize()), false);
357 * @return DOCUMENT ME!
359 public Font getFont()
371 public void setAlignment(AlignmentI align)
373 replaceMappings(align);
374 super.setAlignment(align);
378 * Replace any codon mappings for this viewport with those for the given
383 public void replaceMappings(AlignmentI align)
387 * Deregister current mappings (if any)
389 deregisterMappings();
392 * Register new mappings (if any)
396 StructureSelectionManager ssm = StructureSelectionManager
397 .getStructureSelectionManager(Desktop.instance);
398 ssm.registerMappings(align.getCodonFrames());
402 * replace mappings on our alignment
404 if (alignment != null && align != null)
406 alignment.setCodonFrames(align.getCodonFrames());
410 protected void deregisterMappings()
412 AlignmentI al = getAlignment();
415 List<AlignedCodonFrame> mappings = al.getCodonFrames();
416 if (mappings != null)
418 StructureSelectionManager ssm = StructureSelectionManager
419 .getStructureSelectionManager(Desktop.instance);
420 for (AlignedCodonFrame acf : mappings)
422 if (noReferencesTo(acf))
424 ssm.deregisterMapping(acf);
434 * @return DOCUMENT ME!
437 public char getGapCharacter()
439 return getAlignment().getGapCharacter();
448 public void setGapCharacter(char gap)
450 if (getAlignment() != null)
452 getAlignment().setGapCharacter(gap);
457 * returns the visible column regions of the alignment
459 * @param selectedRegionOnly
460 * true to just return the contigs intersecting with the selected
464 public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
468 if (selectedRegionOnly && selectionGroup != null)
470 start = selectionGroup.getStartRes();
471 end = selectionGroup.getEndRes() + 1;
475 end = alignment.getWidth();
477 return (alignment.getHiddenColumns().getVisContigsIterator(start, end,
482 * get hash of undo and redo list for the alignment
484 * @return long[] { historyList.hashCode, redoList.hashCode };
486 public long[] getUndoRedoHash()
489 if (historyList == null || redoList == null)
491 return new long[] { -1, -1 };
493 return new long[] { historyList.hashCode(), this.redoList.hashCode() };
497 * test if a particular set of hashcodes are different to the hashcodes for
498 * the undo and redo list.
501 * the stored set of hashcodes as returned by getUndoRedoHash
502 * @return true if the hashcodes differ (ie the alignment has been edited) or
503 * the stored hashcode array differs in size
505 public boolean isUndoRedoHashModified(long[] undoredo)
507 if (undoredo == null)
511 long[] cstate = getUndoRedoHash();
512 if (cstate.length != undoredo.length)
517 for (int i = 0; i < cstate.length; i++)
519 if (cstate[i] != undoredo[i])
527 public boolean followSelection = true;
530 * @return true if view selection should always follow the selections
531 * broadcast by other selection sources
533 public boolean getFollowSelection()
535 return followSelection;
539 * Send the current selection to be broadcast to any selection listeners.
542 public void sendSelection()
544 jalview.structure.StructureSelectionManager
545 .getStructureSelectionManager(Desktop.instance)
546 .sendSelection(new SequenceGroup(getSelectionGroup()),
547 new ColumnSelection(getColumnSelection()),
548 new HiddenColumns(getAlignment().getHiddenColumns()),
553 * return the alignPanel containing the given viewport. Use this to get the
554 * components currently handling the given viewport.
557 * @return null or an alignPanel guaranteed to have non-null alignFrame
560 public AlignmentPanel getAlignPanel()
562 AlignmentPanel[] aps = PaintRefresher
563 .getAssociatedPanels(this.getSequenceSetId());
564 for (int p = 0; aps != null && p < aps.length; p++)
566 if (aps[p].av == this)
574 public boolean getSortByTree()
579 public void setSortByTree(boolean sort)
585 * Returns the (Desktop) instance of the StructureSelectionManager
588 public StructureSelectionManager getStructureSelectionManager()
590 return StructureSelectionManager
591 .getStructureSelectionManager(Desktop.instance);
595 public boolean isNormaliseSequenceLogo()
597 return normaliseSequenceLogo;
600 public void setNormaliseSequenceLogo(boolean state)
602 normaliseSequenceLogo = state;
607 * @return true if alignment characters should be displayed
610 public boolean isValidCharWidth()
612 return validCharWidth;
615 private Hashtable<String, AutoCalcSetting> calcIdParams = new Hashtable<>();
617 public AutoCalcSetting getCalcIdSettingsFor(String calcId)
619 return calcIdParams.get(calcId);
622 public void setCalcIdSettingsFor(String calcId, AutoCalcSetting settings,
625 calcIdParams.put(calcId, settings);
626 // TODO: create a restart list to trigger any calculations that need to be
627 // restarted after load
628 // calculator.getRegisteredWorkersOfClass(settings.getWorkerClass())
631 Cache.log.debug("trigger update for " + calcId);
636 * Method called when another alignment's edit (or possibly other) command is
639 * To allow for sequence mappings (e.g. protein to cDNA), we have to first
640 * 'unwind' the command on the source sequences (in simulation, not in fact),
641 * and then for each edit in turn:
643 * <li>compute the equivalent edit on the mapped sequences</li>
644 * <li>apply the mapped edit</li>
645 * <li>'apply' the source edit to the working copy of the source
654 public void mirrorCommand(CommandI command, boolean undo,
655 StructureSelectionManager ssm, VamsasSource source)
658 * Do nothing unless we are a 'complement' of the source. May replace this
659 * with direct calls not via SSM.
661 if (source instanceof AlignViewportI
662 && ((AlignViewportI) source).getCodingComplement() == this)
671 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
673 if (mappedCommand != null)
675 AlignmentI[] views = getAlignPanel().alignFrame.getViewAlignments();
676 mappedCommand.doCommand(views);
677 getAlignPanel().alignmentChanged();
682 * Add the sequences from the given alignment to this viewport. Optionally,
683 * may give the user the option to open a new frame, or split panel, with cDNA
684 * and protein linked.
689 public void addAlignment(AlignmentI toAdd, String title)
691 // TODO: promote to AlignViewportI? applet CutAndPasteTransfer is different
693 // JBPComment: title is a largely redundant parameter at the moment
694 // JBPComment: this really should be an 'insert/pre/append' controller
695 // JBPComment: but the DNA/Protein check makes it a bit more complex
697 // refactored from FileLoader / CutAndPasteTransfer / SequenceFetcher with
699 // TODO: create undo object for this JAL-1101
702 * Ensure datasets are created for the new alignment as
703 * mappings operate on dataset sequences
705 toAdd.setDataset(null);
708 * Check if any added sequence could be the object of a mapping or
709 * cross-reference; if so, make the mapping explicit
711 getAlignment().realiseMappings(toAdd.getSequences());
714 * If any cDNA/protein mappings exist or can be made between the alignments,
715 * offer to open a split frame with linked alignments
717 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
719 if (AlignmentUtils.isMappable(toAdd, getAlignment()))
721 openLinkedAlignment(toAdd, title);
725 addDataToAlignment(toAdd);
729 * adds sequences to this alignment
733 void addDataToAlignment(AlignmentI toAdd)
735 // TODO: JAL-407 regardless of above - identical sequences (based on ID and
736 // provenance) should share the same dataset sequence
738 AlignmentI al = getAlignment();
739 String gap = String.valueOf(al.getGapCharacter());
740 for (int i = 0; i < toAdd.getHeight(); i++)
742 SequenceI seq = toAdd.getSequenceAt(i);
745 * - 'align' any mapped sequences as per existing
746 * e.g. cdna to genome, domain hit to protein sequence
747 * very experimental! (need a separate menu option for this)
748 * - only add mapped sequences ('select targets from a dataset')
750 if (true /*AlignmentUtils.alignSequenceAs(seq, al, gap, true, true)*/)
756 ranges.setEndSeq(getAlignment().getHeight() - 1); // BH 2019.04.18
757 firePropertyChange("alignment", null, getAlignment().getSequences());
761 * Show a dialog with the option to open and link (cDNA <-> protein) as a new
762 * alignment, either as a standalone alignment or in a split frame. Returns
763 * true if the new alignment was opened, false if not, because the user
764 * declined the offer.
769 protected void openLinkedAlignment(AlignmentI al, String title)
771 String[] options = new String[] { MessageManager.getString("action.no"),
772 MessageManager.getString("label.split_window"),
773 MessageManager.getString("label.new_window"), };
774 final String question = JvSwingUtils.wrapTooltip(true,
775 MessageManager.getString("label.open_split_window?"));
776 final AlignViewport us = this;
779 * options No, Split Window, New Window correspond to
780 * dialog responses 0, 1, 2 (even though JOptionPane shows them
783 JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.desktop)
784 .setResponseHandler(NO_SPLIT, new Runnable()
789 addDataToAlignment(al);
791 }).setResponseHandler(SPLIT_FRAME, new Runnable()
796 openLinkedAlignmentAs(getAlignPanel().alignFrame,
797 new Alignment(getAlignment()), al, title,
799 // us.openLinkedAlignmentAs(al, title, true);
801 }).setResponseHandler(NEW_WINDOW, new Runnable()
806 openLinkedAlignmentAs(null, getAlignment(), al, title,
810 dialog.showDialog(question,
811 MessageManager.getString("label.open_split_window"),
812 JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
813 options, options[0]);
816 * Open a split frame or a new window
821 * SPLIT_FRAME or NEW_WINDOW
823 public static void openLinkedAlignmentAs(AlignFrame thisFrame,
824 AlignmentI thisAlignment, AlignmentI al, String title, int mode)
827 * Identify protein and dna alignments. Make a copy of this one if opening
828 * in a new split pane.
830 AlignmentI protein = al.isNucleotide() ? thisAlignment : al;
831 AlignmentI cdna = al.isNucleotide() ? al : thisAlignment;
833 * Map sequences. At least one should get mapped as we have already passed
834 * the test for 'mappability'. Any mappings made will be added to the
835 * protein alignment. Note creating dataset sequences on the new alignment
836 * is a pre-requisite for building mappings.
839 AlignmentUtils.mapProteinAlignmentToCdna(protein, cdna);
842 * Create the AlignFrame for the added alignment. If it is protein, mappings
843 * are registered with StructureSelectionManager as a side-effect.
845 AlignFrame newAlignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
846 AlignFrame.DEFAULT_HEIGHT);
847 newAlignFrame.setTitle(title);
848 newAlignFrame.setStatus(MessageManager
849 .formatMessage("label.successfully_loaded_file", new Object[]
852 // TODO if we want this (e.g. to enable reload of the alignment from file),
853 // we will need to add parameters to the stack.
854 // if (!protocol.equals(DataSourceType.PASTE))
856 // alignFrame.setFileName(file, format);
859 if (mode == NEW_WINDOW)
861 Desktop.addInternalFrame(newAlignFrame, title,
862 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
867 newAlignFrame.setMaximum(
868 jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false));
869 } catch (java.beans.PropertyVetoException ex)
873 if (mode == SPLIT_FRAME)
875 al.alignAs(thisAlignment);
876 openSplitFrame(thisFrame, newAlignFrame, thisAlignment);
881 * Helper method to open a new SplitFrame holding linked dna and protein
884 * @param newAlignFrame
885 * containing a new alignment to be shown
887 * cdna/protein complement alignment to show in the other split half
888 * @return the protein alignment in the split frame
890 static protected AlignmentI openSplitFrame(AlignFrame thisFrame,
891 AlignFrame newAlignFrame, AlignmentI complement)
894 * Make a new frame with a copy of the alignment we are adding to. If this
895 * is protein, the mappings to cDNA will be registered with
896 * StructureSelectionManager as a side-effect.
898 AlignFrame copyMe = new AlignFrame(complement, AlignFrame.DEFAULT_WIDTH,
899 AlignFrame.DEFAULT_HEIGHT);
900 copyMe.setTitle(thisFrame.getTitle());
903 AlignmentI al = newAlignFrame.viewport.getAlignment();
904 final AlignFrame proteinFrame = al.isNucleotide() ? copyMe
906 final AlignFrame cdnaFrame = al.isNucleotide() ? newAlignFrame : copyMe;
907 cdnaFrame.setVisible(true);
908 proteinFrame.setVisible(true);
909 String linkedTitle = MessageManager
910 .getString("label.linked_view_title");
913 * Open in split pane. DNA sequence above, protein below.
915 JInternalFrame splitFrame = new SplitFrame(cdnaFrame, proteinFrame);
916 Desktop.addInternalFrame(splitFrame, linkedTitle, -1, -1);
918 return proteinFrame.viewport.getAlignment();
921 public AnnotationColumnChooser getAnnotationColumnSelectionState()
923 return annotationColumnSelectionState;
926 public void setAnnotationColumnSelectionState(
927 AnnotationColumnChooser currentAnnotationColumnSelectionState)
929 this.annotationColumnSelectionState = currentAnnotationColumnSelectionState;
933 public void setIdWidth(int i)
936 AlignmentPanel ap = getAlignPanel();
939 // modify GUI elements to reflect geometry change
940 Dimension idw = ap.getIdPanel().getIdCanvas().getPreferredSize();
942 ap.getIdPanel().getIdCanvas().setPreferredSize(idw);
946 public Rectangle getExplodedGeometry()
948 return explodedGeometry;
951 public void setExplodedGeometry(Rectangle explodedPosition)
953 this.explodedGeometry = explodedPosition;
956 public boolean isGatherViewsHere()
958 return gatherViewsHere;
961 public void setGatherViewsHere(boolean gatherViewsHere)
963 this.gatherViewsHere = gatherViewsHere;
967 * If this viewport has a (Protein/cDNA) complement, then scroll the
968 * complementary alignment to match this one.
970 public void scrollComplementaryAlignment()
973 * Populate a SearchResults object with the mapped location to scroll to. If
974 * there is no complement, or it is not following highlights, or no mapping
975 * is found, the result will be empty.
977 SearchResultsI sr = new SearchResults();
978 int verticalOffset = findComplementScrollTarget(sr);
981 // TODO would like next line without cast but needs more refactoring...
982 final AlignmentPanel complementPanel = ((AlignViewport) getCodingComplement())
984 complementPanel.setToScrollComplementPanel(false);
985 complementPanel.scrollToCentre(sr, verticalOffset);
986 complementPanel.setToScrollComplementPanel(true);
991 * Answers true if no alignment holds a reference to the given mapping
996 protected boolean noReferencesTo(AlignedCodonFrame acf)
998 AlignFrame[] frames = Desktop.getAlignFrames();
1003 for (AlignFrame af : frames)
1007 for (AlignmentViewPanel ap : af.getAlignPanels())
1009 AlignmentI al = ap.getAlignment();
1010 if (al != null && al.getCodonFrames().contains(acf))
1021 * Applies the supplied feature settings descriptor to currently known
1022 * features. This supports an 'initial configuration' of feature colouring
1023 * based on a preset or user favourite. This may then be modified in the usual
1024 * way using the Feature Settings dialogue.
1026 * @param featureSettings
1029 public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
1031 transferFeaturesStyles(featureSettings, false);
1035 * Applies the supplied feature settings descriptor to currently known features.
1036 * This supports an 'initial configuration' of feature colouring based on a
1037 * preset or user favourite. This may then be modified in the usual way using
1038 * the Feature Settings dialogue.
1040 * @param featureSettings
1043 public void mergeFeaturesStyle(FeatureSettingsModelI featureSettings)
1045 transferFeaturesStyles(featureSettings, true);
1049 * when mergeOnly is set, then group and feature visibility or feature colours
1050 * are not modified for features and groups already known to the feature
1051 * renderer. Feature ordering is always adjusted, and transparency is always set
1054 * @param featureSettings
1057 private void transferFeaturesStyles(FeatureSettingsModelI featureSettings,
1060 if (featureSettings == null)
1065 FeatureRenderer fr = getAlignPanel().getSeqPanel().seqCanvas
1066 .getFeatureRenderer();
1067 List<String> origRenderOrder = new ArrayList(),
1068 origGroups = new ArrayList();
1069 // preserve original render order - allows differentiation between user configured colours and autogenerated ones
1070 origRenderOrder.addAll(fr.getRenderOrder());
1071 origGroups.addAll(fr.getFeatureGroups());
1073 fr.findAllFeatures(true);
1074 List<String> renderOrder = fr.getRenderOrder();
1075 FeaturesDisplayedI displayed = fr.getFeaturesDisplayed();
1078 // only clear displayed features if we are mergeing
1081 // TODO this clears displayed.featuresRegistered - do we care?
1083 // JAL-3330 - JBP - yes we do - calling applyFeatureStyle to a view where
1084 // feature visibility has already been configured is not very friendly
1086 * set feature colour if specified by feature settings
1087 * set visibility of all features
1089 for (String type : renderOrder)
1091 FeatureColourI preferredColour = featureSettings
1092 .getFeatureColour(type);
1093 FeatureColourI origColour = fr.getFeatureStyle(type);
1094 if (!mergeOnly || (!origRenderOrder.contains(type)
1095 || origColour == null
1096 || (!origColour.isGraduatedColour()
1097 && origColour.getColour() != null
1098 && origColour.getColour().equals(
1099 ColorUtils.createColourFromName(type)))))
1101 // if we are merging, only update if there wasn't already a colour defined for
1103 if (preferredColour != null)
1105 fr.setColour(type, preferredColour);
1107 if (featureSettings.isFeatureDisplayed(type))
1109 displayed.setVisible(type);
1115 * set visibility of feature groups
1117 for (String group : fr.getFeatureGroups())
1119 if (!mergeOnly || !origGroups.contains(group))
1121 // when merging, display groups only if the aren't already marked as not visible
1122 fr.setGroupVisibility(group,
1123 featureSettings.isGroupDisplayed(group));
1128 * order the features
1130 if (featureSettings.optimiseOrder())
1132 // TODO not supported (yet?)
1136 fr.orderFeatures(featureSettings);
1138 fr.setTransparency(featureSettings.getTransparency());
1141 public String getViewName()
1146 public void setViewName(String viewName)
1148 this.viewName = viewName;