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.AlignmentAnnotation;
49 import jalview.datamodel.AlignmentI;
50 import jalview.datamodel.ColumnSelection;
51 import jalview.datamodel.ContactMatrixI;
52 import jalview.datamodel.HiddenColumns;
53 import jalview.datamodel.SearchResults;
54 import jalview.datamodel.SearchResultsI;
55 import jalview.datamodel.SequenceGroup;
56 import jalview.datamodel.SequenceI;
57 import jalview.io.AppletFormatAdapter;
58 import jalview.io.DataSourceType;
59 import jalview.io.FileFormatException;
60 import jalview.io.FileFormatI;
61 import jalview.io.FileFormats;
62 import jalview.io.FileLoader;
63 import jalview.io.IdentifyFile;
64 import jalview.renderer.ResidueShader;
65 import jalview.schemes.ColourSchemeI;
66 import jalview.schemes.ColourSchemeProperty;
67 import jalview.schemes.ResidueColourScheme;
68 import jalview.schemes.UserColourScheme;
69 import jalview.structure.SelectionSource;
70 import jalview.structure.StructureSelectionManager;
71 import jalview.structure.VamsasSource;
72 import jalview.util.ColorUtils;
73 import jalview.util.MessageManager;
74 import jalview.viewmodel.AlignmentViewport;
75 import jalview.ws.params.AutoCalcSetting;
81 * @version $Revision: 1.141 $
83 public class AlignViewport extends AlignmentViewport
84 implements SelectionSource
88 boolean cursorMode = false;
90 boolean antiAlias = false;
92 private Rectangle explodedGeometry = null;
94 private String viewName = null;
97 * Flag set true on the view that should 'gather' multiple views of the same
98 * sequence set id when a project is reloaded. Set false on all views when
99 * they are 'exploded' into separate windows. Set true on the current view
100 * when 'Gather' is performed, and also on the first tab when the first new
103 private boolean gatherViewsHere = false;
105 private AnnotationColumnChooser annotationColumnSelectionState;
108 * Creates a new AlignViewport object.
113 public AlignViewport(AlignmentI al)
120 * Create a new AlignViewport object with a specific sequence set ID
124 * (may be null - but potential for ambiguous constructor exception)
126 public AlignViewport(AlignmentI al, String seqsetid)
128 this(al, seqsetid, null);
131 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
134 sequenceSetID = seqsetid;
136 // TODO remove these once 2.4.VAMSAS release finished
137 if (seqsetid != null)
140 "Setting viewport's sequence set id : " + sequenceSetID);
144 Console.debug("Setting viewport's view id : " + viewId);
151 * Create a new AlignViewport with hidden regions
155 * @param hiddenColumns
158 public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns)
161 if (hiddenColumns != null)
163 al.setHiddenColumns(hiddenColumns);
169 * New viewport with hidden columns and an existing sequence set id
172 * @param hiddenColumns
176 public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns,
179 this(al, hiddenColumns, seqsetid, null);
183 * New viewport with hidden columns and an existing sequence set id and viewid
186 * @param hiddenColumns
192 public AlignViewport(AlignmentI al, HiddenColumns hiddenColumns,
193 String seqsetid, String viewid)
196 sequenceSetID = seqsetid;
198 // TODO remove these once 2.4.VAMSAS release finished
199 if (seqsetid != null)
202 "Setting viewport's sequence set id : " + sequenceSetID);
206 Console.debug("Setting viewport's view id : " + viewId);
209 if (hiddenColumns != null)
211 al.setHiddenColumns(hiddenColumns);
217 * Apply any settings saved in user preferences
219 private void applyViewProperties()
221 antiAlias = Cache.getDefault("ANTI_ALIAS", true);
223 viewStyle.setShowJVSuffix(Cache.getDefault("SHOW_JVSUFFIX", true));
224 setShowAnnotation(Cache.getDefault("SHOW_ANNOTATIONS", true));
226 setRightAlignIds(Cache.getDefault("RIGHT_ALIGN_IDS", false));
227 setCentreColumnLabels(Cache.getDefault("CENTRE_COLUMN_LABELS", false));
228 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
230 setPadGaps(Cache.getDefault("PAD_GAPS", true));
231 setShowNPFeats(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
232 setShowDBRefs(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
233 viewStyle.setSeqNameItalics(Cache.getDefault("ID_ITALICS", true));
234 viewStyle.setWrapAlignment(Cache.getDefault("WRAP_ALIGNMENT", false));
235 viewStyle.setShowUnconserved(
236 Cache.getDefault("SHOW_UNCONSERVED", false));
237 sortByTree = Cache.getDefault("SORT_BY_TREE", false);
238 followSelection = Cache.getDefault("FOLLOW_SELECTIONS", true);
239 sortAnnotationsBy = SequenceAnnotationOrder
240 .valueOf(Cache.getDefault(Preferences.SORT_ANNOTATIONS,
241 SequenceAnnotationOrder.NONE.name()));
242 showAutocalculatedAbove = Cache
243 .getDefault(Preferences.SHOW_AUTOCALC_ABOVE, false);
244 viewStyle.setScaleProteinAsCdna(
245 Cache.getDefault(Preferences.SCALE_PROTEIN_TO_CDNA, true));
250 applyViewProperties();
252 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
253 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
254 String fontSize = Cache.getDefault("FONT_SIZE", "10");
258 if (fontStyle.equals("bold"))
262 else if (fontStyle.equals("italic"))
267 setFont(new Font(fontName, style, Integer.parseInt(fontSize)), true);
270 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
272 // We must set conservation and consensus before setting colour,
273 // as Blosum and Clustal require this to be done
274 if (hconsensus == null && !isDataset)
276 if (!alignment.isNucleotide())
278 showConservation = Cache.getDefault("SHOW_CONSERVATION", true);
279 showQuality = Cache.getDefault("SHOW_QUALITY", true);
280 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
283 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
285 showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
286 normaliseSequenceLogo = Cache.getDefault("NORMALISE_CONSENSUS_LOGO",
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 String colourProperty = alignment.isNucleotide()
295 ? Preferences.DEFAULT_COLOUR_NUC
296 : Preferences.DEFAULT_COLOUR_PROT;
297 String schemeName = Cache.getProperty(colourProperty);
298 if (schemeName == null)
300 // only DEFAULT_COLOUR available in Jalview before 2.9
301 schemeName = Cache.getDefault(Preferences.DEFAULT_COLOUR,
302 ResidueColourScheme.NONE);
304 ColourSchemeI colourScheme = ColourSchemeProperty.getColourScheme(this,
305 alignment, schemeName);
306 residueShading = new ResidueShader(colourScheme);
308 if (colourScheme instanceof UserColourScheme)
310 residueShading = new ResidueShader(
311 UserDefinedColours.loadDefaultColours());
312 residueShading.setThreshold(0, isIgnoreGapsConsensus());
315 if (residueShading != null)
317 residueShading.setConsensus(hconsensus);
319 setColourAppliesToAllGroups(true);
322 boolean validCharWidth;
328 public void setFont(Font f, boolean setGrid)
332 Container c = new Container();
336 FontMetrics fm = c.getFontMetrics(font);
337 int ww = fm.charWidth('M');
338 setCharHeight(fm.getHeight());
341 viewStyle.setFontName(font.getName());
342 viewStyle.setFontStyle(font.getStyle());
343 viewStyle.setFontSize(font.getSize());
345 validCharWidth = true;
349 public void setViewStyle(ViewStyleI settingsForView)
351 super.setViewStyle(settingsForView);
352 setFont(new Font(viewStyle.getFontName(), viewStyle.getFontStyle(),
353 viewStyle.getFontSize()), false);
359 * @return DOCUMENT ME!
361 public Font getFont()
373 public void setAlignment(AlignmentI align)
375 replaceMappings(align);
376 super.setAlignment(align);
380 * Replace any codon mappings for this viewport with those for the given
385 public void replaceMappings(AlignmentI align)
389 * Deregister current mappings (if any)
391 deregisterMappings();
394 * Register new mappings (if any)
398 StructureSelectionManager ssm = StructureSelectionManager
399 .getStructureSelectionManager(Desktop.instance);
400 ssm.registerMappings(align.getCodonFrames());
404 * replace mappings on our alignment
406 if (alignment != null && align != null)
408 alignment.setCodonFrames(align.getCodonFrames());
412 protected void deregisterMappings()
414 AlignmentI al = getAlignment();
417 List<AlignedCodonFrame> mappings = al.getCodonFrames();
418 if (mappings != null)
420 StructureSelectionManager ssm = StructureSelectionManager
421 .getStructureSelectionManager(Desktop.instance);
422 for (AlignedCodonFrame acf : mappings)
424 if (noReferencesTo(acf))
426 ssm.deregisterMapping(acf);
436 * @return DOCUMENT ME!
439 public char getGapCharacter()
441 return getAlignment().getGapCharacter();
450 public void setGapCharacter(char gap)
452 if (getAlignment() != null)
454 getAlignment().setGapCharacter(gap);
459 * get hash of undo and redo list for the alignment
461 * @return long[] { historyList.hashCode, redoList.hashCode };
463 public long[] getUndoRedoHash()
466 if (historyList == null || redoList == null)
468 return new long[] { -1, -1 };
470 return new long[] { historyList.hashCode(), this.redoList.hashCode() };
474 * test if a particular set of hashcodes are different to the hashcodes for
475 * the undo and redo list.
478 * the stored set of hashcodes as returned by getUndoRedoHash
479 * @return true if the hashcodes differ (ie the alignment has been edited) or
480 * the stored hashcode array differs in size
482 public boolean isUndoRedoHashModified(long[] undoredo)
484 if (undoredo == null)
488 long[] cstate = getUndoRedoHash();
489 if (cstate.length != undoredo.length)
494 for (int i = 0; i < cstate.length; i++)
496 if (cstate[i] != undoredo[i])
504 public boolean followSelection = true;
507 * @return true if view selection should always follow the selections
508 * broadcast by other selection sources
510 public boolean getFollowSelection()
512 return followSelection;
516 * Send the current selection to be broadcast to any selection listeners.
519 public void sendSelection()
521 jalview.structure.StructureSelectionManager
522 .getStructureSelectionManager(Desktop.instance)
523 .sendSelection(new SequenceGroup(getSelectionGroup()),
524 new ColumnSelection(getColumnSelection()),
525 new HiddenColumns(getAlignment().getHiddenColumns()),
530 * return the alignPanel containing the given viewport. Use this to get the
531 * components currently handling the given viewport.
534 * @return null or an alignPanel guaranteed to have non-null alignFrame
537 public AlignmentPanel getAlignPanel()
539 AlignmentPanel[] aps = PaintRefresher
540 .getAssociatedPanels(this.getSequenceSetId());
541 for (int p = 0; aps != null && p < aps.length; p++)
543 if (aps[p].av == this)
551 public boolean getSortByTree()
556 public void setSortByTree(boolean sort)
562 * Returns the (Desktop) instance of the StructureSelectionManager
565 public StructureSelectionManager getStructureSelectionManager()
567 return StructureSelectionManager
568 .getStructureSelectionManager(Desktop.instance);
572 public boolean isNormaliseSequenceLogo()
574 return normaliseSequenceLogo;
577 public void setNormaliseSequenceLogo(boolean state)
579 normaliseSequenceLogo = state;
584 * @return true if alignment characters should be displayed
587 public boolean isValidCharWidth()
589 return validCharWidth;
592 private Hashtable<String, AutoCalcSetting> calcIdParams = new Hashtable<>();
594 public AutoCalcSetting getCalcIdSettingsFor(String calcId)
596 return calcIdParams.get(calcId);
599 public void setCalcIdSettingsFor(String calcId, AutoCalcSetting settings,
602 calcIdParams.put(calcId, settings);
603 // TODO: create a restart list to trigger any calculations that need to be
604 // restarted after load
605 // calculator.getRegisteredWorkersOfClass(settings.getWorkerClass())
608 Console.debug("trigger update for " + calcId);
613 * Method called when another alignment's edit (or possibly other) command is
616 * To allow for sequence mappings (e.g. protein to cDNA), we have to first
617 * 'unwind' the command on the source sequences (in simulation, not in fact),
618 * and then for each edit in turn:
620 * <li>compute the equivalent edit on the mapped sequences</li>
621 * <li>apply the mapped edit</li>
622 * <li>'apply' the source edit to the working copy of the source
631 public void mirrorCommand(CommandI command, boolean undo,
632 StructureSelectionManager ssm, VamsasSource source)
635 * Do nothing unless we are a 'complement' of the source. May replace this
636 * with direct calls not via SSM.
638 if (source instanceof AlignViewportI
639 && ((AlignViewportI) source).getCodingComplement() == this)
648 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
650 if (mappedCommand != null)
652 AlignmentI[] views = getAlignPanel().alignFrame.getViewAlignments();
653 mappedCommand.doCommand(views);
654 getAlignPanel().alignmentChanged();
659 * Add the sequences from the given alignment to this viewport. Optionally,
660 * may give the user the option to open a new frame, or split panel, with cDNA
661 * and protein linked.
666 public void addAlignment(AlignmentI toAdd, String title)
668 // TODO: promote to AlignViewportI? applet CutAndPasteTransfer is different
670 // JBPComment: title is a largely redundant parameter at the moment
671 // JBPComment: this really should be an 'insert/pre/append' controller
672 // JBPComment: but the DNA/Protein check makes it a bit more complex
674 // refactored from FileLoader / CutAndPasteTransfer / SequenceFetcher with
676 // TODO: create undo object for this JAL-1101
679 * Ensure datasets are created for the new alignment as
680 * mappings operate on dataset sequences
682 toAdd.setDataset(null);
685 * Check if any added sequence could be the object of a mapping or
686 * cross-reference; if so, make the mapping explicit
688 getAlignment().realiseMappings(toAdd.getSequences());
691 * If any cDNA/protein mappings exist or can be made between the alignments,
692 * offer to open a split frame with linked alignments
694 if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
696 if (AlignmentUtils.isMappable(toAdd, getAlignment()))
698 openLinkedAlignment(toAdd, title);
702 addDataToAlignment(toAdd);
706 * adds sequences to this alignment
710 void addDataToAlignment(AlignmentI toAdd)
712 // TODO: JAL-407 regardless of above - identical sequences (based on ID and
713 // provenance) should share the same dataset sequence
715 AlignmentI al = getAlignment();
716 String gap = String.valueOf(al.getGapCharacter());
717 for (int i = 0; i < toAdd.getHeight(); i++)
719 SequenceI seq = toAdd.getSequenceAt(i);
722 * - 'align' any mapped sequences as per existing
723 * e.g. cdna to genome, domain hit to protein sequence
724 * very experimental! (need a separate menu option for this)
725 * - only add mapped sequences ('select targets from a dataset')
727 if (true /*AlignmentUtils.alignSequenceAs(seq, al, gap, true, true)*/)
732 for (ContactMatrixI cm : toAdd.getContactMaps())
734 al.addContactList(cm);
736 ranges.setEndSeq(getAlignment().getHeight() - 1); // BH 2019.04.18
737 firePropertyChange("alignment", null, getAlignment().getSequences());
741 * Load a File into this AlignViewport attempting to detect format if not
742 * given or given as null.
747 public void addFile(File file, FileFormatI format)
749 addFile(file, format, true);
752 public void addFile(File file, FileFormatI format, boolean async)
754 DataSourceType protocol = AppletFormatAdapter.checkProtocol(file);
760 format = new IdentifyFile().identify(file, protocol);
761 } catch (FileFormatException e1)
763 jalview.bin.Console.error("Unknown file format for '" + file + "'");
766 else if (FileFormats.getInstance().isIdentifiable(format))
770 format = new IdentifyFile().identify(file, protocol);
771 } catch (FileFormatException e)
773 jalview.bin.Console.error("Unknown file format for '" + file + "'",
778 new FileLoader().LoadFile(this, file, DataSourceType.FILE, format,
782 public void addFile(File file)
788 * Show a dialog with the option to open and link (cDNA <-> protein) as a new
789 * alignment, either as a standalone alignment or in a split frame. Returns
790 * true if the new alignment was opened, false if not, because the user
791 * declined the offer.
796 protected void openLinkedAlignment(AlignmentI al, String title)
798 String[] options = new String[] { MessageManager.getString("action.no"),
799 MessageManager.getString("label.split_window"),
800 MessageManager.getString("label.new_window"), };
801 final String question = JvSwingUtils.wrapTooltip(true,
802 MessageManager.getString("label.open_split_window?"));
803 final AlignViewport us = this;
806 * options No, Split Window, New Window correspond to
807 * dialog responses 0, 1, 2 (even though JOptionPane shows them
810 JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.desktop)
811 .setResponseHandler(0, () -> {
812 addDataToAlignment(al);
813 }).setResponseHandler(1, () -> {
814 us.openLinkedAlignmentAs(al, title, true);
815 }).setResponseHandler(2, () -> {
816 us.openLinkedAlignmentAs(al, title, false);
818 dialog.showDialog(question,
819 MessageManager.getString("label.open_split_window"),
820 JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
821 options, options[0]);
824 protected void openLinkedAlignmentAs(AlignmentI al, String title,
825 boolean newWindowOrSplitPane)
828 * Identify protein and dna alignments. Make a copy of this one if opening
829 * in a new split pane.
831 AlignmentI thisAlignment = newWindowOrSplitPane
832 ? new Alignment(getAlignment())
834 AlignmentI protein = al.isNucleotide() ? thisAlignment : al;
835 final AlignmentI cdna = al.isNucleotide() ? al : thisAlignment;
838 * Map sequences. At least one should get mapped as we have already passed
839 * the test for 'mappability'. Any mappings made will be added to the
840 * protein alignment. Note creating dataset sequences on the new alignment
841 * is a pre-requisite for building mappings.
844 AlignmentUtils.mapProteinAlignmentToCdna(protein, cdna);
847 * Create the AlignFrame for the added alignment. If it is protein, mappings
848 * are registered with StructureSelectionManager as a side-effect.
850 AlignFrame newAlignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
851 AlignFrame.DEFAULT_HEIGHT);
852 newAlignFrame.setTitle(title);
853 newAlignFrame.setStatus(MessageManager
854 .formatMessage("label.successfully_loaded_file", new Object[]
857 // TODO if we want this (e.g. to enable reload of the alignment from file),
858 // we will need to add parameters to the stack.
859 // if (!protocol.equals(DataSourceType.PASTE))
861 // alignFrame.setFileName(file, format);
864 if (!newWindowOrSplitPane)
866 Desktop.addInternalFrame(newAlignFrame, title,
867 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
872 newAlignFrame.setMaximum(Cache.getDefault("SHOW_FULLSCREEN", false));
873 } catch (java.beans.PropertyVetoException ex)
877 if (newWindowOrSplitPane)
879 al.alignAs(thisAlignment);
880 protein = openSplitFrame(newAlignFrame, thisAlignment);
885 * Helper method to open a new SplitFrame holding linked dna and protein
888 * @param newAlignFrame
889 * containing a new alignment to be shown
891 * cdna/protein complement alignment to show in the other split half
892 * @return the protein alignment in the split frame
894 protected AlignmentI openSplitFrame(AlignFrame newAlignFrame,
895 AlignmentI complement)
898 * Make a new frame with a copy of the alignment we are adding to. If this
899 * is protein, the mappings to cDNA will be registered with
900 * StructureSelectionManager as a side-effect.
902 AlignFrame copyMe = new AlignFrame(complement, AlignFrame.DEFAULT_WIDTH,
903 AlignFrame.DEFAULT_HEIGHT);
904 copyMe.setTitle(getAlignPanel().alignFrame.getTitle());
906 AlignmentI al = newAlignFrame.viewport.getAlignment();
907 final AlignFrame proteinFrame = al.isNucleotide() ? copyMe
909 final AlignFrame cdnaFrame = al.isNucleotide() ? newAlignFrame : copyMe;
910 cdnaFrame.setVisible(true);
911 proteinFrame.setVisible(true);
912 String linkedTitle = MessageManager
913 .getString("label.linked_view_title");
916 * Open in split pane. DNA sequence above, protein below.
918 JInternalFrame splitFrame = new SplitFrame(cdnaFrame, proteinFrame);
919 Desktop.addInternalFrame(splitFrame, linkedTitle, -1, -1);
921 return proteinFrame.viewport.getAlignment();
924 public AnnotationColumnChooser getAnnotationColumnSelectionState()
926 return annotationColumnSelectionState;
929 public void setAnnotationColumnSelectionState(
930 AnnotationColumnChooser currentAnnotationColumnSelectionState)
932 this.annotationColumnSelectionState = currentAnnotationColumnSelectionState;
936 public void setIdWidth(int i)
939 AlignmentPanel ap = getAlignPanel();
942 // modify GUI elements to reflect geometry change
943 Dimension idw = ap.getIdPanel().getIdCanvas().getPreferredSize();
945 ap.getIdPanel().getIdCanvas().setPreferredSize(idw);
949 public Rectangle getExplodedGeometry()
951 return explodedGeometry;
954 public void setExplodedGeometry(Rectangle explodedPosition)
956 this.explodedGeometry = explodedPosition;
959 public boolean isGatherViewsHere()
961 return gatherViewsHere;
964 public void setGatherViewsHere(boolean gatherViewsHere)
966 this.gatherViewsHere = gatherViewsHere;
970 * If this viewport has a (Protein/cDNA) complement, then scroll the
971 * complementary alignment to match this one.
973 public void scrollComplementaryAlignment()
976 * Populate a SearchResults object with the mapped location to scroll to. If
977 * there is no complement, or it is not following highlights, or no mapping
978 * is found, the result will be empty.
980 SearchResultsI sr = new SearchResults();
981 int verticalOffset = findComplementScrollTarget(sr);
984 // TODO would like next line without cast but needs more refactoring...
985 final AlignmentPanel complementPanel = ((AlignViewport) getCodingComplement())
987 complementPanel.setToScrollComplementPanel(false);
988 complementPanel.scrollToCentre(sr, verticalOffset);
989 complementPanel.setToScrollComplementPanel(true);
994 * Answers true if no alignment holds a reference to the given mapping
999 protected boolean noReferencesTo(AlignedCodonFrame acf)
1001 AlignFrame[] frames = Desktop.getAlignFrames();
1006 for (AlignFrame af : frames)
1010 for (AlignmentViewPanel ap : af.getAlignPanels())
1012 AlignmentI al = ap.getAlignment();
1013 if (al != null && al.getCodonFrames().contains(acf))
1024 * Applies the supplied feature settings descriptor to currently known
1025 * features. This supports an 'initial configuration' of feature colouring
1026 * based on a preset or user favourite. This may then be modified in the usual
1027 * way using the Feature Settings dialogue.
1029 * @param featureSettings
1032 public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
1034 transferFeaturesStyles(featureSettings, false);
1038 * Applies the supplied feature settings descriptor to currently known
1039 * features. This supports an 'initial configuration' of feature colouring
1040 * based on a preset or user favourite. This may then be modified in the usual
1041 * way using the Feature Settings dialogue.
1043 * @param featureSettings
1046 public void mergeFeaturesStyle(FeatureSettingsModelI featureSettings)
1048 transferFeaturesStyles(featureSettings, true);
1052 * when mergeOnly is set, then group and feature visibility or feature colours
1053 * are not modified for features and groups already known to the feature
1054 * renderer. Feature ordering is always adjusted, and transparency is always
1057 * @param featureSettings
1060 private void transferFeaturesStyles(FeatureSettingsModelI featureSettings,
1063 if (featureSettings == null)
1068 FeatureRenderer fr = getAlignPanel().getSeqPanel().seqCanvas
1069 .getFeatureRenderer();
1070 List<String> origRenderOrder = new ArrayList<>();
1071 List<String> origGroups = new ArrayList<>();
1072 // preserve original render order - allows differentiation between user
1073 // configured colours and autogenerated ones
1074 origRenderOrder.addAll(fr.getRenderOrder());
1075 origGroups.addAll(fr.getFeatureGroups());
1077 fr.findAllFeatures(true);
1078 List<String> renderOrder = fr.getRenderOrder();
1079 FeaturesDisplayedI displayed = fr.getFeaturesDisplayed();
1082 // only clear displayed features if we are mergeing
1083 // displayed.clear();
1085 // TODO this clears displayed.featuresRegistered - do we care?
1087 // JAL-3330 - JBP - yes we do - calling applyFeatureStyle to a view where
1088 // feature visibility has already been configured is not very friendly
1090 * set feature colour if specified by feature settings
1091 * set visibility of all features
1093 for (String type : renderOrder)
1095 FeatureColourI preferredColour = featureSettings
1096 .getFeatureColour(type);
1097 FeatureColourI origColour = fr.getFeatureStyle(type);
1098 if (!mergeOnly || (!origRenderOrder.contains(type)
1099 || origColour == null
1100 || (!origColour.isGraduatedColour()
1101 && origColour.getColour() != null
1102 && origColour.getColour().equals(
1103 ColorUtils.createColourFromName(type)))))
1105 // if we are merging, only update if there wasn't already a colour
1108 if (preferredColour != null)
1110 fr.setColour(type, preferredColour);
1112 if (featureSettings.isFeatureDisplayed(type))
1114 displayed.setVisible(type);
1116 else if (featureSettings.isFeatureHidden(type))
1118 displayed.setHidden(type);
1124 * set visibility of feature groups
1126 for (String group : fr.getFeatureGroups())
1128 if (!mergeOnly || !origGroups.contains(group))
1130 // when merging, display groups only if the aren't already marked as not
1132 fr.setGroupVisibility(group,
1133 featureSettings.isGroupDisplayed(group));
1138 * order the features
1140 if (featureSettings.optimiseOrder())
1142 // TODO not supported (yet?)
1146 fr.orderFeatures(featureSettings);
1148 fr.setTransparency(featureSettings.getTransparency());
1150 fr.notifyFeaturesChanged();
1153 public String getViewName()
1158 public void setViewName(String viewName)
1160 this.viewName = viewName;