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;
58 private AnnotationColumnChooser annotationColumnSelectionState;
60 public AlignViewport(AlignmentI al, JalviewLite applet)
63 calculator = new jalview.workers.AlignCalcManager();
67 this.setPadGaps(true);
71 // get the width and height scaling factors if they were specified
72 String param = applet.getParameter("widthScale");
77 widthScale = new Float(param).floatValue();
81 if (widthScale <= 1.0)
84 "Invalid alignment character width scaling factor ("
85 + widthScale + "). Ignoring.");
88 if (JalviewLite.debug)
91 "Alignment character width scaling factor is now "
95 param = applet.getParameter("heightScale");
100 heightScale = new Float(param).floatValue();
101 } catch (Exception e)
104 if (heightScale <= 1.0)
107 "Invalid alignment character height scaling factor ("
108 + heightScale + "). Ignoring.");
111 if (JalviewLite.debug)
114 "Alignment character height scaling factor is now "
124 applet.getDefaultParameter("showFullId", getShowJVSuffix()));
126 setShowAnnotation(applet.getDefaultParameter("showAnnotation",
127 isShowAnnotation()));
129 showConservation = applet.getDefaultParameter("showConservation",
132 showQuality = applet.getDefaultParameter("showQuality", showQuality);
134 showConsensus = applet.getDefaultParameter("showConsensus",
137 showOccupancy = applet.getDefaultParameter("showOccupancy",
140 setShowUnconserved(applet.getDefaultParameter("showUnconserved",
141 getShowUnconserved()));
143 setScaleProteinAsCdna(applet.getDefaultParameter("scaleProteinAsCdna",
144 isScaleProteinAsCdna()));
146 String param = applet.getParameter("upperCase");
149 if (param.equalsIgnoreCase("bold"))
151 setUpperCasebold(true);
154 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
156 setFollowHighlight(applet.getDefaultParameter("automaticScrolling",
157 isFollowHighlight()));
158 followSelection = isFollowHighlight();
160 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
163 normaliseSequenceLogo = applet.getDefaultParameter(
164 "normaliseSequenceLogo", applet.getDefaultParameter(
165 "normaliseLogo", normaliseSequenceLogo));
167 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
170 showGroupConservation = applet.getDefaultParameter(
171 "showGroupConservation", showGroupConservation);
173 showConsensusHistogram = applet.getDefaultParameter(
174 "showConsensusHistogram", showConsensusHistogram);
180 String colour = al.isNucleotide()
181 ? applet.getParameter("defaultColourNuc")
182 : applet.getParameter("defaultColourProt");
185 colour = applet.getParameter("defaultColour");
189 colour = applet.getParameter("userDefinedColour");
192 colour = "User Defined";
198 residueShading = new ResidueShader(
199 ColourSchemeProperty.getColourScheme(alignment, colour));
200 if (residueShading != null)
202 residueShading.setConsensus(hconsensus);
206 if (applet.getParameter("userDefinedColour") != null)
208 residueShading = new ResidueShader(new UserColourScheme(
209 applet.getParameter("userDefinedColour")));
212 initAutoAnnotation();
216 java.awt.Frame nullFrame;
218 protected FeatureSettings featureSettings = null;
220 private float heightScale = 1, widthScale = 1;
226 public void setFont(Font f, boolean setGrid)
229 if (nullFrame == null)
231 nullFrame = new java.awt.Frame();
232 nullFrame.addNotify();
237 FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
238 setCharHeight((int) (heightScale * fm.getHeight()));
239 setCharWidth((int) (widthScale * fm.charWidth('M')));
242 if (isUpperCasebold())
244 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
245 FontMetrics fm = nullFrame.getGraphics().getFontMetrics(f2);
247 (int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10)));
251 public Font getFont()
256 public void resetSeqLimits(int height)
258 ranges.setEndSeq(height / getCharHeight());
261 boolean centreColumnLabels;
263 public boolean getCentreColumnLabels()
265 return centreColumnLabels;
268 public boolean followSelection = true;
271 * @return true if view selection should always follow the selections
272 * broadcast by other selection sources
274 public boolean getFollowSelection()
276 return followSelection;
280 public void sendSelection()
282 getStructureSelectionManager().sendSelection(
283 new SequenceGroup(getSelectionGroup()),
284 new ColumnSelection(getColumnSelection()),
285 new HiddenColumns(getAlignment().getHiddenColumns()), this);
289 * Returns an instance of the StructureSelectionManager scoped to this applet
295 public StructureSelectionManager getStructureSelectionManager()
297 return jalview.structure.StructureSelectionManager
298 .getStructureSelectionManager(applet);
302 public boolean isNormaliseSequenceLogo()
304 return normaliseSequenceLogo;
307 public void setNormaliseSequenceLogo(boolean state)
309 normaliseSequenceLogo = state;
314 * @return true if alignment characters should be displayed
317 public boolean isValidCharWidth()
319 return validCharWidth;
322 public AnnotationColumnChooser getAnnotationColumnSelectionState()
324 return annotationColumnSelectionState;
327 public void setAnnotationColumnSelectionState(
328 AnnotationColumnChooser annotationColumnSelectionState)
330 this.annotationColumnSelectionState = annotationColumnSelectionState;
334 public void mirrorCommand(CommandI command, boolean undo,
335 StructureSelectionManager ssm, VamsasSource source)
337 // TODO refactor so this can be pulled up to superclass or controller
339 * Do nothing unless we are a 'complement' of the source. May replace this
340 * with direct calls not via SSM.
342 if (source instanceof AlignViewportI
343 && ((AlignViewportI) source).getCodingComplement() == this)
352 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
354 if (mappedCommand != null)
356 mappedCommand.doCommand(null);
357 firePropertyChange("alignment", null, getAlignment().getSequences());
359 // ap.scalePanelHolder.repaint();
365 public VamsasSource getVamsasSource()
371 * If this viewport has a (Protein/cDNA) complement, then scroll the
372 * complementary alignment to match this one.
374 public void scrollComplementaryAlignment(AlignmentPanel complementPanel)
376 if (complementPanel == null)
382 * Populate a SearchResults object with the mapped location to scroll to. If
383 * there is no complement, or it is not following highlights, or no mapping
384 * is found, the result will be empty.
386 SearchResultsI sr = new SearchResults();
387 int seqOffset = findComplementScrollTarget(sr);
390 complementPanel.setToScrollComplementPanel(false);
391 complementPanel.scrollToCentre(sr, seqOffset);
392 complementPanel.setToScrollComplementPanel(true);
397 * Applies the supplied feature settings descriptor to currently known
398 * features. This supports an 'initial configuration' of feature colouring
399 * based on a preset or user favourite. This may then be modified in the usual
400 * way using the Feature Settings dialogue.
402 * @param featureSettings
405 public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
407 // TODO implement for applet