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.
21 package jalview.appletgui;
23 import jalview.analysis.NJTree;
24 import jalview.api.AlignViewportI;
25 import jalview.api.FeatureSettingsModelI;
26 import jalview.bin.JalviewLite;
27 import jalview.commands.CommandI;
28 import jalview.datamodel.AlignmentI;
29 import jalview.datamodel.ColumnSelection;
30 import jalview.datamodel.SearchResults;
31 import jalview.datamodel.SearchResultsI;
32 import jalview.datamodel.Sequence;
33 import jalview.datamodel.SequenceGroup;
34 import jalview.datamodel.SequenceI;
35 import jalview.renderer.ResidueShader;
36 import jalview.schemes.ColourSchemeProperty;
37 import jalview.schemes.UserColourScheme;
38 import jalview.structure.SelectionSource;
39 import jalview.structure.StructureSelectionManager;
40 import jalview.structure.VamsasSource;
41 import jalview.viewmodel.AlignmentViewport;
42 import jalview.viewmodel.ViewportRanges;
45 import java.awt.FontMetrics;
47 public class AlignViewport extends AlignmentViewport implements
50 boolean cursorMode = false;
52 Font font = new Font("SansSerif", Font.PLAIN, 10);
54 boolean validCharWidth = true;
56 NJTree currentTree = null;
58 public jalview.bin.JalviewLite applet;
62 private AnnotationColumnChooser annotationColumnSelectionState;
65 public void finalize()
73 public AlignViewport(AlignmentI al, JalviewLite applet)
76 calculator = new jalview.workers.AlignCalcManager();
79 ranges = new ViewportRanges(this.alignment);
81 this.setPadGaps(true);
85 // get the width and height scaling factors if they were specified
86 String param = applet.getParameter("widthScale");
91 widthScale = new Float(param).floatValue();
95 if (widthScale <= 1.0)
98 .println("Invalid alignment character width scaling factor ("
99 + widthScale + "). Ignoring.");
102 if (JalviewLite.debug)
105 .println("Alignment character width scaling factor is now "
109 param = applet.getParameter("heightScale");
114 heightScale = new Float(param).floatValue();
115 } catch (Exception e)
118 if (heightScale <= 1.0)
121 .println("Invalid alignment character height scaling factor ("
122 + heightScale + "). Ignoring.");
125 if (JalviewLite.debug)
128 .println("Alignment character height scaling factor is now "
135 MAC = new jalview.util.Platform().isAMac();
139 setShowJVSuffix(applet.getDefaultParameter("showFullId",
142 setShowAnnotation(applet.getDefaultParameter("showAnnotation",
143 isShowAnnotation()));
145 showConservation = applet.getDefaultParameter("showConservation",
148 showQuality = applet.getDefaultParameter("showQuality", showQuality);
150 showConsensus = applet.getDefaultParameter("showConsensus",
153 setShowUnconserved(applet.getDefaultParameter("showUnconserved",
154 getShowUnconserved()));
156 setScaleProteinAsCdna(applet.getDefaultParameter(
157 "scaleProteinAsCdna", isScaleProteinAsCdna()));
159 String param = applet.getParameter("upperCase");
162 if (param.equalsIgnoreCase("bold"))
164 setUpperCasebold(true);
167 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
169 setFollowHighlight(applet.getDefaultParameter("automaticScrolling",
170 isFollowHighlight()));
171 followSelection = isFollowHighlight();
173 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
176 normaliseSequenceLogo = applet.getDefaultParameter(
177 "normaliseSequenceLogo", applet.getDefaultParameter(
178 "normaliseLogo", normaliseSequenceLogo));
180 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
183 showGroupConservation = applet.getDefaultParameter(
184 "showGroupConservation", showGroupConservation);
186 showConsensusHistogram = applet.getDefaultParameter(
187 "showConsensusHistogram", showConsensusHistogram);
193 String colour = al.isNucleotide() ? applet
194 .getParameter("defaultColourNuc") : applet
195 .getParameter("defaultColourProt");
198 colour = applet.getParameter("defaultColour");
202 colour = applet.getParameter("userDefinedColour");
205 colour = "User Defined";
211 residueShading = new ResidueShader(
212 ColourSchemeProperty.getColourScheme(alignment, colour));
213 if (residueShading != null)
215 residueShading.setConsensus(hconsensus);
219 if (applet.getParameter("userDefinedColour") != null)
221 residueShading = new ResidueShader(
222 new UserColourScheme(
223 applet.getParameter("userDefinedColour")));
226 initAutoAnnotation();
231 * get the consensus sequence as displayed under the PID consensus annotation
234 * @return consensus sequence as a new sequence object
236 public SequenceI getConsensusSeq()
238 if (consensus == null)
240 updateConsensus(null);
242 if (consensus == null)
246 StringBuilder seqs = new StringBuilder(consensus.annotations.length);
247 for (int i = 0; i < consensus.annotations.length; i++)
249 if (consensus.annotations[i] != null)
251 if (consensus.annotations[i].description.charAt(0) == '[')
253 seqs.append(consensus.annotations[i].description.charAt(1));
257 seqs.append(consensus.annotations[i].displayCharacter);
261 SequenceI sq = new Sequence("Consensus", seqs.toString());
262 sq.setDescription("Percentage Identity Consensus "
263 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
267 java.awt.Frame nullFrame;
269 protected FeatureSettings featureSettings = null;
271 private float heightScale = 1, widthScale = 1;
277 public void setFont(Font f, boolean setGrid)
280 if (nullFrame == null)
282 nullFrame = new java.awt.Frame();
283 nullFrame.addNotify();
288 FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
289 setCharHeight((int) (heightScale * fm.getHeight()));
290 setCharWidth((int) (widthScale * fm.charWidth('M')));
293 if (isUpperCasebold())
295 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
296 FontMetrics fm = nullFrame.getGraphics().getFontMetrics(f2);
297 setCharWidth((int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10)));
301 public Font getFont()
306 public void resetSeqLimits(int height)
308 ranges.setEndSeq(height / getCharHeight());
311 public void setCurrentTree(NJTree tree)
316 public NJTree getCurrentTree()
321 boolean centreColumnLabels;
323 public boolean getCentreColumnLabels()
325 return centreColumnLabels;
328 public boolean followSelection = true;
331 * @return true if view selection should always follow the selections
332 * broadcast by other selection sources
334 public boolean getFollowSelection()
336 return followSelection;
340 public void sendSelection()
342 getStructureSelectionManager().sendSelection(
343 new SequenceGroup(getSelectionGroup()),
344 new ColumnSelection(getColumnSelection()), this);
348 * Returns an instance of the StructureSelectionManager scoped to this applet
354 public StructureSelectionManager getStructureSelectionManager()
356 return jalview.structure.StructureSelectionManager
357 .getStructureSelectionManager(applet);
361 public boolean isNormaliseSequenceLogo()
363 return normaliseSequenceLogo;
366 public void setNormaliseSequenceLogo(boolean state)
368 normaliseSequenceLogo = state;
373 * @return true if alignment characters should be displayed
376 public boolean isValidCharWidth()
378 return validCharWidth;
381 public AnnotationColumnChooser getAnnotationColumnSelectionState()
383 return annotationColumnSelectionState;
386 public void setAnnotationColumnSelectionState(
387 AnnotationColumnChooser annotationColumnSelectionState)
389 this.annotationColumnSelectionState = annotationColumnSelectionState;
393 public void mirrorCommand(CommandI command, boolean undo,
394 StructureSelectionManager ssm, VamsasSource source)
396 // TODO refactor so this can be pulled up to superclass or controller
398 * Do nothing unless we are a 'complement' of the source. May replace this
399 * with direct calls not via SSM.
401 if (source instanceof AlignViewportI
402 && ((AlignViewportI) source).getCodingComplement() == this)
411 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
413 if (mappedCommand != null)
415 mappedCommand.doCommand(null);
416 firePropertyChange("alignment", null, getAlignment().getSequences());
418 // ap.scalePanelHolder.repaint();
424 public VamsasSource getVamsasSource()
430 * If this viewport has a (Protein/cDNA) complement, then scroll the
431 * complementary alignment to match this one.
433 public void scrollComplementaryAlignment(AlignmentPanel complementPanel)
435 if (complementPanel == null)
441 * Populate a SearchResults object with the mapped location to scroll to. If
442 * there is no complement, or it is not following highlights, or no mapping
443 * is found, the result will be empty.
445 SearchResultsI sr = new SearchResults();
446 int seqOffset = findComplementScrollTarget(sr);
449 complementPanel.setFollowingComplementScroll(true);
450 complementPanel.scrollToCentre(sr, seqOffset);
455 * Applies the supplied feature settings descriptor to currently known
456 * features. This supports an 'initial configuration' of feature colouring
457 * based on a preset or user favourite. This may then be modified in the usual
458 * way using the Feature Settings dialogue.
460 * @param featureSettings
463 public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
465 // TODO implement for applet