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;
25 import jalview.analysis.NJTree;
26 import jalview.api.AlignViewportI;
27 import jalview.api.FeatureRenderer;
28 import jalview.bin.JalviewLite;
29 import jalview.commands.CommandI;
30 import jalview.datamodel.AlignmentI;
31 import jalview.datamodel.ColumnSelection;
32 import jalview.datamodel.SearchResults;
33 import jalview.datamodel.Sequence;
34 import jalview.datamodel.SequenceGroup;
35 import jalview.datamodel.SequenceI;
36 import jalview.schemes.ColourSchemeProperty;
37 import jalview.schemes.UserColourScheme;
38 import jalview.structure.CommandListener;
39 import jalview.structure.SelectionSource;
40 import jalview.structure.StructureSelectionManager;
41 import jalview.structure.VamsasSource;
42 import jalview.viewmodel.AlignmentViewport;
44 public class AlignViewport extends AlignmentViewport implements
45 SelectionSource, VamsasSource, CommandListener
47 boolean cursorMode = false;
49 Font font = new Font("SansSerif", Font.PLAIN, 10);
51 boolean validCharWidth = true;
53 NJTree currentTree = null;
55 public jalview.bin.JalviewLite applet;
59 private AnnotationColumnChooser annotationColumnSelectionState;
61 private FeatureRenderer featureRenderer;
63 private boolean includeHiddenRegion = true;
65 public void finalize()
73 public AlignViewport(AlignmentI al, JalviewLite applet)
76 calculator = new jalview.workers.AlignCalcManager();
80 this.setPadGaps(true);
82 this.endRes = al.getWidth() - 1;
84 this.endSeq = al.getHeight() - 1;
87 // get the width and height scaling factors if they were specified
88 String param = applet.getParameter("widthScale");
93 widthScale = new Float(param).floatValue();
97 if (widthScale <= 1.0)
100 .println("Invalid alignment character width scaling factor ("
101 + widthScale + "). Ignoring.");
104 if (JalviewLite.debug)
107 .println("Alignment character width scaling factor is now "
111 param = applet.getParameter("heightScale");
116 heightScale = new Float(param).floatValue();
117 } catch (Exception e)
120 if (heightScale <= 1.0)
123 .println("Invalid alignment character height scaling factor ("
124 + heightScale + "). Ignoring.");
127 if (JalviewLite.debug)
130 .println("Alignment character height scaling factor is now "
137 MAC = new jalview.util.Platform().isAMac();
141 setShowJVSuffix(applet.getDefaultParameter("showFullId",
144 setShowAnnotation(applet.getDefaultParameter("showAnnotation",
145 isShowAnnotation()));
147 showConservation = applet.getDefaultParameter("showConservation",
150 showQuality = applet.getDefaultParameter("showQuality", showQuality);
152 showConsensus = applet.getDefaultParameter("showConsensus",
155 setShowUnconserved(applet.getDefaultParameter("showUnconserved",
156 getShowUnconserved()));
158 setScaleProteinAsCdna(applet.getDefaultParameter(
159 "scaleProteinAsCdna", isScaleProteinAsCdna()));
161 String param = applet.getParameter("upperCase");
164 if (param.equalsIgnoreCase("bold"))
166 setUpperCasebold(true);
169 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
171 setFollowHighlight(applet.getDefaultParameter("automaticScrolling",
172 isFollowHighlight()));
173 followSelection = isFollowHighlight();
175 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
178 normaliseSequenceLogo = applet.getDefaultParameter(
179 "normaliseSequenceLogo", applet.getDefaultParameter(
180 "normaliseLogo", normaliseSequenceLogo));
182 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
185 showGroupConservation = applet.getDefaultParameter(
186 "showGroupConservation", showGroupConservation);
188 showConsensusHistogram = applet.getDefaultParameter(
189 "showConsensusHistogram", showConsensusHistogram);
195 String colour = applet.getParameter("defaultColour");
199 colour = applet.getParameter("userDefinedColour");
202 colour = "User Defined";
208 globalColourScheme = ColourSchemeProperty.getColour(alignment,
210 if (globalColourScheme != null)
212 globalColourScheme.setConsensus(hconsensus);
216 if (applet.getParameter("userDefinedColour") != null)
218 ((UserColourScheme) globalColourScheme).parseAppletParameter(applet
219 .getParameter("userDefinedColour"));
222 initAutoAnnotation();
227 * get the consensus sequence as displayed under the PID consensus annotation
230 * @return consensus sequence as a new sequence object
232 public SequenceI getConsensusSeq()
234 if (consensus == null)
236 updateConsensus(null);
238 if (consensus == null)
242 StringBuilder seqs = new StringBuilder(consensus.annotations.length);
243 for (int i = 0; i < consensus.annotations.length; i++)
245 if (consensus.annotations[i] != null)
247 if (consensus.annotations[i].description.charAt(0) == '[')
249 seqs.append(consensus.annotations[i].description.charAt(1));
253 seqs.append(consensus.annotations[i].displayCharacter);
257 SequenceI sq = new Sequence("Consensus", seqs.toString());
258 sq.setDescription("Percentage Identity Consensus "
259 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
263 java.awt.Frame nullFrame;
265 protected FeatureSettings featureSettings = null;
267 private float heightScale = 1, widthScale = 1;
269 public void setFont(Font f)
272 if (nullFrame == null)
274 nullFrame = new java.awt.Frame();
275 nullFrame.addNotify();
278 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
279 setCharHeight((int) (heightScale * fm.getHeight()));
280 setCharWidth((int) (widthScale * fm.charWidth('M')));
282 if (isUpperCasebold())
284 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
285 fm = nullFrame.getGraphics().getFontMetrics(f2);
286 setCharWidth((int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10)));
290 public Font getFont()
296 public void resetSeqLimits(int height)
298 setEndSeq(height / getCharHeight());
301 public void setCurrentTree(NJTree tree)
306 public NJTree getCurrentTree()
312 boolean centreColumnLabels;
314 public boolean getCentreColumnLabels()
316 return centreColumnLabels;
319 public boolean followSelection = true;
322 * @return true if view selection should always follow the selections
323 * broadcast by other selection sources
325 public boolean getFollowSelection()
327 return followSelection;
330 public void sendSelection()
332 getStructureSelectionManager().sendSelection(
333 new SequenceGroup(getSelectionGroup()),
334 new ColumnSelection(getColumnSelection()), this);
338 * Returns an instance of the StructureSelectionManager scoped to this applet
344 public StructureSelectionManager getStructureSelectionManager()
346 return jalview.structure.StructureSelectionManager
347 .getStructureSelectionManager(applet);
351 * synthesize a column selection if none exists so it covers the given
352 * selection group. if wholewidth is false, no column selection is made if the
353 * selection group covers the whole alignment width.
358 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
362 && (sgs = sg.getStartRes()) >= 0
363 && sg.getStartRes() <= (sge = sg.getEndRes())
364 && (colSel == null || colSel.getSelected() == null || colSel
365 .getSelected().size() == 0))
367 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
374 colSel = new ColumnSelection();
376 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
378 colSel.addElement(cspos);
383 public boolean isNormaliseSequenceLogo()
385 return normaliseSequenceLogo;
388 public void setNormaliseSequenceLogo(boolean state)
390 normaliseSequenceLogo = state;
395 * @return true if alignment characters should be displayed
397 public boolean isValidCharWidth()
399 return validCharWidth;
402 public AnnotationColumnChooser getAnnotationColumnSelectionState()
404 return annotationColumnSelectionState;
407 public void setAnnotationColumnSelectionState(
408 AnnotationColumnChooser annotationColumnSelectionState)
410 this.annotationColumnSelectionState = annotationColumnSelectionState;
414 public void mirrorCommand(CommandI command, boolean undo,
415 StructureSelectionManager ssm, VamsasSource source)
417 // TODO refactor so this can be pulled up to superclass or controller
419 * Do nothing unless we are a 'complement' of the source. May replace this
420 * with direct calls not via SSM.
422 if (source instanceof AlignViewportI
423 && ((AlignViewportI) source).getCodingComplement() == this)
432 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
434 if (mappedCommand != null)
436 mappedCommand.doCommand(null);
437 firePropertyChange("alignment", null, getAlignment().getSequences());
439 // ap.scalePanelHolder.repaint();
445 public VamsasSource getVamsasSource()
451 * If this viewport has a (Protein/cDNA) complement, then scroll the
452 * complementary alignment to match this one.
454 public void scrollComplementaryAlignment(AlignmentPanel complementPanel)
456 if (complementPanel == null)
462 * Populate a SearchResults object with the mapped location to scroll to. If
463 * there is no complement, or it is not following highlights, or no mapping
464 * is found, the result will be empty.
466 SearchResults sr = new SearchResults();
467 int seqOffset = findComplementScrollTarget(sr);
470 complementPanel.setFollowingComplementScroll(true);
471 complementPanel.scrollToCentre(sr, seqOffset);
476 public FeatureRenderer getFeatureRenderer()
478 return featureRenderer;
482 public void setFeatureRenderer(FeatureRenderer featureRenderer)
484 this.featureRenderer = featureRenderer;
488 public boolean isIncludeHiddenRegion()
490 return includeHiddenRegion;
493 public void setIncludeHiddenRegion(boolean includeHiddenRegion)
495 this.includeHiddenRegion = includeHiddenRegion;