2 * Copyright (C) $$Year-Rel$$ The Jalview Authors
3 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
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 java.awt.Frame nullFrame;
59 protected FeatureSettings featureSettings = null;
61 private float heightScale = 1, widthScale = 1;
63 public AlignViewport(AlignmentI al, JalviewLite applet)
66 calculator = new jalview.workers.AlignCalcManager2();
70 this.setPadGaps(true);
74 // get the width and height scaling factors if they were specified
75 String param = applet.getParameter("widthScale");
80 widthScale = Float.valueOf(param).floatValue();
84 if (widthScale <= 1.0)
87 "Invalid alignment character width scaling factor ("
88 + widthScale + "). Ignoring.");
91 if (JalviewLite.debug)
94 "Alignment character width scaling factor is now "
98 param = applet.getParameter("heightScale");
103 heightScale = Float.valueOf(param).floatValue();
104 } catch (Exception e)
107 if (heightScale <= 1.0)
110 "Invalid alignment character height scaling factor ("
111 + heightScale + "). Ignoring.");
114 if (JalviewLite.debug)
117 "Alignment character height scaling factor is now "
127 applet.getDefaultParameter("showFullId", getShowJVSuffix()));
129 setShowAnnotation(applet.getDefaultParameter("showAnnotation",
130 isShowAnnotation()));
132 showConservation = applet.getDefaultParameter("showConservation",
135 showQuality = applet.getDefaultParameter("showQuality", showQuality);
137 showConsensus = applet.getDefaultParameter("showConsensus",
140 showOccupancy = applet.getDefaultParameter("showOccupancy",
143 setShowUnconserved(applet.getDefaultParameter("showUnconserved",
144 getShowUnconserved()));
146 setScaleProteinAsCdna(applet.getDefaultParameter("scaleProteinAsCdna",
147 isScaleProteinAsCdna()));
149 String param = applet.getParameter("upperCase");
152 if (param.equalsIgnoreCase("bold"))
154 setUpperCasebold(true);
157 sortByTree = applet.getDefaultParameter("sortByTree", sortByTree);
159 setFollowHighlight(applet.getDefaultParameter("automaticScrolling",
160 isFollowHighlight()));
161 followSelection = isFollowHighlight();
163 showSequenceLogo = applet.getDefaultParameter("showSequenceLogo",
166 normaliseSequenceLogo = applet.getDefaultParameter(
167 "normaliseSequenceLogo", applet.getDefaultParameter(
168 "normaliseLogo", normaliseSequenceLogo));
170 showGroupConsensus = applet.getDefaultParameter("showGroupConsensus",
173 showGroupConservation = applet.getDefaultParameter(
174 "showGroupConservation", showGroupConservation);
176 showConsensusHistogram = applet.getDefaultParameter(
177 "showConsensusHistogram", showConsensusHistogram);
183 String colour = al.isNucleotide()
184 ? applet.getParameter("defaultColourNuc")
185 : applet.getParameter("defaultColourProt");
188 colour = applet.getParameter("defaultColour");
192 colour = applet.getParameter("userDefinedColour");
195 colour = "User Defined";
201 residueShading = new ResidueShader(
202 ColourSchemeProperty.getColourScheme(this, alignment,
204 if (residueShading != null)
206 residueShading.setConsensus(consensusProfiles);
210 if (applet.getParameter("userDefinedColour") != null)
212 residueShading = new ResidueShader(new UserColourScheme(
213 applet.getParameter("userDefinedColour")));
216 initAutoAnnotation();
223 public void setFont(Font f, boolean setGrid)
226 if (nullFrame == null)
228 nullFrame = new java.awt.Frame();
229 nullFrame.addNotify();
234 FontMetrics fm = nullFrame.getGraphics().getFontMetrics(font);
235 setCharHeight((int) (heightScale * fm.getHeight()));
236 setCharWidth((int) (widthScale * fm.charWidth('M')));
239 if (isUpperCasebold())
241 Font f2 = new Font(f.getName(), Font.BOLD, f.getSize());
242 FontMetrics fm = nullFrame.getGraphics().getFontMetrics(f2);
244 (int) (widthScale * (fm.stringWidth("MMMMMMMMMMM") / 10)));
248 public Font getFont()
253 public void resetSeqLimits(int height)
255 ranges.setEndSeq(height / getCharHeight() - 1); // BH 2019.04.18
258 boolean centreColumnLabels;
260 public boolean getCentreColumnLabels()
262 return centreColumnLabels;
265 public boolean followSelection = true;
268 * @return true if view selection should always follow the selections
269 * broadcast by other selection sources
271 public boolean getFollowSelection()
273 return followSelection;
277 public void sendSelection()
279 getStructureSelectionManager().sendSelection(
280 new SequenceGroup(getSelectionGroup()),
281 new ColumnSelection(getColumnSelection()),
282 new HiddenColumns(getAlignment().getHiddenColumns()), this);
286 * Returns an instance of the StructureSelectionManager scoped to this applet
292 public StructureSelectionManager getStructureSelectionManager()
294 return jalview.structure.StructureSelectionManager
295 .getStructureSelectionManager(applet);
300 * @return true if alignment characters should be displayed
303 public boolean isValidCharWidth()
305 return validCharWidth;
308 public AnnotationColumnChooser getAnnotationColumnSelectionState()
310 return annotationColumnSelectionState;
313 public void setAnnotationColumnSelectionState(
314 AnnotationColumnChooser annotationColumnSelectionState)
316 this.annotationColumnSelectionState = annotationColumnSelectionState;
320 public void mirrorCommand(CommandI command, boolean undo,
321 StructureSelectionManager ssm, VamsasSource source)
323 // TODO refactor so this can be pulled up to superclass or controller
325 * Do nothing unless we are a 'complement' of the source. May replace this
326 * with direct calls not via SSM.
328 if (source instanceof AlignViewportI
329 && ((AlignViewportI) source).getCodingComplement() == this)
338 CommandI mappedCommand = ssm.mapCommand(command, undo, getAlignment(),
340 if (mappedCommand != null)
342 mappedCommand.doCommand(null);
345 // ap.scalePanelHolder.repaint();
351 public VamsasSource getVamsasSource()
357 * If this viewport has a (Protein/cDNA) complement, then scroll the
358 * complementary alignment to match this one.
360 public void scrollComplementaryAlignment(AlignmentPanel complementPanel)
362 if (complementPanel == null)
368 * Populate a SearchResults object with the mapped location to scroll to. If
369 * there is no complement, or it is not following highlights, or no mapping
370 * is found, the result will be empty.
372 SearchResultsI sr = new SearchResults();
373 int seqOffset = findComplementScrollTarget(sr);
376 complementPanel.setToScrollComplementPanel(false);
377 complementPanel.scrollToCentre(sr, seqOffset);
378 complementPanel.setToScrollComplementPanel(true);
383 * Applies the supplied feature settings descriptor to currently known features.
384 * This supports an 'initial configuration' of feature colouring based on a
385 * preset or user favourite. This may then be modified in the usual way using
386 * the Feature Settings dialogue. NOT IMPLEMENTED FOR APPLET
388 * @param featureSettings
391 public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
393 // TODO implement for applet
397 * Merges the supplied feature settings descriptor with existing feature styles.
398 * This supports an 'initial configuration' of feature colouring based on a
399 * preset or user favourite. This may then be modified in the usual way using
400 * the Feature Settings dialogue. NOT IMPLEMENTED FOR APPLET
402 * @param featureSettings
405 public void mergeFeaturesStyle(FeatureSettingsModelI featureSettings)
407 // TODO Auto-generated method stub