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.bin.JalviewLite;
26 import jalview.commands.CommandI;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.ColumnSelection;
29 import jalview.datamodel.SearchResults;
30 import jalview.datamodel.Sequence;
31 import jalview.datamodel.SequenceGroup;
32 import jalview.datamodel.SequenceI;
33 import jalview.schemes.ColourSchemeProperty;
34 import jalview.schemes.UserColourScheme;
35 import jalview.structure.CommandListener;
36 import jalview.structure.SelectionSource;
37 import jalview.structure.StructureSelectionManager;
38 import jalview.structure.VamsasSource;
39 import jalview.viewmodel.AlignmentViewport;
43 public class AlignViewport extends AlignmentViewport implements
44 SelectionSource, VamsasSource, CommandListener
46 boolean cursorMode = false;
48 Font font = new Font("SansSerif", Font.PLAIN, 10);
50 boolean validCharWidth = true;
52 NJTree currentTree = null;
54 public jalview.bin.JalviewLite applet;
58 private AnnotationColumnChooser annotationColumnSelectionState;
60 public void finalize()
68 public AlignViewport(AlignmentI al, JalviewLite applet)
71 calculator = new jalview.workers.AlignCalcManager();
75 this.setPadGaps(true);
77 this.endRes = al.getWidth() - 1;
79 this.endSeq = al.getHeight() - 1;
82 // get the width and height scaling factors if they were specified
83 String param = applet.getParameter("widthScale");
88 widthScale = new Float(param).floatValue();
92 if (widthScale <= 1.0)
95 .println("Invalid alignment character width scaling factor ("
96 + widthScale + "). Ignoring.");
99 if (JalviewLite.debug)
102 .println("Alignment character width scaling factor is now "
106 param = applet.getParameter("heightScale");
111 heightScale = new Float(param).floatValue();
112 } catch (Exception e)
115 if (heightScale <= 1.0)
118 .println("Invalid alignment character height scaling factor ("
119 + heightScale + "). Ignoring.");
122 if (JalviewLite.debug)
125 .println("Alignment character height scaling factor is now "
132 MAC = new jalview.util.Platform().isAMac();
136 setShowJVSuffix(applet.getDefaultParameter("showFullId",
139 setShowAnnotation(applet.getDefaultParameter("showAnnotation",
140 isShowAnnotation()));
142 showConservation = applet.getDefaultParameter("showConservation",
145 showQuality = applet.getDefaultParameter("showQuality", showQuality);
147 showConsensus = applet.getDefaultParameter("showConsensus",
150 setShowUnconserved(applet.getDefaultParameter("showUnconserved",
151 getShowUnconserved()));
153 setScaleProteinAsCdna(applet.getDefaultParameter(
154 "scaleProteinAsCdna", isScaleProteinAsCdna()));
156 String param = applet.getParameter("upperCase");
159 if (param.equalsIgnoreCase("bold"))
161 setUpperCasebold(true);
164 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
166 setFollowHighlight(applet.getDefaultParameter("automaticScrolling",
167 isFollowHighlight()));
168 followSelection = isFollowHighlight();
170 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
173 normaliseSequenceLogo = applet.getDefaultParameter(
174 "normaliseSequenceLogo", applet.getDefaultParameter(
175 "normaliseLogo", normaliseSequenceLogo));
177 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
180 showGroupConservation = applet.getDefaultParameter(
181 "showGroupConservation", showGroupConservation);
183 showConsensusHistogram = applet.getDefaultParameter(
184 "showConsensusHistogram", showConsensusHistogram);
190 String colour = applet.getParameter("defaultColour");
194 colour = applet.getParameter("userDefinedColour");
197 colour = "User Defined";
203 globalColourScheme = ColourSchemeProperty.getColour(alignment,
205 if (globalColourScheme != null)
207 globalColourScheme.setConsensus(hconsensus);
211 if (applet.getParameter("userDefinedColour") != null)
213 ((UserColourScheme) globalColourScheme).parseAppletParameter(applet
214 .getParameter("userDefinedColour"));
217 initAutoAnnotation();
222 * get the consensus sequence as displayed under the PID consensus annotation
225 * @return consensus sequence as a new sequence object
227 public SequenceI getConsensusSeq()
229 if (consensus == null)
231 updateConsensus(null);
233 if (consensus == null)
237 StringBuilder seqs = new StringBuilder(consensus.annotations.length);
238 for (int i = 0; i < consensus.annotations.length; i++)
240 if (consensus.annotations[i] != null)
242 if (consensus.annotations[i].description.charAt(0) == '[')
244 seqs.append(consensus.annotations[i].description.charAt(1));
248 seqs.append(consensus.annotations[i].displayCharacter);
252 SequenceI sq = new Sequence("Consensus", seqs.toString());
253 sq.setDescription("Percentage Identity Consensus "
254 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
258 java.awt.Frame nullFrame;
260 protected FeatureSettings featureSettings = null;
262 private float heightScale = 1, widthScale = 1;
264 public void setFont(Font f)
267 if (nullFrame == null)
269 nullFrame = new java.awt.Frame();
270 nullFrame.addNotify();
273 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
274 setCharHeight((int) (heightScale * fm.getHeight()));
275 setCharWidth((int) (widthScale * fm.charWidth('M')));
277 if (isUpperCasebold())
279 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
280 fm = nullFrame.getGraphics().getFontMetrics(f2);
281 setCharWidth((int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10)));
285 public Font getFont()
291 public void resetSeqLimits(int height)
293 setEndSeq(height / getCharHeight());
296 public void setCurrentTree(NJTree tree)
301 public NJTree getCurrentTree()
307 boolean centreColumnLabels;
309 public boolean getCentreColumnLabels()
311 return centreColumnLabels;
314 public boolean followSelection = true;
317 * @return true if view selection should always follow the selections
318 * broadcast by other selection sources
320 public boolean getFollowSelection()
322 return followSelection;
325 public void sendSelection()
327 getStructureSelectionManager().sendSelection(
328 new SequenceGroup(getSelectionGroup()),
329 new ColumnSelection(getColumnSelection()), this);
333 * Returns an instance of the StructureSelectionManager scoped to this applet
339 public StructureSelectionManager getStructureSelectionManager()
341 return jalview.structure.StructureSelectionManager
342 .getStructureSelectionManager(applet);
346 * synthesize a column selection if none exists so it covers the given
347 * selection group. if wholewidth is false, no column selection is made if the
348 * selection group covers the whole alignment width.
353 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
357 && (sgs = sg.getStartRes()) >= 0
358 && sg.getStartRes() <= (sge = sg.getEndRes())
359 && (colSel == null || colSel.getSelected() == null || colSel
360 .getSelected().size() == 0))
362 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
369 colSel = new ColumnSelection();
371 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
373 colSel.addElement(cspos);
378 public boolean isNormaliseSequenceLogo()
380 return normaliseSequenceLogo;
383 public void setNormaliseSequenceLogo(boolean state)
385 normaliseSequenceLogo = state;
390 * @return true if alignment characters should be displayed
392 public boolean isValidCharWidth()
394 return validCharWidth;
397 public AnnotationColumnChooser getAnnotationColumnSelectionState()
399 return annotationColumnSelectionState;
402 public void setAnnotationColumnSelectionState(
403 AnnotationColumnChooser annotationColumnSelectionState)
405 this.annotationColumnSelectionState = annotationColumnSelectionState;
409 public void mirrorCommand(CommandI command, boolean undo,
410 StructureSelectionManager ssm, VamsasSource source)
412 // TODO refactor so this can be pulled up to superclass or controller
414 * Do nothing unless we are a 'complement' of the source. May replace this
415 * with direct calls not via SSM.
417 if (source instanceof AlignViewportI
418 && ((AlignViewportI) source).getCodingComplement() == this)
427 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
429 if (mappedCommand != null)
431 mappedCommand.doCommand(null);
432 firePropertyChange("alignment", null, getAlignment().getSequences());
434 // ap.scalePanelHolder.repaint();
440 public VamsasSource getVamsasSource()
446 * If this viewport has a (Protein/cDNA) complement, then scroll the
447 * complementary alignment to match this one.
449 public void scrollComplementaryAlignment(AlignmentPanel complementPanel)
451 if (complementPanel == null)
457 * Populate a SearchResults object with the mapped location to scroll to. If
458 * there is no complement, or it is not following highlights, or no mapping
459 * is found, the result will be empty.
461 SearchResults sr = new SearchResults();
462 int seqOffset = findComplementScrollTarget(sr);
465 complementPanel.setFollowingComplementScroll(true);
466 complementPanel.scrollToCentre(sr, seqOffset);