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;
45 public class AlignViewport extends AlignmentViewport implements
48 boolean cursorMode = false;
50 Font font = new Font("SansSerif", Font.PLAIN, 10);
52 boolean validCharWidth = true;
54 NJTree currentTree = null;
56 public jalview.bin.JalviewLite applet;
60 private AnnotationColumnChooser annotationColumnSelectionState;
63 public void finalize()
71 public AlignViewport(AlignmentI al, JalviewLite applet)
74 calculator = new jalview.workers.AlignCalcManager();
78 this.setPadGaps(true);
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 = al.isNucleotide() ? applet
191 .getParameter("defaultColourNuc") : applet
192 .getParameter("defaultColourProt");
195 colour = applet.getParameter("defaultColour");
199 colour = applet.getParameter("userDefinedColour");
202 colour = "User Defined";
208 residueShading = new ResidueShader(
209 ColourSchemeProperty.getColourScheme(alignment, colour));
210 if (residueShading != null)
212 residueShading.setConsensus(hconsensus);
216 if (applet.getParameter("userDefinedColour") != null)
218 residueShading = new ResidueShader(
219 new UserColourScheme(
220 applet.getParameter("userDefinedColour")));
223 initAutoAnnotation();
228 * get the consensus sequence as displayed under the PID consensus annotation
231 * @return consensus sequence as a new sequence object
233 public SequenceI getConsensusSeq()
235 if (consensus == null)
237 updateConsensus(null);
239 if (consensus == null)
243 StringBuilder seqs = new StringBuilder(consensus.annotations.length);
244 for (int i = 0; i < consensus.annotations.length; i++)
246 if (consensus.annotations[i] != null)
248 if (consensus.annotations[i].description.charAt(0) == '[')
250 seqs.append(consensus.annotations[i].description.charAt(1));
254 seqs.append(consensus.annotations[i].displayCharacter);
258 SequenceI sq = new Sequence("Consensus", seqs.toString());
259 sq.setDescription("Percentage Identity Consensus "
260 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
264 java.awt.Frame nullFrame;
266 protected FeatureSettings featureSettings = null;
268 private float heightScale = 1, widthScale = 1;
270 public void setFont(Font f)
273 if (nullFrame == null)
275 nullFrame = new java.awt.Frame();
276 nullFrame.addNotify();
279 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
280 setCharHeight((int) (heightScale * fm.getHeight()));
281 setCharWidth((int) (widthScale * fm.charWidth('M')));
283 if (isUpperCasebold())
285 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
286 fm = nullFrame.getGraphics().getFontMetrics(f2);
287 setCharWidth((int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10)));
291 public Font getFont()
296 public void resetSeqLimits(int height)
298 ranges.setEndSeq(height / getCharHeight());
301 public void setCurrentTree(NJTree tree)
306 public NJTree getCurrentTree()
311 boolean centreColumnLabels;
313 public boolean getCentreColumnLabels()
315 return centreColumnLabels;
318 public boolean followSelection = true;
321 * @return true if view selection should always follow the selections
322 * broadcast by other selection sources
324 public boolean getFollowSelection()
326 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 public boolean isNormaliseSequenceLogo()
353 return normaliseSequenceLogo;
356 public void setNormaliseSequenceLogo(boolean state)
358 normaliseSequenceLogo = state;
363 * @return true if alignment characters should be displayed
366 public boolean isValidCharWidth()
368 return validCharWidth;
371 public AnnotationColumnChooser getAnnotationColumnSelectionState()
373 return annotationColumnSelectionState;
376 public void setAnnotationColumnSelectionState(
377 AnnotationColumnChooser annotationColumnSelectionState)
379 this.annotationColumnSelectionState = annotationColumnSelectionState;
383 public void mirrorCommand(CommandI command, boolean undo,
384 StructureSelectionManager ssm, VamsasSource source)
386 // TODO refactor so this can be pulled up to superclass or controller
388 * Do nothing unless we are a 'complement' of the source. May replace this
389 * with direct calls not via SSM.
391 if (source instanceof AlignViewportI
392 && ((AlignViewportI) source).getCodingComplement() == this)
401 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
403 if (mappedCommand != null)
405 mappedCommand.doCommand(null);
406 firePropertyChange("alignment", null, getAlignment().getSequences());
408 // ap.scalePanelHolder.repaint();
414 public VamsasSource getVamsasSource()
420 * If this viewport has a (Protein/cDNA) complement, then scroll the
421 * complementary alignment to match this one.
423 public void scrollComplementaryAlignment(AlignmentPanel complementPanel)
425 if (complementPanel == null)
431 * Populate a SearchResults object with the mapped location to scroll to. If
432 * there is no complement, or it is not following highlights, or no mapping
433 * is found, the result will be empty.
435 SearchResultsI sr = new SearchResults();
436 int seqOffset = findComplementScrollTarget(sr);
439 complementPanel.setFollowingComplementScroll(true);
440 complementPanel.scrollToCentre(sr, seqOffset);
445 * Applies the supplied feature settings descriptor to currently known
446 * features. This supports an 'initial configuration' of feature colouring
447 * based on a preset or user favourite. This may then be modified in the usual
448 * way using the Feature Settings dialogue.
450 * @param featureSettings
453 public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
455 // TODO implement for applet