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.TreeModel;
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.HiddenColumns;
31 import jalview.datamodel.SearchResults;
32 import jalview.datamodel.SearchResultsI;
33 import jalview.datamodel.Sequence;
34 import jalview.datamodel.SequenceGroup;
35 import jalview.datamodel.SequenceI;
36 import jalview.renderer.ResidueShader;
37 import jalview.schemes.ColourSchemeProperty;
38 import jalview.schemes.UserColourScheme;
39 import jalview.structure.SelectionSource;
40 import jalview.structure.StructureSelectionManager;
41 import jalview.structure.VamsasSource;
42 import jalview.viewmodel.AlignmentViewport;
43 import jalview.viewmodel.ViewportRanges;
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 TreeModel 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 showOccupancy = applet.getDefaultParameter("showOccupancy",
156 setShowUnconserved(applet.getDefaultParameter("showUnconserved",
157 getShowUnconserved()));
159 setScaleProteinAsCdna(applet.getDefaultParameter(
160 "scaleProteinAsCdna", isScaleProteinAsCdna()));
162 String param = applet.getParameter("upperCase");
165 if (param.equalsIgnoreCase("bold"))
167 setUpperCasebold(true);
170 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
172 setFollowHighlight(applet.getDefaultParameter("automaticScrolling",
173 isFollowHighlight()));
174 followSelection = isFollowHighlight();
176 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
179 normaliseSequenceLogo = applet.getDefaultParameter(
180 "normaliseSequenceLogo", applet.getDefaultParameter(
181 "normaliseLogo", normaliseSequenceLogo));
183 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
186 showGroupConservation = applet.getDefaultParameter(
187 "showGroupConservation", showGroupConservation);
189 showConsensusHistogram = applet.getDefaultParameter(
190 "showConsensusHistogram", showConsensusHistogram);
196 String colour = al.isNucleotide() ? applet
197 .getParameter("defaultColourNuc") : applet
198 .getParameter("defaultColourProt");
201 colour = applet.getParameter("defaultColour");
205 colour = applet.getParameter("userDefinedColour");
208 colour = "User Defined";
214 residueShading = new ResidueShader(
215 ColourSchemeProperty.getColourScheme(alignment, colour));
216 if (residueShading != null)
218 residueShading.setConsensus(hconsensus);
222 if (applet.getParameter("userDefinedColour") != null)
224 residueShading = new ResidueShader(
225 new UserColourScheme(
226 applet.getParameter("userDefinedColour")));
229 initAutoAnnotation();
234 * get the consensus sequence as displayed under the PID consensus annotation
237 * @return consensus sequence as a new sequence object
239 public SequenceI getConsensusSeq()
241 if (consensus == null)
243 updateConsensus(null);
245 if (consensus == null)
249 StringBuilder seqs = new StringBuilder(consensus.annotations.length);
250 for (int i = 0; i < consensus.annotations.length; i++)
252 if (consensus.annotations[i] != null)
254 if (consensus.annotations[i].description.charAt(0) == '[')
256 seqs.append(consensus.annotations[i].description.charAt(1));
260 seqs.append(consensus.annotations[i].displayCharacter);
264 SequenceI sq = new Sequence("Consensus", seqs.toString());
265 sq.setDescription("Percentage Identity Consensus "
266 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
270 java.awt.Frame nullFrame;
272 protected FeatureSettings featureSettings = null;
274 private float heightScale = 1, widthScale = 1;
276 public void setFont(Font f)
279 if (nullFrame == null)
281 nullFrame = new java.awt.Frame();
282 nullFrame.addNotify();
285 java.awt.FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
286 setCharHeight((int) (heightScale * fm.getHeight()));
287 setCharWidth((int) (widthScale * fm.charWidth('M')));
289 if (isUpperCasebold())
291 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
292 fm = nullFrame.getGraphics().getFontMetrics(f2);
293 setCharWidth((int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10)));
297 public Font getFont()
302 public void resetSeqLimits(int height)
304 ranges.setEndSeq(height / getCharHeight());
307 public void setCurrentTree(TreeModel tree)
312 public TreeModel getCurrentTree()
317 boolean centreColumnLabels;
319 public boolean getCentreColumnLabels()
321 return centreColumnLabels;
324 public boolean followSelection = true;
327 * @return true if view selection should always follow the selections
328 * broadcast by other selection sources
330 public boolean getFollowSelection()
332 return followSelection;
336 public void sendSelection()
338 getStructureSelectionManager().sendSelection(
339 new SequenceGroup(getSelectionGroup()),
340 new ColumnSelection(getColumnSelection()),
341 new HiddenColumns(getAlignment().getHiddenColumns()), this);
345 * Returns an instance of the StructureSelectionManager scoped to this applet
351 public StructureSelectionManager getStructureSelectionManager()
353 return jalview.structure.StructureSelectionManager
354 .getStructureSelectionManager(applet);
358 public boolean isNormaliseSequenceLogo()
360 return normaliseSequenceLogo;
363 public void setNormaliseSequenceLogo(boolean state)
365 normaliseSequenceLogo = state;
370 * @return true if alignment characters should be displayed
373 public boolean isValidCharWidth()
375 return validCharWidth;
378 public AnnotationColumnChooser getAnnotationColumnSelectionState()
380 return annotationColumnSelectionState;
383 public void setAnnotationColumnSelectionState(
384 AnnotationColumnChooser annotationColumnSelectionState)
386 this.annotationColumnSelectionState = annotationColumnSelectionState;
390 public void mirrorCommand(CommandI command, boolean undo,
391 StructureSelectionManager ssm, VamsasSource source)
393 // TODO refactor so this can be pulled up to superclass or controller
395 * Do nothing unless we are a 'complement' of the source. May replace this
396 * with direct calls not via SSM.
398 if (source instanceof AlignViewportI
399 && ((AlignViewportI) source).getCodingComplement() == this)
408 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
410 if (mappedCommand != null)
412 mappedCommand.doCommand(null);
413 firePropertyChange("alignment", null, getAlignment().getSequences());
415 // ap.scalePanelHolder.repaint();
421 public VamsasSource getVamsasSource()
427 * If this viewport has a (Protein/cDNA) complement, then scroll the
428 * complementary alignment to match this one.
430 public void scrollComplementaryAlignment(AlignmentPanel complementPanel)
432 if (complementPanel == null)
438 * Populate a SearchResults object with the mapped location to scroll to. If
439 * there is no complement, or it is not following highlights, or no mapping
440 * is found, the result will be empty.
442 SearchResultsI sr = new SearchResults();
443 int seqOffset = findComplementScrollTarget(sr);
446 complementPanel.setFollowingComplementScroll(true);
447 complementPanel.scrollToCentre(sr, seqOffset);
452 * Applies the supplied feature settings descriptor to currently known
453 * features. This supports an 'initial configuration' of feature colouring
454 * based on a preset or user favourite. This may then be modified in the usual
455 * way using the Feature Settings dialogue.
457 * @param featureSettings
460 public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
462 // TODO implement for applet