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.api.AlignViewportI;
24 import jalview.api.FeatureSettingsModelI;
25 import jalview.bin.JalviewLite;
26 import jalview.commands.CommandI;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.Annotation;
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;
45 import java.awt.FontMetrics;
47 public class AlignViewport extends AlignmentViewport
48 implements SelectionSource
50 boolean cursorMode = false;
52 Font font = new Font("SansSerif", Font.PLAIN, 10);
54 boolean validCharWidth = true;
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 "Invalid alignment character width scaling factor ("
96 + widthScale + "). Ignoring.");
99 if (JalviewLite.debug)
102 "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 "Invalid alignment character height scaling factor ("
119 + heightScale + "). Ignoring.");
122 if (JalviewLite.debug)
125 "Alignment character height scaling factor is now "
132 MAC = new jalview.util.Platform().isAMac();
137 applet.getDefaultParameter("showFullId", getShowJVSuffix()));
139 setShowAnnotation(applet.getDefaultParameter("showAnnotation",
140 isShowAnnotation()));
142 showConservation = applet.getDefaultParameter("showConservation",
145 showQuality = applet.getDefaultParameter("showQuality", showQuality);
147 showConsensus = applet.getDefaultParameter("showConsensus",
150 showOccupancy = applet.getDefaultParameter("showOccupancy",
153 setShowUnconserved(applet.getDefaultParameter("showUnconserved",
154 getShowUnconserved()));
156 setScaleProteinAsCdna(applet.getDefaultParameter("scaleProteinAsCdna",
157 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()
194 ? applet.getParameter("defaultColourNuc")
195 : applet.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(new UserColourScheme(
222 applet.getParameter("userDefinedColour")));
225 initAutoAnnotation();
229 java.awt.Frame nullFrame;
231 protected FeatureSettings featureSettings = null;
233 private float heightScale = 1, widthScale = 1;
239 public void setFont(Font f, boolean setGrid)
242 if (nullFrame == null)
244 nullFrame = new java.awt.Frame();
245 nullFrame.addNotify();
250 FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
251 setCharHeight((int) (heightScale * fm.getHeight()));
252 setCharWidth((int) (widthScale * fm.charWidth('M')));
255 if (isUpperCasebold())
257 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
258 FontMetrics fm = nullFrame.getGraphics().getFontMetrics(f2);
260 (int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10)));
264 public Font getFont()
269 public void resetSeqLimits(int height)
271 ranges.setEndSeq(height / getCharHeight());
274 boolean centreColumnLabels;
276 public boolean getCentreColumnLabels()
278 return centreColumnLabels;
281 public boolean followSelection = true;
284 * @return true if view selection should always follow the selections
285 * broadcast by other selection sources
287 public boolean getFollowSelection()
289 return followSelection;
293 public void sendSelection()
295 getStructureSelectionManager().sendSelection(
296 new SequenceGroup(getSelectionGroup()),
297 new ColumnSelection(getColumnSelection()),
298 new HiddenColumns(getAlignment().getHiddenColumns()), this);
302 * Returns an instance of the StructureSelectionManager scoped to this applet
308 public StructureSelectionManager getStructureSelectionManager()
310 return jalview.structure.StructureSelectionManager
311 .getStructureSelectionManager(applet);
315 public boolean isNormaliseSequenceLogo()
317 return normaliseSequenceLogo;
320 public void setNormaliseSequenceLogo(boolean state)
322 normaliseSequenceLogo = state;
327 * @return true if alignment characters should be displayed
330 public boolean isValidCharWidth()
332 return validCharWidth;
335 public AnnotationColumnChooser getAnnotationColumnSelectionState()
337 return annotationColumnSelectionState;
340 public void setAnnotationColumnSelectionState(
341 AnnotationColumnChooser annotationColumnSelectionState)
343 this.annotationColumnSelectionState = annotationColumnSelectionState;
347 public void mirrorCommand(CommandI command, boolean undo,
348 StructureSelectionManager ssm, VamsasSource source)
350 // TODO refactor so this can be pulled up to superclass or controller
352 * Do nothing unless we are a 'complement' of the source. May replace this
353 * with direct calls not via SSM.
355 if (source instanceof AlignViewportI
356 && ((AlignViewportI) source).getCodingComplement() == this)
365 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
367 if (mappedCommand != null)
369 mappedCommand.doCommand(null);
370 firePropertyChange("alignment", null, getAlignment().getSequences());
372 // ap.scalePanelHolder.repaint();
378 public VamsasSource getVamsasSource()
384 * If this viewport has a (Protein/cDNA) complement, then scroll the
385 * complementary alignment to match this one.
387 public void scrollComplementaryAlignment(AlignmentPanel complementPanel)
389 if (complementPanel == null)
395 * Populate a SearchResults object with the mapped location to scroll to. If
396 * there is no complement, or it is not following highlights, or no mapping
397 * is found, the result will be empty.
399 SearchResultsI sr = new SearchResults();
400 int seqOffset = findComplementScrollTarget(sr);
403 complementPanel.setToScrollComplementPanel(false);
404 complementPanel.scrollToCentre(sr, seqOffset);
405 complementPanel.setToScrollComplementPanel(true);
410 * Applies the supplied feature settings descriptor to currently known
411 * features. This supports an 'initial configuration' of feature colouring
412 * based on a preset or user favourite. This may then be modified in the usual
413 * way using the Feature Settings dialogue.
415 * @param featureSettings
418 public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
420 // TODO implement for applet