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.ColumnSelection;
29 import jalview.datamodel.HiddenColumns;
30 import jalview.datamodel.SearchResults;
31 import jalview.datamodel.SearchResultsI;
32 import jalview.datamodel.SequenceGroup;
33 import jalview.renderer.ResidueShader;
34 import jalview.schemes.ColourSchemeProperty;
35 import jalview.schemes.UserColourScheme;
36 import jalview.structure.SelectionSource;
37 import jalview.structure.StructureSelectionManager;
38 import jalview.structure.VamsasSource;
39 import jalview.viewmodel.AlignmentViewport;
42 import java.awt.FontMetrics;
44 public class AlignViewport extends AlignmentViewport
45 implements SelectionSource
47 boolean cursorMode = false;
49 Font font = new Font("SansSerif", Font.PLAIN, 10);
51 boolean validCharWidth = true;
53 public jalview.bin.JalviewLite applet;
55 private AnnotationColumnChooser annotationColumnSelectionState;
57 public AlignViewport(AlignmentI al, JalviewLite applet)
60 calculator = new jalview.workers.AlignCalcManager();
64 this.setPadGaps(true);
68 // get the width and height scaling factors if they were specified
69 String param = applet.getParameter("widthScale");
74 widthScale = new Float(param).floatValue();
78 if (widthScale <= 1.0)
81 "Invalid alignment character width scaling factor ("
82 + widthScale + "). Ignoring.");
85 if (JalviewLite.debug)
88 "Alignment character width scaling factor is now "
92 param = applet.getParameter("heightScale");
97 heightScale = new Float(param).floatValue();
101 if (heightScale <= 1.0)
104 "Invalid alignment character height scaling factor ("
105 + heightScale + "). Ignoring.");
108 if (JalviewLite.debug)
111 "Alignment character height scaling factor is now "
121 applet.getDefaultParameter("showFullId", getShowJVSuffix()));
123 setShowAnnotation(applet.getDefaultParameter("showAnnotation",
124 isShowAnnotation()));
126 showConservation = applet.getDefaultParameter("showConservation",
129 showQuality = applet.getDefaultParameter("showQuality", showQuality);
131 showConsensus = applet.getDefaultParameter("showConsensus",
134 showOccupancy = applet.getDefaultParameter("showOccupancy",
137 setShowUnconserved(applet.getDefaultParameter("showUnconserved",
138 getShowUnconserved()));
140 setScaleProteinAsCdna(applet.getDefaultParameter("scaleProteinAsCdna",
141 isScaleProteinAsCdna()));
143 String param = applet.getParameter("upperCase");
146 if (param.equalsIgnoreCase("bold"))
148 setUpperCasebold(true);
151 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
153 setFollowHighlight(applet.getDefaultParameter("automaticScrolling",
154 isFollowHighlight()));
155 followSelection = isFollowHighlight();
157 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
160 normaliseSequenceLogo = applet.getDefaultParameter(
161 "normaliseSequenceLogo", applet.getDefaultParameter(
162 "normaliseLogo", normaliseSequenceLogo));
164 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
167 showGroupConservation = applet.getDefaultParameter(
168 "showGroupConservation", showGroupConservation);
170 showConsensusHistogram = applet.getDefaultParameter(
171 "showConsensusHistogram", showConsensusHistogram);
177 String colour = al.isNucleotide()
178 ? applet.getParameter("defaultColourNuc")
179 : applet.getParameter("defaultColourProt");
182 colour = applet.getParameter("defaultColour");
186 colour = applet.getParameter("userDefinedColour");
189 colour = "User Defined";
195 residueShading = new ResidueShader(
196 ColourSchemeProperty.getColourScheme(this, alignment,
198 if (residueShading != null)
200 residueShading.setConsensus(hconsensus);
204 if (applet.getParameter("userDefinedColour") != null)
206 residueShading = new ResidueShader(new UserColourScheme(
207 applet.getParameter("userDefinedColour")));
210 initAutoAnnotation();
214 java.awt.Frame nullFrame;
216 protected FeatureSettings featureSettings = null;
218 private float heightScale = 1, widthScale = 1;
224 public void setFont(Font f, boolean setGrid)
227 if (nullFrame == null)
229 nullFrame = new java.awt.Frame();
230 nullFrame.addNotify();
235 FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
236 setCharHeight((int) (heightScale * fm.getHeight()));
237 setCharWidth((int) (widthScale * fm.charWidth('M')));
240 if (isUpperCasebold())
242 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
243 FontMetrics fm = nullFrame.getGraphics().getFontMetrics(f2);
245 (int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10)));
249 public Font getFont()
254 public void resetSeqLimits(int height)
256 ranges.setEndSeq(height / getCharHeight());
259 boolean centreColumnLabels;
261 public boolean getCentreColumnLabels()
263 return centreColumnLabels;
266 public boolean followSelection = true;
269 * @return true if view selection should always follow the selections
270 * broadcast by other selection sources
272 public boolean getFollowSelection()
274 return followSelection;
278 public void sendSelection()
280 getStructureSelectionManager().sendSelection(
281 new SequenceGroup(getSelectionGroup()),
282 new ColumnSelection(getColumnSelection()),
283 new HiddenColumns(getAlignment().getHiddenColumns()), this);
287 * Returns an instance of the StructureSelectionManager scoped to this applet
293 public StructureSelectionManager getStructureSelectionManager()
295 return jalview.structure.StructureSelectionManager
296 .getStructureSelectionManager(applet);
300 public boolean isNormaliseSequenceLogo()
302 return normaliseSequenceLogo;
305 public void setNormaliseSequenceLogo(boolean state)
307 normaliseSequenceLogo = state;
312 * @return true if alignment characters should be displayed
315 public boolean isValidCharWidth()
317 return validCharWidth;
320 public AnnotationColumnChooser getAnnotationColumnSelectionState()
322 return annotationColumnSelectionState;
325 public void setAnnotationColumnSelectionState(
326 AnnotationColumnChooser annotationColumnSelectionState)
328 this.annotationColumnSelectionState = annotationColumnSelectionState;
332 public void mirrorCommand(CommandI command, boolean undo,
333 StructureSelectionManager ssm, VamsasSource source)
335 // TODO refactor so this can be pulled up to superclass or controller
337 * Do nothing unless we are a 'complement' of the source. May replace this
338 * with direct calls not via SSM.
340 if (source instanceof AlignViewportI
341 && ((AlignViewportI) source).getCodingComplement() == this)
350 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
352 if (mappedCommand != null)
354 mappedCommand.doCommand(null);
355 firePropertyChange("alignment", null, getAlignment().getSequences());
357 // ap.scalePanelHolder.repaint();
363 public VamsasSource getVamsasSource()
369 * If this viewport has a (Protein/cDNA) complement, then scroll the
370 * complementary alignment to match this one.
372 public void scrollComplementaryAlignment(AlignmentPanel complementPanel)
374 if (complementPanel == null)
380 * Populate a SearchResults object with the mapped location to scroll to. If
381 * there is no complement, or it is not following highlights, or no mapping
382 * is found, the result will be empty.
384 SearchResultsI sr = new SearchResults();
385 int seqOffset = findComplementScrollTarget(sr);
388 complementPanel.setToScrollComplementPanel(false);
389 complementPanel.scrollToCentre(sr, seqOffset);
390 complementPanel.setToScrollComplementPanel(true);
395 * Applies the supplied feature settings descriptor to currently known
396 * features. This supports an 'initial configuration' of feature colouring
397 * based on a preset or user favourite. This may then be modified in the usual
398 * way using the Feature Settings dialogue.
400 * @param featureSettings
403 public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
405 // TODO implement for applet