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 java.awt.Container;
24 import java.awt.Dimension;
26 import java.awt.FontMetrics;
27 import java.awt.Rectangle;
29 import java.util.ArrayList;
30 import java.util.Hashtable;
31 import java.util.List;
33 import javax.swing.JInternalFrame;
35 import jalview.analysis.AlignmentUtils;
36 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
37 import jalview.api.AlignViewportI;
38 import jalview.api.AlignmentViewPanel;
39 import jalview.api.FeatureColourI;
40 import jalview.api.FeatureSettingsModelI;
41 import jalview.api.FeaturesDisplayedI;
42 import jalview.api.ViewStyleI;
43 import jalview.bin.Cache;
44 import jalview.bin.Console;
45 import jalview.commands.CommandI;
46 import jalview.datamodel.AlignedCodonFrame;
47 import jalview.datamodel.Alignment;
48 import jalview.datamodel.AlignmentI;
49 import jalview.datamodel.ColumnSelection;
50 import jalview.datamodel.ContactMatrixI;
51 import jalview.datamodel.HiddenColumns;
52 import jalview.datamodel.SearchResults;
53 import jalview.datamodel.SearchResultsI;
54 import jalview.datamodel.SequenceGroup;
55 import jalview.datamodel.SequenceI;
56 import jalview.io.AppletFormatAdapter;
57 import jalview.io.DataSourceType;
58 import jalview.io.FileFormatException;
59 import jalview.io.FileFormatI;
60 import jalview.io.FileFormats;
61 import jalview.io.FileLoader;
62 import jalview.io.IdentifyFile;
63 import jalview.renderer.ResidueShader;
64 import jalview.schemes.ColourSchemeI;
65 import jalview.schemes.ColourSchemeProperty;
66 import jalview.schemes.ResidueColourScheme;
67 import jalview.schemes.UserColourScheme;
68 import jalview.structure.SelectionSource;
69 import jalview.structure.StructureSelectionManager;
70 import jalview.structure.VamsasSource;
71 import jalview.util.ColorUtils;
72 import jalview.util.MessageManager;
73 import jalview.viewmodel.AlignmentViewport;
74 import jalview.ws.params.AutoCalcSetting;
80 * @version $Revision: 1.141 $
82 public class AlignViewport extends AlignmentViewport
83 implements SelectionSource
87 boolean cursorMode = false;
89 boolean antiAlias = false;
91 private Rectangle explodedGeometry = null;
93 private String viewName = null;
96 * Flag set true on the view that should 'gather' multiple views of the same
97 * sequence set id when a project is reloaded. Set false on all views when
98 * they are 'exploded' into separate windows. Set true on the current view
99 * when 'Gather' is performed, and also on the first tab when the first new
102 private boolean gatherViewsHere = false;
104 private AnnotationColumnChooser annotationColumnSelectionState;
107 * Creates a new AlignViewport object.
112 public AlignViewport(AlignmentI al)
119 * Create a new AlignViewport object with a specific sequence set ID
123 * (may be null - but potential for ambiguous constructor exception)
125 public AlignViewport(AlignmentI al, String seqsetid)
127 this(al, seqsetid, null);
130 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
133 sequenceSetID = seqsetid;
135 // TODO remove these once 2.4.VAMSAS release finished
136 if (seqsetid != null)
139 "Setting viewport's sequence set id : " + sequenceSetID);
143 Console.debug("Setting viewport's view id : " + viewId);
150 * Create a new AlignViewport with hidden regions
154 * @param hiddenColumns
157 public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns)
160 if (hiddenColumns != null)
162 al.setHiddenColumns(hiddenColumns);
168 * New viewport with hidden columns and an existing sequence set id
171 * @param hiddenColumns
175 public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns,
178 this(al, hiddenColumns, seqsetid, null);
182 * New viewport with hidden columns and an existing sequence set id and viewid
185 * @param hiddenColumns
191 public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns,
192 String seqsetid, String viewid)
195 sequenceSetID = seqsetid;
197 // TODO remove these once 2.4.VAMSAS release finished
198 if (seqsetid != null)
201 "Setting viewport's sequence set id : " + sequenceSetID);
205 Console.debug("Setting viewport's view id : " + viewId);
208 if (hiddenColumns != null)
210 al.setHiddenColumns(hiddenColumns);
216 * Apply any settings saved in user preferences
218 private void applyViewProperties()
220 antiAlias = Cache.getDefault("ANTI_ALIAS", true);
222 viewStyle.setShowJVSuffix(Cache.getDefault("SHOW_JVSUFFIX", true));
223 setShowAnnotation(Cache.getDefault("SHOW_ANNOTATIONS", true));
225 setRightAlignIds(Cache.getDefault("RIGHT_ALIGN_IDS", false));
226 setCentreColumnLabels(Cache.getDefault("CENTRE_COLUMN_LABELS", false));
227 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
229 setPadGaps(Cache.getDefault("PAD_GAPS", true));
230 setShowNPFeats(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
231 setShowDBRefs(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
232 viewStyle.setSeqNameItalics(Cache.getDefault("ID_ITALICS", true));
233 viewStyle.setWrapAlignment(Cache.getDefault("WRAP_ALIGNMENT", false));
234 viewStyle.setShowUnconserved(
235 Cache.getDefault("SHOW_UNCONSERVED", false));
236 sortByTree = Cache.getDefault("SORT_BY_TREE", false);
237 followSelection = Cache.getDefault("FOLLOW_SELECTIONS", true);
238 sortAnnotationsBy = SequenceAnnotationOrder
239 .valueOf(Cache.getDefault(Preferences.SORT_ANNOTATIONS,
240 SequenceAnnotationOrder.NONE.name()));
241 showAutocalculatedAbove = Cache
242 .getDefault(Preferences.SHOW_AUTOCALC_ABOVE, false);
243 viewStyle.setScaleProteinAsCdna(
244 Cache.getDefault(Preferences.SCALE_PROTEIN_TO_CDNA, true));
249 applyViewProperties();
251 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
252 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
253 String fontSize = Cache.getDefault("FONT_SIZE", "10");
257 if (fontStyle.equals("bold"))
261 else if (fontStyle.equals("italic"))
266 setFont(new Font(fontName, style, Integer.parseInt(fontSize)), true);
269 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
271 // We must set conservation and consensus before setting colour,
272 // as Blosum and Clustal require this to be done
273 if (hconsensus == null && !isDataset)
275 if (!alignment.isNucleotide())
277 showConservation = Cache.getDefault("SHOW_CONSERVATION", true);
278 showQuality = Cache.getDefault("SHOW_QUALITY", true);
279 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
282 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
284 showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
285 normaliseSequenceLogo = Cache.getDefault("NORMALISE_CONSENSUS_LOGO",
287 showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
288 showConsensus = Cache.getDefault("SHOW_IDENTITY", true);
290 showOccupancy = Cache.getDefault(Preferences.SHOW_OCCUPANCY, true);
292 initAutoAnnotation();
293 String colourProperty = alignment.isNucleotide()
294 ? Preferences.DEFAULT_COLOUR_NUC
295 : Preferences.DEFAULT_COLOUR_PROT;
296 String schemeName = Cache.getProperty(colourProperty);
297 if (schemeName == null)
299 // only DEFAULT_COLOUR available in Jalview before 2.9
300 schemeName = Cache.getDefault(Preferences.DEFAULT_COLOUR,
301 ResidueColourScheme.NONE);
303 ColourSchemeI colourScheme = ColourSchemeProperty.getColourScheme(this,
304 alignment, schemeName);
305 residueShading = new ResidueShader(colourScheme);
307 if (colourScheme instanceof UserColourScheme)
309 residueShading = new ResidueShader(
310 UserDefinedColours.loadDefaultColours());
311 residueShading.setThreshold(0, isIgnoreGapsConsensus());
314 if (residueShading != null)
316 residueShading.setConsensus(hconsensus);
318 setColourAppliesToAllGroups(true);
321 boolean validCharWidth;
327 public void setFont(Font f, boolean setGrid)
331 Container c = new Container();
335 FontMetrics fm = c.getFontMetrics(font);
336 int ww = fm.charWidth('M');
337 setCharHeight(fm.getHeight());
340 viewStyle.setFontName(font.getName());
341 viewStyle.setFontStyle(font.getStyle());
342 viewStyle.setFontSize(font.getSize());
344 validCharWidth = true;
348 public void setViewStyle(ViewStyleI settingsForView)
350 super.setViewStyle(settingsForView);
351 setFont(new Font(viewStyle.getFontName(), viewStyle.getFontStyle(),
352 viewStyle.getFontSize()), false);
358 * @return DOCUMENT ME!
360 public Font getFont()
372 public void setAlignment(AlignmentI align)
374 replaceMappings(align);
375 super.setAlignment(align);
379 * Replace any codon mappings for this viewport with those for the given
384 public void replaceMappings(AlignmentI align)
388 * Deregister current mappings (if any)
390 deregisterMappings();
393 * Register new mappings (if any)
397 StructureSelectionManager ssm = StructureSelectionManager
398 .getStructureSelectionManager(Desktop.instance);
399 ssm.registerMappings(align.getCodonFrames());
403 * replace mappings on our alignment
405 if (alignment != null && align != null)
407 alignment.setCodonFrames(align.getCodonFrames());
411 protected void deregisterMappings()
413 AlignmentI al = getAlignment();
416 List<AlignedCodonFrame> mappings = al.getCodonFrames();
417 if (mappings != null)
419 StructureSelectionManager ssm = StructureSelectionManager
420 .getStructureSelectionManager(Desktop.instance);
421 for (AlignedCodonFrame acf : mappings)
423 if (noReferencesTo(acf))
425 ssm.deregisterMapping(acf);
435 * @return DOCUMENT ME!
438 public char getGapCharacter()
440 return getAlignment().getGapCharacter();
449 public void setGapCharacter(char gap)
451 if (getAlignment() != null)
453 getAlignment().setGapCharacter(gap);
458 * get hash of undo and redo list for the alignment
460 * @return long[] { historyList.hashCode, redoList.hashCode };
462 public long[] getUndoRedoHash()
465 if (historyList == null || redoList == null)
467 return new long[] { -1, -1 };
469 return new long[] { historyList.hashCode(), this.redoList.hashCode() };
473 * test if a particular set of hashcodes are different to the hashcodes for
474 * the undo and redo list.
477 * the stored set of hashcodes as returned by getUndoRedoHash
478 * @return true if the hashcodes differ (ie the alignment has been edited) or
479 * the stored hashcode array differs in size
481 public boolean isUndoRedoHashModified(long[] undoredo)
483 if (undoredo == null)
487 long[] cstate = getUndoRedoHash();
488 if (cstate.length != undoredo.length)
493 for (int i = 0; i < cstate.length; i++)
495 if (cstate[i] != undoredo[i])
503 public boolean followSelection = true;
506 * @return true if view selection should always follow the selections
507 * broadcast by other selection sources
509 public boolean getFollowSelection()
511 return followSelection;
515 * Send the current selection to be broadcast to any selection listeners.
518 public void sendSelection()
520 jalview.structure.StructureSelectionManager
521 .getStructureSelectionManager(Desktop.instance)
522 .sendSelection(new SequenceGroup(getSelectionGroup()),
523 new ColumnSelection(getColumnSelection()),
524 new HiddenColumns(getAlignment().getHiddenColumns()),
529 * return the alignPanel containing the given viewport. Use this to get the
530 * components currently handling the given viewport.
533 * @return null or an alignPanel guaranteed to have non-null alignFrame
536 public AlignmentPanel getAlignPanel()
538 AlignmentPanel[] aps = PaintRefresher
539 .getAssociatedPanels(this.getSequenceSetId());
540 for (int p = 0; aps != null && p < aps.length; p++)
542 if (aps[p].av == this)
550 public boolean getSortByTree()
555 public void setSortByTree(boolean sort)
561 * Returns the (Desktop) instance of the StructureSelectionManager
564 public StructureSelectionManager getStructureSelectionManager()
566 return StructureSelectionManager
567 .getStructureSelectionManager(Desktop.instance);
571 public boolean isNormaliseSequenceLogo()
573 return normaliseSequenceLogo;
576 public void setNormaliseSequenceLogo(boolean state)
578 normaliseSequenceLogo = state;
583 * @return true if alignment characters should be displayed
586 public boolean isValidCharWidth()
588 return validCharWidth;
591 private Hashtable<String, AutoCalcSetting> calcIdParams = new Hashtable<>();
593 public AutoCalcSetting getCalcIdSettingsFor(String calcId)
595 return calcIdParams.get(calcId);
598 public void setCalcIdSettingsFor(String calcId, AutoCalcSetting settings,
601 calcIdParams.put(calcId, settings);
602 // TODO: create a restart list to trigger any calculations that need to be
603 // restarted after load
604 // calculator.getRegisteredWorkersOfClass(settings.getWorkerClass())
607 Console.debug("trigger update for " + calcId);
612 * Method called when another alignment's edit (or possibly other) command is
615 * To allow for sequence mappings (e.g. protein to cDNA), we have to first
616 * 'unwind' the command on the source sequences (in simulation, not in fact),
617 * and then for each edit in turn:
619 * <li>compute the equivalent edit on the mapped sequences</li>
620 * <li>apply the mapped edit</li>
621 * <li>'apply' the source edit to the working copy of the source
630 public void mirrorCommand(CommandI command, boolean undo,
631 StructureSelectionManager ssm, VamsasSource source)
634 * Do nothing unless we are a 'complement' of the source. May replace this
635 * with direct calls not via SSM.
637 if (source instanceof AlignViewportI
638 && ((AlignViewportI) source).getCodingComplement() == this)
647 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
649 if (mappedCommand != null)
651 AlignmentI[] views = getAlignPanel().alignFrame.getViewAlignments();
652 mappedCommand.doCommand(views);
653 getAlignPanel().alignmentChanged();
658 * Add the sequences from the given alignment to this viewport. Optionally,
659 * may give the user the option to open a new frame, or split panel, with cDNA
660 * and protein linked.
665 public void addAlignment(AlignmentI toAdd, String title)
667 // TODO: promote to AlignViewportI? applet CutAndPasteTransfer is different
669 // JBPComment: title is a largely redundant parameter at the moment
670 // JBPComment: this really should be an 'insert/pre/append' controller
671 // JBPComment: but the DNA/Protein check makes it a bit more complex
673 // refactored from FileLoader / CutAndPasteTransfer / SequenceFetcher with
675 // TODO: create undo object for this JAL-1101
678 * Ensure datasets are created for the new alignment as
679 * mappings operate on dataset sequences
681 toAdd.setDataset(null);
684 * Check if any added sequence could be the object of a mapping or
685 * cross-reference; if so, make the mapping explicit
687 getAlignment().realiseMappings(toAdd.getSequences());
690 * If any cDNA/protein mappings exist or can be made between the alignments,
691 * offer to open a split frame with linked alignments
693 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
695 if (AlignmentUtils.isMappable(toAdd, getAlignment()))
697 openLinkedAlignment(toAdd, title);
701 addDataToAlignment(toAdd);
705 * adds sequences to this alignment
709 void addDataToAlignment(AlignmentI toAdd)
711 // TODO: JAL-407 regardless of above - identical sequences (based on ID and
712 // provenance) should share the same dataset sequence
714 AlignmentI al = getAlignment();
715 String gap = String.valueOf(al.getGapCharacter());
716 for (int i = 0; i < toAdd.getHeight(); i++)
718 SequenceI seq = toAdd.getSequenceAt(i);
721 * - 'align' any mapped sequences as per existing
722 * e.g. cdna to genome, domain hit to protein sequence
723 * very experimental! (need a separate menu option for this)
724 * - only add mapped sequences ('select targets from a dataset')
726 if (true /*AlignmentUtils.alignSequenceAs(seq, al, gap, true, true)*/)
731 for (ContactMatrixI cm : toAdd.getContactMaps())
733 al.addContactList(cm);
735 ranges.setEndSeq(getAlignment().getHeight() - 1); // BH 2019.04.18
736 firePropertyChange("alignment", null, getAlignment().getSequences());
740 * Load a File into this AlignViewport attempting to detect format if not
741 * given or given as null.
746 public void addFile(File file, FileFormatI format)
748 addFile(file, format, true);
751 public void addFile(File file, FileFormatI format, boolean async)
753 DataSourceType protocol = AppletFormatAdapter.checkProtocol(file);
759 format = new IdentifyFile().identify(file, protocol);
760 } catch (FileFormatException e1)
762 jalview.bin.Console.error("Unknown file format for '" + file + "'");
765 else if (FileFormats.getInstance().isIdentifiable(format))
769 format = new IdentifyFile().identify(file, protocol);
770 } catch (FileFormatException e)
772 jalview.bin.Console.error("Unknown file format for '" + file + "'",
777 new FileLoader().LoadFile(this, file, DataSourceType.FILE, format,
781 public void addFile(File file)
787 * Show a dialog with the option to open and link (cDNA <-> protein) as a new
788 * alignment, either as a standalone alignment or in a split frame. Returns
789 * true if the new alignment was opened, false if not, because the user
790 * declined the offer.
795 protected void openLinkedAlignment(AlignmentI al, String title)
797 String[] options = new String[] { MessageManager.getString("action.no"),
798 MessageManager.getString("label.split_window"),
799 MessageManager.getString("label.new_window"), };
800 final String question = JvSwingUtils.wrapTooltip(true,
801 MessageManager.getString("label.open_split_window?"));
802 final AlignViewport us = this;
805 * options No, Split Window, New Window correspond to
806 * dialog responses 0, 1, 2 (even though JOptionPane shows them
809 JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.desktop)
810 .setResponseHandler(0, () -> {
811 addDataToAlignment(al);
812 }).setResponseHandler(1, () -> {
813 us.openLinkedAlignmentAs(al, title, true);
814 }).setResponseHandler(2, () -> {
815 us.openLinkedAlignmentAs(al, title, false);
817 dialog.showDialog(question,
818 MessageManager.getString("label.open_split_window"),
819 JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
820 options, options[0]);
823 protected void openLinkedAlignmentAs(AlignmentI al, String title,
824 boolean newWindowOrSplitPane)
827 * Identify protein and dna alignments. Make a copy of this one if opening
828 * in a new split pane.
830 AlignmentI thisAlignment = newWindowOrSplitPane
831 ? new Alignment(getAlignment())
833 AlignmentI protein = al.isNucleotide() ? thisAlignment : al;
834 final AlignmentI cdna = al.isNucleotide() ? al : thisAlignment;
837 * Map sequences. At least one should get mapped as we have already passed
838 * the test for 'mappability'. Any mappings made will be added to the
839 * protein alignment. Note creating dataset sequences on the new alignment
840 * is a pre-requisite for building mappings.
843 AlignmentUtils.mapProteinAlignmentToCdna(protein, cdna);
846 * Create the AlignFrame for the added alignment. If it is protein, mappings
847 * are registered with StructureSelectionManager as a side-effect.
849 AlignFrame newAlignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
850 AlignFrame.DEFAULT_HEIGHT);
851 newAlignFrame.setTitle(title);
852 newAlignFrame.setStatus(MessageManager
853 .formatMessage("label.successfully_loaded_file", new Object[]
856 // TODO if we want this (e.g. to enable reload of the alignment from file),
857 // we will need to add parameters to the stack.
858 // if (!protocol.equals(DataSourceType.PASTE))
860 // alignFrame.setFileName(file, format);
863 if (!newWindowOrSplitPane)
865 Desktop.addInternalFrame(newAlignFrame, title,
866 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
871 newAlignFrame.setMaximum(Cache.getDefault("SHOW_FULLSCREEN", false));
872 } catch (java.beans.PropertyVetoException ex)
876 if (newWindowOrSplitPane)
878 al.alignAs(thisAlignment);
879 protein = openSplitFrame(newAlignFrame, thisAlignment);
884 * Helper method to open a new SplitFrame holding linked dna and protein
887 * @param newAlignFrame
888 * containing a new alignment to be shown
890 * cdna/protein complement alignment to show in the other split half
891 * @return the protein alignment in the split frame
893 protected AlignmentI openSplitFrame(AlignFrame newAlignFrame,
894 AlignmentI complement)
897 * Make a new frame with a copy of the alignment we are adding to. If this
898 * is protein, the mappings to cDNA will be registered with
899 * StructureSelectionManager as a side-effect.
901 AlignFrame copyMe = new AlignFrame(complement, AlignFrame.DEFAULT_WIDTH,
902 AlignFrame.DEFAULT_HEIGHT);
903 copyMe.setTitle(getAlignPanel().alignFrame.getTitle());
905 AlignmentI al = newAlignFrame.viewport.getAlignment();
906 final AlignFrame proteinFrame = al.isNucleotide() ? copyMe
908 final AlignFrame cdnaFrame = al.isNucleotide() ? newAlignFrame : copyMe;
909 cdnaFrame.setVisible(true);
910 proteinFrame.setVisible(true);
911 String linkedTitle = MessageManager
912 .getString("label.linked_view_title");
915 * Open in split pane. DNA sequence above, protein below.
917 JInternalFrame splitFrame = new SplitFrame(cdnaFrame, proteinFrame);
918 Desktop.addInternalFrame(splitFrame, linkedTitle, -1, -1);
920 return proteinFrame.viewport.getAlignment();
923 public AnnotationColumnChooser getAnnotationColumnSelectionState()
925 return annotationColumnSelectionState;
928 public void setAnnotationColumnSelectionState(
929 AnnotationColumnChooser currentAnnotationColumnSelectionState)
931 this.annotationColumnSelectionState = currentAnnotationColumnSelectionState;
935 public void setIdWidth(int i)
938 AlignmentPanel ap = getAlignPanel();
941 // modify GUI elements to reflect geometry change
942 Dimension idw = ap.getIdPanel().getIdCanvas().getPreferredSize();
944 ap.getIdPanel().getIdCanvas().setPreferredSize(idw);
948 public Rectangle getExplodedGeometry()
950 return explodedGeometry;
953 public void setExplodedGeometry(Rectangle explodedPosition)
955 this.explodedGeometry = explodedPosition;
958 public boolean isGatherViewsHere()
960 return gatherViewsHere;
963 public void setGatherViewsHere(boolean gatherViewsHere)
965 this.gatherViewsHere = gatherViewsHere;
969 * If this viewport has a (Protein/cDNA) complement, then scroll the
970 * complementary alignment to match this one.
972 public void scrollComplementaryAlignment()
975 * Populate a SearchResults object with the mapped location to scroll to. If
976 * there is no complement, or it is not following highlights, or no mapping
977 * is found, the result will be empty.
979 SearchResultsI sr = new SearchResults();
980 int verticalOffset = findComplementScrollTarget(sr);
983 // TODO would like next line without cast but needs more refactoring...
984 final AlignmentPanel complementPanel = ((AlignViewport) getCodingComplement())
986 complementPanel.setToScrollComplementPanel(false);
987 complementPanel.scrollToCentre(sr, verticalOffset);
988 complementPanel.setToScrollComplementPanel(true);
993 * Answers true if no alignment holds a reference to the given mapping
998 protected boolean noReferencesTo(AlignedCodonFrame acf)
1000 AlignFrame[] frames = Desktop.getDesktopAlignFrames();
1005 for (AlignFrame af : frames)
1009 for (AlignmentViewPanel ap : af.getAlignPanels())
1011 AlignmentI al = ap.getAlignment();
1012 if (al != null && al.getCodonFrames().contains(acf))
1023 * Applies the supplied feature settings descriptor to currently known
1024 * features. This supports an 'initial configuration' of feature colouring
1025 * based on a preset or user favourite. This may then be modified in the usual
1026 * way using the Feature Settings dialogue.
1028 * @param featureSettings
1031 public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
1033 transferFeaturesStyles(featureSettings, false);
1037 * Applies the supplied feature settings descriptor to currently known
1038 * features. This supports an 'initial configuration' of feature colouring
1039 * based on a preset or user favourite. This may then be modified in the usual
1040 * way using the Feature Settings dialogue.
1042 * @param featureSettings
1045 public void mergeFeaturesStyle(FeatureSettingsModelI featureSettings)
1047 transferFeaturesStyles(featureSettings, true);
1051 * when mergeOnly is set, then group and feature visibility or feature colours
1052 * are not modified for features and groups already known to the feature
1053 * renderer. Feature ordering is always adjusted, and transparency is always
1056 * @param featureSettings
1059 private void transferFeaturesStyles(FeatureSettingsModelI featureSettings,
1062 if (featureSettings == null)
1067 FeatureRenderer fr = getAlignPanel().getSeqPanel().seqCanvas
1068 .getFeatureRenderer();
1069 List<String> origRenderOrder = new ArrayList<>();
1070 List<String> origGroups = new ArrayList<>();
1071 // preserve original render order - allows differentiation between user
1072 // configured colours and autogenerated ones
1073 origRenderOrder.addAll(fr.getRenderOrder());
1074 origGroups.addAll(fr.getFeatureGroups());
1076 fr.findAllFeatures(true);
1077 List<String> renderOrder = fr.getRenderOrder();
1078 FeaturesDisplayedI displayed = fr.getFeaturesDisplayed();
1081 // only clear displayed features if we are mergeing
1082 // displayed.clear();
1084 // TODO this clears displayed.featuresRegistered - do we care?
1086 // JAL-3330 - JBP - yes we do - calling applyFeatureStyle to a view where
1087 // feature visibility has already been configured is not very friendly
1089 * set feature colour if specified by feature settings
1090 * set visibility of all features
1092 for (String type : renderOrder)
1094 FeatureColourI preferredColour = featureSettings
1095 .getFeatureColour(type);
1096 FeatureColourI origColour = fr.getFeatureStyle(type);
1097 if (!mergeOnly || (!origRenderOrder.contains(type)
1098 || origColour == null
1099 || (!origColour.isGraduatedColour()
1100 && origColour.getColour() != null
1101 && origColour.getColour().equals(
1102 ColorUtils.createColourFromName(type)))))
1104 // if we are merging, only update if there wasn't already a colour
1107 if (preferredColour != null)
1109 fr.setColour(type, preferredColour);
1111 if (featureSettings.isFeatureDisplayed(type))
1113 displayed.setVisible(type);
1115 else if (featureSettings.isFeatureHidden(type))
1117 displayed.setHidden(type);
1123 * set visibility of feature groups
1125 for (String group : fr.getFeatureGroups())
1127 if (!mergeOnly || !origGroups.contains(group))
1129 // when merging, display groups only if the aren't already marked as not
1131 fr.setGroupVisibility(group,
1132 featureSettings.isGroupDisplayed(group));
1137 * order the features
1139 if (featureSettings.optimiseOrder())
1141 // TODO not supported (yet?)
1145 fr.orderFeatures(featureSettings);
1147 fr.setTransparency(featureSettings.getTransparency());
1149 fr.notifyFeaturesChanged();
1152 public String getViewName()
1157 public void setViewName(String viewName)
1159 this.viewName = viewName;